commit ac4ad2ffd51eb1f5c9a10d2a45104fe7f8641915
parent 9288d9846770ab450405aeaf8c990c9f961e29eb
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 19 Oct 2024 18:09:52 +0900
add sync.Mutex to qidPool
Diffstat:
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/diskfs/qid_unix.go b/diskfs/qid_unix.go
@@ -7,6 +7,7 @@ import (
"io/fs"
"os"
"path/filepath"
+ "sync"
"syscall"
"time"
@@ -31,6 +32,7 @@ type qidRec struct {
type QidPool struct {
m map[fileID]*qidRec
nextQid uint64
+ *sync.Mutex
}
// id derives the fileID from the file.
@@ -57,7 +59,9 @@ func idFromInfo(path string, info fs.FileInfo) fileID {
// newQidPool allocates a QidPool.
func newQidPool() *QidPool {
return &QidPool{
- m: make(map[fileID]*qidRec),
+ make(map[fileID]*qidRec),
+ 0,
+ new(sync.Mutex),
}
}
@@ -81,6 +85,8 @@ func (pool *QidPool) lookup(f *File) (lib9p.Qid, bool) {
// It also checks if the file is modified after the last access by
// comparing the qidReq.mtime and mtime, and update Qid.Vers if needed.
func (pool *QidPool) lookupID(id fileID, mtime time.Time) (lib9p.Qid, bool) {
+ pool.Lock()
+ defer pool.Unlock()
qrec, ok := pool.m[id]
if !ok {
return lib9p.Qid{}, false
@@ -108,6 +114,8 @@ func (pool *QidPool) add(f *File) (lib9p.Qid, error) {
// addID does the same as add, but by fileID.
func (pool *QidPool) addID(id fileID, info fs.FileInfo) (lib9p.Qid, error) {
+ pool.Lock()
+ defer pool.Unlock()
qtype := lib9p.FSModeToQidType(info.Mode())
qid := &lib9p.Qid{
Path: pool.nextQid,
@@ -124,5 +132,7 @@ func (pool *QidPool) delete(f *File) {
if err != nil {
return
}
+ pool.Lock()
+ defer pool.Unlock()
delete(pool.m, id)
}