diff --git a/module/zfs/dmu_objset.c b/module/zfs/dmu_objset.c index fa80e3a61..f95915b9e 100644 --- a/module/zfs/dmu_objset.c +++ b/module/zfs/dmu_objset.c @@ -2433,7 +2433,8 @@ dmu_objset_userobjspace_upgradable(objset_t *os) return (dmu_objset_type(os) == DMU_OST_ZFS && !dmu_objset_is_snapshot(os) && dmu_objset_userobjused_enabled(os) && - !dmu_objset_userobjspace_present(os)); + !dmu_objset_userobjspace_present(os) && + spa_writeable(dmu_objset_spa(os))); } boolean_t @@ -2442,7 +2443,8 @@ dmu_objset_projectquota_upgradable(objset_t *os) return (dmu_objset_type(os) == DMU_OST_ZFS && !dmu_objset_is_snapshot(os) && dmu_objset_projectquota_enabled(os) && - !dmu_objset_projectquota_present(os)); + !dmu_objset_projectquota_present(os) && + spa_writeable(dmu_objset_spa(os))); } void diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index d6bc77a6b..b4dd29fae 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -841,7 +841,8 @@ tests = ['truncate_001_pos', 'truncate_002_pos', 'truncate_timestamps'] tags = ['functional', 'truncate'] [tests/functional/upgrade] -tests = ['upgrade_userobj_001_pos', 'upgrade_projectquota_001_pos'] +tests = ['upgrade_userobj_001_pos', 'upgrade_projectquota_001_pos', + 'upgrade_readonly_pool'] tags = ['functional', 'upgrade'] [tests/functional/user_namespace] diff --git a/tests/zfs-tests/tests/functional/upgrade/Makefile.am b/tests/zfs-tests/tests/functional/upgrade/Makefile.am index a774989cc..743baa484 100644 --- a/tests/zfs-tests/tests/functional/upgrade/Makefile.am +++ b/tests/zfs-tests/tests/functional/upgrade/Makefile.am @@ -3,7 +3,8 @@ dist_pkgdata_SCRIPTS = \ setup.ksh \ cleanup.ksh \ upgrade_userobj_001_pos.ksh \ - upgrade_projectquota_001_pos.ksh + upgrade_projectquota_001_pos.ksh \ + upgrade_readonly_pool.ksh dist_pkgdata_DATA = \ upgrade_common.kshlib diff --git a/tests/zfs-tests/tests/functional/upgrade/upgrade_readonly_pool.ksh b/tests/zfs-tests/tests/functional/upgrade/upgrade_readonly_pool.ksh new file mode 100755 index 000000000..750620e6d --- /dev/null +++ b/tests/zfs-tests/tests/functional/upgrade/upgrade_readonly_pool.ksh @@ -0,0 +1,66 @@ +#!/bin/ksh -p +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2019, loli10K . All rights reserved. +# + +. $STF_SUITE/tests/functional/upgrade/upgrade_common.kshlib + +# +# DESCRIPTION: +# User accounting upgrade should not be executed on readonly pool +# +# STRATEGY: +# 1. Create a pool with the feature@userobj_accounting disabled to simulate +# a legacy pool from a previous ZFS version. +# 2. Create a file on the "legecy" dataset and store its checksum +# 3. Enable feature@userobj_accounting on the pool and verify it is only +# "enabled" and not "active": upgrading starts when the filesystem is mounted +# 4. Export the pool and re-import is readonly, without mounting any filesystem +# 5. Try to mount the root dataset manually without the "ro" option, then verify +# filesystem status and the pool feature status (not "active") to ensure the +# pool "readonly" status is enforced. +# + +verify_runnable "global" + +TESTFILE="$TESTDIR/file.bin" + +log_assert "User accounting upgrade should not be executed on readonly pool" +log_onexit cleanup_upgrade + +# 1. Create a pool with the feature@userobj_accounting disabled to simulate +# a legacy pool from a previous ZFS version. +log_must zpool create -d -m $TESTDIR $TESTPOOL $TMPDEV + +# 2. Create a file on the "legecy" dataset +log_must touch $TESTDIR/file.bin + +# 3. Enable feature@userobj_accounting on the pool and verify it is only +# "enabled" and not "active": upgrading starts when the filesystem is mounted +log_must zpool set feature@userobj_accounting=enabled $TESTPOOL +log_must test "enabled" == "$(get_pool_prop 'feature@userobj_accounting' $TESTPOOL)" + +# 4. Export the pool and re-import is readonly, without mounting any filesystem +log_must zpool export $TESTPOOL +log_must zpool import -o readonly=on -N -d "$(dirname $TMPDEV)" $TESTPOOL + +# 5. Try to mount the root dataset manually without the "ro" option, then verify +# filesystem status and the pool feature status (not "active") to ensure the +# pool "readonly" status is enforced. +log_must mount -t zfs -o zfsutil $TESTPOOL $TESTDIR +log_must stat "$TESTFILE" +log_mustnot touch "$TESTFILE" +log_must test "enabled" == "$(get_pool_prop 'feature@userobj_accounting' $TESTPOOL)" + +log_pass "User accounting upgrade is not executed on readonly pool"