From 190842cb92ae61c0636eaff9be316af05065cadf Mon Sep 17 00:00:00 2001 From: Liang Kang Date: Tue, 21 Nov 2023 12:43:05 +0800 Subject: [PATCH] duplicate target to parallel file handling --- nfs/target.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/nfs/target.go b/nfs/target.go index 3a734d1..40c06e7 100644 --- a/nfs/target.go +++ b/nfs/target.go @@ -18,6 +18,7 @@ import ( type Target struct { *rpc.Client + addr string auth rpc.Auth fh []byte dirPath string @@ -39,6 +40,7 @@ func NewTarget(addr string, auth rpc.Auth, fh []byte, dirpath string) (*Target, vol := &Target{ Client: client, + addr: addr, auth: auth, fh: fh, dirPath: dirpath, @@ -74,6 +76,37 @@ func (v *Target) call(c interface{}) (io.ReadSeeker, error) { return res, nil } +func (v *Target) Dup() (*Target, error) { + m := rpc.Mapping{ + Prog: Nfs3Prog, + Vers: Nfs3Vers, + Prot: rpc.IPProtoTCP, + Port: 0, + } + + client, err := DialService(v.addr, m) + if err != nil { + return nil, err + } + + vol := &Target{ + Client: client, + auth: v.auth, + fh: v.fh, + dirPath: v.dirPath, + } + + fsinfo, err := vol.FSInfo() + if err != nil { + return nil, err + } + + vol.fsinfo = fsinfo + util.Debugf("%s:%s fsinfo=%#v", v.addr, v.dirPath, fsinfo) + + return vol, nil +} + func (v *Target) FSInfo() (*FSInfo, error) { type FSInfoArgs struct { rpc.Header