From 3a246ac3d1368931998a082043c9b719dd3c10cd Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 16 Oct 2013 20:42:50 +0000 Subject: [PATCH] Change default values for devicemapper as variable instead of env --- devmapper/deviceset_devmapper.go | 37 ++++++-------------------------- runtime_test.go | 14 +++++++----- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/devmapper/deviceset_devmapper.go b/devmapper/deviceset_devmapper.go index 876d781fba..e55b3d482f 100644 --- a/devmapper/deviceset_devmapper.go +++ b/devmapper/deviceset_devmapper.go @@ -17,9 +17,9 @@ import ( ) var ( - defaultDataLoopbackSize int64 = 100 * 1024 * 1024 * 1024 - defaultMetaDataLoopbackSize int64 = 2 * 1024 * 1024 * 1024 - defaultBaseFsSize uint64 = 10 * 1024 * 1024 * 1024 + DefaultDataLoopbackSize int64 = 100 * 1024 * 1024 * 1024 + DefaultMetaDataLoopbackSize int64 = 2 * 1024 * 1024 * 1024 + DefaultBaseFsSize uint64 = 10 * 1024 * 1024 * 1024 ) type DevInfo struct { @@ -47,30 +47,6 @@ type DeviceSetDM struct { activeMounts map[string]int } -func init() { - var err error - - rawMetaSize := os.Getenv("DOCKER_LOOPBACK_META_SIZE") - rawDataSize := os.Getenv("DOCKER_LOOPBACK_DATA_SIZE") - rawBaseFSSize := os.Getenv("DOCKER_BASE_FS_SIZE") - - if rawMetaSize != "" { - if defaultMetaDataLoopbackSize, err = strconv.ParseInt(rawMetaSize, 0, 0); err != nil { - panic(err) - } - } - if rawDataSize != "" { - if defaultDataLoopbackSize, err = strconv.ParseInt(rawDataSize, 0, 0); err != nil { - panic(err) - } - } - if rawBaseFSSize != "" { - if defaultBaseFsSize, err = strconv.ParseUint(rawBaseFSSize, 0, 0); err != nil { - panic(err) - } - } -} - func getDevName(name string) string { return "/dev/mapper/" + name } @@ -307,7 +283,8 @@ func (devices *DeviceSetDM) setupBaseImage() error { return err } - info, err := devices.registerDevice(id, "", defaultBaseFsSize) + utils.Debugf("Registering base device (id %v) with FS size %v", id, DefaultBaseFsSize) + info, err := devices.registerDevice(id, "", DefaultBaseFsSize) if err != nil { _ = deleteDevice(devices.getPoolDevName(), id) utils.Debugf("\n--->Err: %s\n", err) @@ -416,13 +393,13 @@ begin: /* If we create the loopback mounts we also need to initialize the base fs */ createdLoopback := !devices.hasImage("data") || !devices.hasImage("metadata") - data, err := devices.ensureImage("data", defaultDataLoopbackSize) + data, err := devices.ensureImage("data", DefaultDataLoopbackSize) if err != nil { utils.Debugf("Error device ensureImage (data): %s\n", err) return err } - metadata, err := devices.ensureImage("metadata", defaultMetaDataLoopbackSize) + metadata, err := devices.ensureImage("metadata", DefaultMetaDataLoopbackSize) if err != nil { utils.Debugf("Error device ensureImage (metadata): %s\n", err) return err diff --git a/runtime_test.go b/runtime_test.go index 79b39ddb89..9c044538d7 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -28,6 +28,10 @@ const ( unitTestStoreBase = "/var/lib/docker/unit-tests" testDaemonAddr = "127.0.0.1:4270" testDaemonProto = "tcp" + + unitTestDMDataLoopbackSize = 209715200 // 200MB + unitTestDMMetaDataLoopbackSize = 104857600 // 100MB + unitTestDMBaseFsSize = 157286400 // 150MB ) var ( @@ -152,9 +156,11 @@ func cleanupDevMapper() error { 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 + // Set unit-test specific values + devmapper.DefaultDataLoopbackSize = unitTestDMDataLoopbackSize + devmapper.DefaultMetaDataLoopbackSize = unitTestDMMetaDataLoopbackSize + devmapper.DefaultBaseFsSize = unitTestDMBaseFsSize + NetworkBridgeIface = unitTestNetworkBridge // Hack to run sys init during unit testing if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || selfPath == "/.dockerinit" { @@ -166,8 +172,6 @@ func init() { log.Fatal("docker tests need to be run as root") } - NetworkBridgeIface = unitTestNetworkBridge - if err := cleanupDevMapper(); err != nil { log.Fatalf("Unable to cleanup devmapper: %s", err) }