From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUIHz-00070G-L4 for qemu-devel@nongnu.org; Mon, 22 Apr 2013 11:04:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUIHt-0000kT-3E for qemu-devel@nongnu.org; Mon, 22 Apr 2013 11:04:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21262) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUIHs-0000kA-NZ for qemu-devel@nongnu.org; Mon, 22 Apr 2013 11:04:12 -0400 Date: Mon, 22 Apr 2013 17:03:48 +0200 From: Stefan Hajnoczi Message-ID: <20130422150348.GC28049@stefanha-thinkpad.redhat.com> References: <1366613950-10918-1-git-send-email-namei.unix@gmail.com> <1366613950-10918-3-git-send-email-namei.unix@gmail.com> <20130422120007.GB21317@stefanha-thinkpad.redhat.com> <517528D2.1040409@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <517528D2.1040409@gmail.com> Subject: Re: [Qemu-devel] [PATCH v2 2/2] sheepdog: implement .bdrv_co_is_allocated() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Yuan Cc: Kevin Wolf , Stefan Hajnoczi , sheepdog@lists.wpkg.org, qemu-devel@nongnu.org, MORITA Kazutaka On Mon, Apr 22, 2013 at 08:10:58PM +0800, Liu Yuan wrote: > On 04/22/2013 08:00 PM, Stefan Hajnoczi wrote: > > On Mon, Apr 22, 2013 at 02:59:10PM +0800, Liu Yuan wrote: > >> +static coroutine_fn int > >> +sd_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, > >> + int *pnum) > >> +{ > >> + BDRVSheepdogState *s = bs->opaque; > >> + SheepdogInode *inode = &s->inode; > >> + unsigned long start = sector_num * BDRV_SECTOR_SIZE / SD_DATA_OBJ_SIZE, idx, > >> + end = DIV_ROUND_UP((sector_num + nb_sectors) * > >> + BDRV_SECTOR_SIZE, SD_DATA_OBJ_SIZE); > > > > Please put the variable declarations on separate lines, it's very easy > > to miss "idx". > > Okay. > > > > >> + int ret = 1; > >> + > >> + for (idx = start; idx <= end; idx++) { > > > > Should this be idx < end? Otherwise you are checking one beyond the > > last SD_DATA_OBJ_SIZE. > > No. the end is index of last object, not index of last object + 1. Imagine sector_num = 0 and nb_sectors = SD_DATA_OBJ_SIZE / BDRV_SECTOR_SIZE. start = 0 end = 1 You don't want object 1, only object 0.