Skip to content

RFC block: Generic file truncation/creation fallbacks

Max Reitz qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest5 patches 14 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5block/nbd: Fix hang in .bdrv_close()block/nbd.c+11 -17 replies
2/5block: Generic truncation fallbackblock/io.c+65 -45 replies
3/5block: Fall back to fallback truncate functionblock/file-posix.c block/sheepdog.c+2 -212 replies
4/5block: Generic file creation fallbackblock.c+65 -120 replies
5/5iotests: Add test for fallback truncate/createtests/qemu-iotests/259 tests/qemu-iotests/259.out tests/qemu-iotests/group+92 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [Qemu-devel] [RFC 0/5] block: Generic file truncation/creation fallbacks

Hi,

Some protocol drivers do not really support file truncation but still implement .bdrv_co_truncate(): They just don’t do anything when asked to shrink a file. This is reflected by qemu-img, which warns if you resize a file and it has the exact same length afterwards as it had before.

We can just do that generically. There is no reason for some protocol drivers to act ashamed and pretend nobody notices. The only thing we have to take care of is to zero everything in the first sector past the desired EOF, so that format probing won’t go wrong.

(RFC: Is it really OK to just do this for all block drivers?)

Similarly, we can add a fallback file creation path: If a block driver does not support creating a file but it already exists, we can just use it. All we have to do is truncate it to the desired size.

This is an RFC because it feels weird and I don’t want people to associate me with weird stuff too closely.

Well, patch 1 isn’t really an RFC. It’s just a fix.

I was inspired to this series by Maxim’s patch “block/nvme: add support for image creation” (from his “Few fixes for userspace NVME driver” series).

Max Reitz (5):
block/nbd: Fix hang in .bdrv_close()
block: Generic truncation fallback
block: Fall back to fallback truncate function
block: Generic file creation fallback
iotests: Add test for fallback truncate/create

 block.c                    | 77 ++++++++++++++++++++++++++++++++------
 block/file-posix.c         | 21 +----------
 block/io.c                 | 69 ++++++++++++++++++++++++++++++++--
 block/nbd.c                | 12 +++++-
 block/sheepdog.c           |  2 +-
 tests/qemu-iotests/259     | 71 +++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/259.out | 20 ++++++++++
 tests/qemu-iotests/group   |  1 +
 8 files changed, 235 insertions(+), 38 deletions(-)
 create mode 100755 tests/qemu-iotests/259
 create mode 100644 tests/qemu-iotests/259.out
Signature · 1 line
2.21.0