From a85667f80a8bc56f5e88b0ebbc652b59d6b42ef6 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 8 Oct 2013 14:54:00 +0200 Subject: [PATCH 1/2] Clean up better from previous unit-test runs This makes sure we unmount existing mounts (as well as removing the devmapper devices), and it fails with proper logs rather than just panic()ing. --- runtime_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/runtime_test.go b/runtime_test.go index e8a6ce08f..a24fd2360 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -98,11 +98,25 @@ func removeDev(name string) { syscall.Close(fd) } if err := devmapper.RemoveDevice(name); err != nil { - panic(fmt.Errorf("Unable to remove existing device %s: %s", name, err)) + log.Fatalf("Unable to remove device %s needed to get a freash unit test environment", name) } } func cleanupDevMapper() { + // Unmount any leftover mounts from previous unit test runs + if data, err := ioutil.ReadFile("/proc/mounts"); err == nil { + for _, line := range strings.Split(string(data), "\n") { + cols := strings.Split(line, " ") + if len(cols) >= 2 && strings.HasPrefix(cols[0], "/dev/mapper/docker-unit-tests-devices") { + err = syscall.Unmount(cols[1], 0) + if err != nil { + log.Fatalf("Unable to unmount %s needed to get a freash unit test environment: %s", cols[1], err) + } + } + } + } + + // Remove any leftover devmapper devices from previous unit run tests infos, _ := ioutil.ReadDir("/dev/mapper") if infos != nil { hasPool := false From 875b3001f8987ca53556be45df13290768a672a8 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Tue, 8 Oct 2013 17:00:40 -0700 Subject: [PATCH 2/2] Migrate AUFS containers to devmapper --- hack/make.sh | 2 +- runtime.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/hack/make.sh b/hack/make.sh index a5d66e367..0dd07bfec 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -45,7 +45,7 @@ fi # Use these flags when compiling the tests and final binary LDFLAGS='-X main.GITCOMMIT "'$GITCOMMIT'" -X main.VERSION "'$VERSION'" -w -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-all"' -BUILDFLAGS='-tags netgo' +BUILDFLAGS='-tags netgo -a' bundle() { diff --git a/runtime.go b/runtime.go index ba2dc9fcc..0a17bfd15 100644 --- a/runtime.go +++ b/runtime.go @@ -321,7 +321,56 @@ func (runtime *Runtime) restore() error { } return len(ic.Links) < len(jc.Links) }) + + deviceSet := runtime.config.DeviceSet for _, container := range containers { + + // Perform a migration for aufs containers + if !deviceSet.HasDevice(container.ID) { + contents, err := ioutil.ReadDir(container.rwPath()) + if err != nil { + if !os.IsNotExist(err) { + utils.Debugf("[migration] Error reading rw dir %s", err) + } + continue + } + + if len(contents) > 0 { + utils.Debugf("[migration] Begin migration of %s", container.ID) + + image, err := runtime.graph.Get(container.Image) + if err != nil { + utils.Debugf("[migratoin] Failed to get image %s", err) + continue + } + + unmount := func() { + if err := image.Unmount(runtime, container.RootfsPath(), container.ID); err != nil { + utils.Debugf("[migraton] Failed to unmount image %s", err) + } + } + + if err := image.Mount(runtime, container.RootfsPath(), container.rwPath(), container.ID); err != nil { + utils.Debugf("[migratoin] Failed to mount image %s", err) + continue + } + + if err := image.applyLayer(container.rwPath(), container.RootfsPath()); err != nil { + utils.Debugf("[migration] Failed to apply layer %s", err) + unmount() + continue + } + + unmount() + + if err := os.RemoveAll(container.rwPath()); err != nil { + utils.Debugf("[migration] Failed to remove rw dir %s", err) + } + + utils.Debugf("[migration] End migration of %s", container.ID) + } + } + if err := runtime.Register(container); err != nil { utils.Debugf("Failed to register container %s: %s", container.ID, err) continue