]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Drop two layers of nesting of memoryBackingDir
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 26 Mar 2020 09:46:41 +0000 (10:46 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 7 Apr 2020 13:26:17 +0000 (15:26 +0200)
Initially introduced in v3.10.0-rc1~172.

When generating a path for memory-backend-file or -mem-path, qemu
driver will use the following pattern:

  $memoryBackingDir/libvirt/qemu/$id-$shortName

where $memoryBackingDir defaults to /var/lib/libvirt/qemu/ram but
can be overridden in qemu.conf. Anyway, the "/libvirt/qemu/" part
looks redundant, because it's already contained in the default,
or creates unnecessary nesting if overridden in qemu.conf.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
src/qemu/qemu_conf.c
src/qemu/qemu_conf.h
src/qemu/qemu_driver.c
tests/qemuxml2argvdata/cpu-numa-memshared.args
tests/qemuxml2argvdata/fd-memory-no-numa-topology.args
tests/qemuxml2argvdata/fd-memory-numa-topology.args
tests/qemuxml2argvdata/fd-memory-numa-topology2.args
tests/qemuxml2argvdata/fd-memory-numa-topology3.args
tests/qemuxml2argvdata/hugepages-memaccess2.args
tests/qemuxml2argvdata/pages-dimm-discard.args
tests/qemuxml2argvdata/vhost-user-fs-fd-memory.x86_64-latest.args

index 5ac316ec77b5f0b7986caa51b4459e790d517c00..5339c5fc0423e0b1af321226f424837a30792008 100644 (file)
@@ -970,7 +970,18 @@ static int
 virQEMUDriverConfigLoadMemoryEntry(virQEMUDriverConfigPtr cfg,
                                    virConfPtr conf)
 {
-    return virConfGetValueString(conf, "memory_backing_dir", &cfg->memoryBackingDir);
+    char *dir = NULL;
+    int rc;
+
+    if ((rc = virConfGetValueString(conf, "memory_backing_dir", &dir)) < 0) {
+        return -1;
+    } else if (rc > 0) {
+        VIR_FREE(cfg->memoryBackingDir);
+        cfg->memoryBackingDir = g_strdup_printf("%s/libvirt/qemu", dir);
+        return 1;
+    }
+
+    return 0;
 }
 
 
@@ -1945,27 +1956,17 @@ qemuGetDomainHupageMemPath(const virDomainDef *def,
 }
 
 
-void
-qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg,
-                             char **path)
-{
-    *path = g_strdup_printf("%s/libvirt/qemu", cfg->memoryBackingDir);
-}
-
-
 int
 qemuGetMemoryBackingDomainPath(const virDomainDef *def,
                                virQEMUDriverConfigPtr cfg,
                                char **path)
 {
     g_autofree char *shortName = NULL;
-    g_autofree char *base = NULL;
 
     if (!(shortName = virDomainDefGetShortName(def)))
         return -1;
 
-    qemuGetMemoryBackingBasePath(cfg, &base);
-    *path = g_strdup_printf("%s/%s", base, shortName);
+    *path = g_strdup_printf("%s/%s", cfg->memoryBackingDir, shortName);
 
     return 0;
 }
index 10bc7e4a5210cd42e5c9bb20b68a4d859ac27008..89332eeb730be30dd0010b75da211282cfa4b22d 100644 (file)
@@ -397,8 +397,6 @@ int qemuGetDomainHupageMemPath(const virDomainDef *def,
                                unsigned long long pagesize,
                                char **memPath);
 
-void qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg,
-                                  char **path);
 int qemuGetMemoryBackingDomainPath(const virDomainDef *def,
                                    virQEMUDriverConfigPtr cfg,
                                    char **path);
index 325dd6bfb162f928eccab8df7fcacdc38935d3e2..0c068c398c69cefa3d6d43d9cfda51c535d4abae 100644 (file)
@@ -635,7 +635,6 @@ qemuStateInitialize(bool privileged,
     virQEMUDriverConfigPtr cfg;
     uid_t run_uid = -1;
     gid_t run_gid = -1;
-    g_autofree char *memoryBackingPath = NULL;
     bool autostart = true;
     size_t i;
     const char *defsecmodel = NULL;
@@ -930,17 +929,8 @@ qemuStateInitialize(bool privileged,
             goto error;
     }
 
-    qemuGetMemoryBackingBasePath(cfg, &memoryBackingPath);
-
-    if (virFileMakePath(memoryBackingPath) < 0) {
-        virReportSystemError(errno,
-                             _("unable to create memory backing path %s"),
-                             memoryBackingPath);
-        goto error;
-    }
-
     if (privileged &&
-        virFileUpdatePerm(memoryBackingPath,
+        virFileUpdatePerm(cfg->memoryBackingDir,
                           0, S_IXGRP | S_IXOTH) < 0)
         goto error;
 
index 752eed8d135b4084c021e1f5e1a082c39fd73d45..8e214189db038c201dc7b0ed8fcf381ca56efeaf 100644 (file)
@@ -15,12 +15,12 @@ QEMU_AUDIO_DRV=none \
 -realtime mlock=off \
 -smp 16,sockets=2,cores=4,threads=2 \
 -object memory-backend-file,id=ram-node0,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\
-share=yes,size=112197632 \
+mem-path=/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node0,share=yes,\
+size=112197632 \
 -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \
 -object memory-backend-file,id=ram-node1,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node1,\
-share=no,size=112197632 \
+mem-path=/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node1,share=no,\
+size=112197632 \
 -numa node,nodeid=1,cpus=8-15,memdev=ram-node1 \
 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
 -display none \
index d23c5755532bc816364201e71096576370986da1..dec35cc10a08059f11f93727692a7b871c414348 100644 (file)
@@ -13,7 +13,7 @@ QEMU_AUDIO_DRV=none \
 -machine pc-i440fx-2.3,accel=kvm,usb=off,dump-guest-core=off \
 -m 14336 \
 -mem-prealloc \
--mem-path /var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram \
+-mem-path /var/lib/libvirt/qemu/ram/-1-instance-00000092/ram \
 -realtime mlock=off \
 -smp 8,sockets=8,cores=1,threads=1 \
 -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \
index 4fbbc8185ba8cd47ad040e9d95b85f24ea9cc2bd..2d3e90ff7a7454e5fbaa6b2e5efcc6e771481db3 100644 (file)
@@ -16,8 +16,8 @@ QEMU_AUDIO_DRV=none \
 -realtime mlock=off \
 -smp 8,sockets=1,cores=8,threads=1 \
 -object memory-backend-file,id=ram-node0,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node0,\
-share=yes,size=15032385536 \
+mem-path=/var/lib/libvirt/qemu/ram/-1-instance-00000092/ram-node0,share=yes,\
+size=15032385536 \
 -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \
 -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \
 -display none \
index 1eeeaec0ce4d47e0a96a81131936b0cbbe21ccd0..6b1695feb19a74a0431812f8a878e063cf86b5a7 100644 (file)
@@ -16,12 +16,12 @@ QEMU_AUDIO_DRV=none \
 -realtime mlock=off \
 -smp 20,sockets=1,cores=8,threads=1 \
 -object memory-backend-file,id=ram-node0,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node0,\
-share=no,size=15032385536 \
+mem-path=/var/lib/libvirt/qemu/ram/-1-instance-00000092/ram-node0,share=no,\
+size=15032385536 \
 -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \
 -object memory-backend-file,id=ram-node1,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node1,\
-share=yes,size=15032385536 \
+mem-path=/var/lib/libvirt/qemu/ram/-1-instance-00000092/ram-node1,share=yes,\
+size=15032385536 \
 -numa node,nodeid=1,cpus=8-15,memdev=ram-node1 \
 -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \
 -display none \
index d75b67916c379196dd9628bf3097685e8e086ff2..205d14a7db29b1ab01b8d77b3ad4260e6d58e54b 100644 (file)
@@ -16,16 +16,16 @@ QEMU_AUDIO_DRV=none \
 -realtime mlock=off \
 -smp 32,sockets=1,cores=24,threads=1 \
 -object memory-backend-file,id=ram-node0,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node0,\
-share=yes,size=15032385536 \
+mem-path=/var/lib/libvirt/qemu/ram/-1-instance-00000092/ram-node0,share=yes,\
+size=15032385536 \
 -numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \
 -object memory-backend-file,id=ram-node1,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node1,\
-share=yes,size=15032385536 \
+mem-path=/var/lib/libvirt/qemu/ram/-1-instance-00000092/ram-node1,share=yes,\
+size=15032385536 \
 -numa node,nodeid=1,cpus=2-3,memdev=ram-node1 \
 -object memory-backend-file,id=ram-node2,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node2,\
-share=no,size=15032385536 \
+mem-path=/var/lib/libvirt/qemu/ram/-1-instance-00000092/ram-node2,share=no,\
+size=15032385536 \
 -numa node,nodeid=2,cpus=4-5,memdev=ram-node2 \
 -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \
 -display none \
index 654baebf9f433ece64c8efb06691d2b20607796e..c1560e63c3815cb64a33b6afaf32380174afcdf2 100644 (file)
@@ -15,20 +15,20 @@ QEMU_AUDIO_DRV=none \
 -realtime mlock=off \
 -smp 4,sockets=4,cores=1,threads=1 \
 -object memory-backend-file,id=ram-node0,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\
-share=no,size=1073741824,host-nodes=0-3,policy=bind \
+mem-path=/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node0,share=no,\
+size=1073741824,host-nodes=0-3,policy=bind \
 -numa node,nodeid=0,cpus=0,memdev=ram-node0 \
 -object memory-backend-file,id=ram-node1,prealloc=yes,\
 mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=yes,size=1073741824,\
 host-nodes=0-3,policy=bind \
 -numa node,nodeid=1,cpus=1,memdev=ram-node1 \
 -object memory-backend-file,id=ram-node2,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node2,\
-share=no,size=1073741824,host-nodes=0-3,policy=bind \
+mem-path=/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node2,share=no,\
+size=1073741824,host-nodes=0-3,policy=bind \
 -numa node,nodeid=2,cpus=2,memdev=ram-node2 \
 -object memory-backend-file,id=ram-node3,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node3,\
-share=no,size=1073741824,host-nodes=3,policy=bind \
+mem-path=/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/ram-node3,share=no,\
+size=1073741824,host-nodes=3,policy=bind \
 -numa node,nodeid=3,cpus=3,memdev=ram-node3 \
 -object memory-backend-file,id=memdimm0,prealloc=yes,\
 mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=yes,size=536870912,\
index fefa205597dfc8e61ccfbc3491fcc745926f42a6..96e9ffdec3e064c3d2df85b36c50002e15990893 100644 (file)
@@ -20,8 +20,8 @@ mem-path=/dev/hugepages1G/libvirt/qemu/-1-fedora,size=1073741824,\
 host-nodes=1-3,policy=bind \
 -device pc-dimm,node=0,memdev=memdimm0,id=dimm0,slot=0 \
 -object memory-backend-file,id=memdimm1,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-fedora/dimm1,\
-discard-data=yes,share=no,size=536870912 \
+mem-path=/var/lib/libvirt/qemu/ram/-1-fedora/dimm1,discard-data=yes,share=no,\
+size=536870912 \
 -device pc-dimm,node=0,memdev=memdimm1,id=dimm1,slot=1 \
 -uuid 63840878-0deb-4095-97e6-fc444d9bc9fa \
 -display none \
index a7df45a7f0f3938990f21c2239bb7acd70f19811..dd5f68abc545b13d458132666df548d177f36db4 100644 (file)
@@ -18,7 +18,7 @@ file=/tmp/lib/domain--1-guest/master-key.aes \
 -overcommit mem-lock=off \
 -smp 2,sockets=2,cores=1,threads=1 \
 -object memory-backend-file,id=ram-node0,\
-mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-guest/ram-node0,share=yes,\
+mem-path=/var/lib/libvirt/qemu/ram/-1-guest/ram-node0,share=yes,\
 size=15032385536 \
 -numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \
 -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \