From patchwork Tue Dec 5 02:24:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 173655 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3171612vqy; Mon, 4 Dec 2023 18:25:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdQUtUpagqZ04CkitvuTSGz1xoSS07K9M2Txf7OPEfYwsgqrOC7POQzCb1DhO+AjrJBzmr X-Received: by 2002:a05:6830:1303:b0:6d8:7cfa:12a4 with SMTP id p3-20020a056830130300b006d87cfa12a4mr4103745otq.72.1701743116806; Mon, 04 Dec 2023 18:25:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701743116; cv=none; d=google.com; s=arc-20160816; b=ncnEDdrNf2BCWCjC6gkioNijK0EQBum7XXQ03v2uOFgNCDM7SqMCicFcOkqXNy+h+u MRd6Yqx3uFxMxi6B7TxlBVslij0NvwgCORIugILtqC/azsO+U4yWu5hO3ui0CHleV+8A sLZ0ML6jr4ow9/eILfeIRaUU4CYJRiySPjQyldDO8EsyM5gS8JMFUUpd6vu2O+gVLdGi lyjPTG7SJpqHl0q/U3ADV9hUwNzytVpnkgcgv0npTQKzp9l6ECKhhTNds0JsXciXpUBY tuXnYhBVZUnwmy9Bbiygp/v2+4VufXY8lCwuGwKBX9o+i0PaF8nmMgbcva7e+3WDXzXQ LIGQ== 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=MXd1D7yrhiKOU6TnSrHtQJWPS/0VvoZfIFu1ppuy74Y=; fh=DgGXwGbnyiv1Rvt/NkXbEKOXDvWVLBCb4IpCdacEJoI=; b=Vq9fWaVWq69Zp13iHcNhDeA+nWbmq7xPCVZfIvr5Jj7FEU49KNJqE7rorgkvDY7hAd GQ1wDA0PTK29whuH30LaeXvKFXWMLtAnxkJOswq6dpjsY8Q8MoDHuMTgbDZlSC0y+OMQ EacqW3JJaxV2hSBx28hoIeskWzElI3Wccj/MFfgLgSuwrW3O7tcdeGYOr45fwzH9bqiU 74p4MI+0mIFYXhKW7Wcnz9SKnM46uBwFfpCJEmZ7iscK5SirG2Up7nDy867Tpqz3uKSV vXJMG4QWYr/zFes+odZ4ZAMDudGNTLoT/Gasf84GWbzg6B96/2VWCkS3F2liVhtt87GA V78g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=HU7imc8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bm1-20020a656e81000000b005b56de1fd82si8971679pgb.272.2023.12.04.18.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:25:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=HU7imc8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id D17338051A34; Mon, 4 Dec 2023 18:25:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344058AbjLECYW (ORCPT + 99 others); Mon, 4 Dec 2023 21:24:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234837AbjLECYQ (ORCPT ); Mon, 4 Dec 2023 21:24:16 -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 49311119; Mon, 4 Dec 2023 18:24:23 -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=MXd1D7yrhiKOU6TnSrHtQJWPS/0VvoZfIFu1ppuy74Y=; b=HU7imc8MVTYmCfuLopTpwdRiVO ZY5qEnjq7pFb1Iq9nr8VSEW7F7WYt8ZFkc/uctjVk6OI0feqjHi05XDaV6I7nz+0tFQzyhH4Ol8C+ vyibxRJczNvuLDegkk7gfBB1DARvN5LOh6otyTax/3v0XkSCGwuflm7wQ4EKlAKiN71JKYMfOdvsR 0DjC1rVe97oZK42zTON+8mIE9d55myiaQ9B07km9jirHB7cfhgvW+8hUNYrzMvPjC/cIhsh9tonkc zN0BO6Ng7jMlrRnceS13ThyUchQl/eg0qQ9uQRUyHIhg2zOq+6aNOzdG4WsVEtQG0T+zxjMiqtlGK eDsffV5Q==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1rAL6j-00792z-1t; Tue, 05 Dec 2023 02:24:21 +0000 From: Al Viro To: linux-arch@vger.kernel.org Cc: gus Gusenleitner Klaus , Al Viro , Thomas Gleixner , lkml , Ingo Molnar , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "David S. Miller" , "dsahern@kernel.org" , "kuba@kernel.org" , Paolo Abeni , Eric Dumazet Subject: [PATCH v2 8/9] kill lock_two_inodes() Date: Tue, 5 Dec 2023 02:24:07 +0000 Message-Id: <20231205022418.1703007-16-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231205022418.1703007-1-viro@zeniv.linux.org.uk> References: <20231205022100.GB1674809@ZenIV> <20231205022418.1703007-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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 18:25:11 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784406990053732205 X-GMAIL-MSGID: 1784406990053732205 There's only one caller left (lock_two_nondirectories()), and it needs less complexity. Fold lock_two_inodes() in there and simplify. Reviewed-by: Jan Kara Signed-off-by: Al Viro --- fs/inode.c | 49 ++++++------------------------------------------- fs/internal.h | 2 -- 2 files changed, 6 insertions(+), 45 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index edcd8a61975f..453d5be1a014 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1087,48 +1087,6 @@ void discard_new_inode(struct inode *inode) } EXPORT_SYMBOL(discard_new_inode); -/** - * lock_two_inodes - lock two inodes (may be regular files but also dirs) - * - * Lock any non-NULL argument. The caller must make sure that if he is passing - * in two directories, one is not ancestor of the other. Zero, one or two - * objects may be locked by this function. - * - * @inode1: first inode to lock - * @inode2: second inode to lock - * @subclass1: inode lock subclass for the first lock obtained - * @subclass2: inode lock subclass for the second lock obtained - */ -void lock_two_inodes(struct inode *inode1, struct inode *inode2, - unsigned subclass1, unsigned subclass2) -{ - if (!inode1 || !inode2) { - /* - * Make sure @subclass1 will be used for the acquired lock. - * This is not strictly necessary (no current caller cares) but - * let's keep things consistent. - */ - if (!inode1) - swap(inode1, inode2); - goto lock; - } - - /* - * If one object is directory and the other is not, we must make sure - * to lock directory first as the other object may be its child. - */ - if (S_ISDIR(inode2->i_mode) == S_ISDIR(inode1->i_mode)) { - if (inode1 > inode2) - swap(inode1, inode2); - } else if (!S_ISDIR(inode1->i_mode)) - swap(inode1, inode2); -lock: - if (inode1) - inode_lock_nested(inode1, subclass1); - if (inode2 && inode2 != inode1) - inode_lock_nested(inode2, subclass2); -} - /** * lock_two_nondirectories - take two i_mutexes on non-directory objects * @@ -1144,7 +1102,12 @@ void lock_two_nondirectories(struct inode *inode1, struct inode *inode2) WARN_ON_ONCE(S_ISDIR(inode1->i_mode)); if (inode2) WARN_ON_ONCE(S_ISDIR(inode2->i_mode)); - lock_two_inodes(inode1, inode2, I_MUTEX_NORMAL, I_MUTEX_NONDIR2); + if (inode1 > inode2) + swap(inode1, inode2); + if (inode1) + inode_lock(inode1); + if (inode2 && inode2 != inode1) + inode_lock_nested(inode2, I_MUTEX_NONDIR2); } EXPORT_SYMBOL(lock_two_nondirectories); diff --git a/fs/internal.h b/fs/internal.h index 58e43341aebf..de67b02226e5 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -196,8 +196,6 @@ extern long prune_icache_sb(struct super_block *sb, struct shrink_control *sc); int dentry_needs_remove_privs(struct mnt_idmap *, struct dentry *dentry); bool in_group_or_capable(struct mnt_idmap *idmap, const struct inode *inode, vfsgid_t vfsgid); -void lock_two_inodes(struct inode *inode1, struct inode *inode2, - unsigned subclass1, unsigned subclass2); /* * fs-writeback.c