* [PATCH] tune2fs:check return value of ext2fs_mmp_update2 in rewrite_metadata_checksums
@ 2022-11-29 6:58 lihaoxiang (F)
2022-12-09 3:36 ` lihaoxiang (F)
2023-01-26 3:50 ` Theodore Ts'o
0 siblings, 2 replies; 4+ messages in thread
From: lihaoxiang (F) @ 2022-11-29 6:58 UTC (permalink / raw
To: tytso; +Cc: linux-ext4, Zhiqiang Liu, linfeilong, louhongxiang, lijinlin (A)
Tune2fs hasn't consider about the result of executing ext2fs_mmp_update2
when it try to rewrite_metadata_checksums. If the ext2fs_mmp_update2
failed, multi-mount protection couldn't guard there has the only node
(i.e. this program) accessing this device in the meantime.
We solve this problem to verify the return value of ext2fs_mmp_update2.
It terminate rewrite_metadata_checksums and exit immediately if the
wrong error code returned.
Signed-off-by: lihaoxiang <lihaoxiang9@huawei.com>
---
misc/tune2fs.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index bed3d95..aa51864 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -930,7 +930,7 @@ static void rewrite_inodes(ext2_filsys fs, unsigned int flags)
ext2fs_free_mem(&ctx.ea_buf);
}
-static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
+static errcode_t rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
{
errcode_t retval;
dgrp_t i;
@@ -945,7 +945,9 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
rewrite_inodes(fs, flags);
ext2fs_mark_ib_dirty(fs);
ext2fs_mark_bb_dirty(fs);
- ext2fs_mmp_update2(fs, 1);
+ retval = ext2fs_mmp_update2(fs, 1);
+ if (retval)
+ return retval;
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
if (ext2fs_has_feature_metadata_csum(fs->super))
@@ -953,6 +955,7 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
else
fs->super->s_checksum_type = 0;
ext2fs_mark_super_dirty(fs);
+ return 0;
}
static void enable_uninit_bg(ext2_filsys fs)
@@ -3410,8 +3413,14 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
}
}
- if (rewrite_checksums)
- rewrite_metadata_checksums(fs, rewrite_checksums);
+ if (rewrite_checksums) {
+ retval = rewrite_metadata_checksums(fs, rewrite_checksums);
+ if (retval != 0) {
+ printf("Failed to rewrite metadata checksums\n");
+ rc = 1;
+ goto closefs;
+ }
+ }
if (l_flag)
list_super(sb);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] tune2fs:check return value of ext2fs_mmp_update2 in rewrite_metadata_checksums
2022-11-29 6:58 [PATCH] tune2fs:check return value of ext2fs_mmp_update2 in rewrite_metadata_checksums lihaoxiang (F)
@ 2022-12-09 3:36 ` lihaoxiang (F)
2023-01-10 9:02 ` lihaoxiang (F)
2023-01-26 3:50 ` Theodore Ts'o
1 sibling, 1 reply; 4+ messages in thread
From: lihaoxiang (F) @ 2022-12-09 3:36 UTC (permalink / raw
To: tytso; +Cc: linux-ext4, Zhiqiang Liu, linfeilong, louhongxiang, lijinlin (A)
friendly ping...
On 2022/11/29 14:58, lihaoxiang (F) wrote:
> Tune2fs hasn't consider about the result of executing ext2fs_mmp_update2
> when it try to rewrite_metadata_checksums. If the ext2fs_mmp_update2
> failed, multi-mount protection couldn't guard there has the only node
> (i.e. this program) accessing this device in the meantime.
>
> We solve this problem to verify the return value of ext2fs_mmp_update2.
> It terminate rewrite_metadata_checksums and exit immediately if the
> wrong error code returned.
>
> Signed-off-by: lihaoxiang <lihaoxiang9@huawei.com>
> ---
> misc/tune2fs.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> index bed3d95..aa51864 100644
> --- a/misc/tune2fs.c
> +++ b/misc/tune2fs.c
> @@ -930,7 +930,7 @@ static void rewrite_inodes(ext2_filsys fs, unsigned int flags)
> ext2fs_free_mem(&ctx.ea_buf);
> }
>
> -static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
> +static errcode_t rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
> {
> errcode_t retval;
> dgrp_t i;
> @@ -945,7 +945,9 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
> rewrite_inodes(fs, flags);
> ext2fs_mark_ib_dirty(fs);
> ext2fs_mark_bb_dirty(fs);
> - ext2fs_mmp_update2(fs, 1);
> + retval = ext2fs_mmp_update2(fs, 1);
> + if (retval)
> + return retval;
> fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
> fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
> if (ext2fs_has_feature_metadata_csum(fs->super))
> @@ -953,6 +955,7 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
> else
> fs->super->s_checksum_type = 0;
> ext2fs_mark_super_dirty(fs);
> + return 0;
> }
>
> static void enable_uninit_bg(ext2_filsys fs)
> @@ -3410,8 +3413,14 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
> }
> }
>
> - if (rewrite_checksums)
> - rewrite_metadata_checksums(fs, rewrite_checksums);
> + if (rewrite_checksums) {
> + retval = rewrite_metadata_checksums(fs, rewrite_checksums);
> + if (retval != 0) {
> + printf("Failed to rewrite metadata checksums\n");
> + rc = 1;
> + goto closefs;
> + }
> + }
>
> if (l_flag)
> list_super(sb);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tune2fs:check return value of ext2fs_mmp_update2 in rewrite_metadata_checksums
2022-12-09 3:36 ` lihaoxiang (F)
@ 2023-01-10 9:02 ` lihaoxiang (F)
0 siblings, 0 replies; 4+ messages in thread
From: lihaoxiang (F) @ 2023-01-10 9:02 UTC (permalink / raw
To: tytso; +Cc: linux-ext4, Zhiqiang Liu, linfeilong, louhongxiang, lijinlin (A)
friendly ping...
On 2022/12/9 11:36, lihaoxiang (F) wrote:
> friendly ping...
>
> On 2022/11/29 14:58, lihaoxiang (F) wrote:
>> Tune2fs hasn't consider about the result of executing ext2fs_mmp_update2
>> when it try to rewrite_metadata_checksums. If the ext2fs_mmp_update2
>> failed, multi-mount protection couldn't guard there has the only node
>> (i.e. this program) accessing this device in the meantime.
>>
>> We solve this problem to verify the return value of ext2fs_mmp_update2.
>> It terminate rewrite_metadata_checksums and exit immediately if the
>> wrong error code returned.
>>
>> Signed-off-by: lihaoxiang <lihaoxiang9@huawei.com>
>> ---
>> misc/tune2fs.c | 17 +++++++++++++----
>> 1 file changed, 13 insertions(+), 4 deletions(-)
>>
>> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
>> index bed3d95..aa51864 100644
>> --- a/misc/tune2fs.c
>> +++ b/misc/tune2fs.c
>> @@ -930,7 +930,7 @@ static void rewrite_inodes(ext2_filsys fs, unsigned int flags)
>> ext2fs_free_mem(&ctx.ea_buf);
>> }
>>
>> -static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
>> +static errcode_t rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
>> {
>> errcode_t retval;
>> dgrp_t i;
>> @@ -945,7 +945,9 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
>> rewrite_inodes(fs, flags);
>> ext2fs_mark_ib_dirty(fs);
>> ext2fs_mark_bb_dirty(fs);
>> - ext2fs_mmp_update2(fs, 1);
>> + retval = ext2fs_mmp_update2(fs, 1);
>> + if (retval)
>> + return retval;
>> fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
>> fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
>> if (ext2fs_has_feature_metadata_csum(fs->super))
>> @@ -953,6 +955,7 @@ static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
>> else
>> fs->super->s_checksum_type = 0;
>> ext2fs_mark_super_dirty(fs);
>> + return 0;
>> }
>>
>> static void enable_uninit_bg(ext2_filsys fs)
>> @@ -3410,8 +3413,14 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
>> }
>> }
>>
>> - if (rewrite_checksums)
>> - rewrite_metadata_checksums(fs, rewrite_checksums);
>> + if (rewrite_checksums) {
>> + retval = rewrite_metadata_checksums(fs, rewrite_checksums);
>> + if (retval != 0) {
>> + printf("Failed to rewrite metadata checksums\n");
>> + rc = 1;
>> + goto closefs;
>> + }
>> + }
>>
>> if (l_flag)
>> list_super(sb);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tune2fs:check return value of ext2fs_mmp_update2 in rewrite_metadata_checksums
2022-11-29 6:58 [PATCH] tune2fs:check return value of ext2fs_mmp_update2 in rewrite_metadata_checksums lihaoxiang (F)
2022-12-09 3:36 ` lihaoxiang (F)
@ 2023-01-26 3:50 ` Theodore Ts'o
1 sibling, 0 replies; 4+ messages in thread
From: Theodore Ts'o @ 2023-01-26 3:50 UTC (permalink / raw
To: lihaoxiang (F)
Cc: Theodore Ts'o, louhongxiang, linux-ext4, linfeilong,
Zhiqiang Liu, lijinlin (A)
On Tue, 29 Nov 2022 14:58:12 +0800, lihaoxiang (F) wrote:
> Tune2fs hasn't consider about the result of executing ext2fs_mmp_update2
> when it try to rewrite_metadata_checksums. If the ext2fs_mmp_update2
> failed, multi-mount protection couldn't guard there has the only node
> (i.e. this program) accessing this device in the meantime.
>
> We solve this problem to verify the return value of ext2fs_mmp_update2.
> It terminate rewrite_metadata_checksums and exit immediately if the
> wrong error code returned.
>
> [...]
Applied, thanks!
[1/1] tune2fs:check return value of ext2fs_mmp_update2 in rewrite_metadata_checksums
(no commit info)
Best regards,
--
Theodore Ts'o <tytso@mit.edu>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-26 3:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-29 6:58 [PATCH] tune2fs:check return value of ext2fs_mmp_update2 in rewrite_metadata_checksums lihaoxiang (F)
2022-12-09 3:36 ` lihaoxiang (F)
2023-01-10 9:02 ` lihaoxiang (F)
2023-01-26 3:50 ` Theodore Ts'o
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 read-only IMAP folder(s) and NNTP newsgroup(s).