Wanlong Gao
2012-Jul-24 08:47 UTC
[Libguestfs] [PATCH V4 1/3] umount: add force umount and lazy umount
Add the option force and lazy for force and lazy umount. Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com> --- daemon/mount.c | 25 +++++++++++++++++++++++-- generator/generator_actions.ml | 23 ++++++++++++----------- gobject/Makefile.inc | 2 ++ po/POTFILES | 1 + 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/daemon/mount.c b/daemon/mount.c index 0661eb8..1ad99fa 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -29,6 +29,8 @@ #include "daemon.h" #include "actions.h" +#define MAX_ARGS 64 + /* You must mount something on "/" first before many operations. * Hence we have an internal function which can test if something is * mounted on *or under* the sysroot directory. (It has to be *or @@ -187,12 +189,16 @@ do_mount_options (const char *options, const char *device, * is kept updated. */ int -do_umount (const char *pathordevice) +do_umount (const char *pathordevice, + int force, int lazyunmount) { int r; char *err; char *buf; int is_dev; + char prog[] = "umount"; + const char *argv[MAX_ARGS]; + size_t i = 0; is_dev = STREQLEN (pathordevice, "/dev/", 5); buf = is_dev ? strdup (pathordevice) @@ -205,7 +211,22 @@ do_umount (const char *pathordevice) if (is_dev) RESOLVE_DEVICE (buf, , { free (buf); return -1; }); - r = command (NULL, &err, "umount", buf, NULL); + if (!(optargs_bitmask & GUESTFS_UMOUNT_FORCE_BITMASK)) + force = 0; + if (!(optargs_bitmask & GUESTFS_UMOUNT_LAZYUNMOUNT_BITMASK)) + lazyunmount = 0; + + ADD_ARG (argv, i, prog); + + if (force) + ADD_ARG (argv, i, "-f"); + if (lazyunmount) + ADD_ARG (argv, i, "-l"); + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); free (buf); if (r == -1) { diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 70fd6e3..d512d7c 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -2772,9 +2772,10 @@ characters does I<not> work, even if the length is specified." }; { defaults with name = "umount"; - style = RErr, [String "pathordevice"], []; + style = RErr, [String "pathordevice"], [OBool "force"; OBool "lazyunmount"]; proc_nr = Some 45; fish_alias = ["unmount"]; + once_had_no_optargs = true; tests = [ InitEmpty, Always, TestOutputListOfDevices ( [["part_disk"; "/dev/sda"; "mbr"]; @@ -2785,7 +2786,7 @@ characters does I<not> work, even if the length is specified." }; [["part_disk"; "/dev/sda"; "mbr"]; ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; ["mount_options"; ""; "/dev/sda1"; "/"]; - ["umount"; "/"]; + ["umount"; "/"; "false"; "false"]; ["mounts"]], []) ]; shortdesc = "unmount a filesystem"; @@ -3467,12 +3468,12 @@ To download an uncompressed tarball, use C<guestfs_tar_out>." }; proc_nr = Some 73; tests = [ InitBasicFS, Always, TestLastFail ( - [["umount"; "/"]; + [["umount"; "/"; "false"; "false"]; ["mount_ro"; "/dev/sda1"; "/"]; ["touch"; "/new"]]); InitBasicFS, Always, TestOutput ( [["write"; "/new"; "data"]; - ["umount"; "/"]; + ["umount"; "/"; "false"; "false"]; ["mount_ro"; "/dev/sda1"; "/"]; ["cat"; "/new"]], "data") ]; @@ -3715,10 +3716,10 @@ C<device>." }; fish_output = Some FishOutputHexadecimal; tests = [ InitBasicFS, Always, TestOutputInt ( - [["umount"; "/dev/sda1"]; + [["umount"; "/dev/sda1"; "false"; "false"]; ["fsck"; "ext2"; "/dev/sda1"]], 0); InitBasicFS, Always, TestOutputInt ( - [["umount"; "/dev/sda1"]; + [["umount"; "/dev/sda1"; "false"; "false"]; ["zero"; "/dev/sda1"]; ["fsck"; "ext2"; "/dev/sda1"]], 8) ]; @@ -3759,7 +3760,7 @@ This command is entirely equivalent to running C<fsck -a -t fstype device>." }; progress = true; tests = [ InitBasicFS, Always, TestRun ( - [["umount"; "/dev/sda1"]; + [["umount"; "/dev/sda1"; "false"; "false"]; ["zero"; "/dev/sda1"]]) ]; shortdesc = "write zeroes to the device"; @@ -4081,7 +4082,7 @@ the human-readable, canonical hex dump of the file." }; ["mkfs"; "ext3"; "/dev/sda1"; ""; "NOARG"; ""; ""]; ["mount_options"; ""; "/dev/sda1"; "/"]; ["write"; "/new"; "test file"]; - ["umount"; "/dev/sda1"]; + ["umount"; "/dev/sda1"; "false"; "false"]; ["zerofree"; "/dev/sda1"]; ["mount_options"; ""; "/dev/sda1"; "/"]; ["cat"; "/new"]], "test file") @@ -4205,7 +4206,7 @@ are activated or deactivated." }; ["mkfs"; "ext2"; "/dev/VG/LV"; ""; "NOARG"; ""; ""]; ["mount_options"; ""; "/dev/VG/LV"; "/"]; ["write"; "/new"; "test content"]; - ["umount"; "/"]; + ["umount"; "/"; "false"; "false"]; ["lvresize"; "/dev/VG/LV"; "20"]; ["e2fsck_f"; "/dev/VG/LV"]; ["e2fsck"; "/dev/VG/LV"; "true"; "false"]; @@ -6564,7 +6565,7 @@ Rename a logical volume C<logvol> with the new name C<newlogvol>." }; proc_nr = Some 220; tests = [ InitBasicFSonLVM, Always, TestOutputList ( - [["umount"; "/"]; + [["umount"; "/"; "false"; "false"]; ["vg_activate"; "false"; "VG"]; ["vgrename"; "VG"; "VG2"]; ["vg_activate"; "true"; "VG2"]; @@ -7685,7 +7686,7 @@ it contains all zero bytes." }; proc_nr = Some 284; tests = [ InitBasicFS, Always, TestOutputTrue ( - [["umount"; "/dev/sda1"]; + [["umount"; "/dev/sda1"; "false"; "false"]; ["zero_device"; "/dev/sda1"]; ["is_zero_device"; "/dev/sda1"]]); InitBasicFS, Always, TestOutputFalse ( diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index c73e5df..230d114 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -45,6 +45,7 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-inspect_get_icon.h \ include/guestfs-gobject/optargs-mount_local.h \ include/guestfs-gobject/optargs-umount_local.h \ + include/guestfs-gobject/optargs-umount.h \ include/guestfs-gobject/optargs-mkfs.h \ include/guestfs-gobject/optargs-mount_9p.h \ include/guestfs-gobject/optargs-ntfsresize.h \ @@ -90,6 +91,7 @@ guestfs_gobject_sources= \ src/optargs-inspect_get_icon.c \ src/optargs-mount_local.c \ src/optargs-umount_local.c \ + src/optargs-umount.c \ src/optargs-mkfs.c \ src/optargs-mount_9p.c \ src/optargs-ntfsresize.c \ diff --git a/po/POTFILES b/po/POTFILES index ad00cd4..228aa39 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -157,6 +157,7 @@ gobject/src/optargs-ntfsfix.c gobject/src/optargs-ntfsresize.c gobject/src/optargs-set_e2attrs.c gobject/src/optargs-tune2fs.c +gobject/src/optargs-umount.c gobject/src/optargs-umount_local.c gobject/src/session.c gobject/src/struct-application.c -- 1.7.12.rc0
Wanlong Gao
2012-Jul-24 08:47 UTC
[Libguestfs] [PATCH V4 2/3] xfs_info: resolve device when doing xfs_info on a device
Resolve device first, like do_umount. Use Dev_or_Path. Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com> --- daemon/xfs.c | 21 ++++++++------------- generator/generator_actions.ml | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/daemon/xfs.c b/daemon/xfs.c index 3efc14f..e0f0062 100644 --- a/daemon/xfs.c +++ b/daemon/xfs.c @@ -311,26 +311,21 @@ error: } guestfs_int_xfsinfo * -do_xfs_info (const char *path) +do_xfs_info (const char *pathordevice) { int r; char *buf; char *out = NULL, *err = NULL; char **lines = NULL; guestfs_int_xfsinfo *ret = NULL; + int is_dev; - if (do_is_dir (path)) { - buf = sysroot_path (path); - if (!buf) { - reply_with_perror ("malloc"); - return NULL; - } - } else { - buf = strdup(path); - if (!buf) { - reply_with_perror ("strdup"); - return NULL; - } + is_dev = STREQLEN (pathordevice, "/dev/", 5); + buf = is_dev ? strdup (pathordevice) + : sysroot_path (pathordevice); + if (buf == NULL) { + reply_with_perror ("malloc"); + return NULL; } r = command (&out, &err, "xfs_info", buf, NULL); diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index d512d7c..4e18b4e 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -8954,7 +8954,7 @@ call C<guestfs_max_disks>." }; { defaults with name = "xfs_info"; - style = RStruct ("info", "xfsinfo"), [Pathname "path"], []; + style = RStruct ("info", "xfsinfo"), [Dev_or_Path "pathordevice"], []; proc_nr = Some 337; optional = Some "xfs"; tests = [ -- 1.7.12.rc0
Wanlong Gao
2012-Jul-24 08:47 UTC
[Libguestfs] [PATCH V4 3/3] umount: use Dev_or_Path for the argument type
Use Dev_or_Path. Remove the RESOLVE_DEVICE since Dev_or_Path will generate the resolve code. Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com> --- daemon/mount.c | 3 --- generator/generator_actions.ml | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/daemon/mount.c b/daemon/mount.c index 1ad99fa..86a707a 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -208,9 +208,6 @@ do_umount (const char *pathordevice, return -1; } - if (is_dev) - RESOLVE_DEVICE (buf, , { free (buf); return -1; }); - if (!(optargs_bitmask & GUESTFS_UMOUNT_FORCE_BITMASK)) force = 0; if (!(optargs_bitmask & GUESTFS_UMOUNT_LAZYUNMOUNT_BITMASK)) diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 4e18b4e..8ac6a14 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -2772,7 +2772,7 @@ characters does I<not> work, even if the length is specified." }; { defaults with name = "umount"; - style = RErr, [String "pathordevice"], [OBool "force"; OBool "lazyunmount"]; + style = RErr, [Dev_or_Path "pathordevice"], [OBool "force"; OBool "lazyunmount"]; proc_nr = Some 45; fish_alias = ["unmount"]; once_had_no_optargs = true; -- 1.7.12.rc0
Richard W.M. Jones
2012-Jul-24 09:09 UTC
[Libguestfs] [PATCH V4 1/3] umount: add force umount and lazy umount
I pushed patch 1 upstream already, with a tiny modification. Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org