Skip to content

cleanup <ID>-init dir and the symlink in <rootdir>/l on failure #49974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zzzzzzzzzy9
Copy link

@zzzzzzzzzy9 zzzzzzzzzy9 commented May 14, 2025

- What I did
This code is used to clean up init when initMount fails, including the <initID>-init folder and <rootdir>/l folder.

- How I did it
Use the ls.driver.Remove() function to cleanup on failure.

- How to verify it

- Human readable description for the release notes

cleanup <ID>-init dir and the symlink in <rootdir>/l on failure

- A picture of a cute animal (not mandatory but encouraged)

@zzzzzzzzzy9
Copy link
Author

@thaJeztah @vvoland Could you please review this pr, thanks.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

This seems to make sense, but I'm also slightly wondering if there's possible errors that should be handled differently (although it looks like Removee already handles "not found" errors for at least some implementations).

I could definitely use some more eyes on this to make sure this is the correct approach.

I noticed there's another location where ls.driver.CreateReadWrite is called, and at a quick glance I didn't see a cleanup there as well;

moby/layer/layer_store.go

Lines 531 to 536 in c3f484d

if err := ls.driver.CreateReadWrite(m.mountID, parentID, createOpts); err != nil {
return nil, err
}
if err := ls.saveMount(m); err != nil {
return nil, err
}

@@ -659,15 +659,19 @@ func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc Mou
}
Copy link
Member

Choose a reason for hiding this comment

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

If we need to remove on any failure, we could use a defer;

  1. add a retErr output variable
func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit, storageOpt map[string]string) (_ string, retErr error) {
  1. define a defer here that attempts to remove on failure;
	defer func() {
		if retErr != nil {
			// cleanup on failure
			if err := ls.driver.Remove(initID); err != nil {
				log.G(context.TODO()).WithFields(log.Fields{
					"initID": initID,
					"error":  err,
				}).Warnf("Removing init layer after failure: %v", retErr)
			}
		}
	}()

@zzzzzzzzzy9
Copy link
Author

Done, thank you for your suggestion. @thaJeztah

Signed-off-by: zzzzzzzzzy9 <zhang.yu58@zte.com.cn>
@thaJeztah
Copy link
Member

cc @dmcgowan ISTR you wanted to have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy