diff options
author | Jamie Liu <jamieliu@google.com> | 2018-06-26 11:34:16 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-06-26 11:35:20 -0700 |
commit | 33041b36cb7e8e9795545837355e4576ff2be4da (patch) | |
tree | 96d60c5252f659dc3b511d04a66f9b4f0f2f05d7 /pkg/sentry/fs | |
parent | 51c1e510ab79607d80d6b81c2ae8ab308c323a58 (diff) |
Add Context to seqfile.SeqSource.ReadSeqFileData.
PiperOrigin-RevId: 202163895
Change-Id: Ib9942fcff80c0834216f4f10780662bef5b52270
Diffstat (limited to 'pkg/sentry/fs')
-rw-r--r-- | pkg/sentry/fs/proc/filesystems.go | 3 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/loadavg.go | 4 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/meminfo.go | 3 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/mounts.go | 5 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/net.go | 4 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/seqfile/seqfile.go | 10 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/seqfile/seqfile_test.go | 2 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/stat.go | 3 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/sys.go | 4 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/task.go | 10 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/uid_gid_map.go | 2 | ||||
-rw-r--r-- | pkg/sentry/fs/proc/version.go | 3 |
12 files changed, 30 insertions, 23 deletions
diff --git a/pkg/sentry/fs/proc/filesystems.go b/pkg/sentry/fs/proc/filesystems.go index fe4de18ba..aa2c4db10 100644 --- a/pkg/sentry/fs/proc/filesystems.go +++ b/pkg/sentry/fs/proc/filesystems.go @@ -18,6 +18,7 @@ import ( "bytes" "fmt" + "gvisor.googlesource.com/gvisor/pkg/sentry/context" "gvisor.googlesource.com/gvisor/pkg/sentry/fs" "gvisor.googlesource.com/gvisor/pkg/sentry/fs/proc/seqfile" ) @@ -33,7 +34,7 @@ func (*filesystemsData) NeedsUpdate(generation int64) bool { // ReadSeqFileData returns data for the SeqFile reader. // SeqData, the current generation and where in the file the handle corresponds to. -func (*filesystemsData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (*filesystemsData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { // We don't ever expect to see a non-nil SeqHandle. if h != nil { return nil, 0 diff --git a/pkg/sentry/fs/proc/loadavg.go b/pkg/sentry/fs/proc/loadavg.go index 694cde656..7583b6ccd 100644 --- a/pkg/sentry/fs/proc/loadavg.go +++ b/pkg/sentry/fs/proc/loadavg.go @@ -18,6 +18,7 @@ import ( "bytes" "fmt" + "gvisor.googlesource.com/gvisor/pkg/sentry/context" "gvisor.googlesource.com/gvisor/pkg/sentry/fs/proc/seqfile" ) @@ -29,7 +30,8 @@ func (*loadavgData) NeedsUpdate(generation int64) bool { return true } -func (d *loadavgData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +// ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. +func (d *loadavgData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } diff --git a/pkg/sentry/fs/proc/meminfo.go b/pkg/sentry/fs/proc/meminfo.go index 489f796e5..49cb0faed 100644 --- a/pkg/sentry/fs/proc/meminfo.go +++ b/pkg/sentry/fs/proc/meminfo.go @@ -18,6 +18,7 @@ import ( "bytes" "fmt" + "gvisor.googlesource.com/gvisor/pkg/sentry/context" "gvisor.googlesource.com/gvisor/pkg/sentry/fs/proc/seqfile" "gvisor.googlesource.com/gvisor/pkg/sentry/kernel" "gvisor.googlesource.com/gvisor/pkg/sentry/usage" @@ -36,7 +37,7 @@ func (*meminfoData) NeedsUpdate(generation int64) bool { } // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. -func (d *meminfoData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (d *meminfoData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } diff --git a/pkg/sentry/fs/proc/mounts.go b/pkg/sentry/fs/proc/mounts.go index 3d276dfa5..b9988625e 100644 --- a/pkg/sentry/fs/proc/mounts.go +++ b/pkg/sentry/fs/proc/mounts.go @@ -19,6 +19,7 @@ import ( "fmt" "sort" + "gvisor.googlesource.com/gvisor/pkg/sentry/context" "gvisor.googlesource.com/gvisor/pkg/sentry/fs" "gvisor.googlesource.com/gvisor/pkg/sentry/fs/proc/seqfile" "gvisor.googlesource.com/gvisor/pkg/sentry/kernel" @@ -67,7 +68,7 @@ func (mif *mountInfoFile) NeedsUpdate(_ int64) bool { } // ReadSeqFileData implements SeqSource.ReadSeqFileData. -func (mif *mountInfoFile) ReadSeqFileData(handle seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (mif *mountInfoFile) ReadSeqFileData(ctx context.Context, handle seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if handle != nil { return nil, 0 } @@ -148,7 +149,7 @@ func (mf *mountsFile) NeedsUpdate(_ int64) bool { } // ReadSeqFileData implements SeqSource.ReadSeqFileData. -func (mf *mountsFile) ReadSeqFileData(handle seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (mf *mountsFile) ReadSeqFileData(ctx context.Context, handle seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if handle != nil { return nil, 0 } diff --git a/pkg/sentry/fs/proc/net.go b/pkg/sentry/fs/proc/net.go index e6bd35f27..ad94c475a 100644 --- a/pkg/sentry/fs/proc/net.go +++ b/pkg/sentry/fs/proc/net.go @@ -94,7 +94,7 @@ func (*ifinet6) NeedsUpdate(generation int64) bool { } // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. -func (n *ifinet6) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (n *ifinet6) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } @@ -119,7 +119,7 @@ func (n *netDev) NeedsUpdate(generation int64) bool { // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. See Linux's // net/core/net-procfs.c:dev_seq_show. -func (n *netDev) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (n *netDev) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } diff --git a/pkg/sentry/fs/proc/seqfile/seqfile.go b/pkg/sentry/fs/proc/seqfile/seqfile.go index e37a85869..c08565f8a 100644 --- a/pkg/sentry/fs/proc/seqfile/seqfile.go +++ b/pkg/sentry/fs/proc/seqfile/seqfile.go @@ -49,7 +49,7 @@ type SeqSource interface { // generation. The first entry in the slice is greater than the handle. // If handle is nil then all known records are returned. Generation // must always be greater than 0. - ReadSeqFileData(handle SeqHandle) ([]SeqData, int64) + ReadSeqFileData(ctx context.Context, handle SeqHandle) ([]SeqData, int64) } // SeqGenerationCounter is a counter to keep track if the SeqSource should be @@ -155,7 +155,7 @@ func (s *SeqFile) DeprecatedPreadv(ctx context.Context, dst usermem.IOSequence, return 0, io.EOF } oldLen := len(s.source) - s.updateSourceLocked(len(s.source)) + s.updateSourceLocked(ctx, len(s.source)) updated = true // We know that we had consumed everything up until this point // so we search in the new slice instead of starting over. @@ -187,7 +187,7 @@ func (s *SeqFile) DeprecatedPreadv(ctx context.Context, dst usermem.IOSequence, // check to see if we've seeked backwards and if so always update our // data source. if !updated && (s.SeqSource.NeedsUpdate(s.generation) || s.lastRead > offset) { - s.updateSourceLocked(i) + s.updateSourceLocked(ctx, i) // recordOffset is 0 here and we won't update records behind the // current one so recordOffset is still 0 even though source // just got updated. Just read the next record. @@ -212,7 +212,7 @@ func (s *SeqFile) DeprecatedPreadv(ctx context.Context, dst usermem.IOSequence, } // updateSourceLocked requires that s.mu is held. -func (s *SeqFile) updateSourceLocked(record int) { +func (s *SeqFile) updateSourceLocked(ctx context.Context, record int) { var h SeqHandle if record == 0 { h = nil @@ -222,7 +222,7 @@ func (s *SeqFile) updateSourceLocked(record int) { // Save what we have previously read. s.source = s.source[:record] var newSource []SeqData - newSource, s.generation = s.SeqSource.ReadSeqFileData(h) + newSource, s.generation = s.SeqSource.ReadSeqFileData(ctx, h) s.source = append(s.source, newSource...) } diff --git a/pkg/sentry/fs/proc/seqfile/seqfile_test.go b/pkg/sentry/fs/proc/seqfile/seqfile_test.go index 0bf39ad82..d90e3e736 100644 --- a/pkg/sentry/fs/proc/seqfile/seqfile_test.go +++ b/pkg/sentry/fs/proc/seqfile/seqfile_test.go @@ -55,7 +55,7 @@ func (s *seqTest) NeedsUpdate(int64) bool { // ReadSeqFiledata returns a slice of SeqData which contains elements // greater than the handle. -func (s *seqTest) ReadSeqFileData(handle SeqHandle) ([]SeqData, int64) { +func (s *seqTest) ReadSeqFileData(ctx context.Context, handle SeqHandle) ([]SeqData, int64) { if handle == nil { return s.actual, 0 } diff --git a/pkg/sentry/fs/proc/stat.go b/pkg/sentry/fs/proc/stat.go index dee836a05..284f3e52b 100644 --- a/pkg/sentry/fs/proc/stat.go +++ b/pkg/sentry/fs/proc/stat.go @@ -19,6 +19,7 @@ import ( "fmt" "gvisor.googlesource.com/gvisor/pkg/abi/linux" + "gvisor.googlesource.com/gvisor/pkg/sentry/context" "gvisor.googlesource.com/gvisor/pkg/sentry/fs/proc/seqfile" "gvisor.googlesource.com/gvisor/pkg/sentry/kernel" ) @@ -73,7 +74,7 @@ func (c cpuStats) String() string { } // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. -func (s *statData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (s *statData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } diff --git a/pkg/sentry/fs/proc/sys.go b/pkg/sentry/fs/proc/sys.go index db9ec83b9..aab891c53 100644 --- a/pkg/sentry/fs/proc/sys.go +++ b/pkg/sentry/fs/proc/sys.go @@ -62,7 +62,7 @@ func (*mmapMinAddrData) NeedsUpdate(generation int64) bool { } // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. -func (d *mmapMinAddrData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (d *mmapMinAddrData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } @@ -81,7 +81,7 @@ func (*overcommitMemory) NeedsUpdate(generation int64) bool { } // ReadSeqFileData implements seqfile.SeqSource. -func (*overcommitMemory) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (*overcommitMemory) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } diff --git a/pkg/sentry/fs/proc/task.go b/pkg/sentry/fs/proc/task.go index 147d57a8f..e2d2ce3ba 100644 --- a/pkg/sentry/fs/proc/task.go +++ b/pkg/sentry/fs/proc/task.go @@ -304,7 +304,7 @@ func (md *mapsData) NeedsUpdate(generation int64) bool { } // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. -func (md *mapsData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (md *mapsData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if mm := md.mm(); mm != nil { return mm.ReadSeqFileData(md.t.AsyncContext(), h) } @@ -334,7 +334,7 @@ func (s *taskStatData) NeedsUpdate(generation int64) bool { // ReadSeqFileData returns data for the SeqFile reader. // SeqData, the current generation and where in the file the handle corresponds to. -func (s *taskStatData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (s *taskStatData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } @@ -405,7 +405,7 @@ func (s *statmData) NeedsUpdate(generation int64) bool { } // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. -func (s *statmData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (s *statmData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } @@ -440,7 +440,7 @@ func (s *statusData) NeedsUpdate(generation int64) bool { } // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. -func (s *statusData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (s *statusData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } @@ -505,7 +505,7 @@ func (i *ioData) NeedsUpdate(generation int64) bool { // ReadSeqFileData returns data for the SeqFile reader. // SeqData, the current generation and where in the file the handle corresponds to. -func (i *ioData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (i *ioData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } diff --git a/pkg/sentry/fs/proc/uid_gid_map.go b/pkg/sentry/fs/proc/uid_gid_map.go index a2a070bdd..85acb5163 100644 --- a/pkg/sentry/fs/proc/uid_gid_map.go +++ b/pkg/sentry/fs/proc/uid_gid_map.go @@ -40,7 +40,7 @@ func (imss *idMapSeqSource) NeedsUpdate(generation int64) bool { } // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. -func (imss *idMapSeqSource) ReadSeqFileData(handle seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (imss *idMapSeqSource) ReadSeqFileData(ctx context.Context, handle seqfile.SeqHandle) ([]seqfile.SeqData, int64) { var start int if handle != nil { start = handle.(*idMapSeqHandle).value diff --git a/pkg/sentry/fs/proc/version.go b/pkg/sentry/fs/proc/version.go index df3040d37..c0f2e87e3 100644 --- a/pkg/sentry/fs/proc/version.go +++ b/pkg/sentry/fs/proc/version.go @@ -17,6 +17,7 @@ package proc import ( "fmt" + "gvisor.googlesource.com/gvisor/pkg/sentry/context" "gvisor.googlesource.com/gvisor/pkg/sentry/fs/proc/seqfile" "gvisor.googlesource.com/gvisor/pkg/sentry/kernel" ) @@ -33,7 +34,7 @@ func (*versionData) NeedsUpdate(generation int64) bool { } // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. -func (v *versionData) ReadSeqFileData(h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { +func (v *versionData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { if h != nil { return nil, 0 } |