suballoc.c (cb5629b10d64a8006622ce3a52bc887d91057d69) suballoc.c (138211515c102807a16c02fdc15feef1f6ef8124)
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * suballoc.c
5 *
6 * metadata alloc and free
7 * Inspired by ext3 block groups.
8 *

--- 1604 unchanged lines hidden (view full) ---

1613 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
1614 ac->ac_bits_given += (*num_bits);
1615 status = 0;
1616bail:
1617 mlog_exit(status);
1618 return status;
1619}
1620
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * suballoc.c
5 *
6 * metadata alloc and free
7 * Inspired by ext3 block groups.
8 *

--- 1604 unchanged lines hidden (view full) ---

1613 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
1614 ac->ac_bits_given += (*num_bits);
1615 status = 0;
1616bail:
1617 mlog_exit(status);
1618 return status;
1619}
1620
1621static void ocfs2_init_inode_ac_group(struct inode *dir,
1622 struct buffer_head *parent_fe_bh,
1623 struct ocfs2_alloc_context *ac)
1624{
1625 struct ocfs2_dinode *fe = (struct ocfs2_dinode *)parent_fe_bh->b_data;
1626 /*
1627 * Try to allocate inodes from some specific group.
1628 *
1629 * If the parent dir has recorded the last group used in allocation,
1630 * cool, use it. Otherwise if we try to allocate new inode from the
1631 * same slot the parent dir belongs to, use the same chunk.
1632 *
1633 * We are very careful here to avoid the mistake of setting
1634 * ac_last_group to a group descriptor from a different (unlocked) slot.
1635 */
1636 if (OCFS2_I(dir)->ip_last_used_group &&
1637 OCFS2_I(dir)->ip_last_used_slot == ac->ac_alloc_slot)
1638 ac->ac_last_group = OCFS2_I(dir)->ip_last_used_group;
1639 else if (le16_to_cpu(fe->i_suballoc_slot) == ac->ac_alloc_slot)
1640 ac->ac_last_group = ocfs2_which_suballoc_group(
1641 le64_to_cpu(fe->i_blkno),
1642 le16_to_cpu(fe->i_suballoc_bit));
1643}
1644
1645static inline void ocfs2_save_inode_ac_group(struct inode *dir,
1646 struct ocfs2_alloc_context *ac)
1647{
1648 OCFS2_I(dir)->ip_last_used_group = ac->ac_last_group;
1649 OCFS2_I(dir)->ip_last_used_slot = ac->ac_alloc_slot;
1650}
1651
1621int ocfs2_claim_new_inode(struct ocfs2_super *osb,
1622 handle_t *handle,
1652int ocfs2_claim_new_inode(struct ocfs2_super *osb,
1653 handle_t *handle,
1654 struct inode *dir,
1655 struct buffer_head *parent_fe_bh,
1623 struct ocfs2_alloc_context *ac,
1624 u16 *suballoc_bit,
1625 u64 *fe_blkno)
1626{
1627 int status;
1628 unsigned int num_bits;
1629 u64 bg_blkno;
1630
1631 mlog_entry_void();
1632
1633 BUG_ON(!ac);
1634 BUG_ON(ac->ac_bits_given != 0);
1635 BUG_ON(ac->ac_bits_wanted != 1);
1636 BUG_ON(ac->ac_which != OCFS2_AC_USE_INODE);
1637
1656 struct ocfs2_alloc_context *ac,
1657 u16 *suballoc_bit,
1658 u64 *fe_blkno)
1659{
1660 int status;
1661 unsigned int num_bits;
1662 u64 bg_blkno;
1663
1664 mlog_entry_void();
1665
1666 BUG_ON(!ac);
1667 BUG_ON(ac->ac_bits_given != 0);
1668 BUG_ON(ac->ac_bits_wanted != 1);
1669 BUG_ON(ac->ac_which != OCFS2_AC_USE_INODE);
1670
1671 ocfs2_init_inode_ac_group(dir, parent_fe_bh, ac);
1672
1638 status = ocfs2_claim_suballoc_bits(osb,
1639 ac,
1640 handle,
1641 1,
1642 1,
1643 suballoc_bit,
1644 &num_bits,
1645 &bg_blkno);
1646 if (status < 0) {
1647 mlog_errno(status);
1648 goto bail;
1649 }
1650 atomic_inc(&osb->alloc_stats.bg_allocs);
1651
1652 BUG_ON(num_bits != 1);
1653
1654 *fe_blkno = bg_blkno + (u64) (*suballoc_bit);
1655 ac->ac_bits_given++;
1673 status = ocfs2_claim_suballoc_bits(osb,
1674 ac,
1675 handle,
1676 1,
1677 1,
1678 suballoc_bit,
1679 &num_bits,
1680 &bg_blkno);
1681 if (status < 0) {
1682 mlog_errno(status);
1683 goto bail;
1684 }
1685 atomic_inc(&osb->alloc_stats.bg_allocs);
1686
1687 BUG_ON(num_bits != 1);
1688
1689 *fe_blkno = bg_blkno + (u64) (*suballoc_bit);
1690 ac->ac_bits_given++;
1691 ocfs2_save_inode_ac_group(dir, ac);
1656 status = 0;
1657bail:
1658 mlog_exit(status);
1659 return status;
1660}
1661
1662/* translate a group desc. blkno and it's bitmap offset into
1663 * disk cluster offset. */

--- 455 unchanged lines hidden ---
1692 status = 0;
1693bail:
1694 mlog_exit(status);
1695 return status;
1696}
1697
1698/* translate a group desc. blkno and it's bitmap offset into
1699 * disk cluster offset. */

--- 455 unchanged lines hidden ---