-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mountinfo.Mounted: optimize by adding fast paths
Add two fast paths to avoid (slow) mountinfo parsing: 1. In case path does not exist, it is definitely NOT a mount point. 2. In case path's st.Dev differs from that of its parent, it is definitely a mount point. In all the other cases (including bind mounts, case of path="/", other errors from unix.Lstat) the code falls back to the old slow method of parsing mountinfo. Signed-off-by: Kir Kolyshkin <[email protected]>
- Loading branch information
Showing
6 changed files
with
55 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module github.com/moby/sys/mountinfo | ||
|
||
go 1.14 | ||
|
||
require golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae |
This file contains 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,2 @@ | ||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= | ||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
This file contains 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 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,35 @@ | ||
// +build !windows | ||
|
||
package mountinfo | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func mounted(path string) (bool, error) { | ||
var st unix.Stat_t | ||
|
||
err := unix.Lstat(path, &st) | ||
switch err { | ||
case unix.ENOENT: | ||
// Nonexistent path, so not a mount point. | ||
return false, nil | ||
case nil: | ||
dev := st.Dev | ||
err = unix.Lstat(filepath.Dir(path), &st) | ||
if err == nil && dev != st.Dev { | ||
// Device number differs from that of parent, | ||
// so definitely a mount point. | ||
return true, nil | ||
} | ||
} | ||
|
||
entries, err := GetMounts(SingleEntryFilter(path)) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
return len(entries) > 0, nil | ||
} |
This file contains 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 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