Skip to content

Commit db49968

Browse files
Eric Schrockbehlendorf
authored andcommitted
Illumos #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> References: https://www.illumos.org/issues/2635 Ported by: Martin Matuska <martin@matuska.org> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #717
1 parent e346ec2 commit db49968

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

cmd/zfs/zfs_main.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/*
2323
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2424
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
25-
* Copyright (c) 2011 by Delphix. All rights reserved.
25+
* Copyright (c) 2012 by Delphix. All rights reserved.
2626
*/
2727

2828
#include <assert.h>
@@ -243,9 +243,9 @@ get_usage(zfs_help_t idx)
243243
"snapshot>\n"
244244
"\treceive [-vnFu] [-d | -e] <filesystem>\n"));
245245
case HELP_RENAME:
246-
return (gettext("\trename <filesystem|volume|snapshot> "
246+
return (gettext("\trename [-f] <filesystem|volume|snapshot> "
247247
"<filesystem|volume|snapshot>\n"
248-
"\trename -p <filesystem|volume> <filesystem|volume>\n"
248+
"\trename [-f] -p <filesystem|volume> <filesystem|volume>\n"
249249
"\trename -r <snapshot> <snapshot>"));
250250
case HELP_ROLLBACK:
251251
return (gettext("\trollback [-rRf] <snapshot>\n"));
@@ -3069,8 +3069,8 @@ zfs_do_list(int argc, char **argv)
30693069
}
30703070

30713071
/*
3072-
* zfs rename <fs | snap | vol> <fs | snap | vol>
3073-
* zfs rename -p <fs | vol> <fs | vol>
3072+
* zfs rename [-f] <fs | snap | vol> <fs | snap | vol>
3073+
* zfs rename [-f] -p <fs | vol> <fs | vol>
30743074
* zfs rename -r <snap> <snap>
30753075
*
30763076
* Renames the given dataset to another of the same type.
@@ -3086,16 +3086,20 @@ zfs_do_rename(int argc, char **argv)
30863086
int ret = 0;
30873087
boolean_t recurse = B_FALSE;
30883088
boolean_t parents = B_FALSE;
3089+
boolean_t force_unmount = B_FALSE;
30893090

30903091
/* check options */
3091-
while ((c = getopt(argc, argv, "pr")) != -1) {
3092+
while ((c = getopt(argc, argv, "prf")) != -1) {
30923093
switch (c) {
30933094
case 'p':
30943095
parents = B_TRUE;
30953096
break;
30963097
case 'r':
30973098
recurse = B_TRUE;
30983099
break;
3100+
case 'f':
3101+
force_unmount = B_TRUE;
3102+
break;
30993103
case '?':
31003104
default:
31013105
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
@@ -3146,7 +3150,7 @@ zfs_do_rename(int argc, char **argv)
31463150
return (1);
31473151
}
31483152

3149-
ret = (zfs_rename(zhp, argv[1], recurse) != 0);
3153+
ret = (zfs_rename(zhp, argv[1], recurse, force_unmount) != 0);
31503154

31513155
zfs_close(zhp);
31523156
return (ret);

include/libzfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ extern int zfs_destroy_snaps_nvl(zfs_handle_t *, nvlist_t *, boolean_t);
553553
extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
554554
extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
555555
extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
556-
extern int zfs_rename(zfs_handle_t *, const char *, boolean_t);
556+
extern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t);
557557

558558
typedef struct sendflags {
559559
/* print informational messages (ie, -v was specified) */

lib/libzfs/libzfs_dataset.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3760,7 +3760,8 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
37603760
* Renames the given dataset.
37613761
*/
37623762
int
3763-
zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive)
3763+
zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive,
3764+
boolean_t force_unmount)
37643765
{
37653766
int ret;
37663767
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)
38823883
goto error;
38833884
}
38843885
} else {
3885-
if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0, 0)) == NULL)
3886+
if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0,
3887+
force_unmount ? MS_FORCE : 0)) == NULL)
38863888
return (-1);
38873889

38883890
if (changelist_haszonedchild(cl)) {

man/man8/zfs.8

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'\" te
22
.\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
3-
.\" Copyright (c) 2011 by Delphix. All rights reserved.
3+
.\" Copyright (c) 2012 by Delphix. All rights reserved.
44
.\" Copyright (c) 2012 Nexenta Systems, Inc. All Rights Reserved.
55
.\" Copyright 2011 Joshua M. Clulow <josh@sysmgr.org>
66
.\" 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
5858

5959
.LP
6060
.nf
61-
\fBzfs\fR \fBrename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR
61+
\fBzfs\fR \fBrename\fR [\fB-f\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR
6262
\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR
6363
.fi
6464

6565
.LP
6666
.nf
67-
\fBzfs\fR \fBrename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR
67+
\fBzfs\fR \fBrename\fR [\fB-fp\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR
6868
.fi
6969

7070
.LP
@@ -1576,15 +1576,15 @@ The snapshot that was cloned, and any snapshots previous to this snapshot, are n
15761576
.ne 2
15771577
.mk
15781578
.na
1579-
\fB\fBzfs rename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR
1579+
\fB\fBzfs rename\fR [\fB-f\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR
15801580
.ad
15811581
.br
15821582
.na
15831583
\fB\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR
15841584
.ad
15851585
.br
15861586
.na
1587-
\fB\fBzfs rename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR\fR
1587+
\fB\fBzfs rename\fR [\fB-fp\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR\fR
15881588
.ad
15891589
.sp .6
15901590
.RS 4n
@@ -1600,6 +1600,16 @@ Renames the given dataset. The new target can be located anywhere in the \fBZFS\
16001600
Creates all the nonexistent parent datasets. Datasets created in this manner are automatically mounted according to the \fBmountpoint\fR property inherited from their parent.
16011601
.RE
16021602

1603+
.sp
1604+
.ne 2
1605+
.na
1606+
\fB\fB-f\fR\fR
1607+
.ad
1608+
.sp .6
1609+
.RS 4n
1610+
Force unmount any filesystems that need to be unmounted in the process.
1611+
.RE
1612+
16031613
.RE
16041614

16051615
.sp

0 commit comments

Comments
 (0)