On Tue, May 05, 2020 at 09:58:47AM -0700, 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 <jaeg...@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; > > 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. > > 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); > > BTW, d_find_any_alias() is unnecessary too. This code should just be using > file_dentry(file) from f2fs_do_sync_file(). >
Also, what is this code trying to accomplish? If it's trying to find the parent directory of an inode with i_nlink == 1, this isn't the correct way to do it. The fsync could be done via a deleted file, which would make the wrong p_ino be set. I think the correct approach would be to iterate through all the dentry's aliases, and choose the parent directory that's !IS_DEADDIR(). - Eric