diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-06-29 12:26:11 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-06-29 12:26:11 +0100 |
commit | b2ed0f4c55c2bd3d07341ba2207f0cb238eb4e18 (patch) | |
tree | 1a8afad7895f932501ff806a5dd3bfc9f2ed5f26 /src | |
parent | 405cf2a5772611ea05cca9fefa843154a9bc64a3 (diff) | |
download | libguestfs-b2ed0f4c55c2bd3d07341ba2207f0cb238eb4e18.tar.gz libguestfs-b2ed0f4c55c2bd3d07341ba2207f0cb238eb4e18.tar.xz libguestfs-b2ed0f4c55c2bd3d07341ba2207f0cb238eb4e18.zip |
Generated code for df / df-h.
Diffstat (limited to 'src')
-rw-r--r-- | src/MAX_PROC_NR | 2 | ||||
-rw-r--r-- | src/guestfs-actions.c | 176 | ||||
-rw-r--r-- | src/guestfs-actions.h | 2 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 20 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 18 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 10 |
6 files changed, 226 insertions, 2 deletions
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index fc902f4f..0a3e7b04 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -124 +126 diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index 4a38b453..745a52bc 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -11381,3 +11381,179 @@ char **guestfs_tail_n (guestfs_h *g, return ctx.ret.lines.lines_val; } +struct df_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_df_ret ret; +}; + +static void df_reply_cb (guestfs_h *g, void *data, XDR *xdr) +{ + guestfs_main_loop *ml = guestfs_get_main_loop (g); + struct df_ctx *ctx = (struct df_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_df"); + return; + } + + ml->main_loop_quit (ml, g); + + if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) { + error (g, "%s: failed to parse reply header", "guestfs_df"); + 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_df"); + return; + } + goto done; + } + if (!xdr_guestfs_df_ret (xdr, &ctx->ret)) { + error (g, "%s: failed to parse reply", "guestfs_df"); + return; + } + done: + ctx->cb_sequence = 1; +} + +char *guestfs_df (guestfs_h *g) +{ + struct df_ctx ctx; + guestfs_main_loop *ml = guestfs_get_main_loop (g); + int serial; + + if (check_state (g, "guestfs_df") == -1) return NULL; + guestfs_set_busy (g); + + memset (&ctx, 0, sizeof ctx); + + serial = guestfs__send_sync (g, GUESTFS_PROC_DF, NULL, NULL); + if (serial == -1) { + guestfs_end_busy (g); + return NULL; + } + + guestfs__switch_to_receiving (g); + ctx.cb_sequence = 0; + guestfs_set_reply_callback (g, df_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_df"); + guestfs_end_busy (g); + return NULL; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DF, 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); + return ctx.ret.output; /* caller will free */ +} + +struct df_h_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_df_h_ret ret; +}; + +static void df_h_reply_cb (guestfs_h *g, void *data, XDR *xdr) +{ + guestfs_main_loop *ml = guestfs_get_main_loop (g); + struct df_h_ctx *ctx = (struct df_h_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_df_h"); + return; + } + + ml->main_loop_quit (ml, g); + + if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) { + error (g, "%s: failed to parse reply header", "guestfs_df_h"); + 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_df_h"); + return; + } + goto done; + } + if (!xdr_guestfs_df_h_ret (xdr, &ctx->ret)) { + error (g, "%s: failed to parse reply", "guestfs_df_h"); + return; + } + done: + ctx->cb_sequence = 1; +} + +char *guestfs_df_h (guestfs_h *g) +{ + struct df_h_ctx ctx; + guestfs_main_loop *ml = guestfs_get_main_loop (g); + int serial; + + if (check_state (g, "guestfs_df_h") == -1) return NULL; + guestfs_set_busy (g); + + memset (&ctx, 0, sizeof ctx); + + serial = guestfs__send_sync (g, GUESTFS_PROC_DF_H, NULL, NULL); + if (serial == -1) { + guestfs_end_busy (g); + return NULL; + } + + guestfs__switch_to_receiving (g); + ctx.cb_sequence = 0; + guestfs_set_reply_callback (g, df_h_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_df_h"); + guestfs_end_busy (g); + return NULL; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DF_H, 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); + return ctx.ret.output; /* caller will free */ +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index 42951cbc..cbf5ff76 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -195,3 +195,5 @@ extern char **guestfs_head (guestfs_h *handle, const char *path); extern char **guestfs_head_n (guestfs_h *handle, int nrlines, const char *path); extern char **guestfs_tail (guestfs_h *handle, const char *path); 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); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index 3f08084d..2830bf2a 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -2131,6 +2131,26 @@ xdr_guestfs_tail_n_ret (XDR *xdrs, guestfs_tail_n_ret *objp) } bool_t +xdr_guestfs_df_ret (XDR *xdrs, guestfs_df_ret *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->output, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_df_h_ret (XDR *xdrs, guestfs_df_h_ret *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->output, ~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 7fe3a32a..16db25af 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -1091,6 +1091,16 @@ struct guestfs_tail_n_ret { }; typedef struct guestfs_tail_n_ret guestfs_tail_n_ret; +struct guestfs_df_ret { + char *output; +}; +typedef struct guestfs_df_ret guestfs_df_ret; + +struct guestfs_df_h_ret { + char *output; +}; +typedef struct guestfs_df_h_ret guestfs_df_h_ret; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -1216,7 +1226,9 @@ enum guestfs_procedure { GUESTFS_PROC_HEAD_N = 122, GUESTFS_PROC_TAIL = 123, GUESTFS_PROC_TAIL_N = 124, - GUESTFS_PROC_NR_PROCS = 124 + 1, + GUESTFS_PROC_DF = 125, + GUESTFS_PROC_DF_H = 126, + GUESTFS_PROC_NR_PROCS = 126 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1442,6 +1454,8 @@ extern bool_t xdr_guestfs_tail_args (XDR *, guestfs_tail_args*); extern bool_t xdr_guestfs_tail_ret (XDR *, guestfs_tail_ret*); extern bool_t xdr_guestfs_tail_n_args (XDR *, guestfs_tail_n_args*); extern bool_t xdr_guestfs_tail_n_ret (XDR *, guestfs_tail_n_ret*); +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_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*); @@ -1626,6 +1640,8 @@ extern bool_t xdr_guestfs_tail_args (); extern bool_t xdr_guestfs_tail_ret (); extern bool_t xdr_guestfs_tail_n_args (); extern bool_t xdr_guestfs_tail_n_ret (); +extern bool_t xdr_guestfs_df_ret (); +extern bool_t xdr_guestfs_df_h_ret (); 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 fd8953f1..702df5bf 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -834,6 +834,14 @@ struct guestfs_tail_n_ret { str lines<>; }; +struct guestfs_df_ret { + string output<>; +}; + +struct guestfs_df_h_ret { + string output<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -959,6 +967,8 @@ enum guestfs_procedure { GUESTFS_PROC_HEAD_N = 122, GUESTFS_PROC_TAIL = 123, GUESTFS_PROC_TAIL_N = 124, + GUESTFS_PROC_DF = 125, + GUESTFS_PROC_DF_H = 126, GUESTFS_PROC_NR_PROCS }; |