From: Chao Yu <yuchao0@huawei.com>
To: Gao Xiang <hsiangkao@gmx.com>, Eric Biggers <ebiggers@kernel.org>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>,
kernel-team@android.com, linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH] f2fs: get parent inode when recovering pino
Date: Thu, 7 May 2020 14:38:39 +0800 [thread overview]
Message-ID: <3a837113-8081-6f01-4d8d-1d4b6600ec8c@huawei.com> (raw)
In-Reply-To: <20200506223623.GA27760@hsiangkao-HP-ZHAN-66-Pro-G1>
On 2020/5/7 6:36, Gao Xiang wrote:
> On Wed, May 06, 2020 at 12:16:13PM -0700, Eric Biggers wrote:
>> On Wed, May 06, 2020 at 02:47:19PM +0800, Gao Xiang wrote:
>>> On Wed, May 06, 2020 at 09:58:22AM +0800, Gao Xiang wrote:
>>>> On Tue, May 05, 2020 at 06:24:28PM -0700, Eric Biggers wrote:
>>>>> On Wed, May 06, 2020 at 08:14:07AM +0800, Gao Xiang wrote:
>>>>>>>
>>>>>>> Actually, I think this is wrong because the fsync can be done via a file
>>>>>>> descriptor that was opened to a now-deleted link to the file.
>>>>>>
>>>>>> I'm still confused about this...
>>>>>>
>>>>>> I don't know what's wrong with this version from my limited knowledge?
>>>>>> inode itself is locked when fsyncing, so
>>>>>>
>>>>>> if the fsync inode->i_nlink == 1, this inode has only one hard link
>>>>>> (not deleted yet) and should belong to a single directory; and
>>>>>>
>>>>>> the only one parent directory would not go away (not deleted as well)
>>>>>> since there are some dirents in it (not empty).
>>>>>>
>>>>>> Could kindly explain more so I would learn more about this scenario?
>>>>>> Thanks a lot!
>>>>>
>>>>> i_nlink == 1 just means that there is one non-deleted link. There can be links
>>>>> that have since been deleted, and file descriptors can still be open to them.
>>>>
>>>> Thanks for your inspiration. You are right, thanks.
>>>>
>>>> Correct my words... I didn't check f2fs code just now, it seems f2fs doesn't
>>>> take inode_lock as some other fs like __generic_file_fsync or ubifs_fsync.
>>>>
>>>> And i_sem locks nlink / try_to_fix_pino similarly in some extent. It seems
>>>> no race by using d_find_alias here. Thanks again.
>>>>
>>>
>>> (think more little bit just now...)
>>>
>>> Thread 1: Thread 2 (fsync):
>>> vfs_unlink try_to_fix_pino
>>> f2fs_unlink
>>> f2fs_delete_entry
>>> f2fs_drop_nlink (i_sem, inode->i_nlink = 1)
>>>
>>> (... but this dentry still hashed) i_sem, check inode->i_nlink = 1
>>> i_sem d_find_alias
>>>
>>> d_delete
>>>
>>> I'm not sure if fsync could still use some wrong alias by chance..
>>> completely untested, maybe just noise...
Another race condition could be:
Thread 1 (fsync) Thread 2 (rename)
- f2fs_sync_fs
- try_to_fix_pino
- f2fs_rename
- down_write
- file_lost_pino
- up_write
- down_write
- file_got_pino
- up_write
Thanks,
>>>
>>
>> Right, good observation. My patch makes it better, but it's still broken.
>>
>> I don't know how to fix it. If we see i_nlink == 1 and multiple hashed
>> dentries, there doesn't appear to be a way to distingush which one corresponds
>> to the remaining link on-disk (if any; it may not even be in the dcache), and
>> which correspond to links that vfs_unlink() has deleted from disk but hasn't yet
>> done d_delete() on.
>>
>> One idea would be choose one, then take inode_lock_shared(dir) and do
>> __f2fs_find_entry() to check if the dentry is really still on-disk. That's
>> heavyweight and error-prone though, and the locking could cause problems.
>>
>> I'm wondering though, does f2fs really need try_to_fix_pino() at all, and did it
>> ever really work? It never actually updates the f2fs_inode::i_name to match the
>> new directory. So independently of this bug with deleted links, I don't see how
>> it can possibly work as intended.
>
> Part of my humble opinion would be "update pino in rename/unlink/link... such ops
> instead of in fsync" (maybe it makes better sense of locking)... But actually I'm
> not a f2fs folk now, just curious about what the original patch resolved with
> these new extra igrab/iput (as I said before, I could not find some clue previously).
>
> Thanks,
> Gao Xiang
>
>>
>> - Eric
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> .
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2020-05-07 6:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 15:31 [f2fs-dev] [PATCH] f2fs: get parent inode when recovering pino Jaegeuk Kim
2020-05-05 16:58 ` Eric Biggers
2020-05-05 17:59 ` Eric Biggers
2020-05-05 18:20 ` Jaegeuk Kim
2020-05-05 18:13 ` Jaegeuk Kim
2020-05-05 18:19 ` Eric Biggers
2020-05-05 18:49 ` Jaegeuk Kim
2020-05-05 19:01 ` Eric Biggers
2020-05-05 19:08 ` Jaegeuk Kim
2020-05-06 0:14 ` Gao Xiang
2020-05-06 1:24 ` Eric Biggers
2020-05-06 1:58 ` Gao Xiang via Linux-f2fs-devel
2020-05-06 6:47 ` Gao Xiang
2020-05-06 19:16 ` Eric Biggers
2020-05-06 22:36 ` Gao Xiang
2020-05-07 6:38 ` Chao Yu [this message]
2020-05-07 7:23 ` Gao Xiang
2020-05-06 6:55 ` Chao Yu
2020-05-07 6:30 ` Chao Yu
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=3a837113-8081-6f01-4d8d-1d4b6600ec8c@huawei.com \
--to=yuchao0@huawei.com \
--cc=ebiggers@kernel.org \
--cc=hsiangkao@gmx.com \
--cc=jaegeuk@kernel.org \
--cc=kernel-team@android.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/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).