diff mbox series

[1/2] zonefs: prevent use of seq files as swap file

Message ID 20210315034919.87980-2-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series zonefs fixes | expand

Commit Message

Damien Le Moal March 15, 2021, 3:49 a.m. UTC
The sequential write constraint of sequential zone file prevent their
use as swap files. Only allow conventional zone files to be used as swap
files.

Fixes: 8dcc1a9d90c1 ("fs: New zonefs file system")
Cc: <stable@vger.kernel.org>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 fs/zonefs/super.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Johannes Thumshirn March 15, 2021, 6:46 a.m. UTC | #1
On 15/03/2021 04:49, Damien Le Moal wrote:
> The sequential write constraint of sequential zone file prevent their
> use as swap files. Only allow conventional zone files to be used as swap
> files.

That would be super useful to test in in zonefs tests as well. I can take
care if you want.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Damien Le Moal March 15, 2021, 7:23 a.m. UTC | #2
On 2021/03/15 15:46, Johannes Thumshirn wrote:
> On 15/03/2021 04:49, Damien Le Moal wrote:
>> The sequential write constraint of sequential zone file prevent their
>> use as swap files. Only allow conventional zone files to be used as swap
>> files.
> 
> That would be super useful to test in in zonefs tests as well. I can take
> care if you want.

Yep. Adding a test case for that.

> 
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>
diff mbox series

Patch

diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index 0fe76f376dee..a3d074f98660 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -165,6 +165,21 @@  static int zonefs_writepages(struct address_space *mapping,
 	return iomap_writepages(mapping, wbc, &wpc, &zonefs_writeback_ops);
 }
 
+static int zonefs_swap_activate(struct swap_info_struct *sis,
+				struct file *swap_file, sector_t *span)
+{
+	struct inode *inode = file_inode(swap_file);
+	struct zonefs_inode_info *zi = ZONEFS_I(inode);
+
+	if (zi->i_ztype != ZONEFS_ZTYPE_CNV) {
+		zonefs_err(inode->i_sb,
+			   "swap file: not a conventional zone file\n");
+		return -EINVAL;
+	}
+
+	return iomap_swapfile_activate(sis, swap_file, span, &zonefs_iomap_ops);
+}
+
 static const struct address_space_operations zonefs_file_aops = {
 	.readpage		= zonefs_readpage,
 	.readahead		= zonefs_readahead,
@@ -177,6 +192,7 @@  static const struct address_space_operations zonefs_file_aops = {
 	.is_partially_uptodate	= iomap_is_partially_uptodate,
 	.error_remove_page	= generic_error_remove_page,
 	.direct_IO		= noop_direct_IO,
+	.swap_activate		= zonefs_swap_activate,
 };
 
 static void zonefs_update_stats(struct inode *inode, loff_t new_isize)