Skip to content

Commit b08968f

Browse files
dhowellstorvalds
authored andcommitted
cachefiles: Fix incorrect length to fallocate()
When cachefiles_shorten_object() calls fallocate() to shape the cache file to match the DIO size, it passes the total file size it wants to achieve, not the amount of zeros that should be inserted. Since this is meant to preallocate that amount of storage for the file, it can cause the cache to fill up the disk and hit ENOSPC. Fix this by passing the length actually required to go from the current EOF to the desired EOF. Fixes: 7623ed6 ("cachefiles: Implement cookie resize for truncate") Reported-by: Jeffle Xu <[email protected]> Signed-off-by: David Howells <[email protected]> Tested-by: Jeff Layton <[email protected]> Reviewed-by: Jeff Layton <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/164630854858.3665356.17419701804248490708.stgit@warthog.procyon.org.uk # v1 Signed-off-by: Linus Torvalds <[email protected]>
1 parent b949c21 commit b08968f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/cachefiles/interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static bool cachefiles_shorten_object(struct cachefiles_object *object,
254254
ret = cachefiles_inject_write_error();
255255
if (ret == 0)
256256
ret = vfs_fallocate(file, FALLOC_FL_ZERO_RANGE,
257-
new_size, dio_size);
257+
new_size, dio_size - new_size);
258258
if (ret < 0) {
259259
trace_cachefiles_io_error(object, file_inode(file), ret,
260260
cachefiles_trace_fallocate_error);

0 commit comments

Comments
 (0)