[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/4] qemu: Move and rename qemuBuildSecretObjectProps



Move the function to secret_util.c and rename to virSecretBuildObjectProps.
This then can be shared with impending storage backend changes that will
need to build up a secret object to pass to qemu-img.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_command.c  | 63 +++---------------------------------------------
 src/secret/secret_util.c | 59 +++++++++++++++++++++++++++++++++++++++++++++
 src/secret/secret_util.h | 10 ++++++++
 4 files changed, 73 insertions(+), 60 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e4bddd3..0cd7a9c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1074,6 +1074,7 @@ nodeSetMemoryParameters;
 
 
 # secret/secret_util.h
+virSecretBuildObjectProps;
 virSecretGetSecretString;
 
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 06d135b..47688e4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -48,6 +48,7 @@
 #include "snapshot_conf.h"
 #include "storage_conf.h"
 #include "secret_conf.h"
+#include "secret_util.h"
 #include "network/bridge_driver.h"
 #include "virnetdevtap.h"
 #include "device_conf.h"
@@ -508,64 +509,6 @@ qemuNetworkDriveGetPort(int protocol,
 
 
 /**
- * qemuBuildSecretObjectProps
- * @data: Pointer to data string
- * @isfile: Boolean to indicate whether data is raw data or a filepath string
- * @fmt: Format for the data/file (may be NULL)
- * @keyid: Master key alias id (may be NULL)
- * @iv: Initialization vector (may be NULL)
- * @propsret: location to store the created/built property object
- *
- * There's many ways to build a secret object for qemu depending on need,
- *
- *    -object secret,id=$alias,data=$data
- *    -object secret,id=$alias,data=$data[,format=base64]
- *    -object secret,id=$alias,file=$file
- *    -object secret,id=$alias,file=$file[,format=base64]
- *    -object secret,id=$alias,data=$data,keyid=$keyid,[iv=$iv],format=base64
- *
- * When a keyid and/or iv are provided, they are assumed to be base64 encoded
- *
- * Build the JSON object property thusly and return
- *
- * Returns 0 on success, -1 on failure w/ error set
- */
-static int
-qemuBuildSecretObjectProps(const char *data,
-                           bool isfile,
-                           const char *fmt,
-                           const char *keyid,
-                           const char *iv,
-                           virJSONValuePtr *propsret)
-{
-    if (!(*propsret = virJSONValueNewObject()))
-        return -1;
-
-    if (isfile && virJSONValueObjectAdd(*propsret, "s:file", data, NULL) < 0)
-        goto error;
-    else if (virJSONValueObjectAdd(*propsret, "s:data", data, NULL) < 0)
-        goto error;
-
-    if (keyid && virJSONValueObjectAdd(*propsret, "s:keyid", keyid, NULL) < 0)
-        goto error;
-
-    if (iv && virJSONValueObjectAdd(*propsret, "s:iv", iv, NULL) < 0)
-        goto error;
-
-    /* NB: QEMU will assume "raw" when fmt not provided! */
-    if (fmt && virJSONValueObjectAdd(*propsret, "s:format", fmt, NULL) < 0)
-        goto error;
-
-    return 0;
-
- error:
-    virJSONValueFree(*propsret);
-
-    return -1;
-}
-
-
-/**
  * qemuBuildSecretInfoProps:
  * @secinfo: pointer to the secret info object
  * @type: returns a pointer to a character string for object name
@@ -589,8 +532,8 @@ qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo,
     if (!(keyid = qemuDomainGetMasterKeyAlias()))
         return -1;
 
-    if (qemuBuildSecretObjectProps(secinfo->s.aes.ciphertext, false, "base64",
-                                   keyid, secinfo->s.aes.iv, propsret) < 0)
+    if (virSecretBuildObjectProps(secinfo->s.aes.ciphertext, false, "base64",
+                                  keyid, secinfo->s.aes.iv, propsret) < 0)
         goto cleanup;
 
     ret = 0;
diff --git a/src/secret/secret_util.c b/src/secret/secret_util.c
index 5602401..cda8ae6 100644
--- a/src/secret/secret_util.c
+++ b/src/secret/secret_util.c
@@ -24,6 +24,7 @@
 #include "secret_util.h"
 #include "viralloc.h"
 #include "virerror.h"
+#include "virjson.h"
 #include "virlog.h"
 #include "virobject.h"
 #include "viruuid.h"
@@ -83,3 +84,61 @@ virSecretGetSecretString(virConnectPtr conn,
     virObjectUnref(sec);
     return ret;
 }
+
+
+/**
+ * virSecretBuildObjectProps
+ * @data: Pointer to data string
+ * @isfile: Boolean to indicate whether data is raw data or a filepath string
+ * @fmt: Format for the data/file (may be NULL)
+ * @keyid: Master key alias id (may be NULL)
+ * @iv: Initialization vector (may be NULL)
+ * @propsret: location to store the created/built property object
+ *
+ * There's many ways to build a secret object for qemu depending on need,
+ *
+ *    -object secret,id=$alias,data=$data
+ *    -object secret,id=$alias,data=$data[,format=base64]
+ *    -object secret,id=$alias,file=$file
+ *    -object secret,id=$alias,file=$file[,format=base64]
+ *    -object secret,id=$alias,data=$data,keyid=$keyid,[iv=$iv],format=base64
+ *
+ * When a keyid and/or iv are provided, they are assumed to be base64 encoded
+ *
+ * Build the JSON object property thusly and return
+ *
+ * Returns 0 on success, -1 on failure w/ error set
+ */
+int
+virSecretBuildObjectProps(const char *data,
+                          bool isfile,
+                          const char *fmt,
+                          const char *keyid,
+                          const char *iv,
+                          virJSONValuePtr *propsret)
+{
+    if (!(*propsret = virJSONValueNewObject()))
+        return -1;
+
+    if (isfile && virJSONValueObjectAdd(*propsret, "s:file", data, NULL) < 0)
+        goto error;
+    else if (virJSONValueObjectAdd(*propsret, "s:data", data, NULL) < 0)
+        goto error;
+
+    if (keyid && virJSONValueObjectAdd(*propsret, "s:keyid", keyid, NULL) < 0)
+        goto error;
+
+    if (iv && virJSONValueObjectAdd(*propsret, "s:iv", iv, NULL) < 0)
+        goto error;
+
+    /* NB: QEMU will assume "raw" when fmt not provided! */
+    if (fmt && virJSONValueObjectAdd(*propsret, "s:format", fmt, NULL) < 0)
+        goto error;
+
+    return 0;
+
+ error:
+    virJSONValueFree(*propsret);
+
+    return -1;
+}
diff --git a/src/secret/secret_util.h b/src/secret/secret_util.h
index a039662..88ccbff 100644
--- a/src/secret/secret_util.h
+++ b/src/secret/secret_util.h
@@ -23,6 +23,7 @@
 # define __VIR_SECRET_H__
 
 # include "internal.h"
+# include "virjson.h"
 # include "virstoragefile.h"
 
 int virSecretGetSecretString(virConnectPtr conn,
@@ -32,4 +33,13 @@ int virSecretGetSecretString(virConnectPtr conn,
                              size_t *ret_secret_size)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4)
     ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK;
+
+int virSecretBuildObjectProps(const char *data,
+                              bool isfile,
+                              const char *fmt,
+                              const char *keyid,
+                              const char *iv,
+                              virJSONValuePtr *propsret)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+
 #endif /* __VIR_SECRET_H__ */
-- 
2.5.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]