Преглед на файлове

Initialize devicemapper in NewRuntimeFromDIrectory

Solomon Hykes преди 11 години
родител
ревизия
7093411a8d
променени са 5 файла, в които са добавени 20 реда и са изтрити 23 реда
  1. 1 2
      docker/docker.go
  2. 6 3
      runtime.go
  3. 10 14
      runtime_test.go
  4. 2 2
      server.go
  5. 1 2
      utils_test.go

+ 1 - 2
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
 	}

+ 6 - 3
runtime.go

@@ -4,6 +4,7 @@ import (
 	"container/list"
 	"fmt"
 	"github.com/dotcloud/docker/utils"
+	"github.com/dotcloud/docker/devmapper"
 	"io"
 	"io/ioutil"
 	"log"
@@ -555,8 +556,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
 	}
@@ -574,7 +575,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) {
@@ -600,6 +601,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,

+ 10 - 14
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)
 }
 
@@ -166,24 +168,18 @@ func init() {
 		log.Fatalf("Unable to cleanup devmapper: %s", err)
 	}
 
-	// Always start from a clean set of loopback mounts
-	err := os.RemoveAll(unitTestStoreDevicesBase)
-	if err != nil {
-		panic(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
-	deviceset.AddDevice("init", "")
-
 	// 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,
@@ -548,7 +544,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)
 	}

+ 2 - 2
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
 	}

+ 1 - 2
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
 	}