Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1011678ybj; Tue, 5 May 2020 11:22:38 -0700 (PDT) X-Google-Smtp-Source: APiQypLap0vcofr5QF7aNiYS9awTRNGHdMD0KvR/afbcsUmnmReA07BHJW8zDK7eOAEALjZwEC8I X-Received: by 2002:a50:c3c2:: with SMTP id i2mr3918430edf.227.1588702957885; Tue, 05 May 2020 11:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588702957; cv=none; d=google.com; s=arc-20160816; b=pIE8nwVD360C+i353gyOL4b3dRUOyG1FdNrpZrHBRtPgCiXTCrs2qW/RPXaNmTRT5+ 2y1UZiPBC9tyGNv1F/c9snXfVCXamKFkIywxVitu5blC9JlofrLinY8rxqiZu+uxxvnQ wPqbJkXdGLfrM3Bh7B3RxxEyAKGeH3skcJQrrJUt1d+Dy43s7X9KQip9cXxENyZd1d5q VTVcarC+g/C1PY8wZ8ReQIXghp0ufBScT4Mua193A/1MAEqfBbhYp49hwEHMqurASwHR j13oLr/BvDgVTtRXK0CsiiJIABGCc2hXRiFOgHTFM5RNarXsCefpPcgExpMQoDXKeEPR P7rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=bNaxx0yuaf2UkfknBkRZsPaRG1HO/OXT517qn9PJ93w=; b=Mt/lYz6CsUtRYsj1yYbDjO9ClpKTzosIOHXKF/a91DkJjA3XwxEGhUPLSM+6djjoxW HjMpzw3B4EEmtqhleox7HzkA74nhzk4H614u0AJkSbqq2Rsre3aZHBYVRtvKaMAcq/nj MhWlY4KvL6PsfxKg+dnkizwP0rMg2/JYrdMXCEkeQPkLu8z5aBLBFigCLHbrknU0RR1U U800afWLbpRFV+61jPLPqlDAE37TYXG3jbQ8sk5vz84PO6qANr/u+WxEnS/UOiEHoh00 +hRtSpNKocGFqLRuQuO/XtAOrlSqfnOKlxISS8n2bOlTjCGA+nLJTOeVrTr33xqQB3dG +1Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Qr8sn+d/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oy7si1605799ejb.169.2020.05.05.11.22.13; Tue, 05 May 2020 11:22:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Qr8sn+d/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730785AbgEESUn (ORCPT + 99 others); Tue, 5 May 2020 14:20:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:33964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730258AbgEESUn (ORCPT ); Tue, 5 May 2020 14:20:43 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BF34120663; Tue, 5 May 2020 18:20:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588702842; bh=ZeZCawDZUxiAGh0E3Qdw7+DHNfklBHHQq4cW7/Bml1U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Qr8sn+d/XkZ7CgQ1XtQVpjFRuDwIcGITLQPkbrbVzG5PSjG6JGHdc/ShQxFBdAV5V gw2WRMZ5iN+VkVXnZ3C7AfsCUyVLU8TGOQrOTGHeE4P9FPT/TTS59GUv94ZIqMIABI MbmoyN8KRbxCwflXMmYOETX6jNAL3NCyNirFJkk8= Date: Tue, 5 May 2020 11:20:42 -0700 From: Jaegeuk Kim To: Eric Biggers 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 Message-ID: <20200505182042.GB55221@google.com> References: <20200505153139.201697-1-jaegeuk@kernel.org> <20200505165847.GA98848@gmail.com> <20200505175907.GB98848@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200505175907.GB98848@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/05, Eric Biggers wrote: > 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 > > > --- > > > 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(). The intention is to give a chance to recover the pino to avoid performance drop on fsync() by avoiding checkpoint(). And the purpose of this is to find a file having single linked file. Otherwise, we'll do checkpoint(). > > - Eric