diff mbox series

[2/7] btrfs-progs: check/original: Add inode mode check

Message ID 20190325082253.19583-3-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: check: Check and repair invalid free space cahce inode mode | expand

Commit Message

Qu Wenruo March 25, 2019, 8:22 a.m. UTC
Just like lowmem mode, check inode mode, specially for S_IFMT bits and
beyond.

Please note that, this check only applies to inodes in fs/subvol trees.
It doesn't apply to free space cache inodes.

Reported-by: Thorsten Hirsch <t.hirsch@web.de>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/main.c          | 5 +++++
 check/mode-original.h | 1 +
 2 files changed, 6 insertions(+)

Comments

Nikolay Borisov March 25, 2019, 3:43 p.m. UTC | #1
On 25.03.19 г. 10:22 ч., Qu Wenruo wrote:
> Just like lowmem mode, check inode mode, specially for S_IFMT bits and
> beyond.
> 
> Please note that, this check only applies to inodes in fs/subvol trees.
> It doesn't apply to free space cache inodes.
> 
> Reported-by: Thorsten Hirsch <t.hirsch@web.de>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  check/main.c          | 5 +++++
>  check/mode-original.h | 1 +
>  2 files changed, 6 insertions(+)
> 
> diff --git a/check/main.c b/check/main.c
> index 7547209c5604..553c93caa2c9 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -616,6 +616,9 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
>  		fprintf(stderr, ", odd inode flags");
>  	if (errors & I_ERR_INLINE_RAM_BYTES_WRONG)
>  		fprintf(stderr, ", invalid inline ram bytes");
> +	if (errors & I_ERR_INVALID_IMODE)
> +		fprintf(stderr, ", invalid inode mode bit 0%o",
> +			rec->imode & ~07777);
>  	fprintf(stderr, "\n");
>  	/* Print the orphan extents if needed */
>  	if (errors & I_ERR_FILE_EXTENT_ORPHAN)
> @@ -811,6 +814,8 @@ static void maybe_free_inode_rec(struct cache_tree *inode_cache,
>  	if (!rec->checked || rec->merging)
>  		return;
>  
> +	if (!is_valid_imode(rec->imode))
> +		rec->errors |= I_ERR_INVALID_IMODE;

should this check actually be moved before the call to imode_to_type.
Because if the mode is busted this means we could potentially get
REF_ERR_FILETYPE_UNMATCH error?  I.e this check should really fail
before anything else ?

>  	if (S_ISDIR(rec->imode)) {
>  		if (rec->found_size != rec->isize)
>  			rec->errors |= I_ERR_DIR_ISIZE_WRONG;
> diff --git a/check/mode-original.h b/check/mode-original.h
> index 25ca274118a7..e40a12930a6f 100644
> --- a/check/mode-original.h
> +++ b/check/mode-original.h
> @@ -189,6 +189,7 @@ struct file_extent_hole {
>  #define I_ERR_ODD_INODE_FLAGS		(1 << 16)
>  #define I_ERR_INLINE_RAM_BYTES_WRONG	(1 << 17)
>  #define I_ERR_MISMATCH_DIR_HASH		(1 << 18)
> +#define I_ERR_INVALID_IMODE		(1 << 19)
>  
>  struct inode_record {
>  	struct list_head backrefs;
>
Qu Wenruo March 25, 2019, 10:59 p.m. UTC | #2
On 2019/3/25 下午11:43, Nikolay Borisov wrote:
>
>
> On 25.03.19 г. 10:22 ч., Qu Wenruo wrote:
>> Just like lowmem mode, check inode mode, specially for S_IFMT bits and
>> beyond.
>>
>> Please note that, this check only applies to inodes in fs/subvol trees.
>> It doesn't apply to free space cache inodes.
>>
>> Reported-by: Thorsten Hirsch <t.hirsch@web.de>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>  check/main.c          | 5 +++++
>>  check/mode-original.h | 1 +
>>  2 files changed, 6 insertions(+)
>>
>> diff --git a/check/main.c b/check/main.c
>> index 7547209c5604..553c93caa2c9 100644
>> --- a/check/main.c
>> +++ b/check/main.c
>> @@ -616,6 +616,9 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
>>  		fprintf(stderr, ", odd inode flags");
>>  	if (errors & I_ERR_INLINE_RAM_BYTES_WRONG)
>>  		fprintf(stderr, ", invalid inline ram bytes");
>> +	if (errors & I_ERR_INVALID_IMODE)
>> +		fprintf(stderr, ", invalid inode mode bit 0%o",
>> +			rec->imode & ~07777);
>>  	fprintf(stderr, "\n");
>>  	/* Print the orphan extents if needed */
>>  	if (errors & I_ERR_FILE_EXTENT_ORPHAN)
>> @@ -811,6 +814,8 @@ static void maybe_free_inode_rec(struct cache_tree *inode_cache,
>>  	if (!rec->checked || rec->merging)
>>  		return;
>>
>> +	if (!is_valid_imode(rec->imode))
>> +		rec->errors |= I_ERR_INVALID_IMODE;
>
> should this check actually be moved before the call to imode_to_type.
> Because if the mode is busted this means we could potentially get
> REF_ERR_FILETYPE_UNMATCH error?  I.e this check should really fail
> before anything else ?

Yes, that should be the case.

I'll update the patch to do this check before using imode.

Thanks,
Qu

>
>>  	if (S_ISDIR(rec->imode)) {
>>  		if (rec->found_size != rec->isize)
>>  			rec->errors |= I_ERR_DIR_ISIZE_WRONG;
>> diff --git a/check/mode-original.h b/check/mode-original.h
>> index 25ca274118a7..e40a12930a6f 100644
>> --- a/check/mode-original.h
>> +++ b/check/mode-original.h
>> @@ -189,6 +189,7 @@ struct file_extent_hole {
>>  #define I_ERR_ODD_INODE_FLAGS		(1 << 16)
>>  #define I_ERR_INLINE_RAM_BYTES_WRONG	(1 << 17)
>>  #define I_ERR_MISMATCH_DIR_HASH		(1 << 18)
>> +#define I_ERR_INVALID_IMODE		(1 << 19)
>>
>>  struct inode_record {
>>  	struct list_head backrefs;
>>
diff mbox series

Patch

diff --git a/check/main.c b/check/main.c
index 7547209c5604..553c93caa2c9 100644
--- a/check/main.c
+++ b/check/main.c
@@ -616,6 +616,9 @@  static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
 		fprintf(stderr, ", odd inode flags");
 	if (errors & I_ERR_INLINE_RAM_BYTES_WRONG)
 		fprintf(stderr, ", invalid inline ram bytes");
+	if (errors & I_ERR_INVALID_IMODE)
+		fprintf(stderr, ", invalid inode mode bit 0%o",
+			rec->imode & ~07777);
 	fprintf(stderr, "\n");
 	/* Print the orphan extents if needed */
 	if (errors & I_ERR_FILE_EXTENT_ORPHAN)
@@ -811,6 +814,8 @@  static void maybe_free_inode_rec(struct cache_tree *inode_cache,
 	if (!rec->checked || rec->merging)
 		return;
 
+	if (!is_valid_imode(rec->imode))
+		rec->errors |= I_ERR_INVALID_IMODE;
 	if (S_ISDIR(rec->imode)) {
 		if (rec->found_size != rec->isize)
 			rec->errors |= I_ERR_DIR_ISIZE_WRONG;
diff --git a/check/mode-original.h b/check/mode-original.h
index 25ca274118a7..e40a12930a6f 100644
--- a/check/mode-original.h
+++ b/check/mode-original.h
@@ -189,6 +189,7 @@  struct file_extent_hole {
 #define I_ERR_ODD_INODE_FLAGS		(1 << 16)
 #define I_ERR_INLINE_RAM_BYTES_WRONG	(1 << 17)
 #define I_ERR_MISMATCH_DIR_HASH		(1 << 18)
+#define I_ERR_INVALID_IMODE		(1 << 19)
 
 struct inode_record {
 	struct list_head backrefs;