]> xenbits.xensource.com Git - qemu-xen-unstable.git/commit
nbd/server: refactor nbd_trip: cmd_read and generic reply
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Thu, 8 Mar 2018 18:46:35 +0000 (21:46 +0300)
committerEric Blake <eblake@redhat.com>
Tue, 13 Mar 2018 20:38:55 +0000 (15:38 -0500)
commit6a4175997b942d74f95d18433cacd98c264c5dc6
tree99ae5e7fd5cc3a9c8c389ecd27a133f623cfec70
parenta0d7ce20a94ba66e1d9577429a62d133f1cd19cf
nbd/server: refactor nbd_trip: cmd_read and generic reply

nbd_trip has difficult logic when sending replies: it tries to use one
code path for all replies. It is ok for simple replies, but is not
comfortable for structured replies. Also, two types of error (and
corresponding messages in local_err) - fatal (leading to disconnect)
and not-fatal (just to be sent to the client) are difficult to follow.

To make things a bit clearer, the following is done:
 - split CMD_READ logic to separate function. It is the most difficult
   command for now, and it is definitely cramped inside nbd_trip. Also,
   it is difficult to follow CMD_READ logic, shared between
   "case NBD_CMD_READ" and "if"s under "reply:" label.
 - create separate helper function nbd_send_generic_reply() and use it
   both in new nbd_do_cmd_read and for other commands in nbd_trip instead
   of common code-path under "reply:" label in nbd_trip. The helper
   supports an error message, so logic with local_err in nbd_trip is
   simplified.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20180308184636.178534-5-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: grammar tweaks and blank line placement]
Signed-off-by: Eric Blake <eblake@redhat.com>
nbd/server.c