mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
nbd/server: Favor [u]int64_t over off_t
Although our compile-time environment is set up so that we always support long files with 64-bit off_t, we have no guarantee whether off_t is the same type as int64_t. This requires casts when printing values, and prevents us from directly using qemu_strtoi64() (which will be done in the next patch). Let's just flip to uint64_t where possible, and stick to int64_t for detecting failure of blk_getlength(); we also keep the assertions added in the previous patch that the resulting values fit in 63 bits. The overflow check in nbd_co_receive_request() was already sane (request->from is validated to fit in 63 bits, and request->len is 32 bits, so the addition can't overflow 64 bits), but rewrite it in a form easier to recognize as a typical overflow check. Rename the variable 'description' to keep line lengths reasonable. Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <20190117193658.16413-7-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
This commit is contained in:
parent
7596bbb390
commit
9d26dfcbab
3 changed files with 22 additions and 29 deletions
18
nbd/server.c
18
nbd/server.c
|
@ -77,8 +77,8 @@ struct NBDExport {
|
|||
BlockBackend *blk;
|
||||
char *name;
|
||||
char *description;
|
||||
off_t dev_offset;
|
||||
off_t size;
|
||||
uint64_t dev_offset;
|
||||
uint64_t size;
|
||||
uint16_t nbdflags;
|
||||
QTAILQ_HEAD(, NBDClient) clients;
|
||||
QTAILQ_ENTRY(NBDExport) next;
|
||||
|
@ -1455,8 +1455,8 @@ static void nbd_eject_notifier(Notifier *n, void *data)
|
|||
nbd_export_close(exp);
|
||||
}
|
||||
|
||||
NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
|
||||
const char *name, const char *description,
|
||||
NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
|
||||
uint64_t size, const char *name, const char *desc,
|
||||
const char *bitmap, uint16_t nbdflags,
|
||||
void (*close)(NBDExport *), bool writethrough,
|
||||
BlockBackend *on_eject_blk, Error **errp)
|
||||
|
@ -1495,12 +1495,12 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
|
|||
exp->refcount = 1;
|
||||
QTAILQ_INIT(&exp->clients);
|
||||
exp->blk = blk;
|
||||
assert(dev_offset >= 0 && dev_offset <= INT64_MAX);
|
||||
assert(dev_offset <= INT64_MAX);
|
||||
exp->dev_offset = dev_offset;
|
||||
exp->name = g_strdup(name);
|
||||
exp->description = g_strdup(description);
|
||||
exp->description = g_strdup(desc);
|
||||
exp->nbdflags = nbdflags;
|
||||
assert(size >= 0 && size <= INT64_MAX - dev_offset);
|
||||
assert(size <= INT64_MAX - dev_offset);
|
||||
exp->size = QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE);
|
||||
|
||||
if (bitmap) {
|
||||
|
@ -2130,10 +2130,10 @@ static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request,
|
|||
return -EROFS;
|
||||
}
|
||||
if (request->from > client->exp->size ||
|
||||
request->from + request->len > client->exp->size) {
|
||||
request->len > client->exp->size - request->from) {
|
||||
error_setg(errp, "operation past EOF; From: %" PRIu64 ", Len: %" PRIu32
|
||||
", Size: %" PRIu64, request->from, request->len,
|
||||
(uint64_t)client->exp->size);
|
||||
client->exp->size);
|
||||
return (request->type == NBD_CMD_WRITE ||
|
||||
request->type == NBD_CMD_WRITE_ZEROES) ? -ENOSPC : -EINVAL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue