提交 608dfc6a 编写于 作者: J John Ferlan

qemu: Split out the master key create and write

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: NJohn Ferlan <jferlan@redhat.com>
上级 70ae856e
......@@ -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;
}
......
......@@ -624,8 +624,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);
......
......@@ -5146,6 +5146,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;
......@@ -5271,8 +5275,8 @@ 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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册