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

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
} }