-
Notifications
You must be signed in to change notification settings - Fork 133
Add overlay driver reflink support detection #961
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
ngopalak-redhat
wants to merge
1
commit into
podman-container-tools:main
Choose a base branch
from
ngopalak-redhat:ngopalak/is-reflink-supported
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,7 @@ type Driver struct { | |
| stagingDirsLocks map[string]*staging_lockfile.StagingLockFile | ||
|
|
||
| supportsIDMappedMounts *bool | ||
| supportsReflinks *bool | ||
| } | ||
|
|
||
| type additionalLayerStore struct { | ||
|
|
@@ -302,6 +303,18 @@ func (d *Driver) getSupportsDataOnly() (bool, error) { | |
| return supportsDataOnly, nil | ||
| } | ||
|
|
||
| func (d *Driver) getSupportsReflinks() (bool, error) { | ||
| if d.supportsReflinks != nil { | ||
| return *d.supportsReflinks, nil | ||
| } | ||
| supportsReflinks, err := checkSupportsReflinks(d.home, d.runhome) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| d.supportsReflinks = &supportsReflinks | ||
|
Comment on lines
+307
to
+314
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unless I am missing something this is being called in Status without the store lock held which means these field assignments are not concurrent safe and can cause a panic if status is being called concurrently for the first time. |
||
| return supportsReflinks, nil | ||
| } | ||
|
|
||
| // isNetworkFileSystem checks if the specified file system is supported by native overlay | ||
| // as backing store when running in a user namespace. | ||
| func isNetworkFileSystem(fsMagic graphdriver.FsMagic) bool { | ||
|
|
@@ -866,13 +879,18 @@ func (d *Driver) Status() [][2]string { | |
| if err != nil { | ||
| supportsVolatile = false | ||
| } | ||
| supportsReflinks, err := d.getSupportsReflinks() | ||
| if err != nil { | ||
| supportsReflinks = false | ||
| } | ||
| return [][2]string{ | ||
| {"Backing Filesystem", backingFs}, | ||
| {"Supports d_type", strconv.FormatBool(d.supportsDType)}, | ||
| {"Native Overlay Diff", strconv.FormatBool(!d.useNaiveDiff())}, | ||
| {"Using metacopy", strconv.FormatBool(d.usingMetacopy)}, | ||
| {"Supports shifting", strconv.FormatBool(d.SupportsShifting(nil, nil))}, | ||
| {"Supports volatile", strconv.FormatBool(supportsVolatile)}, | ||
| {"Supports reflinks", strconv.FormatBool(supportsReflinks)}, | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| //go:build linux | ||
|
|
||
| package overlay | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
| "go.podman.io/storage/pkg/fileutils" | ||
| ) | ||
|
|
||
| func checkSupportsReflinks(home, runhome string) (bool, error) { | ||
| const feature = "reflinks" | ||
|
|
||
| reflinkCacheResult, _, err := cachedFeatureCheck(runhome, feature) | ||
| if err == nil { | ||
| logrus.Debugf("Cached reflink support: %v", reflinkCacheResult) | ||
| return reflinkCacheResult, nil | ||
| } | ||
|
|
||
| supportsReflinks, err := testReflinkSupport(home) | ||
| if err != nil { | ||
| logrus.Debugf("overlay: reflink test failed: %v", err) | ||
| supportsReflinks = false | ||
| } | ||
| logrus.Debugf("overlay: reflink support: %v", supportsReflinks) | ||
|
|
||
| if err := cachedFeatureRecord(runhome, feature, supportsReflinks, ""); err != nil { | ||
| return false, fmt.Errorf("recording reflink-support status: %w", err) | ||
| } | ||
|
|
||
| return supportsReflinks, nil | ||
| } | ||
|
|
||
| func testReflinkSupport(testDir string) (bool, error) { | ||
| srcPath := filepath.Join(testDir, ".reflink-test-src") | ||
| dstPath := filepath.Join(testDir, ".reflink-test-dst") | ||
| defer os.Remove(srcPath) | ||
| defer os.Remove(dstPath) | ||
|
|
||
| srcFile, err := os.Create(srcPath) | ||
| if err != nil { | ||
| return false, fmt.Errorf("failed to create source file: %w", err) | ||
| } | ||
|
|
||
| testData := []byte("reflink test") | ||
| if _, err := srcFile.Write(testData); err != nil { | ||
| srcFile.Close() | ||
| return false, fmt.Errorf("failed to write test data: %w", err) | ||
| } | ||
|
|
||
| if err := srcFile.Sync(); err != nil { | ||
| srcFile.Close() | ||
| return false, fmt.Errorf("failed to sync source file: %w", err) | ||
| } | ||
| srcFile.Close() | ||
|
|
||
| srcFile, err = os.Open(srcPath) | ||
| if err != nil { | ||
| return false, fmt.Errorf("failed to reopen source file: %w", err) | ||
| } | ||
| defer srcFile.Close() | ||
|
|
||
| dstFile, err := os.Create(dstPath) | ||
| if err != nil { | ||
| return false, fmt.Errorf("failed to create destination file: %w", err) | ||
| } | ||
| defer dstFile.Close() | ||
|
|
||
| err = fileutils.Reflink(srcFile, dstFile) | ||
| if err != nil { | ||
| logrus.Debugf("reflink test failed: %v", err) | ||
| return false, nil | ||
| } | ||
|
|
||
| dstFile.Close() | ||
| dstContent, err := os.ReadFile(dstPath) | ||
| if err != nil { | ||
| return false, fmt.Errorf("failed to read destination file: %w", err) | ||
| } | ||
|
|
||
| if string(dstContent) != string(testData) { | ||
| return false, fmt.Errorf("reflink data mismatch") | ||
| } | ||
|
|
||
| return true, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| //go:build linux | ||
|
|
||
| package overlay | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestCheckSupportsReflinks(t *testing.T) { | ||
| tmpHome := t.TempDir() | ||
| tmpRunHome := t.TempDir() | ||
|
|
||
| supported, err := checkSupportsReflinks(tmpHome, tmpRunHome) | ||
| if err != nil { | ||
| t.Fatalf("checkSupportsReflinks failed: %v", err) | ||
| } | ||
|
|
||
| cachedSupported, _, err := cachedFeatureCheck(tmpRunHome, "reflinks") | ||
| if err != nil { | ||
| t.Fatalf("cachedFeatureCheck failed: %v", err) | ||
| } | ||
|
|
||
| if supported != cachedSupported { | ||
| t.Errorf("cached result mismatch: got %v, want %v", cachedSupported, supported) | ||
| } | ||
|
|
||
| supported2, err := checkSupportsReflinks(tmpHome, tmpRunHome) | ||
| if err != nil { | ||
| t.Fatalf("checkSupportsReflinks second call failed: %v", err) | ||
| } | ||
|
|
||
| if supported != supported2 { | ||
| t.Errorf("second call result mismatch: got %v, want %v", supported2, supported) | ||
| } | ||
| } | ||
|
|
||
| func TestTestReflinkSupport(t *testing.T) { | ||
| tmpDir := t.TempDir() | ||
|
|
||
| supported, err := testReflinkSupport(tmpDir) | ||
| if err != nil { | ||
| t.Logf("testReflinkSupport error (may be expected on non-reflink filesystem): %v", err) | ||
| } | ||
|
|
||
| srcPath := filepath.Join(tmpDir, ".reflink-test-src") | ||
| dstPath := filepath.Join(tmpDir, ".reflink-test-dst") | ||
|
|
||
| if _, err := os.Stat(srcPath); !os.IsNotExist(err) { | ||
| t.Errorf("source file was not cleaned up: %v", err) | ||
| } | ||
| if _, err := os.Stat(dstPath); !os.IsNotExist(err) { | ||
| t.Errorf("destination file was not cleaned up: %v", err) | ||
| } | ||
|
|
||
| t.Logf("Reflink support on this filesystem: %v", supported) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The status field is targeted at human readers and is not an appropriate mechanism for API consumers. (E.g., purely hypothetically, it might be localized!)
(Also, well, the
containers-storagetool is rarely given to users as a supported binary.)Throughout the Go codebase, this needs to be an explicit API (
DedupPossibleInPrinciple?) which returns a boolean. And then we can talk about whether / how it is consumable from shell scripts.