[PATCH RFC 3/7] virfile: Introduce virFileSetupDev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/lxc/lxc_controller.c | 14 +-------------
 src/util/virfile.c       | 30 ++++++++++++++++++++++++++++++
 src/util/virfile.h       |  3 +++
 4 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 868905e..b984fa1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1602,6 +1602,7 @@ virFileResolveAllLinks;
 virFileResolveLink;
 virFileRewrite;
 virFileSanitizePath;
+virFileSetupDev;
 virFileSkipRoot;
 virFileStripSuffix;
 virFileTouch;
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 130b09f..3ab155f 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1457,12 +1457,6 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl)
                     LXC_STATE_DIR, ctrl->def->name) < 0)
         goto cleanup;
 
-    if (virFileMakePath(dev) < 0) {
-        virReportSystemError(errno,
-                             _("Failed to make path %s"), dev);
-        goto cleanup;
-    }
-
     /*
      * tmpfs is limited to 64kb, since we only have device nodes in there
      * and don't want to DOS the entire OS RAM usage
@@ -1472,14 +1466,8 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl)
                     "mode=755,size=65536%s", mount_options) < 0)
         goto cleanup;
 
-    VIR_DEBUG("Mount devfs on %s type=tmpfs flags=%x, opts=%s",
-              dev, MS_NOSUID, opts);
-    if (mount("devfs", dev, "tmpfs", MS_NOSUID, opts) < 0) {
-        virReportSystemError(errno,
-                             _("Failed to mount devfs on %s type %s (%s)"),
-                             dev, "tmpfs", opts);
+    if (virFileSetupDev(dev, opts) < 0)
         goto cleanup;
-    }
 
     if (lxcContainerChown(ctrl->def, dev) < 0)
         goto cleanup;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index eae4db4..d86acbf 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -32,6 +32,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
+#include <sys/mount.h>
 #include <unistd.h>
 #include <dirent.h>
 #include <dirname.h>
@@ -3532,3 +3533,32 @@ virFilePopulateDevices(const char *prefix,
     VIR_FREE(path);
     return ret;
 }
+
+
+int
+virFileSetupDev(const char *path,
+                const char *mount_options)
+{
+    const unsigned long mount_flags = MS_NOSUID;
+    const char *mount_fs = "tmpfs";
+    int ret = -1;
+
+    if (virFileMakePath(path) < 0) {
+        virReportSystemError(errno,
+                             _("Failed to make path %s"), path);
+        goto cleanup;
+    }
+
+    VIR_DEBUG("Mount devfs on %s type=tmpfs flags=%lx, opts=%s",
+              path, mount_flags, mount_options);
+    if (mount("devfs", path, mount_fs, mount_flags, mount_options) < 0) {
+        virReportSystemError(errno,
+                             _("Failed to mount devfs on %s type %s (%s)"),
+                             path, mount_fs, mount_options);
+        goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    return ret;
+}
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 3b3dd13..1b3830d 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -319,4 +319,7 @@ struct _virFileDevices {
 
 int virFilePopulateDevices(const char *prefix,
                            const virFileDevices *const devs);
+
+int virFileSetupDev(const char *path,
+                    const char *mount_options);
 #endif /* __VIR_FILE_H */
-- 
2.8.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]