summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-09-14 13:14:11 -0400
committerGitHub <noreply@github.com>2021-09-14 13:14:11 -0400
commit6a34045c670b3f0184b4ba88faeb11bb4a58c747 (patch)
tree856e9ffd0eba7b03c7ee02987f7f61b966eb8ca1 /libpod
parent65b1ff25a3444f16c9b0524f8a02cd6e56976e2b (diff)
parenta55e2a00fcb82485333eeec55aa2eaee338782d7 (diff)
downloadpodman-6a34045c670b3f0184b4ba88faeb11bb4a58c747.tar.gz
podman-6a34045c670b3f0184b4ba88faeb11bb4a58c747.tar.bz2
podman-6a34045c670b3f0184b4ba88faeb11bb4a58c747.zip
Merge pull request #11170 from flouthoc/support-rootfs-overlay
rootfs: Add support for rootfs-overlay.
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_config.go2
-rw-r--r--libpod/container_internal.go38
-rw-r--r--libpod/options.go3
3 files changed, 42 insertions, 1 deletions
diff --git a/libpod/container_config.go b/libpod/container_config.go
index b80b23c25..a2c989a1a 100644
--- a/libpod/container_config.go
+++ b/libpod/container_config.go
@@ -107,6 +107,8 @@ type ContainerRootFSConfig struct {
// as the container's root.
// Conflicts with RootfsImageID.
Rootfs string `json:"rootfs,omitempty"`
+ // RootfsOverlay tells if rootfs has to be mounted as an overlay
+ RootfsOverlay bool `json:"rootfs_overlay,omitempty"`
// ShmDir is the path to be mounted on /dev/shm in container.
// If not set manually at creation time, Libpod will create a tmpfs
// with the size specified in ShmSize and populate this with the path of
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 18b80475b..1033729ae 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"
@@ -1550,6 +1551,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 {
@@ -1723,6 +1750,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 {
diff --git a/libpod/options.go b/libpod/options.go
index 4cbd2b5e2..7b0c6641a 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -1337,7 +1337,7 @@ func WithCommand(command []string) CtrCreateOption {
// WithRootFS sets the rootfs for the container.
// This creates a container from a directory on disk and not an image.
-func WithRootFS(rootfs string) CtrCreateOption {
+func WithRootFS(rootfs string, overlay bool) CtrCreateOption {
return func(ctr *Container) error {
if ctr.valid {
return define.ErrCtrFinalized
@@ -1346,6 +1346,7 @@ func WithRootFS(rootfs string) CtrCreateOption {
return err
}
ctr.config.Rootfs = rootfs
+ ctr.config.RootfsOverlay = overlay
return nil
}
}