Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1308042pxb; Tue, 29 Mar 2022 23:51:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/ylUayiFNgs/McbJDOya/jsj08ezQKu9kr6JuNnKPMbABXVf7h+RRzwn0OQVQvp7Lyz/e X-Received: by 2002:a17:90b:4a41:b0:1c7:a0d7:718c with SMTP id lb1-20020a17090b4a4100b001c7a0d7718cmr3307945pjb.57.1648623066735; Tue, 29 Mar 2022 23:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648623066; cv=none; d=google.com; s=arc-20160816; b=tth1gNHSoAizvV4b0k32jLXUtX6keusOGcyyMVswUTTLz0E/Eb3jMdT/seNrzLbLEW frcJXvP9YSDvFXjfBe+30R+eiuFp5CgULr/fBD2EO7lLCjOrYEMbg3Ga+GBuVol2eRyL idEH3Oobvz9pYvGgPPmZrekSLCnE2h47DogsBm4XV5dN7BwC+fXhAbaVZUO5U5e51rU8 z9YWX38vxQoSlV+5Q9HK+viYxhu7JKkE+FBD+p8O3bWprXpQwpbwZUy0M0bwpovKxuGh 7xwLgh4Qiq+FA7TM1ITrcdIW+4rQCBvFlOSZVCxMAQi5zCPtG/pnI95DeC3dvHoMqGJL thGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature:dkim-signature; bh=fUqsktX1Dv6qEK49ZdefTv/pOyZaEMsB1qtsMGhOrI4=; b=WGlIBfZP+80MaF9eAd3UfjNRXvaDBA/EIuYRw4L1fvhUM8B5WeZrayWHp61cv9WcUP F1gEQQq1onqmgn8h5c4PmOLzTh+DjNviWVllkDjxkSY1SPIPx0R7S+w+Bc3IB7zPjgPw 51yCwFde8bvqNX00fZo4s+KetabDWqIsExoMA/Zw/dHU1P7UyK90LqHgKI3zHI34e5RE wYFF8gXMWlan0H5xEEAMVAsZiiD8nMX+PXKwZkHaNvb4E2cdZoJnPV+sAY7lr3Y/fxk8 4AolbQP1iNTlqgXEBkEm4luSE5qpfGcMIf/fLmT9c0ql3FC+s61X8p6Pa73VLx4VxFTn QAZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LvNolslL; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=QOa9e9vj; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j9-20020a633c09000000b003816043f135si19703941pga.810.2022.03.29.23.50.41; Tue, 29 Mar 2022 23:51:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LvNolslL; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=QOa9e9vj; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241184AbiC2Xxm (ORCPT + 99 others); Tue, 29 Mar 2022 19:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241318AbiC2Xx2 (ORCPT ); Tue, 29 Mar 2022 19:53:28 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1770D21A8BC; Tue, 29 Mar 2022 16:51:37 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AE73E210E4; Tue, 29 Mar 2022 23:51:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1648597895; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fUqsktX1Dv6qEK49ZdefTv/pOyZaEMsB1qtsMGhOrI4=; b=LvNolslLWWnhLdL/xjqxOHqkEMnr1D2s2zo0ZkV7o4M61dzgurAVy4d+4feES/DzhFlvBA Rwmaqp1DJD194Fis6kF6LpmUVovPGYtCPJsjN+6ncbXteQIE6K5e0huLuNB0kbxZSF3cRq B4q7NuCJVrWUsoRRDFHbzkkFQXKbIK4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1648597895; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fUqsktX1Dv6qEK49ZdefTv/pOyZaEMsB1qtsMGhOrI4=; b=QOa9e9vj7wV7WsyjC3Pj4tX/B/UhY320L+3XytQmEOmOmBS9JgR9QB46s/Bkan94wyYnjP JXPSJwFAzw/4QvAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7F53A13A7E; Tue, 29 Mar 2022 23:51:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id E/MiD4KbQ2IvLwAAMHmgww (envelope-from ); Tue, 29 Mar 2022 23:51:30 +0000 Subject: [PATCH 03/10] MM: move responsibility for setting SWP_FS_OPS to ->swap_activate From: NeilBrown To: Andrew Morton Cc: Christoph Hellwig , David Howells , linux-nfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Wed, 30 Mar 2022 10:49:41 +1100 Message-ID: <164859778123.29473.17908205846599043598.stgit@noble.brown> In-Reply-To: <164859751830.29473.5309689752169286816.stgit@noble.brown> References: <164859751830.29473.5309689752169286816.stgit@noble.brown> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,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-nfs@vger.kernel.org If a filesystem wishes to handle all swap IO itself (via ->direct_IO and ->readpage), rather than just providing devices addresses for submit_bio(), SWP_FS_OPS must be set. Currently the protocol for setting this it to have ->swap_activate return zero. In that case SWP_FS_OPS is set, and add_swap_extent() is called for the entire file. This is a little clumsy as different return values for ->swap_activate have quite different meanings, and it makes it hard to search for which filesystems require SWP_FS_OPS to be set. So remove the special meaning of a zero return, and require the filesystem to set SWP_FS_OPS if it so desires, and to always call add_swap_extent() as required. Currently only NFS and CIFS return zero for add_swap_extent(). Reviewed-by: Christoph Hellwig Signed-off-by: NeilBrown --- fs/cifs/file.c | 3 ++- fs/nfs/file.c | 13 +++++++++++-- include/linux/swap.h | 6 ++++++ mm/swapfile.c | 10 +++------- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 60f43bff7ccb..050f463580f3 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -4927,7 +4927,8 @@ static int cifs_swap_activate(struct swap_info_struct *sis, * from reading or writing the file */ - return 0; + sis->flags |= SWP_FS_OPS; + return add_swap_extent(sis, 0, sis->max, 0); } static void cifs_swap_deactivate(struct file *file) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 2df2a5392737..66136dca0ad5 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -488,6 +488,7 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file, { unsigned long blocks; long long isize; + int ret; struct rpc_clnt *clnt = NFS_CLIENT(file->f_mapping->host); struct inode *inode = file->f_mapping->host; @@ -500,9 +501,17 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file, return -EINVAL; } + ret = rpc_clnt_swap_activate(clnt); + if (ret) + return ret; + ret = add_swap_extent(sis, 0, sis->max, 0); + if (ret < 0) { + rpc_clnt_swap_deactivate(clnt); + return ret; + } *span = sis->pages; - - return rpc_clnt_swap_activate(clnt); + sis->flags |= SWP_FS_OPS; + return ret; } static void nfs_swap_deactivate(struct file *file) diff --git a/include/linux/swap.h b/include/linux/swap.h index 6bc9e21262de..e18b7edccc1d 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -570,6 +570,12 @@ static inline swp_entry_t get_swap_page(struct page *page) return entry; } +static inline int add_swap_extent(struct swap_info_struct *sis, + unsigned long start_page, + unsigned long nr_pages, sector_t start_block) +{ + return -EINVAL; +} #endif /* CONFIG_SWAP */ #ifdef CONFIG_THP_SWAP diff --git a/mm/swapfile.c b/mm/swapfile.c index 2650927a009b..8710c9c29862 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2244,13 +2244,9 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span) if (mapping->a_ops->swap_activate) { ret = mapping->a_ops->swap_activate(sis, swap_file, span); - if (ret >= 0) - sis->flags |= SWP_ACTIVATED; - if (!ret) { - sis->flags |= SWP_FS_OPS; - ret = add_swap_extent(sis, 0, sis->max, 0); - *span = sis->pages; - } + if (ret < 0) + return ret; + sis->flags |= SWP_ACTIVATED; return ret; }