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:
parent
87e248f524
commit
f317a6b6fe
4 changed files with 18 additions and 7 deletions
15
runtime.go
15
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) {
|
func NewRuntime(flGraphPath string, deviceSet DeviceSet, autoRestart bool, dns []string) (*Runtime, error) {
|
||||||
runtime, err := NewRuntimeFromDirectory(flGraphPath, autoRestart)
|
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 {
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue