Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp145228rdd; Wed, 22 Nov 2023 11:37:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOYkxgv23qODxF862BmnwropMoGU3eCbCF1ZCZEsWoAE93rS/i4DUFYOO/jqFGGtdORMHw X-Received: by 2002:a05:6830:44a1:b0:6d3:472b:f38d with SMTP id r33-20020a05683044a100b006d3472bf38dmr4787642otv.5.1700681860186; Wed, 22 Nov 2023 11:37:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700681860; cv=none; d=google.com; s=arc-20160816; b=LcpoPo/1ntLW2I5BSTk09qhLZOl+v4rlMx3dqffHo/jVNAvvbhrqwEpshs3Kdo6HRL WvnlXddwGuCck6g/Td5iNuKCk7+MizkgqWSA+FO6IlbXvlHihoRFZ3RNjpRbVyfwZFqj JiJDy4TmivMtoryeGJcXfQ8n8r0dgf9+HX7UV7jmlnH+8FM9V/SIlHE932xRrlK72JTm z0jtN6zqWguGpgLw4sl0wvOa0AU+49stFoSkOdJjJv6yvJ4ovVEV2G4nj8yVtUhbb0d0 9/12RrSdCj6ZMQn2rC59o0KL6qCp1i87RVAu0chclIPbBbDr8GoDlQG2TXRCXQg12+Hu A6vA== 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=74v1Dg7yBE+4rxKY7xG9GKf0VfPvIUvY43ZeQBhdM3Q=; fh=W6BEtqt7iV8phMzKg0C2MCZmXBORzGPTeuIhW3f8iqY=; b=Lt8CzthUaY//md4isCXg3/CjgmvPUVP0ZcRkmAb6claYGk8DOYI//kQ7+J7LM3dYLt qH8IbsBqSKTwzvy8Rnw/TCFJ/+9AsW3US+GxPTilA2lBMY9DyW8m11tK6XLEOcePAh5C u5d2xx8YuZcKXegB/5QbXWOJaNoyiAFM2u+61t1CBbCmtmjCnd1JwMr2rwjzI1X4+Sk0 5HmJvDW4wzUHp038inkQOMJpeSSHo2Mt7qOg7cC91JVwj+g+DY6l0RMBAsSC0NFq5fIt Ap+n2Y/qpWjrZ2YJEucw+oteD5kukIvNehDSbvhb9bC0+zFTkumUvSw6yTz2i4xTZMqI bA0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="flAxY/Wb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o31-20020a635a1f000000b005898e10f9b9si111901pgb.213.2023.11.22.11.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 11:37:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="flAxY/Wb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 145A5819DFCC; Wed, 22 Nov 2023 11:37:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344515AbjKVThE (ORCPT + 99 others); Wed, 22 Nov 2023 14:37:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344050AbjKVTg6 (ORCPT ); Wed, 22 Nov 2023 14:36:58 -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 9D1531A8; 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=74v1Dg7yBE+4rxKY7xG9GKf0VfPvIUvY43ZeQBhdM3Q=; b=flAxY/WbiiMK3fPdqrhtjrTbxn knWsKpeOfxS/4NrPxAIcl8WOgTbfTXsv0aD4CodgCbFtRtHRh66vrZXa+5JY3Rgn7LEdSvGS1DiMO kSrZkHjLnDAcilDWdjOzrILwGHoUz/p/al5cIA2WRE9QA9jcYJgZDkgvXuukrsHhU8Db9IqZR8gma 4EbU61wQYxwy/NpdYp7IL+2NKlEDEQX/7r9fWfe7WVxxh1WvoMtG8BCEniS6YnOodUM/LCcyJ0E8i lS7BEu4tFzW7o6EBDkkcrKvhMHj4sFIRILfKgOG6AFT1RAapGtNYrUBIStplYTjITEstVZC8PnDi5 AvB/GrOw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r5t1o-001l1g-2B; 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 2/9] ocfs2: Avoid touching renamed directory if parent does not change Date: Wed, 22 Nov 2023 19:36:45 +0000 Message-Id: <20231122193652.419091-2-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 Content-Transfer-Encoding: 8bit Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 22 Nov 2023 11:37:18 -0800 (PST) From: Jan Kara The VFS will not be locking moved directory if its parent does not change. Change ocfs2 rename code to avoid touching renamed directory if its parent does not change as without locking that can corrupt the filesystem. Signed-off-by: Jan Kara Signed-off-by: Al Viro --- fs/ocfs2/namei.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index 814733ba2f4b..9221a33f917b 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c @@ -1336,7 +1336,7 @@ static int ocfs2_rename(struct mnt_idmap *idmap, goto bail; } - if (S_ISDIR(old_inode->i_mode)) { + if (S_ISDIR(old_inode->i_mode) && new_dir != old_dir) { u64 old_inode_parent; update_dot_dot = 1; @@ -1353,8 +1353,7 @@ static int ocfs2_rename(struct mnt_idmap *idmap, goto bail; } - if (!new_inode && new_dir != old_dir && - new_dir->i_nlink >= ocfs2_link_max(osb)) { + if (!new_inode && new_dir->i_nlink >= ocfs2_link_max(osb)) { status = -EMLINK; goto bail; } @@ -1601,6 +1600,9 @@ static int ocfs2_rename(struct mnt_idmap *idmap, mlog_errno(status); goto bail; } + } + + if (S_ISDIR(old_inode->i_mode)) { drop_nlink(old_dir); if (new_inode) { drop_nlink(new_inode); -- 2.39.2