Skip to content

fix(install): open the target disk with a path-recording backend - #5135

Merged
Itxaka merged 1 commit into
kairos-io:masterfrom
ci-forks:bot/5134-blkpg-backend-path
Oct 20, 2026
Merged

Itxaka merged 1 commit into
kairos-io:masterfrom
ci-forks:bot/5134-blkpg-backend-path

Conversation

@ci-robbot

Copy link
Copy Markdown
Collaborator

Fixes #5134

Summary

agent/pkg/partitioner.NewDisk opened the install target with diskfs.Open, which builds its backend with file.New. file.New's own doc comment says it "will not store any path", so Backend.Path() was always empty under Kairos.

go-diskfs needs that path. When BLKRRPART cannot make the kernel re-read the table, it falls back to per-partition BLKPG reconciliation (what partx does), and that fallback reads Backend.Path() on its first line and gives up with backend has no path; cannot reconcile partitions when it is empty. So the fallback could never run here, and every busy device turned into a fatal partition table written to disk but kernel re-read deferred and failed the install. The write itself provokes the busy condition, because it triggers a udev re-probe.

This is what reddens test-core-rocky-9 / selinux on master, most recently in run 37016179742.

The fix builds the backend with file.OpenFromPathWithExclusive(device, false, true), which records the path and keeps exactly the O_RDWR|O_EXCL flags diskfs.Open defaulted to, and hands it to diskfs.OpenBackend.

Separate from #4632, which fixes the other defect in the same code path: that the re-read retry loop's result is discarded by an unconditional extra call. Both are needed. With #4632 alone the five retries would still each hit EBUSY with the fallback disabled.

How it was tested

TestNewDiskBackendRecordsPath pins Backend.Path(), the exact value the BLKPG fallback reads, and then partitions the disk to confirm the open is still read-write.

Red on master:

--- FAIL: TestNewDiskBackendRecordsPath (0.00s)
    disk_test.go:697: Backend.Path() = "", want "/tmp/.../disk.img"; the BLKPG fallback refuses to run without it

Green with the change, along with the rest of the package and its caller:

$ go test ./agent/pkg/partitioner/...
ok  	github.com/kairos-io/kairos/v4/agent/pkg/partitioner	0.011s
$ go test ./agent/pkg/elemental/...
ok  	github.com/kairos-io/kairos/v4/agent/pkg/elemental	12.176s
$ go build ./agent/...

The install path itself needs a real block device, so the BLKPG fallback firing end to end is only provable in the e2e jobs on this PR.

AI was used to write this change. No human has read it yet.

🤖 Generated with Claude Code

go-diskfs falls back to per-partition BLKPG reconciliation when BLKRRPART
cannot make the kernel re-read the partition table, which is the common case
right after writing a table because the write triggers a udev re-probe. That
fallback reads Backend.Path() first and gives up when it is empty.

NewDisk opened the target with diskfs.Open, which builds its backend with
file.New. file.New does not record the path, so Backend.Path() was always
empty under Kairos and the fallback could never run: every busy device turned
into a fatal "kernel re-read deferred" and failed the install.

Build the backend with file.OpenFromPathWithExclusive instead, which records
the path and keeps the same O_RDWR|O_EXCL flags diskfs.Open defaulted to.

Fixes kairos-io#5134

Signed-off-by: Ettore Di Giacinto <mudler@kairos.io>

@itxaka-agent itxaka-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

Approving. file.OpenFromPathWithExclusive(device, false, true) opens with the same O_RDWR|O_EXCL as diskfs.Open, goes through the same initDisk path in OpenBackend, and now records the path that the BLKPG fallback reads first. NewDisk has one production caller (elemental.go), and the ISO extractor's diskfs.Open is read-only and untouched.

I ran go test ./agent/pkg/partitioner/... on master (4433f215) merged with this PR and it passes. The 2026-10-13 red unit-tests / test failed in kairos-init/pkg/validation, which this PR does not touch, and the rerun on the same head passed.

@itxaka-agent

Copy link
Copy Markdown
Collaborator

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

QA in progress: I'm testing this now. Results and proof will follow here.

@itxaka-agent

Copy link
Copy Markdown
Collaborator

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

QA: pass at 7a74c87 (unit tests on the merge with master, no VM), details and proof: #5134 (comment)

@itxaka-agent

Copy link
Copy Markdown
Collaborator

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override any
action taken here.

The earlier QA: pass on this PR and its issue rested on unit tests only, which does not meet our QA bar. The label is withdrawn and both cards are back in QA. We will re-run QA end to end in a VM.

@itxaka-agent

Copy link
Copy Markdown
Collaborator

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

QA: pass at 7a74c874, VM install before/after (busy device was injected), details and proof: #5134 (comment)

@Itxaka
Itxaka merged commit d1a2114 into kairos-io:master Oct 20, 2026
88 of 90 checks passed
@github-project-automation github-project-automation Bot moved this from QA OK to Done âś… in đź§™Issue tracking board Oct 20, 2026

This branch was previously deployed

1 inactive deployment
fork-pr-builds — 7a74c874 Deployed Oct 2, 2026 by ci-robbot via authorize #1010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install: the BLKPG partition-table fallback can never run, because the disk is opened with a path-less backend

4 participants