Since the secret information is really _virStorageSource specific
piece of data, let's create a privateData object for _virStorageSource
and move the @secinfo from _qemuDomainDiskPrivate into a new
_qemuDomainDiskSrcPrivate structure and manage it from there.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/domain_conf.c | 5 +++++
src/conf/domain_conf.h | 1 +
src/qemu/qemu_command.c | 6 ++++--
src/qemu/qemu_domain.c | 54 +++++++++++++++++++++++++++++++++++++++++------
src/qemu/qemu_domain.h | 17 +++++++++++----
src/qemu/qemu_hotplug.c | 11 +++++++---
src/util/virstoragefile.c | 1 +
src/util/virstoragefile.h | 3 +++
8 files changed, 83 insertions(+), 15 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 542d14ed6..a3900488f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1720,6 +1720,11 @@ virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
!(ret->privateData = xmlopt->privateData.diskNew()))
goto error;
+ if (xmlopt &&
+ xmlopt->privateData.diskSrcNew &&
+ !(ret->src->privateData = xmlopt->privateData.diskSrcNew()))
+ goto error;
+
return ret;
error:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index bb3b6f0c3..f6c9417b4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2620,6 +2620,7 @@ struct _virDomainXMLPrivateDataCallbacks {
/* note that private data for devices are not copied when using
* virDomainDefCopy and similar functions */
virDomainXMLPrivateDataNewFunc diskNew;
+ virDomainXMLPrivateDataNewFunc diskSrcNew;
virDomainXMLPrivateDataNewFunc hostdevNew;
virDomainXMLPrivateDataNewFunc vcpuNew;
virDomainXMLPrivateDataNewFunc chrSourceNew;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d553df57f..898a60f3b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1340,7 +1340,8 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
{
int actualType = virStorageSourceGetActualType(disk->src);
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
- qemuDomainSecretInfoPtr secinfo = diskPriv->secinfo;
+ qemuDomainDiskSrcPrivatePtr diskSrcPriv =
QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
+ qemuDomainSecretInfoPtr secinfo = diskSrcPriv->secinfo;
qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
virJSONValuePtr srcprops = NULL;
char *source = NULL;
@@ -2171,7 +2172,8 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
bool driveBoot = false;
virDomainDiskDefPtr disk = def->disks[i];
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
- qemuDomainSecretInfoPtr secinfo = diskPriv->secinfo;
+ qemuDomainDiskSrcPrivatePtr diskSrcPriv =
QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
+ qemuDomainSecretInfoPtr secinfo = diskSrcPriv->secinfo;
qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
/* PowerPC pseries based VMs do not support floppy device */
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 05f8e9488..94b6d87d6 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -921,11 +921,52 @@ qemuDomainDiskPrivateDispose(void *obj)
{
qemuDomainDiskPrivatePtr priv = obj;
- qemuDomainSecretInfoFree(&priv->secinfo);
qemuDomainSecretInfoFree(&priv->encinfo);
}
+static virClassPtr qemuDomainDiskSrcPrivateClass;
+static void qemuDomainDiskSrcPrivateDispose(void *obj);
+
+static int
+qemuDomainDiskSrcPrivateOnceInit(void)
+{
+ qemuDomainDiskSrcPrivateClass = virClassNew(virClassForObject(),
+ "qemuDomainDiskSrcPrivate",
+ sizeof(qemuDomainDiskSrcPrivate),
+ qemuDomainDiskSrcPrivateDispose);
+ if (!qemuDomainDiskSrcPrivateClass)
+ return -1;
+ else
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(qemuDomainDiskSrcPrivate)
+
+static virObjectPtr
+qemuDomainDiskSrcPrivateNew(void)
+{
+ qemuDomainDiskSrcPrivatePtr priv;
+
+ if (qemuDomainDiskSrcPrivateInitialize() < 0)
+ return NULL;
+
+ if (!(priv = virObjectNew(qemuDomainDiskSrcPrivateClass)))
+ return NULL;
+
+ return (virObjectPtr) priv;
+}
+
+
+static void
+qemuDomainDiskSrcPrivateDispose(void *obj)
+{
+ qemuDomainDiskSrcPrivatePtr priv = obj;
+
+ qemuDomainSecretInfoFree(&priv->secinfo);
+}
+
+
static virClassPtr qemuDomainHostdevPrivateClass;
static void qemuDomainHostdevPrivateDispose(void *obj);
@@ -1294,12 +1335,11 @@ qemuDomainSecretInfoTLSNew(virConnectPtr conn,
void
qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
{
- qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
-
- if (!diskPriv || !diskPriv->secinfo)
+ qemuDomainDiskSrcPrivatePtr diskSrcPriv =
QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
+ if (!diskSrcPriv || !diskSrcPriv->secinfo)
return;
- qemuDomainSecretInfoFree(&diskPriv->secinfo);
+ qemuDomainSecretInfoFree(&diskSrcPriv->secinfo);
}
@@ -1345,6 +1385,7 @@ qemuDomainSecretDiskPrepare(virConnectPtr conn,
{
virStorageSourcePtr src = disk->src;
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+ qemuDomainDiskSrcPrivatePtr diskSrcPriv =
QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
if (qemuDomainSecretDiskCapable(src)) {
virSecretUsageType usageType = VIR_SECRET_USAGE_TYPE_ISCSI;
@@ -1352,7 +1393,7 @@ qemuDomainSecretDiskPrepare(virConnectPtr conn,
if (src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD)
usageType = VIR_SECRET_USAGE_TYPE_CEPH;
- if (!(diskPriv->secinfo =
+ if (!(diskSrcPriv->secinfo =
qemuDomainSecretInfoNew(conn, priv, disk->info.alias,
usageType, src->auth->username,
&src->auth->seclookupdef, false)))
@@ -2276,6 +2317,7 @@ virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks =
{
.alloc = qemuDomainObjPrivateAlloc,
.free = qemuDomainObjPrivateFree,
.diskNew = qemuDomainDiskPrivateNew,
+ .diskSrcNew = qemuDomainDiskSrcPrivateNew,
.vcpuNew = qemuDomainVcpuPrivateNew,
.hostdevNew = qemuDomainHostdevPrivateNew,
.chrSourceNew = qemuDomainChrSourcePrivateNew,
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index b291dc308..d212812dd 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -346,10 +346,6 @@ struct _qemuDomainDiskPrivate {
bool migrating; /* the disk is being migrated */
- /* for storage devices using auth/secret
- * NB: *not* to be written to qemu domain object XML */
- qemuDomainSecretInfoPtr secinfo;
-
/* for storage devices using encryption/secret
* Can have both <auth> and <encryption> for some disks
* NB:*not* to be written to qemu domain object XML */
@@ -360,6 +356,19 @@ struct _qemuDomainDiskPrivate {
bool removable; /* device media can be removed/changed */
};
+# define QEMU_DOMAIN_DISK_SRC_PRIVATE(src) \
+ ((qemuDomainDiskSrcPrivatePtr) (src)->privateData)
+
+typedef struct _qemuDomainDiskSrcPrivate qemuDomainDiskSrcPrivate;
+typedef qemuDomainDiskSrcPrivate *qemuDomainDiskSrcPrivatePtr;
+struct _qemuDomainDiskSrcPrivate {
+ virObject parent;
+
+ /* for each storage source using auth/secret
+ * NB: *not* to be written to qemu domain object XML */
+ qemuDomainSecretInfoPtr secinfo;
+};
+
# define QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev) \
((qemuDomainHostdevPrivatePtr) (hostdev)->privateData)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7dd6e5fd9..2942772c2 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -218,6 +218,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
char *driveAlias = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+ qemuDomainDiskSrcPrivatePtr diskSrcPriv =
QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
const char *format = NULL;
char *sourcestr = NULL;
@@ -259,7 +260,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
}
if (!virStorageSourceIsEmpty(newsrc)) {
- if (qemuGetDriveSourceString(newsrc, diskPriv->secinfo, &sourcestr) <
0)
+ if (qemuGetDriveSourceString(newsrc, diskSrcPriv->secinfo, &sourcestr)
< 0)
goto error;
if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) {
@@ -329,6 +330,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
virJSONValuePtr secobjProps = NULL;
virJSONValuePtr encobjProps = NULL;
qemuDomainDiskPrivatePtr diskPriv;
+ qemuDomainDiskSrcPrivatePtr diskSrcPriv;
qemuDomainSecretInfoPtr secinfo;
qemuDomainSecretInfoPtr encinfo;
@@ -366,7 +368,8 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
goto error;
diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
- secinfo = diskPriv->secinfo;
+ diskSrcPriv = QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
+ secinfo = diskSrcPriv->secinfo;
if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
if (qemuBuildSecretInfoProps(secinfo, &secobjProps) < 0)
goto error;
@@ -621,6 +624,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
virJSONValuePtr encobjProps = NULL;
virJSONValuePtr secobjProps = NULL;
qemuDomainDiskPrivatePtr diskPriv;
+ qemuDomainDiskSrcPrivatePtr diskSrcPriv;
qemuDomainSecretInfoPtr encinfo;
qemuDomainSecretInfoPtr secinfo;
@@ -654,7 +658,8 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
goto error;
diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
- secinfo = diskPriv->secinfo;
+ diskSrcPriv = QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
+ secinfo = diskSrcPriv->secinfo;
if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
if (qemuBuildSecretInfoProps(secinfo, &secobjProps) < 0)
goto error;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 1040e9a17..39cda9c89 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2271,6 +2271,7 @@ virStorageSourceClear(virStorageSourcePtr def)
virStorageNetHostDefFree(def->nhosts, def->hosts);
virStorageAuthDefFree(def->auth);
+ virObjectUnref(def->privateData);
VIR_FREE(def->nodestorage);
VIR_FREE(def->nodeformat);
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 6c388b1a5..005f22d8e 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -27,6 +27,7 @@
# include <sys/stat.h>
# include "virbitmap.h"
+# include "virobject.h"
# include "virseclabel.h"
# include "virstorageencryption.h"
# include "virutil.h"
@@ -239,6 +240,8 @@ struct _virStorageSource {
virStorageAuthDefPtr auth;
virStorageEncryptionPtr encryption;
+ virObjectPtr privateData; /* Usable to store hypervisor specific data */
+
char *driverName;
int format; /* virStorageFileFormat in domain backing chains, but
* pool-specific enum for storage volumes */
--
2.13.5