Browse code

Merge pull request #43 from alexlarsson/dm-plugin-use-root-subdir

devmapper: Use a "root" subdirectory in the devmapper volume

Victor Vieux authored on 2013/11/20 06:51:04
Showing 1 changed files
... ...
@@ -3,6 +3,7 @@ package devmapper
3 3
 import (
4 4
 	"fmt"
5 5
 	"github.com/dotcloud/docker/graphdriver"
6
+	"io/ioutil"
6 7
 	"os"
7 8
 	"path"
8 9
 )
... ...
@@ -57,7 +58,26 @@ func (d *Driver) Cleanup() error {
57 57
 }
58 58
 
59 59
 func (d *Driver) Create(id string, parent string) error {
60
-	return d.DeviceSet.AddDevice(id, parent)
60
+	if err := d.DeviceSet.AddDevice(id, parent); err != nil {
61
+		return err
62
+	}
63
+
64
+	mp := path.Join(d.home, "mnt", id)
65
+	if err := d.mount(id, mp); err != nil {
66
+		return err
67
+	}
68
+
69
+	if err := os.MkdirAll(path.Join(mp, "rootfs"), 0755); err != nil && !os.IsExist(err) {
70
+		return err
71
+	}
72
+
73
+	// Create an "id" file with the container/image id in it to help reconscruct this in case
74
+	// of later problems
75
+	if err := ioutil.WriteFile(path.Join(mp, "id"), []byte(id), 0600); err != nil {
76
+		return err
77
+	}
78
+
79
+	return nil
61 80
 }
62 81
 
63 82
 func (d *Driver) Remove(id string) error {
... ...
@@ -73,7 +93,7 @@ func (d *Driver) Get(id string) (string, error) {
73 73
 	if err := d.mount(id, mp); err != nil {
74 74
 		return "", err
75 75
 	}
76
-	return mp, nil
76
+	return path.Join(mp, "rootfs"), nil
77 77
 }
78 78
 
79 79
 func (d *Driver) mount(id, mountPoint string) error {