On Sat, Jan 17, 2015 at 13:09:35 +0800, Luyao Huang wrote: > qemuMonitorAttachRNGDev and qemuMonitorDetachRNGDev functions > just do some basic check and then call qemuMonitorJSONAttachRNGDev > and qemuMonitorDelObject to help us. > > Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx> > --- > src/qemu/qemu_monitor.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > src/qemu/qemu_monitor.h | 7 +++++++ > src/qemu/qemu_monitor_json.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > src/qemu/qemu_monitor_json.h | 5 +++++ > 4 files changed, 98 insertions(+) ... > diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c > index da5c14d..33c3866 100644 > --- a/src/qemu/qemu_monitor_json.c > +++ b/src/qemu/qemu_monitor_json.c > @@ -6235,6 +6235,49 @@ qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon, > return ret; > } > > +int > +qemuMonitorJSONAttachRNGDev(qemuMonitorPtr mon, > + const char *chrID, > + const char *objID, > + virDomainRNGDefPtr rng) > +{ > + 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; > + > + case VIR_DOMAIN_RNG_BACKEND_LAST: > + /*shouldn't happen*/ > + goto cleanup; > + } > + > + return qemuMonitorJSONAddObject(mon, type, objID, props); > + > + cleanup: > + virJSONValueFree(props); > + return -1; > +} My recent series introduces a function that allows to unify the commandline and monitor object creation so that we don't have code duplication as would be introduced here. As my series is not pushed yet and was posted after your series I'll take over the series and refactor it to the new code to save you hassle of re-doing it again and also refactoring the existing code. Peter
Attachment:
signature.asc
Description: Digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list