From 29ba2517005ccd2bbf4ba746a05d43e53f640dc8 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:05:24 -0800 Subject: [PATCH 01/13] test: local disk full with real binaries (WAL mid-I/O, a new durable root, the host-limit dir) Co-Authored-By: Claude Opus 5.5 --- .../procedure_diskfull_integration_test.go | 272 ++++++++++++++++++ .../cmd/blockvolume/testdata/diskfull.sh | 38 +++ 2 files changed, 310 insertions(+) create mode 100644 seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go create mode 100755 seaweed-block/cmd/blockvolume/testdata/diskfull.sh diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go new file mode 100644 index 0000000000..dc900a925d --- /dev/null +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -0,0 +1,272 @@ +//go:build subprocess && chunkstore_integration + +package main_test + +import ( + "bytes" + "errors" + "fmt" + "os" + "path/filepath" + "strings" + "syscall" + "testing" + "time" +) + +// Local disk full (V1-SPEC r2.55 round 2), with real binaries: blockmaster, a +// real filer (weed, its data elsewhere) and walstore-chunk blockvolumes whose +// durable roots and --host-limit-dir are on small filesystems the harness +// mounts (cmd/blockvolume/testdata/diskfull.sh). A filler file takes the free +// space; deleting it frees it. +// +// 1. The WAL's disk fills under guest I/O: every guest command answers within +// a bound (an error is allowed, a hang is not); after the space is freed +// and the holder restarts, every flush-acknowledged block reads back and +// the next cut moves HEAD and verifies. +// 2. A new volume's durable root is full: blockvolume exits within a bound and +// says why; after the space is freed it starts and serves. +// 3. The --host-limit-dir disk is full: a cut answers within a bound and guest +// I/O keeps working meanwhile; after the space is freed a cut commits. +// +// Environment: SWBLOCK_DISKFULL_ROOT and SWBLOCK_DISKFULL_LIMIT (two mounted +// filesystems, nothing else on them); CHUNKSTORE_WEED; optional +// SWBLOCK_TEST_BINS and SWBLOCK_REPLAY_LOGS (logs are copied there). +const diskFullBound = 30 * time.Second + +func TestProcedureLocalDiskFull(t *testing.T) { + root, limit := os.Getenv("SWBLOCK_DISKFULL_ROOT"), os.Getenv("SWBLOCK_DISKFULL_LIMIT") + if root == "" && limit == "" { + t.Skip("requires the disk-full harness (two small mounted filesystems)") + } + if root == "" || limit == "" { + t.Fatalf("SWBLOCK_DISKFULL_ROOT=%q and SWBLOCK_DISKFULL_LIMIT=%q must be set together", root, limit) + } + env := startHandoffEnvWith(t, 1, []string{"v2"}) + if d := os.Getenv("SWBLOCK_REPLAY_LOGS"); d != "" { + t.Cleanup(func() { copyLogs(t, env.h.dir, d) }) + } + for id, dir := range map[string]string{"s1": "vol", "n-v2": "vol-v2"} { + h := env.hosts[id] + h.root = filepath.Join(root, dir) + env.hosts[id] = h + } + env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} + cut := []string{"ops", "chunk", "cut", "--volume", "v1", "--status-addr", env.hosts["s1"].status} + verify := []string{"ops", "chunk", "verify", "--volume", "v1", "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--depth", "data", "--timeout", "5m"} + headGen := func() uint64 { + out, _ := env.h.command(t, env.chunkShow()...) + hd, err := parseHead(out) + if err != nil { + t.Fatal(err) + } + return hd.Gen + } + cutAdvances := func(what string) { + t.Helper() + g0 := headGen() + env.h.command(t, cut...) + if g := headGen(); g <= g0 { + t.Fatalf("%s: the cut left HEAD at gen %d (was %d)", what, g, g0) + } + if out, errOut, rc := env.h.run(t, verify...); rc != 0 { + t.Fatalf("%s: HEAD does not verify (exit %d):\n%s\n%s", what, rc, out, errOut) + } + } + + holder := env.start(t, "blockvolume-v1", "s1") + e := env.adopt(t, holder, "s1") + env.writeCutCrashImage(t, 'A') + cutAdvances("before the disk fills") + + // 1. The WAL's disk fills under guest I/O. + fill := fillDisk(t, root, 2<<20) + c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) + want := map[uint64][]byte{} + var pending []uint64 + var firstErr error + const maxWrites = 8192 // 32 MiB, far more than the 2 MiB left + for i := 0; i < maxWrites && firstErr == nil; i++ { + lba := uint64(i) + b := cutCrashBlock('W', lba) + if err := diskFullOp(c, func() error { return c.tryWrite(lba, b) }); err != nil { + firstErr = fmt.Errorf("write %d: %w", i, err) + break + } + pending = append(pending, lba) + if (i+1)%8 == 0 { + if err := diskFullOp(c, c.tryFlush); err != nil { + firstErr = fmt.Errorf("flush after write %d: %w", i, err) + break + } + for _, l := range pending { + want[l] = cutCrashBlock('W', l) + } + pending = pending[:0] + } + } + if errors.Is(firstErr, errDiskFullHang) { + t.Fatalf("case 1: a guest command did not answer within %s on a full disk: %v", diskFullBound, firstErr) + } + // INV-FE-ERROR-RETRY-CLASS-001: ENOSPC is a permanent cause, so NVMe + // Generic/Internal Error with DNR (0x800c); a WAL pressure timeout is the + // documented retryable Namespace Not Ready, DNR=0 (0x0104). Anything else + // (a generic transport error, another code) is not the documented answer. + if firstErr != nil && !strings.Contains(firstErr.Error(), "status 0x800c") && !strings.Contains(firstErr.Error(), "status 0x0104") { + t.Fatalf("case 1: the guest saw %v, not a documented completion for a full disk", firstErr) + } + t.Logf("case 1: %d flush-acknowledged writes, %d unflushed; first error: %v; frontend ready: %v", + len(want), len(pending), firstErr, env.frontendReadyAt("s1")) + c.close() + fill.free(t) + holder.kill(t) + holder = env.start(t, "blockvolume-v1-after-full-wal", "s1") + if got := env.adopt(t, holder, "s1"); got != e { + t.Fatalf("case 1: the restarted holder adopted epoch %d; want %d", got, e) + } + func() { + c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) + defer c.close() + for ch := 0; ch < cutCrashChunks; ch++ { + for i := 0; i < cutCrashPer; i++ { + lba := uint64(ch*ladderChunkBlocks + i) + got := c.read(t, lba, 4096) + if w, ok := want[lba]; ok { + if !bytes.Equal(got, w) { + t.Fatalf("case 1: flush-acknowledged LBA %d lost after the disk filled", lba) + } + } else if !bytes.Equal(got, cutCrashBlock('A', lba)) && !bytes.Equal(got, cutCrashBlock('W', lba)) { + t.Fatalf("case 1: LBA %d reads neither image A nor its unflushed write", lba) + } + } + } + }() + cutAdvances("case 1, after the space is freed") + + // 2. A new volume's durable root is full. + fill = fillDisk(t, root, 0) + v2 := env.start(t, "blockvolume-v2-full", "n-v2") + err := v2.wait(diskFullBound) + if err == nil || strings.Contains(err.Error(), "still running") { + t.Fatalf("case 2: blockvolume on a full durable root: %v (want an exit with a reason within %s)", err, diskFullBound) + } + if !v2.has("no space left on device") { + t.Fatalf("case 2: blockvolume exited (%v) without naming the full disk; log %s", err, v2.log) + } + fill.free(t) + v2 = env.start(t, "blockvolume-v2", "n-v2") + v2.waitLog(t, 60*time.Second, "blockvolume: volume v2 adopted as PRIMARY at r1@") + t.Logf("case 2: exited on the full root (%v), then started and adopted v2", err) + + // 3. The --host-limit-dir disk is full. + holder.term(t, 30*time.Second) + slots := filepath.Join(limit, "slots") + if err := os.Mkdir(slots, 0o700); err != nil { + t.Fatal(err) + } + fill = fillDisk(t, limit, 0) + env.volExtra = append(env.volExtra, "--host-limit-dir", slots) + holder = env.start(t, "blockvolume-v1-full-limit-dir", "s1") + if got := env.adopt(t, holder, "s1"); got != e { + t.Fatalf("case 3: the holder adopted epoch %d; want %d", got, e) + } + env.writeCutCrashImage(t, 'B') + type cutResult struct { + out string + rc int + } + done := make(chan cutResult, 1) + g0 := headGen() + go func() { + out, errOut, rc := env.h.run(t, cut...) + done <- cutResult{out + errOut, rc} + }() + func() { + c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) + defer c.close() + lba := uint64(cutCrashChunks * ladderChunkBlocks) + if err := diskFullOp(c, func() error { return c.tryWrite(lba, cutCrashBlock('L', lba)) }); err != nil { + t.Fatalf("case 3: guest write with the host-limit dir full: %v", err) + } + if err := diskFullOp(c, c.tryFlush); err != nil { + t.Fatalf("case 3: guest flush with the host-limit dir full: %v", err) + } + }() + var r cutResult + select { + case r = <-done: + case <-time.After(2 * time.Minute): + t.Fatalf("case 3: a cut with the host-limit dir full did not answer within 2m") + } + // The docs name no outcome for a full --host-limit-dir (the launch check, + // INV-HOST-LAUNCH-CHECK-001, only reads it). A definite answer either way + // is accepted: a refusal naming the full disk, or a commit that moved HEAD. + switch g := headGen(); { + case r.rc != 0 && !strings.Contains(r.out, "no space left on device"): + t.Fatalf("case 3: the cut failed (exit %d) without naming the full disk:\n%s", r.rc, r.out) + case r.rc == 0 && g <= g0: + t.Fatalf("case 3: the cut exited 0 but HEAD stayed at gen %d", g) + } + t.Logf("case 3: cut with the host-limit dir full exited %d; guest write+flush succeeded meanwhile", r.rc) + fill.free(t) + cutAdvances("case 3, after the space is freed") + env.requireCutCrashImage(t, "s1", 'B') + fmt.Println("DISKFULL_OK") +} + +var errDiskFullHang = errors.New("no answer within the bound") + +// diskFullOp runs op with a deadline on the I/O queue; a timeout is a hang. +func diskFullOp(c *nvmeInitiator, op func() error) error { + _ = c.io.SetDeadline(time.Now().Add(diskFullBound)) + err := op() + var ne interface{ Timeout() bool } + if errors.As(err, &ne) && ne.Timeout() { + return fmt.Errorf("%w: %v", errDiskFullHang, err) + } + return err +} + +type diskFiller struct{ path string } + +// fillDisk writes a filler file on dir's filesystem until it is full, then +// shrinks it to leave about keep bytes free. +func fillDisk(t *testing.T, dir string, keep int64) diskFiller { + t.Helper() + path := filepath.Join(dir, fmt.Sprintf("filler-%d", time.Now().UnixNano())) + f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o600) + if err != nil { + t.Fatal(err) + } + buf := make([]byte, 1<<20) + var n int64 + for { + w, err := f.Write(buf) + n += int64(w) + if err != nil { + if !errors.Is(err, syscall.ENOSPC) { + t.Fatalf("filler: %v", err) + } + break + } + } + if keep > 0 { + if err := f.Truncate(max(n-keep, 0)); err != nil { + t.Fatal(err) + } + } + if err := f.Close(); err != nil && !errors.Is(err, syscall.ENOSPC) { + t.Fatal(err) + } + var st syscall.Statfs_t + _ = syscall.Statfs(dir, &st) + t.Logf("filled %s: filler %d MiB, %d KiB free", dir, n>>20, int64(st.Bavail)*int64(st.Bsize)>>10) + return diskFiller{path: path} +} + +func (d diskFiller) free(t *testing.T) { + t.Helper() + if err := os.Remove(d.path); err != nil { + t.Fatal(err) + } +} diff --git a/seaweed-block/cmd/blockvolume/testdata/diskfull.sh b/seaweed-block/cmd/blockvolume/testdata/diskfull.sh new file mode 100755 index 0000000000..fe98c8a2a9 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/testdata/diskfull.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Disk-full harness for TestProcedureLocalDiskFull. Root only; it formats only +# loop devices over private sparse files under WORKDIR and always tears them +# down, also when the test fails or is killed. +# +# diskfull.sh WORKDIR -- TEST_COMMAND... +# +# The test runs with SWBLOCK_DISKFULL_ROOT (128 MiB ext4, for durable roots), +# SWBLOCK_DISKFULL_LIMIT (8 MiB ext4, for --host-limit-dir) and +# SWBLOCK_REPLAY_LOGS. No reserved blocks (-m 0): the test runs as root. +set -euo pipefail +[ "$(id -u)" = 0 ] || { echo "root required" >&2; exit 2; } +work=$(realpath "${1:?existing empty work dir}") +[ "${2:-}" = -- ] || { echo "usage: $0 WORKDIR -- TEST_COMMAND..." >&2; exit 2; } +shift 2 +for c in losetup mkfs.ext4 mount umount mountpoint truncate; do command -v "$c" >/dev/null; done +mkdir "$work/root" "$work/limit" "$work/logs" +loops=() +cleanup() { + set +e + for m in "$work/root" "$work/limit"; do mountpoint -q "$m" && umount "$m"; done + for l in "${loops[@]}"; do losetup -d "$l"; done + # Only the sparse images this script created under WORKDIR. + rm -f -- "$work/root.img" "$work/limit.img" +} +trap cleanup EXIT +for fs in root:128M limit:8M; do + name=${fs%%:*} + truncate -s "${fs#*:}" "$work/$name.img" + dev=$(losetup --find --show "$work/$name.img"); loops+=("$dev") + mkfs.ext4 -q -F -m 0 "$dev" + mount "$dev" "$work/$name" +done +set +e +SWBLOCK_DISKFULL_ROOT=$work/root SWBLOCK_DISKFULL_LIMIT=$work/limit SWBLOCK_REPLAY_LOGS=$work/logs "$@" +rc=$? +set -e +exit $rc From 9627030aeac47a68ba96b25196c4793adf9489da Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:09:11 -0800 Subject: [PATCH 02/13] test: disk full: documented error class (0x0104 only without ENOSPC), reads while full, restart while full, limiter fails open and detach --plain seals, 20 s bound Co-Authored-By: Claude Opus 5.5 --- .../procedure_diskfull_integration_test.go | 186 +++++++++++++----- 1 file changed, 142 insertions(+), 44 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index dc900a925d..b6f9d37dac 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -21,18 +21,29 @@ import ( // space; deleting it frees it. // // 1. The WAL's disk fills under guest I/O: every guest command answers within -// a bound (an error is allowed, a hang is not); after the space is freed -// and the holder restarts, every flush-acknowledged block reads back and -// the next cut moves HEAD and verifies. -// 2. A new volume's durable root is full: blockvolume exits within a bound and -// says why; after the space is freed it starts and serves. -// 3. The --host-limit-dir disk is full: a cut answers within a bound and guest -// I/O keeps working meanwhile; after the space is freed a cut commits. +// the bound; the first error is the documented permanent one (0x800c), or +// 0x0104 only without ENOSPC behind it; image A stays readable; the test +// logs whether writes resume once the space is freed without a restart. +// 1b. The holder restarts with the disk still full: it serves reads or +// exits naming the full disk. After the space is freed and a restart, +// every flush-acknowledged block reads back and the next cut moves HEAD +// and verifies. +// 2. A new volume's durable root is full: blockvolume exits and says why; +// after the space is freed it starts and serves. +// 3. The --host-limit-dir disk is full: the limiter fails open (the cut +// commits) and detach --plain still seals; guest I/O works meanwhile. +// +// A FINDING (a wrong error class, a limiter that does not fail open) fails +// the test with t.Errorf and the run continues to the end. // // Environment: SWBLOCK_DISKFULL_ROOT and SWBLOCK_DISKFULL_LIMIT (two mounted // filesystems, nothing else on them); CHUNKSTORE_WEED; optional // SWBLOCK_TEST_BINS and SWBLOCK_REPLAY_LOGS (logs are copied there). -const diskFullBound = 30 * time.Second +// +// diskFullBound stays below the Linux NVMe host default I/O timeout (30 s) +// with margin: an answer at 29 s would still make a real guest reset the +// controller. +const diskFullBound = 20 * time.Second func TestProcedureLocalDiskFull(t *testing.T) { root, limit := os.Getenv("SWBLOCK_DISKFULL_ROOT"), os.Getenv("SWBLOCK_DISKFULL_LIMIT") @@ -79,45 +90,114 @@ func TestProcedureLocalDiskFull(t *testing.T) { env.writeCutCrashImage(t, 'A') cutAdvances("before the disk fills") - // 1. The WAL's disk fills under guest I/O. + // 1. The WAL's disk fills under guest I/O. LBAs 0.. are written in order + // (chunks 0-7 at most); image A in chunks 40-47 is never overwritten here. fill := fillDisk(t, root, 2<<20) c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) want := map[uint64][]byte{} var pending []uint64 - var firstErr error - const maxWrites = 8192 // 32 MiB, far more than the 2 MiB left - for i := 0; i < maxWrites && firstErr == nil; i++ { - lba := uint64(i) - b := cutCrashBlock('W', lba) - if err := diskFullOp(c, func() error { return c.tryWrite(lba, b) }); err != nil { - firstErr = fmt.Errorf("write %d: %w", i, err) - break - } - pending = append(pending, lba) - if (i+1)%8 == 0 { - if err := diskFullOp(c, c.tryFlush); err != nil { - firstErr = fmt.Errorf("flush after write %d: %w", i, err) - break + next := 0 + writeUntilError := func(n int) error { + for end := next + n; next < end; next++ { + lba := uint64(next) + b := cutCrashBlock('W', lba) + if err := diskFullOp(c, func() error { return c.tryWrite(lba, b) }); err != nil { + return fmt.Errorf("write %d: %w", next, err) } - for _, l := range pending { - want[l] = cutCrashBlock('W', l) + pending = append(pending, lba) + if (next+1)%8 == 0 { + if err := diskFullOp(c, c.tryFlush); err != nil { + return fmt.Errorf("flush after write %d: %w", next, err) + } + for _, l := range pending { + want[l] = cutCrashBlock('W', l) + } + pending = pending[:0] } - pending = pending[:0] } + return nil } + firstErr := writeUntilError(8192) // 32 MiB, far more than the 2 MiB left if errors.Is(firstErr, errDiskFullHang) { t.Fatalf("case 1: a guest command did not answer within %s on a full disk: %v", diskFullBound, firstErr) } // INV-FE-ERROR-RETRY-CLASS-001: ENOSPC is a permanent cause, so NVMe - // Generic/Internal Error with DNR (0x800c); a WAL pressure timeout is the - // documented retryable Namespace Not Ready, DNR=0 (0x0104). Anything else - // (a generic transport error, another code) is not the documented answer. - if firstErr != nil && !strings.Contains(firstErr.Error(), "status 0x800c") && !strings.Contains(firstErr.Error(), "status 0x0104") { + // Generic/Internal Error with DNR (0x800c). Namespace Not Ready, DNR=0 + // (0x0104) is right only for WAL pressure a cut relieves; with ENOSPC + // behind it a guest would retry for ever: a wrong class, reported. + switch { + case firstErr == nil: + t.Logf("case 1: no error in %d writes with 2 MiB free", next) + case strings.Contains(firstErr.Error(), "status 0x800c"): + case strings.Contains(firstErr.Error(), "status 0x0104"): + if holder.has("no space left on device") { + t.Errorf("FINDING case 1: the guest saw retryable 0x0104 (%v) while the holder logs ENOSPC: a permanent cause surfaced as retryable", firstErr) + } + default: t.Fatalf("case 1: the guest saw %v, not a documented completion for a full disk", firstErr) } t.Logf("case 1: %d flush-acknowledged writes, %d unflushed; first error: %v; frontend ready: %v", len(want), len(pending), firstErr, env.frontendReadyAt("s1")) + // A full disk never makes existing data unreadable. + readImageA := func(what string, c *nvmeInitiator) { + t.Helper() + for ch := 40; ch < cutCrashChunks; ch++ { + for i := 0; i < cutCrashPer; i += 16 { + lba := uint64(ch*ladderChunkBlocks + i) + var got []byte + err := diskFullOp(c, func() (err error) { got, err = c.tryRead(lba, 4096); return err }) + if err != nil || !bytes.Equal(got, cutCrashBlock('A', lba)) { + t.Fatalf("%s: image A at LBA %d is not readable on a full disk: %v", what, lba, err) + } + } + } + } + readImageA("case 1, after the first write error", c) + // Without a restart: do writes resume once the space is freed? + fill.free(t) + if err := writeUntilError(16); err != nil { + t.Logf("case 1: after freeing the space, without a restart, writes still fail (latched until restart): %v", err) + } else { + t.Logf("case 1: after freeing the space, without a restart, writes and flushes resume") + } c.close() + + // 1b. Restart while the disk is still full: serve (reads at least) or exit + // within the bound naming the full disk; never damage acknowledged data. + fill = fillDisk(t, root, 0) + holder.kill(t) + holder = env.start(t, "blockvolume-v1-restart-full", "s1") + served := false + for end := time.Now().Add(60 * time.Second); ; time.Sleep(500 * time.Millisecond) { + if holder.has("blockvolume: volume v1 adopted as PRIMARY at r1@") { + served = true + break + } + exited := false + select { + case <-holder.done: + exited = true + default: + } + if exited { + if !holder.has("no space left on device") { + t.Fatalf("case 1b: the holder exited on a full disk without naming it (%v); log %s", holder.err, holder.log) + } + break + } + if time.Now().After(end) { + t.Fatalf("case 1b: the holder neither served nor exited within 60s on a full disk") + } + } + if served { + env.h.waitPrimaryAt(t, env.hosts["s1"].status, e) + c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) + readImageA("case 1b, restarted on a full disk", c) + c.close() + t.Logf("case 1b: restarted on a full disk and serves reads") + } else { + t.Logf("case 1b: restart on a full disk exited naming the full disk") + } fill.free(t) holder.kill(t) holder = env.start(t, "blockvolume-v1-after-full-wal", "s1") @@ -140,15 +220,20 @@ func TestProcedureLocalDiskFull(t *testing.T) { } } } + for lba, w := range want { + if !bytes.Equal(c.read(t, lba, 4096), w) { + t.Fatalf("case 1: flush-acknowledged LBA %d lost after the disk filled", lba) + } + } }() cutAdvances("case 1, after the space is freed") // 2. A new volume's durable root is full. fill = fillDisk(t, root, 0) v2 := env.start(t, "blockvolume-v2-full", "n-v2") - err := v2.wait(diskFullBound) + err := v2.wait(60 * time.Second) if err == nil || strings.Contains(err.Error(), "still running") { - t.Fatalf("case 2: blockvolume on a full durable root: %v (want an exit with a reason within %s)", err, diskFullBound) + t.Fatalf("case 2: blockvolume on a full durable root: %v (want an exit with a reason within 60s)", err) } if !v2.has("no space left on device") { t.Fatalf("case 2: blockvolume exited (%v) without naming the full disk; log %s", err, v2.log) @@ -199,27 +284,40 @@ func TestProcedureLocalDiskFull(t *testing.T) { t.Fatalf("case 3: a cut with the host-limit dir full did not answer within 2m") } // The docs name no outcome for a full --host-limit-dir (the launch check, - // INV-HOST-LAUNCH-CHECK-001, only reads it). A definite answer either way - // is accepted: a refusal naming the full disk, or a commit that moved HEAD. - switch g := headGen(); { - case r.rc != 0 && !strings.Contains(r.out, "no space left on device"): - t.Fatalf("case 3: the cut failed (exit %d) without naming the full disk:\n%s", r.rc, r.out) - case r.rc == 0 && g <= g0: - t.Fatalf("case 3: the cut exited 0 but HEAD stayed at gen %d", g) + // INV-HOST-LAUNCH-CHECK-001, only reads it). The position for the ruling: + // the limiter paces background cuts and must fail open, so the cut + // commits; a refusal is reported for a ruling, not accepted. + if g := headGen(); r.rc != 0 || g <= g0 { + t.Errorf("FINDING case 3: with the host-limit dir full the cut exited %d and HEAD is at gen %d (was %d); the limiter did not fail open:\n%s", r.rc, g, g0, r.out) } t.Logf("case 3: cut with the host-limit dir full exited %d; guest write+flush succeeded meanwhile", r.rc) + // The seal of a planned hand-over must not depend on the limit directory. + out, errOut, rc := env.h.run(t, "ops", "chunk", "detach", "--plain", "--volume", "v1", "--status-addr", env.hosts["s1"].status, "--timeout", "120s") + if rc != 0 { + t.Errorf("FINDING case 3: detach --plain with the host-limit dir full exited %d:\n%s\n%s", rc, out, errOut) + } else { + t.Logf("case 3: detach --plain with the host-limit dir full sealed the volume") + } fill.free(t) - cutAdvances("case 3, after the space is freed") - env.requireCutCrashImage(t, "s1", 'B') - fmt.Println("DISKFULL_OK") + t.Logf("slowest guest command answer: %s (bound %s)", diskFullSlowest, diskFullBound) + if !t.Failed() { + fmt.Println("DISKFULL_OK") + } } -var errDiskFullHang = errors.New("no answer within the bound") +var ( + errDiskFullHang = errors.New("no answer within the bound") + diskFullSlowest time.Duration +) // diskFullOp runs op with a deadline on the I/O queue; a timeout is a hang. func diskFullOp(c *nvmeInitiator, op func() error) error { - _ = c.io.SetDeadline(time.Now().Add(diskFullBound)) + start := time.Now() + _ = c.io.SetDeadline(start.Add(diskFullBound)) err := op() + if d := time.Since(start); d > diskFullSlowest { + diskFullSlowest = d + } var ne interface{ Timeout() bool } if errors.As(err, &ne) && ne.Timeout() { return fmt.Errorf("%w: %v", errDiskFullHang, err) From bff08486b77b660f17b9001e21c83297bde0193a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:35:51 -0800 Subject: [PATCH 03/13] test: disk full: write past the preallocated WAL; stop v1 before the new-volume case Co-Authored-By: Claude Opus 5.5 --- .../procedure_diskfull_integration_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index b6f9d37dac..de07550248 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -91,7 +91,7 @@ func TestProcedureLocalDiskFull(t *testing.T) { cutAdvances("before the disk fills") // 1. The WAL's disk fills under guest I/O. LBAs 0.. are written in order - // (chunks 0-7 at most); image A in chunks 40-47 is never overwritten here. + // (chunks 0-31 at most); image A in chunks 40-47 is never overwritten here. fill := fillDisk(t, root, 2<<20) c := dialNVMe(t, env.hosts["s1"].nvme, plannedHandoffNQN) want := map[uint64][]byte{} @@ -117,7 +117,9 @@ func TestProcedureLocalDiskFull(t *testing.T) { } return nil } - firstErr := writeUntilError(8192) // 32 MiB, far more than the 2 MiB left + // 128 MiB: more than the 2 MiB left and more than the preallocated WAL, so + // the WAL fills too when the flusher cannot write extents. + firstErr := writeUntilError(32768) if errors.Is(firstErr, errDiskFullHang) { t.Fatalf("case 1: a guest command did not answer within %s on a full disk: %v", diskFullBound, firstErr) } @@ -228,7 +230,9 @@ func TestProcedureLocalDiskFull(t *testing.T) { }() cutAdvances("case 1, after the space is freed") - // 2. A new volume's durable root is full. + // 2. A new volume's durable root is full. v1 stops first: its flusher + // would take any space freed on the shared disk. + holder.term(t, 30*time.Second) fill = fillDisk(t, root, 0) v2 := env.start(t, "blockvolume-v2-full", "n-v2") err := v2.wait(60 * time.Second) @@ -244,7 +248,6 @@ func TestProcedureLocalDiskFull(t *testing.T) { t.Logf("case 2: exited on the full root (%v), then started and adopted v2", err) // 3. The --host-limit-dir disk is full. - holder.term(t, 30*time.Second) slots := filepath.Join(limit, "slots") if err := os.Mkdir(slots, 0o700); err != nil { t.Fatal(err) From 9465248b78f62175d0eb16a0f45e77c49d3b613a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:37:42 -0800 Subject: [PATCH 04/13] test: disk-full harness: 512 MiB root, room for the volume's own data once the filler is gone Co-Authored-By: Claude Opus 5.5 --- seaweed-block/cmd/blockvolume/testdata/diskfull.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/testdata/diskfull.sh b/seaweed-block/cmd/blockvolume/testdata/diskfull.sh index fe98c8a2a9..cdf3a06e3f 100755 --- a/seaweed-block/cmd/blockvolume/testdata/diskfull.sh +++ b/seaweed-block/cmd/blockvolume/testdata/diskfull.sh @@ -5,7 +5,7 @@ # # diskfull.sh WORKDIR -- TEST_COMMAND... # -# The test runs with SWBLOCK_DISKFULL_ROOT (128 MiB ext4, for durable roots), +# The test runs with SWBLOCK_DISKFULL_ROOT (512 MiB ext4, for durable roots), # SWBLOCK_DISKFULL_LIMIT (8 MiB ext4, for --host-limit-dir) and # SWBLOCK_REPLAY_LOGS. No reserved blocks (-m 0): the test runs as root. set -euo pipefail @@ -24,7 +24,7 @@ cleanup() { rm -f -- "$work/root.img" "$work/limit.img" } trap cleanup EXIT -for fs in root:128M limit:8M; do +for fs in root:512M limit:8M; do name=${fs%%:*} truncate -s "${fs#*:}" "$work/$name.img" dev=$(losetup --find --show "$work/$name.img"); loops+=("$dev") From 141d21c355c3d03d857a088ce0b7a7b211c67c1d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:40:51 -0800 Subject: [PATCH 05/13] test: disk full, new volume: a faulted-and-up answer naming ENOSPC is accepted; the next start works over the partial create Co-Authored-By: Claude Opus 5.5 --- .../procedure_diskfull_integration_test.go | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index de07550248..db0ac3affd 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -234,18 +234,36 @@ func TestProcedureLocalDiskFull(t *testing.T) { // would take any space freed on the shared disk. holder.term(t, 30*time.Second) fill = fillDisk(t, root, 0) + // Either answer names the full disk within the bound: an exit, or the + // process stays up with its durable recovery faulted (status stays + // available, readiness blocked) and never serves. v2 := env.start(t, "blockvolume-v2-full", "n-v2") - err := v2.wait(60 * time.Second) - if err == nil || strings.Contains(err.Error(), "still running") { - t.Fatalf("case 2: blockvolume on a full durable root: %v (want an exit with a reason within 60s)", err) + outcome := "" + for end := time.Now().Add(60 * time.Second); outcome == ""; time.Sleep(500 * time.Millisecond) { + select { + case <-v2.done: + outcome = fmt.Sprintf("exited (%v)", v2.err) + default: + } + switch { + case outcome != "": + case v2.has("durable recovery faulted"): + outcome = "stayed up with durable recovery faulted" + case v2.has("adopted as PRIMARY"): + t.Fatalf("case 2: v2 adopted as primary on a full durable root") + case time.Now().After(end): + t.Fatalf("case 2: blockvolume on a full durable root neither exited nor faulted within 60s; log %s", v2.log) + } } if !v2.has("no space left on device") { - t.Fatalf("case 2: blockvolume exited (%v) without naming the full disk; log %s", err, v2.log) + t.Fatalf("case 2: blockvolume %s without naming the full disk; log %s", outcome, v2.log) } + v2.kill(t) fill.free(t) + // What the failed create left behind must not stop the next start. v2 = env.start(t, "blockvolume-v2", "n-v2") v2.waitLog(t, 60*time.Second, "blockvolume: volume v2 adopted as PRIMARY at r1@") - t.Logf("case 2: exited on the full root (%v), then started and adopted v2", err) + t.Logf("case 2: on the full root blockvolume %s naming ENOSPC; after freeing, it started over the partial create and adopted v2", outcome) // 3. The --host-limit-dir disk is full. slots := filepath.Join(limit, "slots") From 2de49cf295dd93d31ab707df80615581ea8fb858 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:43:43 -0800 Subject: [PATCH 06/13] test: disk-full filler ends with 4 KiB writes so no small file fits Co-Authored-By: Claude Opus 5.5 --- .../procedure_diskfull_integration_test.go | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index db0ac3affd..415faac4a2 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -357,18 +357,24 @@ func fillDisk(t *testing.T, dir string, keep int64) diskFiller { if err != nil { t.Fatal(err) } - buf := make([]byte, 1<<20) var n int64 - for { - w, err := f.Write(buf) - n += int64(w) - if err != nil { - if !errors.Is(err, syscall.ENOSPC) { - t.Fatalf("filler: %v", err) + // 1 MiB writes, then 4 KiB ones, so not even a small file still fits. + for _, size := range []int{1 << 20, 4096} { + buf := make([]byte, size) + for { + w, err := f.Write(buf) + n += int64(w) + if err != nil { + if !errors.Is(err, syscall.ENOSPC) { + t.Fatalf("filler: %v", err) + } + break } - break } } + if err := f.Sync(); err != nil && !errors.Is(err, syscall.ENOSPC) { + t.Fatalf("filler sync: %v", err) + } if keep > 0 { if err := f.Truncate(max(n-keep, 0)); err != nil { t.Fatal(err) From 4f3fcb36e8fb1864fb5588ad93ba23fe2e9d81ee Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:49:49 -0800 Subject: [PATCH 07/13] test: disk full: each filed defect (#484 #485 #486) is a known-finding row, strict once removed from the list Co-Authored-By: Claude Opus 5.5 --- .../procedure_diskfull_integration_test.go | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index 415faac4a2..4162d7559e 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -33,8 +33,10 @@ import ( // 3. The --host-limit-dir disk is full: the limiter fails open (the cut // commits) and detach --plain still seals; guest I/O works meanwhile. // -// A FINDING (a wrong error class, a limiter that does not fail open) fails -// the test with t.Errorf and the run continues to the end. +// Each filed defect is a known-finding row (diskFullFinding): while it +// reproduces the row logs KNOWN FINDING #n and passes; once fixed it logs +// FIXED #n; removing the issue from knownDiskFullFindings makes the row a +// strict assertion. A defect not in the list fails the test. // // Environment: SWBLOCK_DISKFULL_ROOT and SWBLOCK_DISKFULL_LIMIT (two mounted // filesystems, nothing else on them); CHUNKSTORE_WEED; optional @@ -131,9 +133,12 @@ func TestProcedureLocalDiskFull(t *testing.T) { case firstErr == nil: t.Logf("case 1: no error in %d writes with 2 MiB free", next) case strings.Contains(firstErr.Error(), "status 0x800c"): + diskFullFinding(t, 484, false, "case 1: the guest saw the permanent 0x800c for ENOSPC") case strings.Contains(firstErr.Error(), "status 0x0104"): if holder.has("no space left on device") { - t.Errorf("FINDING case 1: the guest saw retryable 0x0104 (%v) while the holder logs ENOSPC: a permanent cause surfaced as retryable", firstErr) + diskFullFinding(t, 484, true, "case 1: the guest saw retryable 0x0104 (%v) while the holder logs ENOSPC: a permanent cause surfaced as retryable", firstErr) + } else { + diskFullFinding(t, 484, false, "case 1: 0x0104 with no ENOSPC behind it") } default: t.Fatalf("case 1: the guest saw %v, not a documented completion for a full disk", firstErr) @@ -308,17 +313,12 @@ func TestProcedureLocalDiskFull(t *testing.T) { // INV-HOST-LAUNCH-CHECK-001, only reads it). The position for the ruling: // the limiter paces background cuts and must fail open, so the cut // commits; a refusal is reported for a ruling, not accepted. - if g := headGen(); r.rc != 0 || g <= g0 { - t.Errorf("FINDING case 3: with the host-limit dir full the cut exited %d and HEAD is at gen %d (was %d); the limiter did not fail open:\n%s", r.rc, g, g0, r.out) - } + g := headGen() + diskFullFinding(t, 485, r.rc != 0 || g <= g0, "case 3: with the host-limit dir full the cut exited %d and HEAD is at gen %d (was %d); the limiter did not fail open:\n%s", r.rc, g, g0, r.out) t.Logf("case 3: cut with the host-limit dir full exited %d; guest write+flush succeeded meanwhile", r.rc) // The seal of a planned hand-over must not depend on the limit directory. out, errOut, rc := env.h.run(t, "ops", "chunk", "detach", "--plain", "--volume", "v1", "--status-addr", env.hosts["s1"].status, "--timeout", "120s") - if rc != 0 { - t.Errorf("FINDING case 3: detach --plain with the host-limit dir full exited %d:\n%s\n%s", rc, out, errOut) - } else { - t.Logf("case 3: detach --plain with the host-limit dir full sealed the volume") - } + diskFullFinding(t, 486, rc != 0, "case 3: detach --plain with the host-limit dir full exited %d:\n%s\n%s", rc, out, errOut) fill.free(t) t.Logf("slowest guest command answer: %s (bound %s)", diskFullSlowest, diskFullBound) if !t.Failed() { @@ -326,6 +326,24 @@ func TestProcedureLocalDiskFull(t *testing.T) { } } +// knownDiskFullFindings are the filed defects this test still expects. +var knownDiskFullFindings = map[int]bool{484: true, 485: true, 486: true} + +// diskFullFinding is one defect row: bad reports whether issue's defect +// reproduced in this run. +func diskFullFinding(t *testing.T, issue int, bad bool, format string, args ...any) { + t.Helper() + msg := fmt.Sprintf(format, args...) + switch { + case bad && knownDiskFullFindings[issue]: + t.Logf("KNOWN FINDING #%d: %s", issue, msg) + case bad: + t.Errorf("FINDING #%d: %s", issue, msg) + case knownDiskFullFindings[issue]: + t.Logf("FIXED #%d: no longer reproduces; remove it from knownDiskFullFindings so this row is strict", issue) + } +} + var ( errDiskFullHang = errors.New("no answer within the bound") diskFullSlowest time.Duration From ddab2fa650d11af0e0600f68d1841f4fbb61a61c Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 00:56:12 -0800 Subject: [PATCH 08/13] test: disk full seen by the Linux kernel NVMe/TCP initiator (records dd, dmesg, behaviour after freeing) Co-Authored-By: Claude Opus 5.5 --- ...cedure_diskfull_kernel_integration_test.go | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go new file mode 100644 index 0000000000..5d01321f3c --- /dev/null +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go @@ -0,0 +1,142 @@ +//go:build subprocess && chunkstore_integration && linux + +package main_test + +import ( + "context" + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + "time" +) + +// What a real Linux guest sees when the local disk under a volume's WAL fills +// (V1-SPEC r2.60, issue 484): the kernel NVMe/TCP initiator connects to the +// volume's own target on this host, the durable root's disk fills, and dd +// writes with O_DIRECT. The test records, for the operator guide, whether dd +// stalls or fails and with what, what the kernel logs, and what happens once +// the space is freed. It records; it asserts only that the kernel connects +// and the namespace appears (data survival is TestProcedureLocalDiskFull's). +// +// Environment: as TestProcedureLocalDiskFull, plus SWBLOCK_DISKFULL_KERNEL=1 +// (root, the nvme-tcp module, a disposable host). +func TestProcedureLocalDiskFullKernelInitiator(t *testing.T) { + if os.Getenv("SWBLOCK_DISKFULL_KERNEL") != "1" { + t.Skip("requires SWBLOCK_DISKFULL_KERNEL=1 on a disposable root host") + } + root := os.Getenv("SWBLOCK_DISKFULL_ROOT") + if root == "" { + t.Fatal("SWBLOCK_DISKFULL_ROOT must be set") + } + env := startHandoffEnvWith(t, 1, nil) + if d := os.Getenv("SWBLOCK_REPLAY_LOGS"); d != "" { + t.Cleanup(func() { copyLogs(t, env.h.dir, d) }) + } + h := env.hosts["s1"] + h.root = filepath.Join(root, "vol") + env.hosts["s1"] = h + env.volExtra = []string{"--chunk-capture-interval", "0", "--chunk-snapshot-schedule", "off"} + holder := env.start(t, "blockvolume-v1", "s1") + env.adopt(t, holder, "s1") + + sh := func(cmd string) string { + out, err := exec.Command("bash", "-c", cmd).CombinedOutput() + if err != nil { + t.Logf("KERNEL: %q: %v", cmd, err) + } + return strings.TrimSpace(string(out)) + } + if out := sh("modprobe nvme-tcp && grep -c . /dev/nvme-fabrics >/dev/null; echo ok"); !strings.HasSuffix(out, "ok") { + t.Fatalf("nvme-tcp: %s", out) + } + sh("dmesg -C") + // The namespace device is the one /sys/block entry the connect adds (a + // multipath head nvmeXnY or a plain one; per-path nvmeXcYnZ is hidden). + blocks := func() map[string]bool { + m := map[string]bool{} + ns, _ := filepath.Glob("/sys/block/nvme*n*") + for _, n := range ns { + if b := filepath.Base(n); !strings.Contains(strings.TrimPrefix(b, "nvme"), "c") { + m[b] = true + } + } + return m + } + before := blocks() + host, port, _ := strings.Cut(env.hosts["s1"].nvme, ":") + connect := fmt.Sprintf("transport=tcp,traddr=%s,trsvcid=%s,nqn=%s,hostnqn=nqn.2026-11.io.seaweedfs:diskfull-kernel", host, port, plannedHandoffNQN) + if out := sh("echo " + connect + " > /dev/nvme-fabrics && echo connected"); !strings.Contains(out, "connected") { + t.Fatalf("kernel connect: %s", out) + } + var ctrl, dev string + for end := time.Now().Add(30 * time.Second); dev == "" || ctrl == ""; time.Sleep(500 * time.Millisecond) { + ctrls, _ := filepath.Glob("/sys/class/nvme/nvme*") + for _, c := range ctrls { + if b, _ := os.ReadFile(filepath.Join(c, "subsysnqn")); strings.TrimSpace(string(b)) == plannedHandoffNQN { + ctrl = c + } + } + for b := range blocks() { + if !before[b] { + dev = "/dev/" + b + } + } + if time.Now().After(end) { + t.Fatalf("no namespace device for %s (controller %q, device %q)", plannedHandoffNQN, ctrl, dev) + } + } + t.Cleanup(func() { _ = os.WriteFile(filepath.Join(ctrl, "delete_controller"), []byte("1"), 0o200) }) + t.Logf("KERNEL: %s connected as %s (%s); multipath=%s io_timeout=%ss max_retries=%s", plannedHandoffNQN, dev, ctrl, + sh("cat /sys/module/nvme_core/parameters/multipath"), sh("cat /sys/module/nvme_core/parameters/io_timeout"), + sh("cat /sys/module/nvme_core/parameters/max_retries")) + + fill := fillDisk(t, root, 2<<20) + // 128 MiB of O_DIRECT 4 KiB writes, more than the 2 MiB left and the WAL. + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) + defer cancel() + dd := exec.CommandContext(ctx, "dd", "if=/dev/urandom", "of="+dev, "bs=4k", "count=32768", "oflag=direct", "status=progress") + var ddOut strings.Builder + dd.Stdout, dd.Stderr = &ddOut, &ddOut + start := time.Now() + if err := dd.Start(); err != nil { + t.Fatal(err) + } + done := make(chan error, 1) + go func() { done <- dd.Wait() }() + var ddErr error + finished := false + select { + case ddErr = <-done: + finished = true + t.Logf("KERNEL: with the disk full, dd ended after %s: err=%v\n%s", time.Since(start).Round(time.Second), ddErr, ddOut.String()) + case <-time.After(4 * time.Minute): + t.Logf("KERNEL: with the disk full, dd is still running after 4m (the guest stalls); its progress:\n%s", ddOut.String()) + } + t.Logf("KERNEL: dmesg while full:\n%s", sh("dmesg -T | grep -iE 'nvme|blk_update|I/O error|Buffer I/O' | tail -40")) + fill.free(t) + freed := time.Now() + if !finished { + select { + case ddErr = <-done: + t.Logf("KERNEL: after freeing the space, dd finished %s later: err=%v\n%s", time.Since(freed).Round(time.Second), ddErr, ddOut.String()) + case <-time.After(4 * time.Minute): + t.Logf("KERNEL: dd still running 4m after the space was freed") + cancel() + <-done + } + } else { + // After a failure: does a new write succeed once the space is free? + t.Logf("KERNEL: after freeing, a new O_DIRECT write: %s", sh("dd if=/dev/urandom of="+dev+" bs=4k count=256 oflag=direct 2>&1 | tail -1")) + } + t.Logf("KERNEL: dmesg at the end:\n%s", sh("dmesg -T | grep -iE 'nvme|blk_update|I/O error|Buffer I/O' | tail -40")) + t.Logf("KERNEL: holder log ENOSPC lines: %d; frontend ready: %v", strings.Count(readFile(holder.log), "no space left on device"), env.frontendReadyAt("s1")) + fmt.Println("DISKFULL_KERNEL_RECORDED") +} + +func readFile(p string) string { + b, _ := os.ReadFile(p) + return string(b) +} From 6b56d708738d06c3c46c80f2692fa8ef376a7525 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:05:43 -0800 Subject: [PATCH 09/13] test: disk-full kernel initiator connects with its own host ID Co-Authored-By: Claude Opus 5.5 --- .../blockvolume/procedure_diskfull_kernel_integration_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go index 5d01321f3c..cde63efed4 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go @@ -67,7 +67,9 @@ func TestProcedureLocalDiskFullKernelInitiator(t *testing.T) { } before := blocks() host, port, _ := strings.Cut(env.hosts["s1"].nvme, ":") - connect := fmt.Sprintf("transport=tcp,traddr=%s,trsvcid=%s,nqn=%s,hostnqn=nqn.2026-11.io.seaweedfs:diskfull-kernel", host, port, plannedHandoffNQN) + // Its own host NQN needs its own host ID: the kernel refuses a known host + // ID with a different host NQN. + connect := fmt.Sprintf("transport=tcp,traddr=%s,trsvcid=%s,nqn=%s,hostnqn=nqn.2026-11.io.seaweedfs:diskfull-kernel,hostid=5eb10cc0-d15c-4f00-8000-000000000484", host, port, plannedHandoffNQN) if out := sh("echo " + connect + " > /dev/nvme-fabrics && echo connected"); !strings.Contains(out, "connected") { t.Fatalf("kernel connect: %s", out) } From 732217f01d39bbb1c09887bfcd6f58e4421e0047 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 01:37:31 -0800 Subject: [PATCH 10/13] test: disk full as ruled: writes resume after freeing (asserted), a cut with the limit dir full fails closed naming the disk (#485 no longer a finding), the headroom refusal accepted for a new volume Co-Authored-By: Claude Opus 5.5 --- .../procedure_diskfull_integration_test.go | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index 4162d7559e..d961dfed67 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -21,17 +21,20 @@ import ( // space; deleting it frees it. // // 1. The WAL's disk fills under guest I/O: every guest command answers within -// the bound; the first error is the documented permanent one (0x800c), or -// 0x0104 only without ENOSPC behind it; image A stays readable; the test -// logs whether writes resume once the space is freed without a restart. +// the bound; the first error is the retryable 0x0104 that 1.0 documents +// (a Linux guest then fails the write with EREMOTEIO after about 75 s; +// the permanent class is #484, after GO); image A stays readable; once +// the space is freed, writes succeed without a restart. // 1b. The holder restarts with the disk still full: it serves reads or // exits naming the full disk. After the space is freed and a restart, // every flush-acknowledged block reads back and the next cut moves HEAD // and verifies. -// 2. A new volume's durable root is full: blockvolume exits and says why; -// after the space is freed it starts and serves. -// 3. The --host-limit-dir disk is full: the limiter fails open (the cut -// commits) and detach --plain still seals; guest I/O works meanwhile. +// 2. A new volume's durable root is full: blockvolume refuses or exits and +// says why; after the space is freed it starts over what is left and +// serves. +// 3. The --host-limit-dir disk is full: a cut is refused naming the full +// disk (background work fails closed, as ruled for #485) and detach +// --plain, the urgent seal, still seals (#486); guest I/O works meanwhile. // // Each filed defect is a known-finding row (diskFullFinding): while it // reproduces the row logs KNOWN FINDING #n and passes; once fixed it logs @@ -160,12 +163,11 @@ func TestProcedureLocalDiskFull(t *testing.T) { } } readImageA("case 1, after the first write error", c) - // Without a restart: do writes resume once the space is freed? + // Operator guide: once space is freed, new writes succeed without a + // restart (on Linux the writes made while full failed with EREMOTEIO). fill.free(t) if err := writeUntilError(16); err != nil { - t.Logf("case 1: after freeing the space, without a restart, writes still fail (latched until restart): %v", err) - } else { - t.Logf("case 1: after freeing the space, without a restart, writes and flushes resume") + t.Fatalf("case 1: after freeing the space, without a restart, writes still fail: %v", err) } c.close() @@ -260,7 +262,9 @@ func TestProcedureLocalDiskFull(t *testing.T) { t.Fatalf("case 2: blockvolume on a full durable root neither exited nor faulted within 60s; log %s", v2.log) } } - if !v2.has("no space left on device") { + // The headroom check refuses the create first (free space below the + // volume size + WAL); without it the create fails with ENOSPC. + if !v2.has("no space left on device") && !v2.has("bytes free; volume v2 needs") { t.Fatalf("case 2: blockvolume %s without naming the full disk; log %s", outcome, v2.log) } v2.kill(t) @@ -309,12 +313,11 @@ func TestProcedureLocalDiskFull(t *testing.T) { case <-time.After(2 * time.Minute): t.Fatalf("case 3: a cut with the host-limit dir full did not answer within 2m") } - // The docs name no outcome for a full --host-limit-dir (the launch check, - // INV-HOST-LAUNCH-CHECK-001, only reads it). The position for the ruling: - // the limiter paces background cuts and must fail open, so the cut - // commits; a refusal is reported for a ruling, not accepted. - g := headGen() - diskFullFinding(t, 485, r.rc != 0 || g <= g0, "case 3: with the host-limit dir full the cut exited %d and HEAD is at gen %d (was %d); the limiter did not fail open:\n%s", r.rc, g, g0, r.out) + // Ruled (issue 485): background work, timer and explicit cuts, fails + // closed when the limiter cannot run, and says why; HEAD stays. + if g := headGen(); r.rc == 0 || g != g0 || !strings.Contains(r.out, "no space left on device") { + t.Fatalf("case 3: with the host-limit dir full a cut must be refused naming the full disk; exit %d, HEAD gen %d (was %d):\n%s", r.rc, g, g0, r.out) + } t.Logf("case 3: cut with the host-limit dir full exited %d; guest write+flush succeeded meanwhile", r.rc) // The seal of a planned hand-over must not depend on the limit directory. out, errOut, rc := env.h.run(t, "ops", "chunk", "detach", "--plain", "--volume", "v1", "--status-addr", env.hosts["s1"].status, "--timeout", "120s") @@ -327,7 +330,7 @@ func TestProcedureLocalDiskFull(t *testing.T) { } // knownDiskFullFindings are the filed defects this test still expects. -var knownDiskFullFindings = map[int]bool{484: true, 485: true, 486: true} +var knownDiskFullFindings = map[int]bool{484: true, 486: true} // diskFullFinding is one defect row: bad reports whether issue's defect // reproduced in this run. From a7b3151e8428cc288fdd2ccfe202f0f0d6139431 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 06:18:58 -0800 Subject: [PATCH 11/13] test: disk full: #486 is fixed by #487, its row is strict Co-Authored-By: Claude Opus 5.5 --- .../cmd/blockvolume/procedure_diskfull_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index d961dfed67..b2284b642b 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -330,7 +330,7 @@ func TestProcedureLocalDiskFull(t *testing.T) { } // knownDiskFullFindings are the filed defects this test still expects. -var knownDiskFullFindings = map[int]bool{484: true, 486: true} +var knownDiskFullFindings = map[int]bool{484: true} // 486 fixed by #487 // diskFullFinding is one defect row: bad reports whether issue's defect // reproduced in this run. From d2d44a3bd3cf1164c74b76bd002d807b7b7d4673 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 06:39:42 -0800 Subject: [PATCH 12/13] test: disk full: a known finding that no longer reproduces fails the test (the list cannot go stale) Co-Authored-By: Claude Opus 5.5 --- .../procedure_diskfull_integration_test.go | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index b2284b642b..66b859fb80 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -37,9 +37,9 @@ import ( // --plain, the urgent seal, still seals (#486); guest I/O works meanwhile. // // Each filed defect is a known-finding row (diskFullFinding): while it -// reproduces the row logs KNOWN FINDING #n and passes; once fixed it logs -// FIXED #n; removing the issue from knownDiskFullFindings makes the row a -// strict assertion. A defect not in the list fails the test. +// reproduces the row logs KNOWN FINDING #n and passes; once fixed the row +// fails with FIXED #n until the issue is removed from knownDiskFullFindings, +// which makes it a strict assertion. A defect not in the list fails the test. // // Environment: SWBLOCK_DISKFULL_ROOT and SWBLOCK_DISKFULL_LIMIT (two mounted // filesystems, nothing else on them); CHUNKSTORE_WEED; optional @@ -336,14 +336,47 @@ var knownDiskFullFindings = map[int]bool{484: true} // 486 fixed by #487 // reproduced in this run. func diskFullFinding(t *testing.T, issue int, bad bool, format string, args ...any) { t.Helper() - msg := fmt.Sprintf(format, args...) + fail, line := diskFullVerdict(knownDiskFullFindings, issue, bad, fmt.Sprintf(format, args...)) switch { - case bad && knownDiskFullFindings[issue]: - t.Logf("KNOWN FINDING #%d: %s", issue, msg) + case fail: + t.Error(line) + case line != "": + t.Log(line) + } +} + +// diskFullVerdict decides a defect row. A known defect that still reproduces +// passes; an unknown one fails; a known one that no longer reproduces fails +// too, so the list cannot go stale and hide a later regression. +func diskFullVerdict(known map[int]bool, issue int, bad bool, msg string) (fail bool, line string) { + switch { + case bad && known[issue]: + return false, fmt.Sprintf("KNOWN FINDING #%d: %s", issue, msg) case bad: - t.Errorf("FINDING #%d: %s", issue, msg) - case knownDiskFullFindings[issue]: - t.Logf("FIXED #%d: no longer reproduces; remove it from knownDiskFullFindings so this row is strict", issue) + return true, fmt.Sprintf("FINDING #%d: %s", issue, msg) + case known[issue]: + return true, fmt.Sprintf("FIXED #%d: no longer reproduces; remove it from knownDiskFullFindings so this row is strict", issue) + } + return false, "" +} + +func TestDiskFullVerdict(t *testing.T) { + known := map[int]bool{1: true} + for _, c := range []struct { + issue int + bad bool + fail bool + line string + }{ + {1, true, false, "KNOWN FINDING #1"}, + {1, false, true, "FIXED #1"}, + {2, true, true, "FINDING #2"}, + {2, false, false, ""}, + } { + fail, line := diskFullVerdict(known, c.issue, c.bad, "m") + if fail != c.fail || !strings.HasPrefix(line, c.line) || (c.line == "" && line != "") { + t.Errorf("issue %d bad %v: fail=%v line=%q", c.issue, c.bad, fail, line) + } } } From 652f25b370dabfb62fa7289b2e0b5dc8ce1e27e2 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 23 Nov 2026 06:45:37 -0800 Subject: [PATCH 13/13] test: disk full lead review: a disk that never fills fails case 1; the seal is checked by its generation and verify; teardown kills holders, fails if anything is left; kernel cleanup at connect; per-read deadlines; no t.Fatal off the test goroutine; mount and still-full guards; %w so timeouts are seen; verdict test untagged Co-Authored-By: Claude Opus 5.5 --- .../cmd/blockvolume/diskfull_verdict_test.go | 42 ++++++++ .../procedure_diskfull_integration_test.go | 98 +++++++++++-------- ...cedure_diskfull_kernel_integration_test.go | 11 ++- .../snapshot_ladder_f1_integration_test.go | 11 ++- .../cmd/blockvolume/testdata/diskfull.sh | 15 ++- 5 files changed, 133 insertions(+), 44 deletions(-) create mode 100644 seaweed-block/cmd/blockvolume/diskfull_verdict_test.go diff --git a/seaweed-block/cmd/blockvolume/diskfull_verdict_test.go b/seaweed-block/cmd/blockvolume/diskfull_verdict_test.go new file mode 100644 index 0000000000..ff8eebb9a7 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/diskfull_verdict_test.go @@ -0,0 +1,42 @@ +package main_test + +import ( + "fmt" + "strings" + "testing" +) + +// diskFullVerdict decides a defect row. A known defect that still reproduces +// passes; an unknown one fails; a known one that no longer reproduces fails +// too, so the list cannot go stale and hide a later regression. +func diskFullVerdict(known map[int]bool, issue int, bad bool, msg string) (fail bool, line string) { + switch { + case bad && known[issue]: + return false, fmt.Sprintf("KNOWN FINDING #%d: %s", issue, msg) + case bad: + return true, fmt.Sprintf("FINDING #%d: %s", issue, msg) + case known[issue]: + return true, fmt.Sprintf("FIXED #%d: no longer reproduces; remove it from knownDiskFullFindings so this row is strict", issue) + } + return false, "" +} + +func TestDiskFullVerdict(t *testing.T) { + known := map[int]bool{1: true} + for _, c := range []struct { + issue int + bad bool + fail bool + line string + }{ + {1, true, false, "KNOWN FINDING #1"}, + {1, false, true, "FIXED #1"}, + {2, true, true, "FINDING #2"}, + {2, false, false, ""}, + } { + fail, line := diskFullVerdict(known, c.issue, c.bad, "m") + if fail != c.fail || !strings.HasPrefix(line, c.line) || (c.line == "" && line != "") { + t.Errorf("issue %d bad %v: fail=%v line=%q", c.issue, c.bad, fail, line) + } + } +} diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go index 66b859fb80..9bbe671405 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_integration_test.go @@ -4,6 +4,7 @@ package main_test import ( "bytes" + "context" "errors" "fmt" "os" @@ -58,6 +59,9 @@ func TestProcedureLocalDiskFull(t *testing.T) { if root == "" || limit == "" { t.Fatalf("SWBLOCK_DISKFULL_ROOT=%q and SWBLOCK_DISKFULL_LIMIT=%q must be set together", root, limit) } + for _, m := range []string{root, limit} { + requireSmallDedicatedMount(t, m) + } env := startHandoffEnvWith(t, 1, []string{"v2"}) if d := os.Getenv("SWBLOCK_REPLAY_LOGS"); d != "" { t.Cleanup(func() { copyLogs(t, env.h.dir, d) }) @@ -134,7 +138,7 @@ func TestProcedureLocalDiskFull(t *testing.T) { // behind it a guest would retry for ever: a wrong class, reported. switch { case firstErr == nil: - t.Logf("case 1: no error in %d writes with 2 MiB free", next) + t.Fatalf("case 1: no write failed in %d writes with 2 MiB free: the disk never filled, so this case tested nothing", next) case strings.Contains(firstErr.Error(), "status 0x800c"): diskFullFinding(t, 484, false, "case 1: the guest saw the permanent 0x800c for ENOSPC") case strings.Contains(firstErr.Error(), "status 0x0104"): @@ -175,6 +179,7 @@ func TestProcedureLocalDiskFull(t *testing.T) { // within the bound naming the full disk; never damage acknowledged data. fill = fillDisk(t, root, 0) holder.kill(t) + requireDiskFull(t, root, "case 1b, at the restart") holder = env.start(t, "blockvolume-v1-restart-full", "s1") served := false for end := time.Now().Add(60 * time.Second); ; time.Sleep(500 * time.Millisecond) { @@ -219,6 +224,7 @@ func TestProcedureLocalDiskFull(t *testing.T) { for ch := 0; ch < cutCrashChunks; ch++ { for i := 0; i < cutCrashPer; i++ { lba := uint64(ch*ladderChunkBlocks + i) + _ = c.io.SetDeadline(time.Now().Add(diskFullBound)) got := c.read(t, lba, 4096) if w, ok := want[lba]; ok { if !bytes.Equal(got, w) { @@ -230,6 +236,7 @@ func TestProcedureLocalDiskFull(t *testing.T) { } } for lba, w := range want { + _ = c.io.SetDeadline(time.Now().Add(diskFullBound)) if !bytes.Equal(c.read(t, lba, 4096), w) { t.Fatalf("case 1: flush-acknowledged LBA %d lost after the disk filled", lba) } @@ -292,8 +299,13 @@ func TestProcedureLocalDiskFull(t *testing.T) { } done := make(chan cutResult, 1) g0 := headGen() - go func() { - out, errOut, rc := env.h.run(t, cut...) + go func() { // off the test goroutine: no t.Fatal here + ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second) + defer cancel() + out, errOut, rc, err := runCLI(ctx, env.h, cut...) + if err != nil { + rc, errOut = -1, errOut+err.Error() + } done <- cutResult{out + errOut, rc} }() func() { @@ -321,7 +333,15 @@ func TestProcedureLocalDiskFull(t *testing.T) { t.Logf("case 3: cut with the host-limit dir full exited %d; guest write+flush succeeded meanwhile", r.rc) // The seal of a planned hand-over must not depend on the limit directory. out, errOut, rc := env.h.run(t, "ops", "chunk", "detach", "--plain", "--volume", "v1", "--status-addr", env.hosts["s1"].status, "--timeout", "120s") - diskFullFinding(t, 486, rc != 0, "case 3: detach --plain with the host-limit dir full exited %d:\n%s\n%s", rc, out, errOut) + sealed, sealErr := sealedGen(out, errOut, e) + diskFullFinding(t, 486, rc != 0 || sealErr != nil || sealed <= g0, + "case 3: detach --plain with the host-limit dir full exited %d, sealed gen %d (HEAD was %d, %v):\n%s\n%s", rc, sealed, g0, sealErr, out, errOut) + if g := headGen(); rc == 0 && g != sealed { + t.Fatalf("case 3: detach --plain reported gen %d but HEAD is at gen %d", sealed, g) + } + if o, eo, vrc := env.h.run(t, verify...); rc == 0 && vrc != 0 { + t.Fatalf("case 3: the sealed HEAD does not verify (exit %d):\n%s\n%s", vrc, o, eo) + } fill.free(t) t.Logf("slowest guest command answer: %s (bound %s)", diskFullSlowest, diskFullBound) if !t.Failed() { @@ -345,41 +365,6 @@ func diskFullFinding(t *testing.T, issue int, bad bool, format string, args ...a } } -// diskFullVerdict decides a defect row. A known defect that still reproduces -// passes; an unknown one fails; a known one that no longer reproduces fails -// too, so the list cannot go stale and hide a later regression. -func diskFullVerdict(known map[int]bool, issue int, bad bool, msg string) (fail bool, line string) { - switch { - case bad && known[issue]: - return false, fmt.Sprintf("KNOWN FINDING #%d: %s", issue, msg) - case bad: - return true, fmt.Sprintf("FINDING #%d: %s", issue, msg) - case known[issue]: - return true, fmt.Sprintf("FIXED #%d: no longer reproduces; remove it from knownDiskFullFindings so this row is strict", issue) - } - return false, "" -} - -func TestDiskFullVerdict(t *testing.T) { - known := map[int]bool{1: true} - for _, c := range []struct { - issue int - bad bool - fail bool - line string - }{ - {1, true, false, "KNOWN FINDING #1"}, - {1, false, true, "FIXED #1"}, - {2, true, true, "FINDING #2"}, - {2, false, false, ""}, - } { - fail, line := diskFullVerdict(known, c.issue, c.bad, "m") - if fail != c.fail || !strings.HasPrefix(line, c.line) || (c.line == "" && line != "") { - t.Errorf("issue %d bad %v: fail=%v line=%q", c.issue, c.bad, fail, line) - } - } -} - var ( errDiskFullHang = errors.New("no answer within the bound") diskFullSlowest time.Duration @@ -440,6 +425,9 @@ func fillDisk(t *testing.T, dir string, keep int64) diskFiller { var st syscall.Statfs_t _ = syscall.Statfs(dir, &st) t.Logf("filled %s: filler %d MiB, %d KiB free", dir, n>>20, int64(st.Bavail)*int64(st.Bsize)>>10) + if free := int64(st.Bavail) * int64(st.Bsize); free > keep+(1<<20) { + t.Fatalf("filled %s but %d bytes are still free (want about %d)", dir, free, keep) + } return diskFiller{path: path} } @@ -449,3 +437,35 @@ func (d diskFiller) free(t *testing.T) { t.Fatal(err) } } + +// requireDiskFull fails unless dir's file system has (almost) no free space. +func requireDiskFull(t *testing.T, dir, what string) { + t.Helper() + var st syscall.Statfs_t + if err := syscall.Statfs(dir, &st); err != nil { + t.Fatal(err) + } + if free := int64(st.Bavail) * int64(st.Bsize); free > 64<<10 { + t.Fatalf("%s: the disk is not full (%d bytes free)", what, free) + } +} + +// requireSmallDedicatedMount guards the fill: dir must be the root of its own +// small file system, so the filler can only fill the harness's mount. +func requireSmallDedicatedMount(t *testing.T, dir string) { + t.Helper() + var fs syscall.Statfs_t + var self, parent syscall.Stat_t + if err := syscall.Statfs(dir, &fs); err != nil { + t.Fatal(err) + } + if err := syscall.Stat(dir, &self); err != nil { + t.Fatal(err) + } + if err := syscall.Stat(filepath.Dir(dir), &parent); err != nil { + t.Fatal(err) + } + if size := int64(fs.Blocks) * int64(fs.Bsize); self.Dev == parent.Dev || size > 2<<30 { + t.Fatalf("%s must be a dedicated mount of at most 2 GiB (own device %v, size %d)", dir, self.Dev != parent.Dev, size) + } +} diff --git a/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go index cde63efed4..710fe70ad5 100644 --- a/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_diskfull_kernel_integration_test.go @@ -73,6 +73,16 @@ func TestProcedureLocalDiskFullKernelInitiator(t *testing.T) { if out := sh("echo " + connect + " > /dev/nvme-fabrics && echo connected"); !strings.Contains(out, "connected") { t.Fatalf("kernel connect: %s", out) } + // Registered at once, by NQN: a later failure must not leave the + // controller connected. + t.Cleanup(func() { + ctrls, _ := filepath.Glob("/sys/class/nvme/nvme*") + for _, c := range ctrls { + if b, _ := os.ReadFile(filepath.Join(c, "subsysnqn")); strings.TrimSpace(string(b)) == plannedHandoffNQN { + _ = os.WriteFile(filepath.Join(c, "delete_controller"), []byte("1"), 0o200) + } + } + }) var ctrl, dev string for end := time.Now().Add(30 * time.Second); dev == "" || ctrl == ""; time.Sleep(500 * time.Millisecond) { ctrls, _ := filepath.Glob("/sys/class/nvme/nvme*") @@ -90,7 +100,6 @@ func TestProcedureLocalDiskFullKernelInitiator(t *testing.T) { t.Fatalf("no namespace device for %s (controller %q, device %q)", plannedHandoffNQN, ctrl, dev) } } - t.Cleanup(func() { _ = os.WriteFile(filepath.Join(ctrl, "delete_controller"), []byte("1"), 0o200) }) t.Logf("KERNEL: %s connected as %s (%s); multipath=%s io_timeout=%ss max_retries=%s", plannedHandoffNQN, dev, ctrl, sh("cat /sys/module/nvme_core/parameters/multipath"), sh("cat /sys/module/nvme_core/parameters/io_timeout"), sh("cat /sys/module/nvme_core/parameters/max_retries")) diff --git a/seaweed-block/cmd/blockvolume/snapshot_ladder_f1_integration_test.go b/seaweed-block/cmd/blockvolume/snapshot_ladder_f1_integration_test.go index 494b282e20..986314f6d8 100644 --- a/seaweed-block/cmd/blockvolume/snapshot_ladder_f1_integration_test.go +++ b/seaweed-block/cmd/blockvolume/snapshot_ladder_f1_integration_test.go @@ -629,7 +629,10 @@ func (c *nvmeInitiator) tryWrite(lba uint64, data []byte) error { } ch, err := c.r.Dequeue() if err != nil || ch.Type != 0x9 { - return fmt.Errorf("nvme Write: want R2T, got type %v err %v", ch, err) + if err != nil { + return fmt.Errorf("nvme Write: want R2T: %w", err) + } + return fmt.Errorf("nvme Write: want R2T, got type %v", ch) } var r2t nvme.R2THeader if err := c.r.Receive(&r2t); err != nil { @@ -653,7 +656,11 @@ func (c *nvmeInitiator) tryFlush() error { func (c *nvmeInitiator) tryStatus(op string) error { ch, err := c.r.Dequeue() if err != nil || ch.Type != 0x5 { - return fmt.Errorf("nvme %s response: type %v err %v", op, ch, err) + if err != nil { + // %w: a deadline on the queue stays a net timeout for errors.As. + return fmt.Errorf("nvme %s response: %w", op, err) + } + return fmt.Errorf("nvme %s response: type %v", op, ch) } var resp nvme.CapsuleResponse if err := c.r.Receive(&resp); err != nil { diff --git a/seaweed-block/cmd/blockvolume/testdata/diskfull.sh b/seaweed-block/cmd/blockvolume/testdata/diskfull.sh index cdf3a06e3f..631627918a 100755 --- a/seaweed-block/cmd/blockvolume/testdata/diskfull.sh +++ b/seaweed-block/cmd/blockvolume/testdata/diskfull.sh @@ -17,11 +17,22 @@ for c in losetup mkfs.ext4 mount umount mountpoint truncate; do command -v "$c" mkdir "$work/root" "$work/limit" "$work/logs" loops=() cleanup() { + local rc=$? failed=0 set +e - for m in "$work/root" "$work/limit"; do mountpoint -q "$m" && umount "$m"; done - for l in "${loops[@]}"; do losetup -d "$l"; done + for m in "$work/root" "$work/limit"; do + mountpoint -q "$m" || continue + # A blockvolume that outlived a killed test would hold the mount busy. + command -v fuser >/dev/null && fuser -km "$m" >/dev/null 2>&1 + umount "$m" 2>/dev/null || { sleep 1; umount "$m"; } || { umount -l "$m"; failed=1; } + done + for l in "${loops[@]}"; do losetup -d "$l" || failed=1; done # Only the sparse images this script created under WORKDIR. rm -f -- "$work/root.img" "$work/limit.img" + if [ "$failed" = 1 ] || losetup -a | grep -qF "$work/"; then + echo "diskfull.sh: teardown incomplete (busy mount or loop device left)" >&2 + exit 3 + fi + exit $rc } trap cleanup EXIT for fs in root:512M limit:8M; do