From b002568227ab21045fe0c5a27b966b4bd66724f0 Mon Sep 17 00:00:00 2001 From: Meinhard Zhou Date: Tue, 21 Nov 2023 20:43:13 +0800 Subject: [PATCH] feat: add rdma support Signed-off-by: Meinhard Zhou --- pkg/nvmf/driver.go | 2 -- pkg/nvmf/fabrics.go | 11 +++++------ pkg/nvmf/nodeserver.go | 4 ++++ pkg/nvmf/nvmf.go | 2 +- pkg/nvmf/nvmf_utils.go | 11 +++-------- pkg/nvmf/server.go | 1 - 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/pkg/nvmf/driver.go b/pkg/nvmf/driver.go index cec33e7..c3b157a 100644 --- a/pkg/nvmf/driver.go +++ b/pkg/nvmf/driver.go @@ -99,8 +99,6 @@ func (d *driver) AddControllerServiceCapabilities(cl []csi.ControllerServiceCapa } d.cscap = csc - - return } func (d *driver) ValidateControllerServiceRequest(c csi.ControllerServiceCapability_RPC_Type) error { diff --git a/pkg/nvmf/fabrics.go b/pkg/nvmf/fabrics.go index 9a45b9d..0e033cc 100644 --- a/pkg/nvmf/fabrics.go +++ b/pkg/nvmf/fabrics.go @@ -20,7 +20,6 @@ import ( b64 "encoding/base64" "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -70,7 +69,7 @@ func _connect(argStr string) error { return err } // todo: read file to verify - lines, err := utils.ReadLinesFromFile(file) + lines, _ := utils.ReadLinesFromFile(file) klog.Infof("Connect: read string %s", lines) return nil } @@ -182,7 +181,7 @@ func disconnectByNqn(nqn, hostnqn string) int { // delete nqn directory if has no hostnqn files nqnPath := filepath.Join(RUN_NVMF, nqn) - hostnqns, err := ioutil.ReadDir(nqnPath) + hostnqns, err := os.ReadDir(nqnPath) if err != nil { klog.Errorf("Disconnect: readdir %s err: %v", nqnPath, err) return -ENOENT @@ -191,7 +190,7 @@ func disconnectByNqn(nqn, hostnqn string) int { os.RemoveAll(nqnPath) } - devices, err := ioutil.ReadDir(SYS_NVMF) + devices, err := os.ReadDir(SYS_NVMF) if err != nil { klog.Errorf("Disconnect: readdir %s err: %s", SYS_NVMF, err) return -ENOENT @@ -204,7 +203,7 @@ func disconnectByNqn(nqn, hostnqn string) int { // disconnect all controllers if has no hostnqn files if len(hostnqns) <= 0 { - devices, err := ioutil.ReadDir(SYS_NVMF) + devices, err := os.ReadDir(SYS_NVMF) if err != nil { klog.Errorf("Disconnect: readdir %s err: %s", SYS_NVMF, err) return -ENOENT @@ -328,7 +327,7 @@ func removeConnectorFile(targetPath string) { } func GetConnectorFromFile(filePath string) (*Connector, error) { - f, err := ioutil.ReadFile(filePath) + f, err := os.ReadFile(filePath) if err != nil { return &Connector{}, err diff --git a/pkg/nvmf/nodeserver.go b/pkg/nvmf/nodeserver.go index 92e42fe..8329215 100644 --- a/pkg/nvmf/nodeserver.go +++ b/pkg/nvmf/nodeserver.go @@ -120,6 +120,10 @@ func (n *NodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVo scanPath := parseDeviceToControllerPath(deviceName) if utils.IsFileExisting(scanPath) { file, err := os.OpenFile(scanPath, os.O_RDWR|os.O_TRUNC, 0766) + if err != nil { + klog.Errorf("NodeExpandVolume: open scan path %s error: %v", scanPath, err) + return nil, status.Errorf(codes.Internal, "NodeExpandVolume: open scan path %s error: %v", scanPath, err) + } err = utils.WriteStringToFile(file, "1") if err != nil { klog.Errorf("NodeExpandVolume: Rescan error: %v", err) diff --git a/pkg/nvmf/nvmf.go b/pkg/nvmf/nvmf.go index 04dbefd..caaa786 100644 --- a/pkg/nvmf/nvmf.go +++ b/pkg/nvmf/nvmf.go @@ -62,7 +62,7 @@ func getNVMfDiskInfo(req *csi.NodePublishVolumeRequest) (*nvmfDiskInfo, error) { nqn := volOpts["nqn"] if targetTrAddr == "" || nqn == "" || targetTrPort == "" || targetTrType == "" || deviceUUID == "" { - return nil, fmt.Errorf("Some Nvme target info is missing, volID: %s ", volName) + return nil, fmt.Errorf("some nvme target info is missing, volID: %s ", volName) } return &nvmfDiskInfo{ diff --git a/pkg/nvmf/nvmf_utils.go b/pkg/nvmf/nvmf_utils.go index cab6b03..475a230 100644 --- a/pkg/nvmf/nvmf_utils.go +++ b/pkg/nvmf/nvmf_utils.go @@ -32,15 +32,10 @@ import ( func waitForPathToExist(devicePath string, maxRetries, intervalSeconds int, deviceTransport string) (bool, error) { for i := 0; i < maxRetries; i++ { - if deviceTransport == "tcp" { - exist := utils.IsFileExisting(devicePath) - if exist { - return true, nil - } - } else { - return false, fmt.Errorf("connect only support tcp") + exist := utils.IsFileExisting(devicePath) + if exist { + return true, nil } - if i == maxRetries-1 { break } diff --git a/pkg/nvmf/server.go b/pkg/nvmf/server.go index b098f91..d86e600 100644 --- a/pkg/nvmf/server.go +++ b/pkg/nvmf/server.go @@ -52,7 +52,6 @@ type nonBlockingGRPCServer struct { func (s *nonBlockingGRPCServer) Start(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer) { s.wg.Add(1) go s.serve(endpoint, ids, cs, ns) - return } func (s *nonBlockingGRPCServer) Wait() {