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);
+extern char *do_dmesg (void);
xdr_free ((xdrproc_t) xdr_guestfs_drop_caches_args, (char *) &args);
}
+static void dmesg_stub (XDR *xdr_in)
+{
+ char *r;
+
+ r = do_dmesg ();
+ if (r == NULL)
+ /* do_dmesg has already called reply_with_error */
+ goto done;
+
+ struct guestfs_dmesg_ret ret;
+ ret.kmsgs = r;
+ reply ((xdrproc_t) &xdr_guestfs_dmesg_ret, (char *) &ret);
+ free (r);
+done: ;
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_DROP_CACHES:
drop_caches_stub (xdr_in);
break;
+ case GUESTFS_PROC_DMESG:
+ dmesg_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
}
printf ("%-20s %s\n", "cp", "copy a file");
printf ("%-20s %s\n", "cp-a", "copy a file or directory recursively");
printf ("%-20s %s\n", "debug", "debugging and internals");
+ printf ("%-20s %s\n", "dmesg", "return kernel messages");
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");
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
+ if (strcasecmp (cmd, "dmesg") == 0)
+ pod2text ("dmesg - return kernel messages", " dmesg\n\nThis returns the kernel messages (C<dmesg> output) from\nthe guest kernel. This is sometimes useful for extended\ndebugging of problems.\n\nAnother way to get the same information is to enable\nverbose messages with C<set_verbose> or by setting\nthe environment variable C<LIBGUESTFS_DEBUG=1> before\nrunning the program.");
+ else
display_builtin_command (cmd);
}
return r;
}
+static int run_dmesg (const char *cmd, int argc, char *argv[])
+{
+ char *r;
+ if (argc != 0) {
+ fprintf (stderr, "%s should have 0 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ r = guestfs_dmesg (g);
+ if (r == NULL) return -1;
+ printf ("%s\n", r);
+ free (r);
+ return 0;
+}
+
int run_action (const char *cmd, int argc, char *argv[])
{
if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
if (strcasecmp (cmd, "drop_caches") == 0 || strcasecmp (cmd, "drop-caches") == 0)
return run_drop_caches (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "dmesg") == 0)
+ return run_dmesg (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"cp",
"cp-a",
"debug",
+ "dmesg",
"download",
"drop-caches",
"exists",
to look at the file C<daemon/debug.c> in the libguestfs source
to find out what you can do.
+=head2 dmesg
+
+ dmesg
+
+This returns the kernel messages (C<dmesg> output) from
+the guest kernel. This is sometimes useful for extended
+debugging of problems.
+
+Another way to get the same information is to enable
+verbose messages with C<set-verbose> or by setting
+the environment variable C<LIBGUESTFS_DEBUG=1> before
+running the program.
+
=head2 download
download remotefilename (filename|-)
This function returns a string, or NULL on error.
I<The caller must free the returned string after use>.
+=head2 guestfs_dmesg
+
+ char *guestfs_dmesg (guestfs_h *handle);
+
+This returns the kernel messages (C<dmesg> output) from
+the guest kernel. This is sometimes useful for extended
+debugging of problems.
+
+Another way to get the same information is to enable
+verbose messages with C<guestfs_set_verbose> or by setting
+the environment variable C<LIBGUESTFS_DEBUG=1> before
+running the program.
+
+This function returns a string, or NULL on error.
+I<The caller must free the returned string after use>.
+
=head2 guestfs_download
int guestfs_download (guestfs_h *handle,
private native void _drop_caches (long g, int whattodrop)
throws LibGuestFSException;
+ /**
+ * return kernel messages
+ *
+ * This returns the kernel messages ("dmesg" output) from
+ * the guest kernel. This is sometimes useful for extended
+ * debugging of problems.
+ *
+ * Another way to get the same information is to enable
+ * verbose messages with "g.set_verbose" or by setting the
+ * environment variable "LIBGUESTFS_DEBUG=1" before running
+ * the program.
+ *
+ * @throws LibGuestFSException
+ */
+ public String dmesg ()
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("dmesg: handle is closed");
+ return _dmesg (g);
+ }
+ private native String _dmesg (long g)
+ throws LibGuestFSException;
+
}
}
}
+JNIEXPORT jstring JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1dmesg
+ (JNIEnv *env, jobject obj, jlong jg)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ jstring jr;
+ char *r;
+
+ r = guestfs_dmesg (g);
+ if (r == NULL) {
+ throw_exception (env, guestfs_last_error (g));
+ return NULL;
+ }
+ jr = (*env)->NewStringUTF (env, r);
+ free (r);
+ return jr;
+}
+
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"
+external dmesg : t -> string = "ocaml_guestfs_dmesg"
val drop_caches : t -> int -> unit
(** drop kernel page cache, dentries and inodes *)
+val dmesg : t -> string
+(** return kernel messages *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_dmesg (value gv)
+{
+ CAMLparam1 (gv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("dmesg: used handle after closing it");
+
+ char *r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_dmesg (g);
+ caml_leave_blocking_section ();
+ if (r == NULL)
+ ocaml_guestfs_raise_error (g, "dmesg");
+
+ rv = caml_copy_string (r);
+ free (r);
+ CAMLreturn (rv);
+}
+
if (r == -1)
croak ("drop_caches: %s", guestfs_last_error (g));
+SV *
+dmesg (g)
+ guestfs_h *g;
+PREINIT:
+ char *kmsgs;
+ CODE:
+ kmsgs = guestfs_dmesg (g);
+ if (kmsgs == NULL)
+ croak ("dmesg: %s", guestfs_last_error (g));
+ RETVAL = newSVpv (kmsgs, 0);
+ free (kmsgs);
+ OUTPUT:
+ RETVAL
+
to look at the file C<daemon/debug.c> in the libguestfs source
to find out what you can do.
+=item $kmsgs = $h->dmesg ();
+
+This returns the kernel messages (C<dmesg> output) from
+the guest kernel. This is sometimes useful for extended
+debugging of problems.
+
+Another way to get the same information is to enable
+verbose messages with C<$h-E<gt>set_verbose> or by setting
+the environment variable C<LIBGUESTFS_DEBUG=1> before
+running the program.
+
=item $h->download ($remotefilename, $filename);
Download file C<remotefilename> and save it as C<filename>
return py_r;
}
+static PyObject *
+py_guestfs_dmesg (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ char *r;
+
+ if (!PyArg_ParseTuple (args, (char *) "O:guestfs_dmesg",
+ &py_g))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_dmesg (g);
+ if (r == NULL) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ py_r = PyString_FromString (r);
+ free (r);
+ return py_r;
+}
+
static PyMethodDef methods[] = {
{ (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
{ (char *) "close", py_guestfs_close, 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 },
+ { (char *) "dmesg", py_guestfs_dmesg, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
"""
return libguestfsmod.drop_caches (self._o, whattodrop)
+ def dmesg (self):
+ u"""This returns the kernel messages ("dmesg" output) from
+ the guest kernel. This is sometimes useful for extended
+ debugging of problems.
+
+ Another way to get the same information is to enable
+ verbose messages with "g.set_verbose" or by setting the
+ environment variable "LIBGUESTFS_DEBUG=1" before running
+ the program.
+ """
+ return libguestfsmod.dmesg (self._o)
+
return Qnil;
}
+static VALUE ruby_guestfs_dmesg (VALUE gv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "dmesg");
+
+
+ char *r;
+
+ r = guestfs_dmesg (g);
+ if (r == NULL)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ VALUE rv = rb_str_new2 (r);
+ free (r);
+ return rv;
+}
+
/* Initialize the module. */
void Init__guestfs ()
{
ruby_guestfs_mv, 2);
rb_define_method (c_guestfs, "drop_caches",
ruby_guestfs_drop_caches, 1);
+ rb_define_method (c_guestfs, "dmesg",
+ ruby_guestfs_dmesg, 0);
}
return 0;
}
+struct dmesg_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_dmesg_ret ret;
+};
+
+static void dmesg_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct dmesg_ctx *ctx = (struct dmesg_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_dmesg");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_dmesg");
+ 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_dmesg");
+ return;
+ }
+ goto done;
+ }
+ if (!xdr_guestfs_dmesg_ret (xdr, &ctx->ret)) {
+ error (g, "%s: failed to parse reply", "guestfs_dmesg");
+ return;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+char *guestfs_dmesg (guestfs_h *g)
+{
+ struct dmesg_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_dmesg") == -1) return NULL;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ serial = guestfs__send_sync (g, GUESTFS_PROC_DMESG, NULL, NULL);
+ if (serial == -1) {
+ guestfs_set_ready (g);
+ return NULL;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, dmesg_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_dmesg");
+ guestfs_set_ready (g);
+ return NULL;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DMESG, serial) == -1) {
+ guestfs_set_ready (g);
+ return NULL;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ guestfs_set_ready (g);
+ return NULL;
+ }
+
+ guestfs_set_ready (g);
+ return ctx.ret.kmsgs; /* caller will free */
+}
+
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);
+extern char *guestfs_dmesg (guestfs_h *handle);
}
bool_t
+xdr_guestfs_dmesg_ret (XDR *xdrs, guestfs_dmesg_ret *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->kmsgs, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
{
register int32_t *buf;
};
typedef struct guestfs_drop_caches_args guestfs_drop_caches_args;
+struct guestfs_dmesg_ret {
+ char *kmsgs;
+};
+typedef struct guestfs_dmesg_ret guestfs_dmesg_ret;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_CP_A = 88,
GUESTFS_PROC_MV = 89,
GUESTFS_PROC_DROP_CACHES = 90,
- GUESTFS_PROC_NR_PROCS = 90 + 1,
+ GUESTFS_PROC_DMESG = 91,
+ GUESTFS_PROC_NR_PROCS = 91 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
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_dmesg_ret (XDR *, guestfs_dmesg_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*);
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_dmesg_ret ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
int whattodrop;
};
+struct guestfs_dmesg_ret {
+ string kmsgs<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_CP_A = 88,
GUESTFS_PROC_MV = 89,
GUESTFS_PROC_DROP_CACHES = 90,
+ GUESTFS_PROC_DMESG = 91,
GUESTFS_PROC_NR_PROCS
};
fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n");
}
+static int test_dmesg_0 (void)
+{
+ /* InitEmpty for dmesg (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 dmesg (0) */
+ {
+ char *r;
+ suppress_error = 0;
+ r = guestfs_dmesg (g);
+ if (r == NULL)
+ return -1;
+ free (r);
+ }
+ return 0;
+}
+
static int test_drop_caches_0 (void)
{
/* InitEmpty for drop_caches (0) */
exit (1);
}
- nr_tests = 102;
+ nr_tests = 103;
test_num++;
+ printf ("%3d/%3d test_dmesg_0\n", test_num, nr_tests);
+ if (test_dmesg_0 () == -1) {
+ printf ("test_dmesg_0 FAILED\n");
+ failed++;
+ }
+ 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");