Wanlong Gao
2012-Jul-23 03:43 UTC
[Libguestfs] [PATCH V2 1/4] mount: add a macro to resolve path or device
Add a macro STRDUP_RESOLVE_DEVICE_OR_PATH to resolve path or device. Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com> --- daemon/daemon.h | 16 ++++++++++++++++ daemon/mount.c | 13 ++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index 85eec45..f7d0c75 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -336,6 +336,22 @@ is_zero (const char *buffer, size_t size) } \ } while (0) +/* Same as REQUIRE_ROOT_OR_RESOLVE_DEVICE but this strdup's the result. */ +#define STRDUP_RESOLVE_DEVICE_OR_PATH(path,buf,cancel_stmt,fail_stmt) \ + do { \ + int is_dev; \ + is_dev = STREQLEN (path, "/dev/", 5); \ + buf = is_dev ? strdup (path) \ + : sysroot_path (path); \ + if (buf == NULL) { \ + cancel_stmt; \ + reply_with_perror ("malloc"); \ + fail_stmt; \ + } \ + if (is_dev) \ + RESOLVE_DEVICE (buf, cancel_stmt, fail_stmt); \ + } while (0) + /* NB: * (1) You must match CHROOT_IN and CHROOT_OUT even along error paths. * (2) You must not change directory! cwd must always be "/", otherwise diff --git a/daemon/mount.c b/daemon/mount.c index 0661eb8..1843165 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -192,18 +192,9 @@ do_umount (const char *pathordevice) int r; char *err; char *buf; - int is_dev; - is_dev = STREQLEN (pathordevice, "/dev/", 5); - buf = is_dev ? strdup (pathordevice) - : sysroot_path (pathordevice); - if (buf == NULL) { - reply_with_perror ("malloc"); - return -1; - } - - if (is_dev) - RESOLVE_DEVICE (buf, , { free (buf); return -1; }); + STRDUP_RESOLVE_DEVICE_OR_PATH (pathordevice, buf, , + { free (buf); return -1;}); r = command (NULL, &err, "umount", buf, NULL); free (buf); -- 1.7.11.3.287.ge771946
Wanlong Gao
2012-Jul-23 03:43 UTC
[Libguestfs] [PATCH V2 2/4] xfs: use the added macro STRDUP_RESOLVE_DEVICE_OR_PATH
Use this macro to simplify the code. Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com> --- daemon/xfs.c | 17 +++-------------- generator/generator_actions.ml | 6 +++--- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/daemon/xfs.c b/daemon/xfs.c index 3efc14f..6736363 100644 --- a/daemon/xfs.c +++ b/daemon/xfs.c @@ -311,7 +311,7 @@ error: } guestfs_int_xfsinfo * -do_xfs_info (const char *path) +do_xfs_info (const char *pathordevice) { int r; char *buf; @@ -319,19 +319,8 @@ do_xfs_info (const char *path) char **lines = NULL; guestfs_int_xfsinfo *ret = NULL; - 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; - } - } + STRDUP_RESOLVE_DEVICE_OR_PATH (pathordevice, buf, , + {free (buf); return NULL;}); r = command (&out, &err, "xfs_info", buf, NULL); free (buf); diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 74f76bb..feb1162 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -8930,7 +8930,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 = [ @@ -8944,8 +8944,8 @@ call C<guestfs_max_disks>." }; ]; shortdesc = "get geometry of XFS filesystem"; longdesc = "\ -C<path> is a mounted XFS filesystem. This command returns the -geometry of the filesystem. +C<pathordevice> is a mounted XFS filesystem. This command returns +the geometry of the filesystem. The returned struct contains geometry information. Missing fields are returned as C<-1> (for numeric fields) or empty -- 1.7.11.3.287.ge771946
Wanlong Gao
2012-Jul-23 03:43 UTC
[Libguestfs] [PATCH V2 3/4] 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 1843165..e755e1a 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,16 +189,35 @@ 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 lazy) { int r; char *err; char *buf; + char prog[] = "umount"; + const char *argv[MAX_ARGS]; + size_t i = 0; STRDUP_RESOLVE_DEVICE_OR_PATH (pathordevice, 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_LAZE_BITMASK)) + lazy = 0; + + ADD_ARG (argv, i, prog); + + if (force) + ADD_ARG (argv, i, "-f"); + if (lazy) + 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 feb1162..da01d7e 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 "laze"]; 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
Wanlong Gao
2012-Jul-23 03:43 UTC
[Libguestfs] [PATCH V2 4/4] umount: use Dev_or_Path instead of untype
Use Dev_or_Path type for device or path arguments. Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com> --- generator/generator_actions.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index da01d7e..ca9e078 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -2749,7 +2749,7 @@ characters does I<not> work, even if the length is specified." }; { defaults with name = "umount"; - style = RErr, [String "pathordevice"], [OBool "force"; OBool "laze"]; + style = RErr, [Dev_or_Path "pathordevice"], [OBool "force"; OBool "laze"]; proc_nr = Some 45; fish_alias = ["unmount"]; once_had_no_optargs = true; -- 1.7.11.3.287.ge771946
Possibly Parallel Threads
- [PATCH 1/5] mount: add a macro to resolve path or device
- [PATCH V3 1/2] umount: add force umount and lazy umount
- [PATCH V4 1/3] umount: add force umount and lazy umount
- [PATCH 3/6] daemon: Refine check for Device and Dev_or_Path parameters (RHBZ#1477623).
- use STREQ(a,b), not strcmp(a,b) == 0