aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/balloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/balloc.c')
-rw-r--r--fs/ext4/balloc.c49
1 files changed, 15 insertions, 34 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 98a97129fc5f..35f5f9a27722 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -666,59 +666,40 @@ int ext4_should_retry_alloc(struct super_block *sb, int *retries)
666 return jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal); 666 return jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal);
667} 667}
668 668
669#define EXT4_META_BLOCK 0x1
670
671static ext4_fsblk_t do_blk_alloc(handle_t *handle, struct inode *inode,
672 ext4_lblk_t iblock, ext4_fsblk_t goal,
673 unsigned long *count, int *errp, int flags)
674{
675 struct ext4_allocation_request ar;
676 ext4_fsblk_t ret;
677
678 memset(&ar, 0, sizeof(ar));
679 /* Fill with neighbour allocated blocks */
680
681 ar.inode = inode;
682 ar.goal = goal;
683 ar.len = *count;
684 ar.logical = iblock;
685
686 if (S_ISREG(inode->i_mode) && !(flags & EXT4_META_BLOCK))
687 /* enable in-core preallocation for data block allocation */
688 ar.flags = EXT4_MB_HINT_DATA;
689 else
690 /* disable in-core preallocation for non-regular files */
691 ar.flags = 0;
692
693 ret = ext4_mb_new_blocks(handle, &ar, errp);
694 *count = ar.len;
695 return ret;
696}
697
698/* 669/*
699 * ext4_new_meta_blocks() -- allocate block for meta data (indexing) blocks 670 * ext4_new_meta_blocks() -- allocate block for meta data (indexing) blocks
700 * 671 *
701 * @handle: handle to this transaction 672 * @handle: handle to this transaction
702 * @inode: file inode 673 * @inode: file inode
703 * @goal: given target block(filesystem wide) 674 * @goal: given target block(filesystem wide)
704 * @count: total number of blocks need 675 * @count: pointer to total number of blocks needed
705 * @errp: error code 676 * @errp: error code
706 * 677 *
707 * Return 1st allocated block numberon success, *count stores total account 678 * Return 1st allocated block number on success, *count stores total account
708 * error stores in errp pointer 679 * error stores in errp pointer
709 */ 680 */
710ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode, 681ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
711 ext4_fsblk_t goal, unsigned long *count, int *errp) 682 ext4_fsblk_t goal, unsigned long *count, int *errp)
712{ 683{
684 struct ext4_allocation_request ar;
713 ext4_fsblk_t ret; 685 ext4_fsblk_t ret;
714 ret = do_blk_alloc(handle, inode, 0, goal, 686
715 count, errp, EXT4_META_BLOCK); 687 memset(&ar, 0, sizeof(ar));
688 /* Fill with neighbour allocated blocks */
689 ar.inode = inode;
690 ar.goal = goal;
691 ar.len = count ? *count : 1;
692
693 ret = ext4_mb_new_blocks(handle, &ar, errp);
694 if (count)
695 *count = ar.len;
696
716 /* 697 /*
717 * Account for the allocated meta blocks 698 * Account for the allocated meta blocks
718 */ 699 */
719 if (!(*errp) && EXT4_I(inode)->i_delalloc_reserved_flag) { 700 if (!(*errp) && EXT4_I(inode)->i_delalloc_reserved_flag) {
720 spin_lock(&EXT4_I(inode)->i_block_reservation_lock); 701 spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
721 EXT4_I(inode)->i_allocated_meta_blocks += *count; 702 EXT4_I(inode)->i_allocated_meta_blocks += ar.len;
722 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 703 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
723 } 704 }
724 return ret; 705 return ret;