xfs_attr.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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. error = xfs_defer_finish(&args.trans, args.dfops, dp);
  290. if (error) {
  291. args.trans = NULL;
  292. xfs_defer_cancel(&dfops);
  293. goto out;
  294. }
  295. /*
  296. * Commit the leaf transformation. We'll need another (linked)
  297. * transaction to add the new attribute to the leaf.
  298. */
  299. error = xfs_trans_roll(&args.trans, dp);
  300. if (error)
  301. goto out;
  302. }
  303. if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
  304. error = xfs_attr_leaf_addname(&args);
  305. else
  306. error = xfs_attr_node_addname(&args);
  307. if (error)
  308. goto out;
  309. /*
  310. * If this is a synchronous mount, make sure that the
  311. * transaction goes to disk before returning to the user.
  312. */
  313. if (mp->m_flags & XFS_MOUNT_WSYNC)
  314. xfs_trans_set_sync(args.trans);
  315. if ((flags & ATTR_KERNOTIME) == 0)
  316. xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
  317. /*
  318. * Commit the last in the sequence of transactions.
  319. */
  320. xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
  321. error = xfs_trans_commit(args.trans);
  322. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  323. return error;
  324. out:
  325. if (args.trans)
  326. xfs_trans_cancel(args.trans);
  327. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  328. return error;
  329. }
  330. /*
  331. * Generic handler routine to remove a name from an attribute list.
  332. * Transitions attribute list from Btree to shortform as necessary.
  333. */
  334. int
  335. xfs_attr_remove(
  336. struct xfs_inode *dp,
  337. const unsigned char *name,
  338. int flags)
  339. {
  340. struct xfs_mount *mp = dp->i_mount;
  341. struct xfs_da_args args;
  342. struct xfs_defer_ops dfops;
  343. xfs_fsblock_t firstblock;
  344. int error;
  345. XFS_STATS_INC(mp, xs_attr_remove);
  346. if (XFS_FORCED_SHUTDOWN(dp->i_mount))
  347. return -EIO;
  348. error = xfs_attr_args_init(&args, dp, name, flags);
  349. if (error)
  350. return error;
  351. args.firstblock = &firstblock;
  352. args.dfops = &dfops;
  353. /*
  354. * we have no control over the attribute names that userspace passes us
  355. * to remove, so we have to allow the name lookup prior to attribute
  356. * removal to fail.
  357. */
  358. args.op_flags = XFS_DA_OP_OKNOENT;
  359. error = xfs_qm_dqattach(dp, 0);
  360. if (error)
  361. return error;
  362. /*
  363. * Root fork attributes can use reserved data blocks for this
  364. * operation if necessary
  365. */
  366. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrrm,
  367. XFS_ATTRRM_SPACE_RES(mp), 0,
  368. (flags & ATTR_ROOT) ? XFS_TRANS_RESERVE : 0,
  369. &args.trans);
  370. if (error)
  371. return error;
  372. xfs_ilock(dp, XFS_ILOCK_EXCL);
  373. /*
  374. * No need to make quota reservations here. We expect to release some
  375. * blocks not allocate in the common case.
  376. */
  377. xfs_trans_ijoin(args.trans, dp, 0);
  378. if (!xfs_inode_hasattr(dp)) {
  379. error = -ENOATTR;
  380. } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
  381. ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
  382. error = xfs_attr_shortform_remove(&args);
  383. } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
  384. error = xfs_attr_leaf_removename(&args);
  385. } else {
  386. error = xfs_attr_node_removename(&args);
  387. }
  388. if (error)
  389. goto out;
  390. /*
  391. * If this is a synchronous mount, make sure that the
  392. * transaction goes to disk before returning to the user.
  393. */
  394. if (mp->m_flags & XFS_MOUNT_WSYNC)
  395. xfs_trans_set_sync(args.trans);
  396. if ((flags & ATTR_KERNOTIME) == 0)
  397. xfs_trans_ichgtime(args.trans, dp, XFS_ICHGTIME_CHG);
  398. /*
  399. * Commit the last in the sequence of transactions.
  400. */
  401. xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
  402. error = xfs_trans_commit(args.trans);
  403. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  404. return error;
  405. out:
  406. if (args.trans)
  407. xfs_trans_cancel(args.trans);
  408. xfs_iunlock(dp, XFS_ILOCK_EXCL);
  409. return error;
  410. }
  411. /*========================================================================
  412. * External routines when attribute list is inside the inode
  413. *========================================================================*/
  414. /*
  415. * Add a name to the shortform attribute list structure
  416. * This is the external routine.
  417. */
  418. STATIC int
  419. xfs_attr_shortform_addname(xfs_da_args_t *args)
  420. {
  421. int newsize, forkoff, retval;
  422. trace_xfs_attr_sf_addname(args);
  423. retval = xfs_attr_shortform_lookup(args);
  424. if ((args->flags & ATTR_REPLACE) && (retval == -ENOATTR)) {
  425. return retval;
  426. } else if (retval == -EEXIST) {
  427. if (args->flags & ATTR_CREATE)
  428. return retval;
  429. retval = xfs_attr_shortform_remove(args);
  430. ASSERT(retval == 0);
  431. }
  432. if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
  433. args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
  434. return -ENOSPC;
  435. newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
  436. newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
  437. forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
  438. if (!forkoff)
  439. return -ENOSPC;
  440. xfs_attr_shortform_add(args, forkoff);
  441. return 0;
  442. }
  443. /*========================================================================
  444. * External routines when attribute list is one block
  445. *========================================================================*/
  446. /*
  447. * Add a name to the leaf attribute list structure
  448. *
  449. * This leaf block cannot have a "remote" value, we only call this routine
  450. * if bmap_one_block() says there is only one block (ie: no remote blks).
  451. */
  452. STATIC int
  453. xfs_attr_leaf_addname(xfs_da_args_t *args)
  454. {
  455. xfs_inode_t *dp;
  456. struct xfs_buf *bp;
  457. int retval, error, forkoff;
  458. trace_xfs_attr_leaf_addname(args);
  459. /*
  460. * Read the (only) block in the attribute list in.
  461. */
  462. dp = args->dp;
  463. args->blkno = 0;
  464. error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
  465. if (error)
  466. return error;
  467. /*
  468. * Look up the given attribute in the leaf block. Figure out if
  469. * the given flags produce an error or call for an atomic rename.
  470. */
  471. retval = xfs_attr3_leaf_lookup_int(bp, args);
  472. if ((args->flags & ATTR_REPLACE) && (retval == -ENOATTR)) {
  473. xfs_trans_brelse(args->trans, bp);
  474. return retval;
  475. } else if (retval == -EEXIST) {
  476. if (args->flags & ATTR_CREATE) { /* pure create op */
  477. xfs_trans_brelse(args->trans, bp);
  478. return retval;
  479. }
  480. trace_xfs_attr_leaf_replace(args);
  481. /* save the attribute state for later removal*/
  482. args->op_flags |= XFS_DA_OP_RENAME; /* an atomic rename */
  483. args->blkno2 = args->blkno; /* set 2nd entry info*/
  484. args->index2 = args->index;
  485. args->rmtblkno2 = args->rmtblkno;
  486. args->rmtblkcnt2 = args->rmtblkcnt;
  487. args->rmtvaluelen2 = args->rmtvaluelen;
  488. /*
  489. * clear the remote attr state now that it is saved so that the
  490. * values reflect the state of the attribute we are about to
  491. * add, not the attribute we just found and will remove later.
  492. */
  493. args->rmtblkno = 0;
  494. args->rmtblkcnt = 0;
  495. args->rmtvaluelen = 0;
  496. }
  497. /*
  498. * Add the attribute to the leaf block, transitioning to a Btree
  499. * if required.
  500. */
  501. retval = xfs_attr3_leaf_add(bp, args);
  502. if (retval == -ENOSPC) {
  503. /*
  504. * Promote the attribute list to the Btree format, then
  505. * Commit that transaction so that the node_addname() call
  506. * can manage its own transactions.
  507. */
  508. xfs_defer_init(args->dfops, args->firstblock);
  509. error = xfs_attr3_leaf_to_node(args);
  510. if (!error)
  511. error = xfs_defer_finish(&args->trans, args->dfops, dp);
  512. if (error) {
  513. args->trans = NULL;
  514. xfs_defer_cancel(args->dfops);
  515. return error;
  516. }
  517. /*
  518. * Commit the current trans (including the inode) and start
  519. * a new one.
  520. */
  521. error = xfs_trans_roll(&args->trans, dp);
  522. if (error)
  523. return error;
  524. /*
  525. * Fob the whole rest of the problem off on the Btree code.
  526. */
  527. error = xfs_attr_node_addname(args);
  528. return error;
  529. }
  530. /*
  531. * Commit the transaction that added the attr name so that
  532. * later routines can manage their own transactions.
  533. */
  534. error = xfs_trans_roll(&args->trans, dp);
  535. if (error)
  536. return error;
  537. /*
  538. * If there was an out-of-line value, allocate the blocks we
  539. * identified for its storage and copy the value. This is done
  540. * after we create the attribute so that we don't overflow the
  541. * maximum size of a transaction and/or hit a deadlock.
  542. */
  543. if (args->rmtblkno > 0) {
  544. error = xfs_attr_rmtval_set(args);
  545. if (error)
  546. return error;
  547. }
  548. /*
  549. * If this is an atomic rename operation, we must "flip" the
  550. * incomplete flags on the "new" and "old" attribute/value pairs
  551. * so that one disappears and one appears atomically. Then we
  552. * must remove the "old" attribute/value pair.
  553. */
  554. if (args->op_flags & XFS_DA_OP_RENAME) {
  555. /*
  556. * In a separate transaction, set the incomplete flag on the
  557. * "old" attr and clear the incomplete flag on the "new" attr.
  558. */
  559. error = xfs_attr3_leaf_flipflags(args);
  560. if (error)
  561. return error;
  562. /*
  563. * Dismantle the "old" attribute/value pair by removing
  564. * a "remote" value (if it exists).
  565. */
  566. args->index = args->index2;
  567. args->blkno = args->blkno2;
  568. args->rmtblkno = args->rmtblkno2;
  569. args->rmtblkcnt = args->rmtblkcnt2;
  570. args->rmtvaluelen = args->rmtvaluelen2;
  571. if (args->rmtblkno) {
  572. error = xfs_attr_rmtval_remove(args);
  573. if (error)
  574. return error;
  575. }
  576. /*
  577. * Read in the block containing the "old" attr, then
  578. * remove the "old" attr from that block (neat, huh!)
  579. */
  580. error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno,
  581. -1, &bp);
  582. if (error)
  583. return error;
  584. xfs_attr3_leaf_remove(bp, args);
  585. /*
  586. * If the result is small enough, shrink it all into the inode.
  587. */
  588. if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
  589. xfs_defer_init(args->dfops, args->firstblock);
  590. error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
  591. /* bp is gone due to xfs_da_shrink_inode */
  592. if (!error)
  593. error = xfs_defer_finish(&args->trans,
  594. args->dfops, dp);
  595. if (error) {
  596. args->trans = NULL;
  597. xfs_defer_cancel(args->dfops);
  598. return error;
  599. }
  600. }
  601. /*
  602. * Commit the remove and start the next trans in series.
  603. */
  604. error = xfs_trans_roll(&args->trans, dp);
  605. } else if (args->rmtblkno > 0) {
  606. /*
  607. * Added a "remote" value, just clear the incomplete flag.
  608. */
  609. error = xfs_attr3_leaf_clearflag(args);
  610. }
  611. return error;
  612. }
  613. /*
  614. * Remove a name from the leaf attribute list structure
  615. *
  616. * This leaf block cannot have a "remote" value, we only call this routine
  617. * if bmap_one_block() says there is only one block (ie: no remote blks).
  618. */
  619. STATIC int
  620. xfs_attr_leaf_removename(xfs_da_args_t *args)
  621. {
  622. xfs_inode_t *dp;
  623. struct xfs_buf *bp;
  624. int error, forkoff;
  625. trace_xfs_attr_leaf_removename(args);
  626. /*
  627. * Remove the attribute.
  628. */
  629. dp = args->dp;
  630. args->blkno = 0;
  631. error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
  632. if (error)
  633. return error;
  634. error = xfs_attr3_leaf_lookup_int(bp, args);
  635. if (error == -ENOATTR) {
  636. xfs_trans_brelse(args->trans, bp);
  637. return error;
  638. }
  639. xfs_attr3_leaf_remove(bp, args);
  640. /*
  641. * If the result is small enough, shrink it all into the inode.
  642. */
  643. if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
  644. xfs_defer_init(args->dfops, args->firstblock);
  645. error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
  646. /* bp is gone due to xfs_da_shrink_inode */
  647. if (!error)
  648. error = xfs_defer_finish(&args->trans, args->dfops, dp);
  649. if (error) {
  650. args->trans = NULL;
  651. xfs_defer_cancel(args->dfops);
  652. return error;
  653. }
  654. }
  655. return 0;
  656. }
  657. /*
  658. * Look up a name in a leaf attribute list structure.
  659. *
  660. * This leaf block cannot have a "remote" value, we only call this routine
  661. * if bmap_one_block() says there is only one block (ie: no remote blks).
  662. */
  663. STATIC int
  664. xfs_attr_leaf_get(xfs_da_args_t *args)
  665. {
  666. struct xfs_buf *bp;
  667. int error;
  668. trace_xfs_attr_leaf_get(args);
  669. args->blkno = 0;
  670. error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
  671. if (error)
  672. return error;
  673. error = xfs_attr3_leaf_lookup_int(bp, args);
  674. if (error != -EEXIST) {
  675. xfs_trans_brelse(args->trans, bp);
  676. return error;
  677. }
  678. error = xfs_attr3_leaf_getvalue(bp, args);
  679. xfs_trans_brelse(args->trans, bp);
  680. if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
  681. error = xfs_attr_rmtval_get(args);
  682. }
  683. return error;
  684. }
  685. /*========================================================================
  686. * External routines when attribute list size > geo->blksize
  687. *========================================================================*/
  688. /*
  689. * Add a name to a Btree-format attribute list.
  690. *
  691. * This will involve walking down the Btree, and may involve splitting
  692. * leaf nodes and even splitting intermediate nodes up to and including
  693. * the root node (a special case of an intermediate node).
  694. *
  695. * "Remote" attribute values confuse the issue and atomic rename operations
  696. * add a whole extra layer of confusion on top of that.
  697. */
  698. STATIC int
  699. xfs_attr_node_addname(xfs_da_args_t *args)
  700. {
  701. xfs_da_state_t *state;
  702. xfs_da_state_blk_t *blk;
  703. xfs_inode_t *dp;
  704. xfs_mount_t *mp;
  705. int retval, error;
  706. trace_xfs_attr_node_addname(args);
  707. /*
  708. * Fill in bucket of arguments/results/context to carry around.
  709. */
  710. dp = args->dp;
  711. mp = dp->i_mount;
  712. restart:
  713. state = xfs_da_state_alloc();
  714. state->args = args;
  715. state->mp = mp;
  716. /*
  717. * Search to see if name already exists, and get back a pointer
  718. * to where it should go.
  719. */
  720. error = xfs_da3_node_lookup_int(state, &retval);
  721. if (error)
  722. goto out;
  723. blk = &state->path.blk[ state->path.active-1 ];
  724. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  725. if ((args->flags & ATTR_REPLACE) && (retval == -ENOATTR)) {
  726. goto out;
  727. } else if (retval == -EEXIST) {
  728. if (args->flags & ATTR_CREATE)
  729. goto out;
  730. trace_xfs_attr_node_replace(args);
  731. /* save the attribute state for later removal*/
  732. args->op_flags |= XFS_DA_OP_RENAME; /* atomic rename op */
  733. args->blkno2 = args->blkno; /* set 2nd entry info*/
  734. args->index2 = args->index;
  735. args->rmtblkno2 = args->rmtblkno;
  736. args->rmtblkcnt2 = args->rmtblkcnt;
  737. args->rmtvaluelen2 = args->rmtvaluelen;
  738. /*
  739. * clear the remote attr state now that it is saved so that the
  740. * values reflect the state of the attribute we are about to
  741. * add, not the attribute we just found and will remove later.
  742. */
  743. args->rmtblkno = 0;
  744. args->rmtblkcnt = 0;
  745. args->rmtvaluelen = 0;
  746. }
  747. retval = xfs_attr3_leaf_add(blk->bp, state->args);
  748. if (retval == -ENOSPC) {
  749. if (state->path.active == 1) {
  750. /*
  751. * Its really a single leaf node, but it had
  752. * out-of-line values so it looked like it *might*
  753. * have been a b-tree.
  754. */
  755. xfs_da_state_free(state);
  756. state = NULL;
  757. xfs_defer_init(args->dfops, args->firstblock);
  758. error = xfs_attr3_leaf_to_node(args);
  759. if (!error)
  760. error = xfs_defer_finish(&args->trans,
  761. args->dfops, dp);
  762. if (error) {
  763. args->trans = NULL;
  764. xfs_defer_cancel(args->dfops);
  765. goto out;
  766. }
  767. /*
  768. * Commit the node conversion and start the next
  769. * trans in the chain.
  770. */
  771. error = xfs_trans_roll(&args->trans, dp);
  772. if (error)
  773. goto out;
  774. goto restart;
  775. }
  776. /*
  777. * Split as many Btree elements as required.
  778. * This code tracks the new and old attr's location
  779. * in the index/blkno/rmtblkno/rmtblkcnt fields and
  780. * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
  781. */
  782. xfs_defer_init(args->dfops, args->firstblock);
  783. error = xfs_da3_split(state);
  784. if (!error)
  785. error = xfs_defer_finish(&args->trans, args->dfops, dp);
  786. if (error) {
  787. args->trans = NULL;
  788. xfs_defer_cancel(args->dfops);
  789. goto out;
  790. }
  791. } else {
  792. /*
  793. * Addition succeeded, update Btree hashvals.
  794. */
  795. xfs_da3_fixhashpath(state, &state->path);
  796. }
  797. /*
  798. * Kill the state structure, we're done with it and need to
  799. * allow the buffers to come back later.
  800. */
  801. xfs_da_state_free(state);
  802. state = NULL;
  803. /*
  804. * Commit the leaf addition or btree split and start the next
  805. * trans in the chain.
  806. */
  807. error = xfs_trans_roll(&args->trans, dp);
  808. if (error)
  809. goto out;
  810. /*
  811. * If there was an out-of-line value, allocate the blocks we
  812. * identified for its storage and copy the value. This is done
  813. * after we create the attribute so that we don't overflow the
  814. * maximum size of a transaction and/or hit a deadlock.
  815. */
  816. if (args->rmtblkno > 0) {
  817. error = xfs_attr_rmtval_set(args);
  818. if (error)
  819. return error;
  820. }
  821. /*
  822. * If this is an atomic rename operation, we must "flip" the
  823. * incomplete flags on the "new" and "old" attribute/value pairs
  824. * so that one disappears and one appears atomically. Then we
  825. * must remove the "old" attribute/value pair.
  826. */
  827. if (args->op_flags & XFS_DA_OP_RENAME) {
  828. /*
  829. * In a separate transaction, set the incomplete flag on the
  830. * "old" attr and clear the incomplete flag on the "new" attr.
  831. */
  832. error = xfs_attr3_leaf_flipflags(args);
  833. if (error)
  834. goto out;
  835. /*
  836. * Dismantle the "old" attribute/value pair by removing
  837. * a "remote" value (if it exists).
  838. */
  839. args->index = args->index2;
  840. args->blkno = args->blkno2;
  841. args->rmtblkno = args->rmtblkno2;
  842. args->rmtblkcnt = args->rmtblkcnt2;
  843. args->rmtvaluelen = args->rmtvaluelen2;
  844. if (args->rmtblkno) {
  845. error = xfs_attr_rmtval_remove(args);
  846. if (error)
  847. return error;
  848. }
  849. /*
  850. * Re-find the "old" attribute entry after any split ops.
  851. * The INCOMPLETE flag means that we will find the "old"
  852. * attr, not the "new" one.
  853. */
  854. args->flags |= XFS_ATTR_INCOMPLETE;
  855. state = xfs_da_state_alloc();
  856. state->args = args;
  857. state->mp = mp;
  858. state->inleaf = 0;
  859. error = xfs_da3_node_lookup_int(state, &retval);
  860. if (error)
  861. goto out;
  862. /*
  863. * Remove the name and update the hashvals in the tree.
  864. */
  865. blk = &state->path.blk[ state->path.active-1 ];
  866. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  867. error = xfs_attr3_leaf_remove(blk->bp, args);
  868. xfs_da3_fixhashpath(state, &state->path);
  869. /*
  870. * Check to see if the tree needs to be collapsed.
  871. */
  872. if (retval && (state->path.active > 1)) {
  873. xfs_defer_init(args->dfops, args->firstblock);
  874. error = xfs_da3_join(state);
  875. if (!error)
  876. error = xfs_defer_finish(&args->trans,
  877. args->dfops, dp);
  878. if (error) {
  879. args->trans = NULL;
  880. xfs_defer_cancel(args->dfops);
  881. goto out;
  882. }
  883. }
  884. /*
  885. * Commit and start the next trans in the chain.
  886. */
  887. error = xfs_trans_roll(&args->trans, dp);
  888. if (error)
  889. goto out;
  890. } else if (args->rmtblkno > 0) {
  891. /*
  892. * Added a "remote" value, just clear the incomplete flag.
  893. */
  894. error = xfs_attr3_leaf_clearflag(args);
  895. if (error)
  896. goto out;
  897. }
  898. retval = error = 0;
  899. out:
  900. if (state)
  901. xfs_da_state_free(state);
  902. if (error)
  903. return error;
  904. return retval;
  905. }
  906. /*
  907. * Remove a name from a B-tree attribute list.
  908. *
  909. * This will involve walking down the Btree, and may involve joining
  910. * leaf nodes and even joining intermediate nodes up to and including
  911. * the root node (a special case of an intermediate node).
  912. */
  913. STATIC int
  914. xfs_attr_node_removename(xfs_da_args_t *args)
  915. {
  916. xfs_da_state_t *state;
  917. xfs_da_state_blk_t *blk;
  918. xfs_inode_t *dp;
  919. struct xfs_buf *bp;
  920. int retval, error, forkoff;
  921. trace_xfs_attr_node_removename(args);
  922. /*
  923. * Tie a string around our finger to remind us where we are.
  924. */
  925. dp = args->dp;
  926. state = xfs_da_state_alloc();
  927. state->args = args;
  928. state->mp = dp->i_mount;
  929. /*
  930. * Search to see if name exists, and get back a pointer to it.
  931. */
  932. error = xfs_da3_node_lookup_int(state, &retval);
  933. if (error || (retval != -EEXIST)) {
  934. if (error == 0)
  935. error = retval;
  936. goto out;
  937. }
  938. /*
  939. * If there is an out-of-line value, de-allocate the blocks.
  940. * This is done before we remove the attribute so that we don't
  941. * overflow the maximum size of a transaction and/or hit a deadlock.
  942. */
  943. blk = &state->path.blk[ state->path.active-1 ];
  944. ASSERT(blk->bp != NULL);
  945. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  946. if (args->rmtblkno > 0) {
  947. /*
  948. * Fill in disk block numbers in the state structure
  949. * so that we can get the buffers back after we commit
  950. * several transactions in the following calls.
  951. */
  952. error = xfs_attr_fillstate(state);
  953. if (error)
  954. goto out;
  955. /*
  956. * Mark the attribute as INCOMPLETE, then bunmapi() the
  957. * remote value.
  958. */
  959. error = xfs_attr3_leaf_setflag(args);
  960. if (error)
  961. goto out;
  962. error = xfs_attr_rmtval_remove(args);
  963. if (error)
  964. goto out;
  965. /*
  966. * Refill the state structure with buffers, the prior calls
  967. * released our buffers.
  968. */
  969. error = xfs_attr_refillstate(state);
  970. if (error)
  971. goto out;
  972. }
  973. /*
  974. * Remove the name and update the hashvals in the tree.
  975. */
  976. blk = &state->path.blk[ state->path.active-1 ];
  977. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  978. retval = xfs_attr3_leaf_remove(blk->bp, args);
  979. xfs_da3_fixhashpath(state, &state->path);
  980. /*
  981. * Check to see if the tree needs to be collapsed.
  982. */
  983. if (retval && (state->path.active > 1)) {
  984. xfs_defer_init(args->dfops, args->firstblock);
  985. error = xfs_da3_join(state);
  986. if (!error)
  987. error = xfs_defer_finish(&args->trans, args->dfops, dp);
  988. if (error) {
  989. args->trans = NULL;
  990. xfs_defer_cancel(args->dfops);
  991. goto out;
  992. }
  993. /*
  994. * Commit the Btree join operation and start a new trans.
  995. */
  996. error = xfs_trans_roll(&args->trans, dp);
  997. if (error)
  998. goto out;
  999. }
  1000. /*
  1001. * If the result is small enough, push it all into the inode.
  1002. */
  1003. if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
  1004. /*
  1005. * Have to get rid of the copy of this dabuf in the state.
  1006. */
  1007. ASSERT(state->path.active == 1);
  1008. ASSERT(state->path.blk[0].bp);
  1009. state->path.blk[0].bp = NULL;
  1010. error = xfs_attr3_leaf_read(args->trans, args->dp, 0, -1, &bp);
  1011. if (error)
  1012. goto out;
  1013. if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
  1014. xfs_defer_init(args->dfops, args->firstblock);
  1015. error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
  1016. /* bp is gone due to xfs_da_shrink_inode */
  1017. if (!error)
  1018. error = xfs_defer_finish(&args->trans,
  1019. args->dfops, dp);
  1020. if (error) {
  1021. args->trans = NULL;
  1022. xfs_defer_cancel(args->dfops);
  1023. goto out;
  1024. }
  1025. } else
  1026. xfs_trans_brelse(args->trans, bp);
  1027. }
  1028. error = 0;
  1029. out:
  1030. xfs_da_state_free(state);
  1031. return error;
  1032. }
  1033. /*
  1034. * Fill in the disk block numbers in the state structure for the buffers
  1035. * that are attached to the state structure.
  1036. * This is done so that we can quickly reattach ourselves to those buffers
  1037. * after some set of transaction commits have released these buffers.
  1038. */
  1039. STATIC int
  1040. xfs_attr_fillstate(xfs_da_state_t *state)
  1041. {
  1042. xfs_da_state_path_t *path;
  1043. xfs_da_state_blk_t *blk;
  1044. int level;
  1045. trace_xfs_attr_fillstate(state->args);
  1046. /*
  1047. * Roll down the "path" in the state structure, storing the on-disk
  1048. * block number for those buffers in the "path".
  1049. */
  1050. path = &state->path;
  1051. ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
  1052. for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
  1053. if (blk->bp) {
  1054. blk->disk_blkno = XFS_BUF_ADDR(blk->bp);
  1055. blk->bp = NULL;
  1056. } else {
  1057. blk->disk_blkno = 0;
  1058. }
  1059. }
  1060. /*
  1061. * Roll down the "altpath" in the state structure, storing the on-disk
  1062. * block number for those buffers in the "altpath".
  1063. */
  1064. path = &state->altpath;
  1065. ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
  1066. for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
  1067. if (blk->bp) {
  1068. blk->disk_blkno = XFS_BUF_ADDR(blk->bp);
  1069. blk->bp = NULL;
  1070. } else {
  1071. blk->disk_blkno = 0;
  1072. }
  1073. }
  1074. return 0;
  1075. }
  1076. /*
  1077. * Reattach the buffers to the state structure based on the disk block
  1078. * numbers stored in the state structure.
  1079. * This is done after some set of transaction commits have released those
  1080. * buffers from our grip.
  1081. */
  1082. STATIC int
  1083. xfs_attr_refillstate(xfs_da_state_t *state)
  1084. {
  1085. xfs_da_state_path_t *path;
  1086. xfs_da_state_blk_t *blk;
  1087. int level, error;
  1088. trace_xfs_attr_refillstate(state->args);
  1089. /*
  1090. * Roll down the "path" in the state structure, storing the on-disk
  1091. * block number for those buffers in the "path".
  1092. */
  1093. path = &state->path;
  1094. ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
  1095. for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
  1096. if (blk->disk_blkno) {
  1097. error = xfs_da3_node_read(state->args->trans,
  1098. state->args->dp,
  1099. blk->blkno, blk->disk_blkno,
  1100. &blk->bp, XFS_ATTR_FORK);
  1101. if (error)
  1102. return error;
  1103. } else {
  1104. blk->bp = NULL;
  1105. }
  1106. }
  1107. /*
  1108. * Roll down the "altpath" in the state structure, storing the on-disk
  1109. * block number for those buffers in the "altpath".
  1110. */
  1111. path = &state->altpath;
  1112. ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
  1113. for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
  1114. if (blk->disk_blkno) {
  1115. error = xfs_da3_node_read(state->args->trans,
  1116. state->args->dp,
  1117. blk->blkno, blk->disk_blkno,
  1118. &blk->bp, XFS_ATTR_FORK);
  1119. if (error)
  1120. return error;
  1121. } else {
  1122. blk->bp = NULL;
  1123. }
  1124. }
  1125. return 0;
  1126. }
  1127. /*
  1128. * Look up a filename in a node attribute list.
  1129. *
  1130. * This routine gets called for any attribute fork that has more than one
  1131. * block, ie: both true Btree attr lists and for single-leaf-blocks with
  1132. * "remote" values taking up more blocks.
  1133. */
  1134. STATIC int
  1135. xfs_attr_node_get(xfs_da_args_t *args)
  1136. {
  1137. xfs_da_state_t *state;
  1138. xfs_da_state_blk_t *blk;
  1139. int error, retval;
  1140. int i;
  1141. trace_xfs_attr_node_get(args);
  1142. state = xfs_da_state_alloc();
  1143. state->args = args;
  1144. state->mp = args->dp->i_mount;
  1145. /*
  1146. * Search to see if name exists, and get back a pointer to it.
  1147. */
  1148. error = xfs_da3_node_lookup_int(state, &retval);
  1149. if (error) {
  1150. retval = error;
  1151. } else if (retval == -EEXIST) {
  1152. blk = &state->path.blk[ state->path.active-1 ];
  1153. ASSERT(blk->bp != NULL);
  1154. ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
  1155. /*
  1156. * Get the value, local or "remote"
  1157. */
  1158. retval = xfs_attr3_leaf_getvalue(blk->bp, args);
  1159. if (!retval && (args->rmtblkno > 0)
  1160. && !(args->flags & ATTR_KERNOVAL)) {
  1161. retval = xfs_attr_rmtval_get(args);
  1162. }
  1163. }
  1164. /*
  1165. * If not in a transaction, we have to release all the buffers.
  1166. */
  1167. for (i = 0; i < state->path.active; i++) {
  1168. xfs_trans_brelse(args->trans, state->path.blk[i].bp);
  1169. state->path.blk[i].bp = NULL;
  1170. }
  1171. xfs_da_state_free(state);
  1172. return retval;
  1173. }