[PATCH v2 02/11] qemu: Drop two layers of nesting of memoryBackingDir

Michal Prívozník mprivozn at redhat.com
Mon Mar 30 16:16:29 UTC 2020


On 30. 3. 2020 13:09, Daniel P. Berrangé wrote:
> On Thu, Mar 26, 2020 at 04:15:06PM +0100, Michal Privoznik wrote:
>> 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.
> 
> I think this was copied from our earlier huge pages code
> which used /dev/hugepages, and then added "/libvirt/qemu"
> to it.
> 
> Now we're stripping off "/libvirt/qemu" though, we're liable
> to a filename clashes if someone edits qemu.conf to point to
> /dev/shm.
> 
> IOW, even though "/libvirt/qemu" is redundant when using our
> default path, I think we need to keep it to avoid clashing
> with custom paths.

Alright. So what if I'd squash this in?

diff --git i/src/qemu/qemu_conf.c w/src/qemu/qemu_conf.c
index 9786e19f8f..2ead5d5920 100644
--- i/src/qemu/qemu_conf.c
+++ w/src/qemu/qemu_conf.c
@@ -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;
 }


This way we would drop "/libvirt/qemu" in the default configuration and keep it if user overrides it in qemu.conf.

Michal




More information about the libvir-list mailing list