From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=53331 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PFXAJ-0000bN-43 for qemu-devel@nongnu.org; Mon, 08 Nov 2010 14:14:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PFXAC-0003Ne-1l for qemu-devel@nongnu.org; Mon, 08 Nov 2010 14:13:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47941) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PFXAB-0003Mc-P1 for qemu-devel@nongnu.org; Mon, 08 Nov 2010 14:13:55 -0500 Message-Id: <20101108190918.072277471@redhat.com> Date: Mon, 08 Nov 2010 17:02:54 -0200 From: Marcelo Tosatti References: <20101108190253.560821111@redhat.com> Content-Disposition: inline; filename=01-block-dirty-log-shift Subject: [Qemu-devel] [patch 1/3] block: fix shift in dirty bitmap calculation List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liran Schour , Kevin Wolf Cc: Marcelo Tosatti , Yoshiaki Tamura , qemu-devel@nongnu.org Otherwise upper 32 bits of bitmap entries are not correctly calculated. Signed-off-by: Marcelo Tosatti Index: qemu-kvm/block.c =================================================================== --- qemu-kvm.orig/block.c +++ qemu-kvm/block.c @@ -930,14 +930,14 @@ static void set_dirty_bitmap(BlockDriver bit = start % (sizeof(unsigned long) * 8); val = bs->dirty_bitmap[idx]; if (dirty) { - if (!(val & (1 << bit))) { + if (!(val & (1UL << bit))) { bs->dirty_count++; - val |= 1 << bit; + val |= 1UL << bit; } } else { - if (val & (1 << bit)) { + if (val & (1UL << bit)) { bs->dirty_count--; - val &= ~(1 << bit); + val &= ~(1UL << bit); } } bs->dirty_bitmap[idx] = val; @@ -2672,8 +2672,8 @@ int bdrv_get_dirty(BlockDriverState *bs, if (bs->dirty_bitmap && (sector << BDRV_SECTOR_BITS) < bdrv_getlength(bs)) { - return bs->dirty_bitmap[chunk / (sizeof(unsigned long) * 8)] & - (1 << (chunk % (sizeof(unsigned long) * 8))); + return !!(bs->dirty_bitmap[chunk / (sizeof(unsigned long) * 8)] & + (1UL << (chunk % (sizeof(unsigned long) * 8)))); } else { return 0; }