linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] erofs-utils: support detecting maximum block size
@ 2023-06-01  6:46 Gao Xiang
  2023-06-01 12:48 ` Kelvin Zhang via Linux-erofs
  0 siblings, 1 reply; 6+ messages in thread
From: Gao Xiang @ 2023-06-01  6:46 UTC (permalink / raw)
  To: linux-erofs; +Cc: Gao Xiang, Kelvin Zhang

Previously PAGE_SIZE was actually unset for most cases so that it was
always hard-coded 4096.

In order to set EROFS_MAX_BLOCK_SIZE correctly, let's detect the real
page size when configuring.

Cc: Kelvin Zhang <zhangkelvin@google.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 configure.ac             | 38 ++++++++++++++++++++++++++++++++++++++
 include/erofs/internal.h |  8 +++-----
 lib/namei.c              |  2 +-
 mkfs/main.c              |  4 ++--
 4 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4dbe86f..2ade490 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,8 @@ AC_DEFUN([EROFS_UTILS_PARSE_DIRECTORY],
  fi
 ])
 
+AC_ARG_VAR([MAX_BLOCK_SIZE], [The maximum block size which erofs-utils supports])
+
 AC_ARG_ENABLE([debug],
     [AS_HELP_STRING([--enable-debug],
                     [enable debugging mode @<:@default=no@:>@])],
@@ -202,6 +204,35 @@ AC_CHECK_FUNCS(m4_flatten([
 	tmpfile64
 	utimensat]))
 
+# Detect maximum block size if necessary
+AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
+  AC_CACHE_CHECK([sysconf (_SC_PAGESIZE)], [erofs_cv_max_block_size],
+               AC_RUN_IFELSE([AC_LANG_PROGRAM(
+[[
+#include <unistd.h>
+#include <stdio.h>
+]],
+[[
+    int result;
+    FILE *f;
+
+    result = sysconf(_SC_PAGESIZE);
+    if (result < 0)
+	return 1;
+
+    f = fopen("conftest.out", "w");
+    if (!f)
+	return 1;
+
+    fprintf(f, "%d", result);
+    fclose(f);
+    return 0;
+]])],
+                             [erofs_cv_max_block_size=`cat conftest.out`],
+                             [],
+                             []))
+], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
+
 # Configure debug mode
 AS_IF([test "x$enable_debug" != "xno"], [], [
   dnl Turn off all assert checking.
@@ -367,6 +398,13 @@ if test "x${have_liblzma}" = "xyes"; then
   AC_SUBST([liblzma_CFLAGS])
 fi
 
+# Dump maximum block size
+AS_IF([test "x$erofs_cv_max_block_size" = "x"],
+      [$erofs_cv_max_block_size = 4096], [])
+
+AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],
+		   [The maximum block size which erofs-utils supports])
+
 AC_CONFIG_FILES([Makefile
 		 man/Makefile
 		 lib/Makefile
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index b3d04be..ee301e0 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -27,15 +27,13 @@ typedef unsigned short umode_t;
 #define PATH_MAX        4096    /* # chars in a path name including nul */
 #endif
 
-#ifndef PAGE_SHIFT
-#define PAGE_SHIFT		(12)
-#endif
-
 #ifndef PAGE_SIZE
-#define PAGE_SIZE		(1U << PAGE_SHIFT)
+#define PAGE_SIZE		4096
 #endif
 
+#ifndef EROFS_MAX_BLOCK_SIZE
 #define EROFS_MAX_BLOCK_SIZE	PAGE_SIZE
+#endif
 
 #define EROFS_ISLOTBITS		5
 #define EROFS_SLOTSIZE		(1U << EROFS_ISLOTBITS)
diff --git a/lib/namei.c b/lib/namei.c
index 3d0cf93..3751741 100644
--- a/lib/namei.c
+++ b/lib/namei.c
@@ -137,7 +137,7 @@ 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() != PAGE_SIZE)
+		if (erofs_blksiz() != EROFS_MAX_BLOCK_SIZE)
 			return -EOPNOTSUPP;
 		return z_erofs_fill_inode(vi);
 	}
diff --git a/mkfs/main.c b/mkfs/main.c
index 3ec4903..a6a2d0e 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -532,7 +532,7 @@ 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() != PAGE_SIZE) {
+	if (cfg.c_compr_alg[0] && erofs_blksiz() != EROFS_MAX_BLOCK_SIZE) {
 		erofs_err("compression is unsupported for now with block size %u",
 			  erofs_blksiz());
 		return -EINVAL;
@@ -670,7 +670,7 @@ static void erofs_mkfs_default_options(void)
 {
 	cfg.c_showprogress = true;
 	cfg.c_legacy_compress = false;
-	sbi.blkszbits = ilog2(PAGE_SIZE);
+	sbi.blkszbits = ilog2(EROFS_MAX_BLOCK_SIZE);
 	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
 	sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
 			     EROFS_FEATURE_COMPAT_MTIME;
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] erofs-utils: support detecting maximum block size
  2023-06-01  6:46 [PATCH] erofs-utils: support detecting maximum block size Gao Xiang
@ 2023-06-01 12:48 ` Kelvin Zhang via Linux-erofs
  2023-06-01 13:14   ` Gao Xiang
  0 siblings, 1 reply; 6+ messages in thread
From: Kelvin Zhang via Linux-erofs @ 2023-06-01 12:48 UTC (permalink / raw)
  To: Gao Xiang; +Cc: linux-erofs

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

On Thu, Jun 1, 2023 at 2:46 AM Gao Xiang <hsiangkao@linux.alibaba.com>
wrote:

> Previously PAGE_SIZE was actually unset for most cases so that it was
> always hard-coded 4096.
>
> In order to set EROFS_MAX_BLOCK_SIZE correctly, let's detect the real
> page size when configuring.
>
> Cc: Kelvin Zhang <zhangkelvin@google.com>
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> ---
>  configure.ac             | 38 ++++++++++++++++++++++++++++++++++++++
>  include/erofs/internal.h |  8 +++-----
>  lib/namei.c              |  2 +-
>  mkfs/main.c              |  4 ++--
>  4 files changed, 44 insertions(+), 8 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 4dbe86f..2ade490 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -59,6 +59,8 @@ AC_DEFUN([EROFS_UTILS_PARSE_DIRECTORY],
>   fi
>  ])
>
> +AC_ARG_VAR([MAX_BLOCK_SIZE], [The maximum block size which erofs-utils
> supports])
> +
>  AC_ARG_ENABLE([debug],
>      [AS_HELP_STRING([--enable-debug],
>                      [enable debugging mode @<:@default=no@:>@])],
> @@ -202,6 +204,35 @@ AC_CHECK_FUNCS(m4_flatten([
>         tmpfile64
>         utimensat]))
>
> +# Detect maximum block size if necessary
> +AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
> +  AC_CACHE_CHECK([sysconf (_SC_PAGESIZE)], [erofs_cv_max_block_size],
> +               AC_RUN_IFELSE([AC_LANG_PROGRAM(
> +[[
> +#include <unistd.h>
> +#include <stdio.h>
> +]],
> +[[
> +    int result;
> +    FILE *f;
> +
> +    result = sysconf(_SC_PAGESIZE);
> +    if (result < 0)
> +       return 1;
> +
> +    f = fopen("conftest.out", "w");
> +    if (!f)
> +       return 1;
> +
> +    fprintf(f, "%d", result);
> +    fclose(f);
> +    return 0;
> +]])],
> +                             [erofs_cv_max_block_size=`cat conftest.out`],
> +                             [],
> +                             []))
> +], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
> +
>  # Configure debug mode
>  AS_IF([test "x$enable_debug" != "xno"], [], [
>    dnl Turn off all assert checking.
> @@ -367,6 +398,13 @@ if test "x${have_liblzma}" = "xyes"; then
>    AC_SUBST([liblzma_CFLAGS])
>  fi
>
> +# Dump maximum block size
> +AS_IF([test "x$erofs_cv_max_block_size" = "x"],
> +      [$erofs_cv_max_block_size = 4096], [])
> +
> +AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],
> +                  [The maximum block size which erofs-utils supports])
> +
>  AC_CONFIG_FILES([Makefile
>                  man/Makefile
>                  lib/Makefile
> diff --git a/include/erofs/internal.h b/include/erofs/internal.h
> index b3d04be..ee301e0 100644
> --- a/include/erofs/internal.h
> +++ b/include/erofs/internal.h
> @@ -27,15 +27,13 @@ typedef unsigned short umode_t;
>  #define PATH_MAX        4096    /* # chars in a path name including nul */
>  #endif
>
> -#ifndef PAGE_SHIFT
> -#define PAGE_SHIFT             (12)
> -#endif
> -
>  #ifndef PAGE_SIZE
> -#define PAGE_SIZE              (1U << PAGE_SHIFT)
> +#define PAGE_SIZE              4096
>  #endif
>
> +#ifndef EROFS_MAX_BLOCK_SIZE
>  #define EROFS_MAX_BLOCK_SIZE   PAGE_SIZE
> +#endif
>
>  #define EROFS_ISLOTBITS                5
>  #define EROFS_SLOTSIZE         (1U << EROFS_ISLOTBITS)
> diff --git a/lib/namei.c b/lib/namei.c
> index 3d0cf93..3751741 100644
> --- a/lib/namei.c
> +++ b/lib/namei.c
> @@ -137,7 +137,7 @@ 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() != PAGE_SIZE)
> +               if (erofs_blksiz() != EROFS_MAX_BLOCK_SIZE)
>                         return -EOPNOTSUPP;
>                 return z_erofs_fill_inode(vi);
>         }
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 3ec4903..a6a2d0e 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -532,7 +532,7 @@ 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() != PAGE_SIZE) {
> +       if (cfg.c_compr_alg[0] && erofs_blksiz() != EROFS_MAX_BLOCK_SIZE) {
>                 erofs_err("compression is unsupported for now with block
> size %u",
>                           erofs_blksiz());
>                 return -EINVAL;
> @@ -670,7 +670,7 @@ static void erofs_mkfs_default_options(void)
>  {
>         cfg.c_showprogress = true;
>         cfg.c_legacy_compress = false;
> -       sbi.blkszbits = ilog2(PAGE_SIZE);
> +       sbi.blkszbits = ilog2(EROFS_MAX_BLOCK_SIZE);
>         sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
>         sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
>                              EROFS_FEATURE_COMPAT_MTIME;
> --
> 2.24.4
>
>
Overall it looks good to me. Do we still need the PAGE_SIZE macro then?

-- 
Sincerely,

Kelvin Zhang

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] erofs-utils: support detecting maximum block size
  2023-06-01 12:48 ` Kelvin Zhang via Linux-erofs
@ 2023-06-01 13:14   ` Gao Xiang
  2023-06-01 14:53     ` [PATCH v2] " Gao Xiang
  0 siblings, 1 reply; 6+ messages in thread
From: Gao Xiang @ 2023-06-01 13:14 UTC (permalink / raw)
  To: Kelvin Zhang; +Cc: linux-erofs



On 2023/6/1 20:48, Kelvin Zhang wrote:
> 
> 
> On Thu, Jun 1, 2023 at 2:46 AM Gao Xiang <hsiangkao@linux.alibaba.com <mailto:hsiangkao@linux.alibaba.com>> wrote:
> 
>     Previously PAGE_SIZE was actually unset for most cases so that it was
>     always hard-coded 4096.
> 
>     In order to set EROFS_MAX_BLOCK_SIZE correctly, let's detect the real
>     page size when configuring.
> 
>     Cc: Kelvin Zhang <zhangkelvin@google.com <mailto:zhangkelvin@google.com>>
>     Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com <mailto:hsiangkao@linux.alibaba.com>>

...

> 
>     -#ifndef PAGE_SHIFT
>     -#define PAGE_SHIFT             (12)
>     -#endif
>     -
>       #ifndef PAGE_SIZE
>     -#define PAGE_SIZE              (1U << PAGE_SHIFT)
>     +#define PAGE_SIZE              4096
>       #endif
> 
>     +#ifndef EROFS_MAX_BLOCK_SIZE
>       #define EROFS_MAX_BLOCK_SIZE   PAGE_SIZE
>     +#endif
> 
>       #define EROFS_ISLOTBITS                5
>       #define EROFS_SLOTSIZE         (1U << EROFS_ISLOTBITS)
>     diff --git a/lib/namei.c b/lib/namei.c
>     index 3d0cf93..3751741 100644
>     --- a/lib/namei.c
>     +++ b/lib/namei.c
>     @@ -137,7 +137,7 @@ 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() != PAGE_SIZE)
>     +               if (erofs_blksiz() != EROFS_MAX_BLOCK_SIZE)
>                              return -EOPNOTSUPP;
>                      return z_erofs_fill_inode(vi);
>              }
>     diff --git a/mkfs/main.c b/mkfs/main.c
>     index 3ec4903..a6a2d0e 100644
>     --- a/mkfs/main.c
>     +++ b/mkfs/main.c
>     @@ -532,7 +532,7 @@ 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() != PAGE_SIZE) {
>     +       if (cfg.c_compr_alg[0] && erofs_blksiz() != EROFS_MAX_BLOCK_SIZE) {
>                      erofs_err("compression is unsupported for now with block size %u",
>                                erofs_blksiz());
>                      return -EINVAL;
>     @@ -670,7 +670,7 @@ static void erofs_mkfs_default_options(void)
>       {
>              cfg.c_showprogress = true;
>              cfg.c_legacy_compress = false;
>     -       sbi.blkszbits = ilog2(PAGE_SIZE);
>     +       sbi.blkszbits = ilog2(EROFS_MAX_BLOCK_SIZE);
>              sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
>              sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
>                                   EROFS_FEATURE_COMPAT_MTIME;
>     -- 
>     2.24.4
> 
> 
> Overall it looks good to me. Do we still need the PAGE_SIZE macro then?

Ok, let's get rid of PAGE_SIZE. Will send the next version.

Thanks,
Gao Xiang

> 
> -- 
> Sincerely,
> 
> Kelvin Zhang

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] erofs-utils: support detecting maximum block size
  2023-06-01 13:14   ` Gao Xiang
@ 2023-06-01 14:53     ` Gao Xiang
  2023-06-01 14:55       ` Kelvin Zhang via Linux-erofs
  0 siblings, 1 reply; 6+ messages in thread
From: Gao Xiang @ 2023-06-01 14:53 UTC (permalink / raw)
  To: linux-erofs; +Cc: Gao Xiang, Kelvin Zhang

Previously PAGE_SIZE was actually unset for most cases so that it was
always hard-coded 4096.

In order to set EROFS_MAX_BLOCK_SIZE correctly, let's detect the real
page size when configuring and get rid of PAGE_SIZE.

Cc: Kelvin Zhang <zhangkelvin@google.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
change since v1:
 - get rid of PAGE_SIZE (Kelvin);

 configure.ac             | 38 ++++++++++++++++++++++++++++++++++++++
 include/erofs/internal.h | 10 ++--------
 lib/namei.c              |  2 +-
 mkfs/main.c              |  4 ++--
 4 files changed, 43 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4dbe86f..2ade490 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,8 @@ AC_DEFUN([EROFS_UTILS_PARSE_DIRECTORY],
  fi
 ])
 
+AC_ARG_VAR([MAX_BLOCK_SIZE], [The maximum block size which erofs-utils supports])
+
 AC_ARG_ENABLE([debug],
     [AS_HELP_STRING([--enable-debug],
                     [enable debugging mode @<:@default=no@:>@])],
@@ -202,6 +204,35 @@ AC_CHECK_FUNCS(m4_flatten([
 	tmpfile64
 	utimensat]))
 
+# Detect maximum block size if necessary
+AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
+  AC_CACHE_CHECK([sysconf (_SC_PAGESIZE)], [erofs_cv_max_block_size],
+               AC_RUN_IFELSE([AC_LANG_PROGRAM(
+[[
+#include <unistd.h>
+#include <stdio.h>
+]],
+[[
+    int result;
+    FILE *f;
+
+    result = sysconf(_SC_PAGESIZE);
+    if (result < 0)
+	return 1;
+
+    f = fopen("conftest.out", "w");
+    if (!f)
+	return 1;
+
+    fprintf(f, "%d", result);
+    fclose(f);
+    return 0;
+]])],
+                             [erofs_cv_max_block_size=`cat conftest.out`],
+                             [],
+                             []))
+], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
+
 # Configure debug mode
 AS_IF([test "x$enable_debug" != "xno"], [], [
   dnl Turn off all assert checking.
@@ -367,6 +398,13 @@ if test "x${have_liblzma}" = "xyes"; then
   AC_SUBST([liblzma_CFLAGS])
 fi
 
+# Dump maximum block size
+AS_IF([test "x$erofs_cv_max_block_size" = "x"],
+      [$erofs_cv_max_block_size = 4096], [])
+
+AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],
+		   [The maximum block size which erofs-utils supports])
+
 AC_CONFIG_FILES([Makefile
 		 man/Makefile
 		 lib/Makefile
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index b3d04be..370cfac 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -27,16 +27,10 @@ typedef unsigned short umode_t;
 #define PATH_MAX        4096    /* # chars in a path name including nul */
 #endif
 
-#ifndef PAGE_SHIFT
-#define PAGE_SHIFT		(12)
+#ifndef EROFS_MAX_BLOCK_SIZE
+#define EROFS_MAX_BLOCK_SIZE	4096
 #endif
 
-#ifndef PAGE_SIZE
-#define PAGE_SIZE		(1U << PAGE_SHIFT)
-#endif
-
-#define EROFS_MAX_BLOCK_SIZE	PAGE_SIZE
-
 #define EROFS_ISLOTBITS		5
 #define EROFS_SLOTSIZE		(1U << EROFS_ISLOTBITS)
 
diff --git a/lib/namei.c b/lib/namei.c
index 3d0cf93..3751741 100644
--- a/lib/namei.c
+++ b/lib/namei.c
@@ -137,7 +137,7 @@ 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() != PAGE_SIZE)
+		if (erofs_blksiz() != EROFS_MAX_BLOCK_SIZE)
 			return -EOPNOTSUPP;
 		return z_erofs_fill_inode(vi);
 	}
diff --git a/mkfs/main.c b/mkfs/main.c
index 3ec4903..a6a2d0e 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -532,7 +532,7 @@ 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() != PAGE_SIZE) {
+	if (cfg.c_compr_alg[0] && erofs_blksiz() != EROFS_MAX_BLOCK_SIZE) {
 		erofs_err("compression is unsupported for now with block size %u",
 			  erofs_blksiz());
 		return -EINVAL;
@@ -670,7 +670,7 @@ static void erofs_mkfs_default_options(void)
 {
 	cfg.c_showprogress = true;
 	cfg.c_legacy_compress = false;
-	sbi.blkszbits = ilog2(PAGE_SIZE);
+	sbi.blkszbits = ilog2(EROFS_MAX_BLOCK_SIZE);
 	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
 	sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
 			     EROFS_FEATURE_COMPAT_MTIME;
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] erofs-utils: support detecting maximum block size
  2023-06-01 14:53     ` [PATCH v2] " Gao Xiang
@ 2023-06-01 14:55       ` Kelvin Zhang via Linux-erofs
  2023-06-01 15:18         ` Gao Xiang
  0 siblings, 1 reply; 6+ messages in thread
From: Kelvin Zhang via Linux-erofs @ 2023-06-01 14:55 UTC (permalink / raw)
  To: Gao Xiang; +Cc: linux-erofs

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

Looks good to me, please merge this patch

On Thu, Jun 1, 2023 at 10:54 AM Gao Xiang <hsiangkao@linux.alibaba.com>
wrote:

> Previously PAGE_SIZE was actually unset for most cases so that it was
> always hard-coded 4096.
>
> In order to set EROFS_MAX_BLOCK_SIZE correctly, let's detect the real
> page size when configuring and get rid of PAGE_SIZE.
>
> Cc: Kelvin Zhang <zhangkelvin@google.com>
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> ---
> change since v1:
>  - get rid of PAGE_SIZE (Kelvin);
>
>  configure.ac             | 38 ++++++++++++++++++++++++++++++++++++++
>  include/erofs/internal.h | 10 ++--------
>  lib/namei.c              |  2 +-
>  mkfs/main.c              |  4 ++--
>  4 files changed, 43 insertions(+), 11 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 4dbe86f..2ade490 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -59,6 +59,8 @@ AC_DEFUN([EROFS_UTILS_PARSE_DIRECTORY],
>   fi
>  ])
>
> +AC_ARG_VAR([MAX_BLOCK_SIZE], [The maximum block size which erofs-utils
> supports])
> +
>  AC_ARG_ENABLE([debug],
>      [AS_HELP_STRING([--enable-debug],
>                      [enable debugging mode @<:@default=no@:>@])],
> @@ -202,6 +204,35 @@ AC_CHECK_FUNCS(m4_flatten([
>         tmpfile64
>         utimensat]))
>
> +# Detect maximum block size if necessary
> +AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
> +  AC_CACHE_CHECK([sysconf (_SC_PAGESIZE)], [erofs_cv_max_block_size],
> +               AC_RUN_IFELSE([AC_LANG_PROGRAM(
> +[[
> +#include <unistd.h>
> +#include <stdio.h>
> +]],
> +[[
> +    int result;
> +    FILE *f;
> +
> +    result = sysconf(_SC_PAGESIZE);
> +    if (result < 0)
> +       return 1;
> +
> +    f = fopen("conftest.out", "w");
> +    if (!f)
> +       return 1;
> +
> +    fprintf(f, "%d", result);
> +    fclose(f);
> +    return 0;
> +]])],
> +                             [erofs_cv_max_block_size=`cat conftest.out`],
> +                             [],
> +                             []))
> +], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
> +
>  # Configure debug mode
>  AS_IF([test "x$enable_debug" != "xno"], [], [
>    dnl Turn off all assert checking.
> @@ -367,6 +398,13 @@ if test "x${have_liblzma}" = "xyes"; then
>    AC_SUBST([liblzma_CFLAGS])
>  fi
>
> +# Dump maximum block size
> +AS_IF([test "x$erofs_cv_max_block_size" = "x"],
> +      [$erofs_cv_max_block_size = 4096], [])
> +
> +AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],
> +                  [The maximum block size which erofs-utils supports])
> +
>  AC_CONFIG_FILES([Makefile
>                  man/Makefile
>                  lib/Makefile
> diff --git a/include/erofs/internal.h b/include/erofs/internal.h
> index b3d04be..370cfac 100644
> --- a/include/erofs/internal.h
> +++ b/include/erofs/internal.h
> @@ -27,16 +27,10 @@ typedef unsigned short umode_t;
>  #define PATH_MAX        4096    /* # chars in a path name including nul */
>  #endif
>
> -#ifndef PAGE_SHIFT
> -#define PAGE_SHIFT             (12)
> +#ifndef EROFS_MAX_BLOCK_SIZE
> +#define EROFS_MAX_BLOCK_SIZE   4096
>  #endif
>
> -#ifndef PAGE_SIZE
> -#define PAGE_SIZE              (1U << PAGE_SHIFT)
> -#endif
> -
> -#define EROFS_MAX_BLOCK_SIZE   PAGE_SIZE
> -
>  #define EROFS_ISLOTBITS                5
>  #define EROFS_SLOTSIZE         (1U << EROFS_ISLOTBITS)
>
> diff --git a/lib/namei.c b/lib/namei.c
> index 3d0cf93..3751741 100644
> --- a/lib/namei.c
> +++ b/lib/namei.c
> @@ -137,7 +137,7 @@ 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() != PAGE_SIZE)
> +               if (erofs_blksiz() != EROFS_MAX_BLOCK_SIZE)
>                         return -EOPNOTSUPP;
>                 return z_erofs_fill_inode(vi);
>         }
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 3ec4903..a6a2d0e 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -532,7 +532,7 @@ 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() != PAGE_SIZE) {
> +       if (cfg.c_compr_alg[0] && erofs_blksiz() != EROFS_MAX_BLOCK_SIZE) {
>                 erofs_err("compression is unsupported for now with block
> size %u",
>                           erofs_blksiz());
>                 return -EINVAL;
> @@ -670,7 +670,7 @@ static void erofs_mkfs_default_options(void)
>  {
>         cfg.c_showprogress = true;
>         cfg.c_legacy_compress = false;
> -       sbi.blkszbits = ilog2(PAGE_SIZE);
> +       sbi.blkszbits = ilog2(EROFS_MAX_BLOCK_SIZE);
>         sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
>         sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
>                              EROFS_FEATURE_COMPAT_MTIME;
> --
> 2.24.4
>
>

-- 
Sincerely,

Kelvin Zhang

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] erofs-utils: support detecting maximum block size
  2023-06-01 14:55       ` Kelvin Zhang via Linux-erofs
@ 2023-06-01 15:18         ` Gao Xiang
  0 siblings, 0 replies; 6+ messages in thread
From: Gao Xiang @ 2023-06-01 15:18 UTC (permalink / raw)
  To: Kelvin Zhang; +Cc: linux-erofs



On 2023/6/1 22:55, Kelvin Zhang wrote:
> Looks good to me, please merge this patch

done

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-01 15:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01  6:46 [PATCH] erofs-utils: support detecting maximum block size Gao Xiang
2023-06-01 12:48 ` Kelvin Zhang via Linux-erofs
2023-06-01 13:14   ` Gao Xiang
2023-06-01 14:53     ` [PATCH v2] " Gao Xiang
2023-06-01 14:55       ` Kelvin Zhang via Linux-erofs
2023-06-01 15:18         ` Gao Xiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).