From db49968e5ca7814bf833477f27c148208a835a7d Mon Sep 17 00:00:00 2001 From: Eric Schrock Date: Fri, 27 Apr 2012 11:14:46 -0700 Subject: [PATCH] Illumos #2635: 'zfs rename -f' to perform force unmount Reviewed by: Matt Ahrens Reviewed by: George Wilson Reviewed by: Bill Pijewski Reviewed by: Richard Elling Approved by: Richard Lowe References: https://www.illumos.org/issues/2635 Ported by: Martin Matuska Signed-off-by: Brian Behlendorf Closes #717 --- cmd/zfs/zfs_main.c | 18 +++++++++++------- include/libzfs.h | 2 +- lib/libzfs/libzfs_dataset.c | 6 ++++-- man/man8/zfs.8 | 20 +++++++++++++++----- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 9efd03723e..d185a31482 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -22,7 +22,7 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2012 Nexenta Systems, Inc. All rights reserved. - * Copyright (c) 2011 by Delphix. All rights reserved. + * Copyright (c) 2012 by Delphix. All rights reserved. */ #include @@ -243,9 +243,9 @@ get_usage(zfs_help_t idx) "snapshot>\n" "\treceive [-vnFu] [-d | -e] \n")); case HELP_RENAME: - return (gettext("\trename " + return (gettext("\trename [-f] " "\n" - "\trename -p \n" + "\trename [-f] -p \n" "\trename -r ")); case HELP_ROLLBACK: return (gettext("\trollback [-rRf] \n")); @@ -3069,8 +3069,8 @@ zfs_do_list(int argc, char **argv) } /* - * zfs rename - * zfs rename -p + * zfs rename [-f] + * zfs rename [-f] -p * zfs rename -r * * Renames the given dataset to another of the same type. @@ -3086,9 +3086,10 @@ zfs_do_rename(int argc, char **argv) int ret = 0; boolean_t recurse = B_FALSE; boolean_t parents = B_FALSE; + boolean_t force_unmount = B_FALSE; /* check options */ - while ((c = getopt(argc, argv, "pr")) != -1) { + while ((c = getopt(argc, argv, "prf")) != -1) { switch (c) { case 'p': parents = B_TRUE; @@ -3096,6 +3097,9 @@ zfs_do_rename(int argc, char **argv) case 'r': recurse = B_TRUE; break; + case 'f': + force_unmount = B_TRUE; + break; case '?': default: (void) fprintf(stderr, gettext("invalid option '%c'\n"), @@ -3146,7 +3150,7 @@ zfs_do_rename(int argc, char **argv) return (1); } - ret = (zfs_rename(zhp, argv[1], recurse) != 0); + ret = (zfs_rename(zhp, argv[1], recurse, force_unmount) != 0); zfs_close(zhp); return (ret); diff --git a/include/libzfs.h b/include/libzfs.h index 83e1bee6e7..c7a7daf2f3 100644 --- a/include/libzfs.h +++ b/include/libzfs.h @@ -553,7 +553,7 @@ extern int zfs_destroy_snaps_nvl(zfs_handle_t *, nvlist_t *, boolean_t); extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t); -extern int zfs_rename(zfs_handle_t *, const char *, boolean_t); +extern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t); typedef struct sendflags { /* print informational messages (ie, -v was specified) */ diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index 2d795d33aa..f216291d29 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -3760,7 +3760,8 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force) * Renames the given dataset. */ int -zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive) +zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive, + boolean_t force_unmount) { int ret; zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; @@ -3882,7 +3883,8 @@ zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive) goto error; } } else { - if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0, 0)) == NULL) + if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0, + force_unmount ? MS_FORCE : 0)) == NULL) return (-1); if (changelist_haszonedchild(cl)) { diff --git a/man/man8/zfs.8 b/man/man8/zfs.8 index 1570caf9fe..508270634f 100644 --- a/man/man8/zfs.8 +++ b/man/man8/zfs.8 @@ -1,6 +1,6 @@ '\" te .\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. -.\" Copyright (c) 2011 by Delphix. All rights reserved. +.\" Copyright (c) 2012 by Delphix. All rights reserved. .\" Copyright (c) 2012 Nexenta Systems, Inc. All Rights Reserved. .\" Copyright 2011 Joshua M. Clulow .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. @@ -58,13 +58,13 @@ zfs \- configures ZFS file systems .LP .nf -\fBzfs\fR \fBrename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR +\fBzfs\fR \fBrename\fR [\fB-f\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR .fi .LP .nf -\fBzfs\fR \fBrename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR +\fBzfs\fR \fBrename\fR [\fB-fp\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR .fi .LP @@ -1576,7 +1576,7 @@ The snapshot that was cloned, and any snapshots previous to this snapshot, are n .ne 2 .mk .na -\fB\fBzfs rename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR +\fB\fBzfs rename\fR [\fB-f\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR .ad .br .na @@ -1584,7 +1584,7 @@ The snapshot that was cloned, and any snapshots previous to this snapshot, are n .ad .br .na -\fB\fBzfs rename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR\fR +\fB\fBzfs rename\fR [\fB-fp\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR\fR .ad .sp .6 .RS 4n @@ -1600,6 +1600,16 @@ Renames the given dataset. The new target can be located anywhere in the \fBZFS\ Creates all the nonexistent parent datasets. Datasets created in this manner are automatically mounted according to the \fBmountpoint\fR property inherited from their parent. .RE +.sp +.ne 2 +.na +\fB\fB-f\fR\fR +.ad +.sp .6 +.RS 4n +Force unmount any filesystems that need to be unmounted in the process. +.RE + .RE .sp