Add the option force and lazy for force and lazy umount.
Signed-off-by: Wanlong Gao <gaowanlong(a)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