mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon: make config reloading more transactional
Config reloading has interleaved validations and other fallible operations with mutating the live daemon configuration. The daemon configuration could be left in a partially-reloaded state if any of the operations returns an error. Mutating a copy of the configuration and atomically swapping the config struct on success is not currently an option as config values are not copyable due to the presence of sync.Mutex fields. Introduce a two-phase commit protocol to defer any mutations of the daemon state until after all fallible operations have succeeded. Reload transactions are not yet entirely hermetic. The platform reloading logic for custom runtimes on *nix could still leave the directory of generated runtime wrapper scripts in an indeterminate state if an error is encountered. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
@@ -12,50 +12,56 @@ import (
|
||||
|
||||
// reloadPlatform updates configuration with platform specific options
|
||||
// and updates the passed attributes
|
||||
func (daemon *Daemon) reloadPlatform(conf *config.Config, attributes map[string]string) error {
|
||||
if err := conf.ValidatePlatformConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
func (daemon *Daemon) reloadPlatform(conf *config.Config) (func(attributes map[string]string), error) {
|
||||
var txns []func()
|
||||
|
||||
if conf.IsValueSet("runtimes") {
|
||||
// Always set the default one
|
||||
conf.Runtimes[config.StockRuntimeName] = types.Runtime{Path: config.DefaultRuntimeBinary}
|
||||
if err := daemon.initRuntimes(conf.Runtimes); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
daemon.configStore.Runtimes = conf.Runtimes
|
||||
txns = append(txns, func() {
|
||||
daemon.configStore.Runtimes = conf.Runtimes
|
||||
})
|
||||
}
|
||||
|
||||
if conf.DefaultRuntime != "" {
|
||||
daemon.configStore.DefaultRuntime = conf.DefaultRuntime
|
||||
txns = append(txns, func() {
|
||||
daemon.configStore.DefaultRuntime = conf.DefaultRuntime
|
||||
})
|
||||
}
|
||||
|
||||
if conf.IsValueSet("default-shm-size") {
|
||||
daemon.configStore.ShmSize = conf.ShmSize
|
||||
}
|
||||
|
||||
if conf.CgroupNamespaceMode != "" {
|
||||
daemon.configStore.CgroupNamespaceMode = conf.CgroupNamespaceMode
|
||||
}
|
||||
|
||||
if conf.IpcMode != "" {
|
||||
daemon.configStore.IpcMode = conf.IpcMode
|
||||
}
|
||||
|
||||
// Update attributes
|
||||
var runtimeList bytes.Buffer
|
||||
for name, rt := range daemon.configStore.Runtimes {
|
||||
if runtimeList.Len() > 0 {
|
||||
runtimeList.WriteRune(' ')
|
||||
return func(attributes map[string]string) {
|
||||
for _, commit := range txns {
|
||||
commit()
|
||||
}
|
||||
runtimeList.WriteString(name + ":" + rt.Path)
|
||||
}
|
||||
|
||||
attributes["runtimes"] = runtimeList.String()
|
||||
attributes["default-runtime"] = daemon.configStore.DefaultRuntime
|
||||
attributes["default-shm-size"] = strconv.FormatInt(int64(daemon.configStore.ShmSize), 10)
|
||||
attributes["default-ipc-mode"] = daemon.configStore.IpcMode
|
||||
attributes["default-cgroupns-mode"] = daemon.configStore.CgroupNamespaceMode
|
||||
if conf.IsValueSet("default-shm-size") {
|
||||
daemon.configStore.ShmSize = conf.ShmSize
|
||||
}
|
||||
|
||||
return nil
|
||||
if conf.CgroupNamespaceMode != "" {
|
||||
daemon.configStore.CgroupNamespaceMode = conf.CgroupNamespaceMode
|
||||
}
|
||||
|
||||
if conf.IpcMode != "" {
|
||||
daemon.configStore.IpcMode = conf.IpcMode
|
||||
}
|
||||
|
||||
// Update attributes
|
||||
var runtimeList bytes.Buffer
|
||||
for name, rt := range daemon.configStore.Runtimes {
|
||||
if runtimeList.Len() > 0 {
|
||||
runtimeList.WriteRune(' ')
|
||||
}
|
||||
runtimeList.WriteString(name + ":" + rt.Path)
|
||||
}
|
||||
|
||||
attributes["runtimes"] = runtimeList.String()
|
||||
attributes["default-runtime"] = daemon.configStore.DefaultRuntime
|
||||
attributes["default-shm-size"] = strconv.FormatInt(int64(daemon.configStore.ShmSize), 10)
|
||||
attributes["default-ipc-mode"] = daemon.configStore.IpcMode
|
||||
attributes["default-cgroupns-mode"] = daemon.configStore.CgroupNamespaceMode
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user