usbip: collapse server state into exportLedger

ServerService used to own three mutexes coordinating six pieces of
mutable state (exports, busy, controlState, controlSeq, controlSubs,
LeaseManager). The lock-ordering rule that fixed the import/attach
race in 0c892411a lived only as a comment. Two-mutex (fast/slow)
ledger absorbs all of it; the two mutexes are never held
simultaneously, so the ordering rule becomes a property of the type
instead of a discipline callers must observe. TryReserveForImport
closes the window where two concurrent OpReqImports could both pass
the busy check before either marked busy.
This commit is contained in:
世界
2026-05-12 20:14:50 +08:00
parent cec39eb00c
commit bee231b9ff
12 changed files with 1112 additions and 818 deletions
+3 -6
View File
@@ -51,7 +51,7 @@ func (s *ServerService) dispatchConn(conn net.Conn) {
s.handleStandardConn(conn, ParseOpHeader(prefix[:]))
}
func (s *ServerService) readControlConn(sub *serverControlConn, done chan<- struct{}) {
func (s *ServerService) readControlConn(sub *exportSubscriber, done chan<- struct{}) {
defer close(done)
var reader controlReader
for {
@@ -62,13 +62,10 @@ func (s *ServerService) readControlConn(sub *serverControlConn, done chan<- stru
frame := message.Frame
switch frame.Type {
case controlFramePing:
s.enqueueControlFrame(sub, controlFrame{
Type: controlFramePong,
Version: controlProtocolVersion,
})
s.ledger.HandleControlPing(sub)
case controlFrameLeaseRequest:
if supportsControlExtensions(sub.capabilities) {
s.handleControlLeaseRequest(sub, message.Payload)
s.ledger.HandleControlLeaseRequest(s.ctx, sub, message.Payload)
continue
}
return