block layer: a read or a writeback that fails is refused, not taken as blank or dropped (#187)

A disk header that cannot be read refuses the attach (BLK_EIO, with a
message naming the disk by size); it was taken as blank and offered for
a format. A data read that fails is refused, not cached as zeros. An
eviction whose writeback fails keeps the slot and refuses the new one;
the changes were lost. test_host_blocks, a device whose reads can fail:
7 of 65 failed against the old code, 65 pass (63 at 32 bits). The
test's own errors (a detached device not reopened; two devices declared
out of the later checks' scope) corrected. ident_attach_fail on amd64:
the attach refused; its two failures left are #179's. The five write
results still thrown away are reported, not changed. Gates pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-21 00:37:33 +00:00
parent 20918f9f09
commit 63e9966abc
9 changed files with 1949 additions and 10 deletions
@@ -0,0 +1,187 @@
[=3h[=3h[=3hBdsDxe: loading Boot0001 "UEFI QEMU DVD-ROM QM00005 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x2,0xFFFF,0x0)
BdsDxe: starting Boot0001 "UEFI QEMU DVD-ROM QM00005 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x2,0xFFFF,0x0)
[=3hStarKernel UEFI Loader
Loading kernel from ESP...
[CKPT 001] Entered efi_main - ConOut live
RAW SERIAL UP
[CKPT 002] Serial (COM1) initialized
Monolithic build - kernel linked directly
Collecting boot information...
CmdLine: parsed OK
[CKPT 004] Command line parsed
[CKPT 005] Kernel stack allocation decided
[CKPT 006] Boot info collected (ACPI table located)
GOP: linear framebuffer found
[CKPT 007] GOP: linear framebuffer found
[CKPT 008] About to enter ExitBootServices retry loop
EBS...
EBS OK
Calling kernel_main (monolithic)...
_____ _ _ __ _
/ ____| | | |/ / | |
| (___ | |_ __ _ _ __| ' / ___ _ __ _ __ ___| |
\___ \| __/ _` | '__| < / _ \ '__| '_ \ / _ \ |
____) | || (_| | | | . \ __/ | | | | | __/ |
|_____/ \__\__,_|_| |_|\_\___|_| |_| |_|\___|_|
LithosAnanke v4.0.0-alpha.5 amd64
Architecture: amd64
Build: Nov 20 2026 22:57:30
UEFI BootServices: EXITED
Console: serial line is a 16550 at port 0x00000000000003f8 (COM1, probed)
=== StarKernel Boot Information ===
Memory map entries: 128
Total memory: 1023 MB
Usable memory: 964 MB
===================================
PMM initialized.
PMM statistics:
Total pages: 248378
Free pages : 246851
Used pages : 1527
Total MB : 970
Free MB : 964
Used MB : 5
VMM initialized (mapped RAM, CR3 switched)
VMM initialized (mapped RAM, CR3 switched)
VMM self-test: mapped OK at 0xffff800000000000
VMM self-test complete.
IDT installed.
APIC: init...
APIC: IA32_APIC_BASE MSR=0x00000000fee00900
APIC: stale-ISR drain: 0 EOI(s) issued
APIC: initialized (xAPIC MMIO, TPR=0, SIVR=0x1FF, EOI-clear)
APIC: init done
I/O APIC: init...
I/O APIC: base=0xfec00000, gsi_base=0, overrides=5
override: source=00 gsi=2 flags=0x0000
override: source=05 gsi=5 flags=0x000d
override: source=09 gsi=9 flags=0x000d
override: source=0a gsi=10 flags=0x000d
override: source=0b gsi=11 flags=0x000d
i8042: keyboard ACKed enable-scanning
i8042: IRQ1 enabled in controller config byte
I/O APIC: keyboard IRQ1 routed (masked)
Timer: init...
Timer: init start
Timer: PM_TMR_BLK discovered from FADT at port 1544
Timer: VM mode detected (hypervisor present).
Timer: HPET calibration disabled (VM-exit MMIO would poison timing).
Timer: WARNING: invariant TSC not present under hypervisor.
Timer: continuing in RELATIVE mode (no determinism guarantees).
Timer: RDTSCP not present; using RDTSC (less serialized).
Timer: CPUID frequency unavailable; trying PM Timer...
Timer: trust=1 (0=NONE,1=REL,2=ABS), TSC=2091557639 Hz
Timer: init done
Kernel heap initialized.
Heap statistics:
Total bytes: 536870872
Free bytes: 536870872
Used bytes: 0
Peak bytes: 0
Heap base addr: 24641536
Heap end addr: 561512448
Heartbeat: init...
APIC Timer: calibrating...
APIC Timer: apic_hz=1008194418, tick_hz=100, initial_count=10081944
APIC Timer: configured (masked, ready to start)
Heartbeat: init done
Kernel initialization complete.
Boot successful!
Boot disk: not a StarshipOS stick
System: StarForth v4 (this build's default)
Stadium: 83886 cells (5242 KB), 50 VM slots
Switch-signal: 50 slots
Kernel-Hermes: 50 channel slots
Kernel-Hermes: 50 pending-queue slots
StarForth v4: Hera, born in the kernel's fabric
V4: capsule v4:sys:map-64.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:map-64.f18 capsule_hash=0x81bda2bfcf496f6a
V4: capsule v4:sys:core.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:core.f18 capsule_hash=0x0f415502fccc3fba
V4: capsule v4:sys:input.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:input.f18 capsule_hash=0x0f13c3f9d5fd07fc
V4: capsule v4:sys:dict.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:dict.f18 capsule_hash=0xe3453808afd5a0af
V4: capsule v4:sys:codegen.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:codegen.f18 capsule_hash=0x36d2ae84d2911b90
V4: capsule v4:sys:compile.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:compile.f18 capsule_hash=0xbef95acf00cb404a
V4: capsule v4:sys:quit.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:quit.f18 capsule_hash=0x7fa7a7668b6bf1ed
V4: capsule v4:sys:forth.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:forth.f18 capsule_hash=0xc4c0ad315c95eda4
V4: capsule v4:sys:numout.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:numout.f18 capsule_hash=0xca0fb0f9c1589e20
V4: capsule v4:sys:words.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:words.f18 capsule_hash=0x2f4e5f7f3e7f736f
V4: capsule v4:sys:system.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:system.f18 capsule_hash=0xfe257eb084c43a5d
V4: capsule v4:sys:qmath.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:qmath.f18 capsule_hash=0xa93783c2c8f9b7db
V4: capsule v4:sys:blocks.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:blocks.f18 capsule_hash=0x09d361dbe6174236
V4: capsule v4:sys:log.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:log.f18 capsule_hash=0x544cd004233dff62
V4: capsule v4:sys:acl.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:acl.f18 capsule_hash=0x5ceb5b43b0c5fbb1
V4: capsule v4:sys:end.f18 signature: missing (unsigned)
PARITY:V4_F18 name=v4:sys:end.f18 capsule_hash=0x22eea18b132f8faf
PARITY:V4_ROM words=2383 rom_hash=0xd858ef412d684f92 instructions=63864013
V4: capsule v4:forth79.4th signature: missing (unsigned)
PARITY:V4_CAPSULE name=v4:forth79.4th capsule_id=0x4609d6ef54166ef8 capsule_hash=0x4609d6ef54166ef8 dict_hash=0xbfcb975ac5a745f2
V4: capsule v4:starshipos.4th signature: missing (unsigned)
PARITY:V4_CAPSULE name=v4:starshipos.4th capsule_id=0x1734a8f4fe7483a5 capsule_hash=0x1734a8f4fe7483a5 dict_hash=0x75401e63fcca3f0d
V4: capsule v4:centre.4th signature: missing (unsigned)
PARITY:V4_CAPSULE name=v4:centre.4th capsule_id=0x53b1e3df644e8e25 capsule_hash=0x53b1e3df644e8e25 dict_hash=0xc22f69bd157a4a70
V4: capsule v4:hera.4th signature: missing (unsigned)
PARITY:V4_CAPSULE name=v4:hera.4th capsule_id=0x78730b1d6effe892 capsule_hash=0x78730b1d6effe892 dict_hash=0x17a3406cec07df1e
V4: capsule v4:physics.4th signature: missing (unsigned)
PARITY:V4_CAPSULE name=v4:physics.4th capsule_id=0xb26da18d35ce5a84 capsule_hash=0xb26da18d35ce5a84 dict_hash=0x7c80c30f0ef456c6
PARITY:V4_POST tests=992 pass=992 fail=0
PARITY:V4_SYSTEM word_count=407 dict_hash=0x7c5a2f0c02145e63
V4: capsule v4:init.4th signature: missing (unsigned)
V4: capsule v4:ACL.4th signature: missing (unsigned)
INFO: ACL: active
PARITY:V4_CAPSULE name=v4:init.4th capsule_id=0x13fe8932fa4d2934 capsule_hash=0x13fe8932fa4d2934 dict_hash=0x1a816036149f1574
PARITY:OK
POST: PASSED
PCI: init...
PCI: ECAM mapped (amd64)
virtio-rng: no device on PCI bus 0
rng: backend = rdrand
entropy: ready
virtio-input: no device on PCI bus 0
Starting heartbeat...
APIC Timer: started (LVT=0x00020020 ICR=10081944)
I/O APIC: keyboard IRQ1 unmasked
Heartbeat running.
Stadium opcodes: 31 resident, hottest opcode 8
Stadium words: promotions=271 evictions=0
Stadium conservation: resident_sum=43680 reservoir=21856 sum=65536 (Q48_ONE=65536)
Stadium conservation: CONSERVED
Stadium quota grant self-test: OK
Hera reservoir=21856
test-vm reservoir=65536
Heartbeat: 3 ticks, trust=0x00010000, variance=0x00000000
blkio_usb: MSC device ready
Artemis: the stick's partition attached
[HADES][WARN ] [KRELTSC: 0] blk: a disk of 512000 KiB: its header could not be read -- not
xhci: USB MSC block-subsystem attach failed
blkio_usb: MSC device ready
Artemis: the stick's partition attached
[Hera] Zuse: genesis minted onto attached thumbdrive
[zuse@Hera] ok> 
+9
View File
@@ -0,0 +1,9 @@
make: Entering directory '/home/user/LithosAnanke/v4'
cd /home/user/LithosAnanke/v4/build/v3o && cc -std=gnu99 -Wall -O2 -g -I/home/user/LithosAnanke/v3/include -I/home/user/LithosAnanke/kernel/include -c /home/user/LithosAnanke/v3/src/block_subsystem.c /home/user/LithosAnanke/v3/src/blkio_ram.c /home/user/LithosAnanke/v3/src/blkio_file.c /home/user/LithosAnanke/v3/src/log.c /home/user/LithosAnanke/v3/src/platform/platform_init.c /home/user/LithosAnanke/v3/src/platform/linux/time.c
ld -r /home/user/LithosAnanke/v4/build/v3o/*.o -o /home/user/LithosAnanke/v4/build/v3blocks.o
cc -std=c99 -Wall -Wextra -Wpedantic -Werror -O2 -g -I/home/user/LithosAnanke/v4/include -isystem /home/user/LithosAnanke/v3/include -isystem /home/user/LithosAnanke/kernel/include -DV4_CELL_BITS=32 -DV4_NODE_WORDS=32768 -DV4_DATA_RING=1022 -DV4_RET_RING=31 -DV4_ROM_WORDS=4096 -DV4_CAPSULE_DIR='"/home/user/LithosAnanke/v4/capsule"' -DV4_SYS_DIR='"/home/user/LithosAnanke/capsules/v4/sys"' -DV4_ROM_LINKED -DV4_ROM_SYM='"/home/user/LithosAnanke/v4/build/rom-32.sym"' -DV4_MESH_ROM_SYM='"/home/user/LithosAnanke/v4/build/mesh-rom-32.sym"' /home/user/LithosAnanke/v4/tests/test_host_blocks.c /home/user/LithosAnanke/v4/src/artifact.c /home/user/LithosAnanke/v4/src/asm.c /home/user/LithosAnanke/v4/src/capsule.c /home/user/LithosAnanke/v4/src/effect.c /home/user/LithosAnanke/v4/src/exec.c /home/user/LithosAnanke/v4/src/fabric.c /home/user/LithosAnanke/v4/src/guard.c /home/user/LithosAnanke/v4/src/heat.c /home/user/LithosAnanke/v4/src/image.c /home/user/LithosAnanke/v4/src/iword.c /home/user/LithosAnanke/v4/src/manage.c /home/user/LithosAnanke/v4/src/message.c /home/user/LithosAnanke/v4/src/node.c /home/user/LithosAnanke/v4/src/place.c /home/user/LithosAnanke/v4/src/stack.c /home/user/LithosAnanke/v4/src/testcode.c /home/user/LithosAnanke/v4/src/text.c /home/user/LithosAnanke/v4/src/umul.c /home/user/LithosAnanke/v4/src/wire.c /home/user/LithosAnanke/v4/system/blocks.c /home/user/LithosAnanke/v4/system/post.c /home/user/LithosAnanke/v4/system/post_cases.c /home/user/LithosAnanke/kernel/src/capsule/capsule_blocks.c /home/user/LithosAnanke/v4/build/v3blocks.o /home/user/LithosAnanke/v4/build/rom-32.c /home/user/LithosAnanke/v4/build/mesh-rom-32.c -o /home/user/LithosAnanke/v4/build/32-test_host_blocks.c
[V4_CELL_BITS=32 run-32-test_host_blocks.c]
v4 block request tests: V4_CELL_BITS=32, V4_NODE_WORDS=32768
63 checks, 0 failures
make: Leaving directory '/home/user/LithosAnanke/v4'
exit 0
+5
View File
@@ -0,0 +1,5 @@
cc -std=c99 -Wall -Wextra -Wpedantic -Werror -O2 -g -I/home/user/LithosAnanke/v4/include -isystem /home/user/LithosAnanke/v3/include -isystem /home/user/LithosAnanke/kernel/include -DV4_CELL_BITS=64 -DV4_NODE_WORDS=32768 -DV4_DATA_RING=1022 -DV4_RET_RING=31 -DV4_ROM_WORDS=4096 -DV4_CAPSULE_DIR='"/home/user/LithosAnanke/v4/capsule"' -DV4_SYS_DIR='"/home/user/LithosAnanke/capsules/v4/sys"' -DV4_ROM_LINKED -DV4_ROM_SYM='"/home/user/LithosAnanke/v4/build/rom-64.sym"' -DV4_MESH_ROM_SYM='"/home/user/LithosAnanke/v4/build/mesh-rom-64.sym"' /home/user/LithosAnanke/v4/tests/test_host_blocks.c /home/user/LithosAnanke/v4/src/artifact.c /home/user/LithosAnanke/v4/src/asm.c /home/user/LithosAnanke/v4/src/capsule.c /home/user/LithosAnanke/v4/src/effect.c /home/user/LithosAnanke/v4/src/exec.c /home/user/LithosAnanke/v4/src/fabric.c /home/user/LithosAnanke/v4/src/guard.c /home/user/LithosAnanke/v4/src/heat.c /home/user/LithosAnanke/v4/src/image.c /home/user/LithosAnanke/v4/src/iword.c /home/user/LithosAnanke/v4/src/manage.c /home/user/LithosAnanke/v4/src/message.c /home/user/LithosAnanke/v4/src/node.c /home/user/LithosAnanke/v4/src/place.c /home/user/LithosAnanke/v4/src/stack.c /home/user/LithosAnanke/v4/src/testcode.c /home/user/LithosAnanke/v4/src/text.c /home/user/LithosAnanke/v4/src/umul.c /home/user/LithosAnanke/v4/src/wire.c /home/user/LithosAnanke/v4/system/blocks.c /home/user/LithosAnanke/v4/system/post.c /home/user/LithosAnanke/v4/system/post_cases.c /home/user/LithosAnanke/kernel/src/capsule/capsule_blocks.c /home/user/LithosAnanke/v4/build/v3blocks.o /home/user/LithosAnanke/v4/build/rom-64.c /home/user/LithosAnanke/v4/build/mesh-rom-64.c -o /home/user/LithosAnanke/v4/build/64-test_host_blocks.c
[V4_CELL_BITS=64 run-64-test_host_blocks.c]
v4 block request tests: V4_CELL_BITS=64, V4_NODE_WORDS=32768
65 checks, 0 failures
exit 0
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,33 @@
LOG: logs/20261120-225815/amd64/qemu-amd64-20261120-225815.log
PASS: POST: PASSED
[23:03:03.694] INFO: blk: disk 'StarForth Volume' v2 LBN 2048..777305 (775258 user blocks); devblocks=264704 bam=6144 base=6146 total=775290 free=775258 fence=128
[23:03:03.785] INFO: blk: disk 'StarForth Volume' v2 LBN 2048..777305 (775258 user blocks); devblocks=264704 bam=6144 base=6146 total=775290 free=775258 fence=128
PASS: no ok> for 20 s with no drive
FAIL: Zuse: the stick's identity partition failed -- not used
--- serial log, after /Artemis|Zuse|xhci/, line 186 (logs/20261120-225815/amd64/qemu-amd64-20261120-225815.log):
186 | Artemis: the stick's partition attached
187 | \x1b[33m[HADES][WARN ] \x1b[0m[KRELTSC: 0] blk: a disk of 512000 KiB: its header could not be read -- not
188 | xhci: USB MSC block-subsystem attach failed
---
--- the CPUs, 1 of 3: RIP=000000003d2d4105 RFL=00000287 [--S--PC] CPL=0 II=0 A20=1 SMM=0 HLT=1
the code at the PC: 000000003d2d4105: 0x0f2e66c3 0x0000841f 0xf3000000 0xfafa1e0f 000000003d2d4115: 0xfffffeb8 0x0f64e6ff 0xfa00401f 0x66fcebf4
--- the CPUs, 2 of 3: RIP=000000003d2d4105 RFL=00000283 [--S---C] CPL=0 II=0 A20=1 SMM=0 HLT=1
the code at the PC: 000000003d2d4105: 0x0f2e66c3 0x0000841f 0xf3000000 0xfafa1e0f 000000003d2d4115: 0xfffffeb8 0x0f64e6ff 0xfa00401f 0x66fcebf4
--- the CPUs, 3 of 3: RIP=000000003d2d4105 RFL=00000283 [--S---C] CPL=0 II=0 A20=1 SMM=0 HLT=1
the code at the PC: 000000003d2d4105: 0x0f2e66c3 0x0000841f 0xf3000000 0xfafa1e0f 000000003d2d4115: 0xfffffeb8 0x0f64e6ff 0xfa00401f 0x66fcebf4
FAIL: Artemis: the stick's partition let go -- both or neither
--- serial log, after /Artemis|Zuse|xhci/, line 186 (logs/20261120-225815/amd64/qemu-amd64-20261120-225815.log):
186 | Artemis: the stick's partition attached
187 | \x1b[33m[HADES][WARN ] \x1b[0m[KRELTSC: 0] blk: a disk of 512000 KiB: its header could not be read -- not
188 | xhci: USB MSC block-subsystem attach failed
---
--- the CPUs, 1 of 3: RIP=000000003d2d4105 RFL=00000297 [--S-APC] CPL=0 II=0 A20=1 SMM=0 HLT=1
the code at the PC: 000000003d2d4105: 0x0f2e66c3 0x0000841f 0xf3000000 0xfafa1e0f 000000003d2d4115: 0xfffffeb8 0x0f64e6ff 0xfa00401f 0x66fcebf4
--- the CPUs, 2 of 3: RIP=000000003d2d4105 RFL=00000287 [--S--PC] CPL=0 II=0 A20=1 SMM=0 HLT=1
the code at the PC: 000000003d2d4105: 0x0f2e66c3 0x0000841f 0xf3000000 0xfafa1e0f 000000003d2d4115: 0xfffffeb8 0x0f64e6ff 0xfa00401f 0x66fcebf4
--- the CPUs, 3 of 3: RIP=000000003d2d4105 RFL=00000283 [--S---C] CPL=0 II=0 A20=1 SMM=0 HLT=1
the code at the PC: 000000003d2d4105: 0x0f2e66c3 0x0000841f 0xf3000000 0xfafa1e0f 000000003d2d4115: 0xfffffeb8 0x0f64e6ff 0xfa00401f 0x66fcebf4
PASS: no ok> for 20 s with the faulty stick
PASS: the same stick, without the fault: genesis
PASS: [zuse@Hera] ok>
RESULT: FAIL
+18 -8
View File
@@ -248,13 +248,14 @@ static inline uint32_t lbn_to_slot_pbn(blk_dev_slot_t *slot, uint32_t lbn) {
static inline uint32_t slot_pbn_to_devblock(uint32_t rel_pbn) { return rel_pbn / BLK_PACK_RATIO; } static inline uint32_t slot_pbn_to_devblock(uint32_t rel_pbn) { return rel_pbn / BLK_PACK_RATIO; }
static inline uint32_t slot_pbn_pack_offset(uint32_t rel_pbn) { return rel_pbn % BLK_PACK_RATIO; } static inline uint32_t slot_pbn_pack_offset(uint32_t rel_pbn) { return rel_pbn % BLK_PACK_RATIO; }
/* A read that fails is BLK_EIO, not zeros (#187, 2026-11-20): a block that cannot be read is not
* given as empty. Past the device's end is zeros, as before: there is nothing there to read. */
static int read_devblock_4k(blk_dev_slot_t *slot, uint32_t dev4k, uint8_t *buf4k) { static int read_devblock_4k(blk_dev_slot_t *slot, uint32_t dev4k, uint8_t *buf4k) {
uint32_t base = devblock4k_to_lba1k(slot, dev4k); uint32_t base = devblock4k_to_lba1k(slot, dev4k);
for (uint32_t i = 0; i < 4; i++) { for (uint32_t i = 0; i < 4; i++) {
uint32_t lba = base + i; uint32_t lba = base + i;
if (lba >= slot->total_blkio_blocks_1k) { memset(buf4k + i*1024u, 0, 1024u); continue; } if (lba >= slot->total_blkio_blocks_1k) { memset(buf4k + i*1024u, 0, 1024u); continue; }
int rc = blkio_read(slot->dev, lba, buf4k + i*1024u); if (blkio_read(slot->dev, lba, buf4k + i*1024u) != BLKIO_OK) return BLK_EIO;
if (rc != BLKIO_OK) memset(buf4k + i*1024u, 0, 1024u);
} }
return BLK_OK; return BLK_OK;
} }
@@ -306,8 +307,9 @@ static cache_slot_t *cache_get_slot(blk_dev_slot_t *slot, uint32_t dev4k) {
return s; return s;
} }
} }
/* evict slot[0] FIFO */ /* evict slot[0] FIFO -- only once what it holds is written: a slot whose writeback fails is kept,
(void) cache_writeback(slot, &slot->cache[0]); * and no slot is given (#187, 2026-11-20; it was evicted whatever the write did, its data lost) */
if (cache_writeback(slot, &slot->cache[0]) != BLK_OK) return NULL;
for (int i = 0; i < DISK_CACHE_SLOTS - 1; i++) slot->cache[i] = slot->cache[i+1]; for (int i = 0; i < DISK_CACHE_SLOTS - 1; i++) slot->cache[i] = slot->cache[i+1];
memset(&slot->cache[DISK_CACHE_SLOTS-1], 0, sizeof(cache_slot_t)); memset(&slot->cache[DISK_CACHE_SLOTS-1], 0, sizeof(cache_slot_t));
slot->cache[DISK_CACHE_SLOTS-1].valid = 1; slot->cache[DISK_CACHE_SLOTS-1].valid = 1;
@@ -319,7 +321,10 @@ static cache_slot_t *cache_load_devblock(blk_dev_slot_t *slot, uint32_t dev4k) {
cache_slot_t *s = cache_get_slot(slot, dev4k); cache_slot_t *s = cache_get_slot(slot, dev4k);
if (!s) return NULL; if (!s) return NULL;
if (!s->loaded) { if (!s->loaded) {
(void) read_devblock_4k(slot, dev4k, s->data); if (read_devblock_4k(slot, dev4k, s->data) != BLK_OK) { /* #187: not cached as zeros */
memset(s, 0, sizeof(*s));
return NULL;
}
uint8_t *mr = s->data + META_REGION_OFFSET; uint8_t *mr = s->data + META_REGION_OFFSET;
for (uint32_t i = 0; i < BLK_PACK_RATIO; i++) { for (uint32_t i = 0; i < BLK_PACK_RATIO; i++) {
meta_from_slice(&s->meta[i], mr + i * META_PER_BLOCK); meta_from_slice(&s->meta[i], mr + i * META_PER_BLOCK);
@@ -347,8 +352,7 @@ static inline void volmeta_to_buf(const blk_volume_meta_t *in, uint8_t *buf) {
static int read_header_4k(blk_dev_slot_t *slot, uint8_t *buf4k) { static int read_header_4k(blk_dev_slot_t *slot, uint8_t *buf4k) {
for (uint32_t i = 0; i < 4; i++) { for (uint32_t i = 0; i < 4; i++) {
if (blkio_read(slot->dev, i, buf4k + i*1024u) != BLKIO_OK) if (blkio_read(slot->dev, i, buf4k + i*1024u) != BLKIO_OK) return BLK_EIO; /* #187 */
memset(buf4k + i*1024u, 0, 1024u);
} }
return BLK_OK; return BLK_OK;
} }
@@ -631,7 +635,13 @@ static int blk_commit_format(blk_dev_slot_t *slot) {
* was left untouched. */ * was left untouched. */
static int blk_format_or_load_disk(blk_dev_slot_t *slot) { static int blk_format_or_load_disk(blk_dev_slot_t *slot) {
uint8_t hdr[BLK_DEVICE_SECTOR] = {0}; uint8_t hdr[BLK_DEVICE_SECTOR] = {0};
(void) read_header_4k(slot, hdr); /* #187 (2026-11-20): a header that cannot be read refuses the attach. It was taken as blank -- a
* formatted disk offered to its owner for a format -- with no message. */
if (read_header_4k(slot, hdr) != BLK_OK) {
log_message(LOG_WARN, "blk: a disk of %u KiB: its header could not be read -- not attached",
(unsigned)slot->total_blkio_blocks_1k);
return BLK_EIO;
}
volmeta_from_buf(&slot->vol_meta, hdr); volmeta_from_buf(&slot->vol_meta, hdr);
if (slot->vol_meta.magic == 0x53544652u && slot->vol_meta.version == 2 && if (slot->vol_meta.magic == 0x53544652u && slot->vol_meta.version == 2 &&
+67 -2
View File
@@ -62,7 +62,14 @@ static unsigned char failing_bytes[FAILING_BLOCKS * 1024u];
static int failing; static int failing;
static int f_open(struct blkio_dev *d, const blkio_params_t *p) { (void)d; (void)p; return BLKIO_OK; } static int f_open(struct blkio_dev *d, const blkio_params_t *p) { (void)d; (void)p; return BLKIO_OK; }
static int f_close(struct blkio_dev *d) { (void)d; return BLKIO_OK; } static int f_close(struct blkio_dev *d) { (void)d; return BLKIO_OK; }
static int f_read(struct blkio_dev *d, uint32_t b, void *dst) { (void)d; memcpy(dst, failing_bytes + (size_t)b * 1024u, 1024); return BLKIO_OK; } static uint32_t fail_read_from, fail_read_to; /* reads of blocks [from, to) fail (#187) */
static int f_read(struct blkio_dev *d, uint32_t b, void *dst)
{
(void)d;
if (b >= fail_read_from && b < fail_read_to) return BLKIO_EIO;
memcpy(dst, failing_bytes + (size_t)b * 1024u, 1024);
return BLKIO_OK;
}
static int f_write(struct blkio_dev *d, uint32_t b, const void *src) static int f_write(struct blkio_dev *d, uint32_t b, const void *src)
{ {
(void)d; (void)d;
@@ -73,6 +80,7 @@ static int f_write(struct blkio_dev *d, uint32_t b, const void *src)
static int f_flush(struct blkio_dev *d) { (void)d; return failing ? BLKIO_EIO : BLKIO_OK; } static int f_flush(struct blkio_dev *d) { (void)d; return failing ? BLKIO_EIO : BLKIO_OK; }
static int f_info(struct blkio_dev *d, blkio_info_t *out) { (void)d; memset(out, 0, sizeof *out); return BLKIO_OK; } static int f_info(struct blkio_dev *d, blkio_info_t *out) { (void)d; memset(out, 0, sizeof *out); return BLKIO_OK; }
static const blkio_vtable_t failing_vt = { f_open, f_close, f_read, f_write, f_flush, f_info }; static const blkio_vtable_t failing_vt = { f_open, f_close, f_read, f_write, f_flush, f_info };
static blkio_dev_t fdev, fdev2; /* the formatted disk, let go and attached again below (#187) */
int main(void) int main(void)
{ {
@@ -189,7 +197,6 @@ int main(void)
/* ---- a write that fails on the device leaves the block as it was ---- */ /* ---- a write that fails on the device leaves the block as it was ---- */
{ {
static blkio_dev_t fdev;
blkio_params_t params; blkio_params_t params;
uint32_t first = 0, n_blocks = 0; uint32_t first = 0, n_blocks = 0;
params.forth_block_size = 0; params.total_blocks = FAILING_BLOCKS; params.opaque = 0; params.forth_block_size = 0; params.total_blocks = FAILING_BLOCKS; params.opaque = 0;
@@ -211,6 +218,64 @@ int main(void)
"nor does it write it later, when the device works again"); "nor does it write it later, when the device works again");
} }
/* ---- a read that fails is not taken as zeros (#187) ---- */
{
blkio_params_t params;
uint32_t first = 0, n_blocks = 0;
params.forth_block_size = 0; params.total_blocks = FAILING_BLOCKS; params.opaque = 0;
(void)tell(V4_REQ_EMPTY_BUFFERS);
CHECK(blk_flush(0) == BLK_OK && blk_subsys_detach_device(&fdev) == BLK_OK, "the formatted disk is let go");
/* its header (device blocks 0 .. 3) cannot be read: the disk is not taken as blank */
fail_read_from = 0; fail_read_to = 4;
CHECK(blkio_open(&fdev2, &failing_vt, &params) == BLKIO_OK && blk_subsys_attach_device(&fdev2) == BLK_EIO
&& blk_get_device_range(&fdev2, &first, &n_blocks) != BLK_OK,
"a disk whose header cannot be read is refused (BLK_EIO), not attached as unformatted");
/* the same disk, read as it is: attached, formatted, its block as written */
fail_read_from = fail_read_to = 0;
CHECK(blk_subsys_attach_device(&fdev2) == BLK_OK && blk_get_device_range(&fdev2, &first, &n_blocks) == BLK_OK
&& ask(V4_REQ_BLOCK, (v4_cell)first + 3) == V4_BLOCK_OK && n.mem[got_addr] == (v4_cell)0x4F4F4F4F,
"the same disk without the fault attaches as before, formatted, its block as written");
/* a block whose data cannot be read is refused, not read as zeros */
(void)tell(V4_REQ_EMPTY_BUFFERS);
{
int f = blk_flush(0), d = blk_subsys_detach_device(&fdev2), /* detaching closes it: opened again */
o = blkio_open(&fdev2, &failing_vt, &params), at = blk_subsys_attach_device(&fdev2),
r = blk_get_device_range(&fdev2, &first, &n_blocks);
CHECK(f == BLK_OK && d == BLK_OK && o == BLKIO_OK && at == BLK_OK && r == BLK_OK,
"attached again, nothing of it in the cache (flush %d, detach %d, open %d, attach %d, range %d)", f, d, o, at, r);
}
fail_read_from = 4; fail_read_to = FAILING_BLOCKS;
CHECK(ask(V4_REQ_BLOCK, (v4_cell)first + 3) != V4_BLOCK_OK,
"with its data unreadable, the block is refused, not given as zeros");
fail_read_from = fail_read_to = 0;
CHECK(ask(V4_REQ_BLOCK, (v4_cell)first + 3) == V4_BLOCK_OK && n.mem[got_addr] == (v4_cell)0x4F4F4F4F,
"and read again once the device works: as written");
}
/* ---- a dirty block is not lost when the write of its eviction fails (#187) ---- */
{
uint32_t first = 0, n_blocks = 0;
blkio_params_t params;
uint8_t *p;
unsigned k, refused = 0;
params.forth_block_size = 0; params.total_blocks = FAILING_BLOCKS; params.opaque = 0;
(void)tell(V4_REQ_EMPTY_BUFFERS);
CHECK(blk_get_device_range(&fdev2, &first, &n_blocks) == BLK_OK && n_blocks > 200, "the disk again, %u blocks", n_blocks);
p = blk_get_buffer(first + 10, 1);
CHECK(p != 0, "a block of it, to change");
if (p) memset(p, 'D', 1024);
failing = 1; /* every write fails: no eviction can write it back */
for (k = 1; k <= 24; k++) if (!blk_get_buffer(first + 10 + k * 8u, 0)) refused++;
CHECK(refused > 0, "with writes failing, blocks that would evict it are refused (%u of 24)", refused);
failing = 0;
CHECK(blk_flush(0) == BLK_OK && blk_subsys_detach_device(&fdev2) == BLK_OK
&& blkio_open(&fdev2, &failing_vt, &params) == BLKIO_OK && blk_subsys_attach_device(&fdev2) == BLK_OK
&& blk_get_device_range(&fdev2, &first, &n_blocks) == BLK_OK,
"the device works again: everything written, the disk let go and attached again");
p = blk_get_buffer(first + 10, 0);
CHECK(p && p[0] == 'D' && p[1023] == 'D', "and the changed block is on the disk, not lost: %c", p ? p[0] : '?');
}
/* ---- what is not a block request ---- */ /* ---- what is not a block request ---- */
v4_dstack_reset(&n.ds); v4_dstack_reset(&n.ds);
v4_dstack_push(&n.ds, 11); v4_dstack_push(&n.ds, 22); v4_dstack_push(&n.ds, 11); v4_dstack_push(&n.ds, 22);