xfs: create a shared header file for format-related information
[deliverable/linux.git] / fs / xfs / xfs_attr.c
1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_format.h"
21 #include "xfs_shared.h"
22 #include "xfs_bit.h"
23 #include "xfs_log.h"
24 #include "xfs_trans.h"
25 #include "xfs_trans_priv.h"
26 #include "xfs_sb.h"
27 #include "xfs_ag.h"
28 #include "xfs_mount.h"
29 #include "xfs_da_btree.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_attr_sf.h"
32 #include "xfs_dinode.h"
33 #include "xfs_inode.h"
34 #include "xfs_alloc.h"
35 #include "xfs_inode_item.h"
36 #include "xfs_bmap.h"
37 #include "xfs_bmap_util.h"
38 #include "xfs_attr.h"
39 #include "xfs_attr_leaf.h"
40 #include "xfs_attr_remote.h"
41 #include "xfs_error.h"
42 #include "xfs_quota.h"
43 #include "xfs_trans_space.h"
44 #include "xfs_trace.h"
45
46 /*
47 * xfs_attr.c
48 *
49 * Provide the external interfaces to manage attribute lists.
50 */
51
52 /*========================================================================
53 * Function prototypes for the kernel.
54 *========================================================================*/
55
56 /*
57 * Internal routines when attribute list fits inside the inode.
58 */
59 STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
60
61 /*
62 * Internal routines when attribute list is one block.
63 */
64 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
65 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
66 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
67
68 /*
69 * Internal routines when attribute list is more than one block.
70 */
71 STATIC int xfs_attr_node_get(xfs_da_args_t *args);
72 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
73 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
74 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
75 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
76
77
78 STATIC int
79 xfs_attr_name_to_xname(
80 struct xfs_name *xname,
81 const unsigned char *aname)
82 {
83 if (!aname)
84 return EINVAL;
85 xname->name = aname;
86 xname->len = strlen((char *)aname);
87 if (xname->len >= MAXNAMELEN)
88 return EFAULT; /* match IRIX behaviour */
89
90 return 0;
91 }
92
93 int
94 xfs_inode_hasattr(
95 struct xfs_inode *ip)
96 {
97 if (!XFS_IFORK_Q(ip) ||
98 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
99 ip->i_d.di_anextents == 0))
100 return 0;
101 return 1;
102 }
103
104 /*========================================================================
105 * Overall external interface routines.
106 *========================================================================*/
107
108 STATIC int
109 xfs_attr_get_int(
110 struct xfs_inode *ip,
111 struct xfs_name *name,
112 unsigned char *value,
113 int *valuelenp,
114 int flags)
115 {
116 xfs_da_args_t args;
117 int error;
118
119 if (!xfs_inode_hasattr(ip))
120 return ENOATTR;
121
122 /*
123 * Fill in the arg structure for this request.
124 */
125 memset((char *)&args, 0, sizeof(args));
126 args.name = name->name;
127 args.namelen = name->len;
128 args.value = value;
129 args.valuelen = *valuelenp;
130 args.flags = flags;
131 args.hashval = xfs_da_hashname(args.name, args.namelen);
132 args.dp = ip;
133 args.whichfork = XFS_ATTR_FORK;
134
135 /*
136 * Decide on what work routines to call based on the inode size.
137 */
138 if (ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
139 error = xfs_attr_shortform_getvalue(&args);
140 } else if (xfs_bmap_one_block(ip, XFS_ATTR_FORK)) {
141 error = xfs_attr_leaf_get(&args);
142 } else {
143 error = xfs_attr_node_get(&args);
144 }
145
146 /*
147 * Return the number of bytes in the value to the caller.
148 */
149 *valuelenp = args.valuelen;
150
151 if (error == EEXIST)
152 error = 0;
153 return(error);
154 }
155
156 int
157 xfs_attr_get(
158 xfs_inode_t *ip,
159 const unsigned char *name,
160 unsigned char *value,
161 int *valuelenp,
162 int flags)
163 {
164 int error;
165 struct xfs_name xname;
166
167 XFS_STATS_INC(xs_attr_get);
168
169 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
170 return(EIO);
171
172 error = xfs_attr_name_to_xname(&xname, name);
173 if (error)
174 return error;
175
176 xfs_ilock(ip, XFS_ILOCK_SHARED);
177 error = xfs_attr_get_int(ip, &xname, value, valuelenp, flags);
178 xfs_iunlock(ip, XFS_ILOCK_SHARED);
179 return(error);
180 }
181
182 /*
183 * Calculate how many blocks we need for the new attribute,
184 */
185 STATIC int
186 xfs_attr_calc_size(
187 struct xfs_inode *ip,
188 int namelen,
189 int valuelen,
190 int *local)
191 {
192 struct xfs_mount *mp = ip->i_mount;
193 int size;
194 int nblks;
195
196 /*
197 * Determine space new attribute will use, and if it would be
198 * "local" or "remote" (note: local != inline).
199 */
200 size = xfs_attr_leaf_newentsize(namelen, valuelen,
201 mp->m_sb.sb_blocksize, local);
202
203 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
204 if (*local) {
205 if (size > (mp->m_sb.sb_blocksize >> 1)) {
206 /* Double split possible */
207 nblks *= 2;
208 }
209 } else {
210 /*
211 * Out of line attribute, cannot double split, but
212 * make room for the attribute value itself.
213 */
214 uint dblocks = XFS_B_TO_FSB(mp, valuelen);
215 nblks += dblocks;
216 nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
217 }
218
219 return nblks;
220 }
221
222 STATIC int
223 xfs_attr_set_int(
224 struct xfs_inode *dp,
225 struct xfs_name *name,
226 unsigned char *value,
227 int valuelen,
228 int flags)
229 {
230 xfs_da_args_t args;
231 xfs_fsblock_t firstblock;
232 xfs_bmap_free_t flist;
233 int error, err2, committed;
234 struct xfs_mount *mp = dp->i_mount;
235 struct xfs_trans_res tres;
236 int rsvd = (flags & ATTR_ROOT) != 0;
237 int local;
238
239 /*
240 * Attach the dquots to the inode.
241 */
242 error = xfs_qm_dqattach(dp, 0);
243 if (error)
244 return error;
245
246 /*
247 * If the inode doesn't have an attribute fork, add one.
248 * (inode must not be locked when we call this routine)
249 */
250 if (XFS_IFORK_Q(dp) == 0) {
251 int sf_size = sizeof(xfs_attr_sf_hdr_t) +
252 XFS_ATTR_SF_ENTSIZE_BYNAME(name->len, valuelen);
253
254 if ((error = xfs_bmap_add_attrfork(dp, sf_size, rsvd)))
255 return(error);
256 }
257
258 /*
259 * Fill in the arg structure for this request.
260 */
261 memset((char *)&args, 0, sizeof(args));
262 args.name = name->name;
263 args.namelen = name->len;
264 args.value = value;
265 args.valuelen = valuelen;
266 args.flags = flags;
267 args.hashval = xfs_da_hashname(args.name, args.namelen);
268 args.dp = dp;
269 args.firstblock = &firstblock;
270 args.flist = &flist;
271 args.whichfork = XFS_ATTR_FORK;
272 args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
273
274 /* Size is now blocks for attribute data */
275 args.total = xfs_attr_calc_size(dp, name->len, valuelen, &local);
276
277 /*
278 * Start our first transaction of the day.
279 *
280 * All future transactions during this code must be "chained" off
281 * this one via the trans_dup() call. All transactions will contain
282 * the inode, and the inode will always be marked with trans_ihold().
283 * Since the inode will be locked in all transactions, we must log
284 * the inode in every transaction to let it float upward through
285 * the log.
286 */
287 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
288
289 /*
290 * Root fork attributes can use reserved data blocks for this
291 * operation if necessary
292 */
293
294 if (rsvd)
295 args.trans->t_flags |= XFS_TRANS_RESERVE;
296
297 tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
298 M_RES(mp)->tr_attrsetrt.tr_logres * args.total;
299 tres.tr_logcount = XFS_ATTRSET_LOG_COUNT;
300 tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
301 error = xfs_trans_reserve(args.trans, &tres, args.total, 0);
302 if (error) {
303 xfs_trans_cancel(args.trans, 0);
304 return(error);
305 }
306 xfs_ilock(dp, XFS_ILOCK_EXCL);
307
308 error = xfs_trans_reserve_quota_nblks(args.trans, dp, args.total, 0,
309 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
310 XFS_QMOPT_RES_REGBLKS);
311 if (error) {
312 xfs_iunlock(dp, XFS_ILOCK_EXCL);
313 xfs_trans_cancel(args.trans, XFS_TRANS_RELEASE_LOG_RES);
314 return (error);
315 }
316
317 xfs_trans_ijoin(args.trans, dp, 0);
318
319 /*
320 * If the attribute list is non-existent or a shortform list,
321 * upgrade it to a single-leaf-block attribute list.
322 */
323 if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
324 ((dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS) &&
325 (dp->i_d.di_anextents == 0))) {
326
327 /*
328 * Build initial attribute list (if required).
329 */
330 if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
331 xfs_attr_shortform_create(&args);
332
333 /*
334 * Try to add the attr to the attribute list in
335 * the inode.
336 */
337 error = xfs_attr_shortform_addname(&args);
338 if (error != ENOSPC) {
339 /*
340 * Commit the shortform mods, and we're done.
341 * NOTE: this is also the error path (EEXIST, etc).
342 */
343 ASSERT(args.trans != NULL);
344
345 /*
346 * If this is a synchronous mount, make sure that
347 * the transaction goes to disk before returning
348 * to the user.
349 */
350 if (mp->m_flags & XFS_MOUNT_WSYNC) {
351 xfs_trans_set_sync(args.trans);
352 }
353
354 if (!error && (flags & ATTR_KERNOTIME) == 0) {
355 xfs_trans_ichgtime(args.trans, dp,
356 XFS_ICHGTIME_CHG);
357 }
358 err2 = xfs_trans_commit(args.trans,
359 XFS_TRANS_RELEASE_LOG_RES);
360 xfs_iunlock(dp, XFS_ILOCK_EXCL);
361
362 return(error == 0 ? err2 : error);
363 }
364
365 /*
366 * It won't fit in the shortform, transform to a leaf block.
367 * GROT: another possible req'mt for a double-split btree op.
368 */
369 xfs_bmap_init(args.flist, args.firstblock);
370 error = xfs_attr_shortform_to_leaf(&args);
371 if (!error) {
372 error = xfs_bmap_finish(&args.trans, args.flist,
373 &committed);
374 }
375 if (error) {
376 ASSERT(committed);
377 args.trans = NULL;
378 xfs_bmap_cancel(&flist);
379 goto out;
380 }
381
382 /*
383 * bmap_finish() may have committed the last trans and started
384 * a new one. We need the inode to be in all transactions.
385 */
386 if (committed)
387 xfs_trans_ijoin(args.trans, dp, 0);
388
389 /*
390 * Commit the leaf transformation. We'll need another (linked)
391 * transaction to add the new attribute to the leaf.
392 */
393
394 error = xfs_trans_roll(&args.trans, dp);
395 if (error)
396 goto out;
397
398 }
399
400 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
401 error = xfs_attr_leaf_addname(&args);
402 } else {
403 error = xfs_attr_node_addname(&args);
404 }
405 if (error) {
406 goto out;
407 }
408
409 /*
410 * If this is a synchronous mount, make sure that the
411 * transaction goes to disk before returning to the user.
412 */
413 if (mp->m_flags & XFS_MOUNT_WSYNC) {
414 xfs_trans_set_sync(args.trans);
415 }
416
417 if ((flags & ATTR_KERNOTIME) == 0)
418 xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
419
420 /*
421 * Commit the last in the sequence of transactions.
422 */
423 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
424 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES);
425 xfs_iunlock(dp, XFS_ILOCK_EXCL);
426
427 return(error);
428
429 out:
430 if (args.trans)
431 xfs_trans_cancel(args.trans,
432 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
433 xfs_iunlock(dp, XFS_ILOCK_EXCL);
434 return(error);
435 }
436
437 int
438 xfs_attr_set(
439 xfs_inode_t *dp,
440 const unsigned char *name,
441 unsigned char *value,
442 int valuelen,
443 int flags)
444 {
445 int error;
446 struct xfs_name xname;
447
448 XFS_STATS_INC(xs_attr_set);
449
450 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
451 return (EIO);
452
453 error = xfs_attr_name_to_xname(&xname, name);
454 if (error)
455 return error;
456
457 return xfs_attr_set_int(dp, &xname, value, valuelen, flags);
458 }
459
460 /*
461 * Generic handler routine to remove a name from an attribute list.
462 * Transitions attribute list from Btree to shortform as necessary.
463 */
464 STATIC int
465 xfs_attr_remove_int(xfs_inode_t *dp, struct xfs_name *name, int flags)
466 {
467 xfs_da_args_t args;
468 xfs_fsblock_t firstblock;
469 xfs_bmap_free_t flist;
470 int error;
471 xfs_mount_t *mp = dp->i_mount;
472
473 /*
474 * Fill in the arg structure for this request.
475 */
476 memset((char *)&args, 0, sizeof(args));
477 args.name = name->name;
478 args.namelen = name->len;
479 args.flags = flags;
480 args.hashval = xfs_da_hashname(args.name, args.namelen);
481 args.dp = dp;
482 args.firstblock = &firstblock;
483 args.flist = &flist;
484 args.total = 0;
485 args.whichfork = XFS_ATTR_FORK;
486
487 /*
488 * we have no control over the attribute names that userspace passes us
489 * to remove, so we have to allow the name lookup prior to attribute
490 * removal to fail.
491 */
492 args.op_flags = XFS_DA_OP_OKNOENT;
493
494 /*
495 * Attach the dquots to the inode.
496 */
497 error = xfs_qm_dqattach(dp, 0);
498 if (error)
499 return error;
500
501 /*
502 * Start our first transaction of the day.
503 *
504 * All future transactions during this code must be "chained" off
505 * this one via the trans_dup() call. All transactions will contain
506 * the inode, and the inode will always be marked with trans_ihold().
507 * Since the inode will be locked in all transactions, we must log
508 * the inode in every transaction to let it float upward through
509 * the log.
510 */
511 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
512
513 /*
514 * Root fork attributes can use reserved data blocks for this
515 * operation if necessary
516 */
517
518 if (flags & ATTR_ROOT)
519 args.trans->t_flags |= XFS_TRANS_RESERVE;
520
521 error = xfs_trans_reserve(args.trans, &M_RES(mp)->tr_attrrm,
522 XFS_ATTRRM_SPACE_RES(mp), 0);
523 if (error) {
524 xfs_trans_cancel(args.trans, 0);
525 return(error);
526 }
527
528 xfs_ilock(dp, XFS_ILOCK_EXCL);
529 /*
530 * No need to make quota reservations here. We expect to release some
531 * blocks not allocate in the common case.
532 */
533 xfs_trans_ijoin(args.trans, dp, 0);
534
535 /*
536 * Decide on what work routines to call based on the inode size.
537 */
538 if (!xfs_inode_hasattr(dp)) {
539 error = XFS_ERROR(ENOATTR);
540 goto out;
541 }
542 if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
543 ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
544 error = xfs_attr_shortform_remove(&args);
545 if (error) {
546 goto out;
547 }
548 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
549 error = xfs_attr_leaf_removename(&args);
550 } else {
551 error = xfs_attr_node_removename(&args);
552 }
553 if (error) {
554 goto out;
555 }
556
557 /*
558 * If this is a synchronous mount, make sure that the
559 * transaction goes to disk before returning to the user.
560 */
561 if (mp->m_flags & XFS_MOUNT_WSYNC) {
562 xfs_trans_set_sync(args.trans);
563 }
564
565 if ((flags & ATTR_KERNOTIME) == 0)
566 xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
567
568 /*
569 * Commit the last in the sequence of transactions.
570 */
571 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
572 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES);
573 xfs_iunlock(dp, XFS_ILOCK_EXCL);
574
575 return(error);
576
577 out:
578 if (args.trans)
579 xfs_trans_cancel(args.trans,
580 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
581 xfs_iunlock(dp, XFS_ILOCK_EXCL);
582 return(error);
583 }
584
585 int
586 xfs_attr_remove(
587 xfs_inode_t *dp,
588 const unsigned char *name,
589 int flags)
590 {
591 int error;
592 struct xfs_name xname;
593
594 XFS_STATS_INC(xs_attr_remove);
595
596 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
597 return (EIO);
598
599 error = xfs_attr_name_to_xname(&xname, name);
600 if (error)
601 return error;
602
603 xfs_ilock(dp, XFS_ILOCK_SHARED);
604 if (!xfs_inode_hasattr(dp)) {
605 xfs_iunlock(dp, XFS_ILOCK_SHARED);
606 return XFS_ERROR(ENOATTR);
607 }
608 xfs_iunlock(dp, XFS_ILOCK_SHARED);
609
610 return xfs_attr_remove_int(dp, &xname, flags);
611 }
612
613
614 /*========================================================================
615 * External routines when attribute list is inside the inode
616 *========================================================================*/
617
618 /*
619 * Add a name to the shortform attribute list structure
620 * This is the external routine.
621 */
622 STATIC int
623 xfs_attr_shortform_addname(xfs_da_args_t *args)
624 {
625 int newsize, forkoff, retval;
626
627 trace_xfs_attr_sf_addname(args);
628
629 retval = xfs_attr_shortform_lookup(args);
630 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
631 return(retval);
632 } else if (retval == EEXIST) {
633 if (args->flags & ATTR_CREATE)
634 return(retval);
635 retval = xfs_attr_shortform_remove(args);
636 ASSERT(retval == 0);
637 }
638
639 if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
640 args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
641 return(XFS_ERROR(ENOSPC));
642
643 newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
644 newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
645
646 forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
647 if (!forkoff)
648 return(XFS_ERROR(ENOSPC));
649
650 xfs_attr_shortform_add(args, forkoff);
651 return(0);
652 }
653
654
655 /*========================================================================
656 * External routines when attribute list is one block
657 *========================================================================*/
658
659 /*
660 * Add a name to the leaf attribute list structure
661 *
662 * This leaf block cannot have a "remote" value, we only call this routine
663 * if bmap_one_block() says there is only one block (ie: no remote blks).
664 */
665 STATIC int
666 xfs_attr_leaf_addname(xfs_da_args_t *args)
667 {
668 xfs_inode_t *dp;
669 struct xfs_buf *bp;
670 int retval, error, committed, forkoff;
671
672 trace_xfs_attr_leaf_addname(args);
673
674 /*
675 * Read the (only) block in the attribute list in.
676 */
677 dp = args->dp;
678 args->blkno = 0;
679 error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
680 if (error)
681 return error;
682
683 /*
684 * Look up the given attribute in the leaf block. Figure out if
685 * the given flags produce an error or call for an atomic rename.
686 */
687 retval = xfs_attr3_leaf_lookup_int(bp, args);
688 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
689 xfs_trans_brelse(args->trans, bp);
690 return retval;
691 } else if (retval == EEXIST) {
692 if (args->flags & ATTR_CREATE) { /* pure create op */
693 xfs_trans_brelse(args->trans, bp);
694 return retval;
695 }
696
697 trace_xfs_attr_leaf_replace(args);
698
699 args->op_flags |= XFS_DA_OP_RENAME; /* an atomic rename */
700 args->blkno2 = args->blkno; /* set 2nd entry info*/
701 args->index2 = args->index;
702 args->rmtblkno2 = args->rmtblkno;
703 args->rmtblkcnt2 = args->rmtblkcnt;
704 }
705
706 /*
707 * Add the attribute to the leaf block, transitioning to a Btree
708 * if required.
709 */
710 retval = xfs_attr3_leaf_add(bp, args);
711 if (retval == ENOSPC) {
712 /*
713 * Promote the attribute list to the Btree format, then
714 * Commit that transaction so that the node_addname() call
715 * can manage its own transactions.
716 */
717 xfs_bmap_init(args->flist, args->firstblock);
718 error = xfs_attr3_leaf_to_node(args);
719 if (!error) {
720 error = xfs_bmap_finish(&args->trans, args->flist,
721 &committed);
722 }
723 if (error) {
724 ASSERT(committed);
725 args->trans = NULL;
726 xfs_bmap_cancel(args->flist);
727 return(error);
728 }
729
730 /*
731 * bmap_finish() may have committed the last trans and started
732 * a new one. We need the inode to be in all transactions.
733 */
734 if (committed)
735 xfs_trans_ijoin(args->trans, dp, 0);
736
737 /*
738 * Commit the current trans (including the inode) and start
739 * a new one.
740 */
741 error = xfs_trans_roll(&args->trans, dp);
742 if (error)
743 return (error);
744
745 /*
746 * Fob the whole rest of the problem off on the Btree code.
747 */
748 error = xfs_attr_node_addname(args);
749 return(error);
750 }
751
752 /*
753 * Commit the transaction that added the attr name so that
754 * later routines can manage their own transactions.
755 */
756 error = xfs_trans_roll(&args->trans, dp);
757 if (error)
758 return (error);
759
760 /*
761 * If there was an out-of-line value, allocate the blocks we
762 * identified for its storage and copy the value. This is done
763 * after we create the attribute so that we don't overflow the
764 * maximum size of a transaction and/or hit a deadlock.
765 */
766 if (args->rmtblkno > 0) {
767 error = xfs_attr_rmtval_set(args);
768 if (error)
769 return(error);
770 }
771
772 /*
773 * If this is an atomic rename operation, we must "flip" the
774 * incomplete flags on the "new" and "old" attribute/value pairs
775 * so that one disappears and one appears atomically. Then we
776 * must remove the "old" attribute/value pair.
777 */
778 if (args->op_flags & XFS_DA_OP_RENAME) {
779 /*
780 * In a separate transaction, set the incomplete flag on the
781 * "old" attr and clear the incomplete flag on the "new" attr.
782 */
783 error = xfs_attr3_leaf_flipflags(args);
784 if (error)
785 return(error);
786
787 /*
788 * Dismantle the "old" attribute/value pair by removing
789 * a "remote" value (if it exists).
790 */
791 args->index = args->index2;
792 args->blkno = args->blkno2;
793 args->rmtblkno = args->rmtblkno2;
794 args->rmtblkcnt = args->rmtblkcnt2;
795 if (args->rmtblkno) {
796 error = xfs_attr_rmtval_remove(args);
797 if (error)
798 return(error);
799 }
800
801 /*
802 * Read in the block containing the "old" attr, then
803 * remove the "old" attr from that block (neat, huh!)
804 */
805 error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
806 -1, &bp);
807 if (error)
808 return error;
809
810 xfs_attr3_leaf_remove(bp, args);
811
812 /*
813 * If the result is small enough, shrink it all into the inode.
814 */
815 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
816 xfs_bmap_init(args->flist, args->firstblock);
817 error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
818 /* bp is gone due to xfs_da_shrink_inode */
819 if (!error) {
820 error = xfs_bmap_finish(&args->trans,
821 args->flist,
822 &committed);
823 }
824 if (error) {
825 ASSERT(committed);
826 args->trans = NULL;
827 xfs_bmap_cancel(args->flist);
828 return(error);
829 }
830
831 /*
832 * bmap_finish() may have committed the last trans
833 * and started a new one. We need the inode to be
834 * in all transactions.
835 */
836 if (committed)
837 xfs_trans_ijoin(args->trans, dp, 0);
838 }
839
840 /*
841 * Commit the remove and start the next trans in series.
842 */
843 error = xfs_trans_roll(&args->trans, dp);
844
845 } else if (args->rmtblkno > 0) {
846 /*
847 * Added a "remote" value, just clear the incomplete flag.
848 */
849 error = xfs_attr3_leaf_clearflag(args);
850 }
851 return error;
852 }
853
854 /*
855 * Remove a name from the leaf attribute list structure
856 *
857 * This leaf block cannot have a "remote" value, we only call this routine
858 * if bmap_one_block() says there is only one block (ie: no remote blks).
859 */
860 STATIC int
861 xfs_attr_leaf_removename(xfs_da_args_t *args)
862 {
863 xfs_inode_t *dp;
864 struct xfs_buf *bp;
865 int error, committed, forkoff;
866
867 trace_xfs_attr_leaf_removename(args);
868
869 /*
870 * Remove the attribute.
871 */
872 dp = args->dp;
873 args->blkno = 0;
874 error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
875 if (error)
876 return error;
877
878 error = xfs_attr3_leaf_lookup_int(bp, args);
879 if (error == ENOATTR) {
880 xfs_trans_brelse(args->trans, bp);
881 return error;
882 }
883
884 xfs_attr3_leaf_remove(bp, args);
885
886 /*
887 * If the result is small enough, shrink it all into the inode.
888 */
889 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
890 xfs_bmap_init(args->flist, args->firstblock);
891 error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
892 /* bp is gone due to xfs_da_shrink_inode */
893 if (!error) {
894 error = xfs_bmap_finish(&args->trans, args->flist,
895 &committed);
896 }
897 if (error) {
898 ASSERT(committed);
899 args->trans = NULL;
900 xfs_bmap_cancel(args->flist);
901 return error;
902 }
903
904 /*
905 * bmap_finish() may have committed the last trans and started
906 * a new one. We need the inode to be in all transactions.
907 */
908 if (committed)
909 xfs_trans_ijoin(args->trans, dp, 0);
910 }
911 return 0;
912 }
913
914 /*
915 * Look up a name in a leaf attribute list structure.
916 *
917 * This leaf block cannot have a "remote" value, we only call this routine
918 * if bmap_one_block() says there is only one block (ie: no remote blks).
919 */
920 STATIC int
921 xfs_attr_leaf_get(xfs_da_args_t *args)
922 {
923 struct xfs_buf *bp;
924 int error;
925
926 trace_xfs_attr_leaf_get(args);
927
928 args->blkno = 0;
929 error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
930 if (error)
931 return error;
932
933 error = xfs_attr3_leaf_lookup_int(bp, args);
934 if (error != EEXIST) {
935 xfs_trans_brelse(args->trans, bp);
936 return error;
937 }
938 error = xfs_attr3_leaf_getvalue(bp, args);
939 xfs_trans_brelse(args->trans, bp);
940 if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
941 error = xfs_attr_rmtval_get(args);
942 }
943 return error;
944 }
945
946 /*========================================================================
947 * External routines when attribute list size > XFS_LBSIZE(mp).
948 *========================================================================*/
949
950 /*
951 * Add a name to a Btree-format attribute list.
952 *
953 * This will involve walking down the Btree, and may involve splitting
954 * leaf nodes and even splitting intermediate nodes up to and including
955 * the root node (a special case of an intermediate node).
956 *
957 * "Remote" attribute values confuse the issue and atomic rename operations
958 * add a whole extra layer of confusion on top of that.
959 */
960 STATIC int
961 xfs_attr_node_addname(xfs_da_args_t *args)
962 {
963 xfs_da_state_t *state;
964 xfs_da_state_blk_t *blk;
965 xfs_inode_t *dp;
966 xfs_mount_t *mp;
967 int committed, retval, error;
968
969 trace_xfs_attr_node_addname(args);
970
971 /*
972 * Fill in bucket of arguments/results/context to carry around.
973 */
974 dp = args->dp;
975 mp = dp->i_mount;
976 restart:
977 state = xfs_da_state_alloc();
978 state->args = args;
979 state->mp = mp;
980 state->blocksize = state->mp->m_sb.sb_blocksize;
981 state->node_ents = state->mp->m_attr_node_ents;
982
983 /*
984 * Search to see if name already exists, and get back a pointer
985 * to where it should go.
986 */
987 error = xfs_da3_node_lookup_int(state, &retval);
988 if (error)
989 goto out;
990 blk = &state->path.blk[ state->path.active-1 ];
991 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
992 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
993 goto out;
994 } else if (retval == EEXIST) {
995 if (args->flags & ATTR_CREATE)
996 goto out;
997
998 trace_xfs_attr_node_replace(args);
999
1000 args->op_flags |= XFS_DA_OP_RENAME; /* atomic rename op */
1001 args->blkno2 = args->blkno; /* set 2nd entry info*/
1002 args->index2 = args->index;
1003 args->rmtblkno2 = args->rmtblkno;
1004 args->rmtblkcnt2 = args->rmtblkcnt;
1005 args->rmtblkno = 0;
1006 args->rmtblkcnt = 0;
1007 }
1008
1009 retval = xfs_attr3_leaf_add(blk->bp, state->args);
1010 if (retval == ENOSPC) {
1011 if (state->path.active == 1) {
1012 /*
1013 * Its really a single leaf node, but it had
1014 * out-of-line values so it looked like it *might*
1015 * have been a b-tree.
1016 */
1017 xfs_da_state_free(state);
1018 state = NULL;
1019 xfs_bmap_init(args->flist, args->firstblock);
1020 error = xfs_attr3_leaf_to_node(args);
1021 if (!error) {
1022 error = xfs_bmap_finish(&args->trans,
1023 args->flist,
1024 &committed);
1025 }
1026 if (error) {
1027 ASSERT(committed);
1028 args->trans = NULL;
1029 xfs_bmap_cancel(args->flist);
1030 goto out;
1031 }
1032
1033 /*
1034 * bmap_finish() may have committed the last trans
1035 * and started a new one. We need the inode to be
1036 * in all transactions.
1037 */
1038 if (committed)
1039 xfs_trans_ijoin(args->trans, dp, 0);
1040
1041 /*
1042 * Commit the node conversion and start the next
1043 * trans in the chain.
1044 */
1045 error = xfs_trans_roll(&args->trans, dp);
1046 if (error)
1047 goto out;
1048
1049 goto restart;
1050 }
1051
1052 /*
1053 * Split as many Btree elements as required.
1054 * This code tracks the new and old attr's location
1055 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1056 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1057 */
1058 xfs_bmap_init(args->flist, args->firstblock);
1059 error = xfs_da3_split(state);
1060 if (!error) {
1061 error = xfs_bmap_finish(&args->trans, args->flist,
1062 &committed);
1063 }
1064 if (error) {
1065 ASSERT(committed);
1066 args->trans = NULL;
1067 xfs_bmap_cancel(args->flist);
1068 goto out;
1069 }
1070
1071 /*
1072 * bmap_finish() may have committed the last trans and started
1073 * a new one. We need the inode to be in all transactions.
1074 */
1075 if (committed)
1076 xfs_trans_ijoin(args->trans, dp, 0);
1077 } else {
1078 /*
1079 * Addition succeeded, update Btree hashvals.
1080 */
1081 xfs_da3_fixhashpath(state, &state->path);
1082 }
1083
1084 /*
1085 * Kill the state structure, we're done with it and need to
1086 * allow the buffers to come back later.
1087 */
1088 xfs_da_state_free(state);
1089 state = NULL;
1090
1091 /*
1092 * Commit the leaf addition or btree split and start the next
1093 * trans in the chain.
1094 */
1095 error = xfs_trans_roll(&args->trans, dp);
1096 if (error)
1097 goto out;
1098
1099 /*
1100 * If there was an out-of-line value, allocate the blocks we
1101 * identified for its storage and copy the value. This is done
1102 * after we create the attribute so that we don't overflow the
1103 * maximum size of a transaction and/or hit a deadlock.
1104 */
1105 if (args->rmtblkno > 0) {
1106 error = xfs_attr_rmtval_set(args);
1107 if (error)
1108 return(error);
1109 }
1110
1111 /*
1112 * If this is an atomic rename operation, we must "flip" the
1113 * incomplete flags on the "new" and "old" attribute/value pairs
1114 * so that one disappears and one appears atomically. Then we
1115 * must remove the "old" attribute/value pair.
1116 */
1117 if (args->op_flags & XFS_DA_OP_RENAME) {
1118 /*
1119 * In a separate transaction, set the incomplete flag on the
1120 * "old" attr and clear the incomplete flag on the "new" attr.
1121 */
1122 error = xfs_attr3_leaf_flipflags(args);
1123 if (error)
1124 goto out;
1125
1126 /*
1127 * Dismantle the "old" attribute/value pair by removing
1128 * a "remote" value (if it exists).
1129 */
1130 args->index = args->index2;
1131 args->blkno = args->blkno2;
1132 args->rmtblkno = args->rmtblkno2;
1133 args->rmtblkcnt = args->rmtblkcnt2;
1134 if (args->rmtblkno) {
1135 error = xfs_attr_rmtval_remove(args);
1136 if (error)
1137 return(error);
1138 }
1139
1140 /*
1141 * Re-find the "old" attribute entry after any split ops.
1142 * The INCOMPLETE flag means that we will find the "old"
1143 * attr, not the "new" one.
1144 */
1145 args->flags |= XFS_ATTR_INCOMPLETE;
1146 state = xfs_da_state_alloc();
1147 state->args = args;
1148 state->mp = mp;
1149 state->blocksize = state->mp->m_sb.sb_blocksize;
1150 state->node_ents = state->mp->m_attr_node_ents;
1151 state->inleaf = 0;
1152 error = xfs_da3_node_lookup_int(state, &retval);
1153 if (error)
1154 goto out;
1155
1156 /*
1157 * Remove the name and update the hashvals in the tree.
1158 */
1159 blk = &state->path.blk[ state->path.active-1 ];
1160 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1161 error = xfs_attr3_leaf_remove(blk->bp, args);
1162 xfs_da3_fixhashpath(state, &state->path);
1163
1164 /*
1165 * Check to see if the tree needs to be collapsed.
1166 */
1167 if (retval && (state->path.active > 1)) {
1168 xfs_bmap_init(args->flist, args->firstblock);
1169 error = xfs_da3_join(state);
1170 if (!error) {
1171 error = xfs_bmap_finish(&args->trans,
1172 args->flist,
1173 &committed);
1174 }
1175 if (error) {
1176 ASSERT(committed);
1177 args->trans = NULL;
1178 xfs_bmap_cancel(args->flist);
1179 goto out;
1180 }
1181
1182 /*
1183 * bmap_finish() may have committed the last trans
1184 * and started a new one. We need the inode to be
1185 * in all transactions.
1186 */
1187 if (committed)
1188 xfs_trans_ijoin(args->trans, dp, 0);
1189 }
1190
1191 /*
1192 * Commit and start the next trans in the chain.
1193 */
1194 error = xfs_trans_roll(&args->trans, dp);
1195 if (error)
1196 goto out;
1197
1198 } else if (args->rmtblkno > 0) {
1199 /*
1200 * Added a "remote" value, just clear the incomplete flag.
1201 */
1202 error = xfs_attr3_leaf_clearflag(args);
1203 if (error)
1204 goto out;
1205 }
1206 retval = error = 0;
1207
1208 out:
1209 if (state)
1210 xfs_da_state_free(state);
1211 if (error)
1212 return(error);
1213 return(retval);
1214 }
1215
1216 /*
1217 * Remove a name from a B-tree attribute list.
1218 *
1219 * This will involve walking down the Btree, and may involve joining
1220 * leaf nodes and even joining intermediate nodes up to and including
1221 * the root node (a special case of an intermediate node).
1222 */
1223 STATIC int
1224 xfs_attr_node_removename(xfs_da_args_t *args)
1225 {
1226 xfs_da_state_t *state;
1227 xfs_da_state_blk_t *blk;
1228 xfs_inode_t *dp;
1229 struct xfs_buf *bp;
1230 int retval, error, committed, forkoff;
1231
1232 trace_xfs_attr_node_removename(args);
1233
1234 /*
1235 * Tie a string around our finger to remind us where we are.
1236 */
1237 dp = args->dp;
1238 state = xfs_da_state_alloc();
1239 state->args = args;
1240 state->mp = dp->i_mount;
1241 state->blocksize = state->mp->m_sb.sb_blocksize;
1242 state->node_ents = state->mp->m_attr_node_ents;
1243
1244 /*
1245 * Search to see if name exists, and get back a pointer to it.
1246 */
1247 error = xfs_da3_node_lookup_int(state, &retval);
1248 if (error || (retval != EEXIST)) {
1249 if (error == 0)
1250 error = retval;
1251 goto out;
1252 }
1253
1254 /*
1255 * If there is an out-of-line value, de-allocate the blocks.
1256 * This is done before we remove the attribute so that we don't
1257 * overflow the maximum size of a transaction and/or hit a deadlock.
1258 */
1259 blk = &state->path.blk[ state->path.active-1 ];
1260 ASSERT(blk->bp != NULL);
1261 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1262 if (args->rmtblkno > 0) {
1263 /*
1264 * Fill in disk block numbers in the state structure
1265 * so that we can get the buffers back after we commit
1266 * several transactions in the following calls.
1267 */
1268 error = xfs_attr_fillstate(state);
1269 if (error)
1270 goto out;
1271
1272 /*
1273 * Mark the attribute as INCOMPLETE, then bunmapi() the
1274 * remote value.
1275 */
1276 error = xfs_attr3_leaf_setflag(args);
1277 if (error)
1278 goto out;
1279 error = xfs_attr_rmtval_remove(args);
1280 if (error)
1281 goto out;
1282
1283 /*
1284 * Refill the state structure with buffers, the prior calls
1285 * released our buffers.
1286 */
1287 error = xfs_attr_refillstate(state);
1288 if (error)
1289 goto out;
1290 }
1291
1292 /*
1293 * Remove the name and update the hashvals in the tree.
1294 */
1295 blk = &state->path.blk[ state->path.active-1 ];
1296 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1297 retval = xfs_attr3_leaf_remove(blk->bp, args);
1298 xfs_da3_fixhashpath(state, &state->path);
1299
1300 /*
1301 * Check to see if the tree needs to be collapsed.
1302 */
1303 if (retval && (state->path.active > 1)) {
1304 xfs_bmap_init(args->flist, args->firstblock);
1305 error = xfs_da3_join(state);
1306 if (!error) {
1307 error = xfs_bmap_finish(&args->trans, args->flist,
1308 &committed);
1309 }
1310 if (error) {
1311 ASSERT(committed);
1312 args->trans = NULL;
1313 xfs_bmap_cancel(args->flist);
1314 goto out;
1315 }
1316
1317 /*
1318 * bmap_finish() may have committed the last trans and started
1319 * a new one. We need the inode to be in all transactions.
1320 */
1321 if (committed)
1322 xfs_trans_ijoin(args->trans, dp, 0);
1323
1324 /*
1325 * Commit the Btree join operation and start a new trans.
1326 */
1327 error = xfs_trans_roll(&args->trans, dp);
1328 if (error)
1329 goto out;
1330 }
1331
1332 /*
1333 * If the result is small enough, push it all into the inode.
1334 */
1335 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1336 /*
1337 * Have to get rid of the copy of this dabuf in the state.
1338 */
1339 ASSERT(state->path.active == 1);
1340 ASSERT(state->path.blk[0].bp);
1341 state->path.blk[0].bp = NULL;
1342
1343 error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
1344 if (error)
1345 goto out;
1346
1347 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1348 xfs_bmap_init(args->flist, args->firstblock);
1349 error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
1350 /* bp is gone due to xfs_da_shrink_inode */
1351 if (!error) {
1352 error = xfs_bmap_finish(&args->trans,
1353 args->flist,
1354 &committed);
1355 }
1356 if (error) {
1357 ASSERT(committed);
1358 args->trans = NULL;
1359 xfs_bmap_cancel(args->flist);
1360 goto out;
1361 }
1362
1363 /*
1364 * bmap_finish() may have committed the last trans
1365 * and started a new one. We need the inode to be
1366 * in all transactions.
1367 */
1368 if (committed)
1369 xfs_trans_ijoin(args->trans, dp, 0);
1370 } else
1371 xfs_trans_brelse(args->trans, bp);
1372 }
1373 error = 0;
1374
1375 out:
1376 xfs_da_state_free(state);
1377 return(error);
1378 }
1379
1380 /*
1381 * Fill in the disk block numbers in the state structure for the buffers
1382 * that are attached to the state structure.
1383 * This is done so that we can quickly reattach ourselves to those buffers
1384 * after some set of transaction commits have released these buffers.
1385 */
1386 STATIC int
1387 xfs_attr_fillstate(xfs_da_state_t *state)
1388 {
1389 xfs_da_state_path_t *path;
1390 xfs_da_state_blk_t *blk;
1391 int level;
1392
1393 trace_xfs_attr_fillstate(state->args);
1394
1395 /*
1396 * Roll down the "path" in the state structure, storing the on-disk
1397 * block number for those buffers in the "path".
1398 */
1399 path = &state->path;
1400 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1401 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1402 if (blk->bp) {
1403 blk->disk_blkno = XFS_BUF_ADDR(blk->bp);
1404 blk->bp = NULL;
1405 } else {
1406 blk->disk_blkno = 0;
1407 }
1408 }
1409
1410 /*
1411 * Roll down the "altpath" in the state structure, storing the on-disk
1412 * block number for those buffers in the "altpath".
1413 */
1414 path = &state->altpath;
1415 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1416 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1417 if (blk->bp) {
1418 blk->disk_blkno = XFS_BUF_ADDR(blk->bp);
1419 blk->bp = NULL;
1420 } else {
1421 blk->disk_blkno = 0;
1422 }
1423 }
1424
1425 return(0);
1426 }
1427
1428 /*
1429 * Reattach the buffers to the state structure based on the disk block
1430 * numbers stored in the state structure.
1431 * This is done after some set of transaction commits have released those
1432 * buffers from our grip.
1433 */
1434 STATIC int
1435 xfs_attr_refillstate(xfs_da_state_t *state)
1436 {
1437 xfs_da_state_path_t *path;
1438 xfs_da_state_blk_t *blk;
1439 int level, error;
1440
1441 trace_xfs_attr_refillstate(state->args);
1442
1443 /*
1444 * Roll down the "path" in the state structure, storing the on-disk
1445 * block number for those buffers in the "path".
1446 */
1447 path = &state->path;
1448 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1449 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1450 if (blk->disk_blkno) {
1451 error = xfs_da3_node_read(state->args->trans,
1452 state->args->dp,
1453 blk->blkno, blk->disk_blkno,
1454 &blk->bp, XFS_ATTR_FORK);
1455 if (error)
1456 return(error);
1457 } else {
1458 blk->bp = NULL;
1459 }
1460 }
1461
1462 /*
1463 * Roll down the "altpath" in the state structure, storing the on-disk
1464 * block number for those buffers in the "altpath".
1465 */
1466 path = &state->altpath;
1467 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1468 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1469 if (blk->disk_blkno) {
1470 error = xfs_da3_node_read(state->args->trans,
1471 state->args->dp,
1472 blk->blkno, blk->disk_blkno,
1473 &blk->bp, XFS_ATTR_FORK);
1474 if (error)
1475 return(error);
1476 } else {
1477 blk->bp = NULL;
1478 }
1479 }
1480
1481 return(0);
1482 }
1483
1484 /*
1485 * Look up a filename in a node attribute list.
1486 *
1487 * This routine gets called for any attribute fork that has more than one
1488 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1489 * "remote" values taking up more blocks.
1490 */
1491 STATIC int
1492 xfs_attr_node_get(xfs_da_args_t *args)
1493 {
1494 xfs_da_state_t *state;
1495 xfs_da_state_blk_t *blk;
1496 int error, retval;
1497 int i;
1498
1499 trace_xfs_attr_node_get(args);
1500
1501 state = xfs_da_state_alloc();
1502 state->args = args;
1503 state->mp = args->dp->i_mount;
1504 state->blocksize = state->mp->m_sb.sb_blocksize;
1505 state->node_ents = state->mp->m_attr_node_ents;
1506
1507 /*
1508 * Search to see if name exists, and get back a pointer to it.
1509 */
1510 error = xfs_da3_node_lookup_int(state, &retval);
1511 if (error) {
1512 retval = error;
1513 } else if (retval == EEXIST) {
1514 blk = &state->path.blk[ state->path.active-1 ];
1515 ASSERT(blk->bp != NULL);
1516 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1517
1518 /*
1519 * Get the value, local or "remote"
1520 */
1521 retval = xfs_attr3_leaf_getvalue(blk->bp, args);
1522 if (!retval && (args->rmtblkno > 0)
1523 && !(args->flags & ATTR_KERNOVAL)) {
1524 retval = xfs_attr_rmtval_get(args);
1525 }
1526 }
1527
1528 /*
1529 * If not in a transaction, we have to release all the buffers.
1530 */
1531 for (i = 0; i < state->path.active; i++) {
1532 xfs_trans_brelse(args->trans, state->path.blk[i].bp);
1533 state->path.blk[i].bp = NULL;
1534 }
1535
1536 xfs_da_state_free(state);
1537 return(retval);
1538 }
This page took 0.116509 seconds and 5 git commands to generate.