diff options
author | Ayush Ranjan <ayushranjan@google.com> | 2019-07-30 19:42:50 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-07-30 19:43:59 -0700 |
commit | 5afa642deb190dbacee225d05f58de69f775d3f3 (patch) | |
tree | a086d06ea3193f72770f5ca7620dfc8979e9d531 /pkg/sentry/fs/ext/extent_test.go | |
parent | 9fbe984dc13f1af42bf3a73b696f7358794dd2d4 (diff) |
ext: Migrate from using fileReader custom interface to using io.Reader.
It gets rid of holding state of the io.Reader offset (which is anyways held by
the vfs.FileDescriptor struct. It is also odd using a io.Reader becuase we
using io.ReaderAt to interact with the device. So making a io.ReaderAt wrapper
makes more sense.
Most importantly, it gets rid of the complexity of extracting the file reader
from a regular file implementation and then using it. Now we can just use the
regular file implementation as a reader which is more intuitive.
PiperOrigin-RevId: 260846927
Diffstat (limited to 'pkg/sentry/fs/ext/extent_test.go')
-rw-r--r-- | pkg/sentry/fs/ext/extent_test.go | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/pkg/sentry/fs/ext/extent_test.go b/pkg/sentry/fs/ext/extent_test.go index 9b3f5469e..d03cd564f 100644 --- a/pkg/sentry/fs/ext/extent_test.go +++ b/pkg/sentry/fs/ext/extent_test.go @@ -16,7 +16,6 @@ package ext import ( "bytes" - "io" "math/rand" "testing" @@ -145,14 +144,13 @@ var ( // TestExtentReader stress tests extentReader functionality. It performs random // length reads from all possible positions in the extent tree. func TestExtentReader(t *testing.T) { - dev, mockExtentFile, want := extentTreeSetUp(t, node0) + mockExtentFile, want := extentTreeSetUp(t, node0) n := len(want) for from := 0; from < n; from++ { - fileReader := mockExtentFile.getFileReader(dev, mockExtentBlkSize, uint64(from)) got := make([]byte, n-from) - if read, err := io.ReadFull(fileReader, got); err != nil { + if read, err := mockExtentFile.ReadAt(got, int64(from)); err != nil { t.Fatalf("file read operation from offset %d to %d only read %d bytes: %v", from, n, read, err) } @@ -164,7 +162,7 @@ func TestExtentReader(t *testing.T) { // TestBuildExtentTree tests the extent tree building logic. func TestBuildExtentTree(t *testing.T) { - _, mockExtentFile, _ := extentTreeSetUp(t, node0) + mockExtentFile, _ := extentTreeSetUp(t, node0) opt := cmpopts.IgnoreUnexported(disklayout.ExtentIdx{}, disklayout.ExtentHeader{}) if diff := cmp.Diff(&mockExtentFile.root, node0, opt); diff != "" { @@ -175,7 +173,7 @@ func TestBuildExtentTree(t *testing.T) { // extentTreeSetUp writes the passed extent tree to a mock disk as an extent // tree. It also constucts a mock extent file with the same tree built in it. // It also writes random data file data and returns it. -func extentTreeSetUp(t *testing.T, root *disklayout.ExtentNode) (io.ReaderAt, *extentFile, []byte) { +func extentTreeSetUp(t *testing.T, root *disklayout.ExtentNode) (*extentFile, []byte) { t.Helper() mockDisk := make([]byte, mockExtentBlkSize*10) @@ -187,17 +185,18 @@ func extentTreeSetUp(t *testing.T, root *disklayout.ExtentNode) (io.ReaderAt, *e SizeLo: uint32(mockExtentBlkSize) * getNumPhyBlks(root), }, }, + blkSize: mockExtentBlkSize, + dev: bytes.NewReader(mockDisk), }, }, } fileData := writeTree(&mockExtentFile.regFile.inode, mockDisk, node0, mockExtentBlkSize) - r := bytes.NewReader(mockDisk) - if err := mockExtentFile.buildExtTree(r, mockExtentBlkSize); err != nil { + if err := mockExtentFile.buildExtTree(); err != nil { t.Fatalf("inode.buildExtTree failed: %v", err) } - return r, mockExtentFile, fileData + return mockExtentFile, fileData } // writeTree writes the tree represented by `root` to the inode and disk. It |