]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Generate memory device aliases according to slot number
authorPeter Krempa <pkrempa@redhat.com>
Tue, 1 Nov 2016 05:21:36 +0000 (06:21 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 10 Nov 2016 16:36:55 +0000 (17:36 +0100)
The memory device alias needs to be treated as machine ABI as qemu is
using it in the migration stream for section labels. To simplify this
generate the alias from the slot number unless an existing broken
configuration is detected.

With this patch the aliases are predictable and even certain
configurations which would not be migratable previously are fixed.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1359135

src/qemu/qemu_alias.c
src/qemu/qemu_alias.h
src/qemu/qemu_hotplug.c
tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm-addr.args

index 9737158488404ca3425d8605cc3d4d24e2653f16..8521a44ff8a88bdc7f806ac3cba67c137c00a30a 100644 (file)
@@ -332,17 +332,34 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def,
 }
 
 
+/**
+ * qemuAssignDeviceMemoryAlias:
+ * @def: domain definition. Necessary only if @oldAlias is true.
+ * @mem: memory device definition
+ * @oldAlias: Generate the alias according to the order of the device in @def
+ *            rather than according to the slot number for legacy reasons.
+ *
+ * Generates alias for a memory device according to slot number if @oldAlias is
+ * false or according to order in @def->mems otherwise.
+ *
+ * Returns 0 on success, -1 on error.
+ */
 int
 qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
-                            virDomainMemoryDefPtr mem)
+                            virDomainMemoryDefPtr mem,
+                            bool oldAlias)
 {
     size_t i;
     int maxidx = 0;
     int idx;
 
-    for (i = 0; i < def->nmems; i++) {
-        if ((idx = qemuDomainDeviceAliasIndex(&def->mems[i]->info, "dimm")) >= maxidx)
-            maxidx = idx + 1;
+    if (oldAlias) {
+        for (i = 0; i < def->nmems; i++) {
+            if ((idx = qemuDomainDeviceAliasIndex(&def->mems[i]->info, "dimm")) >= maxidx)
+                maxidx = idx + 1;
+        }
+    } else {
+        maxidx = mem->info.addr.dimm.slot;
     }
 
     if (virAsprintf(&mem->info.alias, "dimm%d", maxidx) < 0)
@@ -475,7 +492,7 @@ 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)
+        if (qemuAssignDeviceMemoryAlias(NULL, def->mems[i], false) < 0)
             return -1;
     }
 
index d298a4dab283f1cc249b0e7de7e803ad637e0bb4..dea05cf992ace8f2cd2d3e32e96bbc0308fef2ee 100644 (file)
@@ -58,7 +58,8 @@ int qemuAssignDeviceRNGAlias(virDomainDefPtr def,
                              virDomainRNGDefPtr rng);
 
 int qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
-                                virDomainMemoryDefPtr mems);
+                                virDomainMemoryDefPtr mems,
+                                bool oldAlias);
 
 int qemuAssignDeviceShmemAlias(virDomainDefPtr def,
                                virDomainShmemDefPtr shmem,
index 7a023d2974cf5b59981bf002e2d5b8c8dd7c5633..1bc27068bbdad3f103f56b7b0714a4fe105efe2a 100644 (file)
@@ -2135,7 +2135,9 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
     if (qemuDomainAssignMemoryDeviceSlot(vm->def, mem) < 0)
         goto cleanup;
 
-    if (qemuAssignDeviceMemoryAlias(vm->def, mem) < 0)
+    /* in cases where we are using a VM with aliases generated according to the
+     * index of the memory device we need to keep continue using that scheme */
+    if (qemuAssignDeviceMemoryAlias(vm->def, mem, priv->memAliasOrderMismatch) < 0)
         goto cleanup;
 
     if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0)
index 23403df5eb44340ce2ebe915f86f7261639a968f..fdbb4c32997edfe7b34660e16cb67011ecf476a1 100644 (file)
@@ -15,8 +15,8 @@ QEMU_AUDIO_DRV=none \
 mem-path=/dev/hugepages2M/libvirt/qemu,size=536870912,host-nodes=1-3,\
 policy=bind \
 -device pc-dimm,node=0,memdev=memdimm0,id=dimm0,slot=0,addr=4294967296 \
--object memory-backend-ram,id=memdimm1,size=536870912 \
--device pc-dimm,node=0,memdev=memdimm1,id=dimm1,slot=2 \
+-object memory-backend-ram,id=memdimm2,size=536870912 \
+-device pc-dimm,node=0,memdev=memdimm2,id=dimm2,slot=2 \
 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
 -nographic \
 -nodefaults \