summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-10-21 12:49:18 +0100
committerRichard W.M. Jones <rjones@redhat.com>2011-10-21 12:49:18 +0100
commit527079aa0db9b608ee4c25e7b3eccc4058685608 (patch)
treead16312e5aff3a27484c47387273a8c9dbd9ec47 /src
parentf5172902bc9d92451c83dc3c1a85b5aeb975b43a (diff)
downloadlibguestfs-527079aa0db9b608ee4c25e7b3eccc4058685608.tar.gz
libguestfs-527079aa0db9b608ee4c25e7b3eccc4058685608.tar.xz
libguestfs-527079aa0db9b608ee4c25e7b3eccc4058685608.zip
lib: Common code for formatting the qemu -drive parameter.
This is just code refactoring.
Diffstat (limited to 'src')
-rw-r--r--src/launch.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/launch.c b/src/launch.c
index ed8d9bdd..ce26e253 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -76,6 +76,7 @@ static int64_t timeval_diff (const struct timeval *x, const struct timeval *y);
static void print_qemu_command_line (guestfs_h *g, char **argv);
static int connect_unix_socket (guestfs_h *g, const char *sock);
static int qemu_supports (guestfs_h *g, const char *option);
+static char *qemu_drive_param (guestfs_h *g, const struct drive *drv);
#if 0
static int qemu_supports_re (guestfs_h *g, const pcre *option_regex);
@@ -186,20 +187,8 @@ guestfs__debug_drives (guestfs_h *g)
ret = safe_malloc (g, sizeof (char *) * (count + 1));
- for (i = 0, drv = g->drives; drv; i++, drv = drv->next) {
- size_t len = 64 + strlen (drv->path) + strlen (drv->iface);
- if (drv->format) len += strlen (drv->format);
-
- ret[i] = safe_malloc (g, len);
-
- snprintf (ret[i], len, "file=%s%s%s%s%s,if=%s",
- drv->path,
- drv->readonly ? ",snapshot=on" : "",
- drv->use_cache_off ? ",cache=off" : "",
- drv->format ? ",format=" : "",
- drv->format ? drv->format : "",
- drv->iface);
- }
+ for (i = 0, drv = g->drives; drv; i++, drv = drv->next)
+ ret[i] = qemu_drive_param (g, drv);
ret[count] = NULL;
@@ -572,25 +561,16 @@ launch_appliance (guestfs_h *g)
g->cmdline[0] = g->qemu;
/* Add drives */
- struct drive *i = g->drives;
- while (i != NULL) {
+ struct drive *drv = g->drives;
+ while (drv != NULL) {
/* Construct the final -drive parameter. */
- size_t len = 64 + strlen (i->path) + strlen (i->iface);
- if (i->format) len += strlen (i->format);
- char buf[len];
-
- snprintf (buf, len, "file=%s%s%s%s%s,if=%s",
- i->path,
- i->readonly ? ",snapshot=on" : "",
- i->use_cache_off ? ",cache=off" : "",
- i->format ? ",format=" : "",
- i->format ? i->format : "",
- i->iface);
+ char *buf = qemu_drive_param (g, drv);
add_cmdline (g, "-drive");
add_cmdline (g, buf);
+ free (buf);
- i = i->next;
+ drv = drv->next;
}
if (qemu_supports (g, "-nodefconfig"))
@@ -1281,6 +1261,30 @@ is_openable (guestfs_h *g, const char *path, int flags)
return 1;
}
+static char *
+qemu_drive_param (guestfs_h *g, const struct drive *drv)
+{
+ size_t len = 64;
+ char *r;
+
+ len += strlen (drv->path);
+ len += strlen (drv->iface);
+ if (drv->format)
+ len += strlen (drv->format);
+
+ r = safe_malloc (g, len);
+
+ snprintf (r, len, "file=%s%s%s%s%s,if=%s",
+ drv->path,
+ drv->readonly ? ",snapshot=on" : "",
+ drv->use_cache_off ? ",cache=off" : "",
+ drv->format ? ",format=" : "",
+ drv->format ? drv->format : "",
+ drv->iface);
+
+ return r; /* caller frees */
+}
+
/* You had to call this function after launch in versions <= 1.0.70,
* but it is now a no-op.
*/