summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Jones <rjones@trick.home.annexia.org>2009-09-21 11:52:53 +0100
committerRichard Jones <rjones@trick.home.annexia.org>2009-09-21 12:01:51 +0100
commit8869adf1e811d894088dbb0f371edc23299005c8 (patch)
tree6c0229f90c81f03f6e989cdd57e20b114a437d41 /src
parent62b322872543c2ec069ac4fb0103ab758f587cef (diff)
downloadlibguestfs-8869adf1e811d894088dbb0f371edc23299005c8.tar.gz
libguestfs-8869adf1e811d894088dbb0f371edc23299005c8.tar.xz
libguestfs-8869adf1e811d894088dbb0f371edc23299005c8.zip
Remove guestfs_wait_ready (turn it into a no-op).
This commit changes guestfs_launch so that it both launches the appliance and waits until it is ready (ie. the daemon communicates back to us). Since we removed the pretence that we could implement a low-level asynchronous API, the need to call launch() followed by wait_ready() has looked a bit silly. Now guestfs_wait_ready() is basically a no-op. It is left in the API for backwards compatibility. Any calls to guestfs_wait_ready() can be removed from client code.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/generator.ml28
-rw-r--r--src/guestfs.c62
2 files changed, 41 insertions, 49 deletions
diff --git a/src/generator.ml b/src/generator.ml
index 179665bc..e5e2681f 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -440,13 +440,18 @@ You should call this after configuring the handle
("wait_ready", (RErr, []), -1, [NotInFish],
[],
- "wait until the qemu subprocess launches",
+ "wait until the qemu subprocess launches (no op)",
"\
-Internally libguestfs is implemented by running a virtual machine
-using L<qemu(1)>.
+This function is a no op.
-You should call this after C<guestfs_launch> to wait for the launch
-to complete.");
+In versions of the API E<lt> 1.0.71 you had to call this function
+just after calling C<guestfs_launch> to wait for the launch
+to complete. However this is no longer necessary because
+C<guestfs_launch> now does the waiting.
+
+If you see any calls to this function in code then you can just
+remove them, unless you want to retain compatibility with older
+versions of the API.");
("kill_subprocess", (RErr, []), -1, [],
[],
@@ -4625,12 +4630,9 @@ static int
check_state (guestfs_h *g, const char *caller)
{
if (!guestfs__is_ready (g)) {
- if (guestfs__is_config (g))
+ if (guestfs__is_config (g) || guestfs__is_launching (g))
error (g, \"%%s: call launch before using this function\\n(in guestfish, don't forget to use the 'run' command)\",
caller);
- else if (guestfs__is_launching (g))
- error (g, \"%%s: call wait_ready() before using this function\",
- caller);
else
error (g, \"%%s called from the wrong state, %%d != READY\",
caller, guestfs__get_state (g));
@@ -5522,11 +5524,6 @@ int main (int argc, char *argv[])
/* Set a timeout in case qemu hangs during launch (RHBZ#505329). */
alarm (600);
- if (guestfs_wait_ready (g) == -1) {
- printf (\"guestfs_wait_ready FAILED\\n\");
- exit (1);
- }
-
/* Cancel previous alarm. */
alarm (0);
@@ -7390,7 +7387,6 @@ Sys::Guestfs - Perl bindings for libguestfs
my $h = Sys::Guestfs->new ();
$h->add_drive ('guest.img');
$h->launch ();
- $h->wait_ready ();
$h->mount ('/dev/sda1', '/');
$h->touch ('/hello');
$h->sync ();
@@ -7928,7 +7924,6 @@ import guestfs
g = guestfs.GuestFS ()
g.add_drive (\"guest.img\")
g.launch ()
-g.wait_ready ()
parts = g.list_partitions ()
The guestfs module provides a Python binding to the libguestfs API
@@ -7963,7 +7958,6 @@ g.add_drive (\"guest.img\")
# Launch the qemu subprocess and wait for it to become ready:
g.launch ()
-g.wait_ready ()
# Now you can issue commands, for example:
logvols = g.lvs ()
diff --git a/src/guestfs.c b/src/guestfs.c
index 17d812ac..417d17fe 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -1208,6 +1208,32 @@ guestfs__launch (guestfs_h *g)
connected:
g->state = LAUNCHING;
+
+ /* Wait for qemu to start and to connect back to us via vmchannel and
+ * send the GUESTFS_LAUNCH_FLAG message.
+ */
+ uint32_t size;
+ void *buf = NULL;
+ r = recv_from_daemon (g, &size, &buf);
+ free (buf);
+
+ if (r == -1) return -1;
+
+ if (size != GUESTFS_LAUNCH_FLAG) {
+ error (g, _("guestfs_launch failed, see earlier error messages"));
+ goto cleanup2;
+ }
+
+ /* This is possible in some really strange situations, such as
+ * guestfsd starts up OK but then qemu immediately exits. Check for
+ * it because the caller is probably expecting to be able to send
+ * commands after this function returns.
+ */
+ if (g->state != READY) {
+ error (g, _("qemu launched and contacted daemon, but state != READY"));
+ goto cleanup2;
+ }
+
return 0;
cleanup2:
@@ -1381,45 +1407,17 @@ qemu_supports (guestfs_h *g, const char *option)
return g->qemu_help && strstr (g->qemu_help, option) != NULL;
}
+/* You had to call this function after launch in versions <= 1.0.70,
+ * but it is now a no-op.
+ */
int
guestfs__wait_ready (guestfs_h *g)
{
- int r;
- uint32_t size;
- void *buf = NULL;
-
- if (g->state == READY) return 0;
-
- if (g->state == BUSY) {
- error (g, _("qemu has finished launching already"));
- return -1;
- }
-
- if (g->state != LAUNCHING) {
+ if (g->state != READY) {
error (g, _("qemu has not been launched yet"));
return -1;
}
- r = recv_from_daemon (g, &size, &buf);
- free (buf);
-
- if (r == -1) return -1;
-
- if (size != GUESTFS_LAUNCH_FLAG) {
- error (g, _("guestfs_wait_ready failed, see earlier error messages"));
- return -1;
- }
-
- /* This is possible in some really strange situations, such as
- * guestfsd starts up OK but then qemu immediately exits. Check for
- * it because the caller is probably expecting to be able to send
- * commands after this function returns.
- */
- if (g->state != READY) {
- error (g, _("qemu launched and contacted daemon, but state != READY"));
- return -1;
- }
-
return 0;
}