Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1507644pxp; Sun, 6 Mar 2022 17:34:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwi32/QQaVExFDk9v50Q+pAgSgLMbyRSBlAYvAUb27MmFeV+q9aDS+Rf3olsUuGtB4xXZzL X-Received: by 2002:a63:d74f:0:b0:374:5bda:909d with SMTP id w15-20020a63d74f000000b003745bda909dmr8017650pgi.215.1646616887862; Sun, 06 Mar 2022 17:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646616887; cv=none; d=google.com; s=arc-20160816; b=ocqjpZuo+F9GkUwB4ac9xGyikEQ4AajGDyG5UQlElRXxPO9rAZdTRcgFRVOzuEm4oS 16D+eoWblzfwAw02lSzBgLB3aNa7oikl0UkNp/1BFXMZ5V44fIMhWSVKDG7BUEfrzkzW dot9TO3C1V3ZoNNZz3k7pTqCUZFfOxpKqiAbbnAsnvcSRKydRpnquzW4zCP6RoSql8nO 2v1CKqPY3VSBPZBRriEdWngxP4lZnG/UbrK+LyoJFwqV+M7KHNYVDY8Jz1kTTdovYJfT RVN9LypXBAymY8TzXRAzJk7nH3s6cz+J4B0vxLujI7YYI8U7Olz22VBA1KBt+TlTnypI grFA== 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=jIwc70WfyZePk+M4TY2KFFjSotnhhDywYz77GPeU54I=; b=w1oXz7xVpL7PgQEt3hR6xpCvVkX75ybbgtVcRdlcfsVnPViPYQu9xFGeEvoO6J8l65 B6xHU9sd8yS95+V7xftyPNbqn5ZVHQQ+3Dqz1NdDWdyyuJVzVpRTlNm1kd3t2pfodY7K 9+fSA3zpLUtN2+Gh+eFkIK7tD0HMBwfCcHqgPzg+GCJnIyLszu4CaLODojPET0Wc68tr 15x78zhzu+KhQSOu495AhKZVc3NMJ+AlTo0O/6VqeCz0yGDXCATuhXr2t2cXKRzW+HYL 4b33T0KIkiTPTbWNbGXuXazfnq/61lfRCaqNgPgAIKQdnCJr4jCFcKwLsEnfWuzgoaFT Ff9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=yW2mlcWW; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 m22-20020a656a16000000b00372b111bf20si13499132pgu.19.2022.03.06.17.34.32; Sun, 06 Mar 2022 17:34:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=yW2mlcWW; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S234503AbiCFXvd (ORCPT + 99 others); Sun, 6 Mar 2022 18:51:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233410AbiCFXvc (ORCPT ); Sun, 6 Mar 2022 18:51:32 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3566C4614A; Sun, 6 Mar 2022 15:50:40 -0800 (PST) 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 DF78C210EA; Sun, 6 Mar 2022 23:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1646610638; 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=jIwc70WfyZePk+M4TY2KFFjSotnhhDywYz77GPeU54I=; b=yW2mlcWWshB+Zpw8lpFaHuA/Po1I8F2jWDiyqn7SoLSvTRka3d/5LKHQAA958Hn/X7jqzQ nPn1sBMTzfBI0RCVJ2S28aRK82AYrW3xg5pTJaCRg3P3dwNe2iXM2f5X2sX6HZDgy3bRjQ xjaohQhwB2DDhNQCyxlXYQ2jBPbw+8Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1646610638; 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=jIwc70WfyZePk+M4TY2KFFjSotnhhDywYz77GPeU54I=; b=Ctxa6xp0IpfZB8kCQyX3+nRmsObXTjF6Y2MZzMXc9UTNyI9IFR7N3dAaYiwjKrXeL+5eaG FmcJk4vtYoJsrBAw== 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 EB19A134CD; Sun, 6 Mar 2022 23:50:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Arb/KMxIJWI3WgAAMHmgww (envelope-from ); Sun, 06 Mar 2022 23:50:36 +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: Mon, 07 Mar 2022 10:49:38 +1100 Message-ID: <164661057804.13454.2171827219509234605.stgit@noble.brown> In-Reply-To: <164661047081.13454.11679636335222534920.stgit@noble.brown> References: <164661047081.13454.11679636335222534920.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-kernel@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 e7af802dcfa6..fe49f1cab018 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -4917,7 +4917,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; }