Linux-NFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] fs/nfs, swapon: check holes in swapfile
@ 2020-01-02  8:04 Murphy Zhou
  2020-01-15  4:49 ` Murphy Zhou
  0 siblings, 1 reply; 2+ messages in thread
From: Murphy Zhou @ 2020-01-02  8:04 UTC (permalink / raw)
  To: linux-nfs

swapon over NFS does not go through generic_swapfile_activate
code path when setting up extents. This makes holes in NFS
swapfiles possible which is not expected for swapon.

Signed-off-by: Murphy Zhou <jencce.kernel@gmail.com>
---
 fs/nfs/file.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 8eb731d..ccd9bc0 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -489,7 +489,19 @@ static int nfs_launder_page(struct page *page)
 static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file,
 						sector_t *span)
 {
+	unsigned long blocks;
+	long long isize;
 	struct rpc_clnt *clnt = NFS_CLIENT(file->f_mapping->host);
+	struct inode *inode = file->f_mapping->host;
+
+	spin_lock(&inode->i_lock);
+	blocks = inode->i_blocks;
+	isize = inode->i_size;
+	spin_unlock(&inode->i_lock);
+	if (blocks*512 < isize) {
+		pr_warn("swap activate: swapfile has holes\n");
+		return -EINVAL;
+	}
 
 	*span = sis->pages;
 
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs/nfs, swapon: check holes in swapfile
  2020-01-02  8:04 [PATCH] fs/nfs, swapon: check holes in swapfile Murphy Zhou
@ 2020-01-15  4:49 ` Murphy Zhou
  0 siblings, 0 replies; 2+ messages in thread
From: Murphy Zhou @ 2020-01-15  4:49 UTC (permalink / raw)
  To: linux-nfs

On Thu, Jan 02, 2020 at 04:04:26PM +0800, Murphy Zhou wrote:
> swapon over NFS does not go through generic_swapfile_activate
> code path when setting up extents. This makes holes in NFS
> swapfiles possible which is not expected for swapon.

Any review?

> 
> Signed-off-by: Murphy Zhou <jencce.kernel@gmail.com>
> ---
>  fs/nfs/file.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/fs/nfs/file.c b/fs/nfs/file.c
> index 8eb731d..ccd9bc0 100644
> --- a/fs/nfs/file.c
> +++ b/fs/nfs/file.c
> @@ -489,7 +489,19 @@ static int nfs_launder_page(struct page *page)
>  static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file,
>  						sector_t *span)
>  {
> +	unsigned long blocks;
> +	long long isize;
>  	struct rpc_clnt *clnt = NFS_CLIENT(file->f_mapping->host);
> +	struct inode *inode = file->f_mapping->host;
> +
> +	spin_lock(&inode->i_lock);
> +	blocks = inode->i_blocks;
> +	isize = inode->i_size;
> +	spin_unlock(&inode->i_lock);
> +	if (blocks*512 < isize) {
> +		pr_warn("swap activate: swapfile has holes\n");
> +		return -EINVAL;
> +	}
>  
>  	*span = sis->pages;
>  
> -- 
> 1.8.3.1
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-02  8:04 [PATCH] fs/nfs, swapon: check holes in swapfile Murphy Zhou
2020-01-15  4:49 ` Murphy Zhou

Linux-NFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nfs/0 linux-nfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nfs linux-nfs/ https://lore.kernel.org/linux-nfs \
		linux-nfs@vger.kernel.org
	public-inbox-index linux-nfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-nfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git