1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
#!/usr/bin/env bash
# Copyright (C) 2024 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Test conversion to thin external origin stack
SKIP_WITH_LVMLOCKD=1
SKIP_WITH_LVMPOLLD=1
export LVM_TEST_THIN_REPAIR_CMD=${LVM_TEST_THIN_REPAIR_CMD-/bin/false}
. lib/inittest
which mkfs.ext4 || skip
which fsck || skip
_prepare() {
lvcreate -L10 -T -V20 -n $lv1 $vg/pool1
mkfs.ext4 "$DM_DEV_DIR/$vg/$lv1"
mkdir -p mnt
mount "$DM_DEV_DIR/$vg/$lv1" mnt
touch mnt/test1
sync
}
#
# Main
#
aux have_thin 1 5 0 || skip
aux prepare_vg 2
_prepare
# We can build chain of external origins with the same thin-pool
lvconvert --type thin --thinpool $vg/pool1 --originname $lv2 $vg/$lv1
lvconvert --type thin --thinpool $vg/pool1 --originname $lv3 $vg/$lv1
lvconvert --type thin --thinpool $vg/pool1 --originname $lv4 $vg/$lv1
# External origins remain inactive
# (only their -real counterparts are in DM table)
check inactive $vg $lv2
check inactive $vg $lv3
check inactive $vg $lv4
check lv_attr_bit perm $vg/$lv2 "r"
check lv_attr_bit perm $vg/$lv3 "r"
check lv_attr_bit perm $vg/$lv4 "r"
lvchange -ay $vg
touch mnt/test2
sync
umount mnt
fsck -n "$DM_DEV_DIR/$vg/$lv1"
fsck -n "$DM_DEV_DIR/$vg/$lv2"
fsck -n "$DM_DEV_DIR/$vg/$lv3"
fsck -n "$DM_DEV_DIR/$vg/$lv4"
# Check the removal works fine
lvremove -f $vg
#####################################################
#
# Now retry with origins across multiple thin pools
#
#####################################################
_prepare
# Create several more thin pools
lvcreate -L10 -T $vg/pool2
lvcreate -L10 -T $vg/pool3
lvcreate -L10 -T $vg/pool4
# thin volume chained into 3 layers, each forming a new external origin
lvconvert --type thin --thinpool $vg/pool2 --originname $lv2 $vg/$lv1
lvconvert --type thin --thinpool $vg/pool3 --originname $lv3 $vg/$lv1
lvconvert --type thin --thinpool $vg/pool4 --originname $lv4 $vg/$lv1
# ATM we are not protecting against 'self-cycling'
lvconvert --type thin --thinpool $vg/pool1 --originname $lv5 $vg/$lv1
umount mnt
fsck -n "$DM_DEV_DIR/$vg/$lv1"
check active $vg $lv1
check inactive $vg $lv2
check inactive $vg $lv3
check inactive $vg $lv4
check inactive $vg $lv5
dm_table $vg-${lv4}-real | grep thin
dm_table $vg-${lv5}-real | grep thin
lvchange -ay $vg/$lv3
check active $vg $lv3
fsck -n "$DM_DEV_DIR/$vg/$lv3"
lvremove -f $vg
lvcreate -L10 -T $vg/pool1
lvcreate -an -pr -L1 -n $lv1 $vg
# Use linear as oring for multiple thins
lvcreate --type thin --thinpool $vg/pool1 $vg/$lv1 -n $lv2
lvcreate --type thin --thinpool $vg/pool1 $vg/$lv1 -n $lv3
lvcreate --type thin --thinpool $vg/pool1 $vg/$lv1 -n $lv4
# Convert existing $lv1 into external origin 'eorigin'
lvconvert -T --thinpool $vg/pool1 --originname eorigin $vg/$lv1
# check $lv1-real was converted into eorigin-real
not dmsetup info $vg-${lv1}-real &> out
grep "not exist" out
dm_table $vg-eorigin-real | grep linear
check inactive $vg $lv1
check inactive $vg eorigin
check active $vg $lv2
check active $vg $lv3
check active $vg $lv4
check lv_field $vg/$lv1 segtype thin
check lv_attr_bit perm $vg/$lv1 "r"
check lv_field $vg/eorigin segtype linear
check lv_attr_bit perm $vg/eorigin "r"
lvs -ao+uuid,segtype $vg
lvremove -f $vg
#####################################################
#
# Check some prohibited conversions
#
#####################################################
lvcreate -L10 -T -V20 -n $lv1 $vg/pool1
#lvcreate -L10 -T -V20 -n $lv2 $vg/pool2
# Take thick/old snapshot
lvcreate -s -L10 -n snap $vg/$lv1
# Converting old-snapshot into external origin is not supported
not lvconvert -T --thinpool $vg/pool1 --originname orig $vg/snap
# Converting thin-pools LVs
not lvconvert -T --thinpool $vg/pool1 --originname orig $vg/pool2
not lvconvert -T --thinpool $vg/pool1 --originname orig $vg/pool2_tmeta
not lvconvert -T --thinpool $vg/pool1 --originname orig $vg/pool2_tdata
# However we should be able to use 'thick' snapshot origin (which is thin)
lvconvert -T --thinpool $vg/pool1 --originname orig $vg/$lv1
check active $vg $lv1
check active $vg orig
check active $vg snap
check lv_field $vg/$lv1 segtype thin
check lv_field $vg/orig segtype thin
check lv_field $vg/snap segtype linear
lvchange -an $vg/orig
lvconvert --type thin --thinpool $vg/pool1 --originname orig2 $vg/orig
check active $vg $lv1
# external origin and snapshot stay inactive
check inactive $vg orig2
check inactive $vg orig
check inactive $vg snap
dm_table $vg-orig2-real | grep thin
|