Revert "snapshot/storage: namespace snapshot drivers"

This reverts commit b1a70aa335.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2017-06-21 15:49:21 -07:00
parent eedcbc64cc
commit 7ddf411ea8
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB
5 changed files with 12 additions and 57 deletions

View File

@ -12,7 +12,6 @@ import (
"testing" "testing"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/snapshot/testsuite" "github.com/containerd/containerd/snapshot/testsuite"
"github.com/containerd/containerd/testutil" "github.com/containerd/containerd/testutil"
@ -51,7 +50,7 @@ func TestBtrfs(t *testing.T) {
func TestBtrfsMounts(t *testing.T) { func TestBtrfsMounts(t *testing.T) {
testutil.RequiresRoot(t) testutil.RequiresRoot(t)
ctx := namespaces.WithNamespace(context.Background(), "snapshotter-btrfs-test") ctx := context.Background()
// create temporary directory for mount point // create temporary directory for mount point
mountPoint, err := ioutil.TempDir("", "containerd-btrfs-test") mountPoint, err := ioutil.TempDir("", "containerd-btrfs-test")

View File

@ -12,7 +12,6 @@ import (
"testing" "testing"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/snapshot/storage" "github.com/containerd/containerd/snapshot/storage"
"github.com/containerd/containerd/snapshot/testsuite" "github.com/containerd/containerd/snapshot/testsuite"
@ -34,7 +33,7 @@ func TestOverlay(t *testing.T) {
} }
func TestOverlayMounts(t *testing.T) { func TestOverlayMounts(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), "snapshotter-overlay-test") ctx := context.TODO()
root, err := ioutil.TempDir("", "overlay") root, err := ioutil.TempDir("", "overlay")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -70,7 +69,7 @@ func TestOverlayMounts(t *testing.T) {
} }
func TestOverlayCommit(t *testing.T) { func TestOverlayCommit(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), "snapshotter-overlay-test") ctx := context.TODO()
root, err := ioutil.TempDir("", "overlay") root, err := ioutil.TempDir("", "overlay")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -99,7 +98,7 @@ func TestOverlayCommit(t *testing.T) {
} }
func TestOverlayOverlayMount(t *testing.T) { func TestOverlayOverlayMount(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), "snapshotter-overlay-test") ctx := context.TODO()
root, err := ioutil.TempDir("", "overlay") root, err := ioutil.TempDir("", "overlay")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -187,7 +186,7 @@ func getParents(ctx context.Context, sn snapshot.Snapshotter, root, key string)
func TestOverlayOverlayRead(t *testing.T) { func TestOverlayOverlayRead(t *testing.T) {
testutil.RequiresRoot(t) testutil.RequiresRoot(t)
ctx := namespaces.WithNamespace(context.Background(), "snapshotter-overlay-test") ctx := context.TODO()
root, err := ioutil.TempDir("", "overlay") root, err := ioutil.TempDir("", "overlay")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -239,7 +238,7 @@ func TestOverlayOverlayRead(t *testing.T) {
} }
func TestOverlayView(t *testing.T) { func TestOverlayView(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), "snapshotter-overlay-test") ctx := context.TODO()
root, err := ioutil.TempDir("", "overlay") root, err := ioutil.TempDir("", "overlay")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -7,7 +7,6 @@ import (
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot"
db "github.com/containerd/containerd/snapshot/storage/proto" db "github.com/containerd/containerd/snapshot/storage/proto"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
@ -138,7 +137,7 @@ func CreateActive(ctx context.Context, key, parent string, readonly bool) (a Act
return errors.Wrapf(errdefs.ErrAlreadyExists, "snapshot %v", key) return errors.Wrapf(errdefs.ErrAlreadyExists, "snapshot %v", key)
} }
id, err := nextSequence(ctx) id, err := bkt.NextSequence()
if err != nil { if err != nil {
return errors.Wrap(err, "unable to get identifier") return errors.Wrap(err, "unable to get identifier")
} }
@ -311,68 +310,28 @@ func CommitActive(ctx context.Context, key, name string, usage snapshot.Usage) (
return return
} }
// nextSequence maintains the snapshot ids in the same space across namespaces
// to avoid collisions on the filesystem, which is typically not namespace
// aware. This will also be useful to ensure that snapshots can be used across
// namespaces in the future, by projecting parent relationships into an
// alternate namespace without fixing up identifiers.
func nextSequence(ctx context.Context) (uint64, error) {
t, ok := ctx.Value(transactionKey{}).(*boltFileTransactor)
if !ok {
return 0, ErrNoTransaction
}
bkt := t.tx.Bucket(bucketKeyStorageVersion)
if bkt == nil {
return 0, errors.New("version bucket required for sequence")
}
return bkt.NextSequence()
}
func withBucket(ctx context.Context, fn func(context.Context, *bolt.Bucket, *bolt.Bucket) error) error { func withBucket(ctx context.Context, fn func(context.Context, *bolt.Bucket, *bolt.Bucket) error) error {
namespace, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return err
}
t, ok := ctx.Value(transactionKey{}).(*boltFileTransactor) t, ok := ctx.Value(transactionKey{}).(*boltFileTransactor)
if !ok { if !ok {
return ErrNoTransaction return ErrNoTransaction
} }
nbkt := t.tx.Bucket(bucketKeyStorageVersion) bkt := t.tx.Bucket(bucketKeyStorageVersion)
if nbkt == nil {
return errors.Wrapf(errdefs.ErrNotFound, "bucket does not exist")
}
bkt := nbkt.Bucket([]byte(namespace))
if bkt == nil { if bkt == nil {
return errors.Wrapf(errdefs.ErrNotFound, "namespace not available in snapshotter") return errors.Wrap(errdefs.ErrNotFound, "bucket does not exist")
} }
return fn(ctx, bkt.Bucket(bucketKeySnapshot), bkt.Bucket(bucketKeyParents)) return fn(ctx, bkt.Bucket(bucketKeySnapshot), bkt.Bucket(bucketKeyParents))
} }
func createBucketIfNotExists(ctx context.Context, fn func(context.Context, *bolt.Bucket, *bolt.Bucket) error) error { func createBucketIfNotExists(ctx context.Context, fn func(context.Context, *bolt.Bucket, *bolt.Bucket) error) error {
namespace, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return err
}
t, ok := ctx.Value(transactionKey{}).(*boltFileTransactor) t, ok := ctx.Value(transactionKey{}).(*boltFileTransactor)
if !ok { if !ok {
return ErrNoTransaction return ErrNoTransaction
} }
nbkt, err := t.tx.CreateBucketIfNotExists(bucketKeyStorageVersion) bkt, err := t.tx.CreateBucketIfNotExists(bucketKeyStorageVersion)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create version bucket") return errors.Wrap(err, "failed to create version bucket")
} }
bkt, err := nbkt.CreateBucketIfNotExists([]byte(namespace))
if err != nil {
return err
}
sbkt, err := bkt.CreateBucketIfNotExists(bucketKeySnapshot) sbkt, err := bkt.CreateBucketIfNotExists(bucketKeySnapshot)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create snapshots bucket") return errors.Wrap(err, "failed to create snapshots bucket")

View File

@ -7,7 +7,6 @@ import (
"testing" "testing"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -46,7 +45,7 @@ func MetaStoreSuite(t *testing.T, name string, meta func(root string) (*MetaStor
// makeTest creates a testsuite with a writable transaction // makeTest creates a testsuite with a writable transaction
func makeTest(t *testing.T, name string, metaFn metaFactory, fn testFunc) func(t *testing.T) { func makeTest(t *testing.T, name string, metaFn metaFactory, fn testFunc) func(t *testing.T) {
return func(t *testing.T) { return func(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), "testing-snapshot-metadata") ctx := context.Background()
tmpDir, err := ioutil.TempDir("", "metastore-test-"+name+"-") tmpDir, err := ioutil.TempDir("", "metastore-test-"+name+"-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -10,7 +10,6 @@ import (
"github.com/containerd/containerd/fs/fstest" "github.com/containerd/containerd/fs/fstest"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/snapshot" "github.com/containerd/containerd/snapshot"
"github.com/containerd/containerd/testutil" "github.com/containerd/containerd/testutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -27,7 +26,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context.
func makeTest(t *testing.T, name string, snapshotterFn func(ctx context.Context, root string) (snapshot.Snapshotter, func(), error), fn func(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string)) func(t *testing.T) { func makeTest(t *testing.T, name string, snapshotterFn func(ctx context.Context, root string) (snapshot.Snapshotter, func(), error), fn func(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string)) func(t *testing.T) {
return func(t *testing.T) { return func(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), "snapshotter-test") ctx := context.Background()
restoreMask := clearMask() restoreMask := clearMask()
defer restoreMask() defer restoreMask()
// Make two directories: a snapshotter root and a play area for the tests: // Make two directories: a snapshotter root and a play area for the tests: