Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <damien.lemoal@opensource.wdc.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

+42 -29
+14 -21
fs/zonefs/file.c
··· 77 77 * checked when writes are issued, so warn if we see a page writeback 78 78 * operation. 79 79 */ 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))) 82 81 return -EIO; 83 82 84 83 /* ··· 127 128 { 128 129 struct zonefs_inode_info *zi = ZONEFS_I(inode); 129 130 130 - if (WARN_ON_ONCE(zi->i_ztype != ZONEFS_ZTYPE_CNV)) 131 + if (WARN_ON_ONCE(zonefs_zone_is_seq(zi))) 131 132 return -EIO; 132 133 if (WARN_ON_ONCE(offset >= i_size_read(inode))) 133 134 return -EIO; ··· 157 158 struct file *swap_file, sector_t *span) 158 159 { 159 160 struct inode *inode = file_inode(swap_file); 160 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 161 161 162 - if (zi->i_ztype != ZONEFS_ZTYPE_CNV) { 162 + if (zonefs_inode_is_seq(inode)) { 163 163 zonefs_err(inode->i_sb, 164 164 "swap file: not a conventional zone file\n"); 165 165 return -EINVAL; ··· 194 196 * only down to a 0 size, which is equivalent to a zone reset, and to 195 197 * the maximum file size, which is equivalent to a zone finish. 196 198 */ 197 - if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 199 + if (!zonefs_zone_is_seq(zi)) 198 200 return -EPERM; 199 201 200 202 if (!isize) ··· 264 266 * Since only direct writes are allowed in sequential files, page cache 265 267 * flush is needed only for conventional zone files. 266 268 */ 267 - if (ZONEFS_I(inode)->i_ztype == ZONEFS_ZTYPE_CNV) 269 + if (zonefs_inode_is_cnv(inode)) 268 270 ret = file_write_and_wait_range(file, start, end); 269 271 if (!ret) 270 272 ret = blkdev_issue_flush(inode->i_sb->s_bdev); ··· 278 280 static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf) 279 281 { 280 282 struct inode *inode = file_inode(vmf->vma->vm_file); 281 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 282 283 vm_fault_t ret; 283 284 284 285 if (unlikely(IS_IMMUTABLE(inode))) ··· 287 290 * Sanity check: only conventional zone files can have shared 288 291 * writeable mappings. 289 292 */ 290 - if (WARN_ON_ONCE(zi->i_ztype != ZONEFS_ZTYPE_CNV)) 293 + if (zonefs_inode_is_seq(inode)) 291 294 return VM_FAULT_NOPAGE; 292 295 293 296 sb_start_pagefault(inode->i_sb); ··· 316 319 * mappings are possible since there are no guarantees for write 317 320 * ordering between msync() and page cache writeback. 318 321 */ 319 - if (ZONEFS_I(file_inode(file))->i_ztype == ZONEFS_ZTYPE_SEQ && 322 + if (zonefs_inode_is_seq(file_inode(file)) && 320 323 (vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) 321 324 return -EINVAL; 322 325 ··· 349 352 return error; 350 353 } 351 354 352 - if (size && zi->i_ztype != ZONEFS_ZTYPE_CNV) { 355 + if (size && zonefs_zone_is_seq(zi)) { 353 356 /* 354 357 * Note that we may be seeing completions out of order, 355 358 * but that is not a problem since a write completed ··· 488 491 return -EINVAL; 489 492 490 493 if (iocb->ki_flags & IOCB_APPEND) { 491 - if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 494 + if (zonefs_zone_is_cnv(zi)) 492 495 return -EINVAL; 493 496 mutex_lock(&zi->i_truncate_mutex); 494 497 iocb->ki_pos = zi->i_wpoffset; ··· 528 531 * as this can cause write reordering (e.g. the first aio gets EAGAIN 529 532 * on the inode lock but the second goes through but is now unaligned). 530 533 */ 531 - if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && !sync && 532 - (iocb->ki_flags & IOCB_NOWAIT)) 534 + if (zonefs_zone_is_seq(zi) && !sync && (iocb->ki_flags & IOCB_NOWAIT)) 533 535 return -EOPNOTSUPP; 534 536 535 537 if (iocb->ki_flags & IOCB_NOWAIT) { ··· 550 554 } 551 555 552 556 /* Enforce sequential writes (append only) in sequential zones */ 553 - if (zi->i_ztype == ZONEFS_ZTYPE_SEQ) { 557 + if (zonefs_zone_is_seq(zi)) { 554 558 mutex_lock(&zi->i_truncate_mutex); 555 559 if (iocb->ki_pos != zi->i_wpoffset) { 556 560 mutex_unlock(&zi->i_truncate_mutex); ··· 566 570 else 567 571 ret = iomap_dio_rw(iocb, from, &zonefs_write_iomap_ops, 568 572 &zonefs_write_dio_ops, 0, NULL, 0); 569 - if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && 573 + if (zonefs_zone_is_seq(zi) && 570 574 (ret > 0 || ret == -EIOCBQUEUED)) { 571 575 if (ret > 0) 572 576 count = ret; ··· 592 596 struct iov_iter *from) 593 597 { 594 598 struct inode *inode = file_inode(iocb->ki_filp); 595 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 596 599 ssize_t ret; 597 600 598 601 /* 599 602 * Direct IO writes are mandatory for sequential zone files so that the 600 603 * write IO issuing order is preserved. 601 604 */ 602 - if (zi->i_ztype != ZONEFS_ZTYPE_CNV) 605 + if (zonefs_inode_is_seq(inode)) 603 606 return -EIO; 604 607 605 608 if (iocb->ki_flags & IOCB_NOWAIT) { ··· 726 731 static inline bool zonefs_seq_file_need_wro(struct inode *inode, 727 732 struct file *file) 728 733 { 729 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 730 - 731 - if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 734 + if (zonefs_inode_is_cnv(inode)) 732 735 return false; 733 736 734 737 if (!(file->f_mode & FMODE_WRITE))
+7 -5
fs/zonefs/super.c
··· 37 37 38 38 lockdep_assert_held(&zi->i_truncate_mutex); 39 39 40 - if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 40 + if (zonefs_zone_is_cnv(zi)) 41 41 return; 42 42 43 43 /* ··· 177 177 zonefs_warn(inode->i_sb, "inode %lu: read-only zone\n", 178 178 inode->i_ino); 179 179 zi->i_flags |= ZONEFS_ZONE_READONLY; 180 - if (zi->i_ztype == ZONEFS_ZTYPE_CNV) 180 + if (zonefs_zone_is_cnv(zi)) 181 181 return zi->i_max_size; 182 182 return zi->i_wpoffset; 183 183 case BLK_ZONE_COND_FULL: 184 184 /* The write pointer of full zones is invalid. */ 185 185 return zi->i_max_size; 186 186 default: 187 - if (zi->i_ztype == ZONEFS_ZTYPE_CNV) 187 + if (zonefs_zone_is_cnv(zi)) 188 188 return zi->i_max_size; 189 189 return (zone->wp - zone->start) << SECTOR_SHIFT; 190 190 } ··· 260 260 * In all cases, warn about inode size inconsistency and handle the 261 261 * IO error according to the zone condition and to the mount options. 262 262 */ 263 - if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && isize != data_size) 263 + if (zonefs_zone_is_seq(zi) && isize != data_size) 264 264 zonefs_warn(sb, "inode %lu: invalid size %lld (should be %lld)\n", 265 265 inode->i_ino, isize, data_size); 266 266 ··· 584 584 inode->i_ino = zone->start >> sbi->s_zone_sectors_shift; 585 585 inode->i_mode = S_IFREG | sbi->s_perm; 586 586 587 - zi->i_ztype = type; 587 + if (type == ZONEFS_ZTYPE_CNV) 588 + zi->i_flags |= ZONEFS_ZONE_CNV; 589 + 588 590 zi->i_zsector = zone->start; 589 591 zi->i_zone_size = zone->len << SECTOR_SHIFT; 590 592 if (zi->i_zone_size > bdev_zone_sectors(sb->s_bdev) << SECTOR_SHIFT &&
+21 -3
fs/zonefs/zonefs.h
··· 44 44 #define ZONEFS_ZONE_ACTIVE (1U << 2) 45 45 #define ZONEFS_ZONE_OFFLINE (1U << 3) 46 46 #define ZONEFS_ZONE_READONLY (1U << 4) 47 + #define ZONEFS_ZONE_CNV (1U << 31) 47 48 48 49 /* 49 50 * In-memory inode data. 50 51 */ 51 52 struct zonefs_inode_info { 52 53 struct inode i_vnode; 53 - 54 - /* File zone type */ 55 - enum zonefs_ztype i_ztype; 56 54 57 55 /* File zone start sector (512B unit) */ 58 56 sector_t i_zsector; ··· 87 89 static inline struct zonefs_inode_info *ZONEFS_I(struct inode *inode) 88 90 { 89 91 return container_of(inode, struct zonefs_inode_info, i_vnode); 92 + } 93 + 94 + static inline bool zonefs_zone_is_cnv(struct zonefs_inode_info *zi) 95 + { 96 + return zi->i_flags & ZONEFS_ZONE_CNV; 97 + } 98 + 99 + static inline bool zonefs_zone_is_seq(struct zonefs_inode_info *zi) 100 + { 101 + return !zonefs_zone_is_cnv(zi); 102 + } 103 + 104 + static inline bool zonefs_inode_is_cnv(struct inode *inode) 105 + { 106 + return zonefs_zone_is_cnv(ZONEFS_I(inode)); 107 + } 108 + 109 + static inline bool zonefs_inode_is_seq(struct inode *inode) 110 + { 111 + return zonefs_zone_is_seq(ZONEFS_I(inode)); 90 112 } 91 113 92 114 /*