From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIN69-0006h6-5K for qemu-devel@nongnu.org; Mon, 02 Feb 2015 14:55:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIN65-0003NF-V2 for qemu-devel@nongnu.org; Mon, 02 Feb 2015 14:55:53 -0500 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:59542 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIN65-0003La-KU for qemu-devel@nongnu.org; Mon, 02 Feb 2015 14:55:49 -0500 Message-ID: <54CFD63F.8010908@kamp.de> Date: Mon, 02 Feb 2015 20:55:43 +0100 From: Peter Lieven MIME-Version: 1.0 References: <1422901789-21027-1-git-send-email-den@openvz.org> <1422901789-21027-3-git-send-email-den@openvz.org> In-Reply-To: <1422901789-21027-3-git-send-email-den@openvz.org> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] nbd: fix max_discard List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Denis V. Lunev" Cc: Kevin Wolf , qemu-devel@nongnu.org Am 02.02.2015 um 19:29 schrieb Denis V. Lunev: > 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. > > Signed-off-by: Denis V. Lunev > CC: Kevin Wolf > CC: Peter Lieven > --- > block/nbd.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/block/nbd.c b/block/nbd.c > index 04cc845..99af713 100644 > --- a/block/nbd.c > +++ b/block/nbd.c > @@ -301,6 +301,11 @@ 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; > +} > + > static int nbd_co_discard(BlockDriverState *bs, int64_t sector_num, > int nb_sectors) > { > @@ -396,6 +401,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 +419,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 +437,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, Reviewed-by: Peter Lieven