Mark more structs in netstack as savable.

PiperOrigin-RevId: 663780274
This commit is contained in:
Nayana Bidari
2024-08-16 10:47:24 -07:00
committed by gVisor bot
parent afa4fef2c8
commit ee34fd3b9d
16 changed files with 52 additions and 13 deletions
+2
View File
@@ -69,6 +69,8 @@ func AppendIovecFromBytes(iovs []unix.Iovec, bs []byte, max int) []unix.Iovec {
}
// MMsgHdr represents the mmsg_hdr structure required by recvmmsg() on linux.
//
// +stateify savable
type MMsgHdr struct {
Msg unix.Msghdr
Len uint32
+3 -3
View File
@@ -129,7 +129,7 @@ type endpoint struct {
// closed is a function to be called when the FD's peer (if any) closes
// its end of the communication pipe.
closed func(tcpip.Error)
closed func(tcpip.Error) `state:"nosave"`
inboundDispatchers []linkDispatcher
@@ -146,7 +146,7 @@ type endpoint struct {
gsoMaxSize uint32
// wg keeps track of running goroutines.
wg sync.WaitGroup
wg sync.WaitGroup `state:"nosave"`
// gsoKind is the supported kind of GSO.
gsoKind stack.SupportedGSO
@@ -837,7 +837,7 @@ func (*endpoint) SetOnCloseAction(func()) {}
// InjectableEndpoint is an injectable fd-based endpoint. The endpoint writes
// to the FD, but does not read from it. All reads come from injected packets.
//
// +satetify savable
// +stateify savable
type InjectableEndpoint struct {
endpoint
+2
View File
@@ -115,6 +115,8 @@ func (t tPacketHdr) Payload() []byte {
// packetMMapDispatcher uses PACKET_RX_RING's to read/dispatch inbound packets.
// See: mmap_amd64_unsafe.go for implementation details.
//
// +stateify savable
type packetMMapDispatcher struct {
stopfd.StopFD
// fd is the file descriptor used to send and receive packets.
@@ -31,6 +31,7 @@ import (
// BufConfig defines the shape of the buffer used to read packets from the NIC.
var BufConfig = []int{128, 256, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768}
// +stateify savable
type iovecBuffer struct {
// buffer is the actual buffer that holds the packet contents. Some contents
// are reused across calls to pullBuffer if number of requested bytes is
@@ -145,6 +146,8 @@ func (b *iovecBuffer) release() {
// readVDispatcher uses readv() system call to read inbound packets and
// dispatches them.
//
// +stateify savable
type readVDispatcher struct {
stopfd.StopFD
// fd is the file descriptor used to send and receive packets.
@@ -207,6 +210,8 @@ func (d *readVDispatcher) dispatch() (bool, tcpip.Error) {
// recvMMsgDispatcher uses the recvmmsg system call to read inbound packets and
// dispatches them.
//
// +stateify savable
type recvMMsgDispatcher struct {
stopfd.StopFD
// fd is the file descriptor used to send and receive packets.
+5 -2
View File
@@ -30,8 +30,9 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/stack/gro"
)
// +stateify savable
type processor struct {
mu sync.Mutex
mu sync.Mutex `state:"nosave"`
// +checklocks:mu
pkts stack.PacketBufferList
@@ -83,10 +84,12 @@ func (p *processor) deliverPackets() {
// processorManager handles starting, closing, and queuing packets on processor
// goroutines.
//
// +stateify savable
type processorManager struct {
processors []processor
seed uint32
wg sync.WaitGroup
wg sync.WaitGroup `state:"nosave"`
e *endpoint
ready []bool
}
+8 -4
View File
@@ -41,8 +41,10 @@ const (
// queueDispatchers. All outgoing packets are consistently hashed to a single
// underlying queue using the PacketBuffer.Hash if set, otherwise all packets
// are queued to the first queue to avoid reordering in case of missing hash.
//
// +stateify savable
type discipline struct {
wg sync.WaitGroup
wg sync.WaitGroup `state:"nosave"`
dispatchers []queueDispatcher
closed atomicbitops.Int32
@@ -51,15 +53,17 @@ type discipline struct {
// queueDispatcher is responsible for dispatching all outbound packets in its
// queue. It will also smartly batch packets when possible and write them
// through the lower LinkWriter.
//
// +stateify savable
type queueDispatcher struct {
lower stack.LinkWriter
mu sync.Mutex
mu sync.Mutex `state:"nosave"`
// +checklocks:mu
queue packetBufferCircularList
newPacketWaker sleep.Waker
closeWaker sleep.Waker
newPacketWaker sleep.Waker `state:"nosave"`
closeWaker sleep.Waker `state:"nosave"`
}
// New creates a new fifo queuing discipline with the n queues with maximum
+2
View File
@@ -61,6 +61,8 @@ func slotToPayloadSize(offset uint64) uint64 {
// pipe. Indices into this pipe are split into two fields: offset, which counts
// the number of bytes from the beginning of the buffer, and revolution, which
// counts the number of times the index has wrapped around.
//
// +stateify savable
type pipe struct {
buffer []byte
}
+2
View File
@@ -15,6 +15,8 @@
package pipe
// Rx is the receive side of the shared memory ring buffer.
//
// +stateify savable
type Rx struct {
p pipe
+2
View File
@@ -15,6 +15,8 @@
package pipe
// Tx is the transmit side of the shared memory ring buffer.
//
// +stateify savable
type Tx struct {
p pipe
maxPayloadSize uint64
+1
View File
@@ -27,6 +27,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/link/sharedmem/queue"
)
// +stateify savable
type serverRx struct {
// packetPipe represents the receive end of the pipe that carries the packet
// descriptors sent by the client.
+2
View File
@@ -30,6 +30,8 @@ import (
// serverTx represents the server end of the sharedmem queue and is used to send
// packets to the peer in the buffers posted by the peer in the fillPipe.
//
// +stateify savable
type serverTx struct {
// fillPipe represents the receive end of the pipe that carries the RxBuffers
// posted by the peer.
+4 -3
View File
@@ -27,6 +27,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/stack"
)
// +stateify savable
type serverEndpoint struct {
// bufferSize is the size of each individual buffer.
// bufferSize is immutable.
@@ -39,7 +40,7 @@ type serverEndpoint struct {
stopRequested atomicbitops.Uint32
// Wait group used to indicate that all workers have stopped.
completed sync.WaitGroup
completed sync.WaitGroup `state:"nosave"`
// peerFD is an fd to the peer that can be used to detect when the peer is
// gone.
@@ -59,10 +60,10 @@ type serverEndpoint struct {
// onClosed is a function to be called when the FD's peer (if any) closes its
// end of the communication pipe.
onClosed func(tcpip.Error)
onClosed func(tcpip.Error) `state:"nosave"`
// mu protects the following fields.
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
// tx is the transmit queue.
// +checklocks:mu
+2
View File
@@ -25,6 +25,8 @@ import (
)
// StopFD is an eventfd used to signal the stop of a dispatcher.
//
// +stateify savable
type StopFD struct {
EFD int
}
+2
View File
@@ -332,6 +332,8 @@ func (d *Device) WriteNotify() {
//
// It is ref-counted as multiple opening files can attach to the same NIC.
// The last owner is responsible for deleting the NIC.
//
// +stateify savable
type tunEndpoint struct {
tunEndpointRefs
*channel.Endpoint
+4 -1
View File
@@ -22,6 +22,7 @@ import (
var _ NetworkLinkEndpoint = (*BridgeEndpoint)(nil)
// +stateify savable
type bridgePort struct {
bridge *BridgeEndpoint
nic *nic
@@ -75,8 +76,10 @@ func NewBridgeEndpoint(mtu uint32) *BridgeEndpoint {
}
// BridgeEndpoint is a bridge endpoint.
//
// +stateify savable
type BridgeEndpoint struct {
mu bridgeRWMutex
mu bridgeRWMutex `state:"nosave"`
// +checklocks:mu
ports map[tcpip.NICID]*bridgePort
// +checklocks:mu
+6
View File
@@ -50,6 +50,8 @@ const (
)
// A groBucket holds packets that are undergoing GRO.
//
// +stateify savable
type groBucket struct {
// count is the number of packets in the bucket.
count int
@@ -265,6 +267,8 @@ func (gb *groBucket) found(gd *GRO, groPkt *groPacket, flushGROPkt bool, pkt *st
// A groPacket is packet undergoing GRO. It may be several packets coalesced
// together.
//
// +stateify savable
type groPacket struct {
// groPacketEntry is an intrusive list.
groPacketEntry
@@ -303,6 +307,8 @@ func (pk *groPacket) payloadSize() int {
}
// GRO coalesces incoming packets to increase throughput.
//
// +stateify savable
type GRO struct {
enabled bool
buckets [groNBuckets]groBucket