diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-06-23 15:53:44 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-06-23 15:53:44 +0100 |
commit | bcb3fc0c3336c05e9ecbbfb25c7c31b42bd3e32e (patch) | |
tree | 80042c722c65911c3a3b55a275daefff96220e7f /src | |
parent | da7cf3670fe60301beeb175ff6c284b737d5b7f4 (diff) | |
download | libguestfs-bcb3fc0c3336c05e9ecbbfb25c7c31b42bd3e32e.tar.gz libguestfs-bcb3fc0c3336c05e9ecbbfb25c7c31b42bd3e32e.tar.xz libguestfs-bcb3fc0c3336c05e9ecbbfb25c7c31b42bd3e32e.zip |
Generated code for 'scrub-*' commands.
Diffstat (limited to 'src')
-rw-r--r-- | src/guestfs-actions.c | 261 | ||||
-rw-r--r-- | src/guestfs-actions.h | 3 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 30 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 26 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 15 |
5 files changed, 334 insertions, 1 deletions
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index e1ec1589..74021053 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -10360,3 +10360,264 @@ char **guestfs_glob_expand (guestfs_h *g, 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; +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index 19996e8f..0f85df7a 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -184,3 +184,6 @@ extern int guestfs_ntfs_3g_probe (guestfs_h *handle, int rw, const char *device) extern char *guestfs_sh (guestfs_h *handle, const char *command); extern char **guestfs_sh_lines (guestfs_h *handle, const char *command); extern char **guestfs_glob_expand (guestfs_h *handle, const char *pattern); +extern int guestfs_scrub_device (guestfs_h *handle, const char *device); +extern int guestfs_scrub_file (guestfs_h *handle, const char *file); +extern int guestfs_scrub_freespace (guestfs_h *handle, const char *dir); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index b2d435ee..a241aa0e 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -1933,6 +1933,36 @@ xdr_guestfs_glob_expand_ret (XDR *xdrs, guestfs_glob_expand_ret *objp) } bool_t +xdr_guestfs_scrub_device_args (XDR *xdrs, guestfs_scrub_device_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_scrub_file_args (XDR *xdrs, guestfs_scrub_file_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->file, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_scrub_freespace_args (XDR *xdrs, guestfs_scrub_freespace_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->dir, ~0)) + return FALSE; + return TRUE; +} + +bool_t xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp) { register int32_t *buf; diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h index 8fdb6640..dc88c70f 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -982,6 +982,21 @@ struct guestfs_glob_expand_ret { }; typedef struct guestfs_glob_expand_ret guestfs_glob_expand_ret; +struct guestfs_scrub_device_args { + char *device; +}; +typedef struct guestfs_scrub_device_args guestfs_scrub_device_args; + +struct guestfs_scrub_file_args { + char *file; +}; +typedef struct guestfs_scrub_file_args guestfs_scrub_file_args; + +struct guestfs_scrub_freespace_args { + char *dir; +}; +typedef struct guestfs_scrub_freespace_args guestfs_scrub_freespace_args; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -1096,7 +1111,10 @@ enum guestfs_procedure { GUESTFS_PROC_SH = 111, GUESTFS_PROC_SH_LINES = 112, GUESTFS_PROC_GLOB_EXPAND = 113, - GUESTFS_PROC_NR_PROCS = 113 + 1, + GUESTFS_PROC_SCRUB_DEVICE = 114, + GUESTFS_PROC_SCRUB_FILE = 115, + GUESTFS_PROC_SCRUB_FREESPACE = 116, + GUESTFS_PROC_NR_PROCS = 116 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1303,6 +1321,9 @@ extern bool_t xdr_guestfs_sh_lines_args (XDR *, guestfs_sh_lines_args*); extern bool_t xdr_guestfs_sh_lines_ret (XDR *, guestfs_sh_lines_ret*); extern bool_t xdr_guestfs_glob_expand_args (XDR *, guestfs_glob_expand_args*); extern bool_t xdr_guestfs_glob_expand_ret (XDR *, guestfs_glob_expand_ret*); +extern bool_t xdr_guestfs_scrub_device_args (XDR *, guestfs_scrub_device_args*); +extern bool_t xdr_guestfs_scrub_file_args (XDR *, guestfs_scrub_file_args*); +extern bool_t xdr_guestfs_scrub_freespace_args (XDR *, guestfs_scrub_freespace_args*); extern bool_t xdr_guestfs_procedure (XDR *, guestfs_procedure*); extern bool_t xdr_guestfs_message_direction (XDR *, guestfs_message_direction*); extern bool_t xdr_guestfs_message_status (XDR *, guestfs_message_status*); @@ -1468,6 +1489,9 @@ extern bool_t xdr_guestfs_sh_lines_args (); extern bool_t xdr_guestfs_sh_lines_ret (); extern bool_t xdr_guestfs_glob_expand_args (); extern bool_t xdr_guestfs_glob_expand_ret (); +extern bool_t xdr_guestfs_scrub_device_args (); +extern bool_t xdr_guestfs_scrub_file_args (); +extern bool_t xdr_guestfs_scrub_freespace_args (); extern bool_t xdr_guestfs_procedure (); extern bool_t xdr_guestfs_message_direction (); extern bool_t xdr_guestfs_message_status (); diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x index d6627267..094200eb 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -756,6 +756,18 @@ struct guestfs_glob_expand_ret { str paths<>; }; +struct guestfs_scrub_device_args { + string device<>; +}; + +struct guestfs_scrub_file_args { + string file<>; +}; + +struct guestfs_scrub_freespace_args { + string dir<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -870,6 +882,9 @@ enum guestfs_procedure { GUESTFS_PROC_SH = 111, GUESTFS_PROC_SH_LINES = 112, GUESTFS_PROC_GLOB_EXPAND = 113, + GUESTFS_PROC_SCRUB_DEVICE = 114, + GUESTFS_PROC_SCRUB_FILE = 115, + GUESTFS_PROC_SCRUB_FREESPACE = 116, GUESTFS_PROC_NR_PROCS }; |