A recent review of related changes noted that we should split the creation
(or generation) of the master key into the qemuProcessPrepareDomain and leave
the writing of the master key for qemuProcessPrepareHost.

Made the adjustment and modified some comments to functions that have
changed calling parameters, but didn't change the intro doc.

Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/qemu/qemu_domain.c  | 23 ++++++++++-------------
 src/qemu/qemu_domain.h  |  6 ++++--
 src/qemu/qemu_process.c | 10 ++++++++--
 3 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 383c735..2cc08b8 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -498,13 +498,14 @@ qemuDomainGetMasterKeyFilePath(const char *libDir)
 
 
 /* qemuDomainWriteMasterKeyFile:
- * @priv: pointer to domain private object
+ * @driver: qemu driver data
+ * @vm: Pointer to the vm object
  *
  * Get the desired path to the masterKey file and store it in the path.
  *
  * Returns 0 on success, -1 on failure with error message indicating failure
  */
-static int
+int
 qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
                              virDomainObjPtr vm)
 {
@@ -513,6 +514,10 @@ qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
     int ret = -1;
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
+    /* Only gets filled in if we have the capability */
+    if (!priv->masterKey)
+        return 0;
+
     if (!(path = qemuDomainGetMasterKeyFilePath(priv->libDir)))
         return -1;
 
@@ -695,7 +700,7 @@ qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv)
 
 
 /* qemuDomainMasterKeyCreate:
- * @priv: Pointer to the domain private object
+ * @vm: Pointer to the domain object
  *
  * As long as the underlying qemu has the secret capability,
  * generate and store 'raw' in a file a random 32-byte key to
@@ -704,8 +709,7 @@ qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv)
  * Returns: 0 on success, -1 w/ error message on failure
  */
 int
-qemuDomainMasterKeyCreate(virQEMUDriverPtr driver,
-                          virDomainObjPtr vm)
+qemuDomainMasterKeyCreate(virDomainObjPtr vm)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
@@ -715,18 +719,11 @@ qemuDomainMasterKeyCreate(virQEMUDriverPtr driver,
 
     if (!(priv->masterKey =
           qemuDomainGenerateRandomKey(QEMU_DOMAIN_MASTER_KEY_LEN)))
-        goto error;
+        return -1;
 
     priv->masterKeyLen = QEMU_DOMAIN_MASTER_KEY_LEN;
 
-    if (qemuDomainWriteMasterKeyFile(driver, vm) < 0)
-        goto error;
-
     return 0;
-
- error:
-    qemuDomainMasterKeyRemove(priv);
-    return -1;
 }
 
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index c81921e..205c47d 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -623,8 +623,10 @@ char *qemuDomainGetMasterKeyFilePath(const char *libDir);
 
 int qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv);
 
-int qemuDomainMasterKeyCreate(virQEMUDriverPtr driver,
-                              virDomainObjPtr vm);
+int qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
+                                 virDomainObjPtr vm);
+
+int qemuDomainMasterKeyCreate(virDomainObjPtr vm);
 
 void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 527300a..2a0362c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5107,6 +5107,10 @@ qemuProcessPrepareDomain(virConnectPtr conn,
             goto cleanup;
     }
 
+    VIR_DEBUG("Create domain masterKey");
+    if (qemuDomainMasterKeyCreate(vm) < 0)
+        goto cleanup;
+
     if (VIR_ALLOC(priv->monConfig) < 0)
         goto cleanup;
 
@@ -5121,6 +5125,7 @@ qemuProcessPrepareDomain(virConnectPtr conn,
 
     ret = 0;
  cleanup:
+    qemuDomainMasterKeyRemove(priv);
     VIR_FREE(nodeset);
     virObjectUnref(caps);
     return ret;
@@ -5232,12 +5237,13 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
         qemuProcessMakeDir(driver, vm, priv->channelTargetDir) < 0)
         goto cleanup;
 
-    VIR_DEBUG("Create domain masterKey");
-    if (qemuDomainMasterKeyCreate(driver, vm) < 0)
+    VIR_DEBUG("Write domain masterKey");
+    if (qemuDomainWriteMasterKeyFile(driver, vm) < 0)
         goto cleanup;
 
     ret = 0;
  cleanup:
+    qemuDomainMasterKeyRemove(priv);
     virObjectUnref(cfg);
     return ret;
 }
-- 
2.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to