summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/vfs/filesystem_impl_util.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2019-12-11 22:29:46 +0000
committergVisor bot <gvisor-bot@google.com>2019-12-11 22:29:46 +0000
commit0c5b3fd72793ffdeaa043c17e5b2a95d8b290626 (patch)
tree881c37f3ae3610350b0ec3a57e07044c25c2b893 /pkg/sentry/vfs/filesystem_impl_util.go
parent97aa9227305245fb9908e51e8b29cc677dafebd6 (diff)
parent481dbfa5ab24ec2c0752b9e748d3617285603c4e (diff)
Merge release-20191129.0-49-g481dbfa (automated)
Diffstat (limited to 'pkg/sentry/vfs/filesystem_impl_util.go')
-rwxr-xr-xpkg/sentry/vfs/filesystem_impl_util.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/sentry/vfs/filesystem_impl_util.go b/pkg/sentry/vfs/filesystem_impl_util.go
index 465e610e0..7315a588e 100755
--- a/pkg/sentry/vfs/filesystem_impl_util.go
+++ b/pkg/sentry/vfs/filesystem_impl_util.go
@@ -16,6 +16,8 @@ package vfs
import (
"strings"
+
+ "gvisor.dev/gvisor/pkg/fspath"
)
// GenericParseMountOptions parses a comma-separated list of options of the
@@ -41,3 +43,27 @@ func GenericParseMountOptions(str string) map[string]string {
}
return m
}
+
+// GenericPrependPath may be used by implementations of
+// FilesystemImpl.PrependPath() for which a single statically-determined lock
+// or set of locks is sufficient to ensure its preconditions (as opposed to
+// e.g. per-Dentry locks).
+//
+// Preconditions: Dentry.Name() and Dentry.Parent() must be held constant for
+// vd.Dentry() and all of its ancestors.
+func GenericPrependPath(vfsroot, vd VirtualDentry, b *fspath.Builder) error {
+ mnt, d := vd.mount, vd.dentry
+ for {
+ if mnt == vfsroot.mount && d == vfsroot.dentry {
+ return PrependPathAtVFSRootError{}
+ }
+ if d == mnt.root {
+ return nil
+ }
+ if d.parent == nil {
+ return PrependPathAtNonMountRootError{}
+ }
+ b.PrependComponent(d.name)
+ d = d.parent
+ }
+}