[sandbox PATCH 10/10] Common-builder: /dev/disk/by-tag/thetag to /dev/vdN

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

 



Common builder counts the disks devices and populates disks.cfg according to that.Disk devices
are always come first than host-based images.In builder-machine, mounts of the host-based images
will be mounted later.
---
 libvirt-sandbox/libvirt-sandbox-builder-machine.c |  6 +-
 libvirt-sandbox/libvirt-sandbox-builder.c         | 73 +++++++++++++++++++++--
 2 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-builder-machine.c b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
index 4148d4b..db956cf 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-machine.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-machine.c
@@ -283,9 +283,10 @@ static gboolean gvir_sandbox_builder_machine_write_mount_cfg(GVirSandboxConfig *
                                             error);
     gboolean ret = FALSE;
     GList *mounts = gvir_sandbox_config_get_mounts(config);
+    GList *disks = gvir_sandbox_config_get_disks(config);
     GList *tmp = NULL;
     size_t nHostBind = 0;
-    size_t nHostImage = 0;
+    guint nVirtioDev = g_list_length(disks);
 
     if (!fos)
         goto cleanup;
@@ -304,7 +305,7 @@ static gboolean gvir_sandbox_builder_machine_write_mount_cfg(GVirSandboxConfig *
             fstype = "9p";
             options = g_strdup("trans=virtio,version=9p2000.u");
         } else if (GVIR_SANDBOX_IS_CONFIG_MOUNT_HOST_IMAGE(mconfig)) {
-            source = g_strdup_printf("/dev/vd%c", (char)('a' + nHostImage++));
+            source = g_strdup_printf("/dev/vd%c", (char)('a' + nVirtioDev++));
             fstype = "ext4";
             options = g_strdup("");
         } else if (GVIR_SANDBOX_IS_CONFIG_MOUNT_GUEST_BIND(mconfig)) {
@@ -351,6 +352,7 @@ static gboolean gvir_sandbox_builder_machine_write_mount_cfg(GVirSandboxConfig *
  cleanup:
     g_list_foreach(mounts, (GFunc)g_object_unref, NULL);
     g_list_free(mounts);
+    g_list_free(disks);
     if (fos)
         g_object_unref(fos);
     if (!ret)
diff --git a/libvirt-sandbox/libvirt-sandbox-builder.c b/libvirt-sandbox/libvirt-sandbox-builder.c
index bcad652..d83fd9f 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder.c
@@ -312,14 +312,75 @@ static gboolean gvir_sandbox_builder_construct_features(GVirSandboxBuilder *buil
     return TRUE;
 }
 
+static gboolean gvir_sandbox_builder_construct_disk_cfg(GVirSandboxConfig *config,
+                                                        const gchar *statedir,
+                                                        GError **error)
+{
 
-static gboolean gvir_sandbox_builder_construct_devices(GVirSandboxBuilder *builder G_GNUC_UNUSED,
-                                                       GVirSandboxConfig *config G_GNUC_UNUSED,
-                                                       const gchar *statedir G_GNUC_UNUSED,
-                                                       GVirConfigDomain *domain G_GNUC_UNUSED,
-                                                       GError **error G_GNUC_UNUSED)
+    guint nVirtioDev = 0;
+    gchar *dskfile = g_strdup_printf("%s/config/disks.cfg", statedir);
+    GFile *file = g_file_new_for_path(dskfile);
+    GFileOutputStream *fos = g_file_replace(file,
+                                            NULL,
+                                            FALSE,
+                                            G_FILE_CREATE_REPLACE_DESTINATION,
+                                            NULL,
+                                            error);
+    gboolean ret = FALSE;
+    GList *disks = gvir_sandbox_config_get_disks(config);
+    GList *tmp = NULL;
+    const gchar *target;
+
+    if (!fos)
+        goto cleanup;
+
+    tmp = disks;
+    while (tmp) {
+        GVirSandboxConfigDisk *mconfig = GVIR_SANDBOX_CONFIG_DISK(tmp->data);
+        gchar *device = g_strdup_printf("/dev/vd%c", (char)('a' + (nVirtioDev)++));
+        gchar *line;
+
+        target = gvir_sandbox_config_disk_get_target(mconfig);
+
+        line = g_strdup_printf("%s\t%s\n",
+                               target, device);
+        g_free(device);
+
+        if (!g_output_stream_write_all(G_OUTPUT_STREAM(fos),
+                                       line, strlen(line),
+                                       NULL, NULL, error)) {
+            g_free(line);
+            goto cleanup;
+        }
+        g_free(line);
+
+        tmp = tmp->next;
+    }
+
+    if (!g_output_stream_close(G_OUTPUT_STREAM(fos), NULL, error))
+        goto cleanup;
+
+    ret = TRUE;
+ cleanup:
+    g_list_foreach(disks, (GFunc)g_object_unref, NULL);
+    g_list_free(disks);
+    if (fos)
+        g_object_unref(fos);
+    if (!ret)
+        g_file_delete(file, NULL, NULL);
+    g_object_unref(file);
+    g_free(dskfile);
+    return ret;
+
+}
+
+static gboolean gvir_sandbox_builder_construct_devices(GVirSandboxBuilder *builder,
+                                                       GVirSandboxConfig *config,
+                                                       const gchar *statedir,
+                                                       GVirConfigDomain *domain,
+                                                       GError **error)
 {
-    return TRUE;
+    return gvir_sandbox_builder_construct_disk_cfg(config,statedir,error);
 }
 
 static gboolean gvir_sandbox_builder_construct_security_selinux (GVirSandboxBuilder *builder,
-- 
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]