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:
@@ -62,7 +62,14 @@ static unsigned char failing_bytes[FAILING_BLOCKS * 1024u];
|
||||
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_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)
|
||||
{
|
||||
(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_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 blkio_dev_t fdev, fdev2; /* the formatted disk, let go and attached again below (#187) */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@@ -189,7 +197,6 @@ int main(void)
|
||||
|
||||
/* ---- a write that fails on the device leaves the block as it was ---- */
|
||||
{
|
||||
static blkio_dev_t fdev;
|
||||
blkio_params_t params;
|
||||
uint32_t first = 0, n_blocks = 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");
|
||||
}
|
||||
|
||||
/* ---- 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, ¶ms) == 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, ¶ms), 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, ¶ms) == 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 ---- */
|
||||
v4_dstack_reset(&n.ds);
|
||||
v4_dstack_push(&n.ds, 11); v4_dstack_push(&n.ds, 22);
|
||||
|
||||
Reference in New Issue
Block a user