Modeled after the qemuDomainDiskPrivatePtr logic, create a privateData
pointer in the _virDomainHostdevDef to allow storage of private data
for a hypervisor in order to at least temporarily store auth/secrets
data for usage during qemuBuildCommandLine.
NB: Since the qemu_parse_command (qemuParseCommandLine) code is not
expecting to restore the auth/secret data, there's no need to add
code to handle this new structure there.
Updated copyrights for modules touched. Some didn't have updates in a
couple years even though changes have been made.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/domain_conf.c | 28 +++++++++++++++++++++------
src/conf/domain_conf.h | 7 +++++--
src/lxc/lxc_native.c | 4 ++--
src/qemu/qemu_domain.c | 44 +++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_domain.h | 13 +++++++++++++
src/qemu/qemu_parse_command.c | 4 ++--
src/vbox/vbox_common.c | 4 ++--
src/xenconfig/xen_common.c | 4 ++--
src/xenconfig/xen_sxpr.c | 4 ++--
tests/virhostdevtest.c | 3 ++-
10 files changed, 96 insertions(+), 19 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 48c7bc5..55b16dc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2115,16 +2115,29 @@ void virDomainVideoDefFree(virDomainVideoDefPtr def)
VIR_FREE(def);
}
-virDomainHostdevDefPtr virDomainHostdevDefAlloc(void)
+
+virDomainHostdevDefPtr
+virDomainHostdevDefAlloc(virDomainXMLOptionPtr xmlopt)
{
virDomainHostdevDefPtr def = NULL;
if (VIR_ALLOC(def) < 0 ||
VIR_ALLOC(def->info) < 0)
VIR_FREE(def);
+
+ if (xmlopt &&
+ xmlopt->privateData.hostdevNew &&
+ !(def->privateData = xmlopt->privateData.hostdevNew()))
+ goto error;
+
return def;
+
+ error:
+ virDomainHostdevDefFree(def);
+ return NULL;
}
+
static void
virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc)
{
@@ -12271,7 +12284,8 @@ virDomainVideoDefParseXML(xmlNodePtr node,
}
static virDomainHostdevDefPtr
-virDomainHostdevDefParseXML(xmlNodePtr node,
+virDomainHostdevDefParseXML(virDomainXMLOptionPtr xmlopt,
+ xmlNodePtr node,
xmlXPathContextPtr ctxt,
virHashTablePtr bootHash,
unsigned int flags)
@@ -12283,7 +12297,7 @@ virDomainHostdevDefParseXML(xmlNodePtr node,
ctxt->node = node;
- if (!(def = virDomainHostdevDefAlloc()))
+ if (!(def = virDomainHostdevDefAlloc(xmlopt)))
goto error;
if (mode) {
@@ -12933,8 +12947,9 @@ virDomainDeviceDefParse(const char *xmlStr,
goto error;
break;
case VIR_DOMAIN_DEVICE_HOSTDEV:
- if (!(dev->data.hostdev = virDomainHostdevDefParseXML(node, ctxt,
- NULL, flags)))
+ if (!(dev->data.hostdev = virDomainHostdevDefParseXML(xmlopt, node,
+ ctxt, NULL,
+ flags)))
goto error;
break;
case VIR_DOMAIN_DEVICE_CONTROLLER:
@@ -16454,7 +16469,8 @@ virDomainDefParseXML(xmlDocPtr xml,
for (i = 0; i < n; i++) {
virDomainHostdevDefPtr hostdev;
- hostdev = virDomainHostdevDefParseXML(nodes[i], ctxt, bootHash, flags);
+ hostdev = virDomainHostdevDefParseXML(xmlopt, nodes[i], ctxt,
+ bootHash, flags);
if (!hostdev)
goto error;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6f93def..d442866 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1,7 +1,7 @@
/*
* domain_conf.h: domain XML processing
*
- * Copyright (C) 2006-2015 Red Hat, Inc.
+ * Copyright (C) 2006-2016 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
* Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
@@ -543,6 +543,8 @@ struct _virDomainHostdevCaps {
/* basic device for direct passthrough */
struct _virDomainHostdevDef {
virDomainDeviceDef parent; /* higher level Def containing this */
+ virObjectPtr privateData;
+
int mode; /* enum virDomainHostdevMode */
int startupPolicy; /* enum virDomainStartupPolicy */
bool managed;
@@ -2486,6 +2488,7 @@ struct _virDomainXMLPrivateDataCallbacks {
virDomainXMLPrivateDataAllocFunc alloc;
virDomainXMLPrivateDataFreeFunc free;
virDomainXMLPrivateDataNewFunc diskNew;
+ virDomainXMLPrivateDataNewFunc hostdevNew;
virDomainXMLPrivateDataFormatFunc format;
virDomainXMLPrivateDataParseFunc parse;
};
@@ -2563,7 +2566,7 @@ void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def);
void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def);
void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def);
void virDomainVideoDefFree(virDomainVideoDefPtr def);
-virDomainHostdevDefPtr virDomainHostdevDefAlloc(void);
+virDomainHostdevDefPtr virDomainHostdevDefAlloc(virDomainXMLOptionPtr xmlopt);
void virDomainHostdevDefClear(virDomainHostdevDefPtr def);
void virDomainHostdevDefFree(virDomainHostdevDefPtr def);
void virDomainHubDefFree(virDomainHubDefPtr def);
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index ef92c7d..31ffce7 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -1,7 +1,7 @@
/*
* lxc_native.c: LXC native configuration import
*
- * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (c) 2014-2016 Red Hat, Inc.
* Copyright (c) 2013-2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* This library is free software; you can redistribute it and/or
@@ -394,7 +394,7 @@ lxcCreateNetDef(const char *type,
static virDomainHostdevDefPtr
lxcCreateHostdevDef(int mode, int type, const char *data)
{
- virDomainHostdevDefPtr hostdev = virDomainHostdevDefAlloc();
+ virDomainHostdevDefPtr hostdev = virDomainHostdevDefAlloc(NULL);
if (!hostdev)
return NULL;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cd11bf8..613bea2 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -783,6 +783,49 @@ qemuDomainDiskPrivateDispose(void *obj)
}
+static virClassPtr qemuDomainHostdevPrivateClass;
+static void qemuDomainHostdevPrivateDispose(void *obj);
+
+static int
+qemuDomainHostdevPrivateOnceInit(void)
+{
+ qemuDomainHostdevPrivateClass =
+ virClassNew(virClassForObject(),
+ "qemuDomainHostdevPrivate",
+ sizeof(qemuDomainHostdevPrivate),
+ qemuDomainHostdevPrivateDispose);
+ if (!qemuDomainHostdevPrivateClass)
+ return -1;
+ else
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(qemuDomainHostdevPrivate)
+
+static virObjectPtr
+qemuDomainHostdevPrivateNew(void)
+{
+ qemuDomainHostdevPrivatePtr priv;
+
+ if (qemuDomainHostdevPrivateInitialize() < 0)
+ return NULL;
+
+ if (!(priv = virObjectNew(qemuDomainHostdevPrivateClass)))
+ return NULL;
+
+ return (virObjectPtr) priv;
+}
+
+
+static void
+qemuDomainHostdevPrivateDispose(void *obj)
+{
+ qemuDomainHostdevPrivatePtr priv = obj;
+
+ qemuDomainSecretInfoFree(&priv->secinfo);
+}
+
+
/* qemuDomainSecretPlainSetup:
* @conn: Pointer to connection
* @secinfo: Pointer to secret info
@@ -1420,6 +1463,7 @@ virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks =
{
.alloc = qemuDomainObjPrivateAlloc,
.free = qemuDomainObjPrivateFree,
.diskNew = qemuDomainDiskPrivateNew,
+ .hostdevNew = qemuDomainHostdevPrivateNew,
.parse = qemuDomainObjPrivateXMLParse,
.format = qemuDomainObjPrivateXMLFormat,
};
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 5609b90..f343590 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -271,6 +271,19 @@ struct _qemuDomainDiskPrivate {
qemuDomainSecretInfoPtr secinfo;
};
+# define QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev) \
+ ((qemuDomainHostdevPrivatePtr) (hostdev)->privateData)
+
+typedef struct _qemuDomainHostdevPrivate qemuDomainHostdevPrivate;
+typedef qemuDomainHostdevPrivate *qemuDomainHostdevPrivatePtr;
+struct _qemuDomainHostdevPrivate {
+ virObject parent;
+
+ /* for hostdev storage devices using auth/secret
+ * NB: *not* to be written to qemu domain object XML */
+ qemuDomainSecretInfoPtr secinfo;
+};
+
typedef enum {
QEMU_PROCESS_EVENT_WATCHDOG = 0,
QEMU_PROCESS_EVENT_GUESTPANIC,
diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
index 8b294a7..47cf48a 100644
--- a/src/qemu/qemu_parse_command.c
+++ b/src/qemu/qemu_parse_command.c
@@ -1161,7 +1161,7 @@ qemuParseCommandLinePCI(const char *val)
int bus = 0, slot = 0, func = 0;
const char *start;
char *end;
- virDomainHostdevDefPtr def = virDomainHostdevDefAlloc();
+ virDomainHostdevDefPtr def = virDomainHostdevDefAlloc(NULL);
if (!def)
goto error;
@@ -1211,7 +1211,7 @@ qemuParseCommandLinePCI(const char *val)
static virDomainHostdevDefPtr
qemuParseCommandLineUSB(const char *val)
{
- virDomainHostdevDefPtr def = virDomainHostdevDefAlloc();
+ virDomainHostdevDefPtr def = virDomainHostdevDefAlloc(NULL);
virDomainHostdevSubsysUSBPtr usbsrc;
int first = 0, second = 0;
const char *start;
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index c305eb5..a848285 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014, Taowei Luo (uaedante(a)gmail.com)
- * Copyright (C) 2010-2015 Red Hat, Inc.
+ * Copyright (C) 2010-2016 Red Hat, Inc.
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
*
* This library is free software; you can redistribute it and/or
@@ -3034,7 +3034,7 @@ vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def,
IMachine *ma
goto release_filters;
for (i = 0; i < def->nhostdevs; i++) {
- def->hostdevs[i] = virDomainHostdevDefAlloc();
+ def->hostdevs[i] = virDomainHostdevDefAlloc(NULL);
if (!def->hostdevs[i])
goto release_hostdevs;
}
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 4dcd484..82ef3a3 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -3,7 +3,7 @@
* between XM and XL
*
* Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
- * Copyright (C) 2006-2007, 2009-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2007, 2009-2016 Red Hat, Inc.
* Copyright (C) 2011 Univention GmbH
* Copyright (C) 2006 Daniel P. Berrange
*
@@ -458,7 +458,7 @@ xenParsePCI(virConfPtr conf, virDomainDefPtr def)
goto skippci;
if (virStrToLong_i(func, NULL, 16, &funcID) < 0)
goto skippci;
- if (!(hostdev = virDomainHostdevDefAlloc()))
+ if (!(hostdev = virDomainHostdevDefAlloc(NULL)))
return -1;
hostdev->managed = false;
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index fdfec2b..7a2d657 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -1,7 +1,7 @@
/*
* xen_sxpr.c: Xen SEXPR parsing functions
*
- * Copyright (C) 2010-2014 Red Hat, Inc.
+ * Copyright (C) 2010-2016 Red Hat, Inc.
* Copyright (C) 2011 Univention GmbH
* Copyright (C) 2005 Anthony Liguori <aliguori(a)us.ibm.com>
*
@@ -1110,7 +1110,7 @@ xenParseSxprPCI(virDomainDefPtr def,
goto error;
}
- if (!(dev = virDomainHostdevDefAlloc()))
+ if (!(dev = virDomainHostdevDefAlloc(NULL)))
goto error;
dev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c
index 610b02a..bc2b44a 100644
--- a/tests/virhostdevtest.c
+++ b/tests/virhostdevtest.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
+ * Copyright (C) 2014-2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -86,7 +87,7 @@ myInit(void)
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevSubsys subsys;
- hostdevs[i] = virDomainHostdevDefAlloc();
+ hostdevs[i] = virDomainHostdevDefAlloc(NULL);
if (!hostdevs[i])
goto cleanup;
hostdevs[i]->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
--
2.5.5