1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. 25# 26 27. $STF_SUITE/include/libtest.shlib 28. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib 29. $STF_SUITE/tests/functional/zvol/zvol_common.shlib 30. $STF_SUITE/tests/functional/zvol/zvol_misc/zvol_misc_common.kshlib 31 32# 33# DESCRIPTION: 34# Verify that ZFS volume property "snapdev" works as intended. 35# 36# STRATEGY: 37# 1. Verify "snapdev" property does not accept invalid values 38# 2. Verify "snapdev" adds and removes device nodes when updated 39# 3. Verify "snapdev" is inherited correctly 40# 41 42verify_runnable "global" 43 44function cleanup 45{ 46 datasetexists $VOLFS && log_must zfs destroy -r $VOLFS 47 datasetexists $ZVOL && log_must zfs destroy -r $ZVOL 48 log_must zfs inherit snapdev $TESTPOOL 49 block_device_wait 50 udev_cleanup 51} 52 53log_assert "Verify that ZFS volume property 'snapdev' works as expected." 54log_onexit cleanup 55 56VOLFS="$TESTPOOL/volfs" 57ZVOL="$TESTPOOL/vol" 58SNAP="$ZVOL@snap" 59SNAPDEV="${ZVOL_DEVDIR}/$SNAP" 60SUBZVOL="$VOLFS/subvol" 61SUBSNAP="$SUBZVOL@snap" 62SUBSNAPDEV="${ZVOL_DEVDIR}/$SUBSNAP" 63 64log_must zfs create -o mountpoint=none $VOLFS 65log_must zfs create -V $VOLSIZE -s $ZVOL 66log_must zfs create -V $VOLSIZE -s $SUBZVOL 67 68# 1. Verify "snapdev" property does not accept invalid values 69typeset badvals=("off" "on" "1" "nope" "-") 70for badval in ${badvals[@]} 71do 72 log_mustnot zfs set snapdev="$badval" $ZVOL 73done 74 75# 2. Verify "snapdev" adds and removes device nodes when updated 76# 2.1 First create a snapshot then change snapdev property 77log_must zfs snapshot $SNAP 78log_must zfs set snapdev=visible $ZVOL 79blockdev_exists $SNAPDEV 80log_must zfs set snapdev=hidden $ZVOL 81blockdev_missing $SNAPDEV 82log_must zfs destroy $SNAP 83# 2.2 First set snapdev property then create a snapshot 84log_must zfs set snapdev=visible $ZVOL 85log_must zfs snapshot $SNAP 86blockdev_exists $SNAPDEV 87log_must zfs destroy $SNAP 88blockdev_missing $SNAPDEV 89# 2.3 Verify setting to the same value multiple times does not lead to issues 90log_must zfs snapshot $SNAP 91log_must zfs set snapdev=visible $ZVOL 92blockdev_exists $SNAPDEV 93log_must zfs set snapdev=visible $ZVOL 94blockdev_exists $SNAPDEV 95log_must zfs set snapdev=hidden $ZVOL 96blockdev_missing $SNAPDEV 97log_must zfs set snapdev=hidden $ZVOL 98blockdev_missing $SNAPDEV 99log_must zfs destroy $SNAP 100 101# 3. Verify "snapdev" is inherited correctly 102# 3.1 Check snapdev=visible case 103log_must zfs snapshot $SNAP 104log_must zfs inherit snapdev $ZVOL 105log_must zfs set snapdev=visible $TESTPOOL 106verify_inherited 'snapdev' 'visible' $ZVOL $TESTPOOL 107blockdev_exists $SNAPDEV 108# 3.2 Check snapdev=hidden case 109log_must zfs set snapdev=hidden $TESTPOOL 110verify_inherited 'snapdev' 'hidden' $ZVOL $TESTPOOL 111blockdev_missing $SNAPDEV 112# 3.3 Check inheritance on multiple levels 113log_must zfs snapshot $SUBSNAP 114log_must zfs inherit snapdev $SUBZVOL 115log_must zfs set snapdev=hidden $VOLFS 116log_must zfs set snapdev=visible $TESTPOOL 117verify_inherited 'snapdev' 'hidden' $SUBZVOL $VOLFS 118blockdev_missing $SUBSNAPDEV 119blockdev_exists $SNAPDEV 120 121log_pass "ZFS volume property 'snapdev' works as expected" 122