commit d6b3dab93f05da8dcd363f4e514ffc968637cb3e parent 72fbeabfdbf6bb72c25520da9fea95e3e88569bb Author: Natanael Copa <ncopa@alpinelinux.org> Date: Wed, 3 May 2023 15:18:30 +0200 fix cdrom symlink with 5.17 kernels 5.17 kernels and newer no longer set the CDROM capability in sysfs. Check if device is removable to detec if it is a cdrom. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1a827ce1b9f2c740d2c6a228afd972970c18bc21 Diffstat:
| M | persistent-storage | | | 2 | +- |
| M | tests/persistent-storage_test | | | 21 | +++++++++++++++++++++ |
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/persistent-storage b/persistent-storage @@ -27,7 +27,7 @@ blkid_encode_string() { case "$MDEV" in sr*|xvd*) caps="$(cat $SYSFS/block/$MDEV/capability 2>/dev/null)" - if [ $(( 0x${caps:-0} & 8 )) -gt 0 ]; then + if [ $(( 0x${caps:-0} & 8 )) -gt 0 ] || [ "$(cat $SYSFS/block/$MDEV/removable 2>/dev/null)" = "1" ]; then symlink_action $MDEV cdrom fi esac diff --git a/tests/persistent-storage_test b/tests/persistent-storage_test @@ -3,6 +3,7 @@ . $(atf_get_srcdir)/test_env.sh init_tests \ persistent_storage_cdrom \ + persistent_storage_cdrom_removable \ persistent_storage_nvme_wwid \ persistent_storage_sda_wwid \ persistent_storage_sda_wwid_partition_symlink \ @@ -37,6 +38,26 @@ persistent_storage_cdrom_body() { done } +persistent_storage_cdrom_removable_body() { + for dev in sr0 xvdc; do + # newer kernels does not set the CDROM capability bit + # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1a827ce1b9f2c740d2c6a228afd972970c18bc21 + mkdir -p sys/block/$dev + echo 5 > sys/block/$dev/capability + echo 1 > sys/block/$dev/removable + + MDEV=$dev ACTION=add atf_check \ + sh $mdevscript + atf_check -o match:"$dev" \ + readlink cdrom + + MDEV=$dev ACTION=remove atf_check \ + sh $mdevscript + atf_check -s not-exit:0 -o not-match:"$dev" \ + readlink cdrom + done +} + persistent_storage_nvme_wwid_body() { mkdir -p sys/class/block/nvme0n1 echo eui.0025386b61b01dcd > sys/class/block/nvme0n1/wwid