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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
#!/usr/bin/env bash
# Copyright (C) 2020 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_description='devices file editing with lvmdevices'
SKIP_WITH_LVMPOLLD=1
. lib/inittest
aux lvmconf 'devices/scan = "/dev"'
aux prepare_devs 1
# The tests run with system dir of "/etc" but lvm when running
# normally has cmd->system_dir set to "/etc/lvm".
DFDIR="$LVM_SYSTEM_DIR/devices"
mkdir -p "$DFDIR" || true
DF="$DFDIR/system.devices"
aux lvmconf 'devices/use_devicesfile = 1'
losetup -h | grep sector-size || skip
which fallocate || skip
fallocate -l 2M loopa
fallocate -l 2M loopb
setup_loop_devs() {
for i in {1..5} ; do
LOOP1=$(losetup -f loopa --show || true)
test -n "$LOOP1" && break
done
for i in {1..5} ; do
LOOP2=$(losetup -f loopb --show || true)
test -n "$LOOP2" && break
done
}
setup_loop_devs
# Tests of devices without PV on them.
# add/del with default idtype loop_file
lvmdevices --adddev "$LOOP1"
grep "$LOOP1" $DF
lvmdevices --adddev "$LOOP2"
grep "$LOOP2" $DF
grep "IDTYPE=loop_file" $DF
not grep "IDTYPE=devname" $DF
lvmdevices --deldev "$LOOP1"
not grep "$LOOP1" $DF
lvmdevices --deldev "$LOOP2"
not grep "$LOOP2" $DF
# add/del with non-default idtype devname
lvmdevices --adddev "$LOOP1" --deviceidtype devname
grep "$LOOP1" $DF
lvmdevices --adddev "$LOOP2" --deviceidtype devname
grep "$LOOP2" $DF
grep "IDTYPE=devname" $DF
not grep "IDTYPE=loop_file" $DF
lvmdevices --deldev "$LOOP1"
not grep "$LOOP1" $DF
lvmdevices --deldev "$LOOP2"
not grep "$LOOP2" $DF
# add/del when dev is missing, using default idtype
lvmdevices --adddev "$LOOP1"
grep "$LOOP1" $DF
lvmdevices --adddev "$LOOP2"
grep "$LOOP2" $DF
losetup -D
grep "$LOOP1" $DF
grep "$LOOP2" $DF
lvmdevices --deldev "$LOOP1"
not grep "$LOOP1" $DF
lvmdevices --deldev "$LOOP2"
not grep "$LOOP2" $DF
not lvmdevices --adddev "$LOOP1"
not lvmdevices --adddev "$LOOP2"
not grep "$LOOP1" $DF
not grep "$LOOP2" $DF
setup_loop_devs
rm $DF
# add/del when dev is missing, using devname idtype
lvmdevices --adddev "$LOOP1" --deviceidtype devname
grep "$LOOP1" $DF
lvmdevices --adddev "$LOOP2" --deviceidtype devname
grep "$LOOP2" $DF
losetup -D
grep "$LOOP1" $DF
grep "$LOOP2" $DF
lvmdevices --deldev "$LOOP1"
not grep "$LOOP1" $DF
lvmdevices --deldev "$LOOP2"
not grep "$LOOP2" $DF
setup_loop_devs
rm $DF
# Tests of devices with PV on them.
touch $DF
pvcreate "$LOOP1"
pvcreate "$LOOP2"
# PVID without dashes for matching devices file fields
PVID1=`pvs "$LOOP1" --noheading -o uuid | tr -d - | awk '{print $1}'`
PVID2=`pvs "$LOOP2" --noheading -o uuid | tr -d - | awk '{print $1}'`
# PVID with dashes for matching pvs -o+uuid output
OPVID1=`pvs "$LOOP1" --noheading -o uuid | awk '{print $1}'`
OPVID2=`pvs "$LOOP2" --noheading -o uuid | awk '{print $1}'`
grep "$LOOP1" $DF
grep "$LOOP2" $DF
grep "$PVID1" $DF
grep "$PVID2" $DF
rm $DF
# add/deldev with default idtype loop_file
lvmdevices --adddev "$LOOP1"
grep "$LOOP1" $DF
grep "$PVID1" $DF
lvmdevices --adddev "$LOOP2"
grep "$LOOP2" $DF
grep "$PVID2" $DF
grep "IDTYPE=loop_file" $DF
not grep "IDTYPE=devname" $DF
lvmdevices --deldev "$LOOP1"
not grep "$LOOP1" $DF
lvmdevices --deldev "$LOOP2"
not grep "$LOOP2" $DF
rm $DF
# deldev using idname
lvmdevices --adddev "$LOOP1"
lvmdevices --adddev "$LOOP2"
vgcreate $vg "$LOOP1" "$LOOP2"
IDNAME1=`pvs "$LOOP1" --noheading -o deviceid | awk '{print $1}'`
IDNAME2=`pvs "$LOOP2" --noheading -o deviceid | awk '{print $1}'`
lvmdevices --deldev "$IDNAME2" --deviceidtype loop_file
not grep "$IDNAME2" $DF
not grep "$LOOP2" $DF
lvmdevices --deldev "$IDNAME1" --deviceidtype loop_file
not grep "$IDNAME1" $DF
not grep "$LOOP1" $DF
lvmdevices --adddev "$LOOP1"
lvmdevices --adddev "$LOOP2"
vgremove $vg
rm $DF
# add/delpvid with default idtype loop_file
lvmdevices --addpvid "$PVID1"
grep "$LOOP1" $DF
grep "$PVID1" $DF
lvmdevices --addpvid "$PVID2"
grep "$LOOP2" $DF
grep "$PVID2" $DF
grep "IDTYPE=loop_file" $DF
not grep "IDTYPE=devname" $DF
lvmdevices --delpvid "$PVID1"
not grep "$LOOP1" $DF
not grep "$PVID1" $DF
lvmdevices --delpvid "$PVID2"
not grep "$LOOP2" $DF
not grep "$PVID2" $DF
rm $DF
# add/deldev with non-default idtype devname
lvmdevices --adddev "$LOOP1" --deviceidtype devname
grep "$LOOP1" $DF
grep "$PVID1" $DF
lvmdevices --adddev "$LOOP2" --deviceidtype devname
grep "$LOOP2" $DF
grep "$PVID2" $DF
grep "IDTYPE=devname" $DF
not grep "IDTYPE=loop_file" $DF
lvmdevices --deldev "$LOOP1"
not grep "$LOOP1" $DF
lvmdevices --deldev "$LOOP2"
not grep "$LOOP2" $DF
rm $DF
# add/delpvid with non-default idtype devname
lvmdevices --addpvid "$PVID1" --deviceidtype devname
grep "$LOOP1" $DF
grep "$PVID1" $DF
lvmdevices --addpvid "$PVID2" --deviceidtype devname
grep "$LOOP2" $DF
grep "$PVID2" $DF
grep "IDTYPE=devname" $DF
not grep "IDTYPE=loop_file" $DF
lvmdevices --deldev "$LOOP1"
not grep "$LOOP1" $DF
lvmdevices --deldev "$LOOP2"
not grep "$LOOP2" $DF
rm $DF
# add/deldev when dev is missing, using default idtype
lvmdevices --adddev "$LOOP1"
grep "$LOOP1" $DF
grep "$PVID1" $DF
lvmdevices --adddev "$LOOP2"
grep "$LOOP2" $DF
grep "$PVID2" $DF
losetup -D
grep "$LOOP1" $DF
grep "$LOOP2" $DF
lvmdevices --deldev "$LOOP1"
not grep "$LOOP1" $DF
not grep "$PVID1" $DF
lvmdevices --deldev "$LOOP2"
not grep "$LOOP2" $DF
not grep "$PVID2" $DF
setup_loop_devs
rm $DF
# add/delpvid when dev is missing, using devname idtype
lvmdevices --addpvid "$PVID1" --deviceidtype devname
grep "$LOOP1" $DF
grep "$PVID1" $DF
lvmdevices --addpvid "$PVID2" --deviceidtype devname
grep "$LOOP2" $DF
grep "$PVID2" $DF
losetup -D
grep "$LOOP1" $DF
grep "$LOOP2" $DF
lvmdevices --delpvid "$PVID1"
not grep "$LOOP1" $DF
not grep "$PVID1" $DF
lvmdevices --delpvid "$PVID2"
not grep "$LOOP2" $DF
not grep "$PVID2" $DF
setup_loop_devs
rm $DF
# test delnotfound
lvmdevices --addpvid "$PVID1"
echo "IDTYPE=sys_wwid IDNAME=naa.123 DEVNAME=/dev/sdx1 PVID=aaa PART=1" >> $DF
echo "IDTYPE=devname IDNAME=/dev/sdy DEVNAME=/dev/sdy PVID=bbb" >> $DF
lvmdevices
lvmdevices --update --delnotfound
not grep PVID=aaa $DF
not grep PVID=bbb $DF
# TODO: add/rem of partitions of same device
losetup -D
rm loopa loopb
|