Commit e01b7eed authored by Carlos Maiolino's avatar Carlos Maiolino Committed by Darrick J. Wong

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: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: default avatarCarlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent c418dbc9
...@@ -428,7 +428,7 @@ xfs_attr_set( ...@@ -428,7 +428,7 @@ xfs_attr_set(
*/ */
if (XFS_IFORK_Q(dp) == 0) { if (XFS_IFORK_Q(dp) == 0) {
int sf_size = sizeof(struct xfs_attr_sf_hdr) + int sf_size = sizeof(struct xfs_attr_sf_hdr) +
XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, xfs_attr_sf_entsize_byname(args->namelen,
args->valuelen); args->valuelen);
error = xfs_bmap_add_attrfork(dp, sf_size, rsvd); error = xfs_bmap_add_attrfork(dp, sf_size, rsvd);
...@@ -523,6 +523,14 @@ xfs_attr_set( ...@@ -523,6 +523,14 @@ xfs_attr_set(
* External routines when attribute list is inside the inode * External routines when attribute list is inside the inode
*========================================================================*/ *========================================================================*/
static inline int xfs_attr_sf_totsize(struct xfs_inode *dp)
{
struct xfs_attr_shortform *sf;
sf = (struct xfs_attr_shortform *)dp->i_afp->if_u1.if_data;
return be16_to_cpu(sf->hdr.totsize);
}
/* /*
* Add a name to the shortform attribute list structure * Add a name to the shortform attribute list structure
* This is the external routine. * This is the external routine.
...@@ -555,8 +563,8 @@ xfs_attr_shortform_addname(xfs_da_args_t *args) ...@@ -555,8 +563,8 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX) args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
return -ENOSPC; return -ENOSPC;
newsize = XFS_ATTR_SF_TOTSIZE(args->dp); newsize = xfs_attr_sf_totsize(args->dp);
newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen); newsize += xfs_attr_sf_entsize_byname(args->namelen, args->valuelen);
forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize); forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
if (!forkoff) if (!forkoff)
......
...@@ -684,9 +684,9 @@ xfs_attr_sf_findname( ...@@ -684,9 +684,9 @@ xfs_attr_sf_findname(
sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data; sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data;
sfe = &sf->list[0]; sfe = &sf->list[0];
end = sf->hdr.count; end = sf->hdr.count;
for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), for (i = 0; i < end; sfe = xfs_attr_sf_nextentry(sfe),
base += size, i++) { base += size, i++) {
size = XFS_ATTR_SF_ENTSIZE(sfe); size = xfs_attr_sf_entsize(sfe);
if (!xfs_attr_match(args, sfe->namelen, sfe->nameval, if (!xfs_attr_match(args, sfe->namelen, sfe->nameval,
sfe->flags)) sfe->flags))
continue; continue;
...@@ -733,7 +733,7 @@ xfs_attr_shortform_add( ...@@ -733,7 +733,7 @@ xfs_attr_shortform_add(
ASSERT(0); ASSERT(0);
offset = (char *)sfe - (char *)sf; offset = (char *)sfe - (char *)sf;
size = XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen); size = xfs_attr_sf_entsize_byname(args->namelen, args->valuelen);
xfs_idata_realloc(dp, size, XFS_ATTR_FORK); xfs_idata_realloc(dp, size, XFS_ATTR_FORK);
sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data; sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data;
sfe = (struct xfs_attr_sf_entry *)((char *)sf + offset); sfe = (struct xfs_attr_sf_entry *)((char *)sf + offset);
...@@ -792,7 +792,7 @@ xfs_attr_shortform_remove( ...@@ -792,7 +792,7 @@ xfs_attr_shortform_remove(
error = xfs_attr_sf_findname(args, &sfe, &base); error = xfs_attr_sf_findname(args, &sfe, &base);
if (error != -EEXIST) if (error != -EEXIST)
return error; return error;
size = XFS_ATTR_SF_ENTSIZE(sfe); size = xfs_attr_sf_entsize(sfe);
/* /*
* Fix up the attribute fork data, covering the hole * Fix up the attribute fork data, covering the hole
...@@ -849,7 +849,7 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args) ...@@ -849,7 +849,7 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args)
sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data; sf = (struct xfs_attr_shortform *)ifp->if_u1.if_data;
sfe = &sf->list[0]; sfe = &sf->list[0];
for (i = 0; i < sf->hdr.count; for (i = 0; i < sf->hdr.count;
sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) { sfe = xfs_attr_sf_nextentry(sfe), i++) {
if (xfs_attr_match(args, sfe->namelen, sfe->nameval, if (xfs_attr_match(args, sfe->namelen, sfe->nameval,
sfe->flags)) sfe->flags))
return -EEXIST; return -EEXIST;
...@@ -876,7 +876,7 @@ xfs_attr_shortform_getvalue( ...@@ -876,7 +876,7 @@ xfs_attr_shortform_getvalue(
sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data; sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data;
sfe = &sf->list[0]; sfe = &sf->list[0];
for (i = 0; i < sf->hdr.count; for (i = 0; i < sf->hdr.count;
sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) { sfe = xfs_attr_sf_nextentry(sfe), i++) {
if (xfs_attr_match(args, sfe->namelen, sfe->nameval, if (xfs_attr_match(args, sfe->namelen, sfe->nameval,
sfe->flags)) sfe->flags))
return xfs_attr_copy_value(args, return xfs_attr_copy_value(args,
...@@ -951,7 +951,7 @@ xfs_attr_shortform_to_leaf( ...@@ -951,7 +951,7 @@ xfs_attr_shortform_to_leaf(
ASSERT(error != -ENOSPC); ASSERT(error != -ENOSPC);
if (error) if (error)
goto out; goto out;
sfe = XFS_ATTR_SF_NEXTENTRY(sfe); sfe = xfs_attr_sf_nextentry(sfe);
} }
error = 0; error = 0;
*leaf_bp = bp; *leaf_bp = bp;
...@@ -992,7 +992,7 @@ xfs_attr_shortform_allfit( ...@@ -992,7 +992,7 @@ xfs_attr_shortform_allfit(
return 0; return 0;
if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX) if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX)
return 0; return 0;
bytes += XFS_ATTR_SF_ENTSIZE_BYNAME(name_loc->namelen, bytes += xfs_attr_sf_entsize_byname(name_loc->namelen,
be16_to_cpu(name_loc->valuelen)); be16_to_cpu(name_loc->valuelen));
} }
if ((dp->i_mount->m_flags & XFS_MOUNT_ATTR2) && if ((dp->i_mount->m_flags & XFS_MOUNT_ATTR2) &&
...@@ -1050,7 +1050,7 @@ xfs_attr_shortform_verify( ...@@ -1050,7 +1050,7 @@ xfs_attr_shortform_verify(
* within the data buffer. The next entry starts after the * within the data buffer. The next entry starts after the
* name component, so nextentry is an acceptable test. * name component, so nextentry is an acceptable test.
*/ */
next_sfep = XFS_ATTR_SF_NEXTENTRY(sfep); next_sfep = xfs_attr_sf_nextentry(sfep);
if ((char *)next_sfep > endp) if ((char *)next_sfep > endp)
return __this_address; return __this_address;
......
...@@ -26,18 +26,26 @@ typedef struct xfs_attr_sf_sort { ...@@ -26,18 +26,26 @@ typedef struct xfs_attr_sf_sort {
unsigned char *name; /* name value, pointer into buffer */ unsigned char *name; /* name value, pointer into buffer */
} xfs_attr_sf_sort_t; } xfs_attr_sf_sort_t;
#define XFS_ATTR_SF_ENTSIZE_BYNAME(nlen,vlen) /* space name/value uses */ \
((sizeof(struct xfs_attr_sf_entry) + (nlen) + (vlen)))
#define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \ #define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \
((1 << (NBBY*(int)sizeof(uint8_t))) - 1) ((1 << (NBBY*(int)sizeof(uint8_t))) - 1)
#define XFS_ATTR_SF_ENTSIZE(sfep) /* space an entry uses */ \
((int)sizeof(struct xfs_attr_sf_entry) + \ /* space name/value uses */
(sfep)->namelen+(sfep)->valuelen) static inline int xfs_attr_sf_entsize_byname(uint8_t nlen, uint8_t vlen)
#define XFS_ATTR_SF_NEXTENTRY(sfep) /* next entry in struct */ \ {
((struct xfs_attr_sf_entry *)((char *)(sfep) + \ return sizeof(struct xfs_attr_sf_entry) + nlen + vlen;
XFS_ATTR_SF_ENTSIZE(sfep))) }
#define XFS_ATTR_SF_TOTSIZE(dp) /* total space in use */ \
(be16_to_cpu(((struct xfs_attr_shortform *) \ /* space an entry uses */
((dp)->i_afp->if_u1.if_data))->hdr.totsize)) static inline int xfs_attr_sf_entsize(struct xfs_attr_sf_entry *sfep)
{
return struct_size(sfep, nameval, sfep->namelen + sfep->valuelen);
}
/* next entry in struct */
static inline struct xfs_attr_sf_entry *
xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep)
{
return (void *)sfep + xfs_attr_sf_entsize(sfep);
}
#endif /* __XFS_ATTR_SF_H__ */ #endif /* __XFS_ATTR_SF_H__ */
...@@ -96,7 +96,7 @@ xfs_attr_shortform_list( ...@@ -96,7 +96,7 @@ xfs_attr_shortform_list(
*/ */
if (context->seen_enough) if (context->seen_enough)
break; break;
sfe = XFS_ATTR_SF_NEXTENTRY(sfe); sfe = xfs_attr_sf_nextentry(sfe);
} }
trace_xfs_attr_list_sf_all(context); trace_xfs_attr_list_sf_all(context);
return 0; return 0;
...@@ -136,7 +136,7 @@ xfs_attr_shortform_list( ...@@ -136,7 +136,7 @@ xfs_attr_shortform_list(
/* These are bytes, and both on-disk, don't endian-flip */ /* These are bytes, and both on-disk, don't endian-flip */
sbp->valuelen = sfe->valuelen; sbp->valuelen = sfe->valuelen;
sbp->flags = sfe->flags; sbp->flags = sfe->flags;
sfe = XFS_ATTR_SF_NEXTENTRY(sfe); sfe = xfs_attr_sf_nextentry(sfe);
sbp++; sbp++;
nsbuf++; nsbuf++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment