mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
iscsi: add alua protocol surface tests
This commit is contained in:
1 parent
949bf834fa
commit
df8e32764c
5 files changed
+427
-51
No files matched your search
@@ -0,0 +1,90 @@
|
||||
package iscsi
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
// ALUAState is the SPC asymmetric logical unit access state exposed to OS
|
||||
// initiators. It is protocol reporting only; authority remains outside iSCSI.
|
||||
type ALUAState uint8
|
||||
|
||||
const (
|
||||
ALUAActiveOptimized ALUAState = 0x00
|
||||
ALUAActiveNonOptimized ALUAState = 0x01
|
||||
ALUAStandby ALUAState = 0x02
|
||||
ALUAUnavailable ALUAState = 0x0e
|
||||
ALUATransitioning ALUAState = 0x0f
|
||||
)
|
||||
|
||||
func (s ALUAState) String() string {
|
||||
switch s {
|
||||
case ALUAActiveOptimized:
|
||||
return "active_optimized"
|
||||
case ALUAActiveNonOptimized:
|
||||
return "active_non_optimized"
|
||||
case ALUAStandby:
|
||||
return "standby"
|
||||
case ALUAUnavailable:
|
||||
return "unavailable"
|
||||
case ALUATransitioning:
|
||||
return "transitioning"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// ALUAProvider is an optional read-only state source for SCSIHandler. It must
|
||||
// consume frontend facts only; it must not mint authority or mutate placement.
|
||||
type ALUAProvider interface {
|
||||
ALUAState() ALUAState
|
||||
TargetPortGroupID() uint16
|
||||
RelativeTargetPortID() uint16
|
||||
DeviceNAA() [8]byte
|
||||
}
|
||||
|
||||
func (h *SCSIHandler) aluaWriteReject() *SCSIResult {
|
||||
if h.alua == nil {
|
||||
return nil
|
||||
}
|
||||
switch h.alua.ALUAState() {
|
||||
case ALUAActiveOptimized, ALUAActiveNonOptimized:
|
||||
return nil
|
||||
default:
|
||||
r := SCSIResult{
|
||||
Status: StatusCheckCondition,
|
||||
SenseKey: SenseNotReady,
|
||||
ASC: ASCNotReady,
|
||||
ASCQ: ASCQTargetPortStandby,
|
||||
Reason: "ALUA path is not writable",
|
||||
}
|
||||
return &r
|
||||
}
|
||||
}
|
||||
|
||||
func (h *SCSIHandler) maintenanceIn(cdb [16]byte) SCSIResult {
|
||||
sa := cdb[1] & 0x1f
|
||||
switch sa {
|
||||
case SaiReportTargetPortGroups:
|
||||
return h.reportTargetPortGroups(cdb)
|
||||
default:
|
||||
return illegalRequest(ASCInvalidOpcode, 0x00, "unsupported MAINTENANCE IN service action")
|
||||
}
|
||||
}
|
||||
|
||||
func (h *SCSIHandler) reportTargetPortGroups(cdb [16]byte) SCSIResult {
|
||||
if h.alua == nil {
|
||||
return illegalRequest(ASCInvalidOpcode, 0x00, "REPORT TARGET PORT GROUPS requires ALUA provider")
|
||||
}
|
||||
allocLen := binary.BigEndian.Uint32(cdb[6:10])
|
||||
data := make([]byte, 16)
|
||||
|
||||
binary.BigEndian.PutUint32(data[0:4], 12) // return data length, excluding header
|
||||
data[4] = uint8(h.alua.ALUAState()) & 0x0f
|
||||
data[5] = 0x8f // A/O, A/NO, Standby, Unavailable, Transitioning supported.
|
||||
binary.BigEndian.PutUint16(data[8:10], h.alua.TargetPortGroupID())
|
||||
data[11] = 0x01 // one target port descriptor
|
||||
binary.BigEndian.PutUint16(data[14:16], h.alua.RelativeTargetPortID())
|
||||
|
||||
if allocLen > 0 && allocLen < uint32(len(data)) {
|
||||
data = data[:allocLen]
|
||||
}
|
||||
return SCSIResult{Status: StatusGood, Data: data}
|
||||
}
|
||||
@@ -11,9 +11,9 @@ import "fmt"
|
||||
// SCSI status byte values (SPC-5 §6). Only the subset we use
|
||||
// directly is declared.
|
||||
const (
|
||||
StatusGood uint8 = 0x00
|
||||
StatusCheckCondition uint8 = 0x02
|
||||
StatusBusy uint8 = 0x08
|
||||
StatusGood uint8 = 0x00
|
||||
StatusCheckCondition uint8 = 0x02
|
||||
StatusBusy uint8 = 0x08
|
||||
StatusReservationConflict uint8 = 0x18
|
||||
)
|
||||
|
||||
@@ -31,11 +31,12 @@ const (
|
||||
|
||||
// ASC/ASCQ (selected — full tables live in spc-5 Annex F).
|
||||
const (
|
||||
ASCInvalidOpcode uint8 = 0x20
|
||||
ASCInvalidFieldInCDB uint8 = 0x24
|
||||
ASCLBAOutOfRange uint8 = 0x21
|
||||
ASCNotReady uint8 = 0x04
|
||||
ASCNotReadyManualIntv uint8 = 0x03
|
||||
ASCInvalidOpcode uint8 = 0x20
|
||||
ASCInvalidFieldInCDB uint8 = 0x24
|
||||
ASCLBAOutOfRange uint8 = 0x21
|
||||
ASCNotReady uint8 = 0x04
|
||||
ASCNotReadyManualIntv uint8 = 0x03
|
||||
ASCQTargetPortStandby uint8 = 0x0B
|
||||
// ASCWriteError — T3b: SYNC_CACHE backend-sync failure maps
|
||||
// here per SPC-5 §D.2.14 ("WRITE ERROR" 0x0C/00).
|
||||
ASCWriteError uint8 = 0x0C
|
||||
@@ -62,11 +63,11 @@ const (
|
||||
// with non-empty sense key; stale READ returns CHECK CONDITION
|
||||
// and does NOT return data to initiator".
|
||||
type SCSIError struct {
|
||||
Status uint8
|
||||
SenseKey uint8
|
||||
ASC uint8
|
||||
ASCQ uint8
|
||||
Reason string // free-form; diagnostic only
|
||||
Status uint8
|
||||
SenseKey uint8
|
||||
ASC uint8
|
||||
ASCQ uint8
|
||||
Reason string // free-form; diagnostic only
|
||||
}
|
||||
|
||||
func (e *SCSIError) Error() string {
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
package iscsi_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/iscsi"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/testback"
|
||||
)
|
||||
|
||||
type testALUAProvider struct {
|
||||
state iscsi.ALUAState
|
||||
tpgID uint16
|
||||
rtpID uint16
|
||||
naa [8]byte
|
||||
}
|
||||
|
||||
func (p *testALUAProvider) ALUAState() iscsi.ALUAState { return p.state }
|
||||
func (p *testALUAProvider) TargetPortGroupID() uint16 { return p.tpgID }
|
||||
func (p *testALUAProvider) RelativeTargetPortID() uint16 { return p.rtpID }
|
||||
func (p *testALUAProvider) DeviceNAA() [8]byte { return p.naa }
|
||||
|
||||
func aluaTestProvider(state iscsi.ALUAState) *testALUAProvider {
|
||||
return &testALUAProvider{
|
||||
state: state,
|
||||
tpgID: 7,
|
||||
rtpID: 3,
|
||||
naa: [8]byte{0x60, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0x11, 0x22},
|
||||
}
|
||||
}
|
||||
|
||||
func inquiryCDB(alloc uint16) [16]byte {
|
||||
var cdb [16]byte
|
||||
cdb[0] = iscsi.ScsiInquiry
|
||||
binary.BigEndian.PutUint16(cdb[3:5], alloc)
|
||||
return cdb
|
||||
}
|
||||
|
||||
func vpdCDB(page uint8, alloc uint16) [16]byte {
|
||||
var cdb [16]byte
|
||||
cdb[0] = iscsi.ScsiInquiry
|
||||
cdb[1] = 0x01
|
||||
cdb[2] = page
|
||||
binary.BigEndian.PutUint16(cdb[3:5], alloc)
|
||||
return cdb
|
||||
}
|
||||
|
||||
func reportTPGCDB(alloc uint32) [16]byte {
|
||||
var cdb [16]byte
|
||||
cdb[0] = iscsi.ScsiMaintenanceIn
|
||||
cdb[1] = iscsi.SaiReportTargetPortGroups
|
||||
binary.BigEndian.PutUint32(cdb[6:10], alloc)
|
||||
return cdb
|
||||
}
|
||||
|
||||
func syncCache10CDB() [16]byte {
|
||||
var cdb [16]byte
|
||||
cdb[0] = iscsi.ScsiSyncCache10
|
||||
return cdb
|
||||
}
|
||||
|
||||
func TestP6ALUA_NoProviderDoesNotAdvertiseALUA(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1", ReplicaID: "r1"})
|
||||
h := iscsi.NewSCSIHandler(iscsi.HandlerConfig{Backend: rec})
|
||||
|
||||
inq := h.HandleCommand(context.Background(), inquiryCDB(96), nil)
|
||||
if inq.Status != iscsi.StatusGood {
|
||||
t.Fatalf("INQUIRY: %v", inq.AsError())
|
||||
}
|
||||
if got := inq.Data[5] & 0x30; got != 0 {
|
||||
t.Fatalf("TPGS bits with no ALUA provider = 0x%02x, want 0", got)
|
||||
}
|
||||
|
||||
rtpg := h.HandleCommand(context.Background(), reportTPGCDB(64), nil)
|
||||
if rtpg.Status == iscsi.StatusGood {
|
||||
t.Fatal("REPORT TARGET PORT GROUPS succeeded without ALUA provider")
|
||||
}
|
||||
if rtpg.SenseKey != iscsi.SenseIllegalRequest {
|
||||
t.Fatalf("REPORT TPG no provider sense=0x%02x want IllegalRequest", rtpg.SenseKey)
|
||||
}
|
||||
|
||||
vpd := h.HandleCommand(context.Background(), vpdCDB(0x83, 255), nil)
|
||||
if vpd.Status != iscsi.StatusGood {
|
||||
t.Fatalf("VPD83 no provider: %v", vpd.AsError())
|
||||
}
|
||||
if pageLen := binary.BigEndian.Uint16(vpd.Data[2:4]); pageLen != 12 {
|
||||
t.Fatalf("VPD83 no provider pageLen=%d want 12", pageLen)
|
||||
}
|
||||
}
|
||||
|
||||
func TestP6ALUA_NonWritableStatesAllowReadButRejectWriteAndSync(t *testing.T) {
|
||||
for _, state := range []iscsi.ALUAState{
|
||||
iscsi.ALUAStandby,
|
||||
iscsi.ALUAUnavailable,
|
||||
iscsi.ALUATransitioning,
|
||||
} {
|
||||
t.Run(state.String(), func(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1", ReplicaID: "r1"})
|
||||
payload := make([]byte, iscsi.DefaultBlockSize)
|
||||
if _, err := rec.Write(context.Background(), 0, payload); err != nil {
|
||||
t.Fatalf("seed Write: %v", err)
|
||||
}
|
||||
prov := aluaTestProvider(state)
|
||||
h := iscsi.NewSCSIHandler(iscsi.HandlerConfig{Backend: rec, ALUA: prov})
|
||||
|
||||
read := h.HandleCommand(context.Background(), readCDB(0, 1), nil)
|
||||
if read.Status != iscsi.StatusGood {
|
||||
t.Fatalf("READ should support path probing: %v", read.AsError())
|
||||
}
|
||||
|
||||
write := h.HandleCommand(context.Background(), writeCDB(0, 1), payload)
|
||||
if write.Status != iscsi.StatusCheckCondition {
|
||||
t.Fatalf("WRITE status=0x%02x want CheckCondition", write.Status)
|
||||
}
|
||||
if write.SenseKey != iscsi.SenseNotReady || write.ASC != iscsi.ASCNotReady || write.ASCQ != iscsi.ASCQTargetPortStandby {
|
||||
t.Fatalf("WRITE sense=%02x/%02x/%02x want NotReady/04/0B",
|
||||
write.SenseKey, write.ASC, write.ASCQ)
|
||||
}
|
||||
|
||||
sync := h.HandleCommand(context.Background(), syncCache10CDB(), nil)
|
||||
if sync.Status != iscsi.StatusCheckCondition {
|
||||
t.Fatalf("SYNC status=0x%02x want CheckCondition", sync.Status)
|
||||
}
|
||||
if rec.SyncCount() != 0 {
|
||||
t.Fatalf("SYNC reached backend %d times", rec.SyncCount())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestP6ALUA_ActiveAdvertisesTPGSAndServesReportTPG(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1", ReplicaID: "r1"})
|
||||
prov := aluaTestProvider(iscsi.ALUAActiveOptimized)
|
||||
h := iscsi.NewSCSIHandler(iscsi.HandlerConfig{Backend: rec, ALUA: prov})
|
||||
|
||||
inq := h.HandleCommand(context.Background(), inquiryCDB(96), nil)
|
||||
if inq.Status != iscsi.StatusGood {
|
||||
t.Fatalf("INQUIRY: %v", inq.AsError())
|
||||
}
|
||||
if got := inq.Data[5] & 0x30; got != 0x10 {
|
||||
t.Fatalf("TPGS bits = 0x%02x want 0x10 implicit ALUA", got)
|
||||
}
|
||||
|
||||
rtpg := h.HandleCommand(context.Background(), reportTPGCDB(64), nil)
|
||||
if rtpg.Status != iscsi.StatusGood {
|
||||
t.Fatalf("REPORT TPG: %v", rtpg.AsError())
|
||||
}
|
||||
if len(rtpg.Data) != 16 {
|
||||
t.Fatalf("REPORT TPG len=%d want 16", len(rtpg.Data))
|
||||
}
|
||||
if state := iscsi.ALUAState(rtpg.Data[4] & 0x0f); state != iscsi.ALUAActiveOptimized {
|
||||
t.Fatalf("REPORT TPG state=%02x want active optimized", state)
|
||||
}
|
||||
if tpg := binary.BigEndian.Uint16(rtpg.Data[8:10]); tpg != prov.tpgID {
|
||||
t.Fatalf("REPORT TPG id=%d want %d", tpg, prov.tpgID)
|
||||
}
|
||||
if rtp := binary.BigEndian.Uint16(rtpg.Data[14:16]); rtp != prov.rtpID {
|
||||
t.Fatalf("REPORT TPG relative target port=%d want %d", rtp, prov.rtpID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestP6ALUA_VPD83AddsPathDescriptorsAndTruncates(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1", ReplicaID: "r1"})
|
||||
prov := aluaTestProvider(iscsi.ALUAActiveOptimized)
|
||||
h := iscsi.NewSCSIHandler(iscsi.HandlerConfig{Backend: rec, ALUA: prov})
|
||||
|
||||
vpd := h.HandleCommand(context.Background(), vpdCDB(0x83, 255), nil)
|
||||
if vpd.Status != iscsi.StatusGood {
|
||||
t.Fatalf("VPD83: %v", vpd.AsError())
|
||||
}
|
||||
if pageLen := binary.BigEndian.Uint16(vpd.Data[2:4]); pageLen != 28 {
|
||||
t.Fatalf("VPD83 pageLen=%d want 28", pageLen)
|
||||
}
|
||||
if got := vpd.Data[8:16]; !bytes.Equal(got, prov.naa[:]) {
|
||||
t.Fatalf("VPD83 NAA=%x want %x", got, prov.naa)
|
||||
}
|
||||
if typ := vpd.Data[17] & 0x0f; typ != 0x05 {
|
||||
t.Fatalf("VPD83 second descriptor type=0x%x want target port group", typ)
|
||||
}
|
||||
if typ := vpd.Data[25] & 0x0f; typ != 0x04 {
|
||||
t.Fatalf("VPD83 third descriptor type=0x%x want relative target port", typ)
|
||||
}
|
||||
|
||||
short := h.HandleCommand(context.Background(), vpdCDB(0x83, 20), nil)
|
||||
if short.Status != iscsi.StatusGood {
|
||||
t.Fatalf("short VPD83: %v", short.AsError())
|
||||
}
|
||||
if len(short.Data) != 20 {
|
||||
t.Fatalf("short VPD83 len=%d want 20", len(short.Data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestP6ALUA_VPD00UnchangedWhenALUAEnabled(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1", ReplicaID: "r1"})
|
||||
noALUA := iscsi.NewSCSIHandler(iscsi.HandlerConfig{Backend: rec})
|
||||
withALUA := iscsi.NewSCSIHandler(iscsi.HandlerConfig{Backend: rec, ALUA: aluaTestProvider(iscsi.ALUAActiveOptimized)})
|
||||
|
||||
a := noALUA.HandleCommand(context.Background(), vpdCDB(0x00, 255), nil)
|
||||
b := withALUA.HandleCommand(context.Background(), vpdCDB(0x00, 255), nil)
|
||||
if a.Status != iscsi.StatusGood || b.Status != iscsi.StatusGood {
|
||||
t.Fatalf("VPD00 statuses noALUA=%v withALUA=%v", a.AsError(), b.AsError())
|
||||
}
|
||||
if !bytes.Equal(a.Data, b.Data) {
|
||||
t.Fatalf("VPD00 changed when ALUA enabled: noALUA=%x withALUA=%x", a.Data, b.Data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestP6ALUA_ReportTPGReflectsStateChanges(t *testing.T) {
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1", ReplicaID: "r1"})
|
||||
prov := aluaTestProvider(iscsi.ALUAActiveOptimized)
|
||||
h := iscsi.NewSCSIHandler(iscsi.HandlerConfig{Backend: rec, ALUA: prov})
|
||||
|
||||
for _, state := range []iscsi.ALUAState{
|
||||
iscsi.ALUAActiveOptimized,
|
||||
iscsi.ALUAActiveNonOptimized,
|
||||
iscsi.ALUAStandby,
|
||||
iscsi.ALUAUnavailable,
|
||||
iscsi.ALUATransitioning,
|
||||
} {
|
||||
prov.state = state
|
||||
rtpg := h.HandleCommand(context.Background(), reportTPGCDB(64), nil)
|
||||
if rtpg.Status != iscsi.StatusGood {
|
||||
t.Fatalf("REPORT TPG state %02x: %v", state, rtpg.AsError())
|
||||
}
|
||||
if got := iscsi.ALUAState(rtpg.Data[4] & 0x0f); got != state {
|
||||
t.Fatalf("REPORT TPG state=%02x want %02x", got, state)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,11 +34,13 @@ const (
|
||||
ScsiSyncCache16 uint8 = 0x91
|
||||
ScsiServiceActionIn16 uint8 = 0x9e
|
||||
ScsiReportLuns uint8 = 0xa0
|
||||
ScsiMaintenanceIn uint8 = 0xa3
|
||||
)
|
||||
|
||||
// Service Action codes for SERVICE ACTION IN(16) opcode 0x9e.
|
||||
// Service Action codes used by supported SCSI service-action commands.
|
||||
const (
|
||||
SaiReadCapacity16 uint8 = 0x10
|
||||
SaiReadCapacity16 uint8 = 0x10
|
||||
SaiReportTargetPortGroups uint8 = 0x0a
|
||||
)
|
||||
|
||||
// Fixed block size for the T2 contract backend. Real volumes
|
||||
@@ -102,6 +104,7 @@ type SCSIHandler struct {
|
||||
vendorID string // 8 bytes
|
||||
productID string // 16 bytes
|
||||
serialNo string
|
||||
alua ALUAProvider
|
||||
}
|
||||
|
||||
// HandlerConfig configures an SCSIHandler. Zero values pick
|
||||
@@ -113,6 +116,7 @@ type HandlerConfig struct {
|
||||
VendorID string
|
||||
ProductID string
|
||||
SerialNo string
|
||||
ALUA ALUAProvider
|
||||
}
|
||||
|
||||
// NewSCSIHandler constructs a handler. Backend MUST be non-nil.
|
||||
@@ -150,6 +154,7 @@ func NewSCSIHandler(cfg HandlerConfig) *SCSIHandler {
|
||||
vendorID: vendor,
|
||||
productID: product,
|
||||
serialNo: cfg.SerialNo,
|
||||
alua: cfg.ALUA,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +195,9 @@ func (h *SCSIHandler) HandleCommand(ctx context.Context, cdb [16]byte, dataOut [
|
||||
case ScsiRead10:
|
||||
return h.read10(ctx, cdb)
|
||||
case ScsiWrite10:
|
||||
if r := h.aluaWriteReject(); r != nil {
|
||||
return *r
|
||||
}
|
||||
return h.write10(ctx, cdb, dataOut)
|
||||
// T3b wire: SYNCHRONIZE_CACHE(10) / (16) dispatches to
|
||||
// Backend.Sync(ctx). Durable backends flush the WAL; memback
|
||||
@@ -198,6 +206,9 @@ func (h *SCSIHandler) HandleCommand(ctx context.Context, cdb [16]byte, dataOut [
|
||||
// rule §3.6 (error-faithful Sync wire) makes data-integrity
|
||||
// hazards visible to the host.
|
||||
case ScsiSyncCache10, ScsiSyncCache16:
|
||||
if r := h.aluaWriteReject(); r != nil {
|
||||
return *r
|
||||
}
|
||||
log.Printf("iscsi: SCSI SYNCHRONIZE_CACHE handler entry opcode=0x%02x", cdb[0])
|
||||
if err := h.backend.Sync(ctx); err != nil {
|
||||
log.Printf("iscsi: SCSI SYNCHRONIZE_CACHE backend.Sync FAILED: %v", err)
|
||||
@@ -215,6 +226,9 @@ func (h *SCSIHandler) HandleCommand(ctx context.Context, cdb [16]byte, dataOut [
|
||||
case ScsiRead16:
|
||||
return h.read16(ctx, cdb)
|
||||
case ScsiWrite16:
|
||||
if r := h.aluaWriteReject(); r != nil {
|
||||
return *r
|
||||
}
|
||||
return h.write16(ctx, cdb, dataOut)
|
||||
case ScsiServiceActionIn16:
|
||||
sa := cdb[1] & 0x1f
|
||||
@@ -225,6 +239,8 @@ func (h *SCSIHandler) HandleCommand(ctx context.Context, cdb [16]byte, dataOut [
|
||||
fmt.Sprintf("unsupported SAI16 service action 0x%02x", sa))
|
||||
case ScsiReportLuns:
|
||||
return h.reportLuns(cdb)
|
||||
case ScsiMaintenanceIn:
|
||||
return h.maintenanceIn(cdb)
|
||||
default:
|
||||
return illegalRequest(ASCInvalidOpcode, 0x00, fmt.Sprintf("unsupported opcode 0x%02x", cdb[0]))
|
||||
}
|
||||
@@ -325,18 +341,21 @@ func (h *SCSIHandler) requestSense(cdb [16]byte) SCSIResult {
|
||||
// response (PM Medium finding 2026-04-22).
|
||||
//
|
||||
// Key V2 parity bytes we now emit:
|
||||
// byte 4 = 91 Additional length (96 - 5)
|
||||
// byte 7 = 0x02 CmdQue=1 — command queuing supported
|
||||
// bytes 8-15 Vendor ID, 8 bytes, space-padded
|
||||
// bytes 16-31 Product ID, 16 bytes, space-padded
|
||||
// bytes 32-35 Product revision "0001"
|
||||
// bytes 36-95 Reserved / zero
|
||||
//
|
||||
// Skip list compliance (ports plan §3.2):
|
||||
// byte 5 bit 4 (TPGS implicit) — NOT set (ALUA is skip-list)
|
||||
// byte 6 / other tuning bits — zero (V2 sets some for
|
||||
// enclosure/multiPort/vendor-specific; T2 has no reason
|
||||
// to advertise them)
|
||||
// byte 4 = 91 Additional length (96 - 5)
|
||||
// byte 7 = 0x02 CmdQue=1 — command queuing supported
|
||||
// bytes 8-15 Vendor ID, 8 bytes, space-padded
|
||||
// bytes 16-31 Product ID, 16 bytes, space-padded
|
||||
// bytes 32-35 Product revision "0001"
|
||||
// bytes 36-95 Reserved / zero
|
||||
//
|
||||
// ALUA discipline:
|
||||
//
|
||||
// byte 5 bit 4 (TPGS implicit) is set only when HandlerConfig.ALUA is
|
||||
// present and REPORT TARGET PORT GROUPS is served.
|
||||
// byte 6 / other tuning bits stay zero (V2 sets some for
|
||||
// enclosure/multiPort/vendor-specific; T2 has no reason
|
||||
// to advertise them)
|
||||
//
|
||||
// NOTE: the prior 36-byte minimal response still worked for
|
||||
// iscsiadm attach, but under-advertised CmdQue and forced the
|
||||
@@ -359,7 +378,11 @@ func (h *SCSIHandler) inquiry(cdb [16]byte) SCSIResult {
|
||||
data[2] = 0x06 // Version: SPC-4
|
||||
data[3] = 0x02 // Response data format (SPC-2+)
|
||||
data[4] = 91 // Additional length (96 - 5)
|
||||
// byte 5: SCCS / ACC / TPGS / 3PC — all zero in T2 (no ALUA)
|
||||
// byte 5: SCCS / ACC / TPGS / 3PC. TPGS is enabled only when
|
||||
// an ALUA provider is configured and REPORT TPG is served.
|
||||
if h.alua != nil {
|
||||
data[5] = 0x10 // TPGS=01b, implicit ALUA
|
||||
}
|
||||
// byte 6: reserved / EncServ / VS / MultiP — zero
|
||||
data[7] = 0x02 // BQue=0, CmdQue=1
|
||||
copy(data[8:16], padRight(h.vendorID, 8))
|
||||
@@ -372,9 +395,9 @@ func (h *SCSIHandler) inquiry(cdb [16]byte) SCSIResult {
|
||||
return SCSIResult{Status: StatusGood, Data: data}
|
||||
}
|
||||
|
||||
// Batch 10.5: INQUIRY VPD. Approved pages: 0x00 (supported list),
|
||||
// 0x80 (unit serial number), 0x83 (device identification, non-ALUA
|
||||
// branch only). VPD 0xB0 / 0xB2 are explicitly NOT implemented
|
||||
// Batch 10.5 / P6: INQUIRY VPD. Approved pages: 0x00 (supported list),
|
||||
// 0x80 (unit serial number), 0x83 (device identification). VPD 0xB0 / 0xB2
|
||||
// are explicitly NOT implemented
|
||||
// and NOT advertised (port plan §3.3 N3 — advertised list must
|
||||
// match implemented set or kernel logs errors on every probe).
|
||||
func (h *SCSIHandler) inquiryVPD(pageCode uint8, allocLen uint16) SCSIResult {
|
||||
@@ -418,7 +441,7 @@ func (h *SCSIHandler) inquiryVPD(pageCode uint8, allocLen uint16) SCSIResult {
|
||||
}
|
||||
return SCSIResult{Status: StatusGood, Data: data}
|
||||
|
||||
case 0x83: // Device Identification (non-ALUA branch only)
|
||||
case 0x83: // Device Identification
|
||||
return h.inquiryVPD83(allocLen)
|
||||
|
||||
default:
|
||||
@@ -427,20 +450,19 @@ func (h *SCSIHandler) inquiryVPD(pageCode uint8, allocLen uint16) SCSIResult {
|
||||
}
|
||||
}
|
||||
|
||||
// inquiryVPD83 emits ONE NAA-6 Registered Extended designator
|
||||
// derived from the volume identity. V2 has an ALUA branch (TPG /
|
||||
// RTP descriptors); that's skipped in Batch 10.5 (ALUA is
|
||||
// skip-list). V2's fallback stub NAA was a hardcoded constant —
|
||||
// unusable for T2 because all volumes would report the same
|
||||
// unique ID and Linux multipath / udev would conflate them
|
||||
// (port plan §3.3 N1). Instead we derive a per-volume NAA from
|
||||
// sha256(VolumeID)[:7] prefixed with 0x60 (NAA-6).
|
||||
// inquiryVPD83 emits an NAA-6 Registered Extended designator derived from
|
||||
// the volume identity. When HandlerConfig.ALUA is present, it also emits the
|
||||
// target port group and relative target port designators needed by
|
||||
// multipath. Without ALUA, it preserves the single-descriptor VPD 0x83 shape.
|
||||
func (h *SCSIHandler) inquiryVPD83(allocLen uint16) SCSIResult {
|
||||
// Designator 1: NAA-6 identifier (8 bytes). Derive from the
|
||||
// frontend.Backend's captured VolumeID — stable across the
|
||||
// backend's lifetime and the only authoritative identity
|
||||
// the handler has access to (no extra config threading).
|
||||
// backend's lifetime. ALUA providers may override it with the
|
||||
// frontend path's explicit device identity.
|
||||
naa := naaFromVolumeID(h.backend.Identity().VolumeID)
|
||||
if h.alua != nil {
|
||||
naa = h.alua.DeviceNAA()
|
||||
}
|
||||
naaDesc := []byte{
|
||||
0x01, // code set = binary
|
||||
0x03, // PIV=0, association=00 (logical unit), type=3 (NAA)
|
||||
@@ -449,11 +471,24 @@ func (h *SCSIHandler) inquiryVPD83(allocLen uint16) SCSIResult {
|
||||
}
|
||||
naaDesc = append(naaDesc, naa[:]...)
|
||||
|
||||
data := make([]byte, 4+len(naaDesc))
|
||||
descs := make([]byte, 0, 28)
|
||||
descs = append(descs, naaDesc...)
|
||||
if h.alua != nil {
|
||||
tpgID := h.alua.TargetPortGroupID()
|
||||
rtpID := h.alua.RelativeTargetPortID()
|
||||
descs = append(descs,
|
||||
0x01, 0x15, 0x00, 0x04,
|
||||
0x00, 0x00, byte(tpgID>>8), byte(tpgID),
|
||||
0x01, 0x14, 0x00, 0x04,
|
||||
0x00, 0x00, byte(rtpID>>8), byte(rtpID),
|
||||
)
|
||||
}
|
||||
|
||||
data := make([]byte, 4+len(descs))
|
||||
data[0] = 0x00
|
||||
data[1] = 0x83
|
||||
binary.BigEndian.PutUint16(data[2:4], uint16(len(naaDesc)))
|
||||
copy(data[4:], naaDesc)
|
||||
binary.BigEndian.PutUint16(data[2:4], uint16(len(descs)))
|
||||
copy(data[4:], descs)
|
||||
if int(allocLen) < len(data) {
|
||||
data = data[:allocLen]
|
||||
}
|
||||
|
||||
@@ -265,31 +265,49 @@ References:
|
||||
- do match V2 externally visible ALUA/MPIO protocol coverage unless V3
|
||||
explicitly rejects a behavior.
|
||||
- ALUA state model:
|
||||
- status: local protocol slice done on `iscsi/csi-node-lifecycle`.
|
||||
- active optimized,
|
||||
- active non-optimized,
|
||||
- standby,
|
||||
- unavailable,
|
||||
- transitioning.
|
||||
- standby command policy:
|
||||
- status: local protocol slice done.
|
||||
- metadata/path probing allowed,
|
||||
- READ allowed for initiator path probing,
|
||||
- WRITE and SYNCHRONIZE_CACHE fail closed.
|
||||
- standard INQUIRY TPGS discipline:
|
||||
- status: local protocol slice done.
|
||||
- TPGS stays off until REPORT TARGET PORT GROUPS and ALUA VPD identity
|
||||
are implemented,
|
||||
- when enabled, advertise implicit ALUA only unless explicit transitions
|
||||
are implemented.
|
||||
- REPORT TARGET PORT GROUPS,
|
||||
- REPORT TARGET PORT GROUPS:
|
||||
- status: local protocol slice done.
|
||||
- no-provider rejection,
|
||||
- short allocation truncation,
|
||||
- five-state reporting.
|
||||
- VPD 0x83 target-port identity:
|
||||
- status: local protocol slice done.
|
||||
- NAA stable per volume,
|
||||
- target port group and relative target port distinguish paths,
|
||||
- short allocation length and no-ALUA branches tested.
|
||||
- VPD 0x00 remains advertised-pages-equal-implemented-pages,
|
||||
- state change while I/O is in flight,
|
||||
- concurrent REPORT TARGET PORT GROUPS and standby write reject tests,
|
||||
- multipath initiator test,
|
||||
- primary failover while mounted,
|
||||
- old primary cannot serve stale successful I/O.
|
||||
- VPD 0x00 remains advertised-pages-equal-implemented-pages:
|
||||
- status: local protocol slice done.
|
||||
- state change while I/O is in flight:
|
||||
- status: local protocol state-change test done.
|
||||
- concurrent REPORT TARGET PORT GROUPS and standby write reject tests:
|
||||
- status: pending.
|
||||
- frontend state provider wiring:
|
||||
- status: next.
|
||||
- connect ALUA provider to current V3 frontend facts without importing
|
||||
authority or placement.
|
||||
- multipath initiator test:
|
||||
- status: pending P6-C.
|
||||
- primary failover while mounted:
|
||||
- status: pending P6-E.
|
||||
- old primary cannot serve stale successful I/O:
|
||||
- status: pending P6-C/P6-E.
|
||||
|
||||
- Close bar:
|
||||
- real initiator sees correct ALUA/MPIO behavior,
|
||||
|
||||
Reference in new issue
Block a user