Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Commit

Permalink
2635 'zfs rename -f' to perform force unmount
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Schrock authored and Eric Schrock committed Apr 27, 2012
1 parent 7d7551b commit 6a9cb0e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
18 changes: 11 additions & 7 deletions usr/src/cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -242,9 +242,9 @@ get_usage(zfs_help_t idx)
"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"));
Expand Down Expand Up @@ -3043,8 +3043,8 @@ zfs_do_list(int argc, char **argv)
}

/*
* 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.
Expand All @@ -3060,16 +3060,20 @@ 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;
break;
case 'r':
recurse = B_TRUE;
break;
case 'f':
force_unmount = B_TRUE;
break;
case '?':
default:
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
Expand Down Expand Up @@ -3120,7 +3124,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);
Expand Down
3 changes: 2 additions & 1 deletion usr/src/cmd/zoneadm/zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
*/

/*
Expand Down Expand Up @@ -723,7 +724,7 @@ rename_snap(zfs_handle_t *zhp, void *data)
(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,
Expand Down
3 changes: 2 additions & 1 deletion usr/src/lib/libbe/common/be_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -175,7 +176,7 @@ be_rename(nvlist_t *be_attrs)
}

/* 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));
Expand Down
2 changes: 1 addition & 1 deletion usr/src/lib/libzfs/common/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,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) */
Expand Down
6 changes: 4 additions & 2 deletions usr/src/lib/libzfs/common/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3546,7 +3546,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 };
Expand Down Expand Up @@ -3658,7 +3659,8 @@ zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive)
}

} 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)) {
Expand Down
20 changes: 15 additions & 5 deletions usr/src/man/man1m/zfs.1m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1979,15 +1979,15 @@ any conflicting snapshots.
.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
\fB\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR
.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
Expand All @@ -2010,6 +2010,16 @@ 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
Expand Down

0 comments on commit 6a9cb0e

Please sign in to comment.