int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info);
int btrfs_prealloc_file_range(struct inode *inode, int mode,
u64 start, u64 num_bytes, u64 min_size,
- loff_t actual_len, u64 *alloc_hint);
+ loff_t actual_len, u64 *alloc_hint,
+ bool update_times);
int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct folio *locked_folio,
u64 start, u64 end, struct writeback_control *wbc);
void btrfs_queue_writepage_fixup(struct btrfs_inode *inode, struct folio *folio);
static int btrfs_fallocate_update_isize(struct inode *inode,
const u64 end,
- const int mode)
+ const int mode,
+ bool update_times)
{
struct btrfs_trans_handle *trans;
struct btrfs_root *root = BTRFS_I(inode)->root;
if (IS_ERR(trans))
return PTR_ERR(trans);
- inode_set_ctime_current(inode);
+ inode_inc_iversion(inode);
+ if (update_times)
+ inode_set_ctime_current(inode);
i_size_write(inode, end);
btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), 0);
ret = btrfs_update_inode(trans, BTRFS_I(inode));
static int btrfs_zero_range(struct inode *inode,
loff_t offset,
loff_t len,
- const int mode)
+ const int mode,
+ bool update_times)
{
struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
struct extent_map *em;
*/
btrfs_free_extent_map(em);
ret = btrfs_fallocate_update_isize(inode, offset + len,
- mode);
+ mode, update_times);
goto out;
}
/*
if (em->flags & EXTENT_FLAG_PREALLOC) {
btrfs_free_extent_map(em);
ret = btrfs_fallocate_update_isize(inode, offset + len,
- mode);
+ mode, update_times);
goto out;
}
if (len < sectorsize && em->disk_bytenr != EXTENT_MAP_HOLE) {
if (!ret)
ret = btrfs_fallocate_update_isize(inode,
offset + len,
- mode);
+ mode,
+ update_times);
return ret;
}
btrfs_free_extent_map(em);
ret = btrfs_prealloc_file_range(inode, mode, alloc_start,
alloc_end - alloc_start,
fs_info->sectorsize,
- offset + len, &alloc_hint);
+ offset + len, &alloc_hint,
+ update_times);
btrfs_unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend,
&cached_state);
/* btrfs_prealloc_file_range releases reserved space on error */
goto out;
}
}
- ret = btrfs_fallocate_update_isize(inode, offset + len, mode);
+ ret = btrfs_fallocate_update_isize(inode, offset + len, mode,
+ update_times);
out:
if (ret && space_reserved)
btrfs_free_reserved_data_space(BTRFS_I(inode), data_reserved,
u64 qgroup_reserved = 0;
struct extent_map *em;
int blocksize = BTRFS_I(inode)->root->fs_info->sectorsize;
+ const bool update_times = btrfs_should_update_cmtime(file);
int ret;
if (btrfs_is_shutdown(inode_to_fs_info(inode)))
goto out;
if (mode & FALLOC_FL_ZERO_RANGE) {
- ret = btrfs_zero_range(inode, offset, len, mode);
+ ret = btrfs_zero_range(inode, offset, len, mode, update_times);
btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
return ret;
}
ret = btrfs_prealloc_file_range(inode, mode,
range->start,
range->len, blocksize,
- offset + len, &alloc_hint);
+ offset + len, &alloc_hint,
+ update_times);
/*
* btrfs_prealloc_file_range() releases space even
* if it returns an error.
* We didn't need to allocate any more space, but we still extended the
* size of the file so we need to update i_size and the inode item.
*/
- ret = btrfs_fallocate_update_isize(inode, actual_end, mode);
+ ret = btrfs_fallocate_update_isize(inode, actual_end, mode,
+ update_times);
out_unlock:
btrfs_unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end,
&cached_state);
static struct btrfs_trans_handle *insert_prealloc_file_extent(
struct btrfs_inode *inode,
struct btrfs_key *ins,
- u64 file_offset)
+ u64 file_offset, bool update_times)
{
struct btrfs_file_extent_item stack_fi;
struct btrfs_replace_extent_info extent_info;
ret = btrfs_replace_file_extents(inode, path, file_offset,
file_offset + len - 1, &extent_info,
- true, &trans);
+ update_times, &trans);
btrfs_free_path(path);
if (ret)
goto free_qgroup;
int btrfs_prealloc_file_range(struct inode *inode, int mode,
u64 start, u64 num_bytes, u64 min_size,
- loff_t actual_len, u64 *alloc_hint)
+ loff_t actual_len, u64 *alloc_hint,
+ bool update_times)
{
struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
struct btrfs_trans_handle *trans;
last_alloc = ins.offset;
trans = insert_prealloc_file_extent(BTRFS_I(inode), &ins,
- cur_offset);
+ cur_offset, update_times);
/*
* Now that we inserted the prealloc extent we can finally
* decrement the number of reservations in the block group.
*alloc_hint = ins.objectid + ins.offset;
inode_inc_iversion(inode);
- inode_set_ctime_current(inode);
+ if (update_times)
+ inode_set_ctime_current(inode);
BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC;
if (!(mode & FALLOC_FL_KEEP_SIZE) &&
(actual_len > inode->i_size) &&