]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - fs/xfs/xfs_attr_remote.c
xfs: validity check the directory block leaf entry count
[mirror_ubuntu-zesty-kernel.git] / fs / xfs / xfs_attr_remote.c
CommitLineData
95920cd6
DC
1/*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
d2e448d5 3 * Copyright (c) 2013 Red Hat, Inc.
95920cd6
DC
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"
a4fbe6ab 21#include "xfs_format.h"
239880ef
DC
22#include "xfs_log_format.h"
23#include "xfs_trans_resv.h"
95920cd6 24#include "xfs_bit.h"
95920cd6
DC
25#include "xfs_sb.h"
26#include "xfs_ag.h"
27#include "xfs_mount.h"
57062787 28#include "xfs_da_format.h"
95920cd6 29#include "xfs_da_btree.h"
95920cd6
DC
30#include "xfs_inode.h"
31#include "xfs_alloc.h"
239880ef 32#include "xfs_trans.h"
95920cd6
DC
33#include "xfs_inode_item.h"
34#include "xfs_bmap.h"
68988114 35#include "xfs_bmap_util.h"
95920cd6
DC
36#include "xfs_attr.h"
37#include "xfs_attr_leaf.h"
38#include "xfs_attr_remote.h"
39#include "xfs_trans_space.h"
40#include "xfs_trace.h"
d2e448d5
DC
41#include "xfs_cksum.h"
42#include "xfs_buf_item.h"
a4fbe6ab 43#include "xfs_error.h"
95920cd6
DC
44
45#define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
46
d2e448d5
DC
47/*
48 * Each contiguous block has a header, so it is not just a simple attribute
49 * length to FSB conversion.
50 */
7bc0dc27 51int
d2e448d5
DC
52xfs_attr3_rmt_blocks(
53 struct xfs_mount *mp,
54 int attrlen)
55{
551b382f
DC
56 if (xfs_sb_version_hascrc(&mp->m_sb)) {
57 int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
58 return (attrlen + buflen - 1) / buflen;
59 }
60 return XFS_B_TO_FSB(mp, attrlen);
d2e448d5
DC
61}
62
7bc0dc27
DC
63/*
64 * Checking of the remote attribute header is split into two parts. The verifier
65 * does CRC, location and bounds checking, the unpacking function checks the
66 * attribute parameters and owner.
67 */
68static bool
69xfs_attr3_rmt_hdr_ok(
70 struct xfs_mount *mp,
71 void *ptr,
72 xfs_ino_t ino,
73 uint32_t offset,
74 uint32_t size,
75 xfs_daddr_t bno)
76{
77 struct xfs_attr3_rmt_hdr *rmt = ptr;
78
79 if (bno != be64_to_cpu(rmt->rm_blkno))
80 return false;
81 if (offset != be32_to_cpu(rmt->rm_offset))
82 return false;
83 if (size != be32_to_cpu(rmt->rm_bytes))
84 return false;
85 if (ino != be64_to_cpu(rmt->rm_owner))
86 return false;
87
88 /* ok */
89 return true;
90}
91
d2e448d5
DC
92static bool
93xfs_attr3_rmt_verify(
7bc0dc27
DC
94 struct xfs_mount *mp,
95 void *ptr,
96 int fsbsize,
97 xfs_daddr_t bno)
d2e448d5 98{
7bc0dc27 99 struct xfs_attr3_rmt_hdr *rmt = ptr;
d2e448d5
DC
100
101 if (!xfs_sb_version_hascrc(&mp->m_sb))
102 return false;
103 if (rmt->rm_magic != cpu_to_be32(XFS_ATTR3_RMT_MAGIC))
104 return false;
105 if (!uuid_equal(&rmt->rm_uuid, &mp->m_sb.sb_uuid))
106 return false;
7bc0dc27
DC
107 if (be64_to_cpu(rmt->rm_blkno) != bno)
108 return false;
109 if (be32_to_cpu(rmt->rm_bytes) > fsbsize - sizeof(*rmt))
d2e448d5
DC
110 return false;
111 if (be32_to_cpu(rmt->rm_offset) +
946217ba 112 be32_to_cpu(rmt->rm_bytes) >= XATTR_SIZE_MAX)
d2e448d5
DC
113 return false;
114 if (rmt->rm_owner == 0)
115 return false;
116
117 return true;
118}
119
120static void
121xfs_attr3_rmt_read_verify(
122 struct xfs_buf *bp)
123{
124 struct xfs_mount *mp = bp->b_target->bt_mount;
7bc0dc27
DC
125 char *ptr;
126 int len;
127 bool corrupt = false;
128 xfs_daddr_t bno;
d2e448d5
DC
129
130 /* no verification of non-crc buffers */
131 if (!xfs_sb_version_hascrc(&mp->m_sb))
132 return;
133
7bc0dc27
DC
134 ptr = bp->b_addr;
135 bno = bp->b_bn;
136 len = BBTOB(bp->b_length);
137 ASSERT(len >= XFS_LBSIZE(mp));
138
139 while (len > 0) {
140 if (!xfs_verify_cksum(ptr, XFS_LBSIZE(mp),
141 XFS_ATTR3_RMT_CRC_OFF)) {
142 corrupt = true;
143 break;
144 }
145 if (!xfs_attr3_rmt_verify(mp, ptr, XFS_LBSIZE(mp), bno)) {
146 corrupt = true;
147 break;
148 }
149 len -= XFS_LBSIZE(mp);
150 ptr += XFS_LBSIZE(mp);
151 bno += mp->m_bsize;
152 }
153
154 if (corrupt) {
d2e448d5
DC
155 XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr);
156 xfs_buf_ioerror(bp, EFSCORRUPTED);
7bc0dc27
DC
157 } else
158 ASSERT(len == 0);
d2e448d5
DC
159}
160
161static void
162xfs_attr3_rmt_write_verify(
163 struct xfs_buf *bp)
164{
165 struct xfs_mount *mp = bp->b_target->bt_mount;
166 struct xfs_buf_log_item *bip = bp->b_fspriv;
7bc0dc27
DC
167 char *ptr;
168 int len;
169 xfs_daddr_t bno;
d2e448d5
DC
170
171 /* no verification of non-crc buffers */
172 if (!xfs_sb_version_hascrc(&mp->m_sb))
173 return;
174
7bc0dc27
DC
175 ptr = bp->b_addr;
176 bno = bp->b_bn;
177 len = BBTOB(bp->b_length);
178 ASSERT(len >= XFS_LBSIZE(mp));
179
180 while (len > 0) {
181 if (!xfs_attr3_rmt_verify(mp, ptr, XFS_LBSIZE(mp), bno)) {
182 XFS_CORRUPTION_ERROR(__func__,
183 XFS_ERRLEVEL_LOW, mp, bp->b_addr);
184 xfs_buf_ioerror(bp, EFSCORRUPTED);
185 return;
186 }
187 if (bip) {
188 struct xfs_attr3_rmt_hdr *rmt;
d2e448d5 189
7bc0dc27
DC
190 rmt = (struct xfs_attr3_rmt_hdr *)ptr;
191 rmt->rm_lsn = cpu_to_be64(bip->bli_item.li_lsn);
192 }
193 xfs_update_cksum(ptr, XFS_LBSIZE(mp), XFS_ATTR3_RMT_CRC_OFF);
194
195 len -= XFS_LBSIZE(mp);
196 ptr += XFS_LBSIZE(mp);
197 bno += mp->m_bsize;
d2e448d5 198 }
7bc0dc27 199 ASSERT(len == 0);
d2e448d5
DC
200}
201
202const struct xfs_buf_ops xfs_attr3_rmt_buf_ops = {
203 .verify_read = xfs_attr3_rmt_read_verify,
204 .verify_write = xfs_attr3_rmt_write_verify,
205};
206
7bc0dc27 207STATIC int
d2e448d5
DC
208xfs_attr3_rmt_hdr_set(
209 struct xfs_mount *mp,
7bc0dc27 210 void *ptr,
d2e448d5
DC
211 xfs_ino_t ino,
212 uint32_t offset,
213 uint32_t size,
7bc0dc27 214 xfs_daddr_t bno)
d2e448d5 215{
7bc0dc27 216 struct xfs_attr3_rmt_hdr *rmt = ptr;
d2e448d5
DC
217
218 if (!xfs_sb_version_hascrc(&mp->m_sb))
219 return 0;
220
221 rmt->rm_magic = cpu_to_be32(XFS_ATTR3_RMT_MAGIC);
222 rmt->rm_offset = cpu_to_be32(offset);
223 rmt->rm_bytes = cpu_to_be32(size);
224 uuid_copy(&rmt->rm_uuid, &mp->m_sb.sb_uuid);
225 rmt->rm_owner = cpu_to_be64(ino);
7bc0dc27 226 rmt->rm_blkno = cpu_to_be64(bno);
d2e448d5
DC
227
228 return sizeof(struct xfs_attr3_rmt_hdr);
229}
230
231/*
7bc0dc27 232 * Helper functions to copy attribute data in and out of the one disk extents
d2e448d5 233 */
7bc0dc27
DC
234STATIC int
235xfs_attr_rmtval_copyout(
236 struct xfs_mount *mp,
237 struct xfs_buf *bp,
238 xfs_ino_t ino,
239 int *offset,
240 int *valuelen,
836a94ad 241 __uint8_t **dst)
d2e448d5 242{
7bc0dc27
DC
243 char *src = bp->b_addr;
244 xfs_daddr_t bno = bp->b_bn;
245 int len = BBTOB(bp->b_length);
d2e448d5 246
7bc0dc27 247 ASSERT(len >= XFS_LBSIZE(mp));
d2e448d5 248
7bc0dc27
DC
249 while (len > 0 && *valuelen > 0) {
250 int hdr_size = 0;
251 int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, XFS_LBSIZE(mp));
252
c5c249b4 253 byte_cnt = min(*valuelen, byte_cnt);
7bc0dc27
DC
254
255 if (xfs_sb_version_hascrc(&mp->m_sb)) {
256 if (!xfs_attr3_rmt_hdr_ok(mp, src, ino, *offset,
257 byte_cnt, bno)) {
258 xfs_alert(mp,
259"remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)",
260 bno, *offset, byte_cnt, ino);
261 return EFSCORRUPTED;
262 }
263 hdr_size = sizeof(struct xfs_attr3_rmt_hdr);
264 }
265
266 memcpy(*dst, src + hdr_size, byte_cnt);
267
268 /* roll buffer forwards */
269 len -= XFS_LBSIZE(mp);
270 src += XFS_LBSIZE(mp);
271 bno += mp->m_bsize;
272
273 /* roll attribute data forwards */
274 *valuelen -= byte_cnt;
275 *dst += byte_cnt;
276 *offset += byte_cnt;
277 }
278 return 0;
279}
280
281STATIC void
282xfs_attr_rmtval_copyin(
283 struct xfs_mount *mp,
284 struct xfs_buf *bp,
285 xfs_ino_t ino,
286 int *offset,
287 int *valuelen,
836a94ad 288 __uint8_t **src)
7bc0dc27
DC
289{
290 char *dst = bp->b_addr;
291 xfs_daddr_t bno = bp->b_bn;
292 int len = BBTOB(bp->b_length);
293
294 ASSERT(len >= XFS_LBSIZE(mp));
295
296 while (len > 0 && *valuelen > 0) {
297 int hdr_size;
298 int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, XFS_LBSIZE(mp));
299
300 byte_cnt = min(*valuelen, byte_cnt);
301 hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset,
302 byte_cnt, bno);
303
304 memcpy(dst + hdr_size, *src, byte_cnt);
305
306 /*
307 * If this is the last block, zero the remainder of it.
308 * Check that we are actually the last block, too.
309 */
310 if (byte_cnt + hdr_size < XFS_LBSIZE(mp)) {
311 ASSERT(*valuelen - byte_cnt == 0);
312 ASSERT(len == XFS_LBSIZE(mp));
313 memset(dst + hdr_size + byte_cnt, 0,
314 XFS_LBSIZE(mp) - hdr_size - byte_cnt);
315 }
316
317 /* roll buffer forwards */
318 len -= XFS_LBSIZE(mp);
319 dst += XFS_LBSIZE(mp);
320 bno += mp->m_bsize;
321
322 /* roll attribute data forwards */
323 *valuelen -= byte_cnt;
324 *src += byte_cnt;
325 *offset += byte_cnt;
326 }
d2e448d5
DC
327}
328
95920cd6
DC
329/*
330 * Read the value associated with an attribute from the out-of-line buffer
331 * that we stored it in.
332 */
333int
d2e448d5
DC
334xfs_attr_rmtval_get(
335 struct xfs_da_args *args)
95920cd6 336{
d2e448d5
DC
337 struct xfs_bmbt_irec map[ATTR_RMTVALUE_MAPSIZE];
338 struct xfs_mount *mp = args->dp->i_mount;
339 struct xfs_buf *bp;
d2e448d5 340 xfs_dablk_t lblkno = args->rmtblkno;
836a94ad 341 __uint8_t *dst = args->value;
d2e448d5
DC
342 int valuelen = args->valuelen;
343 int nmap;
344 int error;
7bc0dc27 345 int blkcnt = args->rmtblkcnt;
d2e448d5
DC
346 int i;
347 int offset = 0;
95920cd6
DC
348
349 trace_xfs_attr_rmtval_get(args);
350
351 ASSERT(!(args->flags & ATTR_KERNOVAL));
352
95920cd6
DC
353 while (valuelen > 0) {
354 nmap = ATTR_RMTVALUE_MAPSIZE;
355 error = xfs_bmapi_read(args->dp, (xfs_fileoff_t)lblkno,
551b382f 356 blkcnt, map, &nmap,
95920cd6
DC
357 XFS_BMAPI_ATTRFORK);
358 if (error)
d2e448d5 359 return error;
95920cd6
DC
360 ASSERT(nmap >= 1);
361
362 for (i = 0; (i < nmap) && (valuelen > 0); i++) {
7bc0dc27
DC
363 xfs_daddr_t dblkno;
364 int dblkcnt;
d2e448d5 365
95920cd6
DC
366 ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
367 (map[i].br_startblock != HOLESTARTBLOCK));
368 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
7bc0dc27 369 dblkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
95920cd6 370 error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp,
7bc0dc27 371 dblkno, dblkcnt, 0, &bp,
d2e448d5 372 &xfs_attr3_rmt_buf_ops);
95920cd6 373 if (error)
d2e448d5
DC
374 return error;
375
7bc0dc27
DC
376 error = xfs_attr_rmtval_copyout(mp, bp, args->dp->i_ino,
377 &offset, &valuelen,
378 &dst);
95920cd6 379 xfs_buf_relse(bp);
7bc0dc27
DC
380 if (error)
381 return error;
d2e448d5 382
7bc0dc27 383 /* roll attribute extent map forwards */
95920cd6 384 lblkno += map[i].br_blockcount;
7bc0dc27 385 blkcnt -= map[i].br_blockcount;
95920cd6
DC
386 }
387 }
388 ASSERT(valuelen == 0);
d2e448d5 389 return 0;
95920cd6
DC
390}
391
392/*
393 * Write the value associated with an attribute into the out-of-line buffer
394 * that we have defined for it.
395 */
396int
d2e448d5
DC
397xfs_attr_rmtval_set(
398 struct xfs_da_args *args)
95920cd6 399{
d2e448d5
DC
400 struct xfs_inode *dp = args->dp;
401 struct xfs_mount *mp = dp->i_mount;
402 struct xfs_bmbt_irec map;
d2e448d5
DC
403 xfs_dablk_t lblkno;
404 xfs_fileoff_t lfileoff = 0;
836a94ad 405 __uint8_t *src = args->value;
d2e448d5
DC
406 int blkcnt;
407 int valuelen;
408 int nmap;
409 int error;
d2e448d5 410 int offset = 0;
95920cd6
DC
411
412 trace_xfs_attr_rmtval_set(args);
413
95920cd6
DC
414 /*
415 * Find a "hole" in the attribute address space large enough for
d2e448d5
DC
416 * us to drop the new attribute's value into. Because CRC enable
417 * attributes have headers, we can't just do a straight byte to FSB
7bc0dc27 418 * conversion and have to take the header space into account.
95920cd6 419 */
26f71445 420 blkcnt = xfs_attr3_rmt_blocks(mp, args->valuelen);
95920cd6
DC
421 error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
422 XFS_ATTR_FORK);
d2e448d5
DC
423 if (error)
424 return error;
425
95920cd6
DC
426 args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
427 args->rmtblkcnt = blkcnt;
428
429 /*
430 * Roll through the "value", allocating blocks on disk as required.
431 */
432 while (blkcnt > 0) {
d2e448d5
DC
433 int committed;
434
95920cd6
DC
435 /*
436 * Allocate a single extent, up to the size of the value.
437 */
438 xfs_bmap_init(args->flist, args->firstblock);
439 nmap = 1;
440 error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno,
441 blkcnt,
442 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
443 args->firstblock, args->total, &map, &nmap,
444 args->flist);
445 if (!error) {
446 error = xfs_bmap_finish(&args->trans, args->flist,
447 &committed);
448 }
449 if (error) {
450 ASSERT(committed);
451 args->trans = NULL;
452 xfs_bmap_cancel(args->flist);
453 return(error);
454 }
455
456 /*
457 * bmap_finish() may have committed the last trans and started
458 * a new one. We need the inode to be in all transactions.
459 */
460 if (committed)
461 xfs_trans_ijoin(args->trans, dp, 0);
462
463 ASSERT(nmap == 1);
464 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
465 (map.br_startblock != HOLESTARTBLOCK));
466 lblkno += map.br_blockcount;
467 blkcnt -= map.br_blockcount;
468
469 /*
470 * Start the next trans in the chain.
471 */
472 error = xfs_trans_roll(&args->trans, dp);
473 if (error)
474 return (error);
475 }
476
477 /*
478 * Roll through the "value", copying the attribute value to the
479 * already-allocated blocks. Blocks are written synchronously
480 * so that we can know they are all on disk before we turn off
481 * the INCOMPLETE flag.
482 */
483 lblkno = args->rmtblkno;
26f71445 484 blkcnt = args->rmtblkcnt;
7bc0dc27 485 valuelen = args->valuelen;
95920cd6 486 while (valuelen > 0) {
7bc0dc27
DC
487 struct xfs_buf *bp;
488 xfs_daddr_t dblkno;
489 int dblkcnt;
490
491 ASSERT(blkcnt > 0);
95920cd6 492
95920cd6
DC
493 xfs_bmap_init(args->flist, args->firstblock);
494 nmap = 1;
495 error = xfs_bmapi_read(dp, (xfs_fileoff_t)lblkno,
26f71445 496 blkcnt, &map, &nmap,
95920cd6
DC
497 XFS_BMAPI_ATTRFORK);
498 if (error)
499 return(error);
500 ASSERT(nmap == 1);
501 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
502 (map.br_startblock != HOLESTARTBLOCK));
503
504 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
26f71445 505 dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
95920cd6 506
26f71445 507 bp = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, 0);
95920cd6
DC
508 if (!bp)
509 return ENOMEM;
d2e448d5 510 bp->b_ops = &xfs_attr3_rmt_buf_ops;
26f71445 511
7bc0dc27
DC
512 xfs_attr_rmtval_copyin(mp, bp, args->dp->i_ino, &offset,
513 &valuelen, &src);
95920cd6
DC
514
515 error = xfs_bwrite(bp); /* GROT: NOTE: synchronous write */
516 xfs_buf_relse(bp);
517 if (error)
518 return error;
d2e448d5 519
95920cd6 520
7bc0dc27 521 /* roll attribute extent map forwards */
95920cd6 522 lblkno += map.br_blockcount;
26f71445 523 blkcnt -= map.br_blockcount;
95920cd6
DC
524 }
525 ASSERT(valuelen == 0);
d2e448d5 526 return 0;
95920cd6
DC
527}
528
529/*
530 * Remove the value associated with an attribute by deleting the
531 * out-of-line buffer that it is stored on.
532 */
533int
7bc0dc27
DC
534xfs_attr_rmtval_remove(
535 struct xfs_da_args *args)
95920cd6 536{
7bc0dc27
DC
537 struct xfs_mount *mp = args->dp->i_mount;
538 xfs_dablk_t lblkno;
539 int blkcnt;
540 int error;
541 int done;
95920cd6
DC
542
543 trace_xfs_attr_rmtval_remove(args);
544
95920cd6 545 /*
58a72281 546 * Roll through the "value", invalidating the attribute value's blocks.
95920cd6
DC
547 */
548 lblkno = args->rmtblkno;
7bc0dc27
DC
549 blkcnt = args->rmtblkcnt;
550 while (blkcnt > 0) {
551 struct xfs_bmbt_irec map;
552 struct xfs_buf *bp;
553 xfs_daddr_t dblkno;
554 int dblkcnt;
555 int nmap;
58a72281 556
95920cd6
DC
557 /*
558 * Try to remember where we decided to put the value.
559 */
560 nmap = 1;
561 error = xfs_bmapi_read(args->dp, (xfs_fileoff_t)lblkno,
58a72281 562 blkcnt, &map, &nmap, XFS_BMAPI_ATTRFORK);
95920cd6
DC
563 if (error)
564 return(error);
565 ASSERT(nmap == 1);
566 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
567 (map.br_startblock != HOLESTARTBLOCK));
568
569 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
58a72281 570 dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
95920cd6
DC
571
572 /*
573 * If the "remote" value is in the cache, remove it.
574 */
58a72281 575 bp = xfs_incore(mp->m_ddev_targp, dblkno, dblkcnt, XBF_TRYLOCK);
95920cd6
DC
576 if (bp) {
577 xfs_buf_stale(bp);
578 xfs_buf_relse(bp);
579 bp = NULL;
580 }
581
95920cd6 582 lblkno += map.br_blockcount;
58a72281 583 blkcnt -= map.br_blockcount;
95920cd6
DC
584 }
585
586 /*
587 * Keep de-allocating extents until the remote-value region is gone.
588 */
589 lblkno = args->rmtblkno;
7bc0dc27 590 blkcnt = args->rmtblkcnt;
95920cd6
DC
591 done = 0;
592 while (!done) {
7bc0dc27
DC
593 int committed;
594
95920cd6
DC
595 xfs_bmap_init(args->flist, args->firstblock);
596 error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
597 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
598 1, args->firstblock, args->flist,
599 &done);
600 if (!error) {
601 error = xfs_bmap_finish(&args->trans, args->flist,
602 &committed);
603 }
604 if (error) {
605 ASSERT(committed);
606 args->trans = NULL;
607 xfs_bmap_cancel(args->flist);
d2e448d5 608 return error;
95920cd6
DC
609 }
610
611 /*
612 * bmap_finish() may have committed the last trans and started
613 * a new one. We need the inode to be in all transactions.
614 */
615 if (committed)
616 xfs_trans_ijoin(args->trans, args->dp, 0);
617
618 /*
619 * Close out trans and start the next one in the chain.
620 */
621 error = xfs_trans_roll(&args->trans, args->dp);
622 if (error)
623 return (error);
624 }
625 return(0);
626}