Skip to content

Commit

Permalink
Make the priority for picking the storage driver configurable
Browse files Browse the repository at this point in the history
This fixes #1457

Signed-off-by: Dan Čermák <dcermak@suse.com>
  • Loading branch information
dcermak committed Jan 3, 2023
1 parent 46e9455 commit b67adf5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
13 changes: 10 additions & 3 deletions drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,22 @@ type Options struct {
}

// New creates the driver and initializes it at the specified root.
func New(name string, config Options) (Driver, error) {
func New(name string, driver_priority []string, config Options) (Driver, error) {
if name != "" {
logrus.Debugf("[graphdriver] trying provided driver %q", name) // so the logs show specified driver
return GetDriver(name, config)
}

// Guess for prior driver
driversMap := scanPriorDrivers(config.Root)
for _, name := range priority {

// use the supplied priority list unless it is empty
prio_list := driver_priority
if len(prio_list) == 0 {
prio_list = priority
}

for _, name := range prio_list {
if name == "vfs" {
// don't use vfs even if there is state present.
continue
Expand Down Expand Up @@ -372,7 +379,7 @@ func New(name string, config Options) (Driver, error) {
}

// Check for priority drivers first
for _, name := range priority {
for _, name := range prio_list {
driver, err := getBuiltinDriver(name, config.Root, config)
if err != nil {
if isDriverNotSupported(err) {
Expand Down
36 changes: 19 additions & 17 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,9 @@ type store struct {

// The following fields are only set when constructing store, and must never be modified afterwards.
// They are safe to access without any other locking.
runRoot string
graphDriverName string // Initially set to the user-requested value, possibly ""; updated during store construction, and does not change afterwards.
runRoot string
graphDriverName string // Initially set to the user-requested value, possibly ""; updated during store construction, and does not change afterwards.
graphDriverPriority []string
// graphLock:
// - Ensures that we always reload graphDriver, and the primary layer store, after any process does store.Shutdown. This is necessary
// because (??) the Shutdown may forcibly unmount and clean up, affecting graph driver state in a way only a graph driver
Expand Down Expand Up @@ -723,20 +724,21 @@ func GetStore(options types.StoreOptions) (Store, error) {
autoNsMaxSize = AutoUserNsMaxSize
}
s := &store{
runRoot: options.RunRoot,
graphDriverName: options.GraphDriverName,
graphLock: graphLock,
usernsLock: usernsLock,
graphRoot: options.GraphRoot,
graphOptions: options.GraphDriverOptions,
pullOptions: options.PullOptions,
uidMap: copyIDMap(options.UIDMap),
gidMap: copyIDMap(options.GIDMap),
autoUsernsUser: options.RootAutoNsUser,
autoNsMinSize: autoNsMinSize,
autoNsMaxSize: autoNsMaxSize,
disableVolatile: options.DisableVolatile,
transientStore: options.TransientStore,
runRoot: options.RunRoot,
graphDriverName: options.GraphDriverName,
graphDriverPriority: options.GraphDriverPriority,
graphLock: graphLock,
usernsLock: usernsLock,
graphRoot: options.GraphRoot,
graphOptions: options.GraphDriverOptions,
pullOptions: options.PullOptions,
uidMap: copyIDMap(options.UIDMap),
gidMap: copyIDMap(options.GIDMap),
autoUsernsUser: options.RootAutoNsUser,
autoNsMinSize: autoNsMinSize,
autoNsMaxSize: autoNsMaxSize,
disableVolatile: options.DisableVolatile,
transientStore: options.TransientStore,

additionalUIDs: nil,
additionalGIDs: nil,
Expand Down Expand Up @@ -940,7 +942,7 @@ func (s *store) createGraphDriverLocked() (drivers.Driver, error) {
UIDMaps: s.uidMap,
GIDMaps: s.gidMap,
}
return drivers.New(s.graphDriverName, config)
return drivers.New(s.graphDriverName, s.graphDriverPriority, config)
}

func (s *store) GraphDriver() (drivers.Driver, error) {
Expand Down
14 changes: 11 additions & 3 deletions types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
type TomlConfig struct {
Storage struct {
Driver string `toml:"driver,omitempty"`
DriverPriority []string `toml:"driver_priority,omitempty"`
RunRoot string `toml:"runroot,omitempty"`
GraphRoot string `toml:"graphroot,omitempty"`
RootlessStoragePath string `toml:"rootless_storage_path,omitempty"`
Expand Down Expand Up @@ -213,10 +214,16 @@ type StoreOptions struct {
// RootlessStoragePath is the storage path for rootless users
// default $HOME/.local/share/containers/storage
RootlessStoragePath string `toml:"rootless_storage_path"`
// GraphDriverName is the underlying storage driver that we'll be
// using. It only needs to be specified the first time a Store is
// initialized for a given RunRoot and GraphRoot.
// If the driver is not specified, the best suited driver will be picked
// either from GraphDriverPriority or from the platform dependent
// priority list (in that order).
GraphDriverName string `json:"driver,omitempty"`
// GraphDriverPriority is a list of storage drivers that will be tried
// to initialize the Store for a given RunRoot and GraphRoot unless a
// GraphDriverName is set.
// This list can be used to define a custom order in which the drivers
// will be tried.
GraphDriverPriority []string `json:"driver-priority,omitempty"`
// GraphDriverOptions are driver-specific options.
GraphDriverOptions []string `json:"driver-options,omitempty"`
// UIDMap and GIDMap are used for setting up a container's root filesystem
Expand Down Expand Up @@ -383,6 +390,7 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) erro
if storeOptions.GraphDriverName == "" {
logrus.Errorf("The storage 'driver' option must be set in %s to guarantee proper operation", configFile)
}
storeOptions.GraphDriverPriority = config.Storage.DriverPriority
if config.Storage.RunRoot != "" {
storeOptions.RunRoot = config.Storage.RunRoot
}
Expand Down

0 comments on commit b67adf5

Please sign in to comment.