Browse code

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

We place the actual image/containers in the "rootfs" directory, which
allows us to have other data in the toplevel directory in the mount.

For starters, this means the "lost+found" directory from mkfs will
not always be in your container/image.

Secondly, we can create a file "id" in the toplevel dir which is not
visible from the container. This is useful because it allows us to map
back from the device fs to the container if something goes wrong with
the devicemapper metadata.

Alexander Larsson authored on 2013/11/19 01:10:47
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 {
... ...
@@ -69,7 +89,7 @@ func (d *Driver) Get(id string) (string, error) {
69 69
 	if err := d.mount(id, mp); err != nil {
70 70
 		return "", err
71 71
 	}
72
-	return mp, nil
72
+	return path.Join(mp, "rootfs"), nil
73 73
 }
74 74
 
75 75
 func (d *Driver) Size(id string) (int64, error) {