Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp467618ybj; Wed, 6 May 2020 23:32:26 -0700 (PDT) X-Google-Smtp-Source: APiQypIoe5kdrm6SEzKmvdUhIQHjcN/fkyZh1uOns0BZ75C7fS1PUxpSTBqnCuxZD2HSEWz0e7U0 X-Received: by 2002:a17:907:2105:: with SMTP id qn5mr84578ejb.3.1588833146581; Wed, 06 May 2020 23:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588833146; cv=none; d=google.com; s=arc-20160816; b=Pyh/qLx5lPnWm8dqJS/KPIiC9kyIV46tuwCnJfgsNgahPIliCBY/YKMQ1uBzRtGBXY daRh75/fB1R5gjW/480K8kwp/4mAQ7OZVw/6GGbdJkKKTTNQR3PsQJcn8bmI1ShoK+8V dIE5A5152yWs01iaQc3kDUI4iGQOk9KK3Hqf96UImg+AiaHyrbQT7tynA6VNiDd58NnW EsYl/dXl+k1gQmchzF4rjpoNeie7ymYgfUxmgSZBinDC+v1XNE3DreflCSkl65jp+TuK xKIIPXW0asNDB3SZsBD1O+mPC25bg44PHX9tm8sge6gqC7ErbAbVRp3sV/r/NUqFL0/T gGRw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=yqSoh2DJaHkC9IPUJwj92SckpM2ygjFt35IigY1LTww=; b=TdV53b/nn/Nv5Po8hufez0M5bdej5BJ42N3xujhNKlvKgCLhy9vy/nkeIcwyYUROGZ 4cUCeM+aKI7iI5YM7TCagO3jEtDLOetdkfBU6vo35K90/UIymDev1EyzZKUwqrWF6Sc9 7YpZREXPnKbCz8KpUAPm38qcWzTAPvC3OZSkPLWSC3XiSMOLZn6xo3PORNACi7CoVqZ2 MlXXWCutYQZAupENVbcBRRQKy3zKO92iJEYF6ayQDyjf2U1dRUqOKM0IHDFxa4Eri4AT FVgrQWmaNqhnBjRawoQ4JvRQNqPIwjA/6hmDzVw4F1nmFzi/IngvJSRBPb0dxYRBkVN9 xdKg== ARC-Authentication-Results: i=1; mx.google.com; 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 j15si174697edt.516.2020.05.06.23.32.02; Wed, 06 May 2020 23:32:26 -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; 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 S1725809AbgEGGaX (ORCPT + 99 others); Thu, 7 May 2020 02:30:23 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:3881 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725783AbgEGGaW (ORCPT ); Thu, 7 May 2020 02:30:22 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3AD732D253226B4F4938; Thu, 7 May 2020 14:30:18 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.205) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 7 May 2020 14:30:16 +0800 Subject: Re: [f2fs-dev] [PATCH] f2fs: get parent inode when recovering pino From: Chao Yu To: Eric Biggers , Gao Xiang CC: Jaegeuk Kim , , , 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> <5641613f-48e0-171c-cfd0-e799e24d8d11@huawei.com> Message-ID: Date: Thu, 7 May 2020 14:30:15 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <5641613f-48e0-171c-cfd0-e799e24d8d11@huawei.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/5/6 14:55, Chao Yu wrote: > On 2020/5/6 9:24, 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. >> >>> >>>> >>>> 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. > > Could you add above testcase into commit message of your patch? it will > be easier to understand the issue we solved with it. > > In addition, how about adding this testcase in fstest as a generic one? Oops, it's not a generic one... please ignore this. > >> >> - Eric >> >> >> _______________________________________________ >> Linux-f2fs-devel mailing list >> Linux-f2fs-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel >> . >> > > > _______________________________________________ > Linux-f2fs-devel mailing list > Linux-f2fs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > . >