2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # vi: ts=4 sw=4 tw=0 et:
8 # Check if all symlinks under /dev/disk/ are valid
9 # shellcheck disable=SC2120
10 helper_check_device_symlinks
() {(
13 local dev link path paths target
15 [[ $# -gt 0 ]] && paths
=("$@") || paths
=("/dev/disk" "/dev/mapper")
17 # Check if all given paths are valid
18 for path
in "${paths[@]}"; do
19 if ! test -e "$path"; then
20 echo >&2 "Path '$path' doesn't exist"
25 while read -r link
; do
26 target
="$(readlink -f "$link")"
27 echo "$link -> $target"
28 # Both checks should do virtually the same thing, but check both to be
30 if [[ ! -e "$link" ||
! -e "$target" ]]; then
31 echo >&2 "ERROR: symlink '$link' points to '$target' which doesn't exist"
35 # Check if the symlink points to the correct device in /dev
36 dev
="/dev/$(udevadm info -q name "$link")"
37 if [[ "$target" != "$dev" ]]; then
38 echo >&2 "ERROR: symlink '$link' points to '$target' but '$dev' was expected"
41 done < <(find "${paths[@]}" -type l
)
44 # Wait for a specific device link to appear
47 # $2 - number of retries (default: 10)
48 helper_wait_for_dev
() {
50 local ntries
="${2:-10}"
53 for ((i
= 0; i
< ntries
; i
++)); do
54 test ! -e "$dev" ||
return 0
61 # Wrapper around `helper_wait_for_lvm_activate()` and `helper_wait_for_pvscan()`
62 # functions to cover differences between pre and post lvm 2.03.14, which introduced
63 # a new way of vgroup autoactivation
64 # See: https://sourceware.org/git/?p=lvm2.git;a=commit;h=67722b312390cdab29c076c912e14bd739c5c0f6
66 # $1 - device path (for helper_wait_for_pvscan())
67 # $2 - volume group name (for helper_wait_for_lvm_activate())
68 # $3 - number of retries (default: 10)
69 helper_wait_for_vgroup
() {
72 local ntries
="${3:-10}"
74 if ! systemctl
-q list-unit-files lvm2-pvscan@.service
>/dev
/null
; then
75 helper_wait_for_lvm_activate
"$vgroup" "$ntries"
77 helper_wait_for_pvscan
"$dev" "$ntries"
81 # Wait for the lvm-activate-$vgroup.service of a specific $vgroup to finish
83 # $1 - volume group name
84 # $2 - number of retries (default: 10)
85 helper_wait_for_lvm_activate
() {
87 local ntries
="${2:-10}"
88 local i lvm_activate_svc
90 lvm_activate_svc
="lvm-activate-$vgroup.service"
91 for ((i
= 0; i
< ntries
; i
++)); do
92 if systemctl
-q is-active
"$lvm_activate_svc"; then
93 # Since the service is started via `systemd-run --no-block`, we need
94 # to wait until it finishes, otherwise we might continue while
95 # `vgchange` is still running
96 if [[ "$(systemctl show -P SubState "$lvm_activate_svc")" == exited
]]; then
100 # Since lvm 2.03.15 the lvm-activate transient unit no longer remains
101 # after finishing, so we have to treat non-existent units as a success
103 # See: https://sourceware.org/git/?p=lvm2.git;a=commit;h=fbd8b0cf43dc67f51f86f060dce748f446985855
104 if [[ "$(systemctl show -P LoadState "$lvm_activate_svc")" == not-found
]]; then
115 # Wait for the lvm2-pvscan@.service of a specific device to finish
118 # $2 - number of retries (default: 10)
119 helper_wait_for_pvscan
() {
121 local ntries
="${2:-10}"
122 local MAJOR MINOR i pvscan_svc real_dev
124 # Sanity check we got a valid block device (or a symlink to it)
125 real_dev
="$(readlink -f "$dev")"
126 if [[ ! -b "$real_dev" ]]; then
127 echo >&2 "ERROR: '$dev ($real_dev) is not a valid block device'"
131 # Get major and minor numbers from the udev database
132 # (udevadm returns MAJOR= and MINOR= expressions, so let's pull them into
133 # the current environment via `source` for easier parsing)
135 # shellcheck source=/dev/null
136 source <(udevadm info
-q property
"$real_dev" |
grep -E "(MAJOR|MINOR)=")
137 # Sanity check if we got correct major and minor numbers
138 test -e "/sys/dev/block/$MAJOR:$MINOR/"
140 # Wait n_tries*0.5 seconds until the respective lvm2-pvscan service becomes
141 # active (i.e. it got executed and finished)
142 pvscan_svc
="lvm2-pvscan@$MAJOR:$MINOR.service"
143 for ((i
= 0; i
< ntries
; i
++)); do
144 ! systemctl
-q is-active
"$pvscan_svc" ||
return 0
151 testcase_megasas2_basic
() {
153 [[ "$(lsblk --scsi --noheadings | wc -l)" -ge 128 ]]
156 testcase_nvme_basic
() {
157 lsblk
--noheadings |
grep "^nvme"
158 [[ "$(lsblk --noheadings | grep -c "^nvme
")" -ge 28 ]]
161 testcase_virtio_scsi_identically_named_partitions
() {
162 lsblk
--noheadings -a -o NAME
,PARTLABEL
163 [[ "$(lsblk --noheadings -a -o NAME,PARTLABEL | grep -c "Hello world
")" -eq $
((16 * 8)) ]]
166 testcase_multipath_basic_failover
() {
167 local dmpath i path wwid
169 # Configure multipath
170 cat >/etc
/multipath.conf
<<\EOF
172 # Use /dev/mapper/$WWN paths instead of /dev/mapper/mpathX
173 user_friendly_names no
178 blacklist_exceptions
{
179 property
"(SCSI_IDENT_|ID_WWN)"
185 modprobe
-v dm_multipath
186 systemctl start multipathd.service
187 systemctl status multipathd.service
190 ls -l /dev
/disk
/by-id
/
193 wwid
="deaddeadbeef$(printf "%.4d
" "$i")"
194 path
="/dev/disk/by-id/wwn-0x$wwid"
195 dmpath
="$(readlink -f "$path")"
198 multipath
-C "$dmpath"
199 # We should have 4 active paths for each multipath device
200 [[ "$(multipath -l "$path" | grep -c running)" -eq 4 ]]
203 # Test failover (with the first multipath device that has a partitioned disk)
204 echo "${FUNCNAME[0]}: test failover"
205 local device expected link mpoint part
207 mpoint
="$(mktemp -d /mnt/mpathXXX)"
208 wwid
="deaddeadbeef0000"
209 path
="/dev/disk/by-id/wwn-0x$wwid"
211 # All following symlinks should exists and should be valid
212 local -a part_links
=(
213 "/dev/disk/by-id/wwn-0x$wwid-part2"
214 "/dev/disk/by-partlabel/failover_part"
215 "/dev/disk/by-partuuid/deadbeef-dead-dead-beef-000000000000"
216 "/dev/disk/by-label/failover_vol"
217 "/dev/disk/by-uuid/deadbeef-dead-dead-beef-111111111111"
219 for link
in "${part_links[@]}"; do
223 # Choose a random symlink to the failover data partition each time, for
225 part
="${part_links[$RANDOM % ${#part_links[@]}]}"
227 # Get all devices attached to a specific multipath device (in H:C:T:L format)
228 # and sort them in a random order, so we cut off different paths each time
229 mapfile
-t devices
< <(multipath
-l "$path" |
grep -Eo '[0-9]+:[0-9]+:[0-9]+:[0-9]+' |
sort -R)
230 if [[ "${#devices[@]}" -ne 4 ]]; then
231 echo "Expected 4 devices attached to WWID=$wwid, got ${#devices[@]} instead"
234 # Drop the last path from the array, since we want to leave at least one path active
236 # Mount the first multipath partition, write some data we can check later,
237 # and then disconnect the remaining paths one by one while checking if we
238 # can still read/write from the mount
239 mount
-t ext4
"$part" "$mpoint"
241 echo -n "$expected" >"$mpoint/test"
242 # Sanity check we actually wrote what we wanted
243 [[ "$(<"$mpoint/test")" == "$expected" ]]
245 for device
in "${devices[@]}"; do
246 echo offline
>"/sys/class/scsi_device/$device/device/state"
247 [[ "$(<"$mpoint/test")" == "$expected" ]]
248 expected
="$((expected + 1))"
249 echo -n "$expected" >"$mpoint/test"
251 # Make sure all symlinks are still valid
252 for link
in "${part_links[@]}"; do
258 # Three paths should be now marked as 'offline' and one as 'running'
259 [[ "$(multipath -l "$path" | grep -c offline)" -eq 3 ]]
260 [[ "$(multipath -l "$path" | grep -c running)" -eq 1 ]]
266 testcase_simultaneous_events
() {
267 local blockdev part partscript
269 blockdev
="$(readlink -f /dev/disk/by-id/scsi-*_deadbeeftest)"
270 partscript
="$(mktemp)"
272 if [[ ! -b "$blockdev" ]]; then
273 echo "ERROR: failed to find the test SCSI block device"
277 cat >"$partscript" <<EOF
278 $(printf 'name="test%d", size=2M\n' {1..50})
281 # Initial partition table
282 sfdisk
-q -X gpt
"$blockdev" <"$partscript"
284 # Delete the partitions, immediately recreate them, wait for udev to settle
285 # down, and then check if we have any dangling symlinks in /dev/disk/. Rinse
288 # On unpatched udev versions the delete-recreate cycle may trigger a race
289 # leading to dead symlinks in /dev/disk/
290 for i
in {1.
.100}; do
291 sfdisk
-q --delete "$blockdev"
292 sfdisk
-q -X gpt
"$blockdev" <"$partscript"
294 if ((i
% 10 == 0)); then
296 helper_check_device_symlinks
303 testcase_lvm_basic
() {
305 local vgroup
="MyTestGroup$RANDOM"
307 /dev
/disk
/by-id
/ata-foobar_deadbeeflvm
{0.
.3}
310 # Make sure all the necessary soon-to-be-LVM devices exist
311 ls -l "${devices[@]}"
313 # Add all test devices into a volume group, create two logical volumes,
314 # and check if necessary symlinks exist (and are valid)
315 lvm pvcreate
-y "${devices[@]}"
317 lvm vgcreate
"$vgroup" -y "${devices[@]}"
319 lvm vgchange
-ay "$vgroup"
320 lvm lvcreate
-y -L 4M
"$vgroup" -n mypart1
321 lvm lvcreate
-y -L 8M
"$vgroup" -n mypart2
324 test -e "/dev/$vgroup/mypart1"
325 test -e "/dev/$vgroup/mypart2"
326 mkfs.ext4
-L mylvpart1
"/dev/$vgroup/mypart1"
328 test -e "/dev/disk/by-label/mylvpart1"
329 helper_check_device_symlinks
"/dev/disk" "/dev/$vgroup"
331 # Disable the VG and check symlinks...
332 lvm vgchange
-an "$vgroup"
334 test ! -e "/dev/$vgroup"
335 test ! -e "/dev/disk/by-label/mylvpart1"
336 helper_check_device_symlinks
"/dev/disk"
338 # reenable the VG and check the symlinks again if all LVs are properly activated
339 lvm vgchange
-ay "$vgroup"
341 test -e "/dev/$vgroup/mypart1"
342 test -e "/dev/$vgroup/mypart2"
343 test -e "/dev/disk/by-label/mylvpart1"
344 helper_check_device_symlinks
"/dev/disk" "/dev/$vgroup"
346 # Same as above, but now with more "stress"
348 lvm vgchange
-an "$vgroup"
349 lvm vgchange
-ay "$vgroup"
351 if ((i
% 5 == 0)); then
353 test -e "/dev/$vgroup/mypart1"
354 test -e "/dev/$vgroup/mypart2"
355 test -e "/dev/disk/by-label/mylvpart1"
356 helper_check_device_symlinks
"/dev/disk" "/dev/$vgroup"
360 # Remove the first LV
361 lvm lvremove
-y "$vgroup/mypart1"
363 test ! -e "/dev/$vgroup/mypart1"
364 test -e "/dev/$vgroup/mypart2"
365 helper_check_device_symlinks
"/dev/disk" "/dev/$vgroup"
367 # Create & remove LVs in a loop, i.e. with more "stress"
369 # 1) Create 16 logical volumes
370 for part
in {0.
.15}; do
371 lvm lvcreate
-y -L 4M
"$vgroup" -n "looppart$part"
374 # 2) Immediately remove them
375 lvm lvremove
-y "$vgroup"/looppart
{0.
.15}
377 # 3) On every 4th iteration settle udev and check if all partitions are
378 # indeed gone, and if all symlinks are still valid
379 if ((i
% 4 == 0)); then
381 for part
in {0.
.15}; do
382 test ! -e "/dev/$vgroup/looppart$part"
384 helper_check_device_symlinks
"/dev/disk" "/dev/$vgroup"
389 testcase_btrfs_basic
() {
390 local dev_stub i label mpoint uuid
392 /dev
/disk
/by-id
/ata-foobar_deadbeefbtrfs
{0.
.3}
395 ls -l "${devices[@]}"
397 echo "Single device: default settings"
398 uuid
="deadbeef-dead-dead-beef-000000000000"
400 mkfs.btrfs
-L "$label" -U "$uuid" "${devices[0]}"
402 btrfs filesystem show
403 test -e "/dev/disk/by-uuid/$uuid"
404 test -e "/dev/disk/by-label/$label"
405 helper_check_device_symlinks
407 echo "Multiple devices: using partitions, data: single, metadata: raid1"
408 uuid
="deadbeef-dead-dead-beef-000000000001"
410 sfdisk
--wipe=always
"${devices[0]}" <<EOF
413 name="diskpart1", size=85M
414 name="diskpart2", size=85M
415 name="diskpart3", size=85M
416 name="diskpart4", size=85M
419 mkfs.btrfs
-d single
-m raid1
-L "$label" -U "$uuid" /dev
/disk
/by-partlabel
/diskpart
{1.
.4}
421 btrfs filesystem show
422 test -e "/dev/disk/by-uuid/$uuid"
423 test -e "/dev/disk/by-label/$label"
424 helper_check_device_symlinks
425 wipefs
-a -f "${devices[0]}"
427 echo "Multiple devices: using disks, data: raid10, metadata: raid10, mixed mode"
428 uuid
="deadbeef-dead-dead-beef-000000000002"
430 mkfs.btrfs
-M -d raid10
-m raid10
-L "$label" -U "$uuid" "${devices[@]}"
432 btrfs filesystem show
433 test -e "/dev/disk/by-uuid/$uuid"
434 test -e "/dev/disk/by-label/$label"
435 helper_check_device_symlinks
437 echo "Multiple devices: using LUKS encrypted disks, data: raid1, metadata: raid1, mixed mode"
438 uuid
="deadbeef-dead-dead-beef-000000000003"
439 label
="btrfs_mencdisk"
440 mpoint
="/btrfs_enc$RANDOM"
443 dd if=/dev
/urandom of
=/etc
/btrfs_keyfile bs
=64 count
=1 iflag
=fullblock
444 chmod 0600 /etc
/btrfs_keyfile
445 # Encrypt each device and add it to /etc/crypttab, so it can be mounted
446 # automagically later
448 for ((i
= 0; i
< ${#devices[@]}; i
++)); do
449 # Intentionally use weaker cipher-related settings, since we don't care
450 # about security here as it's a throwaway LUKS partition
451 cryptsetup luksFormat
-q \
452 --use-urandom --pbkdf pbkdf2
--pbkdf-force-iterations 1000 \
453 --uuid "deadbeef-dead-dead-beef-11111111111$i" --label "encdisk$i" "${devices[$i]}" /etc
/btrfs_keyfile
455 test -e "/dev/disk/by-uuid/deadbeef-dead-dead-beef-11111111111$i"
456 test -e "/dev/disk/by-label/encdisk$i"
457 # Add the device into /etc/crypttab, reload systemd, and then activate
458 # the device so we can create a filesystem on it later
459 echo "encbtrfs$i UUID=deadbeef-dead-dead-beef-11111111111$i /etc/btrfs_keyfile luks,noearly" >>/etc
/crypttab
460 systemctl daemon-reload
461 systemctl start
"systemd-cryptsetup@encbtrfs$i"
463 helper_check_device_symlinks
464 # Check if we have all necessary DM devices
465 ls -l /dev
/mapper
/encbtrfs
{0.
.3}
466 # Create a multi-device btrfs filesystem on the LUKS devices
467 mkfs.btrfs
-M -d raid1
-m raid1
-L "$label" -U "$uuid" /dev
/mapper
/encbtrfs
{0.
.3}
469 btrfs filesystem show
470 test -e "/dev/disk/by-uuid/$uuid"
471 test -e "/dev/disk/by-label/$label"
472 helper_check_device_symlinks
473 # Mount it and write some data to it we can compare later
474 mount
-t btrfs
/dev
/mapper
/encbtrfs0
"$mpoint"
475 echo "hello there" >"$mpoint/test"
476 # "Deconstruct" the btrfs device and check if we're in a sane state (symlink-wise)
478 systemctl stop systemd-cryptsetup@encbtrfs
{0.
.3}
479 test ! -e "/dev/disk/by-uuid/$uuid"
480 helper_check_device_symlinks
481 # Add the mount point to /etc/fstab and check if the device can be put together
482 # automagically. The source device is the DM name of the first LUKS device
483 # (from /etc/crypttab). We have to specify all LUKS devices manually, as
484 # registering the necessary devices is usually initrd's job (via btrfs device scan)
485 dev_stub
="/dev/mapper/encbtrfs"
486 echo "/dev/mapper/encbtrfs0 $mpoint btrfs device=${dev_stub}0,device=${dev_stub}1,device=${dev_stub}2,device=${dev_stub}3 0 2" >>/etc
/fstab
487 # Tell systemd about the new mount
488 systemctl daemon-reload
489 # Restart cryptsetup.target to trigger autounlock of partitions in /etc/crypttab
490 systemctl restart cryptsetup.target
491 # Start the corresponding mount unit and check if the btrfs device was reconstructed
493 systemctl start
"${mpoint##*/}.mount"
494 btrfs filesystem show
495 test -e "/dev/disk/by-uuid/$uuid"
496 test -e "/dev/disk/by-label/$label"
497 helper_check_device_symlinks
498 grep "hello there" "$mpoint/test"
500 systemctl stop
"${mpoint##*/}.mount"
501 systemctl stop systemd-cryptsetup@encbtrfs
{0.
.3}
502 sed -i "/${mpoint##*/}/d" /etc
/fstab
505 systemctl daemon-reload
509 testcase_iscsi_lvm
() {
510 local dev i label link lun_id mpoint target_name uuid
511 local target_ip
="127.0.0.1"
512 local target_port
="3260"
513 local vgroup
="iscsi_lvm$RANDOM"
514 local expected_symlinks
=()
516 /dev
/disk
/by-id
/ata-foobar_deadbeefiscsi
{0.
.3}
519 ls -l "${devices[@]}"
521 # Start the target daemon
523 systemctl status tgtd
525 echo "iSCSI LUNs backed by devices"
526 # See RFC3721 and RFC7143
527 target_name
="iqn.2021-09.com.example:iscsi.test"
528 # Initialize a new iSCSI target <$target_name> consisting of 4 LUNs, each
530 tgtadm
--lld iscsi
--op new
--mode target
--tid=1 --targetname "$target_name"
531 for ((i
= 0; i
< ${#devices[@]}; i
++)); do
532 # lun-0 is reserved by iSCSI
534 tgtadm
--lld iscsi
--op new
--mode logicalunit
--tid 1 --lun "$lun_id" -b "${devices[$i]}"
535 tgtadm
--lld iscsi
--op update
--mode logicalunit
--tid 1 --lun "$lun_id"
537 "/dev/disk/by-path/ip-$target_ip:$target_port-iscsi-$target_name-lun-$lun_id"
540 tgtadm
--lld iscsi
--op bind --mode target
--tid 1 -I ALL
541 # Configure the iSCSI initiator
542 iscsiadm
--mode discoverydb
--type sendtargets
--portal "$target_ip" --discover
543 iscsiadm
--mode node
--targetname "$target_name" --portal "$target_ip:$target_port" --login
545 # Check if all device symlinks are valid and if all expected device symlinks exist
546 for link
in "${expected_symlinks[@]}"; do
547 # We need to do some active waiting anyway, as it may take kernel a bit
548 # to attach the newly connected SCSI devices
549 helper_wait_for_dev
"$link"
553 helper_check_device_symlinks
555 iscsiadm
--mode node
--targetname "$target_name" --portal "$target_ip:$target_port" --logout
556 tgtadm
--lld iscsi
--op delete
--mode target
--tid=1
558 echo "iSCSI LUNs backed by files + LVM"
559 # Note: we use files here to "trick" LVM the disks are indeed on a different
560 # host, so it doesn't automagically detect another path to the backing
561 # device once we disconnect the iSCSI devices
562 target_name
="iqn.2021-09.com.example:iscsi.lvm.test"
563 mpoint
="$(mktemp -d /iscsi_storeXXX)"
565 # Use the first device as it's configured with larger capacity
566 mkfs.ext4
-L iscsi_store
"${devices[0]}"
568 mount
"${devices[0]}" "$mpoint"
570 dd if=/dev
/zero of
="$mpoint/lun$i.img" bs
=1M count
=32
572 # Initialize a new iSCSI target <$target_name> consisting of 4 LUNs, each
574 tgtadm
--lld iscsi
--op new
--mode target
--tid=2 --targetname "$target_name"
575 # lun-0 is reserved by iSCSI
577 tgtadm
--lld iscsi
--op new
--mode logicalunit
--tid 2 --lun "$i" -b "$mpoint/lun$i.img"
578 tgtadm
--lld iscsi
--op update
--mode logicalunit
--tid 2 --lun "$i"
580 "/dev/disk/by-path/ip-$target_ip:$target_port-iscsi-$target_name-lun-$i"
583 tgtadm
--lld iscsi
--op bind --mode target
--tid 2 -I ALL
584 # Configure the iSCSI initiator
585 iscsiadm
--mode discoverydb
--type sendtargets
--portal "$target_ip" --discover
586 iscsiadm
--mode node
--targetname "$target_name" --portal "$target_ip:$target_port" --login
588 # Check if all device symlinks are valid and if all expected device symlinks exist
589 for link
in "${expected_symlinks[@]}"; do
590 # We need to do some active waiting anyway, as it may take kernel a bit
591 # to attach the newly connected SCSI devices
592 helper_wait_for_dev
"$link"
596 helper_check_device_symlinks
597 # Add all iSCSI devices into a LVM volume group, create two logical volumes,
598 # and check if necessary symlinks exist (and are valid)
599 lvm pvcreate
-y "${expected_symlinks[@]}"
601 lvm vgcreate
"$vgroup" -y "${expected_symlinks[@]}"
603 lvm vgchange
-ay "$vgroup"
604 lvm lvcreate
-y -L 4M
"$vgroup" -n mypart1
605 lvm lvcreate
-y -L 8M
"$vgroup" -n mypart2
608 test -e "/dev/$vgroup/mypart1"
609 test -e "/dev/$vgroup/mypart2"
610 mkfs.ext4
-L mylvpart1
"/dev/$vgroup/mypart1"
612 test -e "/dev/disk/by-label/mylvpart1"
613 helper_check_device_symlinks
"/dev/disk" "/dev/$vgroup"
614 # Disconnect the iSCSI devices and check all the symlinks
615 iscsiadm
--mode node
--targetname "$target_name" --portal "$target_ip:$target_port" --logout
616 # "Reset" the DM state, since we yanked the backing storage from under the LVM,
617 # so the currently active VGs/LVs are invalid
618 dmsetup remove_all
--deferred
620 # The LVM and iSCSI related symlinks should be gone
621 test ! -e "/dev/$vgroup"
622 test ! -e "/dev/disk/by-label/mylvpart1"
623 for link
in "${expected_symlinks[@]}"; do
626 helper_check_device_symlinks
"/dev/disk"
627 # Reconnect the iSCSI devices and check if everything get detected correctly
628 iscsiadm
--mode discoverydb
--type sendtargets
--portal "$target_ip" --discover
629 iscsiadm
--mode node
--targetname "$target_name" --portal "$target_ip:$target_port" --login
631 for link
in "${expected_symlinks[@]}"; do
632 helper_wait_for_dev
"$link"
633 helper_wait_for_vgroup
"$link" "$vgroup"
637 test -e "/dev/$vgroup/mypart1"
638 test -e "/dev/$vgroup/mypart2"
639 test -e "/dev/disk/by-label/mylvpart1"
640 helper_check_device_symlinks
"/dev/disk" "/dev/$vgroup"
642 iscsiadm
--mode node
--targetname "$target_name" --portal "$target_ip:$target_port" --logout
643 tgtadm
--lld iscsi
--op delete
--mode target
--tid=2
648 testcase_long_sysfs_path
() {
649 local link logfile mpoint
650 local expected_symlinks
=(
651 "/dev/disk/by-label/data_vol"
652 "/dev/disk/by-label/swap_vol"
653 "/dev/disk/by-partlabel/test_swap"
654 "/dev/disk/by-partlabel/test_part"
655 "/dev/disk/by-partuuid/deadbeef-dead-dead-beef-000000000000"
656 "/dev/disk/by-uuid/deadbeef-dead-dead-beef-111111111111"
657 "/dev/disk/by-uuid/deadbeef-dead-dead-beef-222222222222"
660 # Make sure the test device is connected and show its "wonderful" path
662 readlink
-f /sys
/block
/vda
/dev
664 for link
in "${expected_symlinks[@]}"; do
668 # Try to mount the data partition manually (using its label)
669 mpoint
="$(mktemp -d /logsysfsXXX)"
670 mount LABEL
=data_vol
"$mpoint"
673 # Do the same, but with UUID and using fstab
674 echo "UUID=deadbeef-dead-dead-beef-222222222222 $mpoint ext4 defaults 0 0" >>/etc
/fstab
675 systemctl daemon-reload
677 test -e "$mpoint/test"
680 # Test out the swap partition
681 swapon
-v -L swap_vol
682 swapoff
-v -L swap_vol
687 journalctl
-b -q --no-pager -o short-monotonic
-p info
--grep "Device path.*vda.?' too long to fit into unit name"
688 # Make sure we don't unnecessarily spam the log
689 journalctl
-b -q --no-pager -o short-monotonic
-p info
--grep "/sys/devices/.+/vda[0-9]?" _PID
=1 + UNIT
=systemd-udevd.service |
tee "$logfile"
690 [[ "$(wc -l <"$logfile")" -lt 10 ]]
693 rm -fr "${logfile:?}" "${mpoint:?}"
699 udevadm control
--log-level debug
702 echo "Check if all symlinks under /dev/disk/ are valid (pre-test)"
703 helper_check_device_symlinks
705 # TEST_FUNCTION_NAME is passed on the kernel command line via systemd.setenv=
706 # in the respective test.sh file
707 if ! command -v "${TEST_FUNCTION_NAME:?}"; then
708 echo >&2 "Missing verification handler for test case '$TEST_FUNCTION_NAME'"
712 echo "TEST_FUNCTION_NAME=$TEST_FUNCTION_NAME"
713 "$TEST_FUNCTION_NAME"
716 echo "Check if all symlinks under /dev/disk/ are valid (post-test)"
717 helper_check_device_symlinks
719 udevadm control
--log-level info
721 systemctl status systemd-udevd