extern int do_cp (const char *src, const char *dest);
extern int do_cp_a (const char *src, const char *dest);
extern int do_mv (const char *src, const char *dest);
+extern int do_drop_caches (int whattodrop);
xdr_free ((xdrproc_t) xdr_guestfs_mv_args, (char *) &args);
}
+static void drop_caches_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_drop_caches_args args;
+ int whattodrop;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_drop_caches_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "drop_caches");
+ return;
+ }
+ whattodrop = args.whattodrop;
+
+ r = do_drop_caches (whattodrop);
+ if (r == -1)
+ /* do_drop_caches has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_drop_caches_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_MV:
mv_stub (xdr_in);
break;
+ case GUESTFS_PROC_DROP_CACHES:
+ drop_caches_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
}
printf ("%-20s %s\n", "cp-a", "copy a file or directory recursively");
printf ("%-20s %s\n", "debug", "debugging and internals");
printf ("%-20s %s\n", "download", "download a file to the local machine");
+ printf ("%-20s %s\n", "drop-caches", "drop kernel page cache, dentries and inodes");
printf ("%-20s %s\n", "exists", "test if file or directory exists");
printf ("%-20s %s\n", "file", "determine file type");
printf ("%-20s %s\n", "fsck", "run the filesystem checker");
if (strcasecmp (cmd, "mv") == 0)
pod2text ("mv - move a file", " mv <src> <dest>\n\nThis moves a file from C<src> to C<dest> where C<dest> is\neither a destination filename or destination directory.");
else
+ if (strcasecmp (cmd, "drop_caches") == 0 || strcasecmp (cmd, "drop-caches") == 0)
+ pod2text ("drop-caches - drop kernel page cache, dentries and inodes", " drop-caches <whattodrop>\n\nThis instructs the guest kernel to drop its page cache,\nand/or dentries and inode caches. The parameter C<whattodrop>\ntells the kernel what precisely to drop, see\nL<http://linux-mm.org/Drop_Caches>\n\nSetting C<whattodrop> to 3 should drop everything.\n\nThis automatically calls L<sync(2)> before the operation,\nso that the maximum guest memory is freed.");
+ else
display_builtin_command (cmd);
}
return r;
}
+static int run_drop_caches (const char *cmd, int argc, char *argv[])
+{
+ int r;
+ int whattodrop;
+ if (argc != 1) {
+ fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ whattodrop = atoi (argv[0]);
+ r = guestfs_drop_caches (g, whattodrop);
+ return r;
+}
+
int run_action (const char *cmd, int argc, char *argv[])
{
if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
if (strcasecmp (cmd, "mv") == 0)
return run_mv (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "drop_caches") == 0 || strcasecmp (cmd, "drop-caches") == 0)
+ return run_drop_caches (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"cp-a",
"debug",
"download",
+ "drop-caches",
"exists",
"file",
"fsck",
Use C<-> instead of a filename to read/write from stdin/stdout.
+=head2 drop-caches
+
+ drop-caches whattodrop
+
+This instructs the guest kernel to drop its page cache,
+and/or dentries and inode caches. The parameter C<whattodrop>
+tells the kernel what precisely to drop, see
+L<http://linux-mm.org/Drop_Caches>
+
+Setting C<whattodrop> to 3 should drop everything.
+
+This automatically calls L<sync(2)> before the operation,
+so that the maximum guest memory is freed.
+
=head2 exists
exists path
This function returns 0 on success or -1 on error.
+=head2 guestfs_drop_caches
+
+ int guestfs_drop_caches (guestfs_h *handle,
+ int whattodrop);
+
+This instructs the guest kernel to drop its page cache,
+and/or dentries and inode caches. The parameter C<whattodrop>
+tells the kernel what precisely to drop, see
+L<http://linux-mm.org/Drop_Caches>
+
+Setting C<whattodrop> to 3 should drop everything.
+
+This automatically calls L<sync(2)> before the operation,
+so that the maximum guest memory is freed.
+
+This function returns 0 on success or -1 on error.
+
=head2 guestfs_exists
int guestfs_exists (guestfs_h *handle,
private native void _mv (long g, String src, String dest)
throws LibGuestFSException;
+ /**
+ * drop kernel page cache, dentries and inodes
+ *
+ * This instructs the guest kernel to drop its page cache,
+ * and/or dentries and inode caches. The parameter
+ * "whattodrop" tells the kernel what precisely to drop,
+ * see <http://linux-mm.org/Drop_Caches>
+ *
+ * Setting "whattodrop" to 3 should drop everything.
+ *
+ * This automatically calls sync(2) before the operation,
+ * so that the maximum guest memory is freed.
+ *
+ * @throws LibGuestFSException
+ */
+ public void drop_caches (int whattodrop)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("drop_caches: handle is closed");
+ _drop_caches (g, whattodrop);
+ }
+ private native void _drop_caches (long g, int whattodrop)
+ throws LibGuestFSException;
+
}
}
}
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1drop_1caches
+ (JNIEnv *env, jobject obj, jlong jg, jint jwhattodrop)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ int r;
+ int whattodrop;
+
+ whattodrop = jwhattodrop;
+ r = guestfs_drop_caches (g, whattodrop);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
external cp : t -> string -> string -> unit = "ocaml_guestfs_cp"
external cp_a : t -> string -> string -> unit = "ocaml_guestfs_cp_a"
external mv : t -> string -> string -> unit = "ocaml_guestfs_mv"
+external drop_caches : t -> int -> unit = "ocaml_guestfs_drop_caches"
val mv : t -> string -> string -> unit
(** move a file *)
+val drop_caches : t -> int -> unit
+(** drop kernel page cache, dentries and inodes *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_drop_caches (value gv, value whattodropv)
+{
+ CAMLparam2 (gv, whattodropv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("drop_caches: used handle after closing it");
+
+ int whattodrop = Int_val (whattodropv);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_drop_caches (g, whattodrop);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "drop_caches");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
if (r == -1)
croak ("mv: %s", guestfs_last_error (g));
+void
+drop_caches (g, whattodrop)
+ guestfs_h *g;
+ int whattodrop;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_drop_caches (g, whattodrop);
+ if (r == -1)
+ croak ("drop_caches: %s", guestfs_last_error (g));
+
See also C<$h-E<gt>upload>, C<$h-E<gt>cat>.
+=item $h->drop_caches ($whattodrop);
+
+This instructs the guest kernel to drop its page cache,
+and/or dentries and inode caches. The parameter C<whattodrop>
+tells the kernel what precisely to drop, see
+L<http://linux-mm.org/Drop_Caches>
+
+Setting C<whattodrop> to 3 should drop everything.
+
+This automatically calls L<sync(2)> before the operation,
+so that the maximum guest memory is freed.
+
=item $existsflag = $h->exists ($path);
This returns C<true> if and only if there is a file, directory
return py_r;
}
+static PyObject *
+py_guestfs_drop_caches (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ int r;
+ int whattodrop;
+
+ if (!PyArg_ParseTuple (args, (char *) "Oi:guestfs_drop_caches",
+ &py_g, &whattodrop))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_drop_caches (g, whattodrop);
+ if (r == -1) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ Py_INCREF (Py_None);
+ py_r = Py_None;
+ return py_r;
+}
+
static PyMethodDef methods[] = {
{ (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
{ (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
{ (char *) "cp", py_guestfs_cp, METH_VARARGS, NULL },
{ (char *) "cp_a", py_guestfs_cp_a, METH_VARARGS, NULL },
{ (char *) "mv", py_guestfs_mv, METH_VARARGS, NULL },
+ { (char *) "drop_caches", py_guestfs_drop_caches, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
"""
return libguestfsmod.mv (self._o, src, dest)
+ def drop_caches (self, whattodrop):
+ u"""This instructs the guest kernel to drop its page cache,
+ and/or dentries and inode caches. The parameter
+ "whattodrop" tells the kernel what precisely to drop,
+ see <http://linux-mm.org/Drop_Caches>
+
+ Setting "whattodrop" to 3 should drop everything.
+
+ This automatically calls sync(2) before the operation,
+ so that the maximum guest memory is freed.
+ """
+ return libguestfsmod.drop_caches (self._o, whattodrop)
+
return Qnil;
}
+static VALUE ruby_guestfs_drop_caches (VALUE gv, VALUE whattodropv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "drop_caches");
+
+ int whattodrop = NUM2INT (whattodropv);
+
+ int r;
+
+ r = guestfs_drop_caches (g, whattodrop);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
/* Initialize the module. */
void Init__guestfs ()
{
ruby_guestfs_cp_a, 2);
rb_define_method (c_guestfs, "mv",
ruby_guestfs_mv, 2);
+ rb_define_method (c_guestfs, "drop_caches",
+ ruby_guestfs_drop_caches, 1);
}
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;
+}
+
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);
}
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;
};
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,
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
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*);
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 ();
string dest<>;
};
+struct guestfs_drop_caches_args {
+ int whattodrop;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_CP = 87,
GUESTFS_PROC_CP_A = 88,
GUESTFS_PROC_MV = 89,
+ GUESTFS_PROC_DROP_CACHES = 90,
GUESTFS_PROC_NR_PROCS
};
fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n");
}
+static int test_drop_caches_0 (void)
+{
+ /* InitEmpty for drop_caches (0) */
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ /* TestRun for drop_caches (0) */
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_drop_caches (g, 3);
+ if (r == -1)
+ return -1;
+ }
+ return 0;
+}
+
static int test_mv_0 (void)
{
/* InitBasicFS for mv (0): create ext2 on /dev/sda1 */
exit (1);
}
- nr_tests = 101;
+ nr_tests = 102;
test_num++;
+ printf ("%3d/%3d test_drop_caches_0\n", test_num, nr_tests);
+ if (test_drop_caches_0 () == -1) {
+ printf ("test_drop_caches_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
printf ("%3d/%3d test_mv_0\n", test_num, nr_tests);
if (test_mv_0 () == -1) {
printf ("test_mv_0 FAILED\n");