summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry/fs')
-rw-r--r--pkg/sentry/fs/file.go10
-rw-r--r--pkg/sentry/fs/file_state.go11
2 files changed, 20 insertions, 1 deletions
diff --git a/pkg/sentry/fs/file.go b/pkg/sentry/fs/file.go
index 904827a3e..36794d378 100644
--- a/pkg/sentry/fs/file.go
+++ b/pkg/sentry/fs/file.go
@@ -85,6 +85,9 @@ type File struct {
// async handles O_ASYNC notifications.
async FileAsync
+ // saving indicates that this file is in the process of being saved.
+ saving bool `state:"nosave"`
+
// mu is dual-purpose: first, to make read(2) and write(2) thread-safe
// in conformity with POSIX, and second, to cancel operations before they
// begin in response to interruptions (i.e. signals).
@@ -127,10 +130,15 @@ func (f *File) DecRef() {
// Release a reference on the Dirent.
f.Dirent.DecRef()
+ // Only unregister if we are currently registered. There is nothing
+ // to register if f.async is nil (this happens when async mode is
+ // enabled without setting an owner). Also, we unregister during
+ // save.
f.flagsMu.Lock()
- if f.flags.Async && f.async != nil {
+ if !f.saving && f.flags.Async && f.async != nil {
f.async.Unregister(f)
}
+ f.async = nil
f.flagsMu.Unlock()
})
}
diff --git a/pkg/sentry/fs/file_state.go b/pkg/sentry/fs/file_state.go
index 3384737ab..f848d1b79 100644
--- a/pkg/sentry/fs/file_state.go
+++ b/pkg/sentry/fs/file_state.go
@@ -14,7 +14,18 @@
package fs
+// beforeSave is invoked by stateify.
+func (f *File) beforeSave() {
+ f.saving = true
+ if f.flags.Async && f.async != nil {
+ f.async.Unregister(f)
+ }
+}
+
// afterLoad is invoked by stateify.
func (f *File) afterLoad() {
f.mu.Init()
+ if f.flags.Async && f.async != nil {
+ f.async.Register(f)
+ }
}