Skip to content

Commit e3c3155

Browse files
morbidrsadamien-lemoal
authored andcommitted
zonefs: add zone-capacity support
In the zoned storage model, the sectors within a zone are typically all writeable. With the introduction of the Zoned Namespace (ZNS) Command Set in the NVM Express organization, the model was extended to have a specific writeable capacity. This zone capacity can be less than the overall zone size for a NVMe ZNS device or null_blk in zoned-mode. For other ZBC/ZAC devices the zone capacity is always equal to the zone size. Use the zone capacity field instead from blk_zone for determining the maximum inode size and inode blocks in zonefs. Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Damien Le Moal <[email protected]>
1 parent 00e4db5 commit e3c3155

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

fs/zonefs/super.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static void zonefs_io_error(struct inode *inode, bool write)
335335
struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
336336
unsigned int noio_flag;
337337
unsigned int nr_zones =
338-
zi->i_max_size >> (sbi->s_zone_sectors_shift + SECTOR_SHIFT);
338+
zi->i_zone_size >> (sbi->s_zone_sectors_shift + SECTOR_SHIFT);
339339
struct zonefs_ioerr_data err = {
340340
.inode = inode,
341341
.write = write,
@@ -398,7 +398,7 @@ static int zonefs_file_truncate(struct inode *inode, loff_t isize)
398398
goto unlock;
399399

400400
ret = blkdev_zone_mgmt(inode->i_sb->s_bdev, op, zi->i_zsector,
401-
zi->i_max_size >> SECTOR_SHIFT, GFP_NOFS);
401+
zi->i_zone_size >> SECTOR_SHIFT, GFP_NOFS);
402402
if (ret) {
403403
zonefs_err(inode->i_sb,
404404
"Zone management operation at %llu failed %d",
@@ -1053,14 +1053,16 @@ static void zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone,
10531053

10541054
zi->i_ztype = type;
10551055
zi->i_zsector = zone->start;
1056+
zi->i_zone_size = zone->len << SECTOR_SHIFT;
1057+
10561058
zi->i_max_size = min_t(loff_t, MAX_LFS_FILESIZE,
1057-
zone->len << SECTOR_SHIFT);
1059+
zone->capacity << SECTOR_SHIFT);
10581060
zi->i_wpoffset = zonefs_check_zone_condition(inode, zone, true, true);
10591061

10601062
inode->i_uid = sbi->s_uid;
10611063
inode->i_gid = sbi->s_gid;
10621064
inode->i_size = zi->i_wpoffset;
1063-
inode->i_blocks = zone->len;
1065+
inode->i_blocks = zi->i_max_size >> SECTOR_SHIFT;
10641066

10651067
inode->i_op = &zonefs_file_inode_operations;
10661068
inode->i_fop = &zonefs_file_operations;
@@ -1167,12 +1169,18 @@ static int zonefs_create_zgroup(struct zonefs_zone_data *zd,
11671169
if (zonefs_zone_type(next) != type)
11681170
break;
11691171
zone->len += next->len;
1172+
zone->capacity += next->capacity;
11701173
if (next->cond == BLK_ZONE_COND_READONLY &&
11711174
zone->cond != BLK_ZONE_COND_OFFLINE)
11721175
zone->cond = BLK_ZONE_COND_READONLY;
11731176
else if (next->cond == BLK_ZONE_COND_OFFLINE)
11741177
zone->cond = BLK_ZONE_COND_OFFLINE;
11751178
}
1179+
if (zone->capacity != zone->len) {
1180+
zonefs_err(sb, "Invalid conventional zone capacity\n");
1181+
ret = -EINVAL;
1182+
goto free;
1183+
}
11761184
}
11771185

11781186
/*

fs/zonefs/zonefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct zonefs_inode_info {
5656
/* File maximum size */
5757
loff_t i_max_size;
5858

59+
/* File zone size */
60+
loff_t i_zone_size;
61+
5962
/*
6063
* To serialise fully against both syscall and mmap based IO and
6164
* sequential file truncation, two locks are used. For serializing

0 commit comments

Comments
 (0)