mirror of https://github.com/xemu-project/xemu.git
nbd: Fix nbd_receive_options()
The client flags are sent exactly once overall, not once per option. Signed-off-by: Max Reitz <mreitz@redhat.com> Message-Id: <1424887718-10800-19-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
3f4726596d
commit
9c122adadb
49
nbd.c
49
nbd.c
|
@ -350,30 +350,39 @@ fail:
|
||||||
|
|
||||||
static int nbd_receive_options(NBDClient *client)
|
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) {
|
while (1) {
|
||||||
int csock = client->sock, ret;
|
int ret;
|
||||||
uint32_t tmp, length;
|
uint32_t tmp, length;
|
||||||
uint64_t magic;
|
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)) {
|
if (read_sync(csock, &magic, sizeof(magic)) != sizeof(magic)) {
|
||||||
LOG("read failed");
|
LOG("read failed");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
Loading…
Reference in New Issue