Skip to content

fix(satellite): leave DRBD slots alone unless blockstor provably owns them - #272

Merged
Andrei Kvapil (kvaps) merged 3 commits into
mainfrom
fix/drbd-sweeper-fail-closed
Nov 23, 2026
Merged

Andrei Kvapil (kvaps) merged 3 commits into
mainfrom
fix/drbd-sweeper-fail-closed

Conversation

@kvaps

Copy link
Copy Markdown
Member

What this PR does

The satellite's DRBD orphan sweeper runs drbdsetup down on kernel slots it decides blockstor owns but no Resource CRD covers. Several paths reached that decision from missing information rather than evidence. On a node where another DRBD manager is still running, LINSTOR during a migration for example, any of them can take down a live resource that blockstor never owned and cannot rebuild. With this change the sweeper fails closed: if it cannot prove ownership it leaves the slot up and logs why, and if it cannot read its inputs it skips the whole cycle and reports it.

Fixed paths, all in pkg/satellite/controllers/sweeper.go and sweeper_resfile.go:

  • A failed read of the local Node was logged and the sweep went ahead, so the skip annotation was ignored at exactly the moment it could not be seen. The cycle is now skipped. A missing Node counts as unreadable.
  • An annotation value that is not a bool (yes, an empty string) was read as "not opted out". It now skips the cycle with an error. Any spelling strconv.ParseBool reads as true still opts out.
  • A failed ResourceDefinition list meant the sweep ran with no grace window, so it could down slots the controller was still creating. The cycle is now skipped.
  • A marker probe that failed with anything other than ENOENT (EACCES, EIO) counted as "owned". It now counts as unknown, so the slot is left up and the failure is logged. If one marker exists, that still proves ownership even when the other cannot be probed.
  • Markers were checked with os.Stat, so a symlink or a directory under a marker's name counted as ownership. Only a regular file counts now, checked with os.Lstat. A kernel name that is not a plain file name is treated as unknown, since joining it onto StateDir could probe a path outside StateDir.
  • An empty StateDir switched off the marker check, so every slot without a CRD looked like an orphan. With no StateDir the sweeper now tears nothing down and reports that on every cycle. Production always sets StateDir, so this only changes behaviour when someone passes --state-dir= explicitly.
  • The .res GC, which downs a loaded slot before it unlinks a stale .res, accepted symlinked .res entries. It now skips them and logs them.

A genuine orphan, meaning a slot with no CRD, a regular ownership marker, readable inputs and no opt-out, is still torn down as before.

The change touches only the DRBD sweeper and its tests, plus one stale doc comment on Reconciler.StateDir(). Manager wiring and the storage sweeper are not touched, so it does not conflict with the storage sweeper removal in #271.

Testing

  • New unit tests in sweeper_failclosed_test.go use a fake client with interceptors and a fake lstat. They cover: Node read error and missing Node (cycle skipped, no kernel calls, .res GC not run); the annotation values table; RD list error (cycle skipped); EACCES and EIO on one or both markers (slot left up, reported as unknown) and EIO on one marker with the other present (still torn down); a symlink or a directory as the marker; non-plain kernel names; no StateDir; a symlinked .res in the GC; and a control showing that the same fixture with readable inputs does down its orphan and collect its stale .res.
  • The existing sweeper tests now give their orphans an explicit ownership marker. Before, they relied on the empty-StateDir fallback this PR removes.
  • Mutation check: I reverted each guard in turn (13 mutations, covering every bullet above plus the "positive proof wins" ordering and the unknown-vs-foreign classification), and each one fails at least one test.
  • make lint-config && make lint: 0 issues.
  • go test ./... with envtest assets: green, including the provenance guard in pkg/naming/guard_test.go.
  • The sweeper tests also pass under go test -race -count=3.

Not tested

  • I have not run this on a stand or on a node with a co-resident LINSTOR satellite. The fail-closed paths are covered by unit tests only.
  • The EACCES and EIO cases are simulated through the lstat hook, not produced by a real filesystem.
  • I did not measure how loud the per-cycle log is when a node sits for a long time with an unreadable Node or no StateDir. It logs one error every 30 s, through the existing tick logging.

The orphan sweeper treated a failed read of its own Node as "no
opt-out" and a failed ResourceDefinition list as "no RD inside the
grace window", and swept anyway. Both are guesses in the direction
that destroys data: the skip annotation is the only way an operator
can stop the sweeper, and a slot inside the grace window is one the
controller is still creating or the satellite is still deleting.

Skip the cycle and report instead. A missing Node counts as
unreadable, and an annotation value that does not parse as a bool
counts as an opt-out we cannot read. The price is one cycle of delay
on a genuine orphan.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The sweeper downs a kernel slot without a Resource CRD only when
blockstor's StateDir holds an ownership marker for it, so that a
co-resident DRBD manager's resources survive. Three paths read "we do
not know" as "ours": a marker probe failing with anything but ENOENT
(EACCES, EIO) counted as owned; os.Stat followed a symlink or accepted
a directory under the marker's name; and an empty StateDir turned the
marker check off, so every slot without a CRD was an orphan. On a node
being migrated from LINSTOR any of these downs a live resource, which
the reconciler cannot rebuild because it was never blockstor's.

Only a regular file under a marker name now proves ownership; a probe
error, a marker of another kind or a kernel name that is not a plain
file name leaves the slot up and logs why. One marker proving
ownership still wins over the other failing to probe. Without a
StateDir the sweeper sweeps nothing and says so every cycle.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
The .res GC downs a loaded kernel slot before unlinking a stale
`<rd>.res`, and it accepted any non-directory entry, a symlink
included. blockstor writes its .res files with os.WriteFile, so a
link in StateDir was put there by something else, for example to
expose another manager's config to drbdadm, and the slot behind it is
not the GC's to down. Skip such entries and log them, matching the
regular-file rule the kernel-slot sweep now applies to its markers.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fa96b9ab-9edf-4916-a56b-d889a03eaccf
Commits

Reviewing files that changed from the base of the PR and between 216e577 and aa53d48.

Files selected for processing: 6

  • pkg/satellite/controllers/sweeper.go
  • pkg/satellite/controllers/sweeper_failclosed_test.go
  • pkg/satellite/controllers/sweeper_resfile.go
  • pkg/satellite/controllers/sweeper_resfile_test.go
  • pkg/satellite/controllers/sweeper_test.go
  • pkg/satellite/reconciler.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every path that used to fall through to a teardown now needs positive proof, and the production wiring keeps the genuine-orphan path alive: manager.go passes cfg.Apply.StateDir() to the sweeper, so the empty-StateDir refusal only affects an explicit --state-dir=. .owned is stamped on every render and survives the startup .res wipe, so slots blockstor brought up still classify as owned after a restart.

The red Integration job is TestGroupFRToggleDiskful2DisklessReapsTieBreaker timing out. It fails the same way on unrelated branches, and the sweeper is not on that path.

@kvaps
Andrei Kvapil (kvaps) merged commit d46abb4 into main Nov 23, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants