| ... | ... |
@@ -15,15 +15,6 @@ func init() {
|
| 15 | 15 |
// Placeholder interfaces, to be replaced |
| 16 | 16 |
// at integration. |
| 17 | 17 |
|
| 18 |
-type Image interface {
|
|
| 19 |
- ID() string |
|
| 20 |
- Parent() (Image, error) |
|
| 21 |
- Path() string |
|
| 22 |
-} |
|
| 23 |
- |
|
| 24 |
-type Change interface {
|
|
| 25 |
-} |
|
| 26 |
- |
|
| 27 | 18 |
// End of placeholder interfaces. |
| 28 | 19 |
|
| 29 | 20 |
type Driver struct {
|
| ... | ... |
@@ -46,54 +37,45 @@ func (d *Driver) Cleanup() error {
|
| 46 | 46 |
return d.DeviceSet.Shutdown() |
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 |
-func (d *Driver) OnCreate(img Image, layer archive.Archive) error {
|
|
| 50 |
- // Determine the source of the snapshot (parent id or init device) |
|
| 51 |
- var parentID string |
|
| 52 |
- if parent, err := img.Parent(); err != nil {
|
|
| 53 |
- return err |
|
| 54 |
- } else if parent != nil {
|
|
| 55 |
- parentID = parent.ID() |
|
| 56 |
- } |
|
| 57 |
- // Create the device for this image by snapshotting source |
|
| 58 |
- if err := d.DeviceSet.AddDevice(img.ID(), parentID); err != nil {
|
|
| 59 |
- return err |
|
| 60 |
- } |
|
| 61 |
- // Mount the device in rootfs |
|
| 62 |
- mp := d.mountpoint(img.ID()) |
|
| 63 |
- if err := os.MkdirAll(mp, 0700); err != nil {
|
|
| 64 |
- return err |
|
| 65 |
- } |
|
| 66 |
- if err := d.DeviceSet.MountDevice(img.ID(), mp, false); err != nil {
|
|
| 67 |
- return err |
|
| 68 |
- } |
|
| 69 |
- // Apply the layer as a diff |
|
| 70 |
- if layer != nil {
|
|
| 71 |
- if err := archive.ApplyLayer(mp, layer); err != nil {
|
|
| 72 |
- return err |
|
| 73 |
- } |
|
| 74 |
- } |
|
| 75 |
- return nil |
|
| 49 |
+func (d *Driver) Create(id string, parent string) error {
|
|
| 50 |
+ return d.DeviceSet.AddDevice(id, parent) |
|
| 76 | 51 |
} |
| 77 | 52 |
|
| 78 |
-func (d *Driver) OnRemove(img Image) error {
|
|
| 79 |
- id := img.ID() |
|
| 80 |
- if err := d.DeviceSet.RemoveDevice(id); err != nil {
|
|
| 81 |
- return fmt.Errorf("Unable to remove device for %v: %v", id, err)
|
|
| 82 |
- } |
|
| 83 |
- return nil |
|
| 53 |
+func (d *Driver) Remove(id string) error {
|
|
| 54 |
+ return d.DeviceSet.RemoveDevice(id) |
|
| 84 | 55 |
} |
| 85 | 56 |
|
| 86 |
-func (d *Driver) mountpoint(id string) string {
|
|
| 87 |
- if d.home == "" {
|
|
| 88 |
- return "" |
|
| 57 |
+func (d *Driver) Get(id string) (string, error) {
|
|
| 58 |
+ mp := path.Join(d.home, "mnt", id) |
|
| 59 |
+ if err := d.mount(id, mp); err != nil {
|
|
| 60 |
+ return "", err |
|
| 89 | 61 |
} |
| 90 |
- return path.Join(d.home, "mnt", id) |
|
| 62 |
+ return mp, nil |
|
| 91 | 63 |
} |
| 92 | 64 |
|
| 93 |
-func (d *Driver) Changes(img *Image, dest string) ([]Change, error) {
|
|
| 65 |
+func (d *Driver) Diff(id string) (archive.Archive, error) {
|
|
| 94 | 66 |
return nil, fmt.Errorf("Not implemented")
|
| 95 | 67 |
} |
| 96 | 68 |
|
| 97 |
-func (d *Driver) Layer(img *Image, dest string) (archive.Archive, error) {
|
|
| 69 |
+func (d *Driver) DiffSize(id string) (int64, error) {
|
|
| 70 |
+ return -1, fmt.Errorf("Not implemented")
|
|
| 71 |
+} |
|
| 72 |
+ |
|
| 73 |
+func (d *Driver) Changes(id string) ([]graphdriver.Change, error) {
|
|
| 98 | 74 |
return nil, fmt.Errorf("Not implemented")
|
| 99 | 75 |
} |
| 76 |
+ |
|
| 77 |
+func (d *Driver) mount(id, mp string) error {
|
|
| 78 |
+ // Create the target directories if they don't exist |
|
| 79 |
+ if err := os.MkdirAll(mp, 0755); err != nil && !os.IsExist(err) {
|
|
| 80 |
+ return err |
|
| 81 |
+ } |
|
| 82 |
+ // If mountpoint is already mounted, do nothing |
|
| 83 |
+ if mounted, err := Mounted(mp); err != nil {
|
|
| 84 |
+ return fmt.Errorf("Error checking mountpoint: %s", err)
|
|
| 85 |
+ } else if mounted {
|
|
| 86 |
+ return nil |
|
| 87 |
+ } |
|
| 88 |
+ // Mount the device |
|
| 89 |
+ return d.DeviceSet.MountDevice(id, mp, false) |
|
| 90 |
+} |
| ... | ... |
@@ -6,32 +6,6 @@ import ( |
| 6 | 6 |
"testing" |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 |
-type TestImage struct {
|
|
| 10 |
- id string |
|
| 11 |
- path string |
|
| 12 |
-} |
|
| 13 |
- |
|
| 14 |
-func (img *TestImage) ID() string {
|
|
| 15 |
- return img.id |
|
| 16 |
-} |
|
| 17 |
- |
|
| 18 |
-func (img *TestImage) Path() string {
|
|
| 19 |
- return img.path |
|
| 20 |
-} |
|
| 21 |
- |
|
| 22 |
-func (img *TestImage) Parent() (Image, error) {
|
|
| 23 |
- return nil, nil |
|
| 24 |
-} |
|
| 25 |
- |
|
| 26 |
- |
|
| 27 |
- |
|
| 28 |
-func mkTestImage(t *testing.T) Image {
|
|
| 29 |
- return &TestImage{
|
|
| 30 |
- path: mkTestDirectory(t), |
|
| 31 |
- id: "4242", |
|
| 32 |
- } |
|
| 33 |
-} |
|
| 34 |
- |
|
| 35 | 9 |
func mkTestDirectory(t *testing.T) string {
|
| 36 | 10 |
dir, err := ioutil.TempDir("", "docker-test-devmapper-")
|
| 37 | 11 |
if err != nil {
|
| ... | ... |
@@ -43,19 +17,27 @@ func mkTestDirectory(t *testing.T) string {
|
| 43 | 43 |
func TestInit(t *testing.T) {
|
| 44 | 44 |
home := mkTestDirectory(t) |
| 45 | 45 |
defer os.RemoveAll(home) |
| 46 |
- plugin, err := Init(home) |
|
| 46 |
+ driver, err := Init(home) |
|
| 47 | 47 |
if err != nil {
|
| 48 | 48 |
t.Fatal(err) |
| 49 | 49 |
} |
| 50 | 50 |
defer func() {
|
| 51 | 51 |
return |
| 52 |
- if err := plugin.Cleanup(); err != nil {
|
|
| 52 |
+ if err := driver.Cleanup(); err != nil {
|
|
| 53 | 53 |
t.Fatal(err) |
| 54 | 54 |
} |
| 55 | 55 |
}() |
| 56 |
- img := mkTestImage(t) |
|
| 57 |
- defer os.RemoveAll(img.(*TestImage).path) |
|
| 58 |
- if err := plugin.OnCreate(img, nil); err != nil {
|
|
| 56 |
+ id := "foo" |
|
| 57 |
+ if err := driver.Create(id, ""); err != nil {
|
|
| 58 |
+ t.Fatal(err) |
|
| 59 |
+ } |
|
| 60 |
+ dir, err := driver.Get(id) |
|
| 61 |
+ if err != nil {
|
|
| 62 |
+ t.Fatal(err) |
|
| 63 |
+ } |
|
| 64 |
+ if st, err := os.Stat(dir); err != nil {
|
|
| 59 | 65 |
t.Fatal(err) |
| 66 |
+ } else if !st.IsDir() {
|
|
| 67 |
+ t.Fatalf("Get(%V) did not return a directory", id)
|
|
| 60 | 68 |
} |
| 61 | 69 |
} |
| 62 | 70 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,27 @@ |
| 0 |
+package devmapper |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "os" |
|
| 4 |
+ "path/filepath" |
|
| 5 |
+ "syscall" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// FIXME: this is copy-pasted from the aufs driver. |
|
| 9 |
+// It should be moved into the core. |
|
| 10 |
+ |
|
| 11 |
+func Mounted(mountpoint string) (bool, error) {
|
|
| 12 |
+ mntpoint, err := os.Stat(mountpoint) |
|
| 13 |
+ if err != nil {
|
|
| 14 |
+ if os.IsNotExist(err) {
|
|
| 15 |
+ return false, nil |
|
| 16 |
+ } |
|
| 17 |
+ return false, err |
|
| 18 |
+ } |
|
| 19 |
+ parent, err := os.Stat(filepath.Join(mountpoint, "..")) |
|
| 20 |
+ if err != nil {
|
|
| 21 |
+ return false, err |
|
| 22 |
+ } |
|
| 23 |
+ mntpointSt := mntpoint.Sys().(*syscall.Stat_t) |
|
| 24 |
+ parentSt := parent.Sys().(*syscall.Stat_t) |
|
| 25 |
+ return mntpointSt.Dev != parentSt.Dev, nil |
|
| 26 |
+} |