add_drive: Don't use cache=off if not supported by underlying filesystem.
[libguestfs.git] / src / generator.ml
index c9b3315..39faffe 100755 (executable)
@@ -301,6 +301,12 @@ and test_init =
     (* Block devices are empty and no filesystems are mounted. *)
   | InitEmpty
 
+    (* /dev/sda contains a single partition /dev/sda1, with random
+     * content.  /dev/sdb and /dev/sdc may have random content.
+     * No LVM.
+     *)
+  | InitPartition
+
     (* /dev/sda contains a single partition /dev/sda1, which is formatted
      * as ext2, empty [except for lost+found] and mounted on /.
      * /dev/sdb and /dev/sdc may have random content.
@@ -448,6 +454,8 @@ image).
 
 This is equivalent to the qemu parameter
 C<-drive file=filename,cache=off,if=...>.
+C<cache=off> is omitted in cases where it is not supported by
+the underlying filesystem.
 
 Note that this call checks for the existence of C<filename>.  This
 stops you from specifying other types of drive which are supported
@@ -755,6 +763,31 @@ C<$major.$minor.$release$extra>
 I<Note:> Don't use this call to test for availability
 of features.  Distro backports makes this unreliable.");
 
+  ("set_selinux", (RErr, [Bool "selinux"]), -1, [FishAlias "selinux"],
+   [InitNone, Always, TestOutputTrue (
+      [["set_selinux"; "true"];
+       ["get_selinux"]])],
+   "set SELinux enabled or disabled at appliance boot",
+   "\
+This sets the selinux flag that is passed to the appliance
+at boot time.  The default is C<selinux=0> (disabled).
+
+Note that if SELinux is enabled, it is always in
+Permissive mode (C<enforcing=0>).
+
+For more information on the architecture of libguestfs,
+see L<guestfs(3)>.");
+
+  ("get_selinux", (RBool "selinux", []), -1, [],
+   [],
+   "get SELinux enabled flag",
+   "\
+This returns the current setting of the selinux flag which
+is passed to the appliance at boot time.  See C<guestfs_set_selinux>.
+
+For more information on the architecture of libguestfs,
+see L<guestfs(3)>.");
+
 ]
 
 (* daemon_functions are any functions which cause some action
@@ -1619,8 +1652,7 @@ This is the same as the C<lstat(2)> system call.");
 
   ("statvfs", (RStruct ("statbuf", "statvfs"), [String "path"]), 54, [],
    [InitSquashFS, Always, TestOutputStruct (
-      [["statvfs"; "/"]], [CompareWithInt ("namemax", 256);
-                           CompareWithInt ("bsize", 131072)])],
+      [["statvfs"; "/"]], [CompareWithInt ("namemax", 256)])],
    "get file system statistics",
    "\
 Returns file system statistics for any mounted file system.
@@ -1756,7 +1788,8 @@ This uses the L<blockdev(8)> command.");
    [InitBasicFS, Always, TestOutput (
       (* Pick a file from cwd which isn't likely to change. *)
       [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
-       ["checksum"; "md5"; "/COPYING.LIB"]], "e3eda01d9815f8d24aae2dbd89b68b06")],
+       ["checksum"; "md5"; "/COPYING.LIB"]],
+        Digest.to_hex (Digest.file "COPYING.LIB"))],
    "upload a file from the local machine",
    "\
 Upload local file C<filename> to C<remotefilename> on the
@@ -1772,7 +1805,8 @@ See also C<guestfs_download>.");
       [["upload"; "../COPYING.LIB"; "/COPYING.LIB"];
        ["download"; "/COPYING.LIB"; "testdownload.tmp"];
        ["upload"; "testdownload.tmp"; "/upload"];
-       ["checksum"; "md5"; "/upload"]], "e3eda01d9815f8d24aae2dbd89b68b06")],
+       ["checksum"; "md5"; "/upload"]],
+        Digest.to_hex (Digest.file "COPYING.LIB"))],
    "download a file to the local machine",
    "\
 Download file C<remotefilename> and save it as C<filename>
@@ -3206,10 +3240,10 @@ C<alloc> command which allocates a file in the host and
 attaches it as a device.");
 
   ("swapon_device", (RErr, [String "device"]), 170, [],
-   [InitNone, Always, TestRun (
-      [["mkswap"; "/dev/sdb"];
-       ["swapon_device"; "/dev/sdb"];
-       ["swapoff_device"; "/dev/sdb"]])],
+   [InitPartition, Always, TestRun (
+      [["mkswap"; "/dev/sda1"];
+       ["swapon_device"; "/dev/sda1"];
+       ["swapoff_device"; "/dev/sda1"]])],
    "enable swap on device",
    "\
 This command enables the libguestfs appliance to use the
@@ -3254,18 +3288,20 @@ This command disables the libguestfs appliance swap on file.");
       [["sfdiskM"; "/dev/sdb"; ","];
        ["mkswap_L"; "swapit"; "/dev/sdb1"];
        ["swapon_label"; "swapit"];
-       ["swapoff_label"; "swapit"]])],
-   "enable swap on labelled swap partition",
+       ["swapoff_label"; "swapit"];
+       ["zero"; "/dev/sdb"];
+       ["blockdev_rereadpt"; "/dev/sdb"]])],
+   "enable swap on labeled swap partition",
    "\
-This command enables swap to a labelled swap partition.
+This command enables swap to a labeled swap partition.
 See C<guestfs_swapon_device> for other notes.");
 
   ("swapoff_label", (RErr, [String "label"]), 175, [],
    [], (* XXX tested by swapon_label *)
-   "disable swap on labelled swap partition",
+   "disable swap on labeled swap partition",
    "\
 This command disables the libguestfs appliance swap on
-labelled swap partition.");
+labeled swap partition.");
 
   ("swapon_uuid", (RErr, [String "uuid"]), 176, [],
    [InitEmpty, Always, TestRun (
@@ -3393,6 +3429,24 @@ This closes the inotify handle which was previously
 opened by inotify_init.  It removes all watches, throws
 away any pending events, and deallocates all resources.");
 
+  ("setcon", (RErr, [String "context"]), 185, [],
+   [],
+   "set SELinux security context",
+   "\
+This sets the SELinux security context of the daemon
+to the string C<context>.
+
+See the documentation about SELINUX in L<guestfs(3)>.");
+
+  ("getcon", (RString "context", []), 186, [],
+   [],
+   "get SELinux security context",
+   "\
+This gets the SELinux security context of the daemon.
+
+See the documentation about SELINUX in L<guestfs(3)>,
+and C<guestfs_setcon>");
+
 ]
 
 let all_functions = non_daemon_functions @ daemon_functions
@@ -5315,6 +5369,13 @@ and generate_one_test_body name i test_name init test =
          [["blockdev_setrw"; "/dev/sda"];
           ["umount_all"];
           ["lvm_remove_all"]]
+   | InitPartition ->
+       pr "  /* InitPartition for %s: create /dev/sda1 */\n" test_name;
+       List.iter (generate_test_command_call test_name)
+         [["blockdev_setrw"; "/dev/sda"];
+          ["umount_all"];
+          ["lvm_remove_all"];
+          ["sfdiskM"; "/dev/sda"; ","]]
    | InitBasicFS ->
        pr "  /* InitBasicFS for %s: create ext2 on /dev/sda1 */\n" test_name;
        List.iter (generate_test_command_call test_name)
@@ -8488,6 +8549,16 @@ and generate_java_struct_list_return typ jtyp cols =
   pr "  guestfs_free_%s_list (r);\n" typ;
   pr "  return jr;\n"
 
+and generate_java_makefile_inc () =
+  generate_header HashStyle GPLv2;
+
+  pr "java_built_sources = \\\n";
+  List.iter (
+    fun (typ, jtyp) ->
+        pr "\tcom/redhat/et/libguestfs/%s.java \\\n" jtyp;
+  ) java_structs;
+  pr "\tcom/redhat/et/libguestfs/GuestFS.java\n"
+
 and generate_haskell_hs () =
   generate_header HaskellStyle LGPLv2;
 
@@ -9245,12 +9316,7 @@ Run it from the top source directory using the command
   ) java_structs;
 
   let close = output_to "java/Makefile.inc" in
-  pr "java_built_sources =";
-  List.iter (
-    fun (typ, jtyp) ->
-        pr " com/redhat/et/libguestfs/%s.java" jtyp;
-  ) java_structs;
-  pr " com/redhat/et/libguestfs/GuestFS.java\n";
+  generate_java_makefile_inc ();
   close ();
 
   let close = output_to "java/com_redhat_et_libguestfs_GuestFS.c" in