diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MAX_PROC_NR | 2 | ||||
-rw-r--r-- | src/guestfs-actions.c | 265 | ||||
-rw-r--r-- | src/guestfs-actions.h | 3 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 34 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 28 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 17 |
6 files changed, 347 insertions, 2 deletions
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index b0d73241..94361d49 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -129 +132 diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index 94a08629..e81245a0 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -11835,3 +11835,268 @@ int guestfs_mount_loop (guestfs_h *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; +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index c0002662..c6d2933c 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -200,3 +200,6 @@ extern char *guestfs_df_h (guestfs_h *handle); extern int64_t guestfs_du (guestfs_h *handle, const char *path); extern char **guestfs_initrd_list (guestfs_h *handle, const char *path); extern int guestfs_mount_loop (guestfs_h *handle, const char *file, const char *mountpoint); +extern int guestfs_mkswap (guestfs_h *handle, const char *device); +extern int guestfs_mkswap_L (guestfs_h *handle, const char *label, const char *device); +extern int guestfs_mkswap_U (guestfs_h *handle, const char *uuid, const char *device); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index 9b12986c..37c74da4 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -2204,6 +2204,40 @@ xdr_guestfs_mount_loop_args (XDR *xdrs, guestfs_mount_loop_args *objp) } bool_t +xdr_guestfs_mkswap_args (XDR *xdrs, guestfs_mkswap_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_mkswap_L_args (XDR *xdrs, guestfs_mkswap_L_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->label, ~0)) + return FALSE; + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_mkswap_U_args (XDR *xdrs, guestfs_mkswap_U_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->uuid, ~0)) + return FALSE; + if (!xdr_string (xdrs, &objp->device, ~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 d127b884..7931bb59 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -1130,6 +1130,23 @@ struct guestfs_mount_loop_args { }; typedef struct guestfs_mount_loop_args guestfs_mount_loop_args; +struct guestfs_mkswap_args { + char *device; +}; +typedef struct guestfs_mkswap_args guestfs_mkswap_args; + +struct guestfs_mkswap_L_args { + char *label; + char *device; +}; +typedef struct guestfs_mkswap_L_args guestfs_mkswap_L_args; + +struct guestfs_mkswap_U_args { + char *uuid; + char *device; +}; +typedef struct guestfs_mkswap_U_args guestfs_mkswap_U_args; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -1260,7 +1277,10 @@ enum guestfs_procedure { GUESTFS_PROC_DU = 127, GUESTFS_PROC_INITRD_LIST = 128, GUESTFS_PROC_MOUNT_LOOP = 129, - GUESTFS_PROC_NR_PROCS = 129 + 1, + GUESTFS_PROC_MKSWAP = 130, + GUESTFS_PROC_MKSWAP_L = 131, + GUESTFS_PROC_MKSWAP_U = 132, + GUESTFS_PROC_NR_PROCS = 132 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1493,6 +1513,9 @@ extern bool_t xdr_guestfs_du_ret (XDR *, guestfs_du_ret*); extern bool_t xdr_guestfs_initrd_list_args (XDR *, guestfs_initrd_list_args*); extern bool_t xdr_guestfs_initrd_list_ret (XDR *, guestfs_initrd_list_ret*); extern bool_t xdr_guestfs_mount_loop_args (XDR *, guestfs_mount_loop_args*); +extern bool_t xdr_guestfs_mkswap_args (XDR *, guestfs_mkswap_args*); +extern bool_t xdr_guestfs_mkswap_L_args (XDR *, guestfs_mkswap_L_args*); +extern bool_t xdr_guestfs_mkswap_U_args (XDR *, guestfs_mkswap_U_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*); @@ -1684,6 +1707,9 @@ extern bool_t xdr_guestfs_du_ret (); extern bool_t xdr_guestfs_initrd_list_args (); extern bool_t xdr_guestfs_initrd_list_ret (); extern bool_t xdr_guestfs_mount_loop_args (); +extern bool_t xdr_guestfs_mkswap_args (); +extern bool_t xdr_guestfs_mkswap_L_args (); +extern bool_t xdr_guestfs_mkswap_U_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 fdc67c15..55782842 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -863,6 +863,20 @@ struct guestfs_mount_loop_args { string mountpoint<>; }; +struct guestfs_mkswap_args { + string device<>; +}; + +struct guestfs_mkswap_L_args { + string label<>; + string device<>; +}; + +struct guestfs_mkswap_U_args { + string uuid<>; + string device<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -993,6 +1007,9 @@ enum guestfs_procedure { GUESTFS_PROC_DU = 127, GUESTFS_PROC_INITRD_LIST = 128, GUESTFS_PROC_MOUNT_LOOP = 129, + GUESTFS_PROC_MKSWAP = 130, + GUESTFS_PROC_MKSWAP_L = 131, + GUESTFS_PROC_MKSWAP_U = 132, GUESTFS_PROC_NR_PROCS }; |