Move Mount into mount pkg

This moves both the Mount type and mountinfo into a single mount
package.

This also opens up the root of the repo to hold the containerd client
implementation.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-05-22 16:35:12 -07:00
parent b07504c713
commit d7af92e00c
32 changed files with 104 additions and 108 deletions

View File

@@ -11,9 +11,8 @@ import (
"github.com/Sirupsen/logrus"
"github.com/containerd/btrfs"
"github.com/containerd/containerd"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mountinfo"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/snapshot/storage"
@@ -36,7 +35,7 @@ type snapshotter struct {
ms *storage.MetaStore
}
func getBtrfsDevice(root string, mounts []mountinfo.Info) (string, error) {
func getBtrfsDevice(root string, mounts []mount.Info) (string, error) {
device := ""
deviceMountpoint := ""
for _, info := range mounts {
@@ -62,7 +61,7 @@ func getBtrfsDevice(root string, mounts []mountinfo.Info) (string, error) {
// a file in the provided root.
// root needs to be a mount point of btrfs.
func NewSnapshotter(root string) (snapshot.Snapshotter, error) {
mounts, err := mountinfo.Self()
mounts, err := mount.Self()
if err != nil {
return nil, err
}
@@ -140,15 +139,15 @@ func (b *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
return storage.WalkInfo(ctx, fn)
}
func (b *snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
func (b *snapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) {
return b.makeActive(ctx, key, parent, false)
}
func (b *snapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
func (b *snapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) {
return b.makeActive(ctx, key, parent, true)
}
func (b *snapshotter) makeActive(ctx context.Context, key, parent string, readonly bool) ([]containerd.Mount, error) {
func (b *snapshotter) makeActive(ctx context.Context, key, parent string, readonly bool) ([]mount.Mount, error) {
ctx, t, err := b.ms.TransactionContext(ctx, true)
if err != nil {
return nil, err
@@ -193,7 +192,7 @@ func (b *snapshotter) makeActive(ctx context.Context, key, parent string, readon
return b.mounts(target)
}
func (b *snapshotter) mounts(dir string) ([]containerd.Mount, error) {
func (b *snapshotter) mounts(dir string) ([]mount.Mount, error) {
var options []string
// get the subvolume id back out for the mount
@@ -208,7 +207,7 @@ func (b *snapshotter) mounts(dir string) ([]containerd.Mount, error) {
options = append(options, "ro")
}
return []containerd.Mount{
return []mount.Mount{
{
Type: "btrfs",
Source: b.device,
@@ -265,7 +264,7 @@ func (b *snapshotter) Commit(ctx context.Context, name, key string) (err error)
// called on an read-write or readonly transaction.
//
// This can be used to recover mounts after calling View or Prepare.
func (b *snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) {
func (b *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) {
ctx, t, err := b.ms.TransactionContext(ctx, false)
if err != nil {
return nil, err

View File

@@ -11,8 +11,7 @@ import (
"strings"
"testing"
"github.com/containerd/containerd"
"github.com/containerd/containerd/mountinfo"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/snapshot/testsuite"
"github.com/containerd/containerd/testutil"
@@ -86,7 +85,7 @@ func TestBtrfsMounts(t *testing.T) {
if err := os.MkdirAll(target, 0755); err != nil {
t.Fatal(err)
}
if err := containerd.MountAll(mounts, target); err != nil {
if err := mount.MountAll(mounts, target); err != nil {
t.Fatal(err)
}
defer testutil.Unmount(t, target)
@@ -116,7 +115,7 @@ func TestBtrfsMounts(t *testing.T) {
t.Fatal(err)
}
if err := containerd.MountAll(mounts, target); err != nil {
if err := mount.MountAll(mounts, target); err != nil {
t.Fatal(err)
}
defer testutil.Unmount(t, target)
@@ -222,12 +221,12 @@ func TestGetBtrfsDevice(t *testing.T) {
expectedDevice string
expectedError string
root string
mounts []mountinfo.Info
mounts []mount.Info
}{
{
expectedDevice: "/dev/loop0",
root: "/var/lib/containerd/snapshot/btrfs",
mounts: []mountinfo.Info{
mounts: []mount.Info{
{Root: "/", Mountpoint: "/", FSType: "ext4", Source: "/dev/sda1"},
{Root: "/", Mountpoint: "/var/lib/containerd/snapshot/btrfs", FSType: "btrfs", Source: "/dev/loop0"},
},
@@ -235,21 +234,21 @@ func TestGetBtrfsDevice(t *testing.T) {
{
expectedError: "/var/lib/containerd/snapshot/btrfs is not mounted as btrfs",
root: "/var/lib/containerd/snapshot/btrfs",
mounts: []mountinfo.Info{
mounts: []mount.Info{
{Root: "/", Mountpoint: "/", FSType: "ext4", Source: "/dev/sda1"},
},
},
{
expectedDevice: "/dev/sda1",
root: "/var/lib/containerd/snapshot/btrfs",
mounts: []mountinfo.Info{
mounts: []mount.Info{
{Root: "/", Mountpoint: "/", FSType: "btrfs", Source: "/dev/sda1"},
},
},
{
expectedDevice: "/dev/sda2",
root: "/var/lib/containerd/snapshot/btrfs",
mounts: []mountinfo.Info{
mounts: []mount.Info{
{Root: "/", Mountpoint: "/", FSType: "btrfs", Source: "/dev/sda1"},
{Root: "/", Mountpoint: "/var/lib/containerd/snapshot/btrfs", FSType: "btrfs", Source: "/dev/sda2"},
},
@@ -257,7 +256,7 @@ func TestGetBtrfsDevice(t *testing.T) {
{
expectedDevice: "/dev/sda2",
root: "/var/lib/containerd/snapshot/btrfs",
mounts: []mountinfo.Info{
mounts: []mount.Info{
{Root: "/", Mountpoint: "/var/lib/containerd/snapshot/btrfs", FSType: "btrfs", Source: "/dev/sda2"},
{Root: "/", Mountpoint: "/var/lib/foooooooooooooooooooo/baaaaaaaaaaaaaaaaaaaar", FSType: "btrfs", Source: "/dev/sda3"}, // mountpoint length longer than /var/lib/containerd/snapshot/btrfs
{Root: "/", Mountpoint: "/", FSType: "btrfs", Source: "/dev/sda1"},

View File

@@ -6,9 +6,9 @@ import (
"os"
"path/filepath"
"github.com/containerd/containerd"
"github.com/containerd/containerd/fs"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/snapshot/storage"
@@ -92,11 +92,11 @@ func (o *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, er
return usage, nil
}
func (o *snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
func (o *snapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) {
return o.createActive(ctx, key, parent, false)
}
func (o *snapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
func (o *snapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) {
return o.createActive(ctx, key, parent, true)
}
@@ -104,7 +104,7 @@ func (o *snapshotter) View(ctx context.Context, key, parent string) ([]container
// called on an read-write or readonly transaction.
//
// This can be used to recover mounts after calling View or Prepare.
func (o *snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) {
func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) {
ctx, t, err := o.ms.TransactionContext(ctx, false)
if err != nil {
return nil, err
@@ -202,7 +202,7 @@ func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
return storage.WalkInfo(ctx, fn)
}
func (o *snapshotter) createActive(ctx context.Context, key, parent string, readonly bool) ([]containerd.Mount, error) {
func (o *snapshotter) createActive(ctx context.Context, key, parent string, readonly bool) ([]mount.Mount, error) {
var (
err error
path, td string
@@ -271,7 +271,7 @@ func (o *snapshotter) getSnapshotDir(id string) string {
return filepath.Join(o.root, "snapshots", id)
}
func (o *snapshotter) mounts(active storage.Active) []containerd.Mount {
func (o *snapshotter) mounts(active storage.Active) []mount.Mount {
var (
roFlag string
source string
@@ -289,7 +289,7 @@ func (o *snapshotter) mounts(active storage.Active) []containerd.Mount {
source = o.getSnapshotDir(active.ParentIDs[0])
}
return []containerd.Mount{
return []mount.Mount{
{
Source: source,
Type: "bind",

View File

@@ -10,9 +10,9 @@ import (
"path/filepath"
"strings"
"github.com/containerd/containerd"
"github.com/containerd/containerd/fs"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/snapshot/storage"
@@ -120,11 +120,11 @@ func (o *snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, er
return usage, nil
}
func (o *snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
func (o *snapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) {
return o.createActive(ctx, key, parent, false)
}
func (o *snapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
func (o *snapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) {
return o.createActive(ctx, key, parent, true)
}
@@ -132,7 +132,7 @@ func (o *snapshotter) View(ctx context.Context, key, parent string) ([]container
// called on an read-write or readonly transaction.
//
// This can be used to recover mounts after calling View or Prepare.
func (o *snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) {
func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) {
ctx, t, err := o.ms.TransactionContext(ctx, false)
if err != nil {
return nil, err
@@ -229,7 +229,7 @@ func (o *snapshotter) Walk(ctx context.Context, fn func(context.Context, snapsho
return storage.WalkInfo(ctx, fn)
}
func (o *snapshotter) createActive(ctx context.Context, key, parent string, readonly bool) ([]containerd.Mount, error) {
func (o *snapshotter) createActive(ctx context.Context, key, parent string, readonly bool) ([]mount.Mount, error) {
var (
path string
snapshotDir = filepath.Join(o.root, "snapshots")
@@ -292,7 +292,7 @@ func (o *snapshotter) createActive(ctx context.Context, key, parent string, read
return o.mounts(active), nil
}
func (o *snapshotter) mounts(active storage.Active) []containerd.Mount {
func (o *snapshotter) mounts(active storage.Active) []mount.Mount {
if len(active.ParentIDs) == 0 {
// if we only have one layer/no parents then just return a bind mount as overlay
// will not work
@@ -301,7 +301,7 @@ func (o *snapshotter) mounts(active storage.Active) []containerd.Mount {
roFlag = "ro"
}
return []containerd.Mount{
return []mount.Mount{
{
Source: o.upperPath(active.ID),
Type: "bind",
@@ -320,7 +320,7 @@ func (o *snapshotter) mounts(active storage.Active) []containerd.Mount {
fmt.Sprintf("upperdir=%s", o.upperPath(active.ID)),
)
} else if len(active.ParentIDs) == 1 {
return []containerd.Mount{
return []mount.Mount{
{
Source: o.upperPath(active.ParentIDs[0]),
Type: "bind",
@@ -338,7 +338,7 @@ func (o *snapshotter) mounts(active storage.Active) []containerd.Mount {
}
options = append(options, fmt.Sprintf("lowerdir=%s", strings.Join(parentPaths, ":")))
return []containerd.Mount{
return []mount.Mount{
{
Type: "overlay",
Source: "overlay",

View File

@@ -11,7 +11,7 @@ import (
"syscall"
"testing"
"github.com/containerd/containerd"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/snapshot/storage"
"github.com/containerd/containerd/snapshot/testsuite"
@@ -221,7 +221,7 @@ func TestOverlayOverlayRead(t *testing.T) {
t.Error(err)
return
}
if err := containerd.MountAll(mounts, dest); err != nil {
if err := mount.MountAll(mounts, dest); err != nil {
t.Error(err)
return
}

View File

@@ -3,7 +3,7 @@ package snapshot
import (
"context"
"github.com/containerd/containerd"
"github.com/containerd/containerd/mount"
)
// Kind identifies the kind of snapshot.
@@ -179,7 +179,7 @@ type Snapshotter interface {
// available only for active snapshots.
//
// This can be used to recover mounts after calling View or Prepare.
Mounts(ctx context.Context, key string) ([]containerd.Mount, error)
Mounts(ctx context.Context, key string) ([]mount.Mount, error)
// Prepare creates an active snapshot identified by key descending from the
// provided parent. The returned mounts can be used to mount the snapshot
@@ -195,7 +195,7 @@ type Snapshotter interface {
// one is done with the transaction, Remove should be called on the key.
//
// Multiple calls to Prepare or View with the same key should fail.
Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error)
Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error)
// View behaves identically to Prepare except the result may not be
// committed back to the snapshot snapshotter. View returns a readonly view on
@@ -210,7 +210,7 @@ type Snapshotter interface {
// Commit may not be called on the provided key and will return an error.
// To collect the resources associated with key, Remove must be called with
// key as the argument.
View(ctx context.Context, key, parent string) ([]containerd.Mount, error)
View(ctx context.Context, key, parent string) ([]mount.Mount, error)
// Commit captures the changes between key and its parent into a snapshot
// identified by name. The name can then be used with the snapshotter's other

View File

@@ -9,8 +9,8 @@ import (
"syscall"
"testing"
"github.com/containerd/containerd"
"github.com/containerd/containerd/fs/fstest"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/testutil"
"github.com/stretchr/testify/assert"
@@ -93,7 +93,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
t.Fatal("expected mounts to have entries")
}
if err := containerd.MountAll(mounts, preparing); err != nil {
if err := mount.MountAll(mounts, preparing); err != nil {
t.Fatalf("failure reason: %+v", err)
}
defer testutil.Unmount(t, preparing)
@@ -124,7 +124,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
if err != nil {
t.Fatalf("failure reason: %+v", err)
}
if err := containerd.MountAll(mounts, next); err != nil {
if err := mount.MountAll(mounts, next); err != nil {
t.Fatalf("failure reason: %+v", err)
}
defer testutil.Unmount(t, next)
@@ -179,7 +179,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
if err != nil {
t.Fatalf("failure reason: %+v", err)
}
if err := containerd.MountAll(mounts, nextnext); err != nil {
if err := mount.MountAll(mounts, nextnext); err != nil {
t.Fatalf("failure reason: %+v", err)
}
defer testutil.Unmount(t, nextnext)
@@ -211,7 +211,7 @@ func checkSnapshotterStatActive(ctx context.Context, t *testing.T, snapshotter s
t.Fatal("expected mounts to have entries")
}
if err = containerd.MountAll(mounts, preparing); err != nil {
if err = mount.MountAll(mounts, preparing); err != nil {
t.Fatal(err)
}
defer testutil.Unmount(t, preparing)
@@ -245,7 +245,7 @@ func checkSnapshotterStatCommitted(ctx context.Context, t *testing.T, snapshotte
t.Fatal("expected mounts to have entries")
}
if err = containerd.MountAll(mounts, preparing); err != nil {
if err = mount.MountAll(mounts, preparing); err != nil {
t.Fatal(err)
}
defer testutil.Unmount(t, preparing)
@@ -284,7 +284,7 @@ func snapshotterPrepareMount(ctx context.Context, snapshotter snapshot.Snapshott
return "", fmt.Errorf("expected mounts to have entries")
}
if err = containerd.MountAll(mounts, preparing); err != nil {
if err = mount.MountAll(mounts, preparing); err != nil {
return "", err
}
return preparing, nil

View File

@@ -6,7 +6,7 @@ import (
"context"
"path/filepath"
"github.com/containerd/containerd"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/snapshot"
"github.com/pkg/errors"
@@ -48,11 +48,11 @@ func (o *Snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, er
panic("not implemented")
}
func (o *Snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
func (o *Snapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) {
panic("not implemented")
}
func (o *Snapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
func (o *Snapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) {
panic("not implemented")
}
@@ -60,7 +60,7 @@ func (o *Snapshotter) View(ctx context.Context, key, parent string) ([]container
// called on an read-write or readonly transaction.
//
// This can be used to recover mounts after calling View or Prepare.
func (o *Snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) {
func (o *Snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) {
panic("not implemented")
}