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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'xfs-fixes-6.16-rc7' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux

Pull xfs fixes from Carlos Maiolino:
"This contains mostly code clean up, refactoring and comments
modification.

The most important patch in this series is the last one that removes
an unnecessary data structure allocation of xfs busy extents which
might lead to a memory leak on the zoned allocator code"

* tag 'xfs-fixes-6.16-rc7' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux:
xfs: don't allocate the xfs_extent_busy structure for zoned RTGs
xfs: remove the bt_bdev_file buftarg field
xfs: rename the bt_bdev_* buftarg fields
xfs: refactor xfs_calc_atomic_write_unit_max
xfs: add a xfs_group_type_buftarg helper
xfs: remove the call to sync_blockdev in xfs_configure_buftarg
xfs: clean up the initial read logic in xfs_readsb
xfs: replace strncpy with memcpy in xattr listing

+108 -124
+9 -5
fs/xfs/libxfs/xfs_group.c
··· 163 163 164 164 xfs_defer_drain_free(&xg->xg_intents_drain); 165 165 #ifdef __KERNEL__ 166 - kfree(xg->xg_busy_extents); 166 + if (xfs_group_has_extent_busy(xg->xg_mount, xg->xg_type)) 167 + kfree(xg->xg_busy_extents); 167 168 #endif 168 169 169 170 if (uninit) ··· 190 189 xg->xg_type = type; 191 190 192 191 #ifdef __KERNEL__ 193 - xg->xg_busy_extents = xfs_extent_busy_alloc(); 194 - if (!xg->xg_busy_extents) 195 - return -ENOMEM; 192 + if (xfs_group_has_extent_busy(mp, type)) { 193 + xg->xg_busy_extents = xfs_extent_busy_alloc(); 194 + if (!xg->xg_busy_extents) 195 + return -ENOMEM; 196 + } 196 197 spin_lock_init(&xg->xg_state_lock); 197 198 xfs_hooks_init(&xg->xg_rmap_update_hooks); 198 199 #endif ··· 213 210 out_drain: 214 211 xfs_defer_drain_free(&xg->xg_intents_drain); 215 212 #ifdef __KERNEL__ 216 - kfree(xg->xg_busy_extents); 213 + if (xfs_group_has_extent_busy(xg->xg_mount, xg->xg_type)) 214 + kfree(xg->xg_busy_extents); 217 215 #endif 218 216 return error; 219 217 }
+5 -10
fs/xfs/xfs_buf.c
··· 1683 1683 fs_put_dax(btp->bt_daxdev, btp->bt_mount); 1684 1684 /* the main block device is closed by kill_block_super */ 1685 1685 if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev) 1686 - bdev_fput(btp->bt_bdev_file); 1686 + bdev_fput(btp->bt_file); 1687 1687 kfree(btp); 1688 1688 } 1689 1689 ··· 1712 1712 max_bytes = 0; 1713 1713 } 1714 1714 1715 - btp->bt_bdev_awu_min = min_bytes; 1716 - btp->bt_bdev_awu_max = max_bytes; 1715 + btp->bt_awu_min = min_bytes; 1716 + btp->bt_awu_max = max_bytes; 1717 1717 } 1718 1718 1719 1719 /* Configure a buffer target that abstracts a block device. */ ··· 1738 1738 return -EINVAL; 1739 1739 } 1740 1740 1741 - /* 1742 - * Flush the block device pagecache so our bios see anything dirtied 1743 - * before mount. 1744 - */ 1745 1741 if (bdev_can_atomic_write(btp->bt_bdev)) 1746 1742 xfs_configure_buftarg_atomic_writes(btp); 1747 - 1748 - return sync_blockdev(btp->bt_bdev); 1743 + return 0; 1749 1744 } 1750 1745 1751 1746 int ··· 1798 1803 btp = kzalloc(sizeof(*btp), GFP_KERNEL | __GFP_NOFAIL); 1799 1804 1800 1805 btp->bt_mount = mp; 1801 - btp->bt_bdev_file = bdev_file; 1806 + btp->bt_file = bdev_file; 1802 1807 btp->bt_bdev = file_bdev(bdev_file); 1803 1808 btp->bt_dev = btp->bt_bdev->bd_dev; 1804 1809 btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off,
+3 -5
fs/xfs/xfs_buf.h
··· 94 94 */ 95 95 struct xfs_buftarg { 96 96 dev_t bt_dev; 97 - struct file *bt_bdev_file; 98 97 struct block_device *bt_bdev; 99 98 struct dax_device *bt_daxdev; 100 99 struct file *bt_file; ··· 111 112 struct percpu_counter bt_readahead_count; 112 113 struct ratelimit_state bt_ioerror_rl; 113 114 114 - /* Atomic write unit values, bytes */ 115 - unsigned int bt_bdev_awu_min; 116 - unsigned int bt_bdev_awu_max; 115 + /* Hardware atomic write unit values, bytes */ 116 + unsigned int bt_awu_min; 117 + unsigned int bt_awu_max; 117 118 118 119 /* built-in cache, if we're not using the perag one */ 119 120 struct xfs_buf_cache bt_cache[]; ··· 374 375 extern void xfs_buftarg_drain(struct xfs_buftarg *); 375 376 int xfs_configure_buftarg(struct xfs_buftarg *btp, unsigned int sectorsize); 376 377 377 - #define xfs_getsize_buftarg(buftarg) block_size((buftarg)->bt_bdev) 378 378 #define xfs_readonly_buftarg(buftarg) bdev_read_only((buftarg)->bt_bdev) 379 379 380 380 int xfs_buf_reverify(struct xfs_buf *bp, const struct xfs_buf_ops *ops);
+7 -22
fs/xfs/xfs_discard.c
··· 103 103 bio_put(bio); 104 104 } 105 105 106 - static inline struct block_device * 107 - xfs_group_bdev( 108 - const struct xfs_group *xg) 109 - { 110 - struct xfs_mount *mp = xg->xg_mount; 111 - 112 - switch (xg->xg_type) { 113 - case XG_TYPE_AG: 114 - return mp->m_ddev_targp->bt_bdev; 115 - case XG_TYPE_RTG: 116 - return mp->m_rtdev_targp->bt_bdev; 117 - default: 118 - ASSERT(0); 119 - break; 120 - } 121 - return NULL; 122 - } 123 - 124 106 /* 125 107 * Walk the discard list and issue discards on all the busy extents in the 126 108 * list. We plug and chain the bios so that we only need a single completion ··· 120 138 121 139 blk_start_plug(&plug); 122 140 list_for_each_entry(busyp, &extents->extent_list, list) { 123 - trace_xfs_discard_extent(busyp->group, busyp->bno, 124 - busyp->length); 141 + struct xfs_group *xg = busyp->group; 142 + struct xfs_buftarg *btp = 143 + xfs_group_type_buftarg(xg->xg_mount, xg->xg_type); 125 144 126 - error = __blkdev_issue_discard(xfs_group_bdev(busyp->group), 127 - xfs_gbno_to_daddr(busyp->group, busyp->bno), 145 + trace_xfs_discard_extent(xg, busyp->bno, busyp->length); 146 + 147 + error = __blkdev_issue_discard(btp->bt_bdev, 148 + xfs_gbno_to_daddr(xg, busyp->bno), 128 149 XFS_FSB_TO_BB(mp, busyp->length), 129 150 GFP_KERNEL, &bio); 130 151 if (error && error != -EOPNOTSUPP) {
+8
fs/xfs/xfs_extent_busy.h
··· 68 68 list_sort(NULL, list, xfs_extent_busy_ag_cmp); 69 69 } 70 70 71 + /* 72 + * Zoned RTGs don't need to track busy extents, as the actual block freeing only 73 + * happens by a zone reset, which forces out all transactions that touched the 74 + * to be reset zone first. 75 + */ 76 + #define xfs_group_has_extent_busy(mp, type) \ 77 + ((type) == XG_TYPE_AG || !xfs_has_zoned((mp))) 78 + 71 79 #endif /* __XFS_EXTENT_BUSY_H__ */
+1 -1
fs/xfs/xfs_file.c
··· 752 752 * HW offload should be faster, so try that first if it is already 753 753 * known that the write length is not too large. 754 754 */ 755 - if (ocount > xfs_inode_buftarg(ip)->bt_bdev_awu_max) 755 + if (ocount > xfs_inode_buftarg(ip)->bt_awu_max) 756 756 dops = &xfs_atomic_write_cow_iomap_ops; 757 757 else 758 758 dops = &xfs_direct_write_iomap_ops;
+1 -1
fs/xfs/xfs_inode.h
··· 358 358 359 359 static inline bool xfs_inode_can_hw_atomic_write(const struct xfs_inode *ip) 360 360 { 361 - return xfs_inode_buftarg(ip)->bt_bdev_awu_max > 0; 361 + return xfs_inode_buftarg(ip)->bt_awu_max > 0; 362 362 } 363 363 364 364 /*
+1 -1
fs/xfs/xfs_iomap.c
··· 827 827 /* 828 828 * The ->iomap_begin caller should ensure this, but check anyway. 829 829 */ 830 - return len <= xfs_inode_buftarg(ip)->bt_bdev_awu_max; 830 + return len <= xfs_inode_buftarg(ip)->bt_awu_max; 831 831 } 832 832 833 833 static int
+1 -1
fs/xfs/xfs_iops.c
··· 665 665 * less than our out of place write limit, but we don't want to exceed 666 666 * the awu_max. 667 667 */ 668 - return min(awu_max, xfs_inode_buftarg(ip)->bt_bdev_awu_max); 668 + return min(awu_max, xfs_inode_buftarg(ip)->bt_awu_max); 669 669 } 670 670 671 671 static void
+39 -58
fs/xfs/xfs_mount.c
··· 171 171 ASSERT(mp->m_ddev_targp != NULL); 172 172 173 173 /* 174 - * For the initial read, we must guess at the sector 175 - * size based on the block device. It's enough to 176 - * get the sb_sectsize out of the superblock and 177 - * then reread with the proper length. 178 - * We don't verify it yet, because it may not be complete. 174 + * In the first pass, use the device sector size to just read enough 175 + * of the superblock to extract the XFS sector size. 176 + * 177 + * The device sector size must be smaller than or equal to the XFS 178 + * sector size and thus we can always read the superblock. Once we know 179 + * the XFS sector size, re-read it and run the buffer verifier. 179 180 */ 180 - sector_size = xfs_getsize_buftarg(mp->m_ddev_targp); 181 + sector_size = mp->m_ddev_targp->bt_logical_sectorsize; 181 182 buf_ops = NULL; 182 183 183 - /* 184 - * Allocate a (locked) buffer to hold the superblock. This will be kept 185 - * around at all times to optimize access to the superblock. 186 - */ 187 184 reread: 188 185 error = xfs_buf_read_uncached(mp->m_ddev_targp, XFS_SB_DADDR, 189 186 BTOBB(sector_size), &bp, buf_ops); ··· 244 247 /* no need to be quiet anymore, so reset the buf ops */ 245 248 bp->b_ops = &xfs_sb_buf_ops; 246 249 250 + /* 251 + * Keep a pointer of the sb buffer around instead of caching it in the 252 + * buffer cache because we access it frequently. 253 + */ 247 254 mp->m_sb_bp = bp; 248 255 xfs_buf_unlock(bp); 249 256 return 0; ··· 679 678 } 680 679 681 680 /* 682 - * If the data device advertises atomic write support, limit the size of data 683 - * device atomic writes to the greatest power-of-two factor of the AG size so 684 - * that every atomic write unit aligns with the start of every AG. This is 685 - * required so that the per-AG allocations for an atomic write will always be 681 + * If the underlying device advertises atomic write support, limit the size of 682 + * atomic writes to the greatest power-of-two factor of the group size so 683 + * that every atomic write unit aligns with the start of every group. This is 684 + * required so that the allocations for an atomic write will always be 686 685 * aligned compatibly with the alignment requirements of the storage. 687 686 * 688 - * If the data device doesn't advertise atomic writes, then there are no 689 - * alignment restrictions and the largest out-of-place write we can do 690 - * ourselves is the number of blocks that user files can allocate from any AG. 687 + * If the device doesn't advertise atomic writes, then there are no alignment 688 + * restrictions and the largest out-of-place write we can do ourselves is the 689 + * number of blocks that user files can allocate from any group. 691 690 */ 692 - static inline xfs_extlen_t xfs_calc_perag_awu_max(struct xfs_mount *mp) 691 + static xfs_extlen_t 692 + xfs_calc_group_awu_max( 693 + struct xfs_mount *mp, 694 + enum xfs_group_type type) 693 695 { 694 - if (mp->m_ddev_targp->bt_bdev_awu_min > 0) 695 - return max_pow_of_two_factor(mp->m_sb.sb_agblocks); 696 - return rounddown_pow_of_two(mp->m_ag_max_usable); 697 - } 696 + struct xfs_groups *g = &mp->m_groups[type]; 697 + struct xfs_buftarg *btp = xfs_group_type_buftarg(mp, type); 698 698 699 - /* 700 - * Reflink on the realtime device requires rtgroups, and atomic writes require 701 - * reflink. 702 - * 703 - * If the realtime device advertises atomic write support, limit the size of 704 - * data device atomic writes to the greatest power-of-two factor of the rtgroup 705 - * size so that every atomic write unit aligns with the start of every rtgroup. 706 - * This is required so that the per-rtgroup allocations for an atomic write 707 - * will always be aligned compatibly with the alignment requirements of the 708 - * storage. 709 - * 710 - * If the rt device doesn't advertise atomic writes, then there are no 711 - * alignment restrictions and the largest out-of-place write we can do 712 - * ourselves is the number of blocks that user files can allocate from any 713 - * rtgroup. 714 - */ 715 - static inline xfs_extlen_t xfs_calc_rtgroup_awu_max(struct xfs_mount *mp) 716 - { 717 - struct xfs_groups *rgs = &mp->m_groups[XG_TYPE_RTG]; 718 - 719 - if (rgs->blocks == 0) 699 + if (g->blocks == 0) 720 700 return 0; 721 - if (mp->m_rtdev_targp && mp->m_rtdev_targp->bt_bdev_awu_min > 0) 722 - return max_pow_of_two_factor(rgs->blocks); 723 - return rounddown_pow_of_two(rgs->blocks); 701 + if (btp && btp->bt_awu_min > 0) 702 + return max_pow_of_two_factor(g->blocks); 703 + return rounddown_pow_of_two(g->blocks); 724 704 } 725 705 726 706 /* Compute the maximum atomic write unit size for each section. */ 727 707 static inline void 728 708 xfs_calc_atomic_write_unit_max( 729 - struct xfs_mount *mp) 709 + struct xfs_mount *mp, 710 + enum xfs_group_type type) 730 711 { 731 - struct xfs_groups *ags = &mp->m_groups[XG_TYPE_AG]; 732 - struct xfs_groups *rgs = &mp->m_groups[XG_TYPE_RTG]; 712 + struct xfs_groups *g = &mp->m_groups[type]; 733 713 734 714 const xfs_extlen_t max_write = xfs_calc_atomic_write_max(mp); 735 715 const xfs_extlen_t max_ioend = xfs_reflink_max_atomic_cow(mp); 736 - const xfs_extlen_t max_agsize = xfs_calc_perag_awu_max(mp); 737 - const xfs_extlen_t max_rgsize = xfs_calc_rtgroup_awu_max(mp); 716 + const xfs_extlen_t max_gsize = xfs_calc_group_awu_max(mp, type); 738 717 739 - ags->awu_max = min3(max_write, max_ioend, max_agsize); 740 - rgs->awu_max = min3(max_write, max_ioend, max_rgsize); 741 - 742 - trace_xfs_calc_atomic_write_unit_max(mp, max_write, max_ioend, 743 - max_agsize, max_rgsize); 718 + g->awu_max = min3(max_write, max_ioend, max_gsize); 719 + trace_xfs_calc_atomic_write_unit_max(mp, type, max_write, max_ioend, 720 + max_gsize, g->awu_max); 744 721 } 745 722 746 723 /* ··· 736 757 max(mp->m_groups[XG_TYPE_AG].blocks, 737 758 mp->m_groups[XG_TYPE_RTG].blocks); 738 759 const xfs_extlen_t max_group_write = 739 - max(xfs_calc_perag_awu_max(mp), xfs_calc_rtgroup_awu_max(mp)); 760 + max(xfs_calc_group_awu_max(mp, XG_TYPE_AG), 761 + xfs_calc_group_awu_max(mp, XG_TYPE_RTG)); 740 762 int error; 741 763 742 764 if (new_max_bytes == 0) ··· 793 813 return error; 794 814 } 795 815 796 - xfs_calc_atomic_write_unit_max(mp); 816 + xfs_calc_atomic_write_unit_max(mp, XG_TYPE_AG); 817 + xfs_calc_atomic_write_unit_max(mp, XG_TYPE_RTG); 797 818 mp->m_awu_max_bytes = new_max_bytes; 798 819 return 0; 799 820 }
+17
fs/xfs/xfs_mount.h
··· 802 802 int xfs_set_max_atomic_write_opt(struct xfs_mount *mp, 803 803 unsigned long long new_max_bytes); 804 804 805 + static inline struct xfs_buftarg * 806 + xfs_group_type_buftarg( 807 + struct xfs_mount *mp, 808 + enum xfs_group_type type) 809 + { 810 + switch (type) { 811 + case XG_TYPE_AG: 812 + return mp->m_ddev_targp; 813 + case XG_TYPE_RTG: 814 + return mp->m_rtdev_targp; 815 + default: 816 + ASSERT(0); 817 + break; 818 + } 819 + return NULL; 820 + } 821 + 805 822 #endif /* __XFS_MOUNT_H__ */
+1 -2
fs/xfs/xfs_notify_failure.c
··· 253 253 return -EOPNOTSUPP; 254 254 } 255 255 256 - error = xfs_dax_translate_range(type == XG_TYPE_RTG ? 257 - mp->m_rtdev_targp : mp->m_ddev_targp, 256 + error = xfs_dax_translate_range(xfs_group_type_buftarg(mp, type), 258 257 offset, len, &daddr, &bblen); 259 258 if (error) 260 259 return error;
+14 -17
fs/xfs/xfs_trace.h
··· 171 171 DEFINE_ATTR_LIST_EVENT(xfs_attr_node_list); 172 172 173 173 TRACE_EVENT(xfs_calc_atomic_write_unit_max, 174 - TP_PROTO(struct xfs_mount *mp, unsigned int max_write, 175 - unsigned int max_ioend, unsigned int max_agsize, 176 - unsigned int max_rgsize), 177 - TP_ARGS(mp, max_write, max_ioend, max_agsize, max_rgsize), 174 + TP_PROTO(struct xfs_mount *mp, enum xfs_group_type type, 175 + unsigned int max_write, unsigned int max_ioend, 176 + unsigned int max_gsize, unsigned int awu_max), 177 + TP_ARGS(mp, type, max_write, max_ioend, max_gsize, awu_max), 178 178 TP_STRUCT__entry( 179 179 __field(dev_t, dev) 180 + __field(enum xfs_group_type, type) 180 181 __field(unsigned int, max_write) 181 182 __field(unsigned int, max_ioend) 182 - __field(unsigned int, max_agsize) 183 - __field(unsigned int, max_rgsize) 184 - __field(unsigned int, data_awu_max) 185 - __field(unsigned int, rt_awu_max) 183 + __field(unsigned int, max_gsize) 184 + __field(unsigned int, awu_max) 186 185 ), 187 186 TP_fast_assign( 188 187 __entry->dev = mp->m_super->s_dev; 188 + __entry->type = type; 189 189 __entry->max_write = max_write; 190 190 __entry->max_ioend = max_ioend; 191 - __entry->max_agsize = max_agsize; 192 - __entry->max_rgsize = max_rgsize; 193 - __entry->data_awu_max = mp->m_groups[XG_TYPE_AG].awu_max; 194 - __entry->rt_awu_max = mp->m_groups[XG_TYPE_RTG].awu_max; 191 + __entry->max_gsize = max_gsize; 192 + __entry->awu_max = awu_max; 195 193 ), 196 - TP_printk("dev %d:%d max_write %u max_ioend %u max_agsize %u max_rgsize %u data_awu_max %u rt_awu_max %u", 194 + TP_printk("dev %d:%d %s max_write %u max_ioend %u max_gsize %u awu_max %u", 197 195 MAJOR(__entry->dev), MINOR(__entry->dev), 196 + __print_symbolic(__entry->type, XG_TYPE_STRINGS), 198 197 __entry->max_write, 199 198 __entry->max_ioend, 200 - __entry->max_agsize, 201 - __entry->max_rgsize, 202 - __entry->data_awu_max, 203 - __entry->rt_awu_max) 199 + __entry->max_gsize, 200 + __entry->awu_max) 204 201 ); 205 202 206 203 TRACE_EVENT(xfs_calc_max_atomic_write_fsblocks,
+1 -1
fs/xfs/xfs_xattr.c
··· 243 243 offset = context->buffer + context->count; 244 244 memcpy(offset, prefix, prefix_len); 245 245 offset += prefix_len; 246 - strncpy(offset, (char *)name, namelen); /* real name */ 246 + memcpy(offset, (char *)name, namelen); /* real name */ 247 247 offset += namelen; 248 248 *offset = '\0'; 249 249