mkfs: support block map for blob devices
PATCH 1/1 mkfs: support block map for blob devices
Currently, using --blobdev to specify an extra device is restricted from working with the block map chunk format. This was previously noted as a task that could be implemented by mapping the device blocks using a global address.
This patch implements this support by allowing the block map to reference chunks residing on extra devices. This is achieved by:
1) Removing the -EINVAL check in mkfs/main.c that blocked this combination of flags.
2) Calculating the global startblk address for the block map by summing the blocks of the primary device and any preceding extra devices.
3) Ensuring that EROFS_CHUNK_FORMAT_INDEXES is only set if the user has not forced the block map format, and adjusting the index unit size to EROFS_BLOCK_MAP_ENTRY_SIZE accordingly.
4) Updating erofs_inode_fixup_chunkformat to correctly identify when 48-bit addressing is required for a block-mapped file on an extra device.
--- lib/blobchunk.c | 34 ++++++++++++++++++++++++++++------ mkfs/main.c | 7 ------- 2 files changed, 28 insertions(+), 13 deletions(-)
lib/blobchunk.c +28 -6
@@ -159,7 +159,17 @@ void erofs_inode_fixup_chunkformat(struct erofs_inode *inode)if (chunk->blkaddr ==EROFS_NULL_ADDR )continue ;if (chunk->device_id) { -if (chunk->blkaddr >UINT32_MAX ) { +if (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )) { +erofs_blk_t mapped_blkaddr = inode->sbi->primarydevice_blocks; +unsigned int i; + +for (i =0 ; i < chunk->device_id -1 ; i++) + mapped_blkaddr += inode->sbi->devs[i].blocks; +if (mapped_blkaddr + chunk->blkaddr >UINT32_MAX ) { + _48bit = true; +break ; + } + }else if (chunk->blkaddr >UINT32_MAX ) { _48bit = true;break ; }
@@ -201,8 +211,16 @@ int erofs_write_chunk_indexes(struct erofs_inode *inode, struct erofs_vfile *vf,if (chunk->blkaddr ==EROFS_NULL_ADDR ) { startblk =EROFS_NULL_ADDR ; }else if (chunk->device_id) { -DBG_BUGON (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )); - startblk = chunk->blkaddr; +if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) { + startblk = chunk->blkaddr; + }else { +unsigned int i; + + startblk = sbi->primarydevice_blocks; +for (i =0 ; i < chunk->device_id -1 ; i++) + startblk += sbi->devs[i].blocks; + startblk += chunk->blkaddr; + } extent_start =EROFS_NULL_ADDR ; }else { startblk = remapped_base + chunk->blkaddr;
@@ -324,7 +342,7 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, chunksize =1ULL << chunkbits; count =DIV_ROUND_UP (inode->i_size, chunksize); -if (sbi->extra_devices) +if (sbi->extra_devices && cfg.c_force_chunkformat !=FORCE_INODE_BLOCK_MAP ) inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ;if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) unit =sizeof (struct erofs_inode_chunk_index );
@@ -494,8 +512,12 @@ int tarerofs_write_chunkes(struct erofs_inode *inode, erofs_off_t data_offset) inode->u.chunkformat |= chunkbits - sbi->blkszbits;if (sbi->extra_devices) { device_id =1 ; - inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ; - unit =sizeof (struct erofs_inode_chunk_index ); +if (cfg.c_force_chunkformat !=FORCE_INODE_BLOCK_MAP ) + inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ; +if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) + unit =sizeof (struct erofs_inode_chunk_index ); +else + unit =EROFS_BLOCK_MAP_ENTRY_SIZE ;DBG_BUGON (erofs_blkoff (sbi, data_offset)); blkaddr =erofs_blknr (sbi, data_offset); }else {
mkfs/main.c +0 -7
@@ -1565,13 +1565,6 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,return -EINVAL ; } -/* TODO: can be implemented with (deviceslot) mapped_blkaddr */ -if (cfg.c_blobdev_path && - cfg.c_force_chunkformat ==FORCE_INODE_BLOCK_MAP ) { -erofs_err ("--blobdev cannot work with block map currently" ); -return -EINVAL ; - } -if (optind >= argc) {erofs_err ("missing argument: FILE" );return -EINVAL ;
Signature · 1 line
2.51.0
Quoted 7 lines · Nithurshen
Currently, using --blobdev to specify an extra device is restricted from working with the block map chunk format. This was previously noted as a task that could be implemented by mapping the device blocks using a global address.
This patch implements this support by allowing the block map to reference chunks residing on extra devices. This is achieved by:
1) Removing the-EINVALcheck inmkfs/main.cthat blocked this combination of flags.
2) Calculating the global startblk address for the block map by summing the blocks of the primary device and any preceding extra devices.
3) Ensuring thatEROFS_CHUNK_FORMAT_INDEXESis only set if the user has not forced the block map format, and adjusting the index unit size toEROFS_BLOCK_MAP_ENTRY_SIZEaccordingly.
4) Updatingerofs_inode_fixup_chunkformatto correctly identify when 48-bit addressing is required for a block-mapped file on an extra device.
Hi Nithurshen,
Each line of the commit message must not exceed 72 characters.
Quoted 13 lines
Signed-off-by Nithurshen <[email protected]>--- lib/blobchunk.c | 34 ++++++++++++++++++++++++++++------ mkfs/main.c | 7 ------- 2 files changed, 28 insertions(+), 13 deletions(-)lib/blobchunk.c +0
-0@@ -159,7 +159,17 @@ void erofs_inode_fixup_chunkformat(struct erofs_inode *inode)if (chunk->blkaddr ==EROFS_NULL_ADDR )continue ;
lib/blobchunk.c void erofs_inode_fixup_chunkformat(struct erofs_inode *inode) · line 169
Quoted 10 lines
lib/blobchunk.c +8
-1if (chunk->device_id) { -if (chunk->blkaddr >UINT32_MAX ) { +if (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )) { +erofs_blk_t mapped_blkaddr = inode->sbi->primarydevice_blocks; +unsigned int i; + +for (i =0 ; i < chunk->device_id -1 ; i++) + mapped_blkaddr += inode->sbi->devs[i].blocks; +if (mapped_blkaddr + chunk->blkaddr >UINT32_MAX ) { + _48bit = true;
It's impossible for 32-bit block map entries to support 48bit mode.
I think we should err out instead of enabling 48bit here.
BTW, it seems the erofs-utils codebase could not read a chunk-based EROFS image
with block map and extra devices (but in-kernel implementation could), as erofs_map_dev() does
not reset m_deviceid. Could you help also fix this? If you are interested please also add related
testcases in erofs/erofsnightly repo.
Thanks,
Yifan Zhao
Quoted 67 lines
lib/blobchunk.c +20
-5+break ; + } + }else if (chunk->blkaddr >UINT32_MAX ) { _48bit = true;break ; }@@ -201,8 +211,16 @@ int erofs_write_chunk_indexes(struct erofs_inode *inode, struct erofs_vfile *vf,if (chunk->blkaddr ==EROFS_NULL_ADDR ) { startblk =EROFS_NULL_ADDR ; }else if (chunk->device_id) { -DBG_BUGON (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )); - startblk = chunk->blkaddr; +if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) { + startblk = chunk->blkaddr; + }else { +unsigned int i; + + startblk = sbi->primarydevice_blocks; +for (i =0 ; i < chunk->device_id -1 ; i++) + startblk += sbi->devs[i].blocks; + startblk += chunk->blkaddr; + } extent_start =EROFS_NULL_ADDR ; }else { startblk = remapped_base + chunk->blkaddr;@@ -324,7 +342,7 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, chunksize =1ULL << chunkbits; count =DIV_ROUND_UP (inode->i_size, chunksize); -if (sbi->extra_devices) +if (sbi->extra_devices && cfg.c_force_chunkformat !=FORCE_INODE_BLOCK_MAP ) inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ;if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) unit =sizeof (struct erofs_inode_chunk_index );@@ -494,8 +512,12 @@ int tarerofs_write_chunkes(struct erofs_inode *inode, erofs_off_t data_offset) inode->u.chunkformat |= chunkbits - sbi->blkszbits;if (sbi->extra_devices) { device_id =1 ; - inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ; - unit =sizeof (struct erofs_inode_chunk_index ); +if (cfg.c_force_chunkformat !=FORCE_INODE_BLOCK_MAP ) + inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ; +if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) + unit =sizeof (struct erofs_inode_chunk_index ); +else + unit =EROFS_BLOCK_MAP_ENTRY_SIZE ;DBG_BUGON (erofs_blkoff (sbi, data_offset)); blkaddr =erofs_blknr (sbi, data_offset); }else {mkfs/main.c +0
-7@@ -1565,13 +1565,6 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,return -EINVAL ; } -/* TODO: can be implemented with (deviceslot) mapped_blkaddr */ -if (cfg.c_blobdev_path && - cfg.c_force_chunkformat ==FORCE_INODE_BLOCK_MAP ) { -erofs_err ("--blobdev cannot work with block map currently" ); -return -EINVAL ; - } -if (optind >= argc) {erofs_err ("missing argument: FILE" );return -EINVAL ;
Hi Yifan Zhao,
Quoted 3 lines
Hi Nithurshen,
Each line of the commit message must not exceed 72 characters.
I don't know how it went wrong, but I will double check from this time.
Quoted 11 lines
It's impossible for 32-bit block map entries to support 48bit mode.
I think we should err out instead of enabling 48bit here.
BTW, it seems the erofs-utils codebase could not read a chunk-based EROFS image
with block map and extra devices (but in-kernel implementation could), as
erofs_map_dev()does
I have taken care of this in v2 Patch.
Quoted 4 lines
Could you help also fix this? If you are
interested please also add relatedtestcases in erofs/erofsnightly repo.
Sure. I am interested.
I will work on it shortly.
Thanks and regards
Nithurshen
Hi Yifan Zhao,
Quoted 4 lines · zhaoyifan (H)
not reset
m_deviceid. Could you help also fix this? If you are interested please also add relatedtestcases in erofs/erofsnightly repo.
I have opened PR #7 in erofs/erofsnightly repo.
https://github.com/erofs/erofsnightly/pull/7
Thanks and regards,
Nithurshen
Quoted 10 lines · Nithurshen Karthikeyan
Hi Yifan Zhao,
Quoted 4 lines · zhaoyifan (H)
not reset
m_deviceid. Could you help also fix this? If you are interested please also add relatedtestcases in erofs/erofsnightly repo.
I have opened PR #7 in erofs/erofsnightly repo.
https://github.com/erofs/erofsnightly/pull/7
Such test cases should be landed in experimental-tests instead rather than integration tests (erofsnightly).
I will check out later, busying in other stuffs.
Thanks,
Gao Xiang
Quoted 4 lines
Thanks and regards,
Nithurshen
Quoted 10 lines · Gao Xiang
Quoted 6 lines · Nithurshen Karthikeyan
Hi Yifan Zhao,
Quoted 3 lines · zhaoyifan (H)
not reset
m_deviceid. Could you help also fix this? If you are interested please also add related
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
testcases in erofs/erofsnightly repo.
I have opened PR #7 in erofs/erofsnightly repo.
https://github.com/erofs/erofsnightly/pull/7Such test cases should be landed in experimental-tests instead rather than integration tests (erofsnightly).
I placed it to erofsnightly because, I was specifically told to by Yifan Zhao. I will send a patch to experimental-tests branch shortly.
Quoted 1 line
I will check out later, busying in other stuffs.
Sure, you can review it when you have time.
Quoted 8 lines
Thanks,
Gao XiangQuoted 4 lines
Thanks and regards,
Nithurshen
Hi Xiang,
Quoted 2 lines · Gao Xiang
Such test cases should be landed in experimental-tests instead rather than integration tests (erofsnightly).
I have sent a patch for experimental-tests branch adding test-028.
Thanks and Regards
Nithurshen
PATCH v2 1/1 mkfs: support block map for blob devices
In reply to NithurshenCurrently, using --blobdev to specify an extra device is restricted from working with the block map chunk format. This was previously noted as a task that could be implemented by mapping the device blocks using a global address.
This patch implements this support by allowing the block map to reference chunks residing on extra devices. This is achieved by:
1) Removing the -EINVAL check in mkfs/main.c.
2) Calculating the global startblk address for the block map by summing the blocks of the primary device and preceding devices.
3) Ensuring EROFS_CHUNK_FORMAT_INDEXES is only set if the user has not forced the block map format.
4) Updating erofs_inode_fixup_chunkformat to error out if the mapped address exceeds UINT32_MAX, as block maps cannot support 48-bit addressing.
In addition, erofs_map_dev() is updated to correctly identify the device ID when a global block address is used with block maps, enabling userspace tools to read these images.
--- lib/blobchunk.c | 34 ++++++++++++++++++++++++++++------ lib/data.c | 1 + mkfs/main.c | 7 ------- 3 files changed, 29 insertions(+), 13 deletions(-)
lib/blobchunk.c +28 -6
@@ -159,7 +159,17 @@ void erofs_inode_fixup_chunkformat(struct erofs_inode *inode)if (chunk->blkaddr ==EROFS_NULL_ADDR )continue ;if (chunk->device_id) { -if (chunk->blkaddr >UINT32_MAX ) { +if (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )) { +erofs_blk_t mapped_blkaddr = inode->sbi->primarydevice_blocks; +unsigned int i; + +for (i =0 ; i < chunk->device_id -1 ; i++) + mapped_blkaddr += inode->sbi->devs[i].blocks; +if (mapped_blkaddr + chunk->blkaddr >UINT32_MAX ) { +erofs_err ("block map cannot support addresses > UINT32_MAX" ); +return ; + } + }else if (chunk->blkaddr >UINT32_MAX ) { _48bit = true;break ; }
@@ -201,8 +211,16 @@ int erofs_write_chunk_indexes(struct erofs_inode *inode, struct erofs_vfile *vf,if (chunk->blkaddr ==EROFS_NULL_ADDR ) { startblk =EROFS_NULL_ADDR ; }else if (chunk->device_id) { -DBG_BUGON (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )); - startblk = chunk->blkaddr; +if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) { + startblk = chunk->blkaddr; + }else { +unsigned int i; + + startblk = sbi->primarydevice_blocks; +for (i =0 ; i < chunk->device_id -1 ; i++) + startblk += sbi->devs[i].blocks; + startblk += chunk->blkaddr; + } extent_start =EROFS_NULL_ADDR ; }else { startblk = remapped_base + chunk->blkaddr;
@@ -324,7 +342,7 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, chunksize =1ULL << chunkbits; count =DIV_ROUND_UP (inode->i_size, chunksize); -if (sbi->extra_devices) +if (sbi->extra_devices && cfg.c_force_chunkformat !=FORCE_INODE_BLOCK_MAP ) inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ;if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) unit =sizeof (struct erofs_inode_chunk_index );
@@ -494,8 +512,12 @@ int tarerofs_write_chunkes(struct erofs_inode *inode, erofs_off_t data_offset) inode->u.chunkformat |= chunkbits - sbi->blkszbits;if (sbi->extra_devices) { device_id =1 ; - inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ; - unit =sizeof (struct erofs_inode_chunk_index ); +if (cfg.c_force_chunkformat !=FORCE_INODE_BLOCK_MAP ) + inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ; +if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) + unit =sizeof (struct erofs_inode_chunk_index ); +else + unit =EROFS_BLOCK_MAP_ENTRY_SIZE ;DBG_BUGON (erofs_blkoff (sbi, data_offset)); blkaddr =erofs_blknr (sbi, data_offset); }else {
lib/data.c +1 -0
@@ -184,6 +184,7 @@ int erofs_map_dev(struct erofs_sb_info *sbi, struct erofs_map_dev *map)if (map->m_pa >= startoff && map->m_pa < startoff + length) { map->m_pa -= startoff; + map->m_deviceid = id +1 ;break ; } }
mkfs/main.c +0 -7
@@ -1565,13 +1565,6 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,return -EINVAL ; } -/* TODO: can be implemented with (deviceslot) mapped_blkaddr */ -if (cfg.c_blobdev_path && - cfg.c_force_chunkformat ==FORCE_INODE_BLOCK_MAP ) { -erofs_err ("--blobdev cannot work with block map currently" ); -return -EINVAL ; - } -if (optind >= argc) {erofs_err ("missing argument: FILE" );return -EINVAL ;
Signature · 1 line
2.51.0