mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-26 01:44:48 +00:00
NVMe/TCP transport support in the CSI driver so Kubernetes pods can mount block volumes via NVMe alongside (or instead of) iSCSI. Transport selection: NVMe preferred when nvme_tcp module loaded + metadata present + nvmeUtil available. Fail-fast on NVMe errors (no silent iSCSI fallback). .transport file persists across CSI restarts. Key changes: - BuildNQN() single source of truth for NQN construction (naming.go) - NVMeUtil interface + realNVMeUtil wrapping nvme-cli (nvme_util.go) - NodeStageVolume/Unstage/Expand dual-transport paths (node.go) - NvmeAddr/NQN fields in VolumeInfo, Controller contexts - VolumeManager NvmeAddr()/VolumeNQN() getters - BlockService NvmeListenAddr()/NQN() accessors - 27 unit tests + 26 QA adversarial tests (nvme_node_test.go, qa_cp102) - Fix: flaky TestQA_Node_ConcurrentStageUnstage (pre-alloc temp dirs) Review fixes applied: F1 (NQN format mismatch), F2 (CreateVolume drops NVMe context), F3 (IsConnected error classification), F4 (findSubsys path validation), F5 (MasterVolumeClient NVMe gap documented). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package blockvol
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var reInvalidFilename = regexp.MustCompile(`[^a-z0-9._-]`)
|
|
var reInvalidIQN = regexp.MustCompile(`[^a-z0-9.\-]`)
|
|
|
|
// SanitizeFilename normalizes a volume name for use as a filename.
|
|
// Lowercases, replaces invalid chars with '-'.
|
|
func SanitizeFilename(name string) string {
|
|
return reInvalidFilename.ReplaceAllString(strings.ToLower(name), "-")
|
|
}
|
|
|
|
// BuildNQN constructs an NVMe NQN from a prefix and volume name.
|
|
// The prefix must already include the separator (e.g. "nqn.2024-01.com.seaweedfs:vol.").
|
|
// This is the single source of truth for NQN construction — used by both
|
|
// the volume server (BlockService) and the CSI driver (VolumeManager/nodeServer).
|
|
func BuildNQN(prefix, name string) string {
|
|
return prefix + SanitizeIQN(name)
|
|
}
|
|
|
|
// SanitizeIQN normalizes a CSI volume ID for use in an IQN.
|
|
// Lowercases, replaces invalid chars with '-', truncates to 64 chars.
|
|
// When truncation is needed, a hash suffix is appended to preserve uniqueness.
|
|
func SanitizeIQN(name string) string {
|
|
s := strings.ToLower(name)
|
|
s = reInvalidIQN.ReplaceAllString(s, "-")
|
|
if len(s) > 64 {
|
|
h := sha256.Sum256([]byte(name))
|
|
suffix := hex.EncodeToString(h[:4]) // 8 hex chars
|
|
s = s[:64-1-len(suffix)] + "-" + suffix
|
|
}
|
|
return s
|
|
}
|