[libvirt] [PATCH v2 07/12] qemu: add a functions for attach a rng object in json monitor
Zhu Guihua
zhugh.fnst at cn.fujitsu.com
Tue Jan 13 04:39:05 UTC 2015
On Tue, 2015-01-13 at 12:05 +0800, lhuang wrote:
> On 01/13/2015 10:35 AM, Zhu Guihua wrote:
> > Hi Luyao,
>
> Hi Guihua,
> > On Mon, 2015-01-12 at 09:38 +0800, lhuang wrote:
> >> On 01/10/2015 11:29 AM, Luyao Huang wrote:
> >>> We need a new function to build a RNG device object.
> >>>
> >>> Signed-off-by: Luyao Huang <lhuang at redhat.com>
> >>> ---
> >>> src/qemu/qemu_monitor_json.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
> >>> src/qemu/qemu_monitor_json.h | 5 +++++
> >>> 2 files changed, 51 insertions(+)
> >>>
> >>> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> >>> index e567aa7..598b15d 100644
> >>> --- a/src/qemu/qemu_monitor_json.c
> >>> +++ b/src/qemu/qemu_monitor_json.c
> >>> @@ -6166,6 +6166,52 @@ qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
> >>> return ret;
> >>> }
> >>>
> >>> +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 = 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;
> >>> + }
> >>> + /*chrID + 4 and objID + 3 pointing to the basic alias name of chrID.*/
> >>> + if (!objID || STRNEQ(chrID + 4, objID + 3)) {
> >>> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> >>> + _("chardev id '%s' basic alias name is different from '%s'",
> >>> + chrID, objID));
> >>> + goto cleanup;
> >>> + }
> >> I made a big mistake here, I found a better way :
> >>
> >> + case VIR_DOMAIN_RNG_BACKEND_EGD:
> >> + if (STRNEQ_NULLABLE(strstr(chrID, "rng"), strstr(objID, "rng"))) {
> >> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> >> + _("chardev id '%s' basic alias name is
> >> different from '%s'",
> >> + chrID, objID));
> >> + goto cleanup;
> >> + }
> >> + type = "rng-egd";
> >> + if (!(props = virJSONValueObjectCreate("s:chardev", chrID, NULL)))
> > Are you sure the above line could pass the compilation?
> > The first parameter of virJSONValueObjectCreate() should be
> > 'struct virJSONValue **'.
> >
> > Regards,
> > Zhu
>
> Oh, my god! thanks your pointing out :)
>
> Maybe this will work? I cannot test it now ,i will double check these
> code this night
>
yeah, it looks ok now.
And I think you'd better test the code in the latest version again.
Regards,
Zhu
> + const char *type = NULL;
> + virJSONValuePtr props;
> +
> + if (!(props = virJSONValueNewObject()))
> + goto cleanup;
> +
> + switch ((virDomainRNGBackend) rng->backend) {
> + case VIR_DOMAIN_RNG_BACKEND_RANDOM:
> + type = "rng-random";
> + if ((virJSONValueObjectCreate(&props, "s:filename",
> rng->source.file, NULL)) < 0)
> + goto cleanup;
> + break;
> +
> + case VIR_DOMAIN_RNG_BACKEND_EGD:
> + if (STRNEQ_NULLABLE(strstr(chrID, "rng"), strstr(objID, "rng"))) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("chardev id '%s' basic alias name is
> different from '%s'",
> + chrID, objID));
> + goto cleanup;
> + }
> + type = "rng-egd";
> + if ((virJSONValueObjectCreate(&props, "s:chardev", chrID,
> NULL)) < 0)
> + goto cleanup;
> + break;
>
> >> + goto cleanup;
> >> + break;
> >> +
> >>
> >> i remove the check of chrID, because this should be done in the function
> >> which call qemuMonitorJSONAttachRNGDev.
> >>> + type = "rng-egd";
> >>> + if (!(props = virJSONValueObjectCreate("s:chardev", chrID, NULL)))
> >>> + 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
> >>> qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon,
> >>> diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
> >>> index 222f11e..66c519d 100644
> >>> --- a/src/qemu/qemu_monitor_json.h
> >>> +++ b/src/qemu/qemu_monitor_json.h
> >>> @@ -459,6 +459,11 @@ int qemuMonitorJSONAttachCharDev(qemuMonitorPtr mon,
> >>> virDomainChrSourceDefPtr chr);
> >>> int qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
> >>> const char *chrID);
> >>> +int qemuMonitorJSONAttachRNGDev(qemuMonitorPtr mon,
> >>> + const char *chrID,
> >>> + const char *objID,
> >>> + virDomainRNGDefPtr rng);
> >>> +
> >>>
> >>> int qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon,
> >>> char ***aliases);
> >> Luyao
> >>
> >> --
> >> libvir-list mailing list
> >> libvir-list at redhat.com
> >> https://www.redhat.com/mailman/listinfo/libvir-list
>
> Thanks,
> Luyao
> >
>
More information about the libvir-list
mailing list