Skip to content

Commit

Permalink
Enable zero-copy support (requires patched fuse pkg)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbuenemann committed Sep 6, 2020
1 parent 479eb2e commit 6b5ad99
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions chunk/manager.go
Expand Up @@ -93,7 +93,7 @@ func NewManager(
}

// GetChunk loads one chunk and starts the preload for the next chunks
func (m *Manager) GetChunk(object *drive.APIObject, offset, size int64) ([]byte, error) {
func (m *Manager) GetChunk(object *drive.APIObject, offset, size, padding int64) ([]byte, error) {
// Log.Tracef("Get %v offset %v size %v", object.ObjectID, offset, size)
maxOffset := int64(object.Size)
if offset > maxOffset {
Expand All @@ -110,7 +110,7 @@ func (m *Manager) GetChunk(object *drive.APIObject, offset, size int64) ([]byte,
m.requestChunk(object, r.offset, r.size, i, responses)
}

data := make([]byte, size, size)
data := make([]byte, size+padding, size+padding)
var err error
for i := 0; i < cap(responses); i++ {
res := <-responses
Expand All @@ -120,7 +120,7 @@ func (m *Manager) GetChunk(object *drive.APIObject, offset, size int64) ([]byte,
}

if err == nil {
dataOffset := ranges[res.Sequence].offset - offset
dataOffset := ranges[res.Sequence].offset - offset + padding

n := copy(data[dataOffset:], res.Bytes)
if n == 0 {
Expand Down
3 changes: 2 additions & 1 deletion mount/mount.go
Expand Up @@ -242,13 +242,14 @@ func (o *Object) Lookup(ctx context.Context, name string) (fs.Node, error) {

// Read reads some bytes or the whole file
func (o *Object) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
data, err := o.chunkManager.GetChunk(o.object, req.Offset, int64(req.Size))
data, err := o.chunkManager.GetChunk(o.object, req.Offset, int64(req.Size), 16)
if nil != err {
Log.Warningf("%v", err)
return fuse.EIO
}

resp.Data = data
resp.ZeroCopy = true
return nil
}

Expand Down

0 comments on commit 6b5ad99

Please sign in to comment.