diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2018-06-25 16:16:23 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-06-25 16:17:12 -0700 |
commit | 1a9917d14d66250fdc9a3781ef65df4413340a2f (patch) | |
tree | 6b732372d89723f27b4fbe547f6eddc8b5680e57 | |
parent | 478f0ac0038afda267814fa154bcd32feb07c3b3 (diff) |
MountSource.Root() should return a refernce on the dirent.
PiperOrigin-RevId: 202038397
Change-Id: I074d525f2e2d9bcd43b247b62f86f9129c101b78
-rw-r--r-- | pkg/sentry/fs/mount.go | 4 | ||||
-rw-r--r-- | pkg/sentry/fs/mount_test.go | 4 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/mounts.go | 8 |
3 files changed, 12 insertions, 4 deletions
diff --git a/pkg/sentry/fs/mount.go b/pkg/sentry/fs/mount.go index a2943b097..1d05a36a7 100644 --- a/pkg/sentry/fs/mount.go +++ b/pkg/sentry/fs/mount.go @@ -198,10 +198,12 @@ func (msrc *MountSource) Submounts() []*MountSource { return ms } -// Root returns the root dirent of this mount. +// Root returns the root dirent of this mount. Callers must call DecRef on the +// returned dirent. func (msrc *MountSource) Root() *Dirent { msrc.mu.Lock() defer msrc.mu.Unlock() + msrc.root.IncRef() return msrc.root } diff --git a/pkg/sentry/fs/mount_test.go b/pkg/sentry/fs/mount_test.go index 3a053c154..968b435ab 100644 --- a/pkg/sentry/fs/mount_test.go +++ b/pkg/sentry/fs/mount_test.go @@ -204,7 +204,9 @@ func mountPathsAre(root *Dirent, got []*MountSource, want ...string) error { } gotPaths := make(map[string]struct{}, len(got)) for _, g := range got { - n, _ := g.Root().FullName(root) + groot := g.Root() + n, _ := groot.FullName(root) + groot.DecRef() gotPaths[n] = struct{}{} } for _, w := range want { diff --git a/pkg/sentry/fs/proc/mounts.go b/pkg/sentry/fs/proc/mounts.go index 76092567d..3d276dfa5 100644 --- a/pkg/sentry/fs/proc/mounts.go +++ b/pkg/sentry/fs/proc/mounts.go @@ -44,7 +44,9 @@ func forEachMountSource(t *kernel.Task, fn func(string, *fs.MountSource)) { return ms[i].ID() < ms[j].ID() }) for _, m := range ms { - mountPath, desc := m.Root().FullName(rootDir) + mroot := m.Root() + mountPath, desc := mroot.FullName(rootDir) + mroot.DecRef() if !desc { // MountSources that are not descendants of the chroot jail are ignored. continue @@ -88,7 +90,9 @@ func (mif *mountInfoFile) ReadSeqFileData(handle seqfile.SeqHandle) ([]seqfile.S // (3) Major:Minor device ID. We don't have a superblock, so we // just use the root inode device number. - sa := m.Root().Inode.StableAttr + mroot := m.Root() + sa := mroot.Inode.StableAttr + mroot.DecRef() fmt.Fprintf(&buf, "%d:%d ", sa.DeviceFileMajor, sa.DeviceFileMinor) // (4) Root: the pathname of the directory in the filesystem |