8000 stage1/fly: evaluate symlinks in mount targets by lucab · Pull Request #3570 · rkt/rkt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

stage1/fly: evaluate symlinks in mount targets #3570

Merged
merged 3 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions stage1_fly/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ import (
"github.com/coreos/rkt/common"
"github.com/coreos/rkt/pkg/fileutil"
pkgflag "github.com/coreos/rkt/pkg/flag"
"github.com/coreos/rkt/pkg/fs"
rktlog "github.com/coreos/rkt/pkg/log"
"github.com/coreos/rkt/pkg/mountinfo"
"github.com/coreos/rkt/pkg/sys"
"github.com/coreos/rkt/pkg/user"
stage1common "github.com/coreos/rkt/stage1/common"
stage1commontypes "github.com/coreos/rkt/stage1/common/types"
stage1initcommon "github.com/coreos/rkt/stage1/init/common"
)

const (
Expand Down Expand Up @@ -358,9 +360,12 @@ func stage1(rp *stage1commontypes.RuntimePod) int {
}
}

mounter := fs.NewLoggingMounter(
fs.MounterFunc(syscall.Mount),
fs.UnmounterFunc(syscall.Unmount),
diag.Printf,
)
for _, mount := range effectiveMounts {
diag.Printf("Processing %+v", mount)

var (
err error
hostPathInfo os.FileInfo
Expand All @@ -376,7 +381,16 @@ func stage1(rp *stage1commontypes.RuntimePod) int {
hostPathInfo = nil
}

absTargetPath := filepath.Join(mount.TargetPrefixPath, mount.RelTargetPath)
absTargetPath := mount.RelTargetPath
if mount.TargetPrefixPath != "" {
absStage2RootFS := common.AppRootfsPath(p.Root, ra.Name)
targetPath, err := stage1initcommon.EvaluateSymlinksInsideApp(absStage2RootFS, mount.RelTargetPath)
if err != nil {
log.PrintE(fmt.Sprintf("evaluate target path %q in %q", mount.RelTargetPath, absStage2RootFS), err)
return 254
}
absTargetPath = filepath.Join(absStage2RootFS, targetPath)
}
if targetPathInfo, err = os.Stat(absTargetPath); err != nil && !os.IsNotExist(err) {
log.PrintE(fmt.Sprintf("stat of target path %s", absTargetPath), err)
return 254
Expand Down Expand Up @@ -418,7 +432,7 @@ func stage1(rp *stage1commontypes.RuntimePod) int {
}
}

if err := syscall.Mount(mount.HostPath, absTargetPath, mount.Fs, mount.Flags, ""); err != nil {
if err := mounter.Mount(mount.HostPath, absTargetPath, mount.Fs, mount.Flags, ""); err != nil {
log.PrintE(fmt.Sprintf("can't mount %q on %q with flags %v", mount.HostPath, absTargetPath, mount.Flags), err)
return 254
}
Expand Down
4 changes: 1 addition & 3 deletions tests/rkt_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build host coreos src

package main

import (
Expand Down Expand Up @@ -125,7 +123,7 @@ func TestMountSymlink(t *testing.T) {

// Read the actual file.
rktCmd := fmt.Sprintf(
"%s --insecure-options=image run %s --set-env=FILE=%s %s",
"%s --insecure-options=image --debug run %s --set-env=FILE=%s %s",
ctx.Cmd(), paramMount, tt.actualFile, image,
)
t.Logf("%s\n", rktCmd)
Expand Down
0