Skip to content

storage: cleanup staged layer if unused#2390

Merged
mtrmac merged 2 commits intocontainers:mainfrom
giuseppe:cleanup-staged-directory
May 16, 2024
Merged

storage: cleanup staged layer if unused#2390
mtrmac merged 2 commits intocontainers:mainfrom
giuseppe:cleanup-staged-directory

Conversation

@giuseppe
Copy link
Copy Markdown
Member

@giuseppe giuseppe commented May 2, 2024

notify c/storage that the staged layer is not used and must be cleaned up on error.

Copy link
Copy Markdown
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Thanks!

This works, but it would be easy to forget next time again.

So I’m leaning towards

out, err :=if err != nil { … }
succeeded := false
defer func() {
    if !succeeded { … CleanupStagedLayer … }
}()
…
…diffOutputs =s.lock.Unlock()
succeeded = true
return

If you think that’s never going to be necessary, shrug, this PR is an improvement as is.


But, also, that code path should never be hit. Is that assumption incorrect?

@giuseppe giuseppe force-pushed the cleanup-staged-directory branch from 5e5e2e9 to 41c9867 Compare May 2, 2024 14:26
@giuseppe
Copy link
Copy Markdown
Member Author

giuseppe commented May 2, 2024

If you think that’s never going to be necessary, shrug, this PR is an improvement as is.

your version is better, I've fixed it and pushed a new version

Copy link
Copy Markdown
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

If I understand correctly, this is to follow the rules, allowing us to more precisely use locks in containers/storage#1916 .

But right now there’s containers/storage#1916 (comment) , so I’d prefer to wait a bit here until the that question is resolved.

@mtrmac mtrmac added the kind/bug A defect in an existing functionality (or a PR fixing it) label May 13, 2024
@giuseppe
Copy link
Copy Markdown
Member Author

containers/storage#1916 is merged, can we reconsider this?

Copy link
Copy Markdown
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

AFAICS, on return from ApplyDiffFromStagingDirectory, the callers can’t tell whether the lock is now unlocked.

But, also, the locks only exist for directories created by MkdirTemp, and the unlock code is ~idempotent, so extra calls of CleanupStagedLayer don’t actually hurt.

LGTM.

giuseppe added 2 commits May 16, 2024 16:34
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
notify c/storage that the staged layer is not used and must be cleaned
up on error.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@mtrmac mtrmac force-pushed the cleanup-staged-directory branch from 41c9867 to 77d7ff5 Compare May 16, 2024 14:34
@TomSweeneyRedHat
Copy link
Copy Markdown
Member

LGTM
once the tests are hip

@mtrmac mtrmac merged commit 4f07d28 into containers:main May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug A defect in an existing functionality (or a PR fixing it)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants