Skip to content

Commit

Permalink
Want lazy unmount support
Browse files Browse the repository at this point in the history
Add "-l" option to perform a lazy unmount in "zfs unmount", "zpool export"
and "zpool destroy".

Signed-off-by: Tim Chase <[email protected]>
Requires-builders: none
  • Loading branch information
dweeezil committed Jan 7, 2018
1 parent d29cc35 commit e865f67
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
7 changes: 5 additions & 2 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6563,13 +6563,16 @@ unshare_unmount(int op, int argc, char **argv)
char sharesmb[ZFS_MAXPROPLEN];

/* check options */
while ((c = getopt(argc, argv, op == OP_SHARE ? ":a" : "af")) != -1) {
while ((c = getopt(argc, argv, op == OP_SHARE ? ":a" : "afl")) != -1) {
switch (c) {
case 'a':
do_all = 1;
break;
case 'f':
flags = MS_FORCE;
flags |= MS_FORCE;
break;
case 'l':
flags |= MS_DETACH;
break;
case ':':
(void) fprintf(stderr, gettext("missing argument for "
Expand Down
20 changes: 15 additions & 5 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ get_usage(zpool_help_t idx)
"\t [-O file-system-property=value] ... \n"
"\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
case HELP_DESTROY:
return (gettext("\tdestroy [-f] <pool>\n"));
return (gettext("\tdestroy [-fl] <pool>\n"));
case HELP_DETACH:
return (gettext("\tdetach <pool> <device>\n"));
case HELP_EXPORT:
Expand Down Expand Up @@ -1314,17 +1314,21 @@ int
zpool_do_destroy(int argc, char **argv)
{
boolean_t force = B_FALSE;
boolean_t lazy = B_FALSE;
int c;
char *pool;
zpool_handle_t *zhp;
int ret;

/* check options */
while ((c = getopt(argc, argv, "f")) != -1) {
while ((c = getopt(argc, argv, "fl")) != -1) {
switch (c) {
case 'f':
force = B_TRUE;
break;
case 'l':
lazy = B_TRUE;
break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
Expand Down Expand Up @@ -1358,7 +1362,7 @@ zpool_do_destroy(int argc, char **argv)
return (1);
}

if (zpool_disable_datasets(zhp, force) != 0) {
if (zpool_disable_datasets(zhp, force, lazy) != 0) {
(void) fprintf(stderr, gettext("could not destroy '%s': "
"could not unmount datasets\n"), zpool_get_name(zhp));
zpool_close(zhp);
Expand All @@ -1378,6 +1382,7 @@ zpool_do_destroy(int argc, char **argv)
typedef struct export_cbdata {
boolean_t force;
boolean_t hardforce;
boolean_t lazy;
} export_cbdata_t;

/*
Expand All @@ -1388,7 +1393,7 @@ zpool_export_one(zpool_handle_t *zhp, void *data)
{
export_cbdata_t *cb = data;

if (zpool_disable_datasets(zhp, cb->force) != 0)
if (zpool_disable_datasets(zhp, cb->force, cb->lazy) != 0)
return (1);

/* The history must be logged as part of the export */
Expand Down Expand Up @@ -1421,10 +1426,11 @@ zpool_do_export(int argc, char **argv)
boolean_t do_all = B_FALSE;
boolean_t force = B_FALSE;
boolean_t hardforce = B_FALSE;
boolean_t lazy = B_FALSE;
int c, ret;

/* check options */
while ((c = getopt(argc, argv, "afF")) != -1) {
while ((c = getopt(argc, argv, "afFl")) != -1) {
switch (c) {
case 'a':
do_all = B_TRUE;
Expand All @@ -1435,6 +1441,9 @@ zpool_do_export(int argc, char **argv)
case 'F':
hardforce = B_TRUE;
break;
case 'l':
lazy = B_TRUE;
break;
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
Expand All @@ -1444,6 +1453,7 @@ zpool_do_export(int argc, char **argv)

cb.force = force;
cb.hardforce = hardforce;
cb.lazy = lazy;
argc -= optind;
argv += optind;

Expand Down
2 changes: 1 addition & 1 deletion include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *);
* sharing/unsharing them.
*/
extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
extern int zpool_disable_datasets(zpool_handle_t *, boolean_t, boolean_t);

/*
* Support for Linux libudev derived persistent device strings
Expand Down
4 changes: 3 additions & 1 deletion lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ mountpoint_compare(const void *a, const void *b)
* and gather all the filesystems that are currently mounted.
*/
int
zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force, boolean_t lazy)
{
int used, alloc;
struct mnttab entry;
Expand All @@ -1337,6 +1337,8 @@ zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
int ret = -1;
int flags = (force ? MS_FORCE : 0);

if (lazy)
flags |= MS_DETACH;
namelen = strlen(zhp->zpool_name);

/* Reopen MNTTAB to prevent reading stale data from open file */
Expand Down
7 changes: 5 additions & 2 deletions man/man8/zfs.8
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
.Fl a | Ar filesystem
.Nm
.Cm unmount
.Op Fl f
.Op Fl fl
.Fl a | Ar filesystem Ns | Ns Ar mountpoint
.Nm
.Cm share
Expand Down Expand Up @@ -3029,7 +3029,7 @@ Report mount progress.
.It Xo
.Nm
.Cm unmount
.Op Fl f
.Op Fl fl
.Fl a | Ar filesystem Ns | Ns Ar mountpoint
.Xc
Unmounts currently mounted ZFS file systems.
Expand All @@ -3043,6 +3043,9 @@ The command can also be given a path to a ZFS file system mount point on the
system.
.It Fl f
Forcefully unmount the file system, even if it is currently in use.
.It Fl l
Lazy unmount. Detaches the filesystem immediately and frees kernel
resources once it is not busy any more.
.El
.It Xo
.Nm
Expand Down
8 changes: 8 additions & 0 deletions man/man8/zpool.8
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
.Nm
.Cm destroy
.Op Fl f
.Op Fl l
.Ar pool
.Nm
.Cm detach
Expand All @@ -73,6 +74,7 @@
.Cm export
.Op Fl a
.Op Fl f
.Op Fl l
.Ar pool Ns ...
.Nm
.Cm get
Expand Down Expand Up @@ -1003,13 +1005,16 @@ block devices.
.Nm
.Cm destroy
.Op Fl f
.Op Fl l
.Ar pool
.Xc
Destroys the given pool, freeing up any devices for other use.
This command tries to unmount any active datasets before destroying the pool.
.Bl -tag -width Ds
.It Fl f
Forces any active datasets contained within the pool to be unmounted.
.It Fl l
Performs a lazy unmount for each mounted dataset within the pool.
.El
.It Xo
.Nm
Expand Down Expand Up @@ -1052,6 +1057,7 @@ Print the entire payload for each event.
.Cm export
.Op Fl a
.Op Fl f
.Op Fl l
.Ar pool Ns ...
.Xc
Exports the given pools from the system.
Expand All @@ -1078,6 +1084,8 @@ Exports all pools imported on the system.
Forcefully unmount all datasets, using the
.Nm unmount Fl f
command.
.It Fl l
Performs a lazy unmount for each mounted dataset within the pool.
.Pp
This command will forcefully export the pool even if it has a shared spare that
is currently being used.
Expand Down

0 comments on commit e865f67

Please sign in to comment.