[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [PATCH v2 2/8] nbd/server: add nbd_read_opt_name helper
From: |
Eric Blake |
Subject: |
Re: [Qemu-block] [PATCH v2 2/8] nbd/server: add nbd_read_opt_name helper |
Date: |
Mon, 12 Mar 2018 21:31:15 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 03/12/2018 10:21 AM, Vladimir Sementsov-Ogievskiy wrote:
Add helper to read name in format:
uint32 len (<= NBD_MAX_NAME_SIZE)
len bytes string (not 0-terminated)
The helper would be reused in following patch.
s/would/will/
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
v2: splitted and changed a lot helper from larger patch of v1
'split' (one of those weird English words whose past and present tense
are spelled the same way; there is no 'splitted')
nbd/server.c | 55 ++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 42 insertions(+), 13 deletions(-)
diff --git a/nbd/server.c b/nbd/server.c
index d163964cf9..085e14afbf 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -273,6 +273,47 @@ static int nbd_opt_read(NBDClient *client, void *buffer,
size_t size,
return qio_channel_read_all(client->ioc, buffer, size, errp) < 0 ? -EIO :
1;
}
+/* nbd_opt_read_name
+ *
+ * Read string in format:
Read a string in the format:
+ * uint32_t len (<= NBD_MAX_NAME_SIZE)
+ * len bytes string (not 0-terminated)
+ *
+ * @name should be enough to store NBD_MAX_NAME_SIZE+1.
+ * if @length is non-zero, it would be set to read string length.
s/if/If/
s/would/will/
s/read/the actual/
+ *
+ * Return -errno on I/O error, 0 if option was completely handled by
+ * sending a reply about inconsistent lengths, or 1 on success. */
+static int nbd_opt_read_name(NBDClient *client, char *name, uint32_t *length,
+ Error **errp)
+{
Function looks good.
@@ -455,19 +496,7 @@ static int nbd_negotiate_handle_info(NBDClient *client,
uint16_t myflags,
2 bytes: N, number of requests (can be 0)
N * 2 bytes: N requests
*/
- rc = nbd_opt_read(client, &namelen, sizeof(namelen), errp);
- if (rc <= 0) {
- return rc;
- }
- be32_to_cpus(&namelen);
- if (namelen >= sizeof(name)) {
- return nbd_opt_invalid(client, errp, "name too long for qemu");
- }
- rc = nbd_opt_read(client, name, namelen, errp);
- if (rc <= 0) {
- return rc;
- }
- name[namelen] = '\0';
+ rc = nbd_opt_read_name(client, name, &namelen, errp);
trace_nbd_negotiate_handle_export_name_request(name);
rc = nbd_opt_read(client, &requests, sizeof(requests), errp);
Oh, so close. You overwrote rc instead of checking for errors. I'm
squashing in the obvious fix, plus the grammar changes, then adding:
Reviewed-by: Eric Blake <address@hidden>
diff --git i/nbd/server.c w/nbd/server.c
index 850c6cd2dad..e28526600c4 100644
--- i/nbd/server.c
+++ w/nbd/server.c
@@ -497,6 +497,9 @@ static int nbd_negotiate_handle_info(NBDClient
*client, uint16_t myflags,
N * 2 bytes: N requests
*/
rc = nbd_opt_read_name(client, name, &namelen, errp);
+ if (rc <= 0) {
+ return rc;
+ }
trace_nbd_negotiate_handle_export_name_request(name);
rc = nbd_opt_read(client, &requests, sizeof(requests), errp);
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
- [Qemu-block] [PATCH v2 0/8] nbd block status base:allocation, Vladimir Sementsov-Ogievskiy, 2018/03/12
- [Qemu-block] [PATCH v2 7/8] iotests: add file_path helper, Vladimir Sementsov-Ogievskiy, 2018/03/12
- [Qemu-block] [PATCH v2 4/8] block/nbd-client: save first fatal error in nbd_iter_error, Vladimir Sementsov-Ogievskiy, 2018/03/12
- [Qemu-block] [PATCH v2 2/8] nbd/server: add nbd_read_opt_name helper, Vladimir Sementsov-Ogievskiy, 2018/03/12
- Re: [Qemu-block] [PATCH v2 2/8] nbd/server: add nbd_read_opt_name helper,
Eric Blake <=
- [Qemu-block] [PATCH v2 8/8] iotests: new test 209 for NBD BLOCK_STATUS, Vladimir Sementsov-Ogievskiy, 2018/03/12
- [Qemu-block] [PATCH v2 5/8] nbd: BLOCK_STATUS for standard get_block_status function: client part, Vladimir Sementsov-Ogievskiy, 2018/03/12
- [Qemu-block] [PATCH v2 6/8] iotests.py: tiny refactor: move system imports up, Vladimir Sementsov-Ogievskiy, 2018/03/12
- [Qemu-block] [PATCH v2 1/8] nbd/server: add nbd_opt_invalid helper, Vladimir Sementsov-Ogievskiy, 2018/03/12
- [Qemu-block] [PATCH v2 3/8] nbd: BLOCK_STATUS for standard get_block_status function: server part, Vladimir Sementsov-Ogievskiy, 2018/03/12