Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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
}


if err := ls.driver.CreateReadWrite(initID, parent, createOpts); err != nil {
return "", err
}
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

@thaJeztah
Copy link
Member

cc @dmcgowan ISTR you wanted to have a look

@vvoland vvoland modified the milestones: 29.0.0, 30.0.0 Jul 14, 2025
@zzzzzzzzzy9
Copy link
Author

@thaJeztah Could you please merge this?

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