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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user