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

xfs: refactor all the EFI/EFD log item sizeof logic

Refactor all the open-coded sizeof logic for EFI/EFD log item and log
format structures into common helper functions whose names reflect the
struct names.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>

+88 -57
+48
fs/xfs/libxfs/xfs_log_format.h
··· 616 616 xfs_extent_t efi_extents[]; /* array of extents to free */ 617 617 } xfs_efi_log_format_t; 618 618 619 + static inline size_t 620 + xfs_efi_log_format_sizeof( 621 + unsigned int nr) 622 + { 623 + return sizeof(struct xfs_efi_log_format) + 624 + nr * sizeof(struct xfs_extent); 625 + } 626 + 619 627 typedef struct xfs_efi_log_format_32 { 620 628 uint16_t efi_type; /* efi log item type */ 621 629 uint16_t efi_size; /* size of this item */ ··· 632 624 xfs_extent_32_t efi_extents[]; /* array of extents to free */ 633 625 } __attribute__((packed)) xfs_efi_log_format_32_t; 634 626 627 + static inline size_t 628 + xfs_efi_log_format32_sizeof( 629 + unsigned int nr) 630 + { 631 + return sizeof(struct xfs_efi_log_format_32) + 632 + nr * sizeof(struct xfs_extent_32); 633 + } 634 + 635 635 typedef struct xfs_efi_log_format_64 { 636 636 uint16_t efi_type; /* efi log item type */ 637 637 uint16_t efi_size; /* size of this item */ ··· 647 631 uint64_t efi_id; /* efi identifier */ 648 632 xfs_extent_64_t efi_extents[]; /* array of extents to free */ 649 633 } xfs_efi_log_format_64_t; 634 + 635 + static inline size_t 636 + xfs_efi_log_format64_sizeof( 637 + unsigned int nr) 638 + { 639 + return sizeof(struct xfs_efi_log_format_64) + 640 + nr * sizeof(struct xfs_extent_64); 641 + } 650 642 651 643 /* 652 644 * This is the structure used to lay out an efd log item in the ··· 669 645 xfs_extent_t efd_extents[]; /* array of extents freed */ 670 646 } xfs_efd_log_format_t; 671 647 648 + static inline size_t 649 + xfs_efd_log_format_sizeof( 650 + unsigned int nr) 651 + { 652 + return sizeof(struct xfs_efd_log_format) + 653 + nr * sizeof(struct xfs_extent); 654 + } 655 + 672 656 typedef struct xfs_efd_log_format_32 { 673 657 uint16_t efd_type; /* efd log item type */ 674 658 uint16_t efd_size; /* size of this item */ ··· 685 653 xfs_extent_32_t efd_extents[]; /* array of extents freed */ 686 654 } __attribute__((packed)) xfs_efd_log_format_32_t; 687 655 656 + static inline size_t 657 + xfs_efd_log_format32_sizeof( 658 + unsigned int nr) 659 + { 660 + return sizeof(struct xfs_efd_log_format_32) + 661 + nr * sizeof(struct xfs_extent_32); 662 + } 663 + 688 664 typedef struct xfs_efd_log_format_64 { 689 665 uint16_t efd_type; /* efd log item type */ 690 666 uint16_t efd_size; /* size of this item */ ··· 700 660 uint64_t efd_efi_id; /* id of corresponding efi */ 701 661 xfs_extent_64_t efd_extents[]; /* array of extents freed */ 702 662 } xfs_efd_log_format_64_t; 663 + 664 + static inline size_t 665 + xfs_efd_log_format64_sizeof( 666 + unsigned int nr) 667 + { 668 + return sizeof(struct xfs_efd_log_format_64) + 669 + nr * sizeof(struct xfs_extent_64); 670 + } 703 671 704 672 /* 705 673 * RUI/RUD (reverse mapping) log format definitions
+20 -49
fs/xfs/xfs_extfree_item.c
··· 66 66 xfs_efi_item_free(efip); 67 67 } 68 68 69 - /* 70 - * This returns the number of iovecs needed to log the given efi item. 71 - * We only need 1 iovec for an efi item. It just logs the efi_log_format 72 - * structure. 73 - */ 74 - static inline int 75 - xfs_efi_item_sizeof( 76 - struct xfs_efi_log_item *efip) 77 - { 78 - return sizeof(struct xfs_efi_log_format) + 79 - efip->efi_format.efi_nextents * sizeof(xfs_extent_t); 80 - } 81 - 82 69 STATIC void 83 70 xfs_efi_item_size( 84 71 struct xfs_log_item *lip, 85 72 int *nvecs, 86 73 int *nbytes) 87 74 { 75 + struct xfs_efi_log_item *efip = EFI_ITEM(lip); 76 + 88 77 *nvecs += 1; 89 - *nbytes += xfs_efi_item_sizeof(EFI_ITEM(lip)); 78 + *nbytes += xfs_efi_log_format_sizeof(efip->efi_format.efi_nextents); 90 79 } 91 80 92 81 /* ··· 101 112 102 113 xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_EFI_FORMAT, 103 114 &efip->efi_format, 104 - xfs_efi_item_sizeof(efip)); 115 + xfs_efi_log_format_sizeof(efip->efi_format.efi_nextents)); 105 116 } 106 117 107 118 ··· 144 155 145 156 { 146 157 struct xfs_efi_log_item *efip; 147 - uint size; 148 158 149 159 ASSERT(nextents > 0); 150 160 if (nextents > XFS_EFI_MAX_FAST_EXTENTS) { 151 - size = (uint)(sizeof(struct xfs_efi_log_item) + 152 - (nextents * sizeof(xfs_extent_t))); 153 - efip = kmem_zalloc(size, 0); 161 + efip = kzalloc(xfs_efi_log_item_sizeof(nextents), 162 + GFP_KERNEL | __GFP_NOFAIL); 154 163 } else { 155 164 efip = kmem_cache_zalloc(xfs_efi_cache, 156 165 GFP_KERNEL | __GFP_NOFAIL); ··· 175 188 { 176 189 xfs_efi_log_format_t *src_efi_fmt = buf->i_addr; 177 190 uint i; 178 - uint len = sizeof(xfs_efi_log_format_t) + 179 - src_efi_fmt->efi_nextents * sizeof(xfs_extent_t); 180 - uint len32 = sizeof(xfs_efi_log_format_32_t) + 181 - src_efi_fmt->efi_nextents * sizeof(xfs_extent_32_t); 182 - uint len64 = sizeof(xfs_efi_log_format_64_t) + 183 - src_efi_fmt->efi_nextents * sizeof(xfs_extent_64_t); 191 + uint len = xfs_efi_log_format_sizeof(src_efi_fmt->efi_nextents); 192 + uint len32 = xfs_efi_log_format32_sizeof(src_efi_fmt->efi_nextents); 193 + uint len64 = xfs_efi_log_format64_sizeof(src_efi_fmt->efi_nextents); 184 194 185 195 if (buf->i_len == len) { 186 196 memcpy(dst_efi_fmt, src_efi_fmt, ··· 235 251 kmem_cache_free(xfs_efd_cache, efdp); 236 252 } 237 253 238 - /* 239 - * This returns the number of iovecs needed to log the given efd item. 240 - * We only need 1 iovec for an efd item. It just logs the efd_log_format 241 - * structure. 242 - */ 243 - static inline int 244 - xfs_efd_item_sizeof( 245 - struct xfs_efd_log_item *efdp) 246 - { 247 - return sizeof(xfs_efd_log_format_t) + 248 - efdp->efd_format.efd_nextents * sizeof(xfs_extent_t); 249 - } 250 - 251 254 STATIC void 252 255 xfs_efd_item_size( 253 256 struct xfs_log_item *lip, 254 257 int *nvecs, 255 258 int *nbytes) 256 259 { 260 + struct xfs_efd_log_item *efdp = EFD_ITEM(lip); 261 + 257 262 *nvecs += 1; 258 - *nbytes += xfs_efd_item_sizeof(EFD_ITEM(lip)); 263 + *nbytes += xfs_efd_log_format_sizeof(efdp->efd_format.efd_nextents); 259 264 } 260 265 261 266 /* ··· 269 296 270 297 xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_EFD_FORMAT, 271 298 &efdp->efd_format, 272 - xfs_efd_item_sizeof(efdp)); 299 + xfs_efd_log_format_sizeof(efdp->efd_format.efd_nextents)); 273 300 } 274 301 275 302 /* ··· 318 345 ASSERT(nextents > 0); 319 346 320 347 if (nextents > XFS_EFD_MAX_FAST_EXTENTS) { 321 - efdp = kmem_zalloc(sizeof(struct xfs_efd_log_item) + 322 - nextents * sizeof(struct xfs_extent), 323 - 0); 348 + efdp = kzalloc(xfs_efd_log_item_sizeof(nextents), 349 + GFP_KERNEL | __GFP_NOFAIL); 324 350 } else { 325 351 efdp = kmem_cache_zalloc(xfs_efd_cache, 326 352 GFP_KERNEL | __GFP_NOFAIL); ··· 710 738 711 739 efi_formatp = item->ri_buf[0].i_addr; 712 740 713 - if (item->ri_buf[0].i_len < 714 - offsetof(struct xfs_efi_log_format, efi_extents)) { 741 + if (item->ri_buf[0].i_len < xfs_efi_log_format_sizeof(0)) { 715 742 XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, log->l_mp); 716 743 return -EFSCORRUPTED; 717 744 } ··· 753 782 struct xfs_efd_log_format *efd_formatp; 754 783 755 784 efd_formatp = item->ri_buf[0].i_addr; 756 - ASSERT((item->ri_buf[0].i_len == (sizeof(xfs_efd_log_format_32_t) + 757 - (efd_formatp->efd_nextents * sizeof(xfs_extent_32_t)))) || 758 - (item->ri_buf[0].i_len == (sizeof(xfs_efd_log_format_64_t) + 759 - (efd_formatp->efd_nextents * sizeof(xfs_extent_64_t))))); 785 + ASSERT(item->ri_buf[0].i_len == xfs_efd_log_format32_sizeof( 786 + efd_formatp->efd_nextents) || 787 + item->ri_buf[0].i_len == xfs_efd_log_format64_sizeof( 788 + efd_formatp->efd_nextents)); 760 789 761 790 xlog_recover_release_intent(log, XFS_LI_EFI, efd_formatp->efd_efi_id); 762 791 return 0;
+16
fs/xfs/xfs_extfree_item.h
··· 52 52 xfs_efi_log_format_t efi_format; 53 53 }; 54 54 55 + static inline size_t 56 + xfs_efi_log_item_sizeof( 57 + unsigned int nr) 58 + { 59 + return offsetof(struct xfs_efi_log_item, efi_format) + 60 + xfs_efi_log_format_sizeof(nr); 61 + } 62 + 55 63 /* 56 64 * This is the "extent free done" log item. It is used to log 57 65 * the fact that some extents earlier mentioned in an efi item ··· 71 63 uint efd_next_extent; 72 64 xfs_efd_log_format_t efd_format; 73 65 }; 66 + 67 + static inline size_t 68 + xfs_efd_log_item_sizeof( 69 + unsigned int nr) 70 + { 71 + return offsetof(struct xfs_efd_log_item, efd_format) + 72 + xfs_efd_log_format_sizeof(nr); 73 + } 74 74 75 75 /* 76 76 * Max number of extents in fast allocation path.
+4 -8
fs/xfs/xfs_super.c
··· 2028 2028 goto out_destroy_trans_cache; 2029 2029 2030 2030 xfs_efd_cache = kmem_cache_create("xfs_efd_item", 2031 - (sizeof(struct xfs_efd_log_item) + 2032 - XFS_EFD_MAX_FAST_EXTENTS * 2033 - sizeof(struct xfs_extent)), 2034 - 0, 0, NULL); 2031 + xfs_efd_log_item_sizeof(XFS_EFD_MAX_FAST_EXTENTS), 2032 + 0, 0, NULL); 2035 2033 if (!xfs_efd_cache) 2036 2034 goto out_destroy_buf_item_cache; 2037 2035 2038 2036 xfs_efi_cache = kmem_cache_create("xfs_efi_item", 2039 - (sizeof(struct xfs_efi_log_item) + 2040 - XFS_EFI_MAX_FAST_EXTENTS * 2041 - sizeof(struct xfs_extent)), 2042 - 0, 0, NULL); 2037 + xfs_efi_log_item_sizeof(XFS_EFI_MAX_FAST_EXTENTS), 2038 + 0, 0, NULL); 2043 2039 if (!xfs_efi_cache) 2044 2040 goto out_destroy_efd_cache; 2045 2041