Commit 77ffd1bf authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c18237fe
...@@ -144,7 +144,7 @@ type fsOptions struct { ...@@ -144,7 +144,7 @@ type fsOptions struct {
Sticky bool Sticky bool
} }
var fSticky = &fsOptions{Sticky: true} // frequently used shortcut XXX -> newFSticky? var fSticky = &fsOptions{Sticky: true} // frequently used shortcut
func (n *fsNode) Deletable() bool { func (n *fsNode) Deletable() bool {
return !n.opt.Sticky return !n.opt.Sticky
...@@ -186,8 +186,8 @@ func (n *fsNode) path() string { ...@@ -186,8 +186,8 @@ func (n *fsNode) path() string {
// //
// Created file is sticky. // Created file is sticky.
func NewStaticFile(data []byte) *SmallFile { func NewStaticFile(data []byte) *SmallFile {
return newSmallFile(func() []byte { return newSmallFile(func(_ *fuse.Context) ([]byte, error) {
return data return data, nil
}, fuse.FOPEN_KEEP_CACHE /*see ^^^*/) }, fuse.FOPEN_KEEP_CACHE /*see ^^^*/)
} }
...@@ -197,10 +197,10 @@ type SmallFile struct { ...@@ -197,10 +197,10 @@ type SmallFile struct {
fuseFlags uint32 // fuse.FOPEN_* fuseFlags uint32 // fuse.FOPEN_*
// readData gives whole file data // readData gives whole file data
readData func() []byte readData func(fctx *fuse.Context) ([]byte, error)
} }
func newSmallFile(readData func() []byte, fuseFlags uint32) *SmallFile { func newSmallFile(readData func(*fuse.Context) ([]byte, error), fuseFlags uint32) *SmallFile {
return &SmallFile{ return &SmallFile{
fsNode: newFSNode(&fsOptions{Sticky: true}), fsNode: newFSNode(&fsOptions{Sticky: true}),
fuseFlags: fuseFlags, fuseFlags: fuseFlags,
...@@ -211,7 +211,7 @@ func newSmallFile(readData func() []byte, fuseFlags uint32) *SmallFile { ...@@ -211,7 +211,7 @@ func newSmallFile(readData func() []byte, fuseFlags uint32) *SmallFile {
// NewSmallFile creates nodefs.Node for file with dynamic, but always small, data. // NewSmallFile creates nodefs.Node for file with dynamic, but always small, data.
// //
// Created file is sticky. // Created file is sticky.
func NewSmallFile(readData func() []byte) *SmallFile { func NewSmallFile(readData func(*fuse.Context) ([]byte, error)) *SmallFile {
return newSmallFile(readData, fuse.FOPEN_DIRECT_IO) return newSmallFile(readData, fuse.FOPEN_DIRECT_IO)
} }
...@@ -223,14 +223,20 @@ func (f *SmallFile) Open(flags uint32, _ *fuse.Context) (nodefs.File, fuse.Statu ...@@ -223,14 +223,20 @@ func (f *SmallFile) Open(flags uint32, _ *fuse.Context) (nodefs.File, fuse.Statu
} }
func (f *SmallFile) GetAttr(out *fuse.Attr, _ nodefs.File, fctx *fuse.Context) fuse.Status { func (f *SmallFile) GetAttr(out *fuse.Attr, _ nodefs.File, fctx *fuse.Context) fuse.Status {
data := f.readData() // XXX pass in fctx, so that the call could be canceled data, err := f.readData(fctx)
if err != nil {
return err2LogStatus(err)
}
out.Size = uint64(len(data)) out.Size = uint64(len(data))
out.Mode = fuse.S_IFREG | 0644 out.Mode = fuse.S_IFREG | 0644
return fuse.OK return fuse.OK
} }
func (f *SmallFile) Read(_ nodefs.File, dest []byte, off int64, fctx *fuse.Context) (fuse.ReadResult, fuse.Status) { func (f *SmallFile) Read(_ nodefs.File, dest []byte, off int64, fctx *fuse.Context) (fuse.ReadResult, fuse.Status) {
data := f.readData() // XXX +fctx -> cancel data, err := f.readData(fctx)
if err != nil {
return nil, err2LogStatus(err)
}
l := int64(len(data)) l := int64(len(data))
end := off + l end := off + l
if end > l { if end > l {
......
...@@ -2176,11 +2176,12 @@ func (f *BigFile) Close() error { ...@@ -2176,11 +2176,12 @@ func (f *BigFile) Close() error {
// ---- misc --- // ---- misc ---
// /(head|<rev>)/at -> readAt serves read. // /(head|<rev>)/at -> readAt serves read.
func (h *Head) readAt() []byte { func (h *Head) readAt(fctx *fuse.Context) ([]byte, error) {
// XXX cancel on fctx cancel
h.zheadMu.RLock() h.zheadMu.RLock()
defer h.zheadMu.RUnlock() defer h.zheadMu.RUnlock()
return []byte(h.zconn.At().String()) return []byte(h.zconn.At().String()), nil
} }
// /(head|<rev>)/ -> Getattr serves stat. // /(head|<rev>)/ -> Getattr serves stat.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment