diff options
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5352db1a3086..ab807963a614 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -1003,17 +1003,12 @@ out: | |||
1003 | return err; | 1003 | return err; |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | qsize_t ext4_get_reserved_space(struct inode *inode) | 1006 | #ifdef CONFIG_QUOTA |
1007 | qsize_t *ext4_get_reserved_space(struct inode *inode) | ||
1007 | { | 1008 | { |
1008 | unsigned long long total; | 1009 | return &EXT4_I(inode)->i_reserved_quota; |
1009 | |||
1010 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1011 | total = EXT4_I(inode)->i_reserved_data_blocks + | ||
1012 | EXT4_I(inode)->i_reserved_meta_blocks; | ||
1013 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1014 | |||
1015 | return (total << inode->i_blkbits); | ||
1016 | } | 1010 | } |
1011 | #endif | ||
1017 | /* | 1012 | /* |
1018 | * Calculate the number of metadata blocks need to reserve | 1013 | * Calculate the number of metadata blocks need to reserve |
1019 | * to allocate @blocks for non extent file based file | 1014 | * to allocate @blocks for non extent file based file |
@@ -1051,7 +1046,7 @@ static int ext4_calc_metadata_amount(struct inode *inode, int blocks) | |||
1051 | static void ext4_da_update_reserve_space(struct inode *inode, int used) | 1046 | static void ext4_da_update_reserve_space(struct inode *inode, int used) |
1052 | { | 1047 | { |
1053 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 1048 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
1054 | int total, mdb, mdb_free; | 1049 | int total, mdb, mdb_free, mdb_claim = 0; |
1055 | 1050 | ||
1056 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | 1051 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); |
1057 | /* recalculate the number of metablocks still need to be reserved */ | 1052 | /* recalculate the number of metablocks still need to be reserved */ |
@@ -1064,7 +1059,9 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used) | |||
1064 | 1059 | ||
1065 | if (mdb_free) { | 1060 | if (mdb_free) { |
1066 | /* Account for allocated meta_blocks */ | 1061 | /* Account for allocated meta_blocks */ |
1067 | mdb_free -= EXT4_I(inode)->i_allocated_meta_blocks; | 1062 | mdb_claim = EXT4_I(inode)->i_allocated_meta_blocks; |
1063 | BUG_ON(mdb_free < mdb_claim); | ||
1064 | mdb_free -= mdb_claim; | ||
1068 | 1065 | ||
1069 | /* update fs dirty blocks counter */ | 1066 | /* update fs dirty blocks counter */ |
1070 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, mdb_free); | 1067 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, mdb_free); |
@@ -1075,8 +1072,11 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used) | |||
1075 | /* update per-inode reservations */ | 1072 | /* update per-inode reservations */ |
1076 | BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks); | 1073 | BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks); |
1077 | EXT4_I(inode)->i_reserved_data_blocks -= used; | 1074 | EXT4_I(inode)->i_reserved_data_blocks -= used; |
1075 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, used + mdb_claim); | ||
1078 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | 1076 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); |
1079 | 1077 | ||
1078 | vfs_dq_claim_block(inode, used + mdb_claim); | ||
1079 | |||
1080 | /* | 1080 | /* |
1081 | * free those over-booking quota for metadata blocks | 1081 | * free those over-booking quota for metadata blocks |
1082 | */ | 1082 | */ |
@@ -1816,19 +1816,17 @@ repeat: | |||
1816 | 1816 | ||
1817 | md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks; | 1817 | md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks; |
1818 | total = md_needed + nrblocks; | 1818 | total = md_needed + nrblocks; |
1819 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1819 | 1820 | ||
1820 | /* | 1821 | /* |
1821 | * Make quota reservation here to prevent quota overflow | 1822 | * Make quota reservation here to prevent quota overflow |
1822 | * later. Real quota accounting is done at pages writeout | 1823 | * later. Real quota accounting is done at pages writeout |
1823 | * time. | 1824 | * time. |
1824 | */ | 1825 | */ |
1825 | if (vfs_dq_reserve_block(inode, total)) { | 1826 | if (vfs_dq_reserve_block(inode, total)) |
1826 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1827 | return -EDQUOT; | 1827 | return -EDQUOT; |
1828 | } | ||
1829 | 1828 | ||
1830 | if (ext4_claim_free_blocks(sbi, total)) { | 1829 | if (ext4_claim_free_blocks(sbi, total)) { |
1831 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1832 | vfs_dq_release_reservation_block(inode, total); | 1830 | vfs_dq_release_reservation_block(inode, total); |
1833 | if (ext4_should_retry_alloc(inode->i_sb, &retries)) { | 1831 | if (ext4_should_retry_alloc(inode->i_sb, &retries)) { |
1834 | yield(); | 1832 | yield(); |
@@ -1836,10 +1834,11 @@ repeat: | |||
1836 | } | 1834 | } |
1837 | return -ENOSPC; | 1835 | return -ENOSPC; |
1838 | } | 1836 | } |
1837 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1839 | EXT4_I(inode)->i_reserved_data_blocks += nrblocks; | 1838 | EXT4_I(inode)->i_reserved_data_blocks += nrblocks; |
1840 | EXT4_I(inode)->i_reserved_meta_blocks = mdblocks; | 1839 | EXT4_I(inode)->i_reserved_meta_blocks += md_needed; |
1841 | |||
1842 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | 1840 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); |
1841 | |||
1843 | return 0; /* success */ | 1842 | return 0; /* success */ |
1844 | } | 1843 | } |
1845 | 1844 | ||
@@ -4794,6 +4793,9 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4794 | ((__u64)le16_to_cpu(raw_inode->i_file_acl_high)) << 32; | 4793 | ((__u64)le16_to_cpu(raw_inode->i_file_acl_high)) << 32; |
4795 | inode->i_size = ext4_isize(raw_inode); | 4794 | inode->i_size = ext4_isize(raw_inode); |
4796 | ei->i_disksize = inode->i_size; | 4795 | ei->i_disksize = inode->i_size; |
4796 | #ifdef CONFIG_QUOTA | ||
4797 | ei->i_reserved_quota = 0; | ||
4798 | #endif | ||
4797 | inode->i_generation = le32_to_cpu(raw_inode->i_generation); | 4799 | inode->i_generation = le32_to_cpu(raw_inode->i_generation); |
4798 | ei->i_block_group = iloc.block_group; | 4800 | ei->i_block_group = iloc.block_group; |
4799 | ei->i_last_alloc_group = ~0; | 4801 | ei->i_last_alloc_group = ~0; |