[RFC PATCH 01/11] domain_conf: support slots and maxmem properties in memory xml

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

 



Add properties slots and maxmem, so as to support memory hotplug.

Signed-off-by: Zhu Guihua <zhugh.fnst@xxxxxxxxxxxxxx>
---
 src/conf/domain_conf.c  | 22 ++++++++++++++++++++++
 src/conf/domain_conf.h  |  4 ++++
 src/qemu/qemu_command.c | 28 ++++++++++++++++++++++++++--
 3 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8792f5e..526f2da 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12594,6 +12594,7 @@ virDomainDefParseXML(xmlDocPtr xml,
     long id = -1;
     virDomainDefPtr def;
     unsigned long count;
+    unsigned int slots;
     bool uuid_generated = false;
     virHashTablePtr bootHash = NULL;
     bool usb_none = false;
@@ -12723,6 +12724,21 @@ virDomainDefParseXML(xmlDocPtr xml,
                              &def->mem.cur_balloon, false, true) < 0)
         goto error;
 
+    n = virXPathUInt("string(./memory[1]/@slots)", ctxt, &slots);
+    if (n == -2) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("maximum slots for memory devices "
+                         "must be an integer"));
+        goto error;
+    } else if (n == -1) {
+        def->mem.slots = -1;
+    } else {
+        def->mem.slots = slots;
+        if (virDomainParseMemory("./maxMemory[1]", NULL, ctxt,
+                                 &def->mem.maxmem, true, true) < 0)
+            goto error;
+    }
+
     /* and info about it */
     if ((tmp = virXPathString("string(./memory[1]/@dumpCore)", ctxt)) &&
         (def->mem.dump_core = virTristateSwitchTypeFromString(tmp)) <= 0) {
@@ -19319,12 +19335,18 @@ virDomainDefFormatInternal(virDomainDefPtr def,
     if (def->mem.dump_core)
         virBufferAsprintf(buf, " dumpCore='%s'",
                           virTristateSwitchTypeToString(def->mem.dump_core));
+    if (def->mem.slots && def->mem.maxmem)
+        virBufferAsprintf(buf, " slot='%u'",
+                          def->mem.slots);
     virBufferAsprintf(buf, " unit='KiB'>%llu</memory>\n",
                       def->mem.max_balloon);
 
     virBufferAsprintf(buf, "<currentMemory unit='KiB'>%llu</currentMemory>\n",
                       def->mem.cur_balloon);
 
+    if (def->mem.slots && def->mem.maxmem)
+        virBufferAsprintf(buf, "<maxMemory unit='KiB'>%llu</maxMemory>\n",
+                          def->mem.maxmem);
     /* add blkiotune only if there are any */
     if (def->blkio.weight) {
         blkio = true;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 09ab194..731d14f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2018,6 +2018,10 @@ struct _virDomainMemtune {
     unsigned long long cur_balloon; /* in kibibytes, capped at ulong thanks
                                        to virDomainGetInfo */
 
+    unsigned int slots; /* the maximum slots for memory devices  */
+    unsigned long long maxmem; /* in kibibytes, the maximum memory
+                                  for the guest */
+
     virDomainHugePagePtr hugepages;
     size_t nhugepages;
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c041ee7..536abc3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6598,6 +6598,26 @@ qemuBuildMachineArgStr(virCommandPtr cmd,
 }
 
 static char *
+qemuBuildMemArgStr(virDomainDefPtr def)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    def->mem.max_balloon = VIR_DIV_UP(def->mem.max_balloon, 1024) * 1024;
+
+    virBufferAsprintf(&buf, "%lluM", def->mem.max_balloon / 1024);
+    if (def->mem.slots != -1) {
+        def->mem.maxmem = VIR_DIV_UP(def->mem.maxmem, 1024) * 1024;
+        virBufferAsprintf(&buf, ",slots=%u", def->mem.slots);
+        virBufferAsprintf(&buf, ",maxmem=%lluM", def->mem.maxmem / 1024);
+    }
+
+    if (virBufferCheckError(&buf) < 0)
+        return NULL;
+
+    return virBufferContentAndReset(&buf);
+}
+
+static char *
 qemuBuildSmpArgStr(const virDomainDef *def,
                    virQEMUCapsPtr qemuCaps)
 {
@@ -7796,6 +7816,7 @@ qemuBuildCommandLine(virConnectPtr conn,
     char uuid[VIR_UUID_STRING_BUFLEN];
     char *cpu;
     char *smp;
+    char *mem;
     int last_good_net = -1;
     bool hasHwVirt = false;
     virCommandPtr cmd = NULL;
@@ -7929,8 +7950,11 @@ qemuBuildCommandLine(virConnectPtr conn,
      * XML to reflect our rounding.
      */
     virCommandAddArg(cmd, "-m");
-    def->mem.max_balloon = VIR_DIV_UP(def->mem.max_balloon, 1024) * 1024;
-    virCommandAddArgFormat(cmd, "%llu", def->mem.max_balloon / 1024);
+    if (!(mem = qemuBuildMemArgStr(def)))
+        goto error;
+    virCommandAddArg(cmd, mem);
+    VIR_FREE(mem);
+
     if (def->mem.nhugepages && (!def->cpu || !def->cpu->ncells)) {
         const long system_page_size = sysconf(_SC_PAGESIZE) / 1024;
         char *mem_path = NULL;
-- 
1.9.3

--
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]