fs: set OpenDirectIO in stats files to avoid having them cached in kernel

bazil.org/fuse switched from having OpenDirectIO on to having it
off by default. This has the side effect of allowing OS X's kernel
to cache the filesystem's files in its UBC, giving us incorrect
stats from cammount's .camli_fs_stats directory. This change sets
it explicitly to get the correct behaviour again.

Updates #556

Change-Id: Ic6400a550e4874086cf5fb725d423fcfde47fd61
This commit is contained in:
Salmān Aljammāz 2014-12-26 17:42:52 +00:00
parent b72628c68a
commit 64220e06ff
2 changed files with 7 additions and 10 deletions

View File

@ -89,6 +89,12 @@ func (s *stat) Attr() fuse.Attr {
}
}
func (s *stat) Open(req *fuse.OpenRequest, res *fuse.OpenResponse, intr fs.Intr) (fs.Handle, fuse.Error) {
// Set DirectIO to keep this file from being cached in OS X's kernel.
res.Flags |= fuse.OpenDirectIO
return s, nil
}
func (s *stat) Read(req *fuse.ReadRequest, res *fuse.ReadResponse, intr fs.Intr) fuse.Error {
c := s.content()
if req.Offset > int64(len(c)) {

View File

@ -296,7 +296,7 @@ func (n *mutDir) Lookup(name string, intr fs.Intr) (ret fs.Node, err fuse.Error)
// foi->flags = O_CREAT | O_RDWR;
//
// 2013/07/21 05:26:35 <- &{Create [ID=0x3 Node=0x8 Uid=61652 Gid=5000 Pid=13115] "x" fl=514 mode=-rw-r--r-- fuse.Intr}
// 2013/07/21 05:26:36 -> 0x3 Create {LookupResponse:{Node:23 Generation:0 EntryValid:1m0s AttrValid:1m0s Attr:{Inode:15976986887557313215 Size:0 Blocks:0 Atime:2013-07-21 05:23:51.537251251 +1200 NZST Mtime:2013-07-21 05:23:51.537251251 +1200 NZST Ctime:2013-07-21 05:23:51.537251251 +1200 NZST Crtime:2013-07-21 05:23:51.537251251 +1200 NZST Mode:-rw------- Nlink:1 Uid:61652 Gid:5000 Rdev:0 Flags:0}} OpenResponse:{Handle:1 Flags:OpenDirectIO}}
// 2013/07/21 05:26:36 -> 0x3 Create {LookupResponse:{Node:23 Generation:0 EntryValid:1m0s AttrValid:1m0s Attr:{Inode:15976986887557313215 Size:0 Blocks:0 Atime:2013-07-21 05:23:51.537251251 +1200 NZST Mtime:2013-07-21 05:23:51.537251251 +1200 NZST Ctime:2013-07-21 05:23:51.537251251 +1200 NZST Crtime:2013-07-21 05:23:51.537251251 +1200 NZST Mode:-rw------- Nlink:1 Uid:61652 Gid:5000 Rdev:0 Flags:0}} OpenResponse:{Handle:1 Flags:0}}
func (n *mutDir) Create(req *fuse.CreateRequest, res *fuse.CreateResponse, intr fs.Intr) (fs.Node, fs.Handle, fuse.Error) {
child, err := n.creat(req.Name, fileType)
if err != nil {
@ -310,11 +310,6 @@ func (n *mutDir) Create(req *fuse.CreateRequest, res *fuse.CreateResponse, intr
return nil, nil, ferr
}
// This isn't required (or even ever been shown to make a
// difference), but we do it to match OpenRequest below, where
// it causes test failures without:
res.OpenResponse.Flags &= ^fuse.OpenDirectIO
return child, h, nil
}
@ -681,10 +676,6 @@ func (n *mutFile) Open(req *fuse.OpenRequest, res *fuse.OpenResponse, intr fs.In
return nil, fuse.EIO
}
// Turn off the OpenDirectIO bit (on by default in rsc fuse server.go),
// else append operations don't work for some reason.
res.Flags &= ^fuse.OpenDirectIO
// Read-only.
if !isWriteFlags(req.Flags) {
mutFileOpenRO.Incr()