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,17 +42,27 @@ type Connector struct {
} }
func getNvmfConnector(nvmfInfo *nvmfDiskInfo) *Connector { func getNvmfConnector(nvmfInfo *nvmfDiskInfo) *Connector {
hostnqn := ""
if nvmfInfo.HostNqn != "" {
hostnqn = nvmfInfo.HostNqn
} else {
hostnqnData, err := os.ReadFile("/etc/nvme/hostnqn") hostnqnData, err := os.ReadFile("/etc/nvme/hostnqn")
hostnqn := strings.TrimSpace(string(hostnqnData)) hostnqn = strings.TrimSpace(string(hostnqnData))
if err != nil { if err != nil {
hostnqn = "" hostnqn = ""
} }
}
hostid := ""
if nvmfInfo.HostId != "" {
hostid = nvmfInfo.HostId
} else {
hostidData, err := os.ReadFile("/etc/nvme/hostid") hostidData, err := os.ReadFile("/etc/nvme/hostid")
hostid := strings.TrimSpace(string(hostidData)) hostid = strings.TrimSpace(string(hostidData))
if err != nil { if err != nil {
hostid = "" hostid = ""
} }
}
return &Connector{ return &Connector{
VolumeID: nvmfInfo.VolName, VolumeID: nvmfInfo.VolName,

View File

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