extern int do_mount_ro (const char *device, const char *mountpoint);
extern int do_mount_options (const char *options, const char *device, const char *mountpoint);
extern int do_mount_vfs (const char *options, const char *vfstype, const char *device, const char *mountpoint);
+extern char *do_debug (const char *subcmd, char * const* const extraargs);
xdr_free ((xdrproc_t) xdr_guestfs_mount_vfs_args, (char *) &args);
}
+static void debug_stub (XDR *xdr_in)
+{
+ char *r;
+ struct guestfs_debug_args args;
+ const char *subcmd;
+ char **extraargs;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_debug_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "debug");
+ return;
+ }
+ subcmd = args.subcmd;
+ args.extraargs.extraargs_val = realloc (args.extraargs.extraargs_val, sizeof (char *) * (args.extraargs.extraargs_len+1));
+ args.extraargs.extraargs_val[args.extraargs.extraargs_len] = NULL;
+ extraargs = args.extraargs.extraargs_val;
+
+ r = do_debug (subcmd, extraargs);
+ if (r == NULL)
+ /* do_debug has already called reply_with_error */
+ goto done;
+
+ struct guestfs_debug_ret ret;
+ ret.result = r;
+ reply ((xdrproc_t) &xdr_guestfs_debug_ret, (char *) &ret);
+ free (r);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_debug_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_MOUNT_VFS:
mount_vfs_stub (xdr_in);
break;
+ case GUESTFS_PROC_DEBUG:
+ debug_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
}
printf ("%-20s %s\n", "command", "run a command from the guest filesystem");
printf ("%-20s %s\n", "command-lines", "run a command, returning lines");
printf ("%-20s %s\n", "config", "add qemu parameters");
+ printf ("%-20s %s\n", "debug", "debugging and internals");
printf ("%-20s %s\n", "download", "download a file to the local machine");
printf ("%-20s %s\n", "exists", "test if file or directory exists");
printf ("%-20s %s\n", "file", "determine file type");
if (strcasecmp (cmd, "mount_vfs") == 0 || strcasecmp (cmd, "mount-vfs") == 0)
pod2text ("mount-vfs - mount a guest disk with mount options and vfstype", " mount-vfs <options> <vfstype> <device> <mountpoint>\n\nThis is the same as the C<mount> command, but it\nallows you to set both the mount options and the vfstype\nas for the L<mount(8)> I<-o> and I<-t> flags.");
else
+ if (strcasecmp (cmd, "debug") == 0)
+ pod2text ("debug - debugging and internals", " debug <subcmd> <extraargs>\n\nThe C<debug> command exposes some internals of\nC<guestfsd> (the guestfs daemon) that runs inside the\nqemu subprocess.\n\nThere is no comprehensive help for this command. You have\nto look at the file C<daemon/debug.c> in the libguestfs source\nto find out what you can do.");
+ else
display_builtin_command (cmd);
}
return r;
}
+static int run_debug (const char *cmd, int argc, char *argv[])
+{
+ char *r;
+ const char *subcmd;
+ char **extraargs;
+ if (argc != 2) {
+ fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ subcmd = argv[0];
+ extraargs = parse_string_list (argv[1]);
+ r = guestfs_debug (g, subcmd, extraargs);
+ 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, "mount_vfs") == 0 || strcasecmp (cmd, "mount-vfs") == 0)
return run_mount_vfs (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "debug") == 0)
+ return run_debug (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"command",
"command-lines",
"config",
+ "debug",
"download",
"exists",
"file",
C<value> can be NULL.
+=head2 debug
+
+ debug subcmd 'extraargs ...'
+
+The C<debug> command exposes some internals of
+C<guestfsd> (the guestfs daemon) that runs inside the
+qemu subprocess.
+
+There is no comprehensive help for this command. You have
+to look at the file C<daemon/debug.c> in the libguestfs source
+to find out what you can do.
+
=head2 download
download remotefilename (filename|-)
This function returns 0 on success or -1 on error.
+=head2 guestfs_debug
+
+ char *guestfs_debug (guestfs_h *handle,
+ const char *subcmd,
+ char * const* const extraargs);
+
+The C<guestfs_debug> command exposes some internals of
+C<guestfsd> (the guestfs daemon) that runs inside the
+qemu subprocess.
+
+There is no comprehensive help for this command. You have
+to look at the file C<daemon/debug.c> in the libguestfs source
+to find out what you can do.
+
+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 _mount_vfs (long g, String options, String vfstype, String device, String mountpoint)
throws LibGuestFSException;
+ /**
+ * debugging and internals
+ *
+ * The "g.debug" command exposes some internals of
+ * "guestfsd" (the guestfs daemon) that runs inside the
+ * qemu subprocess.
+ *
+ * There is no comprehensive help for this command. You
+ * have to look at the file "daemon/debug.c" in the
+ * libguestfs source to find out what you can do.
+ *
+ * @throws LibGuestFSException
+ */
+ public String debug (String subcmd, String[] extraargs)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("debug: handle is closed");
+ return _debug (g, subcmd, extraargs);
+ }
+ private native String _debug (long g, String subcmd, String[] extraargs)
+ throws LibGuestFSException;
+
}
}
}
+JNIEXPORT jstring JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1debug
+ (JNIEnv *env, jobject obj, jlong jg, jstring jsubcmd, jobjectArray jextraargs)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ jstring jr;
+ char *r;
+ const char *subcmd;
+ int extraargs_len;
+ const char **extraargs;
+ int i;
+
+ subcmd = (*env)->GetStringUTFChars (env, jsubcmd, NULL);
+ extraargs_len = (*env)->GetArrayLength (env, jextraargs);
+ extraargs = malloc (sizeof (char *) * (extraargs_len+1));
+ for (i = 0; i < extraargs_len; ++i) {
+ jobject o = (*env)->GetObjectArrayElement (env, jextraargs, i);
+ extraargs[i] = (*env)->GetStringUTFChars (env, o, NULL);
+ }
+ extraargs[extraargs_len] = NULL;
+ r = guestfs_debug (g, subcmd, extraargs);
+ (*env)->ReleaseStringUTFChars (env, jsubcmd, subcmd);
+ for (i = 0; i < extraargs_len; ++i) {
+ jobject o = (*env)->GetObjectArrayElement (env, jextraargs, i);
+ (*env)->ReleaseStringUTFChars (env, o, extraargs[i]);
+ }
+ free (extraargs);
+ if (r == NULL) {
+ throw_exception (env, guestfs_last_error (g));
+ return NULL;
+ }
+ jr = (*env)->NewStringUTF (env, r);
+ free (r);
+ return jr;
+}
+
external mount_ro : t -> string -> string -> unit = "ocaml_guestfs_mount_ro"
external mount_options : t -> string -> string -> string -> unit = "ocaml_guestfs_mount_options"
external mount_vfs : t -> string -> string -> string -> string -> unit = "ocaml_guestfs_mount_vfs"
+external debug : t -> string -> string array -> string = "ocaml_guestfs_debug"
val mount_vfs : t -> string -> string -> string -> string -> unit
(** mount a guest disk with mount options and vfstype *)
+val debug : t -> string -> string array -> string
+(** debugging and internals *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_debug (value gv, value subcmdv, value extraargsv)
+{
+ CAMLparam3 (gv, subcmdv, extraargsv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("debug: used handle after closing it");
+
+ const char *subcmd = String_val (subcmdv);
+ char **extraargs = ocaml_guestfs_strings_val (extraargsv);
+ char *r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_debug (g, subcmd, extraargs);
+ caml_leave_blocking_section ();
+ ocaml_guestfs_free_strings (extraargs);
+ if (r == NULL)
+ ocaml_guestfs_raise_error (g, "debug");
+
+ rv = caml_copy_string (r);
+ free (r);
+ CAMLreturn (rv);
+}
+
if (r == -1)
croak ("mount_vfs: %s", guestfs_last_error (g));
+SV *
+debug (g, subcmd, extraargs)
+ guestfs_h *g;
+ char *subcmd;
+ char **extraargs;
+PREINIT:
+ char *result;
+ CODE:
+ result = guestfs_debug (g, subcmd, extraargs);
+ free (extraargs);
+ if (result == NULL)
+ croak ("debug: %s", guestfs_last_error (g));
+ RETVAL = newSVpv (result, 0);
+ free (result);
+ OUTPUT:
+ RETVAL
+
C<value> can be NULL.
+=item $result = $h->debug ($subcmd, \@extraargs);
+
+The C<$h-E<gt>debug> command exposes some internals of
+C<guestfsd> (the guestfs daemon) that runs inside the
+qemu subprocess.
+
+There is no comprehensive help for this command. You have
+to look at the file C<daemon/debug.c> in the libguestfs source
+to find out what you can do.
+
=item $h->download ($remotefilename, $filename);
Download file C<remotefilename> and save it as C<filename>
return py_r;
}
+static PyObject *
+py_guestfs_debug (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ char *r;
+ const char *subcmd;
+ PyObject *py_extraargs;
+ const char **extraargs;
+
+ if (!PyArg_ParseTuple (args, (char *) "OsO:guestfs_debug",
+ &py_g, &subcmd, &py_extraargs))
+ return NULL;
+ g = get_handle (py_g);
+ extraargs = get_string_list (py_extraargs);
+ if (!extraargs) return NULL;
+
+ r = guestfs_debug (g, subcmd, extraargs);
+ free (extraargs);
+ 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 *) "mount_ro", py_guestfs_mount_ro, METH_VARARGS, NULL },
{ (char *) "mount_options", py_guestfs_mount_options, METH_VARARGS, NULL },
{ (char *) "mount_vfs", py_guestfs_mount_vfs, METH_VARARGS, NULL },
+ { (char *) "debug", py_guestfs_debug, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
"""
return libguestfsmod.mount_vfs (self._o, options, vfstype, device, mountpoint)
+ def debug (self, subcmd, extraargs):
+ u"""The "g.debug" command exposes some internals of
+ "guestfsd" (the guestfs daemon) that runs inside the
+ qemu subprocess.
+
+ There is no comprehensive help for this command. You
+ have to look at the file "daemon/debug.c" in the
+ libguestfs source to find out what you can do.
+ """
+ return libguestfsmod.debug (self._o, subcmd, extraargs)
+
return Qnil;
}
+static VALUE ruby_guestfs_debug (VALUE gv, VALUE subcmdv, VALUE extraargsv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "debug");
+
+ const char *subcmd = StringValueCStr (subcmdv);
+ if (!subcmd)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "subcmd", "debug");
+ char **extraargs; {
+ int i, len;
+ len = RARRAY_LEN (extraargsv);
+ extraargs = malloc (sizeof (char *) * (len+1));
+ for (i = 0; i < len; ++i) {
+ VALUE v = rb_ary_entry (extraargsv, i);
+ extraargs[i] = StringValueCStr (v);
+ }
+ }
+
+ char *r;
+
+ r = guestfs_debug (g, subcmd, extraargs);
+ free (extraargs);
+ 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_mount_options, 3);
rb_define_method (c_guestfs, "mount_vfs",
ruby_guestfs_mount_vfs, 4);
+ rb_define_method (c_guestfs, "debug",
+ ruby_guestfs_debug, 2);
}
return 0;
}
+struct debug_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 = send called,
+ * 1001 = reply called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+ struct guestfs_debug_ret ret;
+};
+
+static void debug_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct debug_ctx *ctx = (struct debug_ctx *) data;
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_debug");
+ 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_debug");
+ return;
+ }
+ goto done;
+ }
+ if (!xdr_guestfs_debug_ret (xdr, &ctx->ret)) {
+ error (g, "%s: failed to parse reply", "guestfs_debug");
+ return;
+ }
+ done:
+ ctx->cb_sequence = 1001;
+}
+
+char *guestfs_debug (guestfs_h *g,
+ const char *subcmd,
+ char * const* const extraargs)
+{
+ struct guestfs_debug_args args;
+ struct debug_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_debug") == -1) return NULL;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.subcmd = (char *) subcmd;
+ args.extraargs.extraargs_val = (char **) extraargs;
+ for (args.extraargs.extraargs_len = 0; extraargs[args.extraargs.extraargs_len]; args.extraargs.extraargs_len++) ;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_DEBUG,
+ (xdrproc_t) xdr_guestfs_debug_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_set_ready (g);
+ return NULL;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, debug_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1001) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_debug");
+ guestfs_set_ready (g);
+ return NULL;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DEBUG, 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.result; /* caller will free */
+}
+
extern int guestfs_mount_ro (guestfs_h *handle, const char *device, const char *mountpoint);
extern int guestfs_mount_options (guestfs_h *handle, const char *options, const char *device, const char *mountpoint);
extern int guestfs_mount_vfs (guestfs_h *handle, const char *options, const char *vfstype, const char *device, const char *mountpoint);
+extern char *guestfs_debug (guestfs_h *handle, const char *subcmd, char * const* const extraargs);
}
bool_t
+xdr_guestfs_debug_args (XDR *xdrs, guestfs_debug_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->subcmd, ~0))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **)&objp->extraargs.extraargs_val, (u_int *) &objp->extraargs.extraargs_len, ~0,
+ sizeof (str), (xdrproc_t) xdr_str))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_guestfs_debug_ret (XDR *xdrs, guestfs_debug_ret *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->result, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
{
register int32_t *buf;
};
typedef struct guestfs_mount_vfs_args guestfs_mount_vfs_args;
+struct guestfs_debug_args {
+ char *subcmd;
+ struct {
+ u_int extraargs_len;
+ str *extraargs_val;
+ } extraargs;
+};
+typedef struct guestfs_debug_args guestfs_debug_args;
+
+struct guestfs_debug_ret {
+ char *result;
+};
+typedef struct guestfs_debug_ret guestfs_debug_ret;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_MOUNT_RO = 73,
GUESTFS_PROC_MOUNT_OPTIONS = 74,
GUESTFS_PROC_MOUNT_VFS = 75,
- GUESTFS_PROC_NR_PROCS = 75 + 1,
+ GUESTFS_PROC_DEBUG = 76,
+ GUESTFS_PROC_NR_PROCS = 76 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
extern bool_t xdr_guestfs_mount_ro_args (XDR *, guestfs_mount_ro_args*);
extern bool_t xdr_guestfs_mount_options_args (XDR *, guestfs_mount_options_args*);
extern bool_t xdr_guestfs_mount_vfs_args (XDR *, guestfs_mount_vfs_args*);
+extern bool_t xdr_guestfs_debug_args (XDR *, guestfs_debug_args*);
+extern bool_t xdr_guestfs_debug_ret (XDR *, guestfs_debug_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_mount_ro_args ();
extern bool_t xdr_guestfs_mount_options_args ();
extern bool_t xdr_guestfs_mount_vfs_args ();
+extern bool_t xdr_guestfs_debug_args ();
+extern bool_t xdr_guestfs_debug_ret ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
string mountpoint<>;
};
+struct guestfs_debug_args {
+ string subcmd<>;
+ str extraargs<>;
+};
+
+struct guestfs_debug_ret {
+ string result<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_MOUNT_RO = 73,
GUESTFS_PROC_MOUNT_OPTIONS = 74,
GUESTFS_PROC_MOUNT_VFS = 75,
+ GUESTFS_PROC_DEBUG = 76,
GUESTFS_PROC_NR_PROCS
};
fprintf (stderr, "warning: \"guestfs_tgz_out\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_mount_options\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_mount_vfs\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_debug\" has no tests\n");
}
static int test_mount_ro_0 (void)