Commit 78d66ab1 authored by Dan Robertson's avatar Dan Robertson Committed by Kent Overstreet

bcachefs: fix truncate without a size change

Do not attempt to shortcut a truncate when the given new size is
the same as the current size. There may be blocks allocated to the
file that extend beyond the i_size. The ctime and mtime should
not be updated in this case.
Signed-off-by: default avatarDan Robertson <dan@dlrobertson.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 6f152b0f
...@@ -2305,16 +2305,17 @@ int bch2_truncate(struct mnt_idmap *idmap, ...@@ -2305,16 +2305,17 @@ int bch2_truncate(struct mnt_idmap *idmap,
int ret = 0; int ret = 0;
/* /*
* Don't update timestamps if we're not doing anything: * If the truncate call with change the size of the file, the
* cmtimes should be updated. If the size will not change, we
* do not need to update the cmtimes.
*/ */
if (iattr->ia_size == inode->v.i_size) if (iattr->ia_size != inode->v.i_size) {
return 0; if (!(iattr->ia_valid & ATTR_MTIME))
ktime_get_coarse_real_ts64(&iattr->ia_mtime);
if (!(iattr->ia_valid & ATTR_MTIME)) if (!(iattr->ia_valid & ATTR_CTIME))
ktime_get_coarse_real_ts64(&iattr->ia_mtime); ktime_get_coarse_real_ts64(&iattr->ia_ctime);
if (!(iattr->ia_valid & ATTR_CTIME)) iattr->ia_valid |= ATTR_MTIME|ATTR_CTIME;
ktime_get_coarse_real_ts64(&iattr->ia_ctime); }
iattr->ia_valid |= ATTR_MTIME|ATTR_CTIME;
inode_dio_wait(&inode->v); inode_dio_wait(&inode->v);
bch2_pagecache_block_get(&inode->ei_pagecache_lock); bch2_pagecache_block_get(&inode->ei_pagecache_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment