Only read storage.conf once
Currently running a simple container runs and stats configuration storage.conf files multiple times on a simple container run. This PR cuts the opens and stats in half by caching the first read. This speeds up start by about 10-20 microseconds. If container engines want to react to storage files changing, added a new function UpdateStoreOptions to allow engines to reload options. Fixes: https://github.com/containers/storage/issues/1403 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
db44035e3c
commit
9e06c38dfe
|
|
@ -35,6 +35,9 @@ const (
|
|||
var (
|
||||
defaultStoreOptionsOnce sync.Once
|
||||
loadDefaultStoreOptionsErr error
|
||||
once sync.Once
|
||||
storeOptions StoreOptions
|
||||
storeError error
|
||||
)
|
||||
|
||||
func loadDefaultStoreOptions() {
|
||||
|
|
@ -167,8 +170,8 @@ 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
|
||||
|
|
@ -176,6 +179,21 @@ func DefaultStoreOptions(rootless bool, rootlessUID int) (StoreOptions, error) {
|
|||
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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue