From 64220e06ff7bcad6cc6d63a2faa73251dbfad068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salm=C4=81n=20Aljamm=C4=81z?= Date: Fri, 26 Dec 2014 17:42:52 +0000 Subject: [PATCH] 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 --- pkg/fs/debug.go | 6 ++++++ pkg/fs/mut.go | 11 +---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pkg/fs/debug.go b/pkg/fs/debug.go index 0548ff26d..d38774371 100644 --- a/pkg/fs/debug.go +++ b/pkg/fs/debug.go @@ -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)) { diff --git a/pkg/fs/mut.go b/pkg/fs/mut.go index 5eafa51d3..97197f0b8 100644 --- a/pkg/fs/mut.go +++ b/pkg/fs/mut.go @@ -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()