From 25d9af8f42a4cf0e6f3bf22f4119ef4f726b59e1 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 9 Nov 2022 11:34:18 +0100 Subject: [PATCH] runtime: Handle the transient store options This handles the transient store options from the container/storage configuration in the runtime/engine. Changes are: * Print transient store status in `podman info` * Print transient store status in runtime debug output * Add --transient-store argument to override config option * Propagate config state to conmon cleanup args so the callback podman gets the same config. Note: This doesn't really change any behaviour yet (other than the changes in containers/storage). Signed-off-by: Alexander Larsson --- cmd/podman/root.go | 2 ++ docs/source/markdown/podman-info.1.md | 4 +++- docs/source/markdown/podman.1.md | 8 ++++++++ libpod/define/info.go | 1 + libpod/info.go | 1 + libpod/options.go | 12 ++++++++++++ libpod/runtime.go | 1 + pkg/domain/entities/engine.go | 11 ++++++----- pkg/domain/infra/runtime_libpod.go | 3 +++ pkg/specgenutil/util.go | 1 + 10 files changed, 38 insertions(+), 6 deletions(-) diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 7d03b0d70e..010fb90967 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -464,6 +464,8 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { pFlags.StringVar(&podmanConfig.Runroot, runrootFlagName, "", "Path to the 'run directory' where all state information is stored") _ = cmd.RegisterFlagCompletionFunc(runrootFlagName, completion.AutocompleteDefault) + pFlags.BoolVar(&podmanConfig.TransientStore, "transient-store", false, "Enable transient container storage") + runtimeFlagName := "runtime" pFlags.StringVar(&podmanConfig.RuntimePath, runtimeFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.OCIRuntime, "Path to the OCI-compatible binary used to run containers.") _ = cmd.RegisterFlagCompletionFunc(runtimeFlagName, completion.AutocompleteDefault) diff --git a/docs/source/markdown/podman-info.1.md b/docs/source/markdown/podman-info.1.md index f892c2d7de..bb6084479c 100644 --- a/docs/source/markdown/podman-info.1.md +++ b/docs/source/markdown/podman-info.1.md @@ -146,6 +146,7 @@ store: imageStore: number: 5 runRoot: /run/user/3267/containers + transientStore: false volumePath: /home/dwalsh/.local/share/containers/storage/volumes version: APIVersion: 4.0.0 @@ -263,7 +264,8 @@ $ podman info --format json "number": 5 }, "runRoot": "/run/user/3267/containers", - "volumePath": "/home/dwalsh/.local/share/containers/storage/volumes" + "volumePath": "/home/dwalsh/.local/share/containers/storage/volumes", + "transientStore": false }, "registries": { "search": [ diff --git a/docs/source/markdown/podman.1.md b/docs/source/markdown/podman.1.md index 905d4fbdf3..8e8b4f6b3e 100644 --- a/docs/source/markdown/podman.1.md +++ b/docs/source/markdown/podman.1.md @@ -162,6 +162,14 @@ Path to the tmp directory, for libpod runtime content. Defaults to `$XDG_RUNTIME NOTE --tmpdir is not used for the temporary storage of downloaded images. Use the environment variable `TMPDIR` to change the temporary storage location of downloaded container images. Podman defaults to use `/var/tmp`. +#### **--transient-store** + +Enables a global transient storaga mode where all container metadata is stored on non-persistant media (i.e. in the location specified by `--runroot`). +This mode allows starting containers faster, as well as guaranteeing a fresh state on boot in case of unclean shutdowns or other problems. However +it is not compabible with a traditional model where containers persist across reboots. + +Default value for this is configured in `/etc/containers/storage.conf`. + #### **--url**=*value* URL to access Podman service (default from `containers.conf`, rootless `unix://run/user/$UID/podman/podman.sock` or as root `unix://run/podman/podman.sock`). Setting this option will switch the **--remote** option to true. diff --git a/libpod/define/info.go b/libpod/define/info.go index c716bec7b0..28260918b5 100644 --- a/libpod/define/info.go +++ b/libpod/define/info.go @@ -118,6 +118,7 @@ type StoreInfo struct { ImageStore ImageStore `json:"imageStore"` RunRoot string `json:"runRoot"` VolumePath string `json:"volumePath"` + TransientStore bool `json:"transientStore"` } // ImageStore describes the image store. Right now only the number diff --git a/libpod/info.go b/libpod/info.go index ad8f654326..953ca0539e 100644 --- a/libpod/info.go +++ b/libpod/info.go @@ -226,6 +226,7 @@ func (r *Runtime) storeInfo() (*define.StoreInfo, error) { GraphOptions: nil, VolumePath: r.config.Engine.VolumePath, ConfigFile: configFile, + TransientStore: r.store.TransientStore(), } graphOptions := map[string]interface{}{} diff --git a/libpod/options.go b/libpod/options.go index 94da2158d6..05bd6d7d1f 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -109,6 +109,18 @@ func WithStorageConfig(config storage.StoreOptions) RuntimeOption { } } +func WithTransientStore(transientStore bool) RuntimeOption { + return func(rt *Runtime) error { + if rt.valid { + return define.ErrRuntimeFinalized + } + + rt.storageConfig.TransientStore = transientStore + + return nil + } +} + // WithSignaturePolicy specifies the path of a file which decides how trust is // managed for images we've pulled. // If this is not specified, the system default configuration will be used diff --git a/libpod/runtime.go b/libpod/runtime.go index 5534e6ab5f..f1b3a29878 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -396,6 +396,7 @@ func makeRuntime(runtime *Runtime) (retErr error) { logrus.Debugf("Using static dir %s", runtime.config.Engine.StaticDir) logrus.Debugf("Using tmp dir %s", runtime.config.Engine.TmpDir) logrus.Debugf("Using volume path %s", runtime.config.Engine.VolumePath) + logrus.Debugf("Using transient store: %v", runtime.storageConfig.TransientStore) // Validate our config against the database, now that we've set our // final storage configuration diff --git a/pkg/domain/entities/engine.go b/pkg/domain/entities/engine.go index 47330da841..aa5ad69260 100644 --- a/pkg/domain/entities/engine.go +++ b/pkg/domain/entities/engine.go @@ -50,9 +50,10 @@ type PodmanConfig struct { Trace bool // Hidden: Trace execution URI string // URI to RESTful API Service - Runroot string - StorageDriver string - StorageOpts []string - SSHMode string - MachineMode bool + Runroot string + StorageDriver string + StorageOpts []string + SSHMode string + MachineMode bool + TransientStore bool } diff --git a/pkg/domain/infra/runtime_libpod.go b/pkg/domain/infra/runtime_libpod.go index 931f4c7851..c9aabc9bd7 100644 --- a/pkg/domain/infra/runtime_libpod.go +++ b/pkg/domain/infra/runtime_libpod.go @@ -171,6 +171,9 @@ func getRuntime(ctx context.Context, fs *flag.FlagSet, opts *engineOpts) (*libpo storageOpts.GraphDriverOptions = cfg.StorageOpts } } + if fs.Changed("transient-store") { + options = append(options, libpod.WithTransientStore(cfg.TransientStore)) + } if opts.migrate { options = append(options, libpod.WithMigrate()) if opts.name != "" { diff --git a/pkg/specgenutil/util.go b/pkg/specgenutil/util.go index d61e57ce2a..4e065347f5 100644 --- a/pkg/specgenutil/util.go +++ b/pkg/specgenutil/util.go @@ -282,6 +282,7 @@ func CreateExitCommandArgs(storageConfig storageTypes.StoreOptions, config *conf "--network-config-dir", config.Network.NetworkConfigDir, "--network-backend", config.Network.NetworkBackend, "--volumepath", config.Engine.VolumePath, + fmt.Sprintf("--transient-store=%t", storageConfig.TransientStore), } if config.Engine.OCIRuntime != "" { command = append(command, []string{"--runtime", config.Engine.OCIRuntime}...)