aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_iomap.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_iomap.c')
-rw-r--r--fs/xfs/xfs_iomap.c425
1 files changed, 234 insertions, 191 deletions
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index ca7afc83a893..788917f355c4 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -262,7 +262,7 @@ phase2:
262 case BMAPI_WRITE: 262 case BMAPI_WRITE:
263 /* If we found an extent, return it */ 263 /* If we found an extent, return it */
264 if (nimaps && 264 if (nimaps &&
265 (imap.br_startblock != HOLESTARTBLOCK) && 265 (imap.br_startblock != HOLESTARTBLOCK) &&
266 (imap.br_startblock != DELAYSTARTBLOCK)) { 266 (imap.br_startblock != DELAYSTARTBLOCK)) {
267 xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, io, 267 xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, io,
268 offset, count, iomapp, &imap, flags); 268 offset, count, iomapp, &imap, flags);
@@ -317,6 +317,58 @@ out:
317} 317}
318 318
319STATIC int 319STATIC int
320xfs_iomap_eof_align_last_fsb(
321 xfs_mount_t *mp,
322 xfs_iocore_t *io,
323 xfs_fsize_t isize,
324 xfs_extlen_t extsize,
325 xfs_fileoff_t *last_fsb)
326{
327 xfs_fileoff_t new_last_fsb = 0;
328 xfs_extlen_t align;
329 int eof, error;
330
331 if (io->io_flags & XFS_IOCORE_RT)
332 ;
333 /*
334 * If mounted with the "-o swalloc" option, roundup the allocation
335 * request to a stripe width boundary if the file size is >=
336 * stripe width and we are allocating past the allocation eof.
337 */
338 else if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC) &&
339 (isize >= XFS_FSB_TO_B(mp, mp->m_swidth)))
340 new_last_fsb = roundup_64(*last_fsb, mp->m_swidth);
341 /*
342 * Roundup the allocation request to a stripe unit (m_dalign) boundary
343 * if the file size is >= stripe unit size, and we are allocating past
344 * the allocation eof.
345 */
346 else if (mp->m_dalign && (isize >= XFS_FSB_TO_B(mp, mp->m_dalign)))
347 new_last_fsb = roundup_64(*last_fsb, mp->m_dalign);
348
349 /*
350 * Always round up the allocation request to an extent boundary
351 * (when file on a real-time subvolume or has di_extsize hint).
352 */
353 if (extsize) {
354 if (new_last_fsb)
355 align = roundup_64(new_last_fsb, extsize);
356 else
357 align = extsize;
358 new_last_fsb = roundup_64(*last_fsb, align);
359 }
360
361 if (new_last_fsb) {
362 error = XFS_BMAP_EOF(mp, io, new_last_fsb, XFS_DATA_FORK, &eof);
363 if (error)
364 return error;
365 if (eof)
366 *last_fsb = new_last_fsb;
367 }
368 return 0;
369}
370
371STATIC int
320xfs_flush_space( 372xfs_flush_space(
321 xfs_inode_t *ip, 373 xfs_inode_t *ip,
322 int *fsynced, 374 int *fsynced,
@@ -362,19 +414,20 @@ xfs_iomap_write_direct(
362 xfs_iocore_t *io = &ip->i_iocore; 414 xfs_iocore_t *io = &ip->i_iocore;
363 xfs_fileoff_t offset_fsb; 415 xfs_fileoff_t offset_fsb;
364 xfs_fileoff_t last_fsb; 416 xfs_fileoff_t last_fsb;
365 xfs_filblks_t count_fsb; 417 xfs_filblks_t count_fsb, resaligned;
366 xfs_fsblock_t firstfsb; 418 xfs_fsblock_t firstfsb;
419 xfs_extlen_t extsz, temp;
420 xfs_fsize_t isize;
367 int nimaps; 421 int nimaps;
368 int error;
369 int bmapi_flag; 422 int bmapi_flag;
370 int quota_flag; 423 int quota_flag;
371 int rt; 424 int rt;
372 xfs_trans_t *tp; 425 xfs_trans_t *tp;
373 xfs_bmbt_irec_t imap; 426 xfs_bmbt_irec_t imap;
374 xfs_bmap_free_t free_list; 427 xfs_bmap_free_t free_list;
375 xfs_filblks_t qblocks, resblks; 428 uint qblocks, resblks, resrtextents;
376 int committed; 429 int committed;
377 int resrtextents; 430 int error;
378 431
379 /* 432 /*
380 * Make sure that the dquots are there. This doesn't hold 433 * Make sure that the dquots are there. This doesn't hold
@@ -384,37 +437,52 @@ xfs_iomap_write_direct(
384 if (error) 437 if (error)
385 return XFS_ERROR(error); 438 return XFS_ERROR(error);
386 439
387 offset_fsb = XFS_B_TO_FSBT(mp, offset); 440 rt = XFS_IS_REALTIME_INODE(ip);
388 last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count))); 441 if (unlikely(rt)) {
389 count_fsb = last_fsb - offset_fsb; 442 if (!(extsz = ip->i_d.di_extsize))
390 if (found && (ret_imap->br_startblock == HOLESTARTBLOCK)) { 443 extsz = mp->m_sb.sb_rextsize;
391 xfs_fileoff_t map_last_fsb; 444 } else {
392 445 extsz = ip->i_d.di_extsize;
393 map_last_fsb = ret_imap->br_blockcount + ret_imap->br_startoff;
394 if (map_last_fsb < last_fsb) {
395 last_fsb = map_last_fsb;
396 count_fsb = last_fsb - offset_fsb;
397 }
398 ASSERT(count_fsb > 0);
399 } 446 }
400 447
401 /* 448 isize = ip->i_d.di_size;
402 * Determine if reserving space on the data or realtime partition. 449 if (io->io_new_size > isize)
403 */ 450 isize = io->io_new_size;
404 if ((rt = XFS_IS_REALTIME_INODE(ip))) {
405 xfs_extlen_t extsz;
406 451
407 if (!(extsz = ip->i_d.di_extsize)) 452 offset_fsb = XFS_B_TO_FSBT(mp, offset);
408 extsz = mp->m_sb.sb_rextsize; 453 last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
409 resrtextents = qblocks = (count_fsb + extsz - 1); 454 if ((offset + count) > isize) {
410 do_div(resrtextents, mp->m_sb.sb_rextsize); 455 error = xfs_iomap_eof_align_last_fsb(mp, io, isize, extsz,
411 resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0); 456 &last_fsb);
412 quota_flag = XFS_QMOPT_RES_RTBLKS; 457 if (error)
458 goto error_out;
413 } else { 459 } else {
414 resrtextents = 0; 460 if (found && (ret_imap->br_startblock == HOLESTARTBLOCK))
415 resblks = qblocks = XFS_DIOSTRAT_SPACE_RES(mp, count_fsb); 461 last_fsb = MIN(last_fsb, (xfs_fileoff_t)
416 quota_flag = XFS_QMOPT_RES_REGBLKS; 462 ret_imap->br_blockcount +
463 ret_imap->br_startoff);
417 } 464 }
465 count_fsb = last_fsb - offset_fsb;
466 ASSERT(count_fsb > 0);
467
468 resaligned = count_fsb;
469 if (unlikely(extsz)) {
470 if ((temp = do_mod(offset_fsb, extsz)))
471 resaligned += temp;
472 if ((temp = do_mod(resaligned, extsz)))
473 resaligned += extsz - temp;
474 }
475
476 if (unlikely(rt)) {
477 resrtextents = qblocks = resaligned;
478 resrtextents /= mp->m_sb.sb_rextsize;
479 resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
480 quota_flag = XFS_QMOPT_RES_RTBLKS;
481 } else {
482 resrtextents = 0;
483 resblks = qblocks = XFS_DIOSTRAT_SPACE_RES(mp, resaligned);
484 quota_flag = XFS_QMOPT_RES_REGBLKS;
485 }
418 486
419 /* 487 /*
420 * Allocate and setup the transaction 488 * Allocate and setup the transaction
@@ -425,7 +493,6 @@ xfs_iomap_write_direct(
425 XFS_WRITE_LOG_RES(mp), resrtextents, 493 XFS_WRITE_LOG_RES(mp), resrtextents,
426 XFS_TRANS_PERM_LOG_RES, 494 XFS_TRANS_PERM_LOG_RES,
427 XFS_WRITE_LOG_COUNT); 495 XFS_WRITE_LOG_COUNT);
428
429 /* 496 /*
430 * Check for running out of space, note: need lock to return 497 * Check for running out of space, note: need lock to return
431 */ 498 */
@@ -435,20 +502,20 @@ xfs_iomap_write_direct(
435 if (error) 502 if (error)
436 goto error_out; 503 goto error_out;
437 504
438 if (XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, tp, ip, qblocks, 0, quota_flag)) { 505 error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, tp, ip,
439 error = (EDQUOT); 506 qblocks, 0, quota_flag);
507 if (error)
440 goto error1; 508 goto error1;
441 }
442 509
443 bmapi_flag = XFS_BMAPI_WRITE;
444 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); 510 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
445 xfs_trans_ihold(tp, ip); 511 xfs_trans_ihold(tp, ip);
446 512
447 if (!(flags & BMAPI_MMAP) && (offset < ip->i_d.di_size || rt)) 513 bmapi_flag = XFS_BMAPI_WRITE;
514 if ((flags & BMAPI_DIRECT) && (offset < ip->i_d.di_size || extsz))
448 bmapi_flag |= XFS_BMAPI_PREALLOC; 515 bmapi_flag |= XFS_BMAPI_PREALLOC;
449 516
450 /* 517 /*
451 * Issue the bmapi() call to allocate the blocks 518 * Issue the xfs_bmapi() call to allocate the blocks
452 */ 519 */
453 XFS_BMAP_INIT(&free_list, &firstfsb); 520 XFS_BMAP_INIT(&free_list, &firstfsb);
454 nimaps = 1; 521 nimaps = 1;
@@ -483,8 +550,10 @@ xfs_iomap_write_direct(
483 "extent-state : %x \n", 550 "extent-state : %x \n",
484 (ip->i_mount)->m_fsname, 551 (ip->i_mount)->m_fsname,
485 (long long)ip->i_ino, 552 (long long)ip->i_ino,
486 ret_imap->br_startblock, ret_imap->br_startoff, 553 (unsigned long long)ret_imap->br_startblock,
487 ret_imap->br_blockcount,ret_imap->br_state); 554 (unsigned long long)ret_imap->br_startoff,
555 (unsigned long long)ret_imap->br_blockcount,
556 ret_imap->br_state);
488 } 557 }
489 return 0; 558 return 0;
490 559
@@ -500,6 +569,63 @@ error_out:
500 return XFS_ERROR(error); 569 return XFS_ERROR(error);
501} 570}
502 571
572/*
573 * If the caller is doing a write at the end of the file,
574 * then extend the allocation out to the file system's write
575 * iosize. We clean up any extra space left over when the
576 * file is closed in xfs_inactive().
577 *
578 * For sync writes, we are flushing delayed allocate space to
579 * try to make additional space available for allocation near
580 * the filesystem full boundary - preallocation hurts in that
581 * situation, of course.
582 */
583STATIC int
584xfs_iomap_eof_want_preallocate(
585 xfs_mount_t *mp,
586 xfs_iocore_t *io,
587 xfs_fsize_t isize,
588 xfs_off_t offset,
589 size_t count,
590 int ioflag,
591 xfs_bmbt_irec_t *imap,
592 int nimaps,
593 int *prealloc)
594{
595 xfs_fileoff_t start_fsb;
596 xfs_filblks_t count_fsb;
597 xfs_fsblock_t firstblock;
598 int n, error, imaps;
599
600 *prealloc = 0;
601 if ((ioflag & BMAPI_SYNC) || (offset + count) <= isize)
602 return 0;
603
604 /*
605 * If there are any real blocks past eof, then don't
606 * do any speculative allocation.
607 */
608 start_fsb = XFS_B_TO_FSBT(mp, ((xfs_ufsize_t)(offset + count - 1)));
609 count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp));
610 while (count_fsb > 0) {
611 imaps = nimaps;
612 firstblock = NULLFSBLOCK;
613 error = XFS_BMAPI(mp, NULL, io, start_fsb, count_fsb,
614 0, &firstblock, 0, imap, &imaps, NULL);
615 if (error)
616 return error;
617 for (n = 0; n < imaps; n++) {
618 if ((imap[n].br_startblock != HOLESTARTBLOCK) &&
619 (imap[n].br_startblock != DELAYSTARTBLOCK))
620 return 0;
621 start_fsb += imap[n].br_blockcount;
622 count_fsb -= imap[n].br_blockcount;
623 }
624 }
625 *prealloc = 1;
626 return 0;
627}
628
503int 629int
504xfs_iomap_write_delay( 630xfs_iomap_write_delay(
505 xfs_inode_t *ip, 631 xfs_inode_t *ip,
@@ -513,13 +639,15 @@ xfs_iomap_write_delay(
513 xfs_iocore_t *io = &ip->i_iocore; 639 xfs_iocore_t *io = &ip->i_iocore;
514 xfs_fileoff_t offset_fsb; 640 xfs_fileoff_t offset_fsb;
515 xfs_fileoff_t last_fsb; 641 xfs_fileoff_t last_fsb;
516 xfs_fsize_t isize; 642 xfs_off_t aligned_offset;
643 xfs_fileoff_t ioalign;
517 xfs_fsblock_t firstblock; 644 xfs_fsblock_t firstblock;
645 xfs_extlen_t extsz;
646 xfs_fsize_t isize;
518 int nimaps; 647 int nimaps;
519 int error;
520 xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS]; 648 xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS];
521 int aeof; 649 int prealloc, fsynced = 0;
522 int fsynced = 0; 650 int error;
523 651
524 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0); 652 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0);
525 653
@@ -527,152 +655,57 @@ xfs_iomap_write_delay(
527 * Make sure that the dquots are there. This doesn't hold 655 * Make sure that the dquots are there. This doesn't hold
528 * the ilock across a disk read. 656 * the ilock across a disk read.
529 */ 657 */
530
531 error = XFS_QM_DQATTACH(mp, ip, XFS_QMOPT_ILOCKED); 658 error = XFS_QM_DQATTACH(mp, ip, XFS_QMOPT_ILOCKED);
532 if (error) 659 if (error)
533 return XFS_ERROR(error); 660 return XFS_ERROR(error);
534 661
662 if (XFS_IS_REALTIME_INODE(ip)) {
663 if (!(extsz = ip->i_d.di_extsize))
664 extsz = mp->m_sb.sb_rextsize;
665 } else {
666 extsz = ip->i_d.di_extsize;
667 }
668
669 offset_fsb = XFS_B_TO_FSBT(mp, offset);
670
535retry: 671retry:
536 isize = ip->i_d.di_size; 672 isize = ip->i_d.di_size;
537 if (io->io_new_size > isize) { 673 if (io->io_new_size > isize)
538 isize = io->io_new_size; 674 isize = io->io_new_size;
539 }
540 675
541 aeof = 0; 676 error = xfs_iomap_eof_want_preallocate(mp, io, isize, offset, count,
542 offset_fsb = XFS_B_TO_FSBT(mp, offset); 677 ioflag, imap, XFS_WRITE_IMAPS, &prealloc);
543 last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count))); 678 if (error)
544 /* 679 return error;
545 * If the caller is doing a write at the end of the file,
546 * then extend the allocation (and the buffer used for the write)
547 * out to the file system's write iosize. We clean up any extra
548 * space left over when the file is closed in xfs_inactive().
549 *
550 * For sync writes, we are flushing delayed allocate space to
551 * try to make additional space available for allocation near
552 * the filesystem full boundary - preallocation hurts in that
553 * situation, of course.
554 */
555 if (!(ioflag & BMAPI_SYNC) && ((offset + count) > ip->i_d.di_size)) {
556 xfs_off_t aligned_offset;
557 xfs_filblks_t count_fsb;
558 unsigned int iosize;
559 xfs_fileoff_t ioalign;
560 int n;
561 xfs_fileoff_t start_fsb;
562 680
563 /* 681 if (prealloc) {
564 * If there are any real blocks past eof, then don't
565 * do any speculative allocation.
566 */
567 start_fsb = XFS_B_TO_FSBT(mp,
568 ((xfs_ufsize_t)(offset + count - 1)));
569 count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp));
570 while (count_fsb > 0) {
571 nimaps = XFS_WRITE_IMAPS;
572 error = XFS_BMAPI(mp, NULL, io, start_fsb, count_fsb,
573 0, &firstblock, 0, imap, &nimaps, NULL);
574 if (error) {
575 return error;
576 }
577 for (n = 0; n < nimaps; n++) {
578 if ( !(io->io_flags & XFS_IOCORE_RT) &&
579 !imap[n].br_startblock) {
580 cmn_err(CE_PANIC,"Access to block "
581 "zero: fs <%s> inode: %lld "
582 "start_block : %llx start_off "
583 ": %llx blkcnt : %llx "
584 "extent-state : %x \n",
585 (ip->i_mount)->m_fsname,
586 (long long)ip->i_ino,
587 imap[n].br_startblock,
588 imap[n].br_startoff,
589 imap[n].br_blockcount,
590 imap[n].br_state);
591 }
592 if ((imap[n].br_startblock != HOLESTARTBLOCK) &&
593 (imap[n].br_startblock != DELAYSTARTBLOCK)) {
594 goto write_map;
595 }
596 start_fsb += imap[n].br_blockcount;
597 count_fsb -= imap[n].br_blockcount;
598 }
599 }
600 iosize = mp->m_writeio_blocks;
601 aligned_offset = XFS_WRITEIO_ALIGN(mp, (offset + count - 1)); 682 aligned_offset = XFS_WRITEIO_ALIGN(mp, (offset + count - 1));
602 ioalign = XFS_B_TO_FSBT(mp, aligned_offset); 683 ioalign = XFS_B_TO_FSBT(mp, aligned_offset);
603 last_fsb = ioalign + iosize; 684 last_fsb = ioalign + mp->m_writeio_blocks;
604 aeof = 1; 685 } else {
686 last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
605 } 687 }
606write_map:
607 nimaps = XFS_WRITE_IMAPS;
608 firstblock = NULLFSBLOCK;
609 688
610 /* 689 if (prealloc || extsz) {
611 * If mounted with the "-o swalloc" option, roundup the allocation 690 error = xfs_iomap_eof_align_last_fsb(mp, io, isize, extsz,
612 * request to a stripe width boundary if the file size is >= 691 &last_fsb);
613 * stripe width and we are allocating past the allocation eof. 692 if (error)
614 */
615 if (!(io->io_flags & XFS_IOCORE_RT) && mp->m_swidth
616 && (mp->m_flags & XFS_MOUNT_SWALLOC)
617 && (isize >= XFS_FSB_TO_B(mp, mp->m_swidth)) && aeof) {
618 int eof;
619 xfs_fileoff_t new_last_fsb;
620
621 new_last_fsb = roundup_64(last_fsb, mp->m_swidth);
622 error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof);
623 if (error) {
624 return error;
625 }
626 if (eof) {
627 last_fsb = new_last_fsb;
628 }
629 /*
630 * Roundup the allocation request to a stripe unit (m_dalign) boundary
631 * if the file size is >= stripe unit size, and we are allocating past
632 * the allocation eof.
633 */
634 } else if (!(io->io_flags & XFS_IOCORE_RT) && mp->m_dalign &&
635 (isize >= XFS_FSB_TO_B(mp, mp->m_dalign)) && aeof) {
636 int eof;
637 xfs_fileoff_t new_last_fsb;
638 new_last_fsb = roundup_64(last_fsb, mp->m_dalign);
639 error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof);
640 if (error) {
641 return error;
642 }
643 if (eof) {
644 last_fsb = new_last_fsb;
645 }
646 /*
647 * Round up the allocation request to a real-time extent boundary
648 * if the file is on the real-time subvolume.
649 */
650 } else if (io->io_flags & XFS_IOCORE_RT && aeof) {
651 int eof;
652 xfs_fileoff_t new_last_fsb;
653
654 new_last_fsb = roundup_64(last_fsb, mp->m_sb.sb_rextsize);
655 error = XFS_BMAP_EOF(mp, io, new_last_fsb, XFS_DATA_FORK, &eof);
656 if (error) {
657 return error; 693 return error;
658 }
659 if (eof)
660 last_fsb = new_last_fsb;
661 } 694 }
695
696 nimaps = XFS_WRITE_IMAPS;
697 firstblock = NULLFSBLOCK;
662 error = xfs_bmapi(NULL, ip, offset_fsb, 698 error = xfs_bmapi(NULL, ip, offset_fsb,
663 (xfs_filblks_t)(last_fsb - offset_fsb), 699 (xfs_filblks_t)(last_fsb - offset_fsb),
664 XFS_BMAPI_DELAY | XFS_BMAPI_WRITE | 700 XFS_BMAPI_DELAY | XFS_BMAPI_WRITE |
665 XFS_BMAPI_ENTIRE, &firstblock, 1, imap, 701 XFS_BMAPI_ENTIRE, &firstblock, 1, imap,
666 &nimaps, NULL); 702 &nimaps, NULL);
667 /* 703 if (error && (error != ENOSPC))
668 * This can be EDQUOT, if nimaps == 0
669 */
670 if (error && (error != ENOSPC)) {
671 return XFS_ERROR(error); 704 return XFS_ERROR(error);
672 } 705
673 /* 706 /*
674 * If bmapi returned us nothing, and if we didn't get back EDQUOT, 707 * If bmapi returned us nothing, and if we didn't get back EDQUOT,
675 * then we must have run out of space. 708 * then we must have run out of space - flush delalloc, and retry..
676 */ 709 */
677 if (nimaps == 0) { 710 if (nimaps == 0) {
678 xfs_iomap_enter_trace(XFS_IOMAP_WRITE_NOSPACE, 711 xfs_iomap_enter_trace(XFS_IOMAP_WRITE_NOSPACE,
@@ -684,17 +717,21 @@ write_map:
684 goto retry; 717 goto retry;
685 } 718 }
686 719
687 *ret_imap = imap[0]; 720 if (!(io->io_flags & XFS_IOCORE_RT) && !ret_imap->br_startblock) {
688 *nmaps = 1;
689 if ( !(io->io_flags & XFS_IOCORE_RT) && !ret_imap->br_startblock) {
690 cmn_err(CE_PANIC,"Access to block zero: fs <%s> inode: %lld " 721 cmn_err(CE_PANIC,"Access to block zero: fs <%s> inode: %lld "
691 "start_block : %llx start_off : %llx blkcnt : %llx " 722 "start_block : %llx start_off : %llx blkcnt : %llx "
692 "extent-state : %x \n", 723 "extent-state : %x \n",
693 (ip->i_mount)->m_fsname, 724 (ip->i_mount)->m_fsname,
694 (long long)ip->i_ino, 725 (long long)ip->i_ino,
695 ret_imap->br_startblock, ret_imap->br_startoff, 726 (unsigned long long)ret_imap->br_startblock,
696 ret_imap->br_blockcount,ret_imap->br_state); 727 (unsigned long long)ret_imap->br_startoff,
728 (unsigned long long)ret_imap->br_blockcount,
729 ret_imap->br_state);
697 } 730 }
731
732 *ret_imap = imap[0];
733 *nmaps = 1;
734
698 return 0; 735 return 0;
699} 736}
700 737
@@ -820,17 +857,21 @@ xfs_iomap_write_allocate(
820 */ 857 */
821 858
822 for (i = 0; i < nimaps; i++) { 859 for (i = 0; i < nimaps; i++) {
823 if ( !(io->io_flags & XFS_IOCORE_RT) && 860 if (!(io->io_flags & XFS_IOCORE_RT) &&
824 !imap[i].br_startblock) { 861 !imap[i].br_startblock) {
825 cmn_err(CE_PANIC,"Access to block zero: " 862 cmn_err(CE_PANIC,"Access to block zero: "
826 "fs <%s> inode: %lld " 863 "fs <%s> inode: %lld "
827 "start_block : %llx start_off : %llx " 864 "start_block : %llx start_off : %llx "
828 "blkcnt : %llx extent-state : %x \n", 865 "blkcnt : %llx extent-state : %x \n",
829 (ip->i_mount)->m_fsname, 866 (ip->i_mount)->m_fsname,
830 (long long)ip->i_ino, 867 (long long)ip->i_ino,
831 imap[i].br_startblock, 868 (unsigned long long)
832 imap[i].br_startoff, 869 imap[i].br_startblock,
833 imap[i].br_blockcount,imap[i].br_state); 870 (unsigned long long)
871 imap[i].br_startoff,
872 (unsigned long long)
873 imap[i].br_blockcount,
874 imap[i].br_state);
834 } 875 }
835 if ((offset_fsb >= imap[i].br_startoff) && 876 if ((offset_fsb >= imap[i].br_startoff) &&
836 (offset_fsb < (imap[i].br_startoff + 877 (offset_fsb < (imap[i].br_startoff +
@@ -867,17 +908,17 @@ xfs_iomap_write_unwritten(
867{ 908{
868 xfs_mount_t *mp = ip->i_mount; 909 xfs_mount_t *mp = ip->i_mount;
869 xfs_iocore_t *io = &ip->i_iocore; 910 xfs_iocore_t *io = &ip->i_iocore;
870 xfs_trans_t *tp;
871 xfs_fileoff_t offset_fsb; 911 xfs_fileoff_t offset_fsb;
872 xfs_filblks_t count_fsb; 912 xfs_filblks_t count_fsb;
873 xfs_filblks_t numblks_fsb; 913 xfs_filblks_t numblks_fsb;
874 xfs_bmbt_irec_t imap; 914 xfs_fsblock_t firstfsb;
915 int nimaps;
916 xfs_trans_t *tp;
917 xfs_bmbt_irec_t imap;
918 xfs_bmap_free_t free_list;
919 uint resblks;
875 int committed; 920 int committed;
876 int error; 921 int error;
877 int nres;
878 int nimaps;
879 xfs_fsblock_t firstfsb;
880 xfs_bmap_free_t free_list;
881 922
882 xfs_iomap_enter_trace(XFS_IOMAP_UNWRITTEN, 923 xfs_iomap_enter_trace(XFS_IOMAP_UNWRITTEN,
883 &ip->i_iocore, offset, count); 924 &ip->i_iocore, offset, count);
@@ -886,9 +927,9 @@ xfs_iomap_write_unwritten(
886 count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count); 927 count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
887 count_fsb = (xfs_filblks_t)(count_fsb - offset_fsb); 928 count_fsb = (xfs_filblks_t)(count_fsb - offset_fsb);
888 929
889 do { 930 resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
890 nres = XFS_DIOSTRAT_SPACE_RES(mp, 0);
891 931
932 do {
892 /* 933 /*
893 * set up a transaction to convert the range of extents 934 * set up a transaction to convert the range of extents
894 * from unwritten to real. Do allocations in a loop until 935 * from unwritten to real. Do allocations in a loop until
@@ -896,7 +937,7 @@ xfs_iomap_write_unwritten(
896 */ 937 */
897 938
898 tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE); 939 tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE);
899 error = xfs_trans_reserve(tp, nres, 940 error = xfs_trans_reserve(tp, resblks,
900 XFS_WRITE_LOG_RES(mp), 0, 941 XFS_WRITE_LOG_RES(mp), 0,
901 XFS_TRANS_PERM_LOG_RES, 942 XFS_TRANS_PERM_LOG_RES,
902 XFS_WRITE_LOG_COUNT); 943 XFS_WRITE_LOG_COUNT);
@@ -915,7 +956,7 @@ xfs_iomap_write_unwritten(
915 XFS_BMAP_INIT(&free_list, &firstfsb); 956 XFS_BMAP_INIT(&free_list, &firstfsb);
916 nimaps = 1; 957 nimaps = 1;
917 error = xfs_bmapi(tp, ip, offset_fsb, count_fsb, 958 error = xfs_bmapi(tp, ip, offset_fsb, count_fsb,
918 XFS_BMAPI_WRITE, &firstfsb, 959 XFS_BMAPI_WRITE|XFS_BMAPI_CONVERT, &firstfsb,
919 1, &imap, &nimaps, &free_list); 960 1, &imap, &nimaps, &free_list);
920 if (error) 961 if (error)
921 goto error_on_bmapi_transaction; 962 goto error_on_bmapi_transaction;
@@ -929,15 +970,17 @@ xfs_iomap_write_unwritten(
929 xfs_iunlock(ip, XFS_ILOCK_EXCL); 970 xfs_iunlock(ip, XFS_ILOCK_EXCL);
930 if (error) 971 if (error)
931 goto error0; 972 goto error0;
932 973
933 if ( !(io->io_flags & XFS_IOCORE_RT) && !imap.br_startblock) { 974 if ( !(io->io_flags & XFS_IOCORE_RT) && !imap.br_startblock) {
934 cmn_err(CE_PANIC,"Access to block zero: fs <%s> " 975 cmn_err(CE_PANIC,"Access to block zero: fs <%s> "
935 "inode: %lld start_block : %llx start_off : " 976 "inode: %lld start_block : %llx start_off : "
936 "%llx blkcnt : %llx extent-state : %x \n", 977 "%llx blkcnt : %llx extent-state : %x \n",
937 (ip->i_mount)->m_fsname, 978 (ip->i_mount)->m_fsname,
938 (long long)ip->i_ino, 979 (long long)ip->i_ino,
939 imap.br_startblock,imap.br_startoff, 980 (unsigned long long)imap.br_startblock,
940 imap.br_blockcount,imap.br_state); 981 (unsigned long long)imap.br_startoff,
982 (unsigned long long)imap.br_blockcount,
983 imap.br_state);
941 } 984 }
942 985
943 if ((numblks_fsb = imap.br_blockcount) == 0) { 986 if ((numblks_fsb = imap.br_blockcount) == 0) {