In qemuBuildMasterKeyCommandLine, rather than inline code build the command use virQEMUBuildSecretObjectProps to generate the JSON secret object and then virQEMUBuildObjectCommandlineFromJSON to build the object. This is just like qemuBuildSecretInfoProps which will now also use the common function. Adjust the tests to remove the "format=raw,", since it's really not necessary as qemu will assume "raw" unless "format=base64" is provided. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/qemu/qemu_command.c | 27 +++++++++++++++------- ...muxml2argv-disk-drive-network-rbd-auth-AES.args | 3 +-- .../qemuxml2argvdata/qemuxml2argv-master-key.args | 3 +-- .../qemuxml2argvdata/qemuxml2argv-name-escape.args | 3 +-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1455c0d..da624d0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -198,6 +198,9 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd, char *alias = NULL; char *path = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; + const char *type = "secret"; + virJSONValuePtr props = NULL; + char *tmp = NULL; /* If the -object secret does not exist, then just return. This just * means the domain won't be able to use a secret master key and is @@ -219,10 +222,19 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd, if (!(path = qemuDomainGetMasterKeyFilePath(domainLibDir))) goto cleanup; - virCommandAddArg(cmd, "-object"); - virBufferAsprintf(&buf, "secret,id=%s,format=raw,file=", alias); qemuBufferEscapeComma(&buf, path); - virCommandAddArgBuffer(cmd, &buf); + if (virBufferCheckError(&buf) < 0) + goto cleanup; + VIR_FREE(path); + path = virBufferContentAndReset(&buf); + + if (virQEMUBuildSecretObjectProps(path, true, NULL, NULL, NULL, &props) < 0) + goto cleanup; + + if (!(tmp = virQEMUBuildObjectCommandlineFromJSON(type, alias, props))) + goto cleanup; + + virCommandAddArgList(cmd, "-object", tmp, NULL); ret = 0; @@ -230,6 +242,7 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd, virBufferFreeAndReset(&buf); VIR_FREE(alias); VIR_FREE(path); + VIR_FREE(tmp); return ret; } @@ -531,11 +544,9 @@ qemuBuildSecretInfoProps(qemuDomainSecretInfoPtr secinfo, if (!(keyid = qemuDomainGetMasterKeyAlias())) return -1; - if (virJSONValueObjectCreate(propsret, - "s:data", secinfo->s.aes.ciphertext, - "s:keyid", keyid, - "s:iv", secinfo->s.aes.iv, - "s:format", "base64", NULL) < 0) + if (virQEMUBuildSecretObjectProps(secinfo->s.aes.ciphertext, false, + "base64", keyid, secinfo->s.aes.iv, + propsret) < 0) goto cleanup; ret = 0; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd-auth-AES.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd-auth-AES.args index 7100d2d..77801bd 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd-auth-AES.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-network-rbd-auth-AES.args @@ -7,8 +7,7 @@ QEMU_AUDIO_DRV=none \ /usr/bin/qemu \ -name QEMUGuest1 \ -S \ --object secret,id=masterKey0,format=raw,\ -file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-object secret,id=masterKey0,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ -M pc \ -m 214 \ -smp 1 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-master-key.args b/tests/qemuxml2argvdata/qemuxml2argv-master-key.args index de030eb..3b1b672 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-master-key.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-master-key.args @@ -7,8 +7,7 @@ QEMU_AUDIO_DRV=none \ /usr/bin/qemu \ -name QEMUGuest1 \ -S \ --object secret,id=masterKey0,format=raw,\ -file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-object secret,id=masterKey0,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ -M pc \ -m 214 \ -smp 2 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-name-escape.args b/tests/qemuxml2argvdata/qemuxml2argv-name-escape.args index b59706c..659379a 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-name-escape.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-name-escape.args @@ -7,8 +7,7 @@ QEMU_AUDIO_DRV=none \ /usr/bin/qemu \ -name guest=foo=1,,bar=2,debug-threads=on \ -S \ --object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-foo=1,,\ -bar=2/master-key.aes \ +-object secret,id=masterKey0,file=/tmp/lib/domain--1-foo=1,,bar=2/master-key.aes \ -M pc \ -m 214 \ -smp 1 \ -- 2.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list