[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 10/17] nbd/server: add nbd_opt_invalid helper
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PULL 10/17] nbd/server: add nbd_opt_invalid helper |
Date: |
Tue, 13 Mar 2018 12:13:38 -0500 |
From: Vladimir Sementsov-Ogievskiy <address@hidden>
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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
---
nbd/server.c | 50 ++++++++++++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 14 deletions(-)
diff --git a/nbd/server.c b/nbd/server.c
index 4776009a2d1..01ea97afe98 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.14.3
- [Qemu-devel] [PULL 02/17] nbd/server: move nbd_co_send_structured_error up, (continued)
- [Qemu-devel] [PULL 02/17] nbd/server: move nbd_co_send_structured_error up, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 01/17] iotests: Fix stuck NBD process on 33, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 13/17] block/nbd-client: save first fatal error in nbd_iter_error, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 07/17] nbd/server: Honor FUA request on NBD_CMD_TRIM, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 14/17] nbd: BLOCK_STATUS for standard get_block_status function: client part, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 03/17] nbd/server: fix sparse read, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 06/17] nbd/server: refactor nbd_trip: split out nbd_handle_request, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 05/17] nbd/server: refactor nbd_trip: cmd_read and generic reply, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 11/17] nbd/server: add nbd_read_opt_name helper, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 12/17] nbd: BLOCK_STATUS for standard get_block_status function: server part, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 10/17] nbd/server: add nbd_opt_invalid helper,
Eric Blake <=
- [Qemu-devel] [PULL 17/17] iotests: new test 209 for NBD BLOCK_STATUS, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 09/17] iotests: add 208 nbd-server + blockdev-snapshot-sync test case, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 16/17] iotests: add file_path helper, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 15/17] iotests.py: tiny refactor: move system imports up, Eric Blake, 2018/03/13
- Re: [Qemu-devel] [PULL 00/17] NBD patches for 2018-03-13 (2.12 softfreeze), no-reply, 2018/03/13
- Re: [Qemu-devel] [PULL 00/17] NBD patches for 2018-03-13 (2.12 softfreeze), no-reply, 2018/03/13