linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: "zhangyi (F)" <yi.zhang@huawei.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>,
	Valdis.Kletnieks@vt.edu, linux-ext4@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	adilger.kernel@dilger.ca
Subject: Re: [RFC PATCH] ext4: increase the protection of drop nlink and ext4 inode destroy
Date: Thu, 5 Jan 2017 09:38:38 -0800	[thread overview]
Message-ID: <20170105173838.GC14021@birch.djwong.org> (raw)
In-Reply-To: <5505c121-8038-1b72-423a-42f36257e959@huawei.com>

On Thu, Jan 05, 2017 at 03:24:14PM +0800, zhangyi (F) wrote:
> 
> On 2017/1/5 7:35, Theodore Ts'o wrote:
> > 
> > So how exactly how did we get into this state?  When we read the inode
> > into memory, if i_nlink is zero, we declare the file system as
> > corrupted immediately.
> > 
> > So I assume this is happening the on-disk i_links_count (which is read
> > into inode->i_nlink) was too low.  So I think the way we should be
> > handling this is in unlink and rename, before we let i_nlink drop to

D'oh, /me failed to notice the patch was against fs/inode.c, not
fs/ext4/inode.c.  Sorry for the noise.

> > zero, we need to check to see if there are other dcache entries
> > pointing at the inode.  If so, we need to call ext4_error(), and in
> > the errors=continue case, return EFSCORRUPTED (aka EUCLEAN).
> > 
> 
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -3662,6 +3662,11 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
>         }
> 
>         if (new.inode) {
> +               if (new.inode->i_nlink == 0) {
> +                       ext4_warning_inode(new.inode, "Removing file '%.*s' with no links",
> +                                      new.dentry->d_name.len, new.dentry->d_name.name);
> +                       set_nlink(new.inode, 1);

Not sure we need to dump the dentry d_name, but I guess it can't hurt.

> +               }
>                 ext4_dec_count(handle, new.inode);
>                 new.inode->i_ctime = ext4_current_time(new.inode);
>         }
> 
> Because the filesystem have many errors, and the reason of i_nlink becomes
> zero is unknown, the on-disk i_links_count was too low may be one reason.  I
> think we can add i_nlink check in ext4_rename just like ext4_unlink did, it
> can avoid inversion under any case.

Er... yes, you could add the same hunk to ext4_unlink.

--D

> 
> 
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2017-01-05 17:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-26 12:34 [RFC PATCH] ext4: increase the protection of drop nlink and ext4 inode destroy yi zhang
2016-12-26 18:32 ` Andreas Dilger
2016-12-31 22:59 ` Valdis.Kletnieks
2017-01-04  8:29   ` zhangyi (F)
2017-01-04 21:54     ` Darrick J. Wong
2017-01-04 22:00       ` Andreas Dilger
2017-01-04 23:35       ` Theodore Ts'o
2017-01-05  7:24         ` zhangyi (F)
2017-01-05 17:38           ` Darrick J. Wong [this message]
2017-01-11  9:07         ` zhangyi (F)
2017-01-11 15:34           ` Theodore Ts'o
2017-01-12  8:00             ` zhangyi (F)
2017-01-12 17:03               ` Theodore Ts'o
2017-01-13  3:42                 ` Al Viro
2017-01-13 14:26                   ` Theodore Ts'o
2017-01-16  3:24             ` zhangyi (F)

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=20170105173838.GC14021@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=adilger.kernel@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@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;
as well as URLs for NNTP newsgroup(s).