[sandbox 06/10] init-qemu: extract the mounts.cfg entry mounting code

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

 



Create a mount_entry function from the code mounting the entries
defined in mounts.cfg in order to be able to reuse that code. This will
later be useful to mount a / from mounts.cfg.
---
 libvirt-sandbox/libvirt-sandbox-init-qemu.c | 68 +++++++++++++++++------------
 1 file changed, 39 insertions(+), 29 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-qemu.c b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
index 45cb9b3..9acea5f 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-qemu.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-qemu.c
@@ -226,6 +226,44 @@ create_virtioblk_device(const char *dev)
     }
 }
 
+static void
+mount_entry(const char *source,
+            const char *target,
+            const char *type,
+            const char * opts)
+{
+    int flags = 0;
+
+    if (strncmp(source, "/dev/vd", 7) == 0)
+        create_virtioblk_device(source);
+
+    if (STREQ(type, "")) {
+        struct stat st;
+        type = NULL;
+        flags |= MS_BIND;
+        if (stat(source, &st) < 0) {
+            fprintf(stderr, "libvirt-sandbox-init-qemu: %s: cannot read mount source %s: %s\n",
+                    __func__, source, strerror(errno));
+            exit_poweroff();
+        }
+        if (S_ISDIR(st.st_mode))
+            mount_mkdir(target, 755);
+        else
+            mount_mkfile(target, 644);
+    } else {
+        if (STREQ(type, "tmpfs"))
+            flags |= MS_NOSUID | MS_NODEV;
+
+        mount_mkdir(target, 0755);
+    }
+
+    if (mount(source, target, type, flags, opts) < 0) {
+        fprintf(stderr, "libvirt-sandbox-init-qemu: %s: cannot mount %s on %s (%s, %s): %s\n",
+                __func__, source, target, type, opts, strerror(errno));
+        exit_poweroff();
+    }
+}
+
 int
 main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED)
 {
@@ -369,40 +407,12 @@ main(int argc ATTR_UNUSED, char **argv ATTR_UNUSED)
         opts++;
         char *tmp = strchr(opts, '\n');
         *tmp = '\0';
-        int flags = 0;
 
         if (debug)
             fprintf(stderr, "libvirt-sandbox-init-qemu: %s: %s -> %s (%s, %s)\n",
                     __func__, source, target, type, opts);
 
-        if (strncmp(source, "/dev/vd", 7) == 0)
-            create_virtioblk_device(source);
-
-        if (STREQ(type, "")) {
-            struct stat st;
-            type = NULL;
-            flags |= MS_BIND;
-            if (stat(source, &st) < 0) {
-                fprintf(stderr, "libvirt-sandbox-init-qemu: %s: cannot read mount source %s: %s\n",
-                        __func__, source, strerror(errno));
-                exit_poweroff();
-            }
-            if (S_ISDIR(st.st_mode))
-                mount_mkdir(target, 755);
-            else
-                mount_mkfile(target, 644);
-        } else {
-            if (STREQ(type, "tmpfs"))
-                flags |= MS_NOSUID | MS_NODEV;
-
-            mount_mkdir(target, 0755);
-        }
-
-        if (mount(source, target, type, flags, opts) < 0) {
-            fprintf(stderr, "libvirt-sandbox-init-qemu: %s: cannot mount %s on %s (%s, %s): %s\n",
-                    __func__, source, target, type, opts, strerror(errno));
-            exit_poweroff();
-        }
+        mount_entry(source, target, type, opts);
     }
     fclose(fp);
 
-- 
2.1.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]