util: qemu: Introduce helper for formatting command line from new object props

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2018-05-18 14:04:21 +02:00
parent f0a23c0c35
commit efd32528d0
3 changed files with 40 additions and 4 deletions

View File

@ -2601,6 +2601,7 @@ virQEMUBuildCommandLineJSON;
virQEMUBuildCommandLineJSONArrayBitmap;
virQEMUBuildCommandLineJSONArrayNumbered;
virQEMUBuildDriveCommandlineFromJSON;
virQEMUBuildObjectCommandlineFromJSON;
virQEMUBuildObjectCommandlineFromJSONType;
virQEMUBuildQemuImgKeySecretOpts;

View File

@ -241,6 +241,29 @@ virQEMUBuildCommandLineJSON(virJSONValuePtr value,
}
static int
virQEMUBuildObjectCommandlineFromJSONInternal(virBufferPtr buf,
const char *type,
const char *alias,
virJSONValuePtr props)
{
if (!type || !alias) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing 'type' or 'alias' field of QOM 'object'"));
return -1;
}
virBufferAsprintf(buf, "%s,id=%s,", type, alias);
if (props &&
virQEMUBuildCommandLineJSON(props, buf,
virQEMUBuildCommandLineJSONArrayBitmap) < 0)
return -1;
return 0;
}
char *
virQEMUBuildObjectCommandlineFromJSONType(const char *type,
const char *alias,
@ -249,10 +272,7 @@ virQEMUBuildObjectCommandlineFromJSONType(const char *type,
virBuffer buf = VIR_BUFFER_INITIALIZER;
char *ret = NULL;
virBufferAsprintf(&buf, "%s,id=%s,", type, alias);
if (virQEMUBuildCommandLineJSON(props, &buf,
virQEMUBuildCommandLineJSONArrayBitmap) < 0)
if (virQEMUBuildObjectCommandlineFromJSONInternal(&buf, type, alias, props) < 0)
goto cleanup;
if (virBufferCheckError(&buf) < 0)
@ -266,6 +286,18 @@ virQEMUBuildObjectCommandlineFromJSONType(const char *type,
}
int
virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
virJSONValuePtr objprops)
{
const char *type = virJSONValueObjectGetString(objprops, "qom-type");
const char *alias = virJSONValueObjectGetString(objprops, "id");
virJSONValuePtr props = virJSONValueObjectGetObject(objprops, "props");
return virQEMUBuildObjectCommandlineFromJSONInternal(buf, type, alias, props);
}
char *
virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
{

View File

@ -47,6 +47,9 @@ char *virQEMUBuildObjectCommandlineFromJSONType(const char *type,
const char *alias,
virJSONValuePtr props);
int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
virJSONValuePtr objprops);
char *virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr src);
void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str);