xfs_attr_remote.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * Copyright (c) 2013 Red Hat, Inc.
  4. * All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it would be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "xfs.h"
  20. #include "xfs_fs.h"
  21. #include "xfs_shared.h"
  22. #include "xfs_format.h"
  23. #include "xfs_log_format.h"
  24. #include "xfs_trans_resv.h"
  25. #include "xfs_bit.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_da_format.h"
  28. #include "xfs_da_btree.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_attr.h"
  36. #include "xfs_attr_leaf.h"
  37. #include "xfs_attr_remote.h"
  38. #include "xfs_trans_space.h"
  39. #include "xfs_trace.h"
  40. #include "xfs_cksum.h"
  41. #include "xfs_buf_item.h"
  42. #include "xfs_error.h"
  43. #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
  44. /*
  45. * Each contiguous block has a header, so it is not just a simple attribute
  46. * length to FSB conversion.
  47. */
  48. int
  49. xfs_attr3_rmt_blocks(
  50. struct xfs_mount *mp,
  51. int attrlen)
  52. {
  53. if (xfs_sb_version_hascrc(&mp->m_sb)) {
  54. int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
  55. return (attrlen + buflen - 1) / buflen;
  56. }
  57. return XFS_B_TO_FSB(mp, attrlen);
  58. }
  59. /*
  60. * Checking of the remote attribute header is split into two parts. The verifier
  61. * does CRC, location and bounds checking, the unpacking function checks the
  62. * attribute parameters and owner.
  63. */
  64. static bool
  65. xfs_attr3_rmt_hdr_ok(
  66. void *ptr,
  67. xfs_ino_t ino,
  68. uint32_t offset,
  69. uint32_t size,
  70. xfs_daddr_t bno)
  71. {
  72. struct xfs_attr3_rmt_hdr *rmt = ptr;
  73. if (bno != be64_to_cpu(rmt->rm_blkno))
  74. return false;
  75. if (offset != be32_to_cpu(rmt->rm_offset))
  76. return false;
  77. if (size != be32_to_cpu(rmt->rm_bytes))
  78. return false;
  79. if (ino != be64_to_cpu(rmt->rm_owner))
  80. return false;
  81. /* ok */
  82. return true;
  83. }
  84. static bool
  85. xfs_attr3_rmt_verify(
  86. struct xfs_mount *mp,
  87. void *ptr,
  88. int fsbsize,
  89. xfs_daddr_t bno)
  90. {
  91. struct xfs_attr3_rmt_hdr *rmt = ptr;
  92. if (!xfs_sb_version_hascrc(&mp->m_sb))
  93. return false;
  94. if (rmt->rm_magic != cpu_to_be32(XFS_ATTR3_RMT_MAGIC))
  95. return false;
  96. if (!uuid_equal(&rmt->rm_uuid, &mp->m_sb.sb_meta_uuid))
  97. return false;
  98. if (be64_to_cpu(rmt->rm_blkno) != bno)
  99. return false;
  100. if (be32_to_cpu(rmt->rm_bytes) > fsbsize - sizeof(*rmt))
  101. return false;
  102. if (be32_to_cpu(rmt->rm_offset) +
  103. be32_to_cpu(rmt->rm_bytes) > XFS_XATTR_SIZE_MAX)
  104. return false;
  105. if (rmt->rm_owner == 0)
  106. return false;
  107. return true;
  108. }
  109. static void
  110. xfs_attr3_rmt_read_verify(
  111. struct xfs_buf *bp)
  112. {
  113. struct xfs_mount *mp = bp->b_target->bt_mount;
  114. char *ptr;
  115. int len;
  116. xfs_daddr_t bno;
  117. int blksize = mp->m_attr_geo->blksize;
  118. /* no verification of non-crc buffers */
  119. if (!xfs_sb_version_hascrc(&mp->m_sb))
  120. return;
  121. ptr = bp->b_addr;
  122. bno = bp->b_bn;
  123. len = BBTOB(bp->b_length);
  124. ASSERT(len >= blksize);
  125. while (len > 0) {
  126. if (!xfs_verify_cksum(ptr, blksize, XFS_ATTR3_RMT_CRC_OFF)) {
  127. xfs_buf_ioerror(bp, -EFSBADCRC);
  128. break;
  129. }
  130. if (!xfs_attr3_rmt_verify(mp, ptr, blksize, bno)) {
  131. xfs_buf_ioerror(bp, -EFSCORRUPTED);
  132. break;
  133. }
  134. len -= blksize;
  135. ptr += blksize;
  136. bno += BTOBB(blksize);
  137. }
  138. if (bp->b_error)
  139. xfs_verifier_error(bp);
  140. else
  141. ASSERT(len == 0);
  142. }
  143. static void
  144. xfs_attr3_rmt_write_verify(
  145. struct xfs_buf *bp)
  146. {
  147. struct xfs_mount *mp = bp->b_target->bt_mount;
  148. int blksize = mp->m_attr_geo->blksize;
  149. char *ptr;
  150. int len;
  151. xfs_daddr_t bno;
  152. /* no verification of non-crc buffers */
  153. if (!xfs_sb_version_hascrc(&mp->m_sb))
  154. return;
  155. ptr = bp->b_addr;
  156. bno = bp->b_bn;
  157. len = BBTOB(bp->b_length);
  158. ASSERT(len >= blksize);
  159. while (len > 0) {
  160. struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr;
  161. if (!xfs_attr3_rmt_verify(mp, ptr, blksize, bno)) {
  162. xfs_buf_ioerror(bp, -EFSCORRUPTED);
  163. xfs_verifier_error(bp);
  164. return;
  165. }
  166. /*
  167. * Ensure we aren't writing bogus LSNs to disk. See
  168. * xfs_attr3_rmt_hdr_set() for the explanation.
  169. */
  170. if (rmt->rm_lsn != cpu_to_be64(NULLCOMMITLSN)) {
  171. xfs_buf_ioerror(bp, -EFSCORRUPTED);
  172. xfs_verifier_error(bp);
  173. return;
  174. }
  175. xfs_update_cksum(ptr, blksize, XFS_ATTR3_RMT_CRC_OFF);
  176. len -= blksize;
  177. ptr += blksize;
  178. bno += BTOBB(blksize);
  179. }
  180. ASSERT(len == 0);
  181. }
  182. const struct xfs_buf_ops xfs_attr3_rmt_buf_ops = {
  183. .name = "xfs_attr3_rmt",
  184. .verify_read = xfs_attr3_rmt_read_verify,
  185. .verify_write = xfs_attr3_rmt_write_verify,
  186. };
  187. STATIC int
  188. xfs_attr3_rmt_hdr_set(
  189. struct xfs_mount *mp,
  190. void *ptr,
  191. xfs_ino_t ino,
  192. uint32_t offset,
  193. uint32_t size,
  194. xfs_daddr_t bno)
  195. {
  196. struct xfs_attr3_rmt_hdr *rmt = ptr;
  197. if (!xfs_sb_version_hascrc(&mp->m_sb))
  198. return 0;
  199. rmt->rm_magic = cpu_to_be32(XFS_ATTR3_RMT_MAGIC);
  200. rmt->rm_offset = cpu_to_be32(offset);
  201. rmt->rm_bytes = cpu_to_be32(size);
  202. uuid_copy(&rmt->rm_uuid, &mp->m_sb.sb_meta_uuid);
  203. rmt->rm_owner = cpu_to_be64(ino);
  204. rmt->rm_blkno = cpu_to_be64(bno);
  205. /*
  206. * Remote attribute blocks are written synchronously, so we don't
  207. * have an LSN that we can stamp in them that makes any sense to log
  208. * recovery. To ensure that log recovery handles overwrites of these
  209. * blocks sanely (i.e. once they've been freed and reallocated as some
  210. * other type of metadata) we need to ensure that the LSN has a value
  211. * that tells log recovery to ignore the LSN and overwrite the buffer
  212. * with whatever is in it's log. To do this, we use the magic
  213. * NULLCOMMITLSN to indicate that the LSN is invalid.
  214. */
  215. rmt->rm_lsn = cpu_to_be64(NULLCOMMITLSN);
  216. return sizeof(struct xfs_attr3_rmt_hdr);
  217. }
  218. /*
  219. * Helper functions to copy attribute data in and out of the one disk extents
  220. */
  221. STATIC int
  222. xfs_attr_rmtval_copyout(
  223. struct xfs_mount *mp,
  224. struct xfs_buf *bp,
  225. xfs_ino_t ino,
  226. int *offset,
  227. int *valuelen,
  228. __uint8_t **dst)
  229. {
  230. char *src = bp->b_addr;
  231. xfs_daddr_t bno = bp->b_bn;
  232. int len = BBTOB(bp->b_length);
  233. int blksize = mp->m_attr_geo->blksize;
  234. ASSERT(len >= blksize);
  235. while (len > 0 && *valuelen > 0) {
  236. int hdr_size = 0;
  237. int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
  238. byte_cnt = min(*valuelen, byte_cnt);
  239. if (xfs_sb_version_hascrc(&mp->m_sb)) {
  240. if (!xfs_attr3_rmt_hdr_ok(src, ino, *offset,
  241. byte_cnt, bno)) {
  242. xfs_alert(mp,
  243. "remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)",
  244. bno, *offset, byte_cnt, ino);
  245. return -EFSCORRUPTED;
  246. }
  247. hdr_size = sizeof(struct xfs_attr3_rmt_hdr);
  248. }
  249. memcpy(*dst, src + hdr_size, byte_cnt);
  250. /* roll buffer forwards */
  251. len -= blksize;
  252. src += blksize;
  253. bno += BTOBB(blksize);
  254. /* roll attribute data forwards */
  255. *valuelen -= byte_cnt;
  256. *dst += byte_cnt;
  257. *offset += byte_cnt;
  258. }
  259. return 0;
  260. }
  261. STATIC void
  262. xfs_attr_rmtval_copyin(
  263. struct xfs_mount *mp,
  264. struct xfs_buf *bp,
  265. xfs_ino_t ino,
  266. int *offset,
  267. int *valuelen,
  268. __uint8_t **src)
  269. {
  270. char *dst = bp->b_addr;
  271. xfs_daddr_t bno = bp->b_bn;
  272. int len = BBTOB(bp->b_length);
  273. int blksize = mp->m_attr_geo->blksize;
  274. ASSERT(len >= blksize);
  275. while (len > 0 && *valuelen > 0) {
  276. int hdr_size;
  277. int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
  278. byte_cnt = min(*valuelen, byte_cnt);
  279. hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset,
  280. byte_cnt, bno);
  281. memcpy(dst + hdr_size, *src, byte_cnt);
  282. /*
  283. * If this is the last block, zero the remainder of it.
  284. * Check that we are actually the last block, too.
  285. */
  286. if (byte_cnt + hdr_size < blksize) {
  287. ASSERT(*valuelen - byte_cnt == 0);
  288. ASSERT(len == blksize);
  289. memset(dst + hdr_size + byte_cnt, 0,
  290. blksize - hdr_size - byte_cnt);
  291. }
  292. /* roll buffer forwards */
  293. len -= blksize;
  294. dst += blksize;
  295. bno += BTOBB(blksize);
  296. /* roll attribute data forwards */
  297. *valuelen -= byte_cnt;
  298. *src += byte_cnt;
  299. *offset += byte_cnt;
  300. }
  301. }
  302. /*
  303. * Read the value associated with an attribute from the out-of-line buffer
  304. * that we stored it in.
  305. */
  306. int
  307. xfs_attr_rmtval_get(
  308. struct xfs_da_args *args)
  309. {
  310. struct xfs_bmbt_irec map[ATTR_RMTVALUE_MAPSIZE];
  311. struct xfs_mount *mp = args->dp->i_mount;
  312. struct xfs_buf *bp;
  313. xfs_dablk_t lblkno = args->rmtblkno;
  314. __uint8_t *dst = args->value;
  315. int valuelen;
  316. int nmap;
  317. int error;
  318. int blkcnt = args->rmtblkcnt;
  319. int i;
  320. int offset = 0;
  321. trace_xfs_attr_rmtval_get(args);
  322. ASSERT(!(args->flags & ATTR_KERNOVAL));
  323. ASSERT(args->rmtvaluelen == args->valuelen);
  324. valuelen = args->rmtvaluelen;
  325. while (valuelen > 0) {
  326. nmap = ATTR_RMTVALUE_MAPSIZE;
  327. error = xfs_bmapi_read(args->dp, (xfs_fileoff_t)lblkno,
  328. blkcnt, map, &nmap,
  329. XFS_BMAPI_ATTRFORK);
  330. if (error)
  331. return error;
  332. ASSERT(nmap >= 1);
  333. for (i = 0; (i < nmap) && (valuelen > 0); i++) {
  334. xfs_daddr_t dblkno;
  335. int dblkcnt;
  336. ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
  337. (map[i].br_startblock != HOLESTARTBLOCK));
  338. dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
  339. dblkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
  340. error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp,
  341. dblkno, dblkcnt, 0, &bp,
  342. &xfs_attr3_rmt_buf_ops);
  343. if (error)
  344. return error;
  345. error = xfs_attr_rmtval_copyout(mp, bp, args->dp->i_ino,
  346. &offset, &valuelen,
  347. &dst);
  348. xfs_buf_relse(bp);
  349. if (error)
  350. return error;
  351. /* roll attribute extent map forwards */
  352. lblkno += map[i].br_blockcount;
  353. blkcnt -= map[i].br_blockcount;
  354. }
  355. }
  356. ASSERT(valuelen == 0);
  357. return 0;
  358. }
  359. /*
  360. * Write the value associated with an attribute into the out-of-line buffer
  361. * that we have defined for it.
  362. */
  363. int
  364. xfs_attr_rmtval_set(
  365. struct xfs_da_args *args)
  366. {
  367. struct xfs_inode *dp = args->dp;
  368. struct xfs_mount *mp = dp->i_mount;
  369. struct xfs_bmbt_irec map;
  370. xfs_dablk_t lblkno;
  371. xfs_fileoff_t lfileoff = 0;
  372. __uint8_t *src = args->value;
  373. int blkcnt;
  374. int valuelen;
  375. int nmap;
  376. int error;
  377. int offset = 0;
  378. trace_xfs_attr_rmtval_set(args);
  379. /*
  380. * Find a "hole" in the attribute address space large enough for
  381. * us to drop the new attribute's value into. Because CRC enable
  382. * attributes have headers, we can't just do a straight byte to FSB
  383. * conversion and have to take the header space into account.
  384. */
  385. blkcnt = xfs_attr3_rmt_blocks(mp, args->rmtvaluelen);
  386. error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
  387. XFS_ATTR_FORK);
  388. if (error)
  389. return error;
  390. args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
  391. args->rmtblkcnt = blkcnt;
  392. /*
  393. * Roll through the "value", allocating blocks on disk as required.
  394. */
  395. while (blkcnt > 0) {
  396. int committed;
  397. /*
  398. * Allocate a single extent, up to the size of the value.
  399. *
  400. * Note that we have to consider this a data allocation as we
  401. * write the remote attribute without logging the contents.
  402. * Hence we must ensure that we aren't using blocks that are on
  403. * the busy list so that we don't overwrite blocks which have
  404. * recently been freed but their transactions are not yet
  405. * committed to disk. If we overwrite the contents of a busy
  406. * extent and then crash then the block may not contain the
  407. * correct metadata after log recovery occurs.
  408. */
  409. xfs_bmap_init(args->flist, args->firstblock);
  410. nmap = 1;
  411. error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno,
  412. blkcnt, XFS_BMAPI_ATTRFORK, args->firstblock,
  413. args->total, &map, &nmap, args->flist);
  414. if (!error) {
  415. error = xfs_bmap_finish(&args->trans, args->flist,
  416. &committed);
  417. }
  418. if (error) {
  419. ASSERT(committed);
  420. args->trans = NULL;
  421. xfs_bmap_cancel(args->flist);
  422. return error;
  423. }
  424. /*
  425. * bmap_finish() may have committed the last trans and started
  426. * a new one. We need the inode to be in all transactions.
  427. */
  428. if (committed)
  429. xfs_trans_ijoin(args->trans, dp, 0);
  430. ASSERT(nmap == 1);
  431. ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
  432. (map.br_startblock != HOLESTARTBLOCK));
  433. lblkno += map.br_blockcount;
  434. blkcnt -= map.br_blockcount;
  435. /*
  436. * Start the next trans in the chain.
  437. */
  438. error = xfs_trans_roll(&args->trans, dp);
  439. if (error)
  440. return error;
  441. }
  442. /*
  443. * Roll through the "value", copying the attribute value to the
  444. * already-allocated blocks. Blocks are written synchronously
  445. * so that we can know they are all on disk before we turn off
  446. * the INCOMPLETE flag.
  447. */
  448. lblkno = args->rmtblkno;
  449. blkcnt = args->rmtblkcnt;
  450. valuelen = args->rmtvaluelen;
  451. while (valuelen > 0) {
  452. struct xfs_buf *bp;
  453. xfs_daddr_t dblkno;
  454. int dblkcnt;
  455. ASSERT(blkcnt > 0);
  456. xfs_bmap_init(args->flist, args->firstblock);
  457. nmap = 1;
  458. error = xfs_bmapi_read(dp, (xfs_fileoff_t)lblkno,
  459. blkcnt, &map, &nmap,
  460. XFS_BMAPI_ATTRFORK);
  461. if (error)
  462. return error;
  463. ASSERT(nmap == 1);
  464. ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
  465. (map.br_startblock != HOLESTARTBLOCK));
  466. dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
  467. dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
  468. bp = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, 0);
  469. if (!bp)
  470. return -ENOMEM;
  471. bp->b_ops = &xfs_attr3_rmt_buf_ops;
  472. xfs_attr_rmtval_copyin(mp, bp, args->dp->i_ino, &offset,
  473. &valuelen, &src);
  474. error = xfs_bwrite(bp); /* GROT: NOTE: synchronous write */
  475. xfs_buf_relse(bp);
  476. if (error)
  477. return error;
  478. /* roll attribute extent map forwards */
  479. lblkno += map.br_blockcount;
  480. blkcnt -= map.br_blockcount;
  481. }
  482. ASSERT(valuelen == 0);
  483. return 0;
  484. }
  485. /*
  486. * Remove the value associated with an attribute by deleting the
  487. * out-of-line buffer that it is stored on.
  488. */
  489. int
  490. xfs_attr_rmtval_remove(
  491. struct xfs_da_args *args)
  492. {
  493. struct xfs_mount *mp = args->dp->i_mount;
  494. xfs_dablk_t lblkno;
  495. int blkcnt;
  496. int error;
  497. int done;
  498. trace_xfs_attr_rmtval_remove(args);
  499. /*
  500. * Roll through the "value", invalidating the attribute value's blocks.
  501. */
  502. lblkno = args->rmtblkno;
  503. blkcnt = args->rmtblkcnt;
  504. while (blkcnt > 0) {
  505. struct xfs_bmbt_irec map;
  506. struct xfs_buf *bp;
  507. xfs_daddr_t dblkno;
  508. int dblkcnt;
  509. int nmap;
  510. /*
  511. * Try to remember where we decided to put the value.
  512. */
  513. nmap = 1;
  514. error = xfs_bmapi_read(args->dp, (xfs_fileoff_t)lblkno,
  515. blkcnt, &map, &nmap, XFS_BMAPI_ATTRFORK);
  516. if (error)
  517. return error;
  518. ASSERT(nmap == 1);
  519. ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
  520. (map.br_startblock != HOLESTARTBLOCK));
  521. dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
  522. dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
  523. /*
  524. * If the "remote" value is in the cache, remove it.
  525. */
  526. bp = xfs_incore(mp->m_ddev_targp, dblkno, dblkcnt, XBF_TRYLOCK);
  527. if (bp) {
  528. xfs_buf_stale(bp);
  529. xfs_buf_relse(bp);
  530. bp = NULL;
  531. }
  532. lblkno += map.br_blockcount;
  533. blkcnt -= map.br_blockcount;
  534. }
  535. /*
  536. * Keep de-allocating extents until the remote-value region is gone.
  537. */
  538. lblkno = args->rmtblkno;
  539. blkcnt = args->rmtblkcnt;
  540. done = 0;
  541. while (!done) {
  542. int committed;
  543. xfs_bmap_init(args->flist, args->firstblock);
  544. error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
  545. XFS_BMAPI_ATTRFORK, 1, args->firstblock,
  546. args->flist, &done);
  547. if (!error) {
  548. error = xfs_bmap_finish(&args->trans, args->flist,
  549. &committed);
  550. }
  551. if (error) {
  552. ASSERT(committed);
  553. args->trans = NULL;
  554. xfs_bmap_cancel(args->flist);
  555. return error;
  556. }
  557. /*
  558. * bmap_finish() may have committed the last trans and started
  559. * a new one. We need the inode to be in all transactions.
  560. */
  561. if (committed)
  562. xfs_trans_ijoin(args->trans, args->dp, 0);
  563. /*
  564. * Close out trans and start the next one in the chain.
  565. */
  566. error = xfs_trans_roll(&args->trans, args->dp);
  567. if (error)
  568. return error;
  569. }
  570. return 0;
  571. }