diff --git a/seaweed-block/core/ops/managed_volume_model.go b/seaweed-block/core/ops/managed_volume_model.go index bd2a0525aa..288866ae51 100644 --- a/seaweed-block/core/ops/managed_volume_model.go +++ b/seaweed-block/core/ops/managed_volume_model.go @@ -106,6 +106,7 @@ type ManagedVolumeFacts struct { PVName string `json:"pv_name,omitempty"` StorageClass string `json:"storage_class,omitempty"` ReplicationFactor int `json:"replication_factor,omitempty"` + DesiredReplicas int `json:"desired_replicas,omitempty"` AckProfile string `json:"ack_profile,omitempty"` ClaimProfile string `json:"claim_profile,omitempty"` Protocol string `json:"protocol,omitempty"` @@ -457,6 +458,7 @@ func managedVolumeFactsFromVolumeEvidence(volume VolumeEvidence) ManagedVolumeFa PVCName: volume.PVCName, PVName: volume.PVName, ReplicationFactor: volume.ReplicationFactor, + DesiredReplicas: volume.DesiredReplicas, AckProfile: volume.AckProfile, ClaimProfile: volume.ClaimProfile, ProductStatus: volume.Status, @@ -610,7 +612,11 @@ func managedVolumeNVMeStatus(facts ManagedVolumeFacts) *ManagedVolumeNVMeStatus if status.ReasonCode == "" && (status.NQN == "" || status.NSID == 0) { status.ReasonCode = ReasonNVMeIdentityIncomplete } - if status.ReasonCode == "" && facts.ReplicationFactor > 1 && status.PathCount < facts.ReplicationFactor { + expectedPathCount := facts.ReplicationFactor + if expectedPathCount <= 0 { + expectedPathCount = facts.DesiredReplicas + } + if status.ReasonCode == "" && expectedPathCount > 1 && status.PathCount < expectedPathCount { status.ReasonCode = ReasonNVMeMultipathPathMissing } return status diff --git a/seaweed-block/core/ops/managed_volume_model_test.go b/seaweed-block/core/ops/managed_volume_model_test.go index 14f8bb69cd..5a502e14ff 100644 --- a/seaweed-block/core/ops/managed_volume_model_test.go +++ b/seaweed-block/core/ops/managed_volume_model_test.go @@ -178,6 +178,33 @@ func TestManagedVolumeProjection_BlocksMissingNVMeMultipath(t *testing.T) { } } +func TestManagedVolumeProjection_BlocksMissingNVMeMultipathFromDesiredReplicas(t *testing.T) { + projection := ProjectManagedVolume(ManagedVolumeFacts{ + VolumeID: "pvc-nvme", + DesiredReplicas: 2, + Authority: &AuthorityFact{ + PrimaryReplica: "r2", + PublishTarget: "127.0.0.1:4421", + }, + Replicas: []ReplicaFact{{ + ReplicaID: "r2", + Observed: true, + Role: "primary", + FrontendProtocol: "nvme", + FrontendAddr: "127.0.0.1:4421", + FrontendNQN: "nqn.2026-05.io.seaweedfs:pvc-nvme", + FrontendNSID: 1, + }}, + }) + + if projection.NVMe == nil || projection.NVMe.PathCount != 1 || projection.NVMe.ReasonCode != ReasonNVMeMultipathPathMissing { + t.Fatalf("nvme=%+v", projection.NVMe) + } + if projection.Status != ManagedVolumeStatusBlocked || projection.ReasonCode != ReasonNVMeMultipathPathMissing { + t.Fatalf("status=%s reason=%s", projection.Status, projection.ReasonCode) + } +} + func TestManagedVolumeProjection_LoopbackCrossNodeBlocked(t *testing.T) { projection := ProjectManagedVolume(ManagedVolumeFacts{ VolumeID: "pvc-a", diff --git a/seaweed-block/scripts/run-nvme-mounted-failover-smoke.sh b/seaweed-block/scripts/run-nvme-mounted-failover-smoke.sh index 474469c777..7644225006 100755 --- a/seaweed-block/scripts/run-nvme-mounted-failover-smoke.sh +++ b/seaweed-block/scripts/run-nvme-mounted-failover-smoke.sh @@ -5,6 +5,7 @@ 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}}" +SUMMARY="${ARTIFACT_DIR}/phase101-nvme-path-failure-summary.txt" 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}" @@ -15,6 +16,7 @@ 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" +: >"$SUMMARY" _USED_PORTS=() @@ -64,6 +66,10 @@ log() { printf '[nvme-failover] %s\n' "$*" | tee -a "$ARTIFACT_DIR/run.log" } +write_summary() { + echo "$*" | tee -a "$SUMMARY" >/dev/null +} + require_cmd() { if ! command -v "$1" >/dev/null 2>&1; then echo "missing required command: $1" >&2 @@ -248,6 +254,72 @@ wait_grouped_device() { exit 1 } +capture_ops_cluster() { + local label="$1" + "${BIN_DIR}/sw-block" ops cluster --master-api "$MASTER_ADDR" -o json \ + >"$ARTIFACT_DIR/cluster-${label}.json" +} + +managed_nvme_field() { + local path="$1" + local field="$2" + python3 - "$path" "$field" <<'PY' +import json, sys +path, field = sys.argv[1], sys.argv[2] +doc = json.load(open(path)) +managed = doc.get("managed_volumes") or [] +if not managed: + sys.exit(2) +volume = managed[0] +nvme = volume.get("nvme") or {} +if field == "status": + print(volume.get("status", "")) +elif field == "reason": + print(volume.get("reason_code", "")) +elif field == "ready_true": + print("true" if any(c.get("type") == "Ready" and c.get("status") == "True" for c in volume.get("conditions") or []) else "false") +elif field == "nvme_reason": + print(nvme.get("reason_code", "")) +elif field == "path_count": + print(nvme.get("path_count", 0)) +elif field == "multipath_observed": + print(str(bool(nvme.get("multipath_observed", False))).lower()) +elif field == "nqn": + print(nvme.get("nqn", "")) +elif field == "nsid": + print(nvme.get("nsid", 0)) +elif field == "addrs": + print(",".join(nvme.get("nvme_addrs") or [])) +else: + sys.exit(3) +PY +} + +wait_managed_nvme_status() { + local label="$1" + local want_paths="$2" + local want_reason="$3" + local require_not_ready="${4:-false}" + local json_path="$ARTIFACT_DIR/cluster-${label}.json" + for _ in $(seq 1 120); do + if capture_ops_cluster "$label" 2>"$ARTIFACT_DIR/cluster-${label}.stderr"; then + local got_paths got_reason ready_true + got_paths="$(managed_nvme_field "$json_path" path_count 2>/dev/null || true)" + got_reason="$(managed_nvme_field "$json_path" nvme_reason 2>/dev/null || true)" + ready_true="$(managed_nvme_field "$json_path" ready_true 2>/dev/null || true)" + if [[ "$got_paths" == "$want_paths" && "$got_reason" == "$want_reason" ]]; then + if [[ "$require_not_ready" != "true" || "$ready_true" != "true" ]]; then + return 0 + fi + fi + fi + sleep 0.25 + done + echo "timed out waiting for managed NVMe status label=${label} paths=${want_paths} reason=${want_reason}" >&2 + [[ -f "$json_path" ]] && cat "$json_path" >&2 + exit 1 +} + require_cmd sudo require_cmd nvme require_cmd curl @@ -256,6 +328,8 @@ require_cmd mkfs.ext4 require_cmd mount require_cmd sha256sum +write_summary "phase101_nvme_path_failure_status=running" +write_summary "phase101_scope=standalone_nvme_multipath_one_path_loss_status_gate" log "run_id=$RUN_ID" log "root=$ROOT" log "artifact_dir=$ARTIFACT_DIR" @@ -283,6 +357,11 @@ else log "build binaries" go build -o "${BIN_DIR}/blockmaster" ./cmd/blockmaster go build -o "${BIN_DIR}/blockvolume" ./cmd/blockvolume + go build -o "${BIN_DIR}/sw-block" ./cmd/sw-block +fi +if [[ ! -x "${BIN_DIR}/sw-block" ]]; then + require_cmd go + go build -o "${BIN_DIR}/sw-block" ./cmd/sw-block fi cat >"$ARTIFACT_DIR/topology.yaml" <"$ARTIFACT_DIR/nvme-list-subsys.before-failover.json" 2>&1 || true parse_nvme_subsys paths >"$ARTIFACT_DIR/path-summary.before-failover.txt" || true +wait_managed_nvme_status before-failover 2 "" +before_status="$(managed_nvme_field "$ARTIFACT_DIR/cluster-before-failover.json" status)" +before_reason="$(managed_nvme_field "$ARTIFACT_DIR/cluster-before-failover.json" reason)" +before_path_count="$(managed_nvme_field "$ARTIFACT_DIR/cluster-before-failover.json" path_count)" +before_multipath_observed="$(managed_nvme_field "$ARTIFACT_DIR/cluster-before-failover.json" multipath_observed)" +before_nqn="$(managed_nvme_field "$ARTIFACT_DIR/cluster-before-failover.json" nqn)" +before_nsid="$(managed_nvme_field "$ARTIFACT_DIR/cluster-before-failover.json" nsid)" +before_addrs="$(managed_nvme_field "$ARTIFACT_DIR/cluster-before-failover.json" addrs)" +write_summary "before_status=${before_status}" +write_summary "before_reason=${before_reason:-none}" +write_summary "before_path_count=${before_path_count}" +write_summary "before_multipath_observed=${before_multipath_observed}" +write_summary "before_nqn=${before_nqn}" +write_summary "before_nsid=${before_nsid}" +write_summary "before_addrs=${before_addrs}" map_dev="$(wait_grouped_device)" log "nvme_namespace_device=${map_dev}" @@ -411,6 +505,21 @@ 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 +wait_managed_nvme_status after-failover 1 "nvme_multipath_path_missing" true +after_status="$(managed_nvme_field "$ARTIFACT_DIR/cluster-after-failover.json" status)" +after_reason="$(managed_nvme_field "$ARTIFACT_DIR/cluster-after-failover.json" reason)" +after_nvme_reason="$(managed_nvme_field "$ARTIFACT_DIR/cluster-after-failover.json" nvme_reason)" +after_ready_true="$(managed_nvme_field "$ARTIFACT_DIR/cluster-after-failover.json" ready_true)" +after_path_count="$(managed_nvme_field "$ARTIFACT_DIR/cluster-after-failover.json" path_count)" +after_multipath_observed="$(managed_nvme_field "$ARTIFACT_DIR/cluster-after-failover.json" multipath_observed)" +after_addrs="$(managed_nvme_field "$ARTIFACT_DIR/cluster-after-failover.json" addrs)" +write_summary "after_status=${after_status}" +write_summary "after_reason=${after_reason}" +write_summary "after_nvme_reason=${after_nvme_reason}" +write_summary "after_ready_true=${after_ready_true}" +write_summary "after_path_count=${after_path_count}" +write_summary "after_multipath_observed=${after_multipath_observed}" +write_summary "after_addrs=${after_addrs}" sleep 3 log "verify mounted workload after failover" @@ -430,6 +539,8 @@ 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 +write_summary "final_nvme_residue_count=0" +write_summary "phase101_nvme_path_failure_status=ok" log "PASS: mounted NVMe multipath workload read/wrote through r1->r2 failover" log "artifacts=$ARTIFACT_DIR" diff --git a/seaweed-block/testops/scenarios/nvme-path-failure-status-chain.yaml b/seaweed-block/testops/scenarios/nvme-path-failure-status-chain.yaml new file mode 100644 index 0000000000..f67e9a5c8e --- /dev/null +++ b/seaweed-block/testops/scenarios/nvme-path-failure-status-chain.yaml @@ -0,0 +1,95 @@ +name: nvme-path-failure-status-chain +timeout: 30m + +env: + product_root: "/tmp/seaweed_block" + ssh_key: "C:\\work\\dev_server\\testdev_key" + +topology: + nodes: + m02: + host: 192.168.1.184 + user: testdev + key: "{{ ssh_key }}" + +phases: + - name: pre_clean + actions: + - action: pre_run_cleanup + node: m02 + kill_patterns: "blockmaster,blockvolume,blockcsi,iscsi-target" + nvme_disconnect: "true" + iscsi_logout_prefix: "iqn.2026-05.io.seaweedfs" + - action: exec + node: m02 + cmd: "rm -rf /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure && mkdir -p /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure" + + - name: nvme_path_failure_status + actions: + - action: exec + node: m02 + timeout: 20m + cmd: "cd {{ product_root }} && bash scripts/run-nvme-mounted-failover-smoke.sh {{ product_root }}" + env.SW_BLOCK_ARTIFACT_DIR: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure/gate" + - action: grep_log + node: m02 + path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure/gate/phase101-nvme-path-failure-summary.txt" + pattern: "^phase101_nvme_path_failure_status=ok$" + save_as: d2_ok + - action: assert_greater + actual: "{{ d2_ok }}" + threshold: "0" + - action: grep_log + node: m02 + path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure/gate/phase101-nvme-path-failure-summary.txt" + pattern: "^before_path_count=2$" + save_as: before_two_paths + - action: assert_greater + actual: "{{ before_two_paths }}" + threshold: "0" + - action: grep_log + node: m02 + path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure/gate/phase101-nvme-path-failure-summary.txt" + pattern: "^after_path_count=1$" + save_as: after_one_path + - action: assert_greater + actual: "{{ after_one_path }}" + threshold: "0" + - action: grep_log + node: m02 + path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure/gate/phase101-nvme-path-failure-summary.txt" + pattern: "^after_nvme_reason=nvme_multipath_path_missing$" + save_as: missing_path_reason + - action: assert_greater + actual: "{{ missing_path_reason }}" + threshold: "0" + - action: grep_log + node: m02 + path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure/gate/phase101-nvme-path-failure-summary.txt" + pattern: "^after_ready_true=false$" + save_as: no_false_ready + - action: assert_greater + actual: "{{ no_false_ready }}" + threshold: "0" + - action: grep_log + node: m02 + path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure/gate/phase101-nvme-path-failure-summary.txt" + pattern: "^final_nvme_residue_count=0$" + save_as: nvme_clean + - action: assert_greater + actual: "{{ nvme_clean }}" + threshold: "0" + + - name: collect_and_cleanup + always: true + actions: + - action: pre_run_cleanup + node: m02 + kill_patterns: "blockmaster,blockvolume,blockcsi,iscsi-target" + nvme_disconnect: "true" + iscsi_logout_prefix: "iqn.2026-05.io.seaweedfs" + - action: collect_path + node: m02 + path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase101-nvme-path-failure" + name: "remote-phases" + ignore_error: true