qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@gmail.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v5 2/2] vmdk: Optimize cluster allocation
Date: Tue, 29 Jul 2014 13:51:44 +0100	[thread overview]
Message-ID: <20140729125144.GA25860@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <20140729010043.GA6544@T430.nay.redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2743 bytes --]

On Tue, Jul 29, 2014 at 09:00:43AM +0800, Fam Zheng wrote:
> On Mon, 07/28 16:11, Stefan Hajnoczi wrote:
> > On Tue, May 27, 2014 at 04:49:22PM +0800, Fam Zheng wrote:
> > > +    if (!bs->backing_hd) {
> > > +        memset(whole_grain, 0,  skip_start_sector << BDRV_SECTOR_BITS);
> > > +        memset(whole_grain + (skip_end_sector << BDRV_SECTOR_BITS), 0,
> > > +               cluster_bytes - (skip_end_sector << BDRV_SECTOR_BITS));
> > > +    }
> > > +
> > > +    assert(skip_end_sector <= sector_num + extent->cluster_sectors);
> > 
> > Does this assertion make sense?  skip_end_sector is a small number of
> > sectors (relative to start of cluster), while sector_num +
> > extent->cluster_sectors is a large absolute sector offset.
> 
> skip_end_sector is absolute sector number too. The caller hunk in this patch
> is:

I disagree.  If it was an absolute sector number then the memset() a few
lines above would be incorrect:

  memset(whole_grain, 0,  skip_start_sector << BDRV_SECTOR_BITS);
  memset(whole_grain + (skip_end_sector << BDRV_SECTOR_BITS), 0,
         cluster_bytes - (skip_end_sector << BDRV_SECTOR_BITS));

Look at the code you pasted again:

> @@ -1406,12 +1468,17 @@ static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
>          if (!extent) {
>              return -EIO;
>          }
> -        ret = get_cluster_offset(
> -                                bs,
> -                                extent,
> -                                &m_data,
> -                                sector_num << 9, !extent->compressed,
> -                                &cluster_offset);
> +        extent_begin_sector = extent->end_sector - extent->sectors;
> +        extent_relative_sector_num = sector_num - extent_begin_sector;
> +        index_in_cluster = extent_relative_sector_num % extent->cluster_sectors;
> +        n = extent->cluster_sectors - index_in_cluster;
> +        if (n > nb_sectors) {
> +            n = nb_sectors;
> +        }
> +        ret = get_cluster_offset(bs, extent, &m_data, sector_num << 9,
> +                                 !(extent->compressed || zeroed),
> +                                 &cluster_offset,
> +                                 index_in_cluster, index_in_cluster + n);
>          if (extent->compressed) {
>              if (ret == VMDK_OK) {
>                  /* Refuse write to allocated cluster for streamOptimized */
> 
> See the last parameter of get_cluster_offset.

The last parameter is (extent_relative_sector_num %
extent->cluster_sectors) + (extent->cluster_sectors - index_in_cluster).
Those are definitely sector counts (like nb_sectors) and not absolute
sector numbers (like sector_num).

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2014-07-29 12:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1401180562-29680-1-git-send-email-famz@redhat.com>
     [not found] ` <1401180562-29680-3-git-send-email-famz@redhat.com>
2014-07-28 15:11   ` [Qemu-devel] [PATCH v5 2/2] vmdk: Optimize cluster allocation Stefan Hajnoczi
2014-07-29  1:00     ` Fam Zheng
2014-07-29 12:51       ` Stefan Hajnoczi [this message]
2014-07-29 13:32         ` Fam Zheng

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=20140729125144.GA25860@stefanha-thinkpad.redhat.com \
    --to=stefanha@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.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).