[Libguestfs] [PATCH 1/2] Allow qemu_supports to run earlier.
Richard W.M. Jones
rjones at redhat.com
Tue Mar 16 21:52:46 UTC 2010
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
-------------- next part --------------
>From 5442f45aea522a728fa5b06396d4f08d8506d7de Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones at redhat.com>
Date: Tue, 16 Mar 2010 21:44:26 +0000
Subject: [PATCH 1/2] Allow qemu_supports to run earlier.
Reimplement qemu_supports() internal function. Allow it to run
before launch so we can test qemu features. Document that you
should run guestfs_set_qemu as early as possible to make sure
these tests are reliable.
---
src/generator.ml | 10 +++++++++-
src/guestfs.c | 27 ++++++++++++++++++---------
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml
index 486b9d8..4f569ba 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -581,7 +581,15 @@ configure script.
You can also override this by setting the C<LIBGUESTFS_QEMU>
environment variable.
-Setting C<qemu> to C<NULL> restores the default qemu binary.");
+Setting C<qemu> to C<NULL> restores the default qemu binary.
+
+Note that you should call this function as early as possible
+after creating the handle. This is because some pre-launch
+operations depend on testing qemu features (by running C<qemu -help>).
+If the qemu binary changes, we don't retest features, and
+so you might see inconsistent results. Using the environment
+variable C<LIBGUESTFS_QEMU> is safest of all since that picks
+the qemu binary at the same time as the handle is created.");
("get_qemu", (RConstString "qemu", []), -1, [],
[InitNone, Always, TestRun (
diff --git a/src/guestfs.c b/src/guestfs.c
index 2ba062c..af60699 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -91,6 +91,7 @@ static int recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn);
static int accept_from_daemon (guestfs_h *g);
static int check_peer_euid (guestfs_h *g, int sock, uid_t *rtn);
static void close_handles (void);
+static int qemu_supports (guestfs_h *g, const char *option);
#define UNIX_PATH_MAX 108
@@ -870,8 +871,6 @@ dir_contains_files (const char *dir, ...)
static void print_timestamped_message (guestfs_h *g, const char *fs, ...);
static int build_supermin_appliance (guestfs_h *g, const char *path, char **kernel, char **initrd);
-static int test_qemu (guestfs_h *g);
-static int qemu_supports (guestfs_h *g, const char *option);
static int is_openable (guestfs_h *g, const char *path, int flags);
static void print_cmdline (guestfs_h *g);
@@ -1023,7 +1022,7 @@ guestfs__launch (guestfs_h *g)
print_timestamped_message (g, "begin testing qemu features");
/* Get qemu help text and version. */
- if (test_qemu (g) == -1)
+ if (qemu_supports (g, NULL) == -1)
goto cleanup0;
/* Choose which vmchannel implementation to use. */
@@ -1607,11 +1606,6 @@ test_qemu (guestfs_h *g)
char cmd[1024];
FILE *fp;
- free (g->qemu_help);
- free (g->qemu_version);
- g->qemu_help = NULL;
- g->qemu_version = NULL;
-
snprintf (cmd, sizeof cmd, "LC_ALL=C '%s' -help", g->qemu);
fp = popen (cmd, "r");
@@ -1672,11 +1666,26 @@ read_all (guestfs_h *g, FILE *fp, char **ret)
/* Test if option is supported by qemu command line (just by grepping
* the help text).
+ *
+ * The first time this is used, it has to run the external qemu
+ * binary. If that fails, it returns -1.
+ *
+ * To just do the first-time run of the qemu binary, call this with
+ * option == NULL, in which case it will return -1 if there was an
+ * error doing that.
*/
static int
qemu_supports (guestfs_h *g, const char *option)
{
- return g->qemu_help && strstr (g->qemu_help, option) != NULL;
+ if (!g->qemu_help) {
+ if (test_qemu (g) == -1)
+ return -1;
+ }
+
+ if (option == NULL)
+ return 1;
+
+ return strstr (g->qemu_help, option) != NULL;
}
/* Check if a file can be opened. */
--
1.7.0.1
More information about the Libguestfs
mailing list