[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 40/42] nbd: fix max_discard/max_transfer_length
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 40/42] nbd: fix max_discard/max_transfer_length |
Date: |
Fri, 6 Feb 2015 17:40:47 +0100 |
From: "Denis V. Lunev" <address@hidden>
nbd_co_discard calls nbd_client_session_co_discard which uses uint32_t
as the length in bytes of the data to discard due to the following
definition:
struct nbd_request {
uint32_t magic;
uint32_t type;
uint64_t handle;
uint64_t from;
uint32_t len; <-- the length of data to be discarded, in bytes
} QEMU_PACKED;
Thus we should limit bl_max_discard to UINT32_MAX >> BDRV_SECTOR_BITS to
avoid overflow.
NBD read/write code uses the same structure for transfers. Fix
max_transfer_length accordingly.
Signed-off-by: Denis V. Lunev <address@hidden>
CC: Peter Lieven <address@hidden>
CC: Kevin Wolf <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/nbd.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/block/nbd.c b/block/nbd.c
index 2e20831..b05d1d0 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -301,6 +301,12 @@ static int nbd_co_flush(BlockDriverState *bs)
return nbd_client_session_co_flush(&s->client);
}
+static void nbd_refresh_limits(BlockDriverState *bs, Error **errp)
+{
+ bs->bl.max_discard = UINT32_MAX >> BDRV_SECTOR_BITS;
+ bs->bl.max_transfer_length = UINT32_MAX >> BDRV_SECTOR_BITS;
+}
+
static int nbd_co_discard(BlockDriverState *bs, int64_t sector_num,
int nb_sectors)
{
@@ -396,6 +402,7 @@ static BlockDriver bdrv_nbd = {
.bdrv_close = nbd_close,
.bdrv_co_flush_to_os = nbd_co_flush,
.bdrv_co_discard = nbd_co_discard,
+ .bdrv_refresh_limits = nbd_refresh_limits,
.bdrv_getlength = nbd_getlength,
.bdrv_detach_aio_context = nbd_detach_aio_context,
.bdrv_attach_aio_context = nbd_attach_aio_context,
@@ -413,6 +420,7 @@ static BlockDriver bdrv_nbd_tcp = {
.bdrv_close = nbd_close,
.bdrv_co_flush_to_os = nbd_co_flush,
.bdrv_co_discard = nbd_co_discard,
+ .bdrv_refresh_limits = nbd_refresh_limits,
.bdrv_getlength = nbd_getlength,
.bdrv_detach_aio_context = nbd_detach_aio_context,
.bdrv_attach_aio_context = nbd_attach_aio_context,
@@ -430,6 +438,7 @@ static BlockDriver bdrv_nbd_unix = {
.bdrv_close = nbd_close,
.bdrv_co_flush_to_os = nbd_co_flush,
.bdrv_co_discard = nbd_co_discard,
+ .bdrv_refresh_limits = nbd_refresh_limits,
.bdrv_getlength = nbd_getlength,
.bdrv_detach_aio_context = nbd_detach_aio_context,
.bdrv_attach_aio_context = nbd_attach_aio_context,
--
1.8.3.1
- [Qemu-devel] [PULL 23/42] block/dmg: process a buffer instead of reading ints, (continued)
- [Qemu-devel] [PULL 23/42] block/dmg: process a buffer instead of reading ints, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 27/42] block/dmg: fix sector data offset calculation, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 28/42] block/dmg: use SectorNumber from BLKX header, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 31/42] block/dmg: improve zeroes handling, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 32/42] qed: check for header size overflow, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 34/42] block: fix off-by-one error in qcow and qcow2, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 37/42] iotests: Fix 104 for NBD, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 30/42] block/dmg: support bzip2 block entry types, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 33/42] qemu-iotests: add 116 invalid QED input file tests, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 38/42] nbd: Improve error messages, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 40/42] nbd: fix max_discard/max_transfer_length,
Kevin Wolf <=
- [Qemu-devel] [PULL 35/42] iotests: Fix 083, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 36/42] iotests: Fix 100 for nbd, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 39/42] block: introduce BDRV_REQUEST_MAX_SECTORS, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 41/42] block: Give always priority to unused entries in the qcow2 L2 cache, Kevin Wolf, 2015/02/06
- [Qemu-devel] [PULL 42/42] qcow2: Rewrite qcow2_alloc_bytes(), Kevin Wolf, 2015/02/06