mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
docs: close iSCSI/NVMe protocol readiness plan (#44)
Close the current protocol-readiness plan and move active work to V2 parity and hardening. The release gate now covers iSCSI ALUA/failover, NVMe ANA/multipath/failover, CSI protocol selection, and the iSCSI compatibility soak. Test layering is documented so default Go tests stay unit/component scoped, local subprocess tests are opt-in, and Linux lab coverage remains in runner-native TestOps suites.
This commit is contained in:
1 parent
fb28af1c17
commit
6dd9dc33e2
112 files changed
+8470
-238
No files matched your search
@@ -99,13 +99,18 @@ If the GHCR packages are not public yet, use the local build path below.
|
||||
bash scripts/build-alpha-images.sh "$PWD"
|
||||
```
|
||||
|
||||
For k3s, import both images:
|
||||
For k3s, build and import both images into k3s containerd in one pinned step:
|
||||
|
||||
```bash
|
||||
docker save sw-block:local | sudo k3s ctr images import -
|
||||
docker save sw-block-csi:local | sudo k3s ctr images import -
|
||||
SW_BLOCK_IMPORT_K3S=1 \
|
||||
SW_BLOCK_ARTIFACT_DIR=/tmp/sw-block-alpha-build \
|
||||
bash scripts/build-alpha-images.sh "$PWD"
|
||||
```
|
||||
|
||||
The artifact directory records image IDs and component `--version` output. This
|
||||
is the preferred local path because it prevents stale k3s images from being
|
||||
mistaken for the current checkout.
|
||||
|
||||
### Run the smoke test
|
||||
|
||||
```bash
|
||||
|
||||
@@ -150,13 +150,16 @@ func TestG15b_Manifest_NodePluginPrivilegedShape(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15b_Manifest_NodePluginLoadsISCSITCPModule(t *testing.T) {
|
||||
func TestG15b_Manifest_NodePluginLoadsFrontendKernelModules(t *testing.T) {
|
||||
doc := g15bFindKind(t, "csi-node.yaml", "DaemonSet")
|
||||
podSpec := g15bMap(t, g15bMap(t, g15bMap(t, doc, "spec"), "template"), "spec")
|
||||
initContainers := g15bSlice(t, podSpec, "initContainers")
|
||||
loader := g15bContainer(t, initContainers, "load-iscsi-tcp")
|
||||
if got := strings.Join(g15bStringSlice(t, loader, "args"), " "); !strings.Contains(got, "modprobe iscsi_tcp") {
|
||||
t.Fatalf("load-iscsi-tcp args=%q, want modprobe iscsi_tcp", got)
|
||||
got := strings.Join(g15bStringSlice(t, loader, "args"), " ")
|
||||
for _, want := range []string{"modprobe iscsi_tcp", "modprobe nvme_tcp"} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("load-iscsi-tcp args=%q, want %s", got, want)
|
||||
}
|
||||
}
|
||||
sec := g15bMap(t, loader, "securityContext")
|
||||
if got, ok := sec["privileged"].(bool); !ok || !got {
|
||||
@@ -211,7 +214,7 @@ func TestG15b_ImageBuildInputs_ContainExpectedBinariesAndNodeTools(t *testing.T)
|
||||
}
|
||||
|
||||
csi := g15bReadDeployFile(t, "Dockerfile.blockcsi")
|
||||
for _, want := range []string{"./cmd/blockcsi", "open-iscsi", "e2fsprogs", "kmod", "util-linux", "/usr/local/bin/blockcsi"} {
|
||||
for _, want := range []string{"./cmd/blockcsi", "open-iscsi", "nvme-cli", "e2fsprogs", "kmod", "util-linux", "/usr/local/bin/blockcsi"} {
|
||||
if !strings.Contains(csi, want) {
|
||||
t.Fatalf("Dockerfile.blockcsi missing %q", want)
|
||||
}
|
||||
@@ -223,6 +226,142 @@ func TestG15b_ImageBuildInputs_ContainExpectedBinariesAndNodeTools(t *testing.T)
|
||||
t.Fatalf("build-alpha-images.sh missing %q", want)
|
||||
}
|
||||
}
|
||||
for _, want := range []string{
|
||||
"SW_BLOCK_IMPORT_K3S",
|
||||
"sudo k3s ctr images import -",
|
||||
"docker image inspect",
|
||||
"alpha-images.env",
|
||||
"blockmaster.version.txt",
|
||||
"blockvolume.version.txt",
|
||||
"blockcsi.version.txt",
|
||||
} {
|
||||
if !strings.Contains(buildScript, want) {
|
||||
t.Fatalf("build-alpha-images.sh missing pin-build/import contract %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
pinBuild := g15bReadScript(t, "testops-pin-alpha-images.sh")
|
||||
for _, want := range []string{
|
||||
"run-request.json",
|
||||
"SW_BLOCK_IMPORT_K3S",
|
||||
"pin-build",
|
||||
"alpha image pin-build/import failed",
|
||||
"result.json",
|
||||
} {
|
||||
if !strings.Contains(pinBuild, want) {
|
||||
t.Fatalf("testops-pin-alpha-images.sh missing %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
suite := g15bReadScript(t, "testops-run-nvme-p5-suite.sh")
|
||||
for _, want := range []string{
|
||||
"alpha-images-pin-build",
|
||||
"nvme-p5-csi-dynamic",
|
||||
"nvme-p5-default-iscsi-regression",
|
||||
"SW_BLOCK_ALPHA_IMAGES_ENV=$PIN_ENV",
|
||||
"nvme-p5-csi-suite",
|
||||
"result.json",
|
||||
} {
|
||||
if !strings.Contains(suite, want) {
|
||||
t.Fatalf("testops-run-nvme-p5-suite.sh missing %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
releaseGate := g15bReadScript(t, "testops-run-protocol-release-gate.sh")
|
||||
for _, want := range []string{
|
||||
"protocol-release-gate-suite",
|
||||
"iscsi-p6-alua-failover-chain.yaml",
|
||||
"nvme-p4-multipath-failover-chain.yaml",
|
||||
"nvme-p5-csi-protocol-chain.yaml",
|
||||
"iscsi-p8-compat-soak-chain.yaml",
|
||||
"child-run.txt",
|
||||
"result.json",
|
||||
"wall_clock_s",
|
||||
"started_at",
|
||||
"swblock exited 0 but did not write latest run pointer",
|
||||
} {
|
||||
if !strings.Contains(releaseGate, want) {
|
||||
t.Fatalf("testops-run-protocol-release-gate.sh missing %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
releaseGatePS := g15bReadScript(t, "testops-run-protocol-release-gate.ps1")
|
||||
for _, want := range []string{
|
||||
"protocol-release-gate-suite",
|
||||
"iscsi-p6-alua-failover-chain.yaml",
|
||||
"nvme-p4-multipath-failover-chain.yaml",
|
||||
"nvme-p5-csi-protocol-chain.yaml",
|
||||
"iscsi-p8-compat-soak-chain.yaml",
|
||||
"child-run.txt",
|
||||
"result.json",
|
||||
"wall_clock_s",
|
||||
"started_at",
|
||||
"Invoke-NativeRedirect",
|
||||
} {
|
||||
if !strings.Contains(releaseGatePS, want) {
|
||||
t.Fatalf("testops-run-protocol-release-gate.ps1 missing %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
releaseGateValidate := g15bReadScript(t, "testops-validate-protocol-release-gate.py")
|
||||
for _, want := range []string{
|
||||
"protocol-release-gate-suite",
|
||||
"EXPECTED_CHILDREN",
|
||||
"iscsi-p6-alua-failover",
|
||||
"nvme-p4-multipath-failover",
|
||||
"nvme-p5-csi-protocol",
|
||||
"iscsi-p8-compat-soak",
|
||||
"wall_clock_s",
|
||||
"--expect-product-commit",
|
||||
"--allow-fail",
|
||||
} {
|
||||
if !strings.Contains(releaseGateValidate, want) {
|
||||
t.Fatalf("testops-validate-protocol-release-gate.py missing %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
releaseGateValidatePS := g15bReadScript(t, "testops-validate-latest-protocol-release-gate.ps1")
|
||||
for _, want := range []string{
|
||||
"validate-bundle",
|
||||
"--profile",
|
||||
"protocol-release-gate",
|
||||
"--expect-commit",
|
||||
"Find-LatestProtocolGateArtifact",
|
||||
"Invoke-Native",
|
||||
} {
|
||||
if !strings.Contains(releaseGateValidatePS, want) {
|
||||
t.Fatalf("testops-validate-latest-protocol-release-gate.ps1 missing %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
releaseGateValidateSH := g15bReadScript(t, "testops-validate-latest-protocol-release-gate.sh")
|
||||
for _, want := range []string{
|
||||
"validate-bundle",
|
||||
"--profile",
|
||||
"protocol-release-gate",
|
||||
"--expect-commit",
|
||||
"find_latest_protocol_gate_artifact",
|
||||
"SWBLOCK_RUNNER_ROOT",
|
||||
} {
|
||||
if !strings.Contains(releaseGateValidateSH, want) {
|
||||
t.Fatalf("testops-validate-latest-protocol-release-gate.sh missing %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15dHarnessConsumesPinnedAlphaImagesEnv(t *testing.T) {
|
||||
body := g15bReadScript(t, "run-g15d-k8s-dynamic.sh")
|
||||
for _, want := range []string{
|
||||
"SW_BLOCK_ALPHA_IMAGES_ENV",
|
||||
"SW_BLOCK_PIN_BUILD_ENV",
|
||||
"source \"$ALPHA_IMAGES_ENV\"",
|
||||
"alpha-images.env",
|
||||
"alpha_images_env=",
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Fatalf("run-g15d-k8s-dynamic.sh missing pinned image env contract %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15b_Harness_CollectsDaemonLogsOnExit(t *testing.T) {
|
||||
|
||||
@@ -39,7 +39,10 @@ func TestG15c_BlockCSICreateVolumeWritesMasterLifecycleIntent(t *testing.T) {
|
||||
CapacityRange: &csipb.CapacityRange{
|
||||
RequiredBytes: 1 << 20,
|
||||
},
|
||||
Parameters: map[string]string{"replicationFactor": "2"},
|
||||
Parameters: map[string]string{
|
||||
"replicationFactor": "2",
|
||||
"sw-block.seaweedfs.com/protocol": "nvme",
|
||||
},
|
||||
VolumeCapabilities: []*csipb.VolumeCapability{
|
||||
testMountCapability(),
|
||||
},
|
||||
@@ -59,6 +62,7 @@ func TestG15c_BlockCSICreateVolumeWritesMasterLifecycleIntent(t *testing.T) {
|
||||
VolumeID string `json:"volume_id"`
|
||||
SizeBytes uint64 `json:"size_bytes"`
|
||||
ReplicationFactor int `json:"replication_factor"`
|
||||
Protocol string `json:"protocol"`
|
||||
} `json:"spec"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &rec); err != nil {
|
||||
@@ -67,6 +71,12 @@ func TestG15c_BlockCSICreateVolumeWritesMasterLifecycleIntent(t *testing.T) {
|
||||
if rec.Spec.VolumeID != "pvc-a" || rec.Spec.SizeBytes != 1<<20 || rec.Spec.ReplicationFactor != 2 {
|
||||
t.Fatalf("record=%+v", rec.Spec)
|
||||
}
|
||||
if rec.Spec.Protocol != "nvme" {
|
||||
t.Fatalf("record protocol=%q want nvme", rec.Spec.Protocol)
|
||||
}
|
||||
if got := resp.GetVolume().GetVolumeContext()["protocol"]; got != "nvme" {
|
||||
t.Fatalf("response protocol=%q want nvme", got)
|
||||
}
|
||||
}
|
||||
|
||||
func startG15cMaster(t *testing.T, bin, art, lifecycleDir string) *g15aProc {
|
||||
|
||||
@@ -70,7 +70,23 @@ func TestG15d_K8sRunner_AppliesLauncherGeneratedManifest(t *testing.T) {
|
||||
"SW_BLOCK_LAUNCHER_PVC_OWNER_REF",
|
||||
"SW_BLOCK_ISCSI_CHAP_USERNAME",
|
||||
"SW_BLOCK_ISCSI_CHAP_SECRET",
|
||||
"SW_BLOCK_FRONTEND_PROTOCOL",
|
||||
"csi.storage.k8s.io/node-stage-secret-name",
|
||||
`sw-block.seaweedfs.com/protocol: \"nvme\"`,
|
||||
`protocol: \"nvme\"`,
|
||||
"frontend_protocol=$FRONTEND_PROTOCOL",
|
||||
"expected_git_revision=${EXPECTED_GIT_REVISION:-unknown}",
|
||||
"blockmaster.version.txt",
|
||||
"blockcsi.version.txt",
|
||||
"blockvolume.version.txt",
|
||||
"kube-system-imageids.txt",
|
||||
"image revision mismatch",
|
||||
"delete-storageclass-before-apply.log",
|
||||
"storageclass.live.yaml",
|
||||
"live StorageClass missing NVMe protocol parameter",
|
||||
"lifecycle-volumes.json",
|
||||
"verified generated blockvolume frontend protocol=nvme",
|
||||
"generated blockvolume manifest rendered iSCSI args while frontend_protocol=nvme",
|
||||
"--launcher-iscsi-chap-secret-name",
|
||||
"BLOCKVOLUME_NAMESPACE=\"kube-system\"",
|
||||
"--kubernetes-pvc-uid-lookup",
|
||||
@@ -84,6 +100,7 @@ func TestG15d_K8sRunner_AppliesLauncherGeneratedManifest(t *testing.T) {
|
||||
"delete generated blockvolume Deployment after manifest cleanup",
|
||||
"wait for Kubernetes GC to delete PVC-owned blockvolume Deployment",
|
||||
"iscsi-sessions.after-delete.txt",
|
||||
"nvme-list-subsys.after-delete.json",
|
||||
"PASS: dynamic PVC create/delete completed checksum write/read and cleanup",
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
@@ -92,6 +109,28 @@ func TestG15d_K8sRunner_AppliesLauncherGeneratedManifest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15d_K8sRunner_NVMeProtocolWrapper(t *testing.T) {
|
||||
body := g15dReadFile(t, "scripts", "run-k8s-alpha-nvme.sh")
|
||||
for _, want := range []string{
|
||||
"SW_BLOCK_FRONTEND_PROTOCOL=nvme",
|
||||
"SW_BLOCK_LAUNCHER_PVC_OWNER_REF",
|
||||
"run-alpha-k8s-dynamic.sh",
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Fatalf("nvme alpha wrapper missing %q:\n%s", want, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlphaCSINode_LoadsBothFrontendKernelModules(t *testing.T) {
|
||||
body := g15dReadFile(t, "deploy", "k8s", "alpha", "csi-node.yaml")
|
||||
for _, want := range []string{"modprobe iscsi_tcp", "modprobe nvme_tcp"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Fatalf("alpha csi-node missing %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlphaScripts_OwnerRefModeInjectsBothLauncherAndCSILookupFlags(t *testing.T) {
|
||||
for _, script := range []string{"run-g15d-k8s-dynamic.sh", "run-alpha-app-demo.sh"} {
|
||||
t.Run(script, func(t *testing.T) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
csipb "github.com/container-storage-interface/spec/lib/go/csi"
|
||||
blockcsi "github.com/seaweedfs/seaweed-block/core/csi"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/internal/buildinfo"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
@@ -29,6 +30,7 @@ type flags struct {
|
||||
nodeID string
|
||||
iqnPrefix string
|
||||
pvcUIDLookup bool
|
||||
version bool
|
||||
printReadyLine bool
|
||||
}
|
||||
|
||||
@@ -40,11 +42,15 @@ func parseFlags(args []string) (flags, error) {
|
||||
fs.StringVar(&f.nodeID, "node-id", "", "CSI node ID; defaults to hostname")
|
||||
fs.StringVar(&f.iqnPrefix, "iqn-prefix", "iqn.2026-05.io.seaweedfs", "fallback IQN prefix for unstage after plugin restart")
|
||||
fs.BoolVar(&f.pvcUIDLookup, "kubernetes-pvc-uid-lookup", false, "opt-in: resolve PVC UID through the in-cluster Kubernetes API before CreateVolume is sent to blockmaster")
|
||||
fs.BoolVar(&f.version, "version", false, "print build provenance and exit")
|
||||
fs.BoolVar(&f.printReadyLine, "t0-print-ready", false, "internal test-only: emit one structured JSON ready line after listener bind")
|
||||
fs.SetOutput(os.Stderr)
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return flags{}, err
|
||||
}
|
||||
if f.version {
|
||||
return f, nil
|
||||
}
|
||||
if f.endpoint == "" {
|
||||
return flags{}, fmt.Errorf("--endpoint is required")
|
||||
}
|
||||
@@ -64,6 +70,10 @@ func main() {
|
||||
fmt.Fprintln(os.Stderr, "blockcsi:", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
if f.version {
|
||||
fmt.Println(buildinfo.Version("blockcsi"))
|
||||
return
|
||||
}
|
||||
os.Exit(run(f))
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,16 @@ func TestBlockCSI_BinaryStartsAndServesIdentity(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFlags_VersionDoesNotRequireEndpoint(t *testing.T) {
|
||||
f, err := parseFlags([]string{"--version"})
|
||||
if err != nil {
|
||||
t.Fatalf("parseFlags --version: %v", err)
|
||||
}
|
||||
if !f.version {
|
||||
t.Fatal("version flag not set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15a_BlockCSIControllerPublishUsesMasterFrontendFact(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("L2 subprocess test; -short skip")
|
||||
|
||||
@@ -81,6 +81,73 @@ func TestG15d_BlockmasterLauncherTickWritesBlockvolumeManifest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15d_BlockmasterLauncherTickRendersNVMeManifestFromLifecycleProtocol(t *testing.T) {
|
||||
h, err := master.New(master.Config{
|
||||
AuthorityStoreDir: t.TempDir(),
|
||||
LifecycleStoreDir: t.TempDir(),
|
||||
Listen: "127.0.0.1:0",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("master.New: %v", err)
|
||||
}
|
||||
h.Start()
|
||||
defer func() { _ = h.Close(context.Background()) }()
|
||||
stores := h.Lifecycle()
|
||||
if _, err := stores.Volumes.CreateVolume(lifecycle.VolumeSpec{
|
||||
VolumeID: "pvc-a",
|
||||
SizeBytes: 1 << 20,
|
||||
ReplicationFactor: 1,
|
||||
Protocol: "nvme",
|
||||
}); err != nil {
|
||||
t.Fatalf("create volume: %v", err)
|
||||
}
|
||||
if _, err := stores.Nodes.RegisterNode(lifecycle.NodeRegistration{
|
||||
ServerID: "m02",
|
||||
DataAddr: "10.0.0.2:9201",
|
||||
CtrlAddr: "10.0.0.2:9101",
|
||||
Pools: []lifecycle.StoragePool{{
|
||||
PoolID: "default",
|
||||
TotalBytes: 1 << 30,
|
||||
FreeBytes: 1 << 30,
|
||||
BlockSize: 4096,
|
||||
}},
|
||||
}); err != nil {
|
||||
t.Fatalf("register node: %v", err)
|
||||
}
|
||||
if _, err := h.RunLifecycleProductTick(); err != nil {
|
||||
t.Fatalf("product tick: %v", err)
|
||||
}
|
||||
|
||||
outDir := t.TempDir()
|
||||
if err := runLifecycleLauncherTick(h, flags{
|
||||
launcherManifestDir: outDir,
|
||||
launcherNamespace: "kube-system",
|
||||
launcherImage: "sw-block:test",
|
||||
launcherMasterAddr: "blockmaster.kube-system.svc.cluster.local:9333",
|
||||
launcherDurableRoot: "/var/lib/sw-block",
|
||||
launcherNVMePortBase: 4420,
|
||||
}); err != nil {
|
||||
t.Fatalf("launcher tick: %v", err)
|
||||
}
|
||||
raw, err := os.ReadFile(filepath.Join(outDir, "sw-blockvolume-pvc-a-r1.yaml"))
|
||||
if err != nil {
|
||||
t.Fatalf("read manifest: %v", err)
|
||||
}
|
||||
body := string(raw)
|
||||
for _, want := range []string{
|
||||
"--nvme-listen=127.0.0.1:4420",
|
||||
"--nvme-subsysnqn=nqn.2026-05.io.seaweedfs:pvc-a",
|
||||
"--nvme-ns=1",
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Fatalf("nvme manifest missing %q:\n%s", want, body)
|
||||
}
|
||||
}
|
||||
if strings.Contains(body, "--iscsi-listen=") || strings.Contains(body, "--iscsi-iqn=") {
|
||||
t.Fatalf("nvme manifest must not render iscsi args:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15e_BlockmasterLauncherTickRemovesManifestAfterVolumeDelete(t *testing.T) {
|
||||
h, err := master.New(master.Config{
|
||||
AuthorityStoreDir: t.TempDir(),
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/seaweedfs/seaweed-block/core/host/master"
|
||||
"github.com/seaweedfs/seaweed-block/core/launcher"
|
||||
"github.com/seaweedfs/seaweed-block/core/lifecycle"
|
||||
"github.com/seaweedfs/seaweed-block/internal/buildinfo"
|
||||
)
|
||||
|
||||
type flags struct {
|
||||
@@ -36,10 +37,12 @@ type flags struct {
|
||||
launcherMasterAddr string
|
||||
launcherDurableRoot string
|
||||
launcherISCSIPortBase int
|
||||
launcherNVMePortBase int
|
||||
launcherPVCOwnerRef bool
|
||||
launcherCHAPSecretName string
|
||||
launcherCHAPUserKey string
|
||||
launcherCHAPSecretKey string
|
||||
version bool
|
||||
// printReadyLine: test-only flag that emits a single
|
||||
// structured JSON line to stdout after the gRPC listener is
|
||||
// bound, so L2 subprocess tests can parse the ready event.
|
||||
@@ -67,15 +70,20 @@ func parseFlags(args []string) (flags, error) {
|
||||
fs.StringVar(&f.launcherMasterAddr, "launcher-master-addr", "", "G15d master address used in rendered blockvolume args; defaults to listener address after bind")
|
||||
fs.StringVar(&f.launcherDurableRoot, "launcher-durable-root", "/var/lib/sw-block", "G15d rendered blockvolume durable root base")
|
||||
fs.IntVar(&f.launcherISCSIPortBase, "launcher-iscsi-port-base", 3260, "G15d iSCSI port base for generated blockvolume workloads")
|
||||
fs.IntVar(&f.launcherNVMePortBase, "launcher-nvme-port-base", 4420, "G15d NVMe/TCP port base for generated blockvolume workloads")
|
||||
fs.BoolVar(&f.launcherPVCOwnerRef, "launcher-pvc-owner-ref", false, "render generated blockvolume Deployments in the source PVC namespace with a PVC ownerReference; disabled by default for alpha harness compatibility")
|
||||
fs.StringVar(&f.launcherCHAPSecretName, "launcher-iscsi-chap-secret-name", "", "optional Kubernetes Secret name used by generated blockvolume Deployments for target-side iSCSI CHAP")
|
||||
fs.StringVar(&f.launcherCHAPUserKey, "launcher-iscsi-chap-username-key", "chapUsername", "Kubernetes Secret key for generated blockvolume iSCSI CHAP username")
|
||||
fs.StringVar(&f.launcherCHAPSecretKey, "launcher-iscsi-chap-secret-key", "chapSecret", "Kubernetes Secret key for generated blockvolume iSCSI CHAP secret")
|
||||
fs.BoolVar(&f.version, "version", false, "print build provenance and exit")
|
||||
fs.BoolVar(&f.printReadyLine, "t0-print-ready", false, "internal test-only: emit one structured JSON line on stdout after listener bound")
|
||||
fs.SetOutput(os.Stderr)
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return flags{}, err
|
||||
}
|
||||
if f.version {
|
||||
return f, nil
|
||||
}
|
||||
if f.authorityStore == "" {
|
||||
return flags{}, fmt.Errorf("--authority-store is required")
|
||||
}
|
||||
@@ -88,6 +96,10 @@ func main() {
|
||||
fmt.Fprintln(os.Stderr, "blockmaster:", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
if f.version {
|
||||
fmt.Println(buildinfo.Version("blockmaster"))
|
||||
return
|
||||
}
|
||||
os.Exit(run(f))
|
||||
}
|
||||
|
||||
@@ -274,6 +286,7 @@ func runLifecycleLauncherLoop(h *master.Host, f flags, interval time.Duration) {
|
||||
func runLifecycleLauncherTick(h *master.Host, f flags) error {
|
||||
result, err := h.RunLifecycleWorkloadPlanTick(lifecycle.WorkloadPlanConfig{
|
||||
ISCSIPortBase: f.launcherISCSIPortBase,
|
||||
NVMePortBase: f.launcherNVMePortBase,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -27,6 +27,16 @@ func TestParseFlags_LifecycleStoreOptional(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFlags_VersionDoesNotRequireStores(t *testing.T) {
|
||||
f, err := parseFlags([]string{"--version"})
|
||||
if err != nil {
|
||||
t.Fatalf("parseFlags --version: %v", err)
|
||||
}
|
||||
if !f.version {
|
||||
t.Fatal("version flag not set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFlags_LifecyclePlacementSeedOptional(t *testing.T) {
|
||||
f, err := parseFlags([]string{
|
||||
"--authority-store", "authority-dir",
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
// frontend client (iSCSI/NVMe). Subprocess test verifies the wiring +
|
||||
// steady-state role split; G5-5 m01 hardware exercises the data path.
|
||||
|
||||
//go:build subprocess
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build subprocess
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build subprocess
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build subprocess
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build subprocess
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -6,6 +6,16 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestParseFlags_VersionDoesNotRequireVolumeArgs(t *testing.T) {
|
||||
got, err := parseFlags([]string{"--version"})
|
||||
if err != nil {
|
||||
t.Fatalf("parseFlags --version: %v", err)
|
||||
}
|
||||
if !got.version {
|
||||
t.Fatal("version flag not set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFlags_IscsiPortalAddrRequiresListen(t *testing.T) {
|
||||
args := append(requiredBlockvolumeArgs(),
|
||||
"--iscsi-portal-addr", "203.0.113.10:3260,1",
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
"github.com/seaweedfs/seaweed-block/core/transport"
|
||||
"github.com/seaweedfs/seaweed-block/internal/buildinfo"
|
||||
)
|
||||
|
||||
type flags struct {
|
||||
@@ -114,6 +115,7 @@ type flags struct {
|
||||
// default. sync-quorum / sync-all opt into foreground write ACK
|
||||
// gating through the durable WriteObserver seam.
|
||||
replicationAck string
|
||||
version bool
|
||||
}
|
||||
|
||||
func parseFlags(args []string) (flags, error) {
|
||||
@@ -174,10 +176,14 @@ func parseFlags(args []string) (flags, error) {
|
||||
fs.StringVar(&f.replicationAck, "replication-ack", "best-effort",
|
||||
"replication acknowledgement profile: \"best-effort\" (default), \"sync-quorum\", or \"sync-all\". "+
|
||||
"sync-* modes fail foreground writes when required replica acknowledgement is unavailable.")
|
||||
fs.BoolVar(&f.version, "version", false, "print build provenance and exit")
|
||||
fs.SetOutput(os.Stderr)
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return flags{}, err
|
||||
}
|
||||
if f.version {
|
||||
return f, nil
|
||||
}
|
||||
if f.recoveryMode != "legacy" && f.recoveryMode != "dual-lane" {
|
||||
return flags{}, fmt.Errorf("--recovery-mode=%q invalid; want \"legacy\" or \"dual-lane\"", f.recoveryMode)
|
||||
}
|
||||
@@ -317,6 +323,10 @@ func main() {
|
||||
fmt.Fprintln(os.Stderr, "blockvolume:", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
if f.version {
|
||||
fmt.Println(buildinfo.Version("blockvolume"))
|
||||
return
|
||||
}
|
||||
os.Exit(run(f))
|
||||
}
|
||||
|
||||
@@ -350,10 +360,7 @@ type nvmeReadyLine struct {
|
||||
}
|
||||
|
||||
func run(f flags) int {
|
||||
var readyCh chan adapter.AssignmentInfo
|
||||
if f.printReadyLine {
|
||||
readyCh = make(chan adapter.AssignmentInfo, 1)
|
||||
}
|
||||
readyCh := make(chan adapter.AssignmentInfo, 16)
|
||||
|
||||
h, err := volume.New(volume.Config{
|
||||
MasterAddr: f.masterAddr,
|
||||
@@ -393,24 +400,6 @@ func run(f flags) int {
|
||||
})
|
||||
}
|
||||
|
||||
if readyCh != nil {
|
||||
go func() {
|
||||
select {
|
||||
case info := <-readyCh:
|
||||
_ = json.NewEncoder(os.Stdout).Encode(readyLine{
|
||||
Component: "blockvolume",
|
||||
Phase: "assignment-received",
|
||||
VolumeID: info.VolumeID,
|
||||
ReplicaID: info.ReplicaID,
|
||||
Epoch: info.Epoch,
|
||||
EndpointVersion: info.EndpointVersion,
|
||||
})
|
||||
case <-time.After(60 * time.Second):
|
||||
// no assignment arrived — exit caller's concern
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// T3b: pick Provider per --durable-root flag. When the flag is
|
||||
// unset, fall back to memback (non-durable, legacy behavior).
|
||||
// When set, DurableProvider opens (or creates) on-disk storage
|
||||
@@ -474,6 +463,7 @@ func run(f flags) int {
|
||||
// SCSI command granularity.
|
||||
provider = memback.NewProvider(h.ProjectionView())
|
||||
}
|
||||
startReadyAssignmentLoop(readyCh, f, durableProv, os.Stdout, os.Stderr)
|
||||
|
||||
// Bind the replication stack — ReplicationVolume for outbound peer
|
||||
// fan-out (primary role) + ReplicaListener for incoming WAL traffic
|
||||
@@ -669,7 +659,7 @@ func run(f flags) int {
|
||||
dualLaneAddr, err := deriveDualLaneAddr(f.dataAddr)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: dual-lane listen addr derive:", err)
|
||||
_ = replListen.Stop
|
||||
replListen.Stop()
|
||||
_ = replVolume.Close()
|
||||
_ = durableProv.Close()
|
||||
if status != nil {
|
||||
@@ -683,7 +673,7 @@ func run(f flags) int {
|
||||
dlLn, err := net.Listen("tcp", dualLaneAddr)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: dual-lane listen:", err)
|
||||
_ = replListen.Stop
|
||||
replListen.Stop()
|
||||
_ = replVolume.Close()
|
||||
_ = durableProv.Close()
|
||||
if status != nil {
|
||||
@@ -800,11 +790,17 @@ func run(f flags) int {
|
||||
var nvmeTarget *nvme.Target
|
||||
if f.nvmeListen != "" {
|
||||
prov := provider
|
||||
var probeProvider nvme.ProbeBackendProvider
|
||||
if durableProv != nil {
|
||||
probeProvider = &durableProbeProvider{provider: durableProv}
|
||||
}
|
||||
nvmeTarget = nvme.NewTarget(nvme.TargetConfig{
|
||||
Listen: f.nvmeListen,
|
||||
SubsysNQN: f.nvmeSubsysNQN,
|
||||
VolumeID: f.volumeID,
|
||||
Provider: prov,
|
||||
Listen: f.nvmeListen,
|
||||
SubsysNQN: f.nvmeSubsysNQN,
|
||||
VolumeID: f.volumeID,
|
||||
Provider: prov,
|
||||
ProbeProvider: probeProvider,
|
||||
ControllerID: nvmeControllerIDFromReplicaID(f.replicaID),
|
||||
// Capacity from durable config (see iSCSI block above).
|
||||
// frontendBlockSize / frontendVolumeSize are 0 on memback
|
||||
// path; nvme HandlerConfig zero-value defaulting preserves
|
||||
@@ -813,6 +809,7 @@ func run(f flags) int {
|
||||
NSID: uint32(f.nvmeNS),
|
||||
BlockSize: frontendBlockSize,
|
||||
VolumeSize: frontendVolumeSize,
|
||||
ANA: newProjectionANAProvider(h.ProjectionView(), f.volumeID, f.replicaID, f.nvmeSubsysNQN),
|
||||
},
|
||||
})
|
||||
nvmeAddr, err := nvmeTarget.Start()
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"hash/fnv"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/engine"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/nvme"
|
||||
"github.com/seaweedfs/seaweed-block/core/host/volume"
|
||||
)
|
||||
|
||||
type projectionANAProvider struct {
|
||||
view *volume.AdapterProjectionView
|
||||
volumeID string
|
||||
replicaID string
|
||||
}
|
||||
|
||||
var _ nvme.ANAProvider = (*projectionANAProvider)(nil)
|
||||
|
||||
func newProjectionANAProvider(view *volume.AdapterProjectionView, volumeID, replicaID string, _ ...string) *projectionANAProvider {
|
||||
return &projectionANAProvider{
|
||||
view: view,
|
||||
volumeID: volumeID,
|
||||
replicaID: replicaID,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *projectionANAProvider) ANAState() nvme.ANAState {
|
||||
if p == nil || p.view == nil {
|
||||
return nvme.ANAInaccessible
|
||||
}
|
||||
fp := p.view.Projection()
|
||||
ep := p.view.EngineProjection()
|
||||
if fp.VolumeID != p.volumeID || fp.ReplicaID != p.replicaID {
|
||||
return nvme.ANAInaccessible
|
||||
}
|
||||
if fp.Healthy {
|
||||
return nvme.ANAOptimized
|
||||
}
|
||||
switch ep.Mode {
|
||||
case engine.ModeRecovering:
|
||||
return nvme.ANAChange
|
||||
case engine.ModeHealthy, engine.ModeIdle:
|
||||
return nvme.ANANonOptimized
|
||||
case engine.ModeDegraded:
|
||||
return nvme.ANAInaccessible
|
||||
default:
|
||||
return nvme.ANAChange
|
||||
}
|
||||
}
|
||||
|
||||
func (p *projectionANAProvider) ANAGroupID() uint32 {
|
||||
// Linux validates ANA group descriptors against Identify Controller's
|
||||
// ANAGRPMAX/NANAGRPID. The current target exposes one namespace and one ANA
|
||||
// group, so the only valid advertised group id is the dense group 1.
|
||||
return 1
|
||||
}
|
||||
|
||||
func (p *projectionANAProvider) ANAChangeCount() uint64 {
|
||||
if p == nil || p.view == nil {
|
||||
return 1
|
||||
}
|
||||
ep := p.view.EngineProjection()
|
||||
const maxUint32 = uint64(^uint32(0))
|
||||
if ep.Epoch <= maxUint32 && ep.EndpointVersion <= maxUint32 {
|
||||
count := uint64(uint32(ep.Epoch))<<32 | uint64(uint32(ep.EndpointVersion))
|
||||
if count == 0 {
|
||||
return 1
|
||||
}
|
||||
return count
|
||||
}
|
||||
var buf [16]byte
|
||||
binary.LittleEndian.PutUint64(buf[0:8], ep.Epoch)
|
||||
binary.LittleEndian.PutUint64(buf[8:16], ep.EndpointVersion)
|
||||
h := fnv.New64a()
|
||||
_, _ = h.Write(buf[:])
|
||||
count := h.Sum64()
|
||||
if count == 0 {
|
||||
return 1
|
||||
}
|
||||
return count
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/engine"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/nvme"
|
||||
"github.com/seaweedfs/seaweed-block/core/host/volume"
|
||||
)
|
||||
|
||||
func TestProjectionANAProvider_StateMapping(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
mode engine.Mode
|
||||
superseded bool
|
||||
want nvme.ANAState
|
||||
}{
|
||||
{name: "healthy", mode: engine.ModeHealthy, want: nvme.ANAOptimized},
|
||||
{name: "superseded healthy", mode: engine.ModeHealthy, superseded: true, want: nvme.ANANonOptimized},
|
||||
{name: "recovering", mode: engine.ModeRecovering, want: nvme.ANAChange},
|
||||
{name: "degraded", mode: engine.ModeDegraded, want: nvme.ANAInaccessible},
|
||||
{name: "idle", mode: engine.ModeIdle, want: nvme.ANANonOptimized},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
view := volume.NewAdapterProjectionView(
|
||||
aluaProjector{p: engine.ReplicaProjection{Mode: tt.mode, Epoch: 1, EndpointVersion: 2}},
|
||||
"v1",
|
||||
"r1",
|
||||
aluaSupersedeProbe{yes: tt.superseded},
|
||||
)
|
||||
prov := newProjectionANAProvider(view, "v1", "r1")
|
||||
if got := prov.ANAState(); got != tt.want {
|
||||
t.Fatalf("ANAState()=%#x want %#x", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectionANAProvider_GroupIDIsDenseAndWithinAdvertisedRange(t *testing.T) {
|
||||
view1 := volume.NewAdapterProjectionView(
|
||||
aluaProjector{p: engine.ReplicaProjection{Mode: engine.ModeHealthy}},
|
||||
"v1",
|
||||
"r1",
|
||||
nil,
|
||||
)
|
||||
r1a := newProjectionANAProvider(view1, "v1", "r1", "nqn.2026-05.io.seaweedfs:v1")
|
||||
r1b := newProjectionANAProvider(view1, "v1", "r1", "nqn.2026-05.io.seaweedfs:v1")
|
||||
|
||||
if got := r1a.ANAGroupID(); got != 1 {
|
||||
t.Fatalf("ANAGroupID()=%d want 1 for single-group ANA", got)
|
||||
}
|
||||
if r1a.ANAGroupID() != r1b.ANAGroupID() {
|
||||
t.Fatalf("same replica produced unstable ANA group: %d vs %d", r1a.ANAGroupID(), r1b.ANAGroupID())
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectionANAProvider_ChangeCountTracksLineage(t *testing.T) {
|
||||
view := volume.NewAdapterProjectionView(
|
||||
aluaProjector{p: engine.ReplicaProjection{Mode: engine.ModeHealthy, Epoch: 3, EndpointVersion: 7}},
|
||||
"v1",
|
||||
"r1",
|
||||
nil,
|
||||
)
|
||||
prov := newProjectionANAProvider(view, "v1", "r1")
|
||||
|
||||
want := uint64(3)<<32 | 7
|
||||
if got := prov.ANAChangeCount(); got != want {
|
||||
t.Fatalf("ANAChangeCount()=%d want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectionANAProvider_FailsClosedOnIdentityMismatch(t *testing.T) {
|
||||
view := volume.NewAdapterProjectionView(
|
||||
aluaProjector{p: engine.ReplicaProjection{Mode: engine.ModeHealthy}},
|
||||
"v1",
|
||||
"r1",
|
||||
nil,
|
||||
)
|
||||
prov := newProjectionANAProvider(view, "v1", "r2")
|
||||
if got := prov.ANAState(); got != nvme.ANAInaccessible {
|
||||
t.Fatalf("identity mismatch ANAState()=%#x want %#x", got, nvme.ANAInaccessible)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectionANAProvider_DoesNotImportControlTruthDomains(t *testing.T) {
|
||||
body, err := os.ReadFile("nvme_ana_provider.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, forbidden := range []string{"core/authority", "core/lifecycle", "core/rpc/control"} {
|
||||
if strings.Contains(string(body), forbidden) {
|
||||
t.Fatalf("projection ANA provider must not import %s", forbidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"hash/fnv"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const maxNVMeControllerID uint32 = 0xffef
|
||||
|
||||
func nvmeControllerIDFromReplicaID(replicaID string) uint16 {
|
||||
if n, ok := trailingDecimal(replicaID); ok {
|
||||
if n == 0 {
|
||||
return 1
|
||||
}
|
||||
if n > uint64(maxNVMeControllerID) {
|
||||
n = uint64(maxNVMeControllerID)
|
||||
}
|
||||
return uint16(n)
|
||||
}
|
||||
h := fnv.New32a()
|
||||
_, _ = h.Write([]byte(replicaID))
|
||||
return uint16(h.Sum32()%maxNVMeControllerID + 1)
|
||||
}
|
||||
|
||||
func trailingDecimal(s string) (uint64, bool) {
|
||||
if s == "" {
|
||||
return 0, false
|
||||
}
|
||||
start := len(s)
|
||||
for start > 0 && s[start-1] >= '0' && s[start-1] <= '9' {
|
||||
start--
|
||||
}
|
||||
if start == len(s) {
|
||||
return 0, false
|
||||
}
|
||||
n, err := strconv.ParseUint(s[start:], 10, 64)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
return n, true
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNVMeControllerIDFromReplicaID_DenseReplicaSuffixes(t *testing.T) {
|
||||
tests := map[string]uint16{
|
||||
"r1": 1,
|
||||
"r2": 2,
|
||||
"replica3": 3,
|
||||
"r0": 1,
|
||||
"r65519": uint16(maxNVMeControllerID),
|
||||
"r65520": uint16(maxNVMeControllerID),
|
||||
"r999999999999": uint16(maxNVMeControllerID),
|
||||
}
|
||||
for replicaID, want := range tests {
|
||||
if got := nvmeControllerIDFromReplicaID(replicaID); got != want {
|
||||
t.Fatalf("nvmeControllerIDFromReplicaID(%q)=%d want %d", replicaID, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNVMeControllerIDFromReplicaID_HashFallbackIsStableAndNonReserved(t *testing.T) {
|
||||
a := nvmeControllerIDFromReplicaID("east-primary")
|
||||
b := nvmeControllerIDFromReplicaID("east-primary")
|
||||
if a != b {
|
||||
t.Fatalf("hash fallback unstable: %d vs %d", a, b)
|
||||
}
|
||||
if a == 0 || a == 0xffff {
|
||||
t.Fatalf("hash fallback returned reserved CNTLID %d", a)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/adapter"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
)
|
||||
|
||||
type primaryOpenProvider interface {
|
||||
Open(context.Context, string) (frontend.Backend, error)
|
||||
}
|
||||
|
||||
func startReadyAssignmentLoop(ch <-chan adapter.AssignmentInfo, f flags, prov primaryOpenProvider, stdout, stderr io.Writer) {
|
||||
go func() {
|
||||
for info := range ch {
|
||||
handleReadyAssignment(info, f, prov, stdout, stderr)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func handleReadyAssignment(info adapter.AssignmentInfo, f flags, prov primaryOpenProvider, stdout, stderr io.Writer) {
|
||||
if f.printReadyLine && stdout != nil {
|
||||
_ = json.NewEncoder(stdout).Encode(readyLine{
|
||||
Component: "blockvolume",
|
||||
Phase: "assignment-received",
|
||||
VolumeID: info.VolumeID,
|
||||
ReplicaID: info.ReplicaID,
|
||||
Epoch: info.Epoch,
|
||||
EndpointVersion: info.EndpointVersion,
|
||||
})
|
||||
}
|
||||
if prov == nil || info.VolumeID != f.volumeID || info.ReplicaID != f.replicaID || info.Epoch == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if _, err := prov.Open(ctx, info.VolumeID); err != nil {
|
||||
if stderr != nil {
|
||||
fmt.Fprintf(stderr, "blockvolume: durable primary lineage ensure failed volume=%s replica=%s epoch=%d ev=%d: %v\n",
|
||||
info.VolumeID, info.ReplicaID, info.Epoch, info.EndpointVersion, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if stderr != nil {
|
||||
fmt.Fprintf(stderr, "blockvolume: durable primary lineage ensured volume=%s replica=%s epoch=%d ev=%d\n",
|
||||
info.VolumeID, info.ReplicaID, info.Epoch, info.EndpointVersion)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/adapter"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
)
|
||||
|
||||
type recordingPrimaryOpenProvider struct {
|
||||
volumeID string
|
||||
calls int
|
||||
err error
|
||||
}
|
||||
|
||||
func (p *recordingPrimaryOpenProvider) Open(_ context.Context, volumeID string) (frontend.Backend, error) {
|
||||
p.calls++
|
||||
p.volumeID = volumeID
|
||||
return nil, p.err
|
||||
}
|
||||
|
||||
func TestReadyAssignment_PrimaryEnsuresDurableLineageAndPrintsReadyLine(t *testing.T) {
|
||||
prov := &recordingPrimaryOpenProvider{}
|
||||
var stdout, stderr bytes.Buffer
|
||||
|
||||
handleReadyAssignment(adapter.AssignmentInfo{
|
||||
VolumeID: "v1", ReplicaID: "r2", Epoch: 2, EndpointVersion: 1,
|
||||
}, flags{
|
||||
volumeID: "v1", replicaID: "r2", printReadyLine: true,
|
||||
}, prov, &stdout, &stderr)
|
||||
|
||||
if prov.calls != 1 || prov.volumeID != "v1" {
|
||||
t.Fatalf("Open calls=%d volume=%q, want 1/v1", prov.calls, prov.volumeID)
|
||||
}
|
||||
if got := stdout.String(); !strings.Contains(got, `"phase":"assignment-received"`) ||
|
||||
!strings.Contains(got, `"epoch":2`) {
|
||||
t.Fatalf("ready line missing assignment fields: %s", got)
|
||||
}
|
||||
if got := stderr.String(); !strings.Contains(got, "durable primary lineage ensured volume=v1 replica=r2 epoch=2 ev=1") {
|
||||
t.Fatalf("ensure log mismatch: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadyAssignment_IgnoresOtherReplica(t *testing.T) {
|
||||
prov := &recordingPrimaryOpenProvider{}
|
||||
|
||||
handleReadyAssignment(adapter.AssignmentInfo{
|
||||
VolumeID: "v1", ReplicaID: "r1", Epoch: 2, EndpointVersion: 1,
|
||||
}, flags{
|
||||
volumeID: "v1", replicaID: "r2",
|
||||
}, prov, nil, nil)
|
||||
|
||||
if prov.calls != 0 {
|
||||
t.Fatalf("Open called for other replica: %d", prov.calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadyAssignment_ReportsDurableEnsureFailure(t *testing.T) {
|
||||
prov := &recordingPrimaryOpenProvider{err: errors.New("boom")}
|
||||
var stderr bytes.Buffer
|
||||
|
||||
handleReadyAssignment(adapter.AssignmentInfo{
|
||||
VolumeID: "v1", ReplicaID: "r2", Epoch: 2, EndpointVersion: 1,
|
||||
}, flags{
|
||||
volumeID: "v1", replicaID: "r2",
|
||||
}, prov, nil, &stderr)
|
||||
|
||||
if prov.calls != 1 {
|
||||
t.Fatalf("Open calls=%d, want 1", prov.calls)
|
||||
}
|
||||
if got := stderr.String(); !strings.Contains(got, "durable primary lineage ensure failed") ||
|
||||
!strings.Contains(got, "boom") {
|
||||
t.Fatalf("failure log mismatch: %s", got)
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ type options struct {
|
||||
artifactDir string
|
||||
runID string
|
||||
commit string
|
||||
params paramFlag
|
||||
list bool
|
||||
}
|
||||
|
||||
@@ -39,6 +40,7 @@ func run(args []string, stdout, stderr io.Writer) int {
|
||||
fs.StringVar(&opts.artifactDir, "artifact-dir", "", "artifact output directory")
|
||||
fs.StringVar(&opts.runID, "run-id", "", "stable run id")
|
||||
fs.StringVar(&opts.commit, "commit", "", "source commit label; defaults to git HEAD")
|
||||
fs.Var(&opts.params, "param", "scenario parameter KEY=VALUE; may be repeated")
|
||||
fs.BoolVar(&opts.list, "list", false, "list registered scenarios")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return 2
|
||||
@@ -73,6 +75,7 @@ func run(args []string, stdout, stderr io.Writer) int {
|
||||
Scenario: registration.Scenario,
|
||||
Source: testops.SourceSpec{Repo: "seaweed_block", Commit: opts.commit},
|
||||
Binaries: testops.BinarySpec{Build: false},
|
||||
ScenarioParams: mergedParams(registration.ScenarioDefaultParams, opts.params),
|
||||
ArtifactDir: opts.artifactDir,
|
||||
RunID: opts.runID,
|
||||
TimeoutSeconds: registration.DefaultTimeoutSeconds,
|
||||
@@ -98,6 +101,50 @@ func run(args []string, stdout, stderr io.Writer) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
type paramFlag map[string]string
|
||||
|
||||
func (p *paramFlag) String() string {
|
||||
if p == nil || len(*p) == 0 {
|
||||
return ""
|
||||
}
|
||||
keys := make([]string, 0, len(*p))
|
||||
for key := range *p {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
parts := make([]string, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
parts = append(parts, key+"="+(*p)[key])
|
||||
}
|
||||
return strings.Join(parts, ",")
|
||||
}
|
||||
|
||||
func (p *paramFlag) Set(value string) error {
|
||||
key, val, ok := strings.Cut(value, "=")
|
||||
if !ok || key == "" {
|
||||
return fmt.Errorf("expected KEY=VALUE")
|
||||
}
|
||||
if *p == nil {
|
||||
*p = make(map[string]string)
|
||||
}
|
||||
(*p)[key] = val
|
||||
return nil
|
||||
}
|
||||
|
||||
func mergedParams(defaults map[string]string, overrides map[string]string) map[string]string {
|
||||
if len(defaults) == 0 && len(overrides) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make(map[string]string, len(defaults)+len(overrides))
|
||||
for key, value := range defaults {
|
||||
out[key] = value
|
||||
}
|
||||
for key, value := range overrides {
|
||||
out[key] = value
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (o *options) normalize() error {
|
||||
root, err := filepath.Abs(o.repoRoot)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -21,6 +22,36 @@ func TestSWTestOpsListShowsRegisteredScenario(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSWTestOpsPassesScenarioParams(t *testing.T) {
|
||||
repoRoot := findRepoRoot(t)
|
||||
artDir := filepath.Join(t.TempDir(), "art")
|
||||
var stdout, stderr bytes.Buffer
|
||||
code := run([]string{
|
||||
"--repo-root", repoRoot,
|
||||
"--scenario", "g15b-manifest",
|
||||
"--artifact-dir", artDir,
|
||||
"--run-id", "cli-param-unit",
|
||||
"--commit", "test-commit",
|
||||
"--param", "SW_BLOCK_ALPHA_IMAGES_ENV=/tmp/pin/alpha-images.env",
|
||||
}, &stdout, &stderr)
|
||||
if code != 0 {
|
||||
t.Fatalf("exit=%d stdout=%s stderr=%s", code, stdout.String(), stderr.String())
|
||||
}
|
||||
raw, err := os.ReadFile(filepath.Join(artDir, "run-request.json"))
|
||||
if err != nil {
|
||||
t.Fatalf("read run-request: %v", err)
|
||||
}
|
||||
var req struct {
|
||||
ScenarioParams map[string]string `json:"scenario_params"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &req); err != nil {
|
||||
t.Fatalf("decode run-request: %v", err)
|
||||
}
|
||||
if got := req.ScenarioParams["SW_BLOCK_ALPHA_IMAGES_ENV"]; got != "/tmp/pin/alpha-images.env" {
|
||||
t.Fatalf("scenario param=%q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func findRepoRoot(t *testing.T) string {
|
||||
t.Helper()
|
||||
_, file, _, ok := runtime.Caller(0)
|
||||
|
||||
@@ -15,6 +15,13 @@ const (
|
||||
ProtocolNVMe Protocol = "nvme"
|
||||
)
|
||||
|
||||
func normalizeProtocol(p Protocol) Protocol {
|
||||
if p == "" {
|
||||
return ProtocolISCSI
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// PublishTarget is a read-only frontend target fact. It is deliberately
|
||||
// not authority-shaped: no epoch/endpoint_version inputs, no assignment
|
||||
// intent, no publisher call surface.
|
||||
@@ -51,6 +58,7 @@ type VolumeSpec struct {
|
||||
VolumeID string
|
||||
SizeBytes uint64
|
||||
ReplicationFactor int
|
||||
Protocol Protocol
|
||||
PVCName string
|
||||
PVCNamespace string
|
||||
PVCUID string
|
||||
@@ -59,6 +67,9 @@ type VolumeSpec struct {
|
||||
|
||||
func publishContext(t PublishTarget) map[string]string {
|
||||
ctx := map[string]string{}
|
||||
if t.Protocol != "" {
|
||||
ctx["protocol"] = string(t.Protocol)
|
||||
}
|
||||
if t.ISCSIAddr != "" && t.IQN != "" {
|
||||
ctx["iscsiAddr"] = t.ISCSIAddr
|
||||
ctx["iqn"] = t.IQN
|
||||
|
||||
@@ -3,6 +3,7 @@ package csi
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
csipb "github.com/container-storage-interface/spec/lib/go/csi"
|
||||
@@ -10,6 +11,8 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
const storageClassProtocolParameter = "sw-block.seaweedfs.com/protocol"
|
||||
|
||||
type ControllerServer struct {
|
||||
csipb.UnimplementedControllerServer
|
||||
lookup PublishTargetLookup
|
||||
@@ -40,6 +43,7 @@ func (s *ControllerServer) CreateVolume(ctx context.Context, req *csipb.CreateVo
|
||||
if err := s.resolveKubernetesMetadata(ctx, &spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("blockcsi: CreateVolume volume=%q protocol=%q replication_factor=%d pvc=%q namespace=%q", spec.VolumeID, spec.Protocol, spec.ReplicationFactor, spec.PVCName, spec.PVCNamespace)
|
||||
created, err := s.provisioner.CreateVolume(ctx, spec)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrVolumeConflict) {
|
||||
@@ -47,12 +51,14 @@ func (s *ControllerServer) CreateVolume(ctx context.Context, req *csipb.CreateVo
|
||||
}
|
||||
return nil, status.Errorf(codes.Internal, "create volume intent: %v", err)
|
||||
}
|
||||
protocol := normalizeProtocol(created.Protocol)
|
||||
return &csipb.CreateVolumeResponse{
|
||||
Volume: &csipb.Volume{
|
||||
VolumeId: created.VolumeID,
|
||||
CapacityBytes: int64(created.SizeBytes),
|
||||
VolumeContext: map[string]string{
|
||||
"replicationFactor": strconv.Itoa(created.ReplicationFactor),
|
||||
"protocol": string(protocol),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
@@ -180,10 +186,15 @@ func volumeSpecFromCreateRequest(req *csipb.CreateVolumeRequest) (VolumeSpec, er
|
||||
}
|
||||
rf = v
|
||||
}
|
||||
protocol, err := protocolFromParameters(req.GetParameters())
|
||||
if err != nil {
|
||||
return VolumeSpec{}, err
|
||||
}
|
||||
return VolumeSpec{
|
||||
VolumeID: req.GetName(),
|
||||
SizeBytes: uint64(size),
|
||||
ReplicationFactor: rf,
|
||||
Protocol: protocol,
|
||||
PVCName: req.GetParameters()["csi.storage.k8s.io/pvc/name"],
|
||||
PVCNamespace: req.GetParameters()["csi.storage.k8s.io/pvc/namespace"],
|
||||
PVCUID: req.GetParameters()["csi.storage.k8s.io/pvc/uid"],
|
||||
@@ -191,6 +202,26 @@ func volumeSpecFromCreateRequest(req *csipb.CreateVolumeRequest) (VolumeSpec, er
|
||||
}, nil
|
||||
}
|
||||
|
||||
func protocolFromParameters(params map[string]string) (Protocol, error) {
|
||||
for _, key := range []string{
|
||||
storageClassProtocolParameter,
|
||||
"protocol",
|
||||
"frontendProtocol",
|
||||
} {
|
||||
raw := params[key]
|
||||
if raw == "" {
|
||||
continue
|
||||
}
|
||||
switch Protocol(raw) {
|
||||
case ProtocolISCSI, ProtocolNVMe:
|
||||
return Protocol(raw), nil
|
||||
default:
|
||||
return "", status.Errorf(codes.InvalidArgument, "invalid protocol %q", raw)
|
||||
}
|
||||
}
|
||||
return ProtocolISCSI, nil
|
||||
}
|
||||
|
||||
func supportsVolumeCapabilities(caps []*csipb.VolumeCapability) bool {
|
||||
for _, cap := range caps {
|
||||
if cap == nil {
|
||||
|
||||
@@ -238,6 +238,9 @@ func TestG15c_ControllerCreateVolume_RecordsDesiredIntentOnly(t *testing.T) {
|
||||
if got := prov.calls[0]; got.VolumeID != "pvc-a" || got.SizeBytes != 1<<30 || got.ReplicationFactor != 2 {
|
||||
t.Fatalf("spec=%+v", got)
|
||||
}
|
||||
if got := prov.calls[0]; got.Protocol != ProtocolISCSI {
|
||||
t.Fatalf("protocol=%q want iscsi", got.Protocol)
|
||||
}
|
||||
if got := prov.calls[0]; got.PVCName != "demo-pvc" || got.PVCNamespace != "demo-ns" || got.PVCUID != "uid-123" || got.PVName != "pvc-a" {
|
||||
t.Fatalf("kubernetes metadata not preserved: %+v", got)
|
||||
}
|
||||
@@ -250,6 +253,69 @@ func TestG15c_ControllerCreateVolume_RecordsDesiredIntentOnly(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15c_ControllerCreateVolume_RecordsProtocolSelection(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
params map[string]string
|
||||
}{
|
||||
{name: "product-prefixed", params: map[string]string{storageClassProtocolParameter: "nvme"}},
|
||||
{name: "legacy-protocol", params: map[string]string{"protocol": "nvme"}},
|
||||
{name: "frontendProtocol", params: map[string]string{"frontendProtocol": "nvme"}},
|
||||
{name: "prefixed-wins", params: map[string]string{storageClassProtocolParameter: "nvme", "protocol": "iscsi"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
prov := &stubProvisioner{}
|
||||
s := NewControllerServerWithProvisioner(&stubLookup{}, prov)
|
||||
|
||||
resp, err := s.CreateVolume(context.Background(), &csipb.CreateVolumeRequest{
|
||||
Name: "pvc-a",
|
||||
CapacityRange: &csipb.CapacityRange{
|
||||
RequiredBytes: 1 << 30,
|
||||
},
|
||||
Parameters: tc.params,
|
||||
VolumeCapabilities: []*csipb.VolumeCapability{
|
||||
testVolumeCapability(),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateVolume: %v", err)
|
||||
}
|
||||
if len(prov.calls) != 1 {
|
||||
t.Fatalf("provisioner calls=%d want 1", len(prov.calls))
|
||||
}
|
||||
if got := prov.calls[0].Protocol; got != ProtocolNVMe {
|
||||
t.Fatalf("protocol=%q want nvme", got)
|
||||
}
|
||||
if got := resp.GetVolume().GetVolumeContext()["protocol"]; got != "nvme" {
|
||||
t.Fatalf("response protocol=%q want nvme", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15c_ControllerCreateVolume_RejectsInvalidProtocol(t *testing.T) {
|
||||
s := NewControllerServerWithProvisioner(&stubLookup{}, &stubProvisioner{})
|
||||
_, err := s.CreateVolume(context.Background(), &csipb.CreateVolumeRequest{
|
||||
Name: "pvc-a",
|
||||
CapacityRange: &csipb.CapacityRange{
|
||||
RequiredBytes: 1 << 30,
|
||||
},
|
||||
Parameters: map[string]string{
|
||||
"protocol": "nfs",
|
||||
},
|
||||
VolumeCapabilities: []*csipb.VolumeCapability{
|
||||
testVolumeCapability(),
|
||||
},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected invalid protocol error")
|
||||
}
|
||||
st, _ := status.FromError(err)
|
||||
if st.Code() != codes.InvalidArgument {
|
||||
t.Fatalf("code=%v want InvalidArgument", st.Code())
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15c_ControllerCreateVolume_ResolvesPVCUIDWhenConfigured(t *testing.T) {
|
||||
prov := &stubProvisioner{}
|
||||
resolver := &stubMetadataResolver{uid: "uid-from-api"}
|
||||
|
||||
@@ -2,9 +2,12 @@ package csi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -14,6 +17,7 @@ func NewDefaultNodeServer(nodeID, iqnPrefix string) *NodeServer {
|
||||
NodeID: nodeID,
|
||||
IQNPrefix: iqnPrefix,
|
||||
ISCSIUtil: &realISCSIUtil{},
|
||||
NVMeUtil: &realNVMeUtil{},
|
||||
MountUtil: &realMountUtil{},
|
||||
})
|
||||
}
|
||||
@@ -123,6 +127,146 @@ func (r *realISCSIUtil) RescanDevice(ctx context.Context, iqn string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type realNVMeUtil struct{}
|
||||
|
||||
func (r *realNVMeUtil) Connect(ctx context.Context, addr, nqn string) error {
|
||||
host, port, err := splitHostPort(addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "nvme", "connect", "-t", "tcp", "-a", host, "-s", port, "-n", nqn)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("nvme connect: %s: %w", string(out), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *realNVMeUtil) Disconnect(ctx context.Context, nqn string) error {
|
||||
cmd := exec.CommandContext(ctx, "nvme", "disconnect", "-n", nqn)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
outStr := string(out)
|
||||
if strings.Contains(outStr, "No such") || strings.Contains(outStr, "not found") {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("nvme disconnect: %s: %w", outStr, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *realNVMeUtil) IsConnected(ctx context.Context, nqn string) (bool, error) {
|
||||
doc, err := nvmeListSubsystems(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return nvmeSubsystemPathCount(doc, nqn) > 0, nil
|
||||
}
|
||||
|
||||
func (r *realNVMeUtil) GetDeviceByNQN(ctx context.Context, nqn string) (string, error) {
|
||||
deadline := time.After(30 * time.Second)
|
||||
ticker := time.NewTicker(200 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return "", ctx.Err()
|
||||
case <-deadline:
|
||||
return "", fmt.Errorf("timeout waiting for NVMe namespace for NQN %s", nqn)
|
||||
case <-ticker.C:
|
||||
devices, err := nvmeNamespaceDevices(nqn)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if len(devices) > 0 {
|
||||
return devices[0], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func splitHostPort(addr string) (string, string, error) {
|
||||
parts := strings.LastIndex(addr, ":")
|
||||
if parts <= 0 || parts == len(addr)-1 {
|
||||
return "", "", fmt.Errorf("nvme address %q must be host:port", addr)
|
||||
}
|
||||
return addr[:parts], addr[parts+1:], nil
|
||||
}
|
||||
|
||||
func nvmeListSubsystems(ctx context.Context) (any, error) {
|
||||
cmd := exec.CommandContext(ctx, "nvme", "list-subsys", "-o", "json")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("nvme list-subsys: %s: %w", string(out), err)
|
||||
}
|
||||
var doc any
|
||||
if err := json.Unmarshal(out, &doc); err != nil {
|
||||
return nil, fmt.Errorf("parse nvme list-subsys: %w", err)
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
func nvmeSubsystemPathCount(doc any, nqn string) int {
|
||||
total := 0
|
||||
for _, sub := range iterNVMeSubsystems(doc) {
|
||||
if got, _ := sub["NQN"].(string); got != nqn {
|
||||
continue
|
||||
}
|
||||
if paths, ok := sub["Paths"].([]any); ok {
|
||||
total += len(paths)
|
||||
}
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
func iterNVMeSubsystems(node any) []map[string]any {
|
||||
var out []map[string]any
|
||||
switch v := node.(type) {
|
||||
case map[string]any:
|
||||
if _, hasNQN := v["NQN"]; hasNQN {
|
||||
if _, hasPaths := v["Paths"]; hasPaths {
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
if subs, ok := v["Subsystems"].([]any); ok {
|
||||
for _, sub := range subs {
|
||||
out = append(out, iterNVMeSubsystems(sub)...)
|
||||
}
|
||||
}
|
||||
case []any:
|
||||
for _, item := range v {
|
||||
out = append(out, iterNVMeSubsystems(item)...)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func nvmeNamespaceDevices(nqn string) ([]string, error) {
|
||||
nqnFiles, err := filepath.Glob("/sys/class/nvme-subsystem/*/subsysnqn")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nsPattern := regexp.MustCompile(`^nvme[0-9]+n[0-9]+$`)
|
||||
var devices []string
|
||||
for _, nqnFile := range nqnFiles {
|
||||
raw, err := os.ReadFile(nqnFile)
|
||||
if err != nil || strings.TrimSpace(string(raw)) != nqn {
|
||||
continue
|
||||
}
|
||||
entries, err := os.ReadDir(filepath.Dir(nqnFile))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, entry := range entries {
|
||||
name := entry.Name()
|
||||
if nsPattern.MatchString(name) {
|
||||
devices = append(devices, filepath.Join("/dev", name))
|
||||
}
|
||||
}
|
||||
}
|
||||
return devices, nil
|
||||
}
|
||||
|
||||
type realMountUtil struct{}
|
||||
|
||||
func (r *realMountUtil) FormatAndMount(ctx context.Context, device, target, fsType string) error {
|
||||
|
||||
@@ -35,6 +35,7 @@ func (p *ControlLifecycleProvisioner) CreateVolume(ctx context.Context, spec Vol
|
||||
VolumeId: spec.VolumeID,
|
||||
SizeBytes: spec.SizeBytes,
|
||||
ReplicationFactor: int32(spec.ReplicationFactor),
|
||||
Protocol: string(spec.Protocol),
|
||||
PvcName: spec.PVCName,
|
||||
PvcNamespace: spec.PVCNamespace,
|
||||
PvcUid: spec.PVCUID,
|
||||
@@ -47,6 +48,7 @@ func (p *ControlLifecycleProvisioner) CreateVolume(ctx context.Context, spec Vol
|
||||
VolumeID: resp.GetVolumeId(),
|
||||
SizeBytes: resp.GetSizeBytes(),
|
||||
ReplicationFactor: int(resp.GetReplicationFactor()),
|
||||
Protocol: normalizeProtocol(Protocol(resp.GetProtocol())),
|
||||
PVCName: resp.GetPvcName(),
|
||||
PVCNamespace: resp.GetPvcNamespace(),
|
||||
PVCUID: resp.GetPvcUid(),
|
||||
|
||||
@@ -104,6 +104,7 @@ func (f *fakeLifecycleClient) CreateVolume(_ context.Context, req *control.Creat
|
||||
VolumeId: req.GetVolumeId(),
|
||||
SizeBytes: req.GetSizeBytes(),
|
||||
ReplicationFactor: req.GetReplicationFactor(),
|
||||
Protocol: req.GetProtocol(),
|
||||
PvcName: req.GetPvcName(),
|
||||
PvcNamespace: req.GetPvcNamespace(),
|
||||
PvcUid: req.GetPvcUid(),
|
||||
@@ -123,6 +124,7 @@ func TestG15c_ControlLifecycleProvisioner_CreateVolumeRoundTrip(t *testing.T) {
|
||||
VolumeID: "pvc-a",
|
||||
SizeBytes: 1 << 30,
|
||||
ReplicationFactor: 2,
|
||||
Protocol: ProtocolNVMe,
|
||||
PVCName: "demo-pvc",
|
||||
PVCNamespace: "demo-ns",
|
||||
PVCUID: "uid-123",
|
||||
@@ -134,12 +136,18 @@ func TestG15c_ControlLifecycleProvisioner_CreateVolumeRoundTrip(t *testing.T) {
|
||||
if client.createReq.GetVolumeId() != "pvc-a" || client.createReq.GetSizeBytes() != 1<<30 || client.createReq.GetReplicationFactor() != 2 {
|
||||
t.Fatalf("request=%+v", client.createReq)
|
||||
}
|
||||
if client.createReq.GetProtocol() != "nvme" {
|
||||
t.Fatalf("protocol=%q want nvme", client.createReq.GetProtocol())
|
||||
}
|
||||
if client.createReq.GetPvcName() != "demo-pvc" || client.createReq.GetPvcNamespace() != "demo-ns" || client.createReq.GetPvcUid() != "uid-123" || client.createReq.GetPvName() != "pvc-a" {
|
||||
t.Fatalf("kubernetes metadata request=%+v", client.createReq)
|
||||
}
|
||||
if got.VolumeID != "pvc-a" || got.SizeBytes != 1<<30 || got.ReplicationFactor != 2 {
|
||||
t.Fatalf("spec=%+v", got)
|
||||
}
|
||||
if got.Protocol != ProtocolNVMe {
|
||||
t.Fatalf("protocol=%q want nvme", got.Protocol)
|
||||
}
|
||||
if got.PVCName != "demo-pvc" || got.PVCNamespace != "demo-ns" || got.PVCUID != "uid-123" || got.PVName != "pvc-a" {
|
||||
t.Fatalf("kubernetes metadata spec=%+v", got)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ const (
|
||||
transportNVMe = "nvme"
|
||||
transportFile = ".transport"
|
||||
volumeFile = ".volume"
|
||||
targetFile = ".target"
|
||||
)
|
||||
|
||||
type ISCSIUtil interface {
|
||||
@@ -30,6 +31,13 @@ type ISCSIUtil interface {
|
||||
RescanDevice(ctx context.Context, iqn string) error
|
||||
}
|
||||
|
||||
type NVMeUtil interface {
|
||||
Connect(ctx context.Context, addr, nqn string) error
|
||||
Disconnect(ctx context.Context, nqn string) error
|
||||
GetDeviceByNQN(ctx context.Context, nqn string) (string, error)
|
||||
IsConnected(ctx context.Context, nqn string) (bool, error)
|
||||
}
|
||||
|
||||
type ISCSIAuth struct {
|
||||
Username string
|
||||
Secret string
|
||||
@@ -45,6 +53,8 @@ type MountUtil interface {
|
||||
type stagedVolumeInfo struct {
|
||||
iqn string
|
||||
iscsiAddr string
|
||||
nqn string
|
||||
nvmeAddr string
|
||||
transport string
|
||||
fsType string
|
||||
stagingPath string
|
||||
@@ -55,6 +65,7 @@ type NodeServer struct {
|
||||
nodeID string
|
||||
iqnPrefix string
|
||||
iscsiUtil ISCSIUtil
|
||||
nvmeUtil NVMeUtil
|
||||
mountUtil MountUtil
|
||||
logger *log.Logger
|
||||
|
||||
@@ -66,6 +77,7 @@ type NodeConfig struct {
|
||||
NodeID string
|
||||
IQNPrefix string
|
||||
ISCSIUtil ISCSIUtil
|
||||
NVMeUtil NVMeUtil
|
||||
MountUtil MountUtil
|
||||
Logger *log.Logger
|
||||
}
|
||||
@@ -79,6 +91,7 @@ func NewNodeServer(cfg NodeConfig) *NodeServer {
|
||||
nodeID: cfg.NodeID,
|
||||
iqnPrefix: cfg.IQNPrefix,
|
||||
iscsiUtil: cfg.ISCSIUtil,
|
||||
nvmeUtil: cfg.NVMeUtil,
|
||||
mountUtil: cfg.MountUtil,
|
||||
logger: lg,
|
||||
staged: make(map[string]*stagedVolumeInfo),
|
||||
@@ -97,7 +110,7 @@ func (s *NodeServer) NodeStageVolume(ctx context.Context, req *csipb.NodeStageVo
|
||||
if req.GetVolumeCapability() == nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "volume capability is required")
|
||||
}
|
||||
if s.iscsiUtil == nil || s.mountUtil == nil {
|
||||
if s.mountUtil == nil {
|
||||
return nil, status.Error(codes.FailedPrecondition, "node attach utilities are not configured")
|
||||
}
|
||||
mounted, err := s.mountUtil.IsMounted(ctx, stagingPath)
|
||||
@@ -112,6 +125,17 @@ func (s *NodeServer) NodeStageVolume(ctx context.Context, req *csipb.NodeStageVo
|
||||
return &csipb.NodeStageVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
transport := transportFromContext(req.GetPublishContext(), req.GetVolumeContext())
|
||||
if transport == transportNVMe {
|
||||
return s.stageNVMe(ctx, req, volumeID, stagingPath)
|
||||
}
|
||||
return s.stageISCSI(ctx, req, volumeID, stagingPath)
|
||||
}
|
||||
|
||||
func (s *NodeServer) stageISCSI(ctx context.Context, req *csipb.NodeStageVolumeRequest, volumeID, stagingPath string) (*csipb.NodeStageVolumeResponse, error) {
|
||||
if s.iscsiUtil == nil {
|
||||
return nil, status.Error(codes.FailedPrecondition, "iSCSI attach utility is not configured")
|
||||
}
|
||||
portal, iqn := iscsiFromContext(req.GetPublishContext())
|
||||
auth := iscsiAuthFromContext(req.GetSecrets())
|
||||
if auth == (ISCSIAuth{}) {
|
||||
@@ -183,6 +207,9 @@ func (s *NodeServer) NodeStageVolume(ctx context.Context, req *csipb.NodeStageVo
|
||||
if err := writeVolumeFile(stagingPath, volumeID); err != nil {
|
||||
s.logger.Printf("NodeStageVolume: %s: %v (non-fatal)", volumeID, err)
|
||||
}
|
||||
if err := writeTargetFile(stagingPath, iqn); err != nil {
|
||||
s.logger.Printf("NodeStageVolume: %s: %v (non-fatal)", volumeID, err)
|
||||
}
|
||||
|
||||
s.stagedMu.Lock()
|
||||
s.staged[volumeID] = &stagedVolumeInfo{
|
||||
@@ -198,6 +225,79 @@ func (s *NodeServer) NodeStageVolume(ctx context.Context, req *csipb.NodeStageVo
|
||||
return &csipb.NodeStageVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *NodeServer) stageNVMe(ctx context.Context, req *csipb.NodeStageVolumeRequest, volumeID, stagingPath string) (*csipb.NodeStageVolumeResponse, error) {
|
||||
if s.nvmeUtil == nil {
|
||||
return nil, status.Error(codes.FailedPrecondition, "NVMe attach utility is not configured")
|
||||
}
|
||||
addr, nqn := nvmeFromContext(req.GetPublishContext())
|
||||
if addr == "" || nqn == "" {
|
||||
addr, nqn = nvmeFromContext(req.GetVolumeContext())
|
||||
}
|
||||
if addr == "" || nqn == "" {
|
||||
return nil, status.Error(codes.FailedPrecondition, "no NVMe publish target")
|
||||
}
|
||||
connected, err := s.nvmeUtil.IsConnected(ctx, nqn)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "check nvme connect: %v", err)
|
||||
}
|
||||
if connected && !s.hasStagedIdentity(volumeID, stagingPath) {
|
||||
return nil, status.Errorf(codes.FailedPrecondition, "NVMe subsystem %q is already connected without staged volume identity", nqn)
|
||||
}
|
||||
connectStarted := false
|
||||
if !connected {
|
||||
if err := s.nvmeUtil.Connect(ctx, addr, nqn); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "nvme connect: %v", err)
|
||||
}
|
||||
connectStarted = true
|
||||
}
|
||||
success := false
|
||||
defer func() {
|
||||
if !success && connectStarted {
|
||||
_ = s.nvmeUtil.Disconnect(context.Background(), nqn)
|
||||
}
|
||||
}()
|
||||
|
||||
device, err := s.nvmeUtil.GetDeviceByNQN(ctx, nqn)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "get nvme device: %v", err)
|
||||
}
|
||||
if device == "" {
|
||||
return nil, status.Error(codes.Internal, "get nvme device: empty path")
|
||||
}
|
||||
if err := os.MkdirAll(stagingPath, 0o750); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "create staging dir: %v", err)
|
||||
}
|
||||
fsType := "ext4"
|
||||
if mnt := req.GetVolumeCapability().GetMount(); mnt != nil && mnt.FsType != "" {
|
||||
fsType = mnt.FsType
|
||||
}
|
||||
if err := s.mountUtil.FormatAndMount(ctx, device, stagingPath, fsType); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "format and mount: %v", err)
|
||||
}
|
||||
if err := writeTransportFile(stagingPath, transportNVMe); err != nil {
|
||||
s.logger.Printf("NodeStageVolume: %s: %v (non-fatal)", volumeID, err)
|
||||
}
|
||||
if err := writeVolumeFile(stagingPath, volumeID); err != nil {
|
||||
s.logger.Printf("NodeStageVolume: %s: %v (non-fatal)", volumeID, err)
|
||||
}
|
||||
if err := writeTargetFile(stagingPath, nqn); err != nil {
|
||||
s.logger.Printf("NodeStageVolume: %s: %v (non-fatal)", volumeID, err)
|
||||
}
|
||||
|
||||
s.stagedMu.Lock()
|
||||
s.staged[volumeID] = &stagedVolumeInfo{
|
||||
nqn: nqn,
|
||||
nvmeAddr: addr,
|
||||
transport: transportNVMe,
|
||||
fsType: fsType,
|
||||
stagingPath: stagingPath,
|
||||
}
|
||||
s.stagedMu.Unlock()
|
||||
|
||||
success = true
|
||||
return &csipb.NodeStageVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *NodeServer) NodeUnstageVolume(ctx context.Context, req *csipb.NodeUnstageVolumeRequest) (*csipb.NodeUnstageVolumeResponse, error) {
|
||||
volumeID := req.GetVolumeId()
|
||||
stagingPath := req.GetStagingTargetPath()
|
||||
@@ -228,6 +328,12 @@ func (s *NodeServer) NodeUnstageVolume(ctx context.Context, req *csipb.NodeUnsta
|
||||
if transport == "" {
|
||||
transport = transportISCSI
|
||||
}
|
||||
nqn := ""
|
||||
if info != nil {
|
||||
nqn = info.nqn
|
||||
} else if transport == transportNVMe {
|
||||
nqn = readTargetFile(stagingPath)
|
||||
}
|
||||
|
||||
var firstErr error
|
||||
if err := s.mountUtil.Unmount(ctx, stagingPath); err != nil {
|
||||
@@ -238,12 +344,18 @@ func (s *NodeServer) NodeUnstageVolume(ctx context.Context, req *csipb.NodeUnsta
|
||||
firstErr = err
|
||||
}
|
||||
}
|
||||
if transport == transportNVMe && nqn != "" && s.nvmeUtil != nil {
|
||||
if err := s.nvmeUtil.Disconnect(ctx, nqn); err != nil && firstErr == nil {
|
||||
firstErr = err
|
||||
}
|
||||
}
|
||||
if firstErr != nil {
|
||||
return nil, status.Errorf(codes.Internal, "unstage: %v", firstErr)
|
||||
}
|
||||
|
||||
_ = os.Remove(filepath.Join(stagingPath, transportFile))
|
||||
_ = os.Remove(filepath.Join(stagingPath, volumeFile))
|
||||
_ = os.Remove(filepath.Join(stagingPath, targetFile))
|
||||
s.stagedMu.Lock()
|
||||
delete(s.staged, volumeID)
|
||||
s.stagedMu.Unlock()
|
||||
@@ -337,6 +449,33 @@ func iscsiFromContext(ctx map[string]string) (portal, iqn string) {
|
||||
return ctx["iscsiAddr"], ctx["iqn"]
|
||||
}
|
||||
|
||||
func nvmeFromContext(ctx map[string]string) (addr, nqn string) {
|
||||
if ctx == nil {
|
||||
return "", ""
|
||||
}
|
||||
return ctx["nvmeAddr"], ctx["nqn"]
|
||||
}
|
||||
|
||||
func transportFromContext(contexts ...map[string]string) string {
|
||||
for _, ctx := range contexts {
|
||||
if ctx == nil {
|
||||
continue
|
||||
}
|
||||
switch ctx["protocol"] {
|
||||
case transportNVMe:
|
||||
return transportNVMe
|
||||
case transportISCSI:
|
||||
return transportISCSI
|
||||
}
|
||||
}
|
||||
for _, ctx := range contexts {
|
||||
if _, ok := ctx["nvmeAddr"]; ok && ctx["nqn"] != "" {
|
||||
return transportNVMe
|
||||
}
|
||||
}
|
||||
return transportISCSI
|
||||
}
|
||||
|
||||
func iscsiAuthFromContext(ctx map[string]string) ISCSIAuth {
|
||||
if ctx == nil {
|
||||
return ISCSIAuth{}
|
||||
@@ -396,6 +535,10 @@ func writeVolumeFile(stagingPath, volumeID string) error {
|
||||
return os.WriteFile(filepath.Join(stagingPath, volumeFile), []byte(volumeID), 0o600)
|
||||
}
|
||||
|
||||
func writeTargetFile(stagingPath, target string) error {
|
||||
return os.WriteFile(filepath.Join(stagingPath, targetFile), []byte(target), 0o600)
|
||||
}
|
||||
|
||||
func readVolumeFile(stagingPath string) string {
|
||||
b, err := os.ReadFile(filepath.Join(stagingPath, volumeFile))
|
||||
if err != nil {
|
||||
@@ -404,6 +547,14 @@ func readVolumeFile(stagingPath string) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func readTargetFile(stagingPath string) string {
|
||||
b, err := os.ReadFile(filepath.Join(stagingPath, targetFile))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func readTransportFile(stagingPath string) string {
|
||||
b, err := os.ReadFile(filepath.Join(stagingPath, transportFile))
|
||||
if err != nil {
|
||||
|
||||
@@ -77,6 +77,47 @@ type mockMountUtil struct {
|
||||
calls []string
|
||||
}
|
||||
|
||||
type mockNVMeUtil struct {
|
||||
connectErr error
|
||||
disconnectErr error
|
||||
getDeviceResult string
|
||||
getDeviceErr error
|
||||
connected map[string]bool
|
||||
calls []string
|
||||
}
|
||||
|
||||
func newMockNVMeUtil() *mockNVMeUtil {
|
||||
return &mockNVMeUtil{connected: map[string]bool{}, getDeviceResult: "/dev/nvme1n1"}
|
||||
}
|
||||
|
||||
func (m *mockNVMeUtil) Connect(_ context.Context, addr, nqn string) error {
|
||||
m.calls = append(m.calls, "connect:"+addr+":"+nqn)
|
||||
if m.connectErr != nil {
|
||||
return m.connectErr
|
||||
}
|
||||
m.connected[nqn] = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockNVMeUtil) Disconnect(_ context.Context, nqn string) error {
|
||||
m.calls = append(m.calls, "disconnect:"+nqn)
|
||||
if m.disconnectErr != nil {
|
||||
return m.disconnectErr
|
||||
}
|
||||
delete(m.connected, nqn)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockNVMeUtil) GetDeviceByNQN(_ context.Context, nqn string) (string, error) {
|
||||
m.calls = append(m.calls, "getdevice:"+nqn)
|
||||
return m.getDeviceResult, m.getDeviceErr
|
||||
}
|
||||
|
||||
func (m *mockNVMeUtil) IsConnected(_ context.Context, nqn string) (bool, error) {
|
||||
m.calls = append(m.calls, "isconnected:"+nqn)
|
||||
return m.connected[nqn], nil
|
||||
}
|
||||
|
||||
func newMockMountUtil() *mockMountUtil {
|
||||
return &mockMountUtil{mounted: map[string]bool{}}
|
||||
}
|
||||
@@ -124,6 +165,16 @@ func newTestNode(mi *mockISCSIUtil, mm *mockMountUtil) *NodeServer {
|
||||
})
|
||||
}
|
||||
|
||||
func newTestNodeWithNVMe(mi *mockISCSIUtil, mn *mockNVMeUtil, mm *mockMountUtil) *NodeServer {
|
||||
return NewNodeServer(NodeConfig{
|
||||
NodeID: "node-a",
|
||||
IQNPrefix: "iqn.2026-05.example.v3",
|
||||
ISCSIUtil: mi,
|
||||
NVMeUtil: mn,
|
||||
MountUtil: mm,
|
||||
})
|
||||
}
|
||||
|
||||
func testVolumeCapability() *csipb.VolumeCapability {
|
||||
return &csipb.VolumeCapability{
|
||||
AccessType: &csipb.VolumeCapability_Mount{
|
||||
@@ -165,6 +216,78 @@ func TestNodeStage_UsesPublishContextBeforeVolumeContext(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeStage_NVMeProtocolUsesNVMeTarget(t *testing.T) {
|
||||
mi, mn, mm := newMockISCSIUtil(), newMockNVMeUtil(), newMockMountUtil()
|
||||
ns := newTestNodeWithNVMe(mi, mn, mm)
|
||||
staging := t.TempDir()
|
||||
|
||||
_, err := ns.NodeStageVolume(context.Background(), &csipb.NodeStageVolumeRequest{
|
||||
VolumeId: "v1",
|
||||
StagingTargetPath: staging,
|
||||
VolumeCapability: testVolumeCapability(),
|
||||
PublishContext: map[string]string{
|
||||
"protocol": "nvme",
|
||||
"nvmeAddr": "127.0.0.1:4420",
|
||||
"nqn": "nqn.2026-05.io.seaweedfs:v1",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NodeStageVolume: %v", err)
|
||||
}
|
||||
want := []string{
|
||||
"isconnected:nqn.2026-05.io.seaweedfs:v1",
|
||||
"connect:127.0.0.1:4420:nqn.2026-05.io.seaweedfs:v1",
|
||||
"getdevice:nqn.2026-05.io.seaweedfs:v1",
|
||||
}
|
||||
for i, w := range want {
|
||||
if i >= len(mn.calls) || mn.calls[i] != w {
|
||||
t.Fatalf("nvme calls=%v want prefix=%v", mn.calls, want)
|
||||
}
|
||||
}
|
||||
if len(mi.calls) != 0 {
|
||||
t.Fatalf("nvme path must not call iscsi util, calls=%v", mi.calls)
|
||||
}
|
||||
if got := readTransportFile(staging); got != transportNVMe {
|
||||
t.Fatalf("transport=%q want nvme", got)
|
||||
}
|
||||
info := ns.staged["v1"]
|
||||
if info == nil || info.transport != transportNVMe || info.nqn != "nqn.2026-05.io.seaweedfs:v1" {
|
||||
t.Fatalf("staged info=%+v", info)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeStage_NVMeCleansUpConnectWhenMountFails(t *testing.T) {
|
||||
_, mn, mm := newMockISCSIUtil(), newMockNVMeUtil(), newMockMountUtil()
|
||||
mm.formatAndMountErr = errors.New("mkfs failed")
|
||||
ns := newTestNodeWithNVMe(newMockISCSIUtil(), mn, mm)
|
||||
|
||||
_, err := ns.NodeStageVolume(context.Background(), &csipb.NodeStageVolumeRequest{
|
||||
VolumeId: "v1",
|
||||
StagingTargetPath: t.TempDir(),
|
||||
VolumeCapability: testVolumeCapability(),
|
||||
PublishContext: map[string]string{
|
||||
"protocol": "nvme",
|
||||
"nvmeAddr": "127.0.0.1:4420",
|
||||
"nqn": "nqn.2026-05.io.seaweedfs:v1",
|
||||
},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected mount failure")
|
||||
}
|
||||
foundDisconnect := false
|
||||
for _, call := range mn.calls {
|
||||
if call == "disconnect:nqn.2026-05.io.seaweedfs:v1" {
|
||||
foundDisconnect = true
|
||||
}
|
||||
}
|
||||
if !foundDisconnect {
|
||||
t.Fatalf("expected cleanup disconnect, calls=%v", mn.calls)
|
||||
}
|
||||
if ns.staged["v1"] != nil {
|
||||
t.Fatalf("staged entry must not be recorded after mount failure: %+v", ns.staged["v1"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeStage_ConfiguresCHAPBeforeLogin(t *testing.T) {
|
||||
mi, mm := newMockISCSIUtil(), newMockMountUtil()
|
||||
ns := newTestNode(mi, mm)
|
||||
@@ -515,6 +638,70 @@ func TestNodeUnstage_NotMountedStillLogsOutAndCleansState(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeUnstage_NVMeDisconnectsAndCleansState(t *testing.T) {
|
||||
mn, mm := newMockNVMeUtil(), newMockMountUtil()
|
||||
ns := newTestNodeWithNVMe(newMockISCSIUtil(), mn, mm)
|
||||
staging := t.TempDir()
|
||||
if err := writeTransportFile(staging, transportNVMe); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ns.staged["v1"] = &stagedVolumeInfo{
|
||||
nqn: "nqn.2026-05.io.seaweedfs:v1",
|
||||
nvmeAddr: "127.0.0.1:4420",
|
||||
transport: transportNVMe,
|
||||
stagingPath: staging,
|
||||
}
|
||||
|
||||
_, err := ns.NodeUnstageVolume(context.Background(), &csipb.NodeUnstageVolumeRequest{
|
||||
VolumeId: "v1",
|
||||
StagingTargetPath: staging,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NodeUnstageVolume: %v", err)
|
||||
}
|
||||
foundDisconnect := false
|
||||
for _, call := range mn.calls {
|
||||
if call == "disconnect:nqn.2026-05.io.seaweedfs:v1" {
|
||||
foundDisconnect = true
|
||||
}
|
||||
}
|
||||
if !foundDisconnect {
|
||||
t.Fatalf("expected nvme disconnect, calls=%v", mn.calls)
|
||||
}
|
||||
if ns.staged["v1"] != nil {
|
||||
t.Fatalf("staged entry should be removed after unstage: %+v", ns.staged["v1"])
|
||||
}
|
||||
if got := readTransportFile(staging); got != "" {
|
||||
t.Fatalf("transport file should be removed, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeUnstage_NVMeRestartFallbackUsesTargetFile(t *testing.T) {
|
||||
mn, mm := newMockNVMeUtil(), newMockMountUtil()
|
||||
ns := newTestNodeWithNVMe(newMockISCSIUtil(), mn, mm)
|
||||
staging := t.TempDir()
|
||||
if err := writeTransportFile(staging, transportNVMe); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := writeTargetFile(staging, "nqn.2026-05.io.seaweedfs:v1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err := ns.NodeUnstageVolume(context.Background(), &csipb.NodeUnstageVolumeRequest{
|
||||
VolumeId: "v1",
|
||||
StagingTargetPath: staging,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NodeUnstageVolume: %v", err)
|
||||
}
|
||||
if len(mn.calls) != 1 || mn.calls[0] != "disconnect:nqn.2026-05.io.seaweedfs:v1" {
|
||||
t.Fatalf("nvme calls=%v", mn.calls)
|
||||
}
|
||||
if got := readTargetFile(staging); got != "" {
|
||||
t.Fatalf("target file should be removed, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeUnstage_RestartFallbackUsesTransportFileAndDerivedIQN(t *testing.T) {
|
||||
mi, mm := newMockISCSIUtil(), newMockMountUtil()
|
||||
ns := newTestNode(mi, mm)
|
||||
|
||||
@@ -522,14 +522,25 @@ func (s *Session) sendSCSIResponse(req *PDU, r SCSIResult) error {
|
||||
p.SetStatSN(s.statSN)
|
||||
p.SetExpCmdSN(req.CmdSN() + 1)
|
||||
p.SetMaxCmdSN(req.CmdSN() + 32)
|
||||
// For CHECK CONDITION responses, sense data rides in the
|
||||
// data segment as fixed-format sense (18 bytes).
|
||||
// iSCSI SCSI Response data segment carries a two-byte
|
||||
// SenseLength followed by fixed-format sense data (RFC 7143
|
||||
// §10.4.7). REQUEST SENSE still returns raw SPC sense bytes;
|
||||
// only the iSCSI response wrapper gets this prefix.
|
||||
if r.Status == StatusCheckCondition {
|
||||
p.DataSegment = buildSenseData(r.SenseKey, r.ASC, r.ASCQ)
|
||||
p.DataSegment = buildSCSIResponseSenseSegment(r.SenseKey, r.ASC, r.ASCQ)
|
||||
}
|
||||
return WritePDU(s.conn, p)
|
||||
}
|
||||
|
||||
func buildSCSIResponseSenseSegment(key, asc, ascq uint8) []byte {
|
||||
sense := buildSenseData(key, asc, ascq)
|
||||
out := make([]byte, 2+len(sense))
|
||||
out[0] = byte(len(sense) >> 8)
|
||||
out[1] = byte(len(sense))
|
||||
copy(out[2:], sense)
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Session) handleLogout(req *PDU) error {
|
||||
resp := &PDU{}
|
||||
resp.SetOpcode(OpLogoutResp)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Ownership: sw regression tests for architect review 2026-04-21
|
||||
// ckpt 10 Medium findings:
|
||||
//
|
||||
// #1 EDTL/CDB consistency check MUST run before the target
|
||||
// allocates memory or issues R2T (was: alloc edtl bytes
|
||||
// upfront, then discover mismatch only when SCSI handler
|
||||
// validated CDB).
|
||||
// #1 EDTL/CDB consistency check MUST run before the target
|
||||
// allocates memory or issues R2T (was: alloc edtl bytes
|
||||
// upfront, then discover mismatch only when SCSI handler
|
||||
// validated CDB).
|
||||
//
|
||||
// #2 R2T-solicited Data-Out must reject TTT=0xFFFFFFFF
|
||||
// (unsolicited marker) — previously accepted, weakening
|
||||
// the InitialR2T=Yes negotiated discipline.
|
||||
// #2 R2T-solicited Data-Out must reject TTT=0xFFFFFFFF
|
||||
// (unsolicited marker) — previously accepted, weakening
|
||||
// the InitialR2T=Yes negotiated discipline.
|
||||
//
|
||||
// Both tests drive a real in-process target via the existing
|
||||
// Go test client; the second bypasses the normal test client's
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
// times Write was invoked. Used to confirm a pre-flight EDTL
|
||||
// rejection NEVER reaches the backend.
|
||||
type countingBackend struct {
|
||||
inner *testback.RecordingBackend
|
||||
inner *testback.RecordingBackend
|
||||
writes atomic.Int32
|
||||
}
|
||||
|
||||
@@ -127,12 +127,19 @@ func TestT2Route_ISCSI_LargeWrite_EDTLCDBMismatch_RejectsWithoutAllocating(t *te
|
||||
if resp.SCSIStatusByte() != iscsi.StatusCheckCondition {
|
||||
t.Fatalf("status=0x%02x want CHECK CONDITION", resp.SCSIStatusByte())
|
||||
}
|
||||
// Sense data rides in the data segment as fixed-format.
|
||||
if len(resp.DataSegment) < 14 {
|
||||
// iSCSI SCSI-Response prefixes fixed-format sense with a
|
||||
// two-byte SenseLength. Linux validates this wrapper before
|
||||
// passing sense up to SCSI.
|
||||
if len(resp.DataSegment) < 16 {
|
||||
t.Fatalf("response missing sense data: len=%d", len(resp.DataSegment))
|
||||
}
|
||||
senseKey := resp.DataSegment[2] & 0x0f
|
||||
asc := resp.DataSegment[12]
|
||||
senseLen := int(resp.DataSegment[0])<<8 | int(resp.DataSegment[1])
|
||||
if senseLen != 18 || len(resp.DataSegment) != 2+senseLen {
|
||||
t.Fatalf("sense wrapper length=%d dataSegmentLen=%d, want 18/20", senseLen, len(resp.DataSegment))
|
||||
}
|
||||
sense := resp.DataSegment[2:]
|
||||
senseKey := sense[2] & 0x0f
|
||||
asc := sense[12]
|
||||
if senseKey != iscsi.SenseIllegalRequest {
|
||||
t.Fatalf("sense key=0x%02x want IllegalRequest", senseKey)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package nvme
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
const (
|
||||
anaLogSize = 40
|
||||
smartLogSize = 512
|
||||
)
|
||||
|
||||
// handleGetLogPage services admin opcode 0x02.
|
||||
//
|
||||
// P3 initially implements only ANA log page 0x0c. Identify still does not
|
||||
// advertise ANA until the host-visible fields are flipped in the later P3-C
|
||||
// slice; serving the page first lets us test the payload without letting Linux
|
||||
// multipath depend on it prematurely.
|
||||
func (s *Session) handleGetLogPage(req *Request) error {
|
||||
cmd := &req.capsule
|
||||
lid := uint8(cmd.D10 & 0xFF)
|
||||
numdl := (cmd.D10 >> 16) & 0xFFFF
|
||||
numdu := cmd.D11 & 0xFFFF
|
||||
numd := (numdu << 16) | numdl
|
||||
length := (numd + 1) * 4
|
||||
lpo := uint64(cmd.D12) | uint64(cmd.D13)<<32
|
||||
|
||||
switch lid {
|
||||
case logPageSMART:
|
||||
return s.handleSMARTLogPage(req, length, lpo)
|
||||
case logPageANA:
|
||||
return s.handleANALogPage(req, length, lpo)
|
||||
default:
|
||||
req.resp.Status = MakeStatusField(SCTGeneric, SCInvalidField, true)
|
||||
s.enqueueResponse(&response{resp: req.resp})
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) handleSMARTLogPage(req *Request, length uint32, offset uint64) error {
|
||||
if length > smartLogSize {
|
||||
length = smartLogSize
|
||||
}
|
||||
if length == 0 {
|
||||
length = 4
|
||||
}
|
||||
|
||||
buf := make([]byte, smartLogSize)
|
||||
// Minimal SMART / Health Information log. Linux fetches this during
|
||||
// controller bring-up; returning success avoids a slow retry path while
|
||||
// keeping all health counters conservative.
|
||||
binary.LittleEndian.PutUint16(buf[1:], 300) // temperature: 300 K
|
||||
buf[3] = 100 // available spare
|
||||
buf[4] = 10 // available spare threshold
|
||||
s.enqueueLogPageResponse(req, buf, length, offset)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Session) handleANALogPage(req *Request, length uint32, offset uint64) error {
|
||||
prov := s.handler.ANAProvider()
|
||||
if prov == nil {
|
||||
req.resp.Status = MakeStatusField(SCTGeneric, SCInvalidField, true)
|
||||
s.enqueueResponse(&response{resp: req.resp})
|
||||
return nil
|
||||
}
|
||||
if length > anaLogSize {
|
||||
length = anaLogSize
|
||||
}
|
||||
if length == 0 {
|
||||
length = 4
|
||||
}
|
||||
|
||||
buf := make([]byte, anaLogSize)
|
||||
changeCount := prov.ANAChangeCount()
|
||||
groupID := prov.ANAGroupID()
|
||||
if groupID == 0 {
|
||||
groupID = 1
|
||||
}
|
||||
|
||||
binary.LittleEndian.PutUint64(buf[0:], changeCount)
|
||||
binary.LittleEndian.PutUint16(buf[8:], 1) // NGRPS
|
||||
|
||||
// Single ANA group descriptor:
|
||||
// [16:20] ANAGRPID
|
||||
// [20:24] NNSID
|
||||
// [24:32] group change count
|
||||
// [32] ANA state
|
||||
// [36:40] NSID
|
||||
binary.LittleEndian.PutUint32(buf[16:], groupID)
|
||||
binary.LittleEndian.PutUint32(buf[20:], 1)
|
||||
binary.LittleEndian.PutUint64(buf[24:], changeCount)
|
||||
buf[32] = byte(prov.ANAState())
|
||||
binary.LittleEndian.PutUint32(buf[36:], s.handler.NSID())
|
||||
|
||||
s.enqueueLogPageResponse(req, buf, length, offset)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Session) enqueueLogPageResponse(req *Request, buf []byte, length uint32, offset uint64) {
|
||||
if offset >= uint64(len(buf)) {
|
||||
req.resp.Status = MakeStatusField(SCTGeneric, SCInvalidField, true)
|
||||
s.enqueueResponse(&response{resp: req.resp})
|
||||
return
|
||||
}
|
||||
end := offset + uint64(length)
|
||||
if end > uint64(len(buf)) {
|
||||
end = uint64(len(buf))
|
||||
}
|
||||
s.enqueueResponse(&response{resp: req.resp, c2hData: buf[offset:end]})
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package nvme_test
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/nvme"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/testback"
|
||||
)
|
||||
|
||||
type testANAProvider struct {
|
||||
state nvme.ANAState
|
||||
groupID uint32
|
||||
changeCount uint64
|
||||
}
|
||||
|
||||
func (p testANAProvider) ANAState() nvme.ANAState { return p.state }
|
||||
func (p testANAProvider) ANAGroupID() uint32 { return p.groupID }
|
||||
func (p testANAProvider) ANAChangeCount() uint64 { return p.changeCount }
|
||||
|
||||
func newANAHarness(t *testing.T, p nvme.ANAProvider) (*nvme.Target, *nvmeClient) {
|
||||
t.Helper()
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{
|
||||
VolumeID: "v1", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1,
|
||||
})
|
||||
prov := testback.NewStaticProvider(rec)
|
||||
tg := nvme.NewTarget(nvme.TargetConfig{
|
||||
Listen: "127.0.0.1:0",
|
||||
SubsysNQN: "nqn.2026-04.example.v3:subsys",
|
||||
VolumeID: "v1",
|
||||
Provider: prov,
|
||||
Handler: nvme.HandlerConfig{
|
||||
ANA: p,
|
||||
},
|
||||
})
|
||||
addr, err := tg.Start()
|
||||
if err != nil {
|
||||
t.Fatalf("Target.Start: %v", err)
|
||||
}
|
||||
cli := dialAndConnectOpts(t, addr, connectOptions{SkipIOQueue: true})
|
||||
t.Cleanup(func() {
|
||||
cli.close()
|
||||
_ = tg.Close()
|
||||
})
|
||||
return tg, cli
|
||||
}
|
||||
|
||||
func TestNVMeANALogPage_NoProviderRejected(t *testing.T) {
|
||||
_, cli := newANAHarness(t, nil)
|
||||
status, data := cli.adminGetLogPage(t, 0x0C, 9)
|
||||
if status == 0 {
|
||||
t.Fatal("ANA log page succeeded without ANA provider")
|
||||
}
|
||||
if len(data) != 0 {
|
||||
t.Fatalf("ANA no-provider returned %d bytes, want none", len(data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestNVMeSMARTLogPage_ReturnsMinimalHealthLog(t *testing.T) {
|
||||
_, cli := newANAHarness(t, nil)
|
||||
status, data := cli.adminGetLogPage(t, 0x02, 127) // 128 dwords = 512 bytes.
|
||||
expectStatusSuccess(t, status, "GetLogPage(SMART)")
|
||||
if len(data) != 512 {
|
||||
t.Fatalf("SMART log len=%d want 512", len(data))
|
||||
}
|
||||
if got := data[0]; got != 0 {
|
||||
t.Fatalf("SMART critical_warning=0x%02x want 0", got)
|
||||
}
|
||||
if got := binary.LittleEndian.Uint16(data[1:3]); got != 300 {
|
||||
t.Fatalf("SMART temperature=%d want 300K", got)
|
||||
}
|
||||
if got := data[3]; got != 100 {
|
||||
t.Fatalf("SMART available_spare=%d want 100", got)
|
||||
}
|
||||
if got := data[4]; got != 10 {
|
||||
t.Fatalf("SMART spare_threshold=%d want 10", got)
|
||||
}
|
||||
if got := data[5]; got != 0 {
|
||||
t.Fatalf("SMART percentage_used=%d want 0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNVMeANALogPage_ReportsProviderState(t *testing.T) {
|
||||
_, cli := newANAHarness(t, testANAProvider{
|
||||
state: nvme.ANANonOptimized,
|
||||
groupID: 1,
|
||||
changeCount: 42,
|
||||
})
|
||||
status, data := cli.adminGetLogPage(t, 0x0C, 9) // 10 dwords = 40 bytes.
|
||||
expectStatusSuccess(t, status, "GetLogPage(ANA)")
|
||||
if len(data) != 40 {
|
||||
t.Fatalf("ANA log len=%d want 40", len(data))
|
||||
}
|
||||
if got := binary.LittleEndian.Uint64(data[0:8]); got != 42 {
|
||||
t.Fatalf("ANA CHGCNT=%d want 42", got)
|
||||
}
|
||||
if got := binary.LittleEndian.Uint16(data[8:10]); got != 1 {
|
||||
t.Fatalf("ANA NGRPS=%d want 1", got)
|
||||
}
|
||||
if got := binary.LittleEndian.Uint32(data[16:20]); got != 1 {
|
||||
t.Fatalf("ANA group id=%d want 1", got)
|
||||
}
|
||||
if got := binary.LittleEndian.Uint32(data[20:24]); got != 1 {
|
||||
t.Fatalf("ANA NNSID=%d want 1", got)
|
||||
}
|
||||
if got := binary.LittleEndian.Uint64(data[24:32]); got != 42 {
|
||||
t.Fatalf("ANA group CHGCNT=%d want 42", got)
|
||||
}
|
||||
if got := data[32]; got != byte(nvme.ANANonOptimized) {
|
||||
t.Fatalf("ANA state=0x%02x want 0x%02x", got, byte(nvme.ANANonOptimized))
|
||||
}
|
||||
if got := binary.LittleEndian.Uint32(data[36:40]); got != 1 {
|
||||
t.Fatalf("ANA NSID=%d want 1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNVMeANAIdentifyAndLogGroupIDsAreConsistent(t *testing.T) {
|
||||
_, cli := newANAHarness(t, testANAProvider{
|
||||
state: nvme.ANAOptimized,
|
||||
groupID: 1,
|
||||
changeCount: 42,
|
||||
})
|
||||
|
||||
status, ctrl := cli.adminIdentify(t, 0x01, 0)
|
||||
expectStatusSuccess(t, status, "Identify Controller")
|
||||
status, ns := cli.adminIdentify(t, 0x00, 1)
|
||||
expectStatusSuccess(t, status, "Identify Namespace")
|
||||
status, logData := cli.adminGetLogPage(t, 0x0C, 9)
|
||||
expectStatusSuccess(t, status, "GetLogPage(ANA)")
|
||||
|
||||
anaGrpMax := binary.LittleEndian.Uint32(ctrl[344:348])
|
||||
anaGrpCount := binary.LittleEndian.Uint32(ctrl[348:352])
|
||||
nsGroupID := binary.LittleEndian.Uint32(ns[92:96])
|
||||
logGroupID := binary.LittleEndian.Uint32(logData[16:20])
|
||||
|
||||
if anaGrpMax != 1 || anaGrpCount != 1 {
|
||||
t.Fatalf("Identify ANA limits mismatch: ANAGRPMAX=%d NANAGRPID=%d want 1/1", anaGrpMax, anaGrpCount)
|
||||
}
|
||||
if logGroupID == 0 || logGroupID > anaGrpMax {
|
||||
t.Fatalf("ANA log group id=%d outside advertised range 1..%d", logGroupID, anaGrpMax)
|
||||
}
|
||||
if nsGroupID != logGroupID {
|
||||
t.Fatalf("Identify NS ANAGRPID=%d does not match ANA log group id=%d", nsGroupID, logGroupID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNVMeANALogPage_TruncatesToRequestedLength(t *testing.T) {
|
||||
_, cli := newANAHarness(t, testANAProvider{
|
||||
state: nvme.ANAOptimized,
|
||||
groupID: 1,
|
||||
changeCount: 9,
|
||||
})
|
||||
status, data := cli.adminGetLogPage(t, 0x0C, 0) // 1 dword = 4 bytes.
|
||||
expectStatusSuccess(t, status, "GetLogPage(ANA truncated)")
|
||||
if len(data) != 4 {
|
||||
t.Fatalf("ANA truncated len=%d want 4", len(data))
|
||||
}
|
||||
if got := binary.LittleEndian.Uint32(data); got != 9 {
|
||||
t.Fatalf("truncated CHGCNT low32=%d want 9", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNVMeGetLogPage_UnknownLIDRejected(t *testing.T) {
|
||||
_, cli := newANAHarness(t, testANAProvider{
|
||||
state: nvme.ANAOptimized,
|
||||
groupID: 1,
|
||||
changeCount: 1,
|
||||
})
|
||||
status, data := cli.adminGetLogPage(t, 0x7F, 0)
|
||||
if status == 0 {
|
||||
t.Fatal("unknown log page succeeded")
|
||||
}
|
||||
if len(data) != 0 {
|
||||
t.Fatalf("unknown log page returned %d bytes, want none", len(data))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package nvme
|
||||
|
||||
// ANAState is the NVMe Asymmetric Namespace Access state reported in the ANA
|
||||
// log page. Values follow NVMe 1.3 ANA state encoding.
|
||||
type ANAState uint8
|
||||
|
||||
const (
|
||||
ANAOptimized ANAState = 0x01
|
||||
ANANonOptimized ANAState = 0x02
|
||||
ANAInaccessible ANAState = 0x03
|
||||
ANAPersistentLoss ANAState = 0x04
|
||||
ANAChange ANAState = 0x0F
|
||||
)
|
||||
|
||||
// ANAProvider supplies host-visible path state. It is deliberately small:
|
||||
// protocol code reports the facts, but authority and replica readiness stay in
|
||||
// product state outside the NVMe package.
|
||||
type ANAProvider interface {
|
||||
ANAState() ANAState
|
||||
ANAGroupID() uint32
|
||||
ANAChangeCount() uint64
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
// Alive/AER in 11b) go here.
|
||||
// - ioConn (QID>0): IO Connect cites the CNTLID; Read/
|
||||
// Write/Flush go here.
|
||||
//
|
||||
// Tests that only need IO round-trip see the existing API
|
||||
// (writeCmd/readCmd dispatch through ioConn); tests that
|
||||
// exercise admin opcodes use adminCmd.
|
||||
@@ -29,13 +30,13 @@ import (
|
||||
type nvmeClient struct {
|
||||
t *testing.T
|
||||
|
||||
admin net.Conn
|
||||
adminR *nvme.Reader
|
||||
adminW *nvme.Writer
|
||||
admin net.Conn
|
||||
adminR *nvme.Reader
|
||||
adminW *nvme.Writer
|
||||
|
||||
io net.Conn
|
||||
ioR *nvme.Reader
|
||||
ioW *nvme.Writer
|
||||
io net.Conn
|
||||
ioR *nvme.Reader
|
||||
ioW *nvme.Writer
|
||||
|
||||
cid atomic.Uint32 // command identifier counter (shared across queues)
|
||||
cntlID uint16 // assigned by admin Connect; echoed by IO Connect
|
||||
@@ -364,6 +365,47 @@ func (c *nvmeClient) adminIdentify(t *testing.T, cns uint8, nsid uint32) (uint16
|
||||
return resp.Status, data
|
||||
}
|
||||
|
||||
// adminGetLogPage issues Get Log Page and returns C2H data + status.
|
||||
// numd is the zero-based DWORD count encoded into CDW10/11.
|
||||
func (c *nvmeClient) adminGetLogPage(t *testing.T, lid uint8, numd uint32) (uint16, []byte) {
|
||||
t.Helper()
|
||||
cid := uint16(c.cid.Add(1))
|
||||
cmd := nvme.CapsuleCommand{
|
||||
OpCode: 0x02, // adminGetLogPage
|
||||
CID: cid,
|
||||
D10: uint32(lid) | ((numd & 0xFFFF) << 16),
|
||||
D11: (numd >> 16) & 0xFFFF,
|
||||
}
|
||||
if err := c.adminW.SendHeaderOnly(0x4, &cmd, 64); err != nil {
|
||||
t.Fatalf("send GetLogPage: %v", err)
|
||||
}
|
||||
ch, err := c.adminR.Dequeue()
|
||||
if err != nil {
|
||||
t.Fatalf("read GetLogPage resp hdr: %v", err)
|
||||
}
|
||||
if ch.Type == 0x5 {
|
||||
var resp nvme.CapsuleResponse
|
||||
_ = c.adminR.Receive(&resp)
|
||||
return resp.Status, nil
|
||||
}
|
||||
if ch.Type != 0x7 {
|
||||
t.Fatalf("expected C2HData, got 0x%x", ch.Type)
|
||||
}
|
||||
var dh nvme.C2HDataHeader
|
||||
if err := c.adminR.Receive(&dh); err != nil {
|
||||
t.Fatalf("recv GetLogPage C2HData: %v", err)
|
||||
}
|
||||
data := make([]byte, c.adminR.Length())
|
||||
if err := c.adminR.ReceiveData(data); err != nil {
|
||||
t.Fatalf("read GetLogPage data: %v", err)
|
||||
}
|
||||
resp := recvCapsuleResp(t, c.adminR)
|
||||
if resp.CID != cid {
|
||||
t.Fatalf("GetLogPage resp CID=%d want %d", resp.CID, cid)
|
||||
}
|
||||
return resp.Status, data
|
||||
}
|
||||
|
||||
// adminPropertyGet issues a Fabric PropertyGet for the given
|
||||
// register offset. size8=true for CAP (8-byte), false for
|
||||
// VS/CC/CSTS (4-byte). Returns (status, value).
|
||||
|
||||
@@ -7,10 +7,10 @@ package nvme
|
||||
// deep-read findings (D1–D11, 2026-04-22):
|
||||
//
|
||||
// D1 Serial "SWF00001" stub → derived from VolumeID (R1, §3.3 N1)
|
||||
// D2 CMIC=0x08 / ANACAP=0x08 / ANAGRPMAX=1 / NANAGRPID=1 /
|
||||
// Identify NS ANAGRPID=1 → ALL ZERO in 11a/11b per QA
|
||||
// finding #3 (Get Log Page ANA is 11c-conditional; advertising
|
||||
// ANA before that commit ships would violate §6 stop-rule #4)
|
||||
// D2 CMIC=0x0a / ANACAP / ANAGRPMAX=1 / NANAGRPID=1 /
|
||||
// Identify NS NMIC.SHARED + ANAGRPID → conditional on ANAProvider.
|
||||
// Without a provider these fields remain zero so "advertised ==
|
||||
// implemented" stays true.
|
||||
// D3 ONCS=0x0C (WriteZeros + DSM) → 0 (neither opcode implemented)
|
||||
// D4 Identify NS NSFEAT=0x01 (thin-prov / Trim advertised) → 0
|
||||
// (Dataset Management not in T2 scope)
|
||||
@@ -101,10 +101,14 @@ func (s *Session) buildIdentifyController() []byte {
|
||||
|
||||
// bytes 73-75: IEEE OUI (0 — not a registered manufacturer)
|
||||
|
||||
ana := s.handler.ANAProvider()
|
||||
// byte 76: CMIC (Controller Multi-Path I/O Capabilities).
|
||||
// D2 fix: V2 sets bit 3 (ANA reporting supported); we set 0
|
||||
// because ANA log is 11c-conditional per QA finding #3.
|
||||
buf[76] = 0x00
|
||||
// Bit 1 advertises multi-controller support and bit 3 advertises ANA
|
||||
// reporting. Linux native multipath rejects a second controller under the
|
||||
// same SubNQN unless bit 1 is set.
|
||||
if ana != nil {
|
||||
buf[76] = 0x0a
|
||||
}
|
||||
|
||||
// byte 77: MDTS (Maximum Data Transfer Size, 2^MDTS × min page).
|
||||
// MDTS=3 → 32 KiB with 4 KiB min-page. Matches our
|
||||
@@ -173,14 +177,18 @@ func (s *Session) buildIdentifyController() []byte {
|
||||
binary.LittleEndian.PutUint16(buf[320:], 1)
|
||||
|
||||
// byte 341: ANACAP (ANA Capabilities).
|
||||
// D2 fix: V2 sets bit 3 (Optimized state reported); we zero
|
||||
// the whole byte until 11c ANA log ships.
|
||||
buf[341] = 0x00
|
||||
// Advertise the states V3 can report through ANAProvider:
|
||||
// optimized, non-optimized, inaccessible, and ANA change.
|
||||
// Persistent loss stays off until a product state maps to it.
|
||||
if ana != nil {
|
||||
buf[341] = 0x17
|
||||
}
|
||||
|
||||
// bytes 344-347: ANAGRPMAX. D2: 0.
|
||||
binary.LittleEndian.PutUint32(buf[344:], 0)
|
||||
// bytes 348-351: NANAGRPID. D2: 0.
|
||||
binary.LittleEndian.PutUint32(buf[348:], 0)
|
||||
// bytes 344-347: ANAGRPMAX; bytes 348-351: NANAGRPID.
|
||||
if ana != nil {
|
||||
binary.LittleEndian.PutUint32(buf[344:], 1)
|
||||
binary.LittleEndian.PutUint32(buf[348:], 1)
|
||||
}
|
||||
|
||||
// byte 512: SQES (Submission Queue Entry Size).
|
||||
// Low nibble = min power-of-2 (6 = 64 B); high nibble = max.
|
||||
@@ -297,13 +305,24 @@ func (s *Session) buildIdentifyNamespace(nsid uint32) []byte {
|
||||
// zeros). Deallocate not implemented → 0.
|
||||
buf[28] = 0x00
|
||||
|
||||
ana := s.handler.ANAProvider()
|
||||
// byte 30: NMIC (Namespace Multi-path I/O Capabilities).
|
||||
// 0 = single controller. T2 single-session-per-subsystem.
|
||||
buf[30] = 0
|
||||
// Bit 0 marks NSID=1 as shareable across controllers. Linux native
|
||||
// multipath rejects a second controller exposing the same NSID unless
|
||||
// this bit is set.
|
||||
if ana != nil {
|
||||
buf[30] = 0x01
|
||||
}
|
||||
|
||||
// bytes 92-95: ANAGRPID. D2 fix: V2 sets 1; we zero until
|
||||
// ANA log ships.
|
||||
binary.LittleEndian.PutUint32(buf[92:], 0)
|
||||
// bytes 92-95: ANAGRPID. Non-zero only when ANA log support
|
||||
// is wired; otherwise the namespace must not advertise ANA.
|
||||
if ana != nil {
|
||||
groupID := ana.ANAGroupID()
|
||||
if groupID == 0 {
|
||||
groupID = 1
|
||||
}
|
||||
binary.LittleEndian.PutUint32(buf[92:], groupID)
|
||||
}
|
||||
|
||||
// bytes 104-119: NGUID (16 bytes). R1: per-(SubsysNQN,
|
||||
// VolumeID) deterministic derivation.
|
||||
@@ -400,13 +419,14 @@ func (s *Session) ctrlVolumeID() string {
|
||||
// nguidFromIdentity builds a 16-byte NGUID from SubsysNQN +
|
||||
// VolumeID. Algorithm (R1, port plan §3.3 N1):
|
||||
//
|
||||
// NGUID = sha256(SubsysNQN + "\x00" + VolumeID)[:16]
|
||||
// NGUID = sha256(SubsysNQN + "\x00" + VolumeID)[:16]
|
||||
//
|
||||
// QA pins four invariants (TestT2V2Port_NVMe_IdentifyNamespaceDescriptor_Deterministic):
|
||||
// (a) same (SubsysNQN, VolumeID) → same NGUID across handler lifetimes
|
||||
// (b) same VolumeID, different SubsysNQN → different NGUID
|
||||
// (c) same SubsysNQN, different VolumeID → different NGUID
|
||||
// (d) EUI-64 = NGUID[:8] always
|
||||
//
|
||||
// (a) same (SubsysNQN, VolumeID) → same NGUID across handler lifetimes
|
||||
// (b) same VolumeID, different SubsysNQN → different NGUID
|
||||
// (c) same SubsysNQN, different VolumeID → different NGUID
|
||||
// (d) EUI-64 = NGUID[:8] always
|
||||
//
|
||||
// No IEEE OUI prefix enforcement — sha256 bytes serve as an
|
||||
// opaque identifier. If Linux requires a registered OUI we
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestT2Batch11a_IdentifyController_SerialIsNotStub(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestT2Batch11a_IdentifyController_ANAFieldsAllZero(t *testing.T) {
|
||||
func TestNVMeIdentifyController_ANAFieldsZeroWithoutProvider(t *testing.T) {
|
||||
tg, _, cli := newIdentifyHarness(t)
|
||||
defer tg.Close()
|
||||
defer cli.close()
|
||||
@@ -88,6 +88,28 @@ func TestT2Batch11a_IdentifyController_ANAFieldsAllZero(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNVMeIdentifyController_ANAFieldsAdvertisedWithProvider(t *testing.T) {
|
||||
_, cli := newANAHarness(t, testANAProvider{
|
||||
state: nvme.ANAOptimized,
|
||||
groupID: 1,
|
||||
changeCount: 1,
|
||||
})
|
||||
_, data := cli.adminIdentify(t, 0x01, 0)
|
||||
|
||||
if got := data[76]; got != 0x0a {
|
||||
t.Fatalf("CMIC=0x%02x want 0x0a (multi-controller + ANA reporting)", got)
|
||||
}
|
||||
if got := data[341]; got != 0x17 {
|
||||
t.Fatalf("ANACAP=0x%02x want 0x17 (optimized/non-optimized/inaccessible/change)", got)
|
||||
}
|
||||
if got := binary.LittleEndian.Uint32(data[344:348]); got != 1 {
|
||||
t.Fatalf("ANAGRPMAX=%d want 1", got)
|
||||
}
|
||||
if got := binary.LittleEndian.Uint32(data[348:352]); got != 1 {
|
||||
t.Fatalf("NANAGRPID=%d want 1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestT2Batch11a_IdentifyController_ONCSAllZero(t *testing.T) {
|
||||
tg, _, cli := newIdentifyHarness(t)
|
||||
defer tg.Close()
|
||||
@@ -238,11 +260,14 @@ func TestT2Batch11a_IdentifyNamespace_NSFEATAndDLFEATZero(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestT2Batch11a_IdentifyNamespace_ANAGRPIDZero(t *testing.T) {
|
||||
func TestNVMeIdentifyNamespace_ANAGRPIDZeroWithoutProvider(t *testing.T) {
|
||||
tg, _, cli := newIdentifyHarness(t)
|
||||
defer tg.Close()
|
||||
defer cli.close()
|
||||
_, data := cli.adminIdentify(t, 0x00, 1)
|
||||
if got := data[30]; got != 0 {
|
||||
t.Fatalf("Identify NS NMIC=0x%02x want 0 without ANA provider", got)
|
||||
}
|
||||
// D2: Identify NS ANAGRPID (92-95) must be 0.
|
||||
got := binary.LittleEndian.Uint32(data[92:96])
|
||||
if got != 0 {
|
||||
@@ -250,6 +275,22 @@ func TestT2Batch11a_IdentifyNamespace_ANAGRPIDZero(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNVMeIdentifyNamespace_ANAFieldsAdvertisedWithProvider(t *testing.T) {
|
||||
_, cli := newANAHarness(t, testANAProvider{
|
||||
state: nvme.ANAOptimized,
|
||||
groupID: 1,
|
||||
changeCount: 1,
|
||||
})
|
||||
_, data := cli.adminIdentify(t, 0x00, 1)
|
||||
if got := data[30]; got != 0x01 {
|
||||
t.Fatalf("Identify NS NMIC=0x%02x want 0x01 (shared namespace)", got)
|
||||
}
|
||||
got := binary.LittleEndian.Uint32(data[92:96])
|
||||
if got != 1 {
|
||||
t.Fatalf("Identify NS ANAGRPID=%d want 1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestT2Batch11a_IdentifyNamespace_LBAF0LBADS9(t *testing.T) {
|
||||
tg, _, cli := newIdentifyHarness(t)
|
||||
defer tg.Close()
|
||||
|
||||
@@ -51,7 +51,7 @@ const (
|
||||
// Fields match the NVMe IO Read/Write CDW10-13 layout:
|
||||
// - SLBA = CDW10 (low) + CDW11 (high) — 64-bit starting LBA
|
||||
// - NLB = CDW12[15:0] + 1 (Number of Logical Blocks, zero-based on wire,
|
||||
// one-based in this struct for readability)
|
||||
// one-based in this struct for readability)
|
||||
// - NSID = command header Namespace Identifier
|
||||
//
|
||||
// Data is the host-provided write payload (nil for Read).
|
||||
@@ -89,9 +89,11 @@ func (r IOResult) AsError() *StatusError {
|
||||
// .Write so the per-op lineage fence fires exactly once per
|
||||
// NVMe command. Stateless with respect to the backend.
|
||||
type IOHandler struct {
|
||||
backend frontend.Backend
|
||||
blockSize uint32
|
||||
volumeSize uint64
|
||||
backend frontend.Backend
|
||||
blockSize uint32
|
||||
volumeSize uint64
|
||||
ana ANAProvider
|
||||
metadataOnly bool
|
||||
// nsid is the single namespace ID this handler serves. T2
|
||||
// advertises NSID=1 (the canonical "first namespace" in
|
||||
// NVMe discovery); commands for any other NSID are
|
||||
@@ -106,6 +108,10 @@ type HandlerConfig struct {
|
||||
BlockSize uint32
|
||||
VolumeSize uint64
|
||||
NSID uint32
|
||||
ANA ANAProvider
|
||||
// MetadataOnly serves admin/Identify/ANA discovery on a standby path but
|
||||
// rejects all namespace data commands before touching Backend.
|
||||
MetadataOnly bool
|
||||
}
|
||||
|
||||
// NewIOHandler builds a handler. Backend MUST be non-nil.
|
||||
@@ -126,10 +132,12 @@ func NewIOHandler(cfg HandlerConfig) *IOHandler {
|
||||
nsid = 1
|
||||
}
|
||||
return &IOHandler{
|
||||
backend: cfg.Backend,
|
||||
blockSize: bs,
|
||||
volumeSize: vs,
|
||||
nsid: nsid,
|
||||
backend: cfg.Backend,
|
||||
blockSize: bs,
|
||||
volumeSize: vs,
|
||||
ana: cfg.ANA,
|
||||
metadataOnly: cfg.MetadataOnly,
|
||||
nsid: nsid,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +150,15 @@ func (h *IOHandler) VolumeSize() uint64 { return h.volumeSize }
|
||||
// NSID exposes the namespace this handler serves.
|
||||
func (h *IOHandler) NSID() uint32 { return h.nsid }
|
||||
|
||||
// ANAProvider exposes the optional path-state provider used by admin log page
|
||||
// 0x0c. Nil means ANA is not implemented for this handler.
|
||||
func (h *IOHandler) ANAProvider() ANAProvider {
|
||||
if h == nil {
|
||||
return nil
|
||||
}
|
||||
return h.ana
|
||||
}
|
||||
|
||||
// Handle dispatches one IOCommand. Minimal T2 opcode set:
|
||||
// Read, Write, Flush. Everything else → Invalid Opcode.
|
||||
func (h *IOHandler) Handle(ctx context.Context, cmd IOCommand) IOResult {
|
||||
@@ -157,10 +174,19 @@ func (h *IOHandler) Handle(ctx context.Context, cmd IOCommand) IOResult {
|
||||
}
|
||||
switch cmd.Opcode {
|
||||
case ioRead:
|
||||
if r := h.metadataOnlyReject("read"); r != nil {
|
||||
return *r
|
||||
}
|
||||
return h.read(ctx, cmd)
|
||||
case ioWrite:
|
||||
if r := h.metadataOnlyReject("write"); r != nil {
|
||||
return *r
|
||||
}
|
||||
return h.write(ctx, cmd)
|
||||
case ioFlush:
|
||||
if r := h.metadataOnlyReject("flush"); r != nil {
|
||||
return *r
|
||||
}
|
||||
// T3b wire: dispatch to Backend.Sync. Durable backends
|
||||
// flush the WAL; memback Sync is a no-op (returns nil).
|
||||
// Errors propagate as InternalError (NVMe 1.4 §4.5; SCT=0
|
||||
@@ -179,6 +205,20 @@ func (h *IOHandler) Handle(ctx context.Context, cmd IOCommand) IOResult {
|
||||
}
|
||||
}
|
||||
|
||||
func (h *IOHandler) metadataOnlyReject(op string) *IOResult {
|
||||
if h == nil || !h.metadataOnly {
|
||||
return nil
|
||||
}
|
||||
if h.ana != nil && h.ana.ANAState() == ANAOptimized {
|
||||
return nil
|
||||
}
|
||||
return &IOResult{
|
||||
SCT: SCTPathRelated,
|
||||
SC: SCPathAsymAccessInaccessible,
|
||||
Reason: "ANA metadata-only path rejects " + op,
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- data path ----------
|
||||
|
||||
func (h *IOHandler) read(ctx context.Context, cmd IOCommand) IOResult {
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// sw may NOT modify this file without architect approval via §8B.4 Discovery Bridge.
|
||||
// See: sw-block/design/v3-phase-15-t2-test-spec.md
|
||||
// Maps to ledger rows: INV-FRONTEND-NVME-001, INV-FRONTEND-PROTOCOL-001,
|
||||
// INV-FRONTEND-PROTOCOL-002.WRITE, INV-FRONTEND-PROTOCOL-002.READ
|
||||
//
|
||||
// INV-FRONTEND-PROTOCOL-002.WRITE, INV-FRONTEND-PROTOCOL-002.READ
|
||||
//
|
||||
// Test layer: Unit (L0)
|
||||
// Protocol: NVMe/TCP
|
||||
@@ -27,6 +28,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
@@ -42,6 +44,17 @@ const (
|
||||
opFlush = 0x00
|
||||
)
|
||||
|
||||
type mutableTestANAProvider struct {
|
||||
state atomic.Uint32
|
||||
}
|
||||
|
||||
func (p *mutableTestANAProvider) ANAState() nvme.ANAState {
|
||||
return nvme.ANAState(p.state.Load())
|
||||
}
|
||||
|
||||
func (p *mutableTestANAProvider) ANAGroupID() uint32 { return 1 }
|
||||
func (p *mutableTestANAProvider) ANAChangeCount() uint64 { return 1 }
|
||||
|
||||
// T2.L0.n1 — Read and Write route through frontend.Backend.
|
||||
func TestT2NVMe_CommandReadWrite_UsesFrontendBackend(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{
|
||||
@@ -206,6 +219,40 @@ func TestT2NVMe_BackendClosed_DistinctFromStale(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestP4NVMe_MetadataOnlyPathAllowsIOAfterPromotion(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1"})
|
||||
ana := &mutableTestANAProvider{}
|
||||
ana.state.Store(uint32(nvme.ANANonOptimized))
|
||||
h := nvme.NewIOHandler(nvme.HandlerConfig{
|
||||
Backend: rec,
|
||||
ANA: ana,
|
||||
MetadataOnly: true,
|
||||
})
|
||||
ctx := context.Background()
|
||||
payload := make([]byte, nvme.DefaultBlockSize)
|
||||
|
||||
before := h.Handle(ctx, nvme.IOCommand{
|
||||
Opcode: opWrite, NSID: 1, SLBA: 0, NLB: 1, Data: payload,
|
||||
})
|
||||
if before.SCT != nvme.SCTPathRelated || before.SC != nvme.SCPathAsymAccessInaccessible {
|
||||
t.Fatalf("pre-promotion write status=(%d,0x%02x), want Path/Inaccessible", before.SCT, before.SC)
|
||||
}
|
||||
if rec.WriteCount() != 0 {
|
||||
t.Fatalf("pre-promotion metadata-only write reached backend; writes=%d", rec.WriteCount())
|
||||
}
|
||||
|
||||
ana.state.Store(uint32(nvme.ANAOptimized))
|
||||
after := h.Handle(ctx, nvme.IOCommand{
|
||||
Opcode: opWrite, NSID: 1, SLBA: 0, NLB: 1, Data: payload,
|
||||
})
|
||||
if err := after.AsError(); err != nil {
|
||||
t.Fatalf("post-promotion write: %v", err)
|
||||
}
|
||||
if rec.WriteCount() != 1 {
|
||||
t.Fatalf("post-promotion write count=%d want 1", rec.WriteCount())
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown opcode rejected without reaching backend.
|
||||
func TestT2NVMe_UnknownOpcode_ReturnsInvalidOpcode(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1"})
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
package nvme_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/nvme"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/testback"
|
||||
)
|
||||
|
||||
type p4NotReadyProvider struct{}
|
||||
|
||||
func (p4NotReadyProvider) Open(context.Context, string) (frontend.Backend, error) {
|
||||
return nil, frontend.ErrNotReady
|
||||
}
|
||||
|
||||
type p4ProbeProvider struct {
|
||||
backend frontend.Backend
|
||||
opens atomic.Int32
|
||||
}
|
||||
|
||||
func (p *p4ProbeProvider) ProbeBackend(context.Context, string) (frontend.Backend, error) {
|
||||
p.opens.Add(1)
|
||||
return p.backend, nil
|
||||
}
|
||||
|
||||
func newP4StandbyProbeHarness(t *testing.T) (*testback.RecordingBackend, *p4ProbeProvider, *nvmeClient) {
|
||||
t.Helper()
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{
|
||||
VolumeID: "v1", ReplicaID: "r2", Epoch: 1, EndpointVersion: 1,
|
||||
})
|
||||
probe := &p4ProbeProvider{backend: rec}
|
||||
tg := nvme.NewTarget(nvme.TargetConfig{
|
||||
Listen: "127.0.0.1:0",
|
||||
SubsysNQN: "nqn.2026-04.example.v3:subsys",
|
||||
VolumeID: "v1",
|
||||
Provider: p4NotReadyProvider{},
|
||||
ProbeProvider: probe,
|
||||
Handler: nvme.HandlerConfig{
|
||||
ANA: testANAProvider{
|
||||
state: nvme.ANANonOptimized,
|
||||
groupID: 1,
|
||||
changeCount: 7,
|
||||
},
|
||||
},
|
||||
})
|
||||
addr, err := tg.Start()
|
||||
if err != nil {
|
||||
t.Fatalf("Target.Start: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = tg.Close() })
|
||||
cli := dialAndConnectOpts(t, addr, connectOptions{SkipIOQueue: true})
|
||||
t.Cleanup(cli.close)
|
||||
return rec, probe, cli
|
||||
}
|
||||
|
||||
func TestP4NVMe_StandbyPathUsesProbeBackendForAdminMetadata(t *testing.T) {
|
||||
_, probe, cli := newP4StandbyProbeHarness(t)
|
||||
if got := probe.opens.Load(); got != 1 {
|
||||
t.Fatalf("ProbeBackend opens=%d want 1 after admin connect", got)
|
||||
}
|
||||
|
||||
status, ctrl := cli.adminIdentify(t, 0x01, 0)
|
||||
expectStatusSuccess(t, status, "standby Identify Controller")
|
||||
if got := ctrl[76]; got != 0x0a {
|
||||
t.Fatalf("CMIC=0x%02x want multi-controller + ANA reporting bits", got)
|
||||
}
|
||||
|
||||
status, ns := cli.adminIdentify(t, 0x00, 1)
|
||||
expectStatusSuccess(t, status, "standby Identify Namespace")
|
||||
if got := ns[30]; got != 0x01 {
|
||||
t.Fatalf("Identify NS NMIC=0x%02x want shared namespace bit", got)
|
||||
}
|
||||
if got := binary.LittleEndian.Uint32(ns[92:96]); got != 1 {
|
||||
t.Fatalf("Identify NS ANAGRPID=%d want 1", got)
|
||||
}
|
||||
|
||||
status, logData := cli.adminGetLogPage(t, 0x0C, 9)
|
||||
expectStatusSuccess(t, status, "standby ANA log")
|
||||
if got := logData[32]; got != byte(nvme.ANANonOptimized) {
|
||||
t.Fatalf("ANA state=0x%02x want non-optimized", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestP4NVMe_StandbyProbePathRejectsDataCommands(t *testing.T) {
|
||||
rec, probe, adminOnly := newP4StandbyProbeHarness(t)
|
||||
adminOnly.close()
|
||||
|
||||
tg := nvme.NewTarget(nvme.TargetConfig{
|
||||
Listen: "127.0.0.1:0",
|
||||
SubsysNQN: "nqn.2026-04.example.v3:subsys",
|
||||
VolumeID: "v1",
|
||||
Provider: p4NotReadyProvider{},
|
||||
ProbeProvider: probe,
|
||||
Handler: nvme.HandlerConfig{
|
||||
ANA: testANAProvider{
|
||||
state: nvme.ANANonOptimized,
|
||||
groupID: 1,
|
||||
changeCount: 7,
|
||||
},
|
||||
},
|
||||
})
|
||||
addr, err := tg.Start()
|
||||
if err != nil {
|
||||
t.Fatalf("Target.Start: %v", err)
|
||||
}
|
||||
defer tg.Close()
|
||||
|
||||
cli := dialAndConnect(t, addr)
|
||||
defer cli.close()
|
||||
status := cli.writeCmd(t, 0, 1, make([]byte, nvme.DefaultBlockSize))
|
||||
gotSCT := uint8((status >> 9) & 0x7)
|
||||
gotSC := uint8((status >> 1) & 0xff)
|
||||
if gotSCT != nvme.SCTPathRelated || gotSC != nvme.SCPathAsymAccessInaccessible {
|
||||
t.Fatalf("standby write status=0x%04x SCT=%d SC=0x%02x want Path/Inaccessible",
|
||||
status, gotSCT, gotSC)
|
||||
}
|
||||
if rec.WriteCount() != 0 {
|
||||
t.Fatalf("standby write reached probe backend; writes=%d", rec.WriteCount())
|
||||
}
|
||||
}
|
||||
|
||||
func TestP4NVMe_ConfiguredControllerIDIsAdvertisedOnConnect(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{
|
||||
VolumeID: "v1", ReplicaID: "r2", Epoch: 1, EndpointVersion: 1,
|
||||
})
|
||||
tg := nvme.NewTarget(nvme.TargetConfig{
|
||||
Listen: "127.0.0.1:0",
|
||||
SubsysNQN: "nqn.2026-04.example.v3:subsys",
|
||||
VolumeID: "v1",
|
||||
Provider: testback.NewStaticProvider(rec),
|
||||
ControllerID: 2,
|
||||
})
|
||||
addr, err := tg.Start()
|
||||
if err != nil {
|
||||
t.Fatalf("Target.Start: %v", err)
|
||||
}
|
||||
defer tg.Close()
|
||||
|
||||
cli := dialAndConnectOpts(t, addr, connectOptions{SkipIOQueue: true})
|
||||
defer cli.close()
|
||||
if cli.cntlID != 2 {
|
||||
t.Fatalf("admin Connect CNTLID=%d want configured controller id 2", cli.cntlID)
|
||||
}
|
||||
}
|
||||
@@ -31,14 +31,20 @@ const (
|
||||
// NVM admin opcode subset. Batch 11a introduces Identify
|
||||
// (0x06). SetFeatures / GetFeatures / KeepAlive / AsyncEventRequest
|
||||
// land with Batch 11b per port plan §7.
|
||||
adminGetLogPage uint8 = 0x02
|
||||
adminIdentify uint8 = 0x06
|
||||
adminAbort uint8 = 0x08
|
||||
adminSetFeatures uint8 = 0x09
|
||||
adminGetFeatures uint8 = 0x0A
|
||||
adminAsyncEvent uint8 = 0x0C
|
||||
adminKeepAlive uint8 = 0x18
|
||||
adminFabric uint8 = 0x7F // Fabric-specific commands
|
||||
adminGetLogPage uint8 = 0x02
|
||||
adminIdentify uint8 = 0x06
|
||||
adminAbort uint8 = 0x08
|
||||
adminSetFeatures uint8 = 0x09
|
||||
adminGetFeatures uint8 = 0x0A
|
||||
adminAsyncEvent uint8 = 0x0C
|
||||
adminKeepAlive uint8 = 0x18
|
||||
adminFabric uint8 = 0x7F // Fabric-specific commands
|
||||
)
|
||||
|
||||
// Log page identifiers.
|
||||
const (
|
||||
logPageSMART uint8 = 0x02
|
||||
logPageANA uint8 = 0x0C
|
||||
)
|
||||
|
||||
// Fabric command types (FCType).
|
||||
|
||||
@@ -297,9 +297,15 @@ func (s *Session) dispatchFromRx(ctx context.Context, req *Request) error {
|
||||
// IO queue. For Write without inline data, collect R2T data
|
||||
// inline FIRST (this is where pendingCapsules gets populated
|
||||
// via bufferInterleaved during recvH2CData), THEN dispatch.
|
||||
if cmd.OpCode == ioWrite && len(req.payload) == 0 {
|
||||
if err := s.collectR2TData(req); err != nil {
|
||||
return err
|
||||
if cmd.OpCode == ioWrite {
|
||||
totalBytes := req.capsule.LbaLength() * s.handler.BlockSize()
|
||||
if len(req.payload) == 0 {
|
||||
s.recordR2TWrite(totalBytes)
|
||||
if err := s.collectR2TData(req); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
s.recordInlineWrite(uint32(len(req.payload)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,6 +392,7 @@ func (s *Session) recvH2CData(totalBytes uint32) ([]byte, error) {
|
||||
if err := s.r.ReceiveData(buf[h2c.DATAO : h2c.DATAO+dataLen]); err != nil {
|
||||
return nil, fmt.Errorf("recvH2CData: receive data: %w", err)
|
||||
}
|
||||
s.recordH2CData(dataLen)
|
||||
received += dataLen
|
||||
}
|
||||
return buf, nil
|
||||
@@ -407,6 +414,8 @@ func (s *Session) bufferInterleaved() error {
|
||||
func (s *Session) adminDispatch(ctx context.Context, req *Request) error {
|
||||
cmd := &req.capsule
|
||||
switch cmd.OpCode {
|
||||
case adminGetLogPage:
|
||||
return s.handleGetLogPage(req)
|
||||
case adminIdentify:
|
||||
return s.handleAdminIdentify(req)
|
||||
case adminSetFeatures:
|
||||
@@ -434,6 +443,7 @@ func (s *Session) dispatchIO(ctx context.Context, req *Request) {
|
||||
case ioWrite:
|
||||
s.handleWrite(ctx, req)
|
||||
case ioFlush:
|
||||
s.recordFlushCommand()
|
||||
// T3b wire: dispatch to IOHandler.Handle which calls
|
||||
// Backend.Sync(ctx) — error propagates to CapsuleResp
|
||||
// status instead of silent Success.
|
||||
@@ -508,6 +518,7 @@ func (s *Session) writeResponse(resp *response) error {
|
||||
}
|
||||
|
||||
if len(resp.c2hData) > 0 {
|
||||
s.recordC2HData(uint32(len(resp.c2hData)))
|
||||
hdr := C2HDataHeader{
|
||||
CCCID: resp.resp.CID,
|
||||
DATAO: 0,
|
||||
@@ -530,6 +541,7 @@ func (s *Session) enqueueResponse(resp *response) {
|
||||
// ---------- IO handlers (run in goroutines) ----------
|
||||
|
||||
func (s *Session) handleRead(ctx context.Context, req *Request) {
|
||||
s.recordReadCommand()
|
||||
res := s.handler.Handle(ctx, IOCommand{
|
||||
Opcode: req.capsule.OpCode,
|
||||
NSID: req.capsule.NSID,
|
||||
@@ -545,6 +557,7 @@ func (s *Session) handleRead(ctx context.Context, req *Request) {
|
||||
}
|
||||
|
||||
func (s *Session) handleWrite(ctx context.Context, req *Request) {
|
||||
s.recordWriteCommand()
|
||||
res := s.handler.Handle(ctx, IOCommand{
|
||||
Opcode: req.capsule.OpCode,
|
||||
NSID: req.capsule.NSID,
|
||||
@@ -645,6 +658,9 @@ func (s *Session) handleAdminConnect(req *Request, cd *ConnectData, qid, queueSi
|
||||
// constraint #2 keeps this store-only, no timer).
|
||||
ctrl.setKATO(req.capsule.D12)
|
||||
s.connected.Store(true)
|
||||
if s.target != nil {
|
||||
s.target.stats.adminConnects.Add(1)
|
||||
}
|
||||
if s.logger != nil {
|
||||
s.logger.Printf("nvme: admin Connect accepted host=%q subsys=%q cntlid=%d qsize=%d kato=%d",
|
||||
cd.HostNQN, cd.SubNQN, ctrl.cntlID, queueSize, req.capsule.D12)
|
||||
@@ -685,6 +701,9 @@ func (s *Session) handleIOConnect(req *Request, cd *ConnectData, qid, queueSize
|
||||
s.queueSize = queueSize
|
||||
s.flowCtlOff = flowCtlOff
|
||||
s.connected.Store(true)
|
||||
if s.target != nil {
|
||||
s.target.stats.ioConnects.Add(1)
|
||||
}
|
||||
if s.logger != nil {
|
||||
s.logger.Printf("nvme: IO Connect accepted host=%q subsys=%q cntlid=%d qid=%d qsize=%d",
|
||||
cd.HostNQN, cd.SubNQN, ctrl.cntlID, qid, queueSize)
|
||||
@@ -695,6 +714,52 @@ func (s *Session) handleIOConnect(req *Request, cd *ConnectData, qid, queueSize
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Session) recordReadCommand() {
|
||||
if s.target != nil {
|
||||
s.target.stats.readCommands.Add(1)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) recordWriteCommand() {
|
||||
if s.target != nil {
|
||||
s.target.stats.writeCommands.Add(1)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) recordFlushCommand() {
|
||||
if s.target != nil {
|
||||
s.target.stats.flushCommands.Add(1)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) recordInlineWrite(bytes uint32) {
|
||||
if s.target != nil {
|
||||
s.target.stats.inlineWriteCommands.Add(1)
|
||||
s.target.stats.inlineWriteBytes.Add(uint64(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) recordR2TWrite(bytes uint32) {
|
||||
if s.target != nil {
|
||||
s.target.stats.r2tWriteCommands.Add(1)
|
||||
s.target.stats.r2tWriteBytes.Add(uint64(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) recordH2CData(bytes uint32) {
|
||||
if s.target != nil {
|
||||
s.target.stats.h2cDataPDUs.Add(1)
|
||||
s.target.stats.h2cDataBytes.Add(uint64(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) recordC2HData(bytes uint32) {
|
||||
if s.target != nil {
|
||||
s.target.stats.c2hDataPDUs.Add(1)
|
||||
s.target.stats.c2hDataBytes.Add(uint64(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
// handleDisconnect (BUG-002).
|
||||
func (s *Session) handleDisconnect(req *Request) error {
|
||||
if s.logger != nil && s.ctrl != nil {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package nvme
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
// Stats is a snapshot of target-level NVMe/TCP activity.
|
||||
//
|
||||
// It is intentionally transport-focused, not a performance API. The first use
|
||||
// is lab evidence: after a real Linux initiator run, we need to know whether
|
||||
// writes arrived inline in the capsule or through R2T/H2CData.
|
||||
type Stats struct {
|
||||
SessionsAccepted uint64 `json:"sessions_accepted"`
|
||||
AdminConnects uint64 `json:"admin_connects"`
|
||||
IOConnects uint64 `json:"io_connects"`
|
||||
|
||||
ReadCommands uint64 `json:"read_commands"`
|
||||
WriteCommands uint64 `json:"write_commands"`
|
||||
FlushCommands uint64 `json:"flush_commands"`
|
||||
|
||||
InlineWriteCommands uint64 `json:"inline_write_commands"`
|
||||
InlineWriteBytes uint64 `json:"inline_write_bytes"`
|
||||
R2TWriteCommands uint64 `json:"r2t_write_commands"`
|
||||
R2TWriteBytes uint64 `json:"r2t_write_bytes"`
|
||||
|
||||
H2CDataPDUs uint64 `json:"h2c_data_pdus"`
|
||||
H2CDataBytes uint64 `json:"h2c_data_bytes"`
|
||||
C2HDataPDUs uint64 `json:"c2h_data_pdus"`
|
||||
C2HDataBytes uint64 `json:"c2h_data_bytes"`
|
||||
}
|
||||
|
||||
type targetStats struct {
|
||||
sessionsAccepted atomic.Uint64
|
||||
adminConnects atomic.Uint64
|
||||
ioConnects atomic.Uint64
|
||||
|
||||
readCommands atomic.Uint64
|
||||
writeCommands atomic.Uint64
|
||||
flushCommands atomic.Uint64
|
||||
|
||||
inlineWriteCommands atomic.Uint64
|
||||
inlineWriteBytes atomic.Uint64
|
||||
r2tWriteCommands atomic.Uint64
|
||||
r2tWriteBytes atomic.Uint64
|
||||
|
||||
h2cDataPDUs atomic.Uint64
|
||||
h2cDataBytes atomic.Uint64
|
||||
c2hDataPDUs atomic.Uint64
|
||||
c2hDataBytes atomic.Uint64
|
||||
}
|
||||
|
||||
func (s *targetStats) snapshot() Stats {
|
||||
if s == nil {
|
||||
return Stats{}
|
||||
}
|
||||
return Stats{
|
||||
SessionsAccepted: s.sessionsAccepted.Load(),
|
||||
AdminConnects: s.adminConnects.Load(),
|
||||
IOConnects: s.ioConnects.Load(),
|
||||
ReadCommands: s.readCommands.Load(),
|
||||
WriteCommands: s.writeCommands.Load(),
|
||||
FlushCommands: s.flushCommands.Load(),
|
||||
InlineWriteCommands: s.inlineWriteCommands.Load(),
|
||||
InlineWriteBytes: s.inlineWriteBytes.Load(),
|
||||
R2TWriteCommands: s.r2tWriteCommands.Load(),
|
||||
R2TWriteBytes: s.r2tWriteBytes.Load(),
|
||||
H2CDataPDUs: s.h2cDataPDUs.Load(),
|
||||
H2CDataBytes: s.h2cDataBytes.Load(),
|
||||
C2HDataPDUs: s.c2hDataPDUs.Load(),
|
||||
C2HDataBytes: s.c2hDataBytes.Load(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package nvme_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/nvme"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/testback"
|
||||
)
|
||||
|
||||
func newStatsTarget(t *testing.T) (*nvme.Target, *nvmeClient) {
|
||||
t.Helper()
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{
|
||||
VolumeID: "v1", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1,
|
||||
})
|
||||
prov := testback.NewStaticProvider(rec)
|
||||
tg := nvme.NewTarget(nvme.TargetConfig{
|
||||
Listen: "127.0.0.1:0",
|
||||
SubsysNQN: "nqn.2026-04.example.v3:subsys",
|
||||
VolumeID: "v1",
|
||||
Provider: prov,
|
||||
})
|
||||
addr, err := tg.Start()
|
||||
if err != nil {
|
||||
t.Fatalf("Target.Start: %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
_ = tg.Close()
|
||||
})
|
||||
cli := dialAndConnect(t, addr)
|
||||
t.Cleanup(func() {
|
||||
cli.close()
|
||||
})
|
||||
return tg, cli
|
||||
}
|
||||
|
||||
func TestTargetStats_RecordInlineAndR2TWrites(t *testing.T) {
|
||||
tg, cli := newStatsTarget(t)
|
||||
|
||||
inlinePayload := make([]byte, nvme.DefaultBlockSize)
|
||||
status := writeInlineOnClient(t, cli, 0, 1, inlinePayload)
|
||||
expectStatusSuccess(t, status, "inline Write")
|
||||
|
||||
r2tPayload := make([]byte, 2*nvme.DefaultBlockSize)
|
||||
status = writeChunkedOnClient(t, cli, 1, 2, r2tPayload, 2)
|
||||
expectStatusSuccess(t, status, "R2T Write")
|
||||
|
||||
st := tg.Stats()
|
||||
if st.AdminConnects != 1 || st.IOConnects != 1 {
|
||||
t.Fatalf("connect stats admin=%d io=%d want 1/1", st.AdminConnects, st.IOConnects)
|
||||
}
|
||||
if st.WriteCommands != 2 {
|
||||
t.Fatalf("write_commands=%d want 2", st.WriteCommands)
|
||||
}
|
||||
if st.InlineWriteCommands != 1 || st.InlineWriteBytes != uint64(len(inlinePayload)) {
|
||||
t.Fatalf("inline stats commands=%d bytes=%d want 1/%d",
|
||||
st.InlineWriteCommands, st.InlineWriteBytes, len(inlinePayload))
|
||||
}
|
||||
if st.R2TWriteCommands != 1 || st.R2TWriteBytes != uint64(len(r2tPayload)) {
|
||||
t.Fatalf("r2t stats commands=%d bytes=%d want 1/%d",
|
||||
st.R2TWriteCommands, st.R2TWriteBytes, len(r2tPayload))
|
||||
}
|
||||
if st.H2CDataPDUs != 2 || st.H2CDataBytes != uint64(len(r2tPayload)) {
|
||||
t.Fatalf("h2c stats pdus=%d bytes=%d want 2/%d",
|
||||
st.H2CDataPDUs, st.H2CDataBytes, len(r2tPayload))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTargetStats_RecordReadAndFlush(t *testing.T) {
|
||||
tg, cli := newStatsTarget(t)
|
||||
|
||||
status := cli.writeCmd(t, 0, 1, make([]byte, nvme.DefaultBlockSize))
|
||||
expectStatusSuccess(t, status, "seed Write")
|
||||
status, data := cli.readCmd(t, 0, 1, int(nvme.DefaultBlockSize))
|
||||
expectStatusSuccess(t, status, "Read")
|
||||
if len(data) != int(nvme.DefaultBlockSize) {
|
||||
t.Fatalf("read len=%d want %d", len(data), nvme.DefaultBlockSize)
|
||||
}
|
||||
status = flushOnClient(t, cli)
|
||||
expectStatusSuccess(t, status, "Flush")
|
||||
|
||||
st := tg.Stats()
|
||||
if st.ReadCommands != 1 {
|
||||
t.Fatalf("read_commands=%d want 1", st.ReadCommands)
|
||||
}
|
||||
if st.FlushCommands != 1 {
|
||||
t.Fatalf("flush_commands=%d want 1", st.FlushCommands)
|
||||
}
|
||||
if st.C2HDataPDUs != 1 || st.C2HDataBytes != uint64(nvme.DefaultBlockSize) {
|
||||
t.Fatalf("c2h stats pdus=%d bytes=%d want 1/%d",
|
||||
st.C2HDataPDUs, st.C2HDataBytes, nvme.DefaultBlockSize)
|
||||
}
|
||||
}
|
||||
|
||||
func writeInlineOnClient(t *testing.T, c *nvmeClient, slba uint64, nlb uint16, payload []byte) uint16 {
|
||||
t.Helper()
|
||||
cid := uint16(c.cid.Add(1))
|
||||
cmd := nvme.CapsuleCommand{
|
||||
OpCode: 0x01,
|
||||
CID: cid,
|
||||
NSID: 1,
|
||||
D10: uint32(slba & 0xFFFFFFFF),
|
||||
D11: uint32(slba >> 32),
|
||||
D12: uint32(nlb - 1),
|
||||
}
|
||||
if err := c.ioW.SendWithData(0x4, 0, &cmd, 64, payload); err != nil {
|
||||
t.Fatalf("send inline Write: %v", err)
|
||||
}
|
||||
resp := recvCapsuleResp(t, c.ioR)
|
||||
if resp.CID != cid {
|
||||
t.Fatalf("inline Write resp CID=%d want %d", resp.CID, cid)
|
||||
}
|
||||
return resp.Status
|
||||
}
|
||||
|
||||
func flushOnClient(t *testing.T, c *nvmeClient) uint16 {
|
||||
t.Helper()
|
||||
cid := uint16(c.cid.Add(1))
|
||||
cmd := nvme.CapsuleCommand{
|
||||
OpCode: 0x00,
|
||||
CID: cid,
|
||||
NSID: 1,
|
||||
}
|
||||
if err := c.ioW.SendHeaderOnly(0x4, &cmd, 64); err != nil {
|
||||
t.Fatalf("send Flush: %v", err)
|
||||
}
|
||||
resp := recvCapsuleResp(t, c.ioR)
|
||||
if resp.CID != cid {
|
||||
t.Fatalf("Flush resp CID=%d want %d", resp.CID, cid)
|
||||
}
|
||||
return resp.Status
|
||||
}
|
||||
|
||||
func TestTargetStats_ZeroForNilTarget(t *testing.T) {
|
||||
var tg *nvme.Target
|
||||
st := tg.Stats()
|
||||
if st != (nvme.Stats{}) {
|
||||
t.Fatalf("nil target stats = %+v, want zero", st)
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@
|
||||
//
|
||||
// Sign-off tier per this checkpoint: T2B-NVMe-provisional
|
||||
// (QA Owner + sw lead per §8B.9). Product-ready requires L2-OS.
|
||||
//go:build subprocess
|
||||
|
||||
package nvme_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
// - YAML ops: write (seed-derived payload), read (asserts
|
||||
// seed-derived expected bytes)
|
||||
|
||||
//go:build subprocess
|
||||
|
||||
package nvme_test
|
||||
|
||||
import (
|
||||
|
||||
@@ -67,16 +67,10 @@ func TestT2V2Port_NVMe_IdentifyCtrl_OAESAllBitsZero(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestT2V2Port_NVMe_IdentifyCtrl_OAESANACrossConsistency(t *testing.T) {
|
||||
// Symmetric pin: OAES bit 11 (ANA Change Notice) fires ONLY if
|
||||
// ANA is implemented. Since sw's TestT2Batch11a_..._ANAFieldsAllZero
|
||||
// already pins ANA fields (CMIC/ANACAP/ANAGRPMAX/NANAGRPID) to 0,
|
||||
// OAES bit 11 MUST also be 0. This test makes the linkage
|
||||
// mechanical: if someone flips one side without the other, the
|
||||
// pair is detected inconsistent before silently-broken
|
||||
// behavior reaches the OS.
|
||||
//
|
||||
// 11c conditional ANA port would flip BOTH sides together; this
|
||||
// test must be updated in the same commit.
|
||||
// OAES bit 11 is ANA Change Notice, an async event source. It is
|
||||
// stronger than ANA log support and must not be advertised unless an event
|
||||
// producer exists. ANA Identify fields may become non-zero before OAES bit
|
||||
// 11; the reverse is invalid.
|
||||
_, cli := targetForNVMe(t, "nqn.2026-04.m01:sub1", "v1")
|
||||
_, data := cli.adminIdentify(t, 0x01, 0)
|
||||
|
||||
@@ -91,11 +85,6 @@ func TestT2V2Port_NVMe_IdentifyCtrl_OAESANACrossConsistency(t *testing.T) {
|
||||
t.Fatal("OAES bit 11 (ANA Change Notice) set but ANA fields all zero — " +
|
||||
"advertising an event source that cannot exist (inconsistent)")
|
||||
}
|
||||
if !anaChangeNoticeBit && !anaFieldsAllZero {
|
||||
t.Fatalf("ANA fields non-zero (cmic-ana=%v anacap=0x%02x grpMax=%d numGrp=%d) but "+
|
||||
"OAES bit 11 clear — implemented without advertising the event (inconsistent)",
|
||||
cmicANA, anacapByte, anaGrpMax, numGrp)
|
||||
}
|
||||
// Both zero (Batch 11 expected) or both non-zero (11c+ ANA) —
|
||||
// consistent either way.
|
||||
// Both zero (no ANA) and ANA-without-OAES are valid. OAES-without-ANA is
|
||||
// the invalid combination guarded above.
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build subprocess
|
||||
|
||||
// Ownership: QA (L1B-1 inventory item, landed early per QA parallel
|
||||
// capacity during Batch 11c sign prep).
|
||||
// sw may NOT modify without architect approval via §8B.4 Discovery
|
||||
@@ -18,7 +20,8 @@
|
||||
// T3 perf gate.
|
||||
//
|
||||
// Test layer: L2 subprocess (real cmd/blockmaster + cmd/blockvolume).
|
||||
// Tagged with testing.Short() skip so CI-short runs exclude it.
|
||||
// Build tag: subprocess. Default go test is kept to unit/component scope;
|
||||
// runner suites should own this style of expensive process test.
|
||||
|
||||
package nvme_test
|
||||
|
||||
|
||||
@@ -94,11 +94,10 @@ func oaesBit(t *testing.T, data []byte, bit uint) bool {
|
||||
return idCtrlU32LE(t, data, idCtrlOffsetOAES)&(1<<bit) != 0
|
||||
}
|
||||
|
||||
// cmicANASupported reports CMIC bit 1 (ANA Reporting Supported). A11.2
|
||||
// ANA-zero sub-test pins this to false.
|
||||
// cmicANASupported reports CMIC bit 3 (ANA Reporting Supported).
|
||||
func cmicANASupported(t *testing.T, data []byte) bool {
|
||||
t.Helper()
|
||||
return idCtrlByte(t, data, idCtrlOffsetCMIC)&(1<<1) != 0
|
||||
return idCtrlByte(t, data, idCtrlOffsetCMIC)&(1<<3) != 0
|
||||
}
|
||||
|
||||
// anacap returns the ANACAP byte. A11.2 pins this to 0 until ANA lands
|
||||
|
||||
@@ -17,6 +17,12 @@ import (
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
)
|
||||
|
||||
// ProbeBackendProvider supplies a borrowed backend for metadata-only ANA path
|
||||
// probing when the write-ready Provider.Open path is not available.
|
||||
type ProbeBackendProvider interface {
|
||||
ProbeBackend(ctx context.Context, volumeID string) (frontend.Backend, error)
|
||||
}
|
||||
|
||||
// TargetConfig configures an NVMe/TCP Target.
|
||||
type TargetConfig struct {
|
||||
// Listen TCP address (":0" for tests).
|
||||
@@ -34,6 +40,18 @@ type TargetConfig struct {
|
||||
// Provider supplies the frontend.Backend per session.
|
||||
Provider frontend.Provider
|
||||
|
||||
// ProbeProvider is optional. If Provider.Open returns ErrNotReady and ANA
|
||||
// reports a non-optimized path, the target uses this backend for admin
|
||||
// connect / Identify / ANA log visibility. Data commands remain rejected
|
||||
// by a metadata-only IOHandler.
|
||||
ProbeProvider ProbeBackendProvider
|
||||
|
||||
// ControllerID is the first CNTLID allocated by this target. Zero uses 1.
|
||||
// Multi-path deployments must configure distinct values per target serving
|
||||
// the same SubsysNQN; Linux rejects duplicate controller IDs inside one
|
||||
// subsystem.
|
||||
ControllerID uint16
|
||||
|
||||
// IO handler tunables (block size, volume size, NSID).
|
||||
// Zero values pick T2 defaults.
|
||||
Handler HandlerConfig
|
||||
@@ -58,6 +76,8 @@ type Target struct {
|
||||
ctrlMu sync.Mutex
|
||||
ctrls map[uint16]*adminController
|
||||
nextCntlID uint16 // monotonic allocator; never reuses a CNTLID within a Target lifetime
|
||||
|
||||
stats targetStats
|
||||
}
|
||||
|
||||
// NewTarget builds a Target. Provider must be non-nil.
|
||||
@@ -69,12 +89,16 @@ func NewTarget(cfg TargetConfig) *Target {
|
||||
if lg == nil {
|
||||
lg = log.Default()
|
||||
}
|
||||
nextCntlID := cfg.ControllerID
|
||||
if nextCntlID == 0 || nextCntlID == 0xffff {
|
||||
nextCntlID = 1
|
||||
}
|
||||
return &Target{
|
||||
cfg: cfg,
|
||||
logger: stdlogAdapter{l: lg},
|
||||
closed: make(chan struct{}),
|
||||
ctrls: map[uint16]*adminController{},
|
||||
nextCntlID: 1, // 0 is reserved per NVMe-oF; host may also read 0xFFFF as "request new"
|
||||
nextCntlID: nextCntlID, // 0 is reserved; 0xFFFF is "request new" on Connect.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,9 +169,25 @@ func (t *Target) Close() error {
|
||||
_ = ln.Close()
|
||||
}
|
||||
t.sessions.Wait()
|
||||
st := t.Stats()
|
||||
t.logger.Printf("nvme: stats sessions=%d admin_connects=%d io_connects=%d reads=%d writes=%d flushes=%d inline_writes=%d inline_bytes=%d r2t_writes=%d r2t_bytes=%d h2c_pdus=%d h2c_bytes=%d c2h_pdus=%d c2h_bytes=%d",
|
||||
st.SessionsAccepted, st.AdminConnects, st.IOConnects,
|
||||
st.ReadCommands, st.WriteCommands, st.FlushCommands,
|
||||
st.InlineWriteCommands, st.InlineWriteBytes,
|
||||
st.R2TWriteCommands, st.R2TWriteBytes,
|
||||
st.H2CDataPDUs, st.H2CDataBytes,
|
||||
st.C2HDataPDUs, st.C2HDataBytes)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stats returns a point-in-time transport counter snapshot.
|
||||
func (t *Target) Stats() Stats {
|
||||
if t == nil {
|
||||
return Stats{}
|
||||
}
|
||||
return t.stats.snapshot()
|
||||
}
|
||||
|
||||
func (t *Target) acceptLoop(ln net.Listener) {
|
||||
for {
|
||||
conn, err := ln.Accept()
|
||||
@@ -168,6 +208,7 @@ func (t *Target) acceptLoop(ln net.Listener) {
|
||||
func (t *Target) handleConn(conn net.Conn) {
|
||||
defer t.sessions.Done()
|
||||
defer conn.Close()
|
||||
t.stats.sessionsAccepted.Add(1)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@@ -179,10 +220,15 @@ func (t *Target) handleConn(conn net.Conn) {
|
||||
}
|
||||
}()
|
||||
|
||||
metadataOnly := false
|
||||
backend, err := t.cfg.Provider.Open(ctx, t.cfg.VolumeID)
|
||||
if err != nil {
|
||||
t.logger.Printf("nvme: Provider.Open(%s): %v", t.cfg.VolumeID, err)
|
||||
return
|
||||
var ok bool
|
||||
backend, metadataOnly, ok = t.tryProbeBackend(ctx, err)
|
||||
if !ok {
|
||||
t.logger.Printf("nvme: Provider.Open(%s): %v", t.cfg.VolumeID, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
// BUG-005 fix (2026-04-22): do NOT close the Backend here.
|
||||
// The Provider owns Backend lifecycle — `DurableProvider`
|
||||
@@ -194,6 +240,7 @@ func (t *Target) handleConn(conn net.Conn) {
|
||||
|
||||
hcfg := t.cfg.Handler
|
||||
hcfg.Backend = backend
|
||||
hcfg.MetadataOnly = metadataOnly
|
||||
handler := NewIOHandler(hcfg)
|
||||
|
||||
sess := newSession(conn, handler, t, t.cfg.SubsysNQN, t.logger)
|
||||
@@ -202,6 +249,27 @@ func (t *Target) handleConn(conn net.Conn) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Target) tryProbeBackend(ctx context.Context, openErr error) (frontend.Backend, bool, bool) {
|
||||
if t.cfg.ProbeProvider == nil || !errors.Is(openErr, frontend.ErrNotReady) {
|
||||
return nil, false, false
|
||||
}
|
||||
ana := t.cfg.Handler.ANA
|
||||
if ana == nil {
|
||||
return nil, false, false
|
||||
}
|
||||
switch ana.ANAState() {
|
||||
case ANAOptimized:
|
||||
return nil, false, false
|
||||
}
|
||||
backend, err := t.cfg.ProbeProvider.ProbeBackend(ctx, t.cfg.VolumeID)
|
||||
if err != nil {
|
||||
t.logger.Printf("nvme: ProbeBackend(%s): %v", t.cfg.VolumeID, err)
|
||||
return nil, false, false
|
||||
}
|
||||
t.logger.Printf("nvme: Provider.Open(%s): %v; using ANA metadata probe backend", t.cfg.VolumeID, openErr)
|
||||
return backend, true, true
|
||||
}
|
||||
|
||||
type stdlogAdapter struct{ l *log.Logger }
|
||||
|
||||
func (a stdlogAdapter) Printf(format string, args ...interface{}) {
|
||||
|
||||
@@ -20,6 +20,7 @@ func TestG15c_LifecycleService_CreateVolumePersistsDesiredIntent(t *testing.T) {
|
||||
VolumeId: "pvc-a",
|
||||
SizeBytes: 1 << 30,
|
||||
ReplicationFactor: 2,
|
||||
Protocol: "nvme",
|
||||
PvcName: "demo-pvc",
|
||||
PvcNamespace: "demo-ns",
|
||||
PvcUid: "uid-123",
|
||||
@@ -34,6 +35,9 @@ func TestG15c_LifecycleService_CreateVolumePersistsDesiredIntent(t *testing.T) {
|
||||
if resp.GetPvcName() != "demo-pvc" || resp.GetPvcNamespace() != "demo-ns" || resp.GetPvcUid() != "uid-123" || resp.GetPvName() != "pvc-a" {
|
||||
t.Fatalf("kubernetes metadata response=%+v", resp)
|
||||
}
|
||||
if resp.GetProtocol() != "nvme" {
|
||||
t.Fatalf("response protocol=%q want nvme", resp.GetProtocol())
|
||||
}
|
||||
rec, ok := h.Lifecycle().Volumes.GetVolume("pvc-a")
|
||||
if !ok {
|
||||
t.Fatal("desired volume not persisted")
|
||||
@@ -41,6 +45,9 @@ func TestG15c_LifecycleService_CreateVolumePersistsDesiredIntent(t *testing.T) {
|
||||
if rec.Spec.VolumeID != "pvc-a" || rec.Spec.SizeBytes != 1<<30 || rec.Spec.ReplicationFactor != 2 {
|
||||
t.Fatalf("record=%+v", rec)
|
||||
}
|
||||
if rec.Spec.Protocol != "nvme" {
|
||||
t.Fatalf("record protocol=%q want nvme", rec.Spec.Protocol)
|
||||
}
|
||||
if rec.Spec.PVCName != "demo-pvc" || rec.Spec.PVCNamespace != "demo-ns" || rec.Spec.PVCUID != "uid-123" || rec.Spec.PVName != "pvc-a" {
|
||||
t.Fatalf("kubernetes metadata record=%+v", rec)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,9 @@ func (s *services) CreateVolume(ctx context.Context, req *control.CreateVolumeRe
|
||||
if stores == nil {
|
||||
return nil, status.Error(codes.FailedPrecondition, "lifecycle store is not configured")
|
||||
}
|
||||
rec, err := stores.Volumes.CreateVolume(lifecycleSpecFromWire(req))
|
||||
spec := lifecycleSpecFromWire(req)
|
||||
s.host.log.Printf("blockmaster: CreateVolume volume=%q protocol=%q replication_factor=%d pvc=%q namespace=%q", spec.VolumeID, spec.Protocol, spec.ReplicationFactor, spec.PVCName, spec.PVCNamespace)
|
||||
rec, err := stores.Volumes.CreateVolume(spec)
|
||||
if err != nil {
|
||||
return nil, lifecycleError("create volume", err)
|
||||
}
|
||||
@@ -59,6 +61,7 @@ func (s *services) CreateVolume(ctx context.Context, req *control.CreateVolumeRe
|
||||
VolumeId: rec.Spec.VolumeID,
|
||||
SizeBytes: rec.Spec.SizeBytes,
|
||||
ReplicationFactor: int32(rec.Spec.ReplicationFactor),
|
||||
Protocol: rec.Spec.Protocol,
|
||||
PvcName: rec.Spec.PVCName,
|
||||
PvcNamespace: rec.Spec.PVCNamespace,
|
||||
PvcUid: rec.Spec.PVCUID,
|
||||
@@ -109,6 +112,7 @@ func lifecycleSpecFromWire(req *control.CreateVolumeRequest) lifecycle.VolumeSpe
|
||||
VolumeID: req.GetVolumeId(),
|
||||
SizeBytes: req.GetSizeBytes(),
|
||||
ReplicationFactor: int(req.GetReplicationFactor()),
|
||||
Protocol: req.GetProtocol(),
|
||||
PVCName: req.GetPvcName(),
|
||||
PVCNamespace: req.GetPvcNamespace(),
|
||||
PVCUID: req.GetPvcUid(),
|
||||
|
||||
@@ -134,8 +134,19 @@ func blockVolumeArgs(plan lifecycle.BlockVolumeWorkloadPlan, replica lifecycle.B
|
||||
fmt.Sprintf("--durable-blocks=%d", plan.SizeBytes/4096),
|
||||
"--durable-blocksize=4096",
|
||||
"--recovery-mode=" + cfg.RecoveryMode,
|
||||
fmt.Sprintf("--iscsi-listen=127.0.0.1:%d", replica.ISCSIListenPort),
|
||||
"--iscsi-iqn=" + replica.ISCSIQualifiedName,
|
||||
}
|
||||
switch plan.Protocol {
|
||||
case "nvme":
|
||||
args = append(args,
|
||||
fmt.Sprintf("--nvme-listen=127.0.0.1:%d", replica.NVMeListenPort),
|
||||
"--nvme-subsysnqn="+replica.NVMeSubsystemNQN,
|
||||
fmt.Sprintf("--nvme-ns=%d", replica.NVMeNSID),
|
||||
)
|
||||
default:
|
||||
args = append(args,
|
||||
fmt.Sprintf("--iscsi-listen=127.0.0.1:%d", replica.ISCSIListenPort),
|
||||
"--iscsi-iqn="+replica.ISCSIQualifiedName,
|
||||
)
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
@@ -59,6 +59,33 @@ func TestG15d_K8sRenderer_RF2UsesDistinctNamesAndPorts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15d_K8sRenderer_RendersNVMeBlockVolumeArgs(t *testing.T) {
|
||||
plan := sampleWorkloadPlan()
|
||||
plan.Protocol = "nvme"
|
||||
manifests, err := RenderBlockVolumeDeployments(plan, K8sRenderConfig{MasterAddr: "m:9333"})
|
||||
if err != nil {
|
||||
t.Fatalf("RenderBlockVolumeDeployments: %v", err)
|
||||
}
|
||||
raw := string(manifests[0].YAML)
|
||||
for _, want := range []string{
|
||||
"--nvme-listen=127.0.0.1:4420",
|
||||
"--nvme-subsysnqn=nqn.test:pvc-a",
|
||||
"--nvme-ns=1",
|
||||
} {
|
||||
if !strings.Contains(raw, want) {
|
||||
t.Fatalf("manifest missing %q:\n%s", want, raw)
|
||||
}
|
||||
}
|
||||
for _, forbidden := range []string{
|
||||
"--iscsi-listen=",
|
||||
"--iscsi-iqn=",
|
||||
} {
|
||||
if strings.Contains(raw, forbidden) {
|
||||
t.Fatalf("nvme manifest must not contain %q:\n%s", forbidden, raw)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15d_K8sRenderer_RequiresMasterAddr(t *testing.T) {
|
||||
_, err := RenderBlockVolumeDeployments(sampleWorkloadPlan(), K8sRenderConfig{})
|
||||
if err == nil {
|
||||
@@ -151,6 +178,7 @@ func sampleWorkloadPlan() lifecycle.BlockVolumeWorkloadPlan {
|
||||
return lifecycle.BlockVolumeWorkloadPlan{
|
||||
VolumeID: "pvc-a",
|
||||
SizeBytes: 1 << 20,
|
||||
Protocol: "iscsi",
|
||||
PVCName: "demo-pvc",
|
||||
PVCNamespace: "default",
|
||||
PVCUID: "uid-123",
|
||||
@@ -164,6 +192,9 @@ func sampleWorkloadPlan() lifecycle.BlockVolumeWorkloadPlan {
|
||||
CtrlAddr: "10.0.0.1:9101",
|
||||
ISCSIListenPort: 3260,
|
||||
ISCSIQualifiedName: "iqn.test:pvc-a",
|
||||
NVMeListenPort: 4420,
|
||||
NVMeSubsystemNQN: "nqn.test:pvc-a",
|
||||
NVMeNSID: 1,
|
||||
},
|
||||
{
|
||||
ServerID: "m02",
|
||||
@@ -174,6 +205,9 @@ func sampleWorkloadPlan() lifecycle.BlockVolumeWorkloadPlan {
|
||||
CtrlAddr: "10.0.0.1:9102",
|
||||
ISCSIListenPort: 3261,
|
||||
ISCSIQualifiedName: "iqn.test:pvc-a",
|
||||
NVMeListenPort: 4421,
|
||||
NVMeSubsystemNQN: "nqn.test:pvc-a",
|
||||
NVMeNSID: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ type VolumeSpec struct {
|
||||
VolumeID string `json:"volume_id"`
|
||||
SizeBytes uint64 `json:"size_bytes"`
|
||||
ReplicationFactor int `json:"replication_factor"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
PVCName string `json:"pvc_name,omitempty"`
|
||||
PVCNamespace string `json:"pvc_namespace,omitempty"`
|
||||
PVCUID string `json:"pvc_uid,omitempty"`
|
||||
@@ -73,6 +74,7 @@ func OpenFileStore(dir string) (*FileStore, error) {
|
||||
// CreateVolume records desired volume state. Repeating the same spec is
|
||||
// idempotent; changing a previously-created spec is rejected.
|
||||
func (s *FileStore) CreateVolume(spec VolumeSpec) (VolumeRecord, error) {
|
||||
spec = normalizeVolumeSpec(spec)
|
||||
if err := validateSpec(spec); err != nil {
|
||||
return VolumeRecord{}, err
|
||||
}
|
||||
@@ -102,9 +104,12 @@ func (s *FileStore) CreateVolume(spec VolumeSpec) (VolumeRecord, error) {
|
||||
}
|
||||
|
||||
func volumeSpecsCompatible(a, b VolumeSpec) bool {
|
||||
a = normalizeVolumeSpec(a)
|
||||
b = normalizeVolumeSpec(b)
|
||||
return a.VolumeID == b.VolumeID &&
|
||||
a.SizeBytes == b.SizeBytes &&
|
||||
a.ReplicationFactor == b.ReplicationFactor
|
||||
a.ReplicationFactor == b.ReplicationFactor &&
|
||||
a.Protocol == b.Protocol
|
||||
}
|
||||
|
||||
func mergeVolumeSpecMetadata(existing, incoming VolumeSpec) VolumeSpec {
|
||||
@@ -233,6 +238,7 @@ func (s *FileStore) load() error {
|
||||
if err := validateSpec(rec.Spec); err != nil {
|
||||
return fmt.Errorf("lifecycle: invalid record %q: %w", path, err)
|
||||
}
|
||||
rec.Spec = normalizeVolumeSpec(rec.Spec)
|
||||
if filepath.Base(s.path(rec.Spec.VolumeID)) != entry.Name() {
|
||||
return fmt.Errorf("lifecycle: record filename %q does not match volume_id %q", entry.Name(), rec.Spec.VolumeID)
|
||||
}
|
||||
@@ -277,6 +283,7 @@ func (s *FileStore) path(volumeID string) string {
|
||||
}
|
||||
|
||||
func validateSpec(spec VolumeSpec) error {
|
||||
spec = normalizeVolumeSpec(spec)
|
||||
if err := validateVolumeID(spec.VolumeID); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -286,9 +293,21 @@ func validateSpec(spec VolumeSpec) error {
|
||||
if spec.ReplicationFactor <= 0 {
|
||||
return fmt.Errorf("%w: replication_factor must be > 0", ErrInvalidVolumeSpec)
|
||||
}
|
||||
switch spec.Protocol {
|
||||
case "iscsi", "nvme":
|
||||
default:
|
||||
return fmt.Errorf("%w: protocol must be iscsi or nvme", ErrInvalidVolumeSpec)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeVolumeSpec(spec VolumeSpec) VolumeSpec {
|
||||
if spec.Protocol == "" {
|
||||
spec.Protocol = "iscsi"
|
||||
}
|
||||
return spec
|
||||
}
|
||||
|
||||
func validateVolumeID(volumeID string) error {
|
||||
if volumeID == "" {
|
||||
return fmt.Errorf("%w: empty volume id", ErrInvalidVolumeSpec)
|
||||
|
||||
@@ -20,6 +20,7 @@ func TestFileStore_CreateVolumePersistsAndIsIdempotent(t *testing.T) {
|
||||
VolumeID: "vol-a",
|
||||
SizeBytes: 1 << 20,
|
||||
ReplicationFactor: 2,
|
||||
Protocol: "iscsi",
|
||||
PVCName: "demo-pvc",
|
||||
PVCNamespace: "demo-ns",
|
||||
PVCUID: "uid-123",
|
||||
@@ -65,6 +66,9 @@ func TestFileStore_CreateVolumeRejectsConflictingSpec(t *testing.T) {
|
||||
if _, err := s.CreateVolume(VolumeSpec{VolumeID: "vol-a", SizeBytes: 2 << 20, ReplicationFactor: 2}); err == nil {
|
||||
t.Fatal("conflicting create must fail")
|
||||
}
|
||||
if _, err := s.CreateVolume(VolumeSpec{VolumeID: "vol-a", SizeBytes: 1 << 20, ReplicationFactor: 2, Protocol: "nvme"}); err == nil {
|
||||
t.Fatal("conflicting protocol create must fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileStore_CreateVolumeMergesMissingKubernetesMetadata(t *testing.T) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
type BlockVolumeWorkloadPlan struct {
|
||||
VolumeID string
|
||||
SizeBytes uint64
|
||||
Protocol string
|
||||
PVCName string
|
||||
PVCNamespace string
|
||||
PVCUID string
|
||||
@@ -26,6 +27,9 @@ type BlockVolumeReplicaWorkload struct {
|
||||
CtrlAddr string
|
||||
ISCSIListenPort int
|
||||
ISCSIQualifiedName string
|
||||
NVMeListenPort int
|
||||
NVMeSubsystemNQN string
|
||||
NVMeNSID int
|
||||
}
|
||||
|
||||
// PlanBlockVolumeWorkloads converts desired lifecycle state plus placement
|
||||
@@ -47,6 +51,16 @@ func PlanBlockVolumeWorkloads(volume VolumeRecord, placement PlacementIntent, no
|
||||
if cfg.IQNPrefix == "" {
|
||||
cfg.IQNPrefix = "iqn.2026-05.io.seaweedfs"
|
||||
}
|
||||
if cfg.NVMePortBase == 0 {
|
||||
cfg.NVMePortBase = 4420
|
||||
}
|
||||
if cfg.NQNPrefix == "" {
|
||||
cfg.NQNPrefix = "nqn.2026-05.io.seaweedfs"
|
||||
}
|
||||
protocol := volume.Spec.Protocol
|
||||
if protocol == "" {
|
||||
protocol = "iscsi"
|
||||
}
|
||||
nodeByID := make(map[string]NodeRegistration, len(nodes))
|
||||
for _, node := range nodes {
|
||||
nodeByID[node.ServerID] = node
|
||||
@@ -55,6 +69,7 @@ func PlanBlockVolumeWorkloads(volume VolumeRecord, placement PlacementIntent, no
|
||||
out := BlockVolumeWorkloadPlan{
|
||||
VolumeID: volume.Spec.VolumeID,
|
||||
SizeBytes: volume.Spec.SizeBytes,
|
||||
Protocol: protocol,
|
||||
PVCName: volume.Spec.PVCName,
|
||||
PVCNamespace: volume.Spec.PVCNamespace,
|
||||
PVCUID: volume.Spec.PVCUID,
|
||||
@@ -79,6 +94,9 @@ func PlanBlockVolumeWorkloads(volume VolumeRecord, placement PlacementIntent, no
|
||||
CtrlAddr: ctrlAddr,
|
||||
ISCSIListenPort: cfg.ISCSIPortBase + i,
|
||||
ISCSIQualifiedName: fmt.Sprintf("%s:%s", cfg.IQNPrefix, volume.Spec.VolumeID),
|
||||
NVMeListenPort: cfg.NVMePortBase + i,
|
||||
NVMeSubsystemNQN: fmt.Sprintf("%s:%s", cfg.NQNPrefix, volume.Spec.VolumeID),
|
||||
NVMeNSID: 1,
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
@@ -87,6 +105,8 @@ func PlanBlockVolumeWorkloads(volume VolumeRecord, placement PlacementIntent, no
|
||||
type WorkloadPlanConfig struct {
|
||||
ISCSIPortBase int
|
||||
IQNPrefix string
|
||||
NVMePortBase int
|
||||
NQNPrefix string
|
||||
}
|
||||
|
||||
func SortWorkloadPlans(plans []BlockVolumeWorkloadPlan) {
|
||||
|
||||
@@ -29,6 +29,9 @@ func TestG15d_WorkloadPlan_BlankPoolRF2CreatesReplicaWorkloads(t *testing.T) {
|
||||
if plan.VolumeID != "pvc-a" || plan.SizeBytes != 1<<20 || len(plan.Replicas) != 2 {
|
||||
t.Fatalf("plan=%+v", plan)
|
||||
}
|
||||
if plan.Protocol != "iscsi" {
|
||||
t.Fatalf("protocol=%q want iscsi", plan.Protocol)
|
||||
}
|
||||
if plan.PVCName != "demo-pvc" || plan.PVCNamespace != "default" || plan.PVCUID != "uid-123" {
|
||||
t.Fatalf("pvc metadata=%+v", plan)
|
||||
}
|
||||
@@ -43,6 +46,42 @@ func TestG15d_WorkloadPlan_BlankPoolRF2CreatesReplicaWorkloads(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15d_WorkloadPlan_NVMeProtocolCreatesNVMeTargets(t *testing.T) {
|
||||
volume := VolumeRecord{Spec: VolumeSpec{
|
||||
VolumeID: "pvc-a",
|
||||
SizeBytes: 1 << 20,
|
||||
ReplicationFactor: 1,
|
||||
Protocol: "nvme",
|
||||
}}
|
||||
placement := PlacementIntent{
|
||||
VolumeID: "pvc-a",
|
||||
DesiredRF: 1,
|
||||
Slots: []PlacementSlotIntent{{
|
||||
ServerID: "node-a",
|
||||
PoolID: "pool-a",
|
||||
Source: PlacementSourceBlankPool,
|
||||
}},
|
||||
}
|
||||
plan, err := PlanBlockVolumeWorkloads(volume, placement, []NodeRegistration{
|
||||
nodeForWorkload("node-a", "10.0.0.1:9201", "10.0.0.1:9101"),
|
||||
}, WorkloadPlanConfig{NVMePortBase: 4420, NQNPrefix: "nqn.test"})
|
||||
if err != nil {
|
||||
t.Fatalf("PlanBlockVolumeWorkloads: %v", err)
|
||||
}
|
||||
if plan.Protocol != "nvme" {
|
||||
t.Fatalf("protocol=%q want nvme", plan.Protocol)
|
||||
}
|
||||
if got := plan.Replicas[0].NVMeListenPort; got != 4420 {
|
||||
t.Fatalf("nvme port=%d want 4420", got)
|
||||
}
|
||||
if got := plan.Replicas[0].NVMeSubsystemNQN; got != "nqn.test:pvc-a" {
|
||||
t.Fatalf("nqn=%q", got)
|
||||
}
|
||||
if got := plan.Replicas[0].NVMeNSID; got != 1 {
|
||||
t.Fatalf("nsid=%d want 1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestG15d_WorkloadPlan_ExistingReplicaKeepsReplicaID(t *testing.T) {
|
||||
volume := VolumeRecord{Spec: VolumeSpec{VolumeID: "pvc-a", SizeBytes: 1 << 20, ReplicationFactor: 1}}
|
||||
placement := PlacementIntent{
|
||||
|
||||
@@ -836,6 +836,7 @@ type CreateVolumeRequest struct {
|
||||
PvcNamespace string `protobuf:"bytes,5,opt,name=pvc_namespace,json=pvcNamespace,proto3" json:"pvc_namespace,omitempty"`
|
||||
PvName string `protobuf:"bytes,6,opt,name=pv_name,json=pvName,proto3" json:"pv_name,omitempty"`
|
||||
PvcUid string `protobuf:"bytes,7,opt,name=pvc_uid,json=pvcUid,proto3" json:"pvc_uid,omitempty"`
|
||||
Protocol string `protobuf:"bytes,8,opt,name=protocol,proto3" json:"protocol,omitempty"` // "iscsi" default | "nvme"
|
||||
}
|
||||
|
||||
func (x *CreateVolumeRequest) Reset() {
|
||||
@@ -919,6 +920,13 @@ func (x *CreateVolumeRequest) GetPvcUid() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CreateVolumeRequest) GetProtocol() string {
|
||||
if x != nil {
|
||||
return x.Protocol
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type CreateVolumeResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -931,6 +939,7 @@ type CreateVolumeResponse struct {
|
||||
PvcNamespace string `protobuf:"bytes,5,opt,name=pvc_namespace,json=pvcNamespace,proto3" json:"pvc_namespace,omitempty"`
|
||||
PvName string `protobuf:"bytes,6,opt,name=pv_name,json=pvName,proto3" json:"pv_name,omitempty"`
|
||||
PvcUid string `protobuf:"bytes,7,opt,name=pvc_uid,json=pvcUid,proto3" json:"pvc_uid,omitempty"`
|
||||
Protocol string `protobuf:"bytes,8,opt,name=protocol,proto3" json:"protocol,omitempty"` // "iscsi" default | "nvme"
|
||||
}
|
||||
|
||||
func (x *CreateVolumeResponse) Reset() {
|
||||
@@ -1014,6 +1023,13 @@ func (x *CreateVolumeResponse) GetPvcUid() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CreateVolumeResponse) GetProtocol() string {
|
||||
if x != nil {
|
||||
return x.Protocol
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type DeleteVolumeRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -1225,7 +1241,7 @@ var file_control_proto_rawDesc = []byte{
|
||||
0x32, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f,
|
||||
0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x72, 0x6f, 0x6e, 0x74,
|
||||
0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x52, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74,
|
||||
0x65, 0x6e, 0x64, 0x73, 0x22, 0xf2, 0x01, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56,
|
||||
0x65, 0x6e, 0x64, 0x73, 0x22, 0x8e, 0x02, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56,
|
||||
0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09,
|
||||
0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x69, 0x7a,
|
||||
@@ -1240,70 +1256,73 @@ var file_control_proto_rawDesc = []byte{
|
||||
0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x5f, 0x6e, 0x61,
|
||||
0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x4e, 0x61, 0x6d, 0x65,
|
||||
0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x22, 0xf3, 0x01, 0x0a, 0x14, 0x43, 0x72,
|
||||
0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12,
|
||||
0x1d, 0x0a, 0x0a, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x04, 0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d,
|
||||
0x0a, 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61,
|
||||
0x63, 0x74, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c,
|
||||
0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a,
|
||||
0x08, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x07, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x0c, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a,
|
||||
0x07, 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
|
||||
0x70, 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69,
|
||||
0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x22,
|
||||
0x32, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65,
|
||||
0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d,
|
||||
0x65, 0x49, 0x64, 0x22, 0x16, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c,
|
||||
0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x78, 0x0a, 0x12, 0x4f,
|
||||
0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
|
||||
0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x48, 0x65, 0x61, 0x72, 0x74,
|
||||
0x62, 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73,
|
||||
0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48,
|
||||
0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x1a, 0x25,
|
||||
0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b,
|
||||
0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65,
|
||||
0x61, 0x74, 0x41, 0x63, 0x6b, 0x32, 0x81, 0x01, 0x0a, 0x11, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e,
|
||||
0x6d, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53,
|
||||
0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65,
|
||||
0x6e, 0x74, 0x73, 0x12, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e,
|
||||
0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75,
|
||||
0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27,
|
||||
0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b,
|
||||
0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d,
|
||||
0x65, 0x6e, 0x74, 0x46, 0x61, 0x63, 0x74, 0x30, 0x01, 0x32, 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69,
|
||||
0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11,
|
||||
0x51, 0x75, 0x65, 0x72, 0x79, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75,
|
||||
0x73, 0x12, 0x26, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c,
|
||||
0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74,
|
||||
0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77,
|
||||
0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x22, 0x8f, 0x02, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
|
||||
0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b,
|
||||
0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x73,
|
||||
0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52,
|
||||
0x09, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65,
|
||||
0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72,
|
||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x70, 0x76, 0x63,
|
||||
0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x76, 0x63,
|
||||
0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x76, 0x63,
|
||||
0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x5f,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x4e, 0x61,
|
||||
0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, 0x64, 0x18, 0x07, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x22, 0x32, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74,
|
||||
0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b,
|
||||
0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x16, 0x0a, 0x14, 0x44,
|
||||
0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x32, 0x78, 0x0a, 0x12, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70,
|
||||
0x6f, 0x72, 0x74, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73,
|
||||
0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63,
|
||||
0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74,
|
||||
0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64,
|
||||
0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x32, 0x81, 0x01,
|
||||
0x0a, 0x11, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76,
|
||||
0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65,
|
||||
0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x29, 0x2e, 0x73, 0x65,
|
||||
0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f,
|
||||
0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64,
|
||||
0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x2e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, 0x63, 0x74, 0x30,
|
||||
0x01, 0x32, 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72,
|
||||
0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, 0x79, 0x56, 0x6f, 0x6c,
|
||||
0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x26, 0x2e, 0x73, 0x65, 0x61, 0x77,
|
||||
0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74,
|
||||
0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x32, 0xec, 0x01, 0x0a, 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, 0x63, 0x6c, 0x65,
|
||||
0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74,
|
||||
0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65,
|
||||
0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f,
|
||||
0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66,
|
||||
0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e,
|
||||
0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70,
|
||||
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f,
|
||||
0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73,
|
||||
0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44,
|
||||
0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62,
|
||||
0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c,
|
||||
0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
|
||||
0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65,
|
||||
0x64, 0x2d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63,
|
||||
0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||
0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c,
|
||||
0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74,
|
||||
0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xec, 0x01, 0x0a, 0x10, 0x4c,
|
||||
0x69, 0x66, 0x65, 0x63, 0x79, 0x63, 0x6c, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12,
|
||||
0x6b, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12,
|
||||
0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63,
|
||||
0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
|
||||
0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e,
|
||||
0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e,
|
||||
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f,
|
||||
0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0c,
|
||||
0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73,
|
||||
0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63,
|
||||
0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c,
|
||||
0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61,
|
||||
0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e,
|
||||
0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d,
|
||||
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74,
|
||||
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66,
|
||||
0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f,
|
||||
0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -198,6 +198,7 @@ message CreateVolumeRequest {
|
||||
string pvc_namespace = 5;
|
||||
string pv_name = 6;
|
||||
string pvc_uid = 7;
|
||||
string protocol = 8; // "iscsi" default | "nvme"
|
||||
}
|
||||
|
||||
message CreateVolumeResponse {
|
||||
@@ -208,6 +209,7 @@ message CreateVolumeResponse {
|
||||
string pvc_namespace = 5;
|
||||
string pv_name = 6;
|
||||
string pvc_uid = 7;
|
||||
string protocol = 8; // "iscsi" default | "nvme"
|
||||
}
|
||||
|
||||
message DeleteVolumeRequest {
|
||||
|
||||
@@ -61,13 +61,17 @@ For local k3s/kind-style testing, build images with:
|
||||
bash scripts/build-alpha-images.sh "$PWD"
|
||||
```
|
||||
|
||||
For k3s, import them into containerd:
|
||||
For k3s, prefer the pinned build/import form:
|
||||
|
||||
```bash
|
||||
docker save sw-block:local | sudo k3s ctr images import -
|
||||
docker save sw-block-csi:local | sudo k3s ctr images import -
|
||||
SW_BLOCK_IMPORT_K3S=1 \
|
||||
SW_BLOCK_ARTIFACT_DIR=/tmp/sw-block-alpha-build \
|
||||
bash scripts/build-alpha-images.sh "$PWD"
|
||||
```
|
||||
|
||||
The artifact directory records image IDs and component `--version` output, so a
|
||||
later smoke failure can distinguish product behavior from a stale runtime image.
|
||||
|
||||
For a cluster that pulls from a registry, set the image names before running the
|
||||
scripted demo:
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ spec:
|
||||
imagePullPolicy: Never
|
||||
command: ["/bin/sh", "-c"]
|
||||
args:
|
||||
- "modprobe iscsi_tcp || true"
|
||||
- "modprobe iscsi_tcp || true; modprobe nvme_tcp || true"
|
||||
securityContext:
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
|
||||
@@ -12,6 +12,7 @@ RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
e2fsprogs \
|
||||
kmod \
|
||||
nvme-cli \
|
||||
open-iscsi \
|
||||
util-linux && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
@@ -21,7 +21,7 @@ spec:
|
||||
imagePullPolicy: Never
|
||||
command: ["/bin/sh", "-c"]
|
||||
args:
|
||||
- "modprobe iscsi_tcp || true"
|
||||
- "modprobe iscsi_tcp || true; modprobe nvme_tcp || true"
|
||||
securityContext:
|
||||
privileged: true
|
||||
volumeMounts:
|
||||
|
||||
@@ -35,12 +35,15 @@ Same as the README quick start:
|
||||
Build and import local images first:
|
||||
|
||||
```bash
|
||||
bash scripts/build-alpha-images.sh "$PWD"
|
||||
|
||||
docker save sw-block:local | sudo k3s ctr images import -
|
||||
docker save sw-block-csi:local | sudo k3s ctr images import -
|
||||
SW_BLOCK_IMPORT_K3S=1 \
|
||||
SW_BLOCK_ARTIFACT_DIR=/tmp/sw-block-alpha-build \
|
||||
bash scripts/build-alpha-images.sh "$PWD"
|
||||
```
|
||||
|
||||
The build artifact directory records image IDs and component `--version`
|
||||
output, which is the useful evidence when a demo host might have stale k3s
|
||||
containerd images.
|
||||
|
||||
For an existing cluster that pulls images from a registry:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -62,14 +62,16 @@ Use this when your test node can build Docker images locally.
|
||||
```bash
|
||||
export KUBECONFIG="${KUBECONFIG:-/etc/rancher/k3s/k3s.yaml}"
|
||||
|
||||
bash scripts/build-alpha-images.sh "$PWD"
|
||||
|
||||
docker save sw-block:local | sudo k3s ctr images import -
|
||||
docker save sw-block-csi:local | sudo k3s ctr images import -
|
||||
SW_BLOCK_IMPORT_K3S=1 \
|
||||
SW_BLOCK_ARTIFACT_DIR=/tmp/sw-block-alpha-build \
|
||||
bash scripts/build-alpha-images.sh "$PWD"
|
||||
|
||||
bash scripts/run-k8s-demo.sh "$PWD"
|
||||
```
|
||||
|
||||
`SW_BLOCK_ARTIFACT_DIR` records the local image IDs and `blockmaster`,
|
||||
`blockvolume`, and `blockcsi` version output used by the cluster.
|
||||
|
||||
Expected final line:
|
||||
|
||||
```text
|
||||
|
||||
@@ -19,7 +19,7 @@ Already demonstrated:
|
||||
Current alpha constraints:
|
||||
|
||||
- single-node Kubernetes lab evidence
|
||||
- iSCSI frontend only
|
||||
- iSCSI and NVMe-oF frontends are release-gated on a single-node lab
|
||||
- `walstore` backend only
|
||||
- launcher-generated blockvolume state uses `emptyDir`
|
||||
- harness applies generated blockvolume manifests
|
||||
@@ -81,14 +81,14 @@ Current alpha constraints:
|
||||
|
||||
## Protocol And Backend Roadmap
|
||||
|
||||
1. iSCSI remains the MVP frontend.
|
||||
1. iSCSI and NVMe-oF are the current release-gated frontends.
|
||||
|
||||
It is the currently tested Kubernetes path and should stay the default until
|
||||
the install and cleanup experience is stable.
|
||||
iSCSI remains the default path for broad compatibility. NVMe-oF is now
|
||||
covered by ANA-aware multipath/failover and CSI protocol-selection gates.
|
||||
|
||||
2. NVMe-oF is a follow-up frontend.
|
||||
2. CSI dispatch is protocol-aware.
|
||||
|
||||
The CSI layer should dispatch by frontend target protocol:
|
||||
The CSI layer dispatches by frontend target protocol:
|
||||
|
||||
```text
|
||||
protocol=iscsi -> iscsiadm path
|
||||
@@ -116,7 +116,7 @@ Requires deeper storage context:
|
||||
- WAL retention and flow control
|
||||
- replica reintegration
|
||||
- multi-node authority/publisher changes
|
||||
- NVMe-oF frontend support
|
||||
- broader V2 parity and long-running protocol regression coverage
|
||||
|
||||
## Definition Of Beta
|
||||
|
||||
@@ -127,7 +127,7 @@ A reasonable beta bar:
|
||||
- Volume data survives blockvolume pod restart.
|
||||
- Multi-node attach works.
|
||||
- Basic failover is tested under an attached workload.
|
||||
- TestOps can run the smoke suite and produce stable artifacts.
|
||||
- TestOps can run the protocol release gate and produce stable artifacts.
|
||||
- Non-claims are documented and visible to users.
|
||||
|
||||
Detailed post-alpha execution planning is kept in `internal/docs/` so the
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package buildinfo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
// Version returns a compact provenance string suitable for lab artifacts.
|
||||
func Version(component string) string {
|
||||
revision := "unknown"
|
||||
modified := "unknown"
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
for _, setting := range info.Settings {
|
||||
switch setting.Key {
|
||||
case "vcs.revision":
|
||||
if setting.Value != "" {
|
||||
revision = setting.Value
|
||||
}
|
||||
case "vcs.modified":
|
||||
if setting.Value != "" {
|
||||
modified = setting.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s revision=%s modified=%s", component, revision, modified)
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
# Current Plan: iSCSI Frontend Completeness
|
||||
# Current Plan: Frontend Completeness And V2 Parity
|
||||
|
||||
Status: active.
|
||||
Status: active, with the iSCSI/NVMe protocol-readiness slice closed.
|
||||
|
||||
Rule: V2 frontend coverage is the minimum height for V3 unless we explicitly
|
||||
drop a feature with a product reason. V3 should keep its own architecture, but
|
||||
the user-visible iSCSI capability should reach and then exceed V2.
|
||||
the user-visible frontend capability should reach and then exceed V2.
|
||||
|
||||
References:
|
||||
|
||||
@@ -14,12 +14,47 @@ References:
|
||||
- `ref/iscsi-csi-alua-review-guide.md`
|
||||
- `ref/iscsi-p6-alua-mpio-design.md`
|
||||
- `ref/iscsi-alua-technical-note.md`
|
||||
- `ref/nvme-ana-parity-plan.md`
|
||||
- `ref/nvme-v2-coverage-gap-audit.md`
|
||||
- `ref/nvme-ana-technical-note.md`
|
||||
- `ref/nvme-p4-multipath-failover-design.md`
|
||||
|
||||
## Current Status: Protocol Readiness Closed
|
||||
|
||||
As of 2026-05-09, the current iSCSI/NVMe frontend protocol-readiness plan is
|
||||
closed for this branch.
|
||||
|
||||
Close evidence:
|
||||
|
||||
- Runner-native protocol release gate PASS on M02:
|
||||
- product commit: `033028e74c1ac3bc06f19c0563bc2e6a0495af59`,
|
||||
- runner commit: `3c1b6603aefcf4c1bf0b22f9a9c081a67e786d8d`,
|
||||
- suite run: `20260509-151531-9c6c`,
|
||||
- wall clock: 1415.97 seconds,
|
||||
- children: `iscsi-p6-alua-failover`, `nvme-p4-multipath-failover`,
|
||||
`nvme-p5-csi-protocol`, and `iscsi-p8-compat-soak`, all PASS.
|
||||
- `swblock validate-bundle --profile protocol-release-gate` classified the
|
||||
native suite bundle as VALID.
|
||||
- Post-run M02 cleanup was clean: no V3 processes and all child
|
||||
`collect_and_cleanup` phases ran.
|
||||
|
||||
Decision:
|
||||
|
||||
- iSCSI and NVMe are now release-gated protocol frontends, not active bring-up
|
||||
work.
|
||||
- Future iSCSI/NVMe changes should enter through regression tests, V2 parity
|
||||
backlog items, or broader availability/performance gates.
|
||||
- Do not treat this as full V2 product parity. Remaining work belongs to
|
||||
parity/hardening: rebuild/reintegration matrices, operator lifecycle,
|
||||
multi-node/cloud scale, longer soak/performance, and scenario corpus
|
||||
migration.
|
||||
|
||||
## Product Goal
|
||||
|
||||
- Make iSCSI a credible Kubernetes block frontend, not only a smoke-test path.
|
||||
- Keep iSCSI and NVMe credible Kubernetes block frontends, not only smoke-test
|
||||
paths.
|
||||
- Support real OS initiators, filesystem workloads, stress, auth, lifecycle,
|
||||
and eventually multipath/failover.
|
||||
multipath, and mounted failover.
|
||||
- Keep protocol code separate from authority and replica readiness decisions.
|
||||
- Use V2 tests as the coverage inventory, not as code to blindly copy.
|
||||
|
||||
@@ -471,7 +506,7 @@ References:
|
||||
- non-claim:
|
||||
compatibility probe only, not a long-running soak or performance claim.
|
||||
|
||||
## Current Active Milestone: TestOps For Frontend Lab Gates
|
||||
## Recently Closed Milestone: TestOps For Frontend Lab Gates
|
||||
|
||||
- Goal:
|
||||
- reduce false failures from manual multi-step lab runs by moving P8-style
|
||||
@@ -481,10 +516,65 @@ References:
|
||||
|
||||
- Tasks:
|
||||
- #QA package P8 compatibility soak as a TestOps scenario:
|
||||
- status: next assignment.
|
||||
- status: done; wrapper proven green in standalone runner and carried back
|
||||
into the product planning flow.
|
||||
- must record commit SHA, command, artifact root, step result, final line,
|
||||
and cleanup status in a single result file.
|
||||
- initial scenario may call `scripts/run-iscsi-compat-soak.sh`.
|
||||
- pin alpha image build/import before K8s frontend gates:
|
||||
- status: QA green at `c3a6e28`; workload composition hook active in this
|
||||
branch.
|
||||
- script: `scripts/build-alpha-images.sh`.
|
||||
- TestOps scenario: `alpha-images-pin-build`.
|
||||
- contract:
|
||||
- build `sw-block:local` and `sw-block-csi:local`,
|
||||
- optionally import both images into k3s containerd with
|
||||
`SW_BLOCK_IMPORT_K3S=1`,
|
||||
- record Docker image IDs,
|
||||
- record `blockmaster`, `blockvolume`, and `blockcsi` `--version`
|
||||
output,
|
||||
- downstream K8s harnesses may consume the build output with
|
||||
`SW_BLOCK_ALPHA_IMAGES_ENV=/path/to/pin-build/alpha-images.env`,
|
||||
- fail before protocol smoke tests if build/import/version capture fails.
|
||||
- composed TestOps workload scenarios:
|
||||
- status: QA green at `cf9183a`.
|
||||
- `nvme-p5-csi-dynamic`,
|
||||
- `nvme-p5-default-iscsi-regression`.
|
||||
- developer-owned P5 suite:
|
||||
- status: QA green at `67592f2`.
|
||||
- `scripts/testops-run-nvme-p5-suite.sh`,
|
||||
- runs pin-build, then both P5 workload scenarios,
|
||||
- passes `alpha-images.env` forward mechanically,
|
||||
- writes one suite-level `result.json`.
|
||||
- reason:
|
||||
- NVMe-P5 showed that stale k3s images can mimic product protocol bugs.
|
||||
The build/import step must be one reviewed gate, not manual lab memory.
|
||||
- platform extraction target:
|
||||
- status: seed shape extracted into standalone runner and native suite
|
||||
flow; continue hardening in runner repo.
|
||||
- port this V3 reference implementation into reusable runner primitives:
|
||||
- `testops_pin_build` for build/import/version/image provenance,
|
||||
- `consume_pin` for passing pinned outputs between phases,
|
||||
- `assert_revision_matches` for component/runtime SHA checks,
|
||||
- suite linkage that passes prior phase outputs without ad-hoc env-file
|
||||
conventions.
|
||||
- reference hardware evidence:
|
||||
- `alpha-images-pin-build` PASS at `cf9183a`,
|
||||
- `nvme-p5-csi-dynamic` PASS at `cf9183a`,
|
||||
- `nvme-p5-default-iscsi-regression` PASS at `cf9183a`.
|
||||
- runner-native protocol release suite:
|
||||
- status: QA green on M02 at product `033028e` and runner `3c1b660`.
|
||||
- suite: `testops/suites/protocol-release-gate.yaml`.
|
||||
- command shape:
|
||||
`swblock suite --results-dir <root> --env product_root=<remote-root>
|
||||
--env ssh_key=<key> testops/suites/protocol-release-gate.yaml`.
|
||||
- children:
|
||||
- `iscsi-p6-alua-failover-chain`,
|
||||
- `nvme-p4-multipath-failover-chain`,
|
||||
- `nvme-p5-csi-protocol-chain`,
|
||||
- `iscsi-p8-compat-soak-chain`.
|
||||
- validation:
|
||||
`swblock validate-bundle --profile protocol-release-gate <suite-run>`.
|
||||
- define the minimal result contract:
|
||||
- scenario name,
|
||||
- repository SHA,
|
||||
@@ -500,11 +590,228 @@ References:
|
||||
- one command runs the P8 full lab gate,
|
||||
- old-commit/stale-binary ambiguity is impossible or explicitly reported,
|
||||
- result file is enough for review without reading raw terminal output.
|
||||
- one runner-native command runs the full iSCSI/NVMe/CSI/soak release gate,
|
||||
and `validate-bundle --profile protocol-release-gate` accepts the bundle.
|
||||
|
||||
- QA/tooling:
|
||||
- #QA assignment should be written before implementation.
|
||||
- Dev owns the core test content and uses TestOps as the primary dev loop.
|
||||
- QA may run the same scenarios, add lab automation, and improve collection,
|
||||
but should not be the only path that can execute a gate end-to-end.
|
||||
- prefer small TestOps wrapper over a wholesale scenario DSL rewrite.
|
||||
|
||||
## Recently Closed Milestone: NVMe-oF / ANA Parity Planning
|
||||
|
||||
- Goal:
|
||||
- bring NVMe-oF up to the same product discipline as the now-green iSCSI
|
||||
frontend.
|
||||
- treat V2 NVMe behavior as the feature floor, not code to copy blindly.
|
||||
- understand the old high-performance path before touching protocol code.
|
||||
|
||||
- Reference:
|
||||
- `internal/docs/ref/nvme-ana-parity-plan.md`.
|
||||
- `internal/docs/ref/nvme-v2-coverage-gap-audit.md`.
|
||||
|
||||
- Tasks:
|
||||
- NVMe-P0 audit:
|
||||
- status: initial audit done; keep updating as code lands.
|
||||
- compare V2 NVMe implementation and scenarios against current V3.
|
||||
- classify every visible feature as present, missing, intentionally
|
||||
deferred, or rejected with product reason.
|
||||
- specifically answer whether the remembered "control API carries data"
|
||||
path was standard NVMe/TCP in-capsule data or a custom V2 shortcut.
|
||||
- initial answer: standard in-capsule data; no custom V2 vendor/admin data
|
||||
command found in the NVMe package.
|
||||
- NVMe-P1 OS kernel baseline:
|
||||
- status: QA green on M02.
|
||||
- script: `scripts/run-nvme-os-smoke.sh`.
|
||||
- #QA assignment:
|
||||
`internal/docs/qa-assignments/nvme-p1-os-smoke-validation.md`.
|
||||
- #QA evidence:
|
||||
- basic OS path PASS on M02,
|
||||
- 60s fio PASS on M02,
|
||||
- loopback 4 KiB fio used inline writes only,
|
||||
- no test NQN or process residue after cleanup.
|
||||
- build a repeatable `nvme connect -> mkfs -> mount -> fio/checksum ->
|
||||
disconnect` script.
|
||||
- dynamic ports only.
|
||||
- no stale sessions or target processes.
|
||||
- NVMe-P2 in-capsule / R2T performance path:
|
||||
- status: QA green on M02 with host-specific classification.
|
||||
- target now reports transport counters in `blockvolume.log` on close:
|
||||
inline writes, R2T writes, H2C/C2H PDU counts, and read/write/flush
|
||||
command counts.
|
||||
- P1 observation: Linux `fio --bs=4k` used inline writes exclusively on
|
||||
M02 (`r2t_writes=0`).
|
||||
- P2 observation: Linux kernel 6.17.0-19 on M02 did not trigger R2T even
|
||||
for `fio --bs=128k` or `dd bs=1M`; all writes were fragmented into
|
||||
inline/in-capsule transfers.
|
||||
- #QA assignment:
|
||||
`internal/docs/qa-assignments/nvme-p2-inline-r2t-validation.md`.
|
||||
- prove whether Linux uses inline data for small writes.
|
||||
- run 128 KiB+ profiles to force or classify the R2T path.
|
||||
- add visible counters or artifacts for inline vs R2T writes.
|
||||
- follow-up:
|
||||
- R2T requires a different initiator/profile or target-side test knob;
|
||||
current M02 kernel behavior is not a product failure.
|
||||
- compare iSCSI and NVMe only under labelled network/backend conditions.
|
||||
- NVMe-P3 ANA identity and log page:
|
||||
- status: QA green on M02 at `d330e89`.
|
||||
- provider: `core/frontend/nvme.ANAProvider`.
|
||||
- product wiring: `cmd/blockvolume` derives ANA state from the same
|
||||
frontend projection used by iSCSI ALUA.
|
||||
- log page: admin Get Log Page `0x0c` returns one ANA group when a
|
||||
provider is configured.
|
||||
- mapping:
|
||||
- frontend Healthy => optimized,
|
||||
- superseded healthy / idle supporting path => non-optimized,
|
||||
- recovering => ANA change,
|
||||
- degraded / identity mismatch => inaccessible.
|
||||
- guard: Identify Controller / Namespace ANA fields remain zero without a
|
||||
provider.
|
||||
- P3-C behavior: with a provider, Identify Controller advertises ANA,
|
||||
Identify Namespace carries the provider's ANA group, and Get Log Page ANA
|
||||
reports the same group/state.
|
||||
- OAES ANA Change Notice remains off; no async event producer exists yet.
|
||||
- #QA assignment:
|
||||
`internal/docs/qa-assignments/nvme-p3-ana-log-validation.md`.
|
||||
- #QA evidence:
|
||||
- ANA log `group_id=1`, `state=0x01`, `nsid=1`,
|
||||
- Identify Controller `cmic=0x8`, `anagrpmax=1`, `nanagrpid=1`,
|
||||
- Identify Namespace `anagrpid=1`,
|
||||
- no `nvme_parse_ana_log` kernel warning,
|
||||
- mkfs/mount/checksum PASS after ANA advertisement is enabled.
|
||||
- NVMe-P4 multipath and mounted failover:
|
||||
- status: fully QA green on M02 at `e1e0e0c`.
|
||||
- #design:
|
||||
`internal/docs/ref/nvme-p4-multipath-failover-design.md`.
|
||||
- #QA assignment:
|
||||
`internal/docs/qa-assignments/nvme-p4-multipath-lab-validation.md`.
|
||||
- reach the iSCSI P6 bar for NVMe multipath.
|
||||
- Test 1/2 discovery and native grouping:
|
||||
- status: QA green on M02 at `a5ef1a5`.
|
||||
- script: `scripts/run-nvme-multipath-smoke.sh`.
|
||||
- evidence:
|
||||
- run ID `20260507T161800Z-test`,
|
||||
- two NVMe/TCP paths registered immediately,
|
||||
- native Linux multipath exposed one namespace device,
|
||||
- ANA log `group_id=1`, `state=0x01 optimized`, `nsid=1`,
|
||||
- identity `nguid=24634c35194743419febbb18e06446be`,
|
||||
`eui64=24634c3519474341`, `anagrpid=1`,
|
||||
- final line:
|
||||
`[nvme-mpath] PASS: two NVMe/TCP paths expose one ANA-aware namespace`.
|
||||
- decision: single ANA group is sufficient for the current two-path
|
||||
native multipath identity model.
|
||||
- mounted failover:
|
||||
- status: QA green on M02 at `e1e0e0c`.
|
||||
- script: `scripts/run-nvme-mounted-failover-smoke.sh`.
|
||||
- local guard:
|
||||
- metadata-only standby NVMe path continues to reject I/O before
|
||||
promotion,
|
||||
- after ANA state becomes optimized, the same session can pass I/O to
|
||||
the backend.
|
||||
- #QA evidence:
|
||||
- run ID `20260507T170000Z-nvme-p4-mounted-failover`,
|
||||
- two TCP paths registered and Linux native multipath merged them to
|
||||
`/dev/nvme1n1`,
|
||||
- mounted ext4 workload survived active r1 kill,
|
||||
- r2 promoted to `Epoch=2`, `AuthorityRole=primary`,
|
||||
`FrontendPrimaryReady=true`,
|
||||
- `pre.bin` checksum remained OK after failover,
|
||||
- `post.bin` write/read/verify succeeded after failover,
|
||||
- cleanup left no test NQN and no blockmaster/blockvolume process.
|
||||
- NVMe-P5 CSI integration:
|
||||
- status: QA green on `frontend/nvme-ana-parity-plan@8e0a28f`.
|
||||
- latest QA:
|
||||
- red at `622fae7`: StorageClass rendered `protocol: nvme`, but
|
||||
lifecycle intent had no protocol and generated blockvolume still used
|
||||
iSCSI args.
|
||||
- red at `a1d5201`: live StorageClass carried both protocol keys, but
|
||||
persisted lifecycle JSON still had no `protocol`; current source has
|
||||
protocol on CSI/RPC/lifecycle, so the harness now gates component
|
||||
`--version` output to catch stale K8s images before protocol checks.
|
||||
- green at `69a1d20`: Test 1 NVMe dynamic PVC passed after rebuilt and
|
||||
k3s-imported images; lifecycle persisted `protocol: "nvme"` and
|
||||
launcher emitted NVMe args only.
|
||||
- green at `8e0a28f`: Test 2 default iSCSI regression passed; all three
|
||||
version gates matched HEAD, lifecycle persisted `protocol: "iscsi"`,
|
||||
generated manifest used iSCSI args only, and cleanup left no iSCSI or
|
||||
NVMe residue.
|
||||
- current fix: prefer product-scoped
|
||||
`sw-block.seaweedfs.com/protocol`, keep `protocol` as compatibility,
|
||||
delete stale cluster-scoped StorageClass before apply, capture
|
||||
`storageclass.live.yaml`, and record `--version` for blockmaster,
|
||||
blockcsi, and generated blockvolume before judging launcher output.
|
||||
- allow StorageClass protocol selection without changing the app.
|
||||
- default StorageClass path stays iSCSI.
|
||||
- `parameters.sw-block.seaweedfs.com/protocol: nvme` selects NVMe target
|
||||
facts end-to-end:
|
||||
- CSI CreateVolume records protocol in lifecycle intent,
|
||||
- master lifecycle RPC carries protocol,
|
||||
- launcher renders `blockvolume` with `--nvme-listen`,
|
||||
`--nvme-subsysnqn`, and `--nvme-ns`,
|
||||
- CSI ControllerPublish returns `protocol=nvme`, `nvmeAddr`, and `nqn`,
|
||||
- CSI NodeStage uses `nvme connect`, formats/mounts the NVMe namespace,
|
||||
and disconnects by NQN on NodeUnstage.
|
||||
- K8s harness:
|
||||
- script: `scripts/run-k8s-alpha-nvme.sh`,
|
||||
- underlying env knob: `SW_BLOCK_FRONTEND_PROTOCOL=nvme`,
|
||||
- dynamic PVC/app manifest remains unchanged except injected
|
||||
StorageClass parameter.
|
||||
- #QA assignment:
|
||||
`internal/docs/qa-assignments/nvme-p5-csi-protocol-selection-validation.md`.
|
||||
- platform lesson:
|
||||
- stale k3s images cost multiple lab rounds; TestOps pin-build/import
|
||||
should make build, k3s image import, digest capture, and component
|
||||
version verification one required step for future release gates.
|
||||
- NVMe-P6 RoCE / network performance matrix:
|
||||
- status: deferred to future network/performance plan.
|
||||
- correctness gates are green; RoCE is no longer part of protocol
|
||||
readiness closure.
|
||||
|
||||
- Close bar for the planning slice:
|
||||
- audit table exists,
|
||||
- next code task has a red test or lab reproduction,
|
||||
- no ANA or performance claim is enabled before matching host evidence.
|
||||
|
||||
- QA/tooling:
|
||||
- protocol assignments remain as historical evidence under
|
||||
`internal/docs/qa-assignments/`.
|
||||
- future protocol changes should update the runner-native release gate rather
|
||||
than adding manual-only QA instructions.
|
||||
|
||||
## Current Active Milestone: V2 Parity And Hardening Backlog
|
||||
|
||||
- Goal:
|
||||
- keep iSCSI/NVMe protocol readiness protected by the release gate while
|
||||
moving active development to remaining V2 parity, product hardening, and
|
||||
TestOps platform work.
|
||||
|
||||
- Work buckets:
|
||||
- V2 parity audit:
|
||||
- compare the old `weed/storage/blockvol` scenario corpus against current
|
||||
V3 capabilities,
|
||||
- classify each gap as already covered by the release gate, still missing,
|
||||
intentionally deferred, or rejected with product reason.
|
||||
- availability/recovery hardening:
|
||||
- replica return and reintegration,
|
||||
- RF2/RF3 rebuild and failover matrices,
|
||||
- WAL retention and flow-control pressure,
|
||||
- longer soak and failure-injection runs.
|
||||
- Kubernetes/operator hardening:
|
||||
- durable blockvolume state beyond throwaway alpha defaults,
|
||||
- operator/controller lifecycle,
|
||||
- multi-node attach and non-loopback frontend addressing.
|
||||
- TestOps platform:
|
||||
- keep product-owned scenarios in this repo,
|
||||
- move repeated primitives into the standalone runner,
|
||||
- use native suite/run-control/validate-bundle for release evidence,
|
||||
- explore controller/agent mode separately from the open SSH runner path.
|
||||
|
||||
- Close bar for the next planning slice:
|
||||
- a V2 parity matrix exists with explicit disposition per feature/scenario,
|
||||
- at least one non-protocol hardening gate is runner-native and repeatable,
|
||||
- protocol release gate remains green after unrelated hardening changes.
|
||||
|
||||
## Cross-Cutting Technical Rules
|
||||
|
||||
- Protocol code must not decide authority.
|
||||
@@ -521,6 +828,18 @@ References:
|
||||
- Prefer scripts or TestOps scenarios over manual command sequences.
|
||||
- Manual testing is allowed for first reproduction, but convert the result into
|
||||
a repeatable script or scenario.
|
||||
- Keep default `go test` focused on unit/component coverage.
|
||||
- Local binary wiring tests that build product binaries, spawn
|
||||
`blockmaster`/`blockvolume`, and use loopback protocol clients must use the
|
||||
explicit `subprocess` build tag. These are not m01/m02 lab integration tests.
|
||||
- Linux OS/K8s/lab tests that use `iscsiadm`, `nvme-cli`, kernel initiators,
|
||||
mounts, `sudo`, or m01/m02 cleanup state belong in runner-native TestOps
|
||||
scenarios, not default `go test` and not the local `subprocess` tag.
|
||||
- When a subprocess or runner integration test fails, first ask whether its
|
||||
assertion can be moved down to a component seam such as authority, engine
|
||||
projection, frontend protocol adapter, lifecycle rendering, or
|
||||
ready-assignment handling. Keep only binary wiring, real OS frontend I/O,
|
||||
process lifecycle, and lab cleanup in the runner layer.
|
||||
- QA report must include:
|
||||
- branch and commit,
|
||||
- command,
|
||||
@@ -534,8 +853,8 @@ References:
|
||||
|
||||
- Use milestone PRs, not one PR per tiny fix.
|
||||
- Target one or two PRs per day at most.
|
||||
- For the current active milestone, keep iSCSI-P2 local tests and required
|
||||
protocol fixes in one coherent PR if possible.
|
||||
- For the current active milestone, keep parity matrix updates, non-protocol
|
||||
hardening gates, and runner scenario changes grouped by reviewable outcome.
|
||||
- Split OS/K8s harness work only if it becomes too large to review cleanly.
|
||||
|
||||
## Finish Action
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
# QA Assignment: NVMe P1 OS Smoke Validation
|
||||
|
||||
Status: ready for QA.
|
||||
Branch: `frontend/nvme-ana-parity-plan`.
|
||||
Scope: first real Linux kernel NVMe/TCP initiator gate for V3.
|
||||
|
||||
## Goal
|
||||
|
||||
- Prove the current NVMe-oF frontend can survive a real OS path:
|
||||
`nvme connect -> mkfs.ext4 -> mount -> checksum write/read -> disconnect`.
|
||||
- Produce artifacts good enough to decide whether NVMe-P2/P3 work starts from
|
||||
a working baseline or from a protocol bug.
|
||||
- Keep this as correctness evidence only. No performance claim.
|
||||
|
||||
## Preconditions
|
||||
|
||||
- Linux host with:
|
||||
- `nvme-cli`,
|
||||
- loadable `nvme_tcp` kernel module,
|
||||
- `mkfs.ext4`,
|
||||
- `mount`,
|
||||
- `sha256sum`,
|
||||
- sudo access.
|
||||
- `fio` installed only for Test 2.
|
||||
- Go installed unless `SW_BLOCK_BIN_DIR` points at prebuilt `blockmaster` and
|
||||
`blockvolume` binaries.
|
||||
- No active sw-block NVMe sessions before the run.
|
||||
|
||||
## Test 1: Basic OS Path
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p1-basic" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
SW_BLOCK_NVME_ITERATIONS=1 \
|
||||
SW_BLOCK_NVME_STRESS=none \
|
||||
bash scripts/run-nvme-os-smoke.sh "$PWD"
|
||||
```
|
||||
|
||||
Expected final line:
|
||||
|
||||
```text
|
||||
[nvme-os] PASS: 1 x nvme connect mkfs mount write/read disconnect
|
||||
```
|
||||
|
||||
## Test 2: FIO Sanity
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p1-fio" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
SW_BLOCK_NVME_ITERATIONS=1 \
|
||||
SW_BLOCK_NVME_STRESS=fio \
|
||||
SW_BLOCK_NVME_FIO_RUNTIME=60 \
|
||||
SW_BLOCK_NVME_FIO_SIZE=128m \
|
||||
bash scripts/run-nvme-os-smoke.sh "$PWD"
|
||||
```
|
||||
|
||||
Expected final line:
|
||||
|
||||
```text
|
||||
[nvme-os] PASS: 1 x nvme connect mkfs mount write/read disconnect
|
||||
```
|
||||
|
||||
## Acceptance
|
||||
|
||||
- `run.log` contains the final PASS line.
|
||||
- `nvme-connect.iter1.log`, `nvme-id-ctrl.iter1.txt`, and
|
||||
`nvme-id-ns.iter1.txt` exist.
|
||||
- `sha256.iter1.log` reports `OK`.
|
||||
- Test 2 includes `fio.iter1.log` with `err= 0` or no fio error.
|
||||
- `nvme-list-subsys.final.json` does not contain the test NQN.
|
||||
- `nvme-list-subsys.after.json` does not contain the test NQN.
|
||||
- `processes.after.txt` has no live `blockmaster` or `blockvolume` process
|
||||
from this run.
|
||||
- `blockvolume.log` has no NVMe session panic and no repeated protocol errors.
|
||||
- `blockvolume.log` contains one `nvme: stats ...` line with non-zero
|
||||
`writes`.
|
||||
- Report whether the host used `inline_writes` or `r2t_writes` for the
|
||||
workload. This is evidence for NVMe-P2, not a pass/fail performance claim.
|
||||
|
||||
## Evidence To Report
|
||||
|
||||
- branch and commit SHA,
|
||||
- host distro/kernel,
|
||||
- `nvme version`,
|
||||
- exact command,
|
||||
- artifact root,
|
||||
- final PASS or failure line,
|
||||
- `sha256.iter1.log`,
|
||||
- fio summary for Test 2,
|
||||
- final `nvme list-subsys -o json` state,
|
||||
- final `nvme: stats ...` line from `blockvolume.log`,
|
||||
- cleanup state.
|
||||
|
||||
## Non-Claims
|
||||
|
||||
- This is not ANA.
|
||||
- This is not multipath.
|
||||
- This is not CSI.
|
||||
- This is not RoCE or performance evidence.
|
||||
- This is not a replacement for the later NVMe-P2 in-capsule/R2T audit.
|
||||
@@ -0,0 +1,109 @@
|
||||
# QA Assignment: NVMe P2 Inline / R2T Validation
|
||||
|
||||
Status: ready for QA.
|
||||
Branch: `frontend/nvme-ana-parity-plan`.
|
||||
Scope: classify Linux NVMe/TCP write transport behavior against V3.
|
||||
|
||||
## Goal
|
||||
|
||||
- Confirm small writes use in-capsule inline data.
|
||||
- Force a larger write profile that exceeds the advertised 32 KiB
|
||||
`MaxH2CDataLength` / `IOCCSZ` inline payload and therefore exercises
|
||||
R2T/H2CData.
|
||||
- Treat this as transport-path classification, not a performance claim.
|
||||
|
||||
## Preconditions
|
||||
|
||||
- Same host requirements as `nvme-p1-os-smoke-validation.md`.
|
||||
- Use current branch HEAD, not the earlier P1-only commit. The current script
|
||||
exposes `SW_BLOCK_NVME_FIO_BS`, `SW_BLOCK_NVME_DD_BS`, and
|
||||
`SW_BLOCK_NVME_DD_COUNT`.
|
||||
|
||||
## Test 1: Inline Baseline
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p2-inline" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
SW_BLOCK_NVME_ITERATIONS=1 \
|
||||
SW_BLOCK_NVME_STRESS=fio \
|
||||
SW_BLOCK_NVME_FIO_RUNTIME=30 \
|
||||
SW_BLOCK_NVME_FIO_SIZE=128m \
|
||||
SW_BLOCK_NVME_FIO_BS=4k \
|
||||
bash scripts/run-nvme-os-smoke.sh "$PWD"
|
||||
```
|
||||
|
||||
Expected:
|
||||
|
||||
- final PASS line,
|
||||
- `blockvolume.log` stats show non-zero `inline_writes`,
|
||||
- `r2t_writes=0` is acceptable for this test.
|
||||
|
||||
## Test 2: R2T Candidate
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p2-r2t" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
SW_BLOCK_NVME_ITERATIONS=1 \
|
||||
SW_BLOCK_NVME_STRESS=fio \
|
||||
SW_BLOCK_NVME_FIO_RUNTIME=60 \
|
||||
SW_BLOCK_NVME_FIO_SIZE=128m \
|
||||
SW_BLOCK_NVME_FIO_BS=128k \
|
||||
bash scripts/run-nvme-os-smoke.sh "$PWD"
|
||||
```
|
||||
|
||||
Expected:
|
||||
|
||||
- final PASS line,
|
||||
- fio exits with `err= 0`,
|
||||
- `blockvolume.log` stats show non-zero `r2t_writes`,
|
||||
- `h2c_pdus` and `h2c_bytes` are non-zero,
|
||||
- no repeated NVMe protocol errors.
|
||||
|
||||
## Fallback If Test 2 Still Uses Inline Only
|
||||
|
||||
Run a larger direct-write profile:
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p2-r2t-dd" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
SW_BLOCK_NVME_ITERATIONS=1 \
|
||||
SW_BLOCK_NVME_STRESS=dd \
|
||||
SW_BLOCK_NVME_DD_BS=1M \
|
||||
SW_BLOCK_NVME_DD_COUNT=32 \
|
||||
bash scripts/run-nvme-os-smoke.sh "$PWD"
|
||||
```
|
||||
|
||||
If both 128 KiB fio and 1 MiB dd still report `r2t_writes=0`, report that as
|
||||
a host/initiator behavior finding. Do not fail the product solely for that; it
|
||||
means the Linux initiator did not choose the R2T path under these profiles.
|
||||
|
||||
## Acceptance
|
||||
|
||||
- At least one run proves inline writes with non-zero `inline_writes`.
|
||||
- At least one run either:
|
||||
- proves R2T with non-zero `r2t_writes`, `h2c_pdus`, and `h2c_bytes`, or
|
||||
- explicitly reports that this host did not trigger R2T under the tested
|
||||
larger profiles.
|
||||
- All runs clean up:
|
||||
- no test NQN in final `nvme list-subsys -o json`,
|
||||
- no stray `blockmaster` / `blockvolume` processes.
|
||||
|
||||
## Evidence To Report
|
||||
|
||||
- branch and commit SHA,
|
||||
- host distro/kernel,
|
||||
- `nvme version`,
|
||||
- exact commands,
|
||||
- artifact roots,
|
||||
- final PASS or failure lines,
|
||||
- fio or dd summaries,
|
||||
- final `nvme: stats ...` lines from every `blockvolume.log`,
|
||||
- cleanup state.
|
||||
|
||||
## Non-Claims
|
||||
|
||||
- This is not a benchmark.
|
||||
- This is not ANA.
|
||||
- This is not multipath or failover.
|
||||
- This is not CSI.
|
||||
- This is not RoCE.
|
||||
@@ -0,0 +1,91 @@
|
||||
# QA Assignment: NVMe P3 ANA Identify / Log Validation
|
||||
|
||||
Status: ready for QA.
|
||||
Branch: `frontend/nvme-ana-parity-plan`.
|
||||
Scope: first real Linux `nvme-cli` validation of V3 ANA Identify fields plus
|
||||
ANA log page.
|
||||
|
||||
## Goal
|
||||
|
||||
- Prove a real Linux host can explicitly read NVMe ANA log page `0x0c` from
|
||||
`blockvolume`.
|
||||
- Prove Identify Controller and Identify Namespace advertise ANA only after the
|
||||
log page and product state provider are wired.
|
||||
- Confirm the target reports one valid ANA group with a non-zero group id,
|
||||
namespace count `1`, the expected NSID, and a recognized ANA state.
|
||||
- This is not a multipath claim. It only validates the single-path primary
|
||||
state and Identify/log consistency.
|
||||
|
||||
## Preconditions
|
||||
|
||||
- Same host requirements as `nvme-p1-os-smoke-validation.md`.
|
||||
- `python3` is required for parsing the raw ANA log.
|
||||
- `nvme-cli` must support:
|
||||
|
||||
```bash
|
||||
nvme get-log /dev/<device> -i 0x0c -l 40 -b
|
||||
```
|
||||
|
||||
## Test 1: Basic ANA Log Capture
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p3-ana" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
SW_BLOCK_NVME_ITERATIONS=1 \
|
||||
SW_BLOCK_NVME_STRESS=none \
|
||||
SW_BLOCK_NVME_COLLECT_ANA=1 \
|
||||
bash scripts/run-nvme-os-smoke.sh "$PWD"
|
||||
```
|
||||
|
||||
Expected final line:
|
||||
|
||||
```text
|
||||
[nvme-os] PASS: 1 x nvme connect mkfs mount write/read disconnect
|
||||
```
|
||||
|
||||
## Acceptance
|
||||
|
||||
- `run.log` contains:
|
||||
- `collect_ana=1`,
|
||||
- the final PASS line.
|
||||
- `nvme-ana-log.iter1.bin` exists and is 40 bytes.
|
||||
- `nvme-ana-log.iter1.summary` exists and contains:
|
||||
- `ana_group_count=1`,
|
||||
- `ana_group_id=1`,
|
||||
- `ana_nsid_count=1`,
|
||||
- `ana_state=0x01 optimized` for the single primary path,
|
||||
- `ana_nsid=1`.
|
||||
- `nvme-id-ctrl.iter1.txt` and `nvme-id-ns.iter1.txt` are captured.
|
||||
- Identify ANA advertisement is on and consistent with the log page:
|
||||
- controller `cmic` shows ANA support,
|
||||
- controller `anacap` is non-zero,
|
||||
- controller `anagrpmax=1`,
|
||||
- controller `nanagrpid=1`,
|
||||
- namespace `anagrpid` matches `ana_group_id` from
|
||||
`nvme-ana-log.iter1.summary`.
|
||||
- OAES ANA Change Notice must remain off unless an async event producer is
|
||||
implemented. Do not fail because OAES is zero.
|
||||
- Cleanup state is the same as P1:
|
||||
- final subsystem list does not contain the test NQN,
|
||||
- no `blockmaster` / `blockvolume` processes from this run remain.
|
||||
|
||||
## Evidence To Report
|
||||
|
||||
- branch and commit SHA,
|
||||
- host distro/kernel,
|
||||
- `nvme version`,
|
||||
- exact command,
|
||||
- artifact root,
|
||||
- final PASS or failure line,
|
||||
- `nvme-ana-log.iter1.summary`,
|
||||
- relevant `nvme id-ctrl` / `nvme id-ns` ANA lines,
|
||||
- final `nvme: stats ...` line from `blockvolume.log`,
|
||||
- cleanup state.
|
||||
|
||||
## Non-Claims
|
||||
|
||||
- This is not Linux NVMe multipath.
|
||||
- This is not mounted failover.
|
||||
- This does not validate ANA Change Notice events.
|
||||
- This is not Kubernetes CSI.
|
||||
- This is not a performance test.
|
||||
@@ -0,0 +1,150 @@
|
||||
# QA Assignment: NVMe P4 Multipath Lab Validation
|
||||
|
||||
Status: Test 1/2/3 QA green.
|
||||
Branch: `frontend/nvme-ana-parity-plan`.
|
||||
Scope: real Linux NVMe/TCP two-path and native multipath validation.
|
||||
|
||||
## Goal
|
||||
|
||||
- Validate that Linux can connect two NVMe/TCP paths for one V3 volume.
|
||||
- Determine whether native NVMe multipath groups those paths.
|
||||
- Do not claim mounted failover until the dedicated failover test passes.
|
||||
|
||||
## Preconditions
|
||||
|
||||
- Linux host with:
|
||||
- `nvme-cli`,
|
||||
- `nvme_tcp`,
|
||||
- native NVMe multipath enabled or explicitly reported disabled,
|
||||
- `mkfs.ext4`,
|
||||
- `mount`,
|
||||
- `sha256sum`,
|
||||
- sudo access.
|
||||
- Record:
|
||||
- distro/kernel,
|
||||
- `nvme version`,
|
||||
- `cat /sys/module/nvme_core/parameters/multipath` if present,
|
||||
- relevant `dmesg` warnings after the run.
|
||||
|
||||
## Test 1: Two-Path Discovery
|
||||
|
||||
Status: PASS on `frontend/nvme-ana-parity-plan@a5ef1a5`.
|
||||
|
||||
Expected script shape:
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p4-two-path" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
bash scripts/run-nvme-multipath-smoke.sh "$PWD"
|
||||
```
|
||||
|
||||
Expected:
|
||||
|
||||
- two NVMe/TCP portals connect for the same test volume,
|
||||
- `nvme list-subsys -o json` shows both paths,
|
||||
- both paths expose the same NGUID / EUI-64 / NSID,
|
||||
- ANA log can be read without kernel warning,
|
||||
- cleanup disconnects both paths.
|
||||
|
||||
Evidence:
|
||||
|
||||
- `nvme list`.
|
||||
- `nvme list-subsys -o json`.
|
||||
- `nvme id-ctrl` per path if addressable.
|
||||
- `nvme id-ns` per path if addressable.
|
||||
- ANA log summary per path.
|
||||
- `dmesg` delta for `nvme_parse_ana_log`, reset, or I/O errors.
|
||||
- final line:
|
||||
`[nvme-mpath] PASS: two NVMe/TCP paths expose one ANA-aware namespace`.
|
||||
|
||||
Observed evidence:
|
||||
|
||||
- run ID: `20260507T161800Z-test`.
|
||||
- `wait_nvme_paths: ok at iter=1 count=2`.
|
||||
- `nvme_namespace_devices=1`.
|
||||
- ANA log: `group_count=1`, `group_id=1`, `state=0x01 optimized`,
|
||||
`nsid=1`.
|
||||
- identity: `nguid=24634c35194743419febbb18e06446be`,
|
||||
`eui64=24634c3519474341`, `anagrpid=1`.
|
||||
- cleanup: clean disconnect, `EXIT=0`.
|
||||
|
||||
## Test 2: Native Multipath Grouping
|
||||
|
||||
Status: PASS with Test 1 on `a5ef1a5`.
|
||||
|
||||
Expected:
|
||||
|
||||
- If native NVMe multipath is enabled:
|
||||
- host presents one logical namespace with multiple paths, or
|
||||
- QA records why Linux did not group them.
|
||||
- If native NVMe multipath is disabled:
|
||||
- report disabled state and stop here; do not fail product correctness.
|
||||
|
||||
Evidence:
|
||||
|
||||
- `/sys/module/nvme_core/parameters/multipath`.
|
||||
- `nvme list-subsys -o json`.
|
||||
- `/sys/class/nvme-subsystem/*` path data if available.
|
||||
|
||||
## Test 3: Mounted Failover
|
||||
|
||||
Status: PASS on `frontend/nvme-ana-parity-plan@e1e0e0c`.
|
||||
|
||||
Command:
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p4-mounted-failover" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
bash scripts/run-nvme-mounted-failover-smoke.sh "$PWD"
|
||||
```
|
||||
|
||||
Expected:
|
||||
|
||||
- mount through the multipath namespace,
|
||||
- pre-failover checksum write/read,
|
||||
- kill active path,
|
||||
- authority/ANA state moves,
|
||||
- post-failover read/write succeeds,
|
||||
- old primary rejects stale writes,
|
||||
- cleanup leaves no NVMe connections or target processes.
|
||||
|
||||
Acceptance:
|
||||
|
||||
- final line:
|
||||
`[nvme-failover] PASS: mounted NVMe multipath workload read/wrote through r1->r2 failover`.
|
||||
- `pre-check-after-failover.log` reports `/pre.bin: OK`.
|
||||
- `post-check.log` reports `/post.bin: OK`.
|
||||
- `status-r2-primary.json` shows r2 primary at epoch `>=2`.
|
||||
- `nvme-list-subsys.final.json` has no test NQN.
|
||||
- `processes.after.txt` has no live `blockmaster` or `blockvolume`.
|
||||
|
||||
Observed evidence:
|
||||
|
||||
- run ID: `20260507T170000Z-nvme-p4-mounted-failover`.
|
||||
- two TCP paths registered and Linux native multipath merged them to
|
||||
`/dev/nvme1n1`.
|
||||
- `mkfs.ext4`, mount, pre-failover write, and SHA256 capture completed before
|
||||
failure injection.
|
||||
- active r1 was killed; r2 promoted to `Epoch=2`, `AuthorityRole=primary`,
|
||||
`FrontendPrimaryReady=true`.
|
||||
- `pre-check-after-failover.log` reported `/pre.bin: OK`.
|
||||
- `post-check.log` reported `/post.bin: OK`.
|
||||
- final cleanup disconnected the test NQN and left no
|
||||
`blockmaster`/`blockvolume` process.
|
||||
|
||||
Failure evidence:
|
||||
|
||||
- `blockvolume-r1.log`, `blockvolume-r2.log`, `blockmaster.log`.
|
||||
- `nvme-list-subsys.before-failover.json`.
|
||||
- `nvme-list-subsys.after-failover.json`.
|
||||
- `path-summary.before-failover.txt`.
|
||||
- `path-summary.after-failover.txt`.
|
||||
- `dmesg` delta if the script captures one or if QA observes a kernel error.
|
||||
|
||||
## Non-Claims
|
||||
|
||||
- No CSI.
|
||||
- No RoCE.
|
||||
- No performance claim.
|
||||
- No long-running HA claim.
|
||||
- No OAES ANA Change Notice claim.
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
# QA Assignment: NVMe P5 CSI Protocol Selection
|
||||
|
||||
Branch: `frontend/nvme-ana-parity-plan`.
|
||||
|
||||
Status: QA green at `8e0a28f`.
|
||||
|
||||
Scope: prove Kubernetes dynamic provisioning can select the NVMe frontend with
|
||||
the same PVC/app smoke shape used by alpha iSCSI. This is a CSI integration
|
||||
gate, not a new NVMe protocol gate.
|
||||
|
||||
## Preconditions
|
||||
|
||||
- Host: M02 k3s lab or equivalent single-node k3s host.
|
||||
- Required host tools:
|
||||
- `kubectl`,
|
||||
- `nvme-cli`,
|
||||
- loadable `nvme_tcp`,
|
||||
- Docker image build/load path for `sw-block:local` and
|
||||
`sw-block-csi:local`.
|
||||
- Rebuild both images from the branch under test before running.
|
||||
- For k3s, use the pinned build/import path before running:
|
||||
|
||||
```bash
|
||||
SW_BLOCK_IMPORT_K3S=1 \
|
||||
SW_BLOCK_ARTIFACT_DIR=/mnt/smb/work/share/g15d-k8s/pin-build-$(date -u +%Y%m%dT%H%M%SZ) \
|
||||
bash scripts/build-alpha-images.sh "$PWD"
|
||||
```
|
||||
|
||||
The scripts gate `blockmaster`, `blockcsi`, and generated `blockvolume`
|
||||
`--version` output against `git HEAD` to catch stale runtime images.
|
||||
- When a pin-build artifact exists, pass it into Test 1 and Test 2 with:
|
||||
|
||||
```bash
|
||||
export SW_BLOCK_ALPHA_IMAGES_ENV=/path/to/pin-build/alpha-images.env
|
||||
```
|
||||
|
||||
The dynamic K8s harness copies that file into each workload artifact
|
||||
directory and renders manifests from the recorded image names.
|
||||
|
||||
## Test 1: NVMe Dynamic PVC
|
||||
|
||||
QA result: PASS at `69a1d20` with rebuilt and k3s-imported images.
|
||||
|
||||
TestOps command after `alpha-images-pin-build`:
|
||||
|
||||
```bash
|
||||
go run ./cmd/sw-testops \
|
||||
--scenario nvme-p5-csi-dynamic \
|
||||
--commit "$(git rev-parse --short HEAD)" \
|
||||
--run-id nvme-p5-csi-dynamic-$(date -u +%Y%m%dT%H%M%SZ) \
|
||||
--artifact-dir "/mnt/smb/work/share/g15d-k8s/nvme-p5-csi-dynamic-$(date -u +%Y%m%dT%H%M%SZ)" \
|
||||
--param SW_BLOCK_ALPHA_IMAGES_ENV=/path/to/pin-build/alpha-images.env
|
||||
```
|
||||
|
||||
Equivalent script command:
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p5-csi-dynamic"
|
||||
SW_BLOCK_ALPHA_IMAGES_ENV="/mnt/smb/work/share/g15d-k8s/alpha-pin-build-c3a6e28/pin-build/alpha-images.env" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
bash scripts/run-k8s-alpha-nvme.sh "$PWD"
|
||||
```
|
||||
|
||||
Expected:
|
||||
|
||||
- `run.log` contains:
|
||||
- `[alpha-nvme] frontend_protocol=nvme`,
|
||||
- final line:
|
||||
`[alpha-nvme] PASS: dynamic PVC create/delete completed checksum write/read and cleanup`.
|
||||
- `dynamic-pvc-pod.rendered.yaml` contains:
|
||||
- `sw-block.seaweedfs.com/protocol: "nvme"` under the StorageClass
|
||||
`parameters`,
|
||||
- `protocol: "nvme"` under the StorageClass `parameters`.
|
||||
- `storageclass.live.yaml` contains:
|
||||
- `sw-block.seaweedfs.com/protocol: nvme` or `protocol: nvme`, proving the
|
||||
live cluster-scoped StorageClass was updated before provisioning evidence is
|
||||
evaluated.
|
||||
- Image provenance:
|
||||
- `blockmaster.version.txt`, `blockcsi.version.txt`, and
|
||||
`blockvolume.version.txt` contain the branch commit under test,
|
||||
- `kube-system-imageids.txt` is present for stale-image forensics.
|
||||
- `generated-blockvolume.yaml` contains:
|
||||
- `--nvme-listen=`,
|
||||
- `--nvme-subsysnqn=`,
|
||||
- `--nvme-ns=1`,
|
||||
- no `--iscsi-listen`.
|
||||
- `lifecycle-volumes.json` contains:
|
||||
- `"protocol": "nvme"`.
|
||||
- `blockcsi-controller.log` or `blockmaster.log` contains a `CreateVolume`
|
||||
line with `protocol="nvme"`.
|
||||
- CSI node evidence:
|
||||
- `csi-node.rendered.yaml` includes `modprobe nvme_tcp`,
|
||||
- CSI node image includes `nvme-cli`.
|
||||
- Workload evidence:
|
||||
- `pod.log` shows checksum verification succeeded.
|
||||
- Cleanup:
|
||||
- `nvme-list-subsys.after-delete.json` has no
|
||||
`nqn.2026-05.io.seaweedfs` test subsystem,
|
||||
- `app-storage.after-delete.txt` shows no PVC residue,
|
||||
- `blockvolume-namespace-pods-deploys.after-delete.txt` shows no
|
||||
generated `sw-blockvolume` deployment residue,
|
||||
- `processes` are clean if separately checked.
|
||||
|
||||
## Test 2: Default iSCSI Regression
|
||||
|
||||
QA result: PASS at `8e0a28f` with rebuilt and k3s-imported images.
|
||||
|
||||
TestOps command after `alpha-images-pin-build`:
|
||||
|
||||
```bash
|
||||
go run ./cmd/sw-testops \
|
||||
--scenario nvme-p5-default-iscsi-regression \
|
||||
--commit "$(git rev-parse --short HEAD)" \
|
||||
--run-id nvme-p5-default-iscsi-$(date -u +%Y%m%dT%H%M%SZ) \
|
||||
--artifact-dir "/mnt/smb/work/share/g15d-k8s/nvme-p5-default-iscsi-$(date -u +%Y%m%dT%H%M%SZ)" \
|
||||
--param SW_BLOCK_ALPHA_IMAGES_ENV=/path/to/pin-build/alpha-images.env
|
||||
```
|
||||
|
||||
Equivalent script command:
|
||||
|
||||
```bash
|
||||
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-nvme-p5-default-iscsi-regression"
|
||||
SW_BLOCK_ALPHA_IMAGES_ENV="/mnt/smb/work/share/g15d-k8s/alpha-pin-build-c3a6e28/pin-build/alpha-images.env" \
|
||||
SW_BLOCK_ARTIFACT_DIR="/mnt/smb/work/share/g15d-k8s/${RUN_ID}" \
|
||||
bash scripts/run-k8s-alpha.sh "$PWD"
|
||||
```
|
||||
|
||||
Expected:
|
||||
|
||||
- `run.log` contains:
|
||||
- `[alpha] frontend_protocol=iscsi`,
|
||||
- final alpha PASS line.
|
||||
- `dynamic-pvc-pod.rendered.yaml` does not contain `protocol: "nvme"`.
|
||||
- `generated-blockvolume.yaml` contains `--iscsi-listen=` and `--iscsi-iqn=`.
|
||||
- Cleanup leaves no PVC, generated Deployment, iSCSI session, or NVMe test
|
||||
subsystem residue.
|
||||
|
||||
## Non-Claims
|
||||
|
||||
- Not a new ANA / native multipath gate.
|
||||
- Not mounted failover.
|
||||
- Not performance evidence.
|
||||
- Single-node k3s only.
|
||||
@@ -0,0 +1,263 @@
|
||||
# NVMe-oF / ANA Parity Plan
|
||||
|
||||
Status: active reference.
|
||||
|
||||
Goal: make NVMe-oF a second credible block frontend beside iSCSI. V2 visible
|
||||
behavior is the minimum height. V3 keeps its own authority, recovery, and
|
||||
frontend boundaries.
|
||||
|
||||
## Product Position
|
||||
|
||||
- iSCSI remains the alpha Kubernetes default until NVMe has the same OS,
|
||||
multipath, failover, and CSI evidence.
|
||||
- NVMe-oF is the performance-oriented frontend:
|
||||
- lower protocol overhead than iSCSI for some workloads,
|
||||
- standard Linux `nvme` tooling,
|
||||
- better fit for multi-queue and high-throughput network paths,
|
||||
- future RoCE path once TCP correctness is pinned.
|
||||
- Do not use NVMe to bypass storage truth:
|
||||
- protocol code must not decide authority,
|
||||
- ANA state must be derived from frontend facts produced by the V3 authority
|
||||
and replica lifecycle,
|
||||
- stale primary writes must fail closed.
|
||||
|
||||
## V2 Reference Points
|
||||
|
||||
- V2 advertises NVMe/TCP in-capsule write support:
|
||||
- Identify Controller sets `IOCCSZ = (64 + maxDataLen) / 16`,
|
||||
- `ICDOFF = 0`,
|
||||
- small writes can carry data directly in the command capsule,
|
||||
- this avoids an R2T round trip for common 4 KiB writes.
|
||||
- V2 has ANA support:
|
||||
- Identify Controller advertises ANA,
|
||||
- Identify Namespace carries an ANA group,
|
||||
- Get Log Page ANA returns group state,
|
||||
- tests cover optimized / standby / inaccessible behavior.
|
||||
- V2 has write pressure behavior:
|
||||
- `writeWithRetry` retries transient WAL-full errors,
|
||||
- WAL pressure can throttle writers before hard failure.
|
||||
- V2 has benchmark-oriented scenarios:
|
||||
- NVMe max-concurrent-write sweeps,
|
||||
- NVMe IO queue count sweeps,
|
||||
- 10.0.0.x / high-speed network paths,
|
||||
- fio-based comparison scenarios.
|
||||
|
||||
## Current V3 State
|
||||
|
||||
- Present:
|
||||
- NVMe/TCP target code under `core/frontend/nvme`,
|
||||
- IC handshake and Fabric Connect,
|
||||
- Admin and IO queue separation,
|
||||
- Identify Controller / Namespace / Namespace Descriptor List,
|
||||
- deterministic NGUID / EUI-64,
|
||||
- inline payload and R2T / H2C data path,
|
||||
- pending capsule buffering during R2T data collection,
|
||||
- one outstanding R2T per session,
|
||||
- READ / WRITE / FLUSH dispatch to `frontend.Backend`,
|
||||
- stale lineage maps to NVMe path-related status,
|
||||
- KATO / KeepAlive support,
|
||||
- unit and component tests for queue routing, large writes, pipelining, and
|
||||
cleanup.
|
||||
- Deliberately not advertised yet:
|
||||
- ANA Identify fields are pinned to zero by tests,
|
||||
- ANA Change Notices are not advertised,
|
||||
- Dataset Management / Write Zeroes are not advertised.
|
||||
- Product gaps:
|
||||
- no current NVMe alpha install path,
|
||||
- no current K8s dynamic PVC path using NVMe,
|
||||
- no current Linux `nvme connect -> mkfs -> mount -> fio -> disconnect`
|
||||
release gate,
|
||||
- no current NVMe multipath mounted failover gate,
|
||||
- no RoCE or 25 GbE claim.
|
||||
|
||||
See `nvme-v2-coverage-gap-audit.md` for the P0 classification table. The
|
||||
important correction from that audit: V2's target-side `writeWithRetry` is not
|
||||
automatically a V3 goal. V3 currently rejects target-side retry by design; any
|
||||
change there needs a separate product decision.
|
||||
|
||||
## Design Rules
|
||||
|
||||
- Standard first:
|
||||
- prefer standard NVMe/TCP in-capsule data and R2T/H2C behavior,
|
||||
- do not add a custom admin/vendor data path until the standard path is
|
||||
measured and found insufficient.
|
||||
- Advertised means implemented:
|
||||
- do not flip ANA Identify bits until Get Log Page ANA and Linux host
|
||||
behavior both pass,
|
||||
- do not advertise Dataset Management or Write Zeroes before command support
|
||||
exists.
|
||||
- Performance claims require network labels:
|
||||
- loopback numbers are correctness evidence only,
|
||||
- 1 GbE, 10.0.0.x, 25 GbE, TCP, and RoCE must be reported separately.
|
||||
- Keep iSCSI and NVMe common where possible:
|
||||
- same `frontend.Backend`,
|
||||
- same authority facts,
|
||||
- same stale-write fence,
|
||||
- same CSI volume lifecycle model,
|
||||
- protocol-specific transport only at the edge.
|
||||
|
||||
## Milestones
|
||||
|
||||
### NVMe-P0 Audit And Red Plan
|
||||
|
||||
- Goal:
|
||||
- pin the V2-to-V3 gap before code changes.
|
||||
- Tasks:
|
||||
- map V2 NVMe files and scenarios to V3 files and tests,
|
||||
- confirm what the old "control API carries data" path actually meant:
|
||||
standard in-capsule data vs custom admin/vendor shortcut,
|
||||
- document which pieces are protocol behavior, which are benchmark knobs,
|
||||
and which are V2-specific architecture,
|
||||
- create red tests for any missing protocol behavior before implementation.
|
||||
- Close bar:
|
||||
- plan table lists every V2 visible NVMe feature,
|
||||
- each item is marked present, missing, intentionally deferred, or rejected
|
||||
with product reason.
|
||||
|
||||
### NVMe-P1 OS Kernel Baseline
|
||||
|
||||
- Goal:
|
||||
- prove one real Linux host can use V3 NVMe-oF as a block device.
|
||||
- Tasks:
|
||||
- script: `nvme connect`,
|
||||
- discover device,
|
||||
- `mkfs.ext4`,
|
||||
- mount,
|
||||
- write/read checksum,
|
||||
- fio 60s,
|
||||
- unmount,
|
||||
- `nvme disconnect`,
|
||||
- no stale sessions or target processes,
|
||||
- dynamic ports only.
|
||||
- #QA:
|
||||
- run on M02 first,
|
||||
- capture `nvme list`, `nvme id-ctrl`, `nvme id-ns`, fio summary, target
|
||||
logs, and cleanup state.
|
||||
- Close bar:
|
||||
- 256 MiB target passes mkfs + fio,
|
||||
- no protocol session errors during fio,
|
||||
- cleanup leaves no NVMe connection or process residue.
|
||||
|
||||
### NVMe-P2 In-Capsule / R2T Performance Path
|
||||
|
||||
- Goal:
|
||||
- verify the fast small-write path before claiming NVMe performance upside.
|
||||
- Tasks:
|
||||
- assert Identify `IOCCSZ` and `ICDOFF` match the implementation,
|
||||
- measure whether Linux sends 4 KiB writes inline or via R2T,
|
||||
- add counters/logs for inline writes vs R2T writes,
|
||||
- run fio profiles:
|
||||
- 4 KiB randwrite, iodepth 1 and 32,
|
||||
- 128 KiB randrw,
|
||||
- sequential write/read,
|
||||
- compare iSCSI vs NVMe on the same backend and same host.
|
||||
- #design:
|
||||
- if V2 used a non-standard admin/vendor command as a data shortcut, decide
|
||||
separately whether V3 should port it. Default answer: no for public
|
||||
product path; maybe yes for internal benchmark only.
|
||||
- Close bar:
|
||||
- data path classification is visible in artifacts,
|
||||
- no performance number is published without network/backend labels.
|
||||
|
||||
### NVMe-P3 ANA Identity And Log Page
|
||||
|
||||
- Goal:
|
||||
- make ANA a real host-visible feature, not only path-related error codes.
|
||||
- Tasks:
|
||||
- add ANA provider based on V3 frontend facts,
|
||||
- Identify Controller:
|
||||
- set CMIC / ANACAP only after log support lands,
|
||||
- set ANAGRPMAX and NANAGRPID,
|
||||
- Identify Namespace:
|
||||
- set ANAGRPID,
|
||||
- Get Log Page ANA:
|
||||
- return group count,
|
||||
- return group state,
|
||||
- return namespace list,
|
||||
- increment change count when path state changes,
|
||||
- keep stale primary errors mapped to path-related status.
|
||||
- #QA:
|
||||
- run `nvme id-ctrl`, `nvme id-ns`, `nvme get-log -i 0x0c` or equivalent
|
||||
host tooling,
|
||||
- verify optimized / standby / inaccessible states.
|
||||
- Close bar:
|
||||
- Linux host observes ANA consistently,
|
||||
- no Identify field advertises a missing log behavior.
|
||||
|
||||
### NVMe-P4 Multipath And Mounted Failover
|
||||
|
||||
- Goal:
|
||||
- reach iSCSI P6-level behavior for NVMe multipath.
|
||||
- Tasks:
|
||||
- two NVMe/TCP paths to one namespace,
|
||||
- common namespace identity,
|
||||
- distinct path state,
|
||||
- Linux NVMe multipath groups one logical device,
|
||||
- mounted ext4 workload survives active path kill,
|
||||
- old primary refuses stale writes.
|
||||
- #QA:
|
||||
- mounted workload failover on M02 first,
|
||||
- later rerun across m01/M02 if lab wiring is stable.
|
||||
- Close bar:
|
||||
- pre-failover checksum survives,
|
||||
- post-failover write succeeds,
|
||||
- old primary logs stale-lineage rejection,
|
||||
- cleanup leaves no NVMe connections or processes.
|
||||
|
||||
### NVMe-P5 CSI Integration
|
||||
|
||||
- Goal:
|
||||
- allow Kubernetes users to opt into NVMe without changing the app.
|
||||
- Tasks:
|
||||
- StorageClass protocol parameter:
|
||||
- default remains iSCSI,
|
||||
- `protocol: nvme` selects NVMe path,
|
||||
- CSI ControllerPublish / NodeStage carries NVMe address and NQN,
|
||||
- CSI node runs `nvme connect` idempotently,
|
||||
- NodeUnstage disconnects only the matching NQN/device,
|
||||
- transport file records enough state for restart cleanup,
|
||||
- no residue after PVC delete.
|
||||
- #QA:
|
||||
- app writer/reader PVC demo with NVMe protocol,
|
||||
- K8s fio 60s,
|
||||
- attach/detach loop.
|
||||
- Close bar:
|
||||
- same user story as alpha iSCSI demo, protocol switched to NVMe by
|
||||
StorageClass only.
|
||||
|
||||
### NVMe-P6 RoCE / Network Performance Matrix
|
||||
|
||||
- Goal:
|
||||
- turn performance from intuition into repeatable data.
|
||||
- Tasks:
|
||||
- run 1 GbE TCP baseline,
|
||||
- run 10.0.0.x / 25 GbE TCP path,
|
||||
- run RoCE path if supported by lab and host drivers,
|
||||
- compare iSCSI vs NVMe,
|
||||
- compare walstore vs smartwal,
|
||||
- record CPU, latency, bandwidth, IOPS, queue depth, and block size.
|
||||
- #QA:
|
||||
- only run after P1-P5 correctness gates are green.
|
||||
- Close bar:
|
||||
- repeatable matrix with artifact bundle,
|
||||
- no "smartwal is faster" claim until the matrix proves it under labelled
|
||||
conditions.
|
||||
|
||||
## Open Questions
|
||||
|
||||
- Did V2 ever use a custom NVMe admin/vendor command for data, or was the
|
||||
remembered fast path standard in-capsule data?
|
||||
- P0 initial answer: no custom vendor/admin data command was found in the V2
|
||||
NVMe package; the visible fast path is standard in-capsule data.
|
||||
- Should V3 expose NVMe alpha before CSI integration, or keep it internal until
|
||||
K8s has a user-facing switch?
|
||||
- Do we want ANA before K8s NVMe, or K8s single-path NVMe before ANA?
|
||||
- Which lab path is authoritative for performance: loopback, 1 GbE LAN, 10.0.0.x,
|
||||
25 GbE, or RoCE?
|
||||
|
||||
## Immediate Next Step
|
||||
|
||||
- Start NVMe-P0.
|
||||
- No product code change until the audit table is done.
|
||||
- First code milestone after P0 should be NVMe-P1 OS kernel baseline, because a
|
||||
real Linux host catches wire behavior that in-process tests miss.
|
||||
@@ -0,0 +1,104 @@
|
||||
# NVMe ANA Technical Note
|
||||
|
||||
Status: reference for NVMe-P3/P4 work.
|
||||
|
||||
## What ANA Is
|
||||
|
||||
- ANA means Asymmetric Namespace Access.
|
||||
- It is the NVMe equivalent of iSCSI ALUA: the target tells the host which
|
||||
path to prefer for a namespace, and which paths are usable only for
|
||||
failover or not usable at all.
|
||||
- Linux NVMe multipath reads ANA information from Identify Controller,
|
||||
Identify Namespace, and the ANA log page. If those surfaces disagree, the
|
||||
host can make bad path decisions.
|
||||
|
||||
## V3 Product Meaning
|
||||
|
||||
- V3 authority decides which replica may acknowledge writes.
|
||||
- NVMe protocol code must only report frontend path facts derived from product
|
||||
state. It must not elect authority or decide replica readiness.
|
||||
- The primary serving path should report optimized access.
|
||||
- A replica path that is caught up enough for failover probing but not writable
|
||||
should report a non-writable ANA state according to the policy we choose.
|
||||
- A stale or degraded path must never report a state that lets the host send
|
||||
successful writes.
|
||||
|
||||
## Minimum Wire Surfaces
|
||||
|
||||
- Identify Controller:
|
||||
- `CMIC` must advertise ANA only when ANA is implemented.
|
||||
- `ANACAP`, `ANAGRPMAX`, and `NANAGRPID` must be non-zero only with a real
|
||||
ANA log implementation.
|
||||
- Identify Namespace:
|
||||
- `ANAGRPID` must point at the ANA group used by the namespace.
|
||||
- Get Log Page:
|
||||
- log page `0x0c` must return an ANA group descriptor for the namespace.
|
||||
- the group must include current ANA state and a change count.
|
||||
- I/O status mapping:
|
||||
- stale primary lineage maps to a path-related status, not success.
|
||||
- inaccessible / transition states must fail writes safely.
|
||||
|
||||
## Current V3 State
|
||||
|
||||
- V3 intentionally zeros ANA Identify fields today.
|
||||
- Existing tests pin that zero state so we do not advertise ANA before the log
|
||||
page and state model exist.
|
||||
- V3 already maps stale lineage to NVMe path-related status for I/O errors.
|
||||
- V3 now has an ANA provider seam and a blockvolume projection provider:
|
||||
- optimized means the frontend projection is healthy,
|
||||
- non-optimized means the path is present for probing/failover but not the
|
||||
optimized write path,
|
||||
- ANA change means recovering,
|
||||
- inaccessible means degraded, mismatched identity, or missing projection.
|
||||
- V3 now implements ANA Get Log Page `0x0c` behind the provider seam.
|
||||
- Identify ANA fields are conditional:
|
||||
- no ANA provider => all ANA Identify fields stay zero,
|
||||
- ANA provider present => Identify Controller advertises ANA and Identify
|
||||
Namespace carries the provider's ANA group.
|
||||
- OAES ANA Change Notice remains off until an async event producer exists.
|
||||
|
||||
## V2 Reference Behavior
|
||||
|
||||
- V2 has an `ANAProvider` with `ANAState()` and `ANAGroupID()`.
|
||||
- V2 Identify advertises ANA fields.
|
||||
- V2 Get Log Page `0x0c` returns a single ANA group.
|
||||
- V2 gates writes based on ANA state.
|
||||
|
||||
V3 should use V2 as the coverage inventory, not as a direct code transplant.
|
||||
V3 state must come from frontend projection facts and authority lineage, not
|
||||
from V2 role ownership.
|
||||
|
||||
## Design Risks
|
||||
|
||||
- Advertising ANA too early is worse than not supporting it: Linux may enable
|
||||
multipath policy based on incomplete data.
|
||||
- A single hard-coded group is acceptable for a first RF=2 path if the state is
|
||||
correct and the Identify limits match it. Linux validates ANA group id
|
||||
against `ANAGRPMAX` / `NANAGRPID`; for the current single-group target the
|
||||
dense group id must be `1`, not a hash-derived value.
|
||||
- ANA state changes need host-visible evidence. Unit tests alone are not
|
||||
enough; P4 must include real `nvme-cli` / Linux multipath validation.
|
||||
- Reads and writes may have different safety policy. The chosen policy must be
|
||||
explicit before code lands.
|
||||
|
||||
## Development Order
|
||||
|
||||
- P3-A: add provider interface and state mapping tests without advertising ANA.
|
||||
- status: done.
|
||||
- P3-B: implement ANA log page and keep Identify ANA fields off.
|
||||
- status: done.
|
||||
- P3-B2: wire blockvolume projection state into the ANA provider.
|
||||
- status: done.
|
||||
- P3-C: flip Identify Controller / Namespace fields only after the log page
|
||||
tests pass.
|
||||
- status: done locally; waiting for host validation at current branch HEAD.
|
||||
- P3-D: add Linux `nvme get-log` / `nvme id-ctrl` / `nvme id-ns` QA assignment.
|
||||
- P4: add two-path Linux multipath validation and mounted failover evidence.
|
||||
|
||||
## Non-Goals For P3
|
||||
|
||||
- No NVMe/RDMA claim.
|
||||
- No Kubernetes CSI protocol switch.
|
||||
- No performance claim.
|
||||
- No multi-volume namespace management.
|
||||
- No host-visible failover claim until P4 passes.
|
||||
@@ -0,0 +1,154 @@
|
||||
# NVMe P4 Multipath / Mounted Failover Design
|
||||
|
||||
Status: fully validated on M02.
|
||||
Branch: `frontend/nvme-ana-parity-plan`.
|
||||
|
||||
## Goal
|
||||
|
||||
- Bring NVMe-oF to the same frontend correctness bar that iSCSI reached in
|
||||
P6: real Linux multipath visibility first, mounted failover second.
|
||||
- Keep this as correctness work. No performance, RoCE, or Kubernetes claim is
|
||||
made by P4.
|
||||
|
||||
## Starting State
|
||||
|
||||
- P1: Linux `nvme connect -> mkfs -> mount -> checksum -> disconnect` is QA
|
||||
green on M02.
|
||||
- P3: ANA Identify fields and ANA log page are QA green on M02:
|
||||
- Identify advertises ANA only when `ANAProvider` is wired,
|
||||
- ANA log group id is dense `1`, matching `ANAGRPMAX=1` and `NANAGRPID=1`,
|
||||
- Linux accepts the controller into ANA-aware init.
|
||||
- P4: native multipath discovery and mounted failover are QA green on M02.
|
||||
|
||||
## Linux Multipath Model
|
||||
|
||||
- NVMe multipath is not `multipathd` for SCSI.
|
||||
- Linux NVMe uses native multipath in the kernel when enabled, usually via:
|
||||
- `nvme_core.multipath=Y` kernel parameter, or
|
||||
- module parameter if supported by the distro.
|
||||
- Evidence must record whether native NVMe multipath is enabled. A two-path
|
||||
test without native multipath only proves two independent controllers, not a
|
||||
usable multipath device.
|
||||
|
||||
## Identity Requirements
|
||||
|
||||
- Both paths for one volume must expose the same namespace identity:
|
||||
- same NGUID,
|
||||
- same EUI-64,
|
||||
- same NSID,
|
||||
- same SubNQN unless the host path model requires otherwise.
|
||||
- The host must be able to tell path state apart through ANA:
|
||||
- active path reports optimized,
|
||||
- non-active but valid path reports non-optimized or inaccessible according
|
||||
to the chosen policy,
|
||||
- stale/degraded path must not report optimized.
|
||||
- Current P3 uses one ANA group id (`1`) because there is one advertised group.
|
||||
P4 may need a dense group allocation policy if Linux requires different path
|
||||
states to live in distinct groups.
|
||||
|
||||
## Policy Question For First P4 Slice
|
||||
|
||||
- Option A: one ANA group per namespace.
|
||||
- simple,
|
||||
- works for single-path P3,
|
||||
- cannot represent two paths with different states in one log response.
|
||||
- Option B: one dense ANA group per path state/path.
|
||||
- required if Linux native multipath expects active and standby paths to
|
||||
report different groups,
|
||||
- `ANAGRPMAX` and `NANAGRPID` must be the dense group count,
|
||||
- every group id in the ANA log must be `<= ANAGRPMAX`.
|
||||
|
||||
P4 should start with discovery evidence before deciding. If Linux groups two
|
||||
paths with the current single group and both are optimized, that is not
|
||||
failover-ready; it is only identity proof.
|
||||
|
||||
Decision after QA on M02:
|
||||
|
||||
- Single ANA group id `1` is sufficient for the current two-path native
|
||||
multipath identity model.
|
||||
- Linux accepted:
|
||||
- one SubNQN,
|
||||
- distinct controller IDs,
|
||||
- CMIC multi-controller + ANA bits,
|
||||
- NMIC shared namespace,
|
||||
- common NGUID/EUI64,
|
||||
- ANA log group id `1`.
|
||||
- Evidence:
|
||||
- branch `frontend/nvme-ana-parity-plan`,
|
||||
- commit `a5ef1a5`,
|
||||
- run `20260507T161800Z-test`,
|
||||
- final line:
|
||||
`[nvme-mpath] PASS: two NVMe/TCP paths expose one ANA-aware namespace`.
|
||||
|
||||
## Milestones
|
||||
|
||||
### P4-A: Two-Path Discovery / Identity
|
||||
|
||||
Status: PASS on M02 at `a5ef1a5`.
|
||||
|
||||
- Start one blockmaster and two blockvolume frontends for one volume.
|
||||
- Expose two NVMe/TCP portals to the same Linux host.
|
||||
- Connect both paths.
|
||||
- Capture:
|
||||
- `nvme list`,
|
||||
- `nvme list-subsys -o json`,
|
||||
- `nvme id-ctrl`,
|
||||
- `nvme id-ns`,
|
||||
- `nvme get-log -i 0x0c`.
|
||||
- Expected:
|
||||
- both paths connect,
|
||||
- no `nvme_parse_ana_log` warning,
|
||||
- same namespace identity across both paths,
|
||||
- cleanup disconnects both paths.
|
||||
|
||||
### P4-B: Native Multipath Grouping
|
||||
|
||||
Status: PASS on M02 at `a5ef1a5`.
|
||||
|
||||
- Preconditions:
|
||||
- Linux native NVMe multipath enabled.
|
||||
- Expected:
|
||||
- host exposes one logical namespace with multiple paths, or reports a
|
||||
clearly documented reason it cannot.
|
||||
- Identify/log fields remain internally consistent.
|
||||
- Non-claim:
|
||||
- no failover yet.
|
||||
|
||||
### P4-C: Mounted Failover
|
||||
|
||||
Status: PASS on M02 at `e1e0e0c`.
|
||||
|
||||
- Mount through the native multipath namespace.
|
||||
- Write and checksum pre-failover data.
|
||||
- Kill or close the active target path.
|
||||
- Wait for authority/ANA state to move.
|
||||
- Verify:
|
||||
- pre-failover data reads back,
|
||||
- post-failover write succeeds,
|
||||
- old primary cannot acknowledge stale writes,
|
||||
- cleanup leaves no NVMe connections or processes.
|
||||
- Evidence:
|
||||
- run ID `20260507T170000Z-nvme-p4-mounted-failover`,
|
||||
- final line:
|
||||
`[nvme-failover] PASS: mounted NVMe multipath workload read/wrote through r1->r2 failover`,
|
||||
- Linux native multipath merged two TCP paths to `/dev/nvme1n1`,
|
||||
- r2 promoted to `Epoch=2` with `FrontendPrimaryReady=true`,
|
||||
- pre-failover checksum read after failover,
|
||||
- post-failover write/read/verify succeeded,
|
||||
- final cleanup removed the test NQN and target processes.
|
||||
|
||||
## Non-Goals
|
||||
|
||||
- No Kubernetes CSI protocol switch.
|
||||
- No RoCE.
|
||||
- No Windows NVMe claim.
|
||||
- No performance claim.
|
||||
- No long soak.
|
||||
- No OAES ANA Change Notice until an async event producer exists.
|
||||
|
||||
## Follow-Up Risks
|
||||
|
||||
- Longer soak is still required before any HA durability claim.
|
||||
- Kubernetes CSI protocol switching is not covered by P4.
|
||||
- RoCE and real network path behavior remain outside this milestone.
|
||||
- OAES ANA Change Notice remains off until an async event producer exists.
|
||||
@@ -0,0 +1,144 @@
|
||||
# NVMe V2 Coverage Gap Audit
|
||||
|
||||
Status: initial P0 audit.
|
||||
|
||||
Purpose: compare the mature V2 NVMe frontend behavior with the current V3
|
||||
implementation. This is a product-facing coverage audit, not a port request.
|
||||
|
||||
Rule: copy expectations first, not code. If V3 rejects a V2 behavior, the audit
|
||||
must say why.
|
||||
|
||||
## Summary
|
||||
|
||||
- V3 already has a substantial NVMe/TCP protocol core:
|
||||
- IC handshake,
|
||||
- Fabric Connect,
|
||||
- admin / IO queue separation,
|
||||
- Identify,
|
||||
- inline write payload,
|
||||
- R2T / H2C data collection,
|
||||
- interleaved Capsule Command buffering,
|
||||
- READ / WRITE / FLUSH,
|
||||
- KATO / KeepAlive,
|
||||
- error mapping for stale-lineage and closed backend.
|
||||
- The largest product gaps are not the basic wire parser. They are:
|
||||
- real Linux OS gate,
|
||||
- ANA advertisement + Get Log Page ANA,
|
||||
- NVMe multipath mounted failover,
|
||||
- CSI NodeStage / NodeUnstage NVMe path,
|
||||
- labelled performance matrix.
|
||||
- The remembered V2 high-performance path appears to be standard NVMe/TCP
|
||||
in-capsule data, not a custom vendor/admin command:
|
||||
- V2 Identify advertises `IOCCSZ`,
|
||||
- V2 sets `ICDOFF=0`,
|
||||
- small write data can ride in the Capsule Command payload,
|
||||
- no custom vendor/admin data command was found in the V2 NVMe package.
|
||||
|
||||
## Coverage Table
|
||||
|
||||
| Area | V2 behavior | V3 state | Classification | Next action |
|
||||
|---|---|---|---|---|
|
||||
| IC handshake | NVMe/TCP ICReq / ICResp with MaxH2CDataLength. | Present in `core/frontend/nvme/session.go`. | Present. | P1 OS gate should verify with Linux `nvme connect`. |
|
||||
| Fabric Connect | Admin queue Connect allocates CNTLID; IO queue Connect validates CNTLID / NQN. | Present with CNTLID and identity tests. | Present. | P1 OS gate. |
|
||||
| Queue separation | Admin and IO queues are separate TCP sessions. | Present; tests cover wrong queue opcodes and parallel queues. | Present. | Add host evidence. |
|
||||
| Number of Queues | V2 grants requested queues up to max. | Present in `admin_features.go`, capped. | Present. | Host fio with `nr_io_queues` profiles later. |
|
||||
| Identify Controller | V2 advertises broader capabilities including ANA and DSM/WriteZeroes. | V3 intentionally advertises only implemented features; ANA/DSM/WriteZeroes are zero. | Partially present by design. | P3 flips ANA only with log support. |
|
||||
| Identify Namespace | V2 includes namespace identity and ANA group. | V3 includes deterministic NGUID/EUI-64; ANAGRPID pinned zero. | Partially present by design. | P3. |
|
||||
| Namespace Descriptor List | V2 has NGUID/EUI style identity. | V3 has deterministic NGUID/EUI and tests. | Present. | P1 host `nvme id-ns` capture. |
|
||||
| In-capsule write data | V2 advertises `IOCCSZ` and `ICDOFF=0`; small writes can carry payload inline. | V3 advertises `IOCCSZ`, `ICDOFF=0`, and parser accepts inline payload. | Present but not host-measured. | P2 add inline-vs-R2T counters and fio evidence. |
|
||||
| R2T / H2C write data | V2 supports R2T and chunked H2C. | V3 supports one outstanding R2T per session and buffers interleaved capsules. | Present in component tests. | P1/P2 host large write. |
|
||||
| Large READ C2H splitting | V2 supports chunked C2H responses. | V3 has C2HData response path and large read tests. | Probably present. | P1/P2 host fio read evidence. |
|
||||
| FLUSH | V2 supports Flush to durable backend. | V3 dispatches Flush to `Backend.Sync`; test exists. | Present. | P1 fio/fsync evidence. |
|
||||
| KeepAlive / KATO | V2 accepts KATO / KeepAlive. | V3 stores KATO and responds KeepAlive; no fatal timer. | Present. | P1 host connect stability. |
|
||||
| Async Event Request | V2 parks AER. | V3 parks one AER and rejects a second slot. | Present minimal. | P3 ANA change notice may need event behavior later. |
|
||||
| Get Log Page ANA | V2 returns ANA log page. | V3 has opcode constant but admin dispatch does not serve Get Log Page. | Missing. | P3 implementation. |
|
||||
| ANA Identify advertisement | V2 advertises ANA. | V3 tests pin ANA fields to zero until log page lands. | Intentionally deferred. | P3 implementation + host verification. |
|
||||
| ANA state provider | V2 maps role to ANA optimized / standby / inaccessible. | V3 currently maps stale-lineage errors to path-related status but does not expose host-visible ANA state. | Missing product behavior. | P3. |
|
||||
| Multipath failover | V2 has NVMe failover scenarios. | V3 has no mounted NVMe multipath lab gate. | Missing product behavior. | P4. |
|
||||
| Target-side write retry | V2 retries transient WAL-full writes in target. | V3 test `t2_v2port_nvme_no_retry_test.go` explicitly rejects target-side retry. | Intentionally not ported. | Keep rejected unless product decision changes. |
|
||||
| WAL pressure throttle | V2 throttles on WAL pressure near frontend. | V3 storage layer has WAL admission/throttle; NVMe target-side throttle is not carried. | Architecture difference. | Performance/soak should observe backend pressure, not hide it in protocol. |
|
||||
| Dataset Management / Trim | V2 advertises DSM/Trim. | V3 does not advertise DSM. | Deferred. | Later storage feature, not frontend-complete blocker. |
|
||||
| Write Zeroes | V2 advertises Write Zeroes. | V3 does not advertise Write Zeroes. | Deferred. | Later storage feature. |
|
||||
| OS nvme-cli smoke | V2 has `nvme_connect` TestOps actions and scenarios. | V3 has `scripts/iterate-m01-nvme.sh`, but no release-grade P1 script. | Partial. | P1 create repeatable OS smoke. |
|
||||
| NVMe soak | V2 has `cp103-soak-nvme-1h.yaml`. | V3 no equivalent product gate. | Missing. | After P1. |
|
||||
| IO queue performance sweeps | V2 has IOQ and max-concurrent-write sweeps. | V3 has component queue tests but no product matrix. | Missing as product evidence. | P2/P6. |
|
||||
| NVMe CSI publish target | V2 TestOps can target NVMe. | V3 `ControlStatusLookup` maps NVMe frontend facts. | Partial. | P5. |
|
||||
| NVMe CSI NodeStage | V2 not directly comparable. | V3 NodeStage is still iSCSI-only; `transportNVMe` is only recognized for file parsing. | Missing. | P5. |
|
||||
| NVMe auth | V2 public evidence unclear. | V3 has no NVMe authentication story. | Deferred. | Not in current frontend-complete scope. |
|
||||
| RoCE / high-speed network | V2 scenarios reference 10.0.0.x and NVMe/RoCE-oriented performance paths. | V3 has no labelled RoCE matrix. | Missing evidence. | P6 after correctness. |
|
||||
|
||||
## Current Code Map
|
||||
|
||||
- V3 protocol core:
|
||||
- `core/frontend/nvme/session.go`
|
||||
- `core/frontend/nvme/identify.go`
|
||||
- `core/frontend/nvme/admin_features.go`
|
||||
- `core/frontend/nvme/fabric.go`
|
||||
- `core/frontend/nvme/io.go`
|
||||
- `core/frontend/nvme/target.go`
|
||||
- V3 command wiring:
|
||||
- `cmd/blockvolume/main.go` exposes `--nvme-listen`, `--nvme-subsysnqn`,
|
||||
and `--nvme-ns`.
|
||||
- V3 CSI partial wiring:
|
||||
- `core/csi/backend.go` has `ProtocolNVMe`,
|
||||
- `core/csi/master_backend.go` maps NVMe status frontends,
|
||||
- `core/csi/node.go` does not stage NVMe devices yet.
|
||||
- V2 references:
|
||||
- `weed/storage/blockvol/nvme/identify.go`,
|
||||
- `weed/storage/blockvol/nvme/admin.go`,
|
||||
- `weed/storage/blockvol/nvme/write_retry.go`,
|
||||
- `weed/storage/blockvol/testrunner/actions/nvme.go`,
|
||||
- `weed/storage/blockvol/testrunner/scenarios/internal/cp103-nvme-*.yaml`,
|
||||
- `weed/storage/blockvol/testrunner/scenarios/internal/ha-nvme-failover.yaml`.
|
||||
|
||||
## P0 Decisions
|
||||
|
||||
- In-capsule data:
|
||||
- treat as standard NVMe/TCP behavior,
|
||||
- keep it in public product path,
|
||||
- measure it before claiming performance.
|
||||
- Custom admin/vendor data path:
|
||||
- no evidence found in V2 NVMe package during this audit,
|
||||
- do not invent one for V3 without a separate design.
|
||||
- Target-side retry:
|
||||
- keep rejected for V3,
|
||||
- host/kernel retry and storage-layer backpressure are the intended owners,
|
||||
- protocol target must surface real backend errors.
|
||||
- ANA:
|
||||
- must be implemented as a complete Identify + Get Log Page + host-observed
|
||||
state set,
|
||||
- do not partially advertise.
|
||||
- CSI:
|
||||
- do not claim NVMe K8s support until NodeStage/NodeUnstage use `nvme`
|
||||
tooling and pass the same app demo as iSCSI.
|
||||
|
||||
## Next Red Tests / Harnesses
|
||||
|
||||
- NVMe-P1 OS smoke:
|
||||
- build blockmaster and blockvolume fresh,
|
||||
- start one NVMe target with dynamic control and transport ports,
|
||||
- `nvme connect`,
|
||||
- find device by NQN,
|
||||
- `mkfs.ext4`,
|
||||
- mount,
|
||||
- checksum write/read,
|
||||
- fio 60s,
|
||||
- unmount and `nvme disconnect`,
|
||||
- assert no `nvme list-subsys` entry for the NQN and no target process.
|
||||
- NVMe-P2 data-path classification:
|
||||
- add debug counters or artifact grep for inline write vs R2T write,
|
||||
- run 4 KiB write fio and confirm which path Linux uses,
|
||||
- run large write fio and confirm R2T/H2C remains stable.
|
||||
- NVMe-P3 ANA red tests:
|
||||
- admin Get Log Page ANA currently returns InvalidOpcode,
|
||||
- Identify ANA fields currently zero,
|
||||
- red test should require both to move together.
|
||||
|
||||
## Open Risks
|
||||
|
||||
- Linux `nvme` host behavior may differ from the Go client tests, especially
|
||||
around IO queue count, in-capsule writes, and reconnect.
|
||||
- ANA correctness requires host tooling and kernel interpretation, not only
|
||||
unit tests.
|
||||
- Performance work can easily pollute correctness work. Keep P1-P4 correctness
|
||||
gates separate from P6 benchmark claims.
|
||||
@@ -0,0 +1,121 @@
|
||||
# Storage Layer Architecture Learning
|
||||
|
||||
Status: reference note.
|
||||
|
||||
Purpose: capture the architecture lessons from comparing V3 block storage with
|
||||
Lakebase/Neon-style database storage, Ceph-style distributed block/object
|
||||
storage, and SPDK-style high-performance storage stacks. This is not a current
|
||||
execution plan and does not change `internal/docs/current-plan.md`.
|
||||
|
||||
## Main Takeaway
|
||||
|
||||
- Modern storage systems increasingly decouple compute/frontends from durable
|
||||
storage state.
|
||||
- The decoupling point determines what optimizations are possible:
|
||||
- block systems see LBA, bytes, flushes, and path state,
|
||||
- database page systems see page identity, LSN, WAL delta, and checkpoint
|
||||
semantics,
|
||||
- table/object systems see files, manifests, snapshots, and metadata commits.
|
||||
- V3 currently operates at the block layer. That is useful and general, but it
|
||||
cannot transparently optimize database-internal WAL semantics.
|
||||
|
||||
## Lakebase / Neon Lesson
|
||||
|
||||
- Lakebase/Neon-style architecture is not a faster iSCSI/NVMe block device.
|
||||
- It changes the Postgres compute/storage boundary:
|
||||
- Postgres compute is stateless,
|
||||
- WAL is streamed directly to distributed safekeepers,
|
||||
- pageserver/storage reconstructs page images from materialized image plus
|
||||
WAL deltas,
|
||||
- storage understands Postgres page identity and LSN.
|
||||
- That is why they can reduce Postgres full-page-write overhead:
|
||||
- Postgres full-page writes protect against torn local data pages,
|
||||
- in their architecture there is no local data directory page that compute
|
||||
depends on,
|
||||
- storage takes over page image generation and keeps delta replay bounded.
|
||||
- A normal block device cannot safely remove Postgres WAL or full-page writes:
|
||||
- by the time writes pass through filesystem + block + iSCSI/NVMe, database
|
||||
page/LSN semantics are gone.
|
||||
|
||||
## What Applies To V3 Block
|
||||
|
||||
- We can use the same architectural idea at block granularity:
|
||||
- append minimal block deltas on the foreground write path,
|
||||
- materialize block images in the background,
|
||||
- bound read replay as `latest block image + limited delta chain`,
|
||||
- compact/checkpoint independently from frontend protocol handling.
|
||||
- This can reduce V3's own backend write amplification and read amplification.
|
||||
- It cannot transparently reduce an application's own WAL unless the application
|
||||
talks to a semantic storage protocol.
|
||||
|
||||
## Product Boundary
|
||||
|
||||
- General block product:
|
||||
- frontends: iSCSI, NVMe-oF, CSI,
|
||||
- input semantics: block writes and flushes,
|
||||
- value: generic PVC/block volume, HA, failover, multipath, snapshots,
|
||||
backend durability.
|
||||
- Semantic storage product:
|
||||
- frontends: Postgres page/WAL protocol, table/manifest protocol, KV/log
|
||||
protocol,
|
||||
- input semantics: application-level objects such as page id, relation id,
|
||||
LSN, manifest commit, or transaction boundary,
|
||||
- value: application-specific write amplification reduction and stronger
|
||||
semantic optimization.
|
||||
- The semantic product can reuse V3's storage core, authority, replication, and
|
||||
placement ideas, but it should not be treated as a small iSCSI/NVMe feature.
|
||||
|
||||
## Current V3 Gap
|
||||
|
||||
- `blockvolume` currently combines several responsibilities:
|
||||
- frontend target,
|
||||
- replica role projection,
|
||||
- local durable backend,
|
||||
- replication/catch-up logic,
|
||||
- protocol-visible readiness.
|
||||
- This was pragmatic for getting iSCSI/NVMe/CSI green quickly.
|
||||
- It becomes limiting for backend evolution:
|
||||
- storage compaction/image generation cannot scale independently,
|
||||
- frontend failover and storage ownership are easy to couple accidentally,
|
||||
- multiple frontend protocols sharing one storage engine is awkward,
|
||||
- DB-aware protocols would inherit blockvolume coupling.
|
||||
|
||||
## Industrial Patterns To Study
|
||||
|
||||
- Ceph-style distributed storage:
|
||||
- clients/frontends use control-plane maps,
|
||||
- storage daemons own data, replication, recovery, rebalancing,
|
||||
- block/file/object frontends sit above a common storage layer.
|
||||
- SPDK-style high-performance storage:
|
||||
- user-space, polled-mode, lockless NVMe drivers,
|
||||
- hardware queue affinity and kernel-bypass data path,
|
||||
- useful later for NVMe performance, not a replacement for clean layering.
|
||||
- Cloud block storage:
|
||||
- control plane manages volume placement and lifecycle,
|
||||
- data plane is storage fleet plus NIC/SSD/hardware acceleration,
|
||||
- hardware acceleration is valuable only after the software boundary is clean.
|
||||
|
||||
## Suggested Future Direction
|
||||
|
||||
- Short term:
|
||||
- keep current frontend plan intact,
|
||||
- document backend coupling points,
|
||||
- define code-level interfaces for storage engine vs frontend target.
|
||||
- Medium term:
|
||||
- split responsibilities in code while still allowing one binary deployment:
|
||||
- `frontend`: iSCSI/NVMe protocol and path state,
|
||||
- `replica controller`: authority projection, fencing, peer set,
|
||||
- `storage engine`: WAL, block image, delta, compaction, snapshot.
|
||||
- Long term:
|
||||
- optionally split process boundaries,
|
||||
- add SPDK/io_uring/RDMA-backed storage paths,
|
||||
- consider a DB-aware page/WAL frontend only after the block storage core is
|
||||
mature.
|
||||
|
||||
## Non-Claims
|
||||
|
||||
- This note does not claim V3 can reduce Postgres WAL or full-page writes today.
|
||||
- This note does not change the active NVMe/iSCSI/CSI roadmap.
|
||||
- This note does not require an immediate process split.
|
||||
- This note argues for learning the industrial boundaries before turning backend
|
||||
work into a hardware-acceleration project.
|
||||
@@ -412,6 +412,124 @@ func TestISCSIP8CompatSoakRegistrationBuildsShellDriver(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlphaImagesPinBuildRegistrationBuildsShellDriver(t *testing.T) {
|
||||
repoRoot := findRepoRoot(t)
|
||||
raw, err := os.Open(registrationPath(repoRoot, "alpha-images-pin-build.json"))
|
||||
if err != nil {
|
||||
t.Fatalf("open registration: %v", err)
|
||||
}
|
||||
defer raw.Close()
|
||||
|
||||
registration, err := DecodeRegistration(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("DecodeRegistration: %v", err)
|
||||
}
|
||||
if registration.Scenario != "alpha-images-pin-build" || registration.Driver.Type != "shell" {
|
||||
t.Fatalf("registration=%+v", registration)
|
||||
}
|
||||
driver, err := registration.NewDriver(repoRoot)
|
||||
if err != nil {
|
||||
t.Fatalf("NewDriver: %v", err)
|
||||
}
|
||||
shell, ok := driver.(ShellDriver)
|
||||
if !ok {
|
||||
t.Fatalf("driver type=%T want ShellDriver", driver)
|
||||
}
|
||||
if !filepath.IsAbs(shell.Path) || filepath.Base(shell.Path) != "testops-pin-alpha-images.sh" {
|
||||
t.Fatalf("shell path=%q", shell.Path)
|
||||
}
|
||||
if _, err := os.Stat(shell.Path); err != nil {
|
||||
t.Fatalf("shell driver path missing: %v", err)
|
||||
}
|
||||
for _, want := range []string{"pin-build/alpha-images.env", "pin-build/blockmaster.version.txt", "pin-build/k3s-import-sw-block.log"} {
|
||||
if !containsString(registration.Artifacts, want) {
|
||||
t.Fatalf("registration artifacts missing %q: %v", want, registration.Artifacts)
|
||||
}
|
||||
}
|
||||
if !containsString(registration.RequiredCapabilities, "k3s") {
|
||||
t.Fatalf("registration must call out k3s import requirement: %v", registration.RequiredCapabilities)
|
||||
}
|
||||
if !containsString(registration.NonClaims, "Does not replace protocol-specific smoke tests.") {
|
||||
t.Fatalf("registration must keep smoke-test non-claim: %v", registration.NonClaims)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNVMeP5CSIRegistrationsBuildShellDrivers(t *testing.T) {
|
||||
repoRoot := findRepoRoot(t)
|
||||
for _, tc := range []struct {
|
||||
file string
|
||||
scenario string
|
||||
scriptBase string
|
||||
driverEnv string
|
||||
wantCap string
|
||||
wantArt string
|
||||
}{
|
||||
{
|
||||
file: "nvme-p5-csi-dynamic.json",
|
||||
scenario: "nvme-p5-csi-dynamic",
|
||||
scriptBase: "testops-run-alpha-k8s.sh",
|
||||
driverEnv: "SW_BLOCK_TESTOPS_WORKLOAD_SCRIPT=scripts/run-k8s-alpha-nvme.sh",
|
||||
wantCap: "nvme_tcp-loadable",
|
||||
wantArt: "nvme-list-subsys.after-delete.json",
|
||||
},
|
||||
{
|
||||
file: "nvme-p5-default-iscsi-regression.json",
|
||||
scenario: "nvme-p5-default-iscsi-regression",
|
||||
scriptBase: "testops-run-alpha-k8s.sh",
|
||||
driverEnv: "SW_BLOCK_TESTOPS_WORKLOAD_SCRIPT=scripts/run-k8s-alpha.sh",
|
||||
wantCap: "iscsi_tcp-loadable",
|
||||
wantArt: "iscsi-sessions.after-delete.txt",
|
||||
},
|
||||
} {
|
||||
t.Run(tc.scenario, func(t *testing.T) {
|
||||
raw, err := os.Open(registrationPath(repoRoot, tc.file))
|
||||
if err != nil {
|
||||
t.Fatalf("open registration: %v", err)
|
||||
}
|
||||
defer raw.Close()
|
||||
|
||||
registration, err := DecodeRegistration(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("DecodeRegistration: %v", err)
|
||||
}
|
||||
if registration.Scenario != tc.scenario || registration.Driver.Type != "shell" {
|
||||
t.Fatalf("registration=%+v", registration)
|
||||
}
|
||||
driver, err := registration.NewDriver(repoRoot)
|
||||
if err != nil {
|
||||
t.Fatalf("NewDriver: %v", err)
|
||||
}
|
||||
shell, ok := driver.(ShellDriver)
|
||||
if !ok {
|
||||
t.Fatalf("driver type=%T want ShellDriver", driver)
|
||||
}
|
||||
if !filepath.IsAbs(shell.Path) || filepath.Base(shell.Path) != tc.scriptBase {
|
||||
t.Fatalf("shell path=%q", shell.Path)
|
||||
}
|
||||
if _, err := os.Stat(shell.Path); err != nil {
|
||||
t.Fatalf("shell path %q missing: %v", shell.Path, err)
|
||||
}
|
||||
if !containsString(registration.Driver.Env, tc.driverEnv) {
|
||||
t.Fatalf("registration driver env missing %q: %v", tc.driverEnv, registration.Driver.Env)
|
||||
}
|
||||
if !containsString(registration.RequiredCapabilities, tc.wantCap) {
|
||||
t.Fatalf("registration capabilities missing %q: %v", tc.wantCap, registration.RequiredCapabilities)
|
||||
}
|
||||
for _, want := range []string{"alpha-images.env", "blockmaster.version.txt", "generated-blockvolume.yaml", tc.wantArt} {
|
||||
if !containsString(registration.Artifacts, want) {
|
||||
t.Fatalf("registration artifacts missing %q: %v", want, registration.Artifacts)
|
||||
}
|
||||
}
|
||||
if got := registration.ScenarioDefaultParams["SW_BLOCK_LAUNCHER_PVC_OWNER_REF"]; got != "1" {
|
||||
t.Fatalf("owner-ref default=%q want 1", got)
|
||||
}
|
||||
if !containsString(registration.NonClaims, "Requires a fresh pin-build artifact passed with --param SW_BLOCK_ALPHA_IMAGES_ENV=...") {
|
||||
t.Fatalf("registration must document pin-build dependency: %v", registration.NonClaims)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func containsString(values []string, want string) bool {
|
||||
for _, value := range values {
|
||||
if value == want {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"scenario": "alpha-images-pin-build",
|
||||
"gate": "M1",
|
||||
"layer": "L0-build",
|
||||
"driver": {
|
||||
"type": "shell",
|
||||
"path": "scripts/testops-pin-alpha-images.sh"
|
||||
},
|
||||
"default_timeout_s": 1200,
|
||||
"required_capabilities": [
|
||||
"bash",
|
||||
"docker",
|
||||
"k3s",
|
||||
"sudo"
|
||||
],
|
||||
"required_images": [
|
||||
"sw-block:local",
|
||||
"sw-block-csi:local"
|
||||
],
|
||||
"known_green_commit": "8e0a28f",
|
||||
"artifacts": [
|
||||
"pin-build/build.stdout.log",
|
||||
"pin-build/build.stderr.log",
|
||||
"pin-build/alpha-images.env",
|
||||
"pin-build/blockmaster.version.txt",
|
||||
"pin-build/blockvolume.version.txt",
|
||||
"pin-build/blockcsi.version.txt",
|
||||
"pin-build/k3s-import-sw-block.log",
|
||||
"pin-build/k3s-import-sw-block-csi.log"
|
||||
],
|
||||
"non_claims": [
|
||||
"Build/import provenance only; no Kubernetes workload or storage data-path claim.",
|
||||
"Does not prove published registry images.",
|
||||
"Does not replace protocol-specific smoke tests."
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"scenario": "nvme-p5-csi-dynamic",
|
||||
"gate": "NVMe-P5",
|
||||
"layer": "L5-k8s",
|
||||
"driver": {
|
||||
"type": "shell",
|
||||
"path": "scripts/testops-run-alpha-k8s.sh",
|
||||
"env": [
|
||||
"SW_BLOCK_TESTOPS_WORKLOAD_SCRIPT=scripts/run-k8s-alpha-nvme.sh"
|
||||
]
|
||||
},
|
||||
"default_timeout_s": 900,
|
||||
"required_capabilities": [
|
||||
"bash",
|
||||
"kubectl",
|
||||
"privileged-k8s-node",
|
||||
"nvme-cli",
|
||||
"nvme_tcp-loadable",
|
||||
"mount"
|
||||
],
|
||||
"required_images": [
|
||||
"sw-block:local",
|
||||
"sw-block-csi:local"
|
||||
],
|
||||
"qa_instruction": "internal/docs/qa-assignments/nvme-p5-csi-protocol-selection-validation.md",
|
||||
"known_green_commit": "ce657d5",
|
||||
"scenario_default_params": {
|
||||
"SW_BLOCK_LAUNCHER_PVC_OWNER_REF": "1"
|
||||
},
|
||||
"artifacts": [
|
||||
"run.log",
|
||||
"alpha-images.env",
|
||||
"blockmaster.version.txt",
|
||||
"blockcsi.version.txt",
|
||||
"blockvolume.version.txt",
|
||||
"storageclass.live.yaml",
|
||||
"lifecycle-volumes.json",
|
||||
"generated-blockvolume.yaml",
|
||||
"pod.log",
|
||||
"blockmaster.log",
|
||||
"blockcsi-controller.log",
|
||||
"blockvolume-generated.log",
|
||||
"nvme-list-subsys.after-delete.json",
|
||||
"cleanup.log"
|
||||
],
|
||||
"non_claims": [
|
||||
"Single-node Kubernetes only.",
|
||||
"Dynamic PVC protocol-selection smoke only.",
|
||||
"Requires a fresh pin-build artifact passed with --param SW_BLOCK_ALPHA_IMAGES_ENV=...",
|
||||
"Not an ANA multipath, mounted failover, or performance gate."
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"schema_version": "1.0",
|
||||
"scenario": "nvme-p5-default-iscsi-regression",
|
||||
"gate": "NVMe-P5",
|
||||
"layer": "L5-k8s",
|
||||
"driver": {
|
||||
"type": "shell",
|
||||
"path": "scripts/testops-run-alpha-k8s.sh",
|
||||
"env": [
|
||||
"SW_BLOCK_TESTOPS_WORKLOAD_SCRIPT=scripts/run-k8s-alpha.sh"
|
||||
]
|
||||
},
|
||||
"default_timeout_s": 900,
|
||||
"required_capabilities": [
|
||||
"bash",
|
||||
"kubectl",
|
||||
"privileged-k8s-node",
|
||||
"iscsiadm",
|
||||
"iscsi_tcp-loadable",
|
||||
"mount"
|
||||
],
|
||||
"required_images": [
|
||||
"sw-block:local",
|
||||
"sw-block-csi:local"
|
||||
],
|
||||
"qa_instruction": "internal/docs/qa-assignments/nvme-p5-csi-protocol-selection-validation.md",
|
||||
"known_green_commit": "ce657d5",
|
||||
"scenario_default_params": {
|
||||
"SW_BLOCK_LAUNCHER_PVC_OWNER_REF": "1"
|
||||
},
|
||||
"artifacts": [
|
||||
"run.log",
|
||||
"alpha-images.env",
|
||||
"blockmaster.version.txt",
|
||||
"blockcsi.version.txt",
|
||||
"blockvolume.version.txt",
|
||||
"storageclass.live.yaml",
|
||||
"lifecycle-volumes.json",
|
||||
"generated-blockvolume.yaml",
|
||||
"pod.log",
|
||||
"blockmaster.log",
|
||||
"blockcsi-controller.log",
|
||||
"blockvolume-generated.log",
|
||||
"iscsi-sessions.after-delete.txt",
|
||||
"nvme-list-subsys.after-delete.json",
|
||||
"cleanup.log"
|
||||
],
|
||||
"non_claims": [
|
||||
"Single-node Kubernetes only.",
|
||||
"Default iSCSI regression for the NVMe protocol-selection feature.",
|
||||
"Requires a fresh pin-build artifact passed with --param SW_BLOCK_ALPHA_IMAGES_ENV=...",
|
||||
"Not an ALUA multipath, mounted failover, or performance gate."
|
||||
]
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type ShellDriver struct {
|
||||
@@ -32,7 +33,7 @@ func (d ShellDriver) Run(ctx context.Context, req RunRequest) (Result, error) {
|
||||
cmd := exec.CommandContext(ctx, d.Path, reqPath)
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
cmd.Env = append(os.Environ(), d.Env...)
|
||||
cmd.Env = shellEnv(d.Env, req.ScenarioParams)
|
||||
err := cmd.Run()
|
||||
|
||||
if stdout.Len() > 0 {
|
||||
@@ -60,6 +61,23 @@ func (d ShellDriver) Run(ctx context.Context, req RunRequest) (Result, error) {
|
||||
return NewResult(req, StatusError, "driver did not write result.json"), fmt.Errorf("testops: shell driver %s did not write result.json", d.Path)
|
||||
}
|
||||
|
||||
func shellEnv(driverEnv []string, params map[string]string) []string {
|
||||
env := append([]string{}, os.Environ()...)
|
||||
env = append(env, driverEnv...)
|
||||
if len(params) == 0 {
|
||||
return env
|
||||
}
|
||||
keys := make([]string, 0, len(params))
|
||||
for key := range params {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
env = append(env, key+"="+params[key])
|
||||
}
|
||||
return env
|
||||
}
|
||||
|
||||
func writeJSON(path string, v any) error {
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
|
||||
@@ -33,6 +33,35 @@ JSON
|
||||
}
|
||||
}
|
||||
|
||||
func TestShellDriverExportsScenarioParams(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
script := writeEnvEchoDriverScript(t, dir)
|
||||
req := RunRequest{
|
||||
SchemaVersion: SchemaVersion,
|
||||
Scenario: "shell-scenario",
|
||||
Source: SourceSpec{Repo: "seaweed_block", Commit: "abc123"},
|
||||
ArtifactDir: filepath.Join(dir, "art"),
|
||||
RunID: "shell-run",
|
||||
ScenarioParams: map[string]string{
|
||||
"SW_BLOCK_ALPHA_IMAGES_ENV": "/tmp/pin/alpha-images.env",
|
||||
},
|
||||
}
|
||||
res, err := ShellDriver{Path: script}.Run(context.Background(), req)
|
||||
if err != nil {
|
||||
t.Fatalf("Run: %v", err)
|
||||
}
|
||||
if res.Status != StatusPass {
|
||||
t.Fatalf("status=%s", res.Status)
|
||||
}
|
||||
raw, err := os.ReadFile(filepath.Join(req.ArtifactDir, "env.txt"))
|
||||
if err != nil {
|
||||
t.Fatalf("read env evidence: %v", err)
|
||||
}
|
||||
if string(raw) != "/tmp/pin/alpha-images.env" {
|
||||
t.Fatalf("env evidence=%q", string(raw))
|
||||
}
|
||||
}
|
||||
|
||||
func TestShellDriverReportsErrorWhenNoResult(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
script := writeTestDriverScript(t, dir, 3, `echo nope >&2`)
|
||||
@@ -55,6 +84,26 @@ func TestShellDriverReportsErrorWhenNoResult(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func writeEnvEchoDriverScript(t *testing.T, dir string) string {
|
||||
t.Helper()
|
||||
if runtime.GOOS == "windows" {
|
||||
path := filepath.Join(dir, "driver.cmd")
|
||||
script := "@echo off\r\n" +
|
||||
"powershell -NoProfile -Command \"$req = Get-Content '%1' | ConvertFrom-Json; $art=$req.artifact_dir; New-Item -ItemType Directory -Force -Path $art | Out-Null; Set-Content -NoNewline -Path (Join-Path $art 'env.txt') -Value $env:SW_BLOCK_ALPHA_IMAGES_ENV; Set-Content -Path (Join-Path $art 'result.json') -Value ('{\\\"schema_version\\\":\\\"1.0\\\",\\\"run_id\\\":\\\"shell-run\\\",\\\"scenario\\\":\\\"shell-scenario\\\",\\\"source_commit\\\":\\\"abc123\\\",\\\"status\\\":\\\"pass\\\",\\\"summary\\\":\\\"script pass\\\",\\\"artifact_dir\\\":\\\"' + ($art -replace '\\\\','\\\\') + '\\\"}')\"\r\n"
|
||||
if err := os.WriteFile(path, []byte(script), 0o755); err != nil {
|
||||
t.Fatalf("write script: %v", err)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
path := filepath.Join(dir, "driver.sh")
|
||||
script := "#!/usr/bin/env bash\nset -euo pipefail\nREQ=\"$1\"\nART=$(python3 - <<'PY' \"$REQ\"\nimport json,sys\nprint(json.load(open(sys.argv[1]))['artifact_dir'])\nPY\n)\nmkdir -p \"$ART\"\nprintf '%s' \"$SW_BLOCK_ALPHA_IMAGES_ENV\" > \"$ART/env.txt\"\ncat > \"$ART/result.json\" <<JSON\n{\"schema_version\":\"1.0\",\"run_id\":\"shell-run\",\"scenario\":\"shell-scenario\",\"source_commit\":\"abc123\",\"status\":\"pass\",\"summary\":\"script pass\",\"artifact_dir\":\"$ART\"}\nJSON\n"
|
||||
if err := os.WriteFile(path, []byte(script), 0o755); err != nil {
|
||||
t.Fatalf("write script: %v", err)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func writeTestDriverScript(t *testing.T, dir string, exitCode int, body string) string {
|
||||
t.Helper()
|
||||
if runtime.GOOS == "windows" {
|
||||
|
||||
@@ -4,14 +4,66 @@ set -euo pipefail
|
||||
ROOT="${1:-$(pwd)}"
|
||||
IMAGE="${SW_BLOCK_IMAGE:-sw-block:local}"
|
||||
CSI_IMAGE="${SW_BLOCK_CSI_IMAGE:-sw-block-csi:local}"
|
||||
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${SW_BLOCK_BUILD_ARTIFACT_DIR:-}}"
|
||||
IMPORT_K3S="${SW_BLOCK_IMPORT_K3S:-0}"
|
||||
|
||||
if [[ -n "$ARTIFACT_DIR" ]]; then
|
||||
mkdir -p "$ARTIFACT_DIR"
|
||||
fi
|
||||
|
||||
echo "[alpha-build] root=$ROOT"
|
||||
echo "[alpha-build] image=$IMAGE"
|
||||
echo "[alpha-build] csi_image=$CSI_IMAGE"
|
||||
echo "[alpha-build] import_k3s=$IMPORT_K3S"
|
||||
|
||||
docker build -t "$IMAGE" -f "$ROOT/deploy/k8s/g15b/Dockerfile.sw-block" "$ROOT"
|
||||
docker build -t "$CSI_IMAGE" -f "$ROOT/deploy/k8s/g15b/Dockerfile.blockcsi" "$ROOT"
|
||||
|
||||
record_build_evidence() {
|
||||
[[ -n "$ARTIFACT_DIR" ]] || return 0
|
||||
|
||||
{
|
||||
echo "SW_BLOCK_IMAGE=$IMAGE"
|
||||
echo "SW_BLOCK_CSI_IMAGE=$CSI_IMAGE"
|
||||
echo "SW_BLOCK_IMAGE_ID=$(docker image inspect "$IMAGE" --format '{{.Id}}')"
|
||||
echo "SW_BLOCK_CSI_IMAGE_ID=$(docker image inspect "$CSI_IMAGE" --format '{{.Id}}')"
|
||||
if git -C "$ROOT" rev-parse --git-dir >/dev/null 2>&1; then
|
||||
echo "GIT_REVISION=$(git -C "$ROOT" rev-parse HEAD)"
|
||||
echo "GIT_DIRTY=$(if git -C "$ROOT" diff --quiet --ignore-submodules HEAD --; then echo false; else echo true; fi)"
|
||||
else
|
||||
echo "GIT_REVISION="
|
||||
echo "GIT_DIRTY=unknown"
|
||||
fi
|
||||
} >"$ARTIFACT_DIR/alpha-images.env"
|
||||
|
||||
docker run --rm "$IMAGE" /usr/local/bin/blockmaster --version >"$ARTIFACT_DIR/blockmaster.version.txt"
|
||||
docker run --rm "$IMAGE" /usr/local/bin/blockvolume --version >"$ARTIFACT_DIR/blockvolume.version.txt"
|
||||
docker run --rm --entrypoint /usr/local/bin/blockcsi "$CSI_IMAGE" --version >"$ARTIFACT_DIR/blockcsi.version.txt"
|
||||
}
|
||||
|
||||
import_k3s_image() {
|
||||
local image="$1"
|
||||
local log_name="$2"
|
||||
local -a ctr=()
|
||||
if command -v k3s >/dev/null 2>&1 && k3s --version >/dev/null 2>&1; then
|
||||
ctr=(k3s ctr images import -)
|
||||
elif command -v sudo >/dev/null 2>&1 && sudo k3s --version >/dev/null 2>&1; then
|
||||
ctr=(sudo k3s ctr images import -)
|
||||
else
|
||||
echo "SW_BLOCK_IMPORT_K3S=1 requires k3s or sudo k3s on PATH" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "[alpha-build] k3s_import image=$image"
|
||||
if [[ -n "$ARTIFACT_DIR" ]]; then
|
||||
docker save "$image" | "${ctr[@]}" >"$ARTIFACT_DIR/$log_name" 2>&1
|
||||
else
|
||||
docker save "$image" | "${ctr[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
record_build_evidence
|
||||
|
||||
if [[ -n "${SW_BLOCK_KIND_CLUSTER:-}" ]]; then
|
||||
if ! command -v kind >/dev/null 2>&1; then
|
||||
echo "SW_BLOCK_KIND_CLUSTER is set but kind is not installed" >&2
|
||||
@@ -21,3 +73,7 @@ if [[ -n "${SW_BLOCK_KIND_CLUSTER:-}" ]]; then
|
||||
kind load docker-image --name "$SW_BLOCK_KIND_CLUSTER" "$CSI_IMAGE"
|
||||
fi
|
||||
|
||||
if [[ "$IMPORT_K3S" == "1" || "$IMPORT_K3S" == "true" ]]; then
|
||||
import_k3s_image "$IMAGE" "k3s-import-sw-block.log"
|
||||
import_k3s_image "$CSI_IMAGE" "k3s-import-sw-block-csi.log"
|
||||
fi
|
||||
@@ -17,6 +17,7 @@ This directory contains developer and QA helper scripts.
|
||||
| `run-k8s-attach-detach-loop.sh` | QA loop wrapper. Repeats the app PVC attach/write/read/delete flow and stores per-iteration artifacts. |
|
||||
| `run-k8s-csi-node-restart.sh` | QA wrapper. Restarts the CSI node DaemonSet between writer and reader pods using the same PVC. |
|
||||
| `build-alpha-images.sh` | Builds local Docker images used by the Kubernetes alpha harness. |
|
||||
| `testops-run-nvme-p5-suite.sh` | Developer-owned TestOps suite: pin-builds alpha images, then runs NVMe dynamic PVC and default iSCSI regression with the pinned image env. |
|
||||
| `run-alpha-k8s-dynamic.sh` | Public dynamic PVC alpha smoke entry. |
|
||||
| `run-alpha-app-demo.sh` | App-demo implementation used by `run-k8s-demo.sh`. |
|
||||
| `run-iscsi-os-smoke.sh` | Privileged Linux OS-initiator smoke: `iscsiadm` -> `mkfs.ext4` -> mount -> checksum -> logout on a 256 MiB target. |
|
||||
@@ -25,6 +26,8 @@ This directory contains developer and QA helper scripts.
|
||||
| `run-iscsi-alua-os-smoke.sh` | Privileged Linux OS-initiator smoke for ALUA reporting: `iscsiadm` -> `sg_inq`/`sg_rtpg` -> mount -> checksum -> logout. |
|
||||
| `run-iscsi-alua-multipath-smoke.sh` | Privileged Linux OS-initiator smoke for two iSCSI paths: two portals -> ALUA active/standby evidence -> standby write reject -> `multipath -ll`. |
|
||||
| `run-iscsi-alua-mounted-failover-smoke.sh` | Privileged Linux OS-initiator smoke for mounted multipath failover: mount `/dev/mapper/*`, kill active path, wait r2 primary, verify checksum read/write. |
|
||||
| `run-nvme-os-smoke.sh` | Privileged Linux OS-initiator smoke: `nvme connect` -> `mkfs.ext4` -> mount -> checksum/fio/dd -> disconnect. |
|
||||
| `run-nvme-multipath-smoke.sh` | Privileged Linux OS-initiator smoke for two NVMe/TCP paths: two portals -> ANA/identity evidence -> native multipath grouping check. |
|
||||
| `build-g15b-images.sh` | Compatibility wrapper for older QA scripts. |
|
||||
| `run-g15b-k8s-static.sh` | Historical static PV Kubernetes harness. |
|
||||
| `run-g15d-k8s-dynamic.sh` | Historical dynamic PVC harness used by compatibility scenarios. |
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="${1:-$(pwd)}"
|
||||
ALPHA_IMAGES_ENV="${SW_BLOCK_ALPHA_IMAGES_ENV:-${SW_BLOCK_PIN_BUILD_ENV:-}}"
|
||||
if [[ -n "$ALPHA_IMAGES_ENV" ]]; then
|
||||
if [[ ! -f "$ALPHA_IMAGES_ENV" ]]; then
|
||||
echo "SW_BLOCK_ALPHA_IMAGES_ENV points to missing file: $ALPHA_IMAGES_ENV" >&2
|
||||
exit 2
|
||||
fi
|
||||
# shellcheck source=/dev/null
|
||||
source "$ALPHA_IMAGES_ENV"
|
||||
fi
|
||||
NAMESPACE="${G15D_NAMESPACE:-default}"
|
||||
ARTIFACT_DIR="${G15D_ARTIFACT_DIR:-/tmp/g15d-k8s-$(date -u +%Y%m%dT%H%M%SZ)}"
|
||||
RUN_LABEL="${SW_BLOCK_RUN_LABEL:-g15d}"
|
||||
@@ -12,6 +21,7 @@ LAUNCHER_PVC_OWNER_REF="${SW_BLOCK_LAUNCHER_PVC_OWNER_REF:-0}"
|
||||
CHAP_USERNAME="${SW_BLOCK_ISCSI_CHAP_USERNAME:-}"
|
||||
CHAP_SECRET="${SW_BLOCK_ISCSI_CHAP_SECRET:-}"
|
||||
CHAP_SECRET_NAME="${SW_BLOCK_ISCSI_CHAP_SECRET_NAME:-sw-block-iscsi-chap}"
|
||||
FRONTEND_PROTOCOL="${SW_BLOCK_FRONTEND_PROTOCOL:-iscsi}"
|
||||
BLOCKVOLUME_NAMESPACE="kube-system"
|
||||
if [[ "$LAUNCHER_PVC_OWNER_REF" == "1" || "$LAUNCHER_PVC_OWNER_REF" == "true" ]]; then
|
||||
BLOCKVOLUME_NAMESPACE="$NAMESPACE"
|
||||
@@ -24,9 +34,21 @@ if [[ -n "$CHAP_USERNAME" || -n "$CHAP_SECRET" ]]; then
|
||||
fi
|
||||
CHAP_ENABLED=1
|
||||
fi
|
||||
if [[ "$FRONTEND_PROTOCOL" != "iscsi" && "$FRONTEND_PROTOCOL" != "nvme" ]]; then
|
||||
echo "SW_BLOCK_FRONTEND_PROTOCOL must be iscsi or nvme" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$FRONTEND_PROTOCOL" == "nvme" && "$CHAP_ENABLED" == "1" ]]; then
|
||||
echo "iSCSI CHAP is not compatible with SW_BLOCK_FRONTEND_PROTOCOL=nvme" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
mkdir -p "$ARTIFACT_DIR"
|
||||
if [[ -n "$ALPHA_IMAGES_ENV" ]]; then
|
||||
cp "$ALPHA_IMAGES_ENV" "$ARTIFACT_DIR/alpha-images.env"
|
||||
fi
|
||||
POLL_LOG="$ARTIFACT_DIR/poll.log"
|
||||
EXPECTED_GIT_REVISION="$(git -C "$ROOT" rev-parse HEAD 2>/dev/null || true)"
|
||||
|
||||
log() {
|
||||
printf '[%s] %s\n' "$RUN_LABEL" "$*" | tee -a "$ARTIFACT_DIR/run.log"
|
||||
@@ -45,6 +67,30 @@ sed_escape() {
|
||||
|
||||
require_cmd kubectl
|
||||
|
||||
verify_revision() {
|
||||
local component="$1"
|
||||
local path="$2"
|
||||
if [[ -z "$EXPECTED_GIT_REVISION" ]]; then
|
||||
return
|
||||
fi
|
||||
if ! grep -q "$EXPECTED_GIT_REVISION" "$path"; then
|
||||
echo "$component image revision mismatch: expected $EXPECTED_GIT_REVISION, got $(cat "$path" 2>/dev/null || true)" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
capture_blockvolume_version() {
|
||||
local out="$1"
|
||||
local err="$2"
|
||||
local deploy
|
||||
deploy="$(kubectl -n "$BLOCKVOLUME_NAMESPACE" get deploy -l app=sw-blockvolume -o name 2>"$err" | head -n 1)"
|
||||
if [[ -z "$deploy" ]]; then
|
||||
echo "generated blockvolume Deployment not found for version capture" >>"$err"
|
||||
return 1
|
||||
fi
|
||||
kubectl -n "$BLOCKVOLUME_NAMESPACE" exec "$deploy" -c blockvolume -- /usr/local/bin/blockvolume --version >"$out" 2>>"$err"
|
||||
}
|
||||
|
||||
NODE_NAME="$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')"
|
||||
STACK_RENDERED="$ARTIFACT_DIR/block-stack.rendered.yaml"
|
||||
CSI_CONTROLLER_RENDERED="$ARTIFACT_DIR/csi-controller.rendered.yaml"
|
||||
@@ -90,8 +136,23 @@ if [[ "$CHAP_ENABLED" == "1" ]]; then
|
||||
' "$DYNAMIC_RENDERED" >"$DYNAMIC_RENDERED.tmp"
|
||||
mv "$DYNAMIC_RENDERED.tmp" "$DYNAMIC_RENDERED"
|
||||
fi
|
||||
if [[ "$FRONTEND_PROTOCOL" == "nvme" ]]; then
|
||||
awk '
|
||||
/^parameters:/ {
|
||||
print
|
||||
print " sw-block.seaweedfs.com/protocol: \"nvme\""
|
||||
print " protocol: \"nvme\""
|
||||
next
|
||||
}
|
||||
{print}
|
||||
' "$DYNAMIC_RENDERED" >"$DYNAMIC_RENDERED.tmp"
|
||||
mv "$DYNAMIC_RENDERED.tmp" "$DYNAMIC_RENDERED"
|
||||
fi
|
||||
|
||||
log "artifact_dir=$ARTIFACT_DIR"
|
||||
if [[ -n "$ALPHA_IMAGES_ENV" ]]; then
|
||||
log "alpha_images_env=$ALPHA_IMAGES_ENV"
|
||||
fi
|
||||
log "root=$ROOT"
|
||||
log "namespace=$NAMESPACE"
|
||||
log "node=$NODE_NAME"
|
||||
@@ -100,6 +161,8 @@ log "csi_image=$CSI_IMAGE"
|
||||
log "blockvolume_namespace=$BLOCKVOLUME_NAMESPACE"
|
||||
log "launcher_pvc_owner_ref=$LAUNCHER_PVC_OWNER_REF"
|
||||
log "chap_enabled=$CHAP_ENABLED"
|
||||
log "frontend_protocol=$FRONTEND_PROTOCOL"
|
||||
log "expected_git_revision=${EXPECTED_GIT_REVISION:-unknown}"
|
||||
log "dynamic_pvc_manifest=$DYNAMIC_PVC_MANIFEST"
|
||||
kubectl version --client=true >"$ARTIFACT_DIR/kubectl-version.txt" 2>&1 || true
|
||||
kubectl get nodes -o wide >"$ARTIFACT_DIR/nodes.before.txt"
|
||||
@@ -130,9 +193,14 @@ collect_daemon_logs() {
|
||||
capture_once "$ARTIFACT_DIR/csi-provisioner.log" kubectl -n kube-system logs deploy/sw-block-csi-controller -c csi-provisioner
|
||||
capture_once "$ARTIFACT_DIR/csi-attacher.log" kubectl -n kube-system logs deploy/sw-block-csi-controller -c csi-attacher
|
||||
capture_once "$ARTIFACT_DIR/blockvolume-generated.log" kubectl -n "$BLOCKVOLUME_NAMESPACE" logs -l sw-block.seaweedfs.com/volume -c blockvolume --tail=-1
|
||||
if [[ ! -s "$ARTIFACT_DIR/blockvolume.version.txt" ]]; then
|
||||
capture_blockvolume_version "$ARTIFACT_DIR/blockvolume.version.txt" "$ARTIFACT_DIR/blockvolume.version.err" || true
|
||||
fi
|
||||
capture_once "$ARTIFACT_DIR/kube-system-pods-deploys.txt" kubectl -n kube-system get pods,deploy -o wide
|
||||
capture_once "$ARTIFACT_DIR/kube-system-imageids.txt" kubectl -n kube-system get pod -l 'app in (sw-blockmaster,sw-block-csi-controller,sw-block-csi-node)' -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{range .status.containerStatuses[*]}{" "}{.name}{" imageID="}{.imageID}{"\n"}{end}{end}'
|
||||
capture_once "$ARTIFACT_DIR/blockvolume-namespace-pods-deploys.txt" kubectl -n "$BLOCKVOLUME_NAMESPACE" get pods,deploy -o wide
|
||||
capture_once "$ARTIFACT_DIR/app-storage.txt" kubectl -n "$NAMESPACE" get sc,pv,pvc,pod -o wide
|
||||
capture_once "$ARTIFACT_DIR/lifecycle-volumes.json" kubectl -n kube-system exec deploy/sw-blockmaster -c blockmaster -- sh -c 'cat /var/lib/sw-block/lifecycle/volumes/*.json'
|
||||
if [[ ! -s "$ARTIFACT_DIR/generated-blockvolume.yaml" ]]; then
|
||||
kubectl -n kube-system exec deploy/sw-blockmaster -c blockmaster -- sh -c 'cat /manifests/*.yaml' >"$ARTIFACT_DIR/generated-blockvolume.yaml" 2>"$ARTIFACT_DIR/generated-blockvolume.err" || true
|
||||
fi
|
||||
@@ -154,10 +222,13 @@ collect_post_delete_state() {
|
||||
kubectl -n "$NAMESPACE" get sc,pv,pvc,pod -o wide >"$ARTIFACT_DIR/app-storage.after-delete.txt" 2>&1 || true
|
||||
if command -v sudo >/dev/null 2>&1; then
|
||||
sudo iscsiadm -m session >"$ARTIFACT_DIR/iscsi-sessions.after-delete.txt" 2>&1 || true
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.after-delete.json" 2>&1 || true
|
||||
elif command -v iscsiadm >/dev/null 2>&1; then
|
||||
iscsiadm -m session >"$ARTIFACT_DIR/iscsi-sessions.after-delete.txt" 2>&1 || true
|
||||
nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.after-delete.json" 2>&1 || true
|
||||
else
|
||||
echo "iscsiadm unavailable" >"$ARTIFACT_DIR/iscsi-sessions.after-delete.txt"
|
||||
echo "nvme unavailable" >"$ARTIFACT_DIR/nvme-list-subsys.after-delete.json"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -167,6 +238,11 @@ trap 'collect_daemon_logs; cleanup' EXIT
|
||||
log "apply product stack without pre-created blockvolumes"
|
||||
kubectl apply -f "$STACK_RENDERED" | tee "$ARTIFACT_DIR/apply-block-stack.log"
|
||||
kubectl -n kube-system wait --for=condition=available deploy/sw-blockmaster --timeout=120s
|
||||
if ! kubectl -n kube-system exec deploy/sw-blockmaster -c blockmaster -- /usr/local/bin/blockmaster --version >"$ARTIFACT_DIR/blockmaster.version.txt" 2>"$ARTIFACT_DIR/blockmaster.version.err"; then
|
||||
echo "blockmaster image does not expose --version; rebuild and reload sw-block image from current branch" >&2
|
||||
exit 1
|
||||
fi
|
||||
verify_revision "blockmaster" "$ARTIFACT_DIR/blockmaster.version.txt"
|
||||
|
||||
log "apply CSI dynamic-provisioning manifests"
|
||||
kubectl apply -f "$ROOT/deploy/k8s/g15d/rbac.yaml" | tee "$ARTIFACT_DIR/apply-rbac.log"
|
||||
@@ -175,6 +251,11 @@ kubectl apply -f "$CSI_CONTROLLER_RENDERED" | tee "$ARTIFACT_DIR/apply-csi-contr
|
||||
kubectl apply -f "$CSI_NODE_RENDERED" | tee "$ARTIFACT_DIR/apply-csi-node.log"
|
||||
kubectl -n kube-system wait --for=condition=available deploy/sw-block-csi-controller --timeout=120s
|
||||
kubectl -n kube-system rollout status ds/sw-block-csi-node --timeout=120s
|
||||
if ! kubectl -n kube-system exec deploy/sw-block-csi-controller -c block-csi -- /usr/local/bin/blockcsi --version >"$ARTIFACT_DIR/blockcsi.version.txt" 2>"$ARTIFACT_DIR/blockcsi.version.err"; then
|
||||
echo "blockcsi image does not expose --version; rebuild and reload sw-block-csi image from current branch" >&2
|
||||
exit 1
|
||||
fi
|
||||
verify_revision "blockcsi" "$ARTIFACT_DIR/blockcsi.version.txt"
|
||||
|
||||
if [[ "$CHAP_ENABLED" == "1" ]]; then
|
||||
log "apply iSCSI CHAP Secret"
|
||||
@@ -187,7 +268,15 @@ if [[ "$CHAP_ENABLED" == "1" ]]; then
|
||||
fi
|
||||
|
||||
log "apply dynamic StorageClass/PVC/pod"
|
||||
kubectl delete storageclass sw-block-dynamic --ignore-not-found=true | tee "$ARTIFACT_DIR/delete-storageclass-before-apply.log"
|
||||
kubectl -n "$NAMESPACE" apply -f "$DYNAMIC_RENDERED" | tee "$ARTIFACT_DIR/apply-dynamic.log"
|
||||
kubectl get storageclass sw-block-dynamic -o yaml >"$ARTIFACT_DIR/storageclass.live.yaml"
|
||||
if [[ "$FRONTEND_PROTOCOL" == "nvme" ]]; then
|
||||
if ! grep -Eq 'sw-block\.seaweedfs\.com/protocol: "?nvme"?|protocol: "?nvme"?' "$ARTIFACT_DIR/storageclass.live.yaml"; then
|
||||
echo "live StorageClass missing NVMe protocol parameter" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
log "wait for launcher-generated blockvolume manifest"
|
||||
for _ in $(seq 1 180); do
|
||||
@@ -201,10 +290,35 @@ if ! kubectl -n kube-system exec deploy/sw-blockmaster -c blockmaster -- sh -c '
|
||||
exit 1
|
||||
fi
|
||||
kubectl -n kube-system exec deploy/sw-blockmaster -c blockmaster -- sh -c 'cat /manifests/*.yaml' >"$ARTIFACT_DIR/generated-blockvolume.yaml"
|
||||
kubectl -n kube-system exec deploy/sw-blockmaster -c blockmaster -- sh -c 'cat /var/lib/sw-block/lifecycle/volumes/*.json' >"$ARTIFACT_DIR/lifecycle-volumes.json" 2>"$ARTIFACT_DIR/lifecycle-volumes.err" || true
|
||||
|
||||
if [[ "$FRONTEND_PROTOCOL" == "nvme" ]]; then
|
||||
for want in "--nvme-listen=" "--nvme-subsysnqn=" "--nvme-ns=1"; do
|
||||
if ! grep -q -- "$want" "$ARTIFACT_DIR/generated-blockvolume.yaml"; then
|
||||
echo "generated blockvolume manifest missing NVMe arg $want" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if grep -q -- "--iscsi-listen=" "$ARTIFACT_DIR/generated-blockvolume.yaml"; then
|
||||
echo "generated blockvolume manifest rendered iSCSI args while frontend_protocol=nvme" >&2
|
||||
exit 1
|
||||
fi
|
||||
log "verified generated blockvolume frontend protocol=nvme"
|
||||
else
|
||||
if ! grep -q -- "--iscsi-listen=" "$ARTIFACT_DIR/generated-blockvolume.yaml"; then
|
||||
echo "generated blockvolume manifest missing iSCSI args while frontend_protocol=iscsi" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
log "apply generated blockvolume manifests"
|
||||
kubectl apply -f "$ARTIFACT_DIR/generated-blockvolume.yaml" | tee "$ARTIFACT_DIR/apply-generated-blockvolume.log"
|
||||
kubectl -n "$BLOCKVOLUME_NAMESPACE" wait --for=condition=available deploy -l app=sw-blockvolume --timeout=120s
|
||||
if ! capture_blockvolume_version "$ARTIFACT_DIR/blockvolume.version.txt" "$ARTIFACT_DIR/blockvolume.version.err"; then
|
||||
echo "failed to capture generated blockvolume version; see $ARTIFACT_DIR/blockvolume.version.err" >&2
|
||||
exit 1
|
||||
fi
|
||||
verify_revision "blockvolume" "$ARTIFACT_DIR/blockvolume.version.txt"
|
||||
|
||||
log "wait for dynamic pod completion"
|
||||
for _ in $(seq 1 240); do
|
||||
@@ -272,6 +386,10 @@ if grep -q 'iqn.2026-05.io.seaweedfs' "$ARTIFACT_DIR/iscsi-sessions.after-delete
|
||||
echo "dangling sw-block iSCSI session after delete" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -q 'nqn.2026-05.io.seaweedfs' "$ARTIFACT_DIR/nvme-list-subsys.after-delete.json" 2>/dev/null; then
|
||||
echo "dangling sw-block NVMe subsystem after delete" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "PASS: dynamic PVC create/delete completed checksum write/read and cleanup"
|
||||
log "artifacts=$ARTIFACT_DIR"
|
||||
@@ -220,6 +220,20 @@ PY
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_log_pattern() {
|
||||
local path="$1"
|
||||
local pattern="$2"
|
||||
local label="$3"
|
||||
for _ in $(seq 1 160); do
|
||||
if grep -q "$pattern" "$path" 2>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
sleep 0.25
|
||||
done
|
||||
echo "timed out waiting for ${label}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
pid_for_replica() {
|
||||
local replica="$1"
|
||||
pgrep -f "${BIN_DIR}/blockvolume.*--replica-id ${replica}" | head -n1
|
||||
@@ -229,14 +243,16 @@ log "start r1 active path"
|
||||
start_blockvolume r1 s1 "$PORT1" "$R1_DATA_ADDR" "$R1_CTRL_ADDR" "$R1_STATUS_ADDR" \
|
||||
"${RUN_DIR}/r1-store" "$ARTIFACT_DIR/blockvolume-r1.log"
|
||||
wait_port "$PORT1"
|
||||
wait_status_healthy "$R1_STATUS_ADDR" r1 1
|
||||
|
||||
log "start r2 standby path"
|
||||
start_blockvolume r2 s2 "$PORT2" "$R2_DATA_ADDR" "$R2_CTRL_ADDR" "$R2_STATUS_ADDR" \
|
||||
"${RUN_DIR}/r2-store" "$ARTIFACT_DIR/blockvolume-r2.log"
|
||||
wait_port "$PORT2"
|
||||
|
||||
log "wait authority projections"
|
||||
wait_status_healthy "$R1_STATUS_ADDR" r1 1
|
||||
wait_status_projected "$R2_STATUS_ADDR" r2
|
||||
wait_log_pattern "$ARTIFACT_DIR/blockvolume-r2.log" "authority is now .*not this replica" "r2 standby authority observation"
|
||||
|
||||
discover_login() {
|
||||
local port="$1"
|
||||
@@ -351,15 +367,21 @@ fi
|
||||
|
||||
log "wait r2 failover"
|
||||
wait_status_healthy "$R2_STATUS_ADDR" r2 2
|
||||
sudo sg_rtpg "$real2" >"$ARTIFACT_DIR/sg_rtpg.r2.after.txt" 2>&1 || true
|
||||
sudo multipath -r >"$ARTIFACT_DIR/multipath.reload.after.txt" 2>&1 || true
|
||||
sudo multipath -ll >"$ARTIFACT_DIR/multipath.ll.after.txt" 2>&1 || true
|
||||
sudo iscsiadm -m session -P 3 >"$ARTIFACT_DIR/iscsi-session-P3.after-failover.txt" 2>&1 || true
|
||||
timeout 15s sudo sg_rtpg "$real2" >"$ARTIFACT_DIR/sg_rtpg.r2.after.txt" 2>&1 || true
|
||||
timeout 15s sudo multipath -r >"$ARTIFACT_DIR/multipath.reload.after.txt" 2>&1 || true
|
||||
timeout 15s sudo multipath -ll >"$ARTIFACT_DIR/multipath.ll.after.txt" 2>&1 || true
|
||||
timeout 15s sudo iscsiadm -m session -P 3 >"$ARTIFACT_DIR/iscsi-session-P3.after-failover.txt" 2>&1 || true
|
||||
|
||||
log "verify mounted workload after failover"
|
||||
sudo sha256sum -c "$ARTIFACT_DIR/pre.sha256" | tee "$ARTIFACT_DIR/pre-check-after-failover.log"
|
||||
sudo dd if=/dev/urandom of="$MOUNT_DIR/post.bin" bs=4096 count=64 status=none
|
||||
sync
|
||||
if ! timeout 60s sudo dd if=/dev/urandom of="$MOUNT_DIR/post.bin" bs=4096 count=64 status=none >"$ARTIFACT_DIR/post-write.stdout" 2>"$ARTIFACT_DIR/post-write.stderr"; then
|
||||
echo "post-failover write did not complete" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! timeout 60s sync; then
|
||||
echo "post-failover sync did not complete" >&2
|
||||
exit 1
|
||||
fi
|
||||
sudo sha256sum "$MOUNT_DIR/post.bin" | tee "$ARTIFACT_DIR/post.sha256"
|
||||
sudo sha256sum -c "$ARTIFACT_DIR/post.sha256" | tee "$ARTIFACT_DIR/post-check.log"
|
||||
|
||||
|
||||
@@ -193,17 +193,34 @@ PY
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_log_pattern() {
|
||||
local path="$1"
|
||||
local pattern="$2"
|
||||
local label="$3"
|
||||
for _ in $(seq 1 160); do
|
||||
if grep -q "$pattern" "$path" 2>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
sleep 0.25
|
||||
done
|
||||
echo "timed out waiting for ${label}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
log "start r1 iSCSI path"
|
||||
start_blockvolume r1 s1 "$PORT1" "$R1_DATA_ADDR" "$R1_CTRL_ADDR" "$R1_STATUS_ADDR" \
|
||||
"${RUN_DIR}/r1-store" "$ARTIFACT_DIR/blockvolume-r1.log"
|
||||
wait_port "$PORT1"
|
||||
wait_status_role "$R1_STATUS_ADDR" r1 primary
|
||||
|
||||
log "start r2 iSCSI path"
|
||||
start_blockvolume r2 s2 "$PORT2" "$R2_DATA_ADDR" "$R2_CTRL_ADDR" "$R2_STATUS_ADDR" \
|
||||
"${RUN_DIR}/r2-store" "$ARTIFACT_DIR/blockvolume-r2.log"
|
||||
wait_port "$PORT2"
|
||||
|
||||
log "wait authority projections"
|
||||
wait_status_role "$R1_STATUS_ADDR" r1 primary
|
||||
wait_status_role "$R2_STATUS_ADDR" r2 standby
|
||||
wait_log_pattern "$ARTIFACT_DIR/blockvolume-r2.log" "authority is now .*not this replica" "r2 standby authority observation"
|
||||
|
||||
discover_login() {
|
||||
local port="$1"
|
||||
|
||||
@@ -78,11 +78,11 @@ require_cmd() {
|
||||
|
||||
cleanup_iqn_records() {
|
||||
local portal portal_no_tpgt
|
||||
sudo iscsiadm -m session 2>/dev/null | awk -v iqn="$IQN" '$0 ~ iqn {print $3}' | while read -r portal; do
|
||||
{ sudo iscsiadm -m session 2>/dev/null || true; } | awk -v iqn="$IQN" '$0 ~ iqn {print $3}' | while read -r portal; do
|
||||
[[ -z "$portal" ]] && continue
|
||||
sudo iscsiadm -m node -T "$IQN" -p "$portal" --logout >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
done
|
||||
sudo iscsiadm -m node 2>/dev/null | awk -v iqn="$IQN" '$0 ~ iqn {print $1}' | while read -r portal; do
|
||||
{ sudo iscsiadm -m node 2>/dev/null || true; } | awk -v iqn="$IQN" '$0 ~ iqn {print $1}' | while read -r portal; do
|
||||
[[ -z "$portal" ]] && continue
|
||||
portal_no_tpgt="${portal%%,*}"
|
||||
sudo iscsiadm -m node -T "$IQN" -p "$portal" -o delete >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="${1:-$(pwd)}"
|
||||
|
||||
export SW_BLOCK_FRONTEND_PROTOCOL=nvme
|
||||
export SW_BLOCK_LAUNCHER_PVC_OWNER_REF="${SW_BLOCK_LAUNCHER_PVC_OWNER_REF:-1}"
|
||||
export SW_BLOCK_RUN_LABEL="${SW_BLOCK_RUN_LABEL:-alpha-nvme}"
|
||||
exec bash "$ROOT/scripts/run-alpha-k8s-dynamic.sh" "$ROOT"
|
||||
+435
@@ -0,0 +1,435 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="${1:-$(pwd)}"
|
||||
RUN_ID="${RUN_ID:-$(date -u +%Y%m%dT%H%M%SZ)}"
|
||||
WORK_DIR="${SW_BLOCK_NVME_FAILOVER_WORK_DIR:-/tmp/sw-block-nvme-failover}"
|
||||
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${WORK_DIR}/runs/${RUN_ID}}"
|
||||
SUBSYS_NQN="${SW_BLOCK_NVME_NQN:-nqn.2026-05.io.seaweedfs:failover-v1}"
|
||||
NSID="${SW_BLOCK_NVME_NSID:-1}"
|
||||
BLOCKS="${SW_BLOCK_DURABLE_BLOCKS:-65536}"
|
||||
BLOCK_SIZE="${SW_BLOCK_DURABLE_BLOCKSIZE:-4096}"
|
||||
DURABLE_IMPL="${SW_BLOCK_DURABLE_IMPL:-smartwal}"
|
||||
BIN_DIR="${SW_BLOCK_BIN_DIR:-${WORK_DIR}/bin}"
|
||||
RUN_DIR="${WORK_DIR}/run"
|
||||
MOUNT_DIR="${SW_BLOCK_NVME_MOUNT_DIR:-${WORK_DIR}/mnt}"
|
||||
|
||||
mkdir -p "$ARTIFACT_DIR" "$BIN_DIR" "$RUN_DIR" "$MOUNT_DIR"
|
||||
|
||||
_USED_PORTS=()
|
||||
|
||||
pick_free_port() {
|
||||
local candidate
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
while true; do
|
||||
candidate="$(python3 - <<'PY'
|
||||
import socket
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.bind(("127.0.0.1", 0))
|
||||
print(s.getsockname()[1])
|
||||
s.close()
|
||||
PY
|
||||
)"
|
||||
if [[ ! " ${_USED_PORTS[*]} " =~ " ${candidate} " ]]; then
|
||||
_USED_PORTS+=("$candidate")
|
||||
printf '%s\n' "$candidate"
|
||||
return
|
||||
fi
|
||||
done
|
||||
fi
|
||||
while true; do
|
||||
candidate="$(shuf -i 20000-60999 -n 1)"
|
||||
if [[ ! " ${_USED_PORTS[*]} " =~ " ${candidate} " ]]; then
|
||||
_USED_PORTS+=("$candidate")
|
||||
printf '%s\n' "$candidate"
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
PORT1="${SW_BLOCK_NVME_PORT1:-$(pick_free_port)}"
|
||||
PORT2="${SW_BLOCK_NVME_PORT2:-$(pick_free_port)}"
|
||||
MASTER_ADDR="${SW_BLOCK_MASTER_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R1_DATA_ADDR="${SW_BLOCK_R1_DATA_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R1_CTRL_ADDR="${SW_BLOCK_R1_CTRL_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R1_STATUS_ADDR="${SW_BLOCK_R1_STATUS_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R2_DATA_ADDR="${SW_BLOCK_R2_DATA_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R2_CTRL_ADDR="${SW_BLOCK_R2_CTRL_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R2_STATUS_ADDR="${SW_BLOCK_R2_STATUS_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
MASTER_PID=""
|
||||
R1_PID=""
|
||||
R2_PID=""
|
||||
|
||||
log() {
|
||||
printf '[nvme-failover] %s\n' "$*" | tee -a "$ARTIFACT_DIR/run.log"
|
||||
}
|
||||
|
||||
require_cmd() {
|
||||
if ! command -v "$1" >/dev/null 2>&1; then
|
||||
echo "missing required command: $1" >&2
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
disconnect_nqn() {
|
||||
sudo nvme disconnect -n "$SUBSYS_NQN" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
set +e
|
||||
log "cleanup"
|
||||
mountpoint -q "$MOUNT_DIR" && sudo umount "$MOUNT_DIR" >>"$ARTIFACT_DIR/cleanup.log" 2>&1
|
||||
disconnect_nqn
|
||||
[[ -n "$R1_PID" ]] && kill "$R1_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$R2_PID" ]] && kill "$R2_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$MASTER_PID" ]] && kill "$MASTER_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -TERM -f "${BIN_DIR}/blockvolume" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -TERM -f "${BIN_DIR}/blockmaster" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
sleep 1
|
||||
[[ -n "$R1_PID" ]] && kill -KILL "$R1_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$R2_PID" ]] && kill -KILL "$R2_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$MASTER_PID" ]] && kill -KILL "$MASTER_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -KILL -f "${BIN_DIR}/blockvolume" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -KILL -f "${BIN_DIR}/blockmaster" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.after.json" 2>&1 || true
|
||||
pgrep -af "${BIN_DIR}/blockmaster|${BIN_DIR}/blockvolume" >"$ARTIFACT_DIR/processes.after.txt" 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
wait_port() {
|
||||
local port="$1"
|
||||
for _ in $(seq 1 100); do
|
||||
if bash -c "</dev/tcp/127.0.0.1/${port}" >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
echo "timed out waiting for port ${port}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_status_role() {
|
||||
local status_addr="$1"
|
||||
local replica="$2"
|
||||
local role="$3"
|
||||
local min_epoch="${4:-0}"
|
||||
local out="$ARTIFACT_DIR/status-${replica}-${role}.json"
|
||||
for _ in $(seq 1 240); do
|
||||
if curl -fsS "http://${status_addr}/status?volume=v1" >"$out.tmp" 2>/dev/null; then
|
||||
if python3 - "$out.tmp" "$replica" "$role" "$min_epoch" <<'PY'
|
||||
import json, sys
|
||||
path, replica, role, min_epoch = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4])
|
||||
body = json.load(open(path))
|
||||
if str(body.get("ReplicaID", "")) != replica:
|
||||
sys.exit(1)
|
||||
epoch = int(body.get("Epoch", 0))
|
||||
authority_role = str(body.get("AuthorityRole", ""))
|
||||
frontend_ready = bool(body.get("FrontendPrimaryReady"))
|
||||
replication_role = str(body.get("ReplicationRole", ""))
|
||||
if role == "primary":
|
||||
sys.exit(0 if authority_role == "primary" and frontend_ready and epoch >= min_epoch else 1)
|
||||
if role == "secondary":
|
||||
ok = authority_role != "primary" and replication_role in ("not_ready", "replica_ready", "recovering")
|
||||
sys.exit(0 if ok else 1)
|
||||
sys.exit(1)
|
||||
PY
|
||||
then
|
||||
mv "$out.tmp" "$out"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
sleep 0.25
|
||||
done
|
||||
curl -fsS "http://${status_addr}/status?volume=v1" >"$ARTIFACT_DIR/status-${replica}-last.json" 2>/dev/null || true
|
||||
pgrep -af "${BIN_DIR}/blockmaster|${BIN_DIR}/blockvolume" >"$ARTIFACT_DIR/processes.${replica}.${role}.timeout.txt" 2>&1 || true
|
||||
echo "timed out waiting for ${replica} ${role} projection" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_log_pattern() {
|
||||
local path="$1"
|
||||
local pattern="$2"
|
||||
local label="$3"
|
||||
for _ in $(seq 1 160); do
|
||||
if grep -q "$pattern" "$path" 2>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
sleep 0.25
|
||||
done
|
||||
echo "timed out waiting for ${label}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
parse_nvme_subsys() {
|
||||
local field="$1"
|
||||
local raw
|
||||
raw="$(sudo nvme list-subsys -o json 2>/dev/null)"
|
||||
python3 - "$SUBSYS_NQN" "$field" "$raw" <<'PY'
|
||||
import glob, json, os, re, sys
|
||||
nqn, field, raw = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
raw = raw.strip()
|
||||
if not raw:
|
||||
sys.exit(1)
|
||||
doc = json.loads(raw)
|
||||
def iter_subsystems(node):
|
||||
if isinstance(node, dict):
|
||||
if "NQN" in node and "Paths" in node:
|
||||
yield node
|
||||
for sub in node.get("Subsystems", []):
|
||||
yield sub
|
||||
elif isinstance(node, list):
|
||||
for item in node:
|
||||
yield from iter_subsystems(item)
|
||||
|
||||
matched = False
|
||||
all_paths = []
|
||||
for sub in iter_subsystems(doc):
|
||||
if sub.get("NQN") != nqn:
|
||||
continue
|
||||
matched = True
|
||||
all_paths.extend(sub.get("Paths", []))
|
||||
if not matched:
|
||||
sys.exit(1)
|
||||
|
||||
ns_devices = []
|
||||
for nqn_file in glob.glob("/sys/class/nvme-subsystem/*/subsysnqn"):
|
||||
try:
|
||||
if open(nqn_file).read().strip() != nqn:
|
||||
continue
|
||||
except OSError:
|
||||
continue
|
||||
sub_dir = os.path.dirname(nqn_file)
|
||||
for entry in os.listdir(sub_dir):
|
||||
if re.fullmatch(r"nvme[0-9]+n[0-9]+", entry):
|
||||
ns_devices.append("/dev/" + entry)
|
||||
|
||||
if field == "path_count":
|
||||
print(len(all_paths))
|
||||
elif field == "devices":
|
||||
print("\n".join(sorted(set(ns_devices))))
|
||||
elif field == "paths":
|
||||
for path in all_paths:
|
||||
print(path)
|
||||
else:
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
PY
|
||||
}
|
||||
|
||||
wait_nvme_paths() {
|
||||
for _ in $(seq 1 900); do
|
||||
if count="$(parse_nvme_subsys path_count 2>/dev/null)" && [[ "${count:-0}" -ge 2 ]]; then
|
||||
return 0
|
||||
fi
|
||||
sleep 0.2
|
||||
done
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.timeout.json" 2>&1 || true
|
||||
echo "timed out waiting for two NVMe paths for ${SUBSYS_NQN}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_grouped_device() {
|
||||
for _ in $(seq 1 900); do
|
||||
parse_nvme_subsys devices >"$ARTIFACT_DIR/devices.txt" 2>/dev/null || true
|
||||
local count
|
||||
count="$(grep -c '^/dev/' "$ARTIFACT_DIR/devices.txt" || true)"
|
||||
if [[ "$count" -eq 1 ]]; then
|
||||
local dev
|
||||
dev="$(head -n1 "$ARTIFACT_DIR/devices.txt")"
|
||||
if [[ -b "$dev" ]]; then
|
||||
printf '%s\n' "$dev"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
sleep 0.2
|
||||
done
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.device-timeout.json" 2>&1 || true
|
||||
echo "timed out waiting for one grouped NVMe namespace device" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
require_cmd sudo
|
||||
require_cmd nvme
|
||||
require_cmd curl
|
||||
require_cmd python3
|
||||
require_cmd mkfs.ext4
|
||||
require_cmd mount
|
||||
require_cmd sha256sum
|
||||
|
||||
log "run_id=$RUN_ID"
|
||||
log "root=$ROOT"
|
||||
log "artifact_dir=$ARTIFACT_DIR"
|
||||
log "nqn=$SUBSYS_NQN"
|
||||
log "portals=127.0.0.1:${PORT1},127.0.0.1:${PORT2}"
|
||||
log "master=${MASTER_ADDR}"
|
||||
log "size_blocks=${BLOCKS} block_size=${BLOCK_SIZE}"
|
||||
log "durable_impl=${DURABLE_IMPL}"
|
||||
|
||||
if [[ -r /sys/module/nvme_core/parameters/multipath ]]; then
|
||||
cat /sys/module/nvme_core/parameters/multipath >"$ARTIFACT_DIR/nvme-core-multipath.txt"
|
||||
log "nvme_core_multipath=$(cat "$ARTIFACT_DIR/nvme-core-multipath.txt")"
|
||||
else
|
||||
echo "missing" >"$ARTIFACT_DIR/nvme-core-multipath.txt"
|
||||
log "nvme_core_multipath=missing"
|
||||
fi
|
||||
|
||||
cd "$ROOT"
|
||||
git rev-parse --short HEAD >"$ARTIFACT_DIR/git-head.txt" 2>/dev/null || true
|
||||
|
||||
if [[ -x "${BIN_DIR}/blockmaster" && -x "${BIN_DIR}/blockvolume" ]]; then
|
||||
log "use prebuilt binaries from ${BIN_DIR}"
|
||||
else
|
||||
require_cmd go
|
||||
log "build binaries"
|
||||
go build -o "${BIN_DIR}/blockmaster" ./cmd/blockmaster
|
||||
go build -o "${BIN_DIR}/blockvolume" ./cmd/blockvolume
|
||||
fi
|
||||
|
||||
cat >"$ARTIFACT_DIR/topology.yaml" <<YAML
|
||||
volumes:
|
||||
- volume_id: v1
|
||||
slots:
|
||||
- replica_id: r1
|
||||
server_id: s1
|
||||
- replica_id: r2
|
||||
server_id: s2
|
||||
YAML
|
||||
|
||||
rm -rf "${RUN_DIR}/master-store" "${RUN_DIR}/r1-store" "${RUN_DIR}/r2-store"
|
||||
mkdir -p "${RUN_DIR}/master-store" "${RUN_DIR}/r1-store" "${RUN_DIR}/r2-store"
|
||||
pkill -KILL -f "${BIN_DIR}/blockvolume" >/dev/null 2>&1 || true
|
||||
pkill -KILL -f "${BIN_DIR}/blockmaster" >/dev/null 2>&1 || true
|
||||
disconnect_nqn
|
||||
sudo modprobe nvme_tcp >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.before.json" 2>&1 || true
|
||||
sudo dmesg >"$ARTIFACT_DIR/dmesg.before.txt" 2>&1 || true
|
||||
|
||||
log "start blockmaster"
|
||||
"${BIN_DIR}/blockmaster" \
|
||||
--authority-store "${RUN_DIR}/master-store" \
|
||||
--listen "$MASTER_ADDR" \
|
||||
--topology "$ARTIFACT_DIR/topology.yaml" \
|
||||
--expected-slots-per-volume 2 \
|
||||
--freshness-window 800ms \
|
||||
--pending-grace 100ms \
|
||||
--t0-print-ready \
|
||||
>"$ARTIFACT_DIR/blockmaster.log" 2>&1 &
|
||||
MASTER_PID=$!
|
||||
for _ in $(seq 1 100); do
|
||||
if ! kill -0 "$MASTER_PID" >/dev/null 2>&1; then
|
||||
cat "$ARTIFACT_DIR/blockmaster.log" >&2 || true
|
||||
echo "blockmaster exited during startup" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -q '"component":"blockmaster".*"phase":"listening"' "$ARTIFACT_DIR/blockmaster.log"; then
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
start_blockvolume() {
|
||||
local replica="$1"
|
||||
local server="$2"
|
||||
local port="$3"
|
||||
local data_addr="$4"
|
||||
local ctrl_addr="$5"
|
||||
local status_addr="$6"
|
||||
local store="$7"
|
||||
local log_file="$8"
|
||||
|
||||
"${BIN_DIR}/blockvolume" \
|
||||
--master "$MASTER_ADDR" \
|
||||
--server-id "$server" \
|
||||
--volume-id v1 \
|
||||
--replica-id "$replica" \
|
||||
--data-addr "$data_addr" \
|
||||
--ctrl-addr "$ctrl_addr" \
|
||||
--status-addr "$status_addr" \
|
||||
--heartbeat-interval 200ms \
|
||||
--t1-readiness \
|
||||
--durable-root "$store" \
|
||||
--durable-impl "$DURABLE_IMPL" \
|
||||
--durable-blocks "$BLOCKS" \
|
||||
--durable-blocksize "$BLOCK_SIZE" \
|
||||
--nvme-listen "127.0.0.1:${port}" \
|
||||
--nvme-subsysnqn "$SUBSYS_NQN" \
|
||||
--nvme-ns "$NSID" \
|
||||
>"$log_file" 2>&1 &
|
||||
}
|
||||
|
||||
log "start r1 NVMe path"
|
||||
start_blockvolume r1 s1 "$PORT1" "$R1_DATA_ADDR" "$R1_CTRL_ADDR" "$R1_STATUS_ADDR" \
|
||||
"${RUN_DIR}/r1-store" "$ARTIFACT_DIR/blockvolume-r1.log"
|
||||
R1_PID=$!
|
||||
wait_port "$PORT1"
|
||||
|
||||
log "start r2 NVMe path"
|
||||
start_blockvolume r2 s2 "$PORT2" "$R2_DATA_ADDR" "$R2_CTRL_ADDR" "$R2_STATUS_ADDR" \
|
||||
"${RUN_DIR}/r2-store" "$ARTIFACT_DIR/blockvolume-r2.log"
|
||||
R2_PID=$!
|
||||
wait_port "$PORT2"
|
||||
|
||||
log "wait authority projections"
|
||||
wait_status_role "$R1_STATUS_ADDR" r1 primary 1
|
||||
wait_status_role "$R2_STATUS_ADDR" r2 secondary 0
|
||||
wait_log_pattern "$ARTIFACT_DIR/blockvolume-r2.log" "using ANA metadata probe backend" "r2 ANA metadata probe readiness"
|
||||
|
||||
log "connect first NVMe path"
|
||||
sudo nvme connect -t tcp -a 127.0.0.1 -s "$PORT1" -n "$SUBSYS_NQN" \
|
||||
>"$ARTIFACT_DIR/nvme-connect-r1.log" 2>&1
|
||||
log "connect second NVMe path"
|
||||
sudo nvme connect -t tcp -a 127.0.0.1 -s "$PORT2" -n "$SUBSYS_NQN" \
|
||||
>"$ARTIFACT_DIR/nvme-connect-r2.log" 2>&1
|
||||
|
||||
wait_nvme_paths
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.before-failover.json" 2>&1 || true
|
||||
parse_nvme_subsys paths >"$ARTIFACT_DIR/path-summary.before-failover.txt" || true
|
||||
map_dev="$(wait_grouped_device)"
|
||||
log "nvme_namespace_device=${map_dev}"
|
||||
|
||||
log "mkfs/mount NVMe multipath namespace"
|
||||
sudo mkfs.ext4 -F "$map_dev" >"$ARTIFACT_DIR/mkfs.log" 2>&1
|
||||
sudo mount "$map_dev" "$MOUNT_DIR"
|
||||
|
||||
log "write pre-failover payload"
|
||||
sudo dd if=/dev/urandom of="$MOUNT_DIR/pre.bin" bs=4096 count=64 status=none
|
||||
sync
|
||||
sudo sha256sum "$MOUNT_DIR/pre.bin" | tee "$ARTIFACT_DIR/pre.sha256"
|
||||
|
||||
if [[ -z "$R1_PID" ]] || ! kill -0 "$R1_PID" >/dev/null 2>&1; then
|
||||
echo "could not find live r1 blockvolume pid" >&2
|
||||
exit 1
|
||||
fi
|
||||
log "kill active r1 pid=${R1_PID}"
|
||||
kill -TERM "$R1_PID" || true
|
||||
sleep 1
|
||||
if kill -0 "$R1_PID" >/dev/null 2>&1; then
|
||||
kill -KILL "$R1_PID" >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
log "wait r2 failover"
|
||||
wait_status_role "$R2_STATUS_ADDR" r2 primary 2
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.after-failover.json" 2>&1 || true
|
||||
parse_nvme_subsys paths >"$ARTIFACT_DIR/path-summary.after-failover.txt" || true
|
||||
sleep 3
|
||||
|
||||
log "verify mounted workload after failover"
|
||||
sudo sha256sum -c "$ARTIFACT_DIR/pre.sha256" | tee "$ARTIFACT_DIR/pre-check-after-failover.log"
|
||||
sudo dd if=/dev/urandom of="$MOUNT_DIR/post.bin" bs=4096 count=64 status=none
|
||||
sync
|
||||
sudo sha256sum "$MOUNT_DIR/post.bin" | tee "$ARTIFACT_DIR/post.sha256"
|
||||
sudo sha256sum -c "$ARTIFACT_DIR/post.sha256" | tee "$ARTIFACT_DIR/post-check.log"
|
||||
|
||||
log "unmount"
|
||||
sudo umount "$MOUNT_DIR"
|
||||
|
||||
log "disconnect NVMe subsystem"
|
||||
disconnect_nqn
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.final.json" 2>&1 || true
|
||||
if grep -q "$SUBSYS_NQN" "$ARTIFACT_DIR/nvme-list-subsys.final.json"; then
|
||||
echo "NVMe subsystem still present after disconnect: $SUBSYS_NQN" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "PASS: mounted NVMe multipath workload read/wrote through r1->r2 failover"
|
||||
log "artifacts=$ARTIFACT_DIR"
|
||||
+533
@@ -0,0 +1,533 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="${1:-$(pwd)}"
|
||||
RUN_ID="${RUN_ID:-$(date -u +%Y%m%dT%H%M%SZ)}"
|
||||
WORK_DIR="${SW_BLOCK_NVME_MPATH_WORK_DIR:-/tmp/sw-block-nvme-mpath}"
|
||||
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${WORK_DIR}/runs/${RUN_ID}}"
|
||||
SUBSYS_NQN="${SW_BLOCK_NVME_NQN:-nqn.2026-05.io.seaweedfs:mpath-v1}"
|
||||
NSID="${SW_BLOCK_NVME_NSID:-1}"
|
||||
BLOCKS="${SW_BLOCK_DURABLE_BLOCKS:-65536}"
|
||||
BLOCK_SIZE="${SW_BLOCK_DURABLE_BLOCKSIZE:-4096}"
|
||||
DURABLE_IMPL="${SW_BLOCK_DURABLE_IMPL:-smartwal}"
|
||||
BIN_DIR="${SW_BLOCK_BIN_DIR:-${WORK_DIR}/bin}"
|
||||
RUN_DIR="${WORK_DIR}/run"
|
||||
|
||||
mkdir -p "$ARTIFACT_DIR" "$BIN_DIR" "$RUN_DIR"
|
||||
|
||||
_USED_PORTS=()
|
||||
|
||||
pick_free_port() {
|
||||
local candidate
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
while true; do
|
||||
candidate="$(python3 - <<'PY'
|
||||
import socket
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.bind(("127.0.0.1", 0))
|
||||
print(s.getsockname()[1])
|
||||
s.close()
|
||||
PY
|
||||
)"
|
||||
if [[ ! " ${_USED_PORTS[*]} " =~ " ${candidate} " ]]; then
|
||||
_USED_PORTS+=("$candidate")
|
||||
printf '%s\n' "$candidate"
|
||||
return
|
||||
fi
|
||||
done
|
||||
fi
|
||||
while true; do
|
||||
candidate="$(shuf -i 20000-60999 -n 1)"
|
||||
if [[ ! " ${_USED_PORTS[*]} " =~ " ${candidate} " ]]; then
|
||||
_USED_PORTS+=("$candidate")
|
||||
printf '%s\n' "$candidate"
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
PORT1="${SW_BLOCK_NVME_PORT1:-$(pick_free_port)}"
|
||||
PORT2="${SW_BLOCK_NVME_PORT2:-$(pick_free_port)}"
|
||||
MASTER_ADDR="${SW_BLOCK_MASTER_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R1_DATA_ADDR="${SW_BLOCK_R1_DATA_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R1_CTRL_ADDR="${SW_BLOCK_R1_CTRL_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R1_STATUS_ADDR="${SW_BLOCK_R1_STATUS_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R2_DATA_ADDR="${SW_BLOCK_R2_DATA_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R2_CTRL_ADDR="${SW_BLOCK_R2_CTRL_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
R2_STATUS_ADDR="${SW_BLOCK_R2_STATUS_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
MASTER_PID=""
|
||||
R1_PID=""
|
||||
R2_PID=""
|
||||
|
||||
log() {
|
||||
printf '[nvme-mpath] %s\n' "$*" | tee -a "$ARTIFACT_DIR/run.log"
|
||||
}
|
||||
|
||||
require_cmd() {
|
||||
if ! command -v "$1" >/dev/null 2>&1; then
|
||||
echo "missing required command: $1" >&2
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
disconnect_nqn() {
|
||||
sudo nvme disconnect -n "$SUBSYS_NQN" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
set +e
|
||||
log "cleanup"
|
||||
disconnect_nqn
|
||||
[[ -n "$R1_PID" ]] && kill "$R1_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$R2_PID" ]] && kill "$R2_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$MASTER_PID" ]] && kill "$MASTER_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -TERM -f "${BIN_DIR}/blockvolume" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -TERM -f "${BIN_DIR}/blockmaster" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
sleep 1
|
||||
[[ -n "$R1_PID" ]] && kill -KILL "$R1_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$R2_PID" ]] && kill -KILL "$R2_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$MASTER_PID" ]] && kill -KILL "$MASTER_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -KILL -f "${BIN_DIR}/blockvolume" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -KILL -f "${BIN_DIR}/blockmaster" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.after.json" 2>&1 || true
|
||||
pgrep -af "${BIN_DIR}/blockmaster|${BIN_DIR}/blockvolume" >"$ARTIFACT_DIR/processes.after.txt" 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
wait_port() {
|
||||
local port="$1"
|
||||
for _ in $(seq 1 100); do
|
||||
if bash -c "</dev/tcp/127.0.0.1/${port}" >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
echo "timed out waiting for port ${port}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_status_role() {
|
||||
local status_addr="$1"
|
||||
local replica="$2"
|
||||
local role="$3"
|
||||
local out="$ARTIFACT_DIR/status-${replica}-${role}.json"
|
||||
for _ in $(seq 1 120); do
|
||||
if curl -fsS "http://${status_addr}/status?volume=v1" >"$out.tmp" 2>/dev/null; then
|
||||
if python3 - "$out.tmp" "$replica" "$role" <<'PY'
|
||||
import json, sys
|
||||
path, replica, role = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
body = json.load(open(path))
|
||||
if str(body.get("ReplicaID", "")) != replica:
|
||||
sys.exit(1)
|
||||
authority_role = str(body.get("AuthorityRole", ""))
|
||||
frontend_ready = bool(body.get("FrontendPrimaryReady"))
|
||||
replication_role = str(body.get("ReplicationRole", ""))
|
||||
if role == "primary":
|
||||
sys.exit(0 if authority_role == "primary" and frontend_ready else 1)
|
||||
if role == "secondary":
|
||||
ok = authority_role != "primary" and replication_role in ("not_ready", "replica_ready", "recovering")
|
||||
sys.exit(0 if ok else 1)
|
||||
sys.exit(1)
|
||||
PY
|
||||
then
|
||||
mv "$out.tmp" "$out"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
sleep 0.25
|
||||
done
|
||||
curl -fsS "http://${status_addr}/status?volume=v1" >"$ARTIFACT_DIR/status-${replica}-last.json" 2>/dev/null || true
|
||||
pgrep -af "${BIN_DIR}/blockmaster|${BIN_DIR}/blockvolume" >"$ARTIFACT_DIR/processes.${replica}.${role}.timeout.txt" 2>&1 || true
|
||||
echo "timed out waiting for ${replica} ${role} projection" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
wait_log_pattern() {
|
||||
local path="$1"
|
||||
local pattern="$2"
|
||||
local label="$3"
|
||||
for _ in $(seq 1 160); do
|
||||
if grep -q "$pattern" "$path" 2>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
sleep 0.25
|
||||
done
|
||||
echo "timed out waiting for ${label}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
parse_nvme_subsys() {
|
||||
local field="$1"
|
||||
local raw
|
||||
raw="$(sudo nvme list-subsys -o json 2>/dev/null)"
|
||||
python3 - "$SUBSYS_NQN" "$field" "$raw" <<'PY'
|
||||
import glob, json, os, re, sys
|
||||
nqn, field, raw = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
raw = raw.strip()
|
||||
if not raw:
|
||||
sys.exit(1)
|
||||
doc = json.loads(raw)
|
||||
def iter_subsystems(node):
|
||||
if isinstance(node, dict):
|
||||
if "NQN" in node and "Paths" in node:
|
||||
yield node
|
||||
for sub in node.get("Subsystems", []):
|
||||
yield sub
|
||||
elif isinstance(node, list):
|
||||
for item in node:
|
||||
yield from iter_subsystems(item)
|
||||
|
||||
matched = False
|
||||
all_paths = []
|
||||
subsys_dirs = []
|
||||
for sub in iter_subsystems(doc):
|
||||
if sub.get("NQN") != nqn:
|
||||
continue
|
||||
matched = True
|
||||
all_paths.extend(sub.get("Paths", []))
|
||||
if not matched:
|
||||
sys.exit(1)
|
||||
|
||||
# Namespace devices live under the SUBSYSTEM (post-merge under native
|
||||
# multipath), not under each controller path. Resolve via sysfs:
|
||||
# /sys/class/nvme-subsystem/<sub>/subsysnqn matches our NQN, then
|
||||
# list direct nvmeXnY children.
|
||||
ns_devices = []
|
||||
for nqn_file in glob.glob("/sys/class/nvme-subsystem/*/subsysnqn"):
|
||||
try:
|
||||
if open(nqn_file).read().strip() != nqn:
|
||||
continue
|
||||
except OSError:
|
||||
continue
|
||||
sub_dir = os.path.dirname(nqn_file)
|
||||
for entry in os.listdir(sub_dir):
|
||||
if re.fullmatch(r"nvme[0-9]+n[0-9]+", entry):
|
||||
ns_devices.append("/dev/" + entry)
|
||||
|
||||
if field == "path_count":
|
||||
print(len(all_paths))
|
||||
elif field == "devices":
|
||||
print("\n".join(sorted(set(ns_devices))))
|
||||
elif field == "paths":
|
||||
for path in all_paths:
|
||||
print(path)
|
||||
else:
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
PY
|
||||
}
|
||||
|
||||
wait_nvme_paths() {
|
||||
log "wait_nvme_paths: enter (180s budget)"
|
||||
local i
|
||||
for i in $(seq 1 900); do
|
||||
if count="$(parse_nvme_subsys path_count 2>/dev/null)" && [[ "${count:-0}" -ge 2 ]]; then
|
||||
log "wait_nvme_paths: ok at iter=$i count=$count"
|
||||
return 0
|
||||
fi
|
||||
if (( i % 25 == 0 )); then
|
||||
log "wait_nvme_paths: iter=$i count=${count:-empty}"
|
||||
sudo nvme list-subsys -o json >>"$ARTIFACT_DIR/wait-debug.json" 2>&1 || true
|
||||
printf '\n--- iter %s ---\n' "$i" >>"$ARTIFACT_DIR/wait-debug.json" 2>&1 || true
|
||||
fi
|
||||
sleep 0.2
|
||||
done
|
||||
log "wait_nvme_paths: timeout after 900 iters (last count=${count:-empty})"
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.timeout.json" 2>&1 || true
|
||||
if count="$(parse_nvme_subsys path_count 2>/dev/null)" && [[ "${count:-0}" -ge 2 ]]; then
|
||||
log "wait_nvme_paths: ok on post-timeout recheck count=$count"
|
||||
return 0
|
||||
fi
|
||||
echo "timed out waiting for two NVMe paths for ${SUBSYS_NQN}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
summarize_ana_log() {
|
||||
local bin="$1"
|
||||
local out="$2"
|
||||
python3 - "$bin" "$NSID" >"$out" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
path = sys.argv[1]
|
||||
want_nsid = int(sys.argv[2], 0)
|
||||
data = open(path, "rb").read()
|
||||
if len(data) < 40:
|
||||
raise SystemExit(f"ANA log too short: {len(data)} bytes, want at least 40")
|
||||
state_names = {
|
||||
0x01: "optimized",
|
||||
0x02: "non_optimized",
|
||||
0x03: "inaccessible",
|
||||
0x04: "persistent_loss",
|
||||
0x0F: "change",
|
||||
}
|
||||
change_count = struct.unpack_from("<Q", data, 0)[0]
|
||||
group_count = struct.unpack_from("<H", data, 8)[0]
|
||||
group_id = struct.unpack_from("<I", data, 16)[0]
|
||||
nsid_count = struct.unpack_from("<I", data, 20)[0]
|
||||
group_change_count = struct.unpack_from("<Q", data, 24)[0]
|
||||
state = data[32]
|
||||
nsid = struct.unpack_from("<I", data, 36)[0]
|
||||
print(f"ana_change_count={change_count}")
|
||||
print(f"ana_group_count={group_count}")
|
||||
print(f"ana_group_id={group_id}")
|
||||
print(f"ana_nsid_count={nsid_count}")
|
||||
print(f"ana_group_change_count={group_change_count}")
|
||||
print(f"ana_state=0x{state:02x} {state_names.get(state, 'unknown')}")
|
||||
print(f"ana_nsid={nsid}")
|
||||
if group_count != 1:
|
||||
raise SystemExit(f"ANA group count={group_count}, want 1")
|
||||
if group_id != 1:
|
||||
raise SystemExit(f"ANA group id={group_id}, want 1 for current single-group model")
|
||||
if nsid_count != 1:
|
||||
raise SystemExit(f"ANA NSID count={nsid_count}, want 1")
|
||||
if nsid != want_nsid:
|
||||
raise SystemExit(f"ANA NSID={nsid}, want {want_nsid}")
|
||||
if state not in state_names:
|
||||
raise SystemExit(f"ANA state=0x{state:02x} is not recognized")
|
||||
PY
|
||||
}
|
||||
|
||||
require_cmd sudo
|
||||
require_cmd nvme
|
||||
require_cmd curl
|
||||
require_cmd python3
|
||||
|
||||
log "run_id=$RUN_ID"
|
||||
log "root=$ROOT"
|
||||
log "artifact_dir=$ARTIFACT_DIR"
|
||||
log "nqn=$SUBSYS_NQN"
|
||||
log "nsid=$NSID"
|
||||
log "portals=127.0.0.1:${PORT1},127.0.0.1:${PORT2}"
|
||||
log "master=${MASTER_ADDR}"
|
||||
log "size_blocks=${BLOCKS} block_size=${BLOCK_SIZE}"
|
||||
log "durable_impl=${DURABLE_IMPL}"
|
||||
|
||||
if [[ -r /sys/module/nvme_core/parameters/multipath ]]; then
|
||||
cat /sys/module/nvme_core/parameters/multipath >"$ARTIFACT_DIR/nvme-core-multipath.txt"
|
||||
log "nvme_core_multipath=$(cat "$ARTIFACT_DIR/nvme-core-multipath.txt")"
|
||||
else
|
||||
echo "missing" >"$ARTIFACT_DIR/nvme-core-multipath.txt"
|
||||
log "nvme_core_multipath=missing"
|
||||
fi
|
||||
|
||||
cd "$ROOT"
|
||||
git rev-parse --short HEAD >"$ARTIFACT_DIR/git-head.txt" 2>/dev/null || true
|
||||
|
||||
if [[ -x "${BIN_DIR}/blockmaster" && -x "${BIN_DIR}/blockvolume" ]]; then
|
||||
log "use prebuilt binaries from ${BIN_DIR}"
|
||||
else
|
||||
require_cmd go
|
||||
log "build binaries"
|
||||
go build -o "${BIN_DIR}/blockmaster" ./cmd/blockmaster
|
||||
go build -o "${BIN_DIR}/blockvolume" ./cmd/blockvolume
|
||||
fi
|
||||
|
||||
cat >"$ARTIFACT_DIR/topology.yaml" <<YAML
|
||||
volumes:
|
||||
- volume_id: v1
|
||||
slots:
|
||||
- replica_id: r1
|
||||
server_id: s1
|
||||
- replica_id: r2
|
||||
server_id: s2
|
||||
YAML
|
||||
|
||||
rm -rf "${RUN_DIR}/master-store" "${RUN_DIR}/r1-store" "${RUN_DIR}/r2-store"
|
||||
mkdir -p "${RUN_DIR}/master-store" "${RUN_DIR}/r1-store" "${RUN_DIR}/r2-store"
|
||||
pkill -KILL -f "${BIN_DIR}/blockvolume" >/dev/null 2>&1 || true
|
||||
pkill -KILL -f "${BIN_DIR}/blockmaster" >/dev/null 2>&1 || true
|
||||
disconnect_nqn
|
||||
sudo modprobe nvme_tcp >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.before.json" 2>&1 || true
|
||||
sudo dmesg >"$ARTIFACT_DIR/dmesg.before.txt" 2>&1 || true
|
||||
|
||||
log "start blockmaster"
|
||||
"${BIN_DIR}/blockmaster" \
|
||||
--authority-store "${RUN_DIR}/master-store" \
|
||||
--listen "$MASTER_ADDR" \
|
||||
--topology "$ARTIFACT_DIR/topology.yaml" \
|
||||
--expected-slots-per-volume 2 \
|
||||
--t0-print-ready \
|
||||
>"$ARTIFACT_DIR/blockmaster.log" 2>&1 &
|
||||
MASTER_PID=$!
|
||||
for _ in $(seq 1 100); do
|
||||
if ! kill -0 "$MASTER_PID" >/dev/null 2>&1; then
|
||||
cat "$ARTIFACT_DIR/blockmaster.log" >&2 || true
|
||||
echo "blockmaster exited during startup" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -q '"component":"blockmaster".*"phase":"listening"' "$ARTIFACT_DIR/blockmaster.log"; then
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
if ! grep -q '"component":"blockmaster".*"phase":"listening"' "$ARTIFACT_DIR/blockmaster.log"; then
|
||||
cat "$ARTIFACT_DIR/blockmaster.log" >&2 || true
|
||||
echo "blockmaster did not report ready" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
start_blockvolume() {
|
||||
local replica="$1"
|
||||
local server="$2"
|
||||
local port="$3"
|
||||
local data_addr="$4"
|
||||
local ctrl_addr="$5"
|
||||
local status_addr="$6"
|
||||
local store="$7"
|
||||
local log_file="$8"
|
||||
|
||||
"${BIN_DIR}/blockvolume" \
|
||||
--master "$MASTER_ADDR" \
|
||||
--server-id "$server" \
|
||||
--volume-id v1 \
|
||||
--replica-id "$replica" \
|
||||
--data-addr "$data_addr" \
|
||||
--ctrl-addr "$ctrl_addr" \
|
||||
--status-addr "$status_addr" \
|
||||
--heartbeat-interval 200ms \
|
||||
--t1-readiness \
|
||||
--durable-root "$store" \
|
||||
--durable-impl "$DURABLE_IMPL" \
|
||||
--durable-blocks "$BLOCKS" \
|
||||
--durable-blocksize "$BLOCK_SIZE" \
|
||||
--nvme-listen "127.0.0.1:${port}" \
|
||||
--nvme-subsysnqn "$SUBSYS_NQN" \
|
||||
--nvme-ns "$NSID" \
|
||||
>"$log_file" 2>&1 &
|
||||
}
|
||||
|
||||
log "start r1 NVMe path"
|
||||
start_blockvolume r1 s1 "$PORT1" "$R1_DATA_ADDR" "$R1_CTRL_ADDR" "$R1_STATUS_ADDR" \
|
||||
"${RUN_DIR}/r1-store" "$ARTIFACT_DIR/blockvolume-r1.log"
|
||||
R1_PID=$!
|
||||
wait_port "$PORT1"
|
||||
|
||||
log "start r2 NVMe path"
|
||||
start_blockvolume r2 s2 "$PORT2" "$R2_DATA_ADDR" "$R2_CTRL_ADDR" "$R2_STATUS_ADDR" \
|
||||
"${RUN_DIR}/r2-store" "$ARTIFACT_DIR/blockvolume-r2.log"
|
||||
R2_PID=$!
|
||||
wait_port "$PORT2"
|
||||
|
||||
log "wait authority projections"
|
||||
wait_status_role "$R1_STATUS_ADDR" r1 primary
|
||||
wait_status_role "$R2_STATUS_ADDR" r2 secondary
|
||||
wait_log_pattern "$ARTIFACT_DIR/blockvolume-r2.log" "using ANA metadata probe backend" "r2 ANA metadata probe readiness"
|
||||
|
||||
log "connect first NVMe path"
|
||||
set +e
|
||||
sudo nvme connect -t tcp -a 127.0.0.1 -s "$PORT1" -n "$SUBSYS_NQN" \
|
||||
>"$ARTIFACT_DIR/nvme-connect-r1.log" 2>&1
|
||||
rc1=$?
|
||||
set -e
|
||||
log "connect first NVMe path: rc=$rc1"
|
||||
if [[ $rc1 -ne 0 ]]; then
|
||||
cat "$ARTIFACT_DIR/nvme-connect-r1.log" >&2 || true
|
||||
echo "first nvme connect failed rc=$rc1" >&2
|
||||
exit 1
|
||||
fi
|
||||
log "connect second NVMe path"
|
||||
set +e
|
||||
sudo nvme connect -t tcp -a 127.0.0.1 -s "$PORT2" -n "$SUBSYS_NQN" \
|
||||
>"$ARTIFACT_DIR/nvme-connect-r2.log" 2>&1
|
||||
rc2=$?
|
||||
set -e
|
||||
log "connect second NVMe path: rc=$rc2"
|
||||
if [[ $rc2 -ne 0 ]]; then
|
||||
cat "$ARTIFACT_DIR/nvme-connect-r2.log" >&2 || true
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.connect-failed.json" 2>&1 || true
|
||||
echo "second nvme connect failed rc=$rc2" >&2
|
||||
exit 1
|
||||
fi
|
||||
log "post-connect snapshot"
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.post-connect.json" 2>&1 || true
|
||||
|
||||
wait_nvme_paths
|
||||
sudo nvme list >"$ARTIFACT_DIR/nvme-list.txt" 2>&1 || true
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.json" 2>&1 || true
|
||||
parse_nvme_subsys paths >"$ARTIFACT_DIR/path-summary.txt" || true
|
||||
parse_nvme_subsys devices >"$ARTIFACT_DIR/devices.txt"
|
||||
|
||||
path_count="$(parse_nvme_subsys path_count)"
|
||||
device_count="$(grep -c '^/dev/' "$ARTIFACT_DIR/devices.txt" || true)"
|
||||
log "nvme_path_count=$path_count"
|
||||
log "nvme_namespace_devices=$device_count"
|
||||
if [[ "$path_count" -lt 2 ]]; then
|
||||
echo "NVMe subsystem did not show two paths" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$device_count" -lt 1 ]]; then
|
||||
cat "$ARTIFACT_DIR/nvme-list-subsys.json" >&2
|
||||
echo "NVMe subsystem reported paths but no namespace device" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$(cat "$ARTIFACT_DIR/nvme-core-multipath.txt")" == "Y" && "$device_count" -ne 1 ]]; then
|
||||
cat "$ARTIFACT_DIR/nvme-list-subsys.json" >&2
|
||||
echo "native NVMe multipath is enabled but host exposed ${device_count} namespace devices; expected one grouped namespace" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
idx=0
|
||||
while IFS= read -r dev; do
|
||||
[[ -n "$dev" ]] || continue
|
||||
idx=$((idx + 1))
|
||||
log "capture identity and ANA for ${dev}"
|
||||
sudo nvme id-ctrl "$dev" >"$ARTIFACT_DIR/nvme-id-ctrl.dev${idx}.txt" 2>&1
|
||||
sudo nvme id-ns "$dev" >"$ARTIFACT_DIR/nvme-id-ns.dev${idx}.txt" 2>&1
|
||||
sudo nvme get-log "$dev" -i 0x0c -l 40 -b \
|
||||
>"$ARTIFACT_DIR/nvme-ana-log.dev${idx}.bin" \
|
||||
2>"$ARTIFACT_DIR/nvme-ana-log.dev${idx}.stderr"
|
||||
summarize_ana_log "$ARTIFACT_DIR/nvme-ana-log.dev${idx}.bin" "$ARTIFACT_DIR/nvme-ana-log.dev${idx}.summary"
|
||||
done <"$ARTIFACT_DIR/devices.txt"
|
||||
|
||||
python3 - "$ARTIFACT_DIR" "$device_count" <<'PY'
|
||||
import pathlib, re, sys
|
||||
art = pathlib.Path(sys.argv[1])
|
||||
device_count = int(sys.argv[2])
|
||||
ids = []
|
||||
for i in range(1, device_count + 1):
|
||||
body = (art / f"nvme-id-ns.dev{i}.txt").read_text(errors="replace")
|
||||
nguid = re.search(r"(?im)^\s*nguid\s*:\s*([0-9a-fA-F]+)", body)
|
||||
eui64 = re.search(r"(?im)^\s*eui64\s*:\s*([0-9a-fA-F]+)", body)
|
||||
anagrpid = re.search(r"(?im)^\s*anagrpid\s*:\s*(\S+)", body)
|
||||
if not nguid or not eui64 or not anagrpid:
|
||||
raise SystemExit(f"missing NGUID/EUI64/ANAGRPID in nvme-id-ns.dev{i}.txt")
|
||||
ids.append((nguid.group(1).lower(), eui64.group(1).lower(), anagrpid.group(1)))
|
||||
if len(set(ids)) != 1:
|
||||
raise SystemExit(f"namespace identity differs across devices: {ids}")
|
||||
(art / "identity-summary.txt").write_text(
|
||||
f"nguid={ids[0][0]}\neui64={ids[0][1]}\nanagrpid={ids[0][2]}\n"
|
||||
)
|
||||
PY
|
||||
|
||||
if grep -R "ana_state=0x03\\|ana_state=0x04\\|ana_state=0x0f" "$ARTIFACT_DIR"/nvme-ana-log.dev*.summary >/dev/null 2>&1; then
|
||||
grep -R "ana_state=" "$ARTIFACT_DIR"/nvme-ana-log.dev*.summary >&2 || true
|
||||
echo "ANA reported inaccessible/persistent-loss/change during steady two-path discovery" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo dmesg >"$ARTIFACT_DIR/dmesg.after.txt" 2>&1 || true
|
||||
python3 - "$ARTIFACT_DIR/dmesg.before.txt" "$ARTIFACT_DIR/dmesg.after.txt" >"$ARTIFACT_DIR/dmesg.new.txt" <<'PY'
|
||||
import sys
|
||||
before = set(open(sys.argv[1], errors="replace").read().splitlines())
|
||||
after = open(sys.argv[2], errors="replace").read().splitlines()
|
||||
for line in after:
|
||||
if line not in before:
|
||||
print(line)
|
||||
PY
|
||||
if grep -Eiq "nvme_parse_ana_log|I/O error|reset controller" "$ARTIFACT_DIR/dmesg.new.txt"; then
|
||||
echo "dmesg contains new NVMe ANA/reset/I/O warning during run" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "disconnect both NVMe paths"
|
||||
disconnect_nqn
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.final.json" 2>&1 || true
|
||||
if grep -q "$SUBSYS_NQN" "$ARTIFACT_DIR/nvme-list-subsys.final.json"; then
|
||||
echo "NVMe subsystem still present after disconnect: $SUBSYS_NQN" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "PASS: two NVMe/TCP paths expose one ANA-aware namespace"
|
||||
log "artifacts=$ARTIFACT_DIR"
|
||||
Executable
+401
@@ -0,0 +1,401 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="${1:-$(pwd)}"
|
||||
RUN_ID="${RUN_ID:-$(date -u +%Y%m%dT%H%M%SZ)}"
|
||||
WORK_DIR="${SW_BLOCK_NVME_WORK_DIR:-/tmp/sw-block-nvme-os}"
|
||||
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${WORK_DIR}/runs/${RUN_ID}}"
|
||||
SUBSYS_NQN="${SW_BLOCK_NVME_NQN:-nqn.2026-05.io.seaweedfs:os-smoke-v1}"
|
||||
NSID="${SW_BLOCK_NVME_NSID:-1}"
|
||||
MOUNT_DIR="${SW_BLOCK_NVME_MOUNT_DIR:-${WORK_DIR}/mnt}"
|
||||
BLOCKS="${SW_BLOCK_DURABLE_BLOCKS:-65536}" # 256 MiB at 4 KiB.
|
||||
BLOCK_SIZE="${SW_BLOCK_DURABLE_BLOCKSIZE:-4096}"
|
||||
DURABLE_IMPL="${SW_BLOCK_DURABLE_IMPL:-smartwal}"
|
||||
ITERATIONS="${SW_BLOCK_NVME_ITERATIONS:-1}"
|
||||
STRESS="${SW_BLOCK_NVME_STRESS:-none}" # none | fio | dd
|
||||
FIO_SIZE="${SW_BLOCK_NVME_FIO_SIZE:-32m}"
|
||||
FIO_RUNTIME="${SW_BLOCK_NVME_FIO_RUNTIME:-10}"
|
||||
FIO_BS="${SW_BLOCK_NVME_FIO_BS:-4k}"
|
||||
DD_BS="${SW_BLOCK_NVME_DD_BS:-1M}"
|
||||
DD_COUNT="${SW_BLOCK_NVME_DD_COUNT:-32}"
|
||||
COLLECT_ANA="${SW_BLOCK_NVME_COLLECT_ANA:-0}"
|
||||
|
||||
BIN_DIR="${SW_BLOCK_BIN_DIR:-${WORK_DIR}/bin}"
|
||||
RUN_DIR="${WORK_DIR}/run"
|
||||
|
||||
mkdir -p "$ARTIFACT_DIR" "$BIN_DIR" "$RUN_DIR" "$MOUNT_DIR"
|
||||
|
||||
_USED_PORTS=()
|
||||
|
||||
pick_free_port() {
|
||||
local candidate
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
while true; do
|
||||
candidate="$(python3 - <<'PY'
|
||||
import socket
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.bind(("127.0.0.1", 0))
|
||||
print(s.getsockname()[1])
|
||||
s.close()
|
||||
PY
|
||||
)"
|
||||
if [[ ! " ${_USED_PORTS[*]} " =~ " ${candidate} " ]]; then
|
||||
_USED_PORTS+=("$candidate")
|
||||
printf '%s\n' "$candidate"
|
||||
return
|
||||
fi
|
||||
done
|
||||
fi
|
||||
while true; do
|
||||
candidate="$(shuf -i 20000-60999 -n 1)"
|
||||
if [[ ! " ${_USED_PORTS[*]} " =~ " ${candidate} " ]]; then
|
||||
_USED_PORTS+=("$candidate")
|
||||
printf '%s\n' "$candidate"
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
PORT="${SW_BLOCK_NVME_PORT:-$(pick_free_port)}"
|
||||
MASTER_ADDR="${SW_BLOCK_MASTER_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
DATA_ADDR="${SW_BLOCK_DATA_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
CTRL_ADDR="${SW_BLOCK_CTRL_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
STATUS_ADDR="${SW_BLOCK_STATUS_ADDR:-127.0.0.1:$(pick_free_port)}"
|
||||
MASTER_PID=""
|
||||
VOLUME_PID=""
|
||||
|
||||
log() {
|
||||
printf '[nvme-os] %s\n' "$*" | tee -a "$ARTIFACT_DIR/run.log"
|
||||
}
|
||||
|
||||
require_cmd() {
|
||||
if ! command -v "$1" >/dev/null 2>&1; then
|
||||
echo "missing required command: $1" >&2
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
disconnect_nqn() {
|
||||
sudo nvme disconnect -n "$SUBSYS_NQN" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
set +e
|
||||
log "cleanup"
|
||||
mountpoint -q "$MOUNT_DIR" && sudo umount "$MOUNT_DIR" >>"$ARTIFACT_DIR/cleanup.log" 2>&1
|
||||
disconnect_nqn
|
||||
[[ -n "$VOLUME_PID" ]] && kill "$VOLUME_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$MASTER_PID" ]] && kill "$MASTER_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -TERM -f "${BIN_DIR}/blockvolume" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -TERM -f "${BIN_DIR}/blockmaster" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
sleep 1
|
||||
[[ -n "$VOLUME_PID" ]] && kill -KILL "$VOLUME_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
[[ -n "$MASTER_PID" ]] && kill -KILL "$MASTER_PID" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -KILL -f "${BIN_DIR}/blockvolume" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
pkill -KILL -f "${BIN_DIR}/blockmaster" >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.after.json" 2>&1 || true
|
||||
pgrep -af "${BIN_DIR}/blockmaster|${BIN_DIR}/blockvolume" >"$ARTIFACT_DIR/processes.after.txt" 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
find_nvme_device() {
|
||||
local nqn="$1"
|
||||
local json
|
||||
json="$(sudo nvme list-subsys -o json 2>/dev/null || true)"
|
||||
if [[ -n "$json" ]] && command -v python3 >/dev/null 2>&1; then
|
||||
python3 -c '
|
||||
import json, re, sys
|
||||
nqn = sys.argv[1]
|
||||
raw = sys.stdin.read().strip()
|
||||
if not raw:
|
||||
sys.exit(1)
|
||||
try:
|
||||
doc = json.loads(raw)
|
||||
except Exception:
|
||||
sys.exit(1)
|
||||
if isinstance(doc, dict):
|
||||
hosts = [doc]
|
||||
else:
|
||||
hosts = doc
|
||||
for host in hosts:
|
||||
for sub in host.get("Subsystems", []):
|
||||
if sub.get("NQN") != nqn:
|
||||
continue
|
||||
for path in sub.get("Paths", []):
|
||||
name = path.get("Name") or ""
|
||||
transport = (path.get("Transport") or "").lower()
|
||||
state = (path.get("State") or "").lower()
|
||||
if name and transport == "tcp" and state in ("live", "connecting", ""):
|
||||
base = name.split("/")[-1]
|
||||
if re.fullmatch(r"nvme[0-9]+n[0-9]+", base):
|
||||
print("/dev/" + base)
|
||||
elif re.fullmatch(r"nvme[0-9]+", base):
|
||||
print("/dev/" + base + "n1")
|
||||
else:
|
||||
print("/dev/" + base)
|
||||
sys.exit(0)
|
||||
sys.exit(1)
|
||||
' "$nqn" <<<"$json"
|
||||
return
|
||||
fi
|
||||
sudo nvme list 2>/dev/null | awk '/SeaweedFS|BlockVol|Seaweed/ {print $1; exit}'
|
||||
}
|
||||
|
||||
wait_nvme_device() {
|
||||
local dev
|
||||
for _ in $(seq 1 150); do
|
||||
dev="$(find_nvme_device "$SUBSYS_NQN" || true)"
|
||||
if [[ -n "$dev" && -b "$dev" ]]; then
|
||||
printf '%s\n' "$dev"
|
||||
return 0
|
||||
fi
|
||||
sleep 0.2
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
require_cmd sudo
|
||||
require_cmd nvme
|
||||
require_cmd mkfs.ext4
|
||||
require_cmd mount
|
||||
require_cmd sha256sum
|
||||
if [[ "$STRESS" == "fio" ]]; then
|
||||
require_cmd fio
|
||||
fi
|
||||
if [[ "$COLLECT_ANA" == "1" ]]; then
|
||||
require_cmd python3
|
||||
fi
|
||||
|
||||
log "run_id=$RUN_ID"
|
||||
log "root=$ROOT"
|
||||
log "artifact_dir=$ARTIFACT_DIR"
|
||||
log "nqn=$SUBSYS_NQN"
|
||||
log "nsid=$NSID"
|
||||
log "portal=127.0.0.1:${PORT}"
|
||||
log "master=${MASTER_ADDR}"
|
||||
log "data_addr=${DATA_ADDR}"
|
||||
log "ctrl_addr=${CTRL_ADDR}"
|
||||
log "status_addr=${STATUS_ADDR}"
|
||||
log "size_blocks=${BLOCKS} block_size=${BLOCK_SIZE}"
|
||||
log "durable_impl=${DURABLE_IMPL}"
|
||||
log "iterations=${ITERATIONS}"
|
||||
log "stress=${STRESS}"
|
||||
log "fio_bs=${FIO_BS}"
|
||||
log "dd_bs=${DD_BS} dd_count=${DD_COUNT}"
|
||||
log "collect_ana=${COLLECT_ANA}"
|
||||
|
||||
cd "$ROOT"
|
||||
git rev-parse --short HEAD >"$ARTIFACT_DIR/git-head.txt" 2>/dev/null || true
|
||||
|
||||
if [[ -x "${BIN_DIR}/blockmaster" && -x "${BIN_DIR}/blockvolume" ]]; then
|
||||
log "use prebuilt binaries from ${BIN_DIR}"
|
||||
else
|
||||
require_cmd go
|
||||
log "build binaries"
|
||||
go build -o "${BIN_DIR}/blockmaster" ./cmd/blockmaster
|
||||
go build -o "${BIN_DIR}/blockvolume" ./cmd/blockvolume
|
||||
fi
|
||||
|
||||
cat >"$ARTIFACT_DIR/topology.yaml" <<YAML
|
||||
volumes:
|
||||
- volume_id: v1
|
||||
slots:
|
||||
- replica_id: r1
|
||||
server_id: s1
|
||||
YAML
|
||||
|
||||
rm -rf "${RUN_DIR}/master-store" "${RUN_DIR}/volume-store"
|
||||
mkdir -p "${RUN_DIR}/master-store" "${RUN_DIR}/volume-store"
|
||||
pkill -KILL -f "${BIN_DIR}/blockvolume" >/dev/null 2>&1 || true
|
||||
pkill -KILL -f "${BIN_DIR}/blockmaster" >/dev/null 2>&1 || true
|
||||
disconnect_nqn
|
||||
sudo modprobe nvme_tcp >>"$ARTIFACT_DIR/cleanup.log" 2>&1 || true
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.before.json" 2>&1 || true
|
||||
|
||||
log "start blockmaster"
|
||||
"${BIN_DIR}/blockmaster" \
|
||||
--authority-store "${RUN_DIR}/master-store" \
|
||||
--listen "$MASTER_ADDR" \
|
||||
--topology "$ARTIFACT_DIR/topology.yaml" \
|
||||
--expected-slots-per-volume 1 \
|
||||
--t0-print-ready \
|
||||
>"$ARTIFACT_DIR/blockmaster.log" 2>&1 &
|
||||
MASTER_PID=$!
|
||||
for _ in $(seq 1 100); do
|
||||
if ! kill -0 "$MASTER_PID" >/dev/null 2>&1; then
|
||||
cat "$ARTIFACT_DIR/blockmaster.log" >&2 || true
|
||||
echo "blockmaster exited during startup" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -q '"component":"blockmaster".*"phase":"listening"' "$ARTIFACT_DIR/blockmaster.log"; then
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
if ! grep -q '"component":"blockmaster".*"phase":"listening"' "$ARTIFACT_DIR/blockmaster.log"; then
|
||||
cat "$ARTIFACT_DIR/blockmaster.log" >&2 || true
|
||||
echo "blockmaster did not report ready" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "start blockvolume NVMe target"
|
||||
"${BIN_DIR}/blockvolume" \
|
||||
--master "$MASTER_ADDR" \
|
||||
--server-id s1 \
|
||||
--volume-id v1 \
|
||||
--replica-id r1 \
|
||||
--data-addr "$DATA_ADDR" \
|
||||
--ctrl-addr "$CTRL_ADDR" \
|
||||
--status-addr "$STATUS_ADDR" \
|
||||
--heartbeat-interval 200ms \
|
||||
--t1-readiness \
|
||||
--durable-root "${RUN_DIR}/volume-store" \
|
||||
--durable-impl "$DURABLE_IMPL" \
|
||||
--durable-blocks "$BLOCKS" \
|
||||
--durable-blocksize "$BLOCK_SIZE" \
|
||||
--nvme-listen "127.0.0.1:${PORT}" \
|
||||
--nvme-subsysnqn "$SUBSYS_NQN" \
|
||||
--nvme-ns "$NSID" \
|
||||
>"$ARTIFACT_DIR/blockvolume.log" 2>&1 &
|
||||
VOLUME_PID=$!
|
||||
|
||||
log "wait NVMe listener"
|
||||
for _ in $(seq 1 100); do
|
||||
if ! kill -0 "$VOLUME_PID" >/dev/null 2>&1; then
|
||||
cat "$ARTIFACT_DIR/blockvolume.log" >&2 || true
|
||||
echo "blockvolume exited during startup" >&2
|
||||
exit 1
|
||||
fi
|
||||
if bash -c "</dev/tcp/127.0.0.1/${PORT}" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
if ! bash -c "</dev/tcp/127.0.0.1/${PORT}" >/dev/null 2>&1; then
|
||||
cat "$ARTIFACT_DIR/blockvolume.log" >&2 || true
|
||||
echo "NVMe listener did not open" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for i in $(seq 1 "$ITERATIONS"); do
|
||||
log "iteration ${i}/${ITERATIONS}: nvme connect"
|
||||
disconnect_nqn
|
||||
sudo nvme connect -t tcp -a 127.0.0.1 -s "$PORT" -n "$SUBSYS_NQN" \
|
||||
>"$ARTIFACT_DIR/nvme-connect.iter${i}.log" 2>&1
|
||||
DEV="$(wait_nvme_device)"
|
||||
log "iteration ${i}/${ITERATIONS}: device=${DEV}"
|
||||
sudo nvme list >"$ARTIFACT_DIR/nvme-list.iter${i}.txt" 2>&1 || true
|
||||
sudo nvme id-ctrl "$DEV" >"$ARTIFACT_DIR/nvme-id-ctrl.iter${i}.txt" 2>&1 || true
|
||||
sudo nvme id-ns "$DEV" >"$ARTIFACT_DIR/nvme-id-ns.iter${i}.txt" 2>&1 || true
|
||||
if [[ "$COLLECT_ANA" == "1" ]]; then
|
||||
log "iteration ${i}/${ITERATIONS}: collect ANA log page"
|
||||
sudo nvme get-log "$DEV" -i 0x0c -l 40 -b \
|
||||
>"$ARTIFACT_DIR/nvme-ana-log.iter${i}.bin" \
|
||||
2>"$ARTIFACT_DIR/nvme-ana-log.iter${i}.stderr"
|
||||
python3 - "$ARTIFACT_DIR/nvme-ana-log.iter${i}.bin" "$NSID" \
|
||||
>"$ARTIFACT_DIR/nvme-ana-log.iter${i}.summary" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
want_nsid = int(sys.argv[2], 0)
|
||||
data = open(path, "rb").read()
|
||||
if len(data) < 40:
|
||||
raise SystemExit(f"ANA log too short: {len(data)} bytes, want at least 40")
|
||||
|
||||
state_names = {
|
||||
0x01: "optimized",
|
||||
0x02: "non_optimized",
|
||||
0x03: "inaccessible",
|
||||
0x04: "persistent_loss",
|
||||
0x0F: "change",
|
||||
}
|
||||
|
||||
change_count = struct.unpack_from("<Q", data, 0)[0]
|
||||
group_count = struct.unpack_from("<H", data, 8)[0]
|
||||
group_id = struct.unpack_from("<I", data, 16)[0]
|
||||
nsid_count = struct.unpack_from("<I", data, 20)[0]
|
||||
group_change_count = struct.unpack_from("<Q", data, 24)[0]
|
||||
state = data[32]
|
||||
nsid = struct.unpack_from("<I", data, 36)[0]
|
||||
|
||||
print(f"ana_change_count={change_count}")
|
||||
print(f"ana_group_count={group_count}")
|
||||
print(f"ana_group_id={group_id}")
|
||||
print(f"ana_nsid_count={nsid_count}")
|
||||
print(f"ana_group_change_count={group_change_count}")
|
||||
print(f"ana_state=0x{state:02x} {state_names.get(state, 'unknown')}")
|
||||
print(f"ana_nsid={nsid}")
|
||||
|
||||
if group_count != 1:
|
||||
raise SystemExit(f"ANA group count={group_count}, want 1")
|
||||
if group_id == 0:
|
||||
raise SystemExit("ANA group id is 0")
|
||||
if nsid_count != 1:
|
||||
raise SystemExit(f"ANA NSID count={nsid_count}, want 1")
|
||||
if nsid != want_nsid:
|
||||
raise SystemExit(f"ANA NSID={nsid}, want {want_nsid}")
|
||||
if state not in state_names:
|
||||
raise SystemExit(f"ANA state=0x{state:02x} is not recognized")
|
||||
PY
|
||||
fi
|
||||
|
||||
log "iteration ${i}/${ITERATIONS}: mkfs/mount"
|
||||
sudo mkfs.ext4 -F "$DEV" >"$ARTIFACT_DIR/mkfs.iter${i}.log" 2>&1
|
||||
sudo mkdir -p "$MOUNT_DIR"
|
||||
sudo mount "$DEV" "$MOUNT_DIR"
|
||||
|
||||
log "iteration ${i}/${ITERATIONS}: checksum write/read"
|
||||
dd if=/dev/urandom of="$ARTIFACT_DIR/payload.iter${i}.bin" bs=4096 count=1 status=none
|
||||
sha256sum "$ARTIFACT_DIR/payload.iter${i}.bin" | awk '{print $1" /tmp/sw-block-nvme-payload.bin"}' >"$ARTIFACT_DIR/payload.iter${i}.sha256"
|
||||
sudo cp "$ARTIFACT_DIR/payload.iter${i}.bin" "$MOUNT_DIR/payload.bin"
|
||||
sudo sync
|
||||
sudo cp "$MOUNT_DIR/payload.bin" /tmp/sw-block-nvme-payload.bin
|
||||
sudo chown "$(id -u):$(id -g)" /tmp/sw-block-nvme-payload.bin
|
||||
sha256sum -c "$ARTIFACT_DIR/payload.iter${i}.sha256" >"$ARTIFACT_DIR/sha256.iter${i}.log"
|
||||
rm -f /tmp/sw-block-nvme-payload.bin
|
||||
|
||||
case "$STRESS" in
|
||||
none)
|
||||
;;
|
||||
dd)
|
||||
log "iteration ${i}/${ITERATIONS}: dd stress"
|
||||
sudo dd if=/dev/zero of="$MOUNT_DIR/dd-stress.bin" bs="$DD_BS" count="$DD_COUNT" conv=fsync \
|
||||
>"$ARTIFACT_DIR/dd.iter${i}.log" 2>&1
|
||||
;;
|
||||
fio)
|
||||
log "iteration ${i}/${ITERATIONS}: fio stress"
|
||||
sudo fio --name=sw-block-nvme-fio \
|
||||
--directory="$MOUNT_DIR" \
|
||||
--rw=randrw \
|
||||
--rwmixread=50 \
|
||||
--bs="$FIO_BS" \
|
||||
--ioengine=psync \
|
||||
--iodepth=1 \
|
||||
--numjobs=1 \
|
||||
--size="$FIO_SIZE" \
|
||||
--runtime="$FIO_RUNTIME" \
|
||||
--time_based \
|
||||
--fsync=1 \
|
||||
--group_reporting \
|
||||
>"$ARTIFACT_DIR/fio.iter${i}.log" 2>&1
|
||||
;;
|
||||
*)
|
||||
echo "unknown SW_BLOCK_NVME_STRESS=${STRESS}" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
log "iteration ${i}/${ITERATIONS}: unmount/disconnect"
|
||||
sudo umount "$MOUNT_DIR"
|
||||
disconnect_nqn
|
||||
done
|
||||
|
||||
sudo nvme list-subsys -o json >"$ARTIFACT_DIR/nvme-list-subsys.final.json" 2>&1 || true
|
||||
if grep -q "$SUBSYS_NQN" "$ARTIFACT_DIR/nvme-list-subsys.final.json"; then
|
||||
echo "NVMe subsystem still present after disconnect: $SUBSYS_NQN" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "PASS: ${ITERATIONS} x nvme connect mkfs mount write/read disconnect"
|
||||
log "artifacts=${ARTIFACT_DIR}"
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REQUEST_JSON="${1:?usage: testops-pin-alpha-images.sh <run-request.json>}"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
eval "$(
|
||||
python3 - "$REQUEST_JSON" <<'PY'
|
||||
import json
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
with open(sys.argv[1], "r", encoding="utf-8") as f:
|
||||
req = json.load(f)
|
||||
|
||||
print(f"RUN_ID={shlex.quote(req['run_id'])}")
|
||||
print(f"SCENARIO={shlex.quote(req['scenario'])}")
|
||||
print(f"SOURCE_COMMIT={shlex.quote(req['source']['commit'])}")
|
||||
print(f"ARTIFACT_DIR={shlex.quote(req['artifact_dir'])}")
|
||||
PY
|
||||
)"
|
||||
|
||||
mkdir -p "$ARTIFACT_DIR"
|
||||
BUILD_DIR="$ARTIFACT_DIR/pin-build"
|
||||
mkdir -p "$BUILD_DIR"
|
||||
|
||||
started_at="$(date +%s)"
|
||||
status="pass"
|
||||
summary="alpha images built, recorded, and imported"
|
||||
rc=0
|
||||
|
||||
set +e
|
||||
SW_BLOCK_ARTIFACT_DIR="$BUILD_DIR" SW_BLOCK_IMPORT_K3S="${SW_BLOCK_IMPORT_K3S:-1}" \
|
||||
bash "$ROOT/scripts/build-alpha-images.sh" "$ROOT" \
|
||||
>"$BUILD_DIR/build.stdout.log" 2>"$BUILD_DIR/build.stderr.log"
|
||||
rc=$?
|
||||
set -e
|
||||
if [[ "$rc" -ne 0 ]]; then
|
||||
status="error"
|
||||
summary="alpha image pin-build/import failed"
|
||||
fi
|
||||
|
||||
ended_at="$(date +%s)"
|
||||
duration="$((ended_at - started_at))"
|
||||
|
||||
python3 - "$ARTIFACT_DIR/result.json" "$RUN_ID" "$SCENARIO" "$SOURCE_COMMIT" "$status" "$summary" "$duration" "$ARTIFACT_DIR" "$BUILD_DIR" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
|
||||
result_path, run_id, scenario, source_commit, status, summary, duration, artifact_dir, build_dir = sys.argv[1:]
|
||||
res = {
|
||||
"schema_version": "1.0",
|
||||
"run_id": run_id,
|
||||
"scenario": scenario,
|
||||
"source_commit": source_commit,
|
||||
"status": status,
|
||||
"summary": summary,
|
||||
"wall_clock_s": float(duration),
|
||||
"phase_results": [
|
||||
{"name": "pin_build_alpha_images", "status": status, "duration_s": float(duration)}
|
||||
],
|
||||
"artifact_dir": artifact_dir,
|
||||
"artifacts": {
|
||||
"pin_build": build_dir,
|
||||
"image_env": f"{build_dir}/alpha-images.env",
|
||||
"blockmaster_version": f"{build_dir}/blockmaster.version.txt",
|
||||
"blockvolume_version": f"{build_dir}/blockvolume.version.txt",
|
||||
"blockcsi_version": f"{build_dir}/blockcsi.version.txt",
|
||||
"build_stdout": f"{build_dir}/build.stdout.log",
|
||||
"build_stderr": f"{build_dir}/build.stderr.log"
|
||||
},
|
||||
"non_claims": [
|
||||
"Build/import provenance only; no Kubernetes workload or storage data-path claim.",
|
||||
"k3s import is controlled by SW_BLOCK_IMPORT_K3S and defaults to enabled for this TestOps scenario."
|
||||
],
|
||||
}
|
||||
with open(result_path, "w", encoding="utf-8") as f:
|
||||
json.dump(res, f, indent=2)
|
||||
f.write("\n")
|
||||
PY
|
||||
|
||||
exit "$rc"
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REQUEST_JSON="${1:?usage: testops-run-alpha-k8s.sh <run-request.json>}"
|
||||
WORKLOAD_SCRIPT="${SW_BLOCK_TESTOPS_WORKLOAD_SCRIPT:?SW_BLOCK_TESTOPS_WORKLOAD_SCRIPT is required}"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
eval "$(
|
||||
python3 - "$REQUEST_JSON" <<'PY'
|
||||
import json
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
with open(sys.argv[1], "r", encoding="utf-8") as f:
|
||||
req = json.load(f)
|
||||
|
||||
print(f"RUN_ID={shlex.quote(req['run_id'])}")
|
||||
print(f"SCENARIO={shlex.quote(req['scenario'])}")
|
||||
print(f"SOURCE_COMMIT={shlex.quote(req['source']['commit'])}")
|
||||
print(f"ARTIFACT_DIR={shlex.quote(req['artifact_dir'])}")
|
||||
PY
|
||||
)"
|
||||
|
||||
mkdir -p "$ARTIFACT_DIR"
|
||||
started_at="$(date +%s)"
|
||||
status="pass"
|
||||
summary="$SCENARIO completed"
|
||||
rc=0
|
||||
|
||||
set +e
|
||||
SW_BLOCK_ARTIFACT_DIR="$ARTIFACT_DIR" \
|
||||
bash "$ROOT/$WORKLOAD_SCRIPT" "$ROOT" \
|
||||
>"$ARTIFACT_DIR/workload.stdout.log" 2>"$ARTIFACT_DIR/workload.stderr.log"
|
||||
rc=$?
|
||||
set -e
|
||||
|
||||
if [[ "$rc" -ne 0 ]]; then
|
||||
status="error"
|
||||
summary="$SCENARIO failed; see workload logs"
|
||||
fi
|
||||
|
||||
ended_at="$(date +%s)"
|
||||
duration="$((ended_at - started_at))"
|
||||
|
||||
python3 - "$ARTIFACT_DIR/result.json" "$RUN_ID" "$SCENARIO" "$SOURCE_COMMIT" "$status" "$summary" "$duration" "$ARTIFACT_DIR" "$WORKLOAD_SCRIPT" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
|
||||
result_path, run_id, scenario, source_commit, status, summary, duration, artifact_dir, workload_script = sys.argv[1:]
|
||||
res = {
|
||||
"schema_version": "1.0",
|
||||
"run_id": run_id,
|
||||
"scenario": scenario,
|
||||
"source_commit": source_commit,
|
||||
"status": status,
|
||||
"summary": summary,
|
||||
"wall_clock_s": float(duration),
|
||||
"phase_results": [
|
||||
{"name": "workload", "status": status, "duration_s": float(duration)}
|
||||
],
|
||||
"artifact_dir": artifact_dir,
|
||||
"artifacts": {
|
||||
"run_log": f"{artifact_dir}/run.log",
|
||||
"alpha_images_env": f"{artifact_dir}/alpha-images.env",
|
||||
"generated_blockvolume": f"{artifact_dir}/generated-blockvolume.yaml",
|
||||
"lifecycle_volumes": f"{artifact_dir}/lifecycle-volumes.json",
|
||||
"pod_log": f"{artifact_dir}/pod.log",
|
||||
"workload_stdout": f"{artifact_dir}/workload.stdout.log",
|
||||
"workload_stderr": f"{artifact_dir}/workload.stderr.log"
|
||||
},
|
||||
"non_claims": [
|
||||
"This wrapper only normalizes TestOps result output around the existing alpha K8s workload script.",
|
||||
f"Workload script: {workload_script}"
|
||||
],
|
||||
}
|
||||
with open(result_path, "w", encoding="utf-8") as f:
|
||||
json.dump(res, f, indent=2)
|
||||
f.write("\n")
|
||||
PY
|
||||
|
||||
exit "$rc"
|
||||
Loaded 100 of 112 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user