Merge pull request #2162 from rhatdan/vendor

Vendor in latest containers/storage
This commit is contained in:
OpenShift Merge Robot
2019-01-16 18:50:01 +01:00
committed by GitHub
7 changed files with 52 additions and 98 deletions

View File

@ -16,7 +16,7 @@ github.com/containerd/continuity 004b46473808b3e7a4a3049c20e4376c91eb966d
github.com/containernetworking/cni v0.7.0-alpha1 github.com/containernetworking/cni v0.7.0-alpha1
github.com/containernetworking/plugins v0.7.4 github.com/containernetworking/plugins v0.7.4
github.com/containers/image v1.3 github.com/containers/image v1.3
github.com/containers/storage v1.4 github.com/containers/storage v1.6
github.com/containers/psgo v1.1 github.com/containers/psgo v1.1
github.com/coreos/go-systemd v14 github.com/coreos/go-systemd v14
github.com/cri-o/ocicni 2d2983e40c242322a56c22a903785e7f83eb378c github.com/cri-o/ocicni 2d2983e40c242322a56c22a903785e7f83eb378c

View File

@ -793,6 +793,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
mountTarget = path.Join(id, "merged") mountTarget = path.Join(id, "merged")
} }
flags, data := mount.ParseOptions(mountData) flags, data := mount.ParseOptions(mountData)
logrus.Debugf("overlay: mount_data=%s", mountData)
if err := mountFunc("overlay", mountTarget, "overlay", uintptr(flags), data); err != nil { if err := mountFunc("overlay", mountTarget, "overlay", uintptr(flags), data); err != nil {
return "", fmt.Errorf("error creating overlay mount to %s: %v", mountTarget, err) return "", fmt.Errorf("error creating overlay mount to %s: %v", mountTarget, err)
} }
@ -986,6 +987,7 @@ func (d *Driver) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMapp
// Mount the new layer and handle ownership changes and possible copy_ups in it. // Mount the new layer and handle ownership changes and possible copy_ups in it.
options := graphdriver.MountOpts{ options := graphdriver.MountOpts{
MountLabel: mountLabel, MountLabel: mountLabel,
Options: strings.Split(d.options.mountOptions, ","),
} }
layerFs, err := d.get(id, true, options) layerFs, err := d.get(id, true, options)
if err != nil { if err != nil {

View File

@ -1,4 +1,4 @@
// +build linux freebsd solaris // +build linux freebsd
package zfs package zfs
@ -16,7 +16,7 @@ import (
"github.com/containers/storage/pkg/idtools" "github.com/containers/storage/pkg/idtools"
"github.com/containers/storage/pkg/mount" "github.com/containers/storage/pkg/mount"
"github.com/containers/storage/pkg/parsers" "github.com/containers/storage/pkg/parsers"
zfs "github.com/mistifyio/go-zfs" "github.com/mistifyio/go-zfs"
"github.com/opencontainers/selinux/go-selinux/label" "github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -38,7 +38,7 @@ type Logger struct{}
// Log wraps log message from ZFS driver with a prefix '[zfs]'. // Log wraps log message from ZFS driver with a prefix '[zfs]'.
func (*Logger) Log(cmd []string) { func (*Logger) Log(cmd []string) {
logrus.Debugf("[zfs] %s", strings.Join(cmd, " ")) logrus.WithField("storage-driver", "zfs").Debugf("%s", strings.Join(cmd, " "))
} }
// Init returns a new ZFS driver. // Init returns a new ZFS driver.
@ -47,14 +47,16 @@ func (*Logger) Log(cmd []string) {
func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
var err error var err error
logger := logrus.WithField("storage-driver", "zfs")
if _, err := exec.LookPath("zfs"); err != nil { if _, err := exec.LookPath("zfs"); err != nil {
logrus.Debugf("[zfs] zfs command is not available: %v", err) logger.Debugf("zfs command is not available: %v", err)
return nil, errors.Wrap(graphdriver.ErrPrerequisites, "the 'zfs' command is not available") return nil, errors.Wrap(graphdriver.ErrPrerequisites, "the 'zfs' command is not available")
} }
file, err := os.OpenFile("/dev/zfs", os.O_RDWR, 0600) file, err := os.OpenFile("/dev/zfs", os.O_RDWR, 0600)
if err != nil { if err != nil {
logrus.Debugf("[zfs] cannot open /dev/zfs: %v", err) logger.Debugf("cannot open /dev/zfs: %v", err)
return nil, errors.Wrapf(graphdriver.ErrPrerequisites, "could not open /dev/zfs: %v", err) return nil, errors.Wrapf(graphdriver.ErrPrerequisites, "could not open /dev/zfs: %v", err)
} }
defer file.Close() defer file.Close()
@ -109,9 +111,6 @@ func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdri
return nil, fmt.Errorf("Failed to create '%s': %v", base, err) return nil, fmt.Errorf("Failed to create '%s': %v", base, err)
} }
if err := mount.MakePrivate(base); err != nil {
return nil, err
}
d := &Driver{ d := &Driver{
dataset: rootDataset, dataset: rootDataset,
options: options, options: options,
@ -157,7 +156,7 @@ func lookupZfsDataset(rootdir string) (string, error) {
} }
for _, m := range mounts { for _, m := range mounts {
if err := unix.Stat(m.Mountpoint, &stat); err != nil { if err := unix.Stat(m.Mountpoint, &stat); err != nil {
logrus.Debugf("[zfs] failed to stat '%s' while scanning for zfs mount: %v", m.Mountpoint, err) logrus.WithField("storage-driver", "zfs").Debugf("failed to stat '%s' while scanning for zfs mount: %v", m.Mountpoint, err)
continue // may fail on fuse file systems continue // may fail on fuse file systems
} }
@ -184,7 +183,7 @@ func (d *Driver) String() string {
return "zfs" return "zfs"
} }
// Cleanup is used to implement graphdriver.ProtoDriver. There is no cleanup required for this driver. // Cleanup is called on when program exits, it is a no-op for ZFS.
func (d *Driver) Cleanup() error { func (d *Driver) Cleanup() error {
return nil return nil
} }
@ -360,11 +359,25 @@ func (d *Driver) Remove(id string) error {
} }
// Get returns the mountpoint for the given id after creating the target directories if necessary. // Get returns the mountpoint for the given id after creating the target directories if necessary.
func (d *Driver) Get(id string, options graphdriver.MountOpts) (string, error) { func (d *Driver) Get(id string, options graphdriver.MountOpts) (_ string, retErr error) {
mountpoint := d.mountPath(id) mountpoint := d.mountPath(id)
if count := d.ctr.Increment(mountpoint); count > 1 { if count := d.ctr.Increment(mountpoint); count > 1 {
return mountpoint, nil return mountpoint, nil
} }
defer func() {
if retErr != nil {
if c := d.ctr.Decrement(mountpoint); c <= 0 {
if mntErr := unix.Unmount(mountpoint, 0); mntErr != nil {
logrus.WithField("storage-driver", "zfs").Errorf("Error unmounting %v: %v", mountpoint, mntErr)
}
if rmErr := unix.Rmdir(mountpoint); rmErr != nil && !os.IsNotExist(rmErr) {
logrus.WithField("storage-driver", "zfs").Debugf("Failed to remove %s: %v", id, rmErr)
}
}
}
}()
mountOptions := d.options.mountOptions mountOptions := d.options.mountOptions
if len(options.Options) > 0 { if len(options.Options) > 0 {
@ -373,29 +386,24 @@ func (d *Driver) Get(id string, options graphdriver.MountOpts) (string, error) {
filesystem := d.zfsPath(id) filesystem := d.zfsPath(id)
opts := label.FormatMountLabel(mountOptions, options.MountLabel) opts := label.FormatMountLabel(mountOptions, options.MountLabel)
logrus.Debugf(`[zfs] mount("%s", "%s", "%s")`, filesystem, mountpoint, opts) logrus.WithField("storage-driver", "zfs").Debugf(`mount("%s", "%s", "%s")`, filesystem, mountpoint, opts)
rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps) rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps)
if err != nil { if err != nil {
d.ctr.Decrement(mountpoint)
return "", err return "", err
} }
// Create the target directories if they don't exist // Create the target directories if they don't exist
if err := idtools.MkdirAllAs(mountpoint, 0755, rootUID, rootGID); err != nil { if err := idtools.MkdirAllAs(mountpoint, 0755, rootUID, rootGID); err != nil {
d.ctr.Decrement(mountpoint)
return "", err return "", err
} }
if err := mount.Mount(filesystem, mountpoint, "zfs", opts); err != nil { if err := mount.Mount(filesystem, mountpoint, "zfs", opts); err != nil {
d.ctr.Decrement(mountpoint) return "", errors.Wrap(err, "error creating zfs mount")
return "", fmt.Errorf("error creating zfs mount of %s to %s: %v", filesystem, mountpoint, err)
} }
// this could be our first mount after creation of the filesystem, and the root dir may still have root // this could be our first mount after creation of the filesystem, and the root dir may still have root
// permissions instead of the remapped root uid:gid (if user namespaces are enabled): // permissions instead of the remapped root uid:gid (if user namespaces are enabled):
if err := os.Chown(mountpoint, rootUID, rootGID); err != nil { if err := os.Chown(mountpoint, rootUID, rootGID); err != nil {
mount.Unmount(mountpoint)
d.ctr.Decrement(mountpoint)
return "", fmt.Errorf("error modifying zfs mountpoint (%s) directory ownership: %v", mountpoint, err) return "", fmt.Errorf("error modifying zfs mountpoint (%s) directory ownership: %v", mountpoint, err)
} }
@ -408,16 +416,18 @@ func (d *Driver) Put(id string) error {
if count := d.ctr.Decrement(mountpoint); count > 0 { if count := d.ctr.Decrement(mountpoint); count > 0 {
return nil return nil
} }
mounted, err := graphdriver.Mounted(graphdriver.FsMagicZfs, mountpoint)
if err != nil || !mounted { logger := logrus.WithField("storage-driver", "zfs")
return err
logger.Debugf(`unmount("%s")`, mountpoint)
if err := unix.Unmount(mountpoint, unix.MNT_DETACH); err != nil {
logger.Warnf("Failed to unmount %s mount %s: %v", id, mountpoint, err)
}
if err := unix.Rmdir(mountpoint); err != nil && !os.IsNotExist(err) {
logger.Debugf("Failed to remove %s mount point %s: %v", id, mountpoint, err)
} }
logrus.Debugf(`[zfs] unmount("%s")`, mountpoint)
if err := mount.Unmount(mountpoint); err != nil {
return fmt.Errorf("error unmounting to %s: %v", mountpoint, err)
}
return nil return nil
} }

View File

@ -18,7 +18,7 @@ func checkRootdirFs(rootdir string) error {
// on FreeBSD buf.Fstypename contains ['z', 'f', 's', 0 ... ] // on FreeBSD buf.Fstypename contains ['z', 'f', 's', 0 ... ]
if (buf.Fstypename[0] != 122) || (buf.Fstypename[1] != 102) || (buf.Fstypename[2] != 115) || (buf.Fstypename[3] != 0) { if (buf.Fstypename[0] != 122) || (buf.Fstypename[1] != 102) || (buf.Fstypename[2] != 115) || (buf.Fstypename[3] != 0) {
logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir) logrus.WithField("storage-driver", "zfs").Debugf("no zfs dataset found for rootdir '%s'", rootdir)
return errors.Wrapf(graphdriver.ErrPrerequisites, "no zfs dataset found for rootdir '%s'", rootdir) return errors.Wrapf(graphdriver.ErrPrerequisites, "no zfs dataset found for rootdir '%s'", rootdir)
} }

View File

@ -1,23 +1,24 @@
package zfs package zfs
import ( import (
"fmt"
"github.com/containers/storage/drivers" "github.com/containers/storage/drivers"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
) )
func checkRootdirFs(rootdir string) error { func checkRootdirFs(rootDir string) error {
var buf unix.Statfs_t fsMagic, err := graphdriver.GetFSMagic(rootDir)
if err := unix.Statfs(rootdir, &buf); err != nil { if err != nil {
return fmt.Errorf("Failed to access '%s': %s", rootdir, err) return err
}
backingFS := "unknown"
if fsName, ok := graphdriver.FsNames[fsMagic]; ok {
backingFS = fsName
} }
if graphdriver.FsMagic(buf.Type) != graphdriver.FsMagicZfs { if fsMagic != graphdriver.FsMagicZfs {
logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir) logrus.WithField("root", rootDir).WithField("backingFS", backingFS).WithField("storage-driver", "zfs").Error("No zfs dataset found for root")
return errors.Wrapf(graphdriver.ErrPrerequisites, "no zfs dataset found for rootdir '%s'", rootdir) return errors.Wrapf(graphdriver.ErrPrerequisites, "no zfs dataset found for rootdir '%s'", rootDir)
} }
return nil return nil

View File

@ -1,59 +0,0 @@
// +build solaris,cgo
package zfs
/*
#include <sys/statvfs.h>
#include <stdlib.h>
static inline struct statvfs *getstatfs(char *s) {
struct statvfs *buf;
int err;
buf = (struct statvfs *)malloc(sizeof(struct statvfs));
err = statvfs(s, buf);
return buf;
}
*/
import "C"
import (
"path/filepath"
"strings"
"unsafe"
"github.com/containers/storage/drivers"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func checkRootdirFs(rootdir string) error {
cs := C.CString(filepath.Dir(rootdir))
defer C.free(unsafe.Pointer(cs))
buf := C.getstatfs(cs)
defer C.free(unsafe.Pointer(buf))
// on Solaris buf.f_basetype contains ['z', 'f', 's', 0 ... ]
if (buf.f_basetype[0] != 122) || (buf.f_basetype[1] != 102) || (buf.f_basetype[2] != 115) ||
(buf.f_basetype[3] != 0) {
logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir)
return errors.Wrapf(graphdriver.ErrPrerequisites, "no zfs dataset found for rootdir '%s'", rootdir)
}
return nil
}
/* rootfs is introduced to comply with the OCI spec
which states that root filesystem must be mounted at <CID>/rootfs/ instead of <CID>/
*/
func getMountpoint(id string) string {
maxlen := 12
// we need to preserve filesystem suffix
suffix := strings.SplitN(id, "-", 2)
if len(suffix) > 1 {
return filepath.Join(id[:maxlen]+"-"+suffix[1], "rootfs", "root")
}
return filepath.Join(id[:maxlen], "rootfs", "root")
}

View File

@ -1,4 +1,4 @@
// +build !linux,!freebsd,!solaris // +build !linux,!freebsd
package zfs package zfs