diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2019-11-20 14:54:03 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-11-20 15:07:16 -0800 |
commit | 012102eefd2b145ddee774cba28e4fa889fadd49 (patch) | |
tree | 8150e163ee3ba161370194d2bdd00642faa820c1 /pkg/sentry/fs/gofer/handles.go | |
parent | ef6f93625457c166628fc9de57c15d986ae83159 (diff) |
Pass OpenTruncate to gofer in Open call when opening file with O_TRUNC.
Note that the Sentry still calls Truncate() on the file before calling Open.
A new p9 version check was added to ensure that the p9 server can handle the
the OpenTruncate flag. If not, then the flag is stripped before sending.
PiperOrigin-RevId: 281609112
Diffstat (limited to 'pkg/sentry/fs/gofer/handles.go')
-rw-r--r-- | pkg/sentry/fs/gofer/handles.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/pkg/sentry/fs/gofer/handles.go b/pkg/sentry/fs/gofer/handles.go index 39c8ec33d..b86c49b39 100644 --- a/pkg/sentry/fs/gofer/handles.go +++ b/pkg/sentry/fs/gofer/handles.go @@ -64,7 +64,7 @@ func (h *handles) DecRef() { }) } -func newHandles(ctx context.Context, file contextFile, flags fs.FileFlags) (*handles, error) { +func newHandles(ctx context.Context, client *p9.Client, file contextFile, flags fs.FileFlags) (*handles, error) { _, newFile, err := file.walk(ctx, nil) if err != nil { return nil, err @@ -81,6 +81,9 @@ func newHandles(ctx context.Context, file contextFile, flags fs.FileFlags) (*han default: panic("impossible fs.FileFlags") } + if flags.Truncate && p9.VersionSupportsOpenTruncateFlag(client.Version()) { + p9flags |= p9.OpenTruncate + } hostFile, _, _, err := newFile.open(ctx, p9flags) if err != nil { |