xfs_attr.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  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_shared.h"
  21. #include "xfs_format.h"
  22. #include "xfs_log_format.h"
  23. #include "xfs_trans_resv.h"
  24. #include "xfs_bit.h"
  25. #include "xfs_mount.h"
  26. #include "xfs_defer.h"
  27. #include "xfs_da_format.h"
  28. #include "xfs_da_btree.h"
  29. #include "xfs_attr_sf.h"
  30. #include "xfs_inode.h"
  31. #include "xfs_alloc.h"
  32. #include "xfs_trans.h"
  33. #include "xfs_inode_item.h"
  34. #include "xfs_bmap.h"
  35. #include "xfs_bmap_util.h"
  36. #include "xfs_bmap_btree.h"
  37. #include "xfs_attr.h"
  38. #include "xfs_attr_leaf.h"
  39. #include "xfs_attr_remote.h"
  40. #include "xfs_error.h"
  41. #include "xfs_quota.h"
  42. #include "xfs_trans_space.h"
  43. #include "xfs_trace.h"
  44. /*
  45. * xfs_attr.c
  46. *
  47. * Provide the external interfaces to manage attribute lists.
  48. */
  49. /*========================================================================
  50. * Function prototypes for the kernel.
  51. *========================================================================*/
  52. /*
  53. * Internal routines when attribute list fits inside the inode.
  54. */
  55. STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
  56. /*
  57. * Internal routines when attribute list is one block.
  58. */
  59. STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
  60. STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
  61. STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
  62. /*
  63. * Internal routines when attribute list is more than one block.
  64. */
  65. STATIC int xfs_attr_node_get(xfs_da_args_t *args);
  66. STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
  67. STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
  68. STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
  69. STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
  70. STATIC int
  71. xfs_attr_args_init(
  72. struct xfs_da_args *args,
  73. struct xfs_inode *dp,
  74. const unsigned char *name,
  75. int flags)
  76. {
  77. if (!name)
  78. return -EINVAL;
  79. memset(args, 0, sizeof(*args));
  80. args->geo = dp->i_mount->m_attr_geo;
  81. args->whichfork = XFS_ATTR_FORK;
  82. args->dp = dp;
  83. args->flags = flags;
  84. args->name = name;
  85. args->namelen = strlen((const char *)name);
  86. if (args->namelen >= MAXNAMELEN)
  87. return -EFAULT; /* match IRIX behaviour */
  88. args->hashval = xfs_da_hashname(args->name, args->namelen);
  89. return 0;
  90. }
  91. int
  92. xfs_inode_hasattr(
  93. struct xfs_inode *ip)
  94. {
  95. if (!XFS_IFORK_Q(ip) ||
  96. (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
  97. ip->i_d.di_anextents == 0))
  98. return 0;
  99. return 1;
  100. }
  101. /*========================================================================
  102. * Overall external interface routines.
  103. *========================================================================*/
  104. /* Retrieve an extended attribute and its value. Must have ilock. */
  105. int
  106. xfs_attr_get_ilocked(
  107. struct xfs_inode *ip,
  108. struct xfs_da_args *args)
  109. {
  110. ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
  111. if (!xfs_inode_hasattr(ip))
  112. return -ENOATTR;
  113. else if (ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL)
  114. return xfs_attr_shortform_getvalue(args);
  115. else if (xfs_bmap_one_block(ip, XFS_ATTR_FORK))
  116. return xfs_attr_leaf_get(args);
  117. else
  118. return xfs_attr_node_get(args);
  119. }
  120. /* Retrieve an extended attribute by name, and its value. */
  121. int
  122. xfs_attr_get(
  123. struct xfs_inode *ip,
  124. const unsigned char *name,
  125. unsigned char *value,
  126. int *valuelenp,
  127. int flags)
  128. {
  129. struct xfs_da_args args;
  130. uint lock_mode;
  131. int error;
  132. XFS_STATS_INC(ip->i_mount, xs_attr_get);
  133. if (XFS_FORCED_SHUTDOWN(ip->i_mount))
  134. return -EIO;
  135. error = xfs_attr_args_init(&args, ip, name, flags);
  136. if (error)
  137. return error;
  138. args.value = value;
  139. args.valuelen = *valuelenp;
  140. /* Entirely possible to look up a name which doesn't exist */
  141. args.op_flags = XFS_DA_OP_OKNOENT;
  142. lock_mode = xfs_ilock_attr_map_shared(ip);
  143. error = xfs_attr_get_ilocked(ip, &args);
  144. xfs_iunlock(ip, lock_mode);
  145. *valuelenp = args.valuelen;
  146. return error == -EEXIST ? 0 : error;
  147. }
  148. /*
  149. * Calculate how many blocks we need for the new attribute,
  150. */
  151. STATIC int
  152. xfs_attr_calc_size(
  153. struct xfs_da_args *args,
  154. int *local)
  155. {
  156. struct xfs_mount *mp = args->dp->i_mount;
  157. int size;
  158. int nblks;
  159. /*
  160. * Determine space new attribute will use, and if it would be
  161. * "local" or "remote" (note: local != inline).
  162. */
  163. size = xfs_attr_leaf_newentsize(args, local);
  164. nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
  165. if (*local) {
  166. if (size > (args->geo->blksize / 2)) {
  167. /* Double split possible */
  168. nblks *= 2;
  169. }
  170. } else {
  171. /*
  172. * Out of line attribute, cannot double split, but
  173. * make room for the attribute value itself.
  174. */
  175. uint dblocks = xfs_attr3_rmt_blocks(mp, args->valuelen);
  176. nblks += dblocks;
  177. nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
  178. }
  179. return nblks;
  180. }
  181. int
  182. xfs_attr_set(
  183. struct xfs_inode *dp,
  184. const unsigned char *name,
  185. unsigned char *value,
  186. int valuelen,
  187. int flags)
  188. {
  189. struct xfs_mount *mp = dp->i_mount;
  190. struct xfs_da_args args;
  191. struct xfs_defer_ops dfops;
  192. struct xfs_trans_res tres;
  193. xfs_fsblock_t firstblock;
  194. int rsvd = (flags & ATTR_ROOT) != 0;
  195. int error, err2, local;
  196. XFS_STATS_INC(mp, xs_attr_set);
  197. if (XFS_FORCED_SHUTDOWN(dp->i_mount))
  198. return -EIO;
  199. error = xfs_attr_args_init(&args, dp, name, flags);
  200. if (error)
  201. return error;
  202. args.value = value;
  203. args.valuelen = valuelen;
  204. args.firstblock = &firstblock;
  205. args.dfops = &dfops;
  206. args.op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT;
  207. args.total = xfs_attr_calc_size(&args, &local);
  208. error = xfs_qm_dqattach(dp, 0);
  209. if (error)
  210. return error;
  211. /*
  212. * If the inode doesn't have an attribute fork, add one.
  213. * (inode must not be locked when we call this routine)
  214. */
  215. if (XFS_IFORK_Q(dp) == 0) {
  216. int sf_size = sizeof(xfs_attr_sf_hdr_t) +
  217. XFS_ATTR_SF_ENTSIZE_BYNAME(args.namelen, valuelen);
  218. error = xfs_bmap_add_attrfork(dp, sf_size, rsvd);
  219. if (error)
  220. return error;
  221. }
  222. tres.tr_logres = M_RES(mp)->tr_attrsetm.tr_logres +
  223. M_RES(mp)->tr_attrsetrt.tr_logres * args.total;
  224. tres.tr_logcount = XFS_ATTRSET_LOG_COUNT;
  225. tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
  226. /*
  227. * Root fork attributes can use reserved data blocks for this
  228. * operation if necessary
  229. */
  230. error = xfs_trans_alloc(mp, &tres, args.total, 0,
  231. rsvd ? XFS_TRANS_RESERVE : 0, &args.trans);
  232. if (error)
  233. return error;
  234. xfs_ilock(dp, XFS_ILOCK_EXCL);
  235. error = xfs_trans_reserve_quota_nblks(args.trans, dp, args.total, 0,
  236. rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
  237. XFS_QMOPT_RES_REGBLKS);
  238. if (error) {
  239. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  240. xfs_trans_cancel(args.trans);
  241. return error;
  242. }
  243. xfs_trans_ijoin(args.trans, dp, 0);
  244. /*
  245. * If the attribute list is non-existent or a shortform list,
  246. * upgrade it to a single-leaf-block attribute list.
  247. */
  248. if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
  249. (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
  250. dp->i_d.di_anextents == 0)) {
  251. /*
  252. * Build initial attribute list (if required).
  253. */
  254. if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
  255. xfs_attr_shortform_create(&args);
  256. /*
  257. * Try to add the attr to the attribute list in
  258. * the inode.
  259. */
  260. error = xfs_attr_shortform_addname(&args);
  261. if (error != -ENOSPC) {
  262. /*
  263. * Commit the shortform mods, and we're done.
  264. * NOTE: this is also the error path (EEXIST, etc).
  265. */
  266. ASSERT(args.trans != NULL);
  267. /*
  268. * If this is a synchronous mount, make sure that
  269. * the transaction goes to disk before returning
  270. * to the user.
  271. */
  272. if (mp->m_flags & XFS_MOUNT_WSYNC)
  273. xfs_trans_set_sync(args.trans);
  274. if (!error && (flags & ATTR_KERNOTIME) == 0) {
  275. xfs_trans_ichgtime(args.trans, dp,
  276. XFS_ICHGTIME_CHG);
  277. }
  278. err2 = xfs_trans_commit(args.trans);
  279. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  280. return error ? error : err2;
  281. }
  282. /*
  283. * It won't fit in the shortform, transform to a leaf block.
  284. * GROT: another possible req'mt for a double-split btree op.
  285. */
  286. xfs_defer_init(args.dfops, args.firstblock);
  287. error = xfs_attr_shortform_to_leaf(&args);
  288. if (error)
  289. goto out_defer_cancel;
  290. xfs_defer_ijoin(args.dfops, dp);
  291. error = xfs_defer_finish(&args.trans, args.dfops);
  292. if (error)
  293. goto out_defer_cancel;
  294. /*
  295. * Commit the leaf transformation. We'll need another (linked)
  296. * transaction to add the new attribute to the leaf.
  297. */
  298. error = xfs_trans_roll_inode(&args.trans, dp);
  299. if (error)
  300. goto out;
  301. }
  302. if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
  303. error = xfs_attr_leaf_addname(&args);
  304. else
  305. error = xfs_attr_node_addname(&args);
  306. if (error)
  307. goto out;
  308. /*
  309. * If this is a synchronous mount, make sure that the
  310. * transaction goes to disk before returning to the user.
  311. */
  312. if (mp->m_flags & XFS_MOUNT_WSYNC)
  313. xfs_trans_set_sync(args.trans);
  314. if ((flags & ATTR_KERNOTIME) == 0)
  315. xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
  316. /*
  317. * Commit the last in the sequence of transactions.
  318. */
  319. xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
  320. error = xfs_trans_commit(args.trans);
  321. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  322. return error;
  323. out_defer_cancel:
  324. xfs_defer_cancel(&dfops);
  325. args.trans = NULL;
  326. out:
  327. if (args.trans)
  328. xfs_trans_cancel(args.trans);
  329. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  330. return error;
  331. }
  332. /*
  333. * Generic handler routine to remove a name from an attribute list.
  334. * Transitions attribute list from Btree to shortform as necessary.
  335. */
  336. int
  337. xfs_attr_remove(
  338. struct xfs_inode *dp,
  339. const unsigned char *name,
  340. int flags)
  341. {
  342. struct xfs_mount *mp = dp->i_mount;
  343. struct xfs_da_args args;
  344. struct xfs_defer_ops dfops;
  345. xfs_fsblock_t firstblock;
  346. int error;
  347. XFS_STATS_INC(mp, xs_attr_remove);
  348. if (XFS_FORCED_SHUTDOWN(dp->i_mount))
  349. return -EIO;
  350. error = xfs_attr_args_init(&args, dp, name, flags);
  351. if (error)
  352. return error;
  353. args.firstblock = &firstblock;
  354. args.dfops = &dfops;
  355. /*
  356. * we have no control over the attribute names that userspace passes us
  357. * to remove, so we have to allow the name lookup prior to attribute
  358. * removal to fail.
  359. */
  360. args.op_flags = XFS_DA_OP_OKNOENT;
  361. error = xfs_qm_dqattach(dp, 0);
  362. if (error)
  363. return error;
  364. /*
  365. * Root fork attributes can use reserved data blocks for this
  366. * operation if necessary
  367. */
  368. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm,
  369. XFS_ATTRRM_SPACE_RES(mp), 0,
  370. (flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
  371. &args.trans);
  372. if (error)
  373. return error;
  374. xfs_ilock(dp, XFS_ILOCK_EXCL);
  375. /*
  376. * No need to make quota reservations here. We expect to release some
  377. * blocks not allocate in the common case.
  378. */
  379. xfs_trans_ijoin(args.trans, dp, 0);
  380. if (!xfs_inode_hasattr(dp)) {
  381. error = -ENOATTR;
  382. } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
  383. ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
  384. error = xfs_attr_shortform_remove(&args);
  385. } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
  386. error = xfs_attr_leaf_removename(&args);
  387. } else {
  388. error = xfs_attr_node_removename(&args);
  389. }
  390. if (error)
  391. goto out;
  392. /*
  393. * If this is a synchronous mount, make sure that the
  394. * transaction goes to disk before returning to the user.
  395. */
  396. if (mp->m_flags & XFS_MOUNT_WSYNC)
  397. xfs_trans_set_sync(args.trans);
  398. if ((flags & ATTR_KERNOTIME) == 0)
  399. xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
  400. /*
  401. * Commit the last in the sequence of transactions.
  402. */
  403. xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
  404. error = xfs_trans_commit(args.trans);
  405. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  406. return error;
  407. out:
  408. if (args.trans)
  409. xfs_trans_cancel(args.trans);
  410. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  411. return error;
  412. }
  413. /*========================================================================
  414. * External routines when attribute list is inside the inode
  415. *========================================================================*/
  416. /*
  417. * Add a name to the shortform attribute list structure
  418. * This is the external routine.
  419. */
  420. STATIC int
  421. xfs_attr_shortform_addname(xfs_da_args_t *args)
  422. {
  423. int newsize, forkoff, retval;
  424. trace_xfs_attr_sf_addname(args);
  425. retval = xfs_attr_shortform_lookup(args);
  426. if ((args->flags & ATTR_REPLACE) && (retval == -ENOATTR)) {
  427. return retval;
  428. } else if (retval == -EEXIST) {
  429. if (args->flags & ATTR_CREATE)
  430. return retval;
  431. retval = xfs_attr_shortform_remove(args);
  432. ASSERT(retval == 0);
  433. }
  434. if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
  435. args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
  436. return -ENOSPC;
  437. newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
  438. newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
  439. forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
  440. if (!forkoff)
  441. return -ENOSPC;
  442. xfs_attr_shortform_add(args, forkoff);
  443. return 0;
  444. }
  445. /*========================================================================
  446. * External routines when attribute list is one block
  447. *========================================================================*/
  448. /*
  449. * Add a name to the leaf attribute list structure
  450. *
  451. * This leaf block cannot have a "remote" value, we only call this routine
  452. * if bmap_one_block() says there is only one block (ie: no remote blks).
  453. */
  454. STATIC int
  455. xfs_attr_leaf_addname(xfs_da_args_t *args)
  456. {
  457. xfs_inode_t *dp;
  458. struct xfs_buf *bp;
  459. int retval, error, forkoff;
  460. trace_xfs_attr_leaf_addname(args);
  461. /*
  462. * Read the (only) block in the attribute list in.
  463. */
  464. dp = args->dp;
  465. args->blkno = 0;
  466. error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
  467. if (error)
  468. return error;
  469. /*
  470. * Look up the given attribute in the leaf block. Figure out if
  471. * the given flags produce an error or call for an atomic rename.
  472. */
  473. retval = xfs_attr3_leaf_lookup_int(bp, args);
  474. if ((args->flags & ATTR_REPLACE) && (retval == -ENOATTR)) {
  475. xfs_trans_brelse(args->trans, bp);
  476. return retval;
  477. } else if (retval == -EEXIST) {
  478. if (args->flags & ATTR_CREATE) { /* pure create op */
  479. xfs_trans_brelse(args->trans, bp);
  480. return retval;
  481. }
  482. trace_xfs_attr_leaf_replace(args);
  483. /* save the attribute state for later removal*/
  484. args->op_flags |= XFS_DA_OP_RENAME; /* an atomic rename */
  485. args->blkno2 = args->blkno; /* set 2nd entry info*/
  486. args->index2 = args->index;
  487. args->rmtblkno2 = args->rmtblkno;
  488. args->rmtblkcnt2 = args->rmtblkcnt;
  489. args->rmtvaluelen2 = args->rmtvaluelen;
  490. /*
  491. * clear the remote attr state now that it is saved so that the
  492. * values reflect the state of the attribute we are about to
  493. * add, not the attribute we just found and will remove later.
  494. */
  495. args->rmtblkno = 0;
  496. args->rmtblkcnt = 0;
  497. args->rmtvaluelen = 0;
  498. }
  499. /*
  500. * Add the attribute to the leaf block, transitioning to a Btree
  501. * if required.
  502. */
  503. retval = xfs_attr3_leaf_add(bp, args);
  504. if (retval == -ENOSPC) {
  505. /*
  506. * Promote the attribute list to the Btree format, then
  507. * Commit that transaction so that the node_addname() call
  508. * can manage its own transactions.
  509. */
  510. xfs_defer_init(args->dfops, args->firstblock);
  511. error = xfs_attr3_leaf_to_node(args);
  512. if (error)
  513. goto out_defer_cancel;
  514. xfs_defer_ijoin(args->dfops, dp);
  515. error = xfs_defer_finish(&args->trans, args->dfops);
  516. if (error)
  517. goto out_defer_cancel;
  518. /*
  519. * Commit the current trans (including the inode) and start
  520. * a new one.
  521. */
  522. error = xfs_trans_roll_inode(&args->trans, dp);
  523. if (error)
  524. return error;
  525. /*
  526. * Fob the whole rest of the problem off on the Btree code.
  527. */
  528. error = xfs_attr_node_addname(args);
  529. return error;
  530. }
  531. /*
  532. * Commit the transaction that added the attr name so that
  533. * later routines can manage their own transactions.
  534. */
  535. error = xfs_trans_roll_inode(&args->trans, dp);
  536. if (error)
  537. return error;
  538. /*
  539. * If there was an out-of-line value, allocate the blocks we
  540. * identified for its storage and copy the value. This is done
  541. * after we create the attribute so that we don't overflow the
  542. * maximum size of a transaction and/or hit a deadlock.
  543. */
  544. if (args->rmtblkno > 0) {
  545. error = xfs_attr_rmtval_set(args);
  546. if (error)
  547. return error;
  548. }
  549. /*
  550. * If this is an atomic rename operation, we must "flip" the
  551. * incomplete flags on the "new" and "old" attribute/value pairs
  552. * so that one disappears and one appears atomically. Then we
  553. * must remove the "old" attribute/value pair.
  554. */
  555. if (args->op_flags & XFS_DA_OP_RENAME) {
  556. /*
  557. * In a separate transaction, set the incomplete flag on the
  558. * "old" attr and clear the incomplete flag on the "new" attr.
  559. */
  560. error = xfs_attr3_leaf_flipflags(args);
  561. if (error)
  562. return error;
  563. /*
  564. * Dismantle the "old" attribute/value pair by removing
  565. * a "remote" value (if it exists).
  566. */
  567. args->index = args->index2;
  568. args->blkno = args->blkno2;
  569. args->rmtblkno = args->rmtblkno2;
  570. args->rmtblkcnt = args->rmtblkcnt2;
  571. args->rmtvaluelen = args->rmtvaluelen2;
  572. if (args->rmtblkno) {
  573. error = xfs_attr_rmtval_remove(args);
  574. if (error)
  575. return error;
  576. }
  577. /*
  578. * Read in the block containing the "old" attr, then
  579. * remove the "old" attr from that block (neat, huh!)
  580. */
  581. error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
  582. -1, &bp);
  583. if (error)
  584. return error;
  585. xfs_attr3_leaf_remove(bp, args);
  586. /*
  587. * If the result is small enough, shrink it all into the inode.
  588. */
  589. if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
  590. xfs_defer_init(args->dfops, args->firstblock);
  591. error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
  592. /* bp is gone due to xfs_da_shrink_inode */
  593. if (error)
  594. goto out_defer_cancel;
  595. xfs_defer_ijoin(args->dfops, dp);
  596. error = xfs_defer_finish(&args->trans, args->dfops);
  597. if (error)
  598. goto out_defer_cancel;
  599. }
  600. /*
  601. * Commit the remove and start the next trans in series.
  602. */
  603. error = xfs_trans_roll_inode(&args->trans, dp);
  604. } else if (args->rmtblkno > 0) {
  605. /*
  606. * Added a "remote" value, just clear the incomplete flag.
  607. */
  608. error = xfs_attr3_leaf_clearflag(args);
  609. }
  610. return error;
  611. out_defer_cancel:
  612. xfs_defer_cancel(args->dfops);
  613. args->trans = NULL;
  614. return error;
  615. }
  616. /*
  617. * Remove a name from the leaf attribute list structure
  618. *
  619. * This leaf block cannot have a "remote" value, we only call this routine
  620. * if bmap_one_block() says there is only one block (ie: no remote blks).
  621. */
  622. STATIC int
  623. xfs_attr_leaf_removename(xfs_da_args_t *args)
  624. {
  625. xfs_inode_t *dp;
  626. struct xfs_buf *bp;
  627. int error, forkoff;
  628. trace_xfs_attr_leaf_removename(args);
  629. /*
  630. * Remove the attribute.
  631. */
  632. dp = args->dp;
  633. args->blkno = 0;
  634. error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
  635. if (error)
  636. return error;
  637. error = xfs_attr3_leaf_lookup_int(bp, args);
  638. if (error == -ENOATTR) {
  639. xfs_trans_brelse(args->trans, bp);
  640. return error;
  641. }
  642. xfs_attr3_leaf_remove(bp, args);
  643. /*
  644. * If the result is small enough, shrink it all into the inode.
  645. */
  646. if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
  647. xfs_defer_init(args->dfops, args->firstblock);
  648. error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
  649. /* bp is gone due to xfs_da_shrink_inode */
  650. if (error)
  651. goto out_defer_cancel;
  652. xfs_defer_ijoin(args->dfops, dp);
  653. error = xfs_defer_finish(&args->trans, args->dfops);
  654. if (error)
  655. goto out_defer_cancel;
  656. }
  657. return 0;
  658. out_defer_cancel:
  659. xfs_defer_cancel(args->dfops);
  660. args->trans = NULL;
  661. return error;
  662. }
  663. /*
  664. * Look up a name in a leaf attribute list structure.
  665. *
  666. * This leaf block cannot have a "remote" value, we only call this routine
  667. * if bmap_one_block() says there is only one block (ie: no remote blks).
  668. */
  669. STATIC int
  670. xfs_attr_leaf_get(xfs_da_args_t *args)
  671. {
  672. struct xfs_buf *bp;
  673. int error;
  674. trace_xfs_attr_leaf_get(args);
  675. args->blkno = 0;
  676. error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
  677. if (error)
  678. return error;
  679. error = xfs_attr3_leaf_lookup_int(bp, args);
  680. if (error != -EEXIST) {
  681. xfs_trans_brelse(args->trans, bp);
  682. return error;
  683. }
  684. error = xfs_attr3_leaf_getvalue(bp, args);
  685. xfs_trans_brelse(args->trans, bp);
  686. if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
  687. error = xfs_attr_rmtval_get(args);
  688. }
  689. return error;
  690. }
  691. /*========================================================================
  692. * External routines when attribute list size > geo->blksize
  693. *========================================================================*/
  694. /*
  695. * Add a name to a Btree-format attribute list.
  696. *
  697. * This will involve walking down the Btree, and may involve splitting
  698. * leaf nodes and even splitting intermediate nodes up to and including
  699. * the root node (a special case of an intermediate node).
  700. *
  701. * "Remote" attribute values confuse the issue and atomic rename operations
  702. * add a whole extra layer of confusion on top of that.
  703. */
  704. STATIC int
  705. xfs_attr_node_addname(xfs_da_args_t *args)
  706. {
  707. xfs_da_state_t *state;
  708. xfs_da_state_blk_t *blk;
  709. xfs_inode_t *dp;
  710. xfs_mount_t *mp;
  711. int retval, error;
  712. trace_xfs_attr_node_addname(args);
  713. /*
  714. * Fill in bucket of arguments/results/context to carry around.
  715. */
  716. dp = args->dp;
  717. mp = dp->i_mount;
  718. restart:
  719. state = xfs_da_state_alloc();
  720. state->args = args;
  721. state->mp = mp;
  722. /*
  723. * Search to see if name already exists, and get back a pointer
  724. * to where it should go.
  725. */
  726. error = xfs_da3_node_lookup_int(state, &retval);
  727. if (error)
  728. goto out;
  729. blk = &state->path.blk[ state->path.active-1 ];
  730. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  731. if ((args->flags & ATTR_REPLACE) && (retval == -ENOATTR)) {
  732. goto out;
  733. } else if (retval == -EEXIST) {
  734. if (args->flags & ATTR_CREATE)
  735. goto out;
  736. trace_xfs_attr_node_replace(args);
  737. /* save the attribute state for later removal*/
  738. args->op_flags |= XFS_DA_OP_RENAME; /* atomic rename op */
  739. args->blkno2 = args->blkno; /* set 2nd entry info*/
  740. args->index2 = args->index;
  741. args->rmtblkno2 = args->rmtblkno;
  742. args->rmtblkcnt2 = args->rmtblkcnt;
  743. args->rmtvaluelen2 = args->rmtvaluelen;
  744. /*
  745. * clear the remote attr state now that it is saved so that the
  746. * values reflect the state of the attribute we are about to
  747. * add, not the attribute we just found and will remove later.
  748. */
  749. args->rmtblkno = 0;
  750. args->rmtblkcnt = 0;
  751. args->rmtvaluelen = 0;
  752. }
  753. retval = xfs_attr3_leaf_add(blk->bp, state->args);
  754. if (retval == -ENOSPC) {
  755. if (state->path.active == 1) {
  756. /*
  757. * Its really a single leaf node, but it had
  758. * out-of-line values so it looked like it *might*
  759. * have been a b-tree.
  760. */
  761. xfs_da_state_free(state);
  762. state = NULL;
  763. xfs_defer_init(args->dfops, args->firstblock);
  764. error = xfs_attr3_leaf_to_node(args);
  765. if (error)
  766. goto out_defer_cancel;
  767. xfs_defer_ijoin(args->dfops, dp);
  768. error = xfs_defer_finish(&args->trans, args->dfops);
  769. if (error)
  770. goto out_defer_cancel;
  771. /*
  772. * Commit the node conversion and start the next
  773. * trans in the chain.
  774. */
  775. error = xfs_trans_roll_inode(&args->trans, dp);
  776. if (error)
  777. goto out;
  778. goto restart;
  779. }
  780. /*
  781. * Split as many Btree elements as required.
  782. * This code tracks the new and old attr's location
  783. * in the index/blkno/rmtblkno/rmtblkcnt fields and
  784. * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
  785. */
  786. xfs_defer_init(args->dfops, args->firstblock);
  787. error = xfs_da3_split(state);
  788. if (error)
  789. goto out_defer_cancel;
  790. xfs_defer_ijoin(args->dfops, dp);
  791. error = xfs_defer_finish(&args->trans, args->dfops);
  792. if (error)
  793. goto out_defer_cancel;
  794. } else {
  795. /*
  796. * Addition succeeded, update Btree hashvals.
  797. */
  798. xfs_da3_fixhashpath(state, &state->path);
  799. }
  800. /*
  801. * Kill the state structure, we're done with it and need to
  802. * allow the buffers to come back later.
  803. */
  804. xfs_da_state_free(state);
  805. state = NULL;
  806. /*
  807. * Commit the leaf addition or btree split and start the next
  808. * trans in the chain.
  809. */
  810. error = xfs_trans_roll_inode(&args->trans, dp);
  811. if (error)
  812. goto out;
  813. /*
  814. * If there was an out-of-line value, allocate the blocks we
  815. * identified for its storage and copy the value. This is done
  816. * after we create the attribute so that we don't overflow the
  817. * maximum size of a transaction and/or hit a deadlock.
  818. */
  819. if (args->rmtblkno > 0) {
  820. error = xfs_attr_rmtval_set(args);
  821. if (error)
  822. return error;
  823. }
  824. /*
  825. * If this is an atomic rename operation, we must "flip" the
  826. * incomplete flags on the "new" and "old" attribute/value pairs
  827. * so that one disappears and one appears atomically. Then we
  828. * must remove the "old" attribute/value pair.
  829. */
  830. if (args->op_flags & XFS_DA_OP_RENAME) {
  831. /*
  832. * In a separate transaction, set the incomplete flag on the
  833. * "old" attr and clear the incomplete flag on the "new" attr.
  834. */
  835. error = xfs_attr3_leaf_flipflags(args);
  836. if (error)
  837. goto out;
  838. /*
  839. * Dismantle the "old" attribute/value pair by removing
  840. * a "remote" value (if it exists).
  841. */
  842. args->index = args->index2;
  843. args->blkno = args->blkno2;
  844. args->rmtblkno = args->rmtblkno2;
  845. args->rmtblkcnt = args->rmtblkcnt2;
  846. args->rmtvaluelen = args->rmtvaluelen2;
  847. if (args->rmtblkno) {
  848. error = xfs_attr_rmtval_remove(args);
  849. if (error)
  850. return error;
  851. }
  852. /*
  853. * Re-find the "old" attribute entry after any split ops.
  854. * The INCOMPLETE flag means that we will find the "old"
  855. * attr, not the "new" one.
  856. */
  857. args->flags |= XFS_ATTR_INCOMPLETE;
  858. state = xfs_da_state_alloc();
  859. state->args = args;
  860. state->mp = mp;
  861. state->inleaf = 0;
  862. error = xfs_da3_node_lookup_int(state, &retval);
  863. if (error)
  864. goto out;
  865. /*
  866. * Remove the name and update the hashvals in the tree.
  867. */
  868. blk = &state->path.blk[ state->path.active-1 ];
  869. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  870. error = xfs_attr3_leaf_remove(blk->bp, args);
  871. xfs_da3_fixhashpath(state, &state->path);
  872. /*
  873. * Check to see if the tree needs to be collapsed.
  874. */
  875. if (retval && (state->path.active > 1)) {
  876. xfs_defer_init(args->dfops, args->firstblock);
  877. error = xfs_da3_join(state);
  878. if (error)
  879. goto out_defer_cancel;
  880. xfs_defer_ijoin(args->dfops, dp);
  881. error = xfs_defer_finish(&args->trans, args->dfops);
  882. if (error)
  883. goto out_defer_cancel;
  884. }
  885. /*
  886. * Commit and start the next trans in the chain.
  887. */
  888. error = xfs_trans_roll_inode(&args->trans, dp);
  889. if (error)
  890. goto out;
  891. } else if (args->rmtblkno > 0) {
  892. /*
  893. * Added a "remote" value, just clear the incomplete flag.
  894. */
  895. error = xfs_attr3_leaf_clearflag(args);
  896. if (error)
  897. goto out;
  898. }
  899. retval = error = 0;
  900. out:
  901. if (state)
  902. xfs_da_state_free(state);
  903. if (error)
  904. return error;
  905. return retval;
  906. out_defer_cancel:
  907. xfs_defer_cancel(args->dfops);
  908. args->trans = NULL;
  909. goto out;
  910. }
  911. /*
  912. * Remove a name from a B-tree attribute list.
  913. *
  914. * This will involve walking down the Btree, and may involve joining
  915. * leaf nodes and even joining intermediate nodes up to and including
  916. * the root node (a special case of an intermediate node).
  917. */
  918. STATIC int
  919. xfs_attr_node_removename(xfs_da_args_t *args)
  920. {
  921. xfs_da_state_t *state;
  922. xfs_da_state_blk_t *blk;
  923. xfs_inode_t *dp;
  924. struct xfs_buf *bp;
  925. int retval, error, forkoff;
  926. trace_xfs_attr_node_removename(args);
  927. /*
  928. * Tie a string around our finger to remind us where we are.
  929. */
  930. dp = args->dp;
  931. state = xfs_da_state_alloc();
  932. state->args = args;
  933. state->mp = dp->i_mount;
  934. /*
  935. * Search to see if name exists, and get back a pointer to it.
  936. */
  937. error = xfs_da3_node_lookup_int(state, &retval);
  938. if (error || (retval != -EEXIST)) {
  939. if (error == 0)
  940. error = retval;
  941. goto out;
  942. }
  943. /*
  944. * If there is an out-of-line value, de-allocate the blocks.
  945. * This is done before we remove the attribute so that we don't
  946. * overflow the maximum size of a transaction and/or hit a deadlock.
  947. */
  948. blk = &state->path.blk[ state->path.active-1 ];
  949. ASSERT(blk->bp != NULL);
  950. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  951. if (args->rmtblkno > 0) {
  952. /*
  953. * Fill in disk block numbers in the state structure
  954. * so that we can get the buffers back after we commit
  955. * several transactions in the following calls.
  956. */
  957. error = xfs_attr_fillstate(state);
  958. if (error)
  959. goto out;
  960. /*
  961. * Mark the attribute as INCOMPLETE, then bunmapi() the
  962. * remote value.
  963. */
  964. error = xfs_attr3_leaf_setflag(args);
  965. if (error)
  966. goto out;
  967. error = xfs_attr_rmtval_remove(args);
  968. if (error)
  969. goto out;
  970. /*
  971. * Refill the state structure with buffers, the prior calls
  972. * released our buffers.
  973. */
  974. error = xfs_attr_refillstate(state);
  975. if (error)
  976. goto out;
  977. }
  978. /*
  979. * Remove the name and update the hashvals in the tree.
  980. */
  981. blk = &state->path.blk[ state->path.active-1 ];
  982. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  983. retval = xfs_attr3_leaf_remove(blk->bp, args);
  984. xfs_da3_fixhashpath(state, &state->path);
  985. /*
  986. * Check to see if the tree needs to be collapsed.
  987. */
  988. if (retval && (state->path.active > 1)) {
  989. xfs_defer_init(args->dfops, args->firstblock);
  990. error = xfs_da3_join(state);
  991. if (error)
  992. goto out_defer_cancel;
  993. xfs_defer_ijoin(args->dfops, dp);
  994. error = xfs_defer_finish(&args->trans, args->dfops);
  995. if (error)
  996. goto out_defer_cancel;
  997. /*
  998. * Commit the Btree join operation and start a new trans.
  999. */
  1000. error = xfs_trans_roll_inode(&args->trans, dp);
  1001. if (error)
  1002. goto out;
  1003. }
  1004. /*
  1005. * If the result is small enough, push it all into the inode.
  1006. */
  1007. if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
  1008. /*
  1009. * Have to get rid of the copy of this dabuf in the state.
  1010. */
  1011. ASSERT(state->path.active == 1);
  1012. ASSERT(state->path.blk[0].bp);
  1013. state->path.blk[0].bp = NULL;
  1014. error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
  1015. if (error)
  1016. goto out;
  1017. if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
  1018. xfs_defer_init(args->dfops, args->firstblock);
  1019. error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
  1020. /* bp is gone due to xfs_da_shrink_inode */
  1021. if (error)
  1022. goto out_defer_cancel;
  1023. xfs_defer_ijoin(args->dfops, dp);
  1024. error = xfs_defer_finish(&args->trans, args->dfops);
  1025. if (error)
  1026. goto out_defer_cancel;
  1027. } else
  1028. xfs_trans_brelse(args->trans, bp);
  1029. }
  1030. error = 0;
  1031. out:
  1032. xfs_da_state_free(state);
  1033. return error;
  1034. out_defer_cancel:
  1035. xfs_defer_cancel(args->dfops);
  1036. args->trans = NULL;
  1037. goto out;
  1038. }
  1039. /*
  1040. * Fill in the disk block numbers in the state structure for the buffers
  1041. * that are attached to the state structure.
  1042. * This is done so that we can quickly reattach ourselves to those buffers
  1043. * after some set of transaction commits have released these buffers.
  1044. */
  1045. STATIC int
  1046. xfs_attr_fillstate(xfs_da_state_t *state)
  1047. {
  1048. xfs_da_state_path_t *path;
  1049. xfs_da_state_blk_t *blk;
  1050. int level;
  1051. trace_xfs_attr_fillstate(state->args);
  1052. /*
  1053. * Roll down the "path" in the state structure, storing the on-disk
  1054. * block number for those buffers in the "path".
  1055. */
  1056. path = &state->path;
  1057. ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
  1058. for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
  1059. if (blk->bp) {
  1060. blk->disk_blkno = XFS_BUF_ADDR(blk->bp);
  1061. blk->bp = NULL;
  1062. } else {
  1063. blk->disk_blkno = 0;
  1064. }
  1065. }
  1066. /*
  1067. * Roll down the "altpath" in the state structure, storing the on-disk
  1068. * block number for those buffers in the "altpath".
  1069. */
  1070. path = &state->altpath;
  1071. ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
  1072. for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
  1073. if (blk->bp) {
  1074. blk->disk_blkno = XFS_BUF_ADDR(blk->bp);
  1075. blk->bp = NULL;
  1076. } else {
  1077. blk->disk_blkno = 0;
  1078. }
  1079. }
  1080. return 0;
  1081. }
  1082. /*
  1083. * Reattach the buffers to the state structure based on the disk block
  1084. * numbers stored in the state structure.
  1085. * This is done after some set of transaction commits have released those
  1086. * buffers from our grip.
  1087. */
  1088. STATIC int
  1089. xfs_attr_refillstate(xfs_da_state_t *state)
  1090. {
  1091. xfs_da_state_path_t *path;
  1092. xfs_da_state_blk_t *blk;
  1093. int level, error;
  1094. trace_xfs_attr_refillstate(state->args);
  1095. /*
  1096. * Roll down the "path" in the state structure, storing the on-disk
  1097. * block number for those buffers in the "path".
  1098. */
  1099. path = &state->path;
  1100. ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
  1101. for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
  1102. if (blk->disk_blkno) {
  1103. error = xfs_da3_node_read(state->args->trans,
  1104. state->args->dp,
  1105. blk->blkno, blk->disk_blkno,
  1106. &blk->bp, XFS_ATTR_FORK);
  1107. if (error)
  1108. return error;
  1109. } else {
  1110. blk->bp = NULL;
  1111. }
  1112. }
  1113. /*
  1114. * Roll down the "altpath" in the state structure, storing the on-disk
  1115. * block number for those buffers in the "altpath".
  1116. */
  1117. path = &state->altpath;
  1118. ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
  1119. for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
  1120. if (blk->disk_blkno) {
  1121. error = xfs_da3_node_read(state->args->trans,
  1122. state->args->dp,
  1123. blk->blkno, blk->disk_blkno,
  1124. &blk->bp, XFS_ATTR_FORK);
  1125. if (error)
  1126. return error;
  1127. } else {
  1128. blk->bp = NULL;
  1129. }
  1130. }
  1131. return 0;
  1132. }
  1133. /*
  1134. * Look up a filename in a node attribute list.
  1135. *
  1136. * This routine gets called for any attribute fork that has more than one
  1137. * block, ie: both true Btree attr lists and for single-leaf-blocks with
  1138. * "remote" values taking up more blocks.
  1139. */
  1140. STATIC int
  1141. xfs_attr_node_get(xfs_da_args_t *args)
  1142. {
  1143. xfs_da_state_t *state;
  1144. xfs_da_state_blk_t *blk;
  1145. int error, retval;
  1146. int i;
  1147. trace_xfs_attr_node_get(args);
  1148. state = xfs_da_state_alloc();
  1149. state->args = args;
  1150. state->mp = args->dp->i_mount;
  1151. /*
  1152. * Search to see if name exists, and get back a pointer to it.
  1153. */
  1154. error = xfs_da3_node_lookup_int(state, &retval);
  1155. if (error) {
  1156. retval = error;
  1157. } else if (retval == -EEXIST) {
  1158. blk = &state->path.blk[ state->path.active-1 ];
  1159. ASSERT(blk->bp != NULL);
  1160. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  1161. /*
  1162. * Get the value, local or "remote"
  1163. */
  1164. retval = xfs_attr3_leaf_getvalue(blk->bp, args);
  1165. if (!retval && (args->rmtblkno > 0)
  1166. && !(args->flags & ATTR_KERNOVAL)) {
  1167. retval = xfs_attr_rmtval_get(args);
  1168. }
  1169. }
  1170. /*
  1171. * If not in a transaction, we have to release all the buffers.
  1172. */
  1173. for (i = 0; i < state->path.active; i++) {
  1174. xfs_trans_brelse(args->trans, state->path.blk[i].bp);
  1175. state->path.blk[i].bp = NULL;
  1176. }
  1177. xfs_da_state_free(state);
  1178. return retval;
  1179. }