X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Fgenerator.ml;h=5e2b4d4b7a2ec5d96348a971124de48f8688b1b6;hb=edd99a3f7903f6f80d3f73643cd6ee114dbdd553;hp=3b08993f21c749de2396c00424051824e9ff70c8;hpb=2b568496e6d571be317bcecd58785edbf5d39ba1;p=libguestfs.git
diff --git a/src/generator.ml b/src/generator.ml
index 3b08993..5e2b4d4 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -33,6 +33,7 @@
*)
#load "unix.cma";;
+#load "str.cma";;
open Printf
@@ -284,6 +285,32 @@ The first character of C string must be a C<-> (dash).
C can be NULL.");
+ ("set_qemu", (RErr, [String "qemu"]), -1, [FishAlias "qemu"],
+ [],
+ "set the qemu binary",
+ "\
+Set the qemu binary that we will use.
+
+The default is chosen when the library was compiled by the
+configure script.
+
+You can also override this by setting the C
+environment variable.
+
+The string C is stashed in the libguestfs handle, so the caller
+must make sure it remains valid for the lifetime of the handle.
+
+Setting C to C restores the default qemu binary.");
+
+ ("get_qemu", (RConstString "qemu", []), -1, [],
+ [],
+ "get the qemu binary",
+ "\
+Return the current qemu binary.
+
+This is always non-NULL. If it wasn't set already, then this will
+return the default qemu binary name.");
+
("set_path", (RErr, [String "path"]), -1, [FishAlias "path"],
[],
"set the search path",
@@ -1151,10 +1178,10 @@ This is the same as the C system call.");
("tune2fs_l", (RHashtable "superblock", [String "device"]), 55, [],
[], (* XXX test *)
- "get ext2/ext3 superblock details",
+ "get ext2/ext3/ext4 superblock details",
"\
-This returns the contents of the ext2 or ext3 filesystem superblock
-on C.
+This returns the contents of the ext2, ext3 or ext4 filesystem
+superblock on C.
It is the same as running C. See L
manpage for more details. The list of fields returned isn't
@@ -1409,6 +1436,135 @@ it to local file C.
To download an uncompressed tarball, use C.");
+ ("mount_ro", (RErr, [String "device"; String "mountpoint"]), 73, [],
+ [InitBasicFS, TestLastFail (
+ [["umount"; "/"];
+ ["mount_ro"; "/dev/sda1"; "/"];
+ ["touch"; "/new"]]);
+ InitBasicFS, TestOutput (
+ [["write_file"; "/new"; "data"; "0"];
+ ["umount"; "/"];
+ ["mount_ro"; "/dev/sda1"; "/"];
+ ["cat"; "/new"]], "data")],
+ "mount a guest disk, read-only",
+ "\
+This is the same as the C command, but it
+mounts the filesystem with the read-only (I<-o ro>) flag.");
+
+ ("mount_options", (RErr, [String "options"; String "device"; String "mountpoint"]), 74, [],
+ [],
+ "mount a guest disk with mount options",
+ "\
+This is the same as the C command, but it
+allows you to set the mount options as for the
+L I<-o> flag.");
+
+ ("mount_vfs", (RErr, [String "options"; String "vfstype"; String "device"; String "mountpoint"]), 75, [],
+ [],
+ "mount a guest disk with mount options and vfstype",
+ "\
+This is the same as the C command, but it
+allows you to set both the mount options and the vfstype
+as for the L I<-o> and I<-t> flags.");
+
+ ("debug", (RString "result", [String "subcmd"; StringList "extraargs"]), 76, [],
+ [],
+ "debugging and internals",
+ "\
+The C command exposes some internals of
+C (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 in the libguestfs source
+to find out what you can do.");
+
+ ("lvremove", (RErr, [String "device"]), 77, [],
+ [InitEmpty, TestOutputList (
+ [["pvcreate"; "/dev/sda"];
+ ["vgcreate"; "VG"; "/dev/sda"];
+ ["lvcreate"; "LV1"; "VG"; "50"];
+ ["lvcreate"; "LV2"; "VG"; "50"];
+ ["lvremove"; "/dev/VG/LV1"];
+ ["lvs"]], ["/dev/VG/LV2"]);
+ InitEmpty, TestOutputList (
+ [["pvcreate"; "/dev/sda"];
+ ["vgcreate"; "VG"; "/dev/sda"];
+ ["lvcreate"; "LV1"; "VG"; "50"];
+ ["lvcreate"; "LV2"; "VG"; "50"];
+ ["lvremove"; "/dev/VG"];
+ ["lvs"]], []);
+ InitEmpty, TestOutputList (
+ [["pvcreate"; "/dev/sda"];
+ ["vgcreate"; "VG"; "/dev/sda"];
+ ["lvcreate"; "LV1"; "VG"; "50"];
+ ["lvcreate"; "LV2"; "VG"; "50"];
+ ["lvremove"; "/dev/VG"];
+ ["vgs"]], ["VG"])],
+ "remove an LVM logical volume",
+ "\
+Remove an LVM logical volume C, where C is
+the path to the LV, such as C.
+
+You can also remove all LVs in a volume group by specifying
+the VG name, C.");
+
+ ("vgremove", (RErr, [String "vgname"]), 78, [],
+ [InitEmpty, TestOutputList (
+ [["pvcreate"; "/dev/sda"];
+ ["vgcreate"; "VG"; "/dev/sda"];
+ ["lvcreate"; "LV1"; "VG"; "50"];
+ ["lvcreate"; "LV2"; "VG"; "50"];
+ ["vgremove"; "VG"];
+ ["lvs"]], []);
+ InitEmpty, TestOutputList (
+ [["pvcreate"; "/dev/sda"];
+ ["vgcreate"; "VG"; "/dev/sda"];
+ ["lvcreate"; "LV1"; "VG"; "50"];
+ ["lvcreate"; "LV2"; "VG"; "50"];
+ ["vgremove"; "VG"];
+ ["vgs"]], [])],
+ "remove an LVM volume group",
+ "\
+Remove an LVM volume group C, (for example C).
+
+This also forcibly removes all logical volumes in the volume
+group (if any).");
+
+ ("pvremove", (RErr, [String "device"]), 79, [],
+ [InitEmpty, TestOutputList (
+ [["pvcreate"; "/dev/sda"];
+ ["vgcreate"; "VG"; "/dev/sda"];
+ ["lvcreate"; "LV1"; "VG"; "50"];
+ ["lvcreate"; "LV2"; "VG"; "50"];
+ ["vgremove"; "VG"];
+ ["pvremove"; "/dev/sda"];
+ ["lvs"]], []);
+ InitEmpty, TestOutputList (
+ [["pvcreate"; "/dev/sda"];
+ ["vgcreate"; "VG"; "/dev/sda"];
+ ["lvcreate"; "LV1"; "VG"; "50"];
+ ["lvcreate"; "LV2"; "VG"; "50"];
+ ["vgremove"; "VG"];
+ ["pvremove"; "/dev/sda"];
+ ["vgs"]], []);
+ InitEmpty, TestOutputList (
+ [["pvcreate"; "/dev/sda"];
+ ["vgcreate"; "VG"; "/dev/sda"];
+ ["lvcreate"; "LV1"; "VG"; "50"];
+ ["lvcreate"; "LV2"; "VG"; "50"];
+ ["vgremove"; "VG"];
+ ["pvremove"; "/dev/sda"];
+ ["pvs"]], [])],
+ "remove an LVM physical volume",
+ "\
+This wipes a physical volume C so that LVM will no longer
+recognise it.
+
+The implementation uses the C command which refuses to
+wipe physical volumes that contain any volume groups, so you have
+to remove those first.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
@@ -2255,8 +2411,7 @@ check_state (guestfs_h *g, const char *caller)
pr "struct %s_ctx {\n" shortname;
pr " /* This flag is set by the callbacks, so we know we've done\n";
pr " * the callbacks as expected, and in the right sequence.\n";
- pr " * 0 = not called, 1 = send called,\n";
- pr " * 1001 = reply called.\n";
+ pr " * 0 = not called, 1 = reply_cb called.\n";
pr " */\n";
pr " int cb_sequence;\n";
pr " struct guestfs_message_header hdr;\n";
@@ -2282,6 +2437,13 @@ check_state (guestfs_h *g, const char *caller)
pr " guestfs_main_loop *ml = guestfs_get_main_loop (g);\n";
pr " struct %s_ctx *ctx = (struct %s_ctx *) data;\n" shortname shortname;
pr "\n";
+ pr " /* This should definitely not happen. */\n";
+ pr " if (ctx->cb_sequence != 0) {\n";
+ pr " ctx->cb_sequence = 9999;\n";
+ pr " error (g, \"%%s: internal error: reply callback called twice\", \"%s\");\n" name;
+ pr " return;\n";
+ pr " }\n";
+ pr "\n";
pr " ml->main_loop_quit (ml, g);\n";
pr "\n";
pr " if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {\n";
@@ -2314,7 +2476,7 @@ check_state (guestfs_h *g, const char *caller)
);
pr " done:\n";
- pr " ctx->cb_sequence = 1001;\n";
+ pr " ctx->cb_sequence = 1;\n";
pr "}\n\n";
(* Generate the action stub. *)
@@ -2409,7 +2571,7 @@ check_state (guestfs_h *g, const char *caller)
pr " guestfs_set_reply_callback (g, %s_reply_cb, &ctx);\n" shortname;
pr " (void) ml->main_loop_run (ml, g);\n";
pr " guestfs_set_reply_callback (g, NULL, NULL);\n";
- pr " if (ctx.cb_sequence != 1001) {\n";
+ pr " if (ctx.cb_sequence != 1) {\n";
pr " error (g, \"%%s reply failed, see earlier error messages\", \"%s\");\n" name;
pr " guestfs_set_ready (g);\n";
pr " return %s;\n" error_code;
@@ -2490,7 +2652,7 @@ and generate_daemon_actions_h () =
and generate_daemon_actions () =
generate_header CStyle GPLv2;
- pr "#define _GNU_SOURCE // for strchrnul\n";
+ pr "#include \n";
pr "\n";
pr "#include \n";
pr "#include \n";
@@ -3752,9 +3914,19 @@ and generate_fish_actions_pod () =
fun (_, _, _, flags, _, _, _) -> not (List.mem NotInFish flags)
) all_functions_sorted in
+ let rex = Str.regexp "C]+\\)>" in
+
List.iter (
fun (name, style, _, flags, _, _, longdesc) ->
- let longdesc = replace_str longdesc "C
+ let sub =
+ try Str.matched_group 1 s
+ with Not_found ->
+ failwithf "error substituting C in longdesc of function %s" name in
+ "C<" ^ replace_char sub '_' '-' ^ ">"
+ ) longdesc in
let name = replace_char name '_' '-' in
let alias =
try find_map (function FishAlias n -> Some n | _ -> None) flags
@@ -3770,7 +3942,7 @@ and generate_fish_actions_pod () =
function
| String n -> pr " %s" n
| OptString n -> pr " %s" n
- | StringList n -> pr " %s,..." n
+ | StringList n -> pr " '%s ...'" n
| Bool _ -> pr " true|false"
| Int n -> pr " %s" n
| FileIn n | FileOut n -> pr " (%s|-)" n
@@ -4080,6 +4252,8 @@ copy_table (char * const * argv)
pr "{\n";
(match params with
+ | [p1; p2; p3; p4; p5] ->
+ pr " CAMLparam5 (%s);\n" (String.concat ", " params)
| p1 :: p2 :: p3 :: p4 :: p5 :: rest ->
pr " CAMLparam5 (%s);\n" (String.concat ", " [p1; p2; p3; p4; p5]);
pr " CAMLxparam%d (%s);\n"
@@ -5332,6 +5506,7 @@ static VALUE ruby_guestfs_close (VALUE gv)
pr " VALUE v = rb_ary_entry (%sv, i);\n" n;
pr " %s[i] = StringValueCStr (v);\n" n;
pr " }\n";
+ pr " %s[len] = NULL;\n" n;
pr " }\n";
| Bool n
| Int n ->
@@ -5710,14 +5885,14 @@ Java_com_redhat_et_libguestfs_GuestFS__1create
return 0;
}
guestfs_set_error_handler (g, NULL, NULL);
- return (jlong) g;
+ return (jlong) (long) g;
}
JNIEXPORT void JNICALL
Java_com_redhat_et_libguestfs_GuestFS__1close
(JNIEnv *env, jobject obj, jlong jg)
{
- guestfs_h *g = (guestfs_h *) jg;
+ guestfs_h *g = (guestfs_h *) (long) jg;
guestfs_close (g);
}
@@ -5758,7 +5933,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close
) (snd style);
pr ")\n";
pr "{\n";
- pr " guestfs_h *g = (guestfs_h *) jg;\n";
+ pr " guestfs_h *g = (guestfs_h *) (long) jg;\n";
let error_code, no_ret =
match fst style with
| RErr -> pr " int r;\n"; "-1", ""