aboutsummaryrefslogtreecommitdiff
path: root/pkg/spec/storage.go
diff options
context:
space:
mode:
authorKir Kolyshkin <kolyshkin@gmail.com>2020-03-31 01:59:44 -0700
committerKir Kolyshkin <kolyshkin@gmail.com>2020-04-02 07:52:34 -0700
commite0614367ca27c2e47649e08291e0f1d19d42232e (patch)
tree8eeb95dd01fc5bed27cd08ffc61244950bed7d56 /pkg/spec/storage.go
parentf2c42a3958d12b45375aeb2384a3a8a103203c1c (diff)
downloadpodman-e0614367ca27c2e47649e08291e0f1d19d42232e.tar.gz
podman-e0614367ca27c2e47649e08291e0f1d19d42232e.tar.bz2
podman-e0614367ca27c2e47649e08291e0f1d19d42232e.zip
pkg/spec.InitFSMounts: optimize
Instead of getting mount options from /proc/self/mountinfo, which is very costly to read/parse (and can even be unreliable), let's use statfs(2) to figure out the flags we need. [v2: move getting default options to pkg/util, make it linux-specific] Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Diffstat (limited to 'pkg/spec/storage.go')
-rw-r--r--pkg/spec/storage.go60
1 files changed, 5 insertions, 55 deletions
diff --git a/pkg/spec/storage.go b/pkg/spec/storage.go
index 335907d12..68a84d638 100644
--- a/pkg/spec/storage.go
+++ b/pkg/spec/storage.go
@@ -10,7 +10,6 @@ import (
"github.com/containers/buildah/pkg/parse"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/util"
- pmount "github.com/containers/storage/pkg/mount"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -856,44 +855,16 @@ func SupercedeUserMounts(mounts []spec.Mount, configMount []spec.Mount) []spec.M
// Ensure mount options on all mounts are correct
func InitFSMounts(mounts []spec.Mount) error {
- // We need to look up mounts so we can figure out the proper mount flags
- // to apply.
- systemMounts, err := pmount.GetMounts()
- if err != nil {
- return errors.Wrapf(err, "error retrieving system mounts to look up mount options")
- }
-
for i, m := range mounts {
- if m.Type == TypeBind {
- baseMnt, err := findMount(m.Source, systemMounts)
- if err != nil {
- return errors.Wrapf(err, "error looking up mountpoint for mount %s", m.Source)
- }
- var noexec, nosuid, nodev bool
- for _, baseOpt := range strings.Split(baseMnt.Opts, ",") {
- switch baseOpt {
- case "noexec":
- noexec = true
- case "nosuid":
- nosuid = true
- case "nodev":
- nodev = true
- }
- }
-
- defaultMountOpts := new(util.DefaultMountOptions)
- defaultMountOpts.Noexec = noexec
- defaultMountOpts.Nosuid = nosuid
- defaultMountOpts.Nodev = nodev
-
- opts, err := util.ProcessOptions(m.Options, false, defaultMountOpts)
+ switch {
+ case m.Type == TypeBind:
+ opts, err := util.ProcessOptions(m.Options, false, m.Source)
if err != nil {
return err
}
mounts[i].Options = opts
- }
- if m.Type == TypeTmpfs && filepath.Clean(m.Destination) != "/dev" {
- opts, err := util.ProcessOptions(m.Options, true, nil)
+ case m.Type == TypeTmpfs && filepath.Clean(m.Destination) != "/dev":
+ opts, err := util.ProcessOptions(m.Options, true, "")
if err != nil {
return err
}
@@ -902,24 +873,3 @@ func InitFSMounts(mounts []spec.Mount) error {
}
return nil
}
-
-// TODO: We could make this a bit faster by building a tree of the mountpoints
-// and traversing it to identify the correct mount.
-func findMount(target string, mounts []*pmount.Info) (*pmount.Info, error) {
- var err error
- target, err = filepath.Abs(target)
- if err != nil {
- return nil, errors.Wrapf(err, "cannot resolve %s", target)
- }
- var bestSoFar *pmount.Info
- for _, i := range mounts {
- if bestSoFar != nil && len(bestSoFar.Mountpoint) > len(i.Mountpoint) {
- // Won't be better than what we have already found
- continue
- }
- if strings.HasPrefix(target, i.Mountpoint) {
- bestSoFar = i
- }
- }
- return bestSoFar, nil
-}