diff --git a/container.go b/container.go index 8dfcbcf3eb..f133bce142 100644 --- a/container.go +++ b/container.go @@ -43,6 +43,7 @@ type Container struct { ResolvConfPath string HostnamePath string HostsPath string + FilesystemType string cmd *exec.Cmd stdout *utils.WriteBroadcaster diff --git a/runtime.go b/runtime.go index dfcb2c1c70..39c9913413 100644 --- a/runtime.go +++ b/runtime.go @@ -16,6 +16,10 @@ import ( "time" ) +const ( + DefaultFilesystemType = "devicemapper" +) + var defaultDns = []string{"8.8.8.8", "8.8.4.4"} type Capabilities struct { @@ -268,9 +272,10 @@ func (runtime *Runtime) restore() error { return err } - deviceSet := runtime.deviceSet - containers := []*Container{} - containersToMigrate := []*Container{} + var ( + containers []*Container + containersToMigrate []*Container + ) for i, v := range dir { id := v.Name() @@ -285,12 +290,12 @@ func (runtime *Runtime) restore() error { utils.Debugf("Loaded container %v", container.ID) containers = append(containers, container) - if !deviceSet.HasDevice(container.ID) { + if container.FilesystemType != DefaultFilesystemType { containersToMigrate = append(containersToMigrate, container) } } - // Migrate AUFS containers to device mapper + // Migrate containers to the default filesystem type if len(containersToMigrate) > 0 { if err := migrateToDeviceMapper(runtime, containersToMigrate); err != nil { return err @@ -366,6 +371,11 @@ func migrateToDeviceMapper(runtime *Runtime, containers []*Container) error { fmt.Printf("Failed to remove rw layer %s\n", err) } + container.FilesystemType = DefaultFilesystemType + if err := container.ToDisk(); err != nil { + fmt.Printf("Failed to save filesystem type to disk %s\n", err) + } + fmt.Printf("Successful migration for %s\n", container.ID) } fmt.Printf("Migration complete\n") @@ -448,7 +458,8 @@ func (runtime *Runtime) Create(config *Config) (*Container, error) { Image: img.ID, // Always use the resolved image id NetworkSettings: &NetworkSettings{}, // FIXME: do we need to store this in the container? - SysInitPath: sysInitPath, + SysInitPath: sysInitPath, + FilesystemType: DefaultFilesystemType, } container.root = runtime.containerRoot(container.ID) // Step 1: create the container directory. diff --git a/runtime_test.go b/runtime_test.go index dd670f0ce0..6cae6e6f82 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -148,7 +148,7 @@ func init() { os.Setenv("TEST", "1") os.Setenv("DOCKER_LOOPBACK_DATA_SIZE", "209715200") // 200MB os.Setenv("DOCKER_LOOPBACK_META_SIZE", "104857600") // 100MB - os.Setenv("DOCKER_BASE_FS_SIZE", "157286400") // 150MB + os.Setenv("DOCKER_BASE_FS_SIZE", "157286400") // 150MB // Hack to run sys init during unit testing if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || selfPath == "/.dockerinit" { @@ -575,3 +575,15 @@ func TestRestore(t *testing.T) { } container2.State.Running = false } + +func TestContainerCreatedWithDefaultFilesystemType(t *testing.T) { + runtime := mkRuntime(t) + defer nuke(runtime) + + container, _, _ := mkContainer(runtime, []string{"_", "ls", "-al"}, t) + defer runtime.Destroy(container) + + if container.FilesystemType != DefaultFilesystemType { + t.Fatalf("Container filesystem type should be %s but got %s", DefaultFilesystemType, container.FilesystemType) + } +}