lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit 9841e7d35d1bc34b2d515a86a9bb086aa8f794cb
parent d5ed46010c01c045ca6f35aba4b81ef019337e0a
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Mon, 22 Jan 2024 08:56:01 +0900

delete fPool from client.Client and move it to client.FS

Diffstat:
Mclient/client.go | 7-------
Mclient/client_test.go | 1-
Mclient/file.go | 2+-
Mclient/fs.go | 13++++++++-----
4 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/client/client.go b/client/client.go @@ -21,18 +21,12 @@ type Client struct { // Uname is used to communicate with a server. uname string - // FPool is the filePool which hold the list of outstanding files. - fPool *filePool - // RPool is the set of all outstanding requests. rPool *reqPool // Txc is used to send a reqest to the multiplexer goroutine txc chan<- *req - // Root is the root file of the file system. - root *File - // Wg is the WaitGroup of all goroutines evoked by this client and its // descendants. wg *sync.WaitGroup @@ -52,7 +46,6 @@ func NewClient(ctx context.Context, mSize uint32, uname string, r io.Reader, w i msize: mSize, mSizeLock: new(sync.Mutex), uname: uname, - fPool: newFilePool(), rPool: newReqPool(), wg: new(sync.WaitGroup), done: ctx.Done(), diff --git a/client/client_test.go b/client/client_test.go @@ -59,7 +59,6 @@ func newClientForTest(ctx context.Context, msize uint32, uname string) (*Client, msize: msize, mSizeLock: new(sync.Mutex), uname: uname, - fPool: newFilePool(), rPool: newReqPool(), wg: new(sync.WaitGroup), } diff --git a/client/file.go b/client/file.go @@ -53,7 +53,7 @@ func (cf *File) Close() error { } err = cf.fs.c.Clunk(tag, cf.fid) cf.fs.tPool.delete(tag) - cf.fs.c.fPool.delete(cf.fid) + cf.fs.fPool.delete(cf.fid) cf.fid = lib9p.NOFID return err } diff --git a/client/fs.go b/client/fs.go @@ -13,7 +13,9 @@ import ( // FS represents the file system the client imports. type FS struct { c *Client + root *File tPool *tagPool + fPool *filePool } // OpenFile opens the file named name in fsys with omode. @@ -66,7 +68,7 @@ func CleanPath(name string) string { // returns the corresponding file. // returned file is not open. func (fsys *FS) walkFile(name string) (*File, error) { - f, err := fsys.c.fPool.add() + f, err := fsys.fPool.add() if err != nil { return nil, fmt.Errorf("add file: %v", err) } @@ -78,13 +80,13 @@ func (fsys *FS) walkFile(name string) (*File, error) { if err != nil { return nil, err } - wqid, err := fsys.c.Walk(tag, fsys.c.root.fid, f.fid, wname) + wqid, err := fsys.c.Walk(tag, fsys.root.fid, f.fid, wname) fsys.tPool.delete(tag) if err != nil { return nil, fmt.Errorf("walk: %v", err) } if len(wqid) < len(wname) { - fsys.c.fPool.delete(f.fid) + fsys.fPool.delete(f.fid) return nil, fmt.Errorf("not found") } var qid lib9p.Qid @@ -117,6 +119,7 @@ func Mount(ctx context.Context, r io.Reader, w io.Writer, uname, aname string) ( cfs := &FS{ c: NewClient(ctx0, mSize, uname, r, w), tPool: newTagPool(), + fPool: newFilePool(), } defer func() { if err != nil { @@ -134,7 +137,7 @@ func Mount(ctx context.Context, r io.Reader, w io.Writer, uname, aname string) ( cfs.c.setMSize(rmSize) } // TODO: auth - f, err := cfs.c.fPool.add() + f, err := cfs.fPool.add() if err != nil { return nil, fmt.Errorf("add file: %v", err) } @@ -151,6 +154,6 @@ func Mount(ctx context.Context, r io.Reader, w io.Writer, uname, aname string) ( f.path = "." f.qid = qid f.fs = cfs - cfs.c.root = f + cfs.root = f return cfs, nil }