diff options
author | Matthew Booth <mbooth@redhat.com> | 2009-06-29 16:27:05 +0100 |
---|---|---|
committer | Matthew Booth <mbooth@redhat.com> | 2009-06-29 16:27:05 +0100 |
commit | 128f822e16bb96677c75b88125e18f48d7ccedaf (patch) | |
tree | c5f09d72e73c90c02967f48151831e6c4a78fb68 /src | |
parent | 103fb55e6b1428366ab31a0f17484ef1baa68e96 (diff) | |
parent | ad475104ec7fae456d3309cbf4261b893ed160bb (diff) | |
download | libguestfs-128f822e16bb96677c75b88125e18f48d7ccedaf.tar.gz libguestfs-128f822e16bb96677c75b88125e18f48d7ccedaf.tar.xz libguestfs-128f822e16bb96677c75b88125e18f48d7ccedaf.zip |
Merge commit 'et/master'
Diffstat (limited to 'src')
-rw-r--r-- | src/MAX_PROC_NR | 2 | ||||
-rwxr-xr-x | src/generator.ml | 24 | ||||
-rw-r--r-- | src/guestfs-actions.c | 186 | ||||
-rw-r--r-- | src/guestfs-actions.h | 2 | ||||
-rw-r--r-- | src/guestfs.c | 7 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 33 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 29 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 15 |
8 files changed, 294 insertions, 4 deletions
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index c75acbe2..b0d73241 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -127 +129 diff --git a/src/generator.ml b/src/generator.ml index 5885ff3f..27a75868 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2599,6 +2599,30 @@ subdirectories (recursively). The result is the estimated size in I<kilobytes> (ie. units of 1024 bytes)."); + ("initrd_list", (RStringList "filenames", [String "path"]), 128, [], + [InitBasicFS, Always, TestOutputList ( + [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"]; + ["initrd_list"; "/initrd"]], ["empty";"known-1";"known-2";"known-3"])], + "list files in an initrd", + "\ +This command lists out files contained in an initrd. + +The files are listed without any initial C</> character. The +files are listed in the order they appear (not necessarily +alphabetical). Directory names are listed as separate items. + +Old Linux kernels (2.4 and earlier) used a compressed ext2 +filesystem as initrd. We I<only> support the newer initramfs +format (compressed cpio files)."); + + ("mount_loop", (RErr, [String "file"; String "mountpoint"]), 129, [], + [], + "mount a file using the loop device", + "\ +This command lets you mount C<file> (a filesystem image +in a file) on a mount point. It is entirely equivalent to +the command C<mount -o loop file mountpoint>."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index b34c8017..94a08629 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -11649,3 +11649,189 @@ int64_t guestfs_du (guestfs_h *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; +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index 3c983325..c0002662 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -198,3 +198,5 @@ extern char **guestfs_tail_n (guestfs_h *handle, int nrlines, const char *path); extern char *guestfs_df (guestfs_h *handle); 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); diff --git a/src/guestfs.c b/src/guestfs.c index fdf5cd36..016d8035 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -1677,7 +1677,7 @@ static void sock_write_event (struct guestfs_main_loop *ml, guestfs_h *g, void *data, int watch, int fd, int events) { - int n; + int n, err; if (g->verbose) fprintf (stderr, @@ -1701,8 +1701,11 @@ sock_write_event (struct guestfs_main_loop *ml, guestfs_h *g, void *data, n = write (g->sock, g->msg_out + g->msg_out_pos, g->msg_out_size - g->msg_out_pos); if (n == -1) { - if (errno != EAGAIN) + err = errno; + if (err != EAGAIN) perrorf (g, "write"); + if (err == EPIPE) /* Disconnected from guest (RHBZ#508713). */ + child_cleanup (g); return; } diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index 050d9282..9b12986c 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -2171,6 +2171,39 @@ xdr_guestfs_du_ret (XDR *xdrs, guestfs_du_ret *objp) } bool_t +xdr_guestfs_initrd_list_args (XDR *xdrs, guestfs_initrd_list_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->path, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_initrd_list_ret (XDR *xdrs, guestfs_initrd_list_ret *objp) +{ + register int32_t *buf; + + if (!xdr_array (xdrs, (char **)&objp->filenames.filenames_val, (u_int *) &objp->filenames.filenames_len, ~0, + sizeof (str), (xdrproc_t) xdr_str)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_mount_loop_args (XDR *xdrs, guestfs_mount_loop_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->file, ~0)) + return FALSE; + if (!xdr_string (xdrs, &objp->mountpoint, ~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 c8231a0d..d127b884 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -1111,6 +1111,25 @@ struct guestfs_du_ret { }; typedef struct guestfs_du_ret guestfs_du_ret; +struct guestfs_initrd_list_args { + char *path; +}; +typedef struct guestfs_initrd_list_args guestfs_initrd_list_args; + +struct guestfs_initrd_list_ret { + struct { + u_int filenames_len; + str *filenames_val; + } filenames; +}; +typedef struct guestfs_initrd_list_ret guestfs_initrd_list_ret; + +struct guestfs_mount_loop_args { + char *file; + char *mountpoint; +}; +typedef struct guestfs_mount_loop_args guestfs_mount_loop_args; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -1239,7 +1258,9 @@ enum guestfs_procedure { GUESTFS_PROC_DF = 125, GUESTFS_PROC_DF_H = 126, GUESTFS_PROC_DU = 127, - GUESTFS_PROC_NR_PROCS = 127 + 1, + GUESTFS_PROC_INITRD_LIST = 128, + GUESTFS_PROC_MOUNT_LOOP = 129, + GUESTFS_PROC_NR_PROCS = 129 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1469,6 +1490,9 @@ extern bool_t xdr_guestfs_df_ret (XDR *, guestfs_df_ret*); extern bool_t xdr_guestfs_df_h_ret (XDR *, guestfs_df_h_ret*); extern bool_t xdr_guestfs_du_args (XDR *, guestfs_du_args*); 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_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*); @@ -1657,6 +1681,9 @@ extern bool_t xdr_guestfs_df_ret (); extern bool_t xdr_guestfs_df_h_ret (); extern bool_t xdr_guestfs_du_args (); 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_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 a895b6d5..fdc67c15 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -850,6 +850,19 @@ struct guestfs_du_ret { hyper sizekb; }; +struct guestfs_initrd_list_args { + string path<>; +}; + +struct guestfs_initrd_list_ret { + str filenames<>; +}; + +struct guestfs_mount_loop_args { + string file<>; + string mountpoint<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -978,6 +991,8 @@ enum guestfs_procedure { GUESTFS_PROC_DF = 125, GUESTFS_PROC_DF_H = 126, GUESTFS_PROC_DU = 127, + GUESTFS_PROC_INITRD_LIST = 128, + GUESTFS_PROC_MOUNT_LOOP = 129, GUESTFS_PROC_NR_PROCS }; |