summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-10-05 15:13:16 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-10-06 23:15:49 +0100
commit328510121ad720680b71b65b9b2a60e816ca49f8 (patch)
treec2cc6f431b4cf50d854f1175f30067946cc2de1d /src
parent92feed7d662b7d9d1f8c475cf06df203143a3a5f (diff)
downloadlibguestfs-328510121ad720680b71b65b9b2a60e816ca49f8.tar.gz
libguestfs-328510121ad720680b71b65b9b2a60e816ca49f8.tar.xz
libguestfs-328510121ad720680b71b65b9b2a60e816ca49f8.zip
launch: Rearrange code for adding drives to the g->drives list in the handle.
This is just code motion.
Diffstat (limited to 'src')
-rw-r--r--src/guestfs.c19
-rw-r--r--src/launch.c85
2 files changed, 62 insertions, 42 deletions
diff --git a/src/guestfs.c b/src/guestfs.c
index a01d5c61..cb9ee6b1 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -1055,25 +1055,6 @@ guestfs___free_string_list (char **argv)
free (argv);
}
-void
-guestfs___free_drives (struct drive **drives)
-{
- struct drive *i = *drives;
- *drives = NULL;
-
- while (i != NULL) {
- struct drive *next = i->next;
-
- free (i->path);
- free (i->format);
- free (i->iface);
- free (i->name);
- free (i);
-
- i = next;
- }
-}
-
char *
guestfs__canonical_device_name (guestfs_h *g, const char *device)
{
diff --git a/src/launch.c b/src/launch.c
index a0d6c121..f325d9f2 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -37,6 +37,8 @@
#include "guestfs-internal-actions.h"
#include "guestfs_protocol.h"
+static void free_drive_struct (struct drive *drv);
+
struct drive **
guestfs___checkpoint_drives (guestfs_h *g)
{
@@ -51,6 +53,60 @@ guestfs___rollback_drives (guestfs_h *g, struct drive **i)
guestfs___free_drives(i);
}
+/* Add struct drive to the g->drives list in the handle. */
+static void
+add_drive_to_handle (guestfs_h *g, struct drive *d)
+{
+ struct drive **drv = &(g->drives);
+
+ while (*drv != NULL)
+ drv = &((*drv)->next);
+
+ *drv = d;
+}
+
+static struct drive *
+create_drive_struct (guestfs_h *g, const char *path,
+ int readonly, const char *format,
+ const char *iface, const char *name,
+ int use_cache_none)
+{
+ struct drive *drv = safe_malloc (g, sizeof (struct drive));
+
+ drv->next = NULL;
+ drv->path = safe_strdup (g, path);
+ drv->readonly = readonly;
+ drv->format = format ? safe_strdup (g, format) : NULL;
+ drv->iface = iface ? safe_strdup (g, iface) : NULL;
+ drv->name = name ? safe_strdup (g, name) : NULL;
+ drv->use_cache_none = use_cache_none;
+
+ return drv;
+}
+
+void
+guestfs___free_drives (struct drive **drives)
+{
+ struct drive *i = *drives;
+ *drives = NULL;
+
+ while (i != NULL) {
+ struct drive *next = i->next;
+ free_drive_struct (i);
+ i = next;
+ }
+}
+
+static void
+free_drive_struct (struct drive *drv)
+{
+ free (drv->path);
+ free (drv->format);
+ free (drv->iface);
+ free (drv->name);
+ free (drv);
+}
+
/* cache=none improves reliability in the event of a host crash.
*
* However this option causes qemu to try to open the file with
@@ -110,27 +166,6 @@ valid_format_iface (const char *str)
return 1;
}
-static void
-add_drive (guestfs_h *g, const char *path,
- int readonly, const char *format,
- const char *iface, const char *name,
- int use_cache_none)
-{
- struct drive **drv = &(g->drives);
-
- while (*drv != NULL)
- drv = &((*drv)->next);
-
- *drv = safe_malloc (g, sizeof (struct drive));
- (*drv)->next = NULL;
- (*drv)->path = safe_strdup (g, path);
- (*drv)->readonly = readonly;
- (*drv)->format = format ? safe_strdup (g, format) : NULL;
- (*drv)->iface = iface ? safe_strdup (g, iface) : NULL;
- (*drv)->name = name ? safe_strdup (g, name) : NULL;
- (*drv)->use_cache_none = use_cache_none;
-}
-
/* Traditionally you have been able to use /dev/null as a filename, as
* many times as you like. Ancient KVM (RHEL 5) cannot handle adding
* /dev/null readonly. qemu 1.2 + virtio-scsi segfaults when you use
@@ -145,6 +180,7 @@ add_null_drive (guestfs_h *g, int readonly, const char *format,
{
char *tmpfile = NULL;
int fd = -1;
+ struct drive *drv;
if (format && STRNEQ (format, "raw")) {
error (g, _("for device '/dev/null', format must be 'raw'"));
@@ -169,7 +205,8 @@ add_null_drive (guestfs_h *g, int readonly, const char *format,
goto err;
}
- add_drive (g, tmpfile, readonly, format, iface, name, 0);
+ drv = create_drive_struct (g, tmpfile, readonly, format, iface, name, 0);
+ add_drive_to_handle (g, drv);
free (tmpfile);
return 0;
@@ -190,6 +227,7 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
const char *iface;
const char *name;
int use_cache_none;
+ struct drive *drv;
if (strchr (filename, ':') != NULL) {
error (g, _("filename cannot contain ':' (colon) character. "
@@ -235,7 +273,8 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
}
}
- add_drive (g, filename, readonly, format, iface, name, use_cache_none);
+ drv = create_drive_struct (g, filename, readonly, format, iface, name, use_cache_none);
+ add_drive_to_handle (g, drv);
return 0;
}