configure runtime without store

some podman commands do not require the use of a container/image store.
in those cases, it is more effecient to not open the store, because that
results in having to also close the store which can be costly when the
system is under heavy write I/O loads.

Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
baude 2019-07-01 13:35:16 -05:00
parent 150778820f
commit d0a0a3fbd9
7 changed files with 52 additions and 7 deletions

View file

@ -60,7 +60,7 @@ func execCmd(c *cliconfig.ExecValues) error {
argStart = 0
}
cmd := args[argStart:]
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
runtime, err := adapter.GetRuntimeNoStore(getContext(), &c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}

View file

@ -107,7 +107,7 @@ func containerExistsCmd(c *cliconfig.ContainerExistsValues) error {
if len(args) > 1 || len(args) < 1 {
return errors.New("you may only check for the existence of one container at a time")
}
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
runtime, err := adapter.GetRuntimeNoStore(getContext(), &c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
@ -126,7 +126,7 @@ func podExistsCmd(c *cliconfig.PodExistsValues) error {
if len(args) > 1 || len(args) < 1 {
return errors.New("you may only check for the existence of one pod at a time")
}
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
runtime, err := adapter.GetRuntimeNoStore(getContext(), &c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}

View file

@ -15,20 +15,25 @@ import (
// GetRuntimeMigrate gets a libpod runtime that will perform a migration of existing containers
func GetRuntimeMigrate(ctx context.Context, c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
return getRuntime(ctx, c, false, true)
return getRuntime(ctx, c, false, true, false)
}
// GetRuntimeRenumber gets a libpod runtime that will perform a lock renumber
func GetRuntimeRenumber(ctx context.Context, c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
return getRuntime(ctx, c, true, false)
return getRuntime(ctx, c, true, false, false)
}
// GetRuntime generates a new libpod runtime configured by command line options
func GetRuntime(ctx context.Context, c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
return getRuntime(ctx, c, false, false)
return getRuntime(ctx, c, false, false, false)
}
func getRuntime(ctx context.Context, c *cliconfig.PodmanCommand, renumber bool, migrate bool) (*libpod.Runtime, error) {
// GetRuntimeNoStore generates a new libpod runtime configured by command line options
func GetRuntimeNoStore(ctx context.Context, c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
return getRuntime(ctx, c, false, false, true)
}
func getRuntime(ctx context.Context, c *cliconfig.PodmanCommand, renumber, migrate, noStore bool) (*libpod.Runtime, error) {
options := []libpod.RuntimeOption{}
storageOpts := storage.StoreOptions{}
storageSet := false
@ -89,6 +94,9 @@ func getRuntime(ctx context.Context, c *cliconfig.PodmanCommand, renumber bool,
options = append(options, libpod.WithStorageConfig(storageOpts))
}
if !storageSet && noStore {
options = append(options, libpod.WithNoStore())
}
// TODO CLI flags for image config?
// TODO CLI flag for signature policy?

View file

@ -300,6 +300,15 @@ func WithTmpDir(dir string) RuntimeOption {
}
}
// WithNoStore sets a bool on the runtime that we do not need
// any containers storage.
func WithNoStore() RuntimeOption {
return func(rt *Runtime) error {
rt.noStore = true
return nil
}
}
// WithMaxLogSize sets the maximum size of container logs.
// Positive sizes are limits in bytes, -1 is unlimited.
func WithMaxLogSize(limit int64) RuntimeOption {

View file

@ -125,6 +125,9 @@ type Runtime struct {
// mechanism to read and write even logs
eventer events.Eventer
// noStore indicates whether we need to interact with a store or not
noStore bool
}
// RuntimeConfig contains configuration options used to set up the runtime
@ -784,11 +787,14 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (err error) {
var store storage.Store
if os.Geteuid() != 0 {
logrus.Debug("Not configuring container store")
} else if runtime.noStore {
logrus.Debug("No store required. Not opening container store.")
} else {
store, err = storage.GetStore(runtime.config.StorageConfig)
if err != nil {
return err
}
err = nil
defer func() {
if err != nil && store != nil {
@ -1148,6 +1154,8 @@ func (r *Runtime) Shutdown(force bool) error {
}
var lastError error
// If no store was requested, it can bew nil and there is no need to
// attempt to shut it down
if r.store != nil {
if _, err := r.store.Shutdown(force); err != nil {
lastError = errors.Wrapf(err, "Error shutting down container storage")

View file

@ -58,12 +58,26 @@ type Volume struct {
// VolumeFilter is for filtering volumes on the client
type VolumeFilter func(*Volume) bool
// GetRuntimeNoStore returns a localruntime struct wit an embedded runtime but
// without a configured storage.
func GetRuntimeNoStore(ctx context.Context, c *cliconfig.PodmanCommand) (*LocalRuntime, error) {
runtime, err := libpodruntime.GetRuntimeNoStore(ctx, c)
if err != nil {
return nil, err
}
return getRuntime(runtime)
}
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
func GetRuntime(ctx context.Context, c *cliconfig.PodmanCommand) (*LocalRuntime, error) {
runtime, err := libpodruntime.GetRuntime(ctx, c)
if err != nil {
return nil, err
}
return getRuntime(runtime)
}
func getRuntime(runtime *libpod.Runtime) (*LocalRuntime, error) {
return &LocalRuntime{
Runtime: runtime,
}, nil

View file

@ -50,6 +50,12 @@ type LocalRuntime struct {
*RemoteRuntime
}
// GetRuntimeNoStore returns a LocalRuntime struct with the actual runtime embedded in it
// The nostore is ignored
func GetRuntimeNoStore(ctx context.Context, c *cliconfig.PodmanCommand) (*LocalRuntime, error) {
return GetRuntime(ctx, c)
}
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
func GetRuntime(ctx context.Context, c *cliconfig.PodmanCommand) (*LocalRuntime, error) {
var (