diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-06-25 14:02:49 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-06-25 14:02:49 -0400 |
commit | 90b835db69d589de559462d988cb3fae5cf1ef49 (patch) | |
tree | 1ca86a1bb3d0127ae8267467e8dff19c68046720 /vendor | |
parent | 65fb42ad55647ebceb8057c4562da0d39da1382d (diff) | |
download | podman-90b835db69d589de559462d988cb3fae5cf1ef49.tar.gz podman-90b835db69d589de559462d988cb3fae5cf1ef49.tar.bz2 podman-90b835db69d589de559462d988cb3fae5cf1ef49.zip |
Update c/storage to 67bf6c9b41967780f4bcb5725c00283ad6397679
Pick up caching of overlay feature checks
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'vendor')
9 files changed, 145 insertions, 57 deletions
diff --git a/vendor/github.com/containers/storage/drivers/aufs/aufs.go b/vendor/github.com/containers/storage/drivers/aufs/aufs.go index e821bc0c5..3b4562bdd 100644 --- a/vendor/github.com/containers/storage/drivers/aufs/aufs.go +++ b/vendor/github.com/containers/storage/drivers/aufs/aufs.go @@ -83,7 +83,7 @@ type Driver struct { // Init returns a new AUFS driver. // An error is returned if AUFS is not supported. -func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { +func Init(home string, options graphdriver.Options) (graphdriver.Driver, error) { // Try to load the aufs kernel module if err := supportsAufs(); err != nil { @@ -91,7 +91,7 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap } - fsMagic, err := graphdriver.GetFSMagic(root) + fsMagic, err := graphdriver.GetFSMagic(home) if err != nil { return nil, err } @@ -106,7 +106,7 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap } var mountOptions string - for _, option := range options { + for _, option := range options.DriverOptions { key, val, err := parsers.ParseKeyValueOpt(option) if err != nil { return nil, err @@ -126,36 +126,36 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap } a := &Driver{ - root: root, - uidMaps: uidMaps, - gidMaps: gidMaps, + root: home, + uidMaps: options.UIDMaps, + gidMaps: options.GIDMaps, pathCache: make(map[string]string), ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicAufs)), locker: locker.New(), mountOptions: mountOptions, } - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) + rootUID, rootGID, err := idtools.GetRootUIDGID(options.UIDMaps, options.GIDMaps) if err != nil { return nil, err } // Create the root aufs driver dir and return // if it already exists // If not populate the dir structure - if err := idtools.MkdirAllAs(root, 0700, rootUID, rootGID); err != nil { + if err := idtools.MkdirAllAs(home, 0700, rootUID, rootGID); err != nil { if os.IsExist(err) { return a, nil } return nil, err } - if err := mountpk.MakePrivate(root); err != nil { + if err := mountpk.MakePrivate(home); err != nil { return nil, err } // Populate the dir structure for _, p := range paths { - if err := idtools.MkdirAllAs(path.Join(root, p), 0700, rootUID, rootGID); err != nil { + if err := idtools.MkdirAllAs(path.Join(home, p), 0700, rootUID, rootGID); err != nil { return nil, err } } @@ -165,7 +165,7 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap }) for _, path := range []string{"mnt", "diff"} { - p := filepath.Join(root, path) + p := filepath.Join(home, path) entries, err := ioutil.ReadDir(p) if err != nil { logger.WithError(err).WithField("dir", p).Error("error reading dir entries") diff --git a/vendor/github.com/containers/storage/drivers/btrfs/btrfs.go b/vendor/github.com/containers/storage/drivers/btrfs/btrfs.go index 30254d9fb..6f632a98d 100644 --- a/vendor/github.com/containers/storage/drivers/btrfs/btrfs.go +++ b/vendor/github.com/containers/storage/drivers/btrfs/btrfs.go @@ -49,7 +49,7 @@ type btrfsOptions struct { // Init returns a new BTRFS driver. // An error is returned if BTRFS is not supported. -func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { +func Init(home string, options graphdriver.Options) (graphdriver.Driver, error) { fsMagic, err := graphdriver.GetFSMagic(home) if err != nil { @@ -60,7 +60,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap return nil, errors.Wrapf(graphdriver.ErrPrerequisites, "%q is not on a btrfs filesystem", home) } - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) + rootUID, rootGID, err := idtools.GetRootUIDGID(options.UIDMaps, options.GIDMaps) if err != nil { return nil, err } @@ -72,15 +72,15 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap return nil, err } - opt, userDiskQuota, err := parseOptions(options) + opt, userDiskQuota, err := parseOptions(options.DriverOptions) if err != nil { return nil, err } driver := &Driver{ home: home, - uidMaps: uidMaps, - gidMaps: gidMaps, + uidMaps: options.UIDMaps, + gidMaps: options.GIDMaps, options: opt, } diff --git a/vendor/github.com/containers/storage/drivers/devmapper/driver.go b/vendor/github.com/containers/storage/drivers/devmapper/driver.go index 13677c93a..f384a6242 100644 --- a/vendor/github.com/containers/storage/drivers/devmapper/driver.go +++ b/vendor/github.com/containers/storage/drivers/devmapper/driver.go @@ -34,8 +34,8 @@ type Driver struct { } // Init creates a driver with the given home and the set of options. -func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - deviceSet, err := NewDeviceSet(home, true, options, uidMaps, gidMaps) +func Init(home string, options graphdriver.Options) (graphdriver.Driver, error) { + deviceSet, err := NewDeviceSet(home, true, options.DriverOptions, options.UIDMaps, options.GIDMaps) if err != nil { return nil, err } @@ -47,8 +47,8 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap d := &Driver{ DeviceSet: deviceSet, home: home, - uidMaps: uidMaps, - gidMaps: gidMaps, + uidMaps: options.UIDMaps, + gidMaps: options.GIDMaps, ctr: graphdriver.NewRefCounter(graphdriver.NewDefaultChecker()), locker: locker.New(), } diff --git a/vendor/github.com/containers/storage/drivers/driver.go b/vendor/github.com/containers/storage/drivers/driver.go index dda172574..ac4775f76 100644 --- a/vendor/github.com/containers/storage/drivers/driver.go +++ b/vendor/github.com/containers/storage/drivers/driver.go @@ -53,7 +53,7 @@ type MountOpts struct { } // InitFunc initializes the storage driver. -type InitFunc func(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (Driver, error) +type InitFunc func(homedir string, options Options) (Driver, error) // ProtoDriver defines the basic capabilities of a driver. // This interface exists solely to be a minimum set of methods @@ -202,7 +202,7 @@ func Register(name string, initFunc InitFunc) error { // GetDriver initializes and returns the registered driver func GetDriver(name string, config Options) (Driver, error) { if initFunc, exists := drivers[name]; exists { - return initFunc(filepath.Join(config.Root, name), config.DriverOptions, config.UIDMaps, config.GIDMaps) + return initFunc(filepath.Join(config.Root, name), config) } logrus.Errorf("Failed to GetDriver graph %s %s", name, config.Root) @@ -210,9 +210,9 @@ func GetDriver(name string, config Options) (Driver, error) { } // getBuiltinDriver initializes and returns the registered driver, but does not try to load from plugins -func getBuiltinDriver(name, home string, options []string, uidMaps, gidMaps []idtools.IDMap) (Driver, error) { +func getBuiltinDriver(name, home string, options Options) (Driver, error) { if initFunc, exists := drivers[name]; exists { - return initFunc(filepath.Join(home, name), options, uidMaps, gidMaps) + return initFunc(filepath.Join(home, name), options) } logrus.Errorf("Failed to built-in GetDriver graph %s %s", name, home) return nil, errors.Wrapf(ErrNotSupported, "failed to built-in GetDriver graph %s %s", name, home) @@ -221,6 +221,7 @@ func getBuiltinDriver(name, home string, options []string, uidMaps, gidMaps []id // Options is used to initialize a graphdriver type Options struct { Root string + RunRoot string DriverOptions []string UIDMaps []idtools.IDMap GIDMaps []idtools.IDMap @@ -244,7 +245,7 @@ func New(name string, config Options) (Driver, error) { if _, prior := driversMap[name]; prior { // of the state found from prior drivers, check in order of our priority // which we would prefer - driver, err := getBuiltinDriver(name, config.Root, config.DriverOptions, config.UIDMaps, config.GIDMaps) + driver, err := getBuiltinDriver(name, config.Root, config) if err != nil { // unlike below, we will return error here, because there is prior // state, and now it is no longer supported/prereq/compatible, so @@ -272,7 +273,7 @@ func New(name string, config Options) (Driver, error) { // Check for priority drivers first for _, name := range priority { - driver, err := getBuiltinDriver(name, config.Root, config.DriverOptions, config.UIDMaps, config.GIDMaps) + driver, err := getBuiltinDriver(name, config.Root, config) if err != nil { if isDriverNotSupported(err) { continue @@ -284,7 +285,7 @@ func New(name string, config Options) (Driver, error) { // Check all registered drivers if no priority driver is found for name, initFunc := range drivers { - driver, err := initFunc(filepath.Join(config.Root, name), config.DriverOptions, config.UIDMaps, config.GIDMaps) + driver, err := initFunc(filepath.Join(config.Root, name), config) if err != nil { if isDriverNotSupported(err) { continue diff --git a/vendor/github.com/containers/storage/drivers/overlay/overlay.go b/vendor/github.com/containers/storage/drivers/overlay/overlay.go index 57d6dd63a..262734d31 100644 --- a/vendor/github.com/containers/storage/drivers/overlay/overlay.go +++ b/vendor/github.com/containers/storage/drivers/overlay/overlay.go @@ -97,6 +97,7 @@ type overlayOptions struct { type Driver struct { name string home string + runhome string uidMaps []idtools.IDMap gidMaps []idtools.IDMap ctr *graphdriver.RefCounter @@ -125,8 +126,8 @@ func init() { // Init returns the a native diff driver for overlay filesystem. // If overlay filesystem is not supported on the host, a wrapped graphdriver.ErrNotSupported is returned as error. // If an overlay filesystem is not supported over an existing filesystem then a wrapped graphdriver.ErrIncompatibleFS is returned. -func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { - opts, err := parseOptions(options) +func Init(home string, options graphdriver.Options) (graphdriver.Driver, error) { + opts, err := parseOptions(options.DriverOptions) if err != nil { return nil, err } @@ -148,7 +149,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap } } - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) + rootUID, rootGID, err := idtools.GetRootUIDGID(options.UIDMaps, options.GIDMaps) if err != nil { return nil, err } @@ -157,32 +158,72 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap if err := idtools.MkdirAllAs(path.Join(home, linkDir), 0700, rootUID, rootGID); err != nil && !os.IsExist(err) { return nil, err } + runhome := filepath.Join(options.RunRoot, filepath.Base(home)) + if err := idtools.MkdirAllAs(runhome, 0700, rootUID, rootGID); err != nil && !os.IsExist(err) { + return nil, err + } var usingMetacopy bool var supportsDType bool if opts.mountProgram != "" { supportsDType = true } else { - supportsDType, err = supportsOverlay(home, fsMagic, rootUID, rootGID) - if err != nil { - os.Remove(filepath.Join(home, linkDir)) - os.Remove(home) - patherr, ok := err.(*os.PathError) - if ok && patherr.Err == syscall.ENOSPC { + feature := "overlay" + overlayCacheResult, overlayCacheText, err := cachedFeatureCheck(runhome, feature) + if err == nil { + if overlayCacheResult { + logrus.Debugf("cached value indicated that overlay is supported") + } else { + logrus.Debugf("cached value indicated that overlay is not supported") + } + supportsDType = overlayCacheResult + if !supportsDType { + return nil, errors.New(overlayCacheText) + } + } else { + supportsDType, err = supportsOverlay(home, fsMagic, rootUID, rootGID) + if err != nil { + os.Remove(filepath.Join(home, linkDir)) + os.Remove(home) + patherr, ok := err.(*os.PathError) + if ok && patherr.Err == syscall.ENOSPC { + return nil, err + } + err = errors.Wrap(err, "kernel does not support overlay fs") + if err2 := cachedFeatureRecord(runhome, feature, false, err.Error()); err2 != nil { + return nil, errors.Wrapf(err2, "error recording overlay not being supported (%v)", err) + } return nil, err } - return nil, errors.Wrap(err, "kernel does not support overlay fs") + if err = cachedFeatureRecord(runhome, feature, supportsDType, ""); err != nil { + return nil, errors.Wrap(err, "error recording overlay support status") + } } - usingMetacopy, err = doesMetacopy(home, opts.mountOptions) + + feature = fmt.Sprintf("metacopy(%s)", opts.mountOptions) + metacopyCacheResult, _, err := cachedFeatureCheck(runhome, feature) if err == nil { - if usingMetacopy { - logrus.Debugf("overlay test mount indicated that metacopy is being used") + if metacopyCacheResult { + logrus.Debugf("cached value indicated that metacopy is being used") } else { - logrus.Debugf("overlay test mount indicated that metacopy is not being used") + logrus.Debugf("cached value indicated that metacopy is not being used") } + usingMetacopy = metacopyCacheResult } else { - logrus.Warnf("overlay test mount did not indicate whether or not metacopy is being used: %v", err) - return nil, err + usingMetacopy, err = doesMetacopy(home, opts.mountOptions) + if err == nil { + if usingMetacopy { + logrus.Debugf("overlay test mount indicated that metacopy is being used") + } else { + logrus.Debugf("overlay test mount indicated that metacopy is not being used") + } + if err = cachedFeatureRecord(runhome, feature, usingMetacopy, ""); err != nil { + return nil, errors.Wrap(err, "error recording metacopy-being-used status") + } + } else { + logrus.Warnf("overlay test mount did not indicate whether or not metacopy is being used: %v", err) + return nil, err + } } } @@ -201,8 +242,9 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap d := &Driver{ name: "overlay", home: home, - uidMaps: uidMaps, - gidMaps: gidMaps, + runhome: runhome, + uidMaps: options.UIDMaps, + gidMaps: options.GIDMaps, ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicOverlay)), supportsDType: supportsDType, usingMetacopy: usingMetacopy, @@ -291,6 +333,36 @@ func parseOptions(options []string) (*overlayOptions, error) { return o, nil } +func cachedFeatureSet(feature string, set bool) string { + if set { + return fmt.Sprintf("%s-true", feature) + } + return fmt.Sprintf("%s-false", feature) +} + +func cachedFeatureCheck(runhome, feature string) (supported bool, text string, err error) { + content, err := ioutil.ReadFile(filepath.Join(runhome, cachedFeatureSet(feature, true))) + if err == nil { + return true, string(content), nil + } + content, err = ioutil.ReadFile(filepath.Join(runhome, cachedFeatureSet(feature, false))) + if err == nil { + return false, string(content), nil + } + return false, "", err +} + +func cachedFeatureRecord(runhome, feature string, supported bool, text string) (err error) { + f, err := os.Create(filepath.Join(runhome, cachedFeatureSet(feature, supported))) + if f != nil { + if text != "" { + fmt.Fprintf(f, "%s", text) + } + f.Close() + } + return err +} + func supportsOverlay(home string, homeMagic graphdriver.FsMagic, rootUID, rootGID int) (supportsDType bool, err error) { // We can try to modprobe overlay first @@ -363,10 +435,24 @@ func (d *Driver) useNaiveDiff() bool { useNaiveDiffOnly = true return } + feature := fmt.Sprintf("native-diff(%s)", d.options.mountOptions) + nativeDiffCacheResult, nativeDiffCacheText, err := cachedFeatureCheck(d.runhome, feature) + if err == nil { + if nativeDiffCacheResult { + logrus.Debugf("cached value indicated that native-diff is usable") + } else { + logrus.Debugf("cached value indicated that native-diff is not being used") + logrus.Warn(nativeDiffCacheText) + } + useNaiveDiffOnly = !nativeDiffCacheResult + return + } if err := doesSupportNativeDiff(d.home, d.options.mountOptions); err != nil { - logrus.Warnf("Not using native diff for overlay, this may cause degraded performance for building images: %v", err) + nativeDiffCacheText = fmt.Sprintf("Not using native diff for overlay, this may cause degraded performance for building images: %v", err) + logrus.Warn(nativeDiffCacheText) useNaiveDiffOnly = true } + cachedFeatureRecord(d.runhome, feature, !useNaiveDiffOnly, nativeDiffCacheText) }) return useNaiveDiffOnly } diff --git a/vendor/github.com/containers/storage/drivers/vfs/driver.go b/vendor/github.com/containers/storage/drivers/vfs/driver.go index 5941ccc17..8b981632a 100644 --- a/vendor/github.com/containers/storage/drivers/vfs/driver.go +++ b/vendor/github.com/containers/storage/drivers/vfs/driver.go @@ -24,16 +24,16 @@ func init() { // Init returns a new VFS driver. // This sets the home directory for the driver and returns NaiveDiffDriver. -func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { +func Init(home string, options graphdriver.Options) (graphdriver.Driver, error) { d := &Driver{ homes: []string{home}, - idMappings: idtools.NewIDMappingsFromMaps(uidMaps, gidMaps), + idMappings: idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps), } rootIDs := d.idMappings.RootPair() if err := idtools.MkdirAllAndChown(home, 0700, rootIDs); err != nil { return nil, err } - for _, option := range options { + for _, option := range options.DriverOptions { if strings.HasPrefix(option, "vfs.imagestore=") { d.homes = append(d.homes, strings.Split(option[15:], ",")...) continue @@ -59,7 +59,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap } } if d.ostreeRepo != "" { - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) + rootUID, rootGID, err := idtools.GetRootUIDGID(options.UIDMaps, options.GIDMaps) if err != nil { return nil, err } diff --git a/vendor/github.com/containers/storage/drivers/windows/windows.go b/vendor/github.com/containers/storage/drivers/windows/windows.go index c7df1c1fe..f0437a275 100644 --- a/vendor/github.com/containers/storage/drivers/windows/windows.go +++ b/vendor/github.com/containers/storage/drivers/windows/windows.go @@ -83,10 +83,10 @@ type Driver struct { } // InitFilter returns a new Windows storage filter driver. -func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { +func InitFilter(home string, options graphdriver.Options) (graphdriver.Driver, error) { logrus.Debugf("WindowsGraphDriver InitFilter at %s", home) - for _, option := range options { + for _, option := range options.DriverOptions { if strings.HasPrefix(option, "windows.mountopt=") { return nil, fmt.Errorf("windows driver does not support mount options") } else { diff --git a/vendor/github.com/containers/storage/drivers/zfs/zfs.go b/vendor/github.com/containers/storage/drivers/zfs/zfs.go index eaa9e8bc5..a2bf5565b 100644 --- a/vendor/github.com/containers/storage/drivers/zfs/zfs.go +++ b/vendor/github.com/containers/storage/drivers/zfs/zfs.go @@ -44,7 +44,7 @@ func (*Logger) Log(cmd []string) { // Init returns a new ZFS driver. // It takes base mount path and an array of options which are represented as key value pairs. // Each option is in the for key=value. 'zfs.fsname' is expected to be a valid key in the options. -func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { +func Init(base string, opt graphdriver.Options) (graphdriver.Driver, error) { var err error logger := logrus.WithField("storage-driver", "zfs") @@ -61,7 +61,7 @@ func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdri } defer file.Close() - options, err := parseOptions(opt) + options, err := parseOptions(opt.DriverOptions) if err != nil { return nil, err } @@ -103,7 +103,7 @@ func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdri return nil, fmt.Errorf("BUG: zfs get all -t filesystem -rHp '%s' should contain '%s'", options.fsName, options.fsName) } - rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) + rootUID, rootGID, err := idtools.GetRootUIDGID(opt.UIDMaps, opt.GIDMaps) if err != nil { return nil, fmt.Errorf("Failed to get root uid/guid: %v", err) } @@ -115,8 +115,8 @@ func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdri dataset: rootDataset, options: options, filesystemsCache: filesystemsCache, - uidMaps: uidMaps, - gidMaps: gidMaps, + uidMaps: opt.UIDMaps, + gidMaps: opt.GIDMaps, ctr: graphdriver.NewRefCounter(graphdriver.NewDefaultChecker()), } return graphdriver.NewNaiveDiffDriver(d, graphdriver.NewNaiveLayerIDMapUpdater(d)), nil diff --git a/vendor/github.com/containers/storage/store.go b/vendor/github.com/containers/storage/store.go index 856c73e51..acc22be27 100644 --- a/vendor/github.com/containers/storage/store.go +++ b/vendor/github.com/containers/storage/store.go @@ -695,6 +695,7 @@ func (s *store) getGraphDriver() (drivers.Driver, error) { } config := drivers.Options{ Root: s.graphRoot, + RunRoot: s.runRoot, DriverOptions: s.graphOptions, UIDMaps: s.uidMap, GIDMaps: s.gidMap, |