From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIN9B-0008JN-Eb for qemu-devel@nongnu.org; Mon, 02 Feb 2015 14:59:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIN97-0004K0-LG for qemu-devel@nongnu.org; Mon, 02 Feb 2015 14:59:01 -0500 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:54900 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIN97-0004Jo-Ax for qemu-devel@nongnu.org; Mon, 02 Feb 2015 14:58:57 -0500 Message-ID: <54CFD6FE.3080204@kamp.de> Date: Mon, 02 Feb 2015 20:58:54 +0100 From: Peter Lieven MIME-Version: 1.0 References: <1422901789-21027-1-git-send-email-den@openvz.org> <1422901789-21027-2-git-send-email-den@openvz.org> In-Reply-To: <1422901789-21027-2-git-send-email-den@openvz.org> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/2] glusterfs: 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: > qemu_gluster_co_discard calculates size to discard as follows > size_t size = nb_sectors * BDRV_SECTOR_SIZE; > ret = glfs_discard_async(s->fd, offset, size, &gluster_finish_aiocb, acb); > > glfs_discard_async is declared as follows: > int glfs_discard_async (glfs_fd_t *fd, off_t length, size_t lent, > glfs_io_cbk fn, void *data) __THROW > This is problematic on i686 as sizeof(size_t) == 4. > > Set bl_max_discard to SIZE_MAX >> BDRV_SECTOR_BITS to avoid overflow > on i386. > > Signed-off-by: Denis V. Lunev > CC: Kevin Wolf > CC: Peter Lieven > --- > block/gluster.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/block/gluster.c b/block/gluster.c > index 1eb3a8c..47bf92d 100644 > --- a/block/gluster.c > +++ b/block/gluster.c > @@ -622,6 +622,13 @@ out: > return ret; > } > > +static void qemu_gluster_refresh_limits(BlockDriverState *bs, Error **errp) > +{ > +#if SIZE_MAX == UINT_MAX > + bs->bl.max_discard = SIZE_MAX >> BDRV_SECTOR_BITS; > +#endif I would write: bs->bl.max_discard = MIN(SIZE_MAX >> BDRV_SECTOR_BITS, INT_MAX); without the condition. Peter > +} > + > #ifdef CONFIG_GLUSTERFS_DISCARD > static coroutine_fn int qemu_gluster_co_discard(BlockDriverState *bs, > int64_t sector_num, int nb_sectors) > @@ -735,6 +742,7 @@ static BlockDriver bdrv_gluster = { > #ifdef CONFIG_GLUSTERFS_DISCARD > .bdrv_co_discard = qemu_gluster_co_discard, > #endif > + .bdrv_refresh_limits = qemu_gluster_refresh_limits, > #ifdef CONFIG_GLUSTERFS_ZEROFILL > .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes, > #endif > @@ -762,6 +770,7 @@ static BlockDriver bdrv_gluster_tcp = { > #ifdef CONFIG_GLUSTERFS_DISCARD > .bdrv_co_discard = qemu_gluster_co_discard, > #endif > + .bdrv_refresh_limits = qemu_gluster_refresh_limits, > #ifdef CONFIG_GLUSTERFS_ZEROFILL > .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes, > #endif > @@ -789,6 +798,7 @@ static BlockDriver bdrv_gluster_unix = { > #ifdef CONFIG_GLUSTERFS_DISCARD > .bdrv_co_discard = qemu_gluster_co_discard, > #endif > + .bdrv_refresh_limits = qemu_gluster_refresh_limits, > #ifdef CONFIG_GLUSTERFS_ZEROFILL > .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes, > #endif > @@ -816,6 +826,7 @@ static BlockDriver bdrv_gluster_rdma = { > #ifdef CONFIG_GLUSTERFS_DISCARD > .bdrv_co_discard = qemu_gluster_co_discard, > #endif > + .bdrv_refresh_limits = qemu_gluster_refresh_limits, > #ifdef CONFIG_GLUSTERFS_ZEROFILL > .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes, > #endif