Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NVMe_FC protocol #39

Open
wants to merge 1 commit into
base: developing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/connector/connector_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,3 +948,26 @@ func RemoveRoCEDevice(device string) ([]string, string, error) {

return devices, multiPathName, nil
}

// RemoveNvmeFcDevice remove dm device if present
func RemoveNvmeFcDevice(device string) (string, error) {
var multiPathName string
var err error
if strings.HasPrefix(device, "dm") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is valid only for DM multipath. If other multipath like Ultrapath or EMCPP comes then we will have to put other checks

multiPathName = device
// devices: nvme0n1, nvme2n1,
_, err = getDeviceFromDM(multiPathName)
if err != nil {
log.Warningf("Get the devices from the multipath %s error: %v", multiPathName, err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is just warning, this means the sys class has issues and we are ignoring it. Further when you try to flush the device without having the sysfs entries, will it create issues?

}

// just flush the dm path. no need to delete device on host, when delete the storage mapping
// the device will be automatically deleted.
err := FlushDMDevice(multiPathName)
if err == nil {
multiPathName = ""
}
}

return multiPathName, nil
}
28 changes: 25 additions & 3 deletions src/connector/nvme/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import (
"connector"
"errors"
"fmt"
"sync"
"time"
"utils/log"
)

type FCNVMe struct{}
type FCNVMe struct {
mutex sync.Mutex
}

const (
intNumTwo = 2
intNumThree = 3
)

func init() {
connector.RegisterConnector(connector.FCNVMeDriver, &FCNVMe{})
Expand All @@ -22,7 +30,7 @@ func (fc *FCNVMe) ConnectVolume(conn map[string]interface{}) (string, error) {
log.Errorln(msg)
return "", errors.New(msg)
}
connectInfo := map[string]interface{} {
connectInfo := map[string]interface{}{
"protocol": "fc",
}
connector.ScanNVMe(connectInfo)
Expand All @@ -48,6 +56,20 @@ func (fc *FCNVMe) ConnectVolume(conn map[string]interface{}) (string, error) {
}

func (fc *FCNVMe) DisConnectVolume(tgtLunGuid string) error {
fc.mutex.Lock()
defer fc.mutex.Unlock()
log.Infof("FC-NVMe Start to disconnect volume ==> Volume Guid info: %v", tgtLunGuid)
return connector.DeleteDevice(tgtLunGuid)
for i := 0; i < 3; i++ {
err := tryDisConnectVolume(tgtLunGuid, true)
if err == nil {
return nil
}

log.Errorf("Failed to delete device in %d time(s), err: %v", i, err)
time.Sleep(time.Second * intNumTwo)
}

msg := fmt.Sprintf("Failed to delete volume %s.", tgtLunGuid)
log.Errorln(msg)
return errors.New(msg)
}
31 changes: 31 additions & 0 deletions src/connector/nvme/nvme_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package nvme

import (
"connector"
"time"
"utils/log"
)

func tryDisConnectVolume(tgtLunWWN string, checkDeviceAvailable bool) error {
device, err := connector.GetDevice(nil, tgtLunWWN, checkDeviceAvailable)
if err != nil {
log.Warningf("Get device of WWN %s error: %v", tgtLunWWN, err)
return err
}

multiPathName, err := connector.RemoveNvmeFcDevice(device)
if err != nil {
log.Errorf("Remove device %s error: %v", device, err)
return err
}

if multiPathName != "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is multipath device, then the device flush attempt has already been done

time.Sleep(time.Second * intNumThree)
err = connector.FlushDMDevice(device)
if err != nil {
return err
}
}

return nil
}
18 changes: 18 additions & 0 deletions yamls/deploy/huawei-csi-configmap-oceanstor-fcnvme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: huawei-csi-configmap
namespace: kube-system
data:
csi.json: |
{
"backends": [
{
"storage": "oceanstor-san",
"name": "***",
"urls": ["https://*.*.*.*:8088", "https://*.*.*.*:8088"],
"pools": ["***", "***"],
"parameters": {"protocol": "fc-nvme"}
}
]
}