X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fguestfs-actions.c;h=68f122aa2580b311e79993d3ffa4b55224712253;hp=1a632360bf31df085b3bedbac3f2bd927c658c02;hb=aed0fa2c015e56a882fd6d4b759c82df08fc40d7;hpb=170f262f0413de843af62b968f6d12c1c476ae7f diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index 1a63236..68f122a 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -139,7 +139,6 @@ int guestfs_mount (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, mount_reply_cb, &ctx); @@ -216,7 +215,6 @@ int guestfs_sync (guestfs_h *g) return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, sync_reply_cb, &ctx); @@ -297,7 +295,6 @@ int guestfs_touch (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, touch_reply_cb, &ctx); @@ -383,7 +380,6 @@ char *guestfs_cat (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, cat_reply_cb, &ctx); @@ -469,7 +465,6 @@ char *guestfs_ll (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, ll_reply_cb, &ctx); @@ -555,7 +550,6 @@ char **guestfs_ls (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, ls_reply_cb, &ctx); @@ -642,7 +636,6 @@ char **guestfs_list_devices (guestfs_h *g) return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, list_devices_reply_cb, &ctx); @@ -729,7 +722,6 @@ char **guestfs_list_partitions (guestfs_h *g) return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, list_partitions_reply_cb, &ctx); @@ -816,7 +808,6 @@ char **guestfs_pvs (guestfs_h *g) return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, pvs_reply_cb, &ctx); @@ -903,7 +894,6 @@ char **guestfs_vgs (guestfs_h *g) return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, vgs_reply_cb, &ctx); @@ -990,7 +980,6 @@ char **guestfs_lvs (guestfs_h *g) return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, lvs_reply_cb, &ctx); @@ -1077,7 +1066,6 @@ struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *g) return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, pvs_full_reply_cb, &ctx); @@ -1160,7 +1148,6 @@ struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *g) return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, vgs_full_reply_cb, &ctx); @@ -1243,7 +1230,6 @@ struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *g) return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, lvs_full_reply_cb, &ctx); @@ -1330,7 +1316,6 @@ char **guestfs_read_lines (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, read_lines_reply_cb, &ctx); @@ -1418,7 +1403,6 @@ int guestfs_aug_init (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_init_reply_cb, &ctx); @@ -1495,7 +1479,6 @@ int guestfs_aug_close (guestfs_h *g) return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_close_reply_cb, &ctx); @@ -1583,7 +1566,6 @@ int guestfs_aug_defvar (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_defvar_reply_cb, &ctx); @@ -1673,7 +1655,6 @@ struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_defnode_reply_cb, &ctx); @@ -1760,7 +1741,6 @@ char *guestfs_aug_get (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_get_reply_cb, &ctx); @@ -1843,7 +1823,6 @@ int guestfs_aug_set (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_set_reply_cb, &ctx); @@ -1928,7 +1907,6 @@ int guestfs_aug_insert (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_insert_reply_cb, &ctx); @@ -2014,7 +1992,6 @@ int guestfs_aug_rm (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_rm_reply_cb, &ctx); @@ -2097,7 +2074,6 @@ int guestfs_aug_mv (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_mv_reply_cb, &ctx); @@ -2183,7 +2159,6 @@ char **guestfs_aug_match (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_match_reply_cb, &ctx); @@ -2265,7 +2240,6 @@ int guestfs_aug_save (guestfs_h *g) return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_save_reply_cb, &ctx); @@ -2342,7 +2316,6 @@ int guestfs_aug_load (guestfs_h *g) return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_load_reply_cb, &ctx); @@ -2428,7 +2401,6 @@ char **guestfs_aug_ls (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, aug_ls_reply_cb, &ctx); @@ -2514,7 +2486,6 @@ int guestfs_rm (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, rm_reply_cb, &ctx); @@ -2595,7 +2566,6 @@ int guestfs_rmdir (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, rmdir_reply_cb, &ctx); @@ -2676,7 +2646,6 @@ int guestfs_rm_rf (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, rm_rf_reply_cb, &ctx); @@ -2757,7 +2726,6 @@ int guestfs_mkdir (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, mkdir_reply_cb, &ctx); @@ -2838,7 +2806,6 @@ int guestfs_mkdir_p (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, mkdir_p_reply_cb, &ctx); @@ -2921,7 +2888,6 @@ int guestfs_chmod (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, chmod_reply_cb, &ctx); @@ -3006,7 +2972,6 @@ int guestfs_chown (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, chown_reply_cb, &ctx); @@ -3092,7 +3057,6 @@ int guestfs_exists (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, exists_reply_cb, &ctx); @@ -3178,7 +3142,6 @@ int guestfs_is_file (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, is_file_reply_cb, &ctx); @@ -3264,7 +3227,6 @@ int guestfs_is_dir (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, is_dir_reply_cb, &ctx); @@ -3345,7 +3307,6 @@ int guestfs_pvcreate (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, pvcreate_reply_cb, &ctx); @@ -3429,7 +3390,6 @@ int guestfs_vgcreate (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, vgcreate_reply_cb, &ctx); @@ -3514,7 +3474,6 @@ int guestfs_lvcreate (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, lvcreate_reply_cb, &ctx); @@ -3597,7 +3556,6 @@ int guestfs_mkfs (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, mkfs_reply_cb, &ctx); @@ -3687,7 +3645,6 @@ int guestfs_sfdisk (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, sfdisk_reply_cb, &ctx); @@ -3772,7 +3729,6 @@ int guestfs_write_file (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, write_file_reply_cb, &ctx); @@ -3853,7 +3809,6 @@ int guestfs_umount (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, umount_reply_cb, &ctx); @@ -3935,7 +3890,6 @@ char **guestfs_mounts (guestfs_h *g) return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, mounts_reply_cb, &ctx); @@ -4017,7 +3971,6 @@ int guestfs_umount_all (guestfs_h *g) return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, umount_all_reply_cb, &ctx); @@ -4094,7 +4047,6 @@ int guestfs_lvm_remove_all (guestfs_h *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); @@ -4180,7 +4132,6 @@ char *guestfs_file (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, file_reply_cb, &ctx); @@ -4267,7 +4218,6 @@ char *guestfs_command (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, command_reply_cb, &ctx); @@ -4354,7 +4304,6 @@ char **guestfs_command_lines (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, command_lines_reply_cb, &ctx); @@ -4445,7 +4394,6 @@ struct guestfs_stat *guestfs_stat (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, stat_reply_cb, &ctx); @@ -4532,7 +4480,6 @@ struct guestfs_stat *guestfs_lstat (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, lstat_reply_cb, &ctx); @@ -4619,7 +4566,6 @@ struct guestfs_statvfs *guestfs_statvfs (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, statvfs_reply_cb, &ctx); @@ -4706,7 +4652,6 @@ char **guestfs_tune2fs_l (guestfs_h *g, return NULL; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, tune2fs_l_reply_cb, &ctx); @@ -4792,7 +4737,6 @@ int guestfs_blockdev_setro (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_setro_reply_cb, &ctx); @@ -4873,7 +4817,6 @@ int guestfs_blockdev_setrw (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_setrw_reply_cb, &ctx); @@ -4959,7 +4902,6 @@ int guestfs_blockdev_getro (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_getro_reply_cb, &ctx); @@ -5045,7 +4987,6 @@ int guestfs_blockdev_getss (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_getss_reply_cb, &ctx); @@ -5131,7 +5072,6 @@ int guestfs_blockdev_getbsz (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_getbsz_reply_cb, &ctx); @@ -5214,7 +5154,6 @@ int guestfs_blockdev_setbsz (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_setbsz_reply_cb, &ctx); @@ -5300,7 +5239,6 @@ int64_t guestfs_blockdev_getsz (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_getsz_reply_cb, &ctx); @@ -5386,7 +5324,6 @@ int64_t guestfs_blockdev_getsize64 (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_getsize64_reply_cb, &ctx); @@ -5467,7 +5404,6 @@ int guestfs_blockdev_flushbufs (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_flushbufs_reply_cb, &ctx); @@ -5548,7 +5484,6 @@ int guestfs_blockdev_rereadpt (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, blockdev_rereadpt_reply_cb, &ctx); @@ -5724,7 +5659,6 @@ int guestfs_download (guestfs_h *g, return -1; } - read_reply: guestfs__switch_to_receiving (g); ctx.cb_sequence = 0; guestfs_set_reply_callback (g, download_reply_cb, &ctx); @@ -5756,3 +5690,1030 @@ int guestfs_download (guestfs_h *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. + */ + int cb_sequence; + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_checksum_ret ret; +}; + +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; + + ml->main_loop_quit (ml, g); + + if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) { + error (g, "%s: failed to parse reply header", "guestfs_checksum"); + 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_checksum"); + return; + } + goto done; + } + if (!xdr_guestfs_checksum_ret (xdr, &ctx->ret)) { + error (g, "%s: failed to parse reply", "guestfs_checksum"); + return; + } + done: + ctx->cb_sequence = 1001; +} + +char *guestfs_checksum (guestfs_h *g, + const char *csumtype, + const char *path) +{ + struct guestfs_checksum_args args; + struct checksum_ctx ctx; + guestfs_main_loop *ml = guestfs_get_main_loop (g); + int serial; + + if (check_state (g, "guestfs_checksum") == -1) return NULL; + guestfs_set_busy (g); + + memset (&ctx, 0, sizeof ctx); + + args.csumtype = (char *) csumtype; + args.path = (char *) path; + serial = guestfs__send_sync (g, GUESTFS_PROC_CHECKSUM, + (xdrproc_t) xdr_guestfs_checksum_args, (char *) &args); + if (serial == -1) { + guestfs_set_ready (g); + return NULL; + } + + 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) { + error (g, "%s reply failed, see earlier error messages", "guestfs_checksum"); + guestfs_set_ready (g); + return NULL; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHECKSUM, serial) == -1) { + guestfs_set_ready (g); + return NULL; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return NULL; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (g); + return -1; + } + + { + int r; + + r = guestfs__send_file_sync (g, tarfile); + if (r == -1) { + guestfs_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_tar_in"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TAR_IN, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_tar_out"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TAR_OUT, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + if (guestfs__receive_file_sync (g, tarfile) == -1) { + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (g); + return -1; + } + + { + int r; + + r = guestfs__send_file_sync (g, tarball); + if (r == -1) { + guestfs_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_tgz_in"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TGZ_IN, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_tgz_out"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TGZ_OUT, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + if (guestfs__receive_file_sync (g, tarball) == -1) { + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_mount_ro"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_RO, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_mount_options"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_OPTIONS, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_mount_vfs"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_VFS, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_debug"); + guestfs_set_ready (g); + return NULL; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DEBUG, serial) == -1) { + guestfs_set_ready (g); + return NULL; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return NULL; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_lvremove"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVREMOVE, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_vgremove"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGREMOVE, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (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 = send called, + * 1001 = reply 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; + + 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 = 1001; +} + +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_set_ready (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 != 1001) { + error (g, "%s reply failed, see earlier error messages", "guestfs_pvremove"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVREMOVE, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (g); + return 0; +} +