erofs-utils: mkfs: add block list support for chunked files
PATCH 1/1 erofs-utils: mkfs: add block list support for chunked files
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.
--- include/erofs/block_list.h | 7 +++++++ lib/blobchunk.c | 27 ++++++++++++++++++++++++- lib/block_list.c | 41 +++++++++++++++++++++++++++++--------- 3 files changed, 65 insertions(+), 10 deletions(-)
include/erofs/block_list.h +7 -0
@@ -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
lib/blobchunk.c +26 -1
@@ -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); }
lib/block_list.c +32 -9
70 lines not on this page · raw message
Signature · 1 line
2.34.0.rc0.344.g81b53c2807-goog
Hi David,
Quoted 5 lines · David Anderson via Linux-erofs
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 <[email protected]>
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!
Thanks,
Gao Xiang
Quoted 167 lines
--- include/erofs/block_list.h | 7 +++++++ lib/blobchunk.c | 27 ++++++++++++++++++++++++- lib/block_list.c | 41 +++++++++++++++++++++++++++++--------- 3 files changed, 65 insertions(+), 10 deletions(-)include/erofs/block_list.h +7
-0@@ -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 lib/blobchunk.c +26
-1@@ -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); }lib/block_list.c +32
-9@@ -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 Signature · 1 line
2.34.0.rc0.344.g81b53c2807-goog
Yue Hu
Tested-byHi Xiang,
Quoted 7 lines · On Thu, 11 Nov 2021 14:17:06 +0800 Gao Xiang <[email protected]>…
Hi David,
Quoted 4 lines · David Anderson via Linux-erofs
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.
Quoted 7 lines
Quoted 1 line
Signed-off-by David Anderson <[email protected]>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.
Thanks.
Quoted 171 lines
Thanks,
Gao XiangQuoted 167 lines
--- include/erofs/block_list.h | 7 +++++++ lib/blobchunk.c | 27 ++++++++++++++++++++++++- lib/block_list.c | 41 +++++++++++++++++++++++++++++--------- 3 files changed, 65 insertions(+), 10 deletions(-)include/erofs/block_list.h +7
-0@@ -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 lib/blobchunk.c +26
-1@@ -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); }lib/block_list.c +32
-9@@ -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 Signature · 1 line
2.34.0.rc0.344.g81b53c2807-goog
Huang Jianan via Linux-erofs
Tested-by Huang JiananQuoted 7 lines · Gao Xiang
Hi David,
Quoted 4 lines · David Anderson via Linux-erofs
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.
Quoted 6 lines
Quoted 1 line
Signed-off-by David Anderson <[email protected]>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!
No impact on our build.
Thanks,
Jianan
Quoted 170 lines
Thanks,
Gao XiangQuoted 167 lines
--- include/erofs/block_list.h | 7 +++++++ lib/blobchunk.c | 27 ++++++++++++++++++++++++- lib/block_list.c | 41 +++++++++++++++++++++++++++++--------- 3 files changed, 65 insertions(+), 10 deletions(-)include/erofs/block_list.h +7
-0@@ -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 lib/blobchunk.c +26
-1@@ -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); }lib/block_list.c +32
-9@@ -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 Signature · 1 line
2.34.0.rc0.344.g81b53c2807-goog
Quoted 8 lines · Huang Jianan via Linux-erofs
Quoted 7 lines · Gao Xiang
Hi David,
Quoted 4 lines · David Anderson via Linux-erofs
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.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by David Anderson <[email protected]>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!No impact on our build.
Tested-by Huang Jianan <[email protected]>
Thanks all for the confirmation! I'll apply this this evening.
Thanks,
Gao Xiang