From: Sean Bartell <wingedtachikoma@gmail.com>
To: "Yan, Zheng " <yanzheng@21cn.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/4] btrfs-convert: Add extent iteration functions.
Date: Tue, 18 May 2010 11:37:23 -0400 [thread overview]
Message-ID: <20100518153723.GA4380@flcl.lan> (raw)
In-Reply-To: <AANLkTil0BsmO29G5Q-gkwXogwJPuL9fbL_kztOv9Us4O@mail.gmail.com>
On Tue, May 18, 2010 at 09:06:54PM +0800, Yan, Zheng wrote:
> On Sat, Mar 20, 2010 at 12:26 PM, Sean Bartell
> <wingedtachikoma@gmail.com> wrote:
> > +int add_file_disk_extent(struct extent_iterate_data *priv, u64 fil=
e_off,
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0u64 disk_off, u64 =
size)
> > +{
> > + =A0 =A0 =A0 BUG_ON(file_off < priv->last_file_off);
> > + =A0 =A0 =A0 int ret;
> > + =A0 =A0 =A0 u64 sectorsize =3D priv->root->sectorsize;
> > + =A0 =A0 =A0 u64 mask =3D sectorsize - 1;
> > + =A0 =A0 =A0 if (size =3D=3D 0)
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
> > + =A0 =A0 =A0 if ((file_off & mask) !=3D (disk_off & mask)) {
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* It's unclear how to CoW this, so d=
on't. */
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 char *data =3D malloc(size);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!data)
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOMEM;
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D read_disk_extent(priv->root, =
disk_off, size, data);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ret) {
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 free(data);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ret;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D add_file_mem_extent(priv, fil=
e_off, size, data);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 free(data);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ret;
> > + =A0 =A0 =A0 }
> > + =A0 =A0 =A0 if (priv->type =3D=3D EXTENT_ITERATE_TYPE_DISK
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && priv->file_off + p=
riv->size =3D=3D file_off
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && priv->disk_off + p=
riv->size =3D=3D disk_off) {
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* It's a continuation of the same di=
sk extent. */
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->size +=3D size;
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
> > + =A0 =A0 =A0 }
> > + =A0 =A0 =A0 if (disk_off =3D=3D 0 || disk_off & mask) {
>=20
> why "disk_off =3D=3D 0" is needed here?
To btrfs, a disk offset of 0 represents a sparse extent. If the origina=
l
filesystem passes in an extent at 0, this chops off the first block to
prevent it from being mistakenly interpreted as a sparse extent.
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* We need to have an aligned start, =
so give the first part to
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* add_file_mem_extent if necessary=
=2E */
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 u64 mem_size =3D min_t(u64, sectorsiz=
e - (disk_off & mask), size);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 char *data =3D malloc(mem_size);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!data)
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOMEM;
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D read_disk_extent(priv->root, =
disk_off, mem_size, data);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ret) {
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 free(data);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ret;
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D add_file_mem_extent(priv, fil=
e_off, mem_size, data);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 free(data);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ret)
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ret;
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 file_off +=3D mem_size;
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 disk_off +=3D mem_size;
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 size -=3D mem_size;
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (size =3D=3D 0)
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
> > + =A0 =A0 =A0 }
> > + =A0 =A0 =A0 ret =3D commit_file_extents(priv);
> > + =A0 =A0 =A0 if (ret)
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ret;
> > + =A0 =A0 =A0 priv->type =3D EXTENT_ITERATE_TYPE_DISK;
> > + =A0 =A0 =A0 priv->size =3D size;
> > + =A0 =A0 =A0 priv->file_off =3D file_off;
> > + =A0 =A0 =A0 priv->disk_off =3D disk_off;
> > + =A0 =A0 =A0 return 0;
> > +}
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" =
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2010-05-18 15:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-20 4:26 [PATCH 2/4] btrfs-convert: Add extent iteration functions Sean Bartell
2010-03-22 4:55 ` Sean Bartell
2010-05-18 13:06 ` Yan, Zheng
2010-05-18 15:37 ` Sean Bartell [this message]
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=20100518153723.GA4380@flcl.lan \
--to=wingedtachikoma@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=yanzheng@21cn.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.