[PATCH 1/2] qemu_alias:Set dimm alias name to dimmX where X=slot number.

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

 



When we hotplug a memory module, qemu will assign
the smallest slot available. At the time of setting
the alias we find the smallest available slot and
assign alias name as dimmX where X=slot number.

Signed-off-by: Nitesh Konkar <nitkon12@xxxxxxxxxxxxxxxxxx>
---
 src/qemu/qemu_alias.c | 51 +++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 41 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 0102c96..23ffdfd 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -28,6 +28,7 @@
 #include "virlog.h"
 #include "virstring.h"
 #include "network/bridge_driver.h"
+#include "qemu_process.h"
 
 #define QEMU_DRIVE_HOST_PREFIX "drive-"
 
@@ -331,21 +332,47 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def,
     return 0;
 }
 
+/* Find the smallest available slot. */
+static int
+qemuGetSmallestSlotIdx(virDomainDefPtr def)
+{
+    size_t i, j;
+    int minidx = 0, idx;
+
+    for (i = 0; i < def->nmems; i++) {
+        if ((idx = qemuDomainDeviceAliasIndex(&def->mems[i]->info, "dimm")) != i) {
+            for (j = 0; j < def->nmems; j++) {
+                if ((idx = qemuDomainDeviceAliasIndex(&def->mems[j]->info, "dimm")) == i)
+                    break;
+            }
+
+            if (j >= def->nmems) {
+                minidx = i;
+                break;
+            }
+        }
+
+        if ((idx = qemuDomainDeviceAliasIndex(&def->mems[i]->info, "dimm")) >= minidx)
+            minidx = idx + 1;
+    }
+
+    return minidx;
+}
 
+/* If the slot is not mentioned then find the smallest slot(X) available
+   and assign alias as dimmX. */
 int
 qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
                             virDomainMemoryDefPtr mem)
 {
-    size_t i;
-    int maxidx = 0;
-    int idx;
+    int minidx = 0;
 
-    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;
 
     return 0;
@@ -445,8 +472,12 @@ 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;
+        if (!def->mems[i]->info.addr.dimm.base) {
+            if (virAsprintf(&def->mems[i]->info.alias, "dimm%zu", i) < 0)
+                return -1;
+        } else if (virAsprintf(&def->mems[i]->info.alias, "dimm%d", def->mems[i]->info.addr.dimm.slot) < 0) {
+              return -1;
+        }
     }
 
     return 0;
-- 
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]