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 }