Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3365176pxb; Mon, 24 Jan 2022 08:07:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5t1zMK2rUcuVSj295RAvvJnxdNpPL6tPhS55QtVwaZDo5V7L9jtr2MH5ff1bYQZ78LIfT X-Received: by 2002:a17:902:700b:b0:14a:436c:dcf7 with SMTP id y11-20020a170902700b00b0014a436cdcf7mr15241571plk.144.1643040477415; Mon, 24 Jan 2022 08:07:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643040477; cv=none; d=google.com; s=arc-20160816; b=qQFV8t6wuFx8IoVK1EtBiC66uyc45ZMOrK74+N3K8eoItkB1wj19lrlXCNekF/WemZ iEkEgSM3cZN3LAMvGXEYvq1kLFkXR4zIBtssvYCuIvWGGXLUDPA+eNNmXrpFsrJMz+GF fN0L7LdWqszuUFwDtYaBrq3+CI7OJ8soLhACTl0wzPoOF2HhY/NX0P4Y6j1HsZdqzg+m d8NcI/8XZ28n9RN2R53YNg7DS2Y8UgHsrQXsM5cXGix8qdpkxbtEiavTchOj8NKUzv4c wuZqHA1pyssE61BX5s4Ax/chRr/3YOPKbdcTNUzMiylPMVhgkGpSgSK/hVeE8iggfdFG 1d5w== 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=n3+8Urza+M6Hp0rhzCu2VxlEP+N2PAYC/q2bkhSRhhQ=; b=gSF6YcylRIY4C/vFGsYnPd8aGvLktipgTGU1U3GARxpTDItpBdiRExFw8o34MXgTYN niPN57oQWJIj0LMLpnnxk16+3+X5VYjhlatZ9CWoHJuu96icU9HUceODLranm8FN8pvM UfanPveNOS9oiC5Yt8v2YHtctpsmHu/ZuJSPSmrxCEmWVIVMI0LyN8QZDLAR8y8b+IYW 1/clfY1nvrvTPFbybouiPBylIpQidcRxUXCrI5JB5AD+X6hype6U3qtdv+KhL0Epdsaa ZKLukTuErYwKYOuaT2StTYvyuQ/06sH7+ZTEIi8uKLosqhDUyBGGDBdxPlH1Qo2omcq0 cZDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="MRpjffj/"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si12445963plt.308.2022.01.24.08.07.41; Mon, 24 Jan 2022 08:07:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="MRpjffj/"; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 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 S241126AbiAXDu6 (ORCPT + 99 others); Sun, 23 Jan 2022 22:50:58 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:56750 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241127AbiAXDuw (ORCPT ); Sun, 23 Jan 2022 22:50:52 -0500 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 0F0922198E; Mon, 24 Jan 2022 03:50:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1642996251; 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=n3+8Urza+M6Hp0rhzCu2VxlEP+N2PAYC/q2bkhSRhhQ=; b=MRpjffj/7VeHdxIDvWWjvl/3r4/m4nUYdxDb5oZ0MqJtNXzmzCabuDPrwJjGKWSRCKT1hv 0eIzNEVsbLqTPxQ8NUD6GLT8O4PJddETBuHpkFe2wmXYa5XWBgH+MaJ4KqUPjU3ewxZtwB KVWPF5jcDiBVq7BwPzWnL2CjuWgH0EQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1642996251; 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=n3+8Urza+M6Hp0rhzCu2VxlEP+N2PAYC/q2bkhSRhhQ=; b=H600lppcNVits1+ijjv1xGR2cG4x3GPjkeRayoUjM2oyaz9E6uw3QaROGd3vyIteNPOVKO H+ylIEPXzcLPB6Aw== 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 0DC1A1331A; Mon, 24 Jan 2022 03:50:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PwBpLhci7mHGRAAAMHmgww (envelope-from ); Mon, 24 Jan 2022 03:50:47 +0000 Subject: [PATCH 04/23] MM: move responsibility for setting SWP_FS_OPS to ->swap_activate From: NeilBrown To: Trond Myklebust , Anna Schumaker , Chuck Lever , Andrew Morton , Mel Gorman , Christoph Hellwig , David Howells Cc: linux-nfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 24 Jan 2022 14:48:32 +1100 Message-ID: <164299611275.26253.11641346650863170349.stgit@noble.brown> In-Reply-To: <164299573337.26253.7538614611220034049.stgit@noble.brown> References: <164299573337.26253.7538614611220034049.stgit@noble.brown> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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), 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(). 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 59334be9ed3b..c795d4a9ec4a 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -4974,7 +4974,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 76d76acbc594..d5aa55c7edb0 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 a43929f7033e..b57cff3c5ac2 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -573,6 +573,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 71c7a31dd291..ed6028aea8bf 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2347,13 +2347,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; }