diff options
author | Joel Becker <joel.becker@oracle.com> | 2010-04-13 02:30:19 -0400 |
---|---|---|
committer | Tao Ma <tao.ma@oracle.com> | 2010-04-13 02:30:19 -0400 |
commit | 7d1fe093bf04124dcc50c5dde1765bd098464bfa (patch) | |
tree | a86faa1dc041acd214de5ccbc1baf80ea0109449 /fs | |
parent | 798db35f4649eac2778381c390ed7d12de9ec767 (diff) |
ocfs2: Pass suballocation results back via a structure.
We're going to be adding more info to a suballocator allocation. Rather
than growing every function in the chain, let's pass a result structure
around.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Tao Ma <tao.ma@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ocfs2/suballoc.c | 165 | ||||
-rw-r--r-- | fs/ocfs2/suballoc.h | 5 |
2 files changed, 72 insertions, 98 deletions
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 2f753954a7a8..3d823cffc620 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c | |||
@@ -53,6 +53,12 @@ | |||
53 | 53 | ||
54 | #define OCFS2_MAX_TO_STEAL 1024 | 54 | #define OCFS2_MAX_TO_STEAL 1024 |
55 | 55 | ||
56 | struct ocfs2_suballoc_result { | ||
57 | u64 sr_bg_blkno; /* The bg we allocated from */ | ||
58 | unsigned int sr_bit_offset; /* The bit in the bg */ | ||
59 | unsigned int sr_bits; /* How many bits we claimed */ | ||
60 | }; | ||
61 | |||
56 | static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg); | 62 | static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg); |
57 | static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe); | 63 | static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe); |
58 | static inline u16 ocfs2_find_victim_chain(struct ocfs2_chain_list *cl); | 64 | static inline u16 ocfs2_find_victim_chain(struct ocfs2_chain_list *cl); |
@@ -74,20 +80,18 @@ static int ocfs2_cluster_group_search(struct inode *inode, | |||
74 | struct buffer_head *group_bh, | 80 | struct buffer_head *group_bh, |
75 | u32 bits_wanted, u32 min_bits, | 81 | u32 bits_wanted, u32 min_bits, |
76 | u64 max_block, | 82 | u64 max_block, |
77 | u16 *bit_off, u16 *bits_found); | 83 | struct ocfs2_suballoc_result *res); |
78 | static int ocfs2_block_group_search(struct inode *inode, | 84 | static int ocfs2_block_group_search(struct inode *inode, |
79 | struct buffer_head *group_bh, | 85 | struct buffer_head *group_bh, |
80 | u32 bits_wanted, u32 min_bits, | 86 | u32 bits_wanted, u32 min_bits, |
81 | u64 max_block, | 87 | u64 max_block, |
82 | u16 *bit_off, u16 *bits_found); | 88 | struct ocfs2_suballoc_result *res); |
83 | static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, | 89 | static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, |
84 | struct ocfs2_alloc_context *ac, | 90 | struct ocfs2_alloc_context *ac, |
85 | handle_t *handle, | 91 | handle_t *handle, |
86 | u32 bits_wanted, | 92 | u32 bits_wanted, |
87 | u32 min_bits, | 93 | u32 min_bits, |
88 | u16 *bit_off, | 94 | struct ocfs2_suballoc_result *res); |
89 | unsigned int *num_bits, | ||
90 | u64 *bg_blkno); | ||
91 | static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh, | 95 | static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh, |
92 | int nr); | 96 | int nr); |
93 | static inline int ocfs2_block_group_set_bits(handle_t *handle, | 97 | static inline int ocfs2_block_group_set_bits(handle_t *handle, |
@@ -1248,8 +1252,7 @@ static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb, | |||
1248 | struct buffer_head *bg_bh, | 1252 | struct buffer_head *bg_bh, |
1249 | unsigned int bits_wanted, | 1253 | unsigned int bits_wanted, |
1250 | unsigned int total_bits, | 1254 | unsigned int total_bits, |
1251 | u16 *bit_off, | 1255 | struct ocfs2_suballoc_result *res) |
1252 | u16 *bits_found) | ||
1253 | { | 1256 | { |
1254 | void *bitmap; | 1257 | void *bitmap; |
1255 | u16 best_offset, best_size; | 1258 | u16 best_offset, best_size; |
@@ -1293,14 +1296,9 @@ static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb, | |||
1293 | } | 1296 | } |
1294 | } | 1297 | } |
1295 | 1298 | ||
1296 | /* XXX: I think the first clause is equivalent to the second | 1299 | if (best_size) { |
1297 | * - jlbec */ | 1300 | res->sr_bit_offset = best_offset; |
1298 | if (found == bits_wanted) { | 1301 | res->sr_bits = best_size; |
1299 | *bit_off = start - found; | ||
1300 | *bits_found = found; | ||
1301 | } else if (best_size) { | ||
1302 | *bit_off = best_offset; | ||
1303 | *bits_found = best_size; | ||
1304 | } else { | 1302 | } else { |
1305 | status = -ENOSPC; | 1303 | status = -ENOSPC; |
1306 | /* No error log here -- see the comment above | 1304 | /* No error log here -- see the comment above |
@@ -1456,14 +1454,13 @@ static int ocfs2_cluster_group_search(struct inode *inode, | |||
1456 | struct buffer_head *group_bh, | 1454 | struct buffer_head *group_bh, |
1457 | u32 bits_wanted, u32 min_bits, | 1455 | u32 bits_wanted, u32 min_bits, |
1458 | u64 max_block, | 1456 | u64 max_block, |
1459 | u16 *bit_off, u16 *bits_found) | 1457 | struct ocfs2_suballoc_result *res) |
1460 | { | 1458 | { |
1461 | int search = -ENOSPC; | 1459 | int search = -ENOSPC; |
1462 | int ret; | 1460 | int ret; |
1463 | u64 blkoff; | 1461 | u64 blkoff; |
1464 | struct ocfs2_group_desc *gd = (struct ocfs2_group_desc *) group_bh->b_data; | 1462 | struct ocfs2_group_desc *gd = (struct ocfs2_group_desc *) group_bh->b_data; |
1465 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 1463 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
1466 | u16 tmp_off, tmp_found; | ||
1467 | unsigned int max_bits, gd_cluster_off; | 1464 | unsigned int max_bits, gd_cluster_off; |
1468 | 1465 | ||
1469 | BUG_ON(!ocfs2_is_cluster_bitmap(inode)); | 1466 | BUG_ON(!ocfs2_is_cluster_bitmap(inode)); |
@@ -1490,15 +1487,15 @@ static int ocfs2_cluster_group_search(struct inode *inode, | |||
1490 | 1487 | ||
1491 | ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb), | 1488 | ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb), |
1492 | group_bh, bits_wanted, | 1489 | group_bh, bits_wanted, |
1493 | max_bits, | 1490 | max_bits, res); |
1494 | &tmp_off, &tmp_found); | ||
1495 | if (ret) | 1491 | if (ret) |
1496 | return ret; | 1492 | return ret; |
1497 | 1493 | ||
1498 | if (max_block) { | 1494 | if (max_block) { |
1499 | blkoff = ocfs2_clusters_to_blocks(inode->i_sb, | 1495 | blkoff = ocfs2_clusters_to_blocks(inode->i_sb, |
1500 | gd_cluster_off + | 1496 | gd_cluster_off + |
1501 | tmp_off + tmp_found); | 1497 | res->sr_bit_offset + |
1498 | res->sr_bits); | ||
1502 | mlog(0, "Checking %llu against %llu\n", | 1499 | mlog(0, "Checking %llu against %llu\n", |
1503 | (unsigned long long)blkoff, | 1500 | (unsigned long long)blkoff, |
1504 | (unsigned long long)max_block); | 1501 | (unsigned long long)max_block); |
@@ -1510,16 +1507,14 @@ static int ocfs2_cluster_group_search(struct inode *inode, | |||
1510 | * return success, but we still want to return | 1507 | * return success, but we still want to return |
1511 | * -ENOSPC unless it found the minimum number | 1508 | * -ENOSPC unless it found the minimum number |
1512 | * of bits. */ | 1509 | * of bits. */ |
1513 | if (min_bits <= tmp_found) { | 1510 | if (min_bits <= res->sr_bits) |
1514 | *bit_off = tmp_off; | ||
1515 | *bits_found = tmp_found; | ||
1516 | search = 0; /* success */ | 1511 | search = 0; /* success */ |
1517 | } else if (tmp_found) { | 1512 | else if (res->sr_bits) { |
1518 | /* | 1513 | /* |
1519 | * Don't show bits which we'll be returning | 1514 | * Don't show bits which we'll be returning |
1520 | * for allocation to the local alloc bitmap. | 1515 | * for allocation to the local alloc bitmap. |
1521 | */ | 1516 | */ |
1522 | ocfs2_local_alloc_seen_free_bits(osb, tmp_found); | 1517 | ocfs2_local_alloc_seen_free_bits(osb, res->sr_bits); |
1523 | } | 1518 | } |
1524 | } | 1519 | } |
1525 | 1520 | ||
@@ -1530,7 +1525,7 @@ static int ocfs2_block_group_search(struct inode *inode, | |||
1530 | struct buffer_head *group_bh, | 1525 | struct buffer_head *group_bh, |
1531 | u32 bits_wanted, u32 min_bits, | 1526 | u32 bits_wanted, u32 min_bits, |
1532 | u64 max_block, | 1527 | u64 max_block, |
1533 | u16 *bit_off, u16 *bits_found) | 1528 | struct ocfs2_suballoc_result *res) |
1534 | { | 1529 | { |
1535 | int ret = -ENOSPC; | 1530 | int ret = -ENOSPC; |
1536 | u64 blkoff; | 1531 | u64 blkoff; |
@@ -1543,10 +1538,10 @@ static int ocfs2_block_group_search(struct inode *inode, | |||
1543 | ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb), | 1538 | ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb), |
1544 | group_bh, bits_wanted, | 1539 | group_bh, bits_wanted, |
1545 | le16_to_cpu(bg->bg_bits), | 1540 | le16_to_cpu(bg->bg_bits), |
1546 | bit_off, bits_found); | 1541 | res); |
1547 | if (!ret && max_block) { | 1542 | if (!ret && max_block) { |
1548 | blkoff = le64_to_cpu(bg->bg_blkno) + *bit_off + | 1543 | blkoff = le64_to_cpu(bg->bg_blkno) + |
1549 | *bits_found; | 1544 | res->sr_bit_offset + res->sr_bits; |
1550 | mlog(0, "Checking %llu against %llu\n", | 1545 | mlog(0, "Checking %llu against %llu\n", |
1551 | (unsigned long long)blkoff, | 1546 | (unsigned long long)blkoff, |
1552 | (unsigned long long)max_block); | 1547 | (unsigned long long)max_block); |
@@ -1589,20 +1584,17 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac, | |||
1589 | handle_t *handle, | 1584 | handle_t *handle, |
1590 | u32 bits_wanted, | 1585 | u32 bits_wanted, |
1591 | u32 min_bits, | 1586 | u32 min_bits, |
1592 | u16 *bit_off, | 1587 | struct ocfs2_suballoc_result *res, |
1593 | unsigned int *num_bits, | ||
1594 | u64 gd_blkno, | ||
1595 | u16 *bits_left) | 1588 | u16 *bits_left) |
1596 | { | 1589 | { |
1597 | int ret; | 1590 | int ret; |
1598 | u16 found; | ||
1599 | struct buffer_head *group_bh = NULL; | 1591 | struct buffer_head *group_bh = NULL; |
1600 | struct ocfs2_group_desc *gd; | 1592 | struct ocfs2_group_desc *gd; |
1601 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)ac->ac_bh->b_data; | 1593 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)ac->ac_bh->b_data; |
1602 | struct inode *alloc_inode = ac->ac_inode; | 1594 | struct inode *alloc_inode = ac->ac_inode; |
1603 | 1595 | ||
1604 | ret = ocfs2_read_group_descriptor(alloc_inode, di, gd_blkno, | 1596 | ret = ocfs2_read_group_descriptor(alloc_inode, di, |
1605 | &group_bh); | 1597 | res->sr_bg_blkno, &group_bh); |
1606 | if (ret < 0) { | 1598 | if (ret < 0) { |
1607 | mlog_errno(ret); | 1599 | mlog_errno(ret); |
1608 | return ret; | 1600 | return ret; |
@@ -1610,17 +1602,15 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac, | |||
1610 | 1602 | ||
1611 | gd = (struct ocfs2_group_desc *) group_bh->b_data; | 1603 | gd = (struct ocfs2_group_desc *) group_bh->b_data; |
1612 | ret = ac->ac_group_search(alloc_inode, group_bh, bits_wanted, min_bits, | 1604 | ret = ac->ac_group_search(alloc_inode, group_bh, bits_wanted, min_bits, |
1613 | ac->ac_max_block, bit_off, &found); | 1605 | ac->ac_max_block, res); |
1614 | if (ret < 0) { | 1606 | if (ret < 0) { |
1615 | if (ret != -ENOSPC) | 1607 | if (ret != -ENOSPC) |
1616 | mlog_errno(ret); | 1608 | mlog_errno(ret); |
1617 | goto out; | 1609 | goto out; |
1618 | } | 1610 | } |
1619 | 1611 | ||
1620 | *num_bits = found; | ||
1621 | |||
1622 | ret = ocfs2_alloc_dinode_update_counts(alloc_inode, handle, ac->ac_bh, | 1612 | ret = ocfs2_alloc_dinode_update_counts(alloc_inode, handle, ac->ac_bh, |
1623 | *num_bits, | 1613 | res->sr_bits, |
1624 | le16_to_cpu(gd->bg_chain)); | 1614 | le16_to_cpu(gd->bg_chain)); |
1625 | if (ret < 0) { | 1615 | if (ret < 0) { |
1626 | mlog_errno(ret); | 1616 | mlog_errno(ret); |
@@ -1628,7 +1618,7 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac, | |||
1628 | } | 1618 | } |
1629 | 1619 | ||
1630 | ret = ocfs2_block_group_set_bits(handle, alloc_inode, gd, group_bh, | 1620 | ret = ocfs2_block_group_set_bits(handle, alloc_inode, gd, group_bh, |
1631 | *bit_off, *num_bits); | 1621 | res->sr_bit_offset, res->sr_bits); |
1632 | if (ret < 0) | 1622 | if (ret < 0) |
1633 | mlog_errno(ret); | 1623 | mlog_errno(ret); |
1634 | 1624 | ||
@@ -1644,13 +1634,11 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, | |||
1644 | handle_t *handle, | 1634 | handle_t *handle, |
1645 | u32 bits_wanted, | 1635 | u32 bits_wanted, |
1646 | u32 min_bits, | 1636 | u32 min_bits, |
1647 | u16 *bit_off, | 1637 | struct ocfs2_suballoc_result *res, |
1648 | unsigned int *num_bits, | ||
1649 | u64 *bg_blkno, | ||
1650 | u16 *bits_left) | 1638 | u16 *bits_left) |
1651 | { | 1639 | { |
1652 | int status; | 1640 | int status; |
1653 | u16 chain, tmp_bits; | 1641 | u16 chain; |
1654 | u32 tmp_used; | 1642 | u32 tmp_used; |
1655 | u64 next_group; | 1643 | u64 next_group; |
1656 | struct inode *alloc_inode = ac->ac_inode; | 1644 | struct inode *alloc_inode = ac->ac_inode; |
@@ -1679,8 +1667,8 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, | |||
1679 | * the 1st group with any empty bits. */ | 1667 | * the 1st group with any empty bits. */ |
1680 | while ((status = ac->ac_group_search(alloc_inode, group_bh, | 1668 | while ((status = ac->ac_group_search(alloc_inode, group_bh, |
1681 | bits_wanted, min_bits, | 1669 | bits_wanted, min_bits, |
1682 | ac->ac_max_block, bit_off, | 1670 | ac->ac_max_block, |
1683 | &tmp_bits)) == -ENOSPC) { | 1671 | res)) == -ENOSPC) { |
1684 | if (!bg->bg_next_group) | 1672 | if (!bg->bg_next_group) |
1685 | break; | 1673 | break; |
1686 | 1674 | ||
@@ -1705,11 +1693,11 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, | |||
1705 | } | 1693 | } |
1706 | 1694 | ||
1707 | mlog(0, "alloc succeeds: we give %u bits from block group %llu\n", | 1695 | mlog(0, "alloc succeeds: we give %u bits from block group %llu\n", |
1708 | tmp_bits, (unsigned long long)le64_to_cpu(bg->bg_blkno)); | 1696 | res->sr_bits, (unsigned long long)le64_to_cpu(bg->bg_blkno)); |
1709 | 1697 | ||
1710 | *num_bits = tmp_bits; | 1698 | res->sr_bg_blkno = le64_to_cpu(bg->bg_blkno); |
1711 | 1699 | ||
1712 | BUG_ON(*num_bits == 0); | 1700 | BUG_ON(res->sr_bits == 0); |
1713 | 1701 | ||
1714 | /* | 1702 | /* |
1715 | * Keep track of previous block descriptor read. When | 1703 | * Keep track of previous block descriptor read. When |
@@ -1726,7 +1714,7 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, | |||
1726 | */ | 1714 | */ |
1727 | if (ac->ac_allow_chain_relink && | 1715 | if (ac->ac_allow_chain_relink && |
1728 | (prev_group_bh) && | 1716 | (prev_group_bh) && |
1729 | (ocfs2_block_group_reasonably_empty(bg, *num_bits))) { | 1717 | (ocfs2_block_group_reasonably_empty(bg, res->sr_bits))) { |
1730 | status = ocfs2_relink_block_group(handle, alloc_inode, | 1718 | status = ocfs2_relink_block_group(handle, alloc_inode, |
1731 | ac->ac_bh, group_bh, | 1719 | ac->ac_bh, group_bh, |
1732 | prev_group_bh, chain); | 1720 | prev_group_bh, chain); |
@@ -1748,25 +1736,24 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, | |||
1748 | } | 1736 | } |
1749 | 1737 | ||
1750 | tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used); | 1738 | tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used); |
1751 | fe->id1.bitmap1.i_used = cpu_to_le32(*num_bits + tmp_used); | 1739 | fe->id1.bitmap1.i_used = cpu_to_le32(res->sr_bits + tmp_used); |
1752 | le32_add_cpu(&cl->cl_recs[chain].c_free, -(*num_bits)); | 1740 | le32_add_cpu(&cl->cl_recs[chain].c_free, -res->sr_bits); |
1753 | ocfs2_journal_dirty(handle, ac->ac_bh); | 1741 | ocfs2_journal_dirty(handle, ac->ac_bh); |
1754 | 1742 | ||
1755 | status = ocfs2_block_group_set_bits(handle, | 1743 | status = ocfs2_block_group_set_bits(handle, |
1756 | alloc_inode, | 1744 | alloc_inode, |
1757 | bg, | 1745 | bg, |
1758 | group_bh, | 1746 | group_bh, |
1759 | *bit_off, | 1747 | res->sr_bit_offset, |
1760 | *num_bits); | 1748 | res->sr_bits); |
1761 | if (status < 0) { | 1749 | if (status < 0) { |
1762 | mlog_errno(status); | 1750 | mlog_errno(status); |
1763 | goto bail; | 1751 | goto bail; |
1764 | } | 1752 | } |
1765 | 1753 | ||
1766 | mlog(0, "Allocated %u bits from suballocator %llu\n", *num_bits, | 1754 | mlog(0, "Allocated %u bits from suballocator %llu\n", res->sr_bits, |
1767 | (unsigned long long)le64_to_cpu(fe->i_blkno)); | 1755 | (unsigned long long)le64_to_cpu(fe->i_blkno)); |
1768 | 1756 | ||
1769 | *bg_blkno = le64_to_cpu(bg->bg_blkno); | ||
1770 | *bits_left = le16_to_cpu(bg->bg_free_bits_count); | 1757 | *bits_left = le16_to_cpu(bg->bg_free_bits_count); |
1771 | bail: | 1758 | bail: |
1772 | brelse(group_bh); | 1759 | brelse(group_bh); |
@@ -1782,14 +1769,11 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, | |||
1782 | handle_t *handle, | 1769 | handle_t *handle, |
1783 | u32 bits_wanted, | 1770 | u32 bits_wanted, |
1784 | u32 min_bits, | 1771 | u32 min_bits, |
1785 | u16 *bit_off, | 1772 | struct ocfs2_suballoc_result *res) |
1786 | unsigned int *num_bits, | ||
1787 | u64 *bg_blkno) | ||
1788 | { | 1773 | { |
1789 | int status; | 1774 | int status; |
1790 | u16 victim, i; | 1775 | u16 victim, i; |
1791 | u16 bits_left = 0; | 1776 | u16 bits_left = 0; |
1792 | u64 hint_blkno = ac->ac_last_group; | ||
1793 | struct ocfs2_chain_list *cl; | 1777 | struct ocfs2_chain_list *cl; |
1794 | struct ocfs2_dinode *fe; | 1778 | struct ocfs2_dinode *fe; |
1795 | 1779 | ||
@@ -1816,22 +1800,16 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, | |||
1816 | goto bail; | 1800 | goto bail; |
1817 | } | 1801 | } |
1818 | 1802 | ||
1819 | if (hint_blkno) { | 1803 | res->sr_bg_blkno = ac->ac_last_group; |
1804 | if (res->sr_bg_blkno) { | ||
1820 | /* Attempt to short-circuit the usual search mechanism | 1805 | /* Attempt to short-circuit the usual search mechanism |
1821 | * by jumping straight to the most recently used | 1806 | * by jumping straight to the most recently used |
1822 | * allocation group. This helps us mantain some | 1807 | * allocation group. This helps us mantain some |
1823 | * contiguousness across allocations. */ | 1808 | * contiguousness across allocations. */ |
1824 | status = ocfs2_search_one_group(ac, handle, bits_wanted, | 1809 | status = ocfs2_search_one_group(ac, handle, bits_wanted, |
1825 | min_bits, bit_off, num_bits, | 1810 | min_bits, res, &bits_left); |
1826 | hint_blkno, &bits_left); | 1811 | if (!status) |
1827 | if (!status) { | ||
1828 | /* Be careful to update *bg_blkno here as the | ||
1829 | * caller is expecting it to be filled in, and | ||
1830 | * ocfs2_search_one_group() won't do that for | ||
1831 | * us. */ | ||
1832 | *bg_blkno = hint_blkno; | ||
1833 | goto set_hint; | 1812 | goto set_hint; |
1834 | } | ||
1835 | if (status < 0 && status != -ENOSPC) { | 1813 | if (status < 0 && status != -ENOSPC) { |
1836 | mlog_errno(status); | 1814 | mlog_errno(status); |
1837 | goto bail; | 1815 | goto bail; |
@@ -1844,8 +1822,8 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, | |||
1844 | ac->ac_chain = victim; | 1822 | ac->ac_chain = victim; |
1845 | ac->ac_allow_chain_relink = 1; | 1823 | ac->ac_allow_chain_relink = 1; |
1846 | 1824 | ||
1847 | status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits, bit_off, | 1825 | status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits, |
1848 | num_bits, bg_blkno, &bits_left); | 1826 | res, &bits_left); |
1849 | if (!status) | 1827 | if (!status) |
1850 | goto set_hint; | 1828 | goto set_hint; |
1851 | if (status < 0 && status != -ENOSPC) { | 1829 | if (status < 0 && status != -ENOSPC) { |
@@ -1869,8 +1847,7 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, | |||
1869 | 1847 | ||
1870 | ac->ac_chain = i; | 1848 | ac->ac_chain = i; |
1871 | status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits, | 1849 | status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits, |
1872 | bit_off, num_bits, bg_blkno, | 1850 | res, &bits_left); |
1873 | &bits_left); | ||
1874 | if (!status) | 1851 | if (!status) |
1875 | break; | 1852 | break; |
1876 | if (status < 0 && status != -ENOSPC) { | 1853 | if (status < 0 && status != -ENOSPC) { |
@@ -1887,7 +1864,7 @@ set_hint: | |||
1887 | if (bits_left < min_bits) | 1864 | if (bits_left < min_bits) |
1888 | ac->ac_last_group = 0; | 1865 | ac->ac_last_group = 0; |
1889 | else | 1866 | else |
1890 | ac->ac_last_group = *bg_blkno; | 1867 | ac->ac_last_group = res->sr_bg_blkno; |
1891 | } | 1868 | } |
1892 | 1869 | ||
1893 | bail: | 1870 | bail: |
@@ -1904,7 +1881,7 @@ int ocfs2_claim_metadata(struct ocfs2_super *osb, | |||
1904 | u64 *blkno_start) | 1881 | u64 *blkno_start) |
1905 | { | 1882 | { |
1906 | int status; | 1883 | int status; |
1907 | u64 bg_blkno; | 1884 | struct ocfs2_suballoc_result res; |
1908 | 1885 | ||
1909 | BUG_ON(!ac); | 1886 | BUG_ON(!ac); |
1910 | BUG_ON(ac->ac_bits_wanted < (ac->ac_bits_given + bits_wanted)); | 1887 | BUG_ON(ac->ac_bits_wanted < (ac->ac_bits_given + bits_wanted)); |
@@ -1915,17 +1892,17 @@ int ocfs2_claim_metadata(struct ocfs2_super *osb, | |||
1915 | handle, | 1892 | handle, |
1916 | bits_wanted, | 1893 | bits_wanted, |
1917 | 1, | 1894 | 1, |
1918 | suballoc_bit_start, | 1895 | &res); |
1919 | num_bits, | ||
1920 | &bg_blkno); | ||
1921 | if (status < 0) { | 1896 | if (status < 0) { |
1922 | mlog_errno(status); | 1897 | mlog_errno(status); |
1923 | goto bail; | 1898 | goto bail; |
1924 | } | 1899 | } |
1925 | atomic_inc(&osb->alloc_stats.bg_allocs); | 1900 | atomic_inc(&osb->alloc_stats.bg_allocs); |
1926 | 1901 | ||
1927 | *blkno_start = bg_blkno + (u64) *suballoc_bit_start; | 1902 | *suballoc_bit_start = res.sr_bit_offset; |
1928 | ac->ac_bits_given += (*num_bits); | 1903 | *blkno_start = res.sr_bg_blkno + (u64)(res.sr_bit_offset); |
1904 | ac->ac_bits_given += res.sr_bits; | ||
1905 | *num_bits = res.sr_bits; | ||
1929 | status = 0; | 1906 | status = 0; |
1930 | bail: | 1907 | bail: |
1931 | mlog_exit(status); | 1908 | mlog_exit(status); |
@@ -1972,8 +1949,7 @@ int ocfs2_claim_new_inode(struct ocfs2_super *osb, | |||
1972 | u64 *fe_blkno) | 1949 | u64 *fe_blkno) |
1973 | { | 1950 | { |
1974 | int status; | 1951 | int status; |
1975 | unsigned int num_bits; | 1952 | struct ocfs2_suballoc_result res; |
1976 | u64 bg_blkno; | ||
1977 | 1953 | ||
1978 | mlog_entry_void(); | 1954 | mlog_entry_void(); |
1979 | 1955 | ||
@@ -1989,18 +1965,17 @@ int ocfs2_claim_new_inode(struct ocfs2_super *osb, | |||
1989 | handle, | 1965 | handle, |
1990 | 1, | 1966 | 1, |
1991 | 1, | 1967 | 1, |
1992 | suballoc_bit, | 1968 | &res); |
1993 | &num_bits, | ||
1994 | &bg_blkno); | ||
1995 | if (status < 0) { | 1969 | if (status < 0) { |
1996 | mlog_errno(status); | 1970 | mlog_errno(status); |
1997 | goto bail; | 1971 | goto bail; |
1998 | } | 1972 | } |
1999 | atomic_inc(&osb->alloc_stats.bg_allocs); | 1973 | atomic_inc(&osb->alloc_stats.bg_allocs); |
2000 | 1974 | ||
2001 | BUG_ON(num_bits != 1); | 1975 | BUG_ON(res.sr_bits != 1); |
2002 | 1976 | ||
2003 | *fe_blkno = bg_blkno + (u64) (*suballoc_bit); | 1977 | *suballoc_bit = res.sr_bit_offset; |
1978 | *fe_blkno = res.sr_bg_blkno + (u64)(res.sr_bit_offset); | ||
2004 | ac->ac_bits_given++; | 1979 | ac->ac_bits_given++; |
2005 | ocfs2_save_inode_ac_group(dir, ac); | 1980 | ocfs2_save_inode_ac_group(dir, ac); |
2006 | status = 0; | 1981 | status = 0; |
@@ -2080,8 +2055,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb, | |||
2080 | { | 2055 | { |
2081 | int status; | 2056 | int status; |
2082 | unsigned int bits_wanted = max_clusters; | 2057 | unsigned int bits_wanted = max_clusters; |
2083 | u64 bg_blkno = 0; | 2058 | struct ocfs2_suballoc_result res; |
2084 | u16 bg_bit_off; | ||
2085 | 2059 | ||
2086 | mlog_entry_void(); | 2060 | mlog_entry_void(); |
2087 | 2061 | ||
@@ -2120,14 +2094,12 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb, | |||
2120 | handle, | 2094 | handle, |
2121 | bits_wanted, | 2095 | bits_wanted, |
2122 | min_clusters, | 2096 | min_clusters, |
2123 | &bg_bit_off, | 2097 | &res); |
2124 | num_clusters, | ||
2125 | &bg_blkno); | ||
2126 | if (!status) { | 2098 | if (!status) { |
2127 | *cluster_start = | 2099 | *cluster_start = |
2128 | ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode, | 2100 | ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode, |
2129 | bg_blkno, | 2101 | res.sr_bg_blkno, |
2130 | bg_bit_off); | 2102 | res.sr_bit_offset); |
2131 | atomic_inc(&osb->alloc_stats.bitmap_data); | 2103 | atomic_inc(&osb->alloc_stats.bitmap_data); |
2132 | } | 2104 | } |
2133 | } | 2105 | } |
@@ -2137,7 +2109,8 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb, | |||
2137 | goto bail; | 2109 | goto bail; |
2138 | } | 2110 | } |
2139 | 2111 | ||
2140 | ac->ac_bits_given += *num_clusters; | 2112 | ac->ac_bits_given += res.sr_bits; |
2113 | *num_clusters = res.sr_bits; | ||
2141 | 2114 | ||
2142 | bail: | 2115 | bail: |
2143 | mlog_exit(status); | 2116 | mlog_exit(status); |
diff --git a/fs/ocfs2/suballoc.h b/fs/ocfs2/suballoc.h index da2f29a55ec3..f5a22cd1640f 100644 --- a/fs/ocfs2/suballoc.h +++ b/fs/ocfs2/suballoc.h | |||
@@ -26,13 +26,14 @@ | |||
26 | #ifndef _CHAINALLOC_H_ | 26 | #ifndef _CHAINALLOC_H_ |
27 | #define _CHAINALLOC_H_ | 27 | #define _CHAINALLOC_H_ |
28 | 28 | ||
29 | struct ocfs2_suballoc_result; | ||
29 | typedef int (group_search_t)(struct inode *, | 30 | typedef int (group_search_t)(struct inode *, |
30 | struct buffer_head *, | 31 | struct buffer_head *, |
31 | u32, /* bits_wanted */ | 32 | u32, /* bits_wanted */ |
32 | u32, /* min_bits */ | 33 | u32, /* min_bits */ |
33 | u64, /* max_block */ | 34 | u64, /* max_block */ |
34 | u16 *, /* *bit_off */ | 35 | struct ocfs2_suballoc_result *); |
35 | u16 *); /* *bits_found */ | 36 | /* found bits */ |
36 | 37 | ||
37 | struct ocfs2_alloc_context { | 38 | struct ocfs2_alloc_context { |
38 | struct inode *ac_inode; /* which bitmap are we allocating from? */ | 39 | struct inode *ac_inode; /* which bitmap are we allocating from? */ |