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 | 33 +++++++++++++++++++++++++-------
src/conf/domain_conf.h | 5 ++++-
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, 99 insertions(+), 19 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 28248c8..07f5b26 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2121,16 +2121,32 @@ 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_ALLOC(def->info) < 0) {
VIR_FREE(def);
+ return NULL;
+ }
+
+ if (xmlopt &&
+ xmlopt->privateData.hostdevNew &&
+ !(def->privateData = xmlopt->privateData.hostdevNew()))
+ goto error;
+
return def;
+
+ error:
+ VIR_FREE(def->info);
+ VIR_FREE(def);
+ return NULL;
}
+
static void
virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc)
{
@@ -12247,7 +12263,8 @@ virDomainVideoDefParseXML(xmlNodePtr node,
}
static virDomainHostdevDefPtr
-virDomainHostdevDefParseXML(xmlNodePtr node,
+virDomainHostdevDefParseXML(virDomainXMLOptionPtr xmlopt,
+ xmlNodePtr node,
xmlXPathContextPtr ctxt,
virHashTablePtr bootHash,
unsigned int flags)
@@ -12259,7 +12276,7 @@ virDomainHostdevDefParseXML(xmlNodePtr node,
ctxt->node = node;
- if (!(def = virDomainHostdevDefAlloc()))
+ if (!(def = virDomainHostdevDefAlloc(xmlopt)))
goto error;
if (mode) {
@@ -12909,8 +12926,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:
@@ -16430,7 +16448,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 1986f53..fb6a02b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -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;
@@ -2495,6 +2497,7 @@ struct _virDomainXMLPrivateDataCallbacks {
virDomainXMLPrivateDataAllocFunc alloc;
virDomainXMLPrivateDataFreeFunc free;
virDomainXMLPrivateDataNewFunc diskNew;
+ virDomainXMLPrivateDataNewFunc hostdevNew;
virDomainXMLPrivateDataFormatFunc format;
virDomainXMLPrivateDataParseFunc parse;
};
@@ -2572,7 +2575,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 93033d9..89b7899 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -792,6 +792,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
@@ -1425,6 +1468,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 bde71a4..3cb961b 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -287,6 +287,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 79f5b92..577651b 100644
--- a/src/qemu/qemu_parse_command.c
+++ b/src/qemu/qemu_parse_command.c
@@ -1164,7 +1164,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;
@@ -1214,7 +1214,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 0cead10..05377f4 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
@@ -3033,7 +3033,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 e1d9cf6..c6aee69 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 2677510..dc47b4d 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