Merge pull request #38 from ghormoon/custom-hostnqn

Allow overriding hostNqn/hostId
This commit is contained in:
Meinhard Zhou
2025-10-08 11:00:23 +08:00
committed by GitHub
2 changed files with 24 additions and 8 deletions

View File

@@ -42,16 +42,26 @@ type Connector struct {
}
func getNvmfConnector(nvmfInfo *nvmfDiskInfo) *Connector {
hostnqnData, err := os.ReadFile("/etc/nvme/hostnqn")
hostnqn := strings.TrimSpace(string(hostnqnData))
if err != nil {
hostnqn = ""
hostnqn := ""
if nvmfInfo.HostNqn != "" {
hostnqn = nvmfInfo.HostNqn
} else {
hostnqnData, err := os.ReadFile("/etc/nvme/hostnqn")
hostnqn = strings.TrimSpace(string(hostnqnData))
if err != nil {
hostnqn = ""
}
}
hostidData, err := os.ReadFile("/etc/nvme/hostid")
hostid := strings.TrimSpace(string(hostidData))
if err != nil {
hostid = ""
hostid := ""
if nvmfInfo.HostId != "" {
hostid = nvmfInfo.HostId
} else {
hostidData, err := os.ReadFile("/etc/nvme/hostid")
hostid = strings.TrimSpace(string(hostidData))
if err != nil {
hostid = ""
}
}
return &Connector{

View File

@@ -33,6 +33,8 @@ type nvmfDiskInfo struct {
Port string
DeviceUUID string
Transport string
HostId string
HostNqn string
}
type nvmfDiskMounter struct {
@@ -59,6 +61,8 @@ func getNVMfDiskInfo(req *csi.NodePublishVolumeRequest) (*nvmfDiskInfo, error) {
targetTrPort := volOpts["targetTrPort"]
targetTrType := volOpts["targetTrType"]
deviceUUID := volOpts["deviceUUID"]
devHostNqn := volOpts["hostNqn"]
devHostId := volOpts["hostId"]
nqn := volOpts["nqn"]
if targetTrAddr == "" || nqn == "" || targetTrPort == "" || targetTrType == "" || deviceUUID == "" {
@@ -72,6 +76,8 @@ func getNVMfDiskInfo(req *csi.NodePublishVolumeRequest) (*nvmfDiskInfo, error) {
Nqn: nqn,
DeviceUUID: deviceUUID,
Transport: targetTrType,
HostNqn: devHostNqn,
HostId: devHostId,
}, nil
}