1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Runtime: Add DeviceSet singleton

This adds a DeviceSet singleton to the Runtime object which will be used for
any DeviceMapper dependent code.
This commit is contained in:
Alexander Larsson 2013-09-05 14:40:12 +02:00 committed by Victor Vieux
parent 87e248f524
commit f317a6b6fe
4 changed files with 18 additions and 7 deletions

View file

@ -38,6 +38,7 @@ type Runtime struct {
volumes *Graph
srv *Server
Dns []string
deviceSet DeviceSet
}
var sysInitPath string
@ -75,6 +76,13 @@ func (runtime *Runtime) getContainerElement(id string) *list.Element {
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.
// If the container is not found, or if an error occurs, nil is returned.
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()
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 {
return nil, err
}
@ -457,7 +465,7 @@ func NewRuntime(flGraphPath string, autoRestart bool, dns []string) (*Runtime, e
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")
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{},
autoRestart: autoRestart,
volumes: volumes,
deviceSet: deviceSet,
}
if err := runtime.restore(); err != nil {

View file

@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"github.com/dotcloud/docker/utils"
"github.com/dotcloud/docker/devmapper"
"io"
"log"
"net"
@ -87,7 +88,7 @@ func init() {
NetworkBridgeIface = unitTestNetworkBridge
// 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)
} else {
globalRuntime = runtime
@ -456,7 +457,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, false)
runtime2, err := NewRuntimeFromDirectory(runtime1.root, devmapper.NewDeviceSetDM(runtime1.root), false)
if err != nil {
t.Fatal(err)
}

View file

@ -1298,7 +1298,7 @@ func NewServer(flGraphPath string, deviceSet DeviceSet, autoRestart, enableCors
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, autoRestart, dns)
runtime, err := NewRuntime(flGraphPath, deviceSet, autoRestart, dns)
if err != nil {
return nil, err
}

View file

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