Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtiofs: fallocate: should enlarge but not shrink the file #203

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

djs55
Copy link
Contributor

@djs55 djs55 commented Jun 24, 2024

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.

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 <dave@recoil.org>
Copy link
Contributor

@slp slp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

I've also noticed SetattrValid::SIZE is currently not supported. I'll send a PR to fix that.

@slp slp merged commit ddbd2fd into containers:main Jul 2, 2024
5 checks passed
@djs55 djs55 deleted the fallocate-no-shrink branch July 2, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants