Skip to content

Commit 7b415bf

Browse files
adityakalitytso
authored andcommitted
ext4: Fix bigalloc quota accounting and i_blocks value
With bigalloc changes, the i_blocks value was not correctly set (it was still set to number of blocks being used, but in case of bigalloc, we want i_blocks to represent the number of clusters being used). Since the quota subsystem sets the i_blocks value, this patch fixes the quota accounting and makes sure that the i_blocks value is set correctly. Signed-off-by: Aditya Kali <adityakali@google.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 27baebb commit 7b415bf

7 files changed

Lines changed: 366 additions & 25 deletions

File tree

‎fs/ext4/balloc.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ int ext4_should_retry_alloc(struct super_block *sb, int *retries)
485485
* @handle: handle to this transaction
486486
* @inode: file inode
487487
* @goal: given target block(filesystem wide)
488-
* @count: pointer to total number of blocks needed
488+
* @count: pointer to total number of clusters needed
489489
* @errp: error code
490490
*
491491
* Return 1st allocated block number on success, *count stores total account
@@ -517,7 +517,8 @@ ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
517517
spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
518518
EXT4_I(inode)->i_allocated_meta_blocks += ar.len;
519519
spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
520-
dquot_alloc_block_nofail(inode, ar.len);
520+
dquot_alloc_block_nofail(inode,
521+
EXT4_C2B(EXT4_SB(inode->i_sb), ar.len));
521522
}
522523
return ret;
523524
}

‎fs/ext4/ext4.h‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,17 @@ struct ext4_allocation_request {
144144
#define EXT4_MAP_UNWRITTEN (1 << BH_Unwritten)
145145
#define EXT4_MAP_BOUNDARY (1 << BH_Boundary)
146146
#define EXT4_MAP_UNINIT (1 << BH_Uninit)
147+
/* Sometimes (in the bigalloc case, from ext4_da_get_block_prep) the caller of
148+
* ext4_map_blocks wants to know whether or not the underlying cluster has
149+
* already been accounted for. EXT4_MAP_FROM_CLUSTER conveys to the caller that
150+
* the requested mapping was from previously mapped (or delayed allocated)
151+
* cluster. We use BH_AllocFromCluster only for this flag. BH_AllocFromCluster
152+
* should never appear on buffer_head's state flags.
153+
*/
154+
#define EXT4_MAP_FROM_CLUSTER (1 << BH_AllocFromCluster)
147155
#define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\
148156
EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY |\
149-
EXT4_MAP_UNINIT)
157+
EXT4_MAP_UNINIT | EXT4_MAP_FROM_CLUSTER)
150158

151159
struct ext4_map_blocks {
152160
ext4_fsblk_t m_pblk;
@@ -1884,6 +1892,7 @@ extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
18841892
extern qsize_t *ext4_get_reserved_space(struct inode *inode);
18851893
extern void ext4_da_update_reserve_space(struct inode *inode,
18861894
int used, int quota_claim);
1895+
extern int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock);
18871896

18881897
/* indirect.c */
18891898
extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
@@ -2284,6 +2293,11 @@ extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t);
22842293
enum ext4_state_bits {
22852294
BH_Uninit /* blocks are allocated but uninitialized on disk */
22862295
= BH_JBDPrivateStart,
2296+
BH_AllocFromCluster, /* allocated blocks were part of already
2297+
* allocated cluster. Note that this flag will
2298+
* never, ever appear in a buffer_head's state
2299+
* flag. See EXT4_MAP_FROM_CLUSTER to see where
2300+
* this is used. */
22872301
};
22882302

22892303
BUFFER_FNS(Uninit, uninit)

‎fs/ext4/ext4_extents.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,7 @@ extern struct ext4_ext_path *ext4_ext_find_extent(struct inode *, ext4_lblk_t,
290290
struct ext4_ext_path *);
291291
extern void ext4_ext_drop_refs(struct ext4_ext_path *);
292292
extern int ext4_ext_check_inode(struct inode *inode);
293+
extern int ext4_find_delalloc_cluster(struct inode *inode, ext4_lblk_t lblk,
294+
int search_hint_reverse);
293295
#endif /* _EXT4_EXTENTS */
294296

0 commit comments

Comments
 (0)