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

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:

@@ -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.

> 
> > +/**
> > + * get_cluster_offset
> > + *
> > + * Look up cluster offset in extent file by sector number, and store in
> > + * @cluster_offset.
> > + *
> > + * For flat extent, the start offset as parsed from the description file is
> 
> s/extent/extents/
> 
> > + * returned.
> > + *
> > + * For sparse extent, look up in L1, L2 table. If allocate is true, return an
> 
> s/extent/extents/
> 
> > + * offset for a new cluster and update L2 cache. If there is a backing file,
> > + * COW is done before returning; otherwise, zeroes are written to the allocated
> > + * cluster. Both COW and zero writting skips the sector range
> 
> s/writting/writing/

Thanks,
Fam

  reply	other threads:[~2014-07-29  1:00 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 [this message]
2014-07-29 12:51       ` Stefan Hajnoczi
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=20140729010043.GA6544@T430.nay.redhat.com \
    --to=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=stefanha@redhat.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).