]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Separate out hugepages basedir making
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 11 Oct 2022 14:41:35 +0000 (16:41 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 17 Oct 2022 06:40:18 +0000 (08:40 +0200)
During its initialization, the QEMU driver iterates over
hugetlbfs mount points, creating the driver specific path in each
of them ($prefix/libvirt/qemu). This path is created with very
wide mode (0777) because per-domain directories are then created
under it.

Separate this code into a function so that it can be re-used.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/qemu/qemu_conf.c
src/qemu/qemu_conf.h
src/qemu/qemu_driver.c

index 4f59e5fb0726e23ab8310d953c2406dfccd3018f..8de887d1faa7e9b517d612a432b17faba6d2c407 100644 (file)
@@ -1576,3 +1576,30 @@ qemuGetMemoryBackingPath(virQEMUDriver *driver,
     *memPath = g_strdup_printf("%s/%s", domainPath, alias);
     return 0;
 }
+
+
+int
+qemuHugepageMakeBasedir(virQEMUDriver *driver,
+                        virHugeTLBFS *hugepage)
+{
+
+    g_autofree char *hugepagePath = NULL;
+
+    hugepagePath = qemuGetBaseHugepagePath(driver, hugepage);
+
+    if (!hugepagePath)
+        return -1;
+
+    if (g_mkdir_with_parents(hugepagePath, 0777) < 0) {
+        virReportSystemError(errno,
+                             _("unable to create hugepage path %s"),
+                             hugepagePath);
+        return -1;
+    }
+
+    if (driver->privileged &&
+        virFileUpdatePerm(hugepage->mnt_dir, 0, S_IXGRP | S_IXOTH) < 0)
+        return -1;
+
+    return 0;
+}
index c40c452f5858ec4725d9c941f620c49f5c271e92..ac911b03c2277accf0282ed1497a7a406014fba0 100644 (file)
@@ -359,3 +359,6 @@ int qemuGetMemoryBackingPath(virQEMUDriver *driver,
                              const virDomainDef *def,
                              const char *alias,
                              char **memPath);
+
+int qemuHugepageMakeBasedir(virQEMUDriver *driver,
+                            virHugeTLBFS *hugepage);
index 40d23b5723838d625c81ac0e89aed7efc110ec20..5c7500074269f8ed823d1a34baea5f81601b5be9 100644 (file)
@@ -837,22 +837,7 @@ qemuStateInitialize(bool privileged,
      * it, since we can't assume the root mount point has permissions that
      * will let our spawned QEMU instances use it. */
     for (i = 0; i < cfg->nhugetlbfs; i++) {
-        g_autofree char *hugepagePath = NULL;
-
-        hugepagePath = qemuGetBaseHugepagePath(qemu_driver, &cfg->hugetlbfs[i]);
-
-        if (!hugepagePath)
-            goto error;
-
-        if (g_mkdir_with_parents(hugepagePath, 0777) < 0) {
-            virReportSystemError(errno,
-                                 _("unable to create hugepage path %s"),
-                                 hugepagePath);
-            goto error;
-        }
-        if (privileged &&
-            virFileUpdatePerm(cfg->hugetlbfs[i].mnt_dir,
-                              0, S_IXGRP | S_IXOTH) < 0)
+        if (qemuHugepageMakeBasedir(qemu_driver, &cfg->hugetlbfs[i]) < 0)
             goto error;
     }