Introduce a new setup function for all the related configuration and
move the setup and attachment of the PR code.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_block.c | 8 ++++++++
src/qemu/qemu_block.h | 3 +++
src/qemu/qemu_command.c | 21 +++++++++++++++++++++
src/qemu/qemu_command.h | 3 +++
src/qemu/qemu_hotplug.c | 16 ++--------------
5 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 73aab9d73a..2bc8120f5f 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1485,6 +1485,7 @@
qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachDataPtr data)
virJSONValueFree(data->storageProps);
virJSONValueFree(data->formatProps);
+ virJSONValueFree(data->prmgrProps);
VIR_FREE(data->driveCmd);
VIR_FREE(data->driveAlias);
VIR_FREE(data);
@@ -1548,6 +1549,10 @@ qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
{
int rv;
+ if (data->prmgrProps &&
+ qemuMonitorAddObject(mon, &data->prmgrProps, &data->prmgrAlias)
< 0)
+ return -1;
+
if (data->storageProps) {
rv = qemuMonitorBlockdevAdd(mon, data->storageProps);
data->storageProps = NULL;
@@ -1609,6 +1614,9 @@ qemuBlockStorageSourceAttachRollback(qemuMonitorPtr mon,
"qemuMonitorAddDevice", data->driveAlias,
data->driveCmd);
}
+ if (data->prmgrAlias)
+ ignore_value(qemuMonitorDelObject(mon, data->prmgrAlias));
+
virErrorRestore(&orig_err);
}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 5c7791ee72..e5064574a9 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -71,6 +71,9 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src);
typedef struct qemuBlockStorageSourceAttachData qemuBlockStorageSourceAttachData;
typedef qemuBlockStorageSourceAttachData *qemuBlockStorageSourceAttachDataPtr;
struct qemuBlockStorageSourceAttachData {
+ virJSONValuePtr prmgrProps;
+ char *prmgrAlias;
+
virJSONValuePtr storageProps;
const char *storageNodeName;
bool storageAttached;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 84bb857507..af97069770 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -10463,3 +10463,24 @@ qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr
disk,
return data;
}
+
+
+/**
+ * qemuBuildStorageSourceAttachPrepareCommon:
+ * @src: storage source
+ * @data: already initialized data for disk source addition
+ *
+ * Prepare data for configuration associated with the disk source such as
+ * secrets/TLS/pr objects etc ...
+ */
+int
+qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src,
+ qemuBlockStorageSourceAttachDataPtr data)
+{
+ if (src->pr &&
+ !virStoragePRDefIsManaged(src->pr) &&
+ !(data->prmgrProps = qemuBuildPRManagerInfoProps(src)))
+ return -1;
+
+ return 0;
+}
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 04f6245bc7..711fce9648 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -106,6 +106,9 @@ char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk);
qemuBlockStorageSourceAttachDataPtr
qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk,
virQEMUCapsPtr qemuCaps);
+int
+qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src,
+ qemuBlockStorageSourceAttachDataPtr data);
/* Current, best practice */
char *qemuBuildDriveDevStr(const virDomainDef *def,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index ece9a82562..7ea5a531f3 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -394,14 +394,12 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
qemuBlockStorageSourceAttachDataPtr data = NULL;
virErrorPtr orig_err;
char *devstr = NULL;
- char *unmanagedPrmgrAlias = NULL;
char *managedPrmgrAlias = NULL;
char *encobjAlias = NULL;
char *secobjAlias = NULL;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virJSONValuePtr secobjProps = NULL;
virJSONValuePtr encobjProps = NULL;
- virJSONValuePtr unmanagedPrmgrProps = NULL;
virJSONValuePtr managedPrmgrProps = NULL;
qemuDomainStorageSourcePrivatePtr srcPriv;
qemuDomainSecretInfoPtr secinfo = NULL;
@@ -433,12 +431,10 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
if (qemuDomainDiskAttachManagedPR(vm, disk, &managedPrmgrProps) < 0)
goto error;
- if (disk->src->pr &&
- !virStoragePRDefIsManaged(disk->src->pr) &&
- !(unmanagedPrmgrProps = qemuBuildPRManagerInfoProps(disk->src)))
+ if (!(data = qemuBuildStorageSourceAttachPrepareDrive(disk, priv->qemuCaps)))
goto error;
- if (!(data = qemuBuildStorageSourceAttachPrepareDrive(disk, priv->qemuCaps)))
+ if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, data) < 0)
goto error;
if (disk->src->haveTLS == VIR_TRISTATE_BOOL_YES &&
@@ -465,10 +461,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
qemuMonitorAddObject(priv->mon, &managedPrmgrProps,
&managedPrmgrAlias) < 0)
goto exit_monitor;
- if (unmanagedPrmgrProps &&
- qemuMonitorAddObject(priv->mon, &unmanagedPrmgrProps,
&unmanagedPrmgrAlias) < 0)
- goto exit_monitor;
-
if (qemuBlockStorageSourceAttachApply(priv->mon, data) < 0)
goto exit_monitor;
@@ -488,12 +480,10 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
cleanup:
qemuBlockStorageSourceAttachDataFree(data);
virJSONValueFree(managedPrmgrProps);
- virJSONValueFree(unmanagedPrmgrProps);
virJSONValueFree(encobjProps);
virJSONValueFree(secobjProps);
qemuDomainSecretDiskDestroy(disk);
VIR_FREE(managedPrmgrAlias);
- VIR_FREE(unmanagedPrmgrAlias);
VIR_FREE(secobjAlias);
VIR_FREE(encobjAlias);
VIR_FREE(devstr);
@@ -508,8 +498,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
ignore_value(qemuMonitorDelObject(priv->mon, secobjAlias));
if (encobjAlias)
ignore_value(qemuMonitorDelObject(priv->mon, encobjAlias));
- if (unmanagedPrmgrAlias)
- ignore_value(qemuMonitorDelObject(priv->mon, unmanagedPrmgrAlias));
if (managedPrmgrAlias)
ignore_value(qemuMonitorDelObject(priv->mon, managedPrmgrAlias));
if (disk->src->tlsAlias)
--
2.16.2