Explorar el Código

Runtime: Add DeviceSet singleton

This adds a DeviceSet singleton to the Runtime object which will be used for
any DeviceMapper dependent code.
Alexander Larsson hace 12 años
padre
commit
f317a6b6fe
Se han modificado 4 ficheros con 18 adiciones y 7 borrados
  1. 12 3
      runtime.go
  2. 3 2
      runtime_test.go
  3. 1 1
      server.go
  4. 2 1
      utils_test.go

+ 12 - 3
runtime.go

@@ -38,6 +38,7 @@ type Runtime struct {
 	volumes        *Graph
 	volumes        *Graph
 	srv            *Server
 	srv            *Server
 	Dns            []string
 	Dns            []string
+	deviceSet      DeviceSet
 }
 }
 
 
 var sysInitPath string
 var sysInitPath string
@@ -75,6 +76,13 @@ func (runtime *Runtime) getContainerElement(id string) *list.Element {
 	return nil
 	return nil
 }
 }
 
 
+func (runtime *Runtime) GetDeviceSet() (DeviceSet, error) {
+	if runtime.deviceSet == nil {
+		return nil, fmt.Errorf("No device set available")
+	}
+	return runtime.deviceSet, nil
+}
+
 // Get looks for a container by the specified ID or name, and returns it.
 // Get looks for a container by the specified ID or name, and returns it.
 // If the container is not found, or if an error occurs, nil is returned.
 // If the container is not found, or if an error occurs, nil is returned.
 func (runtime *Runtime) Get(name string) *Container {
 func (runtime *Runtime) Get(name string) *Container {
@@ -438,8 +446,8 @@ func (runtime *Runtime) Commit(container *Container, repository, tag, comment, a
 }
 }
 
 
 // FIXME: harmonize with NewGraph()
 // FIXME: harmonize with NewGraph()
-func NewRuntime(flGraphPath string, autoRestart bool, dns []string) (*Runtime, error) {
-	runtime, err := NewRuntimeFromDirectory(flGraphPath, autoRestart)
+func NewRuntime(flGraphPath string, deviceSet DeviceSet, autoRestart bool, dns []string) (*Runtime, error) {
+	runtime, err := NewRuntimeFromDirectory(flGraphPath, deviceSet, autoRestart)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -457,7 +465,7 @@ func NewRuntime(flGraphPath string, autoRestart bool, dns []string) (*Runtime, e
 	return runtime, nil
 	return runtime, nil
 }
 }
 
 
-func NewRuntimeFromDirectory(root string, autoRestart bool) (*Runtime, error) {
+func NewRuntimeFromDirectory(root string, deviceSet DeviceSet, autoRestart bool) (*Runtime, error) {
 	runtimeRepo := path.Join(root, "containers")
 	runtimeRepo := path.Join(root, "containers")
 
 
 	if err := os.MkdirAll(runtimeRepo, 0700); err != nil && !os.IsExist(err) {
 	if err := os.MkdirAll(runtimeRepo, 0700); err != nil && !os.IsExist(err) {
@@ -494,6 +502,7 @@ func NewRuntimeFromDirectory(root string, autoRestart bool) (*Runtime, error) {
 		capabilities:   &Capabilities{},
 		capabilities:   &Capabilities{},
 		autoRestart:    autoRestart,
 		autoRestart:    autoRestart,
 		volumes:        volumes,
 		volumes:        volumes,
+		deviceSet:      deviceSet,
 	}
 	}
 
 
 	if err := runtime.restore(); err != nil {
 	if err := runtime.restore(); err != nil {

+ 3 - 2
runtime_test.go

@@ -4,6 +4,7 @@ import (
 	"bytes"
 	"bytes"
 	"fmt"
 	"fmt"
 	"github.com/dotcloud/docker/utils"
 	"github.com/dotcloud/docker/utils"
+	"github.com/dotcloud/docker/devmapper"
 	"io"
 	"io"
 	"log"
 	"log"
 	"net"
 	"net"
@@ -87,7 +88,7 @@ func init() {
 	NetworkBridgeIface = unitTestNetworkBridge
 	NetworkBridgeIface = unitTestNetworkBridge
 
 
 	// Make it our Store root
 	// Make it our Store root
-	if runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false); err != nil {
+	if runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, devmapper.NewDeviceSetDM(unitTestStoreBase), false); err != nil {
 		panic(err)
 		panic(err)
 	} else {
 	} else {
 		globalRuntime = runtime
 		globalRuntime = runtime
@@ -456,7 +457,7 @@ func TestRestore(t *testing.T) {
 
 
 	// Here are are simulating a docker restart - that is, reloading all containers
 	// Here are are simulating a docker restart - that is, reloading all containers
 	// from scratch
 	// from scratch
-	runtime2, err := NewRuntimeFromDirectory(runtime1.root, false)
+	runtime2, err := NewRuntimeFromDirectory(runtime1.root, devmapper.NewDeviceSetDM(runtime1.root), false)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}

+ 1 - 1
server.go

@@ -1298,7 +1298,7 @@ func NewServer(flGraphPath string, deviceSet DeviceSet, autoRestart, enableCors
 	if runtime.GOARCH != "amd64" {
 	if runtime.GOARCH != "amd64" {
 		log.Fatalf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH)
 		log.Fatalf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH)
 	}
 	}
-	runtime, err := NewRuntime(flGraphPath, autoRestart, dns)
+	runtime, err := NewRuntime(flGraphPath, deviceSet, autoRestart, dns)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}

+ 2 - 1
utils_test.go

@@ -2,6 +2,7 @@ package docker
 
 
 import (
 import (
 	"github.com/dotcloud/docker/utils"
 	"github.com/dotcloud/docker/utils"
+	"github.com/dotcloud/docker/devmapper"
 	"io"
 	"io"
 	"io/ioutil"
 	"io/ioutil"
 	"os"
 	"os"
@@ -42,7 +43,7 @@ func newTestRuntime() (*Runtime, error) {
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	runtime, err := NewRuntimeFromDirectory(root, false)
+	runtime, err := NewRuntimeFromDirectory(root, devmapper.NewDeviceSetDM(root), false)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}