提交 fcf7f0e7 作者: Juan Batiz-Benet

fuse/ipfs: seeking

This commit changed the "ReadAll" to do proper read requests.
Seeking in fuse mounted fs now works. Note: this is why opening a
mounted video didnt work... we just didnt look at this code in
months.
上级 3c34ab8e
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
package readonly package readonly
import ( import (
"io/ioutil" "io"
"os" "os"
fuse "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse" fuse "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
...@@ -16,12 +16,13 @@ import ( ...@@ -16,12 +16,13 @@ import (
core "github.com/jbenet/go-ipfs/core" core "github.com/jbenet/go-ipfs/core"
mdag "github.com/jbenet/go-ipfs/merkledag" mdag "github.com/jbenet/go-ipfs/merkledag"
path "github.com/jbenet/go-ipfs/path" path "github.com/jbenet/go-ipfs/path"
eventlog "github.com/jbenet/go-ipfs/thirdparty/eventlog"
uio "github.com/jbenet/go-ipfs/unixfs/io" uio "github.com/jbenet/go-ipfs/unixfs/io"
ftpb "github.com/jbenet/go-ipfs/unixfs/pb" ftpb "github.com/jbenet/go-ipfs/unixfs/pb"
u "github.com/jbenet/go-ipfs/util" lgbl "github.com/jbenet/go-ipfs/util/eventlog/loggables"
) )
var log = u.Logger("ipfs") var log = eventlog.Logger("fuse/ipfs")
// FileSystem is the readonly Ipfs Fuse Filesystem. // FileSystem is the readonly Ipfs Fuse Filesystem.
type FileSystem struct { type FileSystem struct {
...@@ -144,14 +145,51 @@ func (s *Node) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) { ...@@ -144,14 +145,51 @@ func (s *Node) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) {
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
// ReadAll reads the object data as file data func (s *Node) Read(req *fuse.ReadRequest, resp *fuse.ReadResponse, intr fs.Intr) fuse.Error {
func (s *Node) ReadAll(intr fs.Intr) ([]byte, fuse.Error) { // intr will be closed by fuse if the request is cancelled. turn this into a context.
log.Debug("Read node.") ctx, cancel := context.WithCancel(context.TODO())
r, err := uio.NewDagReader(context.TODO(), s.Nd, s.Ipfs.DAG) defer cancel() // make sure all operations we started close.
// we wait on intr and cancel our context if it closes.
go func() {
select {
case <-intr: // closed by fuse
cancel() // cancel our context
case <-ctx.Done():
}
}()
k, err := s.Nd.Key()
if err != nil { if err != nil {
return nil, err return err
} }
// this is a terrible function... 'ReadAll'?
// what if i have a 6TB file? GG RAM. // setup our logging event
return ioutil.ReadAll(r) lm := make(lgbl.DeferredMap)
lm["key"] = func() interface{} { return k.Pretty() }
lm["req_offset"] = req.Offset
lm["req_size"] = req.Size
defer log.EventBegin(ctx, "fuseRead", lm).Done()
r, err := uio.NewDagReader(ctx, s.Nd, s.Ipfs.DAG)
if err != nil {
return err
}
o, err := r.Seek(req.Offset, os.SEEK_SET)
lm["req_offset"] = o
if err != nil {
return err
}
n, err := io.ReadFull(r, resp.Data[:req.Size])
resp.Data = resp.Data[:n]
lm["req_size"] = n
return err // may be non-nil / not succeeded
} }
// // ReadAll reads the object data as file data
// func (s *Node) ReadAll(intr fs.Intr) ([]byte, fuse.Error) {
// // this is a terrible function... 'ReadAll'?
// // what if i have a 6TB file? GG RAM.
// return ioutil.ReadAll(r)
// }
// GG RAM alright... -jbenet
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论