public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Ye Bin <yebin10@huawei.com>
Cc: jack@suse.cz, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH -next] ext2: fix fs corruption when trying to remove a non-empty directory with IO error
Date: Wed, 15 Jun 2022 19:13:13 +0200	[thread overview]
Message-ID: <20220615171313.fnfn6cnozn76cmrl@quack3.lan> (raw)
In-Reply-To: <20220615090010.1544152-1-yebin10@huawei.com>

On Wed 15-06-22 17:00:10, Ye Bin wrote:
> We got issue as follows:
> [home]# mount  /dev/sdd  test
> [home]# cd test
> [test]# ls
> dir1  lost+found
> [test]# rmdir  dir1
> ext2_empty_dir: inject fault
> [test]# ls
> lost+found
> [test]# cd ..
> [home]# umount test
> [home]# fsck.ext2 -fn  /dev/sdd
> e2fsck 1.42.9 (28-Dec-2013)
> Pass 1: Checking inodes, blocks, and sizes
> Inode 4065, i_size is 0, should be 1024.  Fix? no
> 
> Pass 2: Checking directory structure
> Pass 3: Checking directory connectivity
> Unconnected directory inode 4065 (/???)
> Connect to /lost+found? no
> 
> '..' in ... (4065) is / (2), should be <The NULL inode> (0).
> Fix? no
> 
> Pass 4: Checking reference counts
> Inode 2 ref count is 3, should be 4.  Fix? no
> 
> Inode 4065 ref count is 2, should be 3.  Fix? no
> 
> Pass 5: Checking group summary information
> 
> /dev/sdd: ********** WARNING: Filesystem still has errors **********
> 
> /dev/sdd: 14/128016 files (0.0% non-contiguous), 18477/512000 blocks
> 
> Reason is same with commit 7aab5c84a0f6. We can't assume directory
> is empty when read directory entry failed.
> 
> Signed-off-by: Ye Bin <yebin10@huawei.com>

Honestly, I'm not very much concerned about corrupting the filesystem more
when we've got EIO for metadata but OK, probably what you propose is a
saner choice. I've added the patch to my tree.

								Honza

> ---
>  fs/ext2/dir.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
> index 3bd5772b401b..8f597753ac12 100644
> --- a/fs/ext2/dir.c
> +++ b/fs/ext2/dir.c
> @@ -672,17 +672,14 @@ int ext2_empty_dir (struct inode * inode)
>  	void *page_addr = NULL;
>  	struct page *page = NULL;
>  	unsigned long i, npages = dir_pages(inode);
> -	int dir_has_error = 0;
>  
>  	for (i = 0; i < npages; i++) {
>  		char *kaddr;
>  		ext2_dirent * de;
> -		page = ext2_get_page(inode, i, dir_has_error, &page_addr);
> +		page = ext2_get_page(inode, i, 0, &page_addr);
>  
> -		if (IS_ERR(page)) {
> -			dir_has_error = 1;
> -			continue;
> -		}
> +		if (IS_ERR(page))
> +			goto not_empty;
>  
>  		kaddr = page_addr;
>  		de = (ext2_dirent *)kaddr;
> -- 
> 2.31.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

      reply	other threads:[~2022-06-15 17:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-15  9:00 [PATCH -next] ext2: fix fs corruption when trying to remove a non-empty directory with IO error Ye Bin
2022-06-15 17:13 ` Jan Kara [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220615171313.fnfn6cnozn76cmrl@quack3.lan \
    --to=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yebin10@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox