From mboxrd@z Thu Jan 1 00:00:00 1970 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=unavailable 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 53E35C47099 for ; Tue, 25 May 2021 13:51:38 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A91A6140E; Tue, 25 May 2021 13:51:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A91A6140E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.92.3) (envelope-from ) id 1llXT6-0005YY-Mn; Tue, 25 May 2021 13:51:36 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1llXT2-0005XP-L6 for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 May 2021 13:51:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Xd8OifYoNQOCikHzR++3NeOR/xz1/yXNT7sn6d6yzXM=; b=c6zxLmiV70yd48KTw+32LFlRKY jIqLNhpvMPA/Tppe3/1YEmh9uE7/TomD0OQUybNGVpx5p9GN5cE/S7wOEbbRvllCvcntoRmZwhB9V BHL2iBukQnIZ9kNLRjXnOUFAGASFCDnAVZXnAmGHtpa1hDuHUTJw+F72orhIDR3E8XEY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Xd8OifYoNQOCikHzR++3NeOR/xz1/yXNT7sn6d6yzXM=; b=cu8L2CDJIfc74Of3B8GcU/JllY UxIipKww57UHgg3V7RHgFbBjH7bjVnUkqP728PalyEfKFhuQWPNSxcvU3P/E4HEdOw5Hk1O/4/Nnj Ki3omV/sj9NCPEcGBIQdPn+SrUaHj4Obn9e12iZhVNcn/HarRp9HwmdneATM0pUdETjA=; Received: from mx2.suse.de ([195.135.220.15]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) id 1llXSj-0003aw-UM for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 May 2021 13:51:21 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1621950662; 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=Xd8OifYoNQOCikHzR++3NeOR/xz1/yXNT7sn6d6yzXM=; b=nm1y6L5sx98fW3ya4ETm6cobwGk3mK4Rbvr0dd27LA7T6Klpj7rp6OLoBr98OmknmeMiA0 GAiNM/TDxIeAirMs1kSu3QJu7SyCutfA5NBEcTZlqMlsknj/z6w9qbeQI/5LTw0E0RhfAK WULOuyv2UNUeZrFDzAsQFxp6PyTHq7w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1621950662; 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=Xd8OifYoNQOCikHzR++3NeOR/xz1/yXNT7sn6d6yzXM=; b=MpXHFE6Xqv1cFmXsCTjOpEiOcYOiUi3nvMA7eShKZt6qV/wNePjLY1ZrolXeIYcMYTldtS PF6XfrOYC1YffOCA== Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B0E75AEB3; Tue, 25 May 2021 13:51:01 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 1FAB91F2CAF; Tue, 25 May 2021 15:51:00 +0200 (CEST) From: Jan Kara To: Date: Tue, 25 May 2021 15:50:41 +0200 Message-Id: <20210525135100.11221-4-jack@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210525125652.20457-1-jack@suse.cz> References: <20210525125652.20457-1-jack@suse.cz> MIME-Version: 1.0 X-Headers-End: 1llXSj-0003aw-UM Subject: [f2fs-dev] [PATCH 04/13] mm: Add functions to lock invalidate_lock for two mappings X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-cifs@vger.kernel.org, Damien Le Moal , linux-ext4@vger.kernel.org, Ted Tso , "Darrick J. Wong" , Jeff Layton , Steve French , Dave Chinner , Matthew Wilcox , linux-f2fs-devel@lists.sourceforge.net, Christoph Hellwig , linux-mm@kvack.org, Miklos Szeredi , Jan Kara , Jaegeuk Kim , ceph-devel@vger.kernel.org, Johannes Thumshirn , linux-xfs@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Some operations such as reflinking blocks among files will need to lock invalidate_lock for two mappings. Add helper functions to do that. 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 897238d9f1e0..e6f7447505f5 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -822,6 +822,12 @@ static inline void inode_lock_shared_nested(struct inode *inode, unsigned subcla void lock_two_nondirectories(struct inode *, struct inode*); void unlock_two_nondirectories(struct inode *, struct inode*); +void filemap_invalidate_down_write_two(struct address_space *mapping1, + struct address_space *mapping2); +void filemap_invalidate_up_write_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 4d9ec4c6cc34..d3801a9739aa 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_down_write_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_down_write_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_down_write_two); + +/* + * filemap_invalidate_up_write_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_up_write_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_up_write_two); + /* * In order to wait for pages to become available there must be * waitqueues associated with pages. By using a hash table of -- 2.26.2 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel