1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22
23#
24# DESCRIPTION:
25# ZVOLs cannot have children datasets: verify zfs commands respect this
26# hierarchy rule.
27#
28# STRATEGY:
29# 1. Create a filesystem and a ZVOL
30# 2. Verify 'zfs recv' will not (force-)receive a ZVOL over the root dataset
31# 3. Verify 'zfs recv' cannot receive a ZVOL overwriting datasets with children
32# 4. Verify 'zfs recv' cannot receive datasets below a ZVOL
33# 5. Verify 'zfs create' cannot create datasets under a ZVOL
34# 6. Verify 'zfs rename' cannot move datasets under a ZVOL
35#
36
37verify_runnable "both"
38
39function cleanup
40{
41	destroy_pool "$poolname"
42	log_must rm -f "$vdevfile" "$streamfile_fs" "$streamfile_zvol"
43}
44
45log_assert "ZVOLs cannot have children datasets: verify zfs commands respect "\
46	"this hierarchy rule"
47log_onexit cleanup
48
49poolname="$TESTPOOL-zvol_hierarchy"
50vdevfile="$TEST_BASE_DIR/vdevfile.$$"
51streamfile_fs="$TEST_BASE_DIR/streamfile_fs.$$"
52streamfile_zvol="$TEST_BASE_DIR/streamfile_zvol.$$"
53
54# 1. Create filesystems and ZVOLs
55# NOTE: set "mountpoint=none" just to speed up the test process
56log_must truncate -s $MINVDEVSIZE "$vdevfile"
57log_must zpool create -O mountpoint=none "$poolname" "$vdevfile"
58log_must zfs create "$poolname/sendfs"
59log_must zfs create -V 1M -s "$poolname/sendvol"
60log_must zfs snapshot "$poolname/sendfs@snap"
61log_must zfs snapshot "$poolname/sendvol@snap"
62log_must eval "zfs send $poolname/sendfs@snap > $streamfile_fs"
63log_must eval "zfs send $poolname/sendvol@snap > $streamfile_zvol"
64
65# 2. Verify 'zfs recv' will not (force-)receive a ZVOL over the root dataset
66log_mustnot eval "zfs receive -F $poolname < $streamfile_zvol"
67
68# 3. Verify 'zfs recv' cannot receive a ZVOL overwriting datasets with children
69log_must zfs create "$poolname/fs"
70log_must zfs create "$poolname/fs/subfs"
71log_mustnot eval "zfs receive -F $poolname/fs < $streamfile_zvol"
72log_must zfs destroy "$poolname/fs/subfs"
73log_must eval "zfs receive -F $poolname/fs < $streamfile_zvol"
74
75# 4. Verify 'zfs recv' cannot receive datasets below a ZVOL
76log_must zfs create -V 1M -s "$poolname/volume"
77log_mustnot eval "zfs receive $poolname/volume/subfs < $streamfile_fs"
78log_mustnot eval "zfs receive $poolname/volume/subvol < $streamfile_zvol"
79
80# 5. Verify 'zfs create' cannot create datasets under a ZVOL
81log_must zfs create -V 1M -s "$poolname/createvol"
82log_mustnot zfs create "$poolname/createvol/fs"
83log_mustnot zfs create -V 1M -s "$poolname/createvol/vol"
84
85# 6. Verify 'zfs rename' cannot move datasets under a ZVOL
86log_must zfs create "$poolname/movefs"
87log_must zfs create -V 1M -s "$poolname/movevol"
88log_must zfs create -V 1M -s "$poolname/renamevol"
89log_mustnot zfs rename "$poolname/fs" "$poolname/renamevol/fs"
90log_mustnot zfs rename "$poolname/vol" "$poolname/renamevol/vol"
91
92log_pass "ZVOLs cannot have children datasets and zfs commands enforce this "\
93	"rule"
94