diff options
author | Fabricio Voznika <fvoznika@google.com> | 2020-06-17 21:21:08 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-06-17 21:22:16 -0700 |
commit | 6e0c170522279ca72119b17c41e2e1dc93c49d6a (patch) | |
tree | af360a26f141e33228f125352f641c0ed3f45cff /pkg/sentry/fsimpl/overlay | |
parent | 22b0bb21383614f6258dee27f4a254d2da97b586 (diff) |
Implement Sync() to directories
Updates #1035, #1199
PiperOrigin-RevId: 317028108
Diffstat (limited to 'pkg/sentry/fsimpl/overlay')
-rw-r--r-- | pkg/sentry/fsimpl/overlay/directory.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/pkg/sentry/fsimpl/overlay/directory.go b/pkg/sentry/fsimpl/overlay/directory.go index 6f47167d3..f5c2462a5 100644 --- a/pkg/sentry/fsimpl/overlay/directory.go +++ b/pkg/sentry/fsimpl/overlay/directory.go @@ -263,3 +263,25 @@ func (fd *directoryFD) Seek(ctx context.Context, offset int64, whence int32) (in return 0, syserror.EINVAL } } + +// Sync implements vfs.FileDescriptionImpl.Sync. Forwards sync to the upper +// layer, if there is one. The lower layer doesn't need to sync because it +// never changes. +func (fd *directoryFD) Sync(ctx context.Context) error { + d := fd.dentry() + if !d.isCopiedUp() { + return nil + } + vfsObj := d.fs.vfsfs.VirtualFilesystem() + pop := vfs.PathOperation{ + Root: d.upperVD, + Start: d.upperVD, + } + upperFD, err := vfsObj.OpenAt(ctx, d.fs.creds, &pop, &vfs.OpenOptions{Flags: linux.O_RDONLY | linux.O_DIRECTORY}) + if err != nil { + return err + } + err = upperFD.Sync(ctx) + upperFD.DecRef() + return err +} |