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.
This commit is contained in:
Iago López Galeiras
2015-03-25 18:57:55 +01:00
parent 05b512cb67
commit 3fe5e18ad2
4 changed files with 31 additions and 10 deletions
+3 -2
View File
@@ -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
+23
View File
@@ -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)
+3 -2
View File
@@ -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() {
+2 -6
View File
@@ -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
}