[libvirt] [PATCH v2 4/6] qemu: Rework secinfo command line building

John Ferlan jferlan at redhat.com
Tue May 31 22:39:38 UTC 2016


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.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/qemu/qemu_command.c | 74 +++++++++++++------------------------------------
 1 file changed, 20 insertions(+), 54 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index da624d0..eac36ab 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -520,79 +520,44 @@ 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 (virQEMUBuildSecretObjectProps(secinfo->s.aes.ciphertext, false,
                                       "base64", keyid, secinfo->s.aes.iv,
-                                      propsret) < 0)
+                                      &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 = virQEMUBuildObjectCommandlineFromJSON(type,
-                                                      secinfo->s.aes.alias,
-                                                      props)))
+    if (!(commandStr =
+          virQEMUBuildObjectCommandlineFromJSON("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;
 }
@@ -602,7 +567,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.
@@ -615,7 +581,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




More information about the libvir-list mailing list