Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5040799ybl; Mon, 9 Dec 2019 22:38:59 -0800 (PST) X-Google-Smtp-Source: APXvYqwq6qn0PbGhZO3p6v4MIoCzVoVlSLLsspjfP/FfL0k3PLx/pnMk4aZhTBfomhQbiM+/+dq6 X-Received: by 2002:a05:6830:22ee:: with SMTP id t14mr23699979otc.236.1575959939830; Mon, 09 Dec 2019 22:38:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575959939; cv=none; d=google.com; s=arc-20160816; b=V/F6cz88A7RDScoqStHZERMlVEHw2g9l52Vkl2CJGOBXwZbxzuema4mj4/7bTDQWM8 dFQZe5DCLGkTjnSWDRb65UJE1calDQyAc2dwrxyMSU6uioMg34i1pQ0KPN8Vw40lGDf+ Mtp+O4aDgPHjVqWsZtBtP1JMi3INmipmvjT0Jc4I9dKJDHdZ47Sqx70ngUKfvrxK+phf skeGSLjRQpSKQbpVnTMZ8vwjlLpVMhsKYV0MbyFpVn0PUknr4pg72/09mR+6udlihD43 uQRe4O+ulQEXaeNiPxxtozF7VEfCw8eMhr2Wcs/IGDcmbiZe2cuQsS/fRVM4P1eydR+F C4Jg== 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:from:references:to:subject; bh=frPw481aHi6Ln/4J/endnTXFjebWJ/Je0pBOKuL/Vas=; b=ZtgTqb8gdoauqc38P3gQ3YGsYGg+GVK6dWmSpboNdnBQpdlqMeXB5j4CG3nVmGsBi5 G+HCkbg7uWnczil89nvS9+MZvwPFITSNp9q1IIW1hr7lMMTZ1OwYmnjkp4NGN0E7NWDY 3xwtB+QIw7l9v2RjyzHYG+GWdb9qTpSBEa+B/9awxkCOzrUBRrJg2YAp14x04mCBzfUw kwlqPB1Ofptnogn9m3URyj/U0b2fd9zz3jvq6YoVacddccZ7yg+1o9RGBk4VF5gOXwPn rFz1OpzPG/50H/WnWrx3ub1KdYHStAb6aCOUfoFHI64M+uth4gM4HgM5lgb/Zv3tRytM wkqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x9si1395545otk.170.2019.12.09.22.38.46; Mon, 09 Dec 2019 22:38:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727143AbfLJGh6 (ORCPT + 99 others); Tue, 10 Dec 2019 01:37:58 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:45538 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726819AbfLJGh6 (ORCPT ); Tue, 10 Dec 2019 01:37:58 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id AFFE434B85D5EC5B8A6E; Tue, 10 Dec 2019 14:37:55 +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.439.0; Tue, 10 Dec 2019 14:37:50 +0800 Subject: Re: [f2fs-dev] [PATCH 6/6] f2fs: set I_LINKABLE early to avoid wrong access by vfs To: Jaegeuk Kim , , References: <20191209222345.1078-1-jaegeuk@kernel.org> <20191209222345.1078-6-jaegeuk@kernel.org> From: Chao Yu Message-ID: <88dcbca9-3757-a440-ed73-9d99a56b816c@huawei.com> Date: Tue, 10 Dec 2019 14:37:49 +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: <20191209222345.1078-6-jaegeuk@kernel.org> 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 2019/12/10 6:23, Jaegeuk Kim wrote: > This patch moves setting I_LINKABLE early in rename2(whiteout) to avoid the > below warning. > > [ 3189.163385] WARNING: CPU: 3 PID: 59523 at fs/inode.c:358 inc_nlink+0x32/0x40 > [ 3189.246979] Call Trace: > [ 3189.248707] f2fs_init_inode_metadata+0x2d6/0x440 [f2fs] > [ 3189.251399] f2fs_add_inline_entry+0x162/0x8c0 [f2fs] > [ 3189.254010] f2fs_add_dentry+0x69/0xe0 [f2fs] > [ 3189.256353] f2fs_do_add_link+0xc5/0x100 [f2fs] > [ 3189.258774] f2fs_rename2+0xabf/0x1010 [f2fs] > [ 3189.261079] vfs_rename+0x3f8/0xaa0 > [ 3189.263056] ? tomoyo_path_rename+0x44/0x60 > [ 3189.265283] ? do_renameat2+0x49b/0x550 > [ 3189.267324] do_renameat2+0x49b/0x550 > [ 3189.269316] __x64_sys_renameat2+0x20/0x30 > [ 3189.271441] do_syscall_64+0x5a/0x230 > [ 3189.273410] entry_SYSCALL_64_after_hwframe+0x49/0xbe > [ 3189.275848] RIP: 0033:0x7f270b4d9a49 > > Signed-off-by: Jaegeuk Kim > --- > fs/f2fs/namei.c | 27 +++++++++++++-------------- > 1 file changed, 13 insertions(+), 14 deletions(-) > > diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c > index a1c507b0b4ac..5d9584281935 100644 > --- a/fs/f2fs/namei.c > +++ b/fs/f2fs/namei.c > @@ -797,6 +797,7 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry, > > if (whiteout) { > f2fs_i_links_write(inode, false); > + inode->i_state |= I_LINKABLE; > *whiteout = inode; > } else { > d_tmpfile(dentry, inode); > @@ -867,6 +868,12 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > F2FS_I(old_dentry->d_inode)->i_projid))) > return -EXDEV; > > + if (flags & RENAME_WHITEOUT) { > + err = f2fs_create_whiteout(old_dir, &whiteout); > + if (err) > + return err; > + } To record quota info correctly, we need to create whiteout inode after dquot_initialize(old_dir)? > + > err = dquot_initialize(old_dir); > if (err) > goto out; > @@ -898,17 +905,11 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > } > } > > - if (flags & RENAME_WHITEOUT) { > - err = f2fs_create_whiteout(old_dir, &whiteout); > - if (err) > - goto out_dir; > - } > - > if (new_inode) { > > err = -ENOTEMPTY; > if (old_dir_entry && !f2fs_empty_dir(new_inode)) > - goto out_whiteout; > + goto out_dir; > > err = -ENOENT; > new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, > @@ -916,7 +917,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > if (!new_entry) { > if (IS_ERR(new_page)) > err = PTR_ERR(new_page); > - goto out_whiteout; > + goto out_dir; > } > > f2fs_balance_fs(sbi, true); > @@ -948,7 +949,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > err = f2fs_add_link(new_dentry, old_inode); > if (err) { > f2fs_unlock_op(sbi); > - goto out_whiteout; > + goto out_dir; > } > > if (old_dir_entry) > @@ -972,7 +973,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > if (IS_ERR(old_page)) > err = PTR_ERR(old_page); > f2fs_unlock_op(sbi); > - goto out_whiteout; > + goto out_dir; > } > } > } > @@ -991,7 +992,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > f2fs_delete_entry(old_entry, old_page, old_dir, NULL); > > if (whiteout) { > - whiteout->i_state |= I_LINKABLE; > set_inode_flag(whiteout, FI_INC_LINK); > err = f2fs_add_link(old_dentry, whiteout); [ 3189.256353] f2fs_do_add_link+0xc5/0x100 [f2fs] [ 3189.258774] f2fs_rename2+0xabf/0x1010 [f2fs] Does the call stack point here? if so, we have set I_LINKABLE before f2fs_add_link(), why the warning still be triggered? Thanks, > if (err) > @@ -1027,15 +1027,14 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > f2fs_unlock_op(sbi); > if (new_page) > f2fs_put_page(new_page, 0); > -out_whiteout: > - if (whiteout) > - iput(whiteout); > out_dir: > if (old_dir_entry) > f2fs_put_page(old_dir_page, 0); > out_old: > f2fs_put_page(old_page, 0); > out: > + if (whiteout) > + iput(whiteout); > return err; > } > >