changeset 13677:a0cbef703c12

2635 'zfs rename -f' to perform force unmount Reviewed by: Matt Ahrens <matt@delphix.com> Reviewed by: George Wilson <George.Wilson@delphix.com> Reviewed by: Bill Pijewski <wdp@joyent.com> Reviewed by: Richard Elling <richard.elling@richardelling.com> Approved by: Richard Lowe <richlowe@richlowe.net>
author Eric Schrock <Eric.Schrock@delphix.com>
date Fri, 27 Apr 2012 11:14:46 -0700
parents 98ca40df9171
children 8f2b5c7a4c80
files usr/src/cmd/zfs/zfs_main.c usr/src/cmd/zoneadm/zfs.c usr/src/lib/libbe/common/be_rename.c usr/src/lib/libzfs/common/libzfs.h usr/src/lib/libzfs/common/libzfs_dataset.c usr/src/man/man1m/zfs.1m
diffstat 6 files changed, 35 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/zfs/zfs_main.c	Thu Apr 19 13:45:01 2012 -0500
+++ b/usr/src/cmd/zfs/zfs_main.c	Fri Apr 27 11:14:46 2012 -0700
@@ -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.
  * Copyright 2012 Milan Jurik. All rights reserved.
  */
 
@@ -242,9 +242,9 @@
 		"snapshot>\n"
 		"\treceive [-vnFu] [-d | -e] <filesystem>\n"));
 	case HELP_RENAME:
-		return (gettext("\trename <filesystem|volume|snapshot> "
+		return (gettext("\trename [-f] <filesystem|volume|snapshot> "
 		    "<filesystem|volume|snapshot>\n"
-		    "\trename -p <filesystem|volume> <filesystem|volume>\n"
+		    "\trename [-f] -p <filesystem|volume> <filesystem|volume>\n"
 		    "\trename -r <snapshot> <snapshot>"));
 	case HELP_ROLLBACK:
 		return (gettext("\trollback [-rRf] <snapshot>\n"));
@@ -3043,8 +3043,8 @@
 }
 
 /*
- * zfs rename <fs | snap | vol> <fs | snap | vol>
- * zfs rename -p <fs | vol> <fs | vol>
+ * zfs rename [-f] <fs | snap | vol> <fs | snap | vol>
+ * zfs rename [-f] -p <fs | vol> <fs | vol>
  * zfs rename -r <snap> <snap>
  *
  * Renames the given dataset to another of the same type.
@@ -3060,9 +3060,10 @@
 	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;
@@ -3070,6 +3071,9 @@
 		case 'r':
 			recurse = B_TRUE;
 			break;
+		case 'f':
+			force_unmount = B_TRUE;
+			break;
 		case '?':
 		default:
 			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
@@ -3120,7 +3124,7 @@
 		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);
--- a/usr/src/cmd/zoneadm/zfs.c	Thu Apr 19 13:45:01 2012 -0500
+++ b/usr/src/cmd/zoneadm/zfs.c	Fri Apr 27 11:14:46 2012 -0700
@@ -21,6 +21,7 @@
 
 /*
  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 by Delphix. All rights reserved.
  */
 
 /*
@@ -723,7 +724,7 @@
 	(void) snprintf(template, sizeof (template), "%s%d", cbp->match_name,
 	    cbp->max++);
 
-	res = (zfs_rename(zhp, template, B_FALSE) != 0);
+	res = (zfs_rename(zhp, template, B_FALSE, B_FALSE) != 0);
 	if (res != 0)
 		(void) fprintf(stderr, gettext("failed to rename snapshot %s "
 		    "to %s: %s\n"), zfs_get_name(zhp), template,
--- a/usr/src/lib/libbe/common/be_rename.c	Thu Apr 19 13:45:01 2012 -0500
+++ b/usr/src/lib/libbe/common/be_rename.c	Fri Apr 27 11:14:46 2012 -0700
@@ -21,6 +21,7 @@
 
 /*
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 by Delphix. All rights reserved.
  */
 
 #include <assert.h>
@@ -175,7 +176,7 @@
 	}
 
 	/* Rename of BE's root dataset. */
-	if (zfs_rename(zhp, bt.nbe_root_ds, B_FALSE) != 0) {
+	if (zfs_rename(zhp, bt.nbe_root_ds, B_FALSE, B_FALSE) != 0) {
 		be_print_err(gettext("be_rename: failed to "
 		    "rename dataset (%s): %s\n"), bt.obe_root_ds,
 		    libzfs_error_description(g_zfs));
--- a/usr/src/lib/libzfs/common/libzfs.h	Thu Apr 19 13:45:01 2012 -0500
+++ b/usr/src/lib/libzfs/common/libzfs.h	Fri Apr 27 11:14:46 2012 -0700
@@ -531,7 +531,7 @@
 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) */
--- a/usr/src/lib/libzfs/common/libzfs_dataset.c	Thu Apr 19 13:45:01 2012 -0500
+++ b/usr/src/lib/libzfs/common/libzfs_dataset.c	Fri Apr 27 11:14:46 2012 -0700
@@ -3546,7 +3546,8 @@
  * 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 };
@@ -3658,7 +3659,8 @@
 		}
 
 	} 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)) {
--- a/usr/src/man/man1m/zfs.1m	Thu Apr 19 13:45:01 2012 -0500
+++ b/usr/src/man/man1m/zfs.1m	Fri Apr 27 11:14:46 2012 -0700
@@ -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.
 .\" 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.
 .\"  See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with
@@ -58,13 +58,13 @@
 
 .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
@@ -1979,7 +1979,7 @@
 .sp
 .ne 2
 .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
@@ -1987,7 +1987,7 @@
 .ad
 .br
 .na
-\fB\fBzfs rename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR
+\fB\fBzfs rename\fR [\fB-fp\fR] \fIfilesystem\fR|\fIvolume\fR
 \fIfilesystem\fR|\fIvolume\fR\fR
 .ad
 .sp .6
@@ -2010,6 +2010,16 @@
 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