Skip to content

Commit

Permalink
Merge pull request #1404 from rhatdan/storage
Browse files Browse the repository at this point in the history
Only read storage.conf once
  • Loading branch information
rhatdan authored Oct 24, 2022
2 parents db44035 + 9e06c38 commit fae5bbf
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const (
var (
defaultStoreOptionsOnce sync.Once
loadDefaultStoreOptionsErr error
once sync.Once
storeOptions StoreOptions
storeError error
)

func loadDefaultStoreOptions() {
Expand Down Expand Up @@ -167,15 +170,30 @@ func defaultStoreOptionsIsolated(rootless bool, rootlessUID int, storageConf str
return storageOpts, nil
}

// DefaultStoreOptions returns the default storage ops for containers
func DefaultStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
// loadStoreOptions returns the default storage ops for containers
func loadStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
storageConf, err := DefaultConfigFile(rootless && rootlessUID != 0)
if err != nil {
return defaultStoreOptions, err
}
return defaultStoreOptionsIsolated(rootless, rootlessUID, storageConf)
}

// UpdateOptions should be called iff container engine recieved a SIGHUP,
// otherwise use DefaultStoreOptions
func UpdateStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
storeOptions, storeError = loadStoreOptions(rootless, rootlessUID)
return storeOptions, storeError
}

// DefaultStoreOptions returns the default storage ops for containers
func DefaultStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
once.Do(func() {
storeOptions, storeError = loadStoreOptions(rootless, rootlessUID)
})
return storeOptions, storeError
}

// StoreOptions is used for passing initialization options to GetStore(), for
// initializing a Store object and the underlying storage that it controls.
type StoreOptions struct {
Expand Down

0 comments on commit fae5bbf

Please sign in to comment.