$ fallocate -o 0 -l 1024 f
$ ls -l f
-rw-r--r-- 1 root root 1024 Jun 24 13:00 f
$ fallocate -o 0 -l 512 f
$ ls -l f
-rw-r--r-- 1 root root 512 Jun 24 13:00 f
Unfortunately the second fallocate call caused the file to shrink, due to the call to ftruncate.
On a tmpfs for comparison the file doesn't shrink:
$ fallocate -o 0 -l 1024 f
$ ls -l f
-rw-r--r-- 1 root root 1024 Jun 24 12:55 f
$ fallocate -o 0 -l 512 f
$ ls -l f
-rw-r--r-- 1 root root 1024 Jun 24 12:56 f
This patch only calls ftuncate() if the proposed_length is larger than the current length.
Before this patch on virtiofs we had:
Unfortunately the second
fallocate
call caused the file to shrink, due to the call toftruncate
.On a tmpfs for comparison the file doesn't shrink:
This patch only calls ftuncate() if the proposed_length is larger than the current length.