Commit 4b60c0ff authored by NeilBrown's avatar NeilBrown Committed by akpm

mm: move responsibility for setting SWP_FS_OPS to ->swap_activate

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().

Link: https://lkml.kernel.org/r/164859778123.29473.17908205846599043598.stgit@noble.brownSigned-off-by: default avatarNeilBrown <neilb@suse.de>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Tested-by: default avatarDavid Howells <dhowells@redhat.com>
Tested-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Cc: Hugh Dickins <hughd@google.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 4c4a7634
...@@ -4933,7 +4933,8 @@ static int cifs_swap_activate(struct swap_info_struct *sis, ...@@ -4933,7 +4933,8 @@ static int cifs_swap_activate(struct swap_info_struct *sis,
* from reading or writing the file * 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) static void cifs_swap_deactivate(struct file *file)
......
...@@ -483,6 +483,7 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file, ...@@ -483,6 +483,7 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file,
{ {
unsigned long blocks; unsigned long blocks;
long long isize; long long isize;
int ret;
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct rpc_clnt *clnt = NFS_CLIENT(inode); struct rpc_clnt *clnt = NFS_CLIENT(inode);
struct nfs_client *cl = NFS_SERVER(inode)->nfs_client; struct nfs_client *cl = NFS_SERVER(inode)->nfs_client;
...@@ -496,13 +497,22 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file, ...@@ -496,13 +497,22 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file,
return -EINVAL; return -EINVAL;
} }
*span = sis->pages; 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;
if (cl->rpc_ops->enable_swap) if (cl->rpc_ops->enable_swap)
cl->rpc_ops->enable_swap(inode); cl->rpc_ops->enable_swap(inode);
return rpc_clnt_swap_activate(clnt); sis->flags |= SWP_FS_OPS;
return ret;
} }
static void nfs_swap_deactivate(struct file *file) static void nfs_swap_deactivate(struct file *file)
......
...@@ -577,6 +577,12 @@ static inline swp_entry_t get_swap_page(struct page *page) ...@@ -577,6 +577,12 @@ static inline swp_entry_t get_swap_page(struct page *page)
return entry; 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 */ #endif /* CONFIG_SWAP */
#ifdef CONFIG_THP_SWAP #ifdef CONFIG_THP_SWAP
......
...@@ -2259,13 +2259,9 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span) ...@@ -2259,13 +2259,9 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span)
if (mapping->a_ops->swap_activate) { if (mapping->a_ops->swap_activate) {
ret = mapping->a_ops->swap_activate(sis, swap_file, span); ret = mapping->a_ops->swap_activate(sis, swap_file, span);
if (ret >= 0) if (ret < 0)
sis->flags |= SWP_ACTIVATED; return ret;
if (!ret) { sis->flags |= SWP_ACTIVATED;
sis->flags |= SWP_FS_OPS;
ret = add_swap_extent(sis, 0, sis->max, 0);
*span = sis->pages;
}
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment