Implement "bos getlog" and reengineer the decode path somewhat
Implement the "bos getlog" subcommand - which requires making the receive side
of split RPC function work. To this end, the following reengineering has been
done to the decode side:
(1) Lift the requirement that the Rx buffer cursor be 4-byte aligned as
BOZO.GetLog() doesn't align the log data it returns.
(2) Permit a request for an unknown - and possibly zero - amount of data to be
set in call->need_size. BOZO.GetLog() doesn't tell you in advance how
much data it will return: the data stops when the Rx receive phase ends
with LAST_PACKET being flagged.
(3) Separate blob decoding (strings & opaques) from bulk decoding in the
member variables of the rx_call struct, where a bulk decode is now a
sequence of blobs, structs or ints.
(4) Handle blob decoding asynchronously, where the buffer into which a blob is
being written may not represent contiguous memory. This is done by
setting up with an init function, called once, and a decode-into function,
called repeatedly whilst it returns 1. The function is only called when
there is sufficient data in the receive buffers.
(5) Decode padding asynchronously by working out up front for a blob how much
padding it requires and then decoding it as its own blob at the end using
a special source buffer as a marker to switch processing.
(6) Perform split reception by adding additional states within the decode
state machine to call out to the handler functions.
The receive() method of the split_handler class provided to a split RPC
function then implements its own state machine on top of the decoder state
machine.
Further:
(*) rxrpc_recv_data() now reports ENODATA rather than EMSGSIZE if the receive
phase ends with short data.
(*) MSG_MORE handling has separate rx_call struct members for the send and
receive phase now to avoid confusion.
(*) rxrpc_enc/dec_slow() now use rxrpc_enc/dec_blob() to avoid duplicating a
lot of code.
(*) rxrpc_enc/dec() now also go to the slow path if the cursor is misaligned,
which may mean the data to be read is split across buffers.
(*) The rx_call struct now has a pointer to a cleanup function to clean up the
decoder state at the end to deal with aborted calls.
(*) rxrpc_post_dec() reduces call->need_size as well as call->data_count as we
don't want to be waiting for N bytes to turn up for a size-N blob if we
have already received N-1 bytes of it and only need one more byte.
This does mean that call->need_size may need resetting more often.
(*) Added an output_raw() python output method to permit bytearray objects to
be printed. Conversion to a string means that control characters and
quotes get escaped (eg. a newline char gets converted to \n).
(*) Catching the SystemExit exception should not produce an error due to ret
not existing as a variable.
Signed-off-by: David Howells <dhowells@redhat.com>