[PATCH v2 2/2] qemu: allow configuring mem-path for ivshmem-plain device

Wang Xin wangxinxin.wang at huawei.com
Fri Jul 17 13:04:51 UTC 2020


The shared memory path is generated by shmem name as default,
however, we may need to change it to avoid filename conflict
when VM migrate to other host.

Signed-off-by: Yang Hang <yanghang44 at huawei.com>
Signed-off-by: Wang Xin <wangxinxin.wang at huawei.com>

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 09d4ad3e96..27fa6306df 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4442,6 +4442,13 @@
             <ref name="scaledInteger"/>
           </element>
         </optional>
+        <optional>
+          <element name="mem">
+            <attribute name="path">
+              <ref name="absFilePath"/>
+            </attribute>
+          </element>
+        </optional>
         <optional>
           <element name="server">
             <optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6e67c7ebe0..41018b12d8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2906,6 +2906,7 @@ void virDomainShmemDefFree(virDomainShmemDefPtr def)
 
     virDomainDeviceInfoClear(&def->info);
     virDomainChrSourceDefClear(&def->server.chr);
+    VIR_FREE(def->memPath);
     VIR_FREE(def->name);
     VIR_FREE(def);
 }
@@ -15381,6 +15382,12 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xmlopt,
                             &def->size, 1, ULLONG_MAX, false) < 0)
         goto cleanup;
 
+    tmp = virXPathString("string(./mem/@path)", ctxt);
+    if (tmp) {
+        def->memPath = virFileSanitizePath(tmp);
+        VIR_FREE(tmp);
+    }
+
     if ((server = virXPathNode("./server[1]", ctxt))) {
         def->server.enabled = true;
 
@@ -27451,6 +27458,12 @@ virDomainShmemDefFormat(virBufferPtr buf,
     virBufferAsprintf(buf, "<model type='%s'/>\n",
                       virDomainShmemModelTypeToString(def->model));
 
+    if (def->memPath) {
+        virBufferAddLit(buf, "<mem");
+        virBufferEscapeString(buf, " path='%s'", def->memPath);
+        virBufferAddLit(buf, "/>\n");
+    }
+
     if (def->size)
         virBufferAsprintf(buf, "<size unit='M'>%llu</size>\n", def->size >> 20);
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 855c144ddb..58fd4f2122 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1782,6 +1782,7 @@ typedef enum {
 struct _virDomainShmemDef {
     char *name;
     unsigned long long size;
+    char *memPath;
     int model; /* enum virDomainShmemModel */
     int role; /* enum virDomainShmemRole */
     struct {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 0655d8359d..db82f66974 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8578,7 +8578,10 @@ qemuBuildShmemBackendMemProps(virDomainShmemDefPtr shmem)
     g_autofree char *mem_path = NULL;
     virJSONValuePtr ret = NULL;
 
-    mem_path = g_strdup_printf("/dev/shm/%s", shmem->name);
+    if (!shmem->memPath)
+        mem_path = g_strdup_printf("/dev/shm/%s", shmem->name);
+    else
+        mem_path = g_strdup_printf("%s", shmem->memPath);
 
     mem_alias = g_strdup_printf("shmmem-%s", shmem->info.alias);
 
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml
index 338017aa28..3970193a80 100644
--- a/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml
@@ -1,5 +1,6 @@
 <shmem name='shmem0' role='peer'>
   <model type='ivshmem-plain'/>
+  <mem path='/dev/shm/shmem0'/>
   <size unit='M'>4</size>
   <alias name='shmem0'/>
   <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml
index 780e49de23..e5c5f61d66 100644
--- a/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml
@@ -1,3 +1,4 @@
 <shmem name='shmem0' role='peer'>
   <model type='ivshmem-plain'/>
+  <mem path='/dev/shm/shmem0'/>
 </shmem>
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml
index 8013264989..0ef2c5027a 100644
--- a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml
+++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml
@@ -47,6 +47,7 @@
     <memballoon model='none'/>
     <shmem name='shmem0' role='peer'>
       <model type='ivshmem-plain'/>
+      <mem path='/dev/shm/shmem0'/>
       <size unit='M'>4</size>
       <alias name='shmem0'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml
index 0490310760..cb9c1238d4 100644
--- a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml
+++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml
@@ -47,6 +47,7 @@
     <memballoon model='none'/>
     <shmem name='shmem0' role='peer'>
       <model type='ivshmem-plain'/>
+      <mem path='/dev/shm/shmem0'/>
       <size unit='M'>4</size>
       <alias name='shmem0'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
diff --git a/tests/qemuxml2argvdata/shmem-plain-doorbell.xml b/tests/qemuxml2argvdata/shmem-plain-doorbell.xml
index 7c76e0fbba..ccad19efe2 100644
--- a/tests/qemuxml2argvdata/shmem-plain-doorbell.xml
+++ b/tests/qemuxml2argvdata/shmem-plain-doorbell.xml
@@ -28,6 +28,7 @@
     </shmem>
     <shmem name='shmem2' role='master'>
       <model type='ivshmem-plain'/>
+      <mem path='/dev/shm/shmem2'/>
       <size unit='M'>256</size>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </shmem>
diff --git a/tests/qemuxml2xmloutdata/shmem-plain-doorbell.xml b/tests/qemuxml2xmloutdata/shmem-plain-doorbell.xml
index 64c0a7d753..aa1b59a50b 100644
--- a/tests/qemuxml2xmloutdata/shmem-plain-doorbell.xml
+++ b/tests/qemuxml2xmloutdata/shmem-plain-doorbell.xml
@@ -33,6 +33,7 @@
     </shmem>
     <shmem name='shmem2' role='master'>
       <model type='ivshmem-plain'/>
+      <mem path='/dev/shm/shmem2'/>
       <size unit='M'>256</size>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </shmem>
-- 
2.26.0.windows.1






More information about the libvir-list mailing list