Skip to content

Commit 1601ea0

Browse files
committed
zonefs: prevent use of seq files as swap file
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>
1 parent 1e28eed commit 1601ea0

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

fs/zonefs/super.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ static int zonefs_writepages(struct address_space *mapping,
165165
return iomap_writepages(mapping, wbc, &wpc, &zonefs_writeback_ops);
166166
}
167167

168+
static int zonefs_swap_activate(struct swap_info_struct *sis,
169+
struct file *swap_file, sector_t *span)
170+
{
171+
struct inode *inode = file_inode(swap_file);
172+
struct zonefs_inode_info *zi = ZONEFS_I(inode);
173+
174+
if (zi->i_ztype != ZONEFS_ZTYPE_CNV) {
175+
zonefs_err(inode->i_sb,
176+
"swap file: not a conventional zone file\n");
177+
return -EINVAL;
178+
}
179+
180+
return iomap_swapfile_activate(sis, swap_file, span, &zonefs_iomap_ops);
181+
}
182+
168183
static const struct address_space_operations zonefs_file_aops = {
169184
.readpage = zonefs_readpage,
170185
.readahead = zonefs_readahead,
@@ -177,6 +192,7 @@ static const struct address_space_operations zonefs_file_aops = {
177192
.is_partially_uptodate = iomap_is_partially_uptodate,
178193
.error_remove_page = generic_error_remove_page,
179194
.direct_IO = noop_direct_IO,
195+
.swap_activate = zonefs_swap_activate,
180196
};
181197

182198
static void zonefs_update_stats(struct inode *inode, loff_t new_isize)

0 commit comments

Comments
 (0)