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(a)huawei.com>
Signed-off-by: Wang Xin <wangxinxin.wang(a)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 83a005a479..641f712877 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);
}
@@ -15365,6 +15366,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;
@@ -27383,6 +27390,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 5ad7964b90..dc40e62186 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8513,7 +8513,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/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