diff options
author | Dan Robertson <dan@dlrobertson.com> | 2021-06-28 03:54:34 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:09:07 +0300 |
commit | 78d66ab1ca541ba95a9ad89780466398b348c230 (patch) | |
tree | c0788ce2190647a93f6c282675e54ce3c6fd4569 /fs/bcachefs/fs-io.c | |
parent | 6f152b0f375450b72724b6eb2ec00f7669fc910e (diff) | |
download | linux-78d66ab1ca541ba95a9ad89780466398b348c230.tar.xz |
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: Dan Robertson <dan@dlrobertson.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/fs-io.c')
-rw-r--r-- | fs/bcachefs/fs-io.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c index a25c3b70ef74..bcf954a2394f 100644 --- a/fs/bcachefs/fs-io.c +++ b/fs/bcachefs/fs-io.c @@ -2305,16 +2305,17 @@ int bch2_truncate(struct mnt_idmap *idmap, 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) - return 0; - - if (!(iattr->ia_valid & ATTR_MTIME)) - ktime_get_coarse_real_ts64(&iattr->ia_mtime); - if (!(iattr->ia_valid & ATTR_CTIME)) - ktime_get_coarse_real_ts64(&iattr->ia_ctime); - iattr->ia_valid |= ATTR_MTIME|ATTR_CTIME; + if (iattr->ia_size != inode->v.i_size) { + if (!(iattr->ia_valid & ATTR_MTIME)) + ktime_get_coarse_real_ts64(&iattr->ia_mtime); + if (!(iattr->ia_valid & ATTR_CTIME)) + ktime_get_coarse_real_ts64(&iattr->ia_ctime); + iattr->ia_valid |= ATTR_MTIME|ATTR_CTIME; + } inode_dio_wait(&inode->v); bch2_pagecache_block_get(&inode->ei_pagecache_lock); |