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.c b/src/qemu/qemu_monitor.c index 6882a50..1e3f8ea 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4206,6 +4206,49 @@ int qemuMonitorDetachCharDev(qemuMonitorPtr mon, return qemuMonitorJSONDetachCharDev(mon, chrID); } +int qemuMonitorAttachRNGDev(qemuMonitorPtr mon, + const char *chrID, + const char *objID, + virDomainRNGDefPtr rng) +{ + VIR_DEBUG("mon=%p chrID=%s objID=%s rng=%p", mon, chrID, objID, rng); + + if (!mon) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("monitor must not be NULL")); + return -1; + } + + if (!mon->json) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("JSON monitor is required")); + return -1; + } + + return qemuMonitorJSONAttachRNGDev(mon, chrID, objID, rng); +} + +int qemuMonitorDetachRNGDev(qemuMonitorPtr mon, + const char *objID) +{ + VIR_DEBUG("mon=%p objID=%s", mon, objID); + + if (!mon) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("monitor must not be NULL")); + return -1; + } + + if (!mon->json) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("JSON monitor is required")); + return -1; + } + + return qemuMonitorDelObject(mon, objID); +} + + int qemuMonitorGetDeviceAliases(qemuMonitorPtr mon, char ***aliases) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 133d42d..a767e3e 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -869,6 +869,13 @@ int qemuMonitorAttachCharDev(qemuMonitorPtr mon, int qemuMonitorDetachCharDev(qemuMonitorPtr mon, const char *chrID); +int qemuMonitorAttachRNGDev(qemuMonitorPtr mon, + const char *chrID, + const char *objID, + virDomainRNGDefPtr rng); +int qemuMonitorDetachRNGDev(qemuMonitorPtr mon, + const char *objID); + int qemuMonitorGetDeviceAliases(qemuMonitorPtr mon, char ***aliases); 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; +} + int qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 1da1a00..04f7ca2 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -462,6 +462,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); -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list