Skip to content

Commit 3442291

Browse files
author
Damien Le Moal
committed
zonefs: Reduce struct zonefs_inode_info size
Instead of using the i_ztype field in struct zonefs_inode_info to indicate the zone type of an inode, introduce the new inode flag ZONEFS_ZONE_CNV to be set in the i_flags field of struct zonefs_inode_info to identify conventional zones. If this flag is not set, the zone of an inode is considered to be a sequential zone. The helpers zonefs_zone_is_cnv(), zonefs_zone_is_seq(), zonefs_inode_is_cnv() and zonefs_inode_is_seq() are introduced to simplify testing the zone type of a struct zonefs_inode_info and of a struct inode. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]>
1 parent 46a9c52 commit 3442291

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

fs/zonefs/file.c

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset,
7777
* checked when writes are issued, so warn if we see a page writeback
7878
* operation.
7979
*/
80-
if (WARN_ON_ONCE(zi->i_ztype == ZONEFS_ZTYPE_SEQ &&
81-
!(flags & IOMAP_DIRECT)))
80+
if (WARN_ON_ONCE(zonefs_zone_is_seq(zi) && !(flags & IOMAP_DIRECT)))
8281
return -EIO;
8382

8483
/*
@@ -128,7 +127,7 @@ static int zonefs_write_map_blocks(struct iomap_writepage_ctx *wpc,
128127
{
129128
struct zonefs_inode_info *zi = ZONEFS_I(inode);
130129

131-
if (WARN_ON_ONCE(zi->i_ztype != ZONEFS_ZTYPE_CNV))
130+
if (WARN_ON_ONCE(zonefs_zone_is_seq(zi)))
132131
return -EIO;
133132
if (WARN_ON_ONCE(offset >= i_size_read(inode)))
134133
return -EIO;
@@ -158,9 +157,8 @@ static int zonefs_swap_activate(struct swap_info_struct *sis,
158157
struct file *swap_file, sector_t *span)
159158
{
160159
struct inode *inode = file_inode(swap_file);
161-
struct zonefs_inode_info *zi = ZONEFS_I(inode);
162160

163-
if (zi->i_ztype != ZONEFS_ZTYPE_CNV) {
161+
if (zonefs_inode_is_seq(inode)) {
164162
zonefs_err(inode->i_sb,
165163
"swap file: not a conventional zone file\n");
166164
return -EINVAL;
@@ -196,7 +194,7 @@ int zonefs_file_truncate(struct inode *inode, loff_t isize)
196194
* only down to a 0 size, which is equivalent to a zone reset, and to
197195
* the maximum file size, which is equivalent to a zone finish.
198196
*/
199-
if (zi->i_ztype != ZONEFS_ZTYPE_SEQ)
197+
if (!zonefs_zone_is_seq(zi))
200198
return -EPERM;
201199

202200
if (!isize)
@@ -266,7 +264,7 @@ static int zonefs_file_fsync(struct file *file, loff_t start, loff_t end,
266264
* Since only direct writes are allowed in sequential files, page cache
267265
* flush is needed only for conventional zone files.
268266
*/
269-
if (ZONEFS_I(inode)->i_ztype == ZONEFS_ZTYPE_CNV)
267+
if (zonefs_inode_is_cnv(inode))
270268
ret = file_write_and_wait_range(file, start, end);
271269
if (!ret)
272270
ret = blkdev_issue_flush(inode->i_sb->s_bdev);
@@ -280,7 +278,6 @@ static int zonefs_file_fsync(struct file *file, loff_t start, loff_t end,
280278
static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf)
281279
{
282280
struct inode *inode = file_inode(vmf->vma->vm_file);
283-
struct zonefs_inode_info *zi = ZONEFS_I(inode);
284281
vm_fault_t ret;
285282

286283
if (unlikely(IS_IMMUTABLE(inode)))
@@ -290,7 +287,7 @@ static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf)
290287
* Sanity check: only conventional zone files can have shared
291288
* writeable mappings.
292289
*/
293-
if (WARN_ON_ONCE(zi->i_ztype != ZONEFS_ZTYPE_CNV))
290+
if (zonefs_inode_is_seq(inode))
294291
return VM_FAULT_NOPAGE;
295292

296293
sb_start_pagefault(inode->i_sb);
@@ -319,7 +316,7 @@ static int zonefs_file_mmap(struct file *file, struct vm_area_struct *vma)
319316
* mappings are possible since there are no guarantees for write
320317
* ordering between msync() and page cache writeback.
321318
*/
322-
if (ZONEFS_I(file_inode(file))->i_ztype == ZONEFS_ZTYPE_SEQ &&
319+
if (zonefs_inode_is_seq(file_inode(file)) &&
323320
(vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
324321
return -EINVAL;
325322

@@ -352,7 +349,7 @@ static int zonefs_file_write_dio_end_io(struct kiocb *iocb, ssize_t size,
352349
return error;
353350
}
354351

355-
if (size && zi->i_ztype != ZONEFS_ZTYPE_CNV) {
352+
if (size && zonefs_zone_is_seq(zi)) {
356353
/*
357354
* Note that we may be seeing completions out of order,
358355
* but that is not a problem since a write completed
@@ -491,7 +488,7 @@ static ssize_t zonefs_write_checks(struct kiocb *iocb, struct iov_iter *from)
491488
return -EINVAL;
492489

493490
if (iocb->ki_flags & IOCB_APPEND) {
494-
if (zi->i_ztype != ZONEFS_ZTYPE_SEQ)
491+
if (zonefs_zone_is_cnv(zi))
495492
return -EINVAL;
496493
mutex_lock(&zi->i_truncate_mutex);
497494
iocb->ki_pos = zi->i_wpoffset;
@@ -531,8 +528,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
531528
* as this can cause write reordering (e.g. the first aio gets EAGAIN
532529
* on the inode lock but the second goes through but is now unaligned).
533530
*/
534-
if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && !sync &&
535-
(iocb->ki_flags & IOCB_NOWAIT))
531+
if (zonefs_zone_is_seq(zi) && !sync && (iocb->ki_flags & IOCB_NOWAIT))
536532
return -EOPNOTSUPP;
537533

538534
if (iocb->ki_flags & IOCB_NOWAIT) {
@@ -554,7 +550,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
554550
}
555551

556552
/* Enforce sequential writes (append only) in sequential zones */
557-
if (zi->i_ztype == ZONEFS_ZTYPE_SEQ) {
553+
if (zonefs_zone_is_seq(zi)) {
558554
mutex_lock(&zi->i_truncate_mutex);
559555
if (iocb->ki_pos != zi->i_wpoffset) {
560556
mutex_unlock(&zi->i_truncate_mutex);
@@ -570,7 +566,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
570566
else
571567
ret = iomap_dio_rw(iocb, from, &zonefs_write_iomap_ops,
572568
&zonefs_write_dio_ops, 0, NULL, 0);
573-
if (zi->i_ztype == ZONEFS_ZTYPE_SEQ &&
569+
if (zonefs_zone_is_seq(zi) &&
574570
(ret > 0 || ret == -EIOCBQUEUED)) {
575571
if (ret > 0)
576572
count = ret;
@@ -596,14 +592,13 @@ static ssize_t zonefs_file_buffered_write(struct kiocb *iocb,
596592
struct iov_iter *from)
597593
{
598594
struct inode *inode = file_inode(iocb->ki_filp);
599-
struct zonefs_inode_info *zi = ZONEFS_I(inode);
600595
ssize_t ret;
601596

602597
/*
603598
* Direct IO writes are mandatory for sequential zone files so that the
604599
* write IO issuing order is preserved.
605600
*/
606-
if (zi->i_ztype != ZONEFS_ZTYPE_CNV)
601+
if (zonefs_inode_is_seq(inode))
607602
return -EIO;
608603

609604
if (iocb->ki_flags & IOCB_NOWAIT) {
@@ -731,9 +726,7 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
731726
static inline bool zonefs_seq_file_need_wro(struct inode *inode,
732727
struct file *file)
733728
{
734-
struct zonefs_inode_info *zi = ZONEFS_I(inode);
735-
736-
if (zi->i_ztype != ZONEFS_ZTYPE_SEQ)
729+
if (zonefs_inode_is_cnv(inode))
737730
return false;
738731

739732
if (!(file->f_mode & FMODE_WRITE))

fs/zonefs/super.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void zonefs_account_active(struct inode *inode)
3737

3838
lockdep_assert_held(&zi->i_truncate_mutex);
3939

40-
if (zi->i_ztype != ZONEFS_ZTYPE_SEQ)
40+
if (zonefs_zone_is_cnv(zi))
4141
return;
4242

4343
/*
@@ -177,14 +177,14 @@ static loff_t zonefs_check_zone_condition(struct inode *inode,
177177
zonefs_warn(inode->i_sb, "inode %lu: read-only zone\n",
178178
inode->i_ino);
179179
zi->i_flags |= ZONEFS_ZONE_READONLY;
180-
if (zi->i_ztype == ZONEFS_ZTYPE_CNV)
180+
if (zonefs_zone_is_cnv(zi))
181181
return zi->i_max_size;
182182
return zi->i_wpoffset;
183183
case BLK_ZONE_COND_FULL:
184184
/* The write pointer of full zones is invalid. */
185185
return zi->i_max_size;
186186
default:
187-
if (zi->i_ztype == ZONEFS_ZTYPE_CNV)
187+
if (zonefs_zone_is_cnv(zi))
188188
return zi->i_max_size;
189189
return (zone->wp - zone->start) << SECTOR_SHIFT;
190190
}
@@ -260,7 +260,7 @@ static int zonefs_io_error_cb(struct blk_zone *zone, unsigned int idx,
260260
* In all cases, warn about inode size inconsistency and handle the
261261
* IO error according to the zone condition and to the mount options.
262262
*/
263-
if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && isize != data_size)
263+
if (zonefs_zone_is_seq(zi) && isize != data_size)
264264
zonefs_warn(sb, "inode %lu: invalid size %lld (should be %lld)\n",
265265
inode->i_ino, isize, data_size);
266266

@@ -584,7 +584,9 @@ static int zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone,
584584
inode->i_ino = zone->start >> sbi->s_zone_sectors_shift;
585585
inode->i_mode = S_IFREG | sbi->s_perm;
586586

587-
zi->i_ztype = type;
587+
if (type == ZONEFS_ZTYPE_CNV)
588+
zi->i_flags |= ZONEFS_ZONE_CNV;
589+
588590
zi->i_zsector = zone->start;
589591
zi->i_zone_size = zone->len << SECTOR_SHIFT;
590592
if (zi->i_zone_size > bdev_zone_sectors(sb->s_bdev) << SECTOR_SHIFT &&

fs/zonefs/zonefs.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@ static inline enum zonefs_ztype zonefs_zone_type(struct blk_zone *zone)
4444
#define ZONEFS_ZONE_ACTIVE (1U << 2)
4545
#define ZONEFS_ZONE_OFFLINE (1U << 3)
4646
#define ZONEFS_ZONE_READONLY (1U << 4)
47+
#define ZONEFS_ZONE_CNV (1U << 31)
4748

4849
/*
4950
* In-memory inode data.
5051
*/
5152
struct zonefs_inode_info {
5253
struct inode i_vnode;
5354

54-
/* File zone type */
55-
enum zonefs_ztype i_ztype;
56-
5755
/* File zone start sector (512B unit) */
5856
sector_t i_zsector;
5957

@@ -91,6 +89,26 @@ static inline struct zonefs_inode_info *ZONEFS_I(struct inode *inode)
9189
return container_of(inode, struct zonefs_inode_info, i_vnode);
9290
}
9391

92+
static inline bool zonefs_zone_is_cnv(struct zonefs_inode_info *zi)
93+
{
94+
return zi->i_flags & ZONEFS_ZONE_CNV;
95+
}
96+
97+
static inline bool zonefs_zone_is_seq(struct zonefs_inode_info *zi)
98+
{
99+
return !zonefs_zone_is_cnv(zi);
100+
}
101+
102+
static inline bool zonefs_inode_is_cnv(struct inode *inode)
103+
{
104+
return zonefs_zone_is_cnv(ZONEFS_I(inode));
105+
}
106+
107+
static inline bool zonefs_inode_is_seq(struct inode *inode)
108+
{
109+
return zonefs_zone_is_seq(ZONEFS_I(inode));
110+
}
111+
94112
/*
95113
* On-disk super block (block 0).
96114
*/

0 commit comments

Comments
 (0)