[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 18/25] nbd: Fix nbd_receive_options()
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH 18/25] nbd: Fix nbd_receive_options() |
Date: |
Wed, 25 Feb 2015 13:08:31 -0500 |
The client flags are sent exactly once overall, not once per option.
Signed-off-by: Max Reitz <address@hidden>
---
nbd.c | 49 +++++++++++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 20 deletions(-)
diff --git a/nbd.c b/nbd.c
index a05fd02..d94cd88 100644
--- a/nbd.c
+++ b/nbd.c
@@ -357,30 +357,39 @@ fail:
static int nbd_receive_options(NBDClient *client)
{
+ int csock = client->sock;
+ uint32_t flags;
+
+ /* Client sends:
+ [ 0 .. 3] client flags
+
+ [ 0 .. 7] NBD_OPTS_MAGIC
+ [ 8 .. 11] NBD option
+ [12 .. 15] Data length
+ ... Rest of request
+
+ [ 0 .. 7] NBD_OPTS_MAGIC
+ [ 8 .. 11] Second NBD option
+ [12 .. 15] Data length
+ ... Rest of request
+ */
+
+ if (read_sync(csock, &flags, sizeof(flags)) != sizeof(flags)) {
+ LOG("read failed");
+ return -EIO;
+ }
+ TRACE("Checking client flags");
+ be32_to_cpus(&flags);
+ if (flags != 0 && flags != NBD_FLAG_C_FIXED_NEWSTYLE) {
+ LOG("Bad client flags received");
+ return -EIO;
+ }
+
while (1) {
- int csock = client->sock, ret;
+ int ret;
uint32_t tmp, length;
uint64_t magic;
- /* Client sends:
- [ 0 .. 3] client flags
- [ 4 .. 11] NBD_OPTS_MAGIC
- [12 .. 15] NBD option
- [16 .. 19] length
- ... Rest of request
- */
-
- if (read_sync(csock, &tmp, sizeof(tmp)) != sizeof(tmp)) {
- LOG("read failed");
- return -EINVAL;
- }
- TRACE("Checking client flags");
- tmp = be32_to_cpu(tmp);
- if (tmp != 0 && tmp != NBD_FLAG_C_FIXED_NEWSTYLE) {
- LOG("Bad client flags received");
- return -EINVAL;
- }
-
if (read_sync(csock, &magic, sizeof(magic)) != sizeof(magic)) {
LOG("read failed");
return -EIO;
--
2.1.0
- [Qemu-devel] [PATCH 12/25] nbd: Set block size to BDRV_SECTOR_SIZE, (continued)
- [Qemu-devel] [PATCH 12/25] nbd: Set block size to BDRV_SECTOR_SIZE, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 13/25] nbd: Enforce sector alignment, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 21/25] nbd: Drop unexpected data for NBD_OPT_LIST, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 11/25] qemu-nbd: Fix and improve input verification, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 16/25] coroutine-io: Add I/O functions with timeout, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 23/25] iotests: Add test for invalid qemu-nbd parameters, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 25/25] iotests: Add test for a non-existing NBD export, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 19/25] nbd: Fix interpretation of the export flags, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 20/25] block/nbd: Comment on discard/flush silently failing, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 22/25] iotests: Add _timeout function, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 18/25] nbd: Fix nbd_receive_options(),
Max Reitz <=
- [Qemu-devel] [PATCH 17/25] nbd: Employ timeouts, Max Reitz, 2015/02/25
- Re: [Qemu-devel] [PATCH 00/25] nbd: Several fixes, Max Reitz, 2015/02/25
- [Qemu-devel] [PATCH 24/25] iotests: Add test for issuing discard over NBD, Max Reitz, 2015/02/25