diff options
author | Christoph Hellwig <hch@infradead.org> | 2010-12-10 10:03:57 -0500 |
---|---|---|
committer | Alex Elder <aelder@sgi.com> | 2010-12-16 17:06:11 -0500 |
commit | 9f9baab38dacd11fe6095a1e59f3783a305f7020 (patch) | |
tree | ea906a3a4be52648b94c8902bd35322421305b30 /fs/xfs | |
parent | ecff71e677c6d469f525dcf31ada709d5858307c (diff) |
xfs: clean up xfs_alloc_ag_vextent_exact
Use a goto label to consolidate all block not found cases, and add a
tracepoint for them. Also clean up a few whitespace issues.
Based on an earlier patch from Dave Chinner.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r-- | fs/xfs/linux-2.6/xfs_trace.h | 1 | ||||
-rw-r--r-- | fs/xfs/xfs_alloc.c | 58 |
2 files changed, 33 insertions, 26 deletions
diff --git a/fs/xfs/linux-2.6/xfs_trace.h b/fs/xfs/linux-2.6/xfs_trace.h index f56431c916a0..83e8760159ef 100644 --- a/fs/xfs/linux-2.6/xfs_trace.h +++ b/fs/xfs/linux-2.6/xfs_trace.h | |||
@@ -1422,6 +1422,7 @@ DEFINE_EVENT(xfs_alloc_class, name, \ | |||
1422 | TP_PROTO(struct xfs_alloc_arg *args), \ | 1422 | TP_PROTO(struct xfs_alloc_arg *args), \ |
1423 | TP_ARGS(args)) | 1423 | TP_ARGS(args)) |
1424 | DEFINE_ALLOC_EVENT(xfs_alloc_exact_done); | 1424 | DEFINE_ALLOC_EVENT(xfs_alloc_exact_done); |
1425 | DEFINE_ALLOC_EVENT(xfs_alloc_exact_notfound); | ||
1425 | DEFINE_ALLOC_EVENT(xfs_alloc_exact_error); | 1426 | DEFINE_ALLOC_EVENT(xfs_alloc_exact_error); |
1426 | DEFINE_ALLOC_EVENT(xfs_alloc_near_nominleft); | 1427 | DEFINE_ALLOC_EVENT(xfs_alloc_near_nominleft); |
1427 | DEFINE_ALLOC_EVENT(xfs_alloc_near_first); | 1428 | DEFINE_ALLOC_EVENT(xfs_alloc_near_first); |
diff --git a/fs/xfs/xfs_alloc.c b/fs/xfs/xfs_alloc.c index 112abc439ca5..d9133f10d2b1 100644 --- a/fs/xfs/xfs_alloc.c +++ b/fs/xfs/xfs_alloc.c | |||
@@ -577,61 +577,58 @@ xfs_alloc_ag_vextent_exact( | |||
577 | xfs_extlen_t rlen; /* length of returned extent */ | 577 | xfs_extlen_t rlen; /* length of returned extent */ |
578 | 578 | ||
579 | ASSERT(args->alignment == 1); | 579 | ASSERT(args->alignment == 1); |
580 | |||
580 | /* | 581 | /* |
581 | * Allocate/initialize a cursor for the by-number freespace btree. | 582 | * Allocate/initialize a cursor for the by-number freespace btree. |
582 | */ | 583 | */ |
583 | bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp, | 584 | bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp, |
584 | args->agno, XFS_BTNUM_BNO); | 585 | args->agno, XFS_BTNUM_BNO); |
586 | |||
585 | /* | 587 | /* |
586 | * Lookup bno and minlen in the btree (minlen is irrelevant, really). | 588 | * Lookup bno and minlen in the btree (minlen is irrelevant, really). |
587 | * Look for the closest free block <= bno, it must contain bno | 589 | * Look for the closest free block <= bno, it must contain bno |
588 | * if any free block does. | 590 | * if any free block does. |
589 | */ | 591 | */ |
590 | if ((error = xfs_alloc_lookup_le(bno_cur, args->agbno, args->minlen, &i))) | 592 | error = xfs_alloc_lookup_le(bno_cur, args->agbno, args->minlen, &i); |
593 | if (error) | ||
591 | goto error0; | 594 | goto error0; |
592 | if (!i) { | 595 | if (!i) |
593 | /* | 596 | goto not_found; |
594 | * Didn't find it, return null. | 597 | |
595 | */ | ||
596 | xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR); | ||
597 | args->agbno = NULLAGBLOCK; | ||
598 | return 0; | ||
599 | } | ||
600 | /* | 598 | /* |
601 | * Grab the freespace record. | 599 | * Grab the freespace record. |
602 | */ | 600 | */ |
603 | if ((error = xfs_alloc_get_rec(bno_cur, &fbno, &flen, &i))) | 601 | error = xfs_alloc_get_rec(bno_cur, &fbno, &flen, &i); |
602 | if (error) | ||
604 | goto error0; | 603 | goto error0; |
605 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); | 604 | XFS_WANT_CORRUPTED_GOTO(i == 1, error0); |
606 | ASSERT(fbno <= args->agbno); | 605 | ASSERT(fbno <= args->agbno); |
607 | minend = args->agbno + args->minlen; | 606 | minend = args->agbno + args->minlen; |
608 | maxend = args->agbno + args->maxlen; | 607 | maxend = args->agbno + args->maxlen; |
609 | fend = fbno + flen; | 608 | fend = fbno + flen; |
609 | |||
610 | /* | 610 | /* |
611 | * Give up if the freespace isn't long enough for the minimum request. | 611 | * Give up if the freespace isn't long enough for the minimum request. |
612 | */ | 612 | */ |
613 | if (fend < minend) { | 613 | if (fend < minend) |
614 | xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR); | 614 | goto not_found; |
615 | args->agbno = NULLAGBLOCK; | 615 | |
616 | return 0; | ||
617 | } | ||
618 | /* | 616 | /* |
619 | * End of extent will be smaller of the freespace end and the | 617 | * End of extent will be smaller of the freespace end and the |
620 | * maximal requested end. | 618 | * maximal requested end. |
621 | */ | 619 | * |
622 | end = XFS_AGBLOCK_MIN(fend, maxend); | ||
623 | /* | ||
624 | * Fix the length according to mod and prod if given. | 620 | * Fix the length according to mod and prod if given. |
625 | */ | 621 | */ |
622 | end = XFS_AGBLOCK_MIN(fend, maxend); | ||
626 | args->len = end - args->agbno; | 623 | args->len = end - args->agbno; |
627 | xfs_alloc_fix_len(args); | 624 | xfs_alloc_fix_len(args); |
628 | if (!xfs_alloc_fix_minleft(args)) { | 625 | if (!xfs_alloc_fix_minleft(args)) |
629 | xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR); | 626 | goto not_found; |
630 | return 0; | 627 | |
631 | } | ||
632 | rlen = args->len; | 628 | rlen = args->len; |
633 | ASSERT(args->agbno + rlen <= fend); | 629 | ASSERT(args->agbno + rlen <= fend); |
634 | end = args->agbno + rlen; | 630 | end = args->agbno + rlen; |
631 | |||
635 | /* | 632 | /* |
636 | * We are allocating agbno for rlen [agbno .. end] | 633 | * We are allocating agbno for rlen [agbno .. end] |
637 | * Allocate/initialize a cursor for the by-size btree. | 634 | * Allocate/initialize a cursor for the by-size btree. |
@@ -640,16 +637,25 @@ xfs_alloc_ag_vextent_exact( | |||
640 | args->agno, XFS_BTNUM_CNT); | 637 | args->agno, XFS_BTNUM_CNT); |
641 | ASSERT(args->agbno + args->len <= | 638 | ASSERT(args->agbno + args->len <= |
642 | be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length)); | 639 | be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length)); |
643 | if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, | 640 | error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno, |
644 | args->agbno, args->len, XFSA_FIXUP_BNO_OK))) { | 641 | args->len, XFSA_FIXUP_BNO_OK); |
642 | if (error) { | ||
645 | xfs_btree_del_cursor(cnt_cur, XFS_BTREE_ERROR); | 643 | xfs_btree_del_cursor(cnt_cur, XFS_BTREE_ERROR); |
646 | goto error0; | 644 | goto error0; |
647 | } | 645 | } |
646 | |||
648 | xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR); | 647 | xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR); |
649 | xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR); | 648 | xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR); |
650 | 649 | ||
651 | trace_xfs_alloc_exact_done(args); | ||
652 | args->wasfromfl = 0; | 650 | args->wasfromfl = 0; |
651 | trace_xfs_alloc_exact_done(args); | ||
652 | return 0; | ||
653 | |||
654 | not_found: | ||
655 | /* Didn't find it, return null. */ | ||
656 | xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR); | ||
657 | args->agbno = NULLAGBLOCK; | ||
658 | trace_xfs_alloc_exact_notfound(args); | ||
653 | return 0; | 659 | return 0; |
654 | 660 | ||
655 | error0: | 661 | error0: |