X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=32a814003a3247d16be83e4bd69b085df57feec1;hp=4bf5aec53028506ee5af776463ce6b30a01d61f4;hb=1214b321621e7750c67423ecf4d9528809e1eeac;hpb=986541c26ddeec7583cfb41412d4edaef60703a2 diff --git a/src/generator.ml b/src/generator.ml index 4bf5aec..32a8140 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -1,6 +1,6 @@ #!/usr/bin/env ocaml (* libguestfs - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009-2010 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,20 +21,31 @@ * all the daemon actions. * * To add a new action there are only two files you need to change, - * this one to describe the interface (see the big table below), and - * daemon/.c to write the implementation. + * this one to describe the interface (see the big table of + * 'daemon_functions' below), and daemon/.c to write the + * implementation. * - * After editing this file, run it (./src/generator.ml) to regenerate all the - * output files. Note that if you are using a separate build directory you - * must run generator.ml from the _source_ directory. + * After editing this file, run it (./src/generator.ml) to regenerate + * all the output files. 'make' will rerun this automatically when + * necessary. Note that if you are using a separate build directory + * you must run generator.ml from the _source_ directory. * * IMPORTANT: This script should NOT print any warnings. If it prints * warnings, you should treat them as errors. + * + * OCaml tips: + * (1) In emacs, install tuareg-mode to display and format OCaml code + * correctly. 'vim' comes with a good OCaml editing mode by default. + * (2) Read the resources at http://ocaml-tutorial.org/ *) #load "unix.cma";; #load "str.cma";; +#directory "+xml-light";; +#directory "+../pkg-lib/xml-light";; (* for GODI users *) +#load "xml-light.cma";; +open Unix open Printf type style = ret * args @@ -153,9 +164,8 @@ and argt = *) | FileIn of string | FileOut of string -(* Not implemented: (* Opaque buffer which can contain arbitrary 8 bit data. - * In the C API, this is expressed as pair. + * In the C API, this is expressed as pair. * Most other languages have a string type which can contain * ASCII NUL. We use whatever type is appropriate for each * language. @@ -164,16 +174,20 @@ and argt = * To return an arbitrary buffer, use RBufferOut. *) | BufferIn of string -*) type flags = | ProtocolLimitWarning (* display warning about protocol size limits *) | DangerWillRobinson (* flags particularly dangerous commands *) | FishAlias of string (* provide an alias for this cmd in guestfish *) - | FishAction of string (* call this function in guestfish *) + | FishOutput of fish_output_t (* how to display output in guestfish *) | NotInFish (* do not export via guestfish *) | NotInDocs (* do not add this function to documentation *) | DeprecatedBy of string (* function is deprecated, use .. instead *) + | Optional of string (* function is part of an optional group *) + +and fish_output_t = + | FishOutputOctal (* for int return, print in octal *) + | FishOutputHexadecimal (* for int return, print in hex *) (* You can supply zero or as many tests as you want per API call. * @@ -346,13 +360,13 @@ and cmd = string list (* Generate a random UUID (used in tests). *) let uuidgen () = - let chan = Unix.open_process_in "uuidgen" in + let chan = open_process_in "uuidgen" in let uuid = input_line chan in - (match Unix.close_process_in chan with - | Unix.WEXITED 0 -> () - | Unix.WEXITED _ -> + (match close_process_in chan with + | WEXITED 0 -> () + | WEXITED _ -> failwith "uuidgen: process exited with non-zero status" - | Unix.WSIGNALED _ | Unix.WSTOPPED _ -> + | WSIGNALED _ | WSTOPPED _ -> failwith "uuidgen: process signalled or stopped by signal" ); uuid @@ -368,6 +382,7 @@ let test_all_args = [ Int64 "integer64"; FileIn "filein"; FileOut "fileout"; + BufferIn "bufferin"; ] let test_all_rets = [ @@ -430,7 +445,7 @@ You probably don't want to call this function.")] *) let non_daemon_functions = test_functions @ [ - ("launch", (RErr, []), -1, [FishAlias "run"; FishAction "launch"], + ("launch", (RErr, []), -1, [FishAlias "run"], [], "launch the qemu subprocess", "\ @@ -478,9 +493,15 @@ image). This is equivalent to the qemu parameter C<-drive file=filename,cache=off,if=...>. + C is omitted in cases where it is not supported by the underlying filesystem. +C is set at compile time by the configuration option +C<./configure --with-drive-if=...>. In the rare case where you +might need to change this at run time, use C +or C. + Note that this call checks for the existence of C. This stops you from specifying other types of drive which are supported by qemu such as C and C URLs. To specify those, use @@ -494,10 +515,24 @@ This function adds a virtual CD-ROM disk image to the guest. This is equivalent to the qemu parameter C<-cdrom filename>. -Note that this call checks for the existence of C. This +Notes: + +=over 4 + +=item * + +This call checks for the existence of C. This stops you from specifying other types of drive which are supported by qemu such as C and C URLs. To specify those, use -the general C call instead."); +the general C call instead. + +=item * + +If you just want to add an ISO file (often you use this as an +efficient way to transfer large files into the guest), then you +should probably use C instead. + +=back"); ("add_drive_ro", (RErr, [String "filename"]), -1, [FishAlias "add-ro"], [], @@ -513,7 +548,14 @@ handle is closed. We don't currently have any method to enable changes to be committed, although qemu can support this. This is equivalent to the qemu parameter -C<-drive file=filename,snapshot=on,if=...>. +C<-drive file=filename,snapshot=on,readonly=on,if=...>. + +C is set at compile time by the configuration option +C<./configure --with-drive-if=...>. In the rare case where you +might need to change this at run time, use C +or C. + +C is only added where qemu supports this option. Note that this call checks for the existence of C. This stops you from specifying other types of drive which are supported @@ -545,7 +587,15 @@ configure script. You can also override this by setting the C environment variable. -Setting C to C restores the default qemu binary."); +Setting C to C restores the default qemu binary. + +Note that you should call this function as early as possible +after creating the handle. This is because some pre-launch +operations depend on testing qemu features (by running C). +If the qemu binary changes, we don't retest features, and +so you might see inconsistent results. Using the environment +variable C is safest of all since that picks +the qemu binary at the same time as the handle is created."); ("get_qemu", (RConstString "qemu", []), -1, [], [InitNone, Always, TestRun ( @@ -757,7 +807,8 @@ To construct the original version string: C<$major.$minor.$release$extra> I Don't use this call to test for availability -of features. Distro backports makes this unreliable."); +of features. Distro backports makes this unreliable. Use +C instead."); ("set_selinux", (RErr, [Bool "selinux"]), -1, [FishAlias "selinux"], [InitNone, Always, TestOutputTrue ( @@ -861,6 +912,20 @@ qemu, which is not very helpful."); "\ Return the recovery process enabled flag."); + ("add_drive_with_if", (RErr, [String "filename"; String "iface"]), -1, [], + [], + "add a drive specifying the QEMU block emulation to use", + "\ +This is the same as C but it allows you +to specify the QEMU interface emulation to use at run time."); + + ("add_drive_ro_with_if", (RErr, [String "filename"; String "iface"]), -1, [], + [], + "add a drive read-only specifying the QEMU block emulation to use", + "\ +This is the same as C but it allows you +to specify the QEMU interface emulation to use at run time."); + ] (* daemon_functions are any functions which cause some action @@ -873,7 +938,7 @@ let daemon_functions = [ [["part_disk"; "/dev/sda"; "mbr"]; ["mkfs"; "ext2"; "/dev/sda1"]; ["mount"; "/dev/sda1"; "/"]; - ["write_file"; "/new"; "new file contents"; "0"]; + ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents")], "mount a guest disk at a position in the filesystem", "\ @@ -891,8 +956,15 @@ exist. The mounted filesystem is writable, if we have sufficient permissions on the underlying device. -The filesystem options C and C are set with this -call, in order to improve reliability."); +B +When you use this call, the filesystem options C and C +are set implicitly. This was originally done because we thought it +would improve reliability, but it turns out that I<-o sync> has a +very large negative performance impact and negligible effect on +reliability. Therefore we recommend that you avoid using +C in any code that needs performance, and instead +use C (use an empty string for the first +parameter if you don't want any options)."); ("sync", (RErr, []), 2, [], [ InitEmpty, Always, TestRun [["sync"]]], @@ -977,7 +1049,7 @@ The full partition device names are returned, eg. C This does not return logical volumes. For that you will need to call C."); - ("pvs", (RStringList "physvols", []), 9, [], + ("pvs", (RStringList "physvols", []), 9, [Optional "lvm2"], [InitBasicFSonLVM, Always, TestOutputListOfDevices ( [["pvs"]], ["/dev/sda1"]); InitEmpty, Always, TestOutputListOfDevices ( @@ -996,7 +1068,7 @@ PVs (eg. C). See also C."); - ("vgs", (RStringList "volgroups", []), 10, [], + ("vgs", (RStringList "volgroups", []), 10, [Optional "lvm2"], [InitBasicFSonLVM, Always, TestOutputList ( [["vgs"]], ["VG"]); InitEmpty, Always, TestOutputList ( @@ -1017,7 +1089,7 @@ detected (eg. C). See also C."); - ("lvs", (RStringList "logvols", []), 11, [], + ("lvs", (RStringList "logvols", []), 11, [Optional "lvm2"], [InitBasicFSonLVM, Always, TestOutputList ( [["lvs"]], ["/dev/VG/LV"]); InitEmpty, Always, TestOutputList ( @@ -1041,21 +1113,21 @@ This returns a list of the logical volume device names See also C."); - ("pvs_full", (RStructList ("physvols", "lvm_pv"), []), 12, [], + ("pvs_full", (RStructList ("physvols", "lvm_pv"), []), 12, [Optional "lvm2"], [], (* XXX how to test? *) "list the LVM physical volumes (PVs)", "\ List all the physical volumes detected. This is the equivalent of the L command. The \"full\" version includes all fields."); - ("vgs_full", (RStructList ("volgroups", "lvm_vg"), []), 13, [], + ("vgs_full", (RStructList ("volgroups", "lvm_vg"), []), 13, [Optional "lvm2"], [], (* XXX how to test? *) "list the LVM volume groups (VGs)", "\ List all the volumes groups detected. This is the equivalent of the L command. The \"full\" version includes all fields."); - ("lvs_full", (RStructList ("logvols", "lvm_lv"), []), 14, [], + ("lvs_full", (RStructList ("logvols", "lvm_lv"), []), 14, [Optional "lvm2"], [], (* XXX how to test? *) "list the LVM logical volumes (LVs)", "\ @@ -1079,7 +1151,7 @@ Note that this function cannot correctly handle binary files as end of line). For those you need to use the C function which has a more complex interface."); - ("aug_init", (RErr, [Pathname "root"; Int "flags"]), 16, [], + ("aug_init", (RErr, [Pathname "root"; Int "flags"]), 16, [Optional "augeas"], [], (* XXX Augeas code needs tests. *) "create a new Augeas handle", "\ @@ -1130,7 +1202,7 @@ To close the handle, you can call C. To find out more about Augeas, see L."); - ("aug_close", (RErr, []), 26, [], + ("aug_close", (RErr, []), 26, [Optional "augeas"], [], (* XXX Augeas code needs tests. *) "close the current Augeas handle", "\ @@ -1139,7 +1211,7 @@ used by it. After calling this, you have to call C again before you can use any other Augeas functions."); - ("aug_defvar", (RInt "nrnodes", [String "name"; OptString "expr"]), 17, [], + ("aug_defvar", (RInt "nrnodes", [String "name"; OptString "expr"]), 17, [Optional "augeas"], [], (* XXX Augeas code needs tests. *) "define an Augeas variable", "\ @@ -1150,7 +1222,7 @@ undefined. On success this returns the number of nodes in C, or C<0> if C evaluates to something which is not a nodeset."); - ("aug_defnode", (RStruct ("nrnodescreated", "int_bool"), [String "name"; String "expr"; String "val"]), 18, [], + ("aug_defnode", (RStruct ("nrnodescreated", "int_bool"), [String "name"; String "expr"; String "val"]), 18, [Optional "augeas"], [], (* XXX Augeas code needs tests. *) "define an Augeas node", "\ @@ -1165,20 +1237,25 @@ On success this returns a pair containing the number of nodes in the nodeset, and a boolean flag if a node was created."); - ("aug_get", (RString "val", [String "augpath"]), 19, [], + ("aug_get", (RString "val", [String "augpath"]), 19, [Optional "augeas"], [], (* XXX Augeas code needs tests. *) "look up the value of an Augeas path", "\ Look up the value associated with C. If C matches exactly one node, the C is returned."); - ("aug_set", (RErr, [String "augpath"; String "val"]), 20, [], + ("aug_set", (RErr, [String "augpath"; String "val"]), 20, [Optional "augeas"], [], (* XXX Augeas code needs tests. *) "set Augeas path to value", "\ -Set the value associated with C to C."); +Set the value associated with C to C. + +In the Augeas API, it is possible to clear a node by setting +the value to NULL. Due to an oversight in the libguestfs API +you cannot do that with this call. Instead you must use the +C call."); - ("aug_insert", (RErr, [String "augpath"; String "label"; Bool "before"]), 21, [], + ("aug_insert", (RErr, [String "augpath"; String "label"; Bool "before"]), 21, [Optional "augeas"], [], (* XXX Augeas code needs tests. *) "insert a sibling Augeas node", "\ @@ -1190,7 +1267,7 @@ C must match exactly one existing node in the tree, and C