Linux-EROFS Archive on lore.kernel.org
 help / color / Atom feed
From: Pratik Shinde <pratikshinde320@gmail.com>
To: Gao Xiang <gaoxiang25@huawei.com>
Cc: linux-erofs@lists.ozlabs.org, miaoxie@huawei.com
Subject: Re: [RFC] erofs-utils: on-disk extent format for blocks.
Date: Mon, 30 Dec 2019 12:34:30 +0530
Message-ID: <CAGu0czS5gEU5Y9UT_fdXuxKNHcHPXJeE7dC+Fh1UMfSa_Q9+1w@mail.gmail.com> (raw)
In-Reply-To: <20191230064911.GA169899@architecture4>

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

Thanks got it.

Then we can use LOG_BLOCK_SIZE , to get block no. for corresponding file
offset.

--Pratik.

On Mon, Dec 30, 2019 at 12:19 PM Gao Xiang <gaoxiang25@huawei.com> wrote:

> On Mon, Dec 30, 2019 at 11:49:55AM +0530, Pratik Shinde wrote:
> > Gao,
> >
> > Okay, I will rename the 'size' variables accordingly.
> > The 'S_SHIFT' gives the logical block number inside file. I am using it
> to
> > assign logical block no.
> > to extents.
>
> S_SHIFT is used to transfer between i_mode and filetype, see:
> https://elixir.bootlin.com/linux/latest/source/fs/ext4/ext4.h#L3196
>
> IMO, which is not the above meaning, how about using EROFS_BLKSIZ
> instead?
>
> Thanks,
> Gao Xiang
>
> > Also, I will modify the code to record only data extents.
> >
> > --Pratik.
> >
> > On Sun, Dec 29, 2019 at 8:26 AM Gao Xiang <hsiangkao@aol.com> wrote:
> >
> > > Hi Pratik,
> > >
> > > On Fri, Dec 27, 2019 at 09:13:48PM +0530, Pratik Shinde wrote:
> > > > since this patch is quite different from previous patches I am
> treating
> > > > this as new patch.
> > > >
> > > > 1) On disk extent format for erofs data blocks.
> > > > 2) Detect holes inside files & skip allocation for hole blocks.
> > > >
> > > > Signed-off-by: Pratik Shinde <pratikshinde320@gmail.com>
> > > > ---
> > > >  include/erofs/internal.h |  21 ++++++-
> > > >  lib/inode.c              | 155
> > > +++++++++++++++++++++++++++++++++++++++++------
> > > >  2 files changed, 156 insertions(+), 20 deletions(-)
> > > >
> > > > diff --git a/include/erofs/internal.h b/include/erofs/internal.h
> > > > index e13adda..128aa63 100644
> > > > --- a/include/erofs/internal.h
> > > > +++ b/include/erofs/internal.h
> > > > @@ -63,7 +63,7 @@ struct erofs_sb_info {
> > > >  extern struct erofs_sb_info sbi;
> > > >
> > > >  struct erofs_inode {
> > > > -     struct list_head i_hash, i_subdirs, i_xattrs;
> > > > +     struct list_head i_hash, i_subdirs, i_xattrs, i_extents;
> > > >
> > > >       unsigned int i_count;
> > > >       struct erofs_inode *i_parent;
> > > > @@ -93,6 +93,7 @@ struct erofs_inode {
> > > >
> > > >       unsigned int xattr_isize;
> > > >       unsigned int extent_isize;
> > > > +     unsigned int extent_meta_isize;
> > >
> > > maybe sparse_extent_isize is better...
> > >
> > > p.s. maybe we could send another patch rename extent_isize to
> > > compress_extent_isize or some better name...
> > >
> > > >
> > > >       erofs_nid_t nid;
> > > >       struct erofs_buffer_head *bh;
> > > > @@ -139,5 +140,23 @@ static inline const char *erofs_strerror(int
> err)
> > > >       return msg;
> > > >  }
> > > >
> > > > +#define HOLE_BLK     -1
> > > > +/* on disk extent format */
> > > > +struct erofs_extent {
> > > > +     __le32 ee_lblk;
> > > > +     __le32 ee_pblk;
> > > > +     __le32 ee_len;
> > > > +};
> > > > +
> > > > +struct erofs_extent_node {
> > > > +     struct list_head next;
> > > > +     erofs_blk_t lblk;
> > > > +     erofs_blk_t pblk;
> > > > +     u32 len;
> > > > +};
> > > > +
> > > > +struct erofs_inline_extent_header {
> > > > +     u32 count;
> > > > +};
> > > >  #endif
> > > >
> > > > diff --git a/lib/inode.c b/lib/inode.c
> > > > index 0e19b11..a6af509 100644
> > > > --- a/lib/inode.c
> > > > +++ b/lib/inode.c
> > > > @@ -38,6 +38,99 @@ static unsigned char erofs_type_by_mode[S_IFMT >>
> > > S_SHIFT] = {
> > > >
> > > >  struct list_head inode_hashtable[NR_INODE_HASHTABLE];
> > > >
> > > > +
> > > > +#define IS_HOLE(start, end) (roundup(start, EROFS_BLKSIZ) == start
> &&
> > >       \
> > > > +                          roundup(end, EROFS_BLKSIZ) == end &&
>  \
> > > > +                         (end - start) % EROFS_BLKSIZ == 0)
> > >
> > > See below..
> > >
> > > > +
> > > > +/* returns the number of holes present in the file */
> > > > +unsigned int erofs_read_extents(struct erofs_inode *inode,
> > > > +                             struct list_head *extents)
> > > > +{
> > > > +     int fd, st, en, dt;
> > > > +     unsigned int nholes = 0;
> > > > +     erofs_off_t data, hole, len, last_data;
> > > > +     struct erofs_extent_node *e_hole, *e_data;
> > > > +
> > > > +     fd = open(inode->i_srcpath, O_RDONLY);
> > > > +     if (fd < 0) {
> > > > +             return -errno;
> > > > +     }
> > > > +     len = lseek(fd, 0, SEEK_END);
> > > > +     if (lseek(fd, 0, SEEK_SET) == -1)
> > > > +             return -errno;
> > > > +     data = 0;
> > > > +     last_data = 0;
> > > > +     while (data < len) {
> > > > +             hole = lseek(fd, data, SEEK_HOLE);
> > > > +             if (hole == len)
> > > > +                     break;
> > > > +             data = lseek(fd, hole, SEEK_DATA);
> > > > +             if (data < 0 || hole > data) {
> > > > +                     return -EINVAL;
> > > > +             }
> > > > +             if (IS_HOLE(hole, data)) {
> > > > +                     st = hole >> S_SHIFT;
> > > > +                     en = data >> S_SHIFT;
> > > > +                     dt = last_data >> S_SHIFT;
> > >
> > > Why using S_SHIFT here, some special meaning?
> > >
> > > > +                     last_data = data;
> > > > +                     e_data = malloc(sizeof(struct
> erofs_extent_node));
> > > > +                     if (e_data == NULL)
> > > > +                             return -ENOMEM;
> > > > +                     e_data->lblk = dt;
> > > > +                     e_data->len = (st - dt);
> > > > +                     list_add_tail(&e_data->next, extents);
> > > > +                     e_hole = malloc(sizeof(struct
> erofs_extent_node));
> > > > +                     if (e_hole == NULL)
> > > > +                             return -ENOMEM;
> > > > +                     e_hole->lblk = st;
> > > > +                     e_hole->pblk = HOLE_BLK;
> > > > +                     e_hole->len = (en - st);
> > > > +                     list_add_tail(&e_hole->next, extents);
> > > > +                     nholes += e_hole->len;
> > >
> > > Maybe we don't need to emit all HOLK extents since all data extents
> > > are with _length_... It is easy to detect all holes between extents...
> > >
> > > If some block doesn't belong to any extent, it's a hole.
> > >
> > > Thanks,
> > > Gao Xiang
> > >
> > > > +             }
> > > > +     }
> > > > +     /* rounddown to exclude tail-end data */
> > > > +     if (last_data < len && (len - last_data) >= EROFS_BLKSIZ) {
> > > > +             e_data = malloc(sizeof(struct erofs_extent_node));
> > > > +             if (e_data == NULL)
> > > > +                     return -ENOMEM;
> > > > +             st = last_data >> S_SHIFT;
> > > > +             e_data->lblk = st;
> > > > +             e_data->len = rounddown((len - last_data),
> EROFS_BLKSIZ)
> > > >> S_SHIFT;
> > > > +             list_add_tail(&e_data->next, extents);
> > > > +     }
> > > > +     return nholes;
> > > > +}
> > > > +
> > > > +char *erofs_create_extent_buffer(struct list_head *extents, unsigned
> > > int size)
> > > > +{
> > > > +     struct erofs_extent_node *e_node;
> > > > +     struct erofs_inline_extent_header *header;
> > > > +     char *buf;
> > > > +     unsigned int p = 0;
> > > > +
> > > > +     buf = malloc(size);
> > > > +     if (buf == NULL)
> > > > +             return ERR_PTR(-ENOMEM);
> > > > +     header = (struct erofs_inline_extent_header *) buf;
> > > > +     header->count = 0;
> > > > +     p += sizeof(struct erofs_inline_extent_header);
> > > > +     list_for_each_entry(e_node, extents, next) {
> > > > +             const struct erofs_extent ee = {
> > > > +                     .ee_lblk = cpu_to_le32(e_node->lblk),
> > > > +                     .ee_pblk = cpu_to_le32(e_node->pblk),
> > > > +                     .ee_len  = cpu_to_le32(e_node->len)
> > > > +             };
> > > > +             memcpy(buf + p, &ee, sizeof(struct erofs_extent));
> > > > +             p += sizeof(struct erofs_extent);
> > > > +             header->count++;
> > > > +             list_del(&e_node->next);
> > > > +             free(e_node);
> > > > +     }
> > > > +     return buf;
> > > > +}
> > > > +
> > > >  void erofs_inode_manager_init(void)
> > > >  {
> > > >       unsigned int i;
> > > > @@ -304,8 +397,9 @@ static bool erofs_file_is_compressible(struct
> > > erofs_inode *inode)
> > > >
> > > >  int erofs_write_file(struct erofs_inode *inode)
> > > >  {
> > > > -     unsigned int nblocks, i;
> > > > +     unsigned int nblocks, i, j, nholes;
> > > >       int ret, fd;
> > > > +     struct erofs_extent_node *e_node;
> > > >
> > > >       if (!inode->i_size) {
> > > >               inode->datalayout = EROFS_INODE_FLAT_PLAIN;
> > > > @@ -322,31 +416,43 @@ int erofs_write_file(struct erofs_inode *inode)
> > > >       /* fallback to all data uncompressed */
> > > >       inode->datalayout = EROFS_INODE_FLAT_INLINE;
> > > >       nblocks = inode->i_size / EROFS_BLKSIZ;
> > > > -
> > > > -     ret = __allocate_inode_bh_data(inode, nblocks);
> > > > +     nholes = erofs_read_extents(inode, &inode->i_extents);
> > > > +     if (nholes < 0)
> > > > +             return nholes;
> > > > +     if (nblocks < 0)
> > > > +             return nblocks;
> > > > +     ret = __allocate_inode_bh_data(inode, nblocks - nholes);
> > > >       if (ret)
> > > >               return ret;
> > > >
> > > >       fd = open(inode->i_srcpath, O_RDONLY | O_BINARY);
> > > >       if (fd < 0)
> > > >               return -errno;
> > > > -
> > > > -     for (i = 0; i < nblocks; ++i) {
> > > > -             char buf[EROFS_BLKSIZ];
> > > > -
> > > > -             ret = read(fd, buf, EROFS_BLKSIZ);
> > > > -             if (ret != EROFS_BLKSIZ) {
> > > > -                     if (ret < 0)
> > > > -                             goto fail;
> > > > -                     close(fd);
> > > > -                     return -EAGAIN;
> > > > +     i = inode->u.i_blkaddr;
> > > > +     inode->extent_meta_isize = sizeof(struct
> > > erofs_inline_extent_header);
> > > > +     list_for_each_entry(e_node, &inode->i_extents, next) {
> > > > +             inode->extent_meta_isize += sizeof(struct
> erofs_extent);
> > > > +             if (e_node->pblk == HOLE_BLK) {
> > > > +                     lseek(fd, e_node->len * EROFS_BLKSIZ,
> SEEK_CUR);
> > > > +                     continue;
> > > >               }
> > > > +             e_node->pblk = i;
> > > > +             i += e_node->len;
> > > > +             for (j = 0; j < e_node->len; j++) {
> > > > +                     char buf[EROFS_BLKSIZ];
> > > > +                     ret = read(fd, buf, EROFS_BLKSIZ);
> > > > +                     if (ret != EROFS_BLKSIZ) {
> > > > +                             if (ret < 0)
> > > > +                                     goto fail;
> > > > +                             close(fd);
> > > > +                             return -EAGAIN;
> > > > +                     }
> > > > +                     ret = blk_write(buf, e_node->pblk + j, 1);
> > > > +                     if (ret)
> > > > +                             goto fail;
> > > >
> > > > -             ret = blk_write(buf, inode->u.i_blkaddr + i, 1);
> > > > -             if (ret)
> > > > -                     goto fail;
> > > > +             }
> > > >       }
> > > > -
> > > >       /* read the tail-end data */
> > > >       inode->idata_size = inode->i_size % EROFS_BLKSIZ;
> > > >       if (inode->idata_size) {
> > > > @@ -479,8 +585,19 @@ static bool erofs_bh_flush_write_inode(struct
> > > erofs_buffer_head *bh)
> > > >               if (ret)
> > > >                       return false;
> > > >               free(inode->compressmeta);
> > > > +             off += inode->extent_isize;
> > > >       }
> > > >
> > > > +     if (inode->extent_meta_isize) {
> > > > +             char *extents =
> > > erofs_create_extent_buffer(&inode->i_extents,
> > > > +
> > > inode->extent_meta_isize);
> > > > +             if (IS_ERR(extents))
> > > > +                     return false;
> > > > +             ret = dev_write(extents, off,
> inode->extent_meta_isize);
> > > > +             free(extents);
> > > > +             if (ret)
> > > > +                     return false;
> > > > +     }
> > > >       inode->bh = NULL;
> > > >       erofs_iput(inode);
> > > >       return erofs_bh_flush_generic_end(bh);
> > > > @@ -737,10 +854,11 @@ struct erofs_inode *erofs_new_inode(void)
> > > >
> > > >       init_list_head(&inode->i_subdirs);
> > > >       init_list_head(&inode->i_xattrs);
> > > > +     init_list_head(&inode->i_extents);
> > > >
> > > >       inode->idata_size = 0;
> > > >       inode->xattr_isize = 0;
> > > > -     inode->extent_isize = 0;
> > > > +     inode->extent_meta_isize = 0;
> > > >
> > > >       inode->bh = inode->bh_inline = inode->bh_data = NULL;
> > > >       inode->idata = NULL;
> > > > @@ -961,4 +1079,3 @@ struct erofs_inode
> > > *erofs_mkfs_build_tree_from_path(struct erofs_inode *parent,
> > > >
> > > >       return erofs_mkfs_build_tree(inode);
> > > >  }
> > > > -
> > > > --
> > > > 2.9.3
> > > >
> > >
>

[-- Attachment #2: Type: text/html, Size: 18795 bytes --]

<div dir="ltr"><div>Thanks got it.</div><div><br></div><div>Then we can use LOG_BLOCK_SIZE , to get block no. for corresponding file offset.</div><div><br></div><div>--Pratik.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 30, 2019 at 12:19 PM Gao Xiang &lt;<a href="mailto:gaoxiang25@huawei.com">gaoxiang25@huawei.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, Dec 30, 2019 at 11:49:55AM +0530, Pratik Shinde wrote:<br>
&gt; Gao,<br>
&gt; <br>
&gt; Okay, I will rename the &#39;size&#39; variables accordingly.<br>
&gt; The &#39;S_SHIFT&#39; gives the logical block number inside file. I am using it to<br>
&gt; assign logical block no.<br>
&gt; to extents.<br>
<br>
S_SHIFT is used to transfer between i_mode and filetype, see:<br>
<a href="https://elixir.bootlin.com/linux/latest/source/fs/ext4/ext4.h#L3196" rel="noreferrer" target="_blank">https://elixir.bootlin.com/linux/latest/source/fs/ext4/ext4.h#L3196</a><br>
<br>
IMO, which is not the above meaning, how about using EROFS_BLKSIZ<br>
instead?<br>
<br>
Thanks,<br>
Gao Xiang<br>
<br>
&gt; Also, I will modify the code to record only data extents.<br>
&gt; <br>
&gt; --Pratik.<br>
&gt; <br>
&gt; On Sun, Dec 29, 2019 at 8:26 AM Gao Xiang &lt;<a href="mailto:hsiangkao@aol.com" target="_blank">hsiangkao@aol.com</a>&gt; wrote:<br>
&gt; <br>
&gt; &gt; Hi Pratik,<br>
&gt; &gt;<br>
&gt; &gt; On Fri, Dec 27, 2019 at 09:13:48PM +0530, Pratik Shinde wrote:<br>
&gt; &gt; &gt; since this patch is quite different from previous patches I am treating<br>
&gt; &gt; &gt; this as new patch.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; 1) On disk extent format for erofs data blocks.<br>
&gt; &gt; &gt; 2) Detect holes inside files &amp; skip allocation for hole blocks.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Signed-off-by: Pratik Shinde &lt;<a href="mailto:pratikshinde320@gmail.com" target="_blank">pratikshinde320@gmail.com</a>&gt;<br>
&gt; &gt; &gt; ---<br>
&gt; &gt; &gt;  include/erofs/internal.h |  21 ++++++-<br>
&gt; &gt; &gt;  lib/inode.c              | 155<br>
&gt; &gt; +++++++++++++++++++++++++++++++++++++++++------<br>
&gt; &gt; &gt;  2 files changed, 156 insertions(+), 20 deletions(-)<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; diff --git a/include/erofs/internal.h b/include/erofs/internal.h<br>
&gt; &gt; &gt; index e13adda..128aa63 100644<br>
&gt; &gt; &gt; --- a/include/erofs/internal.h<br>
&gt; &gt; &gt; +++ b/include/erofs/internal.h<br>
&gt; &gt; &gt; @@ -63,7 +63,7 @@ struct erofs_sb_info {<br>
&gt; &gt; &gt;  extern struct erofs_sb_info sbi;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;  struct erofs_inode {<br>
&gt; &gt; &gt; -     struct list_head i_hash, i_subdirs, i_xattrs;<br>
&gt; &gt; &gt; +     struct list_head i_hash, i_subdirs, i_xattrs, i_extents;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;       unsigned int i_count;<br>
&gt; &gt; &gt;       struct erofs_inode *i_parent;<br>
&gt; &gt; &gt; @@ -93,6 +93,7 @@ struct erofs_inode {<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;       unsigned int xattr_isize;<br>
&gt; &gt; &gt;       unsigned int extent_isize;<br>
&gt; &gt; &gt; +     unsigned int extent_meta_isize;<br>
&gt; &gt;<br>
&gt; &gt; maybe sparse_extent_isize is better...<br>
&gt; &gt;<br>
&gt; &gt; p.s. maybe we could send another patch rename extent_isize to<br>
&gt; &gt; compress_extent_isize or some better name...<br>
&gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;       erofs_nid_t nid;<br>
&gt; &gt; &gt;       struct erofs_buffer_head *bh;<br>
&gt; &gt; &gt; @@ -139,5 +140,23 @@ static inline const char *erofs_strerror(int err)<br>
&gt; &gt; &gt;       return msg;<br>
&gt; &gt; &gt;  }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; +#define HOLE_BLK     -1<br>
&gt; &gt; &gt; +/* on disk extent format */<br>
&gt; &gt; &gt; +struct erofs_extent {<br>
&gt; &gt; &gt; +     __le32 ee_lblk;<br>
&gt; &gt; &gt; +     __le32 ee_pblk;<br>
&gt; &gt; &gt; +     __le32 ee_len;<br>
&gt; &gt; &gt; +};<br>
&gt; &gt; &gt; +<br>
&gt; &gt; &gt; +struct erofs_extent_node {<br>
&gt; &gt; &gt; +     struct list_head next;<br>
&gt; &gt; &gt; +     erofs_blk_t lblk;<br>
&gt; &gt; &gt; +     erofs_blk_t pblk;<br>
&gt; &gt; &gt; +     u32 len;<br>
&gt; &gt; &gt; +};<br>
&gt; &gt; &gt; +<br>
&gt; &gt; &gt; +struct erofs_inline_extent_header {<br>
&gt; &gt; &gt; +     u32 count;<br>
&gt; &gt; &gt; +};<br>
&gt; &gt; &gt;  #endif<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; diff --git a/lib/inode.c b/lib/inode.c<br>
&gt; &gt; &gt; index 0e19b11..a6af509 100644<br>
&gt; &gt; &gt; --- a/lib/inode.c<br>
&gt; &gt; &gt; +++ b/lib/inode.c<br>
&gt; &gt; &gt; @@ -38,6 +38,99 @@ static unsigned char erofs_type_by_mode[S_IFMT &gt;&gt;<br>
&gt; &gt; S_SHIFT] = {<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;  struct list_head inode_hashtable[NR_INODE_HASHTABLE];<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; +<br>
&gt; &gt; &gt; +#define IS_HOLE(start, end) (roundup(start, EROFS_BLKSIZ) == start &amp;&amp;<br>
&gt; &gt;       \<br>
&gt; &gt; &gt; +                          roundup(end, EROFS_BLKSIZ) == end &amp;&amp;       \<br>
&gt; &gt; &gt; +                         (end - start) % EROFS_BLKSIZ == 0)<br>
&gt; &gt;<br>
&gt; &gt; See below..<br>
&gt; &gt;<br>
&gt; &gt; &gt; +<br>
&gt; &gt; &gt; +/* returns the number of holes present in the file */<br>
&gt; &gt; &gt; +unsigned int erofs_read_extents(struct erofs_inode *inode,<br>
&gt; &gt; &gt; +                             struct list_head *extents)<br>
&gt; &gt; &gt; +{<br>
&gt; &gt; &gt; +     int fd, st, en, dt;<br>
&gt; &gt; &gt; +     unsigned int nholes = 0;<br>
&gt; &gt; &gt; +     erofs_off_t data, hole, len, last_data;<br>
&gt; &gt; &gt; +     struct erofs_extent_node *e_hole, *e_data;<br>
&gt; &gt; &gt; +<br>
&gt; &gt; &gt; +     fd = open(inode-&gt;i_srcpath, O_RDONLY);<br>
&gt; &gt; &gt; +     if (fd &lt; 0) {<br>
&gt; &gt; &gt; +             return -errno;<br>
&gt; &gt; &gt; +     }<br>
&gt; &gt; &gt; +     len = lseek(fd, 0, SEEK_END);<br>
&gt; &gt; &gt; +     if (lseek(fd, 0, SEEK_SET) == -1)<br>
&gt; &gt; &gt; +             return -errno;<br>
&gt; &gt; &gt; +     data = 0;<br>
&gt; &gt; &gt; +     last_data = 0;<br>
&gt; &gt; &gt; +     while (data &lt; len) {<br>
&gt; &gt; &gt; +             hole = lseek(fd, data, SEEK_HOLE);<br>
&gt; &gt; &gt; +             if (hole == len)<br>
&gt; &gt; &gt; +                     break;<br>
&gt; &gt; &gt; +             data = lseek(fd, hole, SEEK_DATA);<br>
&gt; &gt; &gt; +             if (data &lt; 0 || hole &gt; data) {<br>
&gt; &gt; &gt; +                     return -EINVAL;<br>
&gt; &gt; &gt; +             }<br>
&gt; &gt; &gt; +             if (IS_HOLE(hole, data)) {<br>
&gt; &gt; &gt; +                     st = hole &gt;&gt; S_SHIFT;<br>
&gt; &gt; &gt; +                     en = data &gt;&gt; S_SHIFT;<br>
&gt; &gt; &gt; +                     dt = last_data &gt;&gt; S_SHIFT;<br>
&gt; &gt;<br>
&gt; &gt; Why using S_SHIFT here, some special meaning?<br>
&gt; &gt;<br>
&gt; &gt; &gt; +                     last_data = data;<br>
&gt; &gt; &gt; +                     e_data = malloc(sizeof(struct erofs_extent_node));<br>
&gt; &gt; &gt; +                     if (e_data == NULL)<br>
&gt; &gt; &gt; +                             return -ENOMEM;<br>
&gt; &gt; &gt; +                     e_data-&gt;lblk = dt;<br>
&gt; &gt; &gt; +                     e_data-&gt;len = (st - dt);<br>
&gt; &gt; &gt; +                     list_add_tail(&amp;e_data-&gt;next, extents);<br>
&gt; &gt; &gt; +                     e_hole = malloc(sizeof(struct erofs_extent_node));<br>
&gt; &gt; &gt; +                     if (e_hole == NULL)<br>
&gt; &gt; &gt; +                             return -ENOMEM;<br>
&gt; &gt; &gt; +                     e_hole-&gt;lblk = st;<br>
&gt; &gt; &gt; +                     e_hole-&gt;pblk = HOLE_BLK;<br>
&gt; &gt; &gt; +                     e_hole-&gt;len = (en - st);<br>
&gt; &gt; &gt; +                     list_add_tail(&amp;e_hole-&gt;next, extents);<br>
&gt; &gt; &gt; +                     nholes += e_hole-&gt;len;<br>
&gt; &gt;<br>
&gt; &gt; Maybe we don&#39;t need to emit all HOLK extents since all data extents<br>
&gt; &gt; are with _length_... It is easy to detect all holes between extents...<br>
&gt; &gt;<br>
&gt; &gt; If some block doesn&#39;t belong to any extent, it&#39;s a hole.<br>
&gt; &gt;<br>
&gt; &gt; Thanks,<br>
&gt; &gt; Gao Xiang<br>
&gt; &gt;<br>
&gt; &gt; &gt; +             }<br>
&gt; &gt; &gt; +     }<br>
&gt; &gt; &gt; +     /* rounddown to exclude tail-end data */<br>
&gt; &gt; &gt; +     if (last_data &lt; len &amp;&amp; (len - last_data) &gt;= EROFS_BLKSIZ) {<br>
&gt; &gt; &gt; +             e_data = malloc(sizeof(struct erofs_extent_node));<br>
&gt; &gt; &gt; +             if (e_data == NULL)<br>
&gt; &gt; &gt; +                     return -ENOMEM;<br>
&gt; &gt; &gt; +             st = last_data &gt;&gt; S_SHIFT;<br>
&gt; &gt; &gt; +             e_data-&gt;lblk = st;<br>
&gt; &gt; &gt; +             e_data-&gt;len = rounddown((len - last_data), EROFS_BLKSIZ)<br>
&gt; &gt; &gt;&gt; S_SHIFT;<br>
&gt; &gt; &gt; +             list_add_tail(&amp;e_data-&gt;next, extents);<br>
&gt; &gt; &gt; +     }<br>
&gt; &gt; &gt; +     return nholes;<br>
&gt; &gt; &gt; +}<br>
&gt; &gt; &gt; +<br>
&gt; &gt; &gt; +char *erofs_create_extent_buffer(struct list_head *extents, unsigned<br>
&gt; &gt; int size)<br>
&gt; &gt; &gt; +{<br>
&gt; &gt; &gt; +     struct erofs_extent_node *e_node;<br>
&gt; &gt; &gt; +     struct erofs_inline_extent_header *header;<br>
&gt; &gt; &gt; +     char *buf;<br>
&gt; &gt; &gt; +     unsigned int p = 0;<br>
&gt; &gt; &gt; +<br>
&gt; &gt; &gt; +     buf = malloc(size);<br>
&gt; &gt; &gt; +     if (buf == NULL)<br>
&gt; &gt; &gt; +             return ERR_PTR(-ENOMEM);<br>
&gt; &gt; &gt; +     header = (struct erofs_inline_extent_header *) buf;<br>
&gt; &gt; &gt; +     header-&gt;count = 0;<br>
&gt; &gt; &gt; +     p += sizeof(struct erofs_inline_extent_header);<br>
&gt; &gt; &gt; +     list_for_each_entry(e_node, extents, next) {<br>
&gt; &gt; &gt; +             const struct erofs_extent ee = {<br>
&gt; &gt; &gt; +                     .ee_lblk = cpu_to_le32(e_node-&gt;lblk),<br>
&gt; &gt; &gt; +                     .ee_pblk = cpu_to_le32(e_node-&gt;pblk),<br>
&gt; &gt; &gt; +                     .ee_len  = cpu_to_le32(e_node-&gt;len)<br>
&gt; &gt; &gt; +             };<br>
&gt; &gt; &gt; +             memcpy(buf + p, &amp;ee, sizeof(struct erofs_extent));<br>
&gt; &gt; &gt; +             p += sizeof(struct erofs_extent);<br>
&gt; &gt; &gt; +             header-&gt;count++;<br>
&gt; &gt; &gt; +             list_del(&amp;e_node-&gt;next);<br>
&gt; &gt; &gt; +             free(e_node);<br>
&gt; &gt; &gt; +     }<br>
&gt; &gt; &gt; +     return buf;<br>
&gt; &gt; &gt; +}<br>
&gt; &gt; &gt; +<br>
&gt; &gt; &gt;  void erofs_inode_manager_init(void)<br>
&gt; &gt; &gt;  {<br>
&gt; &gt; &gt;       unsigned int i;<br>
&gt; &gt; &gt; @@ -304,8 +397,9 @@ static bool erofs_file_is_compressible(struct<br>
&gt; &gt; erofs_inode *inode)<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;  int erofs_write_file(struct erofs_inode *inode)<br>
&gt; &gt; &gt;  {<br>
&gt; &gt; &gt; -     unsigned int nblocks, i;<br>
&gt; &gt; &gt; +     unsigned int nblocks, i, j, nholes;<br>
&gt; &gt; &gt;       int ret, fd;<br>
&gt; &gt; &gt; +     struct erofs_extent_node *e_node;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;       if (!inode-&gt;i_size) {<br>
&gt; &gt; &gt;               inode-&gt;datalayout = EROFS_INODE_FLAT_PLAIN;<br>
&gt; &gt; &gt; @@ -322,31 +416,43 @@ int erofs_write_file(struct erofs_inode *inode)<br>
&gt; &gt; &gt;       /* fallback to all data uncompressed */<br>
&gt; &gt; &gt;       inode-&gt;datalayout = EROFS_INODE_FLAT_INLINE;<br>
&gt; &gt; &gt;       nblocks = inode-&gt;i_size / EROFS_BLKSIZ;<br>
&gt; &gt; &gt; -<br>
&gt; &gt; &gt; -     ret = __allocate_inode_bh_data(inode, nblocks);<br>
&gt; &gt; &gt; +     nholes = erofs_read_extents(inode, &amp;inode-&gt;i_extents);<br>
&gt; &gt; &gt; +     if (nholes &lt; 0)<br>
&gt; &gt; &gt; +             return nholes;<br>
&gt; &gt; &gt; +     if (nblocks &lt; 0)<br>
&gt; &gt; &gt; +             return nblocks;<br>
&gt; &gt; &gt; +     ret = __allocate_inode_bh_data(inode, nblocks - nholes);<br>
&gt; &gt; &gt;       if (ret)<br>
&gt; &gt; &gt;               return ret;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;       fd = open(inode-&gt;i_srcpath, O_RDONLY | O_BINARY);<br>
&gt; &gt; &gt;       if (fd &lt; 0)<br>
&gt; &gt; &gt;               return -errno;<br>
&gt; &gt; &gt; -<br>
&gt; &gt; &gt; -     for (i = 0; i &lt; nblocks; ++i) {<br>
&gt; &gt; &gt; -             char buf[EROFS_BLKSIZ];<br>
&gt; &gt; &gt; -<br>
&gt; &gt; &gt; -             ret = read(fd, buf, EROFS_BLKSIZ);<br>
&gt; &gt; &gt; -             if (ret != EROFS_BLKSIZ) {<br>
&gt; &gt; &gt; -                     if (ret &lt; 0)<br>
&gt; &gt; &gt; -                             goto fail;<br>
&gt; &gt; &gt; -                     close(fd);<br>
&gt; &gt; &gt; -                     return -EAGAIN;<br>
&gt; &gt; &gt; +     i = inode-&gt;u.i_blkaddr;<br>
&gt; &gt; &gt; +     inode-&gt;extent_meta_isize = sizeof(struct<br>
&gt; &gt; erofs_inline_extent_header);<br>
&gt; &gt; &gt; +     list_for_each_entry(e_node, &amp;inode-&gt;i_extents, next) {<br>
&gt; &gt; &gt; +             inode-&gt;extent_meta_isize += sizeof(struct erofs_extent);<br>
&gt; &gt; &gt; +             if (e_node-&gt;pblk == HOLE_BLK) {<br>
&gt; &gt; &gt; +                     lseek(fd, e_node-&gt;len * EROFS_BLKSIZ, SEEK_CUR);<br>
&gt; &gt; &gt; +                     continue;<br>
&gt; &gt; &gt;               }<br>
&gt; &gt; &gt; +             e_node-&gt;pblk = i;<br>
&gt; &gt; &gt; +             i += e_node-&gt;len;<br>
&gt; &gt; &gt; +             for (j = 0; j &lt; e_node-&gt;len; j++) {<br>
&gt; &gt; &gt; +                     char buf[EROFS_BLKSIZ];<br>
&gt; &gt; &gt; +                     ret = read(fd, buf, EROFS_BLKSIZ);<br>
&gt; &gt; &gt; +                     if (ret != EROFS_BLKSIZ) {<br>
&gt; &gt; &gt; +                             if (ret &lt; 0)<br>
&gt; &gt; &gt; +                                     goto fail;<br>
&gt; &gt; &gt; +                             close(fd);<br>
&gt; &gt; &gt; +                             return -EAGAIN;<br>
&gt; &gt; &gt; +                     }<br>
&gt; &gt; &gt; +                     ret = blk_write(buf, e_node-&gt;pblk + j, 1);<br>
&gt; &gt; &gt; +                     if (ret)<br>
&gt; &gt; &gt; +                             goto fail;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; -             ret = blk_write(buf, inode-&gt;u.i_blkaddr + i, 1);<br>
&gt; &gt; &gt; -             if (ret)<br>
&gt; &gt; &gt; -                     goto fail;<br>
&gt; &gt; &gt; +             }<br>
&gt; &gt; &gt;       }<br>
&gt; &gt; &gt; -<br>
&gt; &gt; &gt;       /* read the tail-end data */<br>
&gt; &gt; &gt;       inode-&gt;idata_size = inode-&gt;i_size % EROFS_BLKSIZ;<br>
&gt; &gt; &gt;       if (inode-&gt;idata_size) {<br>
&gt; &gt; &gt; @@ -479,8 +585,19 @@ static bool erofs_bh_flush_write_inode(struct<br>
&gt; &gt; erofs_buffer_head *bh)<br>
&gt; &gt; &gt;               if (ret)<br>
&gt; &gt; &gt;                       return false;<br>
&gt; &gt; &gt;               free(inode-&gt;compressmeta);<br>
&gt; &gt; &gt; +             off += inode-&gt;extent_isize;<br>
&gt; &gt; &gt;       }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; +     if (inode-&gt;extent_meta_isize) {<br>
&gt; &gt; &gt; +             char *extents =<br>
&gt; &gt; erofs_create_extent_buffer(&amp;inode-&gt;i_extents,<br>
&gt; &gt; &gt; +<br>
&gt; &gt; inode-&gt;extent_meta_isize);<br>
&gt; &gt; &gt; +             if (IS_ERR(extents))<br>
&gt; &gt; &gt; +                     return false;<br>
&gt; &gt; &gt; +             ret = dev_write(extents, off, inode-&gt;extent_meta_isize);<br>
&gt; &gt; &gt; +             free(extents);<br>
&gt; &gt; &gt; +             if (ret)<br>
&gt; &gt; &gt; +                     return false;<br>
&gt; &gt; &gt; +     }<br>
&gt; &gt; &gt;       inode-&gt;bh = NULL;<br>
&gt; &gt; &gt;       erofs_iput(inode);<br>
&gt; &gt; &gt;       return erofs_bh_flush_generic_end(bh);<br>
&gt; &gt; &gt; @@ -737,10 +854,11 @@ struct erofs_inode *erofs_new_inode(void)<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;       init_list_head(&amp;inode-&gt;i_subdirs);<br>
&gt; &gt; &gt;       init_list_head(&amp;inode-&gt;i_xattrs);<br>
&gt; &gt; &gt; +     init_list_head(&amp;inode-&gt;i_extents);<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;       inode-&gt;idata_size = 0;<br>
&gt; &gt; &gt;       inode-&gt;xattr_isize = 0;<br>
&gt; &gt; &gt; -     inode-&gt;extent_isize = 0;<br>
&gt; &gt; &gt; +     inode-&gt;extent_meta_isize = 0;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;       inode-&gt;bh = inode-&gt;bh_inline = inode-&gt;bh_data = NULL;<br>
&gt; &gt; &gt;       inode-&gt;idata = NULL;<br>
&gt; &gt; &gt; @@ -961,4 +1079,3 @@ struct erofs_inode<br>
&gt; &gt; *erofs_mkfs_build_tree_from_path(struct erofs_inode *parent,<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;       return erofs_mkfs_build_tree(inode);<br>
&gt; &gt; &gt;  }<br>
&gt; &gt; &gt; -<br>
&gt; &gt; &gt; --<br>
&gt; &gt; &gt; 2.9.3<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
</blockquote></div>

  reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-27 15:43 Pratik Shinde
2019-12-29  2:55 ` Gao Xiang via Linux-erofs
2019-12-30  6:19   ` Pratik Shinde
2019-12-30  6:49     ` Gao Xiang
2019-12-30  7:04       ` Pratik Shinde [this message]
2019-12-30  7:16         ` Pratik Shinde
2019-12-30  7:47           ` Gao Xiang

Reply instructions:

You may reply publically 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=CAGu0czS5gEU5Y9UT_fdXuxKNHcHPXJeE7dC+Fh1UMfSa_Q9+1w@mail.gmail.com \
    --to=pratikshinde320@gmail.com \
    --cc=gaoxiang25@huawei.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=miaoxie@huawei.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

Linux-EROFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-erofs/0 linux-erofs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-erofs linux-erofs/ https://lore.kernel.org/linux-erofs \
		linux-erofs@lists.ozlabs.org linux-erofs@ozlabs.org
	public-inbox-index linux-erofs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.ozlabs.lists.linux-erofs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git