提交 5f2a1327 编写于 作者: J John Ferlan

qemu: Introduce qemuDomainChardevPrivatePtr

Modeled after the qemuDomainHostdevPrivatePtr (commit id '27726d8c'),
create a privateData pointer in the _virDomainChardevDef to allow storage
of private data for a hypervisor in order to at least temporarily store
secret data for usage during qemuBuildCommandLine.

NB: Since the qemu_parse_command (qemuParseCommandLine) code is not
expecting to restore the secret data, there's no need to add code
code to handle this new structure there.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 3b668bb5
......@@ -2125,6 +2125,8 @@ void virDomainChrDefFree(virDomainChrDefPtr def)
VIR_FREE(def->seclabels);
}
virObjectUnref(def->privateData);
VIR_FREE(def);
}
......@@ -10318,7 +10320,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
* default port.
*/
virDomainChrDefPtr
virDomainChrDefNew(void)
virDomainChrDefNew(virDomainXMLOptionPtr xmlopt)
{
virDomainChrDefPtr def = NULL;
......@@ -10326,6 +10328,11 @@ virDomainChrDefNew(void)
return NULL;
def->target.port = -1;
if (xmlopt && xmlopt->privateData.chardevNew &&
!(def->privateData = xmlopt->privateData.chardevNew()))
VIR_FREE(def);
return def;
}
......@@ -10373,7 +10380,8 @@ virDomainChrDefNew(void)
*
*/
static virDomainChrDefPtr
virDomainChrDefParseXML(xmlXPathContextPtr ctxt,
virDomainChrDefParseXML(virDomainXMLOptionPtr xmlopt,
xmlXPathContextPtr ctxt,
xmlNodePtr node,
virSecurityLabelDefPtr* vmSeclabels,
int nvmSeclabels,
......@@ -10385,7 +10393,7 @@ virDomainChrDefParseXML(xmlXPathContextPtr ctxt,
virDomainChrDefPtr def;
bool seenTarget = false;
if (!(def = virDomainChrDefNew()))
if (!(def = virDomainChrDefNew(xmlopt)))
return NULL;
type = virXMLPropString(node, "type");
......@@ -13563,7 +13571,8 @@ virDomainDeviceDefParse(const char *xmlStr,
goto error;
break;
case VIR_DOMAIN_DEVICE_CHR:
if (!(dev->data.chr = virDomainChrDefParseXML(ctxt,
if (!(dev->data.chr = virDomainChrDefParseXML(xmlopt,
ctxt,
node,
def->seclabels,
def->nseclabels,
......@@ -17182,7 +17191,8 @@ virDomainDefParseXML(xmlDocPtr xml,
goto error;
for (i = 0; i < n; i++) {
virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt,
virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
ctxt,
nodes[i],
def->seclabels,
def->nseclabels,
......@@ -17209,7 +17219,8 @@ virDomainDefParseXML(xmlDocPtr xml,
goto error;
for (i = 0; i < n; i++) {
virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt,
virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
ctxt,
nodes[i],
def->seclabels,
def->nseclabels,
......@@ -17238,7 +17249,8 @@ virDomainDefParseXML(xmlDocPtr xml,
goto error;
for (i = 0; i < n; i++) {
virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt,
virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
ctxt,
nodes[i],
def->seclabels,
def->nseclabels,
......@@ -17257,7 +17269,8 @@ virDomainDefParseXML(xmlDocPtr xml,
goto error;
for (i = 0; i < n; i++) {
virDomainChrDefPtr chr = virDomainChrDefParseXML(ctxt,
virDomainChrDefPtr chr = virDomainChrDefParseXML(xmlopt,
ctxt,
nodes[i],
def->seclabels,
def->nseclabels,
......
......@@ -1117,6 +1117,7 @@ struct _virDomainChrSourceDef {
/* A complete character device, both host and domain views. */
struct _virDomainChrDef {
int deviceType; /* enum virDomainChrDeviceType */
virObjectPtr privateData;
bool targetTypeAttr;
int targetType; /* enum virDomainChrConsoleTargetType ||
......@@ -2446,6 +2447,7 @@ struct _virDomainXMLPrivateDataCallbacks {
virDomainXMLPrivateDataNewFunc diskNew;
virDomainXMLPrivateDataNewFunc hostdevNew;
virDomainXMLPrivateDataNewFunc vcpuNew;
virDomainXMLPrivateDataNewFunc chardevNew;
virDomainXMLPrivateDataFormatFunc format;
virDomainXMLPrivateDataParseFunc parse;
};
......@@ -2581,7 +2583,7 @@ bool virDomainDefHasDeviceAddress(virDomainDefPtr def,
void virDomainDefFree(virDomainDefPtr vm);
virDomainChrDefPtr virDomainChrDefNew(void);
virDomainChrDefPtr virDomainChrDefNew(virDomainXMLOptionPtr xmlopt);
virDomainDefPtr virDomainDefNew(void);
virDomainDefPtr virDomainDefNewFull(const char *name,
......
......@@ -389,7 +389,7 @@ libxlDomainDefPostParse(virDomainDefPtr def,
if (def->os.type != VIR_DOMAIN_OSTYPE_HVM && def->nconsoles == 0) {
virDomainChrDefPtr chrdef;
if (!(chrdef = virDomainChrDefNew()))
if (!(chrdef = virDomainChrDefNew(NULL)))
return -1;
chrdef->source.type = VIR_DOMAIN_CHR_TYPE_PTY;
......
......@@ -703,7 +703,7 @@ lxcCreateConsoles(virDomainDefPtr def, virConfPtr properties)
def->nconsoles = nbttys;
for (i = 0; i < nbttys; i++) {
if (!(console = virDomainChrDefNew()))
if (!(console = virDomainChrDefNew(NULL)))
goto error;
console->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
......
......@@ -864,6 +864,49 @@ qemuDomainVcpuPrivateDispose(void *obj)
}
static virClassPtr qemuDomainChardevPrivateClass;
static void qemuDomainChardevPrivateDispose(void *obj);
static int
qemuDomainChardevPrivateOnceInit(void)
{
qemuDomainChardevPrivateClass =
virClassNew(virClassForObject(),
"qemuDomainChardevPrivate",
sizeof(qemuDomainChardevPrivate),
qemuDomainChardevPrivateDispose);
if (!qemuDomainChardevPrivateClass)
return -1;
else
return 0;
}
VIR_ONCE_GLOBAL_INIT(qemuDomainChardevPrivate)
static virObjectPtr
qemuDomainChardevPrivateNew(void)
{
qemuDomainChardevPrivatePtr priv;
if (qemuDomainChardevPrivateInitialize() < 0)
return NULL;
if (!(priv = virObjectNew(qemuDomainChardevPrivateClass)))
return NULL;
return (virObjectPtr) priv;
}
static void
qemuDomainChardevPrivateDispose(void *obj)
{
qemuDomainChardevPrivatePtr priv = obj;
qemuDomainSecretInfoFree(&priv->secinfo);
}
/* qemuDomainSecretPlainSetup:
* @conn: Pointer to connection
* @secinfo: Pointer to secret info
......@@ -1764,6 +1807,7 @@ virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks = {
.diskNew = qemuDomainDiskPrivateNew,
.vcpuNew = qemuDomainVcpuPrivateNew,
.hostdevNew = qemuDomainHostdevPrivateNew,
.chardevNew = qemuDomainChardevPrivateNew,
.parse = qemuDomainObjPrivateXMLParse,
.format = qemuDomainObjPrivateXMLFormat,
};
......
......@@ -352,6 +352,20 @@ struct _qemuDomainHostdevPrivate {
qemuDomainSecretInfoPtr secinfo;
};
# define QEMU_DOMAIN_CHARDEV_PRIVATE(chardev) \
((qemuDomainChardevPrivatePtr) (chardev)->privateData)
typedef struct _qemuDomainChardevPrivate qemuDomainChardevPrivate;
typedef qemuDomainChardevPrivate *qemuDomainChardevPrivatePtr;
struct _qemuDomainChardevPrivate {
virObject parent;
/* for char devices using secret
* NB: *not* to be written to qemu domain object XML */
qemuDomainSecretInfoPtr secinfo;
};
typedef enum {
QEMU_PROCESS_EVENT_WATCHDOG = 0,
QEMU_PROCESS_EVENT_GUESTPANIC,
......
......@@ -2189,7 +2189,7 @@ qemuParseCommandLine(virCapsPtr caps,
if (STRNEQ(val, "none")) {
virDomainChrDefPtr chr;
if (!(chr = virDomainChrDefNew()))
if (!(chr = virDomainChrDefNew(NULL)))
goto error;
if (qemuParseCommandLineChr(&chr->source, val) < 0) {
......@@ -2208,7 +2208,7 @@ qemuParseCommandLine(virCapsPtr caps,
if (STRNEQ(val, "none")) {
virDomainChrDefPtr chr;
if (!(chr = virDomainChrDefNew()))
if (!(chr = virDomainChrDefNew(NULL)))
goto error;
if (qemuParseCommandLineChr(&chr->source, val) < 0) {
......
......@@ -1214,7 +1214,7 @@ prlsdkAddSerialInfo(PRL_HANDLE sdkdom,
ret = PrlVmCfg_GetSerialPort(sdkdom, i, &serialPort);
prlsdkCheckRetGoto(ret, cleanup);
if (!(chr = virDomainChrDefNew()))
if (!(chr = virDomainChrDefNew(NULL)))
goto cleanup;
if (prlsdkGetSerialInfo(serialPort, chr))
......
......@@ -190,7 +190,7 @@ xenParseSxprChar(const char *value,
char *tmp;
virDomainChrDefPtr def;
if (!(def = virDomainChrDefNew()))
if (!(def = virDomainChrDefNew(NULL)))
return NULL;
prefix = value;
......
......@@ -737,7 +737,7 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
key = nextkey;
}
if (!(channel = virDomainChrDefNew()))
if (!(channel = virDomainChrDefNew(NULL)))
goto cleanup;
if (STRPREFIX(type, "socket")) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册