From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu2I9-0004O5-9k for qemu-devel@nongnu.org; Fri, 20 Dec 2013 10:47:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vu2I4-0000Ov-4U for qemu-devel@nongnu.org; Fri, 20 Dec 2013 10:47:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56550) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vu2I3-0000O5-SM for qemu-devel@nongnu.org; Fri, 20 Dec 2013 10:47:04 -0500 From: Stefan Hajnoczi Date: Fri, 20 Dec 2013 16:46:39 +0100 Message-Id: <1387554416-5837-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1387554416-5837-1-git-send-email-stefanha@redhat.com> References: <1387554416-5837-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 01/18] sheepdog: fix dynamic grow for running qcow2 format List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori From: Liu Yuan When running qcow2 over sheepdog, we might meet following problem qemu-system-x86_64: shrinking is not supported And cause IO errors to Guest. This is because we abuse bs->total_sectors, which is manipulated by generic block layer and race with sheepdog code. We should directly check if offset > vdi_size to dynamically enlarge the volume instead of 'offset > bs->total_sectors', which will cause problem when following case happens: vdi_size > offset > bs->total_sectors # then trigger sd_truncate() to shrink the volume wrongly. Cc: qemu-devel@nongnu.org Cc: Kevin Wolf Cc: Stefan Hajnoczi Reported-by: Hadrien KOHL Signed-off-by: Liu Yuan Signed-off-by: Stefan Hajnoczi --- block/sheepdog.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index d1c812d..ba451a9 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2048,13 +2048,14 @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, { SheepdogAIOCB *acb; int ret; + int64_t offset = (sector_num + nb_sectors) * BDRV_SECTOR_SIZE; + BDRVSheepdogState *s = bs->opaque; - if (bs->growable && sector_num + nb_sectors > bs->total_sectors) { - ret = sd_truncate(bs, (sector_num + nb_sectors) * BDRV_SECTOR_SIZE); + if (bs->growable && offset > s->inode.vdi_size) { + ret = sd_truncate(bs, offset); if (ret < 0) { return ret; } - bs->total_sectors = sector_num + nb_sectors; } acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); -- 1.8.4.2