Skip to contentSkip to conversation

erofs-utils: Relax the hardchecks on the blocksize

PATCH In review Sandeep Dhavale via Linux-erofs 2 participants 5 messages Aug 30, 2023 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 erofs-utils: Relax the hardchecks on the blocksize

As erofs-utils supports different block sizes upto EROFS_MAX_BLOCK_SIZE, relax the checks so same tools can be used to create images for platforms where page size can be greater than 4096.

---
 lib/namei.c | 2 --
 mkfs/main.c | 9 +++++----
 2 files changed, 5 insertions(+), 6 deletions(-)
lib/namei.c +0 -2
index 2bb1d4c..45dbcd3 100644
@@ -144,8 +144,6 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
 		vi->u.chunkbits = sbi->blkszbits +
 			(vi->u.chunkformat & EROFS_CHUNK_FORMAT_BLKBITS_MASK);
 	} else if (erofs_inode_is_data_compressed(vi->datalayout)) {
-		if (erofs_blksiz(vi->sbi) != EROFS_MAX_BLOCK_SIZE)
-			return -EOPNOTSUPP;
 		return z_erofs_fill_inode(vi);
 	}
 	return 0;
mkfs/main.c +5 -4
index c03a7a8..37bf658 100644
@@ -550,10 +550,11 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		cfg.c_dbg_lvl = EROFS_ERR;
 		cfg.c_showprogress = false;
 	}
-	if (cfg.c_compr_alg[0] && erofs_blksiz(&sbi) != EROFS_MAX_BLOCK_SIZE) {
-		erofs_err("compression is unsupported for now with block size %u",
-			  erofs_blksiz(&sbi));
-		return -EINVAL;
+	if (cfg.c_compr_alg[0] && erofs_blksiz(&sbi) != getpagesize()) {
+		erofs_warn("subpage blocksize with compression is not yet "
+			"supported. Compressed image will only work with "
+			"arch pagesize = blocksize = %u bytes",
+			erofs_blksiz(&sbi));
 	}
 	if (pclustersize_max) {
 		if (pclustersize_max < erofs_blksiz(&sbi) ||
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
#1 lore raw

PATCH 2/2 erofs-utils: Set mkfs default blocksize based on current platform

Set mkfs default blocksize to current platform pagesize. This means mkfs with default options will work on current platform. If we are building image for a platform for a different blocksize, we can override default with -b option up to EROFS_MAX_BLOCK_SIZE.

---
 mkfs/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/main.c +1 -1
index 37bf658..8c2c2e3 100644
@@ -689,7 +689,7 @@ static void erofs_mkfs_default_options(void)
 {
 	cfg.c_showprogress = true;
 	cfg.c_legacy_compress = false;
-	sbi.blkszbits = ilog2(EROFS_MAX_BLOCK_SIZE);
+	sbi.blkszbits = ilog2(getpagesize());
 	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_ZERO_PADDING;
 	sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
 			     EROFS_FEATURE_COMPAT_MTIME;
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
#2 lore raw
In reply to Sandeep Dhavale via Linux-erofs

Hi Sandeep,

Quoted 32 lines · Sandeep Dhavale

As erofs-utils supports different block sizes upto EROFS_MAX_BLOCK_SIZE, relax the checks so same tools can be used to create images for platforms where page size can be greater than 4096.

---
  lib/namei.c | 2 --
  mkfs/main.c | 9 +++++----
  2 files changed, 5 insertions(+), 6 deletions(-)
lib/namei.c +0 -2
index 2bb1d4c..45dbcd3 100644
@@ -144,8 +144,6 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
  		vi->u.chunkbits = sbi->blkszbits +
  			(vi->u.chunkformat & EROFS_CHUNK_FORMAT_BLKBITS_MASK);
  	} else if (erofs_inode_is_data_compressed(vi->datalayout)) {
-		if (erofs_blksiz(vi->sbi) != EROFS_MAX_BLOCK_SIZE)
-			return -EOPNOTSUPP;
  		return z_erofs_fill_inode(vi);
  	}
  	return 0;
mkfs/main.c +0 -0
index c03a7a8..37bf658 100644
@@ -550,10 +550,11 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
  		cfg.c_dbg_lvl = EROFS_ERR;
  		cfg.c_showprogress = false;
  	}

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 558

Quoted 10 lines
mkfs/main.c +5 -4
-	if (cfg.c_compr_alg[0] && erofs_blksiz(&sbi) != EROFS_MAX_BLOCK_SIZE) {
-		erofs_err("compression is unsupported for now with block size %u",
-			  erofs_blksiz(&sbi));
-		return -EINVAL;
+	if (cfg.c_compr_alg[0] && erofs_blksiz(&sbi) != getpagesize()) {
+		erofs_warn("subpage blocksize with compression is not yet "
+			"supported. Compressed image will only work with "
+			"arch pagesize = blocksize = %u bytes",
+			erofs_blksiz(&sbi));
  	}

Thanks for the patches.

I'm fine to relax EROFS_MAX_BLOCK_SIZE check, yet could we add a check as erofs_blksiz <= EROFS_MAX_BLOCK_SIZE somewhere?

Otherwise, we could suffer from stack overflow (if EROFS_MAX_BLOCK_SIZE is outdated or somewhat small...)

Thanks,
Gao Xiang

#3 lore raw
Quoted 49 lines · Gao Xiang

Hi Sandeep,

Quoted 32 lines · Sandeep Dhavale

As erofs-utils supports different block sizes upto EROFS_MAX_BLOCK_SIZE, relax the checks so same tools can be used to create images for platforms where page size can be greater than 4096.

---
  lib/namei.c | 2 --
  mkfs/main.c | 9 +++++----
  2 files changed, 5 insertions(+), 6 deletions(-)
lib/namei.c +0 -2
index 2bb1d4c..45dbcd3 100644
@@ -144,8 +144,6 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
              vi->u.chunkbits = sbi->blkszbits +
                      (vi->u.chunkformat & EROFS_CHUNK_FORMAT_BLKBITS_MASK);
      } else if (erofs_inode_is_data_compressed(vi->datalayout)) {
-             if (erofs_blksiz(vi->sbi) != EROFS_MAX_BLOCK_SIZE)
-                     return -EOPNOTSUPP;
              return z_erofs_fill_inode(vi);
      }
      return 0;
mkfs/main.c +0 -0
index c03a7a8..37bf658 100644
@@ -550,10 +550,11 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
              cfg.c_dbg_lvl = EROFS_ERR;
              cfg.c_showprogress = false;
      }

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 558

Quoted 10 lines
mkfs/main.c +5 -4
-     if (cfg.c_compr_alg[0] && erofs_blksiz(&sbi) != EROFS_MAX_BLOCK_SIZE) {
-             erofs_err("compression is unsupported for now with block size %u",
-                       erofs_blksiz(&sbi));
-             return -EINVAL;
+     if (cfg.c_compr_alg[0] && erofs_blksiz(&sbi) != getpagesize()) {
+             erofs_warn("subpage blocksize with compression is not yet "
+                     "supported. Compressed image will only work with "
+                     "arch pagesize = blocksize = %u bytes",
+                     erofs_blksiz(&sbi));
      }

Thanks for the patches.

Quoted 6 lines

I'm fine to relax EROFS_MAX_BLOCK_SIZE check, yet could we add a check as erofs_blksiz <= EROFS_MAX_BLOCK_SIZE somewhere?

Otherwise, we could suffer from stack overflow (if EROFS_MAX_BLOCK_SIZE is outdated or somewhat small...)

Hi Gao,
There is already a check in place for -b option to validate the block size passed is within range [512..EROFS_MAX_BLOCK_SIZE] in function mkfs_parse_options_cfg()

Please correct me if I misunderstood your comment.

Thanks,
Sandeep.

Quoted 2 lines

Thanks,
Gao Xiang

#4 lore raw
Quoted 56 lines · Sandeep Dhavale
Quoted 49 lines · Gao Xiang

Hi Sandeep,

Quoted 32 lines · Sandeep Dhavale

As erofs-utils supports different block sizes upto EROFS_MAX_BLOCK_SIZE, relax the checks so same tools can be used to create images for platforms where page size can be greater than 4096.

---
   lib/namei.c | 2 --
   mkfs/main.c | 9 +++++----
   2 files changed, 5 insertions(+), 6 deletions(-)
lib/namei.c +0 -2
index 2bb1d4c..45dbcd3 100644
@@ -144,8 +144,6 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
               vi->u.chunkbits = sbi->blkszbits +
                       (vi->u.chunkformat & EROFS_CHUNK_FORMAT_BLKBITS_MASK);
       } else if (erofs_inode_is_data_compressed(vi->datalayout)) {
-             if (erofs_blksiz(vi->sbi) != EROFS_MAX_BLOCK_SIZE)
-                     return -EOPNOTSUPP;
               return z_erofs_fill_inode(vi);
       }
       return 0;
mkfs/main.c +0 -0
index c03a7a8..37bf658 100644
@@ -550,10 +550,11 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
               cfg.c_dbg_lvl = EROFS_ERR;
               cfg.c_showprogress = false;
       }

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 558

Quoted 10 lines
mkfs/main.c +5 -4
-     if (cfg.c_compr_alg[0] && erofs_blksiz(&sbi) != EROFS_MAX_BLOCK_SIZE) {
-             erofs_err("compression is unsupported for now with block size %u",
-                       erofs_blksiz(&sbi));
-             return -EINVAL;
+     if (cfg.c_compr_alg[0] && erofs_blksiz(&sbi) != getpagesize()) {
+             erofs_warn("subpage blocksize with compression is not yet "
+                     "supported. Compressed image will only work with "
+                     "arch pagesize = blocksize = %u bytes",
+                     erofs_blksiz(&sbi));
       }

Thanks for the patches.

Quoted 6 lines

I'm fine to relax EROFS_MAX_BLOCK_SIZE check, yet could we add a check as erofs_blksiz <= EROFS_MAX_BLOCK_SIZE somewhere?

Otherwise, we could suffer from stack overflow (if EROFS_MAX_BLOCK_SIZE is outdated or somewhat small...)

Quoted 6 lines

Hi Gao,
There is already a check in place for -b option to validate the block size passed is within range [512..EROFS_MAX_BLOCK_SIZE] in function mkfs_parse_options_cfg()

Please correct me if I misunderstood your comment.

Oh, sorry I didn't check the current code and thanks for your pointing out! Now I have no more questions.

Will apply soon.

Thanks,
Gao Xiang