[PATCH v2]Pre-assign memory modules slot number and assign alias.

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

 



Find the smallest missing slot number and
pre-assign slot numbers and assign aliases
of memory modules. This keeps the slot number
consistent with the alias.

Signed-off-by: Nitesh Konkar <nitkon12@xxxxxxxxxxxxxxxxxx>
---
 src/qemu/qemu_alias.c   | 54 +++++++++++++++++++++++++++++++++++++++----------
 src/qemu/qemu_command.c |  5 ++++-
 2 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index cc83fec..cdca69a 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -331,23 +331,49 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def,
     return 0;
 }
 
+static int
+qemuGetSmallestSlotIdx(virDomainDefPtr def)
+{
+    size_t i;
+    int idx = 0;
+    int minidx = 0;
+    bool check[100] = {false};
+
+    /* Find the missing slot */
+    for (i = 0; i < def->nmems; i++) {
+        idx = qemuDomainDeviceAliasIndex(&def->mems[i]->info, "dimm");
+        check[idx] = true;
+    }
+
+    for (i = 0; i < def->nmems; i++) {
+        if (!check[i]) {
+            minidx = i;
+            break;
+        }
+    }
+
+    if (i >= def->nmems)
+       minidx = i;
+
+    return minidx;
+}
 
 int
 qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
                             virDomainMemoryDefPtr mem)
 {
-    size_t i;
-    int maxidx = 0;
-    int idx;
+    int minidx;
 
-    for (i = 0; i < def->nmems; i++) {
-        if ((idx = qemuDomainDeviceAliasIndex(&def->mems[i]->info, "dimm")) >= maxidx)
-            maxidx = idx + 1;
-    }
+    if (mem->info.addr.dimm.base)
+        minidx = mem->info.addr.dimm.slot;
+    else
+        minidx = qemuGetSmallestSlotIdx(def);
 
-    if (virAsprintf(&mem->info.alias, "dimm%d", maxidx) < 0)
+    if (virAsprintf(&mem->info.alias, "dimm%d", minidx) < 0)
         return -1;
 
+    mem->info.addr.dimm.slot = minidx;
+
     return 0;
 }
 
@@ -381,7 +407,6 @@ qemuAssignDeviceShmemAlias(virDomainDefPtr def,
     return 0;
 }
 
-
 int
 qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
 {
@@ -475,8 +500,15 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
             return -1;
     }
     for (i = 0; i < def->nmems; i++) {
-        if (virAsprintf(&def->mems[i]->info.alias, "dimm%zu", i) < 0)
-            return -1;
+        def->mems[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM;
+        if (def->mems[i]->info.addr.dimm.base) {
+            if (virAsprintf(&def->mems[i]->info.alias, "dimm%d", def->mems[i]->info.addr.dimm.slot) < 0)
+                return -1;
+        } else {
+            def->mems[i]->info.addr.dimm.slot = i;
+            if (virAsprintf(&def->mems[i]->info.alias, "dimm%zu", i) < 0)
+                return -1;
+        }
     }
 
     return 0;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f24a98b..e236918 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3469,8 +3469,11 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem)
                           mem->info.alias, mem->info.alias);
 
         if (mem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM) {
+            if (mem->info.addr.dimm.base)
+                virBufferAsprintf(&buf, ",addr=%llu", mem->info.addr.dimm.base);
+
             virBufferAsprintf(&buf, ",slot=%d", mem->info.addr.dimm.slot);
-            virBufferAsprintf(&buf, ",addr=%llu", mem->info.addr.dimm.base);
+
         }
 
         break;
-- 
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]