[PATCH] erofs-utils: mkfs: add block list support for chunked files
Yue Hu
zbestahu at gmail.com
Thu Nov 11 20:20:42 AEDT 2021
Hi Xiang,
On Thu, 11 Nov 2021 14:17:06 +0800
Gao Xiang <hsiangkao at linux.alibaba.com> wrote:
> Hi David,
>
> On Thu, Nov 11, 2021 at 05:30:31AM +0000, David Anderson via Linux-erofs wrote:
> > When using the --block-list-file option, add block mapping lines for
> > chunked files. The extent printing code has been slightly refactored to
> > accommodate multiple extent ranges.
> >
> > Signed-off-by: David Anderson <dvander at google.com>
>
> Thanks for the patch. Currently. I don't have Android environment at hand.
>
> Hi Yue and Jianan,
> Could you help check this patch in your environments as well and add
> "Tested-by:" tags on this? Many thanks!
This patch has no impact for block mapping without --chunksize in build.
Tested-by: Yue Hu <huyue2 at yulong.com>
Thanks.
>
> Thanks,
> Gao Xiang
>
> > ---
> > include/erofs/block_list.h | 7 +++++++
> > lib/blobchunk.c | 27 ++++++++++++++++++++++++-
> > lib/block_list.c | 41 +++++++++++++++++++++++++++++---------
> > 3 files changed, 65 insertions(+), 10 deletions(-)
> >
> > diff --git a/include/erofs/block_list.h b/include/erofs/block_list.h
> > index dcc0e50..40df228 100644
> > --- a/include/erofs/block_list.h
> > +++ b/include/erofs/block_list.h
> > @@ -15,11 +15,18 @@ void erofs_droid_blocklist_write(struct erofs_inode *inode,
> > erofs_blk_t blk_start, erofs_blk_t nblocks);
> > void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,
> > erofs_blk_t blkaddr);
> > +void erofs_droid_blocklist_write_extent(struct erofs_inode *inode,
> > + erofs_blk_t blk_start, erofs_blk_t nblocks,
> > + bool first_extent, bool last_extent);
> > #else
> > static inline void erofs_droid_blocklist_write(struct erofs_inode *inode,
> > erofs_blk_t blk_start, erofs_blk_t nblocks) {}
> > static inline void
> > erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,
> > erofs_blk_t blkaddr) {}
> > +static inline void
> > +erofs_droid_blocklist_write_extent(struct erofs_inode *inode,
> > + erofs_blk_t blk_start, erofs_blk_t nblocks,
> > + bool first_extent, bool last_extent) {}
> > #endif
> > #endif
> > diff --git a/lib/blobchunk.c b/lib/blobchunk.c
> > index 661c5d0..a2e62be 100644
> > --- a/lib/blobchunk.c
> > +++ b/lib/blobchunk.c
> > @@ -7,6 +7,7 @@
> > #define _GNU_SOURCE
> > #include "erofs/hashmap.h"
> > #include "erofs/blobchunk.h"
> > +#include "erofs/block_list.h"
> > #include "erofs/cache.h"
> > #include "erofs/io.h"
> > #include <unistd.h>
> > @@ -101,7 +102,10 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
> > erofs_off_t off)
> > {
> > struct erofs_inode_chunk_index idx = {0};
> > - unsigned int dst, src, unit;
> > + erofs_blk_t extent_start = EROFS_NULL_ADDR;
> > + erofs_blk_t extent_end = EROFS_NULL_ADDR;
> > + unsigned int dst, src, unit, num_extents;
> > + bool first_extent = true;
> >
> > if (inode->u.chunkformat & EROFS_CHUNK_FORMAT_INDEXES)
> > unit = sizeof(struct erofs_inode_chunk_index);
> > @@ -115,6 +119,20 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
> > chunk = *(void **)(inode->chunkindexes + src);
> >
> > idx.blkaddr = chunk->blkaddr + remapped_base;
> > + if (extent_start != EROFS_NULL_ADDR &&
> > + idx.blkaddr == extent_end + 1) {
> > + extent_end = idx.blkaddr;
> > + } else {
> > + if (extent_start != EROFS_NULL_ADDR) {
> > + erofs_droid_blocklist_write_extent(inode,
> > + extent_start,
> > + (extent_end - extent_start) + 1,
> > + first_extent, false);
> > + first_extent = false;
> > + }
> > + extent_start = idx.blkaddr;
> > + extent_end = idx.blkaddr;
> > + }
> > if (unit == EROFS_BLOCK_MAP_ENTRY_SIZE)
> > memcpy(inode->chunkindexes + dst, &idx.blkaddr, unit);
> > else
> > @@ -122,6 +140,13 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
> > }
> > off = roundup(off, unit);
> >
> > + if (extent_start == EROFS_NULL_ADDR)
> > + num_extents = 0;
> > + else
> > + num_extents = (extent_end - extent_start) + 1;
> > + erofs_droid_blocklist_write_extent(inode, extent_start, num_extents,
> > + first_extent, true);
> > +
> > return dev_write(inode->chunkindexes, off, inode->extent_isize);
> > }
> >
> > diff --git a/lib/block_list.c b/lib/block_list.c
> > index 096dc9b..87609a9 100644
> > --- a/lib/block_list.c
> > +++ b/lib/block_list.c
> > @@ -32,25 +32,48 @@ void erofs_droid_blocklist_fclose(void)
> > }
> >
> > static void blocklist_write(const char *path, erofs_blk_t blk_start,
> > - erofs_blk_t nblocks, bool has_tail)
> > + erofs_blk_t nblocks, bool first_extent,
> > + bool last_extent)
> > {
> > const char *fspath = erofs_fspath(path);
> >
> > - fprintf(block_list_fp, "/%s", cfg.mount_point);
> > + if (first_extent) {
> > + fprintf(block_list_fp, "/%s", cfg.mount_point);
> >
> > - if (fspath[0] != '/')
> > - fprintf(block_list_fp, "/");
> > + if (fspath[0] != '/')
> > + fprintf(block_list_fp, "/");
> > +
> > + fprintf(block_list_fp, "%s", fspath);
> > + }
> >
> > if (nblocks == 1)
> > - fprintf(block_list_fp, "%s %u", fspath, blk_start);
> > + fprintf(block_list_fp, " %u", blk_start);
> > else
> > - fprintf(block_list_fp, "%s %u-%u", fspath, blk_start,
> > + fprintf(block_list_fp, " %u-%u", blk_start,
> > blk_start + nblocks - 1);
> >
> > - if (!has_tail)
> > + if (last_extent)
> > fprintf(block_list_fp, "\n");
> > }
> >
> > +void erofs_droid_blocklist_write_extent(struct erofs_inode *inode,
> > + erofs_blk_t blk_start,
> > + erofs_blk_t nblocks, bool first_extent,
> > + bool last_extent)
> > +{
> > + if (!block_list_fp || !cfg.mount_point)
> > + return;
> > +
> > + if (!nblocks) {
> > + if (last_extent)
> > + fprintf(block_list_fp, "\n");
> > + return;
> > + }
> > +
> > + blocklist_write(inode->i_srcpath, blk_start, nblocks, first_extent,
> > + last_extent);
> > +}
> > +
> > void erofs_droid_blocklist_write(struct erofs_inode *inode,
> > erofs_blk_t blk_start, erofs_blk_t nblocks)
> > {
> > @@ -58,7 +81,7 @@ void erofs_droid_blocklist_write(struct erofs_inode *inode,
> > return;
> >
> > blocklist_write(inode->i_srcpath, blk_start, nblocks,
> > - !!inode->idata_size);
> > + true, !inode->idata_size);
> > }
> >
> > void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,
> > @@ -80,6 +103,6 @@ void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,
> > return;
> > }
> > if (blkaddr != NULL_ADDR)
> > - blocklist_write(inode->i_srcpath, blkaddr, 1, false);
> > + blocklist_write(inode->i_srcpath, blkaddr, 1, true, true);
> > }
> > #endif
> > --
> > 2.34.0.rc0.344.g81b53c2807-goog
More information about the Linux-erofs
mailing list