pxa2xx_spi: register earlier
[linux-2.6/mini2440.git] / fs / xfs / xfs_attr.c
blob4ece1906bd41c0d801f8b66a41efb48bd3bcad6d
1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "xfs.h"
20 #include "xfs_fs.h"
21 #include "xfs_types.h"
22 #include "xfs_bit.h"
23 #include "xfs_log.h"
24 #include "xfs_inum.h"
25 #include "xfs_trans.h"
26 #include "xfs_sb.h"
27 #include "xfs_ag.h"
28 #include "xfs_dir2.h"
29 #include "xfs_dmapi.h"
30 #include "xfs_mount.h"
31 #include "xfs_da_btree.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_ialloc_btree.h"
35 #include "xfs_dir2_sf.h"
36 #include "xfs_attr_sf.h"
37 #include "xfs_dinode.h"
38 #include "xfs_inode.h"
39 #include "xfs_alloc.h"
40 #include "xfs_btree.h"
41 #include "xfs_inode_item.h"
42 #include "xfs_bmap.h"
43 #include "xfs_attr.h"
44 #include "xfs_attr_leaf.h"
45 #include "xfs_error.h"
46 #include "xfs_quota.h"
47 #include "xfs_trans_space.h"
48 #include "xfs_rw.h"
49 #include "xfs_vnodeops.h"
52 * xfs_attr.c
54 * Provide the external interfaces to manage attribute lists.
57 /*========================================================================
58 * Function prototypes for the kernel.
59 *========================================================================*/
62 * Internal routines when attribute list fits inside the inode.
64 STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
67 * Internal routines when attribute list is one block.
69 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
70 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
71 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
72 STATIC int xfs_attr_leaf_list(xfs_attr_list_context_t *context);
75 * Internal routines when attribute list is more than one block.
77 STATIC int xfs_attr_node_get(xfs_da_args_t *args);
78 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
79 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
80 STATIC int xfs_attr_node_list(xfs_attr_list_context_t *context);
81 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
82 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
85 * Routines to manipulate out-of-line attribute values.
87 STATIC int xfs_attr_rmtval_set(xfs_da_args_t *args);
88 STATIC int xfs_attr_rmtval_remove(xfs_da_args_t *args);
90 #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
92 #if defined(XFS_ATTR_TRACE)
93 ktrace_t *xfs_attr_trace_buf;
94 #endif
96 STATIC int
97 xfs_attr_name_to_xname(
98 struct xfs_name *xname,
99 const char *aname)
101 if (!aname)
102 return EINVAL;
103 xname->name = aname;
104 xname->len = strlen(aname);
105 if (xname->len >= MAXNAMELEN)
106 return EFAULT; /* match IRIX behaviour */
108 return 0;
111 STATIC int
112 xfs_inode_hasattr(
113 struct xfs_inode *ip)
115 if (!XFS_IFORK_Q(ip) ||
116 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
117 ip->i_d.di_anextents == 0))
118 return 0;
119 return 1;
122 /*========================================================================
123 * Overall external interface routines.
124 *========================================================================*/
127 xfs_attr_fetch(xfs_inode_t *ip, struct xfs_name *name,
128 char *value, int *valuelenp, int flags)
130 xfs_da_args_t args;
131 int error;
133 if (!xfs_inode_hasattr(ip))
134 return ENOATTR;
137 * Fill in the arg structure for this request.
139 memset((char *)&args, 0, sizeof(args));
140 args.name = name->name;
141 args.namelen = name->len;
142 args.value = value;
143 args.valuelen = *valuelenp;
144 args.flags = flags;
145 args.hashval = xfs_da_hashname(args.name, args.namelen);
146 args.dp = ip;
147 args.whichfork = XFS_ATTR_FORK;
150 * Decide on what work routines to call based on the inode size.
152 if (ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
153 error = xfs_attr_shortform_getvalue(&args);
154 } else if (xfs_bmap_one_block(ip, XFS_ATTR_FORK)) {
155 error = xfs_attr_leaf_get(&args);
156 } else {
157 error = xfs_attr_node_get(&args);
161 * Return the number of bytes in the value to the caller.
163 *valuelenp = args.valuelen;
165 if (error == EEXIST)
166 error = 0;
167 return(error);
171 xfs_attr_get(
172 xfs_inode_t *ip,
173 const char *name,
174 char *value,
175 int *valuelenp,
176 int flags)
178 int error;
179 struct xfs_name xname;
181 XFS_STATS_INC(xs_attr_get);
183 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
184 return(EIO);
186 error = xfs_attr_name_to_xname(&xname, name);
187 if (error)
188 return error;
190 xfs_ilock(ip, XFS_ILOCK_SHARED);
191 error = xfs_attr_fetch(ip, &xname, value, valuelenp, flags);
192 xfs_iunlock(ip, XFS_ILOCK_SHARED);
193 return(error);
197 * Calculate how many blocks we need for the new attribute,
200 xfs_attr_calc_size(
201 struct xfs_inode *ip,
202 int namelen,
203 int valuelen,
204 int *local)
206 struct xfs_mount *mp = ip->i_mount;
207 int size;
208 int nblks;
211 * Determine space new attribute will use, and if it would be
212 * "local" or "remote" (note: local != inline).
214 size = xfs_attr_leaf_newentsize(namelen, valuelen,
215 mp->m_sb.sb_blocksize, local);
217 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
218 if (*local) {
219 if (size > (mp->m_sb.sb_blocksize >> 1)) {
220 /* Double split possible */
221 nblks *= 2;
223 } else {
225 * Out of line attribute, cannot double split, but
226 * make room for the attribute value itself.
228 uint dblocks = XFS_B_TO_FSB(mp, valuelen);
229 nblks += dblocks;
230 nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
233 return nblks;
236 STATIC int
237 xfs_attr_set_int(xfs_inode_t *dp, struct xfs_name *name,
238 char *value, int valuelen, int flags)
240 xfs_da_args_t args;
241 xfs_fsblock_t firstblock;
242 xfs_bmap_free_t flist;
243 int error, err2, committed;
244 xfs_mount_t *mp = dp->i_mount;
245 int rsvd = (flags & ATTR_ROOT) != 0;
246 int local;
249 * Attach the dquots to the inode.
251 error = xfs_qm_dqattach(dp, 0);
252 if (error)
253 return error;
256 * If the inode doesn't have an attribute fork, add one.
257 * (inode must not be locked when we call this routine)
259 if (XFS_IFORK_Q(dp) == 0) {
260 int sf_size = sizeof(xfs_attr_sf_hdr_t) +
261 XFS_ATTR_SF_ENTSIZE_BYNAME(name->len, valuelen);
263 if ((error = xfs_bmap_add_attrfork(dp, sf_size, rsvd)))
264 return(error);
268 * Fill in the arg structure for this request.
270 memset((char *)&args, 0, sizeof(args));
271 args.name = name->name;
272 args.namelen = name->len;
273 args.value = value;
274 args.valuelen = valuelen;
275 args.flags = flags;
276 args.hashval = xfs_da_hashname(args.name, args.namelen);
277 args.dp = dp;
278 args.firstblock = &firstblock;
279 args.flist = &flist;
280 args.whichfork = XFS_ATTR_FORK;
281 args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
283 /* Size is now blocks for attribute data */
284 args.total = xfs_attr_calc_size(dp, name->len, valuelen, &local);
287 * Start our first transaction of the day.
289 * All future transactions during this code must be "chained" off
290 * this one via the trans_dup() call. All transactions will contain
291 * the inode, and the inode will always be marked with trans_ihold().
292 * Since the inode will be locked in all transactions, we must log
293 * the inode in every transaction to let it float upward through
294 * the log.
296 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
299 * Root fork attributes can use reserved data blocks for this
300 * operation if necessary
303 if (rsvd)
304 args.trans->t_flags |= XFS_TRANS_RESERVE;
306 if ((error = xfs_trans_reserve(args.trans, args.total,
307 XFS_ATTRSET_LOG_RES(mp, args.total), 0,
308 XFS_TRANS_PERM_LOG_RES, XFS_ATTRSET_LOG_COUNT))) {
309 xfs_trans_cancel(args.trans, 0);
310 return(error);
312 xfs_ilock(dp, XFS_ILOCK_EXCL);
314 error = xfs_trans_reserve_quota_nblks(args.trans, dp, args.total, 0,
315 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
316 XFS_QMOPT_RES_REGBLKS);
317 if (error) {
318 xfs_iunlock(dp, XFS_ILOCK_EXCL);
319 xfs_trans_cancel(args.trans, XFS_TRANS_RELEASE_LOG_RES);
320 return (error);
323 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
324 xfs_trans_ihold(args.trans, dp);
327 * If the attribute list is non-existent or a shortform list,
328 * upgrade it to a single-leaf-block attribute list.
330 if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
331 ((dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS) &&
332 (dp->i_d.di_anextents == 0))) {
335 * Build initial attribute list (if required).
337 if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
338 xfs_attr_shortform_create(&args);
341 * Try to add the attr to the attribute list in
342 * the inode.
344 error = xfs_attr_shortform_addname(&args);
345 if (error != ENOSPC) {
347 * Commit the shortform mods, and we're done.
348 * NOTE: this is also the error path (EEXIST, etc).
350 ASSERT(args.trans != NULL);
353 * If this is a synchronous mount, make sure that
354 * the transaction goes to disk before returning
355 * to the user.
357 if (mp->m_flags & XFS_MOUNT_WSYNC) {
358 xfs_trans_set_sync(args.trans);
360 err2 = xfs_trans_commit(args.trans,
361 XFS_TRANS_RELEASE_LOG_RES);
362 xfs_iunlock(dp, XFS_ILOCK_EXCL);
365 * Hit the inode change time.
367 if (!error && (flags & ATTR_KERNOTIME) == 0) {
368 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
370 return(error == 0 ? err2 : error);
374 * It won't fit in the shortform, transform to a leaf block.
375 * GROT: another possible req'mt for a double-split btree op.
377 xfs_bmap_init(args.flist, args.firstblock);
378 error = xfs_attr_shortform_to_leaf(&args);
379 if (!error) {
380 error = xfs_bmap_finish(&args.trans, args.flist,
381 &committed);
383 if (error) {
384 ASSERT(committed);
385 args.trans = NULL;
386 xfs_bmap_cancel(&flist);
387 goto out;
391 * bmap_finish() may have committed the last trans and started
392 * a new one. We need the inode to be in all transactions.
394 if (committed) {
395 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
396 xfs_trans_ihold(args.trans, dp);
400 * Commit the leaf transformation. We'll need another (linked)
401 * transaction to add the new attribute to the leaf.
404 error = xfs_trans_roll(&args.trans, dp);
405 if (error)
406 goto out;
410 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
411 error = xfs_attr_leaf_addname(&args);
412 } else {
413 error = xfs_attr_node_addname(&args);
415 if (error) {
416 goto out;
420 * If this is a synchronous mount, make sure that the
421 * transaction goes to disk before returning to the user.
423 if (mp->m_flags & XFS_MOUNT_WSYNC) {
424 xfs_trans_set_sync(args.trans);
428 * Commit the last in the sequence of transactions.
430 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
431 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES);
432 xfs_iunlock(dp, XFS_ILOCK_EXCL);
435 * Hit the inode change time.
437 if (!error && (flags & ATTR_KERNOTIME) == 0) {
438 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
441 return(error);
443 out:
444 if (args.trans)
445 xfs_trans_cancel(args.trans,
446 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
447 xfs_iunlock(dp, XFS_ILOCK_EXCL);
448 return(error);
452 xfs_attr_set(
453 xfs_inode_t *dp,
454 const char *name,
455 char *value,
456 int valuelen,
457 int flags)
459 int error;
460 struct xfs_name xname;
462 XFS_STATS_INC(xs_attr_set);
464 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
465 return (EIO);
467 error = xfs_attr_name_to_xname(&xname, name);
468 if (error)
469 return error;
471 return xfs_attr_set_int(dp, &xname, value, valuelen, flags);
475 * Generic handler routine to remove a name from an attribute list.
476 * Transitions attribute list from Btree to shortform as necessary.
478 STATIC int
479 xfs_attr_remove_int(xfs_inode_t *dp, struct xfs_name *name, int flags)
481 xfs_da_args_t args;
482 xfs_fsblock_t firstblock;
483 xfs_bmap_free_t flist;
484 int error;
485 xfs_mount_t *mp = dp->i_mount;
488 * Fill in the arg structure for this request.
490 memset((char *)&args, 0, sizeof(args));
491 args.name = name->name;
492 args.namelen = name->len;
493 args.flags = flags;
494 args.hashval = xfs_da_hashname(args.name, args.namelen);
495 args.dp = dp;
496 args.firstblock = &firstblock;
497 args.flist = &flist;
498 args.total = 0;
499 args.whichfork = XFS_ATTR_FORK;
502 * Attach the dquots to the inode.
504 error = xfs_qm_dqattach(dp, 0);
505 if (error)
506 return error;
509 * Start our first transaction of the day.
511 * All future transactions during this code must be "chained" off
512 * this one via the trans_dup() call. All transactions will contain
513 * the inode, and the inode will always be marked with trans_ihold().
514 * Since the inode will be locked in all transactions, we must log
515 * the inode in every transaction to let it float upward through
516 * the log.
518 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
521 * Root fork attributes can use reserved data blocks for this
522 * operation if necessary
525 if (flags & ATTR_ROOT)
526 args.trans->t_flags |= XFS_TRANS_RESERVE;
528 if ((error = xfs_trans_reserve(args.trans,
529 XFS_ATTRRM_SPACE_RES(mp),
530 XFS_ATTRRM_LOG_RES(mp),
531 0, XFS_TRANS_PERM_LOG_RES,
532 XFS_ATTRRM_LOG_COUNT))) {
533 xfs_trans_cancel(args.trans, 0);
534 return(error);
537 xfs_ilock(dp, XFS_ILOCK_EXCL);
539 * No need to make quota reservations here. We expect to release some
540 * blocks not allocate in the common case.
542 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
543 xfs_trans_ihold(args.trans, dp);
546 * Decide on what work routines to call based on the inode size.
548 if (!xfs_inode_hasattr(dp)) {
549 error = XFS_ERROR(ENOATTR);
550 goto out;
552 if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
553 ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
554 error = xfs_attr_shortform_remove(&args);
555 if (error) {
556 goto out;
558 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
559 error = xfs_attr_leaf_removename(&args);
560 } else {
561 error = xfs_attr_node_removename(&args);
563 if (error) {
564 goto out;
568 * If this is a synchronous mount, make sure that the
569 * transaction goes to disk before returning to the user.
571 if (mp->m_flags & XFS_MOUNT_WSYNC) {
572 xfs_trans_set_sync(args.trans);
576 * Commit the last in the sequence of transactions.
578 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
579 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES);
580 xfs_iunlock(dp, XFS_ILOCK_EXCL);
583 * Hit the inode change time.
585 if (!error && (flags & ATTR_KERNOTIME) == 0) {
586 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
589 return(error);
591 out:
592 if (args.trans)
593 xfs_trans_cancel(args.trans,
594 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
595 xfs_iunlock(dp, XFS_ILOCK_EXCL);
596 return(error);
600 xfs_attr_remove(
601 xfs_inode_t *dp,
602 const char *name,
603 int flags)
605 int error;
606 struct xfs_name xname;
608 XFS_STATS_INC(xs_attr_remove);
610 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
611 return (EIO);
613 error = xfs_attr_name_to_xname(&xname, name);
614 if (error)
615 return error;
617 xfs_ilock(dp, XFS_ILOCK_SHARED);
618 if (!xfs_inode_hasattr(dp)) {
619 xfs_iunlock(dp, XFS_ILOCK_SHARED);
620 return XFS_ERROR(ENOATTR);
622 xfs_iunlock(dp, XFS_ILOCK_SHARED);
624 return xfs_attr_remove_int(dp, &xname, flags);
628 xfs_attr_list_int(xfs_attr_list_context_t *context)
630 int error;
631 xfs_inode_t *dp = context->dp;
633 XFS_STATS_INC(xs_attr_list);
635 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
636 return EIO;
638 xfs_ilock(dp, XFS_ILOCK_SHARED);
639 xfs_attr_trace_l_c("syscall start", context);
642 * Decide on what work routines to call based on the inode size.
644 if (!xfs_inode_hasattr(dp)) {
645 error = 0;
646 } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
647 error = xfs_attr_shortform_list(context);
648 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
649 error = xfs_attr_leaf_list(context);
650 } else {
651 error = xfs_attr_node_list(context);
654 xfs_iunlock(dp, XFS_ILOCK_SHARED);
655 xfs_attr_trace_l_c("syscall end", context);
657 return error;
660 #define ATTR_ENTBASESIZE /* minimum bytes used by an attr */ \
661 (((struct attrlist_ent *) 0)->a_name - (char *) 0)
662 #define ATTR_ENTSIZE(namelen) /* actual bytes used by an attr */ \
663 ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
664 & ~(sizeof(u_int32_t)-1))
667 * Format an attribute and copy it out to the user's buffer.
668 * Take care to check values and protect against them changing later,
669 * we may be reading them directly out of a user buffer.
671 /*ARGSUSED*/
672 STATIC int
673 xfs_attr_put_listent(xfs_attr_list_context_t *context, int flags,
674 char *name, int namelen,
675 int valuelen, char *value)
677 struct attrlist *alist = (struct attrlist *)context->alist;
678 attrlist_ent_t *aep;
679 int arraytop;
681 ASSERT(!(context->flags & ATTR_KERNOVAL));
682 ASSERT(context->count >= 0);
683 ASSERT(context->count < (ATTR_MAX_VALUELEN/8));
684 ASSERT(context->firstu >= sizeof(*alist));
685 ASSERT(context->firstu <= context->bufsize);
688 * Only list entries in the right namespace.
690 if (((context->flags & ATTR_SECURE) == 0) !=
691 ((flags & XFS_ATTR_SECURE) == 0))
692 return 0;
693 if (((context->flags & ATTR_ROOT) == 0) !=
694 ((flags & XFS_ATTR_ROOT) == 0))
695 return 0;
697 arraytop = sizeof(*alist) +
698 context->count * sizeof(alist->al_offset[0]);
699 context->firstu -= ATTR_ENTSIZE(namelen);
700 if (context->firstu < arraytop) {
701 xfs_attr_trace_l_c("buffer full", context);
702 alist->al_more = 1;
703 context->seen_enough = 1;
704 return 1;
707 aep = (attrlist_ent_t *)&context->alist[context->firstu];
708 aep->a_valuelen = valuelen;
709 memcpy(aep->a_name, name, namelen);
710 aep->a_name[namelen] = 0;
711 alist->al_offset[context->count++] = context->firstu;
712 alist->al_count = context->count;
713 xfs_attr_trace_l_c("add", context);
714 return 0;
718 * Generate a list of extended attribute names and optionally
719 * also value lengths. Positive return value follows the XFS
720 * convention of being an error, zero or negative return code
721 * is the length of the buffer returned (negated), indicating
722 * success.
725 xfs_attr_list(
726 xfs_inode_t *dp,
727 char *buffer,
728 int bufsize,
729 int flags,
730 attrlist_cursor_kern_t *cursor)
732 xfs_attr_list_context_t context;
733 struct attrlist *alist;
734 int error;
737 * Validate the cursor.
739 if (cursor->pad1 || cursor->pad2)
740 return(XFS_ERROR(EINVAL));
741 if ((cursor->initted == 0) &&
742 (cursor->hashval || cursor->blkno || cursor->offset))
743 return XFS_ERROR(EINVAL);
746 * Check for a properly aligned buffer.
748 if (((long)buffer) & (sizeof(int)-1))
749 return XFS_ERROR(EFAULT);
750 if (flags & ATTR_KERNOVAL)
751 bufsize = 0;
754 * Initialize the output buffer.
756 memset(&context, 0, sizeof(context));
757 context.dp = dp;
758 context.cursor = cursor;
759 context.resynch = 1;
760 context.flags = flags;
761 context.alist = buffer;
762 context.bufsize = (bufsize & ~(sizeof(int)-1)); /* align */
763 context.firstu = context.bufsize;
764 context.put_listent = xfs_attr_put_listent;
766 alist = (struct attrlist *)context.alist;
767 alist->al_count = 0;
768 alist->al_more = 0;
769 alist->al_offset[0] = context.bufsize;
771 error = xfs_attr_list_int(&context);
772 ASSERT(error >= 0);
773 return error;
776 int /* error */
777 xfs_attr_inactive(xfs_inode_t *dp)
779 xfs_trans_t *trans;
780 xfs_mount_t *mp;
781 int error;
783 mp = dp->i_mount;
784 ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
786 xfs_ilock(dp, XFS_ILOCK_SHARED);
787 if (!xfs_inode_hasattr(dp) ||
788 dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
789 xfs_iunlock(dp, XFS_ILOCK_SHARED);
790 return 0;
792 xfs_iunlock(dp, XFS_ILOCK_SHARED);
795 * Start our first transaction of the day.
797 * All future transactions during this code must be "chained" off
798 * this one via the trans_dup() call. All transactions will contain
799 * the inode, and the inode will always be marked with trans_ihold().
800 * Since the inode will be locked in all transactions, we must log
801 * the inode in every transaction to let it float upward through
802 * the log.
804 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL);
805 if ((error = xfs_trans_reserve(trans, 0, XFS_ATTRINVAL_LOG_RES(mp), 0,
806 XFS_TRANS_PERM_LOG_RES,
807 XFS_ATTRINVAL_LOG_COUNT))) {
808 xfs_trans_cancel(trans, 0);
809 return(error);
811 xfs_ilock(dp, XFS_ILOCK_EXCL);
814 * No need to make quota reservations here. We expect to release some
815 * blocks, not allocate, in the common case.
817 xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
818 xfs_trans_ihold(trans, dp);
821 * Decide on what work routines to call based on the inode size.
823 if (!xfs_inode_hasattr(dp) ||
824 dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
825 error = 0;
826 goto out;
828 error = xfs_attr_root_inactive(&trans, dp);
829 if (error)
830 goto out;
832 * signal synchronous inactive transactions unless this
833 * is a synchronous mount filesystem in which case we
834 * know that we're here because we've been called out of
835 * xfs_inactive which means that the last reference is gone
836 * and the unlink transaction has already hit the disk so
837 * async inactive transactions are safe.
839 if ((error = xfs_itruncate_finish(&trans, dp, 0LL, XFS_ATTR_FORK,
840 (!(mp->m_flags & XFS_MOUNT_WSYNC)
841 ? 1 : 0))))
842 goto out;
845 * Commit the last in the sequence of transactions.
847 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
848 error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES);
849 xfs_iunlock(dp, XFS_ILOCK_EXCL);
851 return(error);
853 out:
854 xfs_trans_cancel(trans, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
855 xfs_iunlock(dp, XFS_ILOCK_EXCL);
856 return(error);
861 /*========================================================================
862 * External routines when attribute list is inside the inode
863 *========================================================================*/
866 * Add a name to the shortform attribute list structure
867 * This is the external routine.
869 STATIC int
870 xfs_attr_shortform_addname(xfs_da_args_t *args)
872 int newsize, forkoff, retval;
874 retval = xfs_attr_shortform_lookup(args);
875 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
876 return(retval);
877 } else if (retval == EEXIST) {
878 if (args->flags & ATTR_CREATE)
879 return(retval);
880 retval = xfs_attr_shortform_remove(args);
881 ASSERT(retval == 0);
884 if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
885 args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
886 return(XFS_ERROR(ENOSPC));
888 newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
889 newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
891 forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
892 if (!forkoff)
893 return(XFS_ERROR(ENOSPC));
895 xfs_attr_shortform_add(args, forkoff);
896 return(0);
900 /*========================================================================
901 * External routines when attribute list is one block
902 *========================================================================*/
905 * Add a name to the leaf attribute list structure
907 * This leaf block cannot have a "remote" value, we only call this routine
908 * if bmap_one_block() says there is only one block (ie: no remote blks).
910 STATIC int
911 xfs_attr_leaf_addname(xfs_da_args_t *args)
913 xfs_inode_t *dp;
914 xfs_dabuf_t *bp;
915 int retval, error, committed, forkoff;
918 * Read the (only) block in the attribute list in.
920 dp = args->dp;
921 args->blkno = 0;
922 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
923 XFS_ATTR_FORK);
924 if (error)
925 return(error);
926 ASSERT(bp != NULL);
929 * Look up the given attribute in the leaf block. Figure out if
930 * the given flags produce an error or call for an atomic rename.
932 retval = xfs_attr_leaf_lookup_int(bp, args);
933 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
934 xfs_da_brelse(args->trans, bp);
935 return(retval);
936 } else if (retval == EEXIST) {
937 if (args->flags & ATTR_CREATE) { /* pure create op */
938 xfs_da_brelse(args->trans, bp);
939 return(retval);
941 args->op_flags |= XFS_DA_OP_RENAME; /* an atomic rename */
942 args->blkno2 = args->blkno; /* set 2nd entry info*/
943 args->index2 = args->index;
944 args->rmtblkno2 = args->rmtblkno;
945 args->rmtblkcnt2 = args->rmtblkcnt;
949 * Add the attribute to the leaf block, transitioning to a Btree
950 * if required.
952 retval = xfs_attr_leaf_add(bp, args);
953 xfs_da_buf_done(bp);
954 if (retval == ENOSPC) {
956 * Promote the attribute list to the Btree format, then
957 * Commit that transaction so that the node_addname() call
958 * can manage its own transactions.
960 xfs_bmap_init(args->flist, args->firstblock);
961 error = xfs_attr_leaf_to_node(args);
962 if (!error) {
963 error = xfs_bmap_finish(&args->trans, args->flist,
964 &committed);
966 if (error) {
967 ASSERT(committed);
968 args->trans = NULL;
969 xfs_bmap_cancel(args->flist);
970 return(error);
974 * bmap_finish() may have committed the last trans and started
975 * a new one. We need the inode to be in all transactions.
977 if (committed) {
978 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
979 xfs_trans_ihold(args->trans, dp);
983 * Commit the current trans (including the inode) and start
984 * a new one.
986 error = xfs_trans_roll(&args->trans, dp);
987 if (error)
988 return (error);
991 * Fob the whole rest of the problem off on the Btree code.
993 error = xfs_attr_node_addname(args);
994 return(error);
998 * Commit the transaction that added the attr name so that
999 * later routines can manage their own transactions.
1001 error = xfs_trans_roll(&args->trans, dp);
1002 if (error)
1003 return (error);
1006 * If there was an out-of-line value, allocate the blocks we
1007 * identified for its storage and copy the value. This is done
1008 * after we create the attribute so that we don't overflow the
1009 * maximum size of a transaction and/or hit a deadlock.
1011 if (args->rmtblkno > 0) {
1012 error = xfs_attr_rmtval_set(args);
1013 if (error)
1014 return(error);
1018 * If this is an atomic rename operation, we must "flip" the
1019 * incomplete flags on the "new" and "old" attribute/value pairs
1020 * so that one disappears and one appears atomically. Then we
1021 * must remove the "old" attribute/value pair.
1023 if (args->op_flags & XFS_DA_OP_RENAME) {
1025 * In a separate transaction, set the incomplete flag on the
1026 * "old" attr and clear the incomplete flag on the "new" attr.
1028 error = xfs_attr_leaf_flipflags(args);
1029 if (error)
1030 return(error);
1033 * Dismantle the "old" attribute/value pair by removing
1034 * a "remote" value (if it exists).
1036 args->index = args->index2;
1037 args->blkno = args->blkno2;
1038 args->rmtblkno = args->rmtblkno2;
1039 args->rmtblkcnt = args->rmtblkcnt2;
1040 if (args->rmtblkno) {
1041 error = xfs_attr_rmtval_remove(args);
1042 if (error)
1043 return(error);
1047 * Read in the block containing the "old" attr, then
1048 * remove the "old" attr from that block (neat, huh!)
1050 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
1051 &bp, XFS_ATTR_FORK);
1052 if (error)
1053 return(error);
1054 ASSERT(bp != NULL);
1055 (void)xfs_attr_leaf_remove(bp, args);
1058 * If the result is small enough, shrink it all into the inode.
1060 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1061 xfs_bmap_init(args->flist, args->firstblock);
1062 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1063 /* bp is gone due to xfs_da_shrink_inode */
1064 if (!error) {
1065 error = xfs_bmap_finish(&args->trans,
1066 args->flist,
1067 &committed);
1069 if (error) {
1070 ASSERT(committed);
1071 args->trans = NULL;
1072 xfs_bmap_cancel(args->flist);
1073 return(error);
1077 * bmap_finish() may have committed the last trans
1078 * and started a new one. We need the inode to be
1079 * in all transactions.
1081 if (committed) {
1082 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1083 xfs_trans_ihold(args->trans, dp);
1085 } else
1086 xfs_da_buf_done(bp);
1089 * Commit the remove and start the next trans in series.
1091 error = xfs_trans_roll(&args->trans, dp);
1093 } else if (args->rmtblkno > 0) {
1095 * Added a "remote" value, just clear the incomplete flag.
1097 error = xfs_attr_leaf_clearflag(args);
1099 return(error);
1103 * Remove a name from the leaf attribute list structure
1105 * This leaf block cannot have a "remote" value, we only call this routine
1106 * if bmap_one_block() says there is only one block (ie: no remote blks).
1108 STATIC int
1109 xfs_attr_leaf_removename(xfs_da_args_t *args)
1111 xfs_inode_t *dp;
1112 xfs_dabuf_t *bp;
1113 int error, committed, forkoff;
1116 * Remove the attribute.
1118 dp = args->dp;
1119 args->blkno = 0;
1120 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1121 XFS_ATTR_FORK);
1122 if (error) {
1123 return(error);
1126 ASSERT(bp != NULL);
1127 error = xfs_attr_leaf_lookup_int(bp, args);
1128 if (error == ENOATTR) {
1129 xfs_da_brelse(args->trans, bp);
1130 return(error);
1133 (void)xfs_attr_leaf_remove(bp, args);
1136 * If the result is small enough, shrink it all into the inode.
1138 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1139 xfs_bmap_init(args->flist, args->firstblock);
1140 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1141 /* bp is gone due to xfs_da_shrink_inode */
1142 if (!error) {
1143 error = xfs_bmap_finish(&args->trans, args->flist,
1144 &committed);
1146 if (error) {
1147 ASSERT(committed);
1148 args->trans = NULL;
1149 xfs_bmap_cancel(args->flist);
1150 return(error);
1154 * bmap_finish() may have committed the last trans and started
1155 * a new one. We need the inode to be in all transactions.
1157 if (committed) {
1158 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1159 xfs_trans_ihold(args->trans, dp);
1161 } else
1162 xfs_da_buf_done(bp);
1163 return(0);
1167 * Look up a name in a leaf attribute list structure.
1169 * This leaf block cannot have a "remote" value, we only call this routine
1170 * if bmap_one_block() says there is only one block (ie: no remote blks).
1172 STATIC int
1173 xfs_attr_leaf_get(xfs_da_args_t *args)
1175 xfs_dabuf_t *bp;
1176 int error;
1178 args->blkno = 0;
1179 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1180 XFS_ATTR_FORK);
1181 if (error)
1182 return(error);
1183 ASSERT(bp != NULL);
1185 error = xfs_attr_leaf_lookup_int(bp, args);
1186 if (error != EEXIST) {
1187 xfs_da_brelse(args->trans, bp);
1188 return(error);
1190 error = xfs_attr_leaf_getvalue(bp, args);
1191 xfs_da_brelse(args->trans, bp);
1192 if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
1193 error = xfs_attr_rmtval_get(args);
1195 return(error);
1199 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1201 STATIC int
1202 xfs_attr_leaf_list(xfs_attr_list_context_t *context)
1204 xfs_attr_leafblock_t *leaf;
1205 int error;
1206 xfs_dabuf_t *bp;
1208 context->cursor->blkno = 0;
1209 error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK);
1210 if (error)
1211 return XFS_ERROR(error);
1212 ASSERT(bp != NULL);
1213 leaf = bp->data;
1214 if (unlikely(be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC)) {
1215 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
1216 context->dp->i_mount, leaf);
1217 xfs_da_brelse(NULL, bp);
1218 return XFS_ERROR(EFSCORRUPTED);
1221 error = xfs_attr_leaf_list_int(bp, context);
1222 xfs_da_brelse(NULL, bp);
1223 return XFS_ERROR(error);
1227 /*========================================================================
1228 * External routines when attribute list size > XFS_LBSIZE(mp).
1229 *========================================================================*/
1232 * Add a name to a Btree-format attribute list.
1234 * This will involve walking down the Btree, and may involve splitting
1235 * leaf nodes and even splitting intermediate nodes up to and including
1236 * the root node (a special case of an intermediate node).
1238 * "Remote" attribute values confuse the issue and atomic rename operations
1239 * add a whole extra layer of confusion on top of that.
1241 STATIC int
1242 xfs_attr_node_addname(xfs_da_args_t *args)
1244 xfs_da_state_t *state;
1245 xfs_da_state_blk_t *blk;
1246 xfs_inode_t *dp;
1247 xfs_mount_t *mp;
1248 int committed, retval, error;
1251 * Fill in bucket of arguments/results/context to carry around.
1253 dp = args->dp;
1254 mp = dp->i_mount;
1255 restart:
1256 state = xfs_da_state_alloc();
1257 state->args = args;
1258 state->mp = mp;
1259 state->blocksize = state->mp->m_sb.sb_blocksize;
1260 state->node_ents = state->mp->m_attr_node_ents;
1263 * Search to see if name already exists, and get back a pointer
1264 * to where it should go.
1266 error = xfs_da_node_lookup_int(state, &retval);
1267 if (error)
1268 goto out;
1269 blk = &state->path.blk[ state->path.active-1 ];
1270 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1271 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
1272 goto out;
1273 } else if (retval == EEXIST) {
1274 if (args->flags & ATTR_CREATE)
1275 goto out;
1276 args->op_flags |= XFS_DA_OP_RENAME; /* atomic rename op */
1277 args->blkno2 = args->blkno; /* set 2nd entry info*/
1278 args->index2 = args->index;
1279 args->rmtblkno2 = args->rmtblkno;
1280 args->rmtblkcnt2 = args->rmtblkcnt;
1281 args->rmtblkno = 0;
1282 args->rmtblkcnt = 0;
1285 retval = xfs_attr_leaf_add(blk->bp, state->args);
1286 if (retval == ENOSPC) {
1287 if (state->path.active == 1) {
1289 * Its really a single leaf node, but it had
1290 * out-of-line values so it looked like it *might*
1291 * have been a b-tree.
1293 xfs_da_state_free(state);
1294 xfs_bmap_init(args->flist, args->firstblock);
1295 error = xfs_attr_leaf_to_node(args);
1296 if (!error) {
1297 error = xfs_bmap_finish(&args->trans,
1298 args->flist,
1299 &committed);
1301 if (error) {
1302 ASSERT(committed);
1303 args->trans = NULL;
1304 xfs_bmap_cancel(args->flist);
1305 goto out;
1309 * bmap_finish() may have committed the last trans
1310 * and started a new one. We need the inode to be
1311 * in all transactions.
1313 if (committed) {
1314 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1315 xfs_trans_ihold(args->trans, dp);
1319 * Commit the node conversion and start the next
1320 * trans in the chain.
1322 error = xfs_trans_roll(&args->trans, dp);
1323 if (error)
1324 goto out;
1326 goto restart;
1330 * Split as many Btree elements as required.
1331 * This code tracks the new and old attr's location
1332 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1333 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1335 xfs_bmap_init(args->flist, args->firstblock);
1336 error = xfs_da_split(state);
1337 if (!error) {
1338 error = xfs_bmap_finish(&args->trans, args->flist,
1339 &committed);
1341 if (error) {
1342 ASSERT(committed);
1343 args->trans = NULL;
1344 xfs_bmap_cancel(args->flist);
1345 goto out;
1349 * bmap_finish() may have committed the last trans and started
1350 * a new one. We need the inode to be in all transactions.
1352 if (committed) {
1353 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1354 xfs_trans_ihold(args->trans, dp);
1356 } else {
1358 * Addition succeeded, update Btree hashvals.
1360 xfs_da_fixhashpath(state, &state->path);
1364 * Kill the state structure, we're done with it and need to
1365 * allow the buffers to come back later.
1367 xfs_da_state_free(state);
1368 state = NULL;
1371 * Commit the leaf addition or btree split and start the next
1372 * trans in the chain.
1374 error = xfs_trans_roll(&args->trans, dp);
1375 if (error)
1376 goto out;
1379 * If there was an out-of-line value, allocate the blocks we
1380 * identified for its storage and copy the value. This is done
1381 * after we create the attribute so that we don't overflow the
1382 * maximum size of a transaction and/or hit a deadlock.
1384 if (args->rmtblkno > 0) {
1385 error = xfs_attr_rmtval_set(args);
1386 if (error)
1387 return(error);
1391 * If this is an atomic rename operation, we must "flip" the
1392 * incomplete flags on the "new" and "old" attribute/value pairs
1393 * so that one disappears and one appears atomically. Then we
1394 * must remove the "old" attribute/value pair.
1396 if (args->op_flags & XFS_DA_OP_RENAME) {
1398 * In a separate transaction, set the incomplete flag on the
1399 * "old" attr and clear the incomplete flag on the "new" attr.
1401 error = xfs_attr_leaf_flipflags(args);
1402 if (error)
1403 goto out;
1406 * Dismantle the "old" attribute/value pair by removing
1407 * a "remote" value (if it exists).
1409 args->index = args->index2;
1410 args->blkno = args->blkno2;
1411 args->rmtblkno = args->rmtblkno2;
1412 args->rmtblkcnt = args->rmtblkcnt2;
1413 if (args->rmtblkno) {
1414 error = xfs_attr_rmtval_remove(args);
1415 if (error)
1416 return(error);
1420 * Re-find the "old" attribute entry after any split ops.
1421 * The INCOMPLETE flag means that we will find the "old"
1422 * attr, not the "new" one.
1424 args->flags |= XFS_ATTR_INCOMPLETE;
1425 state = xfs_da_state_alloc();
1426 state->args = args;
1427 state->mp = mp;
1428 state->blocksize = state->mp->m_sb.sb_blocksize;
1429 state->node_ents = state->mp->m_attr_node_ents;
1430 state->inleaf = 0;
1431 error = xfs_da_node_lookup_int(state, &retval);
1432 if (error)
1433 goto out;
1436 * Remove the name and update the hashvals in the tree.
1438 blk = &state->path.blk[ state->path.active-1 ];
1439 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1440 error = xfs_attr_leaf_remove(blk->bp, args);
1441 xfs_da_fixhashpath(state, &state->path);
1444 * Check to see if the tree needs to be collapsed.
1446 if (retval && (state->path.active > 1)) {
1447 xfs_bmap_init(args->flist, args->firstblock);
1448 error = xfs_da_join(state);
1449 if (!error) {
1450 error = xfs_bmap_finish(&args->trans,
1451 args->flist,
1452 &committed);
1454 if (error) {
1455 ASSERT(committed);
1456 args->trans = NULL;
1457 xfs_bmap_cancel(args->flist);
1458 goto out;
1462 * bmap_finish() may have committed the last trans
1463 * and started a new one. We need the inode to be
1464 * in all transactions.
1466 if (committed) {
1467 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1468 xfs_trans_ihold(args->trans, dp);
1473 * Commit and start the next trans in the chain.
1475 error = xfs_trans_roll(&args->trans, dp);
1476 if (error)
1477 goto out;
1479 } else if (args->rmtblkno > 0) {
1481 * Added a "remote" value, just clear the incomplete flag.
1483 error = xfs_attr_leaf_clearflag(args);
1484 if (error)
1485 goto out;
1487 retval = error = 0;
1489 out:
1490 if (state)
1491 xfs_da_state_free(state);
1492 if (error)
1493 return(error);
1494 return(retval);
1498 * Remove a name from a B-tree attribute list.
1500 * This will involve walking down the Btree, and may involve joining
1501 * leaf nodes and even joining intermediate nodes up to and including
1502 * the root node (a special case of an intermediate node).
1504 STATIC int
1505 xfs_attr_node_removename(xfs_da_args_t *args)
1507 xfs_da_state_t *state;
1508 xfs_da_state_blk_t *blk;
1509 xfs_inode_t *dp;
1510 xfs_dabuf_t *bp;
1511 int retval, error, committed, forkoff;
1514 * Tie a string around our finger to remind us where we are.
1516 dp = args->dp;
1517 state = xfs_da_state_alloc();
1518 state->args = args;
1519 state->mp = dp->i_mount;
1520 state->blocksize = state->mp->m_sb.sb_blocksize;
1521 state->node_ents = state->mp->m_attr_node_ents;
1524 * Search to see if name exists, and get back a pointer to it.
1526 error = xfs_da_node_lookup_int(state, &retval);
1527 if (error || (retval != EEXIST)) {
1528 if (error == 0)
1529 error = retval;
1530 goto out;
1534 * If there is an out-of-line value, de-allocate the blocks.
1535 * This is done before we remove the attribute so that we don't
1536 * overflow the maximum size of a transaction and/or hit a deadlock.
1538 blk = &state->path.blk[ state->path.active-1 ];
1539 ASSERT(blk->bp != NULL);
1540 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1541 if (args->rmtblkno > 0) {
1543 * Fill in disk block numbers in the state structure
1544 * so that we can get the buffers back after we commit
1545 * several transactions in the following calls.
1547 error = xfs_attr_fillstate(state);
1548 if (error)
1549 goto out;
1552 * Mark the attribute as INCOMPLETE, then bunmapi() the
1553 * remote value.
1555 error = xfs_attr_leaf_setflag(args);
1556 if (error)
1557 goto out;
1558 error = xfs_attr_rmtval_remove(args);
1559 if (error)
1560 goto out;
1563 * Refill the state structure with buffers, the prior calls
1564 * released our buffers.
1566 error = xfs_attr_refillstate(state);
1567 if (error)
1568 goto out;
1572 * Remove the name and update the hashvals in the tree.
1574 blk = &state->path.blk[ state->path.active-1 ];
1575 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1576 retval = xfs_attr_leaf_remove(blk->bp, args);
1577 xfs_da_fixhashpath(state, &state->path);
1580 * Check to see if the tree needs to be collapsed.
1582 if (retval && (state->path.active > 1)) {
1583 xfs_bmap_init(args->flist, args->firstblock);
1584 error = xfs_da_join(state);
1585 if (!error) {
1586 error = xfs_bmap_finish(&args->trans, args->flist,
1587 &committed);
1589 if (error) {
1590 ASSERT(committed);
1591 args->trans = NULL;
1592 xfs_bmap_cancel(args->flist);
1593 goto out;
1597 * bmap_finish() may have committed the last trans and started
1598 * a new one. We need the inode to be in all transactions.
1600 if (committed) {
1601 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1602 xfs_trans_ihold(args->trans, dp);
1606 * Commit the Btree join operation and start a new trans.
1608 error = xfs_trans_roll(&args->trans, dp);
1609 if (error)
1610 goto out;
1614 * If the result is small enough, push it all into the inode.
1616 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1618 * Have to get rid of the copy of this dabuf in the state.
1620 ASSERT(state->path.active == 1);
1621 ASSERT(state->path.blk[0].bp);
1622 xfs_da_buf_done(state->path.blk[0].bp);
1623 state->path.blk[0].bp = NULL;
1625 error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
1626 XFS_ATTR_FORK);
1627 if (error)
1628 goto out;
1629 ASSERT(be16_to_cpu(((xfs_attr_leafblock_t *)
1630 bp->data)->hdr.info.magic)
1631 == XFS_ATTR_LEAF_MAGIC);
1633 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1634 xfs_bmap_init(args->flist, args->firstblock);
1635 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1636 /* bp is gone due to xfs_da_shrink_inode */
1637 if (!error) {
1638 error = xfs_bmap_finish(&args->trans,
1639 args->flist,
1640 &committed);
1642 if (error) {
1643 ASSERT(committed);
1644 args->trans = NULL;
1645 xfs_bmap_cancel(args->flist);
1646 goto out;
1650 * bmap_finish() may have committed the last trans
1651 * and started a new one. We need the inode to be
1652 * in all transactions.
1654 if (committed) {
1655 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1656 xfs_trans_ihold(args->trans, dp);
1658 } else
1659 xfs_da_brelse(args->trans, bp);
1661 error = 0;
1663 out:
1664 xfs_da_state_free(state);
1665 return(error);
1669 * Fill in the disk block numbers in the state structure for the buffers
1670 * that are attached to the state structure.
1671 * This is done so that we can quickly reattach ourselves to those buffers
1672 * after some set of transaction commits have released these buffers.
1674 STATIC int
1675 xfs_attr_fillstate(xfs_da_state_t *state)
1677 xfs_da_state_path_t *path;
1678 xfs_da_state_blk_t *blk;
1679 int level;
1682 * Roll down the "path" in the state structure, storing the on-disk
1683 * block number for those buffers in the "path".
1685 path = &state->path;
1686 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1687 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1688 if (blk->bp) {
1689 blk->disk_blkno = xfs_da_blkno(blk->bp);
1690 xfs_da_buf_done(blk->bp);
1691 blk->bp = NULL;
1692 } else {
1693 blk->disk_blkno = 0;
1698 * Roll down the "altpath" in the state structure, storing the on-disk
1699 * block number for those buffers in the "altpath".
1701 path = &state->altpath;
1702 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1703 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1704 if (blk->bp) {
1705 blk->disk_blkno = xfs_da_blkno(blk->bp);
1706 xfs_da_buf_done(blk->bp);
1707 blk->bp = NULL;
1708 } else {
1709 blk->disk_blkno = 0;
1713 return(0);
1717 * Reattach the buffers to the state structure based on the disk block
1718 * numbers stored in the state structure.
1719 * This is done after some set of transaction commits have released those
1720 * buffers from our grip.
1722 STATIC int
1723 xfs_attr_refillstate(xfs_da_state_t *state)
1725 xfs_da_state_path_t *path;
1726 xfs_da_state_blk_t *blk;
1727 int level, error;
1730 * Roll down the "path" in the state structure, storing the on-disk
1731 * block number for those buffers in the "path".
1733 path = &state->path;
1734 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1735 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1736 if (blk->disk_blkno) {
1737 error = xfs_da_read_buf(state->args->trans,
1738 state->args->dp,
1739 blk->blkno, blk->disk_blkno,
1740 &blk->bp, XFS_ATTR_FORK);
1741 if (error)
1742 return(error);
1743 } else {
1744 blk->bp = NULL;
1749 * Roll down the "altpath" in the state structure, storing the on-disk
1750 * block number for those buffers in the "altpath".
1752 path = &state->altpath;
1753 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1754 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1755 if (blk->disk_blkno) {
1756 error = xfs_da_read_buf(state->args->trans,
1757 state->args->dp,
1758 blk->blkno, blk->disk_blkno,
1759 &blk->bp, XFS_ATTR_FORK);
1760 if (error)
1761 return(error);
1762 } else {
1763 blk->bp = NULL;
1767 return(0);
1771 * Look up a filename in a node attribute list.
1773 * This routine gets called for any attribute fork that has more than one
1774 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1775 * "remote" values taking up more blocks.
1777 STATIC int
1778 xfs_attr_node_get(xfs_da_args_t *args)
1780 xfs_da_state_t *state;
1781 xfs_da_state_blk_t *blk;
1782 int error, retval;
1783 int i;
1785 state = xfs_da_state_alloc();
1786 state->args = args;
1787 state->mp = args->dp->i_mount;
1788 state->blocksize = state->mp->m_sb.sb_blocksize;
1789 state->node_ents = state->mp->m_attr_node_ents;
1792 * Search to see if name exists, and get back a pointer to it.
1794 error = xfs_da_node_lookup_int(state, &retval);
1795 if (error) {
1796 retval = error;
1797 } else if (retval == EEXIST) {
1798 blk = &state->path.blk[ state->path.active-1 ];
1799 ASSERT(blk->bp != NULL);
1800 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1803 * Get the value, local or "remote"
1805 retval = xfs_attr_leaf_getvalue(blk->bp, args);
1806 if (!retval && (args->rmtblkno > 0)
1807 && !(args->flags & ATTR_KERNOVAL)) {
1808 retval = xfs_attr_rmtval_get(args);
1813 * If not in a transaction, we have to release all the buffers.
1815 for (i = 0; i < state->path.active; i++) {
1816 xfs_da_brelse(args->trans, state->path.blk[i].bp);
1817 state->path.blk[i].bp = NULL;
1820 xfs_da_state_free(state);
1821 return(retval);
1824 STATIC int /* error */
1825 xfs_attr_node_list(xfs_attr_list_context_t *context)
1827 attrlist_cursor_kern_t *cursor;
1828 xfs_attr_leafblock_t *leaf;
1829 xfs_da_intnode_t *node;
1830 xfs_da_node_entry_t *btree;
1831 int error, i;
1832 xfs_dabuf_t *bp;
1834 cursor = context->cursor;
1835 cursor->initted = 1;
1838 * Do all sorts of validation on the passed-in cursor structure.
1839 * If anything is amiss, ignore the cursor and look up the hashval
1840 * starting from the btree root.
1842 bp = NULL;
1843 if (cursor->blkno > 0) {
1844 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1845 &bp, XFS_ATTR_FORK);
1846 if ((error != 0) && (error != EFSCORRUPTED))
1847 return(error);
1848 if (bp) {
1849 node = bp->data;
1850 switch (be16_to_cpu(node->hdr.info.magic)) {
1851 case XFS_DA_NODE_MAGIC:
1852 xfs_attr_trace_l_cn("wrong blk", context, node);
1853 xfs_da_brelse(NULL, bp);
1854 bp = NULL;
1855 break;
1856 case XFS_ATTR_LEAF_MAGIC:
1857 leaf = bp->data;
1858 if (cursor->hashval > be32_to_cpu(leaf->entries[
1859 be16_to_cpu(leaf->hdr.count)-1].hashval)) {
1860 xfs_attr_trace_l_cl("wrong blk",
1861 context, leaf);
1862 xfs_da_brelse(NULL, bp);
1863 bp = NULL;
1864 } else if (cursor->hashval <=
1865 be32_to_cpu(leaf->entries[0].hashval)) {
1866 xfs_attr_trace_l_cl("maybe wrong blk",
1867 context, leaf);
1868 xfs_da_brelse(NULL, bp);
1869 bp = NULL;
1871 break;
1872 default:
1873 xfs_attr_trace_l_c("wrong blk - ??", context);
1874 xfs_da_brelse(NULL, bp);
1875 bp = NULL;
1881 * We did not find what we expected given the cursor's contents,
1882 * so we start from the top and work down based on the hash value.
1883 * Note that start of node block is same as start of leaf block.
1885 if (bp == NULL) {
1886 cursor->blkno = 0;
1887 for (;;) {
1888 error = xfs_da_read_buf(NULL, context->dp,
1889 cursor->blkno, -1, &bp,
1890 XFS_ATTR_FORK);
1891 if (error)
1892 return(error);
1893 if (unlikely(bp == NULL)) {
1894 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1895 XFS_ERRLEVEL_LOW,
1896 context->dp->i_mount);
1897 return(XFS_ERROR(EFSCORRUPTED));
1899 node = bp->data;
1900 if (be16_to_cpu(node->hdr.info.magic)
1901 == XFS_ATTR_LEAF_MAGIC)
1902 break;
1903 if (unlikely(be16_to_cpu(node->hdr.info.magic)
1904 != XFS_DA_NODE_MAGIC)) {
1905 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1906 XFS_ERRLEVEL_LOW,
1907 context->dp->i_mount,
1908 node);
1909 xfs_da_brelse(NULL, bp);
1910 return(XFS_ERROR(EFSCORRUPTED));
1912 btree = node->btree;
1913 for (i = 0; i < be16_to_cpu(node->hdr.count);
1914 btree++, i++) {
1915 if (cursor->hashval
1916 <= be32_to_cpu(btree->hashval)) {
1917 cursor->blkno = be32_to_cpu(btree->before);
1918 xfs_attr_trace_l_cb("descending",
1919 context, btree);
1920 break;
1923 if (i == be16_to_cpu(node->hdr.count)) {
1924 xfs_da_brelse(NULL, bp);
1925 return(0);
1927 xfs_da_brelse(NULL, bp);
1930 ASSERT(bp != NULL);
1933 * Roll upward through the blocks, processing each leaf block in
1934 * order. As long as there is space in the result buffer, keep
1935 * adding the information.
1937 for (;;) {
1938 leaf = bp->data;
1939 if (unlikely(be16_to_cpu(leaf->hdr.info.magic)
1940 != XFS_ATTR_LEAF_MAGIC)) {
1941 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1942 XFS_ERRLEVEL_LOW,
1943 context->dp->i_mount, leaf);
1944 xfs_da_brelse(NULL, bp);
1945 return(XFS_ERROR(EFSCORRUPTED));
1947 error = xfs_attr_leaf_list_int(bp, context);
1948 if (error) {
1949 xfs_da_brelse(NULL, bp);
1950 return error;
1952 if (context->seen_enough || leaf->hdr.info.forw == 0)
1953 break;
1954 cursor->blkno = be32_to_cpu(leaf->hdr.info.forw);
1955 xfs_da_brelse(NULL, bp);
1956 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1957 &bp, XFS_ATTR_FORK);
1958 if (error)
1959 return(error);
1960 if (unlikely((bp == NULL))) {
1961 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1962 XFS_ERRLEVEL_LOW,
1963 context->dp->i_mount);
1964 return(XFS_ERROR(EFSCORRUPTED));
1967 xfs_da_brelse(NULL, bp);
1968 return(0);
1972 /*========================================================================
1973 * External routines for manipulating out-of-line attribute values.
1974 *========================================================================*/
1977 * Read the value associated with an attribute from the out-of-line buffer
1978 * that we stored it in.
1981 xfs_attr_rmtval_get(xfs_da_args_t *args)
1983 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE];
1984 xfs_mount_t *mp;
1985 xfs_daddr_t dblkno;
1986 xfs_caddr_t dst;
1987 xfs_buf_t *bp;
1988 int nmap, error, tmp, valuelen, blkcnt, i;
1989 xfs_dablk_t lblkno;
1991 ASSERT(!(args->flags & ATTR_KERNOVAL));
1993 mp = args->dp->i_mount;
1994 dst = args->value;
1995 valuelen = args->valuelen;
1996 lblkno = args->rmtblkno;
1997 while (valuelen > 0) {
1998 nmap = ATTR_RMTVALUE_MAPSIZE;
1999 error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
2000 args->rmtblkcnt,
2001 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2002 NULL, 0, map, &nmap, NULL, NULL);
2003 if (error)
2004 return(error);
2005 ASSERT(nmap >= 1);
2007 for (i = 0; (i < nmap) && (valuelen > 0); i++) {
2008 ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
2009 (map[i].br_startblock != HOLESTARTBLOCK));
2010 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
2011 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
2012 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno,
2013 blkcnt,
2014 XFS_BUF_LOCK | XBF_DONT_BLOCK,
2015 &bp);
2016 if (error)
2017 return(error);
2019 tmp = (valuelen < XFS_BUF_SIZE(bp))
2020 ? valuelen : XFS_BUF_SIZE(bp);
2021 xfs_biomove(bp, 0, tmp, dst, XFS_B_READ);
2022 xfs_buf_relse(bp);
2023 dst += tmp;
2024 valuelen -= tmp;
2026 lblkno += map[i].br_blockcount;
2029 ASSERT(valuelen == 0);
2030 return(0);
2034 * Write the value associated with an attribute into the out-of-line buffer
2035 * that we have defined for it.
2037 STATIC int
2038 xfs_attr_rmtval_set(xfs_da_args_t *args)
2040 xfs_mount_t *mp;
2041 xfs_fileoff_t lfileoff;
2042 xfs_inode_t *dp;
2043 xfs_bmbt_irec_t map;
2044 xfs_daddr_t dblkno;
2045 xfs_caddr_t src;
2046 xfs_buf_t *bp;
2047 xfs_dablk_t lblkno;
2048 int blkcnt, valuelen, nmap, error, tmp, committed;
2050 dp = args->dp;
2051 mp = dp->i_mount;
2052 src = args->value;
2055 * Find a "hole" in the attribute address space large enough for
2056 * us to drop the new attribute's value into.
2058 blkcnt = XFS_B_TO_FSB(mp, args->valuelen);
2059 lfileoff = 0;
2060 error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
2061 XFS_ATTR_FORK);
2062 if (error) {
2063 return(error);
2065 args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
2066 args->rmtblkcnt = blkcnt;
2069 * Roll through the "value", allocating blocks on disk as required.
2071 while (blkcnt > 0) {
2073 * Allocate a single extent, up to the size of the value.
2075 xfs_bmap_init(args->flist, args->firstblock);
2076 nmap = 1;
2077 error = xfs_bmapi(args->trans, dp, (xfs_fileoff_t)lblkno,
2078 blkcnt,
2079 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
2080 XFS_BMAPI_WRITE,
2081 args->firstblock, args->total, &map, &nmap,
2082 args->flist, NULL);
2083 if (!error) {
2084 error = xfs_bmap_finish(&args->trans, args->flist,
2085 &committed);
2087 if (error) {
2088 ASSERT(committed);
2089 args->trans = NULL;
2090 xfs_bmap_cancel(args->flist);
2091 return(error);
2095 * bmap_finish() may have committed the last trans and started
2096 * a new one. We need the inode to be in all transactions.
2098 if (committed) {
2099 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
2100 xfs_trans_ihold(args->trans, dp);
2103 ASSERT(nmap == 1);
2104 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2105 (map.br_startblock != HOLESTARTBLOCK));
2106 lblkno += map.br_blockcount;
2107 blkcnt -= map.br_blockcount;
2110 * Start the next trans in the chain.
2112 error = xfs_trans_roll(&args->trans, dp);
2113 if (error)
2114 return (error);
2118 * Roll through the "value", copying the attribute value to the
2119 * already-allocated blocks. Blocks are written synchronously
2120 * so that we can know they are all on disk before we turn off
2121 * the INCOMPLETE flag.
2123 lblkno = args->rmtblkno;
2124 valuelen = args->valuelen;
2125 while (valuelen > 0) {
2127 * Try to remember where we decided to put the value.
2129 xfs_bmap_init(args->flist, args->firstblock);
2130 nmap = 1;
2131 error = xfs_bmapi(NULL, dp, (xfs_fileoff_t)lblkno,
2132 args->rmtblkcnt,
2133 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2134 args->firstblock, 0, &map, &nmap,
2135 NULL, NULL);
2136 if (error) {
2137 return(error);
2139 ASSERT(nmap == 1);
2140 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2141 (map.br_startblock != HOLESTARTBLOCK));
2143 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2144 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2146 bp = xfs_buf_get_flags(mp->m_ddev_targp, dblkno, blkcnt,
2147 XFS_BUF_LOCK | XBF_DONT_BLOCK);
2148 ASSERT(bp);
2149 ASSERT(!XFS_BUF_GETERROR(bp));
2151 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen :
2152 XFS_BUF_SIZE(bp);
2153 xfs_biomove(bp, 0, tmp, src, XFS_B_WRITE);
2154 if (tmp < XFS_BUF_SIZE(bp))
2155 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp);
2156 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */
2157 return (error);
2159 src += tmp;
2160 valuelen -= tmp;
2162 lblkno += map.br_blockcount;
2164 ASSERT(valuelen == 0);
2165 return(0);
2169 * Remove the value associated with an attribute by deleting the
2170 * out-of-line buffer that it is stored on.
2172 STATIC int
2173 xfs_attr_rmtval_remove(xfs_da_args_t *args)
2175 xfs_mount_t *mp;
2176 xfs_bmbt_irec_t map;
2177 xfs_buf_t *bp;
2178 xfs_daddr_t dblkno;
2179 xfs_dablk_t lblkno;
2180 int valuelen, blkcnt, nmap, error, done, committed;
2182 mp = args->dp->i_mount;
2185 * Roll through the "value", invalidating the attribute value's
2186 * blocks.
2188 lblkno = args->rmtblkno;
2189 valuelen = args->rmtblkcnt;
2190 while (valuelen > 0) {
2192 * Try to remember where we decided to put the value.
2194 xfs_bmap_init(args->flist, args->firstblock);
2195 nmap = 1;
2196 error = xfs_bmapi(NULL, args->dp, (xfs_fileoff_t)lblkno,
2197 args->rmtblkcnt,
2198 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2199 args->firstblock, 0, &map, &nmap,
2200 args->flist, NULL);
2201 if (error) {
2202 return(error);
2204 ASSERT(nmap == 1);
2205 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2206 (map.br_startblock != HOLESTARTBLOCK));
2208 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2209 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2212 * If the "remote" value is in the cache, remove it.
2214 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt,
2215 XFS_INCORE_TRYLOCK);
2216 if (bp) {
2217 XFS_BUF_STALE(bp);
2218 XFS_BUF_UNDELAYWRITE(bp);
2219 xfs_buf_relse(bp);
2220 bp = NULL;
2223 valuelen -= map.br_blockcount;
2225 lblkno += map.br_blockcount;
2229 * Keep de-allocating extents until the remote-value region is gone.
2231 lblkno = args->rmtblkno;
2232 blkcnt = args->rmtblkcnt;
2233 done = 0;
2234 while (!done) {
2235 xfs_bmap_init(args->flist, args->firstblock);
2236 error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
2237 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2238 1, args->firstblock, args->flist,
2239 NULL, &done);
2240 if (!error) {
2241 error = xfs_bmap_finish(&args->trans, args->flist,
2242 &committed);
2244 if (error) {
2245 ASSERT(committed);
2246 args->trans = NULL;
2247 xfs_bmap_cancel(args->flist);
2248 return(error);
2252 * bmap_finish() may have committed the last trans and started
2253 * a new one. We need the inode to be in all transactions.
2255 if (committed) {
2256 xfs_trans_ijoin(args->trans, args->dp, XFS_ILOCK_EXCL);
2257 xfs_trans_ihold(args->trans, args->dp);
2261 * Close out trans and start the next one in the chain.
2263 error = xfs_trans_roll(&args->trans, args->dp);
2264 if (error)
2265 return (error);
2267 return(0);
2270 #if defined(XFS_ATTR_TRACE)
2272 * Add a trace buffer entry for an attr_list context structure.
2274 void
2275 xfs_attr_trace_l_c(char *where, struct xfs_attr_list_context *context)
2277 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C, where, context,
2278 (__psunsigned_t)NULL,
2279 (__psunsigned_t)NULL,
2280 (__psunsigned_t)NULL);
2284 * Add a trace buffer entry for a context structure and a Btree node.
2286 void
2287 xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
2288 struct xfs_da_intnode *node)
2290 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN, where, context,
2291 (__psunsigned_t)be16_to_cpu(node->hdr.count),
2292 (__psunsigned_t)be32_to_cpu(node->btree[0].hashval),
2293 (__psunsigned_t)be32_to_cpu(node->btree[
2294 be16_to_cpu(node->hdr.count)-1].hashval));
2298 * Add a trace buffer entry for a context structure and a Btree element.
2300 void
2301 xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
2302 struct xfs_da_node_entry *btree)
2304 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB, where, context,
2305 (__psunsigned_t)be32_to_cpu(btree->hashval),
2306 (__psunsigned_t)be32_to_cpu(btree->before),
2307 (__psunsigned_t)NULL);
2311 * Add a trace buffer entry for a context structure and a leaf block.
2313 void
2314 xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
2315 struct xfs_attr_leafblock *leaf)
2317 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL, where, context,
2318 (__psunsigned_t)be16_to_cpu(leaf->hdr.count),
2319 (__psunsigned_t)be32_to_cpu(leaf->entries[0].hashval),
2320 (__psunsigned_t)be32_to_cpu(leaf->entries[
2321 be16_to_cpu(leaf->hdr.count)-1].hashval));
2325 * Add a trace buffer entry for the arguments given to the routine,
2326 * generic form.
2328 void
2329 xfs_attr_trace_enter(int type, char *where,
2330 struct xfs_attr_list_context *context,
2331 __psunsigned_t a13, __psunsigned_t a14,
2332 __psunsigned_t a15)
2334 ASSERT(xfs_attr_trace_buf);
2335 ktrace_enter(xfs_attr_trace_buf, (void *)((__psunsigned_t)type),
2336 (void *)((__psunsigned_t)where),
2337 (void *)((__psunsigned_t)context->dp),
2338 (void *)((__psunsigned_t)context->cursor->hashval),
2339 (void *)((__psunsigned_t)context->cursor->blkno),
2340 (void *)((__psunsigned_t)context->cursor->offset),
2341 (void *)((__psunsigned_t)context->alist),
2342 (void *)((__psunsigned_t)context->bufsize),
2343 (void *)((__psunsigned_t)context->count),
2344 (void *)((__psunsigned_t)context->firstu),
2345 NULL,
2346 (void *)((__psunsigned_t)context->dupcnt),
2347 (void *)((__psunsigned_t)context->flags),
2348 (void *)a13, (void *)a14, (void *)a15);
2350 #endif /* XFS_ATTR_TRACE */