diff --git a/components/engine/devmapper/devmapper.go b/components/engine/devmapper/devmapper.go index 97a388e4c9..a925c1a996 100644 --- a/components/engine/devmapper/devmapper.go +++ b/components/engine/devmapper/devmapper.go @@ -175,6 +175,11 @@ const ( DeviceSetGeometry ) +const ( + AddNodeOnResume AddNodeType = iota + AddNodeOnCreate +) + var ( ErrTaskRun = errors.New("dm_task_run failed") ErrTaskSetName = errors.New("dm_task_set_name failed") @@ -209,6 +214,7 @@ type ( TargetCount int32 } TaskType int + AddNodeType int ) func (t *Task) destroy() { @@ -274,6 +280,13 @@ func (t *Task) SetCookie(cookie *uint32, flags uint16) error { return nil } +func (t *Task) SetAddNode(add_node AddNodeType) error { + if res := C.dm_task_set_add_node(t.unmanaged, C.dm_add_node_t (add_node)); res != 1 { + return ErrTaskSetAddNode + } + return nil +} + func (t *Task) SetRo() error { if res := C.dm_task_set_ro(t.unmanaged); res != 1 { return ErrTaskSetRO @@ -614,6 +627,9 @@ func activateDevice(poolName string, name string, deviceId int, size uint64) err if err := task.AddTarget(0, size/512, "thin", params); err != nil { return fmt.Errorf("Can't add target") } + if err := task.SetAddNode(AddNodeOnCreate); err != nil { + return fmt.Errorf("Can't add node") + } var cookie uint32 = 0 if err := task.SetCookie(&cookie, 0); err != nil { diff --git a/components/engine/docker/docker.go b/components/engine/docker/docker.go index 8118dbb611..cb1a5020f4 100644 --- a/components/engine/docker/docker.go +++ b/components/engine/docker/docker.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "github.com/dotcloud/docker" - "github.com/dotcloud/docker/devmapper" "github.com/dotcloud/docker/utils" "io/ioutil" "log" @@ -134,7 +133,7 @@ func daemon(pidfile string, flGraphPath string, protoAddrs []string, autoRestart if flDns != "" { dns = []string{flDns} } - server, err := docker.NewServer(flGraphPath, devmapper.NewDeviceSetDM(flGraphPath), autoRestart, enableCors, dns) + server, err := docker.NewServer(flGraphPath, autoRestart, enableCors, dns) if err != nil { return err } diff --git a/components/engine/runtime.go b/components/engine/runtime.go index 39c9913413..94c8f21d20 100644 --- a/components/engine/runtime.go +++ b/components/engine/runtime.go @@ -4,6 +4,7 @@ import ( "container/list" "fmt" "github.com/dotcloud/docker/utils" + "github.com/dotcloud/docker/devmapper" "io" "io/ioutil" "log" @@ -566,8 +567,8 @@ func (runtime *Runtime) Commit(container *Container, repository, tag, comment, a } // FIXME: harmonize with NewGraph() -func NewRuntime(flGraphPath string, deviceSet DeviceSet, autoRestart bool, dns []string) (*Runtime, error) { - runtime, err := NewRuntimeFromDirectory(flGraphPath, deviceSet, autoRestart) +func NewRuntime(flGraphPath string, autoRestart bool, dns []string) (*Runtime, error) { + runtime, err := NewRuntimeFromDirectory(flGraphPath, autoRestart) if err != nil { return nil, err } @@ -585,7 +586,7 @@ func NewRuntime(flGraphPath string, deviceSet DeviceSet, autoRestart bool, dns [ return runtime, nil } -func NewRuntimeFromDirectory(root string, deviceSet DeviceSet, autoRestart bool) (*Runtime, error) { +func NewRuntimeFromDirectory(root string, autoRestart bool) (*Runtime, error) { runtimeRepo := path.Join(root, "containers") if err := os.MkdirAll(runtimeRepo, 0700); err != nil && !os.IsExist(err) { @@ -611,6 +612,8 @@ func NewRuntimeFromDirectory(root string, deviceSet DeviceSet, autoRestart bool) if err != nil { return nil, err } + deviceSet := devmapper.NewDeviceSetDM(root) + // Initialize devicemapper deviceSet runtime := &Runtime{ root: root, repository: runtimeRepo, diff --git a/components/engine/runtime_test.go b/components/engine/runtime_test.go index 79465f8f7a..d0c489de7a 100644 --- a/components/engine/runtime_test.go +++ b/components/engine/runtime_test.go @@ -25,7 +25,6 @@ const ( unitTestImageID = "83599e29c455eb719f77d799bc7c51521b9551972f5a850d7ad265bc1b5292f6" // 1.0 unitTestNetworkBridge = "testdockbr0" unitTestStoreBase = "/var/lib/docker/unit-tests" - unitTestStoreDevicesBase = "/var/lib/docker/unit-tests-devices" testDaemonAddr = "127.0.0.1:4270" testDaemonProto = "tcp" ) @@ -51,6 +50,9 @@ func nuke(runtime *Runtime) error { for _, container := range runtime.List() { container.EnsureUnmounted() } + if err := runtime.deviceSet.Shutdown(); err != nil { + utils.Debugf("Error shutting down devicemapper for runtime %s", runtime.root) + } return os.RemoveAll(runtime.root) } @@ -170,25 +172,18 @@ func init() { log.Fatalf("Unable to cleanup devmapper: %s", err) } - // Always start from a clean set of loopback mounts - if err := os.RemoveAll(unitTestStoreDevicesBase); err != nil { - log.Fatalf("Unable to remove former unit-test directory: %s", err) - } - - deviceset := devmapper.NewDeviceSetDM(unitTestStoreDevicesBase) - // Create a device, which triggers the initiation of the base FS - // This avoids other tests doing this and timing out - if err := deviceset.AddDevice("init", ""); err != nil { - log.Fatalf("Unable to create the base device: %s", err) - } - // Make it our Store root - if runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, deviceset, false); err != nil { + if runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false); err != nil { log.Fatalf("Unable to create a runtime for tests:", err) } else { globalRuntime = runtime } + // Create a device, which triggers the initiation of the base FS + // This avoids other tests doing this and timing out + deviceset := devmapper.NewDeviceSetDM(unitTestStoreBase) + deviceset.AddDevice("init", "") + // Create the "Server" srv := &Server{ runtime: globalRuntime, @@ -553,7 +548,7 @@ func TestRestore(t *testing.T) { // Here are are simulating a docker restart - that is, reloading all containers // from scratch - runtime2, err := NewRuntimeFromDirectory(runtime1.root, runtime1.deviceSet, false) + runtime2, err := NewRuntimeFromDirectory(runtime1.root, false) if err != nil { t.Fatal(err) } diff --git a/components/engine/server.go b/components/engine/server.go index 45d8bbf9cf..7e6c556a3f 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -1337,11 +1337,11 @@ func (srv *Server) ContainerCopy(name string, resource string, out io.Writer) er } -func NewServer(flGraphPath string, deviceSet DeviceSet, autoRestart, enableCors bool, dns ListOpts) (*Server, error) { +func NewServer(flGraphPath string, autoRestart, enableCors bool, dns ListOpts) (*Server, error) { if runtime.GOARCH != "amd64" { log.Fatalf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH) } - runtime, err := NewRuntime(flGraphPath, deviceSet, autoRestart, dns) + runtime, err := NewRuntime(flGraphPath, autoRestart, dns) if err != nil { return nil, err } diff --git a/components/engine/utils_test.go b/components/engine/utils_test.go index 9c7ab2f26c..013626a03a 100644 --- a/components/engine/utils_test.go +++ b/components/engine/utils_test.go @@ -6,7 +6,6 @@ import ( "io/ioutil" "os" "path" - "path/filepath" "strings" "testing" ) @@ -43,7 +42,7 @@ func newTestRuntime() (*Runtime, error) { return nil, err } - runtime, err := NewRuntimeFromDirectory(root, NewDeviceSetWrapper(globalRuntime.deviceSet, filepath.Base(root)), false) + runtime, err := NewRuntimeFromDirectory(root, false) if err != nil { return nil, err }