ext4: Clean up ext4_get_blocks() so it does not depend on bh_result->b_state
The ext4_get_blocks() function was depending on the value of bh_result->b_state as an input parameter to decide whether or not update the delalloc accounting statistics by calling ext4_da_update_reserve_space(). We now use a separate flag, EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE, to requests this update, so that all callers of ext4_get_blocks() can clear map_bh.b_state before calling ext4_get_blocks() without worrying about any consistency issues. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
parent
2fa3cdfb31
commit
2ac3b6e00a
|
@ -318,16 +318,21 @@ struct ext4_new_group_data {
|
||||||
*/
|
*/
|
||||||
/* Allocate any needed blocks and/or convert an unitialized
|
/* Allocate any needed blocks and/or convert an unitialized
|
||||||
extent to be an initialized ext4 */
|
extent to be an initialized ext4 */
|
||||||
#define EXT4_GET_BLOCKS_CREATE 1
|
#define EXT4_GET_BLOCKS_CREATE 0x0001
|
||||||
/* Request the creation of an unitialized extent */
|
/* Request the creation of an unitialized extent */
|
||||||
#define EXT4_GET_BLOCKS_UNINIT_EXT 2
|
#define EXT4_GET_BLOCKS_UNINIT_EXT 0x0002
|
||||||
#define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\
|
#define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\
|
||||||
EXT4_GET_BLOCKS_CREATE)
|
EXT4_GET_BLOCKS_CREATE)
|
||||||
/* Update the ext4_inode_info i_disksize field */
|
/* Update the ext4_inode_info i_disksize field */
|
||||||
#define EXT4_GET_BLOCKS_EXTEND_DISKSIZE 4
|
#define EXT4_GET_BLOCKS_EXTEND_DISKSIZE 0x0004
|
||||||
/* Caller is from the delayed allocation writeout path,
|
/* Caller is from the delayed allocation writeout path,
|
||||||
so the filesystem blocks have already been accounted for */
|
so set the magic i_delalloc_reserve_flag after taking the
|
||||||
#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 8
|
inode allocation semaphore for */
|
||||||
|
#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0008
|
||||||
|
/* Call ext4_da_update_reserve_space() after successfully
|
||||||
|
allocating the blocks */
|
||||||
|
#define EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE 0x0010
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ioctl commands
|
* ioctl commands
|
||||||
|
|
|
@ -1234,16 +1234,15 @@ int ext4_get_blocks(handle_t *handle, struct inode *inode, sector_t block,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) {
|
if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
|
||||||
EXT4_I(inode)->i_delalloc_reserved_flag = 0;
|
EXT4_I(inode)->i_delalloc_reserved_flag = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update reserved blocks/metadata blocks
|
* Update reserved blocks/metadata blocks after successful
|
||||||
* after successful block allocation
|
* block allocation which had been deferred till now.
|
||||||
* which were deferred till now
|
|
||||||
*/
|
*/
|
||||||
if ((retval > 0) && buffer_delay(bh))
|
if ((retval > 0) && (flags & EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE))
|
||||||
ext4_da_update_reserve_space(inode, retval);
|
ext4_da_update_reserve_space(inode, retval);
|
||||||
}
|
|
||||||
|
|
||||||
up_write((&EXT4_I(inode)->i_data_sem));
|
up_write((&EXT4_I(inode)->i_data_sem));
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -2015,7 +2014,7 @@ static void ext4_print_free_blocks(struct inode *inode)
|
||||||
*/
|
*/
|
||||||
static int mpage_da_map_blocks(struct mpage_da_data *mpd)
|
static int mpage_da_map_blocks(struct mpage_da_data *mpd)
|
||||||
{
|
{
|
||||||
int err, blks;
|
int err, blks, get_blocks_flags;
|
||||||
struct buffer_head new;
|
struct buffer_head new;
|
||||||
sector_t next = mpd->b_blocknr;
|
sector_t next = mpd->b_blocknr;
|
||||||
unsigned max_blocks = mpd->b_size >> mpd->inode->i_blkbits;
|
unsigned max_blocks = mpd->b_size >> mpd->inode->i_blkbits;
|
||||||
|
@ -2040,23 +2039,30 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)
|
||||||
BUG_ON(!handle);
|
BUG_ON(!handle);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We need to make sure the BH_Delay flag is passed down to
|
* Call ext4_get_blocks() to allocate any delayed allocation
|
||||||
* ext4_da_get_block_write(), since it calls ext4_get_blocks()
|
* blocks, or to convert an uninitialized extent to be
|
||||||
* with the EXT4_GET_BLOCKS_DELALLOC_RESERVE flag. This flag
|
* initialized (in the case where we have written into
|
||||||
* causes ext4_get_blocks() to call
|
* one or more preallocated blocks).
|
||||||
* ext4_da_update_reserve_space() if the passed buffer head
|
*
|
||||||
* has the BH_Delay flag set. In the future, once we clean up
|
* We pass in the magic EXT4_GET_BLOCKS_DELALLOC_RESERVE to
|
||||||
* the interfaces to ext4_get_blocks(), we should pass in a
|
* indicate that we are on the delayed allocation path. This
|
||||||
* separate flag which requests that the delayed allocation
|
* affects functions in many different parts of the allocation
|
||||||
* statistics should be updated, instead of depending on the
|
* call path. This flag exists primarily because we don't
|
||||||
* state information getting passed down via the map_bh's
|
* want to change *many* call functions, so ext4_get_blocks()
|
||||||
* state bitmasks plus the magic
|
* will set the magic i_delalloc_reserved_flag once the
|
||||||
* EXT4_GET_BLOCKS_DELALLOC_RESERVE flag.
|
* inode's allocation semaphore is taken.
|
||||||
|
*
|
||||||
|
* If the blocks in questions were delalloc blocks, set
|
||||||
|
* EXT4_GET_BLOCKS_DELALLOC_RESERVE so the delalloc accounting
|
||||||
|
* variables are updated after the blocks have been allocated.
|
||||||
*/
|
*/
|
||||||
new.b_state = mpd->b_state & (1 << BH_Delay);
|
new.b_state = 0;
|
||||||
blks = ext4_get_blocks(handle, mpd->inode, next, max_blocks,
|
get_blocks_flags = (EXT4_GET_BLOCKS_CREATE |
|
||||||
&new, EXT4_GET_BLOCKS_CREATE|
|
|
||||||
EXT4_GET_BLOCKS_DELALLOC_RESERVE);
|
EXT4_GET_BLOCKS_DELALLOC_RESERVE);
|
||||||
|
if (mpd->b_state & (1 << BH_Delay))
|
||||||
|
get_blocks_flags |= EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE;
|
||||||
|
blks = ext4_get_blocks(handle, mpd->inode, next, max_blocks,
|
||||||
|
&new, get_blocks_flags);
|
||||||
if (blks < 0) {
|
if (blks < 0) {
|
||||||
err = blks;
|
err = blks;
|
||||||
/*
|
/*
|
||||||
|
|
Reference in New Issue