pkg/containerfs: drop ContainerFS type alias

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider 2022-09-23 14:21:31 -04:00
parent e332c41e9d
commit 9ce2b30b81
29 changed files with 48 additions and 70 deletions

View File

@ -14,7 +14,6 @@ import (
containerpkg "github.com/docker/docker/container"
"github.com/docker/docker/image"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/containerfs"
)
const (
@ -26,7 +25,7 @@ const (
// instructions in the builder.
type Source interface {
// Root returns root path for accessing source
Root() containerfs.ContainerFS
Root() string
// Close allows to signal that the filesystem tree won't be used anymore.
// For Context implementations using a temporary directory, it is recommended to
// delete the temporary directory in Close().
@ -110,6 +109,6 @@ type ROLayer interface {
// RWLayer is active layer that can be read/modified
type RWLayer interface {
Release() error
Root() containerfs.ContainerFS
Root() string
Commit() (ROLayer, error)
}

View File

@ -38,7 +38,7 @@ type pathCache interface {
// copyInfo is a data object which stores the metadata about each source file in
// a copyInstruction
type copyInfo struct {
root containerfs.ContainerFS
root string
path string
hash string
noDecompress bool

View File

@ -14,7 +14,6 @@ import (
"github.com/docker/docker/image"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/go-connections/nat"
"github.com/opencontainers/go-digest"
"gotest.tools/v3/assert"
@ -183,8 +182,8 @@ func TestDeepCopyRunConfig(t *testing.T) {
type MockRWLayer struct{}
func (l *MockRWLayer) Release() error { return nil }
func (l *MockRWLayer) Root() containerfs.ContainerFS { return "" }
func (l *MockRWLayer) Release() error { return nil }
func (l *MockRWLayer) Root() string { return "" }
func (l *MockRWLayer) Commit() (builder.ROLayer, error) {
return &MockROLayer{
diffID: layer.DiffID(digest.Digest("sha256:1234")),

View File

@ -13,7 +13,6 @@ import (
containerpkg "github.com/docker/docker/container"
"github.com/docker/docker/image"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/containerfs"
)
// MockBackend implements the builder.Backend interface for unit testing
@ -143,6 +142,6 @@ func (l *mockRWLayer) Commit() (builder.ROLayer, error) {
return nil, nil
}
func (l *mockRWLayer) Root() containerfs.ContainerFS {
func (l *mockRWLayer) Root() string {
return ""
}

View File

@ -15,7 +15,7 @@ import (
)
type archiveContext struct {
root containerfs.ContainerFS
root string
sums tarsum.FileInfoSums
}
@ -82,7 +82,7 @@ func FromArchive(tarStream io.Reader) (builder.Source, error) {
return tsc, nil
}
func (c *archiveContext) Root() containerfs.ContainerFS {
func (c *archiveContext) Root() string {
return c.root
}
@ -115,7 +115,7 @@ func (c *archiveContext) Hash(path string) (string, error) {
return path, nil // backwards compat TODO: see if really needed
}
func normalize(path string, root containerfs.ContainerFS) (cleanPath, fullPath string, err error) {
func normalize(path string, root string) (cleanPath, fullPath string, err error) {
cleanPath = filepath.Clean(string(filepath.Separator) + path)[1:]
fullPath, err = containerfs.ResolveScopedPath(root, path)
if err != nil {

View File

@ -9,7 +9,6 @@ import (
"testing"
"github.com/docker/docker/builder"
"github.com/docker/docker/pkg/containerfs"
)
const (
@ -105,14 +104,14 @@ func TestProcessShouldLeaveAllFiles(t *testing.T) {
// TODO: remove after moving to a separate pkg
type stubRemote struct {
root containerfs.ContainerFS
root string
}
func (r *stubRemote) Hash(path string) (string, error) {
return "", errors.New("not implemented")
}
func (r *stubRemote) Root() containerfs.ContainerFS {
func (r *stubRemote) Root() string {
return r.root
}
func (r *stubRemote) Close() error {

View File

@ -8,7 +8,6 @@ import (
"strings"
"github.com/docker/docker/builder"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/pools"
"github.com/pkg/errors"
)
@ -16,7 +15,7 @@ import (
// NewLazySource creates a new LazyContext. LazyContext defines a hashed build
// context based on a root directory. Individual files are hashed first time
// they are asked. It is not safe to call methods of LazyContext concurrently.
func NewLazySource(root containerfs.ContainerFS) (builder.Source, error) {
func NewLazySource(root string) (builder.Source, error) {
return &lazySource{
root: root,
sums: make(map[string]string),
@ -24,11 +23,11 @@ func NewLazySource(root containerfs.ContainerFS) (builder.Source, error) {
}
type lazySource struct {
root containerfs.ContainerFS
root string
sums map[string]string
}
func (c *lazySource) Root() containerfs.ContainerFS {
func (c *lazySource) Root() string {
return c.root
}
@ -88,7 +87,7 @@ func (c *lazySource) prepareHash(relPath string, fi os.FileInfo) (string, error)
// Rel makes a path relative to base path. Same as `filepath.Rel` but can also
// handle UUID paths in windows.
func Rel(basepath containerfs.ContainerFS, targpath string) (string, error) {
func Rel(basepath string, targpath string) (string, error) {
// filepath.Rel can't handle UUID paths in windows
if runtime.GOOS == "windows" {
pfx := basepath + `\`

View File

@ -5,7 +5,6 @@ import (
"path/filepath"
"sync"
"github.com/docker/docker/pkg/containerfs"
iradix "github.com/hashicorp/go-immutable-radix"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
@ -19,7 +18,7 @@ type hashed interface {
// CachableSource is a source that contains cache records for its contents
type CachableSource struct {
mu sync.Mutex
root containerfs.ContainerFS
root string
tree *iradix.Tree
txn *iradix.Txn
}
@ -145,7 +144,7 @@ func (cs *CachableSource) Hash(path string) (string, error) {
}
// Root returns a root directory for the source
func (cs *CachableSource) Root() containerfs.ContainerFS {
func (cs *CachableSource) Root() string {
return cs.root
}

View File

@ -61,10 +61,10 @@ type ExitStatus struct {
type Container struct {
StreamConfig *stream.Config
// embed for Container to support states directly.
*State `json:"State"` // Needed for Engine API version <= 1.11
Root string `json:"-"` // Path to the "home" of the container, including metadata.
BaseFS containerfs.ContainerFS `json:"-"` // interface containing graphdriver mount
RWLayer layer.RWLayer `json:"-"`
*State `json:"State"` // Needed for Engine API version <= 1.11
Root string `json:"-"` // Path to the "home" of the container, including metadata.
BaseFS string `json:"-"` // Path to the graphdriver mountpoint
RWLayer layer.RWLayer `json:"-"`
ID string
Created time.Time
Managed bool

View File

@ -38,7 +38,6 @@ import (
"github.com/docker/docker/libnetwork/options"
lntypes "github.com/docker/docker/libnetwork/types"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/parsers/kernel"
@ -1072,8 +1071,8 @@ func removeDefaultBridgeInterface() {
}
}
func setupInitLayer(idMapping idtools.IdentityMapping) func(containerfs.ContainerFS) error {
return func(initPath containerfs.ContainerFS) error {
func setupInitLayer(idMapping idtools.IdentityMapping) func(string) error {
return func(initPath string) error {
return initlayer.Setup(initPath, idMapping.RootPair())
}
}

View File

@ -23,7 +23,6 @@ import (
winlibnetwork "github.com/docker/docker/libnetwork/drivers/windows"
"github.com/docker/docker/libnetwork/netlabel"
"github.com/docker/docker/libnetwork/options"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/parsers/operatingsystem"
@ -64,7 +63,7 @@ func (daemon *Daemon) parseSecurityOpt(container *container.Container, hostConfi
return nil
}
func setupInitLayer(idMapping idtools.IdentityMapping) func(containerfs.ContainerFS) error {
func setupInitLayer(idMapping idtools.IdentityMapping) func(string) error {
return nil
}

View File

@ -351,7 +351,7 @@ func atomicRemove(source string) error {
// Get returns the rootfs path for the id.
// This will mount the dir at its given path
func (a *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
func (a *Driver) Get(id, mountLabel string) (string, error) {
a.locker.Lock(id)
defer a.locker.Unlock(id)
parents, err := a.getParentLayerPaths(id)

View File

@ -627,7 +627,7 @@ func (d *Driver) Remove(id string) error {
}
// Get the requested filesystem id.
func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
func (d *Driver) Get(id, mountLabel string) (string, error) {
dir := d.subvolumesDirID(id)
st, err := os.Stat(dir)
if err != nil {

View File

@ -10,7 +10,6 @@ import (
"strconv"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/devicemapper"
"github.com/docker/docker/pkg/idtools"
units "github.com/docker/go-units"
@ -175,7 +174,7 @@ func (d *Driver) Remove(id string) error {
}
// Get mounts a device with given id into the root filesystem
func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
func (d *Driver) Get(id, mountLabel string) (string, error) {
d.locker.Lock(id)
defer d.locker.Unlock(id)
mp := path.Join(d.home, "mnt", id)

View File

@ -7,7 +7,6 @@ import (
"strings"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/plugingetter"
"github.com/pkg/errors"
@ -60,7 +59,7 @@ type ProtoDriver interface {
// Get returns the mountpoint for the layered filesystem referred
// to by this id. You can optionally specify a mountLabel or "".
// Returns the absolute path to the mounted layered filesystem.
Get(id, mountLabel string) (fs containerfs.ContainerFS, err error)
Get(id, mountLabel string) (fs string, err error)
// Put releases the system resources for the specified id,
// e.g, unmounting layered filesystem.
Put(id string) error

View File

@ -303,7 +303,7 @@ func (d *Driver) Remove(id string) error {
}
// Get creates and mounts the required file system for the given id and returns the mount path.
func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr error) {
func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) {
d.locker.Lock(id)
defer d.locker.Unlock(id)
dir := d.dir(id)

View File

@ -339,7 +339,7 @@ func (d *Driver) Remove(id string) error {
}
// Get creates and mounts the required file system for the given id and returns the mount path.
func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, err error) {
func (d *Driver) Get(id, mountLabel string) (_ string, err error) {
d.locker.Lock(id)
defer d.locker.Unlock(id)
dir := d.dir(id)

View File

@ -513,7 +513,7 @@ func (d *Driver) Remove(id string) error {
}
// Get creates and mounts the required file system for the given id and returns the mount path.
func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr error) {
func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) {
d.locker.Lock(id)
defer d.locker.Unlock(id)
dir := d.dir(id)

View File

@ -6,7 +6,6 @@ import (
"io"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/plugingetter"
"github.com/docker/docker/pkg/plugins"
@ -128,7 +127,7 @@ func (d *graphDriverProxy) Remove(id string) error {
return nil
}
func (d *graphDriverProxy) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
func (d *graphDriverProxy) Get(id, mountLabel string) (string, error) {
args := &graphDriverRequest{
ID: id,
MountLabel: mountLabel,

View File

@ -185,7 +185,7 @@ func (d *Driver) Remove(id string) error {
}
// Get returns the directory for the given id.
func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
func (d *Driver) Get(id, mountLabel string) (string, error) {
dir := d.dir(id)
if st, err := os.Stat(dir); err != nil {
return "", err

View File

@ -27,7 +27,6 @@ import (
"github.com/Microsoft/hcsshim/osversion"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/longpath"
@ -393,7 +392,7 @@ func (d *Driver) GetLayerPath(id string) (string, error) {
}
// Get returns the rootfs path for the id. This will mount the dir at its given path.
func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
func (d *Driver) Get(id, mountLabel string) (string, error) {
logrus.Debugf("WindowsGraphDriver Get() id %s mountLabel %s", id, mountLabel)
var dir string

View File

@ -14,7 +14,6 @@ import (
"time"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/parsers"
zfs "github.com/mistifyio/go-zfs"
@ -363,7 +362,7 @@ func (d *Driver) Remove(id string) error {
}
// Get returns the mountpoint for the given id after creating the target directories if necessary.
func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr error) {
func (d *Driver) Get(id, mountLabel string) (_ string, retErr error) {
d.locker.Lock(id)
defer d.locker.Unlock(id)
mountpoint := d.mountPath(id)

View File

@ -14,7 +14,6 @@ import (
"github.com/docker/docker/errdefs"
"github.com/docker/docker/image"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/pkg/stringid"
@ -83,10 +82,10 @@ type rwLayer struct {
released bool
layerStore layer.Store
rwLayer layer.RWLayer
fs containerfs.ContainerFS
fs string
}
func (l *rwLayer) Root() containerfs.ContainerFS {
func (l *rwLayer) Root() string {
return l.fs
}

View File

@ -8,7 +8,6 @@ import (
"path/filepath"
"strings"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"golang.org/x/sys/unix"
)
@ -18,7 +17,7 @@ import (
//
// This extra layer is used by all containers as the top-most ro layer. It protects
// the container from unwanted side-effects on the rw layer.
func Setup(initLayerFs containerfs.ContainerFS, rootIdentity idtools.Identity) error {
func Setup(initLayerFs string, rootIdentity idtools.Identity) error {
// Since all paths are local to the container, we can just extract initLayerFs.Path()
initLayer := initLayerFs

View File

@ -15,7 +15,6 @@ import (
"github.com/docker/distribution"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/containerfs"
"github.com/opencontainers/go-digest"
"github.com/sirupsen/logrus"
)
@ -114,7 +113,7 @@ type RWLayer interface {
// Mount mounts the RWLayer and returns the filesystem path
// to the writable layer.
Mount(mountLabel string) (containerfs.ContainerFS, error)
Mount(mountLabel string) (string, error)
// Unmount unmounts the RWLayer. This should be called
// for every mount. If there are multiple mount calls
@ -158,7 +157,7 @@ type Metadata struct {
// writable mount. Changes made here will
// not be included in the Tar stream of the
// RWLayer.
type MountInit func(root containerfs.ContainerFS) error
type MountInit func(root string) error
// CreateRWLayerOpts contains optional arguments to be passed to CreateRWLayer
type CreateRWLayerOpts struct {

View File

@ -13,7 +13,6 @@ import (
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/daemon/graphdriver/vfs"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/stringid"
"github.com/opencontainers/go-digest"
@ -80,7 +79,7 @@ func newTestStore(t *testing.T) (Store, string, func()) {
}
}
type layerInit func(root containerfs.ContainerFS) error
type layerInit func(root string) error
func createLayer(ls Store, parent ChainID, layerFunc layerInit) (Layer, error) {
containerID := stringid.GenerateRandomID()
@ -121,7 +120,7 @@ func createLayer(ls Store, parent ChainID, layerFunc layerInit) (Layer, error) {
}
type FileApplier interface {
ApplyFile(root containerfs.ContainerFS) error
ApplyFile(root string) error
}
type testFile struct {
@ -138,7 +137,7 @@ func newTestFile(name string, content []byte, perm os.FileMode) FileApplier {
}
}
func (tf *testFile) ApplyFile(root containerfs.ContainerFS) error {
func (tf *testFile) ApplyFile(root string) error {
fullPath := filepath.Join(root, tf.name)
if err := os.MkdirAll(filepath.Dir(fullPath), 0755); err != nil {
return err
@ -153,7 +152,7 @@ func (tf *testFile) ApplyFile(root containerfs.ContainerFS) error {
}
func initWithFiles(files ...FileApplier) layerInit {
return func(root containerfs.ContainerFS) error {
return func(root string) error {
for _, f := range files {
if err := f.ApplyFile(root); err != nil {
return err

View File

@ -10,7 +10,6 @@ import (
"github.com/containerd/continuity/driver"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/containerfs"
)
func TestMountInit(t *testing.T) {
@ -30,7 +29,7 @@ func TestMountInit(t *testing.T) {
t.Fatal(err)
}
mountInit := func(root containerfs.ContainerFS) error {
mountInit := func(root string) error {
return initfile.ApplyFile(root)
}
@ -90,7 +89,7 @@ func TestMountSize(t *testing.T) {
t.Fatal(err)
}
mountInit := func(root containerfs.ContainerFS) error {
mountInit := func(root string) error {
return newTestFile("file-init", contentInit, 0777).ApplyFile(root)
}
rwLayerOpts := &CreateRWLayerOpts{
@ -142,7 +141,7 @@ func TestMountChanges(t *testing.T) {
t.Fatal(err)
}
mountInit := func(root containerfs.ContainerFS) error {
mountInit := func(root string) error {
return initfile.ApplyFile(root)
}
rwLayerOpts := &CreateRWLayerOpts{

View File

@ -5,7 +5,6 @@ import (
"sync"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/containerfs"
)
type mountedLayer struct {
@ -100,7 +99,7 @@ type referencedRWLayer struct {
*mountedLayer
}
func (rl *referencedRWLayer) Mount(mountLabel string) (containerfs.ContainerFS, error) {
func (rl *referencedRWLayer) Mount(mountLabel string) (string, error) {
return rl.layerStore.driver.Get(rl.mountedLayer.mountID, mountLabel)
}

View File

@ -6,9 +6,6 @@ import (
"github.com/moby/sys/symlink"
)
// ContainerFS is that represents a root file system
type ContainerFS = string
// ResolveScopedPath evaluates the given path scoped to the root.
// For example, if root=/a, and path=/b/c, then this function would return /a/b/c.
func ResolveScopedPath(root, path string) (string, error) {