From f5f6fb03b7e5e3d06da4c04b26319758568ae238 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Fri, 6 Mar 2020 12:28:19 -0500 Subject: [PATCH] Change default to overlay=on Filesystems allow overlay mounts by default on FreeBSD and Linux. Respect the native convention by switching the default to overlay=on, while retaining the option to turn the property off for compatibility with other operating systems' conventions. Update documentation and tests accordingly. Reviewed-by: Richard Laager Reviewed-by: Brian Behlendorf Signed-off-by: Ryan Moeller Closes #10030 --- lib/libzfs/libzfs_mount.c | 6 +-- man/man8/zfsprops.8 | 14 ++++--- module/zcommon/zfs_prop.c | 2 +- tests/runfiles/common.run | 2 +- .../functional/cli_root/zfs_mount/Makefile.am | 2 +- .../cli_root/zfs_mount/zfs_mount_006_pos.ksh | 38 +++++++++---------- .../cli_root/zfs_mount/zfs_mount_008_pos.ksh | 3 +- ...ount_012_neg.ksh => zfs_mount_012_pos.ksh} | 23 +++-------- .../cli_root/zfs_mount/zfs_mount_all_fail.ksh | 27 ++++++------- 9 files changed, 53 insertions(+), 64 deletions(-) rename tests/zfs-tests/tests/functional/cli_root/zfs_mount/{zfs_mount_012_neg.ksh => zfs_mount_012_pos.ksh} (74%) diff --git a/lib/libzfs/libzfs_mount.c b/lib/libzfs/libzfs_mount.c index c3fe97d55..4d4b49753 100644 --- a/lib/libzfs/libzfs_mount.c +++ b/lib/libzfs/libzfs_mount.c @@ -474,8 +474,8 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags, } /* - * Overlay mounts are disabled by default but may be enabled - * via the 'overlay' property or the 'zfs mount -O' option. + * Overlay mounts are enabled by default but may be disabled + * via the 'overlay' property. The -O flag remains for compatibility. */ if (!(flags & MS_OVERLAY)) { if (zfs_prop_get(zhp, ZFS_PROP_OVERLAY, overlay, @@ -489,7 +489,7 @@ zfs_mount_at(zfs_handle_t *zhp, const char *options, int flags, /* * Determine if the mountpoint is empty. If so, refuse to perform the * mount. We don't perform this check if 'remount' is - * specified or if overlay option(-O) is given + * specified or if overlay option (-O) is given */ if ((flags & MS_OVERLAY) == 0 && !remount && !dir_is_empty(mountpoint)) { diff --git a/man/man8/zfsprops.8 b/man/man8/zfsprops.8 index a0a0c46ac..b87e3e608 100644 --- a/man/man8/zfsprops.8 +++ b/man/man8/zfsprops.8 @@ -1157,14 +1157,16 @@ See for more information on .Sy nbmand mounts. This property is not used on Linux. -.It Sy overlay Ns = Ns Sy off Ns | Ns Sy on +.It Sy overlay Ns = Ns Sy on Ns | Ns Sy off Allow mounting on a busy directory or a directory which already contains -files or directories. This is the default mount behavior for Linux file systems. -For consistency with OpenZFS on other platforms overlay mounts are -.Sy off -by default. Set to +files or directories. +This is the default mount behavior for Linux and FreeBSD file systems. +On these platforms the property is .Sy on -to enable overlay mounts. +by default. +Set to +.Sy off +to disable overlay mounts for consistency with OpenZFS on other platforms. .It Sy primarycache Ns = Ns Sy all Ns | Ns Sy none Ns | Ns Sy metadata Controls what is cached in the primary cache .Pq ARC . diff --git a/module/zcommon/zfs_prop.c b/module/zcommon/zfs_prop.c index 8dfadfaaf..3ba3b8a84 100644 --- a/module/zcommon/zfs_prop.c +++ b/module/zcommon/zfs_prop.c @@ -406,7 +406,7 @@ 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, + zprop_register_index(ZFS_PROP_OVERLAY, "overlay", 1, PROP_INHERIT, ZFS_TYPE_FILESYSTEM, "on | off", "OVERLAY", boolean_table); /* default index properties */ diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index ea26a3ae3..f2107f47b 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -181,7 +181,7 @@ tags = ['functional', 'cli_root', 'zfs_load-key'] tests = ['zfs_mount_001_pos', 'zfs_mount_002_pos', 'zfs_mount_003_pos', 'zfs_mount_004_pos', 'zfs_mount_005_pos', 'zfs_mount_007_pos', 'zfs_mount_009_neg', 'zfs_mount_010_neg', 'zfs_mount_011_neg', - 'zfs_mount_012_neg', 'zfs_mount_all_001_pos', 'zfs_mount_encrypted', + 'zfs_mount_012_pos', 'zfs_mount_all_001_pos', 'zfs_mount_encrypted', 'zfs_mount_remount', 'zfs_mount_all_fail', 'zfs_mount_all_mountpoints', 'zfs_mount_test_race'] tags = ['functional', 'cli_root', 'zfs_mount'] diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am index 8a137b830..37c094238 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am @@ -13,7 +13,7 @@ dist_pkgdata_SCRIPTS = \ zfs_mount_009_neg.ksh \ zfs_mount_010_neg.ksh \ zfs_mount_011_neg.ksh \ - zfs_mount_012_neg.ksh \ + zfs_mount_012_pos.ksh \ zfs_mount_all_001_pos.ksh \ zfs_mount_all_fail.ksh \ zfs_mount_all_mountpoints.ksh \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos.ksh index 5c954354d..5edce35c7 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_006_pos.ksh @@ -35,22 +35,20 @@ # # DESCRIPTION: -# Invoke "zfs mount " with a filesystem -# mountpoint that is identical to an existing one. -# It will fail with a return code of 1. For Linux, -# place a file in the directory to ensure the failure. -# Also for Linux, test overlay=off (default) in which case -# the mount will fail, and overlay=on, where the mount -# will succeed. +# Invoke "zfs mount " with a filesystem mountpoint that is +# identical to an existing one. It will fail with a return code of 1 +# when overlay=off. Place a file in the directory to ensure the failure. +# Also test overlay=on (default) in which case the mount will not fail. # # STRATEGY: # 1. Prepare an existing mounted filesystem. -# 2. Setup a new filesystem and make sure that it is unmounted. -# 3. For Linux, place a file in the mount point folder. -# 4. Mount the new filesystem using the various combinations -# - zfs set mountpoint= -# - zfs set mountpoint= -# 5. Verify that mount failed with return code of 1. +# 2. Setup a new filesystem with overlay=off and make sure that it is +# unmounted. +# 3. Place a file in the mount point folder. +# 4. Mount the new filesystem using the various combinations +# - zfs set mountpoint= +# - zfs set mountpoint= +# 5. Verify that mount failed with return code of 1. # 6. For Linux, also set overlay=on and verify the mount is # allowed. # @@ -76,7 +74,7 @@ typeset -i ret=0 log_assert "Verify that 'zfs $mountcmd '" \ "where the mountpoint is identical or on top of an existing one" \ - "will fail with return code 1." + "will fail with return code 1 when overlay=off." log_onexit cleanup @@ -98,8 +96,8 @@ done log_must zfs set mountpoint=$mtpt $TESTPOOL/$TESTFS log_must zfs $mountcmd $TESTPOOL/$TESTFS -if is_linux; then - log_must zfs set overlay=off $TESTPOOL/$TESTFS +log_must zfs set overlay=off $TESTPOOL/$TESTFS +if ! is_illumos; then touch $mtpt/file.1 log_must ls -l $mtpt | grep file fi @@ -107,7 +105,7 @@ fi mounted $TESTPOOL/$TESTFS || \ log_unresolved "Filesystem $TESTPOOL/$TESTFS is unmounted" -log_must zfs create $TESTPOOL/$TESTFS1 +log_must zfs create -o overlay=off $TESTPOOL/$TESTFS1 unmounted $TESTPOOL/$TESTFS1 || \ log_must force_unmount $TESTPOOL/$TESTFS1 @@ -123,9 +121,9 @@ while [[ $depth -gt 0 ]] ; do log_mustnot zfs $mountcmd $TESTPOOL/$TESTFS1 - # For Linux, test the overlay=on feature which allows - # mounting of non-empty directory. - if is_linux; then + if ! is_illumos; then + # Test the overlay=on feature which allows + # mounting of non-empty directory. log_must zfs set overlay=on $TESTPOOL/$TESTFS1 log_must zfs $mountcmd $TESTPOOL/$TESTFS1 log_must force_unmount $TESTPOOL/$TESTFS1 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh index 84835a0d6..4b3bf40bc 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh @@ -73,7 +73,8 @@ log_must mkfile 1M $testfile $testfile1 log_must zfs unmount $fs1 log_must zfs set mountpoint=$mntpnt $fs1 -log_mustnot zfs mount $fs1 +log_must zfs mount $fs1 +log_must zfs unmount $fs1 log_must zfs mount -O $fs1 # Create new file in override mountpoint diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_pos.ksh similarity index 74% rename from tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_neg.ksh rename to tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_pos.ksh index 3e6799aa0..5ff094d2c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_pos.ksh @@ -18,9 +18,6 @@ # # DESCRIPTION: -# Linux: -# Verify that zfs mount fails with a non-empty directory -# FreeSD: # Verify that zfs mount succeeds with a non-empty directory # @@ -34,18 +31,12 @@ # 6. Unmount the dataset # 7. Create a file in the directory created in step 2 # 8. Attempt to mount the dataset -# 9. Verify the mount fails +# 9. Verify the mount succeeds # verify_runnable "both" -if is_linux; then - behaves="fails" -else - behaves="succeeds" -fi - -log_assert "zfs mount $behaves with non-empty directory" +log_assert "zfs mount succeeds with non-empty directory" fs=$TESTPOOL/$TESTFS @@ -55,12 +46,8 @@ log_must zfs set mountpoint=$TESTDIR $fs log_must zfs mount $fs log_must zfs umount $fs log_must touch $TESTDIR/testfile.$$ -if is_linux; then - log_mustnot zfs mount $fs -else - log_must zfs mount $fs - log_must zfs umount $fs -fi +log_must zfs mount $fs +log_must zfs umount $fs log_must rm -rf $TESTDIR -log_pass "zfs mount $behaves with non-empty directory as expected." +log_pass "zfs mount succeeds with non-empty directory as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh index 93a47d7d6..d1103bddc 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh @@ -30,8 +30,8 @@ # 1. Create zfs filesystems # 2. Unmount a leaf filesystem # 3. Create a file in the above filesystem's mountpoint -# 4. Verify that 'zfs mount -a' fails to mount the above if on Linux -# or succeeds if on FreeBSD +# 4. Verify that 'zfs mount -a' succeeds if overlay=on and +# fails to mount the above if overlay=off # 5. Verify that all other filesystems were mounted # @@ -83,17 +83,18 @@ done # Create a stray file in one filesystem's mountpoint touch $path/0/strayfile -# Verify that zfs mount -a fails on Linux or succeeds on FreeBSD export __ZFS_POOL_RESTRICT="$TESTPOOL" -if is_linux; then - log_mustnot zfs $mountall - log_mustnot mounted "$TESTPOOL/0" - typeset behaved="failed" -else - log_must zfs $mountall - log_must mounted "$TESTPOOL/0" - typeset behaved="succeeded" -fi + +# Verify that zfs mount -a succeeds with overlay=on (default) +log_must zfs $mountall +log_must mounted "$TESTPOOL/0" +log_must zfs $unmountall + +# Verify that zfs mount -a succeeds with overlay=off +log_must zfs set overlay=off "$TESTPOOL/0" +log_mustnot zfs $mountall +log_mustnot mounted "$TESTPOOL/0" + unset __ZFS_POOL_RESTRICT # All other filesystems should be mounted @@ -101,4 +102,4 @@ for ((i=1; i<$fscount; i++)); do log_must mounted "$TESTPOOL/$i" done -log_pass "'zfs $mountall' $behaved as expected." +log_pass "'zfs $mountall' behaves as expected."