lib9p

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

commit a66ad50c693dd549728431f8492f27d5c128b9f3
parent e98ed8795fadc0e594d8b7b2fdec5b88cb9ffa13
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sun,  7 Jan 2024 11:30:02 +0900

delete context from Client functions

Diffstat:
Mclient/client.go | 54+++++++++++++++++++++++++++---------------------------
Mclient/client_test.go | 43++++++++++++++++++++-----------------------
Mclient/file.go | 9++++-----
Mclient/fs.go | 8++++----
Mdiskfs/file_test.go | 8++++----
Mdiskfs/stat_unix_test.go | 18+++++++++---------
6 files changed, 68 insertions(+), 72 deletions(-)

diff --git a/client/client.go b/client/client.go @@ -261,7 +261,7 @@ func (c *Client) runMultiplexer(ctx context.Context, tmsgc chan<- lib9p.Msg, rms // Transact send 9P lib9p.Msg of r to the multiplexer goroutines and recieves // the reply. -func (c *Client) transact(_ context.Context, tmsg lib9p.Msg) (lib9p.Msg, error) { +func (c *Client) transact(tmsg lib9p.Msg) (lib9p.Msg, error) { r := newReq(tmsg) select { case c.txc <- r: @@ -278,9 +278,9 @@ func (c *Client) transact(_ context.Context, tmsg lib9p.Msg) (lib9p.Msg, error) } } -func (c *Client) Version(ctx context.Context, tag uint16, msize uint32, version string) (uint32, string, error) { +func (c *Client) Version(tag uint16, msize uint32, version string) (uint32, string, error) { tmsg := &lib9p.TVersion{Tag: tag, Msize: msize, Version: version} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return 0, "", fmt.Errorf("transact: %v", err) } @@ -294,9 +294,9 @@ func (c *Client) Version(ctx context.Context, tag uint16, msize uint32, version } } -func (c *Client) Auth(ctx context.Context, tag uint16, afid uint32, uname, aname string) (lib9p.Qid, error) { +func (c *Client) Auth(tag uint16, afid uint32, uname, aname string) (lib9p.Qid, error) { tmsg := &lib9p.TAuth{Tag: tag, Afid: afid, Uname: uname} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return lib9p.Qid{}, fmt.Errorf("transact: %v", err) } @@ -310,9 +310,9 @@ func (c *Client) Auth(ctx context.Context, tag uint16, afid uint32, uname, aname } } -func (c *Client) Attach(ctx context.Context, tag uint16, fid, afid uint32, uname, aname string) (lib9p.Qid, error) { +func (c *Client) Attach(tag uint16, fid, afid uint32, uname, aname string) (lib9p.Qid, error) { tmsg := &lib9p.TAttach{Tag: tag, Fid: fid, Afid: afid, Uname: uname, Aname: aname} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return lib9p.Qid{}, fmt.Errorf("transact: %v", err) } @@ -326,9 +326,9 @@ func (c *Client) Attach(ctx context.Context, tag uint16, fid, afid uint32, uname } } -func (c *Client) Flush(ctx context.Context, tag, oldtag uint16) error { +func (c *Client) Flush(tag, oldtag uint16) error { tmsg := &lib9p.TFlush{Tag: tag, Oldtag: oldtag} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return fmt.Errorf("transact: %v", err) } @@ -341,9 +341,9 @@ func (c *Client) Flush(ctx context.Context, tag, oldtag uint16) error { return fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Walk(ctx context.Context, tag uint16, fid, newfid uint32, wnames []string) (wqid []lib9p.Qid, err error) { +func (c *Client) Walk(tag uint16, fid, newfid uint32, wnames []string) (wqid []lib9p.Qid, err error) { tmsg := &lib9p.TWalk{Tag: tag, Fid: fid, Newfid: newfid, Wnames: wnames} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return nil, fmt.Errorf("transact: %v", err) } @@ -356,9 +356,9 @@ func (c *Client) Walk(ctx context.Context, tag uint16, fid, newfid uint32, wname return nil, fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Open(ctx context.Context, tag uint16, fid uint32, mode lib9p.OpenMode) (qid lib9p.Qid, iounit uint32, err error) { +func (c *Client) Open(tag uint16, fid uint32, mode lib9p.OpenMode) (qid lib9p.Qid, iounit uint32, err error) { tmsg := &lib9p.TOpen{Tag: tag, Fid: fid, Mode: mode} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return lib9p.Qid{}, 0, fmt.Errorf("transact: %v", err) } @@ -371,9 +371,9 @@ func (c *Client) Open(ctx context.Context, tag uint16, fid uint32, mode lib9p.Op return lib9p.Qid{}, 0, fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Create(ctx context.Context, tag uint16, fid uint32, name string, perm lib9p.FileMode, mode lib9p.OpenMode) (lib9p.Qid, uint32, error) { +func (c *Client) Create(tag uint16, fid uint32, name string, perm lib9p.FileMode, mode lib9p.OpenMode) (lib9p.Qid, uint32, error) { tmsg := &lib9p.TCreate{Tag: tag, Fid: fid, Name: name, Perm: perm, Mode: mode} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return lib9p.Qid{}, 0, fmt.Errorf("transact: %v", err) } @@ -386,9 +386,9 @@ func (c *Client) Create(ctx context.Context, tag uint16, fid uint32, name string return lib9p.Qid{}, 0, fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Read(ctx context.Context, tag uint16, fid uint32, offset uint64, count uint32) (data []byte, err error) { +func (c *Client) Read(tag uint16, fid uint32, offset uint64, count uint32) (data []byte, err error) { tmsg := &lib9p.TRead{Tag: tag, Fid: fid, Offset: offset, Count: count} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return nil, fmt.Errorf("transact: %v", err) } @@ -401,9 +401,9 @@ func (c *Client) Read(ctx context.Context, tag uint16, fid uint32, offset uint64 return nil, fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Write(ctx context.Context, tag uint16, fid uint32, offset uint64, count uint32, data []byte) (uint32, error) { +func (c *Client) Write(tag uint16, fid uint32, offset uint64, count uint32, data []byte) (uint32, error) { tmsg := &lib9p.TWrite{Tag: tag, Fid: fid, Offset: offset, Count: count, Data: data} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return 0, fmt.Errorf("transact: %v", err) } @@ -416,9 +416,9 @@ func (c *Client) Write(ctx context.Context, tag uint16, fid uint32, offset uint6 return 0, fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Clunk(ctx context.Context, tag uint16, fid uint32) error { +func (c *Client) Clunk(tag uint16, fid uint32) error { tmsg := &lib9p.TClunk{Tag: tag, Fid: fid} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return fmt.Errorf("transact: %v", err) } @@ -431,9 +431,9 @@ func (c *Client) Clunk(ctx context.Context, tag uint16, fid uint32) error { return fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Remove(ctx context.Context, tag uint16, fid uint32) error { +func (c *Client) Remove(tag uint16, fid uint32) error { tmsg := &lib9p.TRemove{Tag: tag, Fid: fid} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return fmt.Errorf("transact: %v", err) } @@ -446,9 +446,9 @@ func (c *Client) Remove(ctx context.Context, tag uint16, fid uint32) error { return fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Stat(ctx context.Context, tag uint16, fid uint32) (*lib9p.Stat, error) { +func (c *Client) Stat(tag uint16, fid uint32) (*lib9p.Stat, error) { tmsg := &lib9p.TStat{Tag: tag, Fid: fid} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return nil, fmt.Errorf("transact: %v", err) } @@ -461,9 +461,9 @@ func (c *Client) Stat(ctx context.Context, tag uint16, fid uint32) (*lib9p.Stat, return nil, fmt.Errorf("invalid reply: %v", rmsg) } } -func (c *Client) Wstat(ctx context.Context, tag uint16, fid uint32, stat *lib9p.Stat) error { +func (c *Client) Wstat(tag uint16, fid uint32, stat *lib9p.Stat) error { tmsg := &lib9p.TWstat{Tag: tag, Fid: fid, Stat: stat} - rmsg, err := c.transact(ctx, tmsg) + rmsg, err := c.transact(tmsg) if err != nil { return fmt.Errorf("transact: %v", err) } diff --git a/client/client_test.go b/client/client_test.go @@ -25,7 +25,7 @@ func TestClientCancel(t *testing.T) { for i := 0; i < 10; i++ { go func(i int) { defer wg.Done() - c.Version(context.Background(), uint16(i), 1024, "9P2000") + c.Version(uint16(i), 1024, "9P2000") }(i) } for i := 0; i < 5; i++ { @@ -53,33 +53,30 @@ func TestDupTag(t *testing.T) { defer cancel() testfs.slow = true defer func() { testfs.slow = false }() - bg := context.Background() - _, _, err := c.Version(bg, 0, 8*1024, "9P2000") + _, _, err := c.Version(0, 8*1024, "9P2000") if err != nil { t.Fatal(err) } - _, err = c.Attach(bg, 0, 0, lib9p.NOFID, "kenji", "") + _, err = c.Attach(0, 0, lib9p.NOFID, "kenji", "") if err != nil { t.Fatal(err) } wname := []string{"a"} - wqid, err := c.Walk(bg, 0, 0, 1, wname) + wqid, err := c.Walk(0, 0, 1, wname) if err != nil { t.Fatal(err) } else if len(wqid) != len(wname) { t.Fatal("file not found") } - _, _, err = c.Open(bg, 0, 1, lib9p.OREAD) + _, _, err = c.Open(0, 1, lib9p.OREAD) if err != nil { t.Fatal(err) } - ctx, cancel := context.WithCancel(bg) - defer cancel() go func() { - _, err = c.Read(ctx, 0, 1, 0, 1024) + _, err = c.Read(0, 1, 0, 1024) }() <-testfs.waitc - _, err = c.Stat(bg, 0, 1) + _, err = c.Stat(0, 1) if err == nil { t.Error("dup tag not reported") } @@ -127,7 +124,7 @@ func TestVersion(t *testing.T) { go func() { ifcall := test.tmsg gotmsize, gotversion, goterr = - c.Version(ctx, ifcall.Tag, ifcall.Msize, ifcall.Version) + c.Version(ifcall.Tag, ifcall.Msize, ifcall.Version) close(done) }() gottmsg := <-tmsgc @@ -191,7 +188,7 @@ func TestAuth(t *testing.T) { go func() { ifcall := test.tmsg gotaqid, goterr = - c.Auth(ctx, ifcall.Tag, ifcall.Afid, ifcall.Uname, ifcall.Aname) + c.Auth(ifcall.Tag, ifcall.Afid, ifcall.Uname, ifcall.Aname) close(done) }() gottmsg := <-tmsgc @@ -254,7 +251,7 @@ func TestAttach(t *testing.T) { go func() { ifcall := test.tmsg gotqid, goterr = - c.Attach(ctx, ifcall.Tag, ifcall.Fid, ifcall.Afid, ifcall.Uname, ifcall.Aname) + c.Attach(ifcall.Tag, ifcall.Fid, ifcall.Afid, ifcall.Uname, ifcall.Aname) close(done) }() gottmsg := <-tmsgc @@ -313,7 +310,7 @@ func TestFlush(t *testing.T) { go func() { ifcall := test.tmsg goterr = - c.Flush(ctx, ifcall.Tag, ifcall.Oldtag) + c.Flush(ifcall.Tag, ifcall.Oldtag) close(done) }() gottmsg := <-tmsgc @@ -372,7 +369,7 @@ func TestWalk(t *testing.T) { go func() { ifcall := test.tmsg gotqids, goterr = - c.Walk(ctx, ifcall.Tag, ifcall.Fid, ifcall.Newfid, ifcall.Wnames) + c.Walk(ifcall.Tag, ifcall.Fid, ifcall.Newfid, ifcall.Wnames) close(done) }() gottmsg := <-tmsgc @@ -436,7 +433,7 @@ func TestOpen(t *testing.T) { go func() { ifcall := test.tmsg gotqid, gotiounit, goterr = - c.Open(ctx, ifcall.Tag, ifcall.Fid, ifcall.Mode) + c.Open(ifcall.Tag, ifcall.Fid, ifcall.Mode) close(done) }() gottmsg := <-tmsgc @@ -500,7 +497,7 @@ func TestCreate(t *testing.T) { go func() { ifcall := test.tmsg gotqid, gotiounit, goterr = - c.Create(ctx, ifcall.Tag, ifcall.Fid, ifcall.Name, ifcall.Perm, ifcall.Mode) + c.Create(ifcall.Tag, ifcall.Fid, ifcall.Name, ifcall.Perm, ifcall.Mode) close(done) }() gottmsg := <-tmsgc @@ -563,7 +560,7 @@ func TestRead(t *testing.T) { go func() { ifcall := test.tmsg gotdata, goterr = - c.Read(ctx, ifcall.Tag, ifcall.Fid, ifcall.Offset, ifcall.Count) + c.Read(ifcall.Tag, ifcall.Fid, ifcall.Offset, ifcall.Count) close(done) }() gottmsg := <-tmsgc @@ -626,7 +623,7 @@ func TestWrite(t *testing.T) { go func() { ifcall := test.tmsg gotcount, goterr = - c.Write(ctx, ifcall.Tag, ifcall.Fid, ifcall.Offset, ifcall.Count, ifcall.Data) + c.Write(ifcall.Tag, ifcall.Fid, ifcall.Offset, ifcall.Count, ifcall.Data) close(done) }() gottmsg := <-tmsgc @@ -688,7 +685,7 @@ func TestClunk(t *testing.T) { go func() { ifcall := test.tmsg goterr = - c.Clunk(ctx, ifcall.Tag, ifcall.Fid) + c.Clunk(ifcall.Tag, ifcall.Fid) close(done) }() gottmsg := <-tmsgc @@ -746,7 +743,7 @@ func TestRemove(t *testing.T) { go func() { ifcall := test.tmsg goterr = - c.Remove(ctx, ifcall.Tag, ifcall.Fid) + c.Remove(ifcall.Tag, ifcall.Fid) close(done) }() gottmsg := <-tmsgc @@ -802,7 +799,7 @@ func TestStat(t *testing.T) { go func() { ifcall := test.tmsg gotstat, goterr = - c.Stat(ctx, ifcall.Tag, ifcall.Fid) + c.Stat(ifcall.Tag, ifcall.Fid) close(done) }() gottmsg := <-tmsgc @@ -864,7 +861,7 @@ func TestWstat(t *testing.T) { go func() { ifcall := test.tmsg goterr = - c.Wstat(ctx, ifcall.Tag, ifcall.Fid, ifcall.Stat) + c.Wstat(ifcall.Tag, ifcall.Fid, ifcall.Stat) close(done) }() gottmsg := <-tmsgc diff --git a/client/file.go b/client/file.go @@ -1,7 +1,6 @@ package client import ( - "context" "errors" "io" "io/fs" @@ -25,7 +24,7 @@ func (cf *File) Stat() (*lib9p.FileInfo, error) { if err != nil { return nil, err } - st, err := cf.fs.c.Stat(context.TODO(), tag, cf.fid.fid) + st, err := cf.fs.c.Stat(tag, cf.fid.fid) cf.fs.tPool.delete(tag) if err != nil { return nil, err @@ -39,7 +38,7 @@ func (cf *File) Close() error { if err != nil { return err } - err = cf.fs.c.Clunk(context.TODO(), tag, cf.fid.fid) + err = cf.fs.c.Clunk(tag, cf.fid.fid) cf.fs.tPool.delete(tag) cf.fs.c.fPool.delete(cf.fid.fid) cf.fid = nil @@ -69,7 +68,7 @@ func (cf *File) Read(b []byte) (int, error) { if err != nil { return 0, err } - buf, err := cf.fs.c.Read(context.TODO(), tag, cf.fid.fid, cf.fid.offset, c) + buf, err := cf.fs.c.Read(tag, cf.fid.fid, cf.fid.offset, c) cf.fs.tPool.delete(tag) var i int for i = 0; i < len(buf); i++ { @@ -107,7 +106,7 @@ func (cf *File) ReadDir(n int) ([]fs.DirEntry, error) { if err != nil { break } - data, err = cf.fs.c.Read(context.TODO(), tag, cf.fid.fid, cf.fid.offset, cf.iounit) + data, err = cf.fs.c.Read(tag, cf.fid.fid, cf.fid.offset, cf.iounit) cf.fs.tPool.delete(tag) if err != nil { break diff --git a/client/fs.go b/client/fs.go @@ -32,7 +32,7 @@ func (fsys *FS) OpenFile(name string, omode lib9p.OpenMode) (lib9p.File, error) if err != nil { return nil, err } - qid, iounit, err = fsys.c.Open(context.TODO(), tag, f.fid.fid, omode) + qid, iounit, err = fsys.c.Open(tag, f.fid.fid, omode) fsys.tPool.delete(tag) if err != nil { f.Close() @@ -61,7 +61,7 @@ func (fsys *FS) walkFile(name string) (*File, error) { if err != nil { return nil, err } - wqid, err := fsys.c.Walk(context.TODO(), tag, fsys.c.rootFid.fid, fid.fid, wname) + wqid, err := fsys.c.Walk(tag, fsys.c.rootFid.fid, fid.fid, wname) fsys.tPool.delete(tag) if err != nil { return nil, fmt.Errorf("walk: %v", err) @@ -110,7 +110,7 @@ func Mount(ctx context.Context, r io.Reader, w io.Writer, uname, aname string) ( cancel0() } }() - rmSize, rver, err := cfs.c.Version(ctx0, lib9p.NOTAG, mSize, version) + rmSize, rver, err := cfs.c.Version(lib9p.NOTAG, mSize, version) if err != nil { return nil, fmt.Errorf("version: %v", err) } @@ -129,7 +129,7 @@ func Mount(ctx context.Context, r io.Reader, w io.Writer, uname, aname string) ( if err != nil { return nil, err } - _, err = cfs.c.Attach(ctx0, tag, fid.fid, lib9p.NOFID, uname, aname) + _, err = cfs.c.Attach(tag, fid.fid, lib9p.NOFID, uname, aname) cfs.tPool.delete(tag) if err != nil { return nil, fmt.Errorf("attach: %v", err) diff --git a/diskfs/file_test.go b/diskfs/file_test.go @@ -26,20 +26,20 @@ func BenchmarkRead(b *testing.B) { s := lib9p.NewServer(disk) go s.Serve(ctx, sr, sw) c := client.NewClient(ctx, 8*1024, "kenji", cr, cw) - _, err = c.Attach(ctx, ^uint16(0), 0, lib9p.NOFID, "kenji", "") + _, err = c.Attach(^uint16(0), 0, lib9p.NOFID, "kenji", "") if err != nil { b.Fatalf("attach: %v", err) } - wqid, err := c.Walk(ctx, 0, 0, 1, []string{"a"}) + wqid, err := c.Walk(0, 0, 1, []string{"a"}) if err != nil || len(wqid) != 1 { b.Fatalf("walk: %v", err) } - _, _, err = c.Open(ctx, 0, 1, lib9p.OREAD) + _, _, err = c.Open(0, 1, lib9p.OREAD) if err != nil { b.Fatalf("open: %v", err) } for i := 0; i < b.N; i++ { - _, err := c.Read(ctx, 0, 1, 0, 8*1024) + _, err := c.Read(0, 1, 0, 8*1024) if err != nil { b.Fatalf("read: %v", err) } diff --git a/diskfs/stat_unix_test.go b/diskfs/stat_unix_test.go @@ -29,12 +29,12 @@ func BenchmarkGID(b *testing.B) { s := lib9p.NewServer(disk) go s.Serve(ctx, sr, sw) c := client.NewClient(ctx, 8*1024, "kenji", cr, cw) - _, err = c.Attach(ctx, ^uint16(0), 0, lib9p.NOFID, "kenji", "") + _, err = c.Attach(^uint16(0), 0, lib9p.NOFID, "kenji", "") if err != nil { b.Fatalf("attach: %v", err) } for i := 0; i < b.N; i++ { - _, err := c.Stat(ctx, 0, 0) + _, err := c.Stat(0, 0) if err != nil { b.Fatalf("stat: %v", err) } @@ -57,27 +57,27 @@ func TestChgrp(t *testing.T) { s := lib9p.NewServer(disk) go s.Serve(ctx, sr, sw) c := client.NewClient(ctx, 8*1024, "kenji", cr, cw) - _, err = c.Attach(ctx, ^uint16(0), 0, lib9p.NOFID, "kenji", "") + _, err = c.Attach(^uint16(0), 0, lib9p.NOFID, "kenji", "") if err != nil { t.Fatalf("attach: %v", err) } wname := []string{"a"} - wqid, err := c.Walk(ctx, 0, 0, 1, wname) + wqid, err := c.Walk(0, 0, 1, wname) if len(wqid) != len(wname) || err != nil { t.Fatalf("file not found: %v", err) } - st, err := c.Stat(ctx, 0, 1) + st, err := c.Stat(0, 1) if err != nil { t.Fatalf("stat: %v", err) } oldGid := st.Gid t.Logf("old stat: %v", st) st.Gid = "wheel" - err = c.Wstat(ctx, 0, 1, st) + err = c.Wstat(0, 1, st) if err != nil { t.Fatalf("wstat: %v", err) } - st, err = c.Stat(ctx, 0, 1) + st, err = c.Stat(0, 1) if err != nil { t.Fatalf("stat: %v", err) } @@ -86,11 +86,11 @@ func TestChgrp(t *testing.T) { t.Fatal("gid not changed to wheel.") } st.Gid = oldGid - err = c.Wstat(ctx, 0, 1, st) + err = c.Wstat(0, 1, st) if err != nil { t.Fatalf("wstat: %v", err) } - st, err = c.Stat(ctx, 0, 1) + st, err = c.Stat(0, 1) if err != nil { t.Fatalf("stat: %v", err) }