]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: test udev with a _very_ long device name
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 1 Oct 2021 11:56:25 +0000 (13:56 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 6 Oct 2021 18:17:44 +0000 (03:17 +0900)
Let's attempt to provide some coverage for #16161, #6867, and similar.

test/TEST-64-UDEV-STORAGE/test.sh
test/units/testsuite-64.sh

index 23cdefa5ce96605d2b431dc244f777e305f1ad55..bd3f8250a3fa598b7f0bbe710d9d1e4ef01f71e0 100755 (executable)
@@ -2,10 +2,9 @@
 # vi: ts=4 sw=4 tw=0 et:
 #
 # TODO:
-#   * iSCSI
-#   * LVM over iSCSI (?)
 #   * SW raid (mdadm)
-#   * MD (mdadm) -> DM-CRYPT -> LVM
+#   * MD (mdadm) -> dm-crypt -> LVM
+#   * iSCSI -> dm-crypt -> LVM
 set -e
 
 TEST_DESCRIPTION="systemd-udev storage tests"
@@ -69,7 +68,7 @@ test_append_files() {(
 
     instmods "=block" "=md" "=nvme" "=scsi"
     install_dmevent
-    image_install lsblk wc wipefs
+    image_install lsblk swapoff swapon wc wipefs
 
     # Install the optional features if the host has the respective tooling
     for feature in "${!features[@]}"; do
@@ -391,13 +390,51 @@ testcase_iscsi_lvm() {
         )
     done
 
-
     KERNEL_APPEND="systemd.setenv=TEST_FUNCTION_NAME=${FUNCNAME[0]} ${USER_KERNEL_APPEND:-}"
     QEMU_OPTIONS="${qemu_opts[*]} ${USER_QEMU_OPTIONS:-}"
     test_run_one "${1:?}" || return $?
 
     rm -f "${TESTDIR:?}"/iscsibasic*.img
 }
+
+testcase_long_sysfs_path() {
+    local brid
+    local testdisk="${TESTDIR:?}/longsysfspath.img"
+    local qemu_opts=(
+        "-drive if=none,id=drive0,format=raw,cache=unsafe,file=$testdisk"
+        "-device pci-bridge,id=pci_bridge0,bus=pci.0,chassis_nr=64"
+    )
+
+    dd if=/dev/zero of="$testdisk" bs=1M count=64
+    lodev="$(losetup --show -f -P "$testdisk")"
+    sfdisk "${lodev:?}" <<EOF
+label: gpt
+
+name="test_swap", size=32M
+uuid="deadbeef-dead-dead-beef-000000000000", name="test_part", size=5M
+EOF
+    udevadm settle
+    mkswap -U "deadbeef-dead-dead-beef-111111111111" -L "swap_vol" "${lodev}p1"
+    mkfs.ext4 -U "deadbeef-dead-dead-beef-222222222222" -L "data_vol" "${lodev}p2"
+    losetup -d "$lodev"
+
+    # Create 25 additional PCI bridges, each one connected to the previous one
+    # (basically a really long extension cable), and attach a virtio drive to
+    # the last one. This should force udev into attempting to create a device
+    # unit with a _really_ long name.
+    for brid in {1..25}; do
+        qemu_opts+=("-device pci-bridge,id=pci_bridge$brid,bus=pci_bridge$((brid-1)),chassis_nr=$((64+brid))")
+    done
+
+    qemu_opts+=("-device virtio-blk-pci,drive=drive0,scsi=off,bus=pci_bridge$brid")
+
+    KERNEL_APPEND="systemd.setenv=TEST_FUNCTION_NAME=${FUNCNAME[0]} ${USER_KERNEL_APPEND:-}"
+    QEMU_OPTIONS="${qemu_opts[*]} ${USER_QEMU_OPTIONS:-}"
+    test_run_one "${1:?}" || return $?
+
+    rm -f "${testdisk:?}"
+}
+
 # Allow overriding which tests should be run from the "outside", useful for manual
 # testing (make -C test/... TESTCASES="testcase1 testcase2")
 if [[ -v "TESTCASES" && -n "$TESTCASES" ]]; then
index 13a1316b7add28f2110cd1d6226b455ff4c2143e..6f8382707facfc17d024abf069564bdd46fb1d60 100755 (executable)
@@ -588,6 +588,53 @@ testcase_iscsi_lvm() {
     umount "$mpoint"
     rm -rf "$mpoint"
 }
+
+testcase_long_sysfs_path() {
+    local link logfile mpoint
+    local expected_symlinks=(
+        "/dev/disk/by-label/data_vol"
+        "/dev/disk/by-label/swap_vol"
+        "/dev/disk/by-partlabel/test_swap"
+        "/dev/disk/by-partlabel/test_part"
+        "/dev/disk/by-partuuid/deadbeef-dead-dead-beef-000000000000"
+        "/dev/disk/by-uuid/deadbeef-dead-dead-beef-111111111111"
+        "/dev/disk/by-uuid/deadbeef-dead-dead-beef-222222222222"
+    )
+
+    # Make sure the test device is connected and show its "wonderful" path
+    stat /sys/block/vda
+    readlink -f /sys/block/vda/dev
+
+    for link in "${expected_symlinks[@]}"; do
+        test -e "$link"
+    done
+
+    # Try to mount the data partition manually (using its label)
+    mpoint="$(mktemp -d /logsysfsXXX)"
+    mount LABEL=data_vol "$mpoint"
+    touch "$mpoint/test"
+    umount "$mpoint"
+    # Do the same, but with UUID and using fstab
+    echo "UUID=deadbeef-dead-dead-beef-222222222222 $mpoint ext4 defaults 0 0" >>/etc/fstab
+    systemctl daemon-reload
+    mount "$mpoint"
+    test -e "$mpoint/test"
+    umount "$mpoint"
+
+    # Test out the swap partition
+    swapon -v -L swap_vol
+    swapoff -v -L swap_vol
+
+    logfile="$(mktemp)"
+    journalctl -b -q --no-pager -o short-monotonic -p info --grep "Device path.*vda.?' too long to fit into unit name"
+    # Make sure we don't unnecessarily spam the log
+    journalctl -b -q --no-pager -o short-monotonic -p info --grep "/sys/devices/.+/vda[0-9]?" _PID=1 + UNIT=systemd-udevd.service | tee "$logfile"
+    [[ "$(wc -l <"$logfile")" -lt 10 ]]
+
+    : >/etc/fstab
+    rm -fr "${logfile:?}" "${mpoint:?}"
+}
+
 : >/failed
 
 udevadm settle
@@ -605,6 +652,7 @@ fi
 
 echo "TEST_FUNCTION_NAME=$TEST_FUNCTION_NAME"
 "$TEST_FUNCTION_NAME"
+udevadm settle
 
 echo "Check if all symlinks under /dev/disk/ are valid (post-test)"
 helper_check_device_symlinks