mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 19:49:43 +00:00
nbd: fix error handling in the server
bdrv_read and bdrv_write return negative errno values, not -1. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
ecda3447d1
commit
adcf6302de
19
nbd.c
19
nbd.c
@ -595,6 +595,7 @@ int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset,
|
|||||||
{
|
{
|
||||||
struct nbd_request request;
|
struct nbd_request request;
|
||||||
struct nbd_reply reply;
|
struct nbd_reply reply;
|
||||||
|
int ret;
|
||||||
|
|
||||||
TRACE("Reading request.");
|
TRACE("Reading request.");
|
||||||
|
|
||||||
@ -633,12 +634,13 @@ int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset,
|
|||||||
case NBD_CMD_READ:
|
case NBD_CMD_READ:
|
||||||
TRACE("Request type is READ");
|
TRACE("Request type is READ");
|
||||||
|
|
||||||
if (bdrv_read(bs, (request.from + dev_offset) / 512,
|
ret = bdrv_read(bs, (request.from + dev_offset) / 512,
|
||||||
data + NBD_REPLY_SIZE,
|
data + NBD_REPLY_SIZE,
|
||||||
request.len / 512) == -1) {
|
request.len / 512);
|
||||||
|
if (ret < 0) {
|
||||||
LOG("reading from file failed");
|
LOG("reading from file failed");
|
||||||
errno = EINVAL;
|
reply.error = -ret;
|
||||||
return -1;
|
request.len = 0;
|
||||||
}
|
}
|
||||||
*offset += request.len;
|
*offset += request.len;
|
||||||
|
|
||||||
@ -681,11 +683,12 @@ int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset,
|
|||||||
} else {
|
} else {
|
||||||
TRACE("Writing to device");
|
TRACE("Writing to device");
|
||||||
|
|
||||||
if (bdrv_write(bs, (request.from + dev_offset) / 512,
|
ret = bdrv_write(bs, (request.from + dev_offset) / 512,
|
||||||
data, request.len / 512) == -1) {
|
data, request.len / 512);
|
||||||
|
if (ret < 0) {
|
||||||
LOG("writing to file failed");
|
LOG("writing to file failed");
|
||||||
errno = EINVAL;
|
reply.error = -ret;
|
||||||
return -1;
|
request.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*offset += request.len;
|
*offset += request.len;
|
||||||
|
Loading…
Reference in New Issue
Block a user