summaryrefslogtreecommitdiff
path: root/libpod/boltdb_state_internal.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-02-28 15:31:58 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-03-01 14:16:55 +0000
commitcb7b0edc5b9f2ef7dda80a69e63fdad034e3e600 (patch)
tree5d9c513e5a9b62528dc8b5ef54c39ff7cd0fb442 /libpod/boltdb_state_internal.go
parente038393cf5aeef713b792ea2c1dd679645e36342 (diff)
downloadpodman-cb7b0edc5b9f2ef7dda80a69e63fdad034e3e600.tar.gz
podman-cb7b0edc5b9f2ef7dda80a69e63fdad034e3e600.tar.bz2
podman-cb7b0edc5b9f2ef7dda80a69e63fdad034e3e600.zip
Fix checks for configuration keys in the DB
Currently, we will error if the DB is configured with the default containers/storage config, and then opened by a libpod which has explicitly set the defaults. This is due to us using an empty config by default (to tell c/storage to use its defaults). This patch changes our handling so that unset storage config (using the default) and explicitly setting the defaults are both compatible. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #423 Approved by: baude
Diffstat (limited to 'libpod/boltdb_state_internal.go')
-rw-r--r--libpod/boltdb_state_internal.go39
1 files changed, 32 insertions, 7 deletions
diff --git a/libpod/boltdb_state_internal.go b/libpod/boltdb_state_internal.go
index 033dbe8bd..9c05dcc3a 100644
--- a/libpod/boltdb_state_internal.go
+++ b/libpod/boltdb_state_internal.go
@@ -64,28 +64,31 @@ func checkRuntimeConfig(db *bolt.DB, runtime *Runtime) error {
}
if err := validateDBAgainstConfig(configBkt, "static dir",
- runtime.config.StaticDir, staticDir); err != nil {
+ runtime.config.StaticDir, staticDir, ""); err != nil {
return err
}
if err := validateDBAgainstConfig(configBkt, "tmp dir",
- runtime.config.TmpDir, tmpDir); err != nil {
+ runtime.config.TmpDir, tmpDir, ""); err != nil {
return err
}
if err := validateDBAgainstConfig(configBkt, "run root",
- runtime.config.StorageConfig.RunRoot, runRoot); err != nil {
+ runtime.config.StorageConfig.RunRoot, runRoot,
+ storage.DefaultStoreOptions.RunRoot); err != nil {
return err
}
if err := validateDBAgainstConfig(configBkt, "graph root",
- runtime.config.StorageConfig.GraphRoot, graphRoot); err != nil {
+ runtime.config.StorageConfig.GraphRoot, graphRoot,
+ storage.DefaultStoreOptions.GraphRoot); err != nil {
return err
}
return validateDBAgainstConfig(configBkt, "graph driver name",
runtime.config.StorageConfig.GraphDriverName,
- graphDriverName)
+ graphDriverName,
+ storage.DefaultStoreOptions.GraphDriverName)
})
return err
@@ -93,14 +96,36 @@ func checkRuntimeConfig(db *bolt.DB, runtime *Runtime) error {
// Validate a configuration entry in the DB against current runtime config
// If the given configuration key does not exist it will be created
-func validateDBAgainstConfig(bucket *bolt.Bucket, fieldName, runtimeValue string, keyName []byte) error {
+// If the given runtimeValue or value retrieved from the database are the empty
+// string and defaultValue is not, defaultValue will be checked instead. This
+// ensures that we will not fail on configuration changes in configured c/storage.
+func validateDBAgainstConfig(bucket *bolt.Bucket, fieldName, runtimeValue string, keyName []byte, defaultValue string) error {
keyBytes := bucket.Get(keyName)
if keyBytes == nil {
- if err := bucket.Put(keyName, []byte(runtimeValue)); err != nil {
+ dbValue := []byte(runtimeValue)
+ if runtimeValue == "" && defaultValue != "" {
+ dbValue = []byte(defaultValue)
+ }
+
+ if err := bucket.Put(keyName, dbValue); err != nil {
return errors.Wrapf(err, "error updating %s in DB runtime config", fieldName)
}
} else {
if runtimeValue != string(keyBytes) {
+ // If runtimeValue is the empty string, check against
+ // the default
+ if runtimeValue == "" && defaultValue != "" &&
+ string(keyBytes) == defaultValue {
+ return nil
+ }
+
+ // If DB value is the empty string, check that the
+ // runtime value is the default
+ if string(keyBytes) == "" && defaultValue != "" &&
+ runtimeValue == defaultValue {
+ return nil
+ }
+
return errors.Wrapf(ErrDBBadConfig, "database %s %s does not match our %s %s",
fieldName, string(keyBytes), fieldName, runtimeValue)
}