Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp497638ybj; Thu, 7 May 2020 00:26:33 -0700 (PDT) X-Google-Smtp-Source: APiQypJcDfns+wCciHiihxA+CSeNnKMYD2UXQ6CZhB/OZFunUpbsFSsNkcMinxJD9IOqqcsTwxLa X-Received: by 2002:a17:906:1d4c:: with SMTP id o12mr10994272ejh.357.1588836393251; Thu, 07 May 2020 00:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588836393; cv=none; d=google.com; s=arc-20160816; b=Oa/C+ddC7poTSS4e9y14bfFI0rhfGpk9wfXCKIhCCODPcwLpBnvIE0xoNXkUL7o1Rz QRG9SNoAxoMuIHOnumFeb4W6kXo7WfGZKGhXx5py9YpMySZfisy2nHVh0WhDtvTpMM9w dDveOKGC7bPY4zZwMk0Z+YZWlyL9ayjltPdDJOrkbF2Wi4FwvXh7oZ9/y86kWjmQY6Hs M2K9tzS4oeWdFnYZpJM8tl1w4ln3wFUuLRSxzFeI6kYzmnmyIswi/VidN/QCg5GfmjA+ bHuMcoxA2mXeX0MjXbpNOfKIGQj1vu546Ms47mEHz64I22DZqvAjDx3C0yRu2w4aKyS6 MECg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:user-agent :in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:dkim-signature; bh=yDHJMaoJHu0tife+9Ua4UP7+o6eb6uuudeWVAMMI1T8=; b=dbwKIs5WpIBLg/Mhcun0l9iqM4niXW6I6XBC0Gi3CEgYdokmfis5fwcQHUqUj87kNy M6JFttnN6p1duYew5fsoGgbqbOK9rW1qJJQgRknm7RifL9bSvGi1IbVaHgN7sUHUo9RQ 8ucNUzFaxHW0iWMXf+n2pv5vTJwgadFkZ6N1H3LSjqGHaHFUoPzJdabsLcw21r0H9Hrv T8uWeI5KeY1Qy8tI6Bgq4m2Rg/fKtuhw4HhVant/kD6cPHCIONIbizt+pQS+Jd4r5AnA e68wJ4sXTCBX+d5ZUiM2dGKOvfQGPxvDPqM5Fy7rIoqA1TiIyMVoyk0T+v4lpN3g5Slx xxVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=C17ZLiwp; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si2531175edi.331.2020.05.07.00.26.10; Thu, 07 May 2020 00:26:33 -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=@gmx.net header.s=badeba3b8450 header.b=C17ZLiwp; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725948AbgEGHYb (ORCPT + 99 others); Thu, 7 May 2020 03:24:31 -0400 Received: from mout.gmx.net ([212.227.15.18]:51165 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbgEGHYa (ORCPT ); Thu, 7 May 2020 03:24:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1588836246; bh=1f7xSnPEdtNZF/l6xObJrCpIG1v1Tm1LqvY2Hch0m2k=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=C17ZLiwpRGGOtauHfCiZIUCyzwfCQHfsfzkE0VZ67PksP8dIHROafvnHZvB6xcLD7 zTvOP4OIXdG80zj0n1qC90S2BsA0bFYpAGdNMISEN6h19ulnOjjGPw9bjoU2JWfm2l x1d0UpkSmmm91BlbghMISG9p+vZ3OQ903qO5mrbc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from hsiangkao-HP-ZHAN-66-Pro-G1 ([120.242.76.42]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MyKHm-1jDoTp2qCq-00yffE; Thu, 07 May 2020 09:24:06 +0200 Date: Thu, 7 May 2020 15:23:58 +0800 From: Gao Xiang To: Chao Yu Cc: Eric Biggers , 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: <20200507072349.GA5471@hsiangkao-HP-ZHAN-66-Pro-G1> References: <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> <20200506191613.GB842@sol.localdomain> <20200506223623.GA27760@hsiangkao-HP-ZHAN-66-Pro-G1> <3a837113-8081-6f01-4d8d-1d4b6600ec8c@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3a837113-8081-6f01-4d8d-1d4b6600ec8c@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Provags-ID: V03:K1:epqsfvnjrfMegoglZ2H2SlmDtQ2iTA+h+5MT5XYtZ6wVemawXz7 KjfgSxr+hQ0R5ywX5ysTbjFNYPp/HKEBeb4AL72vBRB27jsQhq+tVJYpEKAN7aBQ631OZ7W uuh/Urv9Dqj3BnfreYV9OCswoeNSpxZZQsilL85sOFO5tTSuv1vKagOEeurrh2/u8NyMRFL xfDzmyLqZlNg/d4dlslrw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03: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vhMhCsqopM74RhEDCrTlcmCjpsvTuc4ByUDKTLZg4MjdJRarWiTX1J+f4sLipEqLF4 iw+LUtfsKoqvoYHZOSgxoB7U4hC0iG/yXwAg1vZ0+VTmNDFUO+j38gU0qrkZnf7TjZywBqFW1 vHHBCe5Pt12BO25DN836ohCvlPAfDsj/yn7KYQXidBQuhmCVf9xm9OzYxoq21DmZ5sIij6aXX fzR9bn9GD0EH/3xhj Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chao, On Thu, May 07, 2020 at 02:38:39PM +0800, Chao Yu wrote: > On 2020/5/7 6:36, Gao Xiang wrote: > > On Wed, May 06, 2020 at 12:16:13PM -0700, Eric Biggers wrote: > >> 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 vi= a 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 knowl= edge? > >>>>>> inode itself is locked when fsyncing, so > >>>>>> > >>>>>> if the fsync inode->i_nlink =3D=3D 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 a= s well) > >>>>>> since there are some dirents in it (not empty). > >>>>>> > >>>>>> Could kindly explain more so I would learn more about this scenar= io? > >>>>>> Thanks a lot! > >>>>> > >>>>> i_nlink =3D=3D 1 just means that there is one non-deleted link. T= here can be links > >>>>> that have since been deleted, and file descriptors can still be op= en to them. > >>>> > >>>> Thanks for your inspiration. You are right, thanks. > >>>> > >>>> Correct my words... I didn't check f2fs code just now, it seems f2f= s 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. I= t 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_pin= o > >>> f2fs_unlink > >>> f2fs_delete_entry > >>> f2fs_drop_nlink (i_sem, inode->i_nlink =3D 1) > >>> > >>> (... but this dentry still hashed) i_sem, check= inode->i_nlink =3D 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... > > Another race condition could be: > > Thread 1 (fsync) Thread 2 (rename) > - f2fs_sync_fs > - try_to_fix_pino > - f2fs_rename > - down_write > - file_lost_pino > - up_write > - down_write > - file_got_pino > - up_write Yes, IMHO, I think it could be not proper to take dir lock in fsync path anyway... I would suggest as before (if it needs to be fixed). And it seems no significant performance difference. Thanks, Gao Xiang > > Thanks, > > >>> > >> > >> Right, good observation. My patch makes it better, but it's still br= oken. > >> > >> I don't know how to fix it. If we see i_nlink =3D=3D 1 and multiple = hashed > >> dentries, there doesn't appear to be a way to distingush which one co= rresponds > >> to the remaining link on-disk (if any; it may not even be in the dcac= he), 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 probl= ems. > >> > >> 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 t= o match the > >> new directory. So independently of this bug with deleted links, I do= n't see how > >> it can possibly work as intended. > > > > Part of my humble opinion would be "update pino in rename/unlink/link.= .. such ops > > instead of in fsync" (maybe it makes better sense of locking)... But a= ctually I'm > > not a f2fs folk now, just curious about what the original patch resolv= ed with > > these new extra igrab/iput (as I said before, I could not find some cl= ue previously). > > > > Thanks, > > Gao Xiang > > > >> > >> - Eric > > > > > > _______________________________________________ > > Linux-f2fs-devel mailing list > > Linux-f2fs-devel@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > > . > >