From: Stefan Hajnoczi <stefanha@redhat.com>
To: Liu Yuan <namei.unix@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@gmail.com>,
sheepdog@lists.wpkg.org, qemu-devel@nongnu.org,
MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Subject: Re: [Qemu-devel] [PATCH v2 2/2] sheepdog: implement .bdrv_co_is_allocated()
Date: Mon, 22 Apr 2013 17:03:48 +0200 [thread overview]
Message-ID: <20130422150348.GC28049@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <517528D2.1040409@gmail.com>
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.
next prev parent reply other threads:[~2013-04-22 15:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-22 6:59 [Qemu-devel] [PATCH v2 0/2] implement .bdrv_co_is_allocated Liu Yuan
2013-04-22 6:59 ` [Qemu-devel] [PATCH v2 1/2] sheepdog: use BDRV_SECTOR_SIZE Liu Yuan
2013-04-22 6:59 ` [Qemu-devel] [PATCH v2 2/2] sheepdog: implement .bdrv_co_is_allocated() Liu Yuan
2013-04-22 12:00 ` Stefan Hajnoczi
2013-04-22 12:10 ` Liu Yuan
2013-04-22 15:03 ` Stefan Hajnoczi [this message]
2013-04-22 15:18 ` Liu Yuan
2013-04-22 20:46 ` Stefan Hajnoczi
2013-04-23 5:55 ` Liu Yuan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130422150348.GC28049@stefanha-thinkpad.redhat.com \
--to=stefanha@redhat.com \
--cc=kwolf@redhat.com \
--cc=morita.kazutaka@lab.ntt.co.jp \
--cc=namei.unix@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=sheepdog@lists.wpkg.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).