Repository navigation
worker: keep in-flight overlay dirs during orphan sweep - #9695
Conversation
RemoveOrphanedResources used a snapshot of live/ and init/ taken at sweep start. A volume created after that snapshot, or renamed from init/ to live/ between the two reads, was treated as an orphan and had its overlay layer or work dir deleted while still mounted. runc then hit ENOENT creating /tmp/gdn-init. Pass a live isKnown callback that stats init/ then live/ at delete time so the handle is always found across the rename. Stat errors other than ErrNotExist fail closed (treat as known) so a permission or IO error cannot mass-delete overlays. concourse#9685 Signed-off-by: Shravanth Reddy <[email protected]>
|
|
|
Thanks for the PR! One of the baggageclaim unit tests is failing: https://ci.concourse-ci.org/teams/contributor/pipelines/pr/jobs/unit/builds/1?vars.number=%229695%22#L6a8ffa44:119:121 This is in my backlog to review. |
chmod 0 on init/ and live/ is not a Stat error for uid 0, so CI
unit-baggageclaim failed with isKnown("any-handle") false. Replace
the dirs with files so Stat returns ENOTDIR, which is not ErrNotExist
even as root.
Signed-off-by: Shravanth Reddy <[email protected]>
Had to implement the Options pattern for Filesystem so we could assert on the inner funcs. Now the tests really guard against the desired behaviour. Rest of the changes are mostly nit-pick stuff, like removing LLM comments. Signed-off-by: Taylor Silva <[email protected]>
taylorsilva
left a comment
There was a problem hiding this comment.
Thanks again for the PR! Overall I think this is the right direction to take this. Most of my feedback is regarding the tests.
I'm going to push a commit in a bit addressing my comments, assuming github doesn't block me, which it sometimes does. If it does block me I'll post my diff here for you to apply.
| It("does not remove an in-flight work dir missing from a stale snapshot", func() { | ||
| inFlight := "in-flight-vol" | ||
| workPath := filepath.Join(overlaysDir, "work", inFlight) | ||
| Expect(os.Mkdir(workPath, 0755)).To(Succeed()) | ||
|
|
||
| orphanPath := filepath.Join(overlaysDir, "work", "work-only-orphan") | ||
| Expect(os.Mkdir(orphanPath, 0755)).To(Succeed()) | ||
|
|
||
| initDir := filepath.Join(filepath.Dir(overlaysDir), "init") | ||
| Expect(os.MkdirAll(initDir, 0755)).To(Succeed()) | ||
| // Handle is absent from the (empty) snapshot but present in init/ | ||
| // by the time the sweeper considers this work dir — or it appears | ||
| // during the sweep via this live check. | ||
| Expect(os.Mkdir(filepath.Join(initDir, inFlight), 0755)).To(Succeed()) | ||
|
|
||
| isKnown := func(handle string) bool { | ||
| _, err := os.Stat(filepath.Join(initDir, handle)) | ||
| if err == nil { | ||
| return true | ||
| } | ||
| if errors.Is(err, os.ErrNotExist) { | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| err := overlayDrv.RemoveOrphanedResources(isKnown) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| Expect(workPath).To(BeADirectory()) | ||
| Expect(orphanPath).ToNot(BeADirectory()) | ||
| }) |
There was a problem hiding this comment.
Not sure this is actually testing anything. We should probably just test that we call the passed in func and the behaviour based on what that func returns.
There was a problem hiding this comment.
Actually there is no behaviour change at the driver-level. There's nothing really to test that isn't already covered by existing tests. I think this test can be deleted.
| if isKnown == nil { | ||
| isKnown = func(string) bool { return false } | ||
| } |
There was a problem hiding this comment.
Wouldn't this result in every volume being deleted? Should probably just return an error.
| defer func() { | ||
| _ = os.Remove(initDir) | ||
| _ = os.Remove(liveDir) | ||
| _ = os.Mkdir(initDir, 0755) | ||
| _ = os.Mkdir(liveDir, 0755) | ||
| }() |
There was a problem hiding this comment.
Not needed, the BeforeEach() that these files/dirs are made in will do the cleanup for us.
| // chmod 0 is not a Stat error as root (CI unit-baggageclaim). | ||
| // Replace the dirs with files so Stat(init/any-handle) returns | ||
| // ENOTDIR, which is not ErrNotExist even as uid 0. |
There was a problem hiding this comment.
Terribly confusing comment. More plain way of saying this:
removing the init/ and live/ dirs and replacing them with files. This will cause os.Stat to return ENOTDIR
|
Pushed my commit successfully! I address all my comments in that commit. Biggest changes are with the tests. Original tests were mostly trying to test the right thing, they just had a few gaps and were overly verbose in a few spots. Assuming the PR checks pass and you also don't see any further issues with this, I'll merge it. |
Changes proposed by this PR
closes #9685
The overlay sweeper deleted layer/work dirs of volumes that were being created or promoted during the sweep. The volume stayed mounted, then runc hit ENOENT creating
/tmp/gdn-initand the container create failed.live/+init/snapshot.RemoveOrphanedResourcesnow takes a liveisKnown(handle)callback.CleanupOrphanedEntriesstatsinit/first, thenlive/at delete time, so aninit→liverename cannot miss both, and a volume created after sweep start is still known.Staterror other thanErrNotExist(permission, IO) is treated as known, so a transient stat failure cannot mass-delete overlays.init/via liveisKnown. Work-only orphans are still deleted.btrfs/naiveimplement the new signature.Notes to reviewer
The in-flight overlay test used to pass the handle as known (
knownHandles(inFlight)), which is the snapshot case, not the race. It now uses a liveStatofinit/while the snapshot is empty.To confirm:
Release Note
/tmp/gdn-init.