X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=691cf606ab79142a17adb8837e39f5f9959a328b;hp=940d1a7305c7f23c31856820b1ca71dbf04d9622;hb=9b41eeb91733ee681a6a804464b6930d42ed8fd1;hpb=79b5084f70cb67c37dd7cbe60821a78981fd8d59 diff --git a/src/generator.ml b/src/generator.ml index 940d1a7..691cf60 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -136,8 +136,10 @@ and argt = | String of string (* const char *name, cannot be NULL *) | Device of string (* /dev device name, cannot be NULL *) | Pathname of string (* file name, cannot be NULL *) + | Dev_or_Path of string (* /dev device name or Pathname, cannot be NULL *) | OptString of string (* const char *name, may be NULL *) | StringList of string(* list of strings (each string cannot be NULL) *) + | DeviceList of string(* list of Device names (each cannot be NULL) *) | Bool of string (* boolean *) | Int of string (* int (smallish ints, signed, <= 31 bits) *) (* These are treated as filenames (simple string parameters) in @@ -341,6 +343,19 @@ and cmd = string list * Apart from that, long descriptions are just perldoc paragraphs. *) +(* Generate a random UUID (used in tests). *) +let uuidgen () = + let chan = Unix.open_process_in "uuidgen" in + let uuid = input_line chan in + (match Unix.close_process_in chan with + | Unix.WEXITED 0 -> () + | Unix.WEXITED _ -> + failwith "uuidgen: process exited with non-zero status" + | Unix.WSIGNALED _ | Unix.WSTOPPED _ -> + failwith "uuidgen: process signalled or stopped by signal" + ); + uuid + (* These test functions are used in the language binding tests. *) let test_all_args = [ @@ -855,7 +870,7 @@ Note that this function cannot correctly handle binary files as end of string). For those you need to use the C or C functions which have a more complex interface."); - ("ll", (RString "listing", [String "directory"]), 5, [], + ("ll", (RString "listing", [Pathname "directory"]), 5, [], [], (* XXX Tricky to test because it depends on the exact format * of the 'ls -l' command, which changes between F10 and F11. *) @@ -867,7 +882,7 @@ there is no cwd) in the format of 'ls -la'. This command is mostly useful for interactive sessions. It is I intended that you try to parse the output string."); - ("ls", (RStringList "listing", [String "directory"]), 6, [], + ("ls", (RStringList "listing", [Pathname "directory"]), 6, [], [InitBasicFS, Always, TestOutputList ( [["touch"; "/new"]; ["touch"; "/newer"]; @@ -1008,7 +1023,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, [String "root"; Int "flags"]), 16, [], + ("aug_init", (RErr, [Pathname "root"; Int "flags"]), 16, [], [], (* XXX Augeas code needs tests. *) "create a new Augeas handle", "\ @@ -1306,7 +1321,7 @@ This creates an LVM physical volume on the named C, where C should usually be a partition name such as C."); - ("vgcreate", (RErr, [String "volgroup"; StringList "physvols"]), 40, [], + ("vgcreate", (RErr, [String "volgroup"; DeviceList "physvols"]), 40, [], [InitEmpty, Always, TestOutputList ( [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["pvcreate"; "/dev/sda1"]; @@ -1477,7 +1492,7 @@ Some internal mounts are not unmounted by this call."); This command removes all LVM logical volumes, volume groups and physical volumes."); - ("file", (RString "description", [Pathname "path"]), 49, [], + ("file", (RString "description", [Dev_or_Path "path"]), 49, [], [InitSquashFS, Always, TestOutput ( [["file"; "/empty"]], "empty"); InitSquashFS, Always, TestOutput ( @@ -1801,7 +1816,7 @@ C can also be a named pipe. See also C."); - ("download", (RErr, [String "remotefilename"; FileOut "filename"]), 67, [], + ("download", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"]), 67, [], [InitBasicFS, Always, TestOutput ( (* Pick a file from cwd which isn't likely to change. *) [["upload"; "../COPYING.LIB"; "/COPYING.LIB"]; @@ -1909,7 +1924,7 @@ I tar file) into C. To upload an uncompressed tarball, use C."); - ("tgz_out", (RErr, [String "directory"; FileOut "tarball"]), 72, [], + ("tgz_out", (RErr, [Pathname "directory"; FileOut "tarball"]), 72, [], [], "pack directory into compressed tarball", "\ @@ -2076,17 +2091,18 @@ This returns the ext2/3/4 filesystem label of the filesystem on C."); ("set_e2uuid", (RErr, [Device "device"; String "uuid"]), 82, [], - [InitBasicFS, Always, TestOutput ( - [["set_e2uuid"; "/dev/sda1"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"]; - ["get_e2uuid"; "/dev/sda1"]], "a3a61220-882b-4f61-89f4-cf24dcc7297d"); - InitBasicFS, Always, TestOutput ( - [["set_e2uuid"; "/dev/sda1"; "clear"]; - ["get_e2uuid"; "/dev/sda1"]], ""); - (* We can't predict what UUIDs will be, so just check the commands run. *) - InitBasicFS, Always, TestRun ( - [["set_e2uuid"; "/dev/sda1"; "random"]]); - InitBasicFS, Always, TestRun ( - [["set_e2uuid"; "/dev/sda1"; "time"]])], + (let uuid = uuidgen () in + [InitBasicFS, Always, TestOutput ( + [["set_e2uuid"; "/dev/sda1"; uuid]; + ["get_e2uuid"; "/dev/sda1"]], uuid); + InitBasicFS, Always, TestOutput ( + [["set_e2uuid"; "/dev/sda1"; "clear"]; + ["get_e2uuid"; "/dev/sda1"]], ""); + (* We can't predict what UUIDs will be, so just check the commands run. *) + InitBasicFS, Always, TestRun ( + [["set_e2uuid"; "/dev/sda1"; "random"]]); + InitBasicFS, Always, TestRun ( + [["set_e2uuid"; "/dev/sda1"; "time"]])]), "set the ext2/3/4 filesystem UUID", "\ This sets the ext2/3/4 filesystem UUID of the filesystem on @@ -2157,7 +2173,7 @@ any partition tables, filesystem superblocks and so on. See also: C."); - ("grub_install", (RErr, [String "root"; Device "device"]), 86, [], + ("grub_install", (RErr, [Pathname "root"; Device "device"]), 86, [], (* Test disabled because grub-install incompatible with virtio-blk driver. * See also: https://bugzilla.redhat.com/show_bug.cgi?id=479760 *) @@ -2169,7 +2185,7 @@ See also: C."); This command installs GRUB (the Grand Unified Bootloader) on C, with the root directory being C."); - ("cp", (RErr, [String "src"; String "dest"]), 87, [], + ("cp", (RErr, [Pathname "src"; Pathname "dest"]), 87, [], [InitBasicFS, Always, TestOutput ( [["write_file"; "/old"; "file content"; "0"]; ["cp"; "/old"; "/new"]; @@ -2188,7 +2204,7 @@ C, with the root directory being C."); This copies a file from C to C where C is either a destination filename or destination directory."); - ("cp_a", (RErr, [String "src"; String "dest"]), 88, [], + ("cp_a", (RErr, [Pathname "src"; Pathname "dest"]), 88, [], [InitBasicFS, Always, TestOutput ( [["mkdir"; "/olddir"]; ["mkdir"; "/newdir"]; @@ -2200,7 +2216,7 @@ either a destination filename or destination directory."); This copies a file or directory from C to C recursively using the C command."); - ("mv", (RErr, [String "src"; String "dest"]), 89, [], + ("mv", (RErr, [Pathname "src"; Pathname "dest"]), 89, [], [InitBasicFS, Always, TestOutput ( [["write_file"; "/old"; "file content"; "0"]; ["mv"; "/old"; "/new"]; @@ -2253,7 +2269,7 @@ the qemu subprocess. Calling this function checks that the daemon responds to the ping message, without affecting the daemon or attached block device(s) in any other way."); - ("equal", (RBool "equality", [String "file1"; String "file2"]), 93, [], + ("equal", (RBool "equality", [Pathname "file1"; Pathname "file2"]), 93, [], [InitBasicFS, Always, TestOutputTrue ( [["write_file"; "/file1"; "contents of a file"; "0"]; ["cp"; "/file1"; "/file2"]; @@ -2444,7 +2460,7 @@ C sometimes gives an error about this and sometimes not. In any case, it is always safe to call C before calling this function."); - ("find", (RStringList "names", [String "directory"]), 107, [], + ("find", (RStringList "names", [Pathname "directory"]), 107, [], [InitBasicFS, Always, TestOutputList ( [["find"; "/"]], ["lost+found"]); InitBasicFS, Always, TestOutputList ( @@ -2550,7 +2566,11 @@ into a list of lines. See also: C"); - ("glob_expand", (RStringList "paths", [String "pattern"]), 113, [], + ("glob_expand", (RStringList "paths", [Pathname "pattern"]), 113, [], + (* Use Pathname here, and hence ABS_PATH (pattern,... in generated + * code in stubs.c, since all valid glob patterns must start with "/". + * There is no concept of "cwd" in libguestfs, hence no "."-relative names. + *) [InitBasicFS, Always, TestOutputList ( [["mkdir_p"; "/a/b/c"]; ["touch"; "/a/b/c/d"]; @@ -2590,7 +2610,7 @@ more difficult. It is an interface to the L program. See that manual page for more details."); - ("scrub_file", (RErr, [String "file"]), 115, [], + ("scrub_file", (RErr, [Pathname "file"]), 115, [], [InitBasicFS, Always, TestRun ( [["write_file"; "/file"; "content"; "0"]; ["scrub_file"; "/file"]])], @@ -2604,7 +2624,7 @@ The file is I after scrubbing. It is an interface to the L program. See that manual page for more details."); - ("scrub_freespace", (RErr, [String "dir"]), 116, [], + ("scrub_freespace", (RErr, [Pathname "dir"]), 116, [], [], (* XXX needs testing *) "scrub (securely wipe) free space", "\ @@ -2771,7 +2791,7 @@ Old Linux kernels (2.4 and earlier) used a compressed ext2 filesystem as initrd. We I support the newer initramfs format (compressed cpio files)."); - ("mount_loop", (RErr, [String "file"; String "mountpoint"]), 129, [], + ("mount_loop", (RErr, [Pathname "file"; Pathname "mountpoint"]), 129, [], [], "mount a file using the loop device", "\ @@ -2800,9 +2820,10 @@ Note that you cannot attach a swap label to a block device a limitation of the kernel or swap tools."); ("mkswap_U", (RErr, [String "uuid"; Device "device"]), 132, [], - [InitEmpty, Always, TestRun ( - [["sfdiskM"; "/dev/sda"; ","]; - ["mkswap_U"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"; "/dev/sda1"]])], + (let uuid = uuidgen () in + [InitEmpty, Always, TestRun ( + [["sfdiskM"; "/dev/sda"; ","]; + ["mkswap_U"; uuid; "/dev/sda1"]])]), "create a swap partition with an explicit UUID", "\ Create a swap partition on C with UUID C."); @@ -2877,7 +2898,7 @@ See also L, C, C. This call returns the previous umask."); - ("readdir", (RStructList ("entries", "dirent"), [String "dir"]), 138, [], + ("readdir", (RStructList ("entries", "dirent"), [Pathname "dir"]), 138, [], [], "read directories entries", "\ @@ -3026,7 +3047,12 @@ This call is similar to C. That call returns a list of devices. This one returns a hash table (map) of device name to directory where the device is mounted."); - ("mkmountpoint", (RErr, [Pathname "path"]), 148, [], + ("mkmountpoint", (RErr, [String "exemptpath"]), 148, [], + (* This is a special case: while you would expect a parameter + * of type "Pathname", that doesn't work, because it implies + * NEED_ROOT in the generated calling code in stubs.c, and + * this function cannot use NEED_ROOT. + *) [], "create a mountpoint", "\ @@ -3181,7 +3207,7 @@ matching lines."); Return the canonicalized absolute pathname of C. The returned path has no C<.>, C<..> or symbolic link path elements."); - ("ln", (RErr, [String "target"; String "linkname"]), 164, [], + ("ln", (RErr, [String "target"; Pathname "linkname"]), 164, [], [InitBasicFS, Always, TestOutputStruct ( [["touch"; "/a"]; ["ln"; "/a"; "/b"]; @@ -3190,7 +3216,7 @@ returned path has no C<.>, C<..> or symbolic link path elements."); "\ This command creates a hard link using the C command."); - ("ln_f", (RErr, [String "target"; String "linkname"]), 165, [], + ("ln_f", (RErr, [String "target"; Pathname "linkname"]), 165, [], [InitBasicFS, Always, TestOutputStruct ( [["touch"; "/a"]; ["touch"; "/b"]; @@ -3201,7 +3227,7 @@ This command creates a hard link using the C command."); This command creates a hard link using the C command. The C<-f> option removes the link (C) if it exists already."); - ("ln_s", (RErr, [String "target"; String "linkname"]), 166, [], + ("ln_s", (RErr, [String "target"; Pathname "linkname"]), 166, [], [InitBasicFS, Always, TestOutputStruct ( [["touch"; "/a"]; ["ln_s"; "a"; "/b"]; @@ -3210,7 +3236,7 @@ The C<-f> option removes the link (C) if it exists already."); "\ This command creates a symbolic link using the C command."); - ("ln_sf", (RErr, [String "target"; String "linkname"]), 167, [], + ("ln_sf", (RErr, [String "target"; Pathname "linkname"]), 167, [], [InitBasicFS, Always, TestOutput ( [["mkdir_p"; "/a/b"]; ["touch"; "/a/b/c"]; @@ -3268,7 +3294,7 @@ This command disables the libguestfs appliance swap device or partition named C. See C."); - ("swapon_file", (RErr, [String "file"]), 172, [], + ("swapon_file", (RErr, [Pathname "file"]), 172, [], [InitBasicFS, Always, TestRun ( [["fallocate"; "/swap"; "8388608"]; ["mkswap_file"; "/swap"]; @@ -3279,7 +3305,7 @@ See C."); This command enables swap to a file. See C for other notes."); - ("swapoff_file", (RErr, [String "file"]), 173, [], + ("swapoff_file", (RErr, [Pathname "file"]), 173, [], [], (* XXX tested by swapon_file *) "disable swap on file", "\ @@ -3306,10 +3332,11 @@ This command disables the libguestfs appliance swap on labeled swap partition."); ("swapon_uuid", (RErr, [String "uuid"]), 176, [], - [InitEmpty, Always, TestRun ( - [["mkswap_U"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"; "/dev/sdb"]; - ["swapon_uuid"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"]; - ["swapoff_uuid"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"]])], + (let uuid = uuidgen () in + [InitEmpty, Always, TestRun ( + [["mkswap_U"; uuid; "/dev/sdb"]; + ["swapon_uuid"; uuid]; + ["swapoff_uuid"; uuid]])]), "enable swap on swap partition by UUID", "\ This command enables swap to a swap partition with the given UUID. @@ -3449,6 +3476,90 @@ This gets the SELinux security context of the daemon. See the documentation about SELINUX in L, and C"); + ("mkfs_b", (RErr, [String "fstype"; Int "blocksize"; Device "device"]), 187, [], + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ","]; + ["mkfs_b"; "ext2"; "4096"; "/dev/sda1"]; + ["mount"; "/dev/sda1"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")], + "make a filesystem with block size", + "\ +This call is similar to C, but it allows you to +control the block size of the resulting filesystem. Supported +block sizes depend on the filesystem type, but typically they +are C<1024>, C<2048> or C<4096> only."); + + ("mke2journal", (RErr, [Int "blocksize"; Device "device"]), 188, [], + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ",100 ,"]; + ["mke2journal"; "4096"; "/dev/sda1"]; + ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"]; + ["mount"; "/dev/sda2"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")], + "make ext2/3/4 external journal", + "\ +This creates an ext2 external journal on C. It is equivalent +to the command: + + mke2fs -O journal_dev -b blocksize device"); + + ("mke2journal_L", (RErr, [Int "blocksize"; String "label"; Device "device"]), 189, [], + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ",100 ,"]; + ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"]; + ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"]; + ["mount"; "/dev/sda2"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")], + "make ext2/3/4 external journal with label", + "\ +This creates an ext2 external journal on C with label C