podman: set volatile storage flag for --rm containers

volatile containers are a storage optimization that disables *sync()
syscalls for the container rootfs.

If a container is created with --rm, then automatically set the
volatile storage flag as anyway the container won't persist after a
reboot or machine crash.

[NO TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2021-05-05 15:44:29 +02:00
parent 4d2ba323f2
commit 68fe1950fe
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED
6 changed files with 25 additions and 0 deletions

View File

@ -646,6 +646,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
s.Umask = c.Umask
s.Secrets = c.Secrets
s.PidFile = c.PidFile
s.Volatile = c.Rm
return nil
}

View File

@ -151,6 +151,9 @@ type ContainerRootFSConfig struct {
Secrets []*secrets.Secret `json:"secrets,omitempty"`
// SecretPath is the secrets location in storage
SecretsPath string `json:"secretsPath"`
// Volatile specifies whether the container storage can be optimized
// at the cost of not syncing all the dirty files in memory.
Volatile bool `json:"volatile,omitempty"`
}
// ContainerSecurityConfig is an embedded sub-config providing security configuration

View File

@ -451,6 +451,8 @@ func (c *Container) setupStorage(ctx context.Context) error {
options.MountOpts = newOptions
}
options.Volatile = c.config.Volatile
c.setupStorageMapping(&options.IDMappingOptions, &c.config.IDMappings)
containerInfo, err := c.runtime.storageService.CreateContainerStorage(ctx, c.runtime.imageContext, c.config.RootfsImageName, c.config.RootfsImageID, c.config.Name, c.config.ID, options)

View File

@ -2318,3 +2318,16 @@ func WithPodSlirp4netns(networkOptions map[string][]string) PodCreateOption {
return nil
}
}
// WithVolatile sets the volatile flag for the container storage.
// The option can potentially cause data loss when used on a container that must survive a machine reboot.
func WithVolatile() CtrCreateOption {
return func(ctr *Container) error {
if ctr.valid {
return define.ErrCtrFinalized
}
ctr.config.Volatile = true
return nil
}
}

View File

@ -194,6 +194,9 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.
if s.Umask != "" {
options = append(options, libpod.WithUmask(s.Umask))
}
if s.Volatile {
options = append(options, libpod.WithVolatile())
}
useSystemd := false
switch s.Systemd {

View File

@ -256,6 +256,9 @@ type ContainerStorageConfig struct {
// Secrets are the secrets that will be added to the container
// Optional.
Secrets []string `json:"secrets,omitempty"`
// Volatile specifies whether the container storage can be optimized
// at the cost of not syncing all the dirty files in memory.
Volatile bool `json:"volatile,omitempty"`
}
// ContainerSecurityConfig is a container's security features, including