Since the encryption information can also be disk source specific
move it from _qemuDomainDiskPrivate to _qemuDomainDiskSrcPrivate.
Since the last allocated element from _qemuDomainDiskPrivate is
removed, that means we no longer need qemuDomainDiskPrivateDispose.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_command.c | 6 ++----
src/qemu/qemu_domain.c | 30 ++++++++++++------------------
src/qemu/qemu_domain.h | 10 +++++-----
src/qemu/qemu_hotplug.c | 8 ++------
4 files changed, 21 insertions(+), 33 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a5033af6d..9e1da10c9 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1348,10 +1348,9 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
virQEMUCapsPtr qemuCaps)
{
int actualType = virStorageSourceGetActualType(disk->src);
- qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
qemuDomainDiskSrcPrivatePtr diskSrcPriv =
QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
qemuDomainSecretInfoPtr secinfo = diskSrcPriv->secinfo;
- qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
+ qemuDomainSecretInfoPtr encinfo = diskSrcPriv->encinfo;
virJSONValuePtr srcprops = NULL;
char *source = NULL;
int ret = -1;
@@ -2180,10 +2179,9 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
unsigned int bootindex = 0;
bool driveBoot = false;
virDomainDiskDefPtr disk = def->disks[i];
- qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
qemuDomainDiskSrcPrivatePtr diskSrcPriv =
QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
qemuDomainSecretInfoPtr secinfo = diskSrcPriv->secinfo;
- qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
+ qemuDomainSecretInfoPtr encinfo = diskSrcPriv->encinfo;
/* PowerPC pseries based VMs do not support floppy device */
if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b9cda79c2..7707e070c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -916,7 +916,6 @@ qemuDomainSecretInfoCopy(qemuDomainSecretInfoPtr src)
static virClassPtr qemuDomainDiskPrivateClass;
-static void qemuDomainDiskPrivateDispose(void *obj);
static int
qemuDomainDiskPrivateOnceInit(void)
@@ -924,7 +923,7 @@ qemuDomainDiskPrivateOnceInit(void)
qemuDomainDiskPrivateClass = virClassNew(virClassForObject(),
"qemuDomainDiskPrivate",
sizeof(qemuDomainDiskPrivate),
- qemuDomainDiskPrivateDispose);
+ NULL);
if (!qemuDomainDiskPrivateClass)
return -1;
else
@@ -948,15 +947,6 @@ qemuDomainDiskPrivateNew(void)
}
-static void
-qemuDomainDiskPrivateDispose(void *obj)
-{
- qemuDomainDiskPrivatePtr priv = obj;
-
- qemuDomainSecretInfoFree(&priv->encinfo);
-}
-
-
static virClassPtr qemuDomainDiskSrcPrivateClass;
static void qemuDomainDiskSrcPrivateDispose(void *obj);
@@ -1001,14 +991,19 @@ qemuDomainStorageSourceCopy(const virStorageSource *src,
if (!(dst = virStorageSourceCopy(src, backingChain)))
return NULL;
- if (!srcPriv->secinfo)
+ if (!srcPriv->secinfo && !srcPriv->encinfo)
return dst;
if (!(dst->privateData = qemuDomainDiskSrcPrivateNew()))
goto error;
dstPriv = QEMU_DOMAIN_DISK_SRC_PRIVATE(dst);
- if (!(dstPriv->secinfo = qemuDomainSecretInfoCopy(srcPriv->secinfo)))
+ if (srcPriv->secinfo &&
+ !(dstPriv->secinfo = qemuDomainSecretInfoCopy(srcPriv->secinfo)))
+ goto error;
+
+ if (srcPriv->encinfo &&
+ !(dstPriv->encinfo = qemuDomainSecretInfoCopy(srcPriv->encinfo)))
goto error;
return dst;
@@ -1025,6 +1020,7 @@ qemuDomainDiskSrcPrivateDispose(void *obj)
qemuDomainDiskSrcPrivatePtr priv = obj;
qemuDomainSecretInfoFree(&priv->secinfo);
+ qemuDomainSecretInfoFree(&priv->encinfo);
}
@@ -1396,14 +1392,13 @@ qemuDomainSecretInfoTLSNew(virConnectPtr conn,
void
qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
{
- qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
qemuDomainDiskSrcPrivatePtr diskSrcPriv =
QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
if (diskSrcPriv && diskSrcPriv->secinfo)
qemuDomainSecretInfoFree(&diskSrcPriv->secinfo);
- if (diskPriv && diskPriv->encinfo)
- qemuDomainSecretInfoFree(&diskPriv->encinfo);
+ if (diskSrcPriv && diskSrcPriv->encinfo)
+ qemuDomainSecretInfoFree(&diskSrcPriv->encinfo);
}
@@ -1448,7 +1443,6 @@ qemuDomainSecretDiskPrepare(virConnectPtr conn,
virDomainDiskDefPtr disk)
{
virStorageSourcePtr src = disk->src;
- qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
qemuDomainDiskSrcPrivatePtr diskSrcPriv =
QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
if (qemuDomainSecretDiskCapable(src)) {
@@ -1465,7 +1459,7 @@ qemuDomainSecretDiskPrepare(virConnectPtr conn,
}
if (qemuDomainDiskHasEncryptionSecret(src)) {
- if (!(diskPriv->encinfo =
+ if (!(diskSrcPriv->encinfo =
qemuDomainSecretInfoNew(conn, priv, disk->info.alias,
VIR_SECRET_USAGE_TYPE_VOLUME, NULL,
&src->encryption->secrets[0]->seclookupdef,
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index c1a5431eb..8a8699240 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -345,11 +345,6 @@ struct _qemuDomainDiskPrivate {
bool migrating; /* the disk is being migrated */
- /* 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 */
- qemuDomainSecretInfoPtr encinfo;
-
/* information about the device */
bool tray; /* device has tray */
bool removable; /* device media can be removed/changed */
@@ -366,6 +361,11 @@ struct _qemuDomainDiskSrcPrivate {
/* for each storage source 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 */
+ qemuDomainSecretInfoPtr encinfo;
};
# define QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev) \
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index ad13f93e8..3f1e6d986 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -329,7 +329,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
const char *src = virDomainDiskGetSource(disk);
virJSONValuePtr secobjProps = NULL;
virJSONValuePtr encobjProps = NULL;
- qemuDomainDiskPrivatePtr diskPriv;
qemuDomainDiskSrcPrivatePtr diskSrcPriv;
qemuDomainSecretInfoPtr secinfo;
qemuDomainSecretInfoPtr encinfo;
@@ -367,7 +366,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
if (qemuDomainSecretDiskPrepare(conn, priv, disk) < 0)
goto error;
- diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
diskSrcPriv = QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
secinfo = diskSrcPriv->secinfo;
if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
@@ -375,7 +373,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
goto error;
}
- encinfo = diskPriv->encinfo;
+ encinfo = diskSrcPriv->encinfo;
if (encinfo && qemuBuildSecretInfoProps(encinfo, &encobjProps) < 0)
goto error;
@@ -623,7 +621,6 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virJSONValuePtr encobjProps = NULL;
virJSONValuePtr secobjProps = NULL;
- qemuDomainDiskPrivatePtr diskPriv;
qemuDomainDiskSrcPrivatePtr diskSrcPriv;
qemuDomainSecretInfoPtr encinfo;
qemuDomainSecretInfoPtr secinfo;
@@ -657,7 +654,6 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
if (qemuDomainSecretDiskPrepare(conn, priv, disk) < 0)
goto error;
- diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
diskSrcPriv = QEMU_DOMAIN_DISK_SRC_PRIVATE(disk->src);
secinfo = diskSrcPriv->secinfo;
if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
@@ -665,7 +661,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
goto error;
}
- encinfo = diskPriv->encinfo;
+ encinfo = diskSrcPriv->encinfo;
if (encinfo && qemuBuildSecretInfoProps(encinfo, &encobjProps) < 0)
goto error;
--
2.13.5