From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Eric Biggers <ebiggers@kernel.org>
Cc: 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: Tue, 5 May 2020 11:49:32 -0700 [thread overview]
Message-ID: <20200505184932.GC55221@google.com> (raw)
In-Reply-To: <20200505181941.GC98848@gmail.com>
On 05/05, Eric Biggers wrote:
> On Tue, May 05, 2020 at 11:13:23AM -0700, Jaegeuk Kim wrote:
> > On 05/05, Eric Biggers wrote:
> > > On Tue, May 05, 2020 at 08:31:39AM -0700, Jaegeuk Kim wrote:
> > > > We had to grab the inode before retrieving i_ino.
> > > >
> > > > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > > > ---
> > > > fs/f2fs/file.c | 8 +++++++-
> > > > 1 file changed, 7 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > > > index a0a4413d6083b..9d4c3e3503567 100644
> > > > --- a/fs/f2fs/file.c
> > > > +++ b/fs/f2fs/file.c
> > > > @@ -168,6 +168,7 @@ static const struct vm_operations_struct f2fs_file_vm_ops = {
> > > > static int get_parent_ino(struct inode *inode, nid_t *pino)
> > > > {
> > > > struct dentry *dentry;
> > > > + struct inode *parent;
> > > >
> > > > inode = igrab(inode);
> > > > dentry = d_find_any_alias(inode);
> > > > @@ -175,8 +176,13 @@ static int get_parent_ino(struct inode *inode, nid_t *pino)
> > > > if (!dentry)
> > > > return 0;
> > > >
> > > > - *pino = parent_ino(dentry);
> > > > + parent = igrab(d_inode(dentry->d_parent));
> > > > dput(dentry);
> > > > + if (!parent)
> > > > + return 0;
> > > > +
> > > > + *pino = parent->i_ino;
> > > > + iput(parent);
> > > > return 1;
> >
> > Hi Eric,
> >
> > >
> > > This doesn't appear to be necessary. parent_ino() is:
> > >
> > > spin_lock(&dentry->d_lock);
> > > res = dentry->d_parent->d_inode->i_ino;
> > > spin_unlock(&dentry->d_lock);
> > >
> > > Since dentry is locked and referenced, ->d_parent is stable and positive.
> >
> > I see, thanks. :)
> >
> > >
> > > In the encrypt+casefold patch I was reviewing, it's indeed necessary, but only
> > > because there was a check of inode->i_flags added outside the locked region.
> > > The following would be simpler:
> > >
> > > spin_lock(&dentry->d_lock);
> > > dir = dentry->d_parent->d_inode;
> > > *pino = dir->i_ino;
> > > needs_recovery = IS_ENCRYPTED(dir) && IS_CASEFOLDED(dir);
> > > spin_unlock(&dentry->d_lock);
> >
> > Ack.
> >
> > >
> > > BTW, d_find_any_alias() is unnecessary too. This code should just be using
> > > file_dentry(file) from f2fs_do_sync_file().
> >
> > How about this?
> >
> > From 9aee969a413b1ed22b48573071bc93fbb4a2002d Mon Sep 17 00:00:00 2001
> > From: Jaegeuk Kim <jaegeuk@kernel.org>
> > Date: Tue, 5 May 2020 11:08:58 -0700
> > Subject: [PATCH] f2fs: remove unnecessary dentry locks
> >
> > As Eric commented, let's kill unnecessary dentry ops when recovering
> > parent inode number.
> >
> > Suggested-by: Eric Biggers <ebiggers@kernel.org>
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > ---
> > fs/f2fs/file.c | 26 ++++++--------------------
> > 1 file changed, 6 insertions(+), 20 deletions(-)
> >
> > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > index a0a4413d6083b..711cebad36fc5 100644
> > --- a/fs/f2fs/file.c
> > +++ b/fs/f2fs/file.c
> > @@ -165,21 +165,6 @@ static const struct vm_operations_struct f2fs_file_vm_ops = {
> > .page_mkwrite = f2fs_vm_page_mkwrite,
> > };
> >
> > -static int get_parent_ino(struct inode *inode, nid_t *pino)
> > -{
> > - struct dentry *dentry;
> > -
> > - inode = igrab(inode);
> > - dentry = d_find_any_alias(inode);
> > - iput(inode);
> > - if (!dentry)
> > - return 0;
> > -
> > - *pino = parent_ino(dentry);
> > - dput(dentry);
> > - return 1;
> > -}
> > -
> > static inline enum cp_reason_type need_do_checkpoint(struct inode *inode)
> > {
> > struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
> > @@ -223,14 +208,15 @@ static bool need_inode_page_update(struct f2fs_sb_info *sbi, nid_t ino)
> > return ret;
> > }
> >
> > -static void try_to_fix_pino(struct inode *inode)
> > +static void try_to_fix_pino(struct dentry *dentry)
> > {
> > + struct inode *inode = d_inode(dentry);
> > struct f2fs_inode_info *fi = F2FS_I(inode);
> > - nid_t pino;
> >
> > down_write(&fi->i_sem);
> > - if (file_wrong_pino(inode) && inode->i_nlink == 1 &&
> > - get_parent_ino(inode, &pino)) {
> > + if (file_wrong_pino(inode) && inode->i_nlink == 1) {
> > + nid_t pino = parent_ino(dentry);
> > +
> > f2fs_i_pino_write(inode, pino);
> > file_got_pino(inode);
> > }
> > @@ -310,7 +296,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
> > * We've secured consistency through sync_fs. Following pino
> > * will be used only for fsynced inodes after checkpoint.
> > */
> > - try_to_fix_pino(inode);
> > + try_to_fix_pino(file_dentry(file));
> > clear_inode_flag(inode, FI_APPEND_WRITE);
> > clear_inode_flag(inode, FI_UPDATE_WRITE);
> > goto out;
>
> 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.
>
> We need to find the dentry whose parent directory is still exists, i.e. the
> parent directory that is counting towards 'inode->i_nlink == 1'.
>
> I think d_find_alias() is what we're looking for.
Yeah, it seems to happen when open/rename/fsync calls, or race condition of
file deletion.
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 6ab8f621a3c5..855f27468baa 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -165,13 +165,13 @@ static int get_parent_ino(struct inode *inode, nid_t *pino)
> {
> struct dentry *dentry;
>
> - inode = igrab(inode);
> - dentry = d_find_any_alias(inode);
> - iput(inode);
> + dentry = d_find_alias(inode);
> if (!dentry)
> return 0;
How about this?
From 2a6b0e53e592854306062a2dc35db2d8f79062f2 Mon Sep 17 00:00:00 2001
From: Jaegeuk Kim <jaegeuk@kernel.org>
Date: Tue, 5 May 2020 11:33:29 -0700
Subject: [PATCH] f2fs: find a living dentry when finding parent ino
We need to check any dentry still alive to get parent inode number.
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/file.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index a0a4413d6083b..95139cb85faca 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -169,9 +169,8 @@ static int get_parent_ino(struct inode *inode, nid_t *pino)
{
struct dentry *dentry;
- inode = igrab(inode);
- dentry = d_find_any_alias(inode);
- iput(inode);
+ /* Need to check if valid dentry still exists. */
+ dentry = d_find_alias(inode);
if (!dentry)
return 0;
--
2.26.2.526.g744177e7f7-goog
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Eric Biggers <ebiggers@kernel.org>
Cc: linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Subject: Re: [f2fs-dev] [PATCH] f2fs: get parent inode when recovering pino
Date: Tue, 5 May 2020 11:49:32 -0700 [thread overview]
Message-ID: <20200505184932.GC55221@google.com> (raw)
In-Reply-To: <20200505181941.GC98848@gmail.com>
On 05/05, Eric Biggers wrote:
> On Tue, May 05, 2020 at 11:13:23AM -0700, Jaegeuk Kim wrote:
> > On 05/05, Eric Biggers wrote:
> > > On Tue, May 05, 2020 at 08:31:39AM -0700, Jaegeuk Kim wrote:
> > > > We had to grab the inode before retrieving i_ino.
> > > >
> > > > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > > > ---
> > > > fs/f2fs/file.c | 8 +++++++-
> > > > 1 file changed, 7 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > > > index a0a4413d6083b..9d4c3e3503567 100644
> > > > --- a/fs/f2fs/file.c
> > > > +++ b/fs/f2fs/file.c
> > > > @@ -168,6 +168,7 @@ static const struct vm_operations_struct f2fs_file_vm_ops = {
> > > > static int get_parent_ino(struct inode *inode, nid_t *pino)
> > > > {
> > > > struct dentry *dentry;
> > > > + struct inode *parent;
> > > >
> > > > inode = igrab(inode);
> > > > dentry = d_find_any_alias(inode);
> > > > @@ -175,8 +176,13 @@ static int get_parent_ino(struct inode *inode, nid_t *pino)
> > > > if (!dentry)
> > > > return 0;
> > > >
> > > > - *pino = parent_ino(dentry);
> > > > + parent = igrab(d_inode(dentry->d_parent));
> > > > dput(dentry);
> > > > + if (!parent)
> > > > + return 0;
> > > > +
> > > > + *pino = parent->i_ino;
> > > > + iput(parent);
> > > > return 1;
> >
> > Hi Eric,
> >
> > >
> > > This doesn't appear to be necessary. parent_ino() is:
> > >
> > > spin_lock(&dentry->d_lock);
> > > res = dentry->d_parent->d_inode->i_ino;
> > > spin_unlock(&dentry->d_lock);
> > >
> > > Since dentry is locked and referenced, ->d_parent is stable and positive.
> >
> > I see, thanks. :)
> >
> > >
> > > In the encrypt+casefold patch I was reviewing, it's indeed necessary, but only
> > > because there was a check of inode->i_flags added outside the locked region.
> > > The following would be simpler:
> > >
> > > spin_lock(&dentry->d_lock);
> > > dir = dentry->d_parent->d_inode;
> > > *pino = dir->i_ino;
> > > needs_recovery = IS_ENCRYPTED(dir) && IS_CASEFOLDED(dir);
> > > spin_unlock(&dentry->d_lock);
> >
> > Ack.
> >
> > >
> > > BTW, d_find_any_alias() is unnecessary too. This code should just be using
> > > file_dentry(file) from f2fs_do_sync_file().
> >
> > How about this?
> >
> > From 9aee969a413b1ed22b48573071bc93fbb4a2002d Mon Sep 17 00:00:00 2001
> > From: Jaegeuk Kim <jaegeuk@kernel.org>
> > Date: Tue, 5 May 2020 11:08:58 -0700
> > Subject: [PATCH] f2fs: remove unnecessary dentry locks
> >
> > As Eric commented, let's kill unnecessary dentry ops when recovering
> > parent inode number.
> >
> > Suggested-by: Eric Biggers <ebiggers@kernel.org>
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > ---
> > fs/f2fs/file.c | 26 ++++++--------------------
> > 1 file changed, 6 insertions(+), 20 deletions(-)
> >
> > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > index a0a4413d6083b..711cebad36fc5 100644
> > --- a/fs/f2fs/file.c
> > +++ b/fs/f2fs/file.c
> > @@ -165,21 +165,6 @@ static const struct vm_operations_struct f2fs_file_vm_ops = {
> > .page_mkwrite = f2fs_vm_page_mkwrite,
> > };
> >
> > -static int get_parent_ino(struct inode *inode, nid_t *pino)
> > -{
> > - struct dentry *dentry;
> > -
> > - inode = igrab(inode);
> > - dentry = d_find_any_alias(inode);
> > - iput(inode);
> > - if (!dentry)
> > - return 0;
> > -
> > - *pino = parent_ino(dentry);
> > - dput(dentry);
> > - return 1;
> > -}
> > -
> > static inline enum cp_reason_type need_do_checkpoint(struct inode *inode)
> > {
> > struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
> > @@ -223,14 +208,15 @@ static bool need_inode_page_update(struct f2fs_sb_info *sbi, nid_t ino)
> > return ret;
> > }
> >
> > -static void try_to_fix_pino(struct inode *inode)
> > +static void try_to_fix_pino(struct dentry *dentry)
> > {
> > + struct inode *inode = d_inode(dentry);
> > struct f2fs_inode_info *fi = F2FS_I(inode);
> > - nid_t pino;
> >
> > down_write(&fi->i_sem);
> > - if (file_wrong_pino(inode) && inode->i_nlink == 1 &&
> > - get_parent_ino(inode, &pino)) {
> > + if (file_wrong_pino(inode) && inode->i_nlink == 1) {
> > + nid_t pino = parent_ino(dentry);
> > +
> > f2fs_i_pino_write(inode, pino);
> > file_got_pino(inode);
> > }
> > @@ -310,7 +296,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
> > * We've secured consistency through sync_fs. Following pino
> > * will be used only for fsynced inodes after checkpoint.
> > */
> > - try_to_fix_pino(inode);
> > + try_to_fix_pino(file_dentry(file));
> > clear_inode_flag(inode, FI_APPEND_WRITE);
> > clear_inode_flag(inode, FI_UPDATE_WRITE);
> > goto out;
>
> 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.
>
> We need to find the dentry whose parent directory is still exists, i.e. the
> parent directory that is counting towards 'inode->i_nlink == 1'.
>
> I think d_find_alias() is what we're looking for.
Yeah, it seems to happen when open/rename/fsync calls, or race condition of
file deletion.
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 6ab8f621a3c5..855f27468baa 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -165,13 +165,13 @@ static int get_parent_ino(struct inode *inode, nid_t *pino)
> {
> struct dentry *dentry;
>
> - inode = igrab(inode);
> - dentry = d_find_any_alias(inode);
> - iput(inode);
> + dentry = d_find_alias(inode);
> if (!dentry)
> return 0;
How about this?
From 2a6b0e53e592854306062a2dc35db2d8f79062f2 Mon Sep 17 00:00:00 2001
From: Jaegeuk Kim <jaegeuk@kernel.org>
Date: Tue, 5 May 2020 11:33:29 -0700
Subject: [PATCH] f2fs: find a living dentry when finding parent ino
We need to check any dentry still alive to get parent inode number.
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/file.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index a0a4413d6083b..95139cb85faca 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -169,9 +169,8 @@ static int get_parent_ino(struct inode *inode, nid_t *pino)
{
struct dentry *dentry;
- inode = igrab(inode);
- dentry = d_find_any_alias(inode);
- iput(inode);
+ /* Need to check if valid dentry still exists. */
+ dentry = d_find_alias(inode);
if (!dentry)
return 0;
--
2.26.2.526.g744177e7f7-goog
next prev parent reply other threads:[~2020-05-05 18:49 UTC|newest]
Thread overview: 38+ 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 15:31 ` Jaegeuk Kim
2020-05-05 16:58 ` [f2fs-dev] " Eric Biggers
2020-05-05 16:58 ` Eric Biggers
2020-05-05 17:59 ` Eric Biggers
2020-05-05 17:59 ` Eric Biggers
2020-05-05 18:20 ` Jaegeuk Kim
2020-05-05 18:20 ` Jaegeuk Kim
2020-05-05 18:13 ` Jaegeuk Kim
2020-05-05 18:13 ` Jaegeuk Kim
2020-05-05 18:19 ` Eric Biggers
2020-05-05 18:19 ` Eric Biggers
2020-05-05 18:49 ` Jaegeuk Kim [this message]
2020-05-05 18:49 ` Jaegeuk Kim
2020-05-05 19:01 ` Eric Biggers
2020-05-05 19:01 ` Eric Biggers
2020-05-05 19:08 ` Jaegeuk Kim
2020-05-05 19:08 ` Jaegeuk Kim
2020-05-06 0:14 ` Gao Xiang
2020-05-06 0:14 ` Gao Xiang
2020-05-06 1:24 ` Eric Biggers
2020-05-06 1:24 ` Eric Biggers
2020-05-06 1:58 ` Gao Xiang via Linux-f2fs-devel
2020-05-06 1:58 ` Gao Xiang
2020-05-06 6:47 ` Gao Xiang
2020-05-06 6:47 ` Gao Xiang
2020-05-06 19:16 ` Eric Biggers
2020-05-06 19:16 ` Eric Biggers
2020-05-06 22:36 ` Gao Xiang
2020-05-06 22:36 ` Gao Xiang
2020-05-07 6:38 ` Chao Yu
2020-05-07 6:38 ` Chao Yu
2020-05-07 7:23 ` Gao Xiang
2020-05-07 7:23 ` Gao Xiang
2020-05-06 6:55 ` Chao Yu
2020-05-06 6:55 ` Chao Yu
2020-05-07 6:30 ` 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=20200505184932.GC55221@google.com \
--to=jaegeuk@kernel.org \
--cc=ebiggers@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.