public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] ext2: drop cached block when detecting corruption
@ 2020-06-03  9:44 Chengguang Xu
  2020-06-04  6:26 ` cgxu
  2020-06-04 19:31 ` Andreas Dilger
  0 siblings, 2 replies; 4+ messages in thread
From: Chengguang Xu @ 2020-06-03  9:44 UTC (permalink / raw)
  To: jack; +Cc: linux-ext4, Chengguang Xu

Currently ext2 uses mdcache for deduplication of extended
attribution blocks. However, there is lack of handling for
corrupted blocks, so newly created EAs may still links to
corrupted blocks. This patch tries to drop cached block
when detecting corruption to mitigate the effect.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/ext2/xattr.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 943cc469f42f..969521e39753 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -93,6 +93,8 @@ static int ext2_xattr_set2(struct inode *, struct buffer_head *,
 			   struct ext2_xattr_header *);
 
 static int ext2_xattr_cache_insert(struct mb_cache *, struct buffer_head *);
+static void ext2_xattr_cache_remove(struct mb_cache *cache,
+				    struct buffer_head *bh);
 static struct buffer_head *ext2_xattr_cache_find(struct inode *,
 						 struct ext2_xattr_header *);
 static void ext2_xattr_rehash(struct ext2_xattr_header *,
@@ -237,8 +239,10 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
 	entry = FIRST_ENTRY(bh);
 	while (!IS_LAST_ENTRY(entry)) {
 		if (!ext2_xattr_entry_valid(entry, end,
-		    inode->i_sb->s_blocksize))
+		    inode->i_sb->s_blocksize)) {
+			ext2_xattr_cache_remove(ea_block_cache, bh);
 			goto bad_block;
+		}
 
 		not_found = ext2_xattr_cmp_entry(name_index, name_len, name,
 						 entry);
@@ -323,8 +327,10 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
 	entry = FIRST_ENTRY(bh);
 	while (!IS_LAST_ENTRY(entry)) {
 		if (!ext2_xattr_entry_valid(entry, end,
-		    inode->i_sb->s_blocksize))
+		    inode->i_sb->s_blocksize)) {
+			ext2_xattr_cache_remove(ea_block_cache, bh);
 			goto bad_block;
+		}
 		entry = EXT2_XATTR_NEXT(entry);
 	}
 	if (ext2_xattr_cache_insert(ea_block_cache, bh))
@@ -407,6 +413,7 @@ int
 ext2_xattr_set(struct inode *inode, int name_index, const char *name,
 	       const void *value, size_t value_len, int flags)
 {
+	struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
 	struct super_block *sb = inode->i_sb;
 	struct buffer_head *bh = NULL;
 	struct ext2_xattr_header *header = NULL;
@@ -464,8 +471,11 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
 		 */
 		last = FIRST_ENTRY(bh);
 		while (!IS_LAST_ENTRY(last)) {
-			if (!ext2_xattr_entry_valid(last, end, sb->s_blocksize))
+			if (!ext2_xattr_entry_valid(last, end,
+			    sb->s_blocksize)) {
+				ext2_xattr_cache_remove(ea_block_cache, bh);
 				goto bad_block;
+			}
 			if (last->e_value_size) {
 				size_t offs = le16_to_cpu(last->e_value_offs);
 				if (offs < min_offs)
@@ -881,6 +891,15 @@ ext2_xattr_cache_insert(struct mb_cache *cache, struct buffer_head *bh)
 	return error;
 }
 
+static void
+ext2_xattr_cache_remove(struct mb_cache *cache, struct buffer_head *bh)
+{
+	lock_buffer(bh);
+	mb_cache_entry_delete(cache, le32_to_cpu(HDR(bh)->h_hash),
+			      bh->b_blocknr);
+	unlock_buffer(bh);
+}
+
 /*
  * ext2_xattr_cmp()
  *
-- 
2.20.1



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

* Re: [RFC PATCH] ext2: drop cached block when detecting corruption
  2020-06-03  9:44 [RFC PATCH] ext2: drop cached block when detecting corruption Chengguang Xu
@ 2020-06-04  6:26 ` cgxu
  2020-06-05 15:26   ` Jan Kara
  2020-06-04 19:31 ` Andreas Dilger
  1 sibling, 1 reply; 4+ messages in thread
From: cgxu @ 2020-06-04  6:26 UTC (permalink / raw)
  To: jack; +Cc: linux-ext4

On 6/3/20 5:44 PM, Chengguang Xu wrote:
> Currently ext2 uses mdcache for deduplication of extended
> attribution blocks. However, there is lack of handling for
> corrupted blocks, so newly created EAs may still links to
> corrupted blocks. This patch tries to drop cached block
> when detecting corruption to mitigate the effect.

ext2_xattr_cmp() will carefully check every entry in the block,
so there is no chance to link to corrupted block, maybe we can
improve the speed of cache related operations by dropping
corrupted blocks.


Thanks,
cgxu

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

* Re: [RFC PATCH] ext2: drop cached block when detecting corruption
  2020-06-03  9:44 [RFC PATCH] ext2: drop cached block when detecting corruption Chengguang Xu
  2020-06-04  6:26 ` cgxu
@ 2020-06-04 19:31 ` Andreas Dilger
  1 sibling, 0 replies; 4+ messages in thread
From: Andreas Dilger @ 2020-06-04 19:31 UTC (permalink / raw)
  To: Chengguang Xu; +Cc: jack, linux-ext4

On Jun 3, 2020, at 03:44, Chengguang Xu <cgxu519@mykernel.net> wrote:
> 
> Currently ext2 uses mdcache for deduplication of extended

(typo) this should be "mbcache"


> attribution blocks. However, there is lack of handling for
> corrupted blocks, so newly created EAs may still links to
> corrupted blocks. This patch tries to drop cached block
> when detecting corruption to mitigate the effect.
> 
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> ---
> fs/ext2/xattr.c | 25 ++++++++++++++++++++++---
> 1 file changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
> index 943cc469f42f..969521e39753 100644
> --- a/fs/ext2/xattr.c
> +++ b/fs/ext2/xattr.c
> @@ -93,6 +93,8 @@ static int ext2_xattr_set2(struct inode *, struct buffer_head *,
>               struct ext2_xattr_header *);
> 
> static int ext2_xattr_cache_insert(struct mb_cache *, struct buffer_head *);
> +static void ext2_xattr_cache_remove(struct mb_cache *cache,
> +                    struct buffer_head *bh);
> static struct buffer_head *ext2_xattr_cache_find(struct inode *,
>                         struct ext2_xattr_header *);
> static void ext2_xattr_rehash(struct ext2_xattr_header *,
> @@ -237,8 +239,10 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
>    entry = FIRST_ENTRY(bh);
>    while (!IS_LAST_ENTRY(entry)) {
>        if (!ext2_xattr_entry_valid(entry, end,
> -            inode->i_sb->s_blocksize))
> +            inode->i_sb->s_blocksize)) {
> +            ext2_xattr_cache_remove(ea_block_cache, bh);
>            goto bad_block;
> +        }
> 
>        not_found = ext2_xattr_cmp_entry(name_index, name_len, name,
>                         entry);
> @@ -323,8 +327,10 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
>    entry = FIRST_ENTRY(bh);
>    while (!IS_LAST_ENTRY(entry)) {
>        if (!ext2_xattr_entry_valid(entry, end,
> -            inode->i_sb->s_blocksize))
> +            inode->i_sb->s_blocksize)) {
> +            ext2_xattr_cache_remove(ea_block_cache, bh);
>            goto bad_block;
> +        }
>        entry = EXT2_XATTR_NEXT(entry);
>    }
>    if (ext2_xattr_cache_insert(ea_block_cache, bh))
> @@ -407,6 +413,7 @@ int
> ext2_xattr_set(struct inode *inode, int name_index, const char *name,
>           const void *value, size_t value_len, int flags)
> {
> +    struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
>    struct super_block *sb = inode->i_sb;
>    struct buffer_head *bh = NULL;
>    struct ext2_xattr_header *header = NULL;
> @@ -464,8 +471,11 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
>         */
>        last = FIRST_ENTRY(bh);
>        while (!IS_LAST_ENTRY(last)) {
> -            if (!ext2_xattr_entry_valid(last, end, sb->s_blocksize))
> +            if (!ext2_xattr_entry_valid(last, end,
> +                sb->s_blocksize)) {
> +                ext2_xattr_cache_remove(ea_block_cache, bh);
>                goto bad_block;
> +            }
>            if (last->e_value_size) {
>                size_t offs = le16_to_cpu(last->e_value_offs);
>                if (offs < min_offs)
> @@ -881,6 +891,15 @@ ext2_xattr_cache_insert(struct mb_cache *cache, struct buffer_head *bh)
>    return error;
> }
> 
> +static void
> +ext2_xattr_cache_remove(struct mb_cache *cache, struct buffer_head *bh)
> +{
> +    lock_buffer(bh);
> +    mb_cache_entry_delete(cache, le32_to_cpu(HDR(bh)->h_hash),
> +                  bh->b_blocknr);
> +    unlock_buffer(bh);
> +}
> +
> /*
>  * ext2_xattr_cmp()
>  *
> -- 
> 2.20.1
> 
> 

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

* Re: [RFC PATCH] ext2: drop cached block when detecting corruption
  2020-06-04  6:26 ` cgxu
@ 2020-06-05 15:26   ` Jan Kara
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2020-06-05 15:26 UTC (permalink / raw)
  To: cgxu; +Cc: jack, linux-ext4

On Thu 04-06-20 14:26:49, cgxu wrote:
> On 6/3/20 5:44 PM, Chengguang Xu wrote:
> > Currently ext2 uses mdcache for deduplication of extended
> > attribution blocks. However, there is lack of handling for
> > corrupted blocks, so newly created EAs may still links to
> > corrupted blocks. This patch tries to drop cached block
> > when detecting corruption to mitigate the effect.
> 
> ext2_xattr_cmp() will carefully check every entry in the block,
> so there is no chance to link to corrupted block, maybe we can
> improve the speed of cache related operations by dropping
> corrupted blocks.

Thanks for the back but as you write, I don't see the point of your patch
because corrupted blocks shouldn't get to mbcache in the first place (and
we check block consistency only when loading block from disk, not from
mbcache). And performance in case of corrupted xattr block doesn't really
matter much so I don't want to complicate the code for that.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

end of thread, other threads:[~2020-06-05 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-03  9:44 [RFC PATCH] ext2: drop cached block when detecting corruption Chengguang Xu
2020-06-04  6:26 ` cgxu
2020-06-05 15:26   ` Jan Kara
2020-06-04 19:31 ` Andreas Dilger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox