diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-05-01 11:18:53 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-05-01 11:18:53 +0100 |
commit | 9222136ac9b2e404dba128b1ac74dacaa8bf1038 (patch) | |
tree | 84d74f0c966b925c3e22bf3322256df10455d94b /src | |
parent | 2dc9e8a858b62830d15a8186fe575eb7903d2171 (diff) | |
download | libguestfs-9222136ac9b2e404dba128b1ac74dacaa8bf1038.tar.gz libguestfs-9222136ac9b2e404dba128b1ac74dacaa8bf1038.tar.xz libguestfs-9222136ac9b2e404dba128b1ac74dacaa8bf1038.zip |
Generated code for drop-caches command.
Diffstat (limited to 'src')
-rw-r--r-- | src/guestfs-actions.c | 86 | ||||
-rw-r--r-- | src/guestfs-actions.h | 1 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 10 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 10 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 5 |
5 files changed, 111 insertions, 1 deletions
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index 49923551..99f8a446 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -8080,3 +8080,89 @@ int guestfs_mv (guestfs_h *g, return 0; } +struct drop_caches_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 drop_caches_reply_cb (guestfs_h *g, void *data, XDR *xdr) +{ + guestfs_main_loop *ml = guestfs_get_main_loop (g); + struct drop_caches_ctx *ctx = (struct drop_caches_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_drop_caches"); + return; + } + + ml->main_loop_quit (ml, g); + + if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) { + error (g, "%s: failed to parse reply header", "guestfs_drop_caches"); + 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_drop_caches"); + return; + } + goto done; + } + done: + ctx->cb_sequence = 1; +} + +int guestfs_drop_caches (guestfs_h *g, + int whattodrop) +{ + struct guestfs_drop_caches_args args; + struct drop_caches_ctx ctx; + guestfs_main_loop *ml = guestfs_get_main_loop (g); + int serial; + + if (check_state (g, "guestfs_drop_caches") == -1) return -1; + guestfs_set_busy (g); + + memset (&ctx, 0, sizeof ctx); + + args.whattodrop = whattodrop; + serial = guestfs__send_sync (g, GUESTFS_PROC_DROP_CACHES, + (xdrproc_t) xdr_guestfs_drop_caches_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, drop_caches_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_drop_caches"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DROP_CACHES, 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 56088bae..ef4e775c 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -129,3 +129,4 @@ extern int guestfs_grub_install (guestfs_h *handle, const char *root, const char extern int guestfs_cp (guestfs_h *handle, const char *src, const char *dest); extern int guestfs_cp_a (guestfs_h *handle, const char *src, const char *dest); extern int guestfs_mv (guestfs_h *handle, const char *src, const char *dest); +extern int guestfs_drop_caches (guestfs_h *handle, int whattodrop); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index 6c00afc3..395e710f 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -1508,6 +1508,16 @@ xdr_guestfs_mv_args (XDR *xdrs, guestfs_mv_args *objp) } bool_t +xdr_guestfs_drop_caches_args (XDR *xdrs, guestfs_drop_caches_args *objp) +{ + register int32_t *buf; + + if (!xdr_int (xdrs, &objp->whattodrop)) + 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 d2c93b99..a3bf1855 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -779,6 +779,11 @@ struct guestfs_mv_args { }; typedef struct guestfs_mv_args guestfs_mv_args; +struct guestfs_drop_caches_args { + int whattodrop; +}; +typedef struct guestfs_drop_caches_args guestfs_drop_caches_args; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -869,7 +874,8 @@ enum guestfs_procedure { GUESTFS_PROC_CP = 87, GUESTFS_PROC_CP_A = 88, GUESTFS_PROC_MV = 89, - GUESTFS_PROC_NR_PROCS = 89 + 1, + GUESTFS_PROC_DROP_CACHES = 90, + GUESTFS_PROC_NR_PROCS = 90 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1041,6 +1047,7 @@ extern bool_t xdr_guestfs_grub_install_args (XDR *, guestfs_grub_install_args*) extern bool_t xdr_guestfs_cp_args (XDR *, guestfs_cp_args*); extern bool_t xdr_guestfs_cp_a_args (XDR *, guestfs_cp_a_args*); extern bool_t xdr_guestfs_mv_args (XDR *, guestfs_mv_args*); +extern bool_t xdr_guestfs_drop_caches_args (XDR *, guestfs_drop_caches_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*); @@ -1171,6 +1178,7 @@ extern bool_t xdr_guestfs_grub_install_args (); extern bool_t xdr_guestfs_cp_args (); extern bool_t xdr_guestfs_cp_a_args (); extern bool_t xdr_guestfs_mv_args (); +extern bool_t xdr_guestfs_drop_caches_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 1a6a2d70..68b0ac4d 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -606,6 +606,10 @@ struct guestfs_mv_args { string dest<>; }; +struct guestfs_drop_caches_args { + int whattodrop; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -696,6 +700,7 @@ enum guestfs_procedure { GUESTFS_PROC_CP = 87, GUESTFS_PROC_CP_A = 88, GUESTFS_PROC_MV = 89, + GUESTFS_PROC_DROP_CACHES = 90, GUESTFS_PROC_NR_PROCS }; |