Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp122707ybj; Wed, 6 May 2020 13:06:16 -0700 (PDT) X-Google-Smtp-Source: APiQypJg/OhYnF7sQqj9h1dwLeoDkSA7/pBeSa5t1UFdrvVF9fapd5zolXGKdMAdxQw/TscAXleZ X-Received: by 2002:a17:906:1696:: with SMTP id s22mr8704110ejd.302.1588795576688; Wed, 06 May 2020 13:06:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588795576; cv=none; d=google.com; s=arc-20160816; b=cwIrpILcIAlNHxJRy4zj5C3kOzoqn44GtLmJVH0BeqAlcZqSB4wKfD2sCA14Na4bEm OJDkyIGdQnc8sppIy8QU+zFivFAMIKrgauLTjzDk6BQ4otC7NmxWcb939BAe955vumuq OOWW8LXbSl0Fv0h/8zbFylrtkqVWAsUbkvpMHYmQSzVWEVG1eDQJlM/Y7kkdIM5YeyK8 /HE6Wmm+klhzHhN25szKGxcbia7XrDfYykiXccF1/cDgRFru9g/yknLGCfzAgt9y7aMM g3lvqXkjgnJD0ViyY0lNBCSFoyMXvWTLkXSPYsws5tdzA93K7yLpaJ8oz8TztP2NdgvR 5ZAw== 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=ulSUYx7ZjegD+oTS6cBVUEO4A/wK+Jxxywwgfcb628Y=; b=mvNB1uxGPHUR4l/r14FBW0Z0YqzZr3VUK0XYqlw1COLRwJDihOdpKSxnjxP1imdVgW sduBFvFbBoTt1M74gUB3j8t6MfXVgAUJAsr08BC+Tzal9NkygY83kaHqDR5ZqcHcI5+V ksxOH2PX0uCkVED1S5pMXAT3Gd3c1OaNSTtKVNrdoiaAWDnRsGPcVECRhbbiPFkLQiCX E+haLcu7yRiwY7w84+qRuXRP5CCXBYFlOLgrcscIEjC3jwTheF1juYAU5B7pMUGMkPjv E/c5Z7WNdM7s6qOC4Mf0irPBPGABiG7BItnQVBY3hnViJ4YYtAKRsHkZZ/86G1DDGKn2 F+2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bjYUPi2p; 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 n24si1894800ejs.457.2020.05.06.13.05.52; Wed, 06 May 2020 13:06:16 -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=bjYUPi2p; 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 S1728447AbgEFTQQ (ORCPT + 99 others); Wed, 6 May 2020 15:16:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:43758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728410AbgEFTQQ (ORCPT ); Wed, 6 May 2020 15:16:16 -0400 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (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 49C9E2075A; Wed, 6 May 2020 19:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588792575; bh=THl2Lpu9sfzGxpEl85CqvltCNIh7W5yIuzClFt9bv4U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bjYUPi2pTno6Scq4ERj8iiHIh0GEoMacr7jaA2J4s/5IsEU1LWt5+o/FCoeLtkmFK DxxtXGvfDR1GG96aaJqEqyebWNFBkIFPkxTQQzxoqE1ij9FvnN6vpdfeXvcarR2rp6 V5nPvdyZqzQ0PF6fqZkn4/A5yvF/qrA1pH9uGbDY= Date: Wed, 6 May 2020 12:16:13 -0700 From: Eric Biggers To: Gao Xiang Cc: 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: <20200506191613.GB842@sol.localdomain> 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> <20200506015813.GA9256@hsiangkao-HP-ZHAN-66-Pro-G1> <20200506064709.GA25482@hsiangkao-HP-ZHAN-66-Pro-G1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200506064709.GA25482@hsiangkao-HP-ZHAN-66-Pro-G1> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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... > 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. - Eric