Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2068420rdh; Sat, 25 Nov 2023 12:12:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFjDmmimKHmtMW8UREZTp2l02RhyCtyYgIraeZrRQYhbaJS+QH55chGwD0padtyC0RoRCH X-Received: by 2002:a05:6a20:c523:b0:187:e9c4:32e4 with SMTP id gm35-20020a056a20c52300b00187e9c432e4mr8330542pzb.13.1700943145117; Sat, 25 Nov 2023 12:12:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700943145; cv=none; d=google.com; s=arc-20160816; b=oqcpm25EM1KIF1ozqiBbdWwzj9LP0WFecVAeyVm9WRkNOYLL1FmFFmOqLQXzJzINBt +i3Afg5tBrovWtmQwMoy7vfWzrjKXL7DS4PBWaRXKtu8brUUug1MdumU4QMbmaFw1Pcu 2KsOKbxe9R+AEPM+Vaykstd11n+Qo2w/Qs5qUkqP3cKTupatsl428PRU3lewdlA96/Cx +qGa+YbrhjfWKkuxYDKTLwVuComT0pXy3OsRQmIqYjDow3SKFb94Q+qtjBvndinjnmvM eg0nvIB7robUTsiv7cCSIipSMAsBaUy+Z2qlxWSB7XXhswUGhalj0hH5gfQ8G/izn4SK uSBA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1kXdQTzP9QbMwip9HhQkODeDCTy6uPz4pJDbGLrfwH4=; fh=W6BEtqt7iV8phMzKg0C2MCZmXBORzGPTeuIhW3f8iqY=; b=QPFlPmA/dImeoYTAIWdztdQa4vdp4HvGZUO5K0KrqQea2nMV5OGO7l5TBrqFWk78Mr TwhO8imMzPzskXiWrxjOVcYqy8GnYWBbADjyNHTBLEFqiPC1WYnCP6XlsgJi0GmLbSzm 6Y1Q7//zj+w22Ef/nCTFiKdx4bJgwq/O7C7dtL7PBMWfgOHymN0/cutqlU3sy/shfASO GiSseX9t/7YtELhx7un8/uE8Z57cRB2VA9XvFtl5ol+h4NJGyCYqq4CBE/Yv22J4yjYj PtKpDrrn03vGy9mjnzWQLWye6uZhWo/D0NWSucVYuHTBT8KTC2q7g5TDrP0OiAl1ZeVU iDXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=XcMyRMly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bw13-20020a056a02048d00b005b8f446408bsi6662667pgb.422.2023.11.25.12.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 12:12:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=XcMyRMly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 846EA8053661; Sat, 25 Nov 2023 12:12:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232394AbjKYULy (ORCPT + 99 others); Sat, 25 Nov 2023 15:11:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbjKYULn (ORCPT ); Sat, 25 Nov 2023 15:11:43 -0500 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2CF413A; Sat, 25 Nov 2023 12:11:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=1kXdQTzP9QbMwip9HhQkODeDCTy6uPz4pJDbGLrfwH4=; b=XcMyRMlyK2J+etyO+6P/aIB6ik pLcqvGbY9qBE5zywvQUnOf0X3uLFW0H/OpUKVdiK04VPwNrsLqjvhPHBz9mOKokwiHL9YFDTv+FT2 xtdJNbOEYAiUQlO2MBcaUBIk5/NjtuNmJTJZJC7ASCA5Mh0608tTMX5KwYtwL62OAKo35eWjOkmWH D9vMKMvDO4yEXVLkvxxOMgzDA0Ofw5bVdAbdVMv+hfTKPEzIO0B572Fm+Xfe5WQ3qpZpThf6yTB0W xZ/ltCn0C1GTsqp7raqEB7lXB+1gCCvH1FIHNnzRvrqzcyTzX2pBtst2B70lIa6sSLgR+94M8A7HX O/s6m2Pw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r6z0G-003A4n-0j; Sat, 25 Nov 2023 20:11:48 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Mo Zou , Jan Kara , linux-kernel@vger.kernel.org Subject: [PATCH v2 6/9] f2fs: Avoid reading renamed directory if parent does not change Date: Sat, 25 Nov 2023 20:11:44 +0000 Message-Id: <20231125201147.753695-6-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231125201147.753695-1-viro@zeniv.linux.org.uk> References: <20231125201015.GA38156@ZenIV> <20231125201147.753695-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sat, 25 Nov 2023 12:12:18 -0800 (PST) From: Jan Kara The VFS will not be locking moved directory if its parent does not change. Change f2fs rename code to avoid reading renamed directory if its parent does not change. Having it uninlined while we are reading it would cause trouble and we won't be able to rely upon ->i_rwsem on the directory being renamed in cases that do not alter its parent. Signed-off-by: Jan Kara Signed-off-by: Al Viro --- fs/f2fs/namei.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index d0053b0284d8..fdc97df6bb85 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -963,6 +963,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir, struct f2fs_dir_entry *old_dir_entry = NULL; struct f2fs_dir_entry *old_entry; struct f2fs_dir_entry *new_entry; + bool old_is_dir = S_ISDIR(old_inode->i_mode); int err; if (unlikely(f2fs_cp_error(sbi))) @@ -1017,7 +1018,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir, goto out; } - if (S_ISDIR(old_inode->i_mode)) { + if (old_is_dir && old_dir != new_dir) { old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page); if (!old_dir_entry) { if (IS_ERR(old_dir_page)) @@ -1029,7 +1030,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir, if (new_inode) { err = -ENOTEMPTY; - if (old_dir_entry && !f2fs_empty_dir(new_inode)) + if (old_is_dir && !f2fs_empty_dir(new_inode)) goto out_dir; err = -ENOENT; @@ -1054,7 +1055,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir, inode_set_ctime_current(new_inode); f2fs_down_write(&F2FS_I(new_inode)->i_sem); - if (old_dir_entry) + if (old_is_dir) f2fs_i_links_write(new_inode, false); f2fs_i_links_write(new_inode, false); f2fs_up_write(&F2FS_I(new_inode)->i_sem); @@ -1074,12 +1075,12 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir, goto out_dir; } - if (old_dir_entry) + if (old_is_dir) f2fs_i_links_write(new_dir, true); } f2fs_down_write(&F2FS_I(old_inode)->i_sem); - if (!old_dir_entry || whiteout) + if (!old_is_dir || whiteout) file_lost_pino(old_inode); else /* adjust dir's i_pino to pass fsck check */ @@ -1105,8 +1106,8 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir, iput(whiteout); } - if (old_dir_entry) { - if (old_dir != new_dir && !whiteout) + if (old_is_dir) { + if (old_dir_entry && !whiteout) f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir); else -- 2.39.2