From patchwork Mon Jul 12 16:55:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 12371641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F65BC07E9C for ; Mon, 12 Jul 2021 16:56:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C12A760C3E for ; Mon, 12 Jul 2021 16:56:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C12A760C3E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7D10E6B009D; Mon, 12 Jul 2021 12:56:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FE4F6B00A4; Mon, 12 Jul 2021 12:56:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF1936B009B; Mon, 12 Jul 2021 12:56:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id 871836B009B for ; Mon, 12 Jul 2021 12:56:12 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 95AA4184E6526 for ; Mon, 12 Jul 2021 16:56:11 +0000 (UTC) X-FDA: 78354538542.10.B518470 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf14.hostedemail.com (Postfix) with ESMTP id 3A32360019A7 for ; Mon, 12 Jul 2021 16:56:11 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 041921FFD3; Mon, 12 Jul 2021 16:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1626108970; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QmszcyVRNOfyO141lqkqYDkpw92FHsSdEmKvmGCXqh4=; b=br6SCOFvzzW3pse2tlfBcXfiJwYYASdQGNFHn10uHXfn62xKZgpAD7QX02nANqnSiuUOvX fn8G4O1ygsjDUHl0obCsuYJEI5APpOMnpDfJU9+la6QDeRO9Gg2JWYPWHP7068mACqWOgb j94z/hCi/UmN83myK39qKuF+xK+79eI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1626108970; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QmszcyVRNOfyO141lqkqYDkpw92FHsSdEmKvmGCXqh4=; b=KItbtZFlBxJGcjExKeGtIesWGb0cegzWvtdtM3y5rEbnfAkLk1+qlIK1F3Y68HSy03wePF IFpQQiNSwcVyfdAg== Received: from quack2.suse.cz (unknown [10.100.224.230]) by relay2.suse.de (Postfix) with ESMTP id DCA44A3B8B; Mon, 12 Jul 2021 16:56:09 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id C2A441F2CD2; Mon, 12 Jul 2021 18:56:09 +0200 (CEST) From: Jan Kara To: Cc: , Christoph Hellwig , "Darrick J. Wong" , Ted Tso , Dave Chinner , Matthew Wilcox , , , linux-f2fs-devel@lists.sourceforge.net, linux-cifs@vger.kernel.org, ceph-devel@vger.kernel.org, Jan Kara , Christoph Hellwig Subject: [PATCH 04/14] mm: Add functions to lock invalidate_lock for two mappings Date: Mon, 12 Jul 2021 18:55:55 +0200 Message-Id: <20210712165609.13215-4-jack@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210712163901.29514-1-jack@suse.cz> References: <20210712163901.29514-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2711; h=from:subject; bh=n/id7CdzTitim6/Q4kdGwpm6fQ2I7WpUBKplzIVZqrg=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBg7HQck5dmKlHI2ci2Ul08y1JbXiN8coVEfYq6hR7g S9CBeRmJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCYOx0HAAKCRCcnaoHP2RA2cMMCA CBmLq4KWHGN4/73gYb+7lHTa7VRBTjJoZ+Oi50OoiHFqE5iGdPJ6T/3YBw8b1cSr5n4umcQf1wPy9Q ON0qo8Nxoz35wNwkzBnNNoGE7KytVDwMowWJTXaHzYwQ6gU0H4EzBM3E3/v2xCWZqNJfrvTVXf1qdr WT+MaP9r5rmMOKBO/rb7avUZkrQ91g6dItPcmEI72JnsF5JmMmTyIRLsbIR7+Y3+mvYS0+EMLVvUKy 52eXgZU3YjlB1w294ho4lmA9TeZI36AQxyIN74pwEWnHhY3+8vAuABIGttpjnw8gWE504G8hIS3Xbq qLtj/sXf/MlNFF2m7jQf7ohsJzj1Sn X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3A32360019A7 X-Stat-Signature: zrmro7c1u4p5og5zsfqkafphxnrz7wka Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=br6SCOFv; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=KItbtZFl; spf=pass (imf14.hostedemail.com: domain of jack@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none X-HE-Tag: 1626108971-893933 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Some operations such as reflinking blocks among files will need to lock invalidate_lock for two mappings. Add helper functions to do that. Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Jan Kara --- include/linux/fs.h | 6 ++++++ mm/filemap.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 90a80de37ad4..894ff2451793 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -849,6 +849,12 @@ static inline void filemap_invalidate_unlock_shared( void lock_two_nondirectories(struct inode *, struct inode*); void unlock_two_nondirectories(struct inode *, struct inode*); +void filemap_invalidate_lock_two(struct address_space *mapping1, + struct address_space *mapping2); +void filemap_invalidate_unlock_two(struct address_space *mapping1, + struct address_space *mapping2); + + /* * NOTE: in a 32bit arch with a preemptable kernel and * an UP compile the i_size_read/write must be atomic diff --git a/mm/filemap.c b/mm/filemap.c index 56988c4e655d..fd3f94d36c49 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1009,6 +1009,44 @@ struct page *__page_cache_alloc(gfp_t gfp) EXPORT_SYMBOL(__page_cache_alloc); #endif +/* + * filemap_invalidate_lock_two - lock invalidate_lock for two mappings + * + * Lock exclusively invalidate_lock of any passed mapping that is not NULL. + * + * @mapping1: the first mapping to lock + * @mapping2: the second mapping to lock + */ +void filemap_invalidate_lock_two(struct address_space *mapping1, + struct address_space *mapping2) +{ + if (mapping1 > mapping2) + swap(mapping1, mapping2); + if (mapping1) + down_write(&mapping1->invalidate_lock); + if (mapping2 && mapping1 != mapping2) + down_write_nested(&mapping2->invalidate_lock, 1); +} +EXPORT_SYMBOL(filemap_invalidate_lock_two); + +/* + * filemap_invalidate_unlock_two - unlock invalidate_lock for two mappings + * + * Unlock exclusive invalidate_lock of any passed mapping that is not NULL. + * + * @mapping1: the first mapping to unlock + * @mapping2: the second mapping to unlock + */ +void filemap_invalidate_unlock_two(struct address_space *mapping1, + struct address_space *mapping2) +{ + if (mapping1) + up_write(&mapping1->invalidate_lock); + if (mapping2 && mapping1 != mapping2) + up_write(&mapping2->invalidate_lock); +} +EXPORT_SYMBOL(filemap_invalidate_unlock_two); + /* * In order to wait for pages to become available there must be * waitqueues associated with pages. By using a hash table of