inode.c (0b02f4c0d6d9e2c611dfbdd4317193e9dca740e6) inode.c (f456767d3391e9f7d9d25a2e7241d75676dc19da)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/ext4/inode.c
4 *
5 * Copyright (C) 1992, 1993, 1994, 1995
6 * Remy Card (card@masi.ibp.fr)
7 * Laboratoire MASI - Institut Blaise Pascal
8 * Universite Pierre et Marie Curie (Paris VI)

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

1590 }
1591 ei->i_reserved_data_blocks++;
1592 trace_ext4_da_reserve_space(inode);
1593 spin_unlock(&ei->i_block_reservation_lock);
1594
1595 return 0; /* success */
1596}
1597
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/ext4/inode.c
4 *
5 * Copyright (C) 1992, 1993, 1994, 1995
6 * Remy Card (card@masi.ibp.fr)
7 * Laboratoire MASI - Institut Blaise Pascal
8 * Universite Pierre et Marie Curie (Paris VI)

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

1590 }
1591 ei->i_reserved_data_blocks++;
1592 trace_ext4_da_reserve_space(inode);
1593 spin_unlock(&ei->i_block_reservation_lock);
1594
1595 return 0; /* success */
1596}
1597
1598static void ext4_da_release_space(struct inode *inode, int to_free)
1598void ext4_da_release_space(struct inode *inode, int to_free)
1599{
1600 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1601 struct ext4_inode_info *ei = EXT4_I(inode);
1602
1603 if (!to_free)
1604 return; /* Nothing to release, exit */
1605
1606 spin_lock(&EXT4_I(inode)->i_block_reservation_lock);

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

1629
1630 dquot_release_reservation_block(inode, EXT4_C2B(sbi, to_free));
1631}
1632
1633static void ext4_da_page_release_reservation(struct page *page,
1634 unsigned int offset,
1635 unsigned int length)
1636{
1599{
1600 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1601 struct ext4_inode_info *ei = EXT4_I(inode);
1602
1603 if (!to_free)
1604 return; /* Nothing to release, exit */
1605
1606 spin_lock(&EXT4_I(inode)->i_block_reservation_lock);

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

1629
1630 dquot_release_reservation_block(inode, EXT4_C2B(sbi, to_free));
1631}
1632
1633static void ext4_da_page_release_reservation(struct page *page,
1634 unsigned int offset,
1635 unsigned int length)
1636{
1637 int to_release = 0, contiguous_blks = 0;
1637 int contiguous_blks = 0;
1638 struct buffer_head *head, *bh;
1639 unsigned int curr_off = 0;
1640 struct inode *inode = page->mapping->host;
1638 struct buffer_head *head, *bh;
1639 unsigned int curr_off = 0;
1640 struct inode *inode = page->mapping->host;
1641 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1642 unsigned int stop = offset + length;
1641 unsigned int stop = offset + length;
1643 int num_clusters;
1644 ext4_fsblk_t lblk;
1645
1646 BUG_ON(stop > PAGE_SIZE || stop < length);
1647
1648 head = page_buffers(page);
1649 bh = head;
1650 do {
1651 unsigned int next_off = curr_off + bh->b_size;
1652
1653 if (next_off > stop)
1654 break;
1655
1656 if ((offset <= curr_off) && (buffer_delay(bh))) {
1642 ext4_fsblk_t lblk;
1643
1644 BUG_ON(stop > PAGE_SIZE || stop < length);
1645
1646 head = page_buffers(page);
1647 bh = head;
1648 do {
1649 unsigned int next_off = curr_off + bh->b_size;
1650
1651 if (next_off > stop)
1652 break;
1653
1654 if ((offset <= curr_off) && (buffer_delay(bh))) {
1657 to_release++;
1658 contiguous_blks++;
1659 clear_buffer_delay(bh);
1660 } else if (contiguous_blks) {
1661 lblk = page->index <<
1662 (PAGE_SHIFT - inode->i_blkbits);
1663 lblk += (curr_off >> inode->i_blkbits) -
1664 contiguous_blks;
1655 contiguous_blks++;
1656 clear_buffer_delay(bh);
1657 } else if (contiguous_blks) {
1658 lblk = page->index <<
1659 (PAGE_SHIFT - inode->i_blkbits);
1660 lblk += (curr_off >> inode->i_blkbits) -
1661 contiguous_blks;
1665 ext4_es_remove_extent(inode, lblk, contiguous_blks);
1662 ext4_es_remove_blks(inode, lblk, contiguous_blks);
1666 contiguous_blks = 0;
1667 }
1668 curr_off = next_off;
1669 } while ((bh = bh->b_this_page) != head);
1670
1671 if (contiguous_blks) {
1672 lblk = page->index << (PAGE_SHIFT - inode->i_blkbits);
1673 lblk += (curr_off >> inode->i_blkbits) - contiguous_blks;
1663 contiguous_blks = 0;
1664 }
1665 curr_off = next_off;
1666 } while ((bh = bh->b_this_page) != head);
1667
1668 if (contiguous_blks) {
1669 lblk = page->index << (PAGE_SHIFT - inode->i_blkbits);
1670 lblk += (curr_off >> inode->i_blkbits) - contiguous_blks;
1674 ext4_es_remove_extent(inode, lblk, contiguous_blks);
1671 ext4_es_remove_blks(inode, lblk, contiguous_blks);
1675 }
1676
1672 }
1673
1677 /* If we have released all the blocks belonging to a cluster, then we
1678 * need to release the reserved space for that cluster. */
1679 num_clusters = EXT4_NUM_B2C(sbi, to_release);
1680 while (num_clusters > 0) {
1681 lblk = (page->index << (PAGE_SHIFT - inode->i_blkbits)) +
1682 ((num_clusters - 1) << sbi->s_cluster_bits);
1683 if (sbi->s_cluster_ratio == 1 ||
1684 !ext4_es_scan_clu(inode, &ext4_es_is_delayed, lblk))
1685 ext4_da_release_space(inode, 1);
1686
1687 num_clusters--;
1688 }
1689}
1690
1691/*
1692 * Delayed allocation stuff
1693 */
1694
1695struct mpage_da_data {
1696 struct inode *inode;

--- 4613 unchanged lines hidden ---
1674}
1675
1676/*
1677 * Delayed allocation stuff
1678 */
1679
1680struct mpage_da_data {
1681 struct inode *inode;

--- 4613 unchanged lines hidden ---