RFC block: add llseek(SEEK_HOLE/SEEK_DATA) support
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest9 patches 29 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/9 | block: add llseek(SEEK_HOLE/SEEK_DATA) supportblock/ include/ | +49 | 1 reply | |
| 2/9 | loop: add llseek(SEEK_HOLE/SEEK_DATA) supportdrivers/ | +30 | 2 replies | |
| 3/9 | selftests: block_seek_hole: add loop block driver teststools/ tools/ tools/ +2 more | +159 | 4 replies | |
| 4/9 | dm: add llseek(SEEK_HOLE/SEEK_DATA) supportdrivers/ include/ | +73 | 5 replies | |
| 5/9 | selftests: block_seek_hole: add dm-zero testtools/ tools/ tools/ | +34 | 2 replies | |
| 6/9 | dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) supportdrivers/ | +25 | 3 replies | |
| 7/9 | selftests: block_seek_hole: add dm-linear testtools/ | +15 | 2 replies | |
| 8/9 | dm thin: add llseek(SEEK_HOLE/SEEK_DATA) supportdrivers/ | +77 | 2 replies | |
| 9/9 | selftests: block_seek_hole: add dm-thin testtools/ tools/ | +81 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC 0/9] block: add llseek(SEEK_HOLE/SEEK_DATA) support
cp(1) and backup tools use llseek(SEEK_HOLE/SEEK_DATA) to skip holes in files. This can speed up the process by reducing the amount of data read and it preserves sparseness when writing to the output file.
This patch series is an initial attempt at implementing llseek(SEEK_HOLE/SEEK_DATA) for block devices. I'm looking for feedback on this approach and suggestions for resolving the open issues.
In the block device world there are similar concepts to holes:
- SCSI has Logical Block Provisioning where the "mapped" state would be considered data and other states would be considered holes.
- NBD has NBD_CMD_BLOCK_STATUS for querying whether blocks are present.
- Linux loop block devices and dm-linear targets can pass through queries to the backing file.
- dm-thin targets can query metadata to find holes.
- ...and you may be able to think of more examples.
Therefore it is possible to offer this functionality in block drivers.
In my use case a QEMU process in userspace copies the contents of a dm-thin target. QEMU already uses SEEK_HOLE but that doesn't work on dm-thin targets without this patch series.
Others have also wished for block device support for SEEK_HOLE. Here is an open issue from the BorgBackup project:
https://github.com/borgbackup/borg/issues/5609
With these patches userspace can identify holes in loop, dm-linear, and dm-thin devices. This is done by adding a seek_hole_data() callback to struct block_device_operations. When the callback is NULL the entire device is considered data. Device-mapper is extended along the same lines so that targets can provide seek_hole_data() callbacks.
I'm unfamiliar with much of this code and have probably missed locking requirements. Since llseek() executes synchronously like ioctl() and is not an asynchronous I/O request it's possible that my changes to the loop block driver and dm-thin are broken (e.g. what if the loop device fd is changed during llseek()?).
To run the tests:
# make TARGETS=block_seek_hole -C tools/testing/selftests run_tests
The code is also available here:
https://gitlab.com/stefanha/linux/-/tree/block-seek-hole
Please take a look and let me know your thoughts. Thanks!
Stefan Hajnoczi (9):
block: add llseek(SEEK_HOLE/SEEK_DATA) support
loop: add llseek(SEEK_HOLE/SEEK_DATA) support
selftests: block_seek_hole: add loop block driver tests
dm: add llseek(SEEK_HOLE/SEEK_DATA) support
selftests: block_seek_hole: add dm-zero test
dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) support
selftests: block_seek_hole: add dm-linear test dm thin: add llseek(SEEK_HOLE/SEEK_DATA) support
selftests: block_seek_hole: add dm-thin test
tools/testing/selftests/Makefile | 1 + .../selftests/block_seek_hole/Makefile | 17 +++ include/linux/blkdev.h | 7 ++ include/linux/device-mapper.h | 5 + block/fops.c | 43 ++++++- drivers/block/loop.c | 36 +++++- drivers/md/dm-linear.c | 25 ++++ drivers/md/dm-thin.c | 77 ++++++++++++ drivers/md/dm.c | 68 ++++++++++ .../testing/selftests/block_seek_hole/config | 3 + .../selftests/block_seek_hole/dm_thin.sh | 80 ++++++++++++ .../selftests/block_seek_hole/dm_zero.sh | 31 +++++ .../selftests/block_seek_hole/map_holes.py | 37 ++++++ .../testing/selftests/block_seek_hole/test.py | 117 ++++++++++++++++++ 14 files changed, 540 insertions(+), 7 deletions(-) create mode 100644 tools/testing/selftests/block_seek_hole/Makefile create mode 100644 tools/testing/selftests/block_seek_hole/config create mode 100755 tools/testing/selftests/block_seek_hole/dm_thin.sh create mode 100755 tools/testing/selftests/block_seek_hole/dm_zero.sh create mode 100755 tools/testing/selftests/block_seek_hole/map_holes.py create mode 100755 tools/testing/selftests/block_seek_hole/test.py
Signature · 1 line
2.44.0