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 76725e2d4e..97c4890935 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1377,10 +1377,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;
@@ -2255,10 +2254,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;
if (disk->info.bootIndex) {
bootindex = disk->info.bootIndex;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 72433ed36a..ad8d484cb1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -917,7 +917,6 @@ qemuDomainSecretInfoCopy(qemuDomainSecretInfoPtr src)
static virClassPtr qemuDomainDiskPrivateClass;
-static void qemuDomainDiskPrivateDispose(void *obj);
static int
qemuDomainDiskPrivateOnceInit(void)
@@ -925,7 +924,7 @@ qemuDomainDiskPrivateOnceInit(void)
qemuDomainDiskPrivateClass = virClassNew(virClassForObject(),
"qemuDomainDiskPrivate",
sizeof(qemuDomainDiskPrivate),
- qemuDomainDiskPrivateDispose);
+ NULL);
if (!qemuDomainDiskPrivateClass)
return -1;
else
@@ -949,15 +948,6 @@ qemuDomainDiskPrivateNew(void)
}
-static void
-qemuDomainDiskPrivateDispose(void *obj)
-{
- qemuDomainDiskPrivatePtr priv = obj;
-
- qemuDomainSecretInfoFree(&priv->encinfo);
-}
-
-
static virClassPtr qemuDomainDiskSrcPrivateClass;
static void qemuDomainDiskSrcPrivateDispose(void *obj);
@@ -1002,14 +992,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;
@@ -1026,6 +1021,7 @@ qemuDomainDiskSrcPrivateDispose(void *obj)
qemuDomainDiskSrcPrivatePtr priv = obj;
qemuDomainSecretInfoFree(&priv->secinfo);
+ qemuDomainSecretInfoFree(&priv->encinfo);
}
@@ -1397,14 +1393,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);
}
@@ -1449,7 +1444,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)) {
@@ -1466,7 +1460,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 fc4f5bc6d8..97b2caefe3 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 544a592fb7..7cfe8f1bc6 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -369,7 +369,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
const char *src = virDomainDiskGetSource(disk);
virJSONValuePtr secobjProps = NULL;
virJSONValuePtr encobjProps = NULL;
- qemuDomainDiskPrivatePtr diskPriv;
qemuDomainDiskSrcPrivatePtr diskSrcPriv;
qemuDomainSecretInfoPtr secinfo;
qemuDomainSecretInfoPtr encinfo;
@@ -407,7 +406,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) {
@@ -415,7 +413,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
goto error;
}
- encinfo = diskPriv->encinfo;
+ encinfo = diskSrcPriv->encinfo;
if (encinfo && qemuBuildSecretInfoProps(encinfo, &encobjProps) < 0)
goto error;
@@ -673,7 +671,6 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virJSONValuePtr encobjProps = NULL;
virJSONValuePtr secobjProps = NULL;
- qemuDomainDiskPrivatePtr diskPriv;
qemuDomainDiskSrcPrivatePtr diskSrcPriv;
qemuDomainSecretInfoPtr encinfo;
qemuDomainSecretInfoPtr secinfo;
@@ -707,7 +704,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) {
@@ -715,7 +711,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
goto error;
}
- encinfo = diskPriv->encinfo;
+ encinfo = diskSrcPriv->encinfo;
if (encinfo && qemuBuildSecretInfoProps(encinfo, &encobjProps) < 0)
goto error;
--
2.13.6