The function being introduced is responsible for excuting
'object_add' command to hot add memory backend.
Signed-off-by: Zhu Guihua <zhugh.fnst(a)cn.fujitsu.com>
---
src/qemu/qemu_monitor.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor.h | 4 ++++
2 files changed, 58 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 6882a50..1db8ad0 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4165,6 +4165,60 @@ int qemuMonitorGetTPMTypes(qemuMonitorPtr mon,
return qemuMonitorJSONGetTPMTypes(mon, tpmtypes);
}
+int qemuMonitorAddMemoryBackend(qemuMonitorPtr mon,
+ const char *objID,
+ virDomainDimmDefPtr dimm)
+{
+ VIR_DEBUG("mon=%p objID=%s dimm=%p",
+ mon, objID, dimm);
+
+ virJSONValuePtr props = NULL;
+ const char *type = NULL;
+
+ if (!mon) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("monitor must not be NULL"));
+ goto cleanup;
+ }
+
+ if (!mon->json) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("JSON monitor is required"));
+ goto cleanup;
+ }
+
+ if (!(props = virJSONValueNewObject()))
+ goto cleanup;
+
+ switch (dimm->backend.type) {
+ case VIR_DOMAIN_MEMORY_BACKEND_RAM:
+ type = "memory-backend-ram";
+ if ( virJSONValueObjectAppendNumberUlong(props,
+ "size", dimm->backend.size * 1024)
< 0)
+ goto cleanup;
+ break;
+
+ case VIR_DOMAIN_MEMORY_BACKEND_FILE:
+ type = "memory-backend-file";
+ if (virJSONValueObjectAppendNumberUlong(props, "size",
+ dimm->backend.size * 1024) < 0)
+ goto cleanup;
+ if (virJSONValueObjectAppendString(props, "mem-path",
+ dimm->backend.mem_path) < 0)
+ goto cleanup;
+ break;
+
+ default:
+ break;
+ }
+
+ return qemuMonitorAddObject(mon, type, objID, props);
+
+ cleanup:
+ virJSONValueFree(props);
+ return -1;
+}
+
int qemuMonitorAttachCharDev(qemuMonitorPtr mon,
const char *chrID,
virDomainChrSourceDefPtr chr)
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 133d42d..9a69611 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -863,6 +863,10 @@ int qemuMonitorGetTPMModels(qemuMonitorPtr mon,
int qemuMonitorGetTPMTypes(qemuMonitorPtr mon,
char ***tpmtypes);
+int qemuMonitorAddMemoryBackend(qemuMonitorPtr mon,
+ const char *objID,
+ virDomainDimmDefPtr dimm);
+
int qemuMonitorAttachCharDev(qemuMonitorPtr mon,
const char *chrID,
virDomainChrSourceDefPtr chr);
--
1.9.3