From patchwork Wed Nov 22 19:36:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 168542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b82:b0:430:37f2:e94a with SMTP id ip2csp1583713vqb; Wed, 22 Nov 2023 11:38:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0h8RB8wySdJI1SfFIHlnoNFHp4JnxbX8ymcsaCDvyvLSYDoYwOUnaIH2ncxblOsT/fHgD X-Received: by 2002:a05:6808:1587:b0:3b8:4762:1e7b with SMTP id t7-20020a056808158700b003b847621e7bmr779231oiw.24.1700681893502; Wed, 22 Nov 2023 11:38:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700681893; cv=none; d=google.com; s=arc-20160816; b=rMZxdZ/nelPvqgL1IBUMnnrvOf99MU2iJIwCVUhfaiqjhAruhkCGWuKShDEdvtBhcg efgO0QeldaxbzPXNuUWHoWIdZRaBIwu9pj/jfFZivn+gJByOVRWBH5hLRfij3yJe5Y7L 21RkvHf2vut+HBlJeHOAbHzYegh8Jk/nWFXkKGZe8Jd4WxSbRP/uhr08RqvVm1ynpDiy PgXgEAReDdnSZm+NnLqwyO3Y7V1DHBqwKW0QkKqGjvxASpuK7XOdMlaL2Vx+BWDDhZKj 9rmsmAFq0VWnrt72JKG9+XAp9NadUO7e79M4cntsRWCQN8CDDfelfH3YVbraz++bSkL4 GUGg== 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=rNmpOBKWoYfvVrhEukRAAHBSo1Q96GuxaczyMAbV7AU=; fh=W6BEtqt7iV8phMzKg0C2MCZmXBORzGPTeuIhW3f8iqY=; b=dX0yq23eBO+vE9+HHBrqvYRaEYXwpSEMWRcdJw2pePBfNPaRXhZyayJKkyDuyXCCJl BYJNNwMSjeH1asSvPIbQQuNvH1HcIsTxXJAJhJN8zVW6ZQWaoF6Mww+IuVL64eyP75AN p56QOLsnp5dR5jOeVZQqVfgqP6dutko+c5FY4rkvN5iShWOGtnT0UCzW2HcsTus9SWiD j3qheiTa865U4lbl4binYBy03IlKTkaAYLt5tVuhAcJqPVaOO1alhAkfyJ9arIrGzLNV imqxN1mke/TUnOelTT/hvd63HEmPiE/bd4y0ceXaF1Ck736uAh4S9PbsVBxZgR6N2tgZ bClQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=pG8jo4TP; 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id n62-20020a632741000000b005b999968b87si100473pgn.580.2023.11.22.11.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 11:38:13 -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=pG8jo4TP; 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 6FE408226F65; Wed, 22 Nov 2023 11:37:37 -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 S1344585AbjKVThL (ORCPT + 99 others); Wed, 22 Nov 2023 14:37:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344421AbjKVTg7 (ORCPT ); Wed, 22 Nov 2023 14:36:59 -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 9D47A1AE; Wed, 22 Nov 2023 11:36:54 -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=rNmpOBKWoYfvVrhEukRAAHBSo1Q96GuxaczyMAbV7AU=; b=pG8jo4TPLP4OImKO1wWH4A1imn jY0RlChB5b9gcRdaSNvfTTygnHegbVfpY3EmJWx5Z6c1WUqI/Io1RU5pcNeH22yLPk54ZUe2T4eCf o7jGAJSzH3FksmBNhRWpSPA56egeiD7tUjiBFz/FIk6xNOI0PDTRmIgwzQqwuGaNueXaYKsGdKZgX LTNxN7fbMbs0T4dweEgv9ND+T8geZzkwX3NNjV1vAmzeCHrfSl3wL38z8I5eEhr/8ri0PHe5NfpVf tZwIHghZnX3G1D5CBeRIaW52QlCUgo4GEXaw/XBli2BF+5eLGwQU6PjNGOGHOtOm66D50TaHNVpnG ukkxBUZw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r5t1o-001l1i-2l; Wed, 22 Nov 2023 19:36:52 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Mo Zou , Jan Kara , linux-kernel@vger.kernel.org Subject: [PATCH 3/9] udf_rename(): only access the child content on cross-directory rename Date: Wed, 22 Nov 2023 19:36:46 +0000 Message-Id: <20231122193652.419091-3-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231122193652.419091-1-viro@zeniv.linux.org.uk> References: <20231122193028.GE38156@ZenIV> <20231122193652.419091-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 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]); Wed, 22 Nov 2023 11:37:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783294217558872529 X-GMAIL-MSGID: 1783294217558872529 We can't really afford locking the source on same-directory rename; currently vfs_rename() tries to do that, but it will have to be changed. The logics in udf_rename() is lazy and goes looking for ".." in source even in same-directory case. It's not hard to get rid of that, leaving that behaviour only for cross-directory case; that VFS can get locks safely (and will keep doing that after the coming changes). Signed-off-by: Al Viro Reviewed-by: Jan Kara --- fs/udf/namei.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 3508ac484da3..fac806a7a8d4 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -766,7 +766,7 @@ static int udf_rename(struct mnt_idmap *idmap, struct inode *old_dir, struct inode *old_inode = d_inode(old_dentry); struct inode *new_inode = d_inode(new_dentry); struct udf_fileident_iter oiter, niter, diriter; - bool has_diriter = false; + bool has_diriter = false, is_dir = false; int retval; struct kernel_lb_addr tloc; @@ -789,6 +789,9 @@ static int udf_rename(struct mnt_idmap *idmap, struct inode *old_dir, if (!empty_dir(new_inode)) goto out_oiter; } + is_dir = true; + } + if (is_dir && old_dir != new_dir) { retval = udf_fiiter_find_entry(old_inode, &dotdot_name, &diriter); if (retval == -ENOENT) { @@ -878,7 +881,9 @@ static int udf_rename(struct mnt_idmap *idmap, struct inode *old_dir, udf_dir_entry_len(&diriter.fi)); udf_fiiter_write_fi(&diriter, NULL); udf_fiiter_release(&diriter); + } + if (is_dir) { inode_dec_link_count(old_dir); if (new_inode) inode_dec_link_count(new_inode);