diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-07-21 05:52:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-21 05:52:09 -0400 |
commit | a7dcae5abc81d4c4809aebca39b2ac9db1bca3d7 (patch) | |
tree | 96d14b43495b50429bca453d0788b4f942343703 /libpod | |
parent | 389c9b8dca942fb4977823dd504d3d351cb92acd (diff) | |
parent | 064bd9d19f30467ffb8f626b6eb13101a12c0ed6 (diff) | |
download | podman-a7dcae5abc81d4c4809aebca39b2ac9db1bca3d7.tar.gz podman-a7dcae5abc81d4c4809aebca39b2ac9db1bca3d7.tar.bz2 podman-a7dcae5abc81d4c4809aebca39b2ac9db1bca3d7.zip |
Merge pull request #10970 from vikas-goel/prepare-volume
Copy the content from the underlying image into the newly created volume
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/runtime_ctr.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 6c69d1b72..ce4c5d758 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -47,6 +47,32 @@ func (r *Runtime) NewContainer(ctx context.Context, rSpec *spec.Spec, options .. return r.newContainer(ctx, rSpec, options...) } +func (r *Runtime) PrepareVolumeOnCreateContainer(ctx context.Context, ctr *Container) error { + // Copy the content from the underlying image into the newly created + // volume if configured to do so. + if !r.config.Containers.PrepareVolumeOnCreate { + return nil + } + + defer func() { + if err := ctr.cleanupStorage(); err != nil { + logrus.Errorf("error cleaning up container storage %s: %v", ctr.ID(), err) + } + }() + + mountPoint, err := ctr.mountStorage() + if err == nil { + // Finish up mountStorage + ctr.state.Mounted = true + ctr.state.Mountpoint = mountPoint + if err = ctr.save(); err != nil { + logrus.Errorf("Error saving container %s state: %v", ctr.ID(), err) + } + } + + return err +} + // RestoreContainer re-creates a container from an imported checkpoint func (r *Runtime) RestoreContainer(ctx context.Context, rSpec *spec.Spec, config *ContainerConfig) (*Container, error) { r.lock.Lock() |