[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [PATCH 1/2] nbd-trdump: Add support for all commands



On Fri, Jan 14, 2022 at 02:29:22PM +0100, Manfred Spraul wrote:
> Support for pretty-printing NBD_CMD_TRIM and NBD_CMD_WRITE_ZEROES is
> missing in nbd-trdump.
> In addition, only the commands right now implemented in nbd-server
> are supported, instead of all commands defined in the protocol.
> 
> Thus:
> - move the existing getcommandname() helper function into a new
>   nbd-helper.h header file.
> - use the helper function in nbd-trdump
> - add all commands from proto.md.
> - in nbd-trdump: change ctest from "char *" to "const char *"
>   and increase number of characters in printf statement.
> 
> Signed-off-by: Manfred Spraul <manfred.spraul@de.bosch.com>
> ---
>  nbd-helper.h | 31 +++++++++++++++++++++++++++++++
>  nbd-server.c | 26 +-------------------------
>  nbd-trdump.c | 24 +++++-------------------
>  nbd.h        |  5 ++++-
>  4 files changed, 41 insertions(+), 45 deletions(-)
>  create mode 100644 nbd-helper.h
> 
> diff --git a/nbd-helper.h b/nbd-helper.h

> +/**
> + * Translate a command name into human readable form
> + *
> + * @param command The command number (after applying NBD_CMD_MASK_COMMAND)
> + * @return pointer to the command name
> + **/
> +#define ENUM2STR(x)	case x: return #x
> +static inline const char * getcommandname(uint32_t command) {
> +	switch (command) {
> +	ENUM2STR(NBD_CMD_READ);
> +	ENUM2STR(NBD_CMD_WRITE);
> +	ENUM2STR(NBD_CMD_DISC);
> +	ENUM2STR(NBD_CMD_FLUSH);
> +	ENUM2STR(NBD_CMD_TRIM);
> +	ENUM2STR(NBD_CMD_WRITE_ZEROES);

Missing ENUM2STR(NBD_CMD_CACHE) between TRIM and WRITE_ZEROES.

> +	ENUM2STR(NBD_CMD_BLOCK_STATUS);
> +	ENUM2STR(NBD_CMD_RESIZE);
> +	default:
> +		return "UNKNOWN";
> +	}

> +++ b/nbd.h
> @@ -35,7 +35,10 @@ enum {
>  	NBD_CMD_DISC = 2,
>  	NBD_CMD_FLUSH = 3,
>  	NBD_CMD_TRIM = 4,
> -	NBD_CMD_WRITE_ZEROES = 6
> +	NBD_CMD_CACHE = 5,
> +	NBD_CMD_WRITE_ZEROES = 6,
> +	NBD_CMD_BLOCK_STATUS = 7,
> +	NBD_CMD_RESIZE = 8
>  };

Absent any strong reason for avoiding trailing commas (such as
insisting on C89 compliance), my personal preference is to use it, so
that future changes can touch one fewer line of code when extending
the enum.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


Reply to: