Prechádzať zdrojové kódy

Add filesystemtype for containers

If no type is specified then assume aufs.
Michael Crosby 11 rokov pred
rodič
commit
80bd64245f
3 zmenil súbory, kde vykonal 31 pridanie a 7 odobranie
  1. 1 0
      container.go
  2. 17 6
      runtime.go
  3. 13 1
      runtime_test.go

+ 1 - 0
container.go

@@ -43,6 +43,7 @@ type Container struct {
 	ResolvConfPath string
 	HostnamePath   string
 	HostsPath      string
+	FilesystemType string
 
 	cmd       *exec.Cmd
 	stdout    *utils.WriteBroadcaster

+ 17 - 6
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.

+ 13 - 1
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)
+	}
+}