All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tune2fs: allow disabling casefold feature
@ 2022-07-07 16:54 Slava Bacherikov
  2022-07-07 18:30 ` Eric Biggers
  0 siblings, 1 reply; 10+ messages in thread
From: Slava Bacherikov @ 2022-07-07 16:54 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, krisman, Slava Bacherikov

Casefold can be safely disabled if there are no directories with +F
attribute ( EXT4_CASEFOLD_FL ). This checks all inodes for that flag and in
case there isn't any, it disables casefold FS feature. When FS has
directories with +F attributes, user could convert these directories,
probably by mounting FS and executing some script or by doing it
manually. Afterwards, it would be possible to disable casefold FS flag
via tune2fs.

Signed-off-by: Slava Bacherikov <slava@bacher09.org>
---
 misc/tune2fs.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 6c162ba5..1c5c2969 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -204,7 +204,8 @@ static __u32 clear_ok_features[3] = {
 		EXT4_FEATURE_INCOMPAT_FLEX_BG |
 		EXT4_FEATURE_INCOMPAT_MMP |
 		EXT4_FEATURE_INCOMPAT_64BIT |
-		EXT4_FEATURE_INCOMPAT_CSUM_SEED,
+		EXT4_FEATURE_INCOMPAT_CSUM_SEED |
+		EXT4_FEATURE_INCOMPAT_CASEFOLD,
 	/* R/O compat */
 	EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
 		EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
@@ -1020,6 +1021,41 @@ out:
 	return retval;
 }
 
+static int has_casefold_inode(ext2_filsys fs)
+{
+	int length = EXT2_INODE_SIZE(fs->super);
+	struct ext2_inode *inode = NULL;
+	ext2_inode_scan	scan;
+	errcode_t	retval;
+	ext2_ino_t	ino;
+	int found_casefold = 0;
+
+	retval = ext2fs_get_mem(length, &inode);
+	if (retval)
+		fatal_err(retval, "while allocating memory");
+
+	retval = ext2fs_open_inode_scan(fs, 0, &scan);
+	if (retval)
+		fatal_err(retval, "while opening inode scan");
+
+	do {
+		retval = ext2fs_get_next_inode_full(scan, &ino, inode, length);
+		if (retval)
+			fatal_err(retval, "while getting next inode");
+		if (!ino)
+			break;
+
+		if(inode->i_flags & EXT4_CASEFOLD_FL) {
+			found_casefold = 1;
+			break;
+		}
+	} while(1);
+
+	ext2fs_free_mem(&inode);
+	ext2fs_close_inode_scan(scan);
+	return found_casefold;
+}
+
 static errcode_t disable_uninit_bg(ext2_filsys fs, __u32 csum_feature_flag)
 {
 	struct ext2_group_desc *gd;
@@ -1554,6 +1590,20 @@ mmp_error:
 		enabling_casefold = 1;
 	}
 
+	if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
+		if (mount_flags & EXT2_MF_MOUNTED) {
+			fputs(_("The casefold feature may only be disabled when "
+				"the filesystem is unmounted.\n"), stderr);
+			return 1;
+		}
+		if (has_casefold_inode(fs)) {
+			fputs(_("The casefold feature couldn't be disabled when "
+					"there are inodes with +F flag.\n"), stderr);
+			return 1;
+		}
+		enabling_casefold = 0;
+	}
+
 	if (FEATURE_ON(E2P_FEATURE_INCOMPAT,
 		EXT4_FEATURE_INCOMPAT_CSUM_SEED)) {
 		if (!ext2fs_has_feature_metadata_csum(sb)) {

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

* Re: [PATCH] tune2fs: allow disabling casefold feature
  2022-07-07 16:54 [PATCH] tune2fs: allow disabling casefold feature Slava Bacherikov
@ 2022-07-07 18:30 ` Eric Biggers
  2022-07-07 19:04   ` [PATCH v2] " Slava Bacherikov
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Biggers @ 2022-07-07 18:30 UTC (permalink / raw)
  To: Slava Bacherikov; +Cc: tytso, linux-ext4, krisman

On Thu, Jul 07, 2022 at 07:54:00PM +0300, Slava Bacherikov wrote:
> Casefold can be safely disabled if there are no directories with +F
> attribute ( EXT4_CASEFOLD_FL ). This checks all inodes for that flag and in
> case there isn't any, it disables casefold FS feature. When FS has
> directories with +F attributes, user could convert these directories,
> probably by mounting FS and executing some script or by doing it
> manually. Afterwards, it would be possible to disable casefold FS flag
> via tune2fs.
> 
> Signed-off-by: Slava Bacherikov <slava@bacher09.org>

Can you please update the man page misc/tune2fs.8.in as well?

- Eric

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

* [PATCH v2] tune2fs: allow disabling casefold feature
  2022-07-07 18:30 ` Eric Biggers
@ 2022-07-07 19:04   ` Slava Bacherikov
  2022-07-07 19:50     ` Eric Biggers
  0 siblings, 1 reply; 10+ messages in thread
From: Slava Bacherikov @ 2022-07-07 19:04 UTC (permalink / raw)
  To: ebiggers; +Cc: tytso, linux-ext4, krisman, Slava Bacherikov

Casefold can be safely disabled if there are no directories with +F
attribute ( EXT4_CASEFOLD_FL ). This checks all inodes for that flag and in
case there isn't any, it disables casefold FS feature. When FS has
directories with +F attributes, user could convert these directories,
probably by mounting FS and executing some script or by doing it
manually. Afterwards, it would be possible to disable casefold FS flag
via tune2fs.

Signed-off-by: Slava Bacherikov <slava@bacher09.org>
---
 misc/tune2fs.8.in |  6 ++++--
 misc/tune2fs.c    | 52 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in
index 628dcdc0..8ef28860 100644
--- a/misc/tune2fs.8.in
+++ b/misc/tune2fs.8.in
@@ -593,8 +593,10 @@ Enable the file system to be larger than 2^32 blocks.
 .TP
 .B casefold
 Enable support for file system level casefolding.
-.B Tune2fs
-currently only supports setting this file system feature.
+The option could be disabled only if filesystem has no
+directories with
+.B F
+attribute.
 .TP
 .B dir_index
 Use hashed b-trees to speed up lookups for large directories.
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 6c162ba5..1c5c2969 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -204,7 +204,8 @@ static __u32 clear_ok_features[3] = {
 		EXT4_FEATURE_INCOMPAT_FLEX_BG |
 		EXT4_FEATURE_INCOMPAT_MMP |
 		EXT4_FEATURE_INCOMPAT_64BIT |
-		EXT4_FEATURE_INCOMPAT_CSUM_SEED,
+		EXT4_FEATURE_INCOMPAT_CSUM_SEED |
+		EXT4_FEATURE_INCOMPAT_CASEFOLD,
 	/* R/O compat */
 	EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
 		EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
@@ -1020,6 +1021,41 @@ out:
 	return retval;
 }
 
+static int has_casefold_inode(ext2_filsys fs)
+{
+	int length = EXT2_INODE_SIZE(fs->super);
+	struct ext2_inode *inode = NULL;
+	ext2_inode_scan	scan;
+	errcode_t	retval;
+	ext2_ino_t	ino;
+	int found_casefold = 0;
+
+	retval = ext2fs_get_mem(length, &inode);
+	if (retval)
+		fatal_err(retval, "while allocating memory");
+
+	retval = ext2fs_open_inode_scan(fs, 0, &scan);
+	if (retval)
+		fatal_err(retval, "while opening inode scan");
+
+	do {
+		retval = ext2fs_get_next_inode_full(scan, &ino, inode, length);
+		if (retval)
+			fatal_err(retval, "while getting next inode");
+		if (!ino)
+			break;
+
+		if(inode->i_flags & EXT4_CASEFOLD_FL) {
+			found_casefold = 1;
+			break;
+		}
+	} while(1);
+
+	ext2fs_free_mem(&inode);
+	ext2fs_close_inode_scan(scan);
+	return found_casefold;
+}
+
 static errcode_t disable_uninit_bg(ext2_filsys fs, __u32 csum_feature_flag)
 {
 	struct ext2_group_desc *gd;
@@ -1554,6 +1590,20 @@ mmp_error:
 		enabling_casefold = 1;
 	}
 
+	if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
+		if (mount_flags & EXT2_MF_MOUNTED) {
+			fputs(_("The casefold feature may only be disabled when "
+				"the filesystem is unmounted.\n"), stderr);
+			return 1;
+		}
+		if (has_casefold_inode(fs)) {
+			fputs(_("The casefold feature couldn't be disabled when "
+					"there are inodes with +F flag.\n"), stderr);
+			return 1;
+		}
+		enabling_casefold = 0;
+	}
+
 	if (FEATURE_ON(E2P_FEATURE_INCOMPAT,
 		EXT4_FEATURE_INCOMPAT_CSUM_SEED)) {
 		if (!ext2fs_has_feature_metadata_csum(sb)) {

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

* Re: [PATCH v2] tune2fs: allow disabling casefold feature
  2022-07-07 19:04   ` [PATCH v2] " Slava Bacherikov
@ 2022-07-07 19:50     ` Eric Biggers
  2022-07-07 20:16       ` Gabriel Krisman Bertazi
                         ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Eric Biggers @ 2022-07-07 19:50 UTC (permalink / raw)
  To: Slava Bacherikov; +Cc: tytso, linux-ext4, krisman

On Thu, Jul 07, 2022 at 10:04:56PM +0300, Slava Bacherikov wrote:
> diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in
> index 628dcdc0..8ef28860 100644
> --- a/misc/tune2fs.8.in
> +++ b/misc/tune2fs.8.in
> @@ -593,8 +593,10 @@ Enable the file system to be larger than 2^32 blocks.
>  .TP
>  .B casefold
>  Enable support for file system level casefolding.
> -.B Tune2fs
> -currently only supports setting this file system feature.
> +The option could be disabled only if filesystem has no
> +directories with
> +.B F
> +attribute.

Please use present tense: "could" => "can".  Otherwise this can be interpreted
as the opposite of what you meant.

Also, "cleared" instead of "disabled", to be consistent with the rest of the
page.

>  static errcode_t disable_uninit_bg(ext2_filsys fs, __u32 csum_feature_flag)
>  {
>  	struct ext2_group_desc *gd;
> @@ -1554,6 +1590,20 @@ mmp_error:
>  		enabling_casefold = 1;
>  	}
>  
> +	if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
> +		if (mount_flags & EXT2_MF_MOUNTED) {
> +			fputs(_("The casefold feature may only be disabled when "
> +				"the filesystem is unmounted.\n"), stderr);
> +			return 1;
> +		}
> +		if (has_casefold_inode(fs)) {
> +			fputs(_("The casefold feature couldn't be disabled when "
> +					"there are inodes with +F flag.\n"), stderr);
> +			return 1;
> +		}
> +		enabling_casefold = 0;

Likewise, "couldn't" => "can't".

Also, what are the semantics of disabling casefold, exactly?  Do the encoding
and encoding flags fields in the superblock also get cleared?

- Eric

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

* Re: [PATCH v2] tune2fs: allow disabling casefold feature
  2022-07-07 19:50     ` Eric Biggers
@ 2022-07-07 20:16       ` Gabriel Krisman Bertazi
  2022-07-07 20:41       ` [PATCH] " Slava Bacherikov
  2022-07-07 20:51       ` [PATCH v2] " Slava Bacherikov
  2 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2022-07-07 20:16 UTC (permalink / raw)
  To: Eric Biggers; +Cc: Slava Bacherikov, tytso, linux-ext4

Eric Biggers <ebiggers@kernel.org> writes:

> On Thu, Jul 07, 2022 at 10:04:56PM +0300, Slava Bacherikov wrote:
>> +	if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
>> +		if (mount_flags & EXT2_MF_MOUNTED) {
>> +			fputs(_("The casefold feature may only be disabled when "
>> +				"the filesystem is unmounted.\n"), stderr);
>> +			return 1;
>> +		}
>> +		if (has_casefold_inode(fs)) {
>> +			fputs(_("The casefold feature couldn't be disabled when "
>> +					"there are inodes with +F flag.\n"), stderr);
>> +			return 1;
>> +		}
>> +		enabling_casefold = 0;
>
> Likewise, "couldn't" => "can't".
>
> Also, what are the semantics of disabling casefold, exactly?  Do the encoding
> and encoding flags fields in the superblock also get cleared?

The kernel is able to ignore the non-zero encoding field if the feature
is not set, but we definitely don't want to rely on that.  The patch
should explicitly zero both s_encoding and s_encoding_flags.

-- 
Gabriel Krisman Bertazi

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

* [PATCH] tune2fs: allow disabling casefold feature
  2022-07-07 19:50     ` Eric Biggers
  2022-07-07 20:16       ` Gabriel Krisman Bertazi
@ 2022-07-07 20:41       ` Slava Bacherikov
  2022-07-07 21:10         ` Gabriel Krisman Bertazi
  2022-07-07 20:51       ` [PATCH v2] " Slava Bacherikov
  2 siblings, 1 reply; 10+ messages in thread
From: Slava Bacherikov @ 2022-07-07 20:41 UTC (permalink / raw)
  To: ebiggers; +Cc: tytso, linux-ext4, krisman, Slava Bacherikov

Casefold can be safely disabled if there are no directories with +F
attribute ( EXT4_CASEFOLD_FL ). This checks all inodes for that flag and in
case there isn't any, it disables casefold FS feature. When FS has
directories with +F attributes, user could convert these directories,
probably by mounting FS and executing some script or by doing it
manually. Afterwards, it would be possible to disable casefold FS flag
via tune2fs.

Signed-off-by: Slava Bacherikov <slava@bacher09.org>
---
 misc/tune2fs.8.in |  6 ++++--
 misc/tune2fs.c    | 54 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in
index 628dcdc0..dcf108c1 100644
--- a/misc/tune2fs.8.in
+++ b/misc/tune2fs.8.in
@@ -593,8 +593,10 @@ Enable the file system to be larger than 2^32 blocks.
 .TP
 .B casefold
 Enable support for file system level casefolding.
-.B Tune2fs
-currently only supports setting this file system feature.
+The option can be cleared only if filesystem has no
+directories with
+.B F
+attribute.
 .TP
 .B dir_index
 Use hashed b-trees to speed up lookups for large directories.
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 6c162ba5..a8355619 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -204,7 +204,8 @@ static __u32 clear_ok_features[3] = {
 		EXT4_FEATURE_INCOMPAT_FLEX_BG |
 		EXT4_FEATURE_INCOMPAT_MMP |
 		EXT4_FEATURE_INCOMPAT_64BIT |
-		EXT4_FEATURE_INCOMPAT_CSUM_SEED,
+		EXT4_FEATURE_INCOMPAT_CSUM_SEED |
+		EXT4_FEATURE_INCOMPAT_CASEFOLD,
 	/* R/O compat */
 	EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
 		EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
@@ -1020,6 +1021,41 @@ out:
 	return retval;
 }
 
+static int has_casefold_inode(ext2_filsys fs)
+{
+	int length = EXT2_INODE_SIZE(fs->super);
+	struct ext2_inode *inode = NULL;
+	ext2_inode_scan	scan;
+	errcode_t	retval;
+	ext2_ino_t	ino;
+	int found_casefold = 0;
+
+	retval = ext2fs_get_mem(length, &inode);
+	if (retval)
+		fatal_err(retval, "while allocating memory");
+
+	retval = ext2fs_open_inode_scan(fs, 0, &scan);
+	if (retval)
+		fatal_err(retval, "while opening inode scan");
+
+	do {
+		retval = ext2fs_get_next_inode_full(scan, &ino, inode, length);
+		if (retval)
+			fatal_err(retval, "while getting next inode");
+		if (!ino)
+			break;
+
+		if(inode->i_flags & EXT4_CASEFOLD_FL) {
+			found_casefold = 1;
+			break;
+		}
+	} while(1);
+
+	ext2fs_free_mem(&inode);
+	ext2fs_close_inode_scan(scan);
+	return found_casefold;
+}
+
 static errcode_t disable_uninit_bg(ext2_filsys fs, __u32 csum_feature_flag)
 {
 	struct ext2_group_desc *gd;
@@ -1554,6 +1590,22 @@ mmp_error:
 		enabling_casefold = 1;
 	}
 
+	if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
+		if (mount_flags & EXT2_MF_MOUNTED) {
+			fputs(_("The casefold feature may only be disabled when "
+				"the filesystem is unmounted.\n"), stderr);
+			return 1;
+		}
+		if (has_casefold_inode(fs)) {
+			fputs(_("The casefold feature can't be cleared when "
+					"there are inodes with +F flag.\n"), stderr);
+			return 1;
+		}
+		fs->super->s_encoding = 0;
+		fs->super->s_encoding_flags = 0;
+		enabling_casefold = 0;
+	}
+
 	if (FEATURE_ON(E2P_FEATURE_INCOMPAT,
 		EXT4_FEATURE_INCOMPAT_CSUM_SEED)) {
 		if (!ext2fs_has_feature_metadata_csum(sb)) {

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

* Re: [PATCH v2] tune2fs: allow disabling casefold feature
  2022-07-07 19:50     ` Eric Biggers
  2022-07-07 20:16       ` Gabriel Krisman Bertazi
  2022-07-07 20:41       ` [PATCH] " Slava Bacherikov
@ 2022-07-07 20:51       ` Slava Bacherikov
  2 siblings, 0 replies; 10+ messages in thread
From: Slava Bacherikov @ 2022-07-07 20:51 UTC (permalink / raw)
  To: Eric Biggers; +Cc: tytso, linux-ext4, krisman



07.07.2022 22:50, Eric Biggers wrote:
> On Thu, Jul 07, 2022 at 10:04:56PM +0300, Slava Bacherikov wrote:

> Also, what are the semantics of disabling casefold, exactly?  Do the encoding
> and encoding flags fields in the superblock also get cleared?
> 
> - Eric

Sorry, I've totally missed that. It worked just fine on a kernel 
compiled without casefold, because kernel is ignoring encoding if there 
is no casefold flag. And dumpe2fs wasn't showing character encoding on 
fs that had no casefold feature.

Anyway, I've already updated patch.

--
Slava Bacherikov

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

* Re: [PATCH] tune2fs: allow disabling casefold feature
  2022-07-07 20:41       ` [PATCH] " Slava Bacherikov
@ 2022-07-07 21:10         ` Gabriel Krisman Bertazi
  2022-07-08 12:26           ` [PATCH v4] " Slava Bacherikov
  0 siblings, 1 reply; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2022-07-07 21:10 UTC (permalink / raw)
  To: Slava Bacherikov; +Cc: ebiggers, tytso, linux-ext4

Slava Bacherikov <slava@bacher09.org> writes:

> Casefold can be safely disabled if there are no directories with +F
> attribute ( EXT4_CASEFOLD_FL ). This checks all inodes for that flag and in
> case there isn't any, it disables casefold FS feature. When FS has
> directories with +F attributes, user could convert these directories,
> probably by mounting FS and executing some script or by doing it
> manually. Afterwards, it would be possible to disable casefold FS flag
> via tune2fs.
>
> Signed-off-by: Slava Bacherikov <slava@bacher09.org>

I think this is a safe thing to do, gave it a quick spin and the patch
now looks good to me.

Reviewed-by: Gabriel Krisman Bertazi <krisman@collabora.com>

Thank you,

> ---
>  misc/tune2fs.8.in |  6 ++++--
>  misc/tune2fs.c    | 54 ++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 57 insertions(+), 3 deletions(-)
>
> diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in
> index 628dcdc0..dcf108c1 100644
> --- a/misc/tune2fs.8.in
> +++ b/misc/tune2fs.8.in
> @@ -593,8 +593,10 @@ Enable the file system to be larger than 2^32 blocks.
>  .TP
>  .B casefold
>  Enable support for file system level casefolding.
> -.B Tune2fs
> -currently only supports setting this file system feature.
> +The option can be cleared only if filesystem has no
> +directories with
> +.B F
> +attribute.
>  .TP
>  .B dir_index
>  Use hashed b-trees to speed up lookups for large directories.
> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> index 6c162ba5..a8355619 100644
> --- a/misc/tune2fs.c
> +++ b/misc/tune2fs.c
> @@ -204,7 +204,8 @@ static __u32 clear_ok_features[3] = {
>  		EXT4_FEATURE_INCOMPAT_FLEX_BG |
>  		EXT4_FEATURE_INCOMPAT_MMP |
>  		EXT4_FEATURE_INCOMPAT_64BIT |
> -		EXT4_FEATURE_INCOMPAT_CSUM_SEED,
> +		EXT4_FEATURE_INCOMPAT_CSUM_SEED |
> +		EXT4_FEATURE_INCOMPAT_CASEFOLD,
>  	/* R/O compat */
>  	EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
>  		EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
> @@ -1020,6 +1021,41 @@ out:
>  	return retval;
>  }
>  
> +static int has_casefold_inode(ext2_filsys fs)
> +{
> +	int length = EXT2_INODE_SIZE(fs->super);
> +	struct ext2_inode *inode = NULL;
> +	ext2_inode_scan	scan;
> +	errcode_t	retval;
> +	ext2_ino_t	ino;
> +	int found_casefold = 0;
> +
> +	retval = ext2fs_get_mem(length, &inode);
> +	if (retval)
> +		fatal_err(retval, "while allocating memory");
> +
> +	retval = ext2fs_open_inode_scan(fs, 0, &scan);
> +	if (retval)
> +		fatal_err(retval, "while opening inode scan");
> +
> +	do {
> +		retval = ext2fs_get_next_inode_full(scan, &ino, inode, length);
> +		if (retval)
> +			fatal_err(retval, "while getting next inode");
> +		if (!ino)
> +			break;
> +
> +		if(inode->i_flags & EXT4_CASEFOLD_FL) {
> +			found_casefold = 1;
> +			break;
> +		}
> +	} while(1);
> +
> +	ext2fs_free_mem(&inode);
> +	ext2fs_close_inode_scan(scan);
> +	return found_casefold;
> +}
> +
>  static errcode_t disable_uninit_bg(ext2_filsys fs, __u32 csum_feature_flag)
>  {
>  	struct ext2_group_desc *gd;
> @@ -1554,6 +1590,22 @@ mmp_error:
>  		enabling_casefold = 1;
>  	}
>  
> +	if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
> +		if (mount_flags & EXT2_MF_MOUNTED) {
> +			fputs(_("The casefold feature may only be disabled when "
> +				"the filesystem is unmounted.\n"), stderr);
> +			return 1;
> +		}
> +		if (has_casefold_inode(fs)) {
> +			fputs(_("The casefold feature can't be cleared when "
> +					"there are inodes with +F flag.\n"), stderr);
> +			return 1;
> +		}
> +		fs->super->s_encoding = 0;
> +		fs->super->s_encoding_flags = 0;
> +		enabling_casefold = 0;
> +	}
> +
>  	if (FEATURE_ON(E2P_FEATURE_INCOMPAT,
>  		EXT4_FEATURE_INCOMPAT_CSUM_SEED)) {
>  		if (!ext2fs_has_feature_metadata_csum(sb)) {

-- 
Gabriel Krisman Bertazi

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

* [PATCH v4] tune2fs: allow disabling casefold feature
  2022-07-07 21:10         ` Gabriel Krisman Bertazi
@ 2022-07-08 12:26           ` Slava Bacherikov
  2022-08-13 14:58             ` Theodore Ts'o
  0 siblings, 1 reply; 10+ messages in thread
From: Slava Bacherikov @ 2022-07-08 12:26 UTC (permalink / raw)
  To: krisman; +Cc: ebiggers, tytso, linux-ext4, Slava Bacherikov

Casefold can be safely disabled if there are no directories with +F
attribute ( EXT4_CASEFOLD_FL ). This checks all inodes for that flag and in
case there isn't any, it disables casefold FS feature. When FS has
directories with +F attributes, user could convert these directories,
probably by mounting FS and executing some script or by doing it
manually. Afterwards, it would be possible to disable casefold FS flag
via tune2fs.

Signed-off-by: Slava Bacherikov <slava@bacher09.org>
Reviewed-by: Gabriel Krisman Bertazi <krisman@collabora.com>
---
 misc/tune2fs.8.in |  6 ++++--
 misc/tune2fs.c    | 54 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in
index 628dcdc0..dcf108c1 100644
--- a/misc/tune2fs.8.in
+++ b/misc/tune2fs.8.in
@@ -593,8 +593,10 @@ Enable the file system to be larger than 2^32 blocks.
 .TP
 .B casefold
 Enable support for file system level casefolding.
-.B Tune2fs
-currently only supports setting this file system feature.
+The option can be cleared only if filesystem has no
+directories with
+.B F
+attribute.
 .TP
 .B dir_index
 Use hashed b-trees to speed up lookups for large directories.
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 6c162ba5..a8355619 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -204,7 +204,8 @@ static __u32 clear_ok_features[3] = {
 		EXT4_FEATURE_INCOMPAT_FLEX_BG |
 		EXT4_FEATURE_INCOMPAT_MMP |
 		EXT4_FEATURE_INCOMPAT_64BIT |
-		EXT4_FEATURE_INCOMPAT_CSUM_SEED,
+		EXT4_FEATURE_INCOMPAT_CSUM_SEED |
+		EXT4_FEATURE_INCOMPAT_CASEFOLD,
 	/* R/O compat */
 	EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
 		EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
@@ -1020,6 +1021,41 @@ out:
 	return retval;
 }
 
+static int has_casefold_inode(ext2_filsys fs)
+{
+	int length = EXT2_INODE_SIZE(fs->super);
+	struct ext2_inode *inode = NULL;
+	ext2_inode_scan	scan;
+	errcode_t	retval;
+	ext2_ino_t	ino;
+	int found_casefold = 0;
+
+	retval = ext2fs_get_mem(length, &inode);
+	if (retval)
+		fatal_err(retval, "while allocating memory");
+
+	retval = ext2fs_open_inode_scan(fs, 0, &scan);
+	if (retval)
+		fatal_err(retval, "while opening inode scan");
+
+	do {
+		retval = ext2fs_get_next_inode_full(scan, &ino, inode, length);
+		if (retval)
+			fatal_err(retval, "while getting next inode");
+		if (!ino)
+			break;
+
+		if(inode->i_flags & EXT4_CASEFOLD_FL) {
+			found_casefold = 1;
+			break;
+		}
+	} while(1);
+
+	ext2fs_free_mem(&inode);
+	ext2fs_close_inode_scan(scan);
+	return found_casefold;
+}
+
 static errcode_t disable_uninit_bg(ext2_filsys fs, __u32 csum_feature_flag)
 {
 	struct ext2_group_desc *gd;
@@ -1554,6 +1590,22 @@ mmp_error:
 		enabling_casefold = 1;
 	}
 
+	if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD)) {
+		if (mount_flags & EXT2_MF_MOUNTED) {
+			fputs(_("The casefold feature may only be disabled when "
+				"the filesystem is unmounted.\n"), stderr);
+			return 1;
+		}
+		if (has_casefold_inode(fs)) {
+			fputs(_("The casefold feature can't be cleared when "
+					"there are inodes with +F flag.\n"), stderr);
+			return 1;
+		}
+		fs->super->s_encoding = 0;
+		fs->super->s_encoding_flags = 0;
+		enabling_casefold = 0;
+	}
+
 	if (FEATURE_ON(E2P_FEATURE_INCOMPAT,
 		EXT4_FEATURE_INCOMPAT_CSUM_SEED)) {
 		if (!ext2fs_has_feature_metadata_csum(sb)) {

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

* Re: [PATCH v4] tune2fs: allow disabling casefold feature
  2022-07-08 12:26           ` [PATCH v4] " Slava Bacherikov
@ 2022-08-13 14:58             ` Theodore Ts'o
  0 siblings, 0 replies; 10+ messages in thread
From: Theodore Ts'o @ 2022-08-13 14:58 UTC (permalink / raw)
  To: slava, krisman; +Cc: Theodore Ts'o, linux-ext4, ebiggers

On Fri, 8 Jul 2022 15:26:58 +0300, Slava Bacherikov wrote:
> Casefold can be safely disabled if there are no directories with +F
> attribute ( EXT4_CASEFOLD_FL ). This checks all inodes for that flag and in
> case there isn't any, it disables casefold FS feature. When FS has
> directories with +F attributes, user could convert these directories,
> probably by mounting FS and executing some script or by doing it
> manually. Afterwards, it would be possible to disable casefold FS flag
> via tune2fs.
> 
> [...]

Applied, thanks!

[1/1] tune2fs: allow disabling casefold feature
      commit: 47f9c3c00bbfdef4a64f400d1c95d9140aab3199

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

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

end of thread, other threads:[~2022-08-13 14:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07 16:54 [PATCH] tune2fs: allow disabling casefold feature Slava Bacherikov
2022-07-07 18:30 ` Eric Biggers
2022-07-07 19:04   ` [PATCH v2] " Slava Bacherikov
2022-07-07 19:50     ` Eric Biggers
2022-07-07 20:16       ` Gabriel Krisman Bertazi
2022-07-07 20:41       ` [PATCH] " Slava Bacherikov
2022-07-07 21:10         ` Gabriel Krisman Bertazi
2022-07-08 12:26           ` [PATCH v4] " Slava Bacherikov
2022-08-13 14:58             ` Theodore Ts'o
2022-07-07 20:51       ` [PATCH v2] " Slava Bacherikov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.