From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com
Subject: Re: [Qemu-devel] [PATCH] nbd: generalize usage of nbd_read
Date: Fri, 1 Feb 2019 12:27:09 -0600 [thread overview]
Message-ID: <eb482fb2-5934-c786-1b23-f46054bbdb39@redhat.com> (raw)
In-Reply-To: <20190128165830.165170-1-vsementsov@virtuozzo.com>
[-- Attachment #1: Type: text/plain, Size: 2156 bytes --]
On 1/28/19 10:58 AM, Vladimir Sementsov-Ogievskiy wrote:
> We generally do very similar things around nbd_read: error_prepend,
> specifying, what we have tried to read and be_to_cpu conversion of
> integers.
>
> So, it seems reasonable to move common things to helper functions,
> which:
> 1. simplify code a bit
> 2. generalize nbd_read error descriptions, all starting with
> "Failed to read"
> 3. make it more difficult to forget to convert things from BE
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> include/block/nbd.h | 31 ++++++++++++++--
> block/nbd-client.c | 5 ++-
> nbd/client.c | 88 +++++++++++++++------------------------------
> nbd/common.c | 2 +-
> nbd/server.c | 27 +++++---------
> 5 files changed, 70 insertions(+), 83 deletions(-)
> +
> +#define DEF_NBD_READ(bits) \
> +static inline int nbd_read ## bits(QIOChannel *ioc, uint ## bits ## _t * val, \
checkpatch didn't flag it, but I think our style is '*val', not '* val'.
> + const char *desc, Error **errp) \
> +{ \
> + if (nbd_read(ioc, val, sizeof(*val), desc, errp) < 0) { \
> + return -1; \
> + } \
> + *val = be ## bits ## _to_cpu(*val); \
> + return 0; \
> }
>
> +DEF_NBD_READ(16) /* Defines nbd_read16(). */
> +DEF_NBD_READ(32) /* Defines nbd_read32(). */
> +DEF_NBD_READ(64) /* Defines nbd_read64(). */
> +
> +#undef DEF_NBD_READ
I think the name DEF_NBD_READ_N is slightly nicer; that's minor enough
that I don't mind tweaking it.
Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks; queued for my next NBD pull request.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-02-01 18:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-28 16:58 [Qemu-devel] [PATCH] nbd: generalize usage of nbd_read Vladimir Sementsov-Ogievskiy
2019-02-01 18:27 ` Eric Blake [this message]
2019-02-01 18:34 ` Eric Blake
2019-02-03 16:01 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eb482fb2-5934-c786-1b23-f46054bbdb39@redhat.com \
--to=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).