Skip to content

Commit 6e7977b

Browse files
E4242E4242
E4242
authored and
E4242
committed
Debugging
1 parent c63fa7a commit 6e7977b

File tree

9 files changed

+73
-36
lines changed

9 files changed

+73
-36
lines changed

pkg/sentry/fs/dirent.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"gvisor.dev/gvisor/pkg/sentry/socket/unix/transport"
3030
"gvisor.dev/gvisor/pkg/sentry/uniqueid"
3131
"gvisor.dev/gvisor/pkg/syserror"
32+
"gvisor.dev/gvisor/pkg/log"
3233
)
3334

3435
type globalDirentMap struct {
@@ -461,6 +462,8 @@ func (d *Dirent) walk(ctx context.Context, root *Dirent, name string, walkMayUnl
461462
return nil, syscall.ENOTDIR
462463
}
463464

465+
log.Infof("TRACE-dirent_walk-(root=" + d.name + ", target=" + name + ")")
466+
464467
if name == "" || name == "." {
465468
d.IncRef()
466469
return d, nil
@@ -592,6 +595,7 @@ func (d *Dirent) walk(ctx context.Context, root *Dirent, name string, walkMayUnl
592595
// only reference we'll ever get. d owns the reference.
593596
return nil, syscall.ENOENT
594597
}
598+
log.Infof("Returning positive dirent")
595599

596600
// Return the positive Dirent.
597601
return c, nil

pkg/sentry/fs/imgfs/file.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"io"
1919
"gvisor.dev/gvisor/pkg/sentry/context"
2020
"gvisor.dev/gvisor/pkg/sentry/fs"
21+
"gvisor.dev/gvisor/pkg/log"
2122
"gvisor.dev/gvisor/pkg/sentry/fs/fsutil"
2223
"gvisor.dev/gvisor/pkg/sentry/memmap"
2324
"gvisor.dev/gvisor/pkg/sentry/usermem"
@@ -48,6 +49,8 @@ type regularFileOperations struct {
4849

4950
// Read implements fs.FileOperations.Read.
5051
func (r *regularFileOperations) Read(ctx context.Context, file *fs.File, dst usermem.IOSequence, offset int64) (int64, error) {
52+
name, _ := file.Dirent.FullName(nil)
53+
log.Infof("imgfs - Reading a file now %v", name)
5154
return r.iops.read(ctx, file, dst, offset)
5255
}
5356

@@ -63,5 +66,6 @@ func (r *regularFileOperations) ConfigureMMap(ctx context.Context, file *fs.File
6366

6467
// ReadFrom implements fs.FileOperations.ReadFrom.
6568
func (r *regularFileOperations) ReadFrom(context.Context, *fs.File, io.Reader, int64) (int64, error) {
69+
log.Infof("imgfs - ReadFrom not implemented")
6670
return 0, syserror.ENOSYS
6771
}

pkg/sentry/fs/inode_overlay.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ func overlayWriteOut(ctx context.Context, o *overlayEntry) error {
5050
// If name exists, it returns true if the Dirent is in the upper, false if the
5151
// Dirent is in the lower.
5252
func overlayLookup(ctx context.Context, parent *overlayEntry, inode *Inode, name string) (*Dirent, bool, error) {
53+
log.Infof("imgfs - looking up in overlay: %v", name)
54+
5355
// Hot path. Avoid defers.
5456
parent.copyMu.RLock()
5557

@@ -68,6 +70,7 @@ func overlayLookup(ctx context.Context, parent *overlayEntry, inode *Inode, name
6870

6971
// Does the parent directory exist in the upper file system?
7072
if parent.upper != nil {
73+
log.Infof("The upper fs is: %v", parent.upper.MountSource.FilesystemType)
7174
// First check if a file object exists in the upper file system.
7275
// A file could have been created over a whiteout, so we need to
7376
// check if something exists in the upper file system first.
@@ -123,6 +126,7 @@ func overlayLookup(ctx context.Context, parent *overlayEntry, inode *Inode, name
123126
// the lower filesystem (e.g. device number, inode number) that were
124127
// visible before a copy up.
125128
if parent.lower != nil {
129+
log.Infof("The lower fs is: %v", parent.lower.MountSource.FilesystemType)
126130
// Check the lower file system.
127131
child, err := parent.lower.Lookup(ctx, name)
128132
// Same song and dance as above.

pkg/sentry/fs/mounts.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ func (mns *MountNamespace) FindLink(ctx context.Context, root, wd *Dirent, path
474474
if len(path) == 0 {
475475
panic("MountNamespace.FindLink: path is empty")
476476
}
477+
478+
log.Infof("Finding link in mountspace for path: %v", path)
477479

478480
// Split the path.
479481
first, remainder := SplitFirst(path)
@@ -532,6 +534,7 @@ func (mns *MountNamespace) FindLink(ctx context.Context, root, wd *Dirent, path
532534
current.DecRef()
533535

534536
if remainder != "" {
537+
log.Infof("About to resolve last stage")
535538
// Ensure it's resolved, unless it's the last level.
536539
//
537540
// See resolve for reference semantics; on err next
@@ -591,6 +594,7 @@ func (mns *MountNamespace) resolve(ctx context.Context, root, node *Dirent, rema
591594
return target, nil
592595

593596
case syscall.ENOLINK:
597+
log.Infof("Not sym")
594598
// Not a symlink.
595599
return node, nil
596600

@@ -608,6 +612,8 @@ func (mns *MountNamespace) resolve(ctx context.Context, root, node *Dirent, rema
608612
return nil, err
609613
}
610614

615+
log.Infof("targetPath: " + targetPath)
616+
611617
// Find the node; we resolve relative to the current symlink's parent.
612618
*remainingTraversals--
613619
d, err := mns.FindInode(ctx, root, node.parent, targetPath, remainingTraversals)

pkg/sentry/fs/ramfs/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ go_library(
2323
"//pkg/sentry/usermem",
2424
"//pkg/syserror",
2525
"//pkg/waiter",
26+
"//pkg/log",
2627
],
2728
)
2829

pkg/sentry/fs/ramfs/symlink.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"gvisor.dev/gvisor/pkg/sentry/fs"
2121
"gvisor.dev/gvisor/pkg/sentry/fs/fsutil"
2222
"gvisor.dev/gvisor/pkg/waiter"
23+
"gvisor.dev/gvisor/pkg/log"
2324
)
2425

2526
// Symlink represents a symlink.
@@ -79,6 +80,7 @@ func (s *Symlink) Readlink(ctx context.Context, _ *fs.Inode) (string, error) {
7980
// Getlink returns ErrResolveViaReadlink, falling back to walking to the result
8081
// of Readlink().
8182
func (*Symlink) Getlink(context.Context, *fs.Inode) (*fs.Dirent, error) {
83+
log.Infof("Getting link in ramfs")
8284
return nil, fs.ErrResolveViaReadlink
8385
}
8486

pkg/sentry/syscalls/linux/sys_file.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"gvisor.dev/gvisor/pkg/sentry/limits"
3131
"gvisor.dev/gvisor/pkg/sentry/usermem"
3232
"gvisor.dev/gvisor/pkg/syserror"
33+
"gvisor.dev/gvisor/pkg/log"
3334
)
3435

3536
// fileOpAt performs an operation on the second last component in the path.
@@ -67,6 +68,7 @@ func fileOpOn(t *kernel.Task, dirFD int32, path string, resolve bool, fn func(ro
6768
f *fs.File // The file corresponding to dirFD (if required.)
6869
err error
6970
)
71+
log.Infof("imgfs - fileOpOn %v", path)
7072

7173
// Extract the working directory (maybe).
7274
if len(path) > 0 && path[0] == '/' {

runsc/boot/fs.go

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func compileMounts(spec *specs.Spec) []specs.Mount {
160160

161161
// p9MountOptions creates a slice of options for a p9 mount.
162162
func p9MountOptions(fd int, fa FileAccessType) []string {
163+
log.Infof("Creating 9p mount options")
163164
opts := []string{
164165
"trans=fd",
165166
"rfdno=" + strconv.Itoa(fd),
@@ -270,37 +271,39 @@ func addSubmountOverlay(ctx context.Context, inode *fs.Inode, submounts []string
270271

271272
// mountExpFS should be executed after root create ramfs stub
272273
func mountExpFS(ctx context.Context, layerFDs []int, submounts []string) (*fs.Inode, error) {
273-
var currentNode *fs.Inode
274-
275-
if submounts != nil {
276-
msrc := fs.NewPseudoMountSource(ctx)
277-
mountTree, err := ramfs.MakeDirectoryTree(ctx, msrc, submounts)
278-
if err != nil {
279-
return nil, fmt.Errorf("creating mount tree: %v", err)
280-
}
281-
currentNode = mountTree
282-
}
283-
284-
flags := fs.MountSourceFlags{ReadOnly: true}
285-
imgFS := mustFindFilesystem("imgfs")
286-
287-
for index, lfd := range layerFDs {
288-
imgfsNode, err := imgFS.Mount(ctx, "imgfs-layer-" + strconv.Itoa(index), flags, "packageFD=" + strconv.Itoa(lfd), nil)
289-
if err != nil {
290-
return nil, fmt.Errorf("mounting imgfs layer %v, layerFD %v, err: %v", index, lfd, err)
291-
}
292-
if currentNode != nil {
293-
if currentNode, err = fs.NewOverlayRoot(ctx, imgfsNode, currentNode, flags); err != nil {
294-
return nil, fmt.Errorf("creating imgfs overlay: %v", err)
295-
}
296-
} else {
297-
currentNode = imgfsNode
298-
}
299-
}
300-
if currentNode == nil {
301-
return nil, fmt.Errorf("container fs: currentNode is nil")
302-
}
303-
return currentNode, nil
274+
var currentNode *fs.Inode
275+
log.Infof("imgfs - mounting imgfs in mountExpFS")
276+
277+
if submounts != nil {
278+
msrc := fs.NewPseudoMountSource(ctx)
279+
mountTree, err := ramfs.MakeDirectoryTree(ctx, msrc, submounts)
280+
if err != nil {
281+
return nil, fmt.Errorf("creating mount tree: %v", err)
282+
}
283+
currentNode = mountTree
284+
}
285+
286+
flags := fs.MountSourceFlags{ReadOnly: true}
287+
imgFS := mustFindFilesystem("imgfs")
288+
289+
for index, lfd := range layerFDs {
290+
imgfsNode, err := imgFS.Mount(ctx, "imgfs-layer-" + strconv.Itoa(index), flags, "packageFD=" + strconv.Itoa(lfd), nil)
291+
if err != nil {
292+
return nil, fmt.Errorf("mounting imgfs layer %v, layerFD %v, err: %v", index, lfd, err)
293+
}
294+
if currentNode != nil {
295+
if currentNode, err = fs.NewOverlayRoot(ctx, imgfsNode, currentNode, flags); err != nil {
296+
return nil, fmt.Errorf("creating imgfs overlay: %v", err)
297+
}
298+
} else {
299+
currentNode = imgfsNode
300+
}
301+
}
302+
303+
if currentNode == nil {
304+
return nil, fmt.Errorf("container fs: currentNode is nil")
305+
}
306+
return currentNode, nil
304307
}
305308

306309
// subtargets takes a set of Mounts and returns only the targets that are
@@ -637,7 +640,7 @@ func (c *containerMounter) setupFS(conf *Config, procArgs *kernel.CreateProcessA
637640

638641
// Set namespace here so that it can be found in rootCtx.
639642
rootProcArgs.MountNamespace = mns
640-
643+
log.Infof("imgfs - About to mount submounts in setupFS")
641644
if err := c.mountSubmounts(rootCtx, conf, mns); err != nil {
642645
return nil, err
643646
}
@@ -649,6 +652,7 @@ func (c *containerMounter) createMountNamespace(ctx context.Context, conf *Confi
649652
if err != nil {
650653
return nil, fmt.Errorf("creating filesystem for container: %v", err)
651654
}
655+
log.Infof("imgfs - About to create a new Mount namespace")
652656
mns, err := fs.NewMountNamespace(ctx, rootInode)
653657
if err != nil {
654658
return nil, fmt.Errorf("creating new mount namespace for container: %v", err)
@@ -663,6 +667,7 @@ func (c *containerMounter) mountSubmounts(ctx context.Context, conf *Config, mns
663667
for _, m := range c.mounts {
664668
log.Debugf("Mounting %q to %q, type: %s, options: %s", m.Source, m.Destination, m.Type, m.Options)
665669
if hint := c.hints.findMount(m); hint != nil && hint.isSupported() {
670+
log.Infof("imgfs - mounting with hint in mountSubmounts")
666671
if err := c.mountSharedSubmount(ctx, mns, root, m, hint); err != nil {
667672
return fmt.Errorf("mount shared mount %q to %q: %v", hint.name, m.Destination, err)
668673
}
@@ -697,6 +702,7 @@ func (c *containerMounter) checkDispenser() error {
697702
// mountSharedMaster mounts the master of a volume that is shared among
698703
// containers in a pod. It returns the root mount's inode.
699704
func (c *containerMounter) mountSharedMaster(ctx context.Context, conf *Config, hint *mountHint) (*fs.Inode, error) {
705+
log.Infof("Mounting shared master")
700706
// Map mount type to filesystem name, and parse out the options that we are
701707
// capable of dealing with.
702708
fsName, opts, useOverlay, err := c.getMountNameAndOptions(conf, hint.mount)
@@ -806,6 +812,7 @@ func (c *containerMounter) getMountNameAndOptions(conf *Config, m specs.Mount) (
806812
}
807813

808814
case bind:
815+
log.Infof("imgfs - about to create p9 options")
809816
fd := c.fds.remove()
810817
fsName = "9p"
811818
// Non-root bind mounts are always shared.
@@ -814,6 +821,7 @@ func (c *containerMounter) getMountNameAndOptions(conf *Config, m specs.Mount) (
814821
useOverlay = conf.Overlay && !mountFlags(m.Options).ReadOnly
815822

816823
case imgfs:
824+
log.Infof("imgfs - got here in switch")
817825
fsName = m.Type
818826
opts = []string{"packageFD=" + strconv.Itoa(conf.PackageFD)}
819827
useOverlay = true // ImgFS will always use overlay
@@ -833,6 +841,7 @@ func (c *containerMounter) getMountNameAndOptions(conf *Config, m specs.Mount) (
833841
func (c *containerMounter) mountSubmount(ctx context.Context, conf *Config, mns *fs.MountNamespace, root *fs.Dirent, m specs.Mount) (*fs.Inode, *fs.Dirent, error) {
834842
// Map mount type to filesystem name, and parse out the options that we are
835843
// capable of dealing with.
844+
log.Infof("mounting submount")
836845
fsName, opts, useOverlay, err := c.getMountNameAndOptions(conf, m)
837846
if err != nil {
838847
return nil, nil, err
@@ -917,6 +926,7 @@ func (c *containerMounter) mountSharedSubmount(ctx context.Context, mns *fs.Moun
917926
// addRestoreMount adds a mount to the MountSources map used for restoring a
918927
// checkpointed container.
919928
func (c *containerMounter) addRestoreMount(conf *Config, renv *fs.RestoreEnvironment, m specs.Mount) error {
929+
log.Infof("Adding restore mount")
920930
fsName, opts, useOverlay, err := c.getMountNameAndOptions(conf, m)
921931
if err != nil {
922932
return err
@@ -946,6 +956,7 @@ func (c *containerMounter) createRestoreEnvironment(conf *Config) (*fs.RestoreEn
946956
MountSources: make(map[string][]fs.MountArgs),
947957
}
948958

959+
log.Infof("imgfs - Creating/restoring enviornement")
949960
// Add root mount.
950961
fd := c.fds.remove()
951962
opts := p9MountOptions(fd, conf.FileAccess)

runsc/sandbox/sandbox.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ func (s *Sandbox) connError(err error) error {
333333
// createSandboxProcess starts the sandbox as a subprocess by running the "boot"
334334
// command, passing in the bundle dir.
335335
func (s *Sandbox) createSandboxProcess(conf *boot.Config, args *Args, startSyncFile *os.File) error {
336+
log.Infof("imgfs - createSandboxProcess")
336337
// nextFD is used to get unused FDs that we can pass to the sandbox. It
337338
// starts at 3 because 0, 1, and 2 are taken by stdin/out/err.
338339
nextFD := 3
@@ -443,6 +444,7 @@ func (s *Sandbox) createSandboxProcess(conf *boot.Config, args *Args, startSyncF
443444
}
444445

445446
//Experiemntal Feature: use multiple layers of imgfs to replace gofer.
447+
log.Infof("imgfs - reading dir to get img files")
446448
files, err := ioutil.ReadDir(args.Spec.Root.Path)
447449
var layers []string
448450
for _, file := range files {
@@ -455,11 +457,12 @@ func (s *Sandbox) createSandboxProcess(conf *boot.Config, args *Args, startSyncF
455457
for _, layer := range layers {
456458
layerFile, err := os.OpenFile(path.Join(args.Spec.Root.Path, layer), os.O_RDONLY, 0644)
457459
if err != nil {
458-
return fmt.Errorf("opening layer file: %v", err)
459-
}
460+
return fmt.Errorf("opening layer file: %v", err)
461+
}
460462
defer layerFile.Close()
461-
cmd.ExtraFiles = append(cmd.ExtraFiles, layerFile)
462-
cmd.Args = append(cmd.Args, "--layer-fds="+strconv.Itoa(nextFD))
463+
cmd.ExtraFiles = append(cmd.ExtraFiles, layerFile)
464+
cmd.Args = append(cmd.Args, "--layer-fds="+strconv.Itoa(nextFD))
465+
log.Infof("imgfs - added FD to --layer-fds: %v", nextFD)
463466
nextFD++
464467
}
465468

0 commit comments

Comments
 (0)