Date: Mon, 30 Apr 2012 07:49:07 GMT From: Marcelo Araujo <araujo@FreeBSD.org> To: freebsd-gnats-submit@FreeBSD.org Subject: kern/167447: zfs rename with forced options to unmount. Message-ID: <201204300749.q3U7n7gq090239@red.freebsd.org> Resent-Message-ID: <201204300750.q3U7oJri065292@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 167447 >Category: kern >Synopsis: zfs rename with forced options to unmount. >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Apr 30 07:50:19 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Marcelo Araujo >Release: 10.0-CURRENT >Organization: FreeBSD >Environment: FreeBSD hosta 10.0-CURRENT FreeBSD 10.0-CURRENT #2 r233530M: Mon Apr 23 11:51:58 UTC 2012 araujo@hosta:/usr/obj/usr/src/sys/HOSTA i386 >Description: Now is possible to use zfs rename -f to perform a force unmount. Based on Illumos-gate commit: a0cbef703c12 by Matt Ahrens. >How-To-Repeat: hosta# zfs rename -fp tank/oi tank/araujo hosta# zfs list NAME USED AVAIL REFER MOUNTPOINT tank 20.4M 39.1G 1.69M /tank tank/araujo 31K 39.1G 31K /tank/araujo tank/jail 31K 39.1G 31K /tank/jail tank/tank1 9.73M 39.1G 1.68M /tank/tank1 >Fix: Patch attached with submission follows: diff -r cfd524f8839b cddl/contrib/opensolaris/cmd/zfs/zfs.8 --- a/cddl/contrib/opensolaris/cmd/zfs/zfs.8 Sat Apr 28 23:13:09 2012 +0000 +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs.8 Mon Apr 30 04:42:55 2012 +0000 @@ -18,9 +18,10 @@ .\" information: Portions Copyright [yyyy] [name of copyright owner] .\" .\" Copyright (c) 2010, 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 (c) 2011, Pawel Jakub Dawidek <pjd@FreeBSD.org> +.\" Copyright (c) 2012, Marcelo Araujo <araujo@FreeBSD.org> .\" .\" $FreeBSD$ .\" @@ -81,7 +82,7 @@ .Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot .Nm .Cm rename -.Fl p +.Fl fp .Ar filesystem Ns | Ns Ar volume .Ar filesystem Ns | Ns Ar volume .Nm @@ -1646,6 +1647,7 @@ .It Xo .Nm .Cm rename +.Fl fp .Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot .Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot .Xc @@ -1677,6 +1679,10 @@ are automatically mounted according to the .Sy mountpoint property inherited from their parent. +.It Fl f +Force +.Sy unmount +any filesystems that need to be unmounted in the process. .It Fl u Do not remount file systems during rename. If a file system's .Sy mountpoint diff -r cfd524f8839b cddl/contrib/opensolaris/cmd/zfs/zfs_main.c --- a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c Sat Apr 28 23:13:09 2012 +0000 +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c Mon Apr 30 04:42:55 2012 +0000 @@ -22,10 +22,11 @@ /* * 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 (c) 2011-2012 Pawel Jakub Dawidek <pawel@dawidek.net>. * All rights reserved. * Copyright (c) 2011 Martin Matuska <mm@FreeBSD.org>. All rights reserved. + * Copyright (c) 2012 Marcelo Araujo <araujo@FreeBSD.org>. All rights reserved. */ #include <assert.h> @@ -256,9 +257,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>\n" "\trename -u [-p] <filesystem> <filesystem>")); case HELP_ROLLBACK: @@ -3091,8 +3092,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> * zfs rename -u [-p] <fs> <fs> * @@ -3110,9 +3111,10 @@ int ret = 0; int types; boolean_t parents = B_FALSE; + boolean_t force_unmount = B_FALSE; /* check options */ - while ((c = getopt(argc, argv, "pru")) != -1) { + while ((c = getopt(argc, argv, "pruf")) != -1) { switch (c) { case 'p': parents = B_TRUE; @@ -3123,6 +3125,9 @@ case 'u': flags.nounmount = B_TRUE; break; + case 'f': + force_unmount = B_TRUE; + break; case '?': default: (void) fprintf(stderr, gettext("invalid option '%c'\n"), @@ -3185,7 +3190,7 @@ return (1); } - ret = (zfs_rename(zhp, argv[1], flags) != 0); + ret = (zfs_rename(zhp, argv[1], flags, force_unmount) != 0); zfs_close(zhp); return (ret); diff -r cfd524f8839b cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h Sat Apr 28 23:13:09 2012 +0000 +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h Mon Apr 30 04:42:55 2012 +0000 @@ -543,7 +543,7 @@ int nounmount : 1; } renameflags_t; -extern int zfs_rename(zfs_handle_t *, const char *, renameflags_t flags); +extern int zfs_rename(zfs_handle_t *, const char *, renameflags_t flags, boolean_t); typedef struct sendflags { /* print informational messages (ie, -v was specified) */ diff -r cfd524f8839b cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c Sat Apr 28 23:13:09 2012 +0000 +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_dataset.c Mon Apr 30 04:42:55 2012 +0000 @@ -3594,7 +3594,8 @@ * Renames the given dataset. */ int -zfs_rename(zfs_handle_t *zhp, const char *target, renameflags_t flags) +zfs_rename(zfs_handle_t *zhp, const char *target, renameflags_t flags, + boolean_t force_unmount) { int ret; zfs_cmd_t zc = { 0 }; @@ -3721,7 +3722,8 @@ } else { if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, - flags.nounmount ? CL_GATHER_DONT_UNMOUNT : 0, 0)) == NULL) { + flags.nounmount ? CL_GATHER_DONT_UNMOUNT : 0 || + (int)force_unmount ? MS_FORCE : 0, 0)) == NULL) { return (-1); } >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204300749.q3U7n7gq090239>