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 | 54 ++++++++++++++++++++++++++-
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c
b/libvirt-sandbox/libvirt-sandbox-init-common.c
index 68f96ba..a0e6e0a 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,54 @@ 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;
+ }
+ if (g_mkdir_with_parents("/dev/disk/by-tag",0755) < 0) {
+ fprintf(stderr, "libvirt-sandbox-init-common: %s: cannot create the
directory: %s\n",
+ __func__, strerror(errno));
+
+ goto cleanup;
+ }
+ while (fgets(line, sizeof line, fp)) {
+ char *tag = line;
+ char *device = strchr(tag, '\t');
+ gchar *path = NULL;
+ *device = '\0';
+ device++;
+ char *tmp = strchr(device, '\n');
+ *tmp = '\0';
+ path = g_strdup_printf("/dev/disk/by-tag/%s", tag);
+
+ 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));
+ g_free(path);
+ goto cleanup;
+ }
+
+ g_free(path);
+ }
+ ret = TRUE;
+ cleanup:
+ fclose(fp);
+ return ret;
+}
static int
start_shell(void)
@@ -258,8 +307,6 @@ static gboolean setup_network_device(GVirSandboxConfigNetwork
*config,
return ret;
}
-
-
static gboolean setup_network(GVirSandboxConfig *config, GError **error)
{
int i = 0;
@@ -1215,6 +1262,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