linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "NeilBrown" <neilb@suse.de>
To: Darrick J.  Wong <darrick.wong@oracle.com>,
	Christoph Hellwig <hch@lst.de>,
	David Howells <dhowells@redhat.com>,
	torvalds@linux-foundation.org, trond.myklebust@primarydata.com
Cc: linux-nfs@vger.kernel.org, linux-mm@kvack.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Don't block writes to swap-files with ETXTBSY.
Date: Thu, 26 Aug 2021 09:57:39 +1000	[thread overview]
Message-ID: <162993585927.7591.10174443410031404560@noble.neil.brown.name> (raw)


Commit dc617f29dbe5 ("vfs: don't allow writes to swap files")
broke swap-over-NFS as it introduced an ETXTBSY error when NFS tries to
swap-out using ->direct_IO().

There is no sound justification for this error.  File permissions are
sufficient to stop non-root users from writing to a swap file, and root
must always be cautious not to do anything dangerous.

These checks effectively provide a mandatory write lock on swap, and
mandatory locks are not supported in Linux.

So remove all the checks that return ETXTBSY when attempts are made to
write to swap.

Fixes: dc617f29dbe5 ("vfs: don't allow writes to swap files")
Signed-off-by: NeilBrown <neilb@suse.de>
---
 fs/block_dev.c  | 3 ---
 fs/read_write.c | 6 ------
 2 files changed, 9 deletions(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 9ef4f1fc2cb0..e5605c88e6e9 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1623,9 +1623,6 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	if (bdev_read_only(I_BDEV(bd_inode)))
 		return -EPERM;
 
-	if (IS_SWAPFILE(bd_inode) && !is_hibernate_resume_dev(bd_inode->i_rdev))
-		return -ETXTBSY;
-
 	if (!iov_iter_count(from))
 		return 0;
 
diff --git a/fs/read_write.c b/fs/read_write.c
index 9db7adf160d2..14f1c622a066 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1442,9 +1442,6 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in,
 	if (IS_IMMUTABLE(inode_out))
 		return -EPERM;
 
-	if (IS_SWAPFILE(inode_in) || IS_SWAPFILE(inode_out))
-		return -ETXTBSY;
-
 	/* Ensure offsets don't wrap. */
 	if (pos_in + count < pos_in || pos_out + count < pos_out)
 		return -EOVERFLOW;
@@ -1646,9 +1643,6 @@ ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from)
 	loff_t count;
 	int ret;
 
-	if (IS_SWAPFILE(inode))
-		return -ETXTBSY;
-
 	if (!iov_iter_count(from))
 		return 0;
 
-- 
2.32.0


             reply	other threads:[~2021-08-25 23:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25 23:57 NeilBrown [this message]
2021-08-27 15:16 ` [PATCH] Don't block writes to swap-files with ETXTBSY Christoph Hellwig
2021-08-27 23:10   ` NeilBrown
2021-08-28  7:10     ` Christoph Hellwig

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=162993585927.7591.10174443410031404560@noble.neil.brown.name \
    --to=neilb@suse.de \
    --cc=darrick.wong@oracle.com \
    --cc=dhowells@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=trond.myklebust@primarydata.com \
    /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).