[PATCH V3 1/2] umount: add force umount and lazy umount
Add the option force and lazy for force and lazy umount. Signed-off-by: Wanlong Gao <gaowanlong@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 74f76bb..1a89b0e 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -2749,9 +2749,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"]; @@ -2762,7 +2763,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"; @@ -3444,12 +3445,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") ]; @@ -3692,10 +3693,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) ]; @@ -3736,7 +3737,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"; @@ -4058,7 +4059,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") @@ -4182,7 +4183,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"]; @@ -6541,7 +6542,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"]; @@ -7662,7 +7663,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.11.3.287.ge771946
Resolve device first, like do_umount. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/xfs.c | 24 +++++++++++------------- generator/generator_actions.ml | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/daemon/xfs.c b/daemon/xfs.c index 3efc14f..d0cfacc 100644 --- a/daemon/xfs.c +++ b/daemon/xfs.c @@ -311,28 +311,26 @@ 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; } + if (is_dev) + RESOLVE_DEVICE (buf, , { free (buf); return NULL; }); + r = command (&out, &err, "xfs_info", buf, NULL); free (buf); if (r == -1) { diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 1a89b0e..4c1e80b 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -8931,7 +8931,7 @@ call C<guestfs_max_disks>." }; { defaults with name = "xfs_info"; - style = RStruct ("info", "xfsinfo"), [Pathname "path"], []; + style = RStruct ("info", "xfsinfo"), [String "pathordevice"], []; proc_nr = Some 337; optional = Some "xfs"; tests = [ -- 1.7.11.3.287.ge771946
ACK to both -- thanks, I'll push them later today once I've cleared my backlog of libvirt changes. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
On Mon, Jul 23, 2012 at 05:51:32PM +0800, Wanlong Gao wrote:
- style = RStruct ("info", "xfsinfo"), [Pathname "path"], []; + style = RStruct ("info", "xfsinfo"), [String "pathordevice"], [];
Actually NACK to this. I don't understand why you don't use Dev_or_Path here. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
On 07/24/2012 04:32 PM, Richard W.M. Jones wrote:
On Mon, Jul 23, 2012 at 05:51:32PM +0800, Wanlong Gao wrote:
- style = RStruct ("info", "xfsinfo"), [Pathname "path"], []; + style = RStruct ("info", "xfsinfo"), [String "pathordevice"], [];
Actually NACK to this. I don't understand why you don't use Dev_or_Path here.
Dev_or_Path generates RESOLVE_DEVICE code in stubs.c, then it does RESOLVE_DEVICE twice, right? Thanks, Wanlong Gao
Rich.
On Tue, Jul 24, 2012 at 04:33:46PM +0800, Wanlong Gao wrote:
On 07/24/2012 04:32 PM, Richard W.M. Jones wrote:
On Mon, Jul 23, 2012 at 05:51:32PM +0800, Wanlong Gao wrote:
- style = RStruct ("info", "xfsinfo"), [Pathname "path"], []; + style = RStruct ("info", "xfsinfo"), [String "pathordevice"], [];
Actually NACK to this. I don't understand why you don't use Dev_or_Path here.
Dev_or_Path generates RESOLVE_DEVICE code in stubs.c, then it does RESOLVE_DEVICE twice, right?
Not if you don't add RESOLVE_DEVICE to the code ... The point about the generator is that it adds all the right things for you, so you don't need to call these functions in the 'do_*' function. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
participants (2)
-
Richard W.M. Jones -
Wanlong Gao