[sandbox PATCH 09/10] Common-init: Building symlink from disks.cfg

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

 



Similar to the existing mounts.cfg, the mapping between the device and the tag is
passed by a new disks.cfg file. Common-init reads disks.cfg and maps the tags
to corresponding devices
---
 libvirt-sandbox/libvirt-sandbox-init-common.c | 51 +++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c b/libvirt-sandbox/libvirt-sandbox-init-common.c
index 68f96ba..f8b2ea5 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -46,6 +46,7 @@
 #include <grp.h>
 
 #include "libvirt-sandbox-rpcpacket.h"
+#include "libvirt-sandbox-init-util.h"
 
 static gboolean debug = FALSE;
 static gboolean verbose = FALSE;
@@ -60,6 +61,51 @@ static void sig_child(int sig ATTR_UNUSED)
         abort();
 }
 
+static gboolean setup_disk_tags(void) {
+    FILE *fp;
+    gboolean ret = FALSE;
+    static char line[1024];
+    if (debug)
+        fprintf(stderr, "libvirt-sandbox-init-common: %s: populate /dev/disk/by-tag/\n",
+			__func__);
+    fp = fopen(SANDBOXCONFIGDIR "/disks.cfg", "r");
+    if (fp == NULL) {
+        fprintf(stderr, "libvirt-sandbox-init-common: %s: cannot open " SANDBOXCONFIGDIR "/disks.cfg: %s\n",
+                __func__, strerror(errno));
+
+        goto cleanup;
+    }
+    gvir_sandbox_init_util_mkdir("/dev/disk/by-tag", 0755, debug == TRUE ? 1 : 0);
+    while (fgets(line, sizeof line, fp)) {
+        char path[1024];
+        char *tag = line;
+        char *device = strchr(tag, '\t');
+        *device = '\0';
+        device++;
+        char *tmp = strchr(device, '\n');
+        *tmp = '\0';
+
+        if (sprintf(path, "/dev/disk/by-tag/%s", tag) < 0) {
+            fprintf(stderr, "libvirt-sandbox-init-common: %s: cannot compute disk path: %s\n",
+                    __func__, strerror(errno));
+            goto cleanup;
+        }
+
+        if (debug)
+            fprintf(stderr, "libvirt-sandbox-init-common: %s: %s -> %s\n",
+                    __func__, path, device);
+
+        if (symlink(device, path) < 0) {
+            fprintf(stderr, "libvirt-sandbox-init-common: %s: cannot create symlink %s -> %s: %s\n",
+                    __func__, path, device, strerror(errno));
+            goto cleanup;
+        }
+    }
+    ret = TRUE;
+ cleanup:
+    fclose(fp);
+    return ret;
+}
 
 static int
 start_shell(void)
@@ -258,8 +304,6 @@ static gboolean setup_network_device(GVirSandboxConfigNetwork *config,
     return ret;
 }
 
-
-
 static gboolean setup_network(GVirSandboxConfig *config, GError **error)
 {
     int i = 0;
@@ -1215,6 +1259,9 @@ int main(int argc, char **argv) {
         start_shell() < 0)
         exit(EXIT_FAILURE);
 
+    if (!setup_disk_tags())
+        exit(EXIT_FAILURE);
+
     if (!setup_network(config, &error))
         goto error;
 
-- 
2.1.0

--
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]