diff options
author | Vikas Goel <vikas.goel@veritas.com> | 2021-07-16 17:32:41 -0700 |
---|---|---|
committer | Vikas Goel <vikas.goel@gmail.com> | 2021-07-20 11:39:32 -0400 |
commit | 064bd9d19f30467ffb8f626b6eb13101a12c0ed6 (patch) | |
tree | 002ce7f2c1db415e9d5d67438ed11b033e7a45ec /libpod/runtime_ctr.go | |
parent | 20c9f74c77683730455df4fb5e7722a192b78a92 (diff) | |
download | podman-064bd9d19f30467ffb8f626b6eb13101a12c0ed6.tar.gz podman-064bd9d19f30467ffb8f626b6eb13101a12c0ed6.tar.bz2 podman-064bd9d19f30467ffb8f626b6eb13101a12c0ed6.zip |
Copy the content from the underlying image into the newly created volume.
Fixes: #10262
Signed-off-by: Vikas Goel <vikas.goel@gmail.com>
Diffstat (limited to 'libpod/runtime_ctr.go')
-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() |