hi Emil,
thank you for this investigation, this history.
for the moment, I simply reversed the function bio_check_ro and the compilation is running...
if all is ok, I will just have to test to see if the blocking is well done...
$ diff -u linux-6.1.15.original/block/blk-core.c linux-6.1.15.me/block/blk-core.c
--- linux-6.1.15.original/block/blk-core.c 2023-03-03 11:52:25.000000000 +0100
+++ linux-6.1.15.me/block/blk-core.c 2023-03-15 13:24:24.680237258 +0100
@@ -485,15 +485,17 @@
late_initcall(fail_make_request_debugfs);
#endif /* CONFIG_FAIL_MAKE_REQUEST */
-static inline void bio_check_ro(struct bio *bio)
+static inline bool bio_check_ro(struct bio *bio)
{
if (op_is_write(bio_op(bio)) && bdev_read_only(bio->bi_bdev)) {
if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
- return;
+ return false;
pr_warn("Trying to write to read-only block-device %pg\n",
bio->bi_bdev);
/* Older lvm-tools actually trigger this */
+ return true;
}
+ return false;
}
I made some tests with
archlinux-2023.03.01-x86_64.iso to answer my question about the need to continue to make a correction : the answer is
yes it is necessary to correct because LVM alters the device set in read-only mode.
/tmp : file *.disk
lvm.disk: QEMU QCOW Image (v3), 268435456 bytes, AES-encrypted (v3), 268435456 bytes
/tmp : sha256sum *.disk
55a9af5144edf235cf0ac16fc60a8dab3c88a0d3451eb6e4d61373e0ad80cb82 lvm.disk
/tmp : qemu -cdrom /mnt/archlinux-2023.03.01-x86_64.iso
root@archiso ~ # cat /etc/udev/rules.d/09-scalpel.rules
KERNEL!="ram*", SUBSYSTEM=="block", RUN+="/usr/local/sbin/rodev /dev/%k"
KERNEL=="rtc*", SUBSYSTEM=="rtc", MODE="0400"
root@archiso ~ # cat /usr/local/sbin/rodev
#!/usr/bin/bash
[ ! "${1}" ] && echo "error: device missing" >/dev/stderr && exit 1
[ "${2}" ] && echo "error: too many devices" >/dev/stderr && exit 1
chmod 440 "${1}"
blockdev --setro "${1}"
root@archiso ~ # chmod +x !$
chmod +x /usr/local/sbin/rodev
root@archiso ~ # udevadm control --reload-rules && udevadm trigger
(qemu) drive_add 0 if=none,file=/tmp/lvm.disk,id=usbdrv
(qemu) device_add usb-storage,drive=usbdrv,id=usbkey
Mar 16 10:07:51 archiso kernel: usb 2-3: new SuperSpeed USB device number 3 using xhci_hcd
Mar 16 10:07:51 archiso kernel: usb 2-3: New USB device found, idVendor=46f4, idProduct=0001, bcdDevice= 0.00
Mar 16 10:07:51 archiso kernel: usb 2-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Mar 16 10:07:51 archiso kernel: usb 2-3: Product: QEMU USB HARDDRIVE
Mar 16 10:07:51 archiso kernel: usb 2-3: Manufacturer: QEMU
Mar 16 10:07:51 archiso kernel: usb 2-3: SerialNumber: 1-0000:00:03.0-3
Mar 16 10:07:51 archiso kernel: usb-storage 2-3:1.0: USB Mass Storage device detected
Mar 16 10:07:51 archiso kernel: scsi host6: usb-storage 2-3:1.0
Mar 16 10:07:52 archiso kernel: scsi 6:0:0:0: Direct-Access QEMU QEMU HARDDISK 2.5+ PQ: 0 ANSI: 5
Mar 16 10:07:52 archiso kernel: sd 6:0:0:0: Power-on or device reset occurred
Mar 16 10:07:52 archiso kernel: sd 6:0:0:0: [sda] 524288 512-byte logical blocks: (268 MB/256 MiB)
Mar 16 10:07:52 archiso kernel: sd 6:0:0:0: [sda] Write Protect is off
Mar 16 10:07:52 archiso kernel: sd 6:0:0:0: [sda] Mode Sense: 63 00 00 08
Mar 16 10:07:52 archiso kernel: sd 6:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
Mar 16 10:07:52 archiso kernel: sda: sda1 sda2 sda3
Mar 16 10:07:52 archiso kernel: sd 6:0:0:0: [sda] Attached SCSI disk
Mar 16 10:07:52 archiso lvm[1047]: PV /dev/sda3 online, VG test.lvm incomplete (need 2).
Mar 16 10:07:52 archiso lvm[1049]: PV /dev/sda1 online, VG test.lvm incomplete (need 1).
Mar 16 10:07:52 archiso lvm[1048]: PV /dev/sda2 online, VG test.lvm is complete.
Mar 16 10:07:52 archiso kernel: raid6: skipped pq benchmark and selected sse2x4
Mar 16 10:07:52 archiso kernel: raid6: using intx1 recovery algorithm
Mar 16 10:07:52 archiso kernel: xor: measuring software checksum speed
Mar 16 10:07:52 archiso kernel: prefetch64-sse : 34921 MB/sec
Mar 16 10:07:52 archiso kernel: generic_sse : 31738 MB/sec
Mar 16 10:07:52 archiso kernel: xor: using function: prefetch64-sse (34921 MB/sec)
Mar 16 10:07:52 archiso kernel: async_tx: api initialized (async)
Mar 16 10:07:52 archiso kernel: device-mapper: raid: Loading target version 1.15.1
Mar 16 10:07:52 archiso kernel: md/raid1:mdX: active with 3 out of 3 mirrors
Mar 16 10:07:52 archiso kernel: Trying to write to read-only block-device dm-0
Mar 16 10:07:52 archiso kernel: Trying to write to read-only block-device dm-2
Mar 16 10:07:52 archiso kernel: Trying to write to read-only block-device dm-4
Mar 16 10:07:52 archiso kernel: Trying to write to read-only block-device dm-0
Mar 16 10:07:52 archiso kernel: Trying to write to read-only block-device sda1
Mar 16 10:07:52 archiso kernel: Trying to write to read-only block-device dm-2
Mar 16 10:07:52 archiso kernel: Trying to write to read-only block-device sda2
Mar 16 10:07:52 archiso kernel: Trying to write to read-only block-device dm-4
Mar 16 10:07:52 archiso kernel: Trying to write to read-only block-device sda3
Mar 16 10:07:52 archiso systemd[1]: Started Device-mapper event daemon.
Mar 16 10:07:53 archiso dmeventd[1114]: dmeventd ready for processing.
Mar 16 10:07:53 archiso dmeventd[1114]: Monitoring RAID device test.lvm-lvm.test for events.
Mar 16 10:07:53 archiso lvm[1060]: 1 logical volume(s) in volume group "test.lvm" now active
Mar 16 10:07:53 archiso systemd[1]: lvm-activate-test.lvm.service: Deactivated successfully.
Mar 16 10:08:08 archiso kernel: Trying to write to read-only block-device dm-0
Mar 16 10:08:08 archiso kernel: Trying to write to read-only block-device dm-2
Mar 16 10:08:08 archiso kernel: Trying to write to read-only block-device dm-4
Mar 16 10:08:08 archiso kernel: Trying to write to read-only block-device dm-0
Mar 16 10:08:08 archiso kernel: Trying to write to read-only block-device sda1
Mar 16 10:08:08 archiso kernel: Trying to write to read-only block-device dm-2
Mar 16 10:08:08 archiso kernel: Trying to write to read-only block-device sda2
Mar 16 10:08:08 archiso kernel: Trying to write to read-only block-device dm-4
Mar 16 10:08:08 archiso kernel: Trying to write to read-only block-device sda3
root@archiso ~ # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 688.5M 1 loop /run/archiso/airootfs
sda 8:0 0 256M 1 disk
├─sda1 8:1 0 83M 1 part
│ ├─test.lvm-lvm.test_rmeta_0 254:0 0 4M 1 lvm
│ │ └─test.lvm-lvm.test 254:6 0 64M 1 lvm
│ └─test.lvm-lvm.test_rimage_0 254:1 0 64M 1 lvm
│ └─test.lvm-lvm.test 254:6 0 64M 1 lvm
├─sda2 8:2 0 83M 1 part
│ ├─test.lvm-lvm.test_rmeta_1 254:2 0 4M 1 lvm
│ │ └─test.lvm-lvm.test 254:6 0 64M 1 lvm
│ └─test.lvm-lvm.test_rimage_1 254:3 0 64M 1 lvm
│ └─test.lvm-lvm.test 254:6 0 64M 1 lvm
└─sda3 8:3 0 83M 1 part
├─test.lvm-lvm.test_rmeta_2 254:4 0 4M 1 lvm
│ └─test.lvm-lvm.test 254:6 0 64M 1 lvm
└─test.lvm-lvm.test_rimage_2 254:5 0 64M 1 lvm
└─test.lvm-lvm.test 254:6 0 64M 1 lvm
sr0 11:0 1 810.3M 1 rom /run/archiso/bootmnt
root@archiso ~ # dd if=/dev/zero of=/dev/sda bs=1M count=16
dd: error writing '/dev/sda': Operation not permitted
1+0 records in
0+0 records out
0 bytes copied, 0.00814249 s, 0.0 kB/s
/tmp : sha256sum *.disk
1a11bb40ee4887d0dabd9fca2224cf7219bb37d7efe2a8fbd73a4b656213c228 lvm.disk
root@archiso ~ # pvdisplay
--- Physical volume ---
PV Name /dev/sda1
VG Name test.lvm
PV Size <83.01 MiB / not usable <3.01 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 20
Free PE 3
Allocated PE 17
PV UUID mQR1eS-K5Zf-5lfl-Dupc-lRhN-Yfpf-7Vl36V
--- Physical volume ---
PV Name /dev/sda2
VG Name test.lvm
PV Size <83.01 MiB / not usable <3.01 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 20
Free PE 3
Allocated PE 17
PV UUID As2RrD-Cev0-hhB7-yohn-r5ym-P34m-MFV0M9
--- Physical volume ---
PV Name /dev/sda3
VG Name test.lvm
PV Size <83.01 MiB / not usable <3.01 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 20
Free PE 3
Allocated PE 17
PV UUID khaOAc-YEX4-bi0u-fdtq-doG9-Wuok-B2kCS8
root@archiso ~ # vgdisplay
--- Volume group ---
VG Name test.lvm
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 240.00 MiB
PE Size 4.00 MiB
Total PE 60
Alloc PE / Size 51 / 204.00 MiB
Free PE / Size 9 / 36.00 MiB
VG UUID sttYAJ-VmEf-biZh-C8Uh-jUCK-orFO-WVNX6t
root@archiso ~ # vgchange -ay test.lvm
1 logical volume(s) in volume group "test.lvm" now active
/tmp : sha256sum *.disk
c39d62a5e9f87dc33339098c64903b56b2d3ac5248d2f34c10e63241a10a35b3 lvm.disk
root@archiso ~ # lvdisplay
--- Logical volume ---
LV Path /dev/test.lvm/lvm.test
LV Name lvm.test
VG Name test.lvm
LV UUID G1y4A0-LbbZ-na9w-AJrQ-jVtc-pKDo-RKgc0S
LV Write Access read/write (activated read only)
LV Creation host, time scalpel, 2019-03-12 14:59:02 +0000
LV Status available
# open 0
LV Size 64.00 MiB
Current LE 16
Mirrored volumes 3
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:6
root@archiso ~ # mount /dev/test.lvm/lvm.test /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
root@archiso ~ # ll /mnt
total 16
drwx------ 2 root root 12288 Mar 12 2019 lost+found
-rwxr-xr-x 1 root root 3155 Mar 12 2019 lvm.md
root@archiso ~ # umount /mnt
(qemu) device_del usbkey
Mar 16 10:21:07 archiso kernel: usb 2-3: USB disconnect, device number 3
Mar 16 10:21:07 archiso kernel: sd 6:0:0:0: [sda] Synchronizing SCSI cache
Mar 16 10:21:07 archiso kernel: sd 6:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
Mar 16 10:21:07 archiso (udev-worker)[1276]: sda2: Process '/usr/local/sbin/rodev /dev/sda2' failed with exit code 1.
Mar 16 10:21:07 archiso systemd-homed[268]: block device /sys/devices/pci0000:00/0000:00:03.0/usb2/2-3/2-3:1.0/host6/target6:0:0/6:0:0:0/block/sda/sda2 has been removed.
Mar 16 10:21:07 archiso (udev-worker)[1275]: sda1: Process '/usr/local/sbin/rodev /dev/sda1' failed with exit code 1.
Mar 16 10:21:07 archiso systemd-homed[268]: block device /sys/devices/pci0000:00/0000:00:03.0/usb2/2-3/2-3:1.0/host6/target6:0:0/6:0:0:0/block/sda/sda1 has been removed.
Mar 16 10:21:07 archiso (udev-worker)[1277]: sda3: Process '/usr/local/sbin/rodev /dev/sda3' failed with exit code 1.
Mar 16 10:21:07 archiso systemd-homed[268]: block device /sys/devices/pci0000:00/0000:00:03.0/usb2/2-3/2-3:1.0/host6/target6:0:0/6:0:0:0/block/sda/sda3 has been removed.
Mar 16 10:21:07 archiso (udev-worker)[1276]: sda: Process '/usr/local/sbin/rodev /dev/sda' failed with exit code 1.
Mar 16 10:21:07 archiso systemd-homed[268]: block device /sys/devices/pci0000:00/0000:00:03.0/usb2/2-3/2-3:1.0/host6/target6:0:0/6:0:0:0/block/sda has been removed.
/tmp : sha256sum *.disk
c39d62a5e9f87dc33339098c64903b56b2d3ac5248d2f34c10e63241a10a35b3 lvm.disk
the same test was performed with for example Linux Software RAID (mdadm) and the device is not modified (as expected from being locked in read-only mode).
in conclusion, it seems that LVM, even in recent version, does not take into account the read-only mode...
regards, lacsaP.