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"},