Eric Blake
2023-Jun-09 02:17 UTC
[Libguestfs] [libnbd PATCH v4 3/4] generator: Rename states-reply-structured to states-reply-chunk
Upcoming patches to add extended headers want to share the common payload parser with structured replies. Renaming the file and the associated states from "structured" to "chunk" makes it more obvious that we will be sharing the code independent from the header style parsed in the earlier REPLY portion of the state machine. Signed-off-by: Eric Blake <eblake at redhat.com> --- generator/state_machine.ml | 26 +++++++++---------- generator/states-reply.c | 2 +- ...eply-structured.c => states-reply-chunk.c} | 22 ++++++++-------- generator/Makefile.am | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) rename generator/{states-reply-structured.c => states-reply-chunk.c} (97%) diff --git a/generator/state_machine.ml b/generator/state_machine.ml index b5485aec..3a912508 100644 --- a/generator/state_machine.ml +++ b/generator/state_machine.ml @@ -782,7 +782,7 @@ and }; Group ("SIMPLE_REPLY", simple_reply_state_machine); - Group ("STRUCTURED_REPLY", structured_reply_state_machine); + Group ("CHUNK_REPLY", chunk_reply_state_machine); State { default_state with @@ -812,76 +812,76 @@ and ] (* Receiving a structured reply payload from the server. - * Implementation: generator/states-reply-structured.c + * Implementation: generator/states-reply-chunk.c *) -and structured_reply_state_machine = [ +and chunk_reply_state_machine = [ State { default_state with name = "START"; - comment = "Start parsing a structured reply payload from the server"; + comment = "Start parsing a chunk reply payload from the server"; external_events = []; }; State { default_state with name = "RECV_ERROR"; - comment = "Receive a structured reply error header"; + comment = "Receive a chunk reply error header"; external_events = [] }; State { default_state with name = "RECV_ERROR_MESSAGE"; - comment = "Receive a structured reply error message"; + comment = "Receive a chunk reply error message"; external_events = []; }; State { default_state with name = "RECV_ERROR_TAIL"; - comment = "Receive a structured reply error tail"; + comment = "Receive a chunk reply error tail"; external_events = []; }; State { default_state with name = "RECV_OFFSET_DATA"; - comment = "Receive a structured reply offset-data header"; + comment = "Receive a chunk reply offset-data header"; external_events = []; }; State { default_state with name = "RECV_OFFSET_DATA_DATA"; - comment = "Receive a structured reply offset-data block of data"; + comment = "Receive a chunk reply offset-data block of data"; external_events = []; }; State { default_state with name = "RECV_OFFSET_HOLE"; - comment = "Receive a structured reply offset-hole header"; + comment = "Receive a chunk reply offset-hole header"; external_events = []; }; State { default_state with name = "RECV_BS_ENTRIES"; - comment = "Receive a structured reply block-status payload"; + comment = "Receive a chunk reply block-status payload"; external_events = []; }; State { default_state with name = "RESYNC"; - comment = "Ignore payload of an unexpected structured reply"; + comment = "Ignore payload of an unexpected chunk reply"; external_events = []; }; State { default_state with name = "FINISH"; - comment = "Finish receiving a structured reply"; + comment = "Finish receiving a chunk reply"; external_events = []; }; ] diff --git a/generator/states-reply.c b/generator/states-reply.c index 87f17bae..bd6336a8 100644 --- a/generator/states-reply.c +++ b/generator/states-reply.c @@ -176,7 +176,7 @@ REPLY.RECV_STRUCTURED_REMAINING: save_reply_state (h); SET_NEXT_STATE (%.READY); return 0; - case 0: SET_NEXT_STATE (%STRUCTURED_REPLY.START); + case 0: SET_NEXT_STATE (%CHUNK_REPLY.START); } return 0; diff --git a/generator/states-reply-structured.c b/generator/states-reply-chunk.c similarity index 97% rename from generator/states-reply-structured.c rename to generator/states-reply-chunk.c index 3a7a03fd..94f3a8ae 100644 --- a/generator/states-reply-structured.c +++ b/generator/states-reply-chunk.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* State machine for parsing structured replies from the server. */ +/* State machine for parsing structured reply chunk payloads from the server. */ #include <stdbool.h> #include <stddef.h> @@ -45,7 +45,7 @@ structured_reply_in_bounds (uint64_t offset, uint32_t length, } STATE_MACHINE { - REPLY.STRUCTURED_REPLY.START: + REPLY.CHUNK_REPLY.START: struct command *cmd = h->reply_cmd; uint16_t flags, type; uint32_t length; @@ -145,7 +145,7 @@ REPLY.STRUCTURED_REPLY.START: SET_NEXT_STATE (%RESYNC); return 0; - REPLY.STRUCTURED_REPLY.RECV_ERROR: + REPLY.CHUNK_REPLY.RECV_ERROR: struct command *cmd = h->reply_cmd; uint32_t length, msglen, error; @@ -184,7 +184,7 @@ REPLY.STRUCTURED_REPLY.RECV_ERROR: SET_NEXT_STATE (%RESYNC); return 0; - REPLY.STRUCTURED_REPLY.RECV_ERROR_MESSAGE: + REPLY.CHUNK_REPLY.RECV_ERROR_MESSAGE: uint32_t length, msglen; uint16_t type; @@ -226,7 +226,7 @@ REPLY.STRUCTURED_REPLY.RECV_ERROR_MESSAGE: } return 0; - REPLY.STRUCTURED_REPLY.RECV_ERROR_TAIL: + REPLY.CHUNK_REPLY.RECV_ERROR_TAIL: struct command *cmd = h->reply_cmd; uint32_t error; uint16_t type; @@ -283,7 +283,7 @@ REPLY.STRUCTURED_REPLY.RECV_ERROR_TAIL: } return 0; - REPLY.STRUCTURED_REPLY.RECV_OFFSET_DATA: + REPLY.CHUNK_REPLY.RECV_OFFSET_DATA: struct command *cmd = h->reply_cmd; uint64_t offset; uint32_t length; @@ -322,7 +322,7 @@ REPLY.STRUCTURED_REPLY.RECV_OFFSET_DATA: } return 0; - REPLY.STRUCTURED_REPLY.RECV_OFFSET_DATA_DATA: + REPLY.CHUNK_REPLY.RECV_OFFSET_DATA_DATA: struct command *cmd = h->reply_cmd; uint64_t offset; uint32_t length; @@ -353,7 +353,7 @@ REPLY.STRUCTURED_REPLY.RECV_OFFSET_DATA_DATA: } return 0; - REPLY.STRUCTURED_REPLY.RECV_OFFSET_HOLE: + REPLY.CHUNK_REPLY.RECV_OFFSET_HOLE: struct command *cmd = h->reply_cmd; uint64_t offset; uint32_t length; @@ -403,7 +403,7 @@ REPLY.STRUCTURED_REPLY.RECV_OFFSET_HOLE: } return 0; - REPLY.STRUCTURED_REPLY.RECV_BS_ENTRIES: + REPLY.CHUNK_REPLY.RECV_BS_ENTRIES: struct command *cmd = h->reply_cmd; uint32_t length; size_t i; @@ -457,7 +457,7 @@ REPLY.STRUCTURED_REPLY.RECV_BS_ENTRIES: } return 0; - REPLY.STRUCTURED_REPLY.RESYNC: + REPLY.CHUNK_REPLY.RESYNC: struct command *cmd = h->reply_cmd; uint16_t type; uint32_t length; @@ -491,7 +491,7 @@ REPLY.STRUCTURED_REPLY.RESYNC: } return 0; - REPLY.STRUCTURED_REPLY.FINISH: + REPLY.CHUNK_REPLY.FINISH: uint16_t flags; flags = be16toh (h->sbuf.sr.structured_reply.flags); diff --git a/generator/Makefile.am b/generator/Makefile.am index 91dbde5c..39285e82 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -37,8 +37,8 @@ states_code = \ states-newstyle-opt-structured-reply.c \ states-newstyle.c \ states-oldstyle.c \ + states-reply-chunk.c \ states-reply-simple.c \ - states-reply-structured.c \ states-reply.c \ $(NULL) -- 2.40.1
Eric Blake
2023-Jun-12 20:34 UTC
[Libguestfs] [libnbd PATCH v4 3/4] generator: Rename states-reply-structured to states-reply-chunk
On Thu, Jun 08, 2023 at 09:17:37PM -0500, Eric Blake wrote:> Upcoming patches to add extended headers want to share the common > payload parser with structured replies. Renaming the file and the > associated states from "structured" to "chunk" makes it more obvious > that we will be sharing the code independent from the header style > parsed in the earlier REPLY portion of the state machine. > > Signed-off-by: Eric Blake <eblake at redhat.com> > --- > generator/state_machine.ml | 26 +++++++++---------- > generator/states-reply.c | 2 +- > ...eply-structured.c => states-reply-chunk.c} | 22 ++++++++-------- > generator/Makefile.am | 2 +- > 4 files changed, 26 insertions(+), 26 deletions(-) > rename generator/{states-reply-structured.c => states-reply-chunk.c} (97%)I'm thinking of squashing in: diff --git c/lib/internal.h w/lib/internal.h index 1e8d02f1..4b0043b3 100644 --- c/lib/internal.h +++ w/lib/internal.h @@ -252,10 +252,10 @@ struct nbd_handle { } hdr; union { uint64_t align_; /* Start reply.payload on an 8-byte alignment */ - struct nbd_structured_reply_offset_data offset_data; - struct nbd_structured_reply_offset_hole offset_hole; + struct nbd_chunk_offset_data offset_data; + struct nbd_chunk_offset_hole offset_hole; struct { - struct nbd_structured_reply_error error; + struct nbd_chunk_error error; char msg[NBD_MAX_STRING]; /* Common to all error types */ uint64_t offset; /* Only used for NBD_REPLY_TYPE_ERROR_OFFSET */ } NBD_ATTRIBUTE_PACKED error; diff --git c/lib/nbd-protocol.h w/lib/nbd-protocol.h index 50275dcd..fef19f2c 100644 --- c/lib/nbd-protocol.h +++ w/lib/nbd-protocol.h @@ -211,20 +211,20 @@ struct nbd_structured_reply { uint16_t flags; /* NBD_REPLY_FLAG_* */ uint16_t type; /* NBD_REPLY_TYPE_* */ uint64_t cookie; /* Opaque handle. */ - uint32_t length; /* Length of payload which follows. */ + uint32_t length; /* Length of following nbd_chunk_* payload. */ } NBD_ATTRIBUTE_PACKED; -struct nbd_structured_reply_offset_data { +struct nbd_chunk_offset_data { uint64_t offset; /* offset */ /* Followed by data. */ } NBD_ATTRIBUTE_PACKED; -struct nbd_structured_reply_offset_hole { +struct nbd_chunk_offset_hole { uint64_t offset; uint32_t length; /* Length of hole. */ } NBD_ATTRIBUTE_PACKED; -struct nbd_structured_reply_error { +struct nbd_chunk_error { uint32_t error; /* NBD_E* error number */ uint16_t len; /* Length of human readable error. */ /* Followed by human readable error string, and possibly more structure. */ -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org