Add 'zfs rename -u' to rename without remounting

Allow to rename file systems without remounting if it is possible.
It is possible for file systems with 'mountpoint' property set to
'legacy' or 'none' - we don't have to change mount directory for them.
Currently such file systems are unmounted on rename and not even
mounted back.

This introduces layering violation, as we need to update
'f_mntfromname' field in statfs structure related to mountpoint (for
the dataset we are renaming and all its children).

In my opinion it is worth it, as it allow to update FreeBSD in even
cleaner way - in ZFS-only configuration root file system is ZFS file
system with 'mountpoint' property set to 'legacy'. If root dataset is
named system/rootfs, we can snapshot it (system/rootfs@upgrade), clone
it (system/oldrootfs), update FreeBSD and if it doesn't boot we can
boot back from system/oldrootfs and rename it back to system/rootfs
while it is mounted as /. Before it was not possible, because
unmounting / was not possible.

Authored by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
Reviewed-by: Allan Jude <allan@klarasystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Ported by: Matt Macy <mmacy@freebsd.org>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #10839
This commit is contained in:
Ryan Moeller
2020-09-01 19:14:16 -04:00
committed by Brian Behlendorf
parent 6512c18fe1
commit 76a157f004
21 changed files with 284 additions and 39 deletions
+13 -1
View File
@@ -642,7 +642,19 @@ extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
extern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps,
nvlist_t *props);
extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
extern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t);
typedef struct renameflags {
/* recursive rename */
int recursive : 1;
/* don't unmount file systems */
int nounmount : 1;
/* force unmount file systems */
int forceunmount : 1;
} renameflags_t;
extern int zfs_rename(zfs_handle_t *, const char *, renameflags_t);
typedef struct sendflags {
/* Amount of extra information to print. */
+4
View File
@@ -166,6 +166,10 @@ int zprop_expand_list(libzfs_handle_t *hdl, zprop_list_t **plp,
* changelist_gather() flag to force it to iterate on mounted datasets only
*/
#define CL_GATHER_ITER_MOUNTED 2
/*
* Use this changelist_gather() flag to prevent unmounting of file systems.
*/
#define CL_GATHER_DONT_UNMOUNT 4
typedef struct prop_changelist prop_changelist_t;
+1 -1
View File
@@ -6,7 +6,7 @@ KERNEL_H = \
zfs_ctldir.h \
zfs_dir.h \
zfs_ioctl_compat.h \
zfs_vfsops.h \
zfs_vfsops_os.h \
zfs_vnops.h \
zfs_znode_impl.h \
zpl.h
@@ -168,7 +168,6 @@ extern boolean_t zfs_is_readonly(zfsvfs_t *zfsvfs);
extern int zfs_get_temporary_prop(struct dsl_dataset *ds, zfs_prop_t zfs_prop,
uint64_t *val, char *setpoint);
extern int zfs_busy(void);
extern void zfsvfs_update_fromname(const char *oldname, const char *newname);
#ifdef __cplusplus
}
+1 -1
View File
@@ -19,7 +19,7 @@ KERNEL_H = \
zfs_context_os.h \
zfs_ctldir.h \
zfs_dir.h \
zfs_vfsops.h \
zfs_vfsops_os.h \
zfs_vnops.h \
zfs_znode_impl.h \
zpl.h
+1
View File
@@ -115,6 +115,7 @@ COMMON_H = \
zfs_sa.h \
zfs_stat.h \
zfs_sysfs.h \
zfs_vfsops.h \
zfs_znode.h \
zil.h \
zil_impl.h \
+35
View File
@@ -0,0 +1,35 @@
/*
* CDDL HEADER START
*
* 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 the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Portions Copyright 2020 iXsystems, Inc.
*/
#ifndef _SYS_ZFS_VFSOPS_H
#define _SYS_ZFS_VFSOPS_H
#ifdef _KERNEL
#include <sys/zfs_vfsops_os.h>
#endif
extern void zfsvfs_update_fromname(const char *, const char *);
#endif /* _SYS_ZFS_VFSOPS_H */