Commit 82359abe authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Levin Zimmermann

wcfs: Switch debug.zheadSockTab to fine-grained locking

Previously we were protecting access to zheadSockTab with zheadMu
because this table was accessed from only two places: when opening
.wcfs/zhead and in zwatcher. Soon we are going to add another place that
will access this table and still using big zheadMu seem less and less
logical.

-> Switch to using dedicated lock to protect table of .wcfs/zhead opens
   as preparatory step for that.

/reviewed-by @levin.zimmermann
/reviewed-on !18
parent a36b5562
...@@ -960,6 +960,7 @@ retry: ...@@ -960,6 +960,7 @@ retry:
} }
// notify .wcfs/zhead // notify .wcfs/zhead
gdebug.zheadSockTabMu.Lock()
for sk := range gdebug.zheadSockTab { for sk := range gdebug.zheadSockTab {
_, err := fmt.Fprintf(xio.BindCtxW(sk, ctx), "%s\n", δZ.Tid) _, err := fmt.Fprintf(xio.BindCtxW(sk, ctx), "%s\n", δZ.Tid)
if err != nil { if err != nil {
...@@ -968,6 +969,7 @@ retry: ...@@ -968,6 +969,7 @@ retry:
delete(gdebug.zheadSockTab, sk) delete(gdebug.zheadSockTab, sk)
} }
} }
gdebug.zheadSockTabMu.Unlock()
// shrink δFtail not to grow indefinitely. // shrink δFtail not to grow indefinitely.
// cover history for at least 1 minute, but including all watches. // cover history for at least 1 minute, but including all watches.
...@@ -2331,11 +2333,11 @@ var gfsconn *nodefs.FileSystemConnector ...@@ -2331,11 +2333,11 @@ var gfsconn *nodefs.FileSystemConnector
// so we still have to reference the root via path. // so we still have to reference the root via path.
var gmntpt string var gmntpt string
// debugging (protected by zhead.W) // debugging
var gdebug = struct { var gdebug = struct {
// .wcfs/zhead opens // .wcfs/zhead opens
// protected by groot.head.zheadMu zheadSockTabMu sync.Mutex
zheadSockTab map[*FileSock]struct{} zheadSockTab map[*FileSock]struct{}
}{} }{}
func init() { func init() {
...@@ -2352,11 +2354,11 @@ func (zh *_wcfs_Zhead) Open(flags uint32, fctx *fuse.Context) (nodefs.File, fuse ...@@ -2352,11 +2354,11 @@ func (zh *_wcfs_Zhead) Open(flags uint32, fctx *fuse.Context) (nodefs.File, fuse
sk := NewFileSock() sk := NewFileSock()
sk.CloseRead() sk.CloseRead()
groot.head.zheadMu.Lock() // TODO +fctx -> cancel
defer groot.head.zheadMu.Unlock()
// TODO del zheadSockTab[sk] on sk.File.Release (= client drops opened handle) // TODO del zheadSockTab[sk] on sk.File.Release (= client drops opened handle)
gdebug.zheadSockTabMu.Lock() // TODO +fctx -> cancel
gdebug.zheadSockTab[sk] = struct{}{} gdebug.zheadSockTab[sk] = struct{}{}
gdebug.zheadSockTabMu.Unlock()
return sk.File(), fuse.OK return sk.File(), fuse.OK
} }
......
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