Generated code for mknod, mkfifo, mknod_b, mknod_c, umask.
[libguestfs.git] / src / guestfs-actions.c
index 70d5cce..a46b339 100644 (file)
@@ -86,8 +86,7 @@ check_state (guestfs_h *g, const char *caller)
 struct mount_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -99,6 +98,13 @@ static void mount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct mount_ctx *ctx = (struct mount_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mount");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -113,7 +119,7 @@ static void mount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_mount (guestfs_h *g,
@@ -135,42 +141,41 @@ int guestfs_mount (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT,
         (xdrproc_t) xdr_guestfs_mount_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, mount_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_mount");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct sync_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -182,6 +187,13 @@ static void sync_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct sync_ctx *ctx = (struct sync_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_sync");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -196,7 +208,7 @@ static void sync_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_sync (guestfs_h *g)
@@ -212,42 +224,41 @@ int guestfs_sync (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_SYNC, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, sync_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_sync");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SYNC, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct touch_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -259,6 +270,13 @@ static void touch_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct touch_ctx *ctx = (struct touch_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_touch");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -273,7 +291,7 @@ static void touch_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_touch (guestfs_h *g,
@@ -293,42 +311,41 @@ int guestfs_touch (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_TOUCH,
         (xdrproc_t) xdr_guestfs_touch_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, touch_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_touch");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TOUCH, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct cat_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -341,6 +358,13 @@ static void cat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct cat_ctx *ctx = (struct cat_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_cat");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -359,7 +383,7 @@ static void cat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char *guestfs_cat (guestfs_h *g,
@@ -379,42 +403,41 @@ char *guestfs_cat (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_CAT,
         (xdrproc_t) xdr_guestfs_cat_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, cat_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_cat");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CAT, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.content; /* caller will free */
 }
 
 struct ll_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -427,6 +450,13 @@ static void ll_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct ll_ctx *ctx = (struct ll_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_ll");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -445,7 +475,7 @@ static void ll_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char *guestfs_ll (guestfs_h *g,
@@ -465,42 +495,41 @@ char *guestfs_ll (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_LL,
         (xdrproc_t) xdr_guestfs_ll_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, ll_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_ll");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LL, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.listing; /* caller will free */
 }
 
 struct ls_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -513,6 +542,13 @@ static void ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct ls_ctx *ctx = (struct ls_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_ls");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -531,7 +567,7 @@ static void ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_ls (guestfs_h *g,
@@ -551,34 +587,34 @@ char **guestfs_ls (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_LS,
         (xdrproc_t) xdr_guestfs_ls_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, ls_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_ls");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.listing.listing_val =
     safe_realloc (g, ctx.ret.listing.listing_val,
@@ -590,8 +626,7 @@ char **guestfs_ls (guestfs_h *g,
 struct list_devices_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -604,6 +639,13 @@ static void list_devices_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct list_devices_ctx *ctx = (struct list_devices_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_list_devices");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -622,7 +664,7 @@ static void list_devices_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_list_devices (guestfs_h *g)
@@ -638,34 +680,34 @@ char **guestfs_list_devices (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_LIST_DEVICES, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, list_devices_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_list_devices");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_DEVICES, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.devices.devices_val =
     safe_realloc (g, ctx.ret.devices.devices_val,
@@ -677,8 +719,7 @@ char **guestfs_list_devices (guestfs_h *g)
 struct list_partitions_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -691,6 +732,13 @@ static void list_partitions_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct list_partitions_ctx *ctx = (struct list_partitions_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_list_partitions");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -709,7 +757,7 @@ static void list_partitions_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_list_partitions (guestfs_h *g)
@@ -725,34 +773,34 @@ char **guestfs_list_partitions (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_LIST_PARTITIONS, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, list_partitions_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_list_partitions");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_PARTITIONS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.partitions.partitions_val =
     safe_realloc (g, ctx.ret.partitions.partitions_val,
@@ -764,8 +812,7 @@ char **guestfs_list_partitions (guestfs_h *g)
 struct pvs_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -778,6 +825,13 @@ static void pvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct pvs_ctx *ctx = (struct pvs_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_pvs");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -796,7 +850,7 @@ static void pvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_pvs (guestfs_h *g)
@@ -812,34 +866,34 @@ char **guestfs_pvs (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_PVS, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, pvs_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_pvs");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.physvols.physvols_val =
     safe_realloc (g, ctx.ret.physvols.physvols_val,
@@ -851,8 +905,7 @@ char **guestfs_pvs (guestfs_h *g)
 struct vgs_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -865,6 +918,13 @@ static void vgs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct vgs_ctx *ctx = (struct vgs_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_vgs");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -883,7 +943,7 @@ static void vgs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_vgs (guestfs_h *g)
@@ -899,34 +959,34 @@ char **guestfs_vgs (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_VGS, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, vgs_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_vgs");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.volgroups.volgroups_val =
     safe_realloc (g, ctx.ret.volgroups.volgroups_val,
@@ -938,8 +998,7 @@ char **guestfs_vgs (guestfs_h *g)
 struct lvs_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -952,6 +1011,13 @@ static void lvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct lvs_ctx *ctx = (struct lvs_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_lvs");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -970,7 +1036,7 @@ static void lvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_lvs (guestfs_h *g)
@@ -986,34 +1052,34 @@ char **guestfs_lvs (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_LVS, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, lvs_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_lvs");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.logvols.logvols_val =
     safe_realloc (g, ctx.ret.logvols.logvols_val,
@@ -1025,8 +1091,7 @@ char **guestfs_lvs (guestfs_h *g)
 struct pvs_full_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1039,6 +1104,13 @@ static void pvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct pvs_full_ctx *ctx = (struct pvs_full_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_pvs_full");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1057,7 +1129,7 @@ static void pvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *g)
@@ -1073,34 +1145,34 @@ struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_PVS_FULL, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, pvs_full_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_pvs_full");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS_FULL, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this */
   return safe_memdup (g, &ctx.ret.physvols, sizeof (ctx.ret.physvols));
 }
@@ -1108,8 +1180,7 @@ struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *g)
 struct vgs_full_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1122,6 +1193,13 @@ static void vgs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct vgs_full_ctx *ctx = (struct vgs_full_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_vgs_full");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1140,7 +1218,7 @@ static void vgs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *g)
@@ -1156,34 +1234,34 @@ struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_VGS_FULL, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, vgs_full_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_vgs_full");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS_FULL, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this */
   return safe_memdup (g, &ctx.ret.volgroups, sizeof (ctx.ret.volgroups));
 }
@@ -1191,8 +1269,7 @@ struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *g)
 struct lvs_full_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1205,6 +1282,13 @@ static void lvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct lvs_full_ctx *ctx = (struct lvs_full_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_lvs_full");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1223,7 +1307,7 @@ static void lvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *g)
@@ -1239,34 +1323,34 @@ struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_LVS_FULL, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, lvs_full_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_lvs_full");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS_FULL, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this */
   return safe_memdup (g, &ctx.ret.logvols, sizeof (ctx.ret.logvols));
 }
@@ -1274,8 +1358,7 @@ struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *g)
 struct read_lines_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1288,6 +1371,13 @@ static void read_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct read_lines_ctx *ctx = (struct read_lines_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_read_lines");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1306,7 +1396,7 @@ static void read_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_read_lines (guestfs_h *g,
@@ -1326,34 +1416,34 @@ char **guestfs_read_lines (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_READ_LINES,
         (xdrproc_t) xdr_guestfs_read_lines_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, read_lines_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_read_lines");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_READ_LINES, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.lines.lines_val =
     safe_realloc (g, ctx.ret.lines.lines_val,
@@ -1365,8 +1455,7 @@ char **guestfs_read_lines (guestfs_h *g,
 struct aug_init_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1378,6 +1467,13 @@ static void aug_init_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_init_ctx *ctx = (struct aug_init_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_init");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1392,7 +1488,7 @@ static void aug_init_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_aug_init (guestfs_h *g,
@@ -1414,42 +1510,41 @@ int guestfs_aug_init (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_INIT,
         (xdrproc_t) xdr_guestfs_aug_init_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_init_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_init");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INIT, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct aug_close_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1461,6 +1556,13 @@ static void aug_close_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_close_ctx *ctx = (struct aug_close_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_close");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1475,7 +1577,7 @@ static void aug_close_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_aug_close (guestfs_h *g)
@@ -1491,42 +1593,41 @@ int guestfs_aug_close (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_CLOSE, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_close_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_close");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_CLOSE, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct aug_defvar_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1539,6 +1640,13 @@ static void aug_defvar_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_defvar_ctx *ctx = (struct aug_defvar_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_defvar");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1557,7 +1665,7 @@ static void aug_defvar_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_aug_defvar (guestfs_h *g,
@@ -1579,42 +1687,41 @@ int guestfs_aug_defvar (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_DEFVAR,
         (xdrproc_t) xdr_guestfs_aug_defvar_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_defvar_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defvar");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFVAR, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.nrnodes;
 }
 
 struct aug_defnode_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1627,6 +1734,13 @@ static void aug_defnode_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_defnode_ctx *ctx = (struct aug_defnode_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_defnode");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1645,7 +1759,7 @@ static void aug_defnode_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *g,
@@ -1669,34 +1783,34 @@ struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_DEFNODE,
         (xdrproc_t) xdr_guestfs_aug_defnode_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_defnode_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defnode");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFNODE, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller with free this */
   return safe_memdup (g, &ctx.ret, sizeof (ctx.ret));
 }
@@ -1704,8 +1818,7 @@ struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *g,
 struct aug_get_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1718,6 +1831,13 @@ static void aug_get_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_get_ctx *ctx = (struct aug_get_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_get");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1736,7 +1856,7 @@ static void aug_get_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char *guestfs_aug_get (guestfs_h *g,
@@ -1756,42 +1876,41 @@ char *guestfs_aug_get (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_GET,
         (xdrproc_t) xdr_guestfs_aug_get_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_get_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_get");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_GET, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.val; /* caller will free */
 }
 
 struct aug_set_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1803,6 +1922,13 @@ static void aug_set_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_set_ctx *ctx = (struct aug_set_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_set");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1817,7 +1943,7 @@ static void aug_set_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_aug_set (guestfs_h *g,
@@ -1839,42 +1965,41 @@ int guestfs_aug_set (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_SET,
         (xdrproc_t) xdr_guestfs_aug_set_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_set_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_set");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SET, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct aug_insert_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1886,6 +2011,13 @@ static void aug_insert_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_insert_ctx *ctx = (struct aug_insert_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_insert");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1900,7 +2032,7 @@ static void aug_insert_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_aug_insert (guestfs_h *g,
@@ -1924,42 +2056,41 @@ int guestfs_aug_insert (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_INSERT,
         (xdrproc_t) xdr_guestfs_aug_insert_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_insert_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_insert");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INSERT, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct aug_rm_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -1972,6 +2103,13 @@ static void aug_rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_rm_ctx *ctx = (struct aug_rm_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_rm");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -1990,7 +2128,7 @@ static void aug_rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_aug_rm (guestfs_h *g,
@@ -2010,42 +2148,41 @@ int guestfs_aug_rm (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_RM,
         (xdrproc_t) xdr_guestfs_aug_rm_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_rm_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_rm");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_RM, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.nrnodes;
 }
 
 struct aug_mv_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2057,6 +2194,13 @@ static void aug_mv_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_mv_ctx *ctx = (struct aug_mv_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_mv");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2071,7 +2215,7 @@ static void aug_mv_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_aug_mv (guestfs_h *g,
@@ -2093,42 +2237,41 @@ int guestfs_aug_mv (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_MV,
         (xdrproc_t) xdr_guestfs_aug_mv_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_mv_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_mv");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MV, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct aug_match_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2141,6 +2284,13 @@ static void aug_match_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_match_ctx *ctx = (struct aug_match_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_match");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2159,7 +2309,7 @@ static void aug_match_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_aug_match (guestfs_h *g,
@@ -2179,34 +2329,34 @@ char **guestfs_aug_match (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_MATCH,
         (xdrproc_t) xdr_guestfs_aug_match_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_match_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_match");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MATCH, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.matches.matches_val =
     safe_realloc (g, ctx.ret.matches.matches_val,
@@ -2218,8 +2368,7 @@ char **guestfs_aug_match (guestfs_h *g,
 struct aug_save_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2231,6 +2380,13 @@ static void aug_save_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_save_ctx *ctx = (struct aug_save_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_save");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2245,7 +2401,7 @@ static void aug_save_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_aug_save (guestfs_h *g)
@@ -2261,42 +2417,41 @@ int guestfs_aug_save (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_SAVE, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_save_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_save");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SAVE, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct aug_load_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2308,6 +2463,13 @@ static void aug_load_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_load_ctx *ctx = (struct aug_load_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_load");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2322,7 +2484,7 @@ static void aug_load_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_aug_load (guestfs_h *g)
@@ -2338,42 +2500,41 @@ int guestfs_aug_load (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_LOAD, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_load_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_load");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LOAD, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct aug_ls_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2386,6 +2547,13 @@ static void aug_ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct aug_ls_ctx *ctx = (struct aug_ls_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_aug_ls");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2404,7 +2572,7 @@ static void aug_ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_aug_ls (guestfs_h *g,
@@ -2424,34 +2592,34 @@ char **guestfs_aug_ls (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_LS,
         (xdrproc_t) xdr_guestfs_aug_ls_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, aug_ls_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_aug_ls");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.matches.matches_val =
     safe_realloc (g, ctx.ret.matches.matches_val,
@@ -2463,8 +2631,7 @@ char **guestfs_aug_ls (guestfs_h *g,
 struct rm_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2476,6 +2643,13 @@ static void rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct rm_ctx *ctx = (struct rm_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_rm");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2490,7 +2664,7 @@ static void rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_rm (guestfs_h *g,
@@ -2510,42 +2684,41 @@ int guestfs_rm (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_RM,
         (xdrproc_t) xdr_guestfs_rm_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, rm_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_rm");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct rmdir_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2557,6 +2730,13 @@ static void rmdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct rmdir_ctx *ctx = (struct rmdir_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_rmdir");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2571,7 +2751,7 @@ static void rmdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_rmdir (guestfs_h *g,
@@ -2591,42 +2771,41 @@ int guestfs_rmdir (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_RMDIR,
         (xdrproc_t) xdr_guestfs_rmdir_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, rmdir_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_rmdir");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RMDIR, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct rm_rf_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2638,6 +2817,13 @@ static void rm_rf_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct rm_rf_ctx *ctx = (struct rm_rf_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_rm_rf");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2652,7 +2838,7 @@ static void rm_rf_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_rm_rf (guestfs_h *g,
@@ -2672,42 +2858,41 @@ int guestfs_rm_rf (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_RM_RF,
         (xdrproc_t) xdr_guestfs_rm_rf_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, rm_rf_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_rm_rf");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM_RF, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct mkdir_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2719,6 +2904,13 @@ static void mkdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct mkdir_ctx *ctx = (struct mkdir_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mkdir");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2733,7 +2925,7 @@ static void mkdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_mkdir (guestfs_h *g,
@@ -2753,42 +2945,41 @@ int guestfs_mkdir (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_MKDIR,
         (xdrproc_t) xdr_guestfs_mkdir_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, mkdir_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct mkdir_p_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2800,6 +2991,13 @@ static void mkdir_p_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct mkdir_p_ctx *ctx = (struct mkdir_p_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mkdir_p");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2814,7 +3012,7 @@ static void mkdir_p_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_mkdir_p (guestfs_h *g,
@@ -2834,42 +3032,41 @@ int guestfs_mkdir_p (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_MKDIR_P,
         (xdrproc_t) xdr_guestfs_mkdir_p_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, mkdir_p_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir_p");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR_P, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct chmod_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2881,6 +3078,13 @@ static void chmod_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct chmod_ctx *ctx = (struct chmod_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_chmod");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2895,7 +3099,7 @@ static void chmod_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_chmod (guestfs_h *g,
@@ -2917,42 +3121,41 @@ int guestfs_chmod (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_CHMOD,
         (xdrproc_t) xdr_guestfs_chmod_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, chmod_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_chmod");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHMOD, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct chown_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -2964,6 +3167,13 @@ static void chown_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct chown_ctx *ctx = (struct chown_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_chown");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -2978,7 +3188,7 @@ static void chown_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_chown (guestfs_h *g,
@@ -3002,42 +3212,41 @@ int guestfs_chown (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_CHOWN,
         (xdrproc_t) xdr_guestfs_chown_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, chown_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_chown");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHOWN, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct exists_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3050,6 +3259,13 @@ static void exists_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct exists_ctx *ctx = (struct exists_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_exists");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3068,7 +3284,7 @@ static void exists_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_exists (guestfs_h *g,
@@ -3088,42 +3304,41 @@ int guestfs_exists (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_EXISTS,
         (xdrproc_t) xdr_guestfs_exists_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, exists_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_exists");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_EXISTS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.existsflag;
 }
 
 struct is_file_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3136,6 +3351,13 @@ static void is_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct is_file_ctx *ctx = (struct is_file_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_is_file");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3154,7 +3376,7 @@ static void is_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_is_file (guestfs_h *g,
@@ -3174,42 +3396,41 @@ int guestfs_is_file (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_IS_FILE,
         (xdrproc_t) xdr_guestfs_is_file_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, is_file_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_is_file");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_FILE, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.fileflag;
 }
 
 struct is_dir_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3222,6 +3443,13 @@ static void is_dir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct is_dir_ctx *ctx = (struct is_dir_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_is_dir");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3240,7 +3468,7 @@ static void is_dir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_is_dir (guestfs_h *g,
@@ -3260,42 +3488,41 @@ int guestfs_is_dir (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_IS_DIR,
         (xdrproc_t) xdr_guestfs_is_dir_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, is_dir_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_is_dir");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_DIR, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.dirflag;
 }
 
 struct pvcreate_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3307,6 +3534,13 @@ static void pvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct pvcreate_ctx *ctx = (struct pvcreate_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_pvcreate");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3321,7 +3555,7 @@ static void pvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_pvcreate (guestfs_h *g,
@@ -3341,42 +3575,41 @@ int guestfs_pvcreate (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_PVCREATE,
         (xdrproc_t) xdr_guestfs_pvcreate_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, pvcreate_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_pvcreate");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVCREATE, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct vgcreate_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3388,6 +3621,13 @@ static void vgcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct vgcreate_ctx *ctx = (struct vgcreate_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_vgcreate");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3402,7 +3642,7 @@ static void vgcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_vgcreate (guestfs_h *g,
@@ -3425,42 +3665,41 @@ int guestfs_vgcreate (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_VGCREATE,
         (xdrproc_t) xdr_guestfs_vgcreate_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, vgcreate_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_vgcreate");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGCREATE, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct lvcreate_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3472,6 +3711,13 @@ static void lvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct lvcreate_ctx *ctx = (struct lvcreate_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_lvcreate");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3486,7 +3732,7 @@ static void lvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_lvcreate (guestfs_h *g,
@@ -3510,42 +3756,41 @@ int guestfs_lvcreate (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_LVCREATE,
         (xdrproc_t) xdr_guestfs_lvcreate_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, lvcreate_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_lvcreate");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVCREATE, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct mkfs_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3557,6 +3802,13 @@ static void mkfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct mkfs_ctx *ctx = (struct mkfs_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mkfs");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3571,7 +3823,7 @@ static void mkfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_mkfs (guestfs_h *g,
@@ -3593,42 +3845,41 @@ int guestfs_mkfs (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_MKFS,
         (xdrproc_t) xdr_guestfs_mkfs_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, mkfs_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_mkfs");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKFS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct sfdisk_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3640,6 +3891,13 @@ static void sfdisk_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct sfdisk_ctx *ctx = (struct sfdisk_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3654,7 +3912,7 @@ static void sfdisk_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_sfdisk (guestfs_h *g,
@@ -3683,42 +3941,41 @@ int guestfs_sfdisk (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK,
         (xdrproc_t) xdr_guestfs_sfdisk_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, sfdisk_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct write_file_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3730,6 +3987,13 @@ static void write_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct write_file_ctx *ctx = (struct write_file_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_write_file");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3744,7 +4008,7 @@ static void write_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_write_file (guestfs_h *g,
@@ -3768,42 +4032,41 @@ int guestfs_write_file (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_WRITE_FILE,
         (xdrproc_t) xdr_guestfs_write_file_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, write_file_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_write_file");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_WRITE_FILE, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct umount_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3815,6 +4078,13 @@ static void umount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct umount_ctx *ctx = (struct umount_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_umount");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3829,7 +4099,7 @@ static void umount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_umount (guestfs_h *g,
@@ -3849,42 +4119,41 @@ int guestfs_umount (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_UMOUNT,
         (xdrproc_t) xdr_guestfs_umount_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, umount_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_umount");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct mounts_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3897,6 +4166,13 @@ static void mounts_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct mounts_ctx *ctx = (struct mounts_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mounts");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3915,7 +4191,7 @@ static void mounts_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_mounts (guestfs_h *g)
@@ -3931,34 +4207,34 @@ char **guestfs_mounts (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNTS, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, mounts_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_mounts");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNTS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.devices.devices_val =
     safe_realloc (g, ctx.ret.devices.devices_val,
@@ -3970,8 +4246,7 @@ char **guestfs_mounts (guestfs_h *g)
 struct umount_all_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -3983,6 +4258,13 @@ static void umount_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct umount_all_ctx *ctx = (struct umount_all_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_umount_all");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -3997,7 +4279,7 @@ static void umount_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_umount_all (guestfs_h *g)
@@ -4013,42 +4295,41 @@ int guestfs_umount_all (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_UMOUNT_ALL, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, umount_all_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_umount_all");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT_ALL, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct lvm_remove_all_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4060,6 +4341,13 @@ static void lvm_remove_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct lvm_remove_all_ctx *ctx = (struct lvm_remove_all_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_lvm_remove_all");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4074,7 +4362,7 @@ static void lvm_remove_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_lvm_remove_all (guestfs_h *g)
@@ -4090,42 +4378,41 @@ int guestfs_lvm_remove_all (guestfs_h *g)
 
   serial = guestfs__send_sync (g, GUESTFS_PROC_LVM_REMOVE_ALL, NULL, NULL);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, lvm_remove_all_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_lvm_remove_all");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVM_REMOVE_ALL, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct file_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4138,6 +4425,13 @@ static void file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct file_ctx *ctx = (struct file_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_file");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4156,7 +4450,7 @@ static void file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char *guestfs_file (guestfs_h *g,
@@ -4176,42 +4470,41 @@ char *guestfs_file (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_FILE,
         (xdrproc_t) xdr_guestfs_file_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, file_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_file");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FILE, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.description; /* caller will free */
 }
 
 struct command_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4224,6 +4517,13 @@ static void command_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct command_ctx *ctx = (struct command_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_command");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4242,7 +4542,7 @@ static void command_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char *guestfs_command (guestfs_h *g,
@@ -4263,42 +4563,41 @@ char *guestfs_command (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_COMMAND,
         (xdrproc_t) xdr_guestfs_command_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, command_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_command");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.output; /* caller will free */
 }
 
 struct command_lines_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4311,6 +4610,13 @@ static void command_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct command_lines_ctx *ctx = (struct command_lines_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_command_lines");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4329,7 +4635,7 @@ static void command_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_command_lines (guestfs_h *g,
@@ -4350,34 +4656,34 @@ char **guestfs_command_lines (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_COMMAND_LINES,
         (xdrproc_t) xdr_guestfs_command_lines_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, command_lines_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_command_lines");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND_LINES, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.lines.lines_val =
     safe_realloc (g, ctx.ret.lines.lines_val,
@@ -4389,8 +4695,7 @@ char **guestfs_command_lines (guestfs_h *g,
 struct stat_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4403,6 +4708,13 @@ static void stat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct stat_ctx *ctx = (struct stat_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_stat");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4421,7 +4733,7 @@ static void stat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 struct guestfs_stat *guestfs_stat (guestfs_h *g,
@@ -4441,34 +4753,34 @@ struct guestfs_stat *guestfs_stat (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_STAT,
         (xdrproc_t) xdr_guestfs_stat_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, stat_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_stat");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STAT, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this */
   return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
 }
@@ -4476,8 +4788,7 @@ struct guestfs_stat *guestfs_stat (guestfs_h *g,
 struct lstat_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4490,6 +4801,13 @@ static void lstat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct lstat_ctx *ctx = (struct lstat_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_lstat");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4508,7 +4826,7 @@ static void lstat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 struct guestfs_stat *guestfs_lstat (guestfs_h *g,
@@ -4528,34 +4846,34 @@ struct guestfs_stat *guestfs_lstat (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_LSTAT,
         (xdrproc_t) xdr_guestfs_lstat_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, lstat_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_lstat");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LSTAT, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this */
   return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
 }
@@ -4563,8 +4881,7 @@ struct guestfs_stat *guestfs_lstat (guestfs_h *g,
 struct statvfs_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4577,6 +4894,13 @@ static void statvfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct statvfs_ctx *ctx = (struct statvfs_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_statvfs");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4595,7 +4919,7 @@ static void statvfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 struct guestfs_statvfs *guestfs_statvfs (guestfs_h *g,
@@ -4615,34 +4939,34 @@ struct guestfs_statvfs *guestfs_statvfs (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_STATVFS,
         (xdrproc_t) xdr_guestfs_statvfs_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, statvfs_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_statvfs");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STATVFS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this */
   return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
 }
@@ -4650,8 +4974,7 @@ struct guestfs_statvfs *guestfs_statvfs (guestfs_h *g,
 struct tune2fs_l_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4664,6 +4987,13 @@ static void tune2fs_l_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct tune2fs_l_ctx *ctx = (struct tune2fs_l_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_tune2fs_l");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4682,7 +5012,7 @@ static void tune2fs_l_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char **guestfs_tune2fs_l (guestfs_h *g,
@@ -4702,34 +5032,34 @@ char **guestfs_tune2fs_l (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_TUNE2FS_L,
         (xdrproc_t) xdr_guestfs_tune2fs_l_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, tune2fs_l_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_tune2fs_l");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TUNE2FS_L, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   /* caller will free this, but we need to add a NULL entry */
   ctx.ret.superblock.superblock_val =
     safe_realloc (g, ctx.ret.superblock.superblock_val,
@@ -4741,8 +5071,7 @@ char **guestfs_tune2fs_l (guestfs_h *g,
 struct blockdev_setro_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4754,6 +5083,13 @@ static void blockdev_setro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_setro_ctx *ctx = (struct blockdev_setro_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_setro");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4768,7 +5104,7 @@ static void blockdev_setro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_blockdev_setro (guestfs_h *g,
@@ -4788,42 +5124,41 @@ int guestfs_blockdev_setro (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_SETRO,
         (xdrproc_t) xdr_guestfs_blockdev_setro_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_setro_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setro");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRO, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct blockdev_setrw_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4835,6 +5170,13 @@ static void blockdev_setrw_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_setrw_ctx *ctx = (struct blockdev_setrw_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_setrw");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4849,7 +5191,7 @@ static void blockdev_setrw_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_blockdev_setrw (guestfs_h *g,
@@ -4869,42 +5211,41 @@ int guestfs_blockdev_setrw (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_SETRW,
         (xdrproc_t) xdr_guestfs_blockdev_setrw_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_setrw_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setrw");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRW, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct blockdev_getro_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -4917,6 +5258,13 @@ static void blockdev_getro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_getro_ctx *ctx = (struct blockdev_getro_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getro");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -4935,7 +5283,7 @@ static void blockdev_getro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_blockdev_getro (guestfs_h *g,
@@ -4955,42 +5303,41 @@ int guestfs_blockdev_getro (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETRO,
         (xdrproc_t) xdr_guestfs_blockdev_getro_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_getro_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getro");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETRO, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.ro;
 }
 
 struct blockdev_getss_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5003,6 +5350,13 @@ static void blockdev_getss_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_getss_ctx *ctx = (struct blockdev_getss_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getss");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5021,7 +5375,7 @@ static void blockdev_getss_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_blockdev_getss (guestfs_h *g,
@@ -5041,42 +5395,41 @@ int guestfs_blockdev_getss (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETSS,
         (xdrproc_t) xdr_guestfs_blockdev_getss_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_getss_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getss");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.sectorsize;
 }
 
 struct blockdev_getbsz_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5089,6 +5442,13 @@ static void blockdev_getbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_getbsz_ctx *ctx = (struct blockdev_getbsz_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getbsz");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5107,7 +5467,7 @@ static void blockdev_getbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_blockdev_getbsz (guestfs_h *g,
@@ -5127,42 +5487,41 @@ int guestfs_blockdev_getbsz (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETBSZ,
         (xdrproc_t) xdr_guestfs_blockdev_getbsz_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_getbsz_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getbsz");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETBSZ, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.blocksize;
 }
 
 struct blockdev_setbsz_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5174,6 +5533,13 @@ static void blockdev_setbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_setbsz_ctx *ctx = (struct blockdev_setbsz_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_setbsz");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5188,7 +5554,7 @@ static void blockdev_setbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_blockdev_setbsz (guestfs_h *g,
@@ -5210,42 +5576,41 @@ int guestfs_blockdev_setbsz (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_SETBSZ,
         (xdrproc_t) xdr_guestfs_blockdev_setbsz_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_setbsz_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setbsz");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETBSZ, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct blockdev_getsz_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5258,6 +5623,13 @@ static void blockdev_getsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_getsz_ctx *ctx = (struct blockdev_getsz_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getsz");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5276,7 +5648,7 @@ static void blockdev_getsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int64_t guestfs_blockdev_getsz (guestfs_h *g,
@@ -5296,42 +5668,41 @@ int64_t guestfs_blockdev_getsz (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETSZ,
         (xdrproc_t) xdr_guestfs_blockdev_getsz_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_getsz_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsz");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSZ, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.sizeinsectors;
 }
 
 struct blockdev_getsize64_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5344,6 +5715,13 @@ static void blockdev_getsize64_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_getsize64_ctx *ctx = (struct blockdev_getsize64_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getsize64");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5362,7 +5740,7 @@ static void blockdev_getsize64_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int64_t guestfs_blockdev_getsize64 (guestfs_h *g,
@@ -5382,42 +5760,41 @@ int64_t guestfs_blockdev_getsize64 (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETSIZE64,
         (xdrproc_t) xdr_guestfs_blockdev_getsize64_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_getsize64_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsize64");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSIZE64, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.sizeinbytes;
 }
 
 struct blockdev_flushbufs_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5429,6 +5806,13 @@ static void blockdev_flushbufs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_flushbufs_ctx *ctx = (struct blockdev_flushbufs_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_flushbufs");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5443,7 +5827,7 @@ static void blockdev_flushbufs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_blockdev_flushbufs (guestfs_h *g,
@@ -5463,42 +5847,41 @@ int guestfs_blockdev_flushbufs (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS,
         (xdrproc_t) xdr_guestfs_blockdev_flushbufs_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_flushbufs_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_flushbufs");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct blockdev_rereadpt_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5510,6 +5893,13 @@ static void blockdev_rereadpt_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct blockdev_rereadpt_ctx *ctx = (struct blockdev_rereadpt_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_rereadpt");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5524,7 +5914,7 @@ static void blockdev_rereadpt_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_blockdev_rereadpt (guestfs_h *g,
@@ -5544,42 +5934,41 @@ int guestfs_blockdev_rereadpt (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_REREADPT,
         (xdrproc_t) xdr_guestfs_blockdev_rereadpt_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, blockdev_rereadpt_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_rereadpt");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_REREADPT, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct upload_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5591,6 +5980,13 @@ static void upload_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct upload_ctx *ctx = (struct upload_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_upload");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5605,7 +6001,7 @@ static void upload_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_upload (guestfs_h *g,
@@ -5626,7 +6022,7 @@ int guestfs_upload (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_UPLOAD,
         (xdrproc_t) xdr_guestfs_upload_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
@@ -5635,7 +6031,7 @@ int guestfs_upload (guestfs_h *g,
 
     r = guestfs__send_file_sync (g, filename);
     if (r == -1) {
-      guestfs_set_ready (g);
+      guestfs_end_busy (g);
       return -1;
     }
     if (r == -2) /* daemon cancelled */
@@ -5648,32 +6044,32 @@ int guestfs_upload (guestfs_h *g,
   guestfs_set_reply_callback (g, upload_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_upload");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UPLOAD, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct download_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5685,6 +6081,13 @@ static void download_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct download_ctx *ctx = (struct download_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_download");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5699,7 +6102,7 @@ static void download_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     goto done;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 int guestfs_download (guestfs_h *g,
@@ -5720,47 +6123,46 @@ int guestfs_download (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_DOWNLOAD,
         (xdrproc_t) xdr_guestfs_download_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, download_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_download");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DOWNLOAD, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return -1;
   }
 
   if (guestfs__receive_file_sync (g, filename) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return -1;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return 0;
 }
 
 struct checksum_ctx {
   /* This flag is set by the callbacks, so we know we've done
    * the callbacks as expected, and in the right sequence.
-   * 0 = not called, 1 = send called,
-   * 1001 = reply called.
+   * 0 = not called, 1 = reply_cb called.
    */
   int cb_sequence;
   struct guestfs_message_header hdr;
@@ -5773,6 +6175,13 @@ static void checksum_reply_cb (guestfs_h *g, void *data, XDR *xdr)
   guestfs_main_loop *ml = guestfs_get_main_loop (g);
   struct checksum_ctx *ctx = (struct checksum_ctx *) data;
 
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_checksum");
+    return;
+  }
+
   ml->main_loop_quit (ml, g);
 
   if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
@@ -5791,7 +6200,7 @@ static void checksum_reply_cb (guestfs_h *g, void *data, XDR *xdr)
     return;
   }
  done:
-  ctx->cb_sequence = 1001;
+  ctx->cb_sequence = 1;
 }
 
 char *guestfs_checksum (guestfs_h *g,
@@ -5813,34 +6222,6341 @@ char *guestfs_checksum (guestfs_h *g,
   serial = guestfs__send_sync (g, GUESTFS_PROC_CHECKSUM,
         (xdrproc_t) xdr_guestfs_checksum_args, (char *) &args);
   if (serial == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
- read_reply:
   guestfs__switch_to_receiving (g);
   ctx.cb_sequence = 0;
   guestfs_set_reply_callback (g, checksum_reply_cb, &ctx);
   (void) ml->main_loop_run (ml, g);
   guestfs_set_reply_callback (g, NULL, NULL);
-  if (ctx.cb_sequence != 1001) {
+  if (ctx.cb_sequence != 1) {
     error (g, "%s reply failed, see earlier error messages", "guestfs_checksum");
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHECKSUM, serial) == -1) {
-    guestfs_set_ready (g);
+    guestfs_end_busy (g);
     return NULL;
   }
 
   if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
     error (g, "%s", ctx.err.error_message);
-    guestfs_set_ready (g);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
     return NULL;
   }
 
-  guestfs_set_ready (g);
+  guestfs_end_busy (g);
   return ctx.ret.checksum; /* caller will free */
 }
 
+struct tar_in_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void tar_in_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct tar_in_ctx *ctx = (struct tar_in_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_tar_in");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_tar_in");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_tar_in");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_tar_in (guestfs_h *g,
+               const char *tarfile,
+               const char *directory)
+{
+  struct guestfs_tar_in_args args;
+  struct tar_in_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_tar_in") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.directory = (char *) directory;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_TAR_IN,
+        (xdrproc_t) xdr_guestfs_tar_in_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  {
+    int r;
+
+    r = guestfs__send_file_sync (g, tarfile);
+    if (r == -1) {
+      guestfs_end_busy (g);
+      return -1;
+    }
+    if (r == -2) /* daemon cancelled */
+      goto read_reply;
+  }
+
+ read_reply:
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, tar_in_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_tar_in");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TAR_IN, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct tar_out_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void tar_out_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct tar_out_ctx *ctx = (struct tar_out_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_tar_out");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_tar_out");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_tar_out");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_tar_out (guestfs_h *g,
+               const char *directory,
+               const char *tarfile)
+{
+  struct guestfs_tar_out_args args;
+  struct tar_out_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_tar_out") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.directory = (char *) directory;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_TAR_OUT,
+        (xdrproc_t) xdr_guestfs_tar_out_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, tar_out_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_tar_out");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TAR_OUT, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (guestfs__receive_file_sync (g, tarfile) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct tgz_in_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void tgz_in_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct tgz_in_ctx *ctx = (struct tgz_in_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_tgz_in");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_tgz_in");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_tgz_in");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_tgz_in (guestfs_h *g,
+               const char *tarball,
+               const char *directory)
+{
+  struct guestfs_tgz_in_args args;
+  struct tgz_in_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_tgz_in") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.directory = (char *) directory;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_TGZ_IN,
+        (xdrproc_t) xdr_guestfs_tgz_in_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  {
+    int r;
+
+    r = guestfs__send_file_sync (g, tarball);
+    if (r == -1) {
+      guestfs_end_busy (g);
+      return -1;
+    }
+    if (r == -2) /* daemon cancelled */
+      goto read_reply;
+  }
+
+ read_reply:
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, tgz_in_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_tgz_in");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TGZ_IN, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct tgz_out_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void tgz_out_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct tgz_out_ctx *ctx = (struct tgz_out_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_tgz_out");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_tgz_out");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_tgz_out");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_tgz_out (guestfs_h *g,
+               const char *directory,
+               const char *tarball)
+{
+  struct guestfs_tgz_out_args args;
+  struct tgz_out_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_tgz_out") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.directory = (char *) directory;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_TGZ_OUT,
+        (xdrproc_t) xdr_guestfs_tgz_out_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, tgz_out_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_tgz_out");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TGZ_OUT, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (guestfs__receive_file_sync (g, tarball) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mount_ro_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mount_ro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mount_ro_ctx *ctx = (struct mount_ro_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mount_ro");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mount_ro");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mount_ro");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mount_ro (guestfs_h *g,
+               const char *device,
+               const char *mountpoint)
+{
+  struct guestfs_mount_ro_args args;
+  struct mount_ro_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mount_ro") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  args.mountpoint = (char *) mountpoint;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT_RO,
+        (xdrproc_t) xdr_guestfs_mount_ro_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mount_ro_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mount_ro");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_RO, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mount_options_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mount_options_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mount_options_ctx *ctx = (struct mount_options_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mount_options");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mount_options");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mount_options");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mount_options (guestfs_h *g,
+               const char *options,
+               const char *device,
+               const char *mountpoint)
+{
+  struct guestfs_mount_options_args args;
+  struct mount_options_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mount_options") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.options = (char *) options;
+  args.device = (char *) device;
+  args.mountpoint = (char *) mountpoint;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT_OPTIONS,
+        (xdrproc_t) xdr_guestfs_mount_options_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mount_options_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mount_options");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_OPTIONS, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mount_vfs_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mount_vfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mount_vfs_ctx *ctx = (struct mount_vfs_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mount_vfs");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mount_vfs");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mount_vfs");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mount_vfs (guestfs_h *g,
+               const char *options,
+               const char *vfstype,
+               const char *device,
+               const char *mountpoint)
+{
+  struct guestfs_mount_vfs_args args;
+  struct mount_vfs_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mount_vfs") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.options = (char *) options;
+  args.vfstype = (char *) vfstype;
+  args.device = (char *) device;
+  args.mountpoint = (char *) mountpoint;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT_VFS,
+        (xdrproc_t) xdr_guestfs_mount_vfs_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mount_vfs_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mount_vfs");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_VFS, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct debug_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_debug_ret ret;
+};
+
+static void debug_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct debug_ctx *ctx = (struct debug_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_debug");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_debug");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_debug");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_debug_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_debug");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_debug (guestfs_h *g,
+               const char *subcmd,
+               char * const* const extraargs)
+{
+  struct guestfs_debug_args args;
+  struct debug_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_debug") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.subcmd = (char *) subcmd;
+  args.extraargs.extraargs_val = (char **) extraargs;
+  for (args.extraargs.extraargs_len = 0; extraargs[args.extraargs.extraargs_len]; args.extraargs.extraargs_len++) ;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_DEBUG,
+        (xdrproc_t) xdr_guestfs_debug_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, debug_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_debug");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DEBUG, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.result; /* caller will free */
+}
+
+struct lvremove_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void lvremove_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct lvremove_ctx *ctx = (struct lvremove_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_lvremove");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_lvremove");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_lvremove");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_lvremove (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_lvremove_args args;
+  struct lvremove_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_lvremove") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_LVREMOVE,
+        (xdrproc_t) xdr_guestfs_lvremove_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, lvremove_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_lvremove");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVREMOVE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct vgremove_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void vgremove_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct vgremove_ctx *ctx = (struct vgremove_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_vgremove");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_vgremove");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_vgremove");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_vgremove (guestfs_h *g,
+               const char *vgname)
+{
+  struct guestfs_vgremove_args args;
+  struct vgremove_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_vgremove") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.vgname = (char *) vgname;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_VGREMOVE,
+        (xdrproc_t) xdr_guestfs_vgremove_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, vgremove_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_vgremove");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGREMOVE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct pvremove_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void pvremove_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct pvremove_ctx *ctx = (struct pvremove_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_pvremove");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_pvremove");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_pvremove");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_pvremove (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_pvremove_args args;
+  struct pvremove_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_pvremove") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_PVREMOVE,
+        (xdrproc_t) xdr_guestfs_pvremove_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, pvremove_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_pvremove");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVREMOVE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct set_e2label_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void set_e2label_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct set_e2label_ctx *ctx = (struct set_e2label_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_set_e2label");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_set_e2label");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_set_e2label");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_set_e2label (guestfs_h *g,
+               const char *device,
+               const char *label)
+{
+  struct guestfs_set_e2label_args args;
+  struct set_e2label_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_set_e2label") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  args.label = (char *) label;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SET_E2LABEL,
+        (xdrproc_t) xdr_guestfs_set_e2label_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, set_e2label_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_set_e2label");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SET_E2LABEL, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct get_e2label_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_get_e2label_ret ret;
+};
+
+static void get_e2label_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct get_e2label_ctx *ctx = (struct get_e2label_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_get_e2label");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_get_e2label");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_get_e2label");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_get_e2label_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_get_e2label");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_get_e2label (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_get_e2label_args args;
+  struct get_e2label_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_get_e2label") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_GET_E2LABEL,
+        (xdrproc_t) xdr_guestfs_get_e2label_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, get_e2label_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_get_e2label");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GET_E2LABEL, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.label; /* caller will free */
+}
+
+struct set_e2uuid_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void set_e2uuid_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct set_e2uuid_ctx *ctx = (struct set_e2uuid_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_set_e2uuid");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_set_e2uuid");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_set_e2uuid");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_set_e2uuid (guestfs_h *g,
+               const char *device,
+               const char *uuid)
+{
+  struct guestfs_set_e2uuid_args args;
+  struct set_e2uuid_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_set_e2uuid") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  args.uuid = (char *) uuid;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SET_E2UUID,
+        (xdrproc_t) xdr_guestfs_set_e2uuid_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, set_e2uuid_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_set_e2uuid");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SET_E2UUID, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct get_e2uuid_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_get_e2uuid_ret ret;
+};
+
+static void get_e2uuid_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct get_e2uuid_ctx *ctx = (struct get_e2uuid_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_get_e2uuid");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_get_e2uuid");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_get_e2uuid");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_get_e2uuid_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_get_e2uuid");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_get_e2uuid (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_get_e2uuid_args args;
+  struct get_e2uuid_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_get_e2uuid") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_GET_E2UUID,
+        (xdrproc_t) xdr_guestfs_get_e2uuid_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, get_e2uuid_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_get_e2uuid");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GET_E2UUID, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.uuid; /* caller will free */
+}
+
+struct fsck_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_fsck_ret ret;
+};
+
+static void fsck_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct fsck_ctx *ctx = (struct fsck_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_fsck");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_fsck");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_fsck");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_fsck_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_fsck");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_fsck (guestfs_h *g,
+               const char *fstype,
+               const char *device)
+{
+  struct guestfs_fsck_args args;
+  struct fsck_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_fsck") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.fstype = (char *) fstype;
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_FSCK,
+        (xdrproc_t) xdr_guestfs_fsck_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, fsck_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_fsck");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FSCK, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.status;
+}
+
+struct zero_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void zero_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct zero_ctx *ctx = (struct zero_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_zero");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_zero");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_zero");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_zero (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_zero_args args;
+  struct zero_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_zero") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_ZERO,
+        (xdrproc_t) xdr_guestfs_zero_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, zero_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_zero");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_ZERO, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct grub_install_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void grub_install_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct grub_install_ctx *ctx = (struct grub_install_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_grub_install");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_grub_install");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_grub_install");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_grub_install (guestfs_h *g,
+               const char *root,
+               const char *device)
+{
+  struct guestfs_grub_install_args args;
+  struct grub_install_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_grub_install") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.root = (char *) root;
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_GRUB_INSTALL,
+        (xdrproc_t) xdr_guestfs_grub_install_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, grub_install_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_grub_install");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GRUB_INSTALL, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct cp_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void cp_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct cp_ctx *ctx = (struct cp_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_cp");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_cp");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_cp");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_cp (guestfs_h *g,
+               const char *src,
+               const char *dest)
+{
+  struct guestfs_cp_args args;
+  struct cp_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_cp") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.src = (char *) src;
+  args.dest = (char *) dest;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_CP,
+        (xdrproc_t) xdr_guestfs_cp_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, cp_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_cp");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CP, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct cp_a_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void cp_a_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct cp_a_ctx *ctx = (struct cp_a_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_cp_a");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_cp_a");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_cp_a");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_cp_a (guestfs_h *g,
+               const char *src,
+               const char *dest)
+{
+  struct guestfs_cp_a_args args;
+  struct cp_a_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_cp_a") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.src = (char *) src;
+  args.dest = (char *) dest;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_CP_A,
+        (xdrproc_t) xdr_guestfs_cp_a_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, cp_a_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_cp_a");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CP_A, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mv_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mv_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mv_ctx *ctx = (struct mv_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mv");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mv");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mv");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mv (guestfs_h *g,
+               const char *src,
+               const char *dest)
+{
+  struct guestfs_mv_args args;
+  struct mv_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mv") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.src = (char *) src;
+  args.dest = (char *) dest;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MV,
+        (xdrproc_t) xdr_guestfs_mv_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mv_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mv");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MV, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct drop_caches_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void drop_caches_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct drop_caches_ctx *ctx = (struct drop_caches_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_drop_caches");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_drop_caches");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_drop_caches");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_drop_caches (guestfs_h *g,
+               int whattodrop)
+{
+  struct guestfs_drop_caches_args args;
+  struct drop_caches_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_drop_caches") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.whattodrop = whattodrop;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_DROP_CACHES,
+        (xdrproc_t) xdr_guestfs_drop_caches_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, drop_caches_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_drop_caches");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DROP_CACHES, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct dmesg_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_dmesg_ret ret;
+};
+
+static void dmesg_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct dmesg_ctx *ctx = (struct dmesg_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_dmesg");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_dmesg");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_dmesg");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_dmesg_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_dmesg");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_dmesg (guestfs_h *g)
+{
+  struct dmesg_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_dmesg") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  serial = guestfs__send_sync (g, GUESTFS_PROC_DMESG, NULL, NULL);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, dmesg_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_dmesg");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DMESG, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.kmsgs; /* caller will free */
+}
+
+struct ping_daemon_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void ping_daemon_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct ping_daemon_ctx *ctx = (struct ping_daemon_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_ping_daemon");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_ping_daemon");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_ping_daemon");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_ping_daemon (guestfs_h *g)
+{
+  struct ping_daemon_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_ping_daemon") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  serial = guestfs__send_sync (g, GUESTFS_PROC_PING_DAEMON, NULL, NULL);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, ping_daemon_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_ping_daemon");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PING_DAEMON, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct equal_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_equal_ret ret;
+};
+
+static void equal_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct equal_ctx *ctx = (struct equal_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_equal");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_equal");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_equal");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_equal_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_equal");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_equal (guestfs_h *g,
+               const char *file1,
+               const char *file2)
+{
+  struct guestfs_equal_args args;
+  struct equal_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_equal") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.file1 = (char *) file1;
+  args.file2 = (char *) file2;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_EQUAL,
+        (xdrproc_t) xdr_guestfs_equal_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, equal_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_equal");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_EQUAL, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.equality;
+}
+
+struct strings_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_strings_ret ret;
+};
+
+static void strings_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct strings_ctx *ctx = (struct strings_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_strings");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_strings");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_strings");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_strings_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_strings");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_strings (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_strings_args args;
+  struct strings_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_strings") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_STRINGS,
+        (xdrproc_t) xdr_guestfs_strings_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, strings_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_strings");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STRINGS, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.stringsout.stringsout_val =
+    safe_realloc (g, ctx.ret.stringsout.stringsout_val,
+                  sizeof (char *) * (ctx.ret.stringsout.stringsout_len + 1));
+  ctx.ret.stringsout.stringsout_val[ctx.ret.stringsout.stringsout_len] = NULL;
+  return ctx.ret.stringsout.stringsout_val;
+}
+
+struct strings_e_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_strings_e_ret ret;
+};
+
+static void strings_e_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct strings_e_ctx *ctx = (struct strings_e_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_strings_e");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_strings_e");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_strings_e");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_strings_e_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_strings_e");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_strings_e (guestfs_h *g,
+               const char *encoding,
+               const char *path)
+{
+  struct guestfs_strings_e_args args;
+  struct strings_e_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_strings_e") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.encoding = (char *) encoding;
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_STRINGS_E,
+        (xdrproc_t) xdr_guestfs_strings_e_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, strings_e_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_strings_e");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STRINGS_E, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.stringsout.stringsout_val =
+    safe_realloc (g, ctx.ret.stringsout.stringsout_val,
+                  sizeof (char *) * (ctx.ret.stringsout.stringsout_len + 1));
+  ctx.ret.stringsout.stringsout_val[ctx.ret.stringsout.stringsout_len] = NULL;
+  return ctx.ret.stringsout.stringsout_val;
+}
+
+struct hexdump_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_hexdump_ret ret;
+};
+
+static void hexdump_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct hexdump_ctx *ctx = (struct hexdump_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_hexdump");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_hexdump");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_hexdump");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_hexdump_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_hexdump");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_hexdump (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_hexdump_args args;
+  struct hexdump_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_hexdump") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_HEXDUMP,
+        (xdrproc_t) xdr_guestfs_hexdump_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, hexdump_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_hexdump");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_HEXDUMP, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.dump; /* caller will free */
+}
+
+struct zerofree_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void zerofree_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct zerofree_ctx *ctx = (struct zerofree_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_zerofree");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_zerofree");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_zerofree");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_zerofree (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_zerofree_args args;
+  struct zerofree_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_zerofree") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_ZEROFREE,
+        (xdrproc_t) xdr_guestfs_zerofree_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, zerofree_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_zerofree");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_ZEROFREE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct pvresize_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void pvresize_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct pvresize_ctx *ctx = (struct pvresize_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_pvresize");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_pvresize");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_pvresize");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_pvresize (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_pvresize_args args;
+  struct pvresize_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_pvresize") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_PVRESIZE,
+        (xdrproc_t) xdr_guestfs_pvresize_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, pvresize_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_pvresize");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVRESIZE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct sfdisk_N_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void sfdisk_N_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct sfdisk_N_ctx *ctx = (struct sfdisk_N_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk_N");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_sfdisk_N");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_sfdisk_N");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_sfdisk_N (guestfs_h *g,
+               const char *device,
+               int partnum,
+               int cyls,
+               int heads,
+               int sectors,
+               const char *line)
+{
+  struct guestfs_sfdisk_N_args args;
+  struct sfdisk_N_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_sfdisk_N") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  args.partnum = partnum;
+  args.cyls = cyls;
+  args.heads = heads;
+  args.sectors = sectors;
+  args.line = (char *) line;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK_N,
+        (xdrproc_t) xdr_guestfs_sfdisk_N_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, sfdisk_N_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk_N");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK_N, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct sfdisk_l_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_sfdisk_l_ret ret;
+};
+
+static void sfdisk_l_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct sfdisk_l_ctx *ctx = (struct sfdisk_l_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk_l");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_sfdisk_l");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_sfdisk_l");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_sfdisk_l_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_sfdisk_l");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_sfdisk_l (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_sfdisk_l_args args;
+  struct sfdisk_l_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_sfdisk_l") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK_L,
+        (xdrproc_t) xdr_guestfs_sfdisk_l_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, sfdisk_l_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk_l");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK_L, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.partitions; /* caller will free */
+}
+
+struct sfdisk_kernel_geometry_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_sfdisk_kernel_geometry_ret ret;
+};
+
+static void sfdisk_kernel_geometry_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct sfdisk_kernel_geometry_ctx *ctx = (struct sfdisk_kernel_geometry_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk_kernel_geometry");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_sfdisk_kernel_geometry");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_sfdisk_kernel_geometry");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_sfdisk_kernel_geometry_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_sfdisk_kernel_geometry");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_sfdisk_kernel_geometry (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_sfdisk_kernel_geometry_args args;
+  struct sfdisk_kernel_geometry_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_sfdisk_kernel_geometry") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK_KERNEL_GEOMETRY,
+        (xdrproc_t) xdr_guestfs_sfdisk_kernel_geometry_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, sfdisk_kernel_geometry_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk_kernel_geometry");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK_KERNEL_GEOMETRY, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.partitions; /* caller will free */
+}
+
+struct sfdisk_disk_geometry_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_sfdisk_disk_geometry_ret ret;
+};
+
+static void sfdisk_disk_geometry_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct sfdisk_disk_geometry_ctx *ctx = (struct sfdisk_disk_geometry_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk_disk_geometry");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_sfdisk_disk_geometry");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_sfdisk_disk_geometry");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_sfdisk_disk_geometry_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_sfdisk_disk_geometry");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_sfdisk_disk_geometry (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_sfdisk_disk_geometry_args args;
+  struct sfdisk_disk_geometry_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_sfdisk_disk_geometry") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK_DISK_GEOMETRY,
+        (xdrproc_t) xdr_guestfs_sfdisk_disk_geometry_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, sfdisk_disk_geometry_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk_disk_geometry");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK_DISK_GEOMETRY, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.partitions; /* caller will free */
+}
+
+struct vg_activate_all_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void vg_activate_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct vg_activate_all_ctx *ctx = (struct vg_activate_all_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_vg_activate_all");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_vg_activate_all");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_vg_activate_all");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_vg_activate_all (guestfs_h *g,
+               int activate)
+{
+  struct guestfs_vg_activate_all_args args;
+  struct vg_activate_all_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_vg_activate_all") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.activate = activate;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_VG_ACTIVATE_ALL,
+        (xdrproc_t) xdr_guestfs_vg_activate_all_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, vg_activate_all_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_vg_activate_all");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VG_ACTIVATE_ALL, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct vg_activate_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void vg_activate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct vg_activate_ctx *ctx = (struct vg_activate_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_vg_activate");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_vg_activate");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_vg_activate");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_vg_activate (guestfs_h *g,
+               int activate,
+               char * const* const volgroups)
+{
+  struct guestfs_vg_activate_args args;
+  struct vg_activate_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_vg_activate") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.activate = activate;
+  args.volgroups.volgroups_val = (char **) volgroups;
+  for (args.volgroups.volgroups_len = 0; volgroups[args.volgroups.volgroups_len]; args.volgroups.volgroups_len++) ;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_VG_ACTIVATE,
+        (xdrproc_t) xdr_guestfs_vg_activate_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, vg_activate_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_vg_activate");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VG_ACTIVATE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct lvresize_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void lvresize_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct lvresize_ctx *ctx = (struct lvresize_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_lvresize");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_lvresize");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_lvresize");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_lvresize (guestfs_h *g,
+               const char *device,
+               int mbytes)
+{
+  struct guestfs_lvresize_args args;
+  struct lvresize_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_lvresize") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  args.mbytes = mbytes;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_LVRESIZE,
+        (xdrproc_t) xdr_guestfs_lvresize_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, lvresize_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_lvresize");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVRESIZE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct resize2fs_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void resize2fs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct resize2fs_ctx *ctx = (struct resize2fs_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_resize2fs");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_resize2fs");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_resize2fs");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_resize2fs (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_resize2fs_args args;
+  struct resize2fs_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_resize2fs") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_RESIZE2FS,
+        (xdrproc_t) xdr_guestfs_resize2fs_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, resize2fs_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_resize2fs");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RESIZE2FS, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct find_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_find_ret ret;
+};
+
+static void find_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct find_ctx *ctx = (struct find_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_find");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_find");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_find");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_find_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_find");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_find (guestfs_h *g,
+               const char *directory)
+{
+  struct guestfs_find_args args;
+  struct find_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_find") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.directory = (char *) directory;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_FIND,
+        (xdrproc_t) xdr_guestfs_find_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, find_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_find");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FIND, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.names.names_val =
+    safe_realloc (g, ctx.ret.names.names_val,
+                  sizeof (char *) * (ctx.ret.names.names_len + 1));
+  ctx.ret.names.names_val[ctx.ret.names.names_len] = NULL;
+  return ctx.ret.names.names_val;
+}
+
+struct e2fsck_f_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void e2fsck_f_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct e2fsck_f_ctx *ctx = (struct e2fsck_f_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_e2fsck_f");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_e2fsck_f");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_e2fsck_f");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_e2fsck_f (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_e2fsck_f_args args;
+  struct e2fsck_f_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_e2fsck_f") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_E2FSCK_F,
+        (xdrproc_t) xdr_guestfs_e2fsck_f_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, e2fsck_f_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_e2fsck_f");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_E2FSCK_F, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct sleep_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void sleep_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct sleep_ctx *ctx = (struct sleep_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_sleep");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_sleep");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_sleep");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_sleep (guestfs_h *g,
+               int secs)
+{
+  struct guestfs_sleep_args args;
+  struct sleep_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_sleep") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.secs = secs;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SLEEP,
+        (xdrproc_t) xdr_guestfs_sleep_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, sleep_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_sleep");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SLEEP, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct ntfs_3g_probe_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_ntfs_3g_probe_ret ret;
+};
+
+static void ntfs_3g_probe_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct ntfs_3g_probe_ctx *ctx = (struct ntfs_3g_probe_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_ntfs_3g_probe");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_ntfs_3g_probe");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_ntfs_3g_probe");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_ntfs_3g_probe_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_ntfs_3g_probe");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_ntfs_3g_probe (guestfs_h *g,
+               int rw,
+               const char *device)
+{
+  struct guestfs_ntfs_3g_probe_args args;
+  struct ntfs_3g_probe_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_ntfs_3g_probe") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.rw = rw;
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_NTFS_3G_PROBE,
+        (xdrproc_t) xdr_guestfs_ntfs_3g_probe_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, ntfs_3g_probe_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_ntfs_3g_probe");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_NTFS_3G_PROBE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.status;
+}
+
+struct sh_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_sh_ret ret;
+};
+
+static void sh_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct sh_ctx *ctx = (struct sh_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_sh");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_sh");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_sh");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_sh_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_sh");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_sh (guestfs_h *g,
+               const char *command)
+{
+  struct guestfs_sh_args args;
+  struct sh_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_sh") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.command = (char *) command;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SH,
+        (xdrproc_t) xdr_guestfs_sh_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, sh_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_sh");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SH, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.output; /* caller will free */
+}
+
+struct sh_lines_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_sh_lines_ret ret;
+};
+
+static void sh_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct sh_lines_ctx *ctx = (struct sh_lines_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_sh_lines");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_sh_lines");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_sh_lines");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_sh_lines_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_sh_lines");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_sh_lines (guestfs_h *g,
+               const char *command)
+{
+  struct guestfs_sh_lines_args args;
+  struct sh_lines_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_sh_lines") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.command = (char *) command;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SH_LINES,
+        (xdrproc_t) xdr_guestfs_sh_lines_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, sh_lines_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_sh_lines");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SH_LINES, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.lines.lines_val =
+    safe_realloc (g, ctx.ret.lines.lines_val,
+                  sizeof (char *) * (ctx.ret.lines.lines_len + 1));
+  ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
+  return ctx.ret.lines.lines_val;
+}
+
+struct glob_expand_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_glob_expand_ret ret;
+};
+
+static void glob_expand_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct glob_expand_ctx *ctx = (struct glob_expand_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_glob_expand");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_glob_expand");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_glob_expand");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_glob_expand_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_glob_expand");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_glob_expand (guestfs_h *g,
+               const char *pattern)
+{
+  struct guestfs_glob_expand_args args;
+  struct glob_expand_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_glob_expand") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.pattern = (char *) pattern;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_GLOB_EXPAND,
+        (xdrproc_t) xdr_guestfs_glob_expand_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, glob_expand_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_glob_expand");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GLOB_EXPAND, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.paths.paths_val =
+    safe_realloc (g, ctx.ret.paths.paths_val,
+                  sizeof (char *) * (ctx.ret.paths.paths_len + 1));
+  ctx.ret.paths.paths_val[ctx.ret.paths.paths_len] = NULL;
+  return ctx.ret.paths.paths_val;
+}
+
+struct scrub_device_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void scrub_device_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct scrub_device_ctx *ctx = (struct scrub_device_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_scrub_device");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_scrub_device");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_scrub_device");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_scrub_device (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_scrub_device_args args;
+  struct scrub_device_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_scrub_device") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SCRUB_DEVICE,
+        (xdrproc_t) xdr_guestfs_scrub_device_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, scrub_device_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_scrub_device");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SCRUB_DEVICE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct scrub_file_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void scrub_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct scrub_file_ctx *ctx = (struct scrub_file_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_scrub_file");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_scrub_file");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_scrub_file");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_scrub_file (guestfs_h *g,
+               const char *file)
+{
+  struct guestfs_scrub_file_args args;
+  struct scrub_file_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_scrub_file") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.file = (char *) file;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SCRUB_FILE,
+        (xdrproc_t) xdr_guestfs_scrub_file_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, scrub_file_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_scrub_file");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SCRUB_FILE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct scrub_freespace_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void scrub_freespace_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct scrub_freespace_ctx *ctx = (struct scrub_freespace_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_scrub_freespace");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_scrub_freespace");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_scrub_freespace");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_scrub_freespace (guestfs_h *g,
+               const char *dir)
+{
+  struct guestfs_scrub_freespace_args args;
+  struct scrub_freespace_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_scrub_freespace") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.dir = (char *) dir;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_SCRUB_FREESPACE,
+        (xdrproc_t) xdr_guestfs_scrub_freespace_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, scrub_freespace_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_scrub_freespace");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SCRUB_FREESPACE, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mkdtemp_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_mkdtemp_ret ret;
+};
+
+static void mkdtemp_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mkdtemp_ctx *ctx = (struct mkdtemp_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mkdtemp");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mkdtemp");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mkdtemp");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_mkdtemp_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_mkdtemp");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_mkdtemp (guestfs_h *g,
+               const char *template)
+{
+  struct guestfs_mkdtemp_args args;
+  struct mkdtemp_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mkdtemp") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.template = (char *) template;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MKDTEMP,
+        (xdrproc_t) xdr_guestfs_mkdtemp_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mkdtemp_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mkdtemp");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDTEMP, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.dir; /* caller will free */
+}
+
+struct wc_l_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_wc_l_ret ret;
+};
+
+static void wc_l_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct wc_l_ctx *ctx = (struct wc_l_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_wc_l");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_wc_l");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_wc_l");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_wc_l_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_wc_l");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_wc_l (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_wc_l_args args;
+  struct wc_l_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_wc_l") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_WC_L,
+        (xdrproc_t) xdr_guestfs_wc_l_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, wc_l_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_wc_l");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_WC_L, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.lines;
+}
+
+struct wc_w_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_wc_w_ret ret;
+};
+
+static void wc_w_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct wc_w_ctx *ctx = (struct wc_w_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_wc_w");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_wc_w");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_wc_w");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_wc_w_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_wc_w");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_wc_w (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_wc_w_args args;
+  struct wc_w_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_wc_w") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_WC_W,
+        (xdrproc_t) xdr_guestfs_wc_w_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, wc_w_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_wc_w");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_WC_W, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.words;
+}
+
+struct wc_c_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_wc_c_ret ret;
+};
+
+static void wc_c_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct wc_c_ctx *ctx = (struct wc_c_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_wc_c");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_wc_c");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_wc_c");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_wc_c_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_wc_c");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_wc_c (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_wc_c_args args;
+  struct wc_c_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_wc_c") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_WC_C,
+        (xdrproc_t) xdr_guestfs_wc_c_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, wc_c_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_wc_c");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_WC_C, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.chars;
+}
+
+struct head_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_head_ret ret;
+};
+
+static void head_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct head_ctx *ctx = (struct head_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_head");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_head");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_head");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_head_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_head");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_head (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_head_args args;
+  struct head_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_head") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_HEAD,
+        (xdrproc_t) xdr_guestfs_head_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, head_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_head");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_HEAD, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.lines.lines_val =
+    safe_realloc (g, ctx.ret.lines.lines_val,
+                  sizeof (char *) * (ctx.ret.lines.lines_len + 1));
+  ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
+  return ctx.ret.lines.lines_val;
+}
+
+struct head_n_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_head_n_ret ret;
+};
+
+static void head_n_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct head_n_ctx *ctx = (struct head_n_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_head_n");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_head_n");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_head_n");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_head_n_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_head_n");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_head_n (guestfs_h *g,
+               int nrlines,
+               const char *path)
+{
+  struct guestfs_head_n_args args;
+  struct head_n_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_head_n") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.nrlines = nrlines;
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_HEAD_N,
+        (xdrproc_t) xdr_guestfs_head_n_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, head_n_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_head_n");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_HEAD_N, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.lines.lines_val =
+    safe_realloc (g, ctx.ret.lines.lines_val,
+                  sizeof (char *) * (ctx.ret.lines.lines_len + 1));
+  ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
+  return ctx.ret.lines.lines_val;
+}
+
+struct tail_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_tail_ret ret;
+};
+
+static void tail_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct tail_ctx *ctx = (struct tail_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_tail");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_tail");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_tail");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_tail_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_tail");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_tail (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_tail_args args;
+  struct tail_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_tail") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_TAIL,
+        (xdrproc_t) xdr_guestfs_tail_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, tail_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_tail");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TAIL, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.lines.lines_val =
+    safe_realloc (g, ctx.ret.lines.lines_val,
+                  sizeof (char *) * (ctx.ret.lines.lines_len + 1));
+  ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
+  return ctx.ret.lines.lines_val;
+}
+
+struct tail_n_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_tail_n_ret ret;
+};
+
+static void tail_n_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct tail_n_ctx *ctx = (struct tail_n_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_tail_n");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_tail_n");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_tail_n");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_tail_n_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_tail_n");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_tail_n (guestfs_h *g,
+               int nrlines,
+               const char *path)
+{
+  struct guestfs_tail_n_args args;
+  struct tail_n_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_tail_n") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.nrlines = nrlines;
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_TAIL_N,
+        (xdrproc_t) xdr_guestfs_tail_n_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, tail_n_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_tail_n");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TAIL_N, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.lines.lines_val =
+    safe_realloc (g, ctx.ret.lines.lines_val,
+                  sizeof (char *) * (ctx.ret.lines.lines_len + 1));
+  ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
+  return ctx.ret.lines.lines_val;
+}
+
+struct df_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_df_ret ret;
+};
+
+static void df_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct df_ctx *ctx = (struct df_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_df");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_df");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_df");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_df_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_df");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_df (guestfs_h *g)
+{
+  struct df_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_df") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  serial = guestfs__send_sync (g, GUESTFS_PROC_DF, NULL, NULL);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, df_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_df");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DF, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.output; /* caller will free */
+}
+
+struct df_h_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_df_h_ret ret;
+};
+
+static void df_h_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct df_h_ctx *ctx = (struct df_h_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_df_h");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_df_h");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_df_h");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_df_h_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_df_h");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char *guestfs_df_h (guestfs_h *g)
+{
+  struct df_h_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_df_h") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  serial = guestfs__send_sync (g, GUESTFS_PROC_DF_H, NULL, NULL);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, df_h_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_df_h");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DF_H, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.output; /* caller will free */
+}
+
+struct du_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_du_ret ret;
+};
+
+static void du_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct du_ctx *ctx = (struct du_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_du");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_du");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_du");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_du_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_du");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int64_t guestfs_du (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_du_args args;
+  struct du_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_du") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_DU,
+        (xdrproc_t) xdr_guestfs_du_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, du_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_du");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DU, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.sizekb;
+}
+
+struct initrd_list_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_initrd_list_ret ret;
+};
+
+static void initrd_list_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct initrd_list_ctx *ctx = (struct initrd_list_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_initrd_list");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_initrd_list");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_initrd_list");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_initrd_list_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_initrd_list");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+char **guestfs_initrd_list (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_initrd_list_args args;
+  struct initrd_list_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_initrd_list") == -1) return NULL;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_INITRD_LIST,
+        (xdrproc_t) xdr_guestfs_initrd_list_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, initrd_list_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_initrd_list");
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_INITRD_LIST, serial) == -1) {
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return NULL;
+  }
+
+  guestfs_end_busy (g);
+  /* caller will free this, but we need to add a NULL entry */
+  ctx.ret.filenames.filenames_val =
+    safe_realloc (g, ctx.ret.filenames.filenames_val,
+                  sizeof (char *) * (ctx.ret.filenames.filenames_len + 1));
+  ctx.ret.filenames.filenames_val[ctx.ret.filenames.filenames_len] = NULL;
+  return ctx.ret.filenames.filenames_val;
+}
+
+struct mount_loop_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mount_loop_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mount_loop_ctx *ctx = (struct mount_loop_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mount_loop");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mount_loop");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mount_loop");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mount_loop (guestfs_h *g,
+               const char *file,
+               const char *mountpoint)
+{
+  struct guestfs_mount_loop_args args;
+  struct mount_loop_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mount_loop") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.file = (char *) file;
+  args.mountpoint = (char *) mountpoint;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT_LOOP,
+        (xdrproc_t) xdr_guestfs_mount_loop_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mount_loop_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mount_loop");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_LOOP, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mkswap_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mkswap_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mkswap_ctx *ctx = (struct mkswap_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mkswap");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mkswap");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mkswap");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mkswap (guestfs_h *g,
+               const char *device)
+{
+  struct guestfs_mkswap_args args;
+  struct mkswap_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mkswap") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MKSWAP,
+        (xdrproc_t) xdr_guestfs_mkswap_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mkswap_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mkswap");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKSWAP, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mkswap_L_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mkswap_L_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mkswap_L_ctx *ctx = (struct mkswap_L_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mkswap_L");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mkswap_L");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mkswap_L");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mkswap_L (guestfs_h *g,
+               const char *label,
+               const char *device)
+{
+  struct guestfs_mkswap_L_args args;
+  struct mkswap_L_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mkswap_L") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.label = (char *) label;
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MKSWAP_L,
+        (xdrproc_t) xdr_guestfs_mkswap_L_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mkswap_L_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mkswap_L");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKSWAP_L, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mkswap_U_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mkswap_U_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mkswap_U_ctx *ctx = (struct mkswap_U_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mkswap_U");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mkswap_U");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mkswap_U");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mkswap_U (guestfs_h *g,
+               const char *uuid,
+               const char *device)
+{
+  struct guestfs_mkswap_U_args args;
+  struct mkswap_U_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mkswap_U") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.uuid = (char *) uuid;
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MKSWAP_U,
+        (xdrproc_t) xdr_guestfs_mkswap_U_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mkswap_U_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mkswap_U");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKSWAP_U, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mknod_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mknod_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mknod_ctx *ctx = (struct mknod_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mknod");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mknod");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mknod");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mknod (guestfs_h *g,
+               int mode,
+               int devmajor,
+               int devminor,
+               const char *path)
+{
+  struct guestfs_mknod_args args;
+  struct mknod_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mknod") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.mode = mode;
+  args.devmajor = devmajor;
+  args.devminor = devminor;
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MKNOD,
+        (xdrproc_t) xdr_guestfs_mknod_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mknod_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mknod");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKNOD, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mkfifo_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mkfifo_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mkfifo_ctx *ctx = (struct mkfifo_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mkfifo");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mkfifo");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mkfifo");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mkfifo (guestfs_h *g,
+               int mode,
+               const char *path)
+{
+  struct guestfs_mkfifo_args args;
+  struct mkfifo_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mkfifo") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.mode = mode;
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MKFIFO,
+        (xdrproc_t) xdr_guestfs_mkfifo_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mkfifo_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mkfifo");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKFIFO, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mknod_b_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mknod_b_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mknod_b_ctx *ctx = (struct mknod_b_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mknod_b");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mknod_b");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mknod_b");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mknod_b (guestfs_h *g,
+               int mode,
+               int devmajor,
+               int devminor,
+               const char *path)
+{
+  struct guestfs_mknod_b_args args;
+  struct mknod_b_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mknod_b") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.mode = mode;
+  args.devmajor = devmajor;
+  args.devminor = devminor;
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MKNOD_B,
+        (xdrproc_t) xdr_guestfs_mknod_b_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mknod_b_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mknod_b");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKNOD_B, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct mknod_c_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+};
+
+static void mknod_c_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct mknod_c_ctx *ctx = (struct mknod_c_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_mknod_c");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_mknod_c");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_mknod_c");
+      return;
+    }
+    goto done;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_mknod_c (guestfs_h *g,
+               int mode,
+               int devmajor,
+               int devminor,
+               const char *path)
+{
+  struct guestfs_mknod_c_args args;
+  struct mknod_c_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_mknod_c") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.mode = mode;
+  args.devmajor = devmajor;
+  args.devminor = devminor;
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_MKNOD_C,
+        (xdrproc_t) xdr_guestfs_mknod_c_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, mknod_c_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_mknod_c");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKNOD_C, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return 0;
+}
+
+struct umask_ctx {
+  /* This flag is set by the callbacks, so we know we've done
+   * the callbacks as expected, and in the right sequence.
+   * 0 = not called, 1 = reply_cb called.
+   */
+  int cb_sequence;
+  struct guestfs_message_header hdr;
+  struct guestfs_message_error err;
+  struct guestfs_umask_ret ret;
+};
+
+static void umask_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct umask_ctx *ctx = (struct umask_ctx *) data;
+
+  /* This should definitely not happen. */
+  if (ctx->cb_sequence != 0) {
+    ctx->cb_sequence = 9999;
+    error (g, "%s: internal error: reply callback called twice", "guestfs_umask");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_umask");
+    return;
+  }
+  if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+    if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+      error (g, "%s: failed to parse reply error", "guestfs_umask");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_umask_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_umask");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_umask (guestfs_h *g,
+               int mask)
+{
+  struct guestfs_umask_args args;
+  struct umask_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_umask") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.mask = mask;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_UMASK,
+        (xdrproc_t) xdr_guestfs_umask_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, umask_reply_cb, &ctx);
+  (void) ml->main_loop_run (ml, g);
+  guestfs_set_reply_callback (g, NULL, NULL);
+  if (ctx.cb_sequence != 1) {
+    error (g, "%s reply failed, see earlier error messages", "guestfs_umask");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMASK, serial) == -1) {
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    free (ctx.err.error_message);
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  guestfs_end_busy (g);
+  return ctx.ret.oldmask;
+}
+