diff options
author | flouthoc <flouthoc.git@gmail.com> | 2021-08-25 16:13:17 +0530 |
---|---|---|
committer | Aditya Rajan <arajan@redhat.com> | 2021-09-14 13:31:39 +0530 |
commit | a55e2a00fcb82485333eeec55aa2eaee338782d7 (patch) | |
tree | d465835a368c7f78239d7abd1c2912347bf23d4c /libpod/container_internal.go | |
parent | b603c7a4b91d30b33ce987740156f46804f24074 (diff) | |
download | podman-a55e2a00fcb82485333eeec55aa2eaee338782d7.tar.gz podman-a55e2a00fcb82485333eeec55aa2eaee338782d7.tar.bz2 podman-a55e2a00fcb82485333eeec55aa2eaee338782d7.zip |
rootfs: Add support for rootfs-overlay and bump to buildah v1.22.1-0.202108
Allows users to specify a readonly rootfs with :O, in exchange podman will create a writable overlay.
bump builah to v1.22.1-0.20210823173221-da2b428c56ce
[NO TESTS NEEDED]
Signed-off-by: flouthoc <flouthoc.git@gmail.com>
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 4d1a25541..63683a8b8 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -15,6 +15,7 @@ import ( metadata "github.com/checkpoint-restore/checkpointctl/lib" "github.com/containers/buildah/copier" + "github.com/containers/buildah/pkg/overlay" butil "github.com/containers/buildah/util" "github.com/containers/podman/v3/libpod/define" "github.com/containers/podman/v3/libpod/events" @@ -1541,6 +1542,32 @@ func (c *Container) mountStorage() (_ string, deferredErr error) { // We need to mount the container before volumes - to ensure the copyup // works properly. mountPoint := c.config.Rootfs + // Check if overlay has to be created on top of Rootfs + if c.config.RootfsOverlay { + overlayDest := c.runtime.store.GraphRoot() + contentDir, err := overlay.GenerateStructure(c.runtime.store.GraphRoot(), c.ID(), "rootfs", c.RootUID(), c.RootGID()) + if err != nil { + return "", errors.Wrapf(err, "rootfs-overlay: failed to create TempDir in the %s directory", overlayDest) + } + overlayMount, err := overlay.Mount(contentDir, c.config.Rootfs, overlayDest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions()) + if err != nil { + return "", errors.Wrapf(err, "rootfs-overlay: creating overlay failed %q", c.config.Rootfs) + } + + // Seems fuse-overlayfs is not present + // fallback to native overlay + if overlayMount.Type == "overlay" { + overlayMount.Options = append(overlayMount.Options, "nodev") + mountOpts := label.FormatMountLabel(strings.Join(overlayMount.Options, ","), c.MountLabel()) + err = mount.Mount("overlay", overlayMount.Source, overlayMount.Type, mountOpts) + if err != nil { + return "", errors.Wrapf(err, "rootfs-overlay: creating overlay failed %q from native overlay", c.config.Rootfs) + } + } + + mountPoint = overlayMount.Source + } + if mountPoint == "" { mountPoint, err = c.mount() if err != nil { @@ -1714,6 +1741,17 @@ func (c *Container) cleanupStorage() error { var cleanupErr error + // umount rootfs overlay if it was created + if c.config.RootfsOverlay { + overlayBasePath := c.runtime.store.GraphRoot() + overlayBasePath = filepath.Join(overlayBasePath, "rootfs") + if err := overlay.Unmount(overlayBasePath); err != nil { + // If the container can't remove content report the error + logrus.Errorf("Failed to cleanup overlay mounts for %s: %v", c.ID(), err) + cleanupErr = err + } + } + for _, containerMount := range c.config.Mounts { if err := c.unmountSHM(containerMount); err != nil { if cleanupErr != nil { |