Re: [PATCH 08/12] qemu: introduce 2 functions for attach a rng object in json monitor

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

 



On 01/03/15 06:06, Luyao Huang wrote:
> We need a new function to build a RNG device object, and need a
> function to build a props which will be used in qemuMonitorJSONAddObject.
> 
> Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx>
> ---
>  src/qemu/qemu_monitor_json.c | 58 ++++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_monitor_json.h |  5 ++++
>  2 files changed, 63 insertions(+)
> 
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index e567aa7..4430819 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -6166,6 +6166,64 @@ qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
>      return ret;
>  }
>  
> +static virJSONValuePtr
> +qemuMonitorJSONRNGPropsCommand(const char *name,
> +                               const char *data)
> +{
> +    virJSONValuePtr ret;
> +
> +    if (!(ret = virJSONValueNewObject()))
> +        goto error;
> +
> +    if (virJSONValueObjectAppendString(ret, name, data) < 0)
> +        goto error;
> +
> +    return ret;
> +
> + error:
> +    virJSONValueFree(ret);
> +    return NULL;
> +}

To allow adding generic properties to objects I've added the
virJSONValueObjectCreate function that allows to create generic json
value objects. Please use that func instead of the above.


> +
> +int
> +qemuMonitorJSONAttachRNGDev(qemuMonitorPtr mon,
> +                            const char *chrID,
> +                            const char *objID,
> +                            virDomainRNGDefPtr rng)
> +{
> +    const char *type = NULL;
> +    virJSONValuePtr props = NULL;
> +
> +    switch ((virDomainRNGBackend) rng->backend) {
> +    case VIR_DOMAIN_RNG_BACKEND_RANDOM:
> +        type = "rng-random";
> +        if (!(props = qemuMonitorJSONRNGPropsCommand("filename", rng->source.file)))

With usage of virJSONValueObjectCreate the code will look like:

if (!(props = virJSONValueObjectCreate("s:filename", rng->source.file,
NULL)))


> +            goto cleanup;
> +        break;
> +
> +    case VIR_DOMAIN_RNG_BACKEND_EGD:
> +        if (!chrID) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR,"%s",
> +                           _("miss chardev id"));
> +            goto cleanup;
> +        }

The chardev and backend object ID can (and should) be inferred from the
rng device ID as they should be the same (except for the "char"/"obj"
prefix).

> +        type = "rng-egd";
> +        if (!(props = qemuMonitorJSONRNGPropsCommand("chardev", chrID)))
> +            goto cleanup;
> +        break;
> +
> +    case VIR_DOMAIN_RNG_BACKEND_LAST:
> +        /*shouldn't happen*/
> +        goto cleanup;
> +    }
> +
> +    return qemuMonitorJSONAddObject(mon, type, objID, props);
> +
> + cleanup:
> +    virJSONValueFree(props);
> +    return -1;
> +}
> +
>  
>  int

Peter


Attachment: signature.asc
Description: OpenPGP digital signature

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

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]