diff options
| author | Christoph Hellwig <hch@lst.de> | 2014-05-13 02:34:43 -0400 |
|---|---|---|
| committer | Dave Chinner <david@fromorbit.com> | 2014-05-13 02:34:43 -0400 |
| commit | 67fd718f30108db320ffc4bef205137b69e60d3a (patch) | |
| tree | b22627d4c80f4634eab38ecd53552a845435cb57 | |
| parent | 1bc426a76b1a8ecf00d9a3ec8e9765a21ab4082f (diff) | |
xfs: simplify attr name setup
Replace xfs_attr_name_to_xname with a new xfs_attr_args_init helper that
sets up the basic da_args structure without using a temporary xfs_name
structure.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
| -rw-r--r-- | fs/xfs/xfs_attr.c | 74 |
1 files changed, 29 insertions, 45 deletions
diff --git a/fs/xfs/xfs_attr.c b/fs/xfs/xfs_attr.c index a96e27bfc58b..120862139a63 100644 --- a/fs/xfs/xfs_attr.c +++ b/fs/xfs/xfs_attr.c | |||
| @@ -77,17 +77,26 @@ STATIC int xfs_attr_refillstate(xfs_da_state_t *state); | |||
| 77 | 77 | ||
| 78 | 78 | ||
| 79 | STATIC int | 79 | STATIC int |
| 80 | xfs_attr_name_to_xname( | 80 | xfs_attr_args_init( |
| 81 | struct xfs_name *xname, | 81 | struct xfs_da_args *args, |
| 82 | const unsigned char *aname) | 82 | struct xfs_inode *dp, |
| 83 | const unsigned char *name, | ||
| 84 | int flags) | ||
| 83 | { | 85 | { |
| 84 | if (!aname) | 86 | |
| 87 | if (!name) | ||
| 85 | return EINVAL; | 88 | return EINVAL; |
| 86 | xname->name = aname; | 89 | |
| 87 | xname->len = strlen((char *)aname); | 90 | memset(args, 0, sizeof(*args)); |
| 88 | if (xname->len >= MAXNAMELEN) | 91 | args->whichfork = XFS_ATTR_FORK; |
| 92 | args->dp = dp; | ||
| 93 | args->flags = flags; | ||
| 94 | args->name = name; | ||
| 95 | args->namelen = strlen((const char *)name); | ||
| 96 | if (args->namelen >= MAXNAMELEN) | ||
| 89 | return EFAULT; /* match IRIX behaviour */ | 97 | return EFAULT; /* match IRIX behaviour */ |
| 90 | 98 | ||
| 99 | args->hashval = xfs_da_hashname(args->name, args->namelen); | ||
| 91 | return 0; | 100 | return 0; |
| 92 | } | 101 | } |
| 93 | 102 | ||
| @@ -115,7 +124,6 @@ xfs_attr_get( | |||
| 115 | int flags) | 124 | int flags) |
| 116 | { | 125 | { |
| 117 | struct xfs_da_args args; | 126 | struct xfs_da_args args; |
| 118 | struct xfs_name xname; | ||
| 119 | uint lock_mode; | 127 | uint lock_mode; |
| 120 | int error; | 128 | int error; |
| 121 | 129 | ||
| @@ -127,19 +135,12 @@ xfs_attr_get( | |||
| 127 | if (!xfs_inode_hasattr(ip)) | 135 | if (!xfs_inode_hasattr(ip)) |
| 128 | return ENOATTR; | 136 | return ENOATTR; |
| 129 | 137 | ||
| 130 | error = xfs_attr_name_to_xname(&xname, name); | 138 | error = xfs_attr_args_init(&args, ip, name, flags); |
| 131 | if (error) | 139 | if (error) |
| 132 | return error; | 140 | return error; |
| 133 | 141 | ||
| 134 | memset(&args, 0, sizeof(args)); | ||
| 135 | args.name = xname.name; | ||
| 136 | args.namelen = xname.len; | ||
| 137 | args.value = value; | 142 | args.value = value; |
| 138 | args.valuelen = *valuelenp; | 143 | args.valuelen = *valuelenp; |
| 139 | args.flags = flags; | ||
| 140 | args.hashval = xfs_da_hashname(args.name, args.namelen); | ||
| 141 | args.dp = ip; | ||
| 142 | args.whichfork = XFS_ATTR_FORK; | ||
| 143 | 144 | ||
| 144 | lock_mode = xfs_ilock_attr_map_shared(ip); | 145 | lock_mode = xfs_ilock_attr_map_shared(ip); |
| 145 | if (!xfs_inode_hasattr(ip)) | 146 | if (!xfs_inode_hasattr(ip)) |
| @@ -208,7 +209,6 @@ xfs_attr_set( | |||
| 208 | struct xfs_da_args args; | 209 | struct xfs_da_args args; |
| 209 | struct xfs_bmap_free flist; | 210 | struct xfs_bmap_free flist; |
| 210 | struct xfs_trans_res tres; | 211 | struct xfs_trans_res tres; |
| 211 | struct xfs_name xname; | ||
| 212 | xfs_fsblock_t firstblock; | 212 | xfs_fsblock_t firstblock; |
| 213 | int rsvd = (flags & ATTR_ROOT) != 0; | 213 | int rsvd = (flags & ATTR_ROOT) != 0; |
| 214 | int error, err2, committed, local; | 214 | int error, err2, committed, local; |
| @@ -218,10 +218,19 @@ xfs_attr_set( | |||
| 218 | if (XFS_FORCED_SHUTDOWN(dp->i_mount)) | 218 | if (XFS_FORCED_SHUTDOWN(dp->i_mount)) |
| 219 | return EIO; | 219 | return EIO; |
| 220 | 220 | ||
| 221 | error = xfs_attr_name_to_xname(&xname, name); | 221 | error = xfs_attr_args_init(&args, dp, name, flags); |
| 222 | if (error) | 222 | if (error) |
| 223 | return error; | 223 | return error; |
| 224 | 224 | ||
| 225 | args.value = value; | ||
| 226 | args.valuelen = valuelen; | ||
| 227 | args.firstblock = &firstblock; | ||
| 228 | args.flist = &flist; | ||
| 229 | args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; | ||
| 230 | |||
| 231 | /* Size is now blocks for attribute data */ | ||
| 232 | args.total = xfs_attr_calc_size(dp, args.namelen, valuelen, &local); | ||
| 233 | |||
| 225 | error = xfs_qm_dqattach(dp, 0); | 234 | error = xfs_qm_dqattach(dp, 0); |
| 226 | if (error) | 235 | if (error) |
| 227 | return error; | 236 | return error; |
| @@ -232,29 +241,13 @@ xfs_attr_set( | |||
| 232 | */ | 241 | */ |
| 233 | if (XFS_IFORK_Q(dp) == 0) { | 242 | if (XFS_IFORK_Q(dp) == 0) { |
| 234 | int sf_size = sizeof(xfs_attr_sf_hdr_t) + | 243 | int sf_size = sizeof(xfs_attr_sf_hdr_t) + |
| 235 | XFS_ATTR_SF_ENTSIZE_BYNAME(xname.len, valuelen); | 244 | XFS_ATTR_SF_ENTSIZE_BYNAME(args.namelen, valuelen); |
| 236 | 245 | ||
| 237 | error = xfs_bmap_add_attrfork(dp, sf_size, rsvd); | 246 | error = xfs_bmap_add_attrfork(dp, sf_size, rsvd); |
| 238 | if (error) | 247 | if (error) |
| 239 | return error; | 248 | return error; |
| 240 | } | 249 | } |
| 241 | 250 | ||
| 242 | memset(&args, 0, sizeof(args)); | ||
| 243 | args.name = xname.name; | ||
| 244 | args.namelen = xname.len; | ||
| 245 | args.value = value; | ||
| 246 | args.valuelen = valuelen; | ||
| 247 | args.flags = flags; | ||
| 248 | args.hashval = xfs_da_hashname(args.name, args.namelen); | ||
| 249 | args.dp = dp; | ||
| 250 | args.firstblock = &firstblock; | ||
| 251 | args.flist = &flist; | ||
| 252 | args.whichfork = XFS_ATTR_FORK; | ||
| 253 | args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; | ||
| 254 | |||
| 255 | /* Size is now blocks for attribute data */ | ||
| 256 | args.total = xfs_attr_calc_size(dp, xname.len, valuelen, &local); | ||
| 257 | |||
| 258 | /* | 251 | /* |
| 259 | * Start our first transaction of the day. | 252 | * Start our first transaction of the day. |
| 260 | * | 253 | * |
| @@ -425,7 +418,6 @@ xfs_attr_remove( | |||
| 425 | struct xfs_mount *mp = dp->i_mount; | 418 | struct xfs_mount *mp = dp->i_mount; |
| 426 | struct xfs_da_args args; | 419 | struct xfs_da_args args; |
| 427 | struct xfs_bmap_free flist; | 420 | struct xfs_bmap_free flist; |
| 428 | struct xfs_name xname; | ||
| 429 | xfs_fsblock_t firstblock; | 421 | xfs_fsblock_t firstblock; |
| 430 | int error; | 422 | int error; |
| 431 | 423 | ||
| @@ -437,20 +429,12 @@ xfs_attr_remove( | |||
| 437 | if (!xfs_inode_hasattr(dp)) | 429 | if (!xfs_inode_hasattr(dp)) |
| 438 | return ENOATTR; | 430 | return ENOATTR; |
| 439 | 431 | ||
| 440 | error = xfs_attr_name_to_xname(&xname, name); | 432 | error = xfs_attr_args_init(&args, dp, name, flags); |
| 441 | if (error) | 433 | if (error) |
| 442 | return error; | 434 | return error; |
| 443 | 435 | ||
| 444 | memset(&args, 0, sizeof(args)); | ||
| 445 | args.name = xname.name; | ||
| 446 | args.namelen = xname.len; | ||
| 447 | args.flags = flags; | ||
| 448 | args.hashval = xfs_da_hashname(args.name, args.namelen); | ||
| 449 | args.dp = dp; | ||
| 450 | args.firstblock = &firstblock; | 436 | args.firstblock = &firstblock; |
| 451 | args.flist = &flist; | 437 | args.flist = &flist; |
| 452 | args.total = 0; | ||
| 453 | args.whichfork = XFS_ATTR_FORK; | ||
| 454 | 438 | ||
| 455 | /* | 439 | /* |
| 456 | * we have no control over the attribute names that userspace passes us | 440 | * we have no control over the attribute names that userspace passes us |
