From f67d709080f3d4a247191f0d25cbedc5da103f78 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Fri, 25 Jul 2014 12:42:00 +0200 Subject: [PATCH] Create an 'overlay' property Add a new 'overlay' property (default 'off') that controls whether the filesystem should be mounted even if the mountpoint is busy or if it should fail with a 'mountpoint not empty'. Doing overlay mounts is the default mount behavior on Linux, but not in ZFS. It have been decided that following the ZFS behavior should be the default, but this overlay allows for site administrator to override this decision on a per-dataset basis. Signed-off-by: Turbo Fredriksson Signed-off-by: Brian Behlendorf Closes: #2503 --- cmd/zfs/zfs_main.c | 14 ++++++++++++++ include/sys/fs/zfs.h | 1 + man/man8/zfs.8 | 11 +++++++++++ module/zcommon/zfs_prop.c | 2 ++ 4 files changed, 28 insertions(+) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 84073435e2..83f02666d2 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -5641,6 +5641,7 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol, char mountpoint[ZFS_MAXPROPLEN]; char shareopts[ZFS_MAXPROPLEN]; char smbshareopts[ZFS_MAXPROPLEN]; + char overlay[ZFS_MAXPROPLEN]; const char *cmdname = op == OP_SHARE ? "share" : "mount"; struct mnttab mnt; uint64_t zoned, canmount; @@ -5747,6 +5748,19 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol, return (0); } + /* + * Overlay mounts are disabled by default but may be enabled + * via the 'overlay' property or the 'zfs mount -O' option. + */ + if (!(flags & MS_OVERLAY)) { + if (zfs_prop_get(zhp, ZFS_PROP_OVERLAY, overlay, + sizeof (overlay), NULL, NULL, 0, B_FALSE) == 0) { + if (strcmp(overlay, "on") == 0) { + flags |= MS_OVERLAY; + } + } + } + /* * At this point, we have verified that the mountpoint and/or * shareopts are appropriate for auto management. If the diff --git a/include/sys/fs/zfs.h b/include/sys/fs/zfs.h index 227d8b2fbd..d54cd56790 100644 --- a/include/sys/fs/zfs.h +++ b/include/sys/fs/zfs.h @@ -150,6 +150,7 @@ typedef enum { ZFS_PROP_SELINUX_ROOTCONTEXT, ZFS_PROP_RELATIME, ZFS_PROP_REDUNDANT_METADATA, + ZFS_PROP_OVERLAY, ZFS_NUM_PROPS } zfs_prop_t; diff --git a/man/man8/zfs.8 b/man/man8/zfs.8 index 96cac6f5a8..8b22c5af46 100644 --- a/man/man8/zfs.8 +++ b/man/man8/zfs.8 @@ -1409,6 +1409,17 @@ This flag sets the SELinux context for unlabeled files. See \fBselinux\fR(8) fo This flag sets the SELinux context for the root inode of the filesystem. See \fBselinux\fR(8) for more information. .RE +.sp +.ne 2 +.mk +.na +\fB\fBoverlay\fR=\fBon\fR | \fBoff\fR\fR +.ad +.sp .6 +.RS 4n +Allow mounting on a busy directory or a directory which already contains files/directories. This is the default mount behavior for Linux filesystems. However, for consistency with ZFS on other platforms overlay mounts are disabled by default. Set \fBoverlay=on\fR to enable overlay mounts. +.RE + .SS "Temporary Mount Point Properties" .LP When a file system is mounted, either through \fBmount\fR(8) for legacy mounts or the \fBzfs mount\fR command for normal file systems, its mount options are set according to its properties. The correlation between properties and mount options is as follows: diff --git a/module/zcommon/zfs_prop.c b/module/zcommon/zfs_prop.c index 77491cdb74..e60c4f7d42 100644 --- a/module/zcommon/zfs_prop.c +++ b/module/zcommon/zfs_prop.c @@ -295,6 +295,8 @@ zfs_prop_init(void) zprop_register_index(ZFS_PROP_NBMAND, "nbmand", 0, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "on | off", "NBMAND", boolean_table); + zprop_register_index(ZFS_PROP_OVERLAY, "overlay", 0, PROP_INHERIT, + ZFS_TYPE_FILESYSTEM, "on | off", "OVERLAY", boolean_table); /* default index properties */ zprop_register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT,