Skip to content

Commit

Permalink
zonefs: prevent use of seq files as swap file
Browse files Browse the repository at this point in the history
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: 8dcc1a9 ("fs: New zonefs file system")
Cc: <stable@vger.kernel.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
  • Loading branch information
Damien Le Moal committed Mar 16, 2021
1 parent 1e28eed commit 1601ea0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions fs/zonefs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 1601ea0

Please sign in to comment.