summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/gofer
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-03-22 18:50:51 +0000
committergVisor bot <gvisor-bot@google.com>2021-03-22 18:50:51 +0000
commiteb11764fbf2f8db7a8ac6b8bf1beaf6b3ea276c4 (patch)
tree1ebd967c4fce187109370f1f17391bcdc404d435 /pkg/sentry/fs/gofer
parent8418ed1b4099d346859d17f44ed868803340eaf1 (diff)
parentb428fd02e627fc151527f0f26cbff9b05f6240e0 (diff)
Merge release-20210315.0-5-gb428fd02e (automated)
Diffstat (limited to 'pkg/sentry/fs/gofer')
-rw-r--r--pkg/sentry/fs/gofer/file.go27
1 files changed, 14 insertions, 13 deletions
diff --git a/pkg/sentry/fs/gofer/file.go b/pkg/sentry/fs/gofer/file.go
index 06d450ba6..8f5a87120 100644
--- a/pkg/sentry/fs/gofer/file.go
+++ b/pkg/sentry/fs/gofer/file.go
@@ -204,20 +204,8 @@ func (f *fileOperations) readdirAll(ctx context.Context) (map[string]fs.DentAttr
return entries, nil
}
-// maybeSync will call FSync on the file if either the cache policy or file
-// flags require it.
+// maybeSync will call FSync on the file if the file flags require it.
func (f *fileOperations) maybeSync(ctx context.Context, file *fs.File, offset, n int64) error {
- if n == 0 {
- // Nothing to sync.
- return nil
- }
-
- if f.inodeOperations.session().cachePolicy.writeThrough(file.Dirent.Inode) {
- // Call WriteOut directly, as some "writethrough" filesystems
- // do not support sync.
- return f.inodeOperations.cachingInodeOps.WriteOut(ctx, file.Dirent.Inode)
- }
-
flags := file.Flags()
var syncType fs.SyncType
switch {
@@ -254,6 +242,19 @@ func (f *fileOperations) Write(ctx context.Context, file *fs.File, src usermem.I
n, err = src.CopyInTo(ctx, f.handles.readWriterAt(ctx, offset))
}
+ if n == 0 {
+ // Nothing written. We are done.
+ return 0, err
+ }
+
+ // Write the dirty pages and attributes if cache policy tells us to.
+ if f.inodeOperations.session().cachePolicy.writeThrough(file.Dirent.Inode) {
+ if werr := f.inodeOperations.cachingInodeOps.WriteDirtyPagesAndAttrs(ctx, file.Dirent.Inode); werr != nil {
+ // Report no bytes written since the write faild.
+ return 0, werr
+ }
+ }
+
// We may need to sync the written bytes.
if syncErr := f.maybeSync(ctx, file, offset, n); syncErr != nil {
// Sync failed. Report 0 bytes written, since none of them are