summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2019-10-23 21:41:43 +0000
committergVisor bot <gvisor-bot@google.com>2019-10-23 21:41:43 +0000
commitbdf5354e934d5b6fa3211d18731f7255c8bd56f4 (patch)
treef913c47d17bb7a0993f24302ac8614eef011f13e /pkg/sentry
parentf2b5f59b124b5571bd2f97322f4c034014ab4289 (diff)
parentfbe6b50d5628bc3d522f87eee2abcc5a923df420 (diff)
Merge release-20190806.1-309-gfbe6b50 (automated)
Diffstat (limited to 'pkg/sentry')
-rw-r--r--pkg/sentry/kernel/fd_table.go22
-rwxr-xr-xpkg/sentry/kernel/kernel_state_autogen.go2
2 files changed, 24 insertions, 0 deletions
diff --git a/pkg/sentry/kernel/fd_table.go b/pkg/sentry/kernel/fd_table.go
index cc3f43a45..11f613a11 100644
--- a/pkg/sentry/kernel/fd_table.go
+++ b/pkg/sentry/kernel/fd_table.go
@@ -81,6 +81,9 @@ type FDTable struct {
// mu protects below.
mu sync.Mutex `state:"nosave"`
+ // next is start position to find fd.
+ next int32
+
// used contains the number of non-nil entries. It must be accessed
// atomically. It may be read atomically without holding mu (but not
// written).
@@ -226,6 +229,11 @@ func (f *FDTable) NewFDs(ctx context.Context, fd int32, files []*fs.File, flags
f.mu.Lock()
defer f.mu.Unlock()
+ // From f.next to find available fd.
+ if fd < f.next {
+ fd = f.next
+ }
+
// Install all entries.
for i := fd; i < end && len(fds) < len(files); i++ {
if d, _, _ := f.get(i); d == nil {
@@ -242,6 +250,11 @@ func (f *FDTable) NewFDs(ctx context.Context, fd int32, files []*fs.File, flags
return nil, syscall.EMFILE
}
+ if fd == f.next {
+ // Update next search start position.
+ f.next = fds[len(fds)-1] + 1
+ }
+
return fds, nil
}
@@ -361,6 +374,11 @@ func (f *FDTable) Remove(fd int32) *fs.File {
f.mu.Lock()
defer f.mu.Unlock()
+ // Update current available position.
+ if fd < f.next {
+ f.next = fd
+ }
+
orig, _, _ := f.get(fd)
if orig != nil {
orig.IncRef() // Reference for caller.
@@ -377,6 +395,10 @@ func (f *FDTable) RemoveIf(cond func(*fs.File, FDFlags) bool) {
f.forEach(func(fd int32, file *fs.File, flags FDFlags) {
if cond(file, flags) {
f.set(fd, nil, FDFlags{}) // Clear from table.
+ // Update current available position.
+ if fd < f.next {
+ f.next = fd
+ }
}
})
}
diff --git a/pkg/sentry/kernel/kernel_state_autogen.go b/pkg/sentry/kernel/kernel_state_autogen.go
index 0dccdb4f0..cd470686a 100755
--- a/pkg/sentry/kernel/kernel_state_autogen.go
+++ b/pkg/sentry/kernel/kernel_state_autogen.go
@@ -69,6 +69,7 @@ func (x *FDTable) save(m state.Map) {
m.Save("AtomicRefCount", &x.AtomicRefCount)
m.Save("k", &x.k)
m.Save("uid", &x.uid)
+ m.Save("next", &x.next)
m.Save("used", &x.used)
}
@@ -77,6 +78,7 @@ func (x *FDTable) load(m state.Map) {
m.Load("AtomicRefCount", &x.AtomicRefCount)
m.Load("k", &x.k)
m.Load("uid", &x.uid)
+ m.Load("next", &x.next)
m.Load("used", &x.used)
m.LoadValue("descriptorTable", new(map[int32]descriptor), func(y interface{}) { x.loadDescriptorTable(y.(map[int32]descriptor)) })
}