mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
Merge pull request #2397 from mheon/volume_path_fixes
Volume path fixes
This commit is contained in:
@ -21,7 +21,7 @@ func GetRuntime(c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
|
||||
func getRuntime(c *cliconfig.PodmanCommand, renumber bool) (*libpod.Runtime, error) {
|
||||
options := []libpod.RuntimeOption{}
|
||||
|
||||
storageOpts, volumePath, err := util.GetDefaultStoreOptions()
|
||||
storageOpts, _, err := util.GetDefaultStoreOptions()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -120,7 +120,6 @@ func getRuntime(c *cliconfig.PodmanCommand, renumber bool) (*libpod.Runtime, err
|
||||
infraCommand, _ := c.Flags().GetString("infra-command")
|
||||
options = append(options, libpod.WithDefaultInfraCommand(infraCommand))
|
||||
}
|
||||
options = append(options, libpod.WithVolumePath(volumePath))
|
||||
if c.Flags().Changed("config") {
|
||||
return libpod.NewRuntimeFromConfig(c.GlobalFlags.Config, options...)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ libpod to manage containers.
|
||||
Default transport method for pulling and pushing images
|
||||
|
||||
**runtime**=""
|
||||
Default OCI runtime to use if nothing is specified
|
||||
Default OCI runtime to use if nothing is specified in **runtimes**
|
||||
|
||||
**runtimes**
|
||||
For each OCI runtime, specify a list of paths to look for. The first one found is used.
|
||||
@ -87,6 +87,10 @@ libpod to manage containers.
|
||||
The default number available is 2048.
|
||||
If this is changed, a lock renumbering must be performed, using the `podman system renumber` command.
|
||||
|
||||
**volume_path**=""
|
||||
Directory where named volumes will be created in using the default volume driver.
|
||||
By default this will be configured relative to where containers/storage stores containers.
|
||||
|
||||
## FILES
|
||||
`/usr/share/containers/libpod.conf`, default libpod configuration path
|
||||
|
||||
|
@ -93,6 +93,12 @@ pause_command = "/pause"
|
||||
# 'podman system renumber' command).
|
||||
num_locks = 2048
|
||||
|
||||
# Directory for libpod named volumes.
|
||||
# By default, this will be configured relative to where containers/storage
|
||||
# stores containers.
|
||||
# Uncomment to change location from this default.
|
||||
#volume_path = "/var/lib/containers/storage/volumes"
|
||||
|
||||
# Default OCI runtime
|
||||
runtime = "runc"
|
||||
|
||||
|
@ -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
|
||||
})
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -47,6 +47,11 @@ 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")
|
||||
rt.configuredFrom.volPathSet = true
|
||||
|
||||
setField = true
|
||||
}
|
||||
|
||||
@ -359,6 +364,7 @@ func WithVolumePath(volPath string) RuntimeOption {
|
||||
}
|
||||
|
||||
rt.config.VolumePath = volPath
|
||||
rt.configuredFrom.volPathSet = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -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"`
|
||||
@ -232,12 +235,14 @@ type runtimeConfiguredFrom struct {
|
||||
storageRunRootSet bool
|
||||
libpodStaticDirSet bool
|
||||
libpodTmpDirSet bool
|
||||
volPathSet bool
|
||||
}
|
||||
|
||||
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",
|
||||
@ -400,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)
|
||||
@ -624,29 +632,52 @@ 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
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user