xfs_attr_remote.c 14.6 KB
Newer Older
1 2
/*
 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3
 * Copyright (c) 2013 Red Hat, Inc.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include "xfs.h"
#include "xfs_fs.h"
21
#include "xfs_shared.h"
22
#include "xfs_format.h"
23 24
#include "xfs_log_format.h"
#include "xfs_trans_resv.h"
25 26 27 28
#include "xfs_bit.h"
#include "xfs_sb.h"
#include "xfs_ag.h"
#include "xfs_mount.h"
29
#include "xfs_da_format.h"
30 31 32
#include "xfs_da_btree.h"
#include "xfs_inode.h"
#include "xfs_alloc.h"
33
#include "xfs_trans.h"
34 35
#include "xfs_inode_item.h"
#include "xfs_bmap.h"
D
Dave Chinner 已提交
36
#include "xfs_bmap_util.h"
37 38 39 40 41
#include "xfs_attr.h"
#include "xfs_attr_leaf.h"
#include "xfs_attr_remote.h"
#include "xfs_trans_space.h"
#include "xfs_trace.h"
42 43
#include "xfs_cksum.h"
#include "xfs_buf_item.h"
44
#include "xfs_error.h"
45 46 47

#define ATTR_RMTVALUE_MAPSIZE	1	/* # of map entries at once */

48 49 50 51
/*
 * Each contiguous block has a header, so it is not just a simple attribute
 * length to FSB conversion.
 */
D
Dave Chinner 已提交
52
int
53 54 55 56
xfs_attr3_rmt_blocks(
	struct xfs_mount *mp,
	int		attrlen)
{
57 58 59 60 61
	if (xfs_sb_version_hascrc(&mp->m_sb)) {
		int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
		return (attrlen + buflen - 1) / buflen;
	}
	return XFS_B_TO_FSB(mp, attrlen);
62 63
}

D
Dave Chinner 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
/*
 * Checking of the remote attribute header is split into two parts. The verifier
 * does CRC, location and bounds checking, the unpacking function checks the
 * attribute parameters and owner.
 */
static bool
xfs_attr3_rmt_hdr_ok(
	void			*ptr,
	xfs_ino_t		ino,
	uint32_t		offset,
	uint32_t		size,
	xfs_daddr_t		bno)
{
	struct xfs_attr3_rmt_hdr *rmt = ptr;

	if (bno != be64_to_cpu(rmt->rm_blkno))
		return false;
	if (offset != be32_to_cpu(rmt->rm_offset))
		return false;
	if (size != be32_to_cpu(rmt->rm_bytes))
		return false;
	if (ino != be64_to_cpu(rmt->rm_owner))
		return false;

	/* ok */
	return true;
}

92 93
static bool
xfs_attr3_rmt_verify(
D
Dave Chinner 已提交
94 95 96 97
	struct xfs_mount	*mp,
	void			*ptr,
	int			fsbsize,
	xfs_daddr_t		bno)
98
{
D
Dave Chinner 已提交
99
	struct xfs_attr3_rmt_hdr *rmt = ptr;
100 101 102 103 104 105 106

	if (!xfs_sb_version_hascrc(&mp->m_sb))
		return false;
	if (rmt->rm_magic != cpu_to_be32(XFS_ATTR3_RMT_MAGIC))
		return false;
	if (!uuid_equal(&rmt->rm_uuid, &mp->m_sb.sb_uuid))
		return false;
D
Dave Chinner 已提交
107 108 109
	if (be64_to_cpu(rmt->rm_blkno) != bno)
		return false;
	if (be32_to_cpu(rmt->rm_bytes) > fsbsize - sizeof(*rmt))
110 111
		return false;
	if (be32_to_cpu(rmt->rm_offset) +
112
				be32_to_cpu(rmt->rm_bytes) > XATTR_SIZE_MAX)
113 114 115 116 117 118 119 120 121 122 123 124
		return false;
	if (rmt->rm_owner == 0)
		return false;

	return true;
}

static void
xfs_attr3_rmt_read_verify(
	struct xfs_buf	*bp)
{
	struct xfs_mount *mp = bp->b_target->bt_mount;
D
Dave Chinner 已提交
125 126 127
	char		*ptr;
	int		len;
	xfs_daddr_t	bno;
128
	int		blksize = mp->m_attr_geo->blksize;
129 130 131 132 133

	/* no verification of non-crc buffers */
	if (!xfs_sb_version_hascrc(&mp->m_sb))
		return;

D
Dave Chinner 已提交
134 135 136
	ptr = bp->b_addr;
	bno = bp->b_bn;
	len = BBTOB(bp->b_length);
137
	ASSERT(len >= blksize);
D
Dave Chinner 已提交
138 139

	while (len > 0) {
140
		if (!xfs_verify_cksum(ptr, blksize, XFS_ATTR3_RMT_CRC_OFF)) {
141
			xfs_buf_ioerror(bp, EFSBADCRC);
D
Dave Chinner 已提交
142 143
			break;
		}
144
		if (!xfs_attr3_rmt_verify(mp, ptr, blksize, bno)) {
145
			xfs_buf_ioerror(bp, EFSCORRUPTED);
D
Dave Chinner 已提交
146 147
			break;
		}
148 149 150
		len -= blksize;
		ptr += blksize;
		bno += BTOBB(blksize);
D
Dave Chinner 已提交
151 152
	}

153 154 155
	if (bp->b_error)
		xfs_verifier_error(bp);
	else
D
Dave Chinner 已提交
156
		ASSERT(len == 0);
157 158 159 160 161 162 163 164
}

static void
xfs_attr3_rmt_write_verify(
	struct xfs_buf	*bp)
{
	struct xfs_mount *mp = bp->b_target->bt_mount;
	struct xfs_buf_log_item	*bip = bp->b_fspriv;
D
Dave Chinner 已提交
165 166 167
	char		*ptr;
	int		len;
	xfs_daddr_t	bno;
168
	int		blksize = mp->m_attr_geo->blksize;
169 170 171 172 173

	/* no verification of non-crc buffers */
	if (!xfs_sb_version_hascrc(&mp->m_sb))
		return;

D
Dave Chinner 已提交
174 175 176
	ptr = bp->b_addr;
	bno = bp->b_bn;
	len = BBTOB(bp->b_length);
177
	ASSERT(len >= blksize);
D
Dave Chinner 已提交
178 179

	while (len > 0) {
180
		if (!xfs_attr3_rmt_verify(mp, ptr, blksize, bno)) {
D
Dave Chinner 已提交
181
			xfs_buf_ioerror(bp, EFSCORRUPTED);
182
			xfs_verifier_error(bp);
D
Dave Chinner 已提交
183 184 185 186
			return;
		}
		if (bip) {
			struct xfs_attr3_rmt_hdr *rmt;
187

D
Dave Chinner 已提交
188 189 190
			rmt = (struct xfs_attr3_rmt_hdr *)ptr;
			rmt->rm_lsn = cpu_to_be64(bip->bli_item.li_lsn);
		}
191
		xfs_update_cksum(ptr, blksize, XFS_ATTR3_RMT_CRC_OFF);
D
Dave Chinner 已提交
192

193 194 195
		len -= blksize;
		ptr += blksize;
		bno += BTOBB(blksize);
196
	}
D
Dave Chinner 已提交
197
	ASSERT(len == 0);
198 199 200 201 202 203 204
}

const struct xfs_buf_ops xfs_attr3_rmt_buf_ops = {
	.verify_read = xfs_attr3_rmt_read_verify,
	.verify_write = xfs_attr3_rmt_write_verify,
};

D
Dave Chinner 已提交
205
STATIC int
206 207
xfs_attr3_rmt_hdr_set(
	struct xfs_mount	*mp,
D
Dave Chinner 已提交
208
	void			*ptr,
209 210 211
	xfs_ino_t		ino,
	uint32_t		offset,
	uint32_t		size,
D
Dave Chinner 已提交
212
	xfs_daddr_t		bno)
213
{
D
Dave Chinner 已提交
214
	struct xfs_attr3_rmt_hdr *rmt = ptr;
215 216 217 218 219 220 221 222 223

	if (!xfs_sb_version_hascrc(&mp->m_sb))
		return 0;

	rmt->rm_magic = cpu_to_be32(XFS_ATTR3_RMT_MAGIC);
	rmt->rm_offset = cpu_to_be32(offset);
	rmt->rm_bytes = cpu_to_be32(size);
	uuid_copy(&rmt->rm_uuid, &mp->m_sb.sb_uuid);
	rmt->rm_owner = cpu_to_be64(ino);
D
Dave Chinner 已提交
224
	rmt->rm_blkno = cpu_to_be64(bno);
225 226 227 228 229

	return sizeof(struct xfs_attr3_rmt_hdr);
}

/*
D
Dave Chinner 已提交
230
 * Helper functions to copy attribute data in and out of the one disk extents
231
 */
D
Dave Chinner 已提交
232 233 234 235 236 237 238
STATIC int
xfs_attr_rmtval_copyout(
	struct xfs_mount *mp,
	struct xfs_buf	*bp,
	xfs_ino_t	ino,
	int		*offset,
	int		*valuelen,
239
	__uint8_t	**dst)
240
{
D
Dave Chinner 已提交
241 242 243
	char		*src = bp->b_addr;
	xfs_daddr_t	bno = bp->b_bn;
	int		len = BBTOB(bp->b_length);
244
	int		blksize = mp->m_attr_geo->blksize;
245

246
	ASSERT(len >= blksize);
247

D
Dave Chinner 已提交
248 249
	while (len > 0 && *valuelen > 0) {
		int hdr_size = 0;
250
		int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
D
Dave Chinner 已提交
251

D
Dave Chinner 已提交
252
		byte_cnt = min(*valuelen, byte_cnt);
D
Dave Chinner 已提交
253 254

		if (xfs_sb_version_hascrc(&mp->m_sb)) {
255
			if (!xfs_attr3_rmt_hdr_ok(src, ino, *offset,
D
Dave Chinner 已提交
256 257 258 259 260 261 262 263 264 265 266 267
						  byte_cnt, bno)) {
				xfs_alert(mp,
"remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)",
					bno, *offset, byte_cnt, ino);
				return EFSCORRUPTED;
			}
			hdr_size = sizeof(struct xfs_attr3_rmt_hdr);
		}

		memcpy(*dst, src + hdr_size, byte_cnt);

		/* roll buffer forwards */
268 269 270
		len -= blksize;
		src += blksize;
		bno += BTOBB(blksize);
D
Dave Chinner 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286

		/* roll attribute data forwards */
		*valuelen -= byte_cnt;
		*dst += byte_cnt;
		*offset += byte_cnt;
	}
	return 0;
}

STATIC void
xfs_attr_rmtval_copyin(
	struct xfs_mount *mp,
	struct xfs_buf	*bp,
	xfs_ino_t	ino,
	int		*offset,
	int		*valuelen,
287
	__uint8_t	**src)
D
Dave Chinner 已提交
288 289 290 291
{
	char		*dst = bp->b_addr;
	xfs_daddr_t	bno = bp->b_bn;
	int		len = BBTOB(bp->b_length);
292
	int		blksize = mp->m_attr_geo->blksize;
D
Dave Chinner 已提交
293

294
	ASSERT(len >= blksize);
D
Dave Chinner 已提交
295 296 297

	while (len > 0 && *valuelen > 0) {
		int hdr_size;
298
		int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize);
D
Dave Chinner 已提交
299 300 301 302 303 304 305 306 307 308 309

		byte_cnt = min(*valuelen, byte_cnt);
		hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset,
						 byte_cnt, bno);

		memcpy(dst + hdr_size, *src, byte_cnt);

		/*
		 * If this is the last block, zero the remainder of it.
		 * Check that we are actually the last block, too.
		 */
310
		if (byte_cnt + hdr_size < blksize) {
D
Dave Chinner 已提交
311
			ASSERT(*valuelen - byte_cnt == 0);
312
			ASSERT(len == blksize);
D
Dave Chinner 已提交
313
			memset(dst + hdr_size + byte_cnt, 0,
314
					blksize - hdr_size - byte_cnt);
D
Dave Chinner 已提交
315 316 317
		}

		/* roll buffer forwards */
318 319 320
		len -= blksize;
		dst += blksize;
		bno += BTOBB(blksize);
D
Dave Chinner 已提交
321 322 323 324 325 326

		/* roll attribute data forwards */
		*valuelen -= byte_cnt;
		*src += byte_cnt;
		*offset += byte_cnt;
	}
327 328
}

329 330 331 332 333
/*
 * Read the value associated with an attribute from the out-of-line buffer
 * that we stored it in.
 */
int
334 335
xfs_attr_rmtval_get(
	struct xfs_da_args	*args)
336
{
337 338 339 340
	struct xfs_bmbt_irec	map[ATTR_RMTVALUE_MAPSIZE];
	struct xfs_mount	*mp = args->dp->i_mount;
	struct xfs_buf		*bp;
	xfs_dablk_t		lblkno = args->rmtblkno;
341
	__uint8_t		*dst = args->value;
342
	int			valuelen;
343 344
	int			nmap;
	int			error;
D
Dave Chinner 已提交
345
	int			blkcnt = args->rmtblkcnt;
346 347
	int			i;
	int			offset = 0;
348 349 350 351

	trace_xfs_attr_rmtval_get(args);

	ASSERT(!(args->flags & ATTR_KERNOVAL));
352
	ASSERT(args->rmtvaluelen == args->valuelen);
353

354
	valuelen = args->rmtvaluelen;
355 356 357
	while (valuelen > 0) {
		nmap = ATTR_RMTVALUE_MAPSIZE;
		error = xfs_bmapi_read(args->dp, (xfs_fileoff_t)lblkno,
358
				       blkcnt, map, &nmap,
359 360
				       XFS_BMAPI_ATTRFORK);
		if (error)
361
			return error;
362 363 364
		ASSERT(nmap >= 1);

		for (i = 0; (i < nmap) && (valuelen > 0); i++) {
D
Dave Chinner 已提交
365 366
			xfs_daddr_t	dblkno;
			int		dblkcnt;
367

368 369 370
			ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
			       (map[i].br_startblock != HOLESTARTBLOCK));
			dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
D
Dave Chinner 已提交
371
			dblkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
372
			error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp,
D
Dave Chinner 已提交
373
						   dblkno, dblkcnt, 0, &bp,
374
						   &xfs_attr3_rmt_buf_ops);
375
			if (error)
376 377
				return error;

D
Dave Chinner 已提交
378 379 380
			error = xfs_attr_rmtval_copyout(mp, bp, args->dp->i_ino,
							&offset, &valuelen,
							&dst);
381
			xfs_buf_relse(bp);
D
Dave Chinner 已提交
382 383
			if (error)
				return error;
384

D
Dave Chinner 已提交
385
			/* roll attribute extent map forwards */
386
			lblkno += map[i].br_blockcount;
D
Dave Chinner 已提交
387
			blkcnt -= map[i].br_blockcount;
388 389 390
		}
	}
	ASSERT(valuelen == 0);
391
	return 0;
392 393 394 395 396 397 398
}

/*
 * Write the value associated with an attribute into the out-of-line buffer
 * that we have defined for it.
 */
int
399 400
xfs_attr_rmtval_set(
	struct xfs_da_args	*args)
401
{
402 403 404 405 406
	struct xfs_inode	*dp = args->dp;
	struct xfs_mount	*mp = dp->i_mount;
	struct xfs_bmbt_irec	map;
	xfs_dablk_t		lblkno;
	xfs_fileoff_t		lfileoff = 0;
407
	__uint8_t		*src = args->value;
408 409 410 411 412
	int			blkcnt;
	int			valuelen;
	int			nmap;
	int			error;
	int			offset = 0;
413 414 415 416 417

	trace_xfs_attr_rmtval_set(args);

	/*
	 * Find a "hole" in the attribute address space large enough for
418 419
	 * us to drop the new attribute's value into. Because CRC enable
	 * attributes have headers, we can't just do a straight byte to FSB
D
Dave Chinner 已提交
420
	 * conversion and have to take the header space into account.
421
	 */
422
	blkcnt = xfs_attr3_rmt_blocks(mp, args->rmtvaluelen);
423 424
	error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
						   XFS_ATTR_FORK);
425 426 427
	if (error)
		return error;

428 429 430 431 432 433 434
	args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
	args->rmtblkcnt = blkcnt;

	/*
	 * Roll through the "value", allocating blocks on disk as required.
	 */
	while (blkcnt > 0) {
435 436
		int	committed;

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
		/*
		 * Allocate a single extent, up to the size of the value.
		 */
		xfs_bmap_init(args->flist, args->firstblock);
		nmap = 1;
		error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno,
				  blkcnt,
				  XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
				  args->firstblock, args->total, &map, &nmap,
				  args->flist);
		if (!error) {
			error = xfs_bmap_finish(&args->trans, args->flist,
						&committed);
		}
		if (error) {
			ASSERT(committed);
			args->trans = NULL;
			xfs_bmap_cancel(args->flist);
E
Eric Sandeen 已提交
455
			return error;
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
		}

		/*
		 * bmap_finish() may have committed the last trans and started
		 * a new one.  We need the inode to be in all transactions.
		 */
		if (committed)
			xfs_trans_ijoin(args->trans, dp, 0);

		ASSERT(nmap == 1);
		ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
		       (map.br_startblock != HOLESTARTBLOCK));
		lblkno += map.br_blockcount;
		blkcnt -= map.br_blockcount;

		/*
		 * Start the next trans in the chain.
		 */
		error = xfs_trans_roll(&args->trans, dp);
		if (error)
E
Eric Sandeen 已提交
476
			return error;
477 478 479 480 481 482 483 484 485
	}

	/*
	 * Roll through the "value", copying the attribute value to the
	 * already-allocated blocks.  Blocks are written synchronously
	 * so that we can know they are all on disk before we turn off
	 * the INCOMPLETE flag.
	 */
	lblkno = args->rmtblkno;
486
	blkcnt = args->rmtblkcnt;
487
	valuelen = args->rmtvaluelen;
488
	while (valuelen > 0) {
D
Dave Chinner 已提交
489 490 491 492 493
		struct xfs_buf	*bp;
		xfs_daddr_t	dblkno;
		int		dblkcnt;

		ASSERT(blkcnt > 0);
494 495 496 497

		xfs_bmap_init(args->flist, args->firstblock);
		nmap = 1;
		error = xfs_bmapi_read(dp, (xfs_fileoff_t)lblkno,
498
				       blkcnt, &map, &nmap,
499 500
				       XFS_BMAPI_ATTRFORK);
		if (error)
E
Eric Sandeen 已提交
501
			return error;
502 503 504 505 506
		ASSERT(nmap == 1);
		ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
		       (map.br_startblock != HOLESTARTBLOCK));

		dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
507
		dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
508

509
		bp = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, 0);
510 511
		if (!bp)
			return ENOMEM;
512
		bp->b_ops = &xfs_attr3_rmt_buf_ops;
513

D
Dave Chinner 已提交
514 515
		xfs_attr_rmtval_copyin(mp, bp, args->dp->i_ino, &offset,
				       &valuelen, &src);
516 517 518 519 520

		error = xfs_bwrite(bp);	/* GROT: NOTE: synchronous write */
		xfs_buf_relse(bp);
		if (error)
			return error;
521

522

D
Dave Chinner 已提交
523
		/* roll attribute extent map forwards */
524
		lblkno += map.br_blockcount;
525
		blkcnt -= map.br_blockcount;
526 527
	}
	ASSERT(valuelen == 0);
528
	return 0;
529 530 531 532 533 534 535
}

/*
 * Remove the value associated with an attribute by deleting the
 * out-of-line buffer that it is stored on.
 */
int
D
Dave Chinner 已提交
536 537
xfs_attr_rmtval_remove(
	struct xfs_da_args	*args)
538
{
D
Dave Chinner 已提交
539 540 541 542 543
	struct xfs_mount	*mp = args->dp->i_mount;
	xfs_dablk_t		lblkno;
	int			blkcnt;
	int			error;
	int			done;
544 545 546 547

	trace_xfs_attr_rmtval_remove(args);

	/*
548
	 * Roll through the "value", invalidating the attribute value's blocks.
549 550
	 */
	lblkno = args->rmtblkno;
D
Dave Chinner 已提交
551 552 553 554 555 556 557
	blkcnt = args->rmtblkcnt;
	while (blkcnt > 0) {
		struct xfs_bmbt_irec	map;
		struct xfs_buf		*bp;
		xfs_daddr_t		dblkno;
		int			dblkcnt;
		int			nmap;
558

559 560 561 562 563
		/*
		 * Try to remember where we decided to put the value.
		 */
		nmap = 1;
		error = xfs_bmapi_read(args->dp, (xfs_fileoff_t)lblkno,
564
				       blkcnt, &map, &nmap, XFS_BMAPI_ATTRFORK);
565
		if (error)
E
Eric Sandeen 已提交
566
			return error;
567 568 569 570 571
		ASSERT(nmap == 1);
		ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
		       (map.br_startblock != HOLESTARTBLOCK));

		dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
572
		dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
573 574 575 576

		/*
		 * If the "remote" value is in the cache, remove it.
		 */
577
		bp = xfs_incore(mp->m_ddev_targp, dblkno, dblkcnt, XBF_TRYLOCK);
578 579 580 581 582 583 584
		if (bp) {
			xfs_buf_stale(bp);
			xfs_buf_relse(bp);
			bp = NULL;
		}

		lblkno += map.br_blockcount;
585
		blkcnt -= map.br_blockcount;
586 587 588 589 590 591
	}

	/*
	 * Keep de-allocating extents until the remote-value region is gone.
	 */
	lblkno = args->rmtblkno;
D
Dave Chinner 已提交
592
	blkcnt = args->rmtblkcnt;
593 594
	done = 0;
	while (!done) {
D
Dave Chinner 已提交
595 596
		int committed;

597 598 599 600 601 602 603 604 605 606 607 608 609
		xfs_bmap_init(args->flist, args->firstblock);
		error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
				    XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
				    1, args->firstblock, args->flist,
				    &done);
		if (!error) {
			error = xfs_bmap_finish(&args->trans, args->flist,
						&committed);
		}
		if (error) {
			ASSERT(committed);
			args->trans = NULL;
			xfs_bmap_cancel(args->flist);
610
			return error;
611 612 613 614 615 616 617 618 619 620 621 622 623 624
		}

		/*
		 * bmap_finish() may have committed the last trans and started
		 * a new one.  We need the inode to be in all transactions.
		 */
		if (committed)
			xfs_trans_ijoin(args->trans, args->dp, 0);

		/*
		 * Close out trans and start the next one in the chain.
		 */
		error = xfs_trans_roll(&args->trans, args->dp);
		if (error)
E
Eric Sandeen 已提交
625
			return error;
626
	}
E
Eric Sandeen 已提交
627
	return 0;
628
}