diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c index 7ca18e138cc2..b68d73c22aa1 100644 --- a/module/zfs/zvol.c +++ b/module/zfs/zvol.c @@ -2252,12 +2252,6 @@ zvol_rename_minors_impl(const char *oldname, const char *newname) mutex_enter(&zv->zv_state_lock); - /* If in use, leave alone */ - if (zv->zv_open_count > 0) { - mutex_exit(&zv->zv_state_lock); - continue; - } - if (strcmp(zv->zv_name, oldname) == 0) { zvol_rename_minor(zv, newname); } else if (strncmp(zv->zv_name, oldname, oldnamelen) == 0 && diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index d3ecf6274770..c9688c271c92 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -887,7 +887,8 @@ tags = ['functional', 'zvol', 'zvol_cli'] [tests/functional/zvol/zvol_misc] tests = ['zvol_misc_001_neg', 'zvol_misc_002_pos', 'zvol_misc_003_neg', 'zvol_misc_004_pos', 'zvol_misc_005_neg', 'zvol_misc_006_pos', - 'zvol_misc_snapdev', 'zvol_misc_volmode', 'zvol_misc_zil'] + 'zvol_misc_snapdev', 'zvol_misc_volmode', 'zvol_misc_zil', + 'zvol_misc_rename_inuse'] tags = ['functional', 'zvol', 'zvol_misc'] [tests/functional/zvol/zvol_swap] diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/Makefile.am b/tests/zfs-tests/tests/functional/zvol/zvol_misc/Makefile.am index a2c95a3ebb72..53b3ee57ff67 100644 --- a/tests/zfs-tests/tests/functional/zvol/zvol_misc/Makefile.am +++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/Makefile.am @@ -8,6 +8,7 @@ dist_pkgdata_SCRIPTS = \ zvol_misc_004_pos.ksh \ zvol_misc_005_neg.ksh \ zvol_misc_006_pos.ksh \ + zvol_misc_rename_inuse.ksh \ zvol_misc_snapdev.ksh \ zvol_misc_volmode.ksh \ zvol_misc_zil.ksh diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/cleanup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/cleanup.ksh index 79836c2e5d18..7714530ff4cb 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_misc/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/cleanup.ksh @@ -36,4 +36,6 @@ verify_runnable "global" default_zvol_cleanup +[[ -d $TESTDIR ]] && rm -rf $TESTDIR + log_pass diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/setup.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/setup.ksh index 017e8b617225..6b2cc821792c 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_misc/setup.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/setup.ksh @@ -36,4 +36,6 @@ verify_runnable "global" default_zvol_setup $DISK $VOLSIZE +log_must mkdir $TESTDIR + log_pass diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh index cc3b5c467009..203b552cff6c 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh @@ -54,7 +54,6 @@ function cleanup ismounted $TESTDIR $NEWFS_DEFAULT_FS (( $? == 0 )) && log_must umount $TESTDIR - [[ -e $TESTDIR ]] && rm -rf $TESTDIR zfs set volsize=$volsize $TESTPOOL/$TESTVOL } @@ -70,7 +69,6 @@ log_must zfs set volsize=128m $TESTPOOL/$TESTVOL echo "y" | newfs -v ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL >/dev/null 2>&1 (( $? != 0 )) && log_fail "Unable to newfs(1M) $TESTPOOL/$TESTVOL" -log_must mkdir $TESTDIR log_must mount ${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL $TESTDIR typeset -i fn=0 diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_rename_inuse.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_rename_inuse.ksh new file mode 100755 index 000000000000..797aadc49e15 --- /dev/null +++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_rename_inuse.ksh @@ -0,0 +1,81 @@ +#!/bin/ksh -p +# +# 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 +# + +# +# Copyright 2019, loli10K . All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/zvol/zvol_common.shlib +. $STF_SUITE/tests/functional/zvol/zvol_misc/zvol_misc_common.kshlib + +# +# DESCRIPTION: +# Verify 'zfs rename' works on a ZVOL already in use as block device +# +# STRATEGY: +# 1. Create a ZVOL +# 2. Create a filesystem on the ZVOL device and mount it +# 3. Rename the ZVOL dataset +# 4. Receive a send stream with the same name as the old ZVOL dataset and verify +# we don't trigger any issue like the one reported in #6263 +# + +verify_runnable "global" + +function cleanup +{ + log_must umount "$MNTPFS" + log_must rmdir "$MNTPFS" + for ds in "$SENDFS" "$ZVOL" "$ZVOL-renamed"; do + destroy_dataset "$ds" '-rf' + done + udev_wait +} + +log_assert "Verify 'zfs rename' works on a ZVOL already in use as block device" +log_onexit cleanup + +ZVOL="$TESTPOOL/vol.$$" +ZDEV="$ZVOL_DEVDIR/$ZVOL" +MNTPFS="$TESTDIR/zvol_inuse_rename" +SENDFS="$TESTPOOL/sendfs.$$" + +# 1. Create a ZVOL +log_must zfs create -V $VOLSIZE "$ZVOL" + +# 2. Create a filesystem on the ZVOL device and mount it +udev_wait +log_must eval "echo y | newfs $ZDEV >/dev/null 2>&1" +log_must mkdir "$MNTPFS" +log_must mount "$ZDEV" "$MNTPFS" + +# 3. Rename the ZVOL dataset +log_must zfs rename "$ZVOL" "$ZVOL-renamed" + +# 4. Receive a send stream with the same name as the old ZVOL dataset and verify +# we don't trigger any issue like the one reported in #6263 +log_must zfs create "$SENDFS" +log_must zfs snap "$SENDFS@snap" +log_must eval "zfs send $SENDFS@snap | zfs recv $ZVOL" + +log_pass "Renaming in use ZVOL works successfully"