xfs_attr.c 34 KB

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