diff --git a/seaweed-block/core/csi/master_backend.go b/seaweed-block/core/csi/master_backend.go index 8dbfc649a4..8ab11206b5 100644 --- a/seaweed-block/core/csi/master_backend.go +++ b/seaweed-block/core/csi/master_backend.go @@ -168,20 +168,23 @@ func publishTargetFromStatus(resp *control.StatusResponse, enableMultipath bool, if ft.GetProtocol() != string(ProtocolISCSI) || ft.GetAddr() == "" || ft.GetIqn() == "" || rejectFrontendAddr(ft.GetAddr(), rejectLoopback) { continue } - if _, ok := iscsiByIQN[ft.GetIqn()]; !ok { - iscsiOrder = append(iscsiOrder, ft.GetIqn()) + // one multipath target is one IQN AND LUN: paths to another LUN of the same IQN are another unit + // (INV-AUTH-HOLDER-IDENTITY-001) + key := ft.GetIqn() + "\x00" + strconv.FormatUint(uint64(ft.GetLun()), 10) + if _, ok := iscsiByIQN[key]; !ok { + iscsiOrder = append(iscsiOrder, key) } - iscsiByIQN[ft.GetIqn()] = append(iscsiByIQN[ft.GetIqn()], ft) + iscsiByIQN[key] = append(iscsiByIQN[key], ft) } - for _, iqn := range iscsiOrder { - frontends := iscsiByIQN[iqn] + for _, key := range iscsiOrder { + frontends := iscsiByIQN[key] if len(frontends) == 0 { continue } out := base out.Protocol = ProtocolISCSI out.ISCSIAddr = frontends[0].GetAddr() - out.IQN = iqn + out.IQN = frontends[0].GetIqn() out.LUN = frontends[0].GetLun() if len(frontends) > 1 { out.Multipath = true diff --git a/seaweed-block/core/csi/primary_owned_frontend_test.go b/seaweed-block/core/csi/primary_owned_frontend_test.go index f7e99b2565..e7aafe59fe 100644 --- a/seaweed-block/core/csi/primary_owned_frontend_test.go +++ b/seaweed-block/core/csi/primary_owned_frontend_test.go @@ -45,6 +45,16 @@ func TestPublishTargetIsPrimaryOwned(t *testing.T) { if !ok || got.LUN != 1 || !got.Multipath || len(got.ISCSIAddrs) != 2 || got.ISCSIAddrs[0] != "192.0.2.1:3260" { t.Fatalf("nonzero LUN match: %+v ok=%v, want multipath primary-first at LUN 1", got, ok) } + // two PRIMARY-owned units of one IQN (q/LUN1 at A, q/LUN2 at B) are two targets, never one multipath target with + // LUN1 for both (codex01: the final grouping binds IQN and LUN too) + got, ok = publishTargetFromStatus(status(lun("r1", "192.0.2.1:3260", 1), lun("r1", "192.0.2.2:3260", 2)), true, false) + if !ok || got.ISCSIAddr != "192.0.2.1:3260" || got.LUN != 1 || got.Multipath || len(got.ISCSIAddrs) != 0 { + t.Fatalf("two primary units: %+v ok=%v, want q/LUN1 at 192.0.2.1 alone (no multipath with LUN2's path)", got, ok) + } + got, ok = publishTargetFromStatus(status(lun("", "192.0.2.1:3260", 1), lun("", "192.0.2.2:3260", 2)), true, false) + if !ok || got.LUN != 1 || got.Multipath { + t.Fatalf("untagged two units: %+v ok=%v, want q/LUN1 alone", got, ok) + } // no primary frontend at all, supporting present: no target if got, ok := publishTargetFromStatus(status(ft("r2", "192.0.2.2:3260", "iqn.v1")), false, false); ok { t.Fatalf("no primary frontend: published %+v, want no target", got) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 678b308f7e..6506e3446d 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -110,7 +110,7 @@ The role a blockvolume takes from each assignment, its replica listener's admiss ```mermaid stateDiagram-v2 [*] --> Unassigned: listener with a floor record, no role yet - Unassigned --> Primary: fact names self (server id + replica, delivered only to its registered host), listener fenced at e + Unassigned --> Primary: fact names self, listener fenced at e Unassigned --> Supporting: fact names another primary, self in peers Supporting --> Primary: promotion, fact names self at a higher epoch Primary --> Supporting: fact names another primary, self in peers