Commit 377f16ac authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: factor out a xfs_attr_match helper

Factor out a helper that compares an on-disk attr vs the name, length and
flags specified in struct xfs_da_args.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 1d733019
...@@ -445,14 +445,21 @@ xfs_attr3_leaf_read( ...@@ -445,14 +445,21 @@ xfs_attr3_leaf_read(
* Namespace helper routines * Namespace helper routines
*========================================================================*/ *========================================================================*/
/* static bool
* If namespace bits don't match return 0. xfs_attr_match(
* If all match then return 1. struct xfs_da_args *args,
*/ uint8_t namelen,
STATIC int unsigned char *name,
xfs_attr_namesp_match(int arg_flags, int ondisk_flags) int flags)
{ {
return XFS_ATTR_NSP_ONDISK(ondisk_flags) == XFS_ATTR_NSP_ARGS_TO_ONDISK(arg_flags); if (args->namelen != namelen)
return false;
if (memcmp(args->name, name, namelen) != 0)
return false;
if (XFS_ATTR_NSP_ARGS_TO_ONDISK(args->flags) !=
XFS_ATTR_NSP_ONDISK(flags))
return false;
return true;
} }
static int static int
...@@ -678,15 +685,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) ...@@ -678,15 +685,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data; sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
sfe = &sf->list[0]; sfe = &sf->list[0];
for (i = 0; i < sf->hdr.count; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) { for (i = 0; i < sf->hdr.count; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
#ifdef DEBUG ASSERT(!xfs_attr_match(args, sfe->namelen, sfe->nameval,
if (sfe->namelen != args->namelen) sfe->flags));
continue;
if (memcmp(args->name, sfe->nameval, args->namelen) != 0)
continue;
if (!xfs_attr_namesp_match(args->flags, sfe->flags))
continue;
ASSERT(0);
#endif
} }
offset = (char *)sfe - (char *)sf; offset = (char *)sfe - (char *)sf;
...@@ -749,12 +749,8 @@ xfs_attr_shortform_remove(xfs_da_args_t *args) ...@@ -749,12 +749,8 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
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 (sfe->namelen != args->namelen) if (xfs_attr_match(args, sfe->namelen, sfe->nameval,
continue; sfe->flags))
if (memcmp(sfe->nameval, args->name, args->namelen) != 0)
continue;
if (!xfs_attr_namesp_match(args->flags, sfe->flags))
continue;
break; break;
} }
if (i == end) if (i == end)
...@@ -816,12 +812,8 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args) ...@@ -816,12 +812,8 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args)
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 (sfe->namelen != args->namelen) if (xfs_attr_match(args, sfe->namelen, sfe->nameval,
continue; sfe->flags))
if (memcmp(args->name, sfe->nameval, args->namelen) != 0)
continue;
if (!xfs_attr_namesp_match(args->flags, sfe->flags))
continue;
return -EEXIST; return -EEXIST;
} }
return -ENOATTR; return -ENOATTR;
...@@ -847,14 +839,10 @@ xfs_attr_shortform_getvalue( ...@@ -847,14 +839,10 @@ xfs_attr_shortform_getvalue(
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 (sfe->namelen != args->namelen) if (xfs_attr_match(args, sfe->namelen, sfe->nameval,
continue; sfe->flags))
if (memcmp(args->name, sfe->nameval, args->namelen) != 0) return xfs_attr_copy_value(args,
continue; &sfe->nameval[args->namelen], sfe->valuelen);
if (!xfs_attr_namesp_match(args->flags, sfe->flags))
continue;
return xfs_attr_copy_value(args, &sfe->nameval[args->namelen],
sfe->valuelen);
} }
return -ENOATTR; return -ENOATTR;
} }
...@@ -2409,23 +2397,15 @@ xfs_attr3_leaf_lookup_int( ...@@ -2409,23 +2397,15 @@ xfs_attr3_leaf_lookup_int(
} }
if (entry->flags & XFS_ATTR_LOCAL) { if (entry->flags & XFS_ATTR_LOCAL) {
name_loc = xfs_attr3_leaf_name_local(leaf, probe); name_loc = xfs_attr3_leaf_name_local(leaf, probe);
if (name_loc->namelen != args->namelen) if (!xfs_attr_match(args, name_loc->namelen,
continue; name_loc->nameval, entry->flags))
if (memcmp(args->name, name_loc->nameval,
args->namelen) != 0)
continue;
if (!xfs_attr_namesp_match(args->flags, entry->flags))
continue; continue;
args->index = probe; args->index = probe;
return -EEXIST; return -EEXIST;
} else { } else {
name_rmt = xfs_attr3_leaf_name_remote(leaf, probe); name_rmt = xfs_attr3_leaf_name_remote(leaf, probe);
if (name_rmt->namelen != args->namelen) if (!xfs_attr_match(args, name_rmt->namelen,
continue; name_rmt->name, entry->flags))
if (memcmp(args->name, name_rmt->name,
args->namelen) != 0)
continue;
if (!xfs_attr_namesp_match(args->flags, entry->flags))
continue; continue;
args->index = probe; args->index = probe;
args->rmtvaluelen = be32_to_cpu(name_rmt->valuelen); args->rmtvaluelen = be32_to_cpu(name_rmt->valuelen);
......
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