From 3fe5e18ad248dd055aa01f92bdf3a01fadf9bfb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= Date: Wed, 25 Mar 2015 18:43:46 +0100 Subject: [PATCH] rkt: fix status with overlay When using overlay fs rkt status stopped working because it searched for the status file in the stage1 rootfs, which is either in a different mount namespace or unmounted. If the container uses overlay fs, we now search in its upper layer, which is accessible outside the mount namespace or when the filesystem is not mounted. --- common/common.go | 5 +++-- rkt/containers.go | 23 +++++++++++++++++++++++ rkt/status.go | 5 +++-- stage0/run.go | 8 ++------ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/common/common.go b/common/common.go index d84951d..1cacf89 100644 --- a/common/common.go +++ b/common/common.go @@ -30,8 +30,9 @@ const ( stage1Dir = "/stage1" stage2Dir = "/opt/stage2" - EnvLockFd = "RKT_LOCK_FD" - Stage1IDFilename = "stage1ID" + EnvLockFd = "RKT_LOCK_FD" + Stage1IDFilename = "stage1ID" + OverlayPreparedFilename = "overlay-prepared" MetadataServiceIP = "169.254.169.255" MetadataServicePubPort = 80 diff --git a/rkt/containers.go b/rkt/containers.go index 5ebff7c..d5381ce 100644 --- a/rkt/containers.go +++ b/rkt/containers.go @@ -747,8 +747,31 @@ func (c *container) getAppCount() (int, error) { return len(m.Apps), nil } +func (c *container) getStatusDir() (string, error) { + _, err := c.openFile(common.OverlayPreparedFilename, syscall.O_RDONLY) + if err == nil { + // the container uses overlay. Since the mount is in another mount + // namespace (or gone), return the status directory from the overlay + // upper layer + stage1Hash, err := c.getStage1Hash() + if err != nil { + return "", err + } + overlayStatusDir := fmt.Sprintf(overlayStatusDirTemplate, stage1Hash.String()) + + return overlayStatusDir, nil + } + + // not using overlay, return the regular status directory + return regularStatusDir, nil +} + // getExitStatuses returns a map of the statuses of the container. func (c *container) getExitStatuses() (map[string]int, error) { + statusDir, err := c.getStatusDir() + if err != nil { + return nil, fmt.Errorf("unable to get status directory: %v", err) + } ls, err := c.getDirNames(statusDir) if err != nil { return nil, fmt.Errorf("unable to read status directory: %v", err) diff --git a/rkt/status.go b/rkt/status.go index 147cd2b..5d45608 100644 --- a/rkt/status.go +++ b/rkt/status.go @@ -27,8 +27,9 @@ var ( ) const ( - statusDir = "stage1/rootfs/rkt/status" - cmdStatusName = "status" + overlayStatusDirTemplate = "overlay/%s/upper/rkt/status" + regularStatusDir = "stage1/rootfs/rkt/status" + cmdStatusName = "status" ) func init() { diff --git a/stage0/run.go b/stage0/run.go index 3d59819..64633be 100644 --- a/stage0/run.go +++ b/stage0/run.go @@ -47,10 +47,6 @@ import ( "github.com/coreos/rocket/version" ) -const ( - overlayFilename = "overlay-prepared" -) - // configuration parameters required by Prepare type PrepareConfig struct { CommonConfig @@ -187,7 +183,7 @@ func Prepare(cfg PrepareConfig, dir string, uuid *types.UUID) error { if useOverlay { // mark the pod as prepared with overlay - f, err := os.Create(filepath.Join(dir, overlayFilename)) + f, err := os.Create(filepath.Join(dir, common.OverlayPreparedFilename)) if err != nil { return fmt.Errorf("error writing overlay marker file: %v", err) } @@ -217,7 +213,7 @@ func supportsOverlay() bool { } func preparedWithOverlay(dir string) (bool, error) { - _, err := os.Stat(filepath.Join(dir, overlayFilename)) + _, err := os.Stat(filepath.Join(dir, common.OverlayPreparedFilename)) if os.IsNotExist(err) { return false, nil }