diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/guestfs-actions.c | 88 | ||||
-rw-r--r-- | src/guestfs-actions.h | 1 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 12 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 11 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 6 |
5 files changed, 117 insertions, 1 deletions
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index e2da1c3a..c20301b8 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -7728,3 +7728,91 @@ int guestfs_zero (guestfs_h *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_set_ready (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_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GRUB_INSTALL, 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; +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index 0fc62a18..843968cc 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -125,3 +125,4 @@ extern int guestfs_set_e2uuid (guestfs_h *handle, const char *device, const char extern char *guestfs_get_e2uuid (guestfs_h *handle, const char *device); extern int guestfs_fsck (guestfs_h *handle, const char *fstype, const char *device); extern int guestfs_zero (guestfs_h *handle, const char *device); +extern int guestfs_grub_install (guestfs_h *handle, const char *root, const char *device); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index b12133a0..2f08afdf 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -1460,6 +1460,18 @@ xdr_guestfs_zero_args (XDR *xdrs, guestfs_zero_args *objp) } bool_t +xdr_guestfs_grub_install_args (XDR *xdrs, guestfs_grub_install_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->root, ~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 2e79669c..69ae268f 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -755,6 +755,12 @@ struct guestfs_zero_args { }; typedef struct guestfs_zero_args guestfs_zero_args; +struct guestfs_grub_install_args { + char *root; + char *device; +}; +typedef struct guestfs_grub_install_args guestfs_grub_install_args; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -841,7 +847,8 @@ enum guestfs_procedure { GUESTFS_PROC_GET_E2UUID = 83, GUESTFS_PROC_FSCK = 84, GUESTFS_PROC_ZERO = 85, - GUESTFS_PROC_NR_PROCS = 85 + 1, + GUESTFS_PROC_GRUB_INSTALL = 86, + GUESTFS_PROC_NR_PROCS = 86 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1009,6 +1016,7 @@ extern bool_t xdr_guestfs_get_e2uuid_ret (XDR *, guestfs_get_e2uuid_ret*); extern bool_t xdr_guestfs_fsck_args (XDR *, guestfs_fsck_args*); extern bool_t xdr_guestfs_fsck_ret (XDR *, guestfs_fsck_ret*); extern bool_t xdr_guestfs_zero_args (XDR *, guestfs_zero_args*); +extern bool_t xdr_guestfs_grub_install_args (XDR *, guestfs_grub_install_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*); @@ -1135,6 +1143,7 @@ extern bool_t xdr_guestfs_get_e2uuid_ret (); extern bool_t xdr_guestfs_fsck_args (); extern bool_t xdr_guestfs_fsck_ret (); extern bool_t xdr_guestfs_zero_args (); +extern bool_t xdr_guestfs_grub_install_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 c940bf44..81833300 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -586,6 +586,11 @@ struct guestfs_zero_args { string device<>; }; +struct guestfs_grub_install_args { + string root<>; + string device<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -672,6 +677,7 @@ enum guestfs_procedure { GUESTFS_PROC_GET_E2UUID = 83, GUESTFS_PROC_FSCK = 84, GUESTFS_PROC_ZERO = 85, + GUESTFS_PROC_GRUB_INSTALL = 86, GUESTFS_PROC_NR_PROCS }; |