Rework the logic to remove the various levels of indirection between
qemuBuildSecretInfoProps and qemuBuildObjectSecretCommandLine. Merge
them into qemuBuildObjectSecinfoCommandLine which will do all the
work of building the secinfo secret object command line. This will
be the model for building the secretdef secret object command line.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_command.c | 73 ++++++++++++++-----------------------------------
1 file changed, 20 insertions(+), 53 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 47688e4..e49327d 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -508,77 +508,43 @@ qemuNetworkDriveGetPort(int protocol,
}
-/**
- * qemuBuildSecretInfoProps:
- * @secinfo: pointer to the secret info object
- * @type: returns a pointer to a character string for object name
- * @props: json properties to return
+/* qemuBuildSecinfoCommandLine:
+ * @cmd: Pointer to the command string
+ * @secinfo: Pointer to a possible secinfo
*
- * Build the JSON properties for the secret info type.
+ * Build the command line string using the secinfo structure and
+ * common json object building principles.
*
- * Returns 0 on success with the filled in JSON property; otherwise,
- * returns -1 on failure error message set.
+ * Returns 0 on success, -1 on failure w/ error message set
*/
static int
-qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo,
- const char **type,
- virJSONValuePtr *propsret)
+qemuBuildObjectSecinfoCommandLine(virCommandPtr cmd,
+ qemuDomainSecretInfoPtr secinfo)
{
int ret = -1;
+ virJSONValuePtr props = NULL;
char *keyid = NULL;
-
- *type = "secret";
+ char *commandStr = NULL;
if (!(keyid = qemuDomainGetMasterKeyAlias()))
return -1;
if (virSecretBuildObjectProps(secinfo->s.aes.ciphertext, false,
"base64",
- keyid, secinfo->s.aes.iv, propsret) < 0)
+ keyid, secinfo->s.aes.iv, &props) < 0)
goto cleanup;
- ret = 0;
-
- cleanup:
- VIR_FREE(keyid);
-
- return ret;
-}
-
-
-/**
- * qemuBuildObjectSecretCommandLine:
- * @cmd: the command to modify
- * @secinfo: pointer to the secret info object
- *
- * If the secinfo is available and associated with an AES secret,
- * then format the command line for the secret object. This object
- * will be referenced by the device that needs/uses it, so it needs
- * to be in place first.
- *
- * Returns 0 on success, -1 w/ error message on failure
- */
-static int
-qemuBuildObjectSecretCommandLine(virCommandPtr cmd,
- qemuDomainSecretInfoPtr secinfo)
-{
- int ret = -1;
- virJSONValuePtr props = NULL;
- const char *type;
- char *tmp = NULL;
-
- if (qemuBuildSecretInfoProps(secinfo, &type, &props) < 0)
- return -1;
-
- if (!(tmp = virJSONBuildObjectCommandline(type, secinfo->s.aes.alias,
- props)))
+ if (!(commandStr = virJSONBuildObjectCommandline("secret",
+ secinfo->s.aes.alias,
+ props)))
goto cleanup;
- virCommandAddArgList(cmd, "-object", tmp, NULL);
+ virCommandAddArgList(cmd, "-object", commandStr, NULL);
ret = 0;
cleanup:
+ VIR_FREE(keyid);
virJSONValueFree(props);
- VIR_FREE(tmp);
+ VIR_FREE(commandStr);
return ret;
}
@@ -588,7 +554,8 @@ qemuBuildObjectSecretCommandLine(virCommandPtr cmd,
* @cmd: Pointer to the command string
* @secinfo: Pointer to a possible secinfo
*
- * Add the secret object for the disks that will be using it to perform
+ * If the secinfo is available and associated with an AES secret, then
+ * add the secret object for the disks that will be using it to perform
* their authentication.
*
* Returns 0 on success, -1 w/ error on some sort of failure.
@@ -601,7 +568,7 @@ qemuBuildDiskSecinfoCommandLine(virCommandPtr cmd,
if (!secinfo || secinfo->type != VIR_DOMAIN_SECRET_INFO_TYPE_AES)
return 0;
- return qemuBuildObjectSecretCommandLine(cmd, secinfo);
+ return qemuBuildObjectSecinfoCommandLine(cmd, secinfo);
}
--
2.5.5