瀏覽代碼

daemon: do not use pointers to map

Also, do not shadow err with :=

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Alexander Morozov 8 年之前
父節點
當前提交
44c280afbf
共有 4 個文件被更改,包括 19 次插入17 次删除
  1. 10 12
      daemon/daemon.go
  2. 2 1
      daemon/daemon_solaris.go
  3. 5 3
      daemon/daemon_unix.go
  4. 2 1
      daemon/daemon_windows.go

+ 10 - 12
daemon/daemon.go

@@ -961,25 +961,23 @@ func (daemon *Daemon) initDiscovery(config *Config) error {
 // - Daemon max concurrent uploads
 // - Cluster discovery (reconfigure and restart).
 // - Daemon live restore
-func (daemon *Daemon) Reload(config *Config) error {
-	var err error
-	// used to hold reloaded changes
-	attributes := map[string]string{}
+func (daemon *Daemon) Reload(config *Config) (err error) {
+
+	daemon.configStore.reloadLock.Lock()
+
+	attributes := daemon.platformReload(config)
 
-	// We need defer here to ensure the lock is released as
-	// daemon.SystemInfo() will try to get it too
 	defer func() {
+		// we're unlocking here, because
+		// LogDaemonEventWithAttributes() -> SystemInfo() -> GetAllRuntimes()
+		// holds that lock too.
+		daemon.configStore.reloadLock.Unlock()
 		if err == nil {
 			daemon.LogDaemonEventWithAttributes("reload", attributes)
 		}
 	}()
 
-	daemon.configStore.reloadLock.Lock()
-	defer daemon.configStore.reloadLock.Unlock()
-
-	daemon.platformReload(config, &attributes)
-
-	if err = daemon.reloadClusterDiscovery(config); err != nil {
+	if err := daemon.reloadClusterDiscovery(config); err != nil {
 		return err
 	}
 

+ 2 - 1
daemon/daemon_solaris.go

@@ -78,7 +78,8 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.
 }
 
 // platformReload update configuration with platform specific options
-func (daemon *Daemon) platformReload(config *Config, attributes *map[string]string) {
+func (daemon *Daemon) platformReload(config *Config) map[string]string {
+	return map[string]string{}
 }
 
 // verifyDaemonSettings performs validation of daemon config struct

+ 5 - 3
daemon/daemon_unix.go

@@ -516,7 +516,7 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.
 }
 
 // platformReload update configuration with platform specific options
-func (daemon *Daemon) platformReload(config *Config, attributes *map[string]string) {
+func (daemon *Daemon) platformReload(config *Config) map[string]string {
 	if config.IsValueSet("runtimes") {
 		daemon.configStore.Runtimes = config.Runtimes
 		// Always set the default one
@@ -536,8 +536,10 @@ func (daemon *Daemon) platformReload(config *Config, attributes *map[string]stri
 		runtimeList.WriteString(fmt.Sprintf("%s:%s", name, rt))
 	}
 
-	(*attributes)["runtimes"] = runtimeList.String()
-	(*attributes)["default-runtime"] = daemon.configStore.DefaultRuntime
+	return map[string]string{
+		"runtimes":        runtimeList.String(),
+		"default-runtime": daemon.configStore.DefaultRuntime,
+	}
 }
 
 // verifyDaemonSettings performs validation of daemon config struct

+ 2 - 1
daemon/daemon_windows.go

@@ -153,7 +153,8 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.
 }
 
 // platformReload update configuration with platform specific options
-func (daemon *Daemon) platformReload(config *Config, attributes *map[string]string) {
+func (daemon *Daemon) platformReload(config *Config) map[string]string {
+	return map[string]string{}
 }
 
 // verifyDaemonSettings performs validation of daemon config struct