linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Murphy Zhou <jencce.kernel@gmail.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH] fs/nfs, swapon: check holes in swapfile
Date: Thu, 2 Jan 2020 16:04:26 +0800	[thread overview]
Message-ID: <20200102080426.byzq4rrdilr2qxx6@xzhoux.usersys.redhat.com> (raw)

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


             reply	other threads:[~2020-01-02  8:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-02  8:04 Murphy Zhou [this message]
2020-01-15  4:49 ` [PATCH] fs/nfs, swapon: check holes in swapfile Murphy Zhou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200102080426.byzq4rrdilr2qxx6@xzhoux.usersys.redhat.com \
    --to=jencce.kernel@gmail.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).