From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com, pbonzini@redhat.com,
eblake@redhat.com, vsementsov@virtuozzo.com, den@openvz.org
Subject: [Qemu-devel] [PATCH 1/9] nbd/server: add nbd_opt_invalid helper
Date: Thu, 15 Feb 2018 16:51:39 +0300 [thread overview]
Message-ID: <1518702707-7077-2-git-send-email-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <1518702707-7077-1-git-send-email-vsementsov@virtuozzo.com>
NBD_REP_ERR_INVALID is often parameter to nbd_opt_drop and it would
be used more in following patches. So, let's add a helper.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
nbd/server.c | 50 ++++++++++++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 14 deletions(-)
diff --git a/nbd/server.c b/nbd/server.c
index 112e3f69df..b9860a6dcf 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -218,22 +218,46 @@ nbd_negotiate_send_rep_err(NBDClient *client, uint32_t type,
/* Drop remainder of the current option, and send a reply with the
* given error type and message. Return -errno on read or write
* failure; or 0 if connection is still live. */
-static int GCC_FMT_ATTR(4, 5)
-nbd_opt_drop(NBDClient *client, uint32_t type, Error **errp,
- const char *fmt, ...)
+static int GCC_FMT_ATTR(4, 0)
+nbd_opt_vdrop(NBDClient *client, uint32_t type, Error **errp,
+ const char *fmt, va_list va)
{
int ret = nbd_drop(client->ioc, client->optlen, errp);
- va_list va;
client->optlen = 0;
if (!ret) {
- va_start(va, fmt);
ret = nbd_negotiate_send_rep_verr(client, type, errp, fmt, va);
- va_end(va);
}
return ret;
}
+static int GCC_FMT_ATTR(4, 5)
+nbd_opt_drop(NBDClient *client, uint32_t type, Error **errp,
+ const char *fmt, ...)
+{
+ int ret;
+ va_list va;
+
+ va_start(va, fmt);
+ ret = nbd_opt_vdrop(client, type, errp, fmt, va);
+ va_end(va);
+
+ return ret;
+}
+
+static int GCC_FMT_ATTR(3, 4)
+nbd_opt_invalid(NBDClient *client, Error **errp, const char *fmt, ...)
+{
+ int ret;
+ va_list va;
+
+ va_start(va, fmt);
+ ret = nbd_opt_vdrop(client, NBD_REP_ERR_INVALID, errp, fmt, va);
+ va_end(va);
+
+ return ret;
+}
+
/* Read size bytes from the unparsed payload of the current option.
* Return -errno on I/O error, 0 if option was completely handled by
* sending a reply about inconsistent lengths, or 1 on success. */
@@ -241,9 +265,9 @@ static int nbd_opt_read(NBDClient *client, void *buffer, size_t size,
Error **errp)
{
if (size > client->optlen) {
- return nbd_opt_drop(client, NBD_REP_ERR_INVALID, errp,
- "Inconsistent lengths in option %s",
- nbd_opt_lookup(client->opt));
+ return nbd_opt_invalid(client, errp,
+ "Inconsistent lengths in option %s",
+ nbd_opt_lookup(client->opt));
}
client->optlen -= size;
return qio_channel_read_all(client->ioc, buffer, size, errp) < 0 ? -EIO : 1;
@@ -398,9 +422,8 @@ static int nbd_reject_length(NBDClient *client, bool fatal, Error **errp)
int ret;
assert(client->optlen);
- ret = nbd_opt_drop(client, NBD_REP_ERR_INVALID, errp,
- "option '%s' has unexpected length",
- nbd_opt_lookup(client->opt));
+ ret = nbd_opt_invalid(client, errp, "option '%s' has unexpected length",
+ nbd_opt_lookup(client->opt));
if (fatal && !ret) {
error_setg(errp, "option '%s' has unexpected length",
nbd_opt_lookup(client->opt));
@@ -438,8 +461,7 @@ static int nbd_negotiate_handle_info(NBDClient *client, uint16_t myflags,
}
be32_to_cpus(&namelen);
if (namelen >= sizeof(name)) {
- return nbd_opt_drop(client, NBD_REP_ERR_INVALID, errp,
- "name too long for qemu");
+ return nbd_opt_invalid(client, errp, "name too long for qemu");
}
rc = nbd_opt_read(client, name, namelen, errp);
if (rc <= 0) {
--
2.11.1
next prev parent reply other threads:[~2018-02-15 13:52 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-15 13:51 [Qemu-devel] [PATCH 0/9] nbd block status base:allocation Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` Vladimir Sementsov-Ogievskiy [this message]
2018-02-15 22:01 ` [Qemu-devel] [PATCH 1/9] nbd/server: add nbd_opt_invalid helper Eric Blake
2018-03-02 12:40 ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 2/9] nbd: change indenting in nbd.h Vladimir Sementsov-Ogievskiy
2018-02-15 22:03 ` Eric Blake
2018-02-15 13:51 ` [Qemu-devel] [PATCH 3/9] nbd: BLOCK_STATUS for standard get_block_status function: server part Vladimir Sementsov-Ogievskiy
2018-02-15 23:02 ` Eric Blake
2018-02-16 11:09 ` Vladimir Sementsov-Ogievskiy
2018-02-16 11:45 ` Eric Blake
2018-02-16 13:21 ` Eric Blake
2018-02-16 14:43 ` Vladimir Sementsov-Ogievskiy
2018-02-16 17:01 ` Eric Blake
2018-03-01 11:36 ` Vladimir Sementsov-Ogievskiy
2018-03-02 15:07 ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 4/9] block/nbd-client: save first fatal error in nbd_iter_error Vladimir Sementsov-Ogievskiy
2018-02-16 17:35 ` Eric Blake
2018-02-15 13:51 ` [Qemu-devel] [PATCH 5/9] nbd/client: fix error messages in nbd_handle_reply_err Vladimir Sementsov-Ogievskiy
2018-02-16 17:38 ` Eric Blake
2018-03-01 11:38 ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 6/9] nbd: BLOCK_STATUS for standard get_block_status function: client part Vladimir Sementsov-Ogievskiy
2018-02-16 20:40 ` Eric Blake
2018-03-09 18:47 ` Vladimir Sementsov-Ogievskiy
2018-03-12 9:06 ` Vladimir Sementsov-Ogievskiy
2018-03-12 9:23 ` Vladimir Sementsov-Ogievskiy
2018-03-12 9:48 ` Vladimir Sementsov-Ogievskiy
2018-03-12 13:13 ` Vladimir Sementsov-Ogievskiy
2018-03-12 14:00 ` Eric Blake
2018-02-15 13:51 ` [Qemu-devel] [PATCH 7/9] iotests.py: tiny refactor: move system imports up Vladimir Sementsov-Ogievskiy
2018-02-16 20:44 ` Eric Blake
2018-03-09 18:54 ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 8/9] iotests: add file_path helper Vladimir Sementsov-Ogievskiy
2018-02-16 20:46 ` Eric Blake
2018-02-20 5:42 ` Jeff Cody
2018-03-12 10:04 ` Vladimir Sementsov-Ogievskiy
2018-02-15 13:51 ` [Qemu-devel] [PATCH 9/9] iotests: new test 206 for NBD BLOCK_STATUS Vladimir Sementsov-Ogievskiy
2018-02-16 21:02 ` Eric Blake
2018-03-01 11:51 ` Vladimir Sementsov-Ogievskiy
2018-03-01 18:23 ` Eric Blake
2018-02-22 19:30 ` [Qemu-devel] [PATCH 0/9] nbd block status base:allocation no-reply
2018-02-23 14:02 ` no-reply
2018-02-24 6:48 ` no-reply
2018-02-26 16:57 ` [Qemu-devel] [PATCH v2 0/2] nbd block status initial patches Eric Blake
2018-02-26 16:57 ` [Qemu-devel] [PATCH v2 1/2] nbd: BLOCK_STATUS constants Eric Blake
2018-03-01 12:06 ` Vladimir Sementsov-Ogievskiy
2018-02-26 16:57 ` [Qemu-devel] [PATCH v2 2/2] nbd/client: fix error messages in nbd_handle_reply_err Eric Blake
2018-03-01 12:10 ` Vladimir Sementsov-Ogievskiy
2018-03-01 18:25 ` Eric Blake
2018-03-09 19:08 ` [Qemu-devel] [PATCH 0/9] nbd block status base:allocation Eric Blake
2018-03-09 19:28 ` Vladimir Sementsov-Ogievskiy
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=1518702707-7077-2-git-send-email-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).