Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp145553rdd; Wed, 22 Nov 2023 11:38:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvnWLBOPA9/xfkmS7Q3eWH7qyOBd5SRMkAjtiUCrcCZcf8GOenXrIXwxzWQF+LqXnsGdqX X-Received: by 2002:a17:902:8607:b0:1cc:32b7:e5b9 with SMTP id f7-20020a170902860700b001cc32b7e5b9mr3052643plo.67.1700681901203; Wed, 22 Nov 2023 11:38:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700681901; cv=none; d=google.com; s=arc-20160816; b=WPkO29nlLjLtxUT4Uaa1XE7MU58OPfig7/ElFRRs/e2U0pF7ohnIAEKBW56uEL81F0 XCxapSB2oUWYFmS9VJCNXrUs+zPtdd8T7y0N9YJ8xAOwwNJuZon9+foGvU07Y+mcoPnk yTJtEHFQD/sTSzzwcKcSGs6P9xDiVKTB2KHRK6Zn0c3VFM1xBckPDppNKb7yMVxq+0hx 6aI8H7+KiXDvfkEd2VdAywIZxtTFjfrlo0RYNdLCyW6VTDp8E0yaUF5fBx98OJPRnyRC ub7FwOBgDsGCPkklOQc97hxWdnJhMTw+WzgmdpCZgtynaZcLnhVjZ19x4jCdtijUFTLo dnVg== 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=8QOQpop95kL18saXqv/BTfGcqZ0IcnSd0yUZGFIOYns=; fh=W6BEtqt7iV8phMzKg0C2MCZmXBORzGPTeuIhW3f8iqY=; b=yNmHQuEj9r9jncFtWJOckPIZNSDDGX74YfbAwg8WRygv5mTbBwKe1dknLHnH5TCZDA 3CbWz+oNRUeFwOpKij8TgA/JmsvRoAjTW3BNRwXApLg7gF3+ze09PgmvXespW2upnUi/ HS/BprrrwjdyA7aY44a6umgnJTddyxihorf5sSzPSoBnQXCSmJoIqVExsGtaTzCwfM+6 bQl73zF8/k5LOkpbAGHRarymSWWt3qyElAcwftN6OzNI9EYgpkOozDME8QptYaP4FfxL 4A5kzsn3nYMbqqfGMVP74rBaTK7La8nqlZjzIfThehfqfMkKHqJ8KTRSJjuuBLcBnXBG Pi8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=C35Pzkvi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id z7-20020a170903018700b001ce5b99a558si85017plg.519.2023.11.22.11.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 11:38:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=C35Pzkvi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id EAAF28271767; Wed, 22 Nov 2023 11:37:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344513AbjKVThJ (ORCPT + 99 others); Wed, 22 Nov 2023 14:37:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344443AbjKVTg7 (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 E18AC1B6; 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=8QOQpop95kL18saXqv/BTfGcqZ0IcnSd0yUZGFIOYns=; b=C35Pzkvi4HIowDl9UXBA5b+YHW C+sNIcDjX6bYZayTNn5EehZyXWftX+Gl1rMAOvyYClQuWLiRaCqo4cyPYPCyBDMF38WP+WSiKxHld YvhpNg59pNQw4rbRLRmWpMhhBimau0x/2JXNpHJPqFxrROBxvFHlND3OPyIZ9tlJY+BZeyg8CJ8aT CuLvxELVcWkzvrB7JqMN9kpgNGjzhSXUYXpr5H+5pc+OzpUZjk25yJ4BPztH10ohblVsYkrP6Ln3L imJVt9DatNbrjJDgYaZX6l9DSst+EfsoM7R8ssMo9UxQ3f4z0IgCURffIHG98QPJjgRlMETAFscwb cNQkZckg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r5t1p-001l24-1t; Wed, 22 Nov 2023 19:36:53 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Mo Zou , Jan Kara , linux-kernel@vger.kernel.org Subject: [PATCH 8/9] kill lock_two_inodes() Date: Wed, 22 Nov 2023 19:36:51 +0000 Message-Id: <20231122193652.419091-8-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=-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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 22 Nov 2023 11:37:56 -0800 (PST) There's only one caller left (lock_two_nondirectories()), and it needs less complexity. Fold lock_two_inodes() in there and simplify. 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 -- 2.39.2