mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
frontend: bound iSCSI Data-Out wait time
This commit is contained in:
1 parent
14bdc1146e
commit
d742b6674a
4 files changed
+122
-17
No files matched your search
@@ -230,3 +230,74 @@ func TestP1_ISCSI_R2TDataOut_PendingQueueBounded(t *testing.T) {
|
||||
t.Fatalf("backend WriteCount=%d want 0 after overflow", rec.WriteCount())
|
||||
}
|
||||
}
|
||||
|
||||
func TestP1_ISCSI_R2TDataOut_TimesOutWhenInitiatorStalls(t *testing.T) {
|
||||
const (
|
||||
blocks = 256
|
||||
maxBurst = 64 * 1024
|
||||
blockSize = int(iscsi.DefaultBlockSize)
|
||||
)
|
||||
totalBytes := blocks * blockSize
|
||||
|
||||
rec := testback.NewRecordingBackend(frontend.Identity{VolumeID: "v1", ReplicaID: "r1"})
|
||||
prov := testback.NewStaticProvider(rec)
|
||||
neg := iscsi.DefaultNegotiableConfig()
|
||||
neg.MaxBurstLength = maxBurst
|
||||
neg.FirstBurstLength = 0
|
||||
tg := iscsi.NewTarget(iscsi.TargetConfig{
|
||||
Listen: "127.0.0.1:0",
|
||||
IQN: "iqn.2026-04.example.v3:v1",
|
||||
VolumeID: "v1",
|
||||
Provider: prov,
|
||||
Negotiation: neg,
|
||||
DataOutTimeout: 100 * time.Millisecond,
|
||||
})
|
||||
addr, err := tg.Start()
|
||||
if err != nil {
|
||||
t.Fatalf("target Start: %v", err)
|
||||
}
|
||||
defer tg.Close()
|
||||
|
||||
cli := dialAndLogin(t, addr)
|
||||
defer cli.logout(t)
|
||||
|
||||
writeCmd := &iscsi.PDU{}
|
||||
writeCmd.SetOpcode(iscsi.OpSCSICmd)
|
||||
writeCmd.SetOpSpecific1(iscsi.FlagF | iscsi.FlagW)
|
||||
writeCmd.SetLUN(0)
|
||||
writeCmd.SetInitiatorTaskTag(cli.itt)
|
||||
cli.itt++
|
||||
writeCmd.SetExpectedDataTransferLength(uint32(totalBytes))
|
||||
writeCmd.SetCmdSN(cli.cmdSN)
|
||||
cli.cmdSN++
|
||||
writeCmd.SetExpStatSN(cli.statSN + 1)
|
||||
writeCmd.SetCDB(writeCDB10(0, uint16(blocks)))
|
||||
if err := iscsi.WritePDU(cli.conn, writeCmd); err != nil {
|
||||
t.Fatalf("write SCSI WRITE(10): %v", err)
|
||||
}
|
||||
|
||||
r2t, err := iscsi.ReadPDU(cli.conn)
|
||||
if err != nil {
|
||||
t.Fatalf("read R2T: %v", err)
|
||||
}
|
||||
if r2t.Opcode() != iscsi.OpR2T {
|
||||
t.Fatalf("first response opcode=%s want R2T", iscsi.OpcodeName(r2t.Opcode()))
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
_ = cli.conn.SetReadDeadline(time.Now().Add(2 * time.Second))
|
||||
_, err = iscsi.ReadPDU(cli.conn)
|
||||
if err == nil {
|
||||
t.Fatal("expected connection close after Data-Out timeout")
|
||||
}
|
||||
elapsed := time.Since(start)
|
||||
if elapsed < 50*time.Millisecond {
|
||||
t.Fatalf("session closed too quickly: %s", elapsed)
|
||||
}
|
||||
if elapsed > time.Second {
|
||||
t.Fatalf("Data-Out timeout took too long: %s", elapsed)
|
||||
}
|
||||
if rec.WriteCount() != 0 {
|
||||
t.Fatalf("backend WriteCount=%d want 0 after timeout", rec.WriteCount())
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
)
|
||||
@@ -72,10 +73,11 @@ type Session struct {
|
||||
// negCfg + resolver + lister are injected by Target at
|
||||
// construction so this layer stays unaware of the target's
|
||||
// catalog.
|
||||
negCfg NegotiableConfig
|
||||
resolver TargetResolver
|
||||
lister TargetLister
|
||||
negResult LoginResult
|
||||
negCfg NegotiableConfig
|
||||
dataOutTimeout time.Duration
|
||||
resolver TargetResolver
|
||||
lister TargetLister
|
||||
negResult LoginResult
|
||||
|
||||
// Backend open is deferred to post-login, Normal-session
|
||||
// only. provider + volumeID + hcfg are captured at session
|
||||
@@ -109,17 +111,18 @@ type Logger interface {
|
||||
// provider + volumeID + hcfg are captured for post-login,
|
||||
// Normal-session-only backend open (residual-risk fix). The
|
||||
// backend is NOT opened at construction.
|
||||
func newSession(conn net.Conn, provider frontend.Provider, volumeID string, hcfg HandlerConfig, negCfg NegotiableConfig, resolver TargetResolver, lister TargetLister, logger Logger) *Session {
|
||||
func newSession(conn net.Conn, provider frontend.Provider, volumeID string, hcfg HandlerConfig, negCfg NegotiableConfig, dataOutTimeout time.Duration, resolver TargetResolver, lister TargetLister, logger Logger) *Session {
|
||||
return &Session{
|
||||
conn: conn,
|
||||
logger: logger,
|
||||
state: SessionLogin,
|
||||
negCfg: negCfg,
|
||||
resolver: resolver,
|
||||
lister: lister,
|
||||
provider: provider,
|
||||
volumeID: volumeID,
|
||||
hcfg: hcfg,
|
||||
conn: conn,
|
||||
logger: logger,
|
||||
state: SessionLogin,
|
||||
negCfg: negCfg,
|
||||
dataOutTimeout: dataOutTimeout,
|
||||
resolver: resolver,
|
||||
lister: lister,
|
||||
provider: provider,
|
||||
volumeID: volumeID,
|
||||
hcfg: hcfg,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,6 +420,13 @@ func (s *Session) collectWriteData(req *PDU, edtl uint32) ([]byte, error) {
|
||||
return nil, fmt.Errorf("send R2T: %w", err)
|
||||
}
|
||||
|
||||
if s.dataOutTimeout > 0 {
|
||||
if err := s.conn.SetReadDeadline(time.Now().Add(s.dataOutTimeout)); err != nil {
|
||||
return nil, fmt.Errorf("set Data-Out deadline: %w", err)
|
||||
}
|
||||
defer s.conn.SetReadDeadline(time.Time{})
|
||||
}
|
||||
|
||||
collector.beginR2T()
|
||||
for collector.receivedBytes() < burstEnd {
|
||||
pdu, err := ReadPDU(s.conn)
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend"
|
||||
)
|
||||
@@ -51,6 +52,12 @@ type TargetConfig struct {
|
||||
// value = DefaultNegotiableConfig().
|
||||
Negotiation NegotiableConfig
|
||||
|
||||
// DataOutTimeout bounds how long a session waits for
|
||||
// R2T-solicited Data-Out after issuing R2T. Zero picks the
|
||||
// default. This is a target-local resource protection knob, not
|
||||
// an iSCSI login-negotiated value.
|
||||
DataOutTimeout time.Duration
|
||||
|
||||
// Logger. Nil → log.Default wrapped for the session layer.
|
||||
Logger *log.Logger
|
||||
}
|
||||
@@ -78,6 +85,9 @@ func NewTarget(cfg TargetConfig) *Target {
|
||||
if cfg.Negotiation == (NegotiableConfig{}) {
|
||||
cfg.Negotiation = DefaultNegotiableConfig()
|
||||
}
|
||||
if cfg.DataOutTimeout == 0 {
|
||||
cfg.DataOutTimeout = 30 * time.Second
|
||||
}
|
||||
return &Target{
|
||||
cfg: cfg,
|
||||
logger: stdlogAdapter{l: lg},
|
||||
@@ -194,7 +204,7 @@ func (t *Target) handleConn(conn net.Conn) {
|
||||
// the backend after login succeeds, and only for Normal
|
||||
// sessions.
|
||||
sess := newSession(conn, t.cfg.Provider, t.cfg.VolumeID, t.cfg.Handler,
|
||||
t.cfg.Negotiation, t, t, t.logger)
|
||||
t.cfg.Negotiation, t.cfg.DataOutTimeout, t, t, t.logger)
|
||||
if err := sess.serve(ctx); err != nil && !errors.Is(err, net.ErrClosed) {
|
||||
t.logger.Printf("iscsi: session error (%s): %v", conn.RemoteAddr(), err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# iSCSI OS Initiator Compatibility Plan
|
||||
|
||||
Status: P1-A/B/C implemented on `fix/iscsi-os-initiator-compat`
|
||||
Status: P1-A/B/C/D implemented on `fix/iscsi-os-initiator-compat`
|
||||
|
||||
Owner track: frontend compatibility
|
||||
|
||||
@@ -230,6 +230,20 @@ Add timeout behavior:
|
||||
- session exits within configured timeout,
|
||||
- no goroutine leak.
|
||||
|
||||
Implementation status:
|
||||
|
||||
```text
|
||||
TargetConfig.DataOutTimeout
|
||||
default: 30s
|
||||
test override: 100ms
|
||||
|
||||
TestP1_ISCSI_R2TDataOut_TimesOutWhenInitiatorStalls
|
||||
target sends R2T
|
||||
initiator sends no Data-Out
|
||||
session closes within timeout
|
||||
backend Write is not called
|
||||
```
|
||||
|
||||
### Slice E: Real OS Initiator Harness
|
||||
|
||||
After A-D pass locally, run hardware:
|
||||
@@ -259,7 +273,7 @@ Only after WRITE/mkfs is green:
|
||||
1. Write Slice A red test. Done.
|
||||
2. Add V3-local pending queue support in current serial session. Done.
|
||||
3. Extract V3-local `DataOutCollector`. Done.
|
||||
4. Add Data-Out timeout.
|
||||
4. Add Data-Out timeout. Done.
|
||||
5. Run Linux OS initiator mkfs harness.
|
||||
6. Add DataInWriter only if OS test or later fio/read test needs it.
|
||||
7. Then decide whether a txLoop is needed.
|
||||
|
||||
Reference in new issue
Block a user