From da70c9db6fb92c69d722d51873840c4e54dbe86d Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 21 Feb 2019 09:24:34 -0500 Subject: When location of c/storage root changes, set VolumePath We want named volumes to be created in a subdirectory of the c/storage graph root, the same as the libpod root directory is now. As such, we need to adjust its location when the graph root changes location. Also, make a change to how we set the default. There's no need to explicitly set it every time we initialize via an option - that might conflict with WithStorageConfig setting it based on graph root changes. Instead, just initialize it in the default config like our other settings. Signed-off-by: Matthew Heon --- libpod/options.go | 4 ++++ libpod/runtime.go | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'libpod') diff --git a/libpod/options.go b/libpod/options.go index e22c81f91..675ebffda 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -47,6 +47,10 @@ func WithStorageConfig(config storage.StoreOptions) RuntimeOption { rt.config.StaticDir = filepath.Join(config.GraphRoot, "libpod") rt.configuredFrom.libpodStaticDirSet = true + // Also set libpod volume path, so we are a subdirectory + // of the c/storage store by default + rt.config.VolumePath = filepath.Join(config.GraphRoot, "volumes") + setField = true } diff --git a/libpod/runtime.go b/libpod/runtime.go index 52f4523ba..762cea32f 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -123,7 +123,10 @@ type RuntimeConfig struct { // Not included in on-disk config, use the dedicated containers/storage // configuration file instead StorageConfig storage.StoreOptions `toml:"-"` - VolumePath string `toml:"volume_path"` + // VolumePath is the default location that named volumes will be created + // under. This convention is followed by the default volume driver, but + // may not be by other drivers. + VolumePath string `toml:"volume_path"` // ImageDefaultTransport is the default transport method used to fetch // images ImageDefaultTransport string `toml:"image_default_transport"` @@ -238,6 +241,7 @@ var ( defaultRuntimeConfig = RuntimeConfig{ // Leave this empty so containers/storage will use its defaults StorageConfig: storage.StoreOptions{}, + VolumePath: filepath.Join(storage.DefaultStoreOptions.GraphRoot, "volumes"), ImageDefaultTransport: DefaultTransport, StateType: BoltDBStateStore, OCIRuntime: "runc", -- cgit v1.2.3-54-g00ecf From d41d8d090e330fe2f0a3c75d24c409d9c345f841 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 21 Feb 2019 09:42:22 -0500 Subject: Validate VolumePath against DB configuration If this doesn't match, we end up not being able to access named volumes mounted into containers, which is bad. Use the same validation that we use for other critical paths to ensure this one also matches. Signed-off-by: Matthew Heon --- libpod/boltdb_state.go | 2 ++ libpod/boltdb_state_internal.go | 11 +++++++++-- libpod/options.go | 2 ++ libpod/runtime.go | 5 +++++ libpod/state.go | 1 + 5 files changed, 19 insertions(+), 2 deletions(-) (limited to 'libpod') diff --git a/libpod/boltdb_state.go b/libpod/boltdb_state.go index 25ef5cd0e..c226a0617 100644 --- a/libpod/boltdb_state.go +++ b/libpod/boltdb_state.go @@ -261,12 +261,14 @@ func (s *BoltState) GetDBConfig() (*DBConfig, error) { storageRoot := configBucket.Get(graphRootKey) storageTmp := configBucket.Get(runRootKey) graphDriver := configBucket.Get(graphDriverKey) + volumePath := configBucket.Get(volPathKey) cfg.LibpodRoot = string(libpodRoot) cfg.LibpodTmp = string(libpodTmp) cfg.StorageRoot = string(storageRoot) cfg.StorageTmp = string(storageTmp) cfg.GraphDriver = string(graphDriver) + cfg.VolumePath = string(volumePath) return nil }) diff --git a/libpod/boltdb_state_internal.go b/libpod/boltdb_state_internal.go index 3d749849d..936ccbf4c 100644 --- a/libpod/boltdb_state_internal.go +++ b/libpod/boltdb_state_internal.go @@ -38,6 +38,7 @@ const ( graphRootName = "graph-root" graphDriverName = "graph-driver-name" osName = "os" + volPathName = "volume-path" ) var ( @@ -67,6 +68,7 @@ var ( graphRootKey = []byte(graphRootName) graphDriverKey = []byte(graphDriverName) osKey = []byte(osName) + volPathKey = []byte(volPathName) ) // Check if the configuration of the database is compatible with the @@ -105,10 +107,15 @@ func checkRuntimeConfig(db *bolt.DB, rt *Runtime) error { return err } - return validateDBAgainstConfig(configBkt, "storage graph driver", + if err := validateDBAgainstConfig(configBkt, "storage graph driver", rt.config.StorageConfig.GraphDriverName, graphDriverKey, - storage.DefaultStoreOptions.GraphDriverName) + storage.DefaultStoreOptions.GraphDriverName); err != nil { + return err + } + + return validateDBAgainstConfig(configBkt, "volume path", + rt.config.VolumePath, volPathKey, "") }) return err diff --git a/libpod/options.go b/libpod/options.go index 675ebffda..184d5d59f 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -50,6 +50,7 @@ func WithStorageConfig(config storage.StoreOptions) RuntimeOption { // Also set libpod volume path, so we are a subdirectory // of the c/storage store by default rt.config.VolumePath = filepath.Join(config.GraphRoot, "volumes") + rt.configuredFrom.volPathSet = true setField = true } @@ -363,6 +364,7 @@ func WithVolumePath(volPath string) RuntimeOption { } rt.config.VolumePath = volPath + rt.configuredFrom.volPathSet = true return nil } diff --git a/libpod/runtime.go b/libpod/runtime.go index 762cea32f..6e250b7a0 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -235,6 +235,7 @@ type runtimeConfiguredFrom struct { storageRunRootSet bool libpodStaticDirSet bool libpodTmpDirSet bool + volPathSet bool } var ( @@ -645,12 +646,16 @@ func makeRuntime(runtime *Runtime) (err error) { if !runtime.configuredFrom.libpodTmpDirSet && dbConfig.LibpodTmp != "" { runtime.config.TmpDir = dbConfig.LibpodTmp } + if !runtime.configuredFrom.volPathSet && dbConfig.VolumePath != "" { + runtime.config.VolumePath = dbConfig.VolumePath + } logrus.Debugf("Using graph driver %s", runtime.config.StorageConfig.GraphDriverName) logrus.Debugf("Using graph root %s", runtime.config.StorageConfig.GraphRoot) logrus.Debugf("Using run root %s", runtime.config.StorageConfig.RunRoot) logrus.Debugf("Using static dir %s", runtime.config.StaticDir) logrus.Debugf("Using tmp dir %s", runtime.config.TmpDir) + logrus.Debugf("Using volume path %s", runtime.config.VolumePath) // Validate our config against the database, now that we've set our // final storage configuration diff --git a/libpod/state.go b/libpod/state.go index 98282fc83..4296fc3cd 100644 --- a/libpod/state.go +++ b/libpod/state.go @@ -8,6 +8,7 @@ type DBConfig struct { StorageRoot string StorageTmp string GraphDriver string + VolumePath string } // State is a storage backend for libpod's current state. -- cgit v1.2.3-54-g00ecf From 0d697573a6cd506f89c5631115f8322f1b6f84f3 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 25 Feb 2019 11:59:56 -0500 Subject: Add path for named volumes to `podman info` Signed-off-by: Matthew Heon --- libpod/info.go | 1 + 1 file changed, 1 insertion(+) (limited to 'libpod') diff --git a/libpod/info.go b/libpod/info.go index 191ce6810..62088b730 100644 --- a/libpod/info.go +++ b/libpod/info.go @@ -121,6 +121,7 @@ func (r *Runtime) storeInfo() (map[string]interface{}, error) { info["RunRoot"] = r.store.RunRoot() info["GraphDriverName"] = r.store.GraphDriverName() info["GraphOptions"] = r.store.GraphOptions() + info["VolumePath"] = r.config.VolumePath statusPairs, err := r.store.Status() if err != nil { return nil, err -- cgit v1.2.3-54-g00ecf From 5a0a9dfa23900f0bf1c53cf5d6d34a665616129e Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 25 Feb 2019 15:35:30 -0500 Subject: Add debug information when overriding paths with the DB Signed-off-by: Matthew Heon --- libpod/runtime.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'libpod') diff --git a/libpod/runtime.go b/libpod/runtime.go index 6e250b7a0..eb9eb9e83 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -629,24 +629,43 @@ func makeRuntime(runtime *Runtime) (err error) { if !runtime.configuredFrom.storageGraphDriverSet && dbConfig.GraphDriver != "" { if runtime.config.StorageConfig.GraphDriverName != dbConfig.GraphDriver && runtime.config.StorageConfig.GraphDriverName != "" { - logrus.Errorf("User-selected graph driver %s overwritten by graph driver %s from database - delete libpod local files to resolve", + logrus.Errorf("User-selected graph driver %q overwritten by graph driver %q from database - delete libpod local files to resolve", runtime.config.StorageConfig.GraphDriverName, dbConfig.GraphDriver) } runtime.config.StorageConfig.GraphDriverName = dbConfig.GraphDriver } if !runtime.configuredFrom.storageGraphRootSet && dbConfig.StorageRoot != "" { + if runtime.config.StorageConfig.GraphRoot != dbConfig.StorageRoot && + runtime.config.StorageConfig.GraphRoot != "" { + logrus.Debugf("Overriding graph root %q with %q from database", + runtime.config.StorageConfig.GraphRoot, dbConfig.StorageRoot) + } runtime.config.StorageConfig.GraphRoot = dbConfig.StorageRoot } if !runtime.configuredFrom.storageRunRootSet && dbConfig.StorageTmp != "" { + if runtime.config.StorageConfig.RunRoot != dbConfig.StorageTmp && + runtime.config.StorageConfig.RunRoot != "" { + logrus.Debugf("Overriding run root %q with %q from database", + runtime.config.StorageConfig.RunRoot, dbConfig.StorageTmp) + } runtime.config.StorageConfig.RunRoot = dbConfig.StorageTmp } if !runtime.configuredFrom.libpodStaticDirSet && dbConfig.LibpodRoot != "" { + if runtime.config.StaticDir != dbConfig.LibpodRoot && runtime.config.StaticDir != "" { + logrus.Debugf("Overriding static dir %q with %q from database", runtime.config.StaticDir, dbConfig.LibpodRoot) + } runtime.config.StaticDir = dbConfig.LibpodRoot } if !runtime.configuredFrom.libpodTmpDirSet && dbConfig.LibpodTmp != "" { + if runtime.config.TmpDir != dbConfig.LibpodTmp && runtime.config.TmpDir != "" { + logrus.Debugf("Overriding tmp dir %q with %q from database", runtime.config.TmpDir, dbConfig.LibpodTmp) + } runtime.config.TmpDir = dbConfig.LibpodTmp } if !runtime.configuredFrom.volPathSet && dbConfig.VolumePath != "" { + if runtime.config.VolumePath != dbConfig.VolumePath && runtime.config.VolumePath != "" { + logrus.Debugf("Overriding volume path %q with %q from database", runtime.config.VolumePath, dbConfig.VolumePath) + } runtime.config.VolumePath = dbConfig.VolumePath } -- cgit v1.2.3-54-g00ecf From ba6f1acf07d1eddcd810cdb4265a8961770329c6 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 25 Feb 2019 15:37:20 -0500 Subject: Record when volume path is explicitly set in config This ensures we won't overwrite it when it's set in the config we load from disk. Signed-off-by: Matthew Heon --- libpod/runtime.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libpod') diff --git a/libpod/runtime.go b/libpod/runtime.go index eb9eb9e83..827c22f5b 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -405,6 +405,9 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) { if tmpConfig.TmpDir != "" { runtime.configuredFrom.libpodTmpDirSet = true } + if tmpConfig.VolumePath != "" { + runtime.configuredFrom.volPathSet = true + } if _, err := toml.Decode(string(contents), runtime.config); err != nil { return nil, errors.Wrapf(err, "error decoding configuration file %s", configPath) -- cgit v1.2.3-54-g00ecf