commit 9964bc7bfd0998c5e29e623ad1ce799ab103b178
parent 959c37c0c1bbd6f5734cdd08a8f67f835deb6efb
Author: Matsuda Kenji <info@mtkn.jp>
Date: Mon, 25 Dec 2023 16:32:29 +0900
delete rWalk
Diffstat:
| M | server.go | | | 60 | ++++++++++++++++++++++-------------------------------------- |
1 file changed, 22 insertions(+), 38 deletions(-)
diff --git a/server.go b/server.go
@@ -158,7 +158,7 @@ func (s *Server) runSpeaker(ctx context.Context) {
// This function is called only by the server's listener goroutine,
// and does not need to lock r.
// The argument ctx is used to set the request's context.
-func (s *Server)getReq(ctx context.Context) *Req {
+func (s *Server) getReq(ctx context.Context) *Req {
ifcall, err := RecvMsg(s.r)
if err != nil {
if err == io.EOF {
@@ -318,12 +318,12 @@ func sAttach(ctx context.Context, s *Server, c <-chan *Req) {
r.Ofcall = &RAttach{
Qid: st.Sys().(*Stat).Qid,
}
-resp:
+ resp:
if r.err != nil {
- r.Srv.fPool.delete(r.Ifcall.(*TAttach).Fid)
+ s.fPool.delete(r.Ifcall.(*TAttach).Fid)
setError(r, r.err)
}
- r.Srv.respChan <- r
+ s.respChan <- r
}
}
}
@@ -347,9 +347,6 @@ func sFlush(ctx context.Context, s *Server, c <-chan *Req) {
}
func sWalk(ctx context.Context, s *Server, c <-chan *Req) {
- rc := make(chan *Req)
- defer close(rc)
- go rWalk(ctx, rc)
for {
select {
case <-ctx.Done():
@@ -358,30 +355,33 @@ func sWalk(ctx context.Context, s *Server, c <-chan *Req) {
if !ok {
return
}
+ var (
+ err error
+ oldst fs.FileInfo
+ newFid *Fid
+ wqids []Qid
+ cwdp string
+ n int
+ )
ifcall := r.Ifcall.(*TWalk)
oldFid, ok := s.fPool.lookup(ifcall.Fid)
if !ok {
r.err = ErrUnknownFid
- rc <- r
- continue
+ goto resp
}
if oldFid.OMode != -1 {
r.err = fmt.Errorf("cannot clone open fid")
- rc <- r
- continue
+ goto resp
}
- oldst, err := fs.Stat(ExportFS{s.fs}, oldFid.path)
+ oldst, err = fs.Stat(ExportFS{s.fs}, oldFid.path)
if err != nil {
r.err = fmt.Errorf("stat: %v", err)
- rc <- r
- continue
+ goto resp
}
if len(ifcall.Wnames) > 0 && oldst.Sys().(*Stat).Qid.Type&QTDIR == 0 {
r.err = fmt.Errorf("walk on non-dir")
- rc <- r
- continue
+ goto resp
}
- var newFid *Fid
if ifcall.Fid == ifcall.Newfid {
newFid = oldFid
} else {
@@ -389,13 +389,11 @@ func sWalk(ctx context.Context, s *Server, c <-chan *Req) {
newFid, err = s.fPool.add(ifcall.Newfid)
if err != nil {
r.err = fmt.Errorf("alloc: %v", err)
- rc <- r
- continue
+ goto resp
}
}
- wqids := make([]Qid, len(ifcall.Wnames))
- cwdp := oldFid.path
- var n int
+ wqids = make([]Qid, len(ifcall.Wnames))
+ cwdp = oldFid.path
// TODO: replace this block with fs.WalkDir.
for i, name := range ifcall.Wnames {
cwdp = path.Join(cwdp, name)
@@ -412,21 +410,7 @@ func sWalk(ctx context.Context, s *Server, c <-chan *Req) {
r.Ofcall = &RWalk{
Qids: wqids[:n],
}
- rc <- r
- }
- }
-}
-
-func rWalk(ctx context.Context, c <-chan *Req) {
- for {
- select {
- case <-ctx.Done():
- return
- case r, ok := <-c:
- if !ok {
- return
- }
- ifcall := r.Ifcall.(*TWalk)
+ resp:
if r.Ofcall == nil {
if r.err == nil {
panic("err and r.Ofcall are both nil")
@@ -446,7 +430,7 @@ func rWalk(ctx context.Context, c <-chan *Req) {
}
}
}
- r.Srv.respChan <- r
+ s.respChan <- r
}
}
}