fix(v4.0.0): three defects -- a refused device write, a failed starting state, a case that QUITs

A block write the device refuses after the kernel has taken the node's
copy: the node was told "Storage refused" while the kernel's cache kept
the new data, to be read back and perhaps written later.  The kernel now
puts its own copy back as it was.  Tested with a device whose writes can
be made to fail; it failed first.

POST's runner: a case whose starting state could not be set says so, with
what the node said, where it showed nothing; and a case that ends with
QUIT fails, as it did when the cases were a capsule, where the runner had
taken it for a completed line.  Both tests failed first.

The v4 boot says "Artemis: virtio-blk attached" only when the attach
worked.

make -C v4 test, sanitize and hosted-check pass; amd64, aarch64 and
riscv64 boot, POST 538 of 538, dict_hash 0x5f0a949a6fc8ef2b on all six:
logs/20261007-135741, -140004, -140329.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rajames
2026-10-07 14:05:14 -04:00
co-authored by Claude Opus 5.5
parent bc6deab3f5
commit 193523d873
11 changed files with 585 additions and 13 deletions
+15 -1
View File
@@ -30,12 +30,14 @@ static v4_cell slot_addr(const v4_blocks *w, unsigned s)
* no longer marked. */
static int write_slot(v4_blocks *w, v4_node *n, unsigned s)
{
static uint8_t was[V4_BLOCK_CELLS * 4u]; /* the block as the kernel had it, in case it is refused */
uint8_t *b = blk_get_buffer(w->block[s], 1);
v4_cell at = slot_addr(w, s);
unsigned i;
w->changed[s] = 0;
if (!b) return V4_BLOCK_REFUSED;
for (i = 0; i < V4_BLOCK_CELLS * 4u; i++) was[i] = b[i];
for (i = 0; i < V4_BLOCK_CELLS; i++) {
v4_ucell c = (v4_ucell)n->mem[at + (v4_cell)i];
b[4u * i] = (uint8_t)(c & 0xFFu);
@@ -43,7 +45,19 @@ static int write_slot(v4_blocks *w, v4_node *n, unsigned s)
b[4u * i + 2u] = (uint8_t)((c >> 16) & 0xFFu);
b[4u * i + 3u] = (uint8_t)((c >> 24) & 0xFFu);
}
return (blk_update(w->block[s]) == BLK_OK && blk_flush(w->block[s]) == BLK_OK) ? V4_BLOCK_OK : V4_BLOCK_REFUSED;
if (blk_update(w->block[s]) == BLK_OK && blk_flush(w->block[s]) == BLK_OK) return V4_BLOCK_OK;
/* Storage would not have it. The node is told so, and the kernel does
* not keep what was refused: its own copy is put back as it was, so
* that the block reads as before and what was refused is not written
* later. The buffer is asked for again, since the failed write may
* have moved it. */
b = blk_get_buffer(w->block[s], 1);
if (b) {
for (i = 0; i < V4_BLOCK_CELLS * 4u; i++) b[i] = was[i];
(void)blk_update(w->block[s]);
}
return V4_BLOCK_REFUSED;
}
/* A slot to put a block in: an empty one, or one whose block is not marked,
+10 -4
View File
@@ -44,13 +44,16 @@ int v4_post_run(const v4_post_host *h, const v4_post_case *cases, unsigned count
for (i = 0; i < count; i++) {
const v4_post_case *c = &cases[i];
unsigned kept = 0, total = 0, len = 0, depth;
int errored = 0, came_back = 1, lost = 0, ok, how;
int errored = 0, came_back = 1, lost = 0, no_state = 0, quit = 0, ok, how;
/* every case starts from the same state */
v4_dstack_reset(&h->n->ds);
how = h->line(h->self, state_line, (unsigned)sizeof state_line - 1u, out, 0u, &len);
how = h->line(h->self, state_line, (unsigned)sizeof state_line - 1u, out, V4_POST_OUT, &len);
if (how < 0) lost = 1;
if (how != V4_TEXT_COMPLETED) came_back = 0;
if (how != V4_TEXT_COMPLETED) { /* what the node said of it is what is shown */
came_back = 0; no_state = 1;
total = len; kept = len < V4_POST_OUT ? len : V4_POST_OUT;
}
v4_dstack_reset(&h->n->ds);
for (k = 0; came_back && k < c->line_count; k++) {
@@ -58,6 +61,7 @@ int v4_post_run(const v4_post_host *h, const v4_post_case *cases, unsigned count
how = h->line(h->self, c->lines[k], length(c->lines[k]), out + kept, V4_POST_OUT - kept, &len);
if (how < 0) { came_back = 0; lost = 1; break; }
if (how == V4_TEXT_ERROR) errored = 1;
if (how == V4_TEXT_QUIT) quit = 1; /* it went back to the terminal: it did not complete */
total += len;
kept = total < V4_POST_OUT ? total : V4_POST_OUT;
}
@@ -70,7 +74,7 @@ int v4_post_run(const v4_post_host *h, const v4_post_case *cases, unsigned count
}
v4_dstack_reset(&h->n->ds);
if (!came_back) {
if (!came_back || quit) {
ok = 0;
} else if (c->expect == V4_POST_ERROR) {
ok = errored;
@@ -92,6 +96,8 @@ int v4_post_run(const v4_post_host *h, const v4_post_case *cases, unsigned count
if (ok) { tally->pass++; continue; }
tally->fail++;
say(h, "POST FAIL: "); say(h, c->name);
if (no_state) say(h, " could not be put in its starting state:");
if (quit) say(h, " ended with QUIT:");
say(h, " out<"); h->say(h->self, out, kept < SHOWN_OUT ? kept : SHOWN_OUT);
say(h, "> stack<");
for (k = depth < SHOWN_STACK ? depth : SHOWN_STACK; k-- > 0; ) { say_number(h, (long long)left[k]); say(h, " "); }