Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1361926ybj; Tue, 5 May 2020 19:04:58 -0700 (PDT) X-Google-Smtp-Source: APiQypLKDlAqNhnOR2YR9vRHdIYJwi4SPo/1uzY+eZqbbo0LTJwcdMsD5CKVx/VmXN38P+MUfckW X-Received: by 2002:a50:e8c1:: with SMTP id l1mr5201094edn.81.1588730697966; Tue, 05 May 2020 19:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588730697; cv=none; d=google.com; s=arc-20160816; b=n+DLjghxJEgurqOFFwLNZo4+gwRHbF5p4WOR0skqAerOcVhuN4Aal0zxoPfW386xQ7 LXf318Ev8VWXrU8FMFelxBk9jwizKdmJk3IeGeQzPD6LRxcT9z4TCCHEGmEEvf2b6hFF Q5tryX3Jhw2shhRROMH4Y4y+KVODpiNVP9zS8tgRhxSpTGbG1g1YI5ZwS/ofIu/cYVnz T1hrRgOCG8TWtLTKeoPGf1u/3uI7H31itRifpq/yDVU+RXW7vv/lKWKNOwcjZEH/sEiP Hq3BNwRPHl/nnBGd3Il44rRmGmnGzDxx+RtYdn+gEqZ02Xd2YZTe8dWSrBM5qvg6yPg+ cw8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CVw8L0hHvwbYi4+P+g/ulJkZcv445iN2F6ec7gN2/Cw=; b=Kec8wnW2Anrd0lMIO3s59sAdkht5zSAhEcRelsRBeiJRPK8awggIBqMyyk4MfdNWDM Uncxl8tSorGMepCb6fqLkcQnbh5zKo5tDnc3ovO6kQP6qrhO6ln1UaTcVGzaZgRVR13J lXmOVwZ92O56c7XG09TJ4IA19eUkTX/2lStZmSjTXQYFmvGKf16zExHNlEZVsZ4OpMcp i8fa6Tr5SVLU7/bITaOuN09k4VxTJlJgtAPkTXLERAkmI0AcK669d3w84/sySkfMo8r0 eLo+uac6FnJjeKM86RBlRXpCYQIPDLHN5Udv/e+fVP/qSNhOm5liMaGeTIkVEd2dWK6r 3hkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=lKfptMr+; 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=REJECT sp=REJECT dis=NONE) header.from=aol.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w14si218353edl.600.2020.05.05.19.04.31; Tue, 05 May 2020 19:04:57 -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=@aol.com header.s=a2048 header.b=lKfptMr+; 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=REJECT sp=REJECT dis=NONE) header.from=aol.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729858AbgEFB6i (ORCPT + 99 others); Tue, 5 May 2020 21:58:38 -0400 Received: from sonic305-22.consmr.mail.ne1.yahoo.com ([66.163.185.148]:44990 "EHLO sonic305-22.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbgEFB6i (ORCPT ); Tue, 5 May 2020 21:58:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1588730317; bh=CVw8L0hHvwbYi4+P+g/ulJkZcv445iN2F6ec7gN2/Cw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=lKfptMr+itf7a5nC8vgOiNk70vnizhd2dn9GIB3ckqnr6nDv63euNBLnwCl31gF2n0zYjjNZHMbduezl2/+KEJW+YVw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HA.Qi7Yk.jxlafUko367oSl _05iYXpCQ.aNCN7_peCIlMjM.DU7CDfJGnfifoyVEmArdO_PSCaCo1tasDEixfQ8sqyYPjAf_5zD lSavLGrzv4rPh_zgQwbAZbEhbqZxkbPcFEW.MmpQRZWep0RGEnPxc1YvOFUUXqVBYlhlGFfaoXbu I4KmD9sWTgF.Aar3KFxoszxXH0kREhXgmAEx8amJLYy4Q0bBH7wdtwjBUuV3jFzBjCjvrL630zGk wnZ.prYznyEQHPQ0LFcjL4FLv3iJJZZuMMeYH43E1vABfMmt4_viDZwUUjDIn7eP4kWBKHQeJ.nv rgHUxz1xKmP8N1GBwjaIWsd91_HcftbiGKLsZtxwiLKoKKJ2IigVrxx3hLlMtt3a43YkdmrNZwu5 MUGymKNdqsV.eB4qF30Dko1MOqz3V8IlRp.VVJ8hb7GQefrBppKIS7stqY5xrK8Rd2Jf189S0rsP EWIRvnc0tRZic26x9yPWCA8FARrWsaWzuT0KplIZSitLNgnMfKcsOiR3y24P3Xae0nd9yClAxTiB QCf5_JEr1kSMrU1CWM4bwwUA.snwVNHASg59f0HQ_ENqzeVIZr3JZexKRT6GStPv8V2w6PD_xqHt oWRU2DRV7IMnc_7ZbsKLriaPFx8s- Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ne1.yahoo.com with HTTP; Wed, 6 May 2020 01:58:37 +0000 Received: by smtp405.mail.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID e5177e5190e2c0ef014e81220c738f10; Wed, 06 May 2020 01:58:34 +0000 (UTC) Date: Wed, 6 May 2020 09:58:22 +0800 From: Gao Xiang To: Eric Biggers Cc: Gao Xiang , Jaegeuk Kim , 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: <20200506015813.GA9256@hsiangkao-HP-ZHAN-66-Pro-G1> References: <20200505153139.201697-1-jaegeuk@kernel.org> <20200505165847.GA98848@gmail.com> <20200505181323.GA55221@google.com> <20200505181941.GC98848@gmail.com> <20200506001403.GA2101@hsiangkao-HP-ZHAN-66-Pro-G1> <20200506012428.GG128280@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200506012428.GG128280@sol.localdomain> User-Agent: Mutt/1.10.1 (2018-07-13) X-Mailer: WebService/1.1.15756 hermes Apache-HttpAsyncClient/4.1.4 (Java/11.0.6) Content-Length: 3207 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks, Gao Xiang > > > > > > > > > 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'. > > > > directory counting towards 'inode->i_nlink == 1', what's happening? > > The non-deleted link is the one counted in i_nlink. > > > > > > > > > I think d_find_alias() is what we're looking for. > > > > It may be simply dentry->d_parent (stable/positive as you said before, and it's > > not empty). why need to d_find_alias()? > > Because we need to get the dentry that hasn't been deleted yet, which isn't > necessarily the one associated with the file descriptor being fsync()'ed. > > > And what is the original problem? I could not get some clue from the original > > patch description (I only saw some extra igrab/iput because of some unknown > > reasons), it there some backtrace related to the problem? > > The problem is that i_pino gets set incorrectly. I just noticed this while > reviewing the code. It's not hard to reproduce, e.g.: > > #include > #include > #include > > int main() > { > int fd; > > mkdir("dir1", 0700); > mkdir("dir2", 0700); > mknod("dir1/file", S_IFREG|0600, 0); > link("dir1/file", "dir2/file"); > fd = open("dir2/file", O_WRONLY); > unlink("dir2/file"); > write(fd, "X", 1); > fsync(fd); > } > > Then: > > sync > echo N | dump.f2fs -i $(stat -c %i dir1/file) /dev/vdb | grep 'i_pino' > echo "dir1 (correct): $(stat -c %i dir1)" > echo "dir2 (wrong): $(stat -c %i dir2)" > > i_pino will point to dir2 rather than dir1 as expected. > > - Eric > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel