seaweed-block: mini under a systemd process tree, and no new lock-dir flag (on #13421) (#13425)

* seaweed-block: mini starts its children without INVOCATION_ID

Run from a systemd service's process tree (a CI runner unit, a terminal
server), mini passed INVOCATION_ID to blockvolume, which then refused
mini's lock directory and the run stopped at startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* seaweed-block: mini's interrupt test expects the resume command with mini's own path

mini prints the resume command with os.Executable(), so the in-process
test saw the test binary's path, not a bare sw-block, and failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* seaweed-block: mini uses the existing hidden lock-dir override, no new flag

--volume-lock-dir set the same field as the hidden --volume-lock-dir-test-only
with the same systemd refusal, and mini was its only caller. Keep one hidden
override so operators are not offered a documented knob that drops the
one-holder-per-volume guarantee outside systemd (containers, hand-run hosts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-12-04 22:38:52 -08:00
1 parent e403ac4c9d
commit 6dbba4cb24
6 files changed
+46 -49

No files matched your search

+3 -19
View File
@@ -129,13 +129,9 @@ type flags struct {
durableBlockSize uint
durableWALMultiBlockRecords bool
durableWALRecoveryTestDisableFlusher bool
// volumeLockDirTestOnly replaces durable.HostVolumeLockDir (hidden,
// test-only; refused under systemd).
// volumeLockDirTestOnly replaces durable.HostVolumeLockDir (hidden, for
// tests and sw-block mini's one-user trial; refused under systemd).
volumeLockDirTestOnly string
// volumeLockDir is the same override for a one-user trial run on a
// disposable host (sw-block mini): it lets the run keep every path in
// its own directory, without root. Refused under systemd, as above.
volumeLockDir string
// WAL retention window past checkpoint LSN. Zero = strict
// checkpoint-driven recycle. Non-zero = walstore relaxes the
@@ -289,9 +285,6 @@ func parseFlagsWithCgroup(args []string, readFile func(string) ([]byte, error))
"sync-* modes fail foreground writes when required replica acknowledgement is unavailable.")
fs.BoolVar(&f.version, "version", false, "print build provenance and exit")
fs.StringVar(&f.volumeLockDirTestOnly, volumeLockDirTestOnlyFlag, "", "")
fs.StringVar(&f.volumeLockDir, "volume-lock-dir", "",
"trial runs only: the volume lock directory instead of "+durable.HostVolumeLockDir+
"; one process per volume is then enforced only among processes using the same directory; refused under systemd")
fs.SetOutput(os.Stderr)
fs.Usage = func() { printVisibleUsage(fs) }
if err := fs.Parse(args); err != nil {
@@ -339,17 +332,8 @@ func parseFlagsWithCgroup(args []string, readFile func(string) ([]byte, error))
if err := checkMasterTLS(f); err != nil {
return flags{}, err
}
if f.volumeLockDir != "" {
if f.volumeLockDirTestOnly != "" {
return flags{}, fmt.Errorf("--volume-lock-dir and --%s both given: pass one", volumeLockDirTestOnlyFlag)
}
if os.Getenv("INVOCATION_ID") != "" {
return flags{}, fmt.Errorf("--volume-lock-dir is for trial runs and refused under systemd (INVOCATION_ID is set): the one-process-per-host guarantee needs %s", durable.HostVolumeLockDir)
}
f.volumeLockDirTestOnly = f.volumeLockDir
}
if f.volumeLockDirTestOnly != "" && os.Getenv("INVOCATION_ID") != "" {
return flags{}, fmt.Errorf("--%s is test-only and refused under systemd (INVOCATION_ID is set): the one-process-per-host guarantee needs %s", volumeLockDirTestOnlyFlag, durable.HostVolumeLockDir)
return flags{}, fmt.Errorf("--%s is for tests and trial runs and refused under systemd (INVOCATION_ID is set): the one-process-per-host guarantee needs %s", volumeLockDirTestOnlyFlag, durable.HostVolumeLockDir)
}
if f.recoveryMode != "legacy" && f.recoveryMode != "dual-lane" {
return flags{}, fmt.Errorf("--recovery-mode=%q invalid; want \"legacy\" or \"dual-lane\"", f.recoveryMode)
@@ -53,27 +53,7 @@ func TestVolumeLockDirTestOnlyHiddenFromHelp(t *testing.T) {
}
}
// The trial lock directory (sw-block mini) takes the same path as the test
// override: accepted outside systemd, refused under it, refused together
// with the test override.
func TestVolumeLockDirTrialFlag(t *testing.T) {
base := append(phase150RequiredBlockvolumeArgs(), "--durable-root="+t.TempDir(), "--durable-impl=walstore")
dir := t.TempDir()
t.Setenv("INVOCATION_ID", "")
f, err := parseFlags(append(base, "--volume-lock-dir="+dir))
if err != nil || f.volumeLockDirTestOnly != dir {
t.Fatalf("the trial lock dir outside systemd: %q %v", f.volumeLockDirTestOnly, err)
}
if _, err := parseFlags(append(base, "--volume-lock-dir="+dir, "--volume-lock-dir-test-only="+dir)); err == nil || !strings.Contains(err.Error(), "both given") {
t.Fatalf("both overrides were accepted: %v", err)
}
t.Setenv("INVOCATION_ID", "0123456789abcdef")
if _, err := parseFlags(append(base, "--volume-lock-dir="+dir)); err == nil || !strings.Contains(err.Error(), "refused under systemd") {
t.Fatalf("the trial lock dir was accepted under systemd: %v", err)
}
}
// Without either flag the lock directory stays the host one: the provider
// Without the override the lock directory stays the host one: the provider
// gets no override, so it uses durable.HostVolumeLockDir.
func TestVolumeLockDirDefaultIsTheHostDirectory(t *testing.T) {
t.Setenv("INVOCATION_ID", "")
@@ -81,8 +61,8 @@ func TestVolumeLockDirDefaultIsTheHostDirectory(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if f.volumeLockDir != "" || f.volumeLockDirTestOnly != "" {
t.Fatalf("a default start overrides the lock directory: %q %q", f.volumeLockDir, f.volumeLockDirTestOnly)
if f.volumeLockDirTestOnly != "" {
t.Fatalf("a default start overrides the lock directory: %q", f.volumeLockDirTestOnly)
}
if durable.HostVolumeLockDir != "/run/sw-block/locks" {
t.Fatalf("the host lock directory moved: %s", durable.HostVolumeLockDir)
+8 -1
View File
@@ -194,7 +194,7 @@ func miniMasterArgs(c miniConfig, chunk bool) []string {
// (a trial override, which blockvolume refuses under systemd); with a chunk
// store it takes no scheduled snapshot (mini prints how to take one).
func miniVolumeArgs(c miniConfig, chunk bool, layoutID string) []string {
a := append(miniVolumeSpec(c, chunk, layoutID).args(), "--volume-lock-dir", filepath.Join(c.Dir, "locks"))
a := append(miniVolumeSpec(c, chunk, layoutID).args(), "--volume-lock-dir-test-only", filepath.Join(c.Dir, "locks"))
if chunk {
a = append(a, "--chunk-snapshot-schedule", "off")
}
@@ -285,6 +285,13 @@ func (r *miniRun) start(name, bin string, args []string) (*miniChild, error) {
}
cmd := exec.Command(bin, args...)
cmd.Stdout, cmd.Stderr, cmd.Stdin = lf, lf, nil
// mini's children are not systemd units even when mini runs under one;
// blockvolume refuses mini's lock directory while INVOCATION_ID is set.
for _, kv := range os.Environ() {
if !strings.HasPrefix(kv, "INVOCATION_ID=") {
cmd.Env = append(cmd.Env, kv)
}
}
if err := cmd.Start(); err != nil {
lf.Close()
return nil, fmt.Errorf("start %s: %w", name, err)
+29 -3
View File
@@ -147,7 +147,7 @@ func TestMiniWalstoreFlagsAreThePage(t *testing.T) {
for f := range got {
// mini keeps the volume lock under --dir, so it needs no root
// (the page's unit uses the host lock directory).
if _, ok := page[f]; !ok && f != "--volume-lock-dir" {
if _, ok := page[f]; !ok && f != "--volume-lock-dir-test-only" {
t.Errorf("%s: mini passes %s; the page's swb_start does not", c.binary, f)
}
}
@@ -346,7 +346,12 @@ func TestMiniInterruptStopsEveryChild(t *testing.T) {
case <-time.After(30 * time.Second):
t.Fatal("mini did not stop")
}
for _, want := range []string{"if v1 is connected: unmount it, then sudo nvme disconnect -n nqn.test:v1", "The data stays in " + c.Dir, " " + miniResume(c) + "\n"} {
self, err := os.Executable()
if err != nil {
t.Fatal(err)
}
resume := miniResume(miniConfig{Dir: c.Dir, Self: self})
for _, want := range []string{"if v1 is connected: unmount it, then sudo nvme disconnect -n nqn.test:v1", "The data stays in " + c.Dir, " " + resume + "\n"} {
if !strings.Contains(out.String(), want) {
t.Fatalf("at stop, output lacks %q:\n%s", want, out.String())
}
@@ -445,7 +450,7 @@ func wantChunkCommands(dir, id string) map[string][]string {
"--durable-root", filepath.Join(dir, "vol"), "--durable-impl", "walstore-chunk", "--durable-blocks", "65536", "--durable-blocksize", "4096",
"--chunk-filer", "127.0.0.1:18888", "--chunk-path", "/swblock/chunks", "--chunk-control-endpoint", "--workspace-lease", "--layout-id", id,
"--nvme-listen", "127.0.0.1:4420", "--nvme-subsysnqn", "nqn.2026-05.io.seaweedfs:v1",
"--volume-lock-dir", filepath.Join(dir, "locks"), "--chunk-snapshot-schedule", "off"},
"--volume-lock-dir-test-only", filepath.Join(dir, "locks"), "--chunk-snapshot-schedule", "off"},
}
}
@@ -803,3 +808,24 @@ func TestMiniPrintedResumeRunsOnASpacedDir(t *testing.T) {
t.Fatalf("control: the unquoted line reached the dir too (exit %d)", code)
}
}
// mini started from a systemd service's process tree (a CI runner unit, a
// terminal server) inherits INVOCATION_ID; blockvolume refuses the lock-dir
// override under it, so mini's children must start without it.
func TestMiniChildrenStartWithoutInvocationID(t *testing.T) {
t.Setenv("INVOCATION_ID", "0123456789abcdef")
dir := t.TempDir()
r := &miniRun{cfg: miniConfig{Dir: dir}, out: io.Discard, log: io.Discard}
c, err := r.start("env", "/bin/sh", []string{"-c", `echo "id=${INVOCATION_ID-unset}"`})
if err != nil {
t.Fatal(err)
}
<-c.done
b, err := os.ReadFile(filepath.Join(dir, "env.log"))
if err != nil {
t.Fatal(err)
}
if got := strings.TrimSpace(string(b)); got != "id=unset" {
t.Fatalf("mini's child saw %q", got)
}
}
+2 -2
View File
@@ -167,8 +167,8 @@ systemd and root access.
`install`, not `mv`: with SELinux, a file moved from a home directory keeps its home label and systemd may refuse
to run it.
blockvolume's volume locks are always in `/run/sw-block/locks` under the units. `--volume-lock-dir DIR` moves
them only for a one-user trial (`sw-block mini` uses it); blockvolume refuses it under systemd.
blockvolume's volume locks are always in `/run/sw-block/locks` under the units. Only `sw-block mini`, a one-user
trial, keeps them under its own `--dir`; blockvolume refuses that override under systemd.
Do **not** enable `sw-blockvolume.service`. It is the single-volume example for the `--topology` setup, which cannot
serve a walstore-chunk volume. This manual runs each volume as the template unit `sw-blockvolume@<volume>.service`,
+1 -1
View File
@@ -500,7 +500,7 @@ sw-block mini --dir ./swb-mini # blockmaster and blockvolume next to sw
- If you connected v1, unmount it and run `sudo nvme disconnect -n <nqn>` **before** stopping mini. Otherwise a mounted filesystem sits on a stopped target while the kernel retries for 3 minutes. mini prints this with the connect command and again when it stops.
- The data stays in `--dir`; `sw-block mini --dir <dir> --reuse` (printed at stop, quoted for the shell) starts it again, with that run's size, ports, mode and NQN (recorded in `<dir>/mini.json`; a flag that differs is refused).
- **It is a trial setup:** one host, loopback, no authentication.
- **No root:** blockvolume's volume lock is in `<dir>/locks` (`--volume-lock-dir`, a trial override that blockvolume refuses under systemd), so mini starts as any user without the tmpfiles.d entry. Every command it prints names sw-block and weed by their absolute paths.
- **No root:** blockvolume's volume lock is in `<dir>/locks` (`--volume-lock-dir-test-only`, a hidden override that blockvolume refuses under systemd), so mini starts as any user without the tmpfiles.d entry. Every command it prints names sw-block and weed by their absolute paths.
- **Snapshots:** mini runs `v1` with `--chunk-snapshot-schedule off` and prints the command that takes one; the units' daily schedule is not part of a trial.
- **A failed start** stops what it started and prints the `--reuse` command that starts again on the same `--dir` (or remove the directory and start fresh).
- **Refusals:** it refuses a `--dir` that already exists, unless you pass `--reuse` to start again on it, and refuses a port that is already in use. `--port-shift N` moves every port by N, for a host where a default port is taken.