Initialize devicemapper in NewRuntimeFromDIrectory
This commit is contained in:
parent
5892c8e469
commit
7093411a8d
5 changed files with 20 additions and 23 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker"
|
"github.com/dotcloud/docker"
|
||||||
"github.com/dotcloud/docker/devmapper"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -134,7 +133,7 @@ func daemon(pidfile string, flGraphPath string, protoAddrs []string, autoRestart
|
||||||
if flDns != "" {
|
if flDns != "" {
|
||||||
dns = []string{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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
|
"github.com/dotcloud/docker/devmapper"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -555,8 +556,8 @@ func (runtime *Runtime) Commit(container *Container, repository, tag, comment, a
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: harmonize with NewGraph()
|
// FIXME: harmonize with NewGraph()
|
||||||
func NewRuntime(flGraphPath string, deviceSet DeviceSet, autoRestart bool, dns []string) (*Runtime, error) {
|
func NewRuntime(flGraphPath string, autoRestart bool, dns []string) (*Runtime, error) {
|
||||||
runtime, err := NewRuntimeFromDirectory(flGraphPath, deviceSet, autoRestart)
|
runtime, err := NewRuntimeFromDirectory(flGraphPath, autoRestart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -574,7 +575,7 @@ func NewRuntime(flGraphPath string, deviceSet DeviceSet, autoRestart bool, dns [
|
||||||
return runtime, nil
|
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")
|
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) {
|
||||||
|
@ -600,6 +601,8 @@ func NewRuntimeFromDirectory(root string, deviceSet DeviceSet, autoRestart bool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
deviceSet := devmapper.NewDeviceSetDM(root)
|
||||||
|
// Initialize devicemapper deviceSet
|
||||||
runtime := &Runtime{
|
runtime := &Runtime{
|
||||||
root: root,
|
root: root,
|
||||||
repository: runtimeRepo,
|
repository: runtimeRepo,
|
||||||
|
|
|
@ -25,7 +25,6 @@ const (
|
||||||
unitTestImageID = "83599e29c455eb719f77d799bc7c51521b9551972f5a850d7ad265bc1b5292f6" // 1.0
|
unitTestImageID = "83599e29c455eb719f77d799bc7c51521b9551972f5a850d7ad265bc1b5292f6" // 1.0
|
||||||
unitTestNetworkBridge = "testdockbr0"
|
unitTestNetworkBridge = "testdockbr0"
|
||||||
unitTestStoreBase = "/var/lib/docker/unit-tests"
|
unitTestStoreBase = "/var/lib/docker/unit-tests"
|
||||||
unitTestStoreDevicesBase = "/var/lib/docker/unit-tests-devices"
|
|
||||||
testDaemonAddr = "127.0.0.1:4270"
|
testDaemonAddr = "127.0.0.1:4270"
|
||||||
testDaemonProto = "tcp"
|
testDaemonProto = "tcp"
|
||||||
)
|
)
|
||||||
|
@ -51,6 +50,9 @@ func nuke(runtime *Runtime) error {
|
||||||
for _, container := range runtime.List() {
|
for _, container := range runtime.List() {
|
||||||
container.EnsureUnmounted()
|
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)
|
return os.RemoveAll(runtime.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,24 +168,18 @@ func init() {
|
||||||
log.Fatalf("Unable to cleanup devmapper: %s", err)
|
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
|
// 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)
|
log.Fatalf("Unable to create a runtime for tests:", err)
|
||||||
} else {
|
} else {
|
||||||
globalRuntime = runtime
|
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"
|
// Create the "Server"
|
||||||
srv := &Server{
|
srv := &Server{
|
||||||
runtime: globalRuntime,
|
runtime: globalRuntime,
|
||||||
|
@ -548,7 +544,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, runtime1.deviceSet, false)
|
runtime2, err := NewRuntimeFromDirectory(runtime1.root, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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" {
|
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, deviceSet, autoRestart, dns)
|
runtime, err := NewRuntime(flGraphPath, autoRestart, dns)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -43,7 +42,7 @@ func newTestRuntime() (*Runtime, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime, err := NewRuntimeFromDirectory(root, NewDeviceSetWrapper(globalRuntime.deviceSet, filepath.Base(root)), false)
|
runtime, err := NewRuntimeFromDirectory(root, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue