Skip to content

Commit

Permalink
zonefs: introduce helper for zone management
Browse files Browse the repository at this point in the history
Introduce a helper function for sending zone management commands to the
block device.

As zone management commands can change a zone write pointer position
reflected in the size of the zone file, this function expects the truncate
mutex to be held.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
  • Loading branch information
Johannes Thumshirn authored and Damien Le Moal committed Sep 15, 2020
1 parent d012a71 commit 5498d5f
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions fs/zonefs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@

#include "zonefs.h"

static inline int zonefs_zone_mgmt(struct inode *inode,
enum req_opf op)
{
struct zonefs_inode_info *zi = ZONEFS_I(inode);
int ret;

lockdep_assert_held(&zi->i_truncate_mutex);

ret = blkdev_zone_mgmt(inode->i_sb->s_bdev, op, zi->i_zsector,
zi->i_zone_size >> SECTOR_SHIFT, GFP_NOFS);
if (ret) {
zonefs_err(inode->i_sb,
"Zone management operation %s at %llu failed %d\n",
blk_op_str(op), zi->i_zsector, ret);
return ret;
}

return 0;
}

static int zonefs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
unsigned int flags, struct iomap *iomap,
struct iomap *srcmap)
Expand Down Expand Up @@ -397,14 +417,9 @@ static int zonefs_file_truncate(struct inode *inode, loff_t isize)
if (isize == old_isize)
goto unlock;

ret = blkdev_zone_mgmt(inode->i_sb->s_bdev, op, zi->i_zsector,
zi->i_zone_size >> SECTOR_SHIFT, GFP_NOFS);
if (ret) {
zonefs_err(inode->i_sb,
"Zone management operation at %llu failed %d",
zi->i_zsector, ret);
ret = zonefs_zone_mgmt(inode, op);
if (ret)
goto unlock;
}

zonefs_update_stats(inode, isize);
truncate_setsize(inode, isize);
Expand Down

0 comments on commit 5498d5f

Please sign in to comment.