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

xfs: Convert xfs_attr_sf macros to inline functions

xfs_attr_sf_totsize() requires access to xfs_inode structure, so, once
xfs_attr_shortform_addname() is its only user, move it to xfs_attr.c
instead of playing with more #includes.

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

authored by

Carlos Maiolino and committed by
Darrick J. Wong
e01b7eed c418dbc9

+41 -25
+11 -3
fs/xfs/libxfs/xfs_attr.c
··· 428 428 */ 429 429 if (XFS_IFORK_Q(dp) == 0) { 430 430 int sf_size = sizeof(struct xfs_attr_sf_hdr) + 431 - XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, 431 + xfs_attr_sf_entsize_byname(args->namelen, 432 432 args->valuelen); 433 433 434 434 error = xfs_bmap_add_attrfork(dp, sf_size, rsvd); ··· 523 523 * External routines when attribute list is inside the inode 524 524 *========================================================================*/ 525 525 526 + static inline int xfs_attr_sf_totsize(struct xfs_inode *dp) 527 + { 528 + struct xfs_attr_shortform *sf; 529 + 530 + sf = (struct xfs_attr_shortform *)dp->i_afp->if_u1.if_data; 531 + return be16_to_cpu(sf->hdr.totsize); 532 + } 533 + 526 534 /* 527 535 * Add a name to the shortform attribute list structure 528 536 * This is the external routine. ··· 563 555 args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX) 564 556 return -ENOSPC; 565 557 566 - newsize = XFS_ATTR_SF_TOTSIZE(args->dp); 567 - newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen); 558 + newsize = xfs_attr_sf_totsize(args->dp); 559 + newsize += xfs_attr_sf_entsize_byname(args->namelen, args->valuelen); 568 560 569 561 forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize); 570 562 if (!forkoff)
+9 -9
fs/xfs/libxfs/xfs_attr_leaf.c
··· 684 684 sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data; 685 685 sfe = &sf->list[0]; 686 686 end = sf->hdr.count; 687 - for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), 687 + for (i = 0; i < end; sfe = xfs_attr_sf_nextentry(sfe), 688 688 base += size, i++) { 689 - size = XFS_ATTR_SF_ENTSIZE(sfe); 689 + size = xfs_attr_sf_entsize(sfe); 690 690 if (!xfs_attr_match(args, sfe->namelen, sfe->nameval, 691 691 sfe->flags)) 692 692 continue; ··· 733 733 ASSERT(0); 734 734 735 735 offset = (char *)sfe - (char *)sf; 736 - size = XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen); 736 + size = xfs_attr_sf_entsize_byname(args->namelen, args->valuelen); 737 737 xfs_idata_realloc(dp, size, XFS_ATTR_FORK); 738 738 sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data; 739 739 sfe = (struct xfs_attr_sf_entry *)((char *)sf + offset); ··· 792 792 error = xfs_attr_sf_findname(args, &sfe, &base); 793 793 if (error != -EEXIST) 794 794 return error; 795 - size = XFS_ATTR_SF_ENTSIZE(sfe); 795 + size = xfs_attr_sf_entsize(sfe); 796 796 797 797 /* 798 798 * Fix up the attribute fork data, covering the hole ··· 849 849 sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data; 850 850 sfe = &sf->list[0]; 851 851 for (i = 0; i < sf->hdr.count; 852 - sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) { 852 + sfe = xfs_attr_sf_nextentry(sfe), i++) { 853 853 if (xfs_attr_match(args, sfe->namelen, sfe->nameval, 854 854 sfe->flags)) 855 855 return -EEXIST; ··· 876 876 sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data; 877 877 sfe = &sf->list[0]; 878 878 for (i = 0; i < sf->hdr.count; 879 - sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) { 879 + sfe = xfs_attr_sf_nextentry(sfe), i++) { 880 880 if (xfs_attr_match(args, sfe->namelen, sfe->nameval, 881 881 sfe->flags)) 882 882 return xfs_attr_copy_value(args, ··· 951 951 ASSERT(error != -ENOSPC); 952 952 if (error) 953 953 goto out; 954 - sfe = XFS_ATTR_SF_NEXTENTRY(sfe); 954 + sfe = xfs_attr_sf_nextentry(sfe); 955 955 } 956 956 error = 0; 957 957 *leaf_bp = bp; ··· 992 992 return 0; 993 993 if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX) 994 994 return 0; 995 - bytes += XFS_ATTR_SF_ENTSIZE_BYNAME(name_loc->namelen, 995 + bytes += xfs_attr_sf_entsize_byname(name_loc->namelen, 996 996 be16_to_cpu(name_loc->valuelen)); 997 997 } 998 998 if ((dp->i_mount->m_flags & XFS_MOUNT_ATTR2) && ··· 1050 1050 * within the data buffer. The next entry starts after the 1051 1051 * name component, so nextentry is an acceptable test. 1052 1052 */ 1053 - next_sfep = XFS_ATTR_SF_NEXTENTRY(sfep); 1053 + next_sfep = xfs_attr_sf_nextentry(sfep); 1054 1054 if ((char *)next_sfep > endp) 1055 1055 return __this_address; 1056 1056
+19 -11
fs/xfs/libxfs/xfs_attr_sf.h
··· 26 26 unsigned char *name; /* name value, pointer into buffer */ 27 27 } xfs_attr_sf_sort_t; 28 28 29 - #define XFS_ATTR_SF_ENTSIZE_BYNAME(nlen,vlen) /* space name/value uses */ \ 30 - ((sizeof(struct xfs_attr_sf_entry) + (nlen) + (vlen))) 31 29 #define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \ 32 30 ((1 << (NBBY*(int)sizeof(uint8_t))) - 1) 33 - #define XFS_ATTR_SF_ENTSIZE(sfep) /* space an entry uses */ \ 34 - ((int)sizeof(struct xfs_attr_sf_entry) + \ 35 - (sfep)->namelen+(sfep)->valuelen) 36 - #define XFS_ATTR_SF_NEXTENTRY(sfep) /* next entry in struct */ \ 37 - ((struct xfs_attr_sf_entry *)((char *)(sfep) + \ 38 - XFS_ATTR_SF_ENTSIZE(sfep))) 39 - #define XFS_ATTR_SF_TOTSIZE(dp) /* total space in use */ \ 40 - (be16_to_cpu(((struct xfs_attr_shortform *) \ 41 - ((dp)->i_afp->if_u1.if_data))->hdr.totsize)) 31 + 32 + /* space name/value uses */ 33 + static inline int xfs_attr_sf_entsize_byname(uint8_t nlen, uint8_t vlen) 34 + { 35 + return sizeof(struct xfs_attr_sf_entry) + nlen + vlen; 36 + } 37 + 38 + /* space an entry uses */ 39 + static inline int xfs_attr_sf_entsize(struct xfs_attr_sf_entry *sfep) 40 + { 41 + return struct_size(sfep, nameval, sfep->namelen + sfep->valuelen); 42 + } 43 + 44 + /* next entry in struct */ 45 + static inline struct xfs_attr_sf_entry * 46 + xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep) 47 + { 48 + return (void *)sfep + xfs_attr_sf_entsize(sfep); 49 + } 42 50 43 51 #endif /* __XFS_ATTR_SF_H__ */
+2 -2
fs/xfs/xfs_attr_list.c
··· 96 96 */ 97 97 if (context->seen_enough) 98 98 break; 99 - sfe = XFS_ATTR_SF_NEXTENTRY(sfe); 99 + sfe = xfs_attr_sf_nextentry(sfe); 100 100 } 101 101 trace_xfs_attr_list_sf_all(context); 102 102 return 0; ··· 136 136 /* These are bytes, and both on-disk, don't endian-flip */ 137 137 sbp->valuelen = sfe->valuelen; 138 138 sbp->flags = sfe->flags; 139 - sfe = XFS_ATTR_SF_NEXTENTRY(sfe); 139 + sfe = xfs_attr_sf_nextentry(sfe); 140 140 sbp++; 141 141 nsbuf++; 142 142 }