Commit ddbd2fd
virtiofs: fallocate: should enlarge but not shrink the file
Before this patch on virtiofs we had:
```
$ 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.
Signed-off-by: David Scott <[email protected]>1 parent c4c4274 commit ddbd2fd
1 file changed
+8
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1731 | 1731 | | |
1732 | 1732 | | |
1733 | 1733 | | |
| 1734 | + | |
1734 | 1735 | | |
1735 | 1736 | | |
1736 | 1737 | | |
1737 | 1738 | | |
1738 | | - | |
| 1739 | + | |
1739 | 1740 | | |
1740 | 1741 | | |
1741 | 1742 | | |
| |||
1748 | 1749 | | |
1749 | 1750 | | |
1750 | 1751 | | |
1751 | | - | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
1752 | 1758 | | |
1753 | 1759 | | |
1754 | 1760 | | |
| |||
0 commit comments