The rx/tx code in pkg/tap/switch.go is a bit hard to follow, with the protocol.Stream() tests, and the Buf()/Read()/Write() code in the stream case.
What the code is doing is to send data to/from the hypervisor. For some hypervisors (qemu, hyperkit, stdio), the size must be sent before the data, either as a 16 bit little-endian, or as a 32 bit little-endian data. This is what the code calls 'stream', and the Buf()/Read()/Write() methods from the streamProtocol interface are only used to write this 2 or 4 bytes for the size.
I've tried to rework this code in https://github.com/cfergeau/gvisor-tap-vsock/tree/rxtx:
- the
streamProtocolinterface is nowReadSize/WriteSizeas I believe this makes the code easier to understand - it introduces a new
hypervisorConnectioninterface to replace theif conn.protocolImpl.Stream()tests
This seems to simplify the code, but is untested, and I don't want to spend more time on this right away. What needs to be done to complete this:
- ideally, have some unit tests to exercise these code paths
- test that data transfer is still working (at least with one 'stream' (qemu) and one 'packet' (hyperkit) hypervisors)
- measure performance, similar to what was done in https://github.com/containers/gvisor-tap-vsock/pull/188
One potential further improvement is to see if we can remove this allocation from rxStream using https://pkg.go.dev/bytes#Buffer
Activity
0No activity yet.