block: add llseek(SEEK_HOLE/SEEK_DATA) support
Subsystems (3)
cover 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
RFC 1/9 block: add llseek(SEEK_HOLE/SEEK_DATA) support
The SEEK_HOLE/SEEK_DATA interface is used by userspace applications to detect sparseness. This makes copying and backup applications faster and reduces space consumption because only ranges that do not contain data can be skipped.
Handle SEEK_HOLE/SEEK_DATA for block devices. No block drivers implement the new callback yet so the entire block device will appear to contain data. Later patches will add support to drivers so this actually becomes useful.
--- include/linux/blkdev.h | 7 +++++++ block/fops.c | 43 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-)
include/linux/blkdev.h +7 -0
@@ -332,6 +332,9 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op,int blk_revalidate_disk_zones (struct gendisk *disk,void (*update_driver_data)(struct gendisk *disk)); +loff_t blkdev_seek_hole_data (struct block_device *bdev,loff_t offset, +int whence); +/* * Independent access ranges: struct blk_independent_access_range describes * a range of contiguous sectors that can be accessed using device command
@@ -1432,6 +1435,10 @@ struct block_device_operations {* driver. */ int (*alternative_gpt_sector)(struct gendisk *disk,sector_t *sector); + +/* Like llseek(SEEK_HOLE/SEEK_DATA). This callback may be NULL. */ +loff_t (*seek_hole_data)(struct block_device *bdev,loff_t offset, +int whence); };#ifdef CONFIG_COMPAT
block/fops.c +42 -1
55 lines not on this page · raw message
Signature · 1 line
2.44.0
Quoted 4 lines · Stefan Hajnoczi
The SEEK_HOLE/SEEK_DATA interface is used by userspace applications to detect sparseness. This makes copying and backup applications faster and reduces space consumption because only ranges that do not contain data can be skipped.
s/only //
Quoted 12 lines
Handle SEEK_HOLE/SEEK_DATA for block devices. No block drivers implement the new callback yet so the entire block device will appear to contain data. Later patches will add support to drivers so this actually becomes useful.
Signed-off-by Stefan Hajnoczi <[email protected]>--- include/linux/blkdev.h | 7 +++++++ block/fops.c | 43 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
RFC 2/9 loop: add llseek(SEEK_HOLE/SEEK_DATA) support
In reply to Stefan Hajnoczi---
Open issues:
- The file offset is updated on both the blkdev file and the backing file. Is there a way to avoid updating the backing file offset so the file opened by userspace is not affected?
- Should this run in the worker or use the cgroups?
--- drivers/block/loop.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-)
drivers/block/loop.c +30 -6
@@ -750,6 +750,29 @@ static void loop_sysfs_exit(struct loop_device *lo) &loop_attribute_group); } +static loff_t lo_seek_hole_data (struct block_device *bdev,loff_t offset, +int whence) +{ +/* TODO need to activate cgroups or use worker? */ +/* TODO locking? */ +struct loop_device *lo = bdev->bd_disk->private_data; +struct file *file = lo->lo_backing_file; + +if (lo->lo_offset >0 ) + offset += lo->lo_offset;/* TODO underflow/overflow? */ + +/* TODO backing file offset is modified! */ + offset =vfs_llseek (file, offset, whence); +if (offset <0 ) +return offset; + +if (lo->lo_offset >0 ) + offset -= lo->lo_offset;/* TODO underflow/overflow? */ +if (lo->lo_sizelimit >0 && offset > lo->lo_sizelimit) + offset = lo->lo_sizelimit; +return offset; +} +static void loop_config_discard (struct loop_device *lo,struct queue_limits *lim) {
@@ -1751,13 +1774,14 @@ static void lo_free_disk(struct gendisk *disk) }static const struct block_device_operations lo_fops = { - .owner =THIS_MODULE , - .release = lo_release, - .ioctl = lo_ioctl, + .owner =THIS_MODULE , + .release = lo_release, + .ioctl = lo_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = lo_compat_ioctl, + .compat_ioctl = lo_compat_ioctl, #endif - .free_disk = lo_free_disk, + .free_disk = lo_free_disk, + .seek_hole_data = lo_seek_hole_data, };/*
@@ -2140,7 +2164,7 @@ static int loop_control_remove(int idx)pr_warn_once ("deleting an unspecified loop device is not supported.\n" );return -EINVAL ; } - +/* Hide this loop device for serialization. */ ret =mutex_lock_killable (&loop_ctl_mutex);if (ret)
Signature · 1 line
2.44.0
Re: [RFC 2/9] loop: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 22 lines · Stefan Hajnoczi
Signed-off-by Stefan Hajnoczi <[email protected]>---
Open issues:
- The file offset is updated on both the blkdev file and the backing file. Is there a way to avoid updating the backing file offset so the file opened by userspace is not affected?
- Should this run in the worker or use the cgroups?--- drivers/block/loop.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-)drivers/block/loop.c +3
-0@@ -750,6 +750,29 @@ static void loop_sysfs_exit(struct loop_device *lo) &loop_attribute_group); } +static loff_t lo_seek_hole_data (struct block_device *bdev,loff_t offset, +int whence) +{
drivers/block/loop.c static void loop_sysfs_exit(struct loop_device *lo) · line 765
Quoted 10 lines
drivers/block/loop.c +10
-0+/* TODO need to activate cgroups or use worker? */ +/* TODO locking? */ +struct loop_device *lo = bdev->bd_disk->private_data; +struct file *file = lo->lo_backing_file; + +if (lo->lo_offset >0 ) + offset += lo->lo_offset;/* TODO underflow/overflow? */ + +/* TODO backing file offset is modified! */ + offset =vfs_llseek (file, offset, whence);
Not only did you modify the underlying offset...
drivers/block/loop.c static void loop_sysfs_exit(struct loop_device *lo) · line 772
Quoted 7 lines
drivers/block/loop.c +7
-0+if (offset <0 ) +return offset; + +if (lo->lo_offset >0 ) + offset -= lo->lo_offset;/* TODO underflow/overflow? */ +if (lo->lo_sizelimit >0 && offset > lo->lo_sizelimit) + offset = lo->lo_sizelimit;
...but if this code kicks in, you have clamped the return result to EOF of the loop device while leaving the underlying offset beyond the limit, which may mess up assumptions of other code expecting the loop to always have an in-bounds offset for the underlying file (offhand, I don't know if there is any such code; but since loop_ctl_fops.llseek = noop_lseek, there may be code relying on an even-tighter restriction that the offset of the underlying file never changes, not even within bounds).
Furthermore, this is inconsistent with all other seek-beyond-end code that fails with -ENXIO instead of returning size.
But for an RFC, the idea of being able to seek to HOLEs in a loop device is awesome!
drivers/block/loop.c static int loop_control_remove(int idx) · line 2170
Quoted 9 lines
drivers/block/loop.c +1
-1@@ -2140,7 +2164,7 @@ static int loop_control_remove(int idx)pr_warn_once ("deleting an unspecified loop device is not supported.\n" );return -EINVAL ; } - +/* Hide this loop device for serialization. */ ret =mutex_lock_killable (&loop_ctl_mutex);if (ret)
Unrelated whitespace change?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 2/9] loop: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 36 lines · Eric Blake
Quoted 22 lines · Stefan Hajnoczi
Signed-off-by Stefan Hajnoczi <[email protected]>---
Open issues:
- The file offset is updated on both the blkdev file and the backing file. Is there a way to avoid updating the backing file offset so the file opened by userspace is not affected?
- Should this run in the worker or use the cgroups?--- drivers/block/loop.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-)drivers/block/loop.c +3
-0@@ -750,6 +750,29 @@ static void loop_sysfs_exit(struct loop_device *lo) &loop_attribute_group); } +static loff_t lo_seek_hole_data (struct block_device *bdev,loff_t offset, +int whence) +{drivers/block/loop.c static void loop_sysfs_exit(struct loop_device *lo) · line 765
Quoted 10 lines
drivers/block/loop.c +10
-0+/* TODO need to activate cgroups or use worker? */ +/* TODO locking? */ +struct loop_device *lo = bdev->bd_disk->private_data; +struct file *file = lo->lo_backing_file; + +if (lo->lo_offset >0 ) + offset += lo->lo_offset;/* TODO underflow/overflow? */ + +/* TODO backing file offset is modified! */ + offset =vfs_llseek (file, offset, whence);Not only did you modify the underlying offset...
Quoted 16 lines
drivers/block/loop.c static void loop_sysfs_exit(struct loop_device *lo) · line 772
Quoted 7 lines
drivers/block/loop.c +7
-0+if (offset <0 ) +return offset; + +if (lo->lo_offset >0 ) + offset -= lo->lo_offset;/* TODO underflow/overflow? */ +if (lo->lo_sizelimit >0 && offset > lo->lo_sizelimit) + offset = lo->lo_sizelimit;...but if this code kicks in, you have clamped the return result to EOF of the loop device while leaving the underlying offset beyond the limit, which may mess up assumptions of other code expecting the loop to always have an in-bounds offset for the underlying file (offhand, I don't know if there is any such code; but since loop_ctl_fops.llseek =
noop_lseek, there may be code relying on an even-tighter restriction that the offset of the underlying file never changes, not even within bounds).
I don't think anything relies on the file offset. Requests coming from the block device contain their own offset (which may have been based on the block device file's offset, but not the backing file's offset).
Quoted 2 lines
Furthermore, this is inconsistent with all other seek-beyond-end code that fails with
-ENXIOinstead of returning size.
You're right, in the SEEK_DATA case the return value should be -ENXIO. The SEEK_HOLE case is correct with lo_sizelimit. There is also an off-by-one error in the comparison.
It should be:
if (lo->lo_sizelimit > 0 && offset >= lo->lo_sizelimit) {
if (whence == SEEK_DATA)
offset = -ENXIO;
else
offset = lo->lo_sizelimit;
}Quoted 14 lines
But for an RFC, the idea of being able to seek to HOLEs in a loop device is awesome!
drivers/block/loop.c static int loop_control_remove(int idx) · line 2170
Quoted 9 lines
drivers/block/loop.c +1
-1@@ -2140,7 +2164,7 @@ static int loop_control_remove(int idx)pr_warn_once ("deleting an unspecified loop device is not supported.\n" );return -EINVAL ; } - +/* Hide this loop device for serialization. */ ret =mutex_lock_killable (&loop_ctl_mutex);if (ret)Unrelated whitespace change?
Yes, I'll drop it.
Stefan
RFC 3/9 selftests: block_seek_hole: add loop block driver tests
In reply to Stefan HajnocziRun the tests with:
$ make TARGETS=block_seek_hole -C tools/selftests run_tests
--- tools/testing/selftests/Makefile | 1 + .../selftests/block_seek_hole/Makefile | 17 +++ .../testing/selftests/block_seek_hole/config | 1 + .../selftests/block_seek_hole/map_holes.py | 37 +++++++ .../testing/selftests/block_seek_hole/test.py | 103 ++++++++++++++++++ 5 files changed, 159 insertions(+) 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/map_holes.py create mode 100755 tools/testing/selftests/block_seek_hole/test.py
tools/testing/selftests/Makefile +1 -0
@@ -2,6 +2,7 @@ TARGETS += alsa TARGETS += amd-pstate TARGETS += arm64 +TARGETS += block_seek_hole TARGETS += bpf TARGETS += breakpoints TARGETS += cachestat
tools/testing/selftests/block_seek_hole/Makefile new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0-only +PY3 = $(shell which python3 2>/dev/null) + +ifneq ($(PY3),) + +TEST_PROGS := test.py + +include ../lib.mk + +else + +all: no_py3_warning + +no_py3_warning: + @echo "Missing python3. This test will be skipped." + +endif
tools/testing/selftests/block_seek_hole/config new file +1 -0
@@ -0,0 +1 @@ +CONFIG_BLK_DEV_LOOP=m
tools/testing/selftests/block_seek_hole/map_holes.py new file +37 -0
@@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +# +# map_holes.py <filename> +# +# Print the holes and data ranges in a file. + +import errno +import os +import sys + +def map_holes(fd): + end = os.lseek(fd, 0, os.SEEK_END) + offset = 0 + + print('TYPE START END SIZE') + + while offset < end: + contents = 'DATA' + new_offset = os.lseek(fd, offset, os.SEEK_HOLE) + if new_offset == offset: + contents = 'HOLE' + try: + new_offset = os.lseek(fd, offset, os.SEEK_DATA) + except OSError as err: + if err.errno == errno.ENXIO: + new_offset = end + else: + raise err + assert new_offset != offset + print(f'{contents} {offset} {new_offset} {new_offset - offset}') + offset = new_offset + +if __name__ == '__main__': + with open(sys.argv[1], 'rb') as f: + fd = f.fileno() + map_holes(fd)
tools/testing/selftests/block_seek_hole/test.py new file +103 -0
103 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [RFC 3/9] selftests: block_seek_hole: add loop block driver tests
Quoted 37 lines · Stefan Hajnoczi
Run the tests with:
$ make TARGETS=block_seek_hole -C tools/selftests run_testsSigned-off-by Stefan Hajnoczi <[email protected]>--- tools/testing/selftests/Makefile | 1 + .../selftests/block_seek_hole/Makefile | 17 +++ .../testing/selftests/block_seek_hole/config | 1 + .../selftests/block_seek_hole/map_holes.py | 37 +++++++ .../testing/selftests/block_seek_hole/test.py | 103 ++++++++++++++++++ 5 files changed, 159 insertions(+) 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/map_holes.py create mode 100755 tools/testing/selftests/block_seek_hole/test.py+++
b/tools/testing/selftests/block_seek_hole/test.pytools/testing/selftests/block_seek_hole/test.py new file +18
-0+ +# Different data layouts to test + +def data_at_beginning_and_end(f): + f.write(b'A' * 4 * KB) + f.seek(256 * MB) + + f.write(b'B' * 64 * KB) + + f.seek(1024 * MB - KB) + f.write(b'C' * KB) + +def holes_at_beginning_and_end(f): + f.seek(128 * MB) + f.write(b'A' * 4 * KB) + + f.seek(512 * MB) + f.write(b'B' * 64 * KB)
tools/testing/selftests/block_seek_hole/test.py line 95
Quoted 10 lines
tools/testing/selftests/block_seek_hole/test.py new file +10
-0+ + f.truncate(1024 * MB) + +def no_holes(f): + # Just 1 MB so test file generation is quick + mb = b'A' * MB + f.write(mb) + +def empty_file(f): + f.truncate(1024 * MB)
Is it also worth attempting to test a (necessarily sparse!) file larger than 2GiB to prove that we are 64-bit clean, even on a 32-bit system where lseek is different than lseek64? (I honestly have no idea if python always uses 64-bit seek even on 32-bit systems, although I would be surprised if it were not)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 3/9] selftests: block_seek_hole: add loop block driver tests
Quoted 46 lines · Eric Blake
Quoted 45 lines · Stefan Hajnoczi
Run the tests with:
$ make TARGETS=block_seek_hole -C tools/selftests run_testsSigned-off-by Stefan Hajnoczi <[email protected]>--- tools/testing/selftests/Makefile | 1 + .../selftests/block_seek_hole/Makefile | 17 +++ .../testing/selftests/block_seek_hole/config | 1 + .../selftests/block_seek_hole/map_holes.py | 37 +++++++ .../testing/selftests/block_seek_hole/test.py | 103 ++++++++++++++++++ 5 files changed, 159 insertions(+) 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/map_holes.py create mode 100755 tools/testing/selftests/block_seek_hole/test.py+++
b/tools/testing/selftests/block_seek_hole/test.pytools/testing/selftests/block_seek_hole/test.py new file +26
-0+ +# Different data layouts to test + +def data_at_beginning_and_end(f): + f.write(b'A' * 4 * KB) + f.seek(256 * MB) + + f.write(b'B' * 64 * KB) + + f.seek(1024 * MB - KB) + f.write(b'C' * KB) + +def holes_at_beginning_and_end(f): + f.seek(128 * MB) + f.write(b'A' * 4 * KB) + + f.seek(512 * MB) + f.write(b'B' * 64 * KB) + + f.truncate(1024 * MB) + +def no_holes(f): + # Just 1 MB so test file generation is quick + mb = b'A' * MB + f.write(mb) +
Quoted 8 lines
tools/testing/selftests/block_seek_hole/test.py line 95
Quoted 2 lines
tools/testing/selftests/block_seek_hole/test.py new file +2
-0+def empty_file(f): + f.truncate(1024 * MB)Is it also worth attempting to test a (necessarily sparse!) file larger than 2GiB to prove that we are 64-bit clean, even on a 32-bit system where lseek is different than lseek64? (I honestly have no idea if python always uses 64-bit seek even on 32-bit systems, although I would be surprised if it were not)
Yes, it wouldn't hurt to add a test case for that. I'll do that.
Stefan
Re: [RFC 3/9] selftests: block_seek_hole: add loop block driver tests
In reply to Stefan HajnocziQuoted 30 lines · Stefan Hajnoczi
Run the tests with:
$ make TARGETS=block_seek_hole -C tools/selftests run_testsSigned-off-by Stefan Hajnoczi <[email protected]>--- tools/testing/selftests/Makefile | 1 + .../selftests/block_seek_hole/Makefile | 17 +++ .../testing/selftests/block_seek_hole/config | 1 + .../selftests/block_seek_hole/map_holes.py | 37 +++++++ .../testing/selftests/block_seek_hole/test.py | 103 ++++++++++++++++++ 5 files changed, 159 insertions(+) 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/map_holes.py create mode 100755 tools/testing/selftests/block_seek_hole/test.pytools/testing/selftests/block_seek_hole/map_holes.py new file +12
-0+ +def map_holes(fd): + end = os.lseek(fd, 0, os.SEEK_END) + offset = 0 + + print('TYPE START END SIZE') + + while offset < end: + contents = 'DATA' + new_offset = os.lseek(fd, offset, os.SEEK_HOLE) + if new_offset == offset: + contents = 'HOLE'
tools/testing/selftests/block_seek_hole/map_holes.py line 32
Quoted 10 lines
tools/testing/selftests/block_seek_hole/map_holes.py new file +10
-0+ try: + new_offset = os.lseek(fd, offset, os.SEEK_DATA) + except OSError as err: + if err.errno == errno.ENXIO: + new_offset = end + else: + raise err + assert new_offset != offset + print(f'{contents} {offset} {new_offset} {new_offset - offset}') + offset = new_offset
Over the years, I've seen various SEEK_HOLE implementation bugs where things work great on the initial boundary, but fail when requested on an offset not aligned to the start of the extent boundary. It would probably be worth enhancing the test to prove that:
if lseek(fd, offset, SEEK_HOLE) == offset:
new_offset = lseek(fd, offset, SEEK_DATA)
assert new_offset > offset
assert lseek(fd, new_offset - 1, SEEK_HOLE) == new_offset - 1
else:
assert lseek(fd, offset, SEEK_DATA) == offset new_offset = lseek(fd, offset, SEEK_HOLE)
assert new_offset > offset
assert lseek(fd, new_offset - 1, SEEK_DATA) == new_offset - 1
Among other things, this would prove that even though block devices generally operate on a minimum granularity of a sector, lseek() still gives byte-accurate results for a random offset that falls in the middle of a sector, and doesn't accidentally round down reporting an offset less than the value passed in to the request.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 3/9] selftests: block_seek_hole: add loop block driver tests
Quoted 57 lines · Eric Blake
Quoted 30 lines · Stefan Hajnoczi
Run the tests with:
$ make TARGETS=block_seek_hole -C tools/selftests run_testsSigned-off-by Stefan Hajnoczi <[email protected]>--- tools/testing/selftests/Makefile | 1 + .../selftests/block_seek_hole/Makefile | 17 +++ .../testing/selftests/block_seek_hole/config | 1 + .../selftests/block_seek_hole/map_holes.py | 37 +++++++ .../testing/selftests/block_seek_hole/test.py | 103 ++++++++++++++++++ 5 files changed, 159 insertions(+) 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/map_holes.py create mode 100755 tools/testing/selftests/block_seek_hole/test.pytools/testing/selftests/block_seek_hole/map_holes.py new file +12
-0+ +def map_holes(fd): + end = os.lseek(fd, 0, os.SEEK_END) + offset = 0 + + print('TYPE START END SIZE') + + while offset < end: + contents = 'DATA' + new_offset = os.lseek(fd, offset, os.SEEK_HOLE) + if new_offset == offset: + contents = 'HOLE'tools/testing/selftests/block_seek_hole/map_holes.py line 32
Quoted 10 lines
tools/testing/selftests/block_seek_hole/map_holes.py new file +10
-0+ try: + new_offset = os.lseek(fd, offset, os.SEEK_DATA) + except OSError as err: + if err.errno == errno.ENXIO: + new_offset = end + else: + raise err + assert new_offset != offset + print(f'{contents} {offset} {new_offset} {new_offset - offset}') + offset = new_offsetOver the years, I've seen various
SEEK_HOLEimplementation bugs where things work great on the initial boundary, but fail when requested on an offset not aligned to the start of the extent boundary. It would probably be worth enhancing the test to prove that:if
lseek(fd, offset, SEEK_HOLE)== offset:
new_offset=lseek(fd, offset, SEEK_DATA)
assertnew_offset> offset
assertlseek(fd, new_offset - 1, SEEK_HOLE)==new_offset- 1
else:
assertlseek(fd, offset, SEEK_DATA)== offsetnew_offset=lseek(fd, offset, SEEK_HOLE)
assertnew_offset> offset
assertlseek(fd, new_offset - 1, SEEK_DATA)==new_offset- 1
Quoted 5 lines
Among other things, this would prove that even though block devices generally operate on a minimum granularity of a sector,
lseek()still gives byte-accurate results for a random offset that falls in the middle of a sector, and doesn't accidentally round down reporting an offset less than the value passed in to the request.
Sure. I'll add a test for that.
Stefan
RFC 4/9 dm: add llseek(SEEK_HOLE/SEEK_DATA) support
In reply to Stefan HajnocziDelegate SEEK_HOLE/SEEK_DATA to device-mapper targets. The new dm_seek_hole_data() callback allows target types to customize behavior. The default implementation treats the target as all data with no holes.
--- include/linux/device-mapper.h | 5 +++ drivers/md/dm.c | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+)
include/linux/device-mapper.h +5 -0
@@ -161,6 +161,10 @@ typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff,typedef size_t (*dm_dax_recovery_write_fn )(struct dm_target *ti,pgoff_t pgoff,void *addr,size_t bytes,struct iov_iter *i); +/* Like llseek(SEEK_HOLE/SEEK_DATA) */ +typedef loff_t (*dm_seek_hole_data )(struct dm_target *ti,loff_t offset, +int whence); +void dm_error (const char *message);struct dm_dev {
@@ -210,6 +214,7 @@ struct target_type {dm_dax_direct_access_fn direct_access;dm_dax_zero_page_range_fn dax_zero_page_range;dm_dax_recovery_write_fn dax_recovery_write; +dm_seek_hole_data seek_hole_data;/* For internal device-mapper use. */ struct list_head list;
drivers/md/dm.c +68 -0
86 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [RFC 4/9] dm: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 14 lines · Stefan Hajnoczi
Delegate SEEK_HOLE/SEEK_DATA to device-mapper targets. The new
dm_seek_hole_data()callback allows target types to customize behavior. The default implementation treats the target as all data with no holes.Signed-off-by Stefan Hajnoczi <[email protected]>--- include/linux/device-mapper.h | 5 +++ drivers/md/dm.c | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+)drivers/md/dm.c +3
-0+/* Default implementation for targets that do not implement the callback */ +static loff_t dm_blk_seek_hole_data_default (loff_t offset,int whence, +loff_t size)
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3182
Quoted 10 lines
drivers/md/dm.c +10
-0+{ +switch (whence) { +case SEEK_DATA : +if ((unsigned long long )offset >= size) +return -ENXIO ; +return offset; +case SEEK_HOLE : +if ((unsigned long long )offset >= size) +return -ENXIO ; +return size;
These fail with -ENXIO if offset == size (matching what we do on files)...
Quoted 6 lines
drivers/md/dm.c +6
-0+default : +return -EINVAL ; + } +} + +static loff_t dm_blk_do_seek_hole_data(struct dm_table *table, loff_t offset,
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3198
Quoted 10 lines
drivers/md/dm.c +10
-0+ int whence) +{ +struct dm_target *ti; +loff_t end; + +/* Loop when the end of a target is reached */ + do { + ti = dm_table_find_target(table, offset >> SECTOR_SHIFT); + if (!ti) + return whence == SEEK_DATA ? -ENXIO : offset;
...but this blindly returns offset for SEEK_HOLE, even when offset is beyond the end of the dm. I think you want 'return -ENXIO;' unconditionally here.
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3203
Quoted 5 lines
drivers/md/dm.c +5
-0+ + end = (ti->begin + ti->len) <<SECTOR_SHIFT ; + +if (ti->type->seek_hole_data) + offset = ti->type->seek_hole_data (ti, offset, whence);
Are we guaranteed that ti->type->seek_hole_data will not return a value exceeding end? Or can dm be used to truncate the view of an underlying device, and the underlying seek_hold_data can now return an answer beyond where dm_table_find_target should look for the next part of the dm's view?
In which case, should the blkdev_seek_hole_data callback be passed a max size parameter everywhere, similar to how fixed_size_llseek does things?
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3208
Quoted 5 lines
drivers/md/dm.c +5
-0+else + offset =dm_blk_seek_hole_data_default (offset, whence, end); + +if (whence ==SEEK_DATA && offset == -ENXIO ) + offset = end;
You have a bug here. If I have a dm contructed of two underlying targets:
|A |B |
and A is all data, then whence == SEEK_HOLE will have offset = -ENXIO at this point, and you fail to check whether B is also data. That is, you have silently treated the rest of the block device as data, which is semantically not wrong (as that is always a safe fallback), but not optimal.
I think the correct logic is s/whence == SEEK_DATA &&//.
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3209
Quoted 1 line
drivers/md/dm.c +1
-0+ }while (offset == end);
I'm trying to make sure that we can never return the equivalent of lseek(dm, 0, SEEK_END). If you make my above suggested changes, we will iterate through the do loop once more at EOF, and dm_table_find_target() will then fail to match at which point we do get the desired -ENXIO for both SEEK_HOLE and SEEK_DATA.
Quoted 4 lines
drivers/md/dm.c +4
-0+ +return offset; +} +
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 4/9] dm: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 40 lines · Eric Blake
Quoted 14 lines · Stefan Hajnoczi
Delegate SEEK_HOLE/SEEK_DATA to device-mapper targets. The new
dm_seek_hole_data()callback allows target types to customize behavior. The default implementation treats the target as all data with no holes.Signed-off-by Stefan Hajnoczi <[email protected]>--- include/linux/device-mapper.h | 5 +++ drivers/md/dm.c | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+)drivers/md/dm.c +3
-0+/* Default implementation for targets that do not implement the callback */ +static loff_t dm_blk_seek_hole_data_default (loff_t offset,int whence, +loff_t size)drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3182
Quoted 10 lines
drivers/md/dm.c +10
-0+{ +switch (whence) { +case SEEK_DATA : +if ((unsigned long long )offset >= size) +return -ENXIO ; +return offset; +case SEEK_HOLE : +if ((unsigned long long )offset >= size) +return -ENXIO ; +return size;These fail with
-ENXIOif offset == size (matching what we do on files)...Quoted 12 lines
drivers/md/dm.c +12
-0+default : +return -EINVAL ; + } +} + +static loff_t dm_blk_do_seek_hole_data (struct dm_table *table,loff_t offset, +int whence) +{ +struct dm_target *ti; +loff_t end; + +/* Loop when the end of a target is reached */
Quoted 8 lines
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3198
Quoted 4 lines
drivers/md/dm.c +4
-0+ do { + ti = dm_table_find_target(table, offset >> SECTOR_SHIFT); + if (!ti) + return whence == SEEK_DATA ? -ENXIO : offset;...but this blindly returns offset for
SEEK_HOLE, even when offset is beyond the end of the dm. I think you want 'return-ENXIO;' unconditionally here.
If the initial offset is beyond the end of the table, then SEEK_HOLE should return -ENXIO. I agree that the code doesn't handle this case.
However, returning offset here is correct when there is data at the end with SEEK_HOLE.
I'll update the code to address the out-of-bounds offset case, perhaps by checking the initial offset before entering the loop.
Quoted 12 lines
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3203
Quoted 6 lines
drivers/md/dm.c +5
-0+ + end = (ti->begin + ti->len) <<SECTOR_SHIFT ; + +if (ti->type->seek_hole_data) + offset = ti->type->seek_hole_data (ti, offset, whence);Are we guaranteed that
ti->type->seek_hole_datawill not return a value exceeding end? Or can dm be used to truncate the view of an underlying device, and the underlyingseek_hold_datacan now return an answer beyond wheredm_table_find_targetshould look for the next part of the dm's view?
ti->type->seek_hole_data() must not return a value larger than (ti->begin + ti->len) << SECTOR_SHIFT.
Quoted 15 lines
In which case, should the
blkdev_seek_hole_datacallback be passed a max size parameter everywhere, similar to howfixed_size_llseekdoes things?drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3208
Quoted 5 lines
drivers/md/dm.c +5
-0+else + offset =dm_blk_seek_hole_data_default (offset, whence, end); + +if (whence ==SEEK_DATA && offset == -ENXIO ) + offset = end;You have a bug here. If I have a dm contructed of two underlying targets:
|A |B |
Quoted 7 lines
and A is all data, then whence ==
SEEK_HOLEwill have offset =-ENXIOat this point, and you fail to check whether B is also data. That is, you have silently treated the rest of the block device as data, which is semantically not wrong (as that is always a safe fallback), but not optimal.I think the correct logic is s/whence ==
SEEK_DATA&&//.
No, with whence == SEEK_HOLE and an initial offset in A, the new offset will be (A->begin + A->end) << SECTOR_SHIFT. The loop will iterate and continue seeking into B.
The if statement you commented on ensures that we also continue looping with whence == SEEK_DATA, because that would otherwise prematurely end with the new offset = -ENXIO.
Quoted 8 lines
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3209
Quoted 2 lines
drivers/md/dm.c +1
-0+ }while (offset == end);I'm trying to make sure that we can never return the equivalent of
lseek(dm, 0, SEEK_END). If you make my above suggested changes, we will iterate through the do loop once more at EOF, anddm_table_find_target()will then fail to match at which point we do get the desired-ENXIOfor bothSEEK_HOLEandSEEK_DATA.
Wait, lseek() is supposed to return the equivalent of lseek(dm, 0, SEEK_END) when whence == SEEK_HOLE and there is data at the end.
Quoted 11 lines
Quoted 5 lines
drivers/md/dm.c +4
-0+ +return offset; +} +Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 4/9] dm: add llseek(SEEK_HOLE/SEEK_DATA) support
On Wed, Apr 03, 2024 at 10:11:47AM -0400, Stefan Hajnoczi wrote:
...
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/md/dm.c +7
-0+static loff_t dm_blk_do_seek_hole_data (struct dm_table *table,loff_t offset, +int whence) +{ +struct dm_target *ti; +loff_t end; + +/* Loop when the end of a target is reached */ Quoted 8 lines
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3198
Quoted 4 lines
drivers/md/dm.c +4
-0+ do { + ti = dm_table_find_target(table, offset >> SECTOR_SHIFT); + if (!ti) + return whence == SEEK_DATA ? -ENXIO : offset;...but this blindly returns offset for
SEEK_HOLE, even when offset is beyond the end of the dm. I think you want 'return-ENXIO;' unconditionally here.
Quoted 8 lines
If the initial offset is beyond the end of the table, then
SEEK_HOLEshould return-ENXIO. I agree that the code doesn't handle this case.However, returning offset here is correct when there is data at the end with
SEEK_HOLE.I'll update the code to address the out-of-bounds offset case, perhaps by checking the initial offset before entering the loop.
You are correct that if we are on the second loop iteration of SEEK_HOLE (because the first iteration saw all data), then we have found the offset of the start of a hole and should return that offset, not -ENXIO. This may be a case where we just have to be careful on whether the initial pass might have any corner cases different from later times through the loop, and that we end the loop with correct results for both SEEK_HOLE and SEEK_DATA.
Quoted 14 lines
Quoted 13 lines
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3203
Quoted 7 lines
drivers/md/dm.c +5
-0+ + end = (ti->begin + ti->len) <<SECTOR_SHIFT ; + +if (ti->type->seek_hole_data) + offset = ti->type->seek_hole_data (ti, offset, whence);Are we guaranteed that
ti->type->seek_hole_datawill not return a value exceeding end? Or can dm be used to truncate the view of an underlying device, and the underlyingseek_hold_datacan now return an answer beyond wheredm_table_find_targetshould look for the next part of the dm's view?
Quoted 2 lines
ti->type->seek_hole_data()must not return a value larger than (ti->begin+ti->len) <<SECTOR_SHIFT.
Worth adding as documentation then.
Quoted 41 lines
Quoted 16 lines
In which case, should the
blkdev_seek_hole_datacallback be passed a max size parameter everywhere, similar to howfixed_size_llseekdoes things?drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3208
Quoted 5 lines
drivers/md/dm.c +5
-0+else + offset =dm_blk_seek_hole_data_default (offset, whence, end); + +if (whence ==SEEK_DATA && offset == -ENXIO ) + offset = end;You have a bug here. If I have a dm contructed of two underlying targets:
|A |B |
Quoted 7 lines
and A is all data, then whence ==
SEEK_HOLEwill have offset =-ENXIOat this point, and you fail to check whether B is also data. That is, you have silently treated the rest of the block device as data, which is semantically not wrong (as that is always a safe fallback), but not optimal.I think the correct logic is s/whence ==
SEEK_DATA&&//.No, with whence ==
SEEK_HOLEand an initial offset in A, the new offset will be (A->begin+A->end) <<SECTOR_SHIFT. The loop will iterate and continue seeking into B.The if statement you commented on ensures that we also continue looping with whence ==
SEEK_DATA, because that would otherwise prematurely end with the new offset =-ENXIO.Quoted 8 lines
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3209
Quoted 2 lines
drivers/md/dm.c +1
-0+ }while (offset == end);I'm trying to make sure that we can never return the equivalent of
lseek(dm, 0, SEEK_END). If you make my above suggested changes, we will iterate through the do loop once more at EOF, anddm_table_find_target()will then fail to match at which point we do get the desired-ENXIOfor bothSEEK_HOLEandSEEK_DATA.
Quoted 2 lines
Wait,
lseek()is supposed to return the equivalent oflseek(dm, 0, SEEK_END)when whence ==SEEK_HOLEand there is data at the end.
It was confusing enough for me to write my initial review, I apologize if I'm making it harder for you. Yes, we want to ensure that:
off1 = lseek(fd, -1, SEEK_END);
off2 = off1 + 1; // == lseek(fd, 0, SEEK_END)
if off1 belongs to a data extent:
- lseek(fd, off1, SEEK_DATA) == off1
- lseek(fd, off1, SEEK_HOLE) == off2
- lseek(fd, off2, SEEK_DATA) == -ENXIO
- lseek(fd, off2, SEEK_HOLE) == -ENXIO
if off1 belongs to a hole:
- lseek(fd, off1, SEEK_DATA) == -ENXIO
- lseek(fd, off1, SEEK_HOLE) == off1
- lseek(fd, off2, SEEK_DATA) == -ENXIO
- lseek(fd, off2, SEEK_HOLE) == -ENXIO
Anything in my wall of text from the earlier message inconsistent with this table can be ignored; but at the same time, I was not able to quickly convince myself that your code properly had those properties, even after writing up the table.
Reiterating what I said elsewhere, it may be smarter to document that for callbacks, it is wiser to require intermediate behavior that the input value 'offset' is always between the half-open range [ti->begin<<SECTOR_SHIFT, (ti->begin+ti->len)<<SECTOR_SHIFT), and on success, the output must be in the fully-closed range [offset, (ti->begin+ti->len)<<SECTOR_SHIFT], errors like -EIO are permitted but -ENXIO should not be returned; and let the caller worry about synthesizing -ENXIO from that (since the caller knows whether or not there is a successor ti where adjacency concerns come into play).
That is, we can never pass in off2 (beyond the bounds of the table), and when passing in off1, I think this interface may be easier to work with in the intermediate layers, even though it differs from the lseek() interface above. For off1 in data:
- dm_blk_do_seek_hole_data(dm, off1, SEEK_DATA) == off1
- dm_blk_do_seek_hole_data(dm, off1, SEEK_HOLE) == off2
and for a hole:
- dm_blk_do_seek_hole_data(dm, off1, SEEK_DATA) == off2
- dm_blk_do_seek_hole_data(dm, off1, SEEK_HOLE) == off1
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 4/9] dm: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 95 lines · Eric Blake
On Wed, Apr 03, 2024 at 10:11:47AM -0400, Stefan Hajnoczi wrote:
...Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/md/dm.c +7
-0+static loff_t dm_blk_do_seek_hole_data (struct dm_table *table,loff_t offset, +int whence) +{ +struct dm_target *ti; +loff_t end; + +/* Loop when the end of a target is reached */ Quoted 8 lines
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3198
Quoted 4 lines
drivers/md/dm.c +4
-0+ do { + ti = dm_table_find_target(table, offset >> SECTOR_SHIFT); + if (!ti) + return whence == SEEK_DATA ? -ENXIO : offset;...but this blindly returns offset for
SEEK_HOLE, even when offset is beyond the end of the dm. I think you want 'return-ENXIO;' unconditionally here.Quoted 8 lines
If the initial offset is beyond the end of the table, then
SEEK_HOLEshould return-ENXIO. I agree that the code doesn't handle this case.However, returning offset here is correct when there is data at the end with
SEEK_HOLE.I'll update the code to address the out-of-bounds offset case, perhaps by checking the initial offset before entering the loop.
You are correct that if we are on the second loop iteration of
SEEK_HOLE(because the first iteration saw all data), then we have found the offset of the start of a hole and should return that offset, not-ENXIO. This may be a case where we just have to be careful on whether the initial pass might have any corner cases different from later times through the loop, and that we end the loop with correct results for bothSEEK_HOLEandSEEK_DATA.Quoted 14 lines
Quoted 13 lines
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3203
Quoted 7 lines
drivers/md/dm.c +5
-0+ + end = (ti->begin + ti->len) <<SECTOR_SHIFT ; + +if (ti->type->seek_hole_data) + offset = ti->type->seek_hole_data (ti, offset, whence);Are we guaranteed that
ti->type->seek_hole_datawill not return a value exceeding end? Or can dm be used to truncate the view of an underlying device, and the underlyingseek_hold_datacan now return an answer beyond wheredm_table_find_targetshould look for the next part of the dm's view?Quoted 2 lines
ti->type->seek_hole_data()must not return a value larger than (ti->begin+ti->len) <<SECTOR_SHIFT.Worth adding as documentation then.
Quoted 41 lines
Quoted 16 lines
In which case, should the
blkdev_seek_hole_datacallback be passed a max size parameter everywhere, similar to howfixed_size_llseekdoes things?drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3208
Quoted 5 lines
drivers/md/dm.c +5
-0+else + offset =dm_blk_seek_hole_data_default (offset, whence, end); + +if (whence ==SEEK_DATA && offset == -ENXIO ) + offset = end;You have a bug here. If I have a dm contructed of two underlying targets:
|A |B |
Quoted 7 lines
and A is all data, then whence ==
SEEK_HOLEwill have offset =-ENXIOat this point, and you fail to check whether B is also data. That is, you have silently treated the rest of the block device as data, which is semantically not wrong (as that is always a safe fallback), but not optimal.I think the correct logic is s/whence ==
SEEK_DATA&&//.No, with whence ==
SEEK_HOLEand an initial offset in A, the new offset will be (A->begin+A->end) <<SECTOR_SHIFT. The loop will iterate and continue seeking into B.The if statement you commented on ensures that we also continue looping with whence ==
SEEK_DATA, because that would otherwise prematurely end with the new offset =-ENXIO.Quoted 8 lines
drivers/md/dm.c void dm_free_md_mempools(struct dm_md_mempools *pools) · line 3209
Quoted 2 lines
drivers/md/dm.c +1
-0+ }while (offset == end);I'm trying to make sure that we can never return the equivalent of
lseek(dm, 0, SEEK_END). If you make my above suggested changes, we will iterate through the do loop once more at EOF, anddm_table_find_target()will then fail to match at which point we do get the desired-ENXIOfor bothSEEK_HOLEandSEEK_DATA.
Quoted 5 lines
Quoted 2 lines
Wait,
lseek()is supposed to return the equivalent oflseek(dm, 0, SEEK_END)when whence ==SEEK_HOLEand there is data at the end.It was confusing enough for me to write my initial review, I apologize if I'm making it harder for you.
No worries, if my code is hard to understand I can learn from your feedback.
Quoted 10 lines
Yes, we want to ensure that:
off1 =
lseek(fd, -1, SEEK_END);
off2 = off1 + 1; // ==lseek(fd, 0, SEEK_END)if off1 belongs to a data extent:
-lseek(fd, off1, SEEK_DATA)== off1
-lseek(fd, off1, SEEK_HOLE)== off2
-lseek(fd, off2, SEEK_DATA)==-ENXIO
-lseek(fd, off2, SEEK_HOLE)==-ENXIO
Agreed.
Quoted 5 lines
if off1 belongs to a hole:
-lseek(fd, off1, SEEK_DATA)==-ENXIO
-lseek(fd, off1, SEEK_HOLE)== off1
-lseek(fd, off2, SEEK_DATA)==-ENXIO
-lseek(fd, off2, SEEK_HOLE)==-ENXIO
Agreed.
Quoted 16 lines
Anything in my wall of text from the earlier message inconsistent with this table can be ignored; but at the same time, I was not able to quickly convince myself that your code properly had those properties, even after writing up the table.
Reiterating what I said elsewhere, it may be smarter to document that for callbacks, it is wiser to require intermediate behavior that the input value 'offset' is always between the half-open range [ti->begin<<SECTOR_SHIFT, (ti->begin+ti->len)<<SECTOR_SHIFT), and on success, the output must be in the fully-closed range [offset, (ti->begin+ti->len)<<SECTOR_SHIFT], errors like
-EIOare permitted but-ENXIOshould not be returned; and let the caller worry about synthesizing-ENXIOfrom that (since the caller knows whether or not there is a successor ti where adjacency concerns come into play).
Quoted 9 lines
That is, we can never pass in off2 (beyond the bounds of the table), and when passing in off1, I think this interface may be easier to work with in the intermediate layers, even though it differs from the
lseek()interface above. For off1 in data:
-dm_blk_do_seek_hole_data(dm, off1, SEEK_DATA)== off1
-dm_blk_do_seek_hole_data(dm, off1, SEEK_HOLE)== off2
and for a hole:
-dm_blk_do_seek_hole_data(dm, off1, SEEK_DATA)== off2
-dm_blk_do_seek_hole_data(dm, off1, SEEK_HOLE)== off1
I'll take a look again starting from block/fops.c, through dm.c, and into dm-linear.c to see how to make things clearest. Although I would like to have the same semantics for every seek function, maybe in the end your suggestion will make the code clearer. Let's see.
Stefan
Re: [RFC 4/9] dm: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 21 lines · Stefan Hajnoczi
Quoted 10 lines
Yes, we want to ensure that:
off1 =
lseek(fd, -1, SEEK_END);
off2 = off1 + 1; // ==lseek(fd, 0, SEEK_END)if off1 belongs to a data extent:
-lseek(fd, off1, SEEK_DATA)== off1
-lseek(fd, off1, SEEK_HOLE)== off2
-lseek(fd, off2, SEEK_DATA)==-ENXIO
-lseek(fd, off2, SEEK_HOLE)==-ENXIOAgreed.
Quoted 5 lines
if off1 belongs to a hole:
-lseek(fd, off1, SEEK_DATA)==-ENXIO
-lseek(fd, off1, SEEK_HOLE)== off1
-lseek(fd, off2, SEEK_DATA)==-ENXIO
-lseek(fd, off2, SEEK_HOLE)==-ENXIOAgreed.
...
Quoted 11 lines
Quoted 10 lines
That is, we can never pass in off2 (beyond the bounds of the table), and when passing in off1, I think this interface may be easier to work with in the intermediate layers, even though it differs from the
lseek()interface above. For off1 in data:
-dm_blk_do_seek_hole_data(dm, off1, SEEK_DATA)== off1
-dm_blk_do_seek_hole_data(dm, off1, SEEK_HOLE)== off2
and for a hole:
-dm_blk_do_seek_hole_data(dm, off1, SEEK_DATA)== off2
-dm_blk_do_seek_hole_data(dm, off1, SEEK_HOLE)== off1
In the caller, we already need to know both off1 and off2 (that is, the offset we are asking about, AND the offset at which the underlying component ends its map at, since that is where we are then in charge of whether to concatenate that with the next component or give the overall result).
If we already guarantee that we never call into a lower layer with off2 (because it was beyond bounds), then the only difference between the two semantics is whether SEEK_DATA in a final hole returns -ENXIO or off2; and it looks like we can do a conversion from either style into the other.
So designing the caller logic, it looks like I would want:
if off1 >= EOF return -ENXIO (out of bounds)
while off1 < EOF:
determine off2 of current lower region
at this point, we are guaranteed off1 < off2
we also know that off2 < EOF unless we are on last lower region call result=lower_layer(off1, SEEK_X)
it is a bug if result is non-negative but < off1, or if result > off2
if result == off1, return result (we are already in the right HOLE or DATA)
if result > off1 and < off2, return result (we had to advance to get to the right region, but the right region was within the lower layer, and we don't need to inspect further layers)
Note - the above two paragraphs can be collapsed into one: if result < off2, return result (the current subregion gave us an adequate answer)
if result == off2, continue to the next region with off1=result (in first semantics, this is only possible for SEEK_HOLE for a lower region ending in data; in the second semantics, it is possible for either SEEK_HOLE or SEEK_DATA for a lower region ending in the type opposite of the request)
if result == -ENXIO, continue to the next region by using off1=off2 (only possible in the first semantics for SEEK_DATA on a lower region ending in a hole)
any other result is necessarily a negative errno like -EIO; return it
if the loop completes without an early return, we are out of lower regions, and we should be left with off1 == EOF. Because we advanced, we know now to:
return whence == SEEK_HOLE ? off1 : -ENXIO
Quoted 4 lines
I'll take a look again starting from
block/fops.c, throughdm.c, and intodm-linear.cto see how to make things clearest. Although I would like to have the same semantics for every seek function, maybe in the end your suggestion will make the code clearer. Let's see.
Keeping lseek semantics may require a couple more lines of code duplicated at each layer, but less maintainer headaches in the long run of converting between slightly different semantics depending on which layer you are at.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
RFC 5/9 selftests: block_seek_hole: add dm-zero test
In reply to Stefan Hajnoczi--- .../selftests/block_seek_hole/Makefile | 2 +- .../testing/selftests/block_seek_hole/config | 2 ++ .../selftests/block_seek_hole/dm_zero.sh | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/block_seek_hole/dm_zero.sh
tools/testing/selftests/block_seek_hole/Makefile +1 -1
@@ -3,7 +3,7 @@ PY3 = $(shell which python3 2>/dev/null) ifneq ($(PY3),) -TEST_PROGS := test.py +TEST_PROGS := test.py dm_zero.sh include ../lib.mk
tools/testing/selftests/block_seek_hole/config +2 -0
@@ -1 +1,3 @@ CONFIG_BLK_DEV_LOOP=m +CONFIG_BLK_DEV_DM=m +CONFIG_DM_ZERO=m
tools/testing/selftests/block_seek_hole/dm_zero.sh new file +31 -0
@@ -0,0 +1,31 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# +# dm_zero.sh +# +# Test that dm-zero reports data because it does not have a custom +# SEEK_HOLE/SEEK_DATA implementation. + +set -e + +dev_name=test-$$ +size=$((1024 * 1024 * 1024 / 512)) # 1 GB + +cleanup() { + dmsetup remove $dev_name +} +trap cleanup EXIT + +dmsetup create $dev_name --table "0 $size zero" + +output=$(./map_holes.py /dev/mapper/$dev_name) +expected='TYPE START END SIZE +DATA 0 1073741824 1073741824' + +if [ "$output" != "$expected" ]; then + echo 'FAIL expected:' + echo "$expected" + echo 'Does not match device output:' + echo "$output" + exit 1 +fi
Signature · 1 line
2.44.0
Re: [RFC 5/9] selftests: block_seek_hole: add dm-zero test
Quoted 11 lines · Stefan Hajnoczi
Signed-off-by Stefan Hajnoczi <[email protected]>--- .../selftests/block_seek_hole/Makefile | 2 +- .../testing/selftests/block_seek_hole/config | 2 ++ .../selftests/block_seek_hole/dm_zero.sh | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/block_seek_hole/dm_zero.sh+++
b/tools/testing/selftests/block_seek_hole/dm_zero.sh
tools/testing/selftests/block_seek_hole/dm_zero.sh line 7
Quoted 7 lines
tools/testing/selftests/block_seek_hole/dm_zero.sh new file +7
-0@@ -0,0 +1,31 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# +# dm_zero.sh +# +# Test that dm-zero reports data because it does not have a custom +# SEEK_HOLE/SEEK_DATA implementation.
Why not? Wouldn't it make more sense to have dm-zero report the entire device as a hole (that is, an in-range SEEK_HOLE always returns the same offset, while an in-range SEEK_DATA returns the device size)?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 5/9] selftests: block_seek_hole: add dm-zero test
Quoted 10 lines · Eric Blake
Quoted 8 lines · Stefan Hajnoczi
Signed-off-by Stefan Hajnoczi <[email protected]>--- .../selftests/block_seek_hole/Makefile | 2 +- .../testing/selftests/block_seek_hole/config | 2 ++ .../selftests/block_seek_hole/dm_zero.sh | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/block_seek_hole/dm_zero.sh
Quoted 13 lines
tools/testing/selftests/block_seek_hole/dm_zero.sh line 7
Quoted 9 lines
+++
b/tools/testing/selftests/block_seek_hole/dm_zero.shtools/testing/selftests/block_seek_hole/dm_zero.sh new file +7
-0@@ -0,0 +1,31 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# +# dm_zero.sh +# +# Test that dm-zero reports data because it does not have a custom +# SEEK_HOLE/SEEK_DATA implementation.Why not? Wouldn't it make more sense to have dm-zero report the entire device as a hole (that is, an in-range
SEEK_HOLEalways returns the same offset, while an in-rangeSEEK_DATAreturns the device size)?
Yes, dm-zero could report a hole. I just added this test to verify that targets that do not implement seek_hole_data() work and the dm-zero target was convenient for testing.
Stefan
Quoted 6 lines
Signature · 4 lines
-- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
RFC 6/9 dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) support
In reply to Stefan Hajnoczi--- drivers/md/dm-linear.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/md/dm-linear.c +25 -0
@@ -147,6 +147,30 @@ static int linear_report_zones(struct dm_target *ti,#define linear_report_zones NULL#endif +static loff_t linear_seek_hole_data (struct dm_target *ti,loff_t offset, +int whence) +{ +struct linear_c *lc = ti->private; +loff_t ti_begin = ti->begin <<SECTOR_SHIFT ; +loff_t ti_len = ti->len <<SECTOR_SHIFT ; +loff_t bdev_start = lc->start <<SECTOR_SHIFT ; +loff_t bdev_offset; + +/* TODO underflow/overflow? */ + bdev_offset = offset - ti_begin + bdev_start; + + bdev_offset =blkdev_seek_hole_data (lc->dev->bdev, bdev_offset, + whence); +if (bdev_offset <0 ) +return bdev_offset; + + offset = bdev_offset - bdev_start; +if (offset >= ti_len) +return whence ==SEEK_DATA ? -ENXIO : ti_begin + ti_len; + +return offset + ti_begin; +} +static int linear_iterate_devices (struct dm_target *ti,iterate_devices_callout_fn fn,void *data) {
@@ -212,6 +236,7 @@ static struct target_type linear_target = { .direct_access = linear_dax_direct_access, .dax_zero_page_range = linear_dax_zero_page_range, .dax_recovery_write = linear_dax_recovery_write, + .seek_hole_data = linear_seek_hole_data, };int __init dm_linear_init (void )
Signature · 1 line
2.44.0
Re: [RFC 6/9] dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 11 lines · Stefan Hajnoczi
Signed-off-by Stefan Hajnoczi <[email protected]>--- drivers/md/dm-linear.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)drivers/md/dm-linear.c +0
-0@@ -147,6 +147,30 @@ static int linear_report_zones(struct dm_target *ti,#define linear_report_zones NULL
drivers/md/dm-linear.c static int linear_report_zones(struct dm_target *ti, · line 157
Quoted 10 lines
drivers/md/dm-linear.c +8
-0#endif +static loff_t linear_seek_hole_data (struct dm_target *ti,loff_t offset, +int whence) +{ +struct linear_c *lc = ti->private; +loff_t ti_begin = ti->begin <<SECTOR_SHIFT ; +loff_t ti_len = ti->len <<SECTOR_SHIFT ; +loff_t bdev_start = lc->start <<SECTOR_SHIFT ; +loff_t bdev_offset;
Okay, given my questions in 4/9, it looks like your intent is that each callback for dm_seek_hole_data will obey its own ti-> limits.
drivers/md/dm-linear.c static int linear_report_zones(struct dm_target *ti, · line 169
Quoted 12 lines
drivers/md/dm-linear.c +12
-0+ +/* TODO underflow/overflow? */ + bdev_offset = offset - ti_begin + bdev_start; + + bdev_offset =blkdev_seek_hole_data (lc->dev->bdev, bdev_offset, + whence); +if (bdev_offset <0 ) +return bdev_offset; + + offset = bdev_offset - bdev_start; +if (offset >= ti_len) +return whence ==SEEK_DATA ? -ENXIO : ti_begin + ti_len;
However, this is inconsistent with dm_blk_seek_hole_data_default in 4/9; I think you want to unconditionally return -ENXIO here, and let the caller figure out when to turn -ENXIO back into end to proceed with the next ti in the list.
OR, you may want to document the semantics that dm_seek_hole_data callbacks must NOT return -ENXIO, but always return ti_begin + ti_len when the answer (either SEEK_HOLE or SEEK_END) did not lie within the current ti - it is DIFFERENT than the semantics for blkdev_seek_hole_data, but gets normalized back into the expected -ENXIO answer when dm_blk_do_seek_hole_data finally advances past the last ti.
At any rate, I know this is an RFC series, but it goes to show that comments will be essential, whichever interface you decide for callbacks to honor (both a guarantee that callbacks will only ever see SEEK_HOLE/SEEK_DATA in bounds, because earlier points in the call stack have filtered out out-of-bounds and SEEK_SET; and constraints on what the return value(s) must be for the various callbacks, especially if it is different from the eventual return value of the overall llseek syscall)
Quoted 18 lines
drivers/md/dm-linear.c +5
-0+ +return offset + ti_begin; +} +static int linear_iterate_devices (struct dm_target *ti,iterate_devices_callout_fn fn,void *data) {@@ -212,6 +236,7 @@ static struct target_type linear_target = { .direct_access = linear_dax_direct_access, .dax_zero_page_range = linear_dax_zero_page_range, .dax_recovery_write = linear_dax_recovery_write, + .seek_hole_data = linear_seek_hole_data, };int __init dm_linear_init (void )Signature · 1 line
2.44.0
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 6/9] dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 14 lines · Eric Blake
Quoted 13 lines · Stefan Hajnoczi
Signed-off-by Stefan Hajnoczi <[email protected]>--- drivers/md/dm-linear.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)drivers/md/dm-linear.c +0
-0@@ -147,6 +147,30 @@ static int linear_report_zones(struct dm_target *ti,#define linear_report_zones NULL#endif
Quoted 11 lines
drivers/md/dm-linear.c static int linear_report_zones(struct dm_target *ti, · line 157
Quoted 8 lines
drivers/md/dm-linear.c +8
-0+static loff_t linear_seek_hole_data (struct dm_target *ti,loff_t offset, +int whence) +{ +struct linear_c *lc = ti->private; +loff_t ti_begin = ti->begin <<SECTOR_SHIFT ; +loff_t ti_len = ti->len <<SECTOR_SHIFT ; +loff_t bdev_start = lc->start <<SECTOR_SHIFT ; +loff_t bdev_offset;Okay, given my questions in 4/9, it looks like your intent is that each callback for
dm_seek_hole_datawill obey its own ti-> limits.
Yes, exactly.
Quoted 27 lines
drivers/md/dm-linear.c static int linear_report_zones(struct dm_target *ti, · line 169
Quoted 13 lines
drivers/md/dm-linear.c +12
-0+ +/* TODO underflow/overflow? */ + bdev_offset = offset - ti_begin + bdev_start; + + bdev_offset =blkdev_seek_hole_data (lc->dev->bdev, bdev_offset, + whence); +if (bdev_offset <0 ) +return bdev_offset; + + offset = bdev_offset - bdev_start; +if (offset >= ti_len) +return whence ==SEEK_DATA ? -ENXIO : ti_begin + ti_len;However, this is inconsistent with
dm_blk_seek_hole_data_defaultin 4/9; I think you want to unconditionally return-ENXIOhere, and let the caller figure out when to turn-ENXIOback into end to proceed with the next ti in the list.OR, you may want to document the semantics that
dm_seek_hole_datacallbacks must NOT return-ENXIO, but always returnti_begin+ti_lenwhen the answer (eitherSEEK_HOLEorSEEK_END) did not lie within the current ti - it is DIFFERENT than the semantics forblkdev_seek_hole_data, but gets normalized back into the expected-ENXIOanswer whendm_blk_do_seek_hole_datafinally advances past the last ti.
Quoted 8 lines
At any rate, I know this is an RFC series, but it goes to show that comments will be essential, whichever interface you decide for callbacks to honor (both a guarantee that callbacks will only ever see SEEK_HOLE/SEEK_DATA in bounds, because earlier points in the call stack have filtered out out-of-bounds and
SEEK_SET; and constraints on what the return value(s) must be for the various callbacks, especially if it is different from the eventual return value of the overall llseek syscall)
It's easier to understand the code when lseek function has the same semantics, so I'd rather not customize the semantics for certain lseek functions.
I'll make sure that the device-mapper targets match the dm_blk_seek_hole_data_default() behavior. To be honest, I relied on dm.c always passing offset values that are within the target, but that in itself is customizing the semantics :).
kernel test robot
build botRe: [RFC 6/9] dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) support
In reply to Stefan Hajnoczikernel test robot noticed the following build errors:
Hi Stefan,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on shuah-kselftest/next]
[also build test ERROR on shuah-kselftest/fixes device-mapper-dm/for-next axboe-block/for-next linus/master v6.9-rc1 next-20240328] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Stefan-Hajnoczi/block-add-llseek-SEEK_HOLE-SEEK_DATA-support/20240329-044334 base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next patch link: https://lore.kernel.org/r/20240328203910.2370087-7-stefanha%40redhat.com patch subject: [RFC 6/9] dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) support config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20240331/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240331/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-gbphy.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-gpio.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-i2c.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-pwm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-sdio.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-spi.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-uart.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/staging/greybus/gb-usb.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/platform/goldfish/goldfish_pipe.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/platform/chrome/cros_kunit_proto_test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mailbox/mtk-cmdq-mailbox.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_simpleondemand.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_performance.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_powersave.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_userspace.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/hwtracing/intel_th/intel_th_msu_sink.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem-apple-efuses.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem_brcm_nvram.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem_u-boot-env.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/interconnect/imx/imx-interconnect.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/interconnect/imx/imx8mm-interconnect.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/interconnect/imx/imx8mq-interconnect.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/interconnect/imx/imx8mn-interconnect.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/interconnect/imx/imx8mp-interconnect.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/hte/hte-tegra194-test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/vdpa/vdpa.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/parport/parport.o
WARNING: modpost: drivers/parport/parport_amiga: section mismatch in reference: amiga_parallel_driver+0x8 (section: .data) -> amiga_parallel_remove (section: .exit.text)
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mtd/parsers/brcm_u-boot.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mtd/parsers/tplink_safeloader.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mtd/chips/cfi_util.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mtd/chips/cfi_cmdset_0020.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/mtd/maps/map_funcs.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/spmi/hisi-spmi-controller.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/spmi/spmi-pmic-arb.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/uio/uio.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/uio/uio_pruss.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pcmcia/pcmcia_rsrc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/pcmcia/i82365.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/hwmon/corsair-cpro.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/hwmon/mr75203.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/vhost/vringh.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/greybus/greybus.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/greybus/gb-es2.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/rpmsg/rpmsg_char.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/iio/adc/ingenic-adc.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/iio/adc/xilinx-ams.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/iio/buffer/kfifo_buf.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-core.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-hub.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-aspeed.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-gpio.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-master-ast-cf.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/fsi/fsi-scom.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/siox/siox-bus-gpio.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/counter/ftm-quaddec.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/oss/dmasound/dmasound_core.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/oss/dmasound/dmasound_atari.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/oss/dmasound/dmasound_paula.o
WARNING: modpost: sound/oss/dmasound/dmasound_paula: section mismatch in reference: amiga_audio_driver+0x8 (section: .data) -> amiga_audio_remove (section: .exit.text)
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/core/snd-pcm-dmaengine.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/core/sound_kunit.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/drivers/snd-pcmtest.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/pci/hda/snd-hda-cirrus-scodec-test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/soc-topology-test.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/codecs/snd-soc-ab8500-codec.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/codecs/snd-soc-sigmadsp.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/codecs/snd-soc-wm-adsp.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/fsl/imx-pcm-dma.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/mxs/snd-soc-mxs-pcm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/qcom/snd-soc-qcom-common.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/qcom/snd-soc-qcom-sdw.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/qcom/qdsp6/snd-q6dsp-common.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/intel/snd-sof-intel-atom.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/intel/snd-sof-acpi-intel-byt.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/intel/snd-sof-acpi-intel-bdw.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/imx/snd-sof-imx8.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/imx/snd-sof-imx8m.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/imx/snd-sof-imx8ulp.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/imx/imx-common.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/mediatek/mtk-adsp-common.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/mediatek/mt8195/snd-sof-mt8195.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/mediatek/mt8186/snd-sof-mt8186.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/snd-sof-utils.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/snd-sof-acpi.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/sof/snd-sof-of.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/xilinx/snd-soc-xlnx-i2s.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/soc/xilinx/snd-soc-xlnx-formatter-pcm.o
WARNING: modpost: missing MODULE_DESCRIPTION() in sound/ac97_bus.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mtty.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mdpy.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mdpy-fb.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/vfio-mdev/mbochs.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/configfs/configfs_sample.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kfifo/bytestream-example.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kfifo/dma-example.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kfifo/inttype-example.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kfifo/record-example.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kobject/kobject-example.o
WARNING: modpost: missing MODULE_DESCRIPTION() in samples/kobject/kset-example.o
>> ERROR: modpost: "blkdev_seek_hole_data" [drivers/md/dm-mod.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [RFC 6/9] dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 118 lines · kernel test robot
Hi Stefan,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on shuah-kselftest/next]
[also build test ERROR on shuah-kselftest/fixes device-mapper-dm/for-next axboe-block/for-next linus/master v6.9-rc1 next-20240328] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Stefan-Hajnoczi/block-add-llseek-SEEK_HOLE-SEEK_DATA-support/20240329-044334 base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next patch link: https://lore.kernel.org/r/20240328203910.2370087-7-stefanha%40redhat.com patch subject: [RFC 6/9] dm-linear: add llseek(SEEK_HOLE/SEEK_DATA) support config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20240331/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240331/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>, old ones prefixed by <<):
WARNING: modpost: missing
MODULE_DESCRIPTION()indrivers/staging/greybus/gb-gbphy.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/staging/greybus/gb-gpio.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/staging/greybus/gb-i2c.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/staging/greybus/gb-pwm.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/staging/greybus/gb-sdio.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/staging/greybus/gb-spi.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/staging/greybus/gb-uart.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/staging/greybus/gb-usb.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/platform/goldfish/goldfish_pipe.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/platform/chrome/cros_kunit_proto_test.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/mailbox/mtk-cmdq-mailbox.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/devfreq/governor_simpleondemand.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/devfreq/governor_performance.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/devfreq/governor_powersave.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/devfreq/governor_userspace.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/hwtracing/intel_th/intel_th_msu_sink.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/nvmem/nvmem-apple-efuses.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/nvmem/nvmem_brcm_nvram.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/nvmem/nvmem_u-boot-env.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/interconnect/imx/imx-interconnect.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/interconnect/imx/imx8mm-interconnect.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/interconnect/imx/imx8mq-interconnect.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/interconnect/imx/imx8mn-interconnect.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/interconnect/imx/imx8mp-interconnect.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/hte/hte-tegra194-test.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/vdpa/vdpa.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/parport/parport.o
WARNING: modpost:drivers/parport/parport_amiga: section mismatch in reference:amiga_parallel_driver+0x8(section: .data) ->amiga_parallel_remove(section: .exit.text)
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/mtd/parsers/brcm_u-boot.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/mtd/parsers/tplink_safeloader.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/mtd/chips/cfi_util.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/mtd/chips/cfi_cmdset_0020.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/mtd/maps/map_funcs.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/spmi/hisi-spmi-controller.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/spmi/spmi-pmic-arb.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/uio/uio.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/uio/uio_pruss.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/pcmcia/pcmcia_rsrc.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/pcmcia/i82365.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/hwmon/corsair-cpro.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/hwmon/mr75203.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/vhost/vringh.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/greybus/greybus.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/greybus/gb-es2.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/rpmsg/rpmsg_char.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/iio/adc/ingenic-adc.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/iio/adc/xilinx-ams.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/iio/buffer/kfifo_buf.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/fsi/fsi-core.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/fsi/fsi-master-hub.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/fsi/fsi-master-aspeed.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/fsi/fsi-master-gpio.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/fsi/fsi-master-ast-cf.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/fsi/fsi-scom.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/siox/siox-bus-gpio.o
WARNING: modpost: missingMODULE_DESCRIPTION()indrivers/counter/ftm-quaddec.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/oss/dmasound/dmasound_core.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/oss/dmasound/dmasound_atari.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/oss/dmasound/dmasound_paula.o
WARNING: modpost:sound/oss/dmasound/dmasound_paula: section mismatch in reference:amiga_audio_driver+0x8(section: .data) ->amiga_audio_remove(section: .exit.text)
WARNING: modpost: missingMODULE_DESCRIPTION()insound/core/snd-pcm-dmaengine.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/core/sound_kunit.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/drivers/snd-pcmtest.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/pci/hda/snd-hda-cirrus-scodec-test.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/soc-topology-test.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/codecs/snd-soc-ab8500-codec.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/codecs/snd-soc-sigmadsp.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/codecs/snd-soc-wm-adsp.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/fsl/imx-pcm-dma.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/mxs/snd-soc-mxs-pcm.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/qcom/snd-soc-qcom-common.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/qcom/snd-soc-qcom-sdw.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/qcom/qdsp6/snd-q6dsp-common.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/intel/snd-sof-intel-atom.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/intel/snd-sof-acpi-intel-byt.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/intel/snd-sof-acpi-intel-bdw.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/imx/snd-sof-imx8.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/imx/snd-sof-imx8m.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/imx/snd-sof-imx8ulp.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/imx/imx-common.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/mediatek/mtk-adsp-common.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/mediatek/mt8195/snd-sof-mt8195.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/mediatek/mt8186/snd-sof-mt8186.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/snd-sof-utils.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/snd-sof-acpi.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/sof/snd-sof-of.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/xilinx/snd-soc-xlnx-i2s.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/soc/xilinx/snd-soc-xlnx-formatter-pcm.o
WARNING: modpost: missingMODULE_DESCRIPTION()insound/ac97_bus.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/vfio-mdev/mtty.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/vfio-mdev/mdpy.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/vfio-mdev/mdpy-fb.o
Quoted 9 lines
WARNING: modpost: missing
MODULE_DESCRIPTION()insamples/vfio-mdev/mbochs.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/configfs/configfs_sample.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/kfifo/bytestream-example.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/kfifo/dma-example.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/kfifo/inttype-example.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/kfifo/record-example.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/kobject/kobject-example.o
WARNING: modpost: missingMODULE_DESCRIPTION()insamples/kobject/kset-example.oQuoted 1 line
Quoted 1 line
ERROR: modpost: "
blkdev_seek_hole_data" [drivers/md/dm-mod.ko] undefined!
I think EXPORT_SYMBOL() is missing. I'll add that in the next revision.
Quoted 5 lines
Signature · 3 lines
-- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC 7/9 selftests: block_seek_hole: add dm-linear test
In reply to Stefan HajnocziThe dm-linear linear target passes through SEEK_HOLE/SEEK_DATA. Extend the test case to check that the same holes/data are reported as for the underlying file.
--- tools/testing/selftests/block_seek_hole/test.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
tools/testing/selftests/block_seek_hole/test.py +15 -1
@@ -45,6 +45,20 @@ def loop_device(file_path): finally: run(['losetup', '-d', loop_path]) +@contextmanager +def dm_linear(file_path): + file_size = os.path.getsize(file_path) + + with loop_device(file_path) as loop_path: + dm_name = f'test-{os.getpid()}' + run(['dmsetup', 'create', dm_name, '--table', + f'0 {file_size // 512} linear {loop_path} 0']) + + try: + yield f'/dev/mapper/{dm_name}' + finally: + run(['dmsetup', 'remove', dm_name]) + def test(layout, dev_context_manager): with test_file(layout) as file_path, dev_context_manager(file_path) as dev_path: cmd = run(['./map_holes.py', file_path])
@@ -99,5 +113,5 @@ if __name__ == '__main__': holes_at_beginning_and_end, no_holes, empty_file] - dev_context_managers = [loop_device] + dev_context_managers = [loop_device, dm_linear] test_all(layouts, dev_context_managers)
Signature · 1 line
2.44.0
Re: [RFC 7/9] selftests: block_seek_hole: add dm-linear test
Quoted 15 lines · Stefan Hajnoczi
The dm-linear linear target passes through SEEK_HOLE/SEEK_DATA. Extend the test case to check that the same holes/data are reported as for the underlying file.
Signed-off-by Stefan Hajnoczi <[email protected]>--- tools/testing/selftests/block_seek_hole/test.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)tools/testing/selftests/block_seek_hole/test.py +0
-0@@ -45,6 +45,20 @@ def loop_device(file_path): finally:
tools/testing/selftests/block_seek_hole/test.py def loop_device(file_path): · line 55
Quoted 10 lines
tools/testing/selftests/block_seek_hole/test.py +8
-0run(['losetup', '-d', loop_path]) +@contextmanager +def dm_linear(file_path): + file_size = os.path.getsize(file_path) + + with loop_device(file_path) as loop_path: + dm_name = f'test-{os.getpid()}' + run(['dmsetup', 'create', dm_name, '--table', + f'0 {file_size // 512} linear {loop_path} 0'])
Would it be worth tryiing to create the dm with two copies of loop_path concatenated one after the other? You'd have to do more work on expected output (coalescing adjacent data or holes between the tail of the first copy and the head of the second), but without that in place, I worry that you are missing logic bugs for when there is more than one table in the overall dm (as evidenced by my review in 4/9).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 7/9] selftests: block_seek_hole: add dm-linear test
Quoted 18 lines · Eric Blake
Quoted 17 lines · Stefan Hajnoczi
The dm-linear linear target passes through SEEK_HOLE/SEEK_DATA. Extend the test case to check that the same holes/data are reported as for the underlying file.
Signed-off-by Stefan Hajnoczi <[email protected]>--- tools/testing/selftests/block_seek_hole/test.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)tools/testing/selftests/block_seek_hole/test.py +0
-0@@ -45,6 +45,20 @@ def loop_device(file_path): finally: run(['losetup', '-d', loop_path])
Quoted 16 lines
tools/testing/selftests/block_seek_hole/test.py def loop_device(file_path): · line 55
Quoted 8 lines
tools/testing/selftests/block_seek_hole/test.py +8
-0+@contextmanager +def dm_linear(file_path): + file_size = os.path.getsize(file_path) + + with loop_device(file_path) as loop_path: + dm_name = f'test-{os.getpid()}' + run(['dmsetup', 'create', dm_name, '--table', + f'0 {file_size // 512} linear {loop_path} 0'])Would it be worth tryiing to create the dm with two copies of
loop_pathconcatenated one after the other? You'd have to do more work on expected output (coalescing adjacent data or holes between the tail of the first copy and the head of the second), but without that in place, I worry that you are missing logic bugs for when there is more than one table in the overall dm (as evidenced by my review in 4/9).
Yes, I agree that more tests are needed to cover transitions between adjacent targets.
Stefan
RFC 8/9 dm thin: add llseek(SEEK_HOLE/SEEK_DATA) support
In reply to Stefan Hajnoczi---
Open issues:
- Locking?
- thin_seek_hole_data() does not run as a bio or request. This patch assumes dm_thin_find_mapped_range() synchronously performs I/O if metadata needs to be loaded from disk. Is that a valid assumption?
--- drivers/md/dm-thin.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
drivers/md/dm-thin.c +77 -0
@@ -4501,6 +4501,82 @@ static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits) } } +static dm_block_t loff_to_block (struct pool *pool,loff_t offset) +{ +sector_t offset_sectors = offset >>SECTOR_SHIFT ; +dm_block_t ret; + +if (block_size_is_power_of_two (pool)) + ret = offset_sectors >> pool->sectors_per_block_shift; +else { + ret = offset_sectors; + (void )sector_div (ret, pool->sectors_per_block); + } + +return ret; +} + +static loff_t block_to_loff (struct pool *pool,dm_block_t block) +{ +return block_to_sectors (pool, block) <<SECTOR_SHIFT ; +} + +static loff_t thin_seek_hole_data (struct dm_target *ti,loff_t offset, +int whence) +{ +struct thin_c *tc = ti->private; +struct dm_thin_device *td = tc->td; +struct pool *pool = tc->pool; +dm_block_t begin; +dm_block_t end; +dm_block_t mapped_begin; +dm_block_t mapped_end; +dm_block_t pool_begin; +bool maybe_shared; +int ret; + +/* TODO locking? */ + +if (block_size_is_power_of_two (pool)) + end = ti->len >> pool->sectors_per_block_shift; +else { + end = ti->len; + (void )sector_div (end, pool->sectors_per_block); + } + + offset -= ti->begin <<SECTOR_SHIFT ; + +while (true) { + begin =loff_to_block (pool, offset); + ret =dm_thin_find_mapped_range (td, begin, end, + &mapped_begin, &mapped_end, + &pool_begin, &maybe_shared); +if (ret == -ENODATA ) { +if (whence ==SEEK_DATA ) +return -ENXIO ; +break ; + }else if (ret <0 ) { +/* TODO handle EWOULDBLOCK? */ +return -ENXIO ; + } + +/* SEEK_DATA finishes here... */ +if (whence ==SEEK_DATA ) { +if (mapped_begin != begin) + offset =block_to_loff (pool, mapped_begin); +break ; + } + +/* ...while SEEK_HOLE may need to look further */ +if (mapped_begin != begin) +break ;/* offset is in a hole */ + + offset =block_to_loff (pool, mapped_end); + } + +return offset + (ti->begin <<SECTOR_SHIFT ); +} +static struct target_type thin_target = { .name ="thin" , .version = {1 ,23 ,0 },
@@ -4515,6 +4591,7 @@ static struct target_type thin_target = { .status = thin_status, .iterate_devices = thin_iterate_devices, .io_hints = thin_io_hints, + .seek_hole_data = thin_seek_hole_data, };/*----------------------------------------------------------------*/
Signature · 1 line
2.44.0
Re: [RFC 8/9] dm thin: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 66 lines · Stefan Hajnoczi
Signed-off-by Stefan Hajnoczi <[email protected]>---
Open issues:
- Locking?
-thin_seek_hole_data()does not run as a bio or request. This patch assumesdm_thin_find_mapped_range()synchronously performs I/O if metadata needs to be loaded from disk. Is that a valid assumption?--- drivers/md/dm-thin.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)drivers/md/dm-thin.c +47
-0@@ -4501,6 +4501,82 @@ static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits) } } +static dm_block_t loff_to_block (struct pool *pool,loff_t offset) +{ +sector_t offset_sectors = offset >>SECTOR_SHIFT ; +dm_block_t ret; + +if (block_size_is_power_of_two (pool)) + ret = offset_sectors >> pool->sectors_per_block_shift; +else { + ret = offset_sectors; + (void )sector_div (ret, pool->sectors_per_block); + } + +return ret; +} + +static loff_t block_to_loff (struct pool *pool,dm_block_t block) +{ +return block_to_sectors (pool, block) <<SECTOR_SHIFT ; +} + +static loff_t thin_seek_hole_data (struct dm_target *ti,loff_t offset, +int whence) +{ +struct thin_c *tc = ti->private; +struct dm_thin_device *td = tc->td; +struct pool *pool = tc->pool; +dm_block_t begin; +dm_block_t end; +dm_block_t mapped_begin; +dm_block_t mapped_end; +dm_block_t pool_begin; +bool maybe_shared; +int ret; + +/* TODO locking? */ + +if (block_size_is_power_of_two (pool)) + end = ti->len >> pool->sectors_per_block_shift; +else { + end = ti->len; + (void )sector_div (end, pool->sectors_per_block); + } + + offset -= ti->begin <<SECTOR_SHIFT ; + +while (true) { + begin =loff_to_block (pool, offset);
drivers/md/dm-thin.c static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits) · line 4560
Quoted 10 lines
drivers/md/dm-thin.c +10
-0+ ret =dm_thin_find_mapped_range (td, begin, end, + &mapped_begin, &mapped_end, + &pool_begin, &maybe_shared); +if (ret == -ENODATA ) { +if (whence ==SEEK_DATA ) +return -ENXIO ; +break ; + }else if (ret <0 ) { +/* TODO handle EWOULDBLOCK? */ +return -ENXIO ;
This should probably be -EIO, not -ENXIO.
Quoted 7 lines
drivers/md/dm-thin.c +7
-0+ } + +/* SEEK_DATA finishes here... */ +if (whence ==SEEK_DATA ) { +if (mapped_begin != begin) + offset =block_to_loff (pool, mapped_begin); +break ;
drivers/md/dm-thin.c static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits) · line 4577
Quoted 10 lines
drivers/md/dm-thin.c +10
-0+ } + +/* ...while SEEK_HOLE may need to look further */ +if (mapped_begin != begin) +break ;/* offset is in a hole */ + + offset =block_to_loff (pool, mapped_end); + } + +return offset + (ti->begin <<SECTOR_SHIFT );
It's hard to follow, but I'm fairly certain that if whence == SEEK_HOLE, you end up returning ti->begin + ti->len instead of -ENXIO if the range from begin to end is fully mapped; which is inconsistent with the semantics you have in 4/9 (although in 6/9 I argue that having all of the dm callbacks return ti->begin + ti->len instead of -ENXIO might make logic easier for iterating through consecutive ti, and then convert to -ENXIO only in the caller).
Quoted 16 lines
drivers/md/dm-thin.c +3
-0+} +static struct target_type thin_target = { .name ="thin" , .version = {1 ,23 ,0 },@@ -4515,6 +4591,7 @@ static struct target_type thin_target = { .status = thin_status, .iterate_devices = thin_iterate_devices, .io_hints = thin_io_hints, + .seek_hole_data = thin_seek_hole_data, };/*----------------------------------------------------------------*/ Signature · 1 line
2.44.0
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Re: [RFC 8/9] dm thin: add llseek(SEEK_HOLE/SEEK_DATA) support
Quoted 71 lines · Eric Blake
Quoted 70 lines · Stefan Hajnoczi
Signed-off-by Stefan Hajnoczi <[email protected]>---
Open issues:
- Locking?
-thin_seek_hole_data()does not run as a bio or request. This patch assumesdm_thin_find_mapped_range()synchronously performs I/O if metadata needs to be loaded from disk. Is that a valid assumption?--- drivers/md/dm-thin.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)drivers/md/dm-thin.c +51
-0@@ -4501,6 +4501,82 @@ static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits) } } +static dm_block_t loff_to_block (struct pool *pool,loff_t offset) +{ +sector_t offset_sectors = offset >>SECTOR_SHIFT ; +dm_block_t ret; + +if (block_size_is_power_of_two (pool)) + ret = offset_sectors >> pool->sectors_per_block_shift; +else { + ret = offset_sectors; + (void )sector_div (ret, pool->sectors_per_block); + } + +return ret; +} + +static loff_t block_to_loff (struct pool *pool,dm_block_t block) +{ +return block_to_sectors (pool, block) <<SECTOR_SHIFT ; +} + +static loff_t thin_seek_hole_data (struct dm_target *ti,loff_t offset, +int whence) +{ +struct thin_c *tc = ti->private; +struct dm_thin_device *td = tc->td; +struct pool *pool = tc->pool; +dm_block_t begin; +dm_block_t end; +dm_block_t mapped_begin; +dm_block_t mapped_end; +dm_block_t pool_begin; +bool maybe_shared; +int ret; + +/* TODO locking? */ + +if (block_size_is_power_of_two (pool)) + end = ti->len >> pool->sectors_per_block_shift; +else { + end = ti->len; + (void )sector_div (end, pool->sectors_per_block); + } + + offset -= ti->begin <<SECTOR_SHIFT ; + +while (true) { + begin =loff_to_block (pool, offset); + ret =dm_thin_find_mapped_range (td, begin, end, + &mapped_begin, &mapped_end, + &pool_begin, &maybe_shared); +if (ret == -ENODATA ) {
Quoted 8 lines
drivers/md/dm-thin.c static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits) · line 4560
Quoted 6 lines
drivers/md/dm-thin.c +6
-0+if (whence ==SEEK_DATA ) +return -ENXIO ; +break ; + }else if (ret <0 ) { +/* TODO handle EWOULDBLOCK? */ +return -ENXIO ;This should probably be
-EIO, not-ENXIO.
Yes. XFS also returns -EIO, so I guess it's okay to do so.
I still need to get to the bottom of whether calling dm_thin_find_mapped_range() is sane here and what to do when/if it returns EWOULDBLOCK.
Quoted 18 lines
Quoted 7 lines
drivers/md/dm-thin.c +7
-0+ } + +/* SEEK_DATA finishes here... */ +if (whence ==SEEK_DATA ) { +if (mapped_begin != begin) + offset =block_to_loff (pool, mapped_begin); +break ;drivers/md/dm-thin.c static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits) · line 4577
Quoted 10 lines
drivers/md/dm-thin.c +10
-0+ } + +/* ...while SEEK_HOLE may need to look further */ +if (mapped_begin != begin) +break ;/* offset is in a hole */ + + offset =block_to_loff (pool, mapped_end); + } + +return offset + (ti->begin <<SECTOR_SHIFT );
Quoted 7 lines
It's hard to follow, but I'm fairly certain that if whence ==
SEEK_HOLE, you end up returningti->begin+ti->leninstead of-ENXIOif the range from begin to end is fully mapped; which is inconsistent with the semantics you have in 4/9 (although in 6/9 I argue that having all of the dm callbacks returnti->begin+ti->leninstead of-ENXIOmight make logic easier for iterating through consecutive ti, and then convert to-ENXIOonly in the caller).
Returning (ti->begin + ti->len) << SECTOR_SHIFT for SEEK_HOLE when there is data at the end of the target is intentional. This matches the semantics of lseek().
I agree there is adjustment necessary in dm.c, but I want to seek the semantics of all lseek() functions identical to avoid confusion.
Stefan
RFC 9/9 selftests: block_seek_hole: add dm-thin test
In reply to Stefan Hajnoczi--- .../selftests/block_seek_hole/Makefile | 2 +- .../selftests/block_seek_hole/dm_thin.sh | 80 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/block_seek_hole/dm_thin.sh
tools/testing/selftests/block_seek_hole/Makefile +1 -1
@@ -3,7 +3,7 @@ PY3 = $(shell which python3 2>/dev/null) ifneq ($(PY3),) -TEST_PROGS := test.py dm_zero.sh +TEST_PROGS := test.py dm_zero.sh dm_thin.sh include ../lib.mk
tools/testing/selftests/block_seek_hole/dm_thin.sh new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.44.0
Quoted 1 line · Stefan Hajnoczi
cp(1) and backup tools use
llseek(SEEK_HOLE/SEEK_DATA)to skip holes in files.
As a minor point of clarity (perhaps as much for my own records for documenting research I've done over the years, and not necessarily something you need to change in the commit message):
Userspace apps generally use lseek(2) from glibc or similar (perhaps via its alias lseek64(), depending on whether userspace is using large file offsets), rather than directly calling the _llseek() syscall. But it all boils down to the same notion of seeking information about various special offsets.
Also, in past history, coreutils cp(1) and dd(1) did experiment with using FS_IOC_FIEMAP ioctls when SEEK_HOLE was not available, but it proved to cause more problems than it solved, so that is not currently in favor. Yes, we could teach more and more block devices to expose specific ioctls for querying sparseness boundaries, and then teach userspace apps a list of ioctls to try; but as cp(1) already learned, having one common interface is much easier than an ever-growing ioctl ladder to be copied across every client that would benefit from knowing where the unallocated portions are.
Quoted 6 lines
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.
One of your open issues was whether adjusting the offset of the block device itself should also adjust the file offset of the underlying file (at least in the case of loopback and dm-linear). What would the community think of adding two additional constants to the entire family of *seek() functions, that have the effect of returning the same offset as their SEEK_HOLE/SEEK_DATA counterparts but without moving the file offset?
Explaining the idea by example, although I'm not stuck on these names:
suppose you have an fd visiting a file description of 2MiB in size, with the first 1MiB being a hole and the second being data.
#define MiB (1024*1024)lseek64(fd, MiB, SEEK_SET); // returns MiB, file offset changed to MiB lseek64(fd, 0, SEEK_HOLE); // returns 0, file offset changed to 0 lseek64(fd, 0, SEEK_DATA); // returns MiB, file offset changed to MiB lseek64(fd, 0, SEEK_PEEK_HOLE); // returns 0, but file offset left at MiB lseek64(fd, 0, SEEK_SET); // returns 0, file offset changed to MiB lseek64(fd, 0, SEEK_PEEK_DATA); // returns MiB, but file offset left at MiB
With semantics like that, it might be easier to implement just SEEK_PEEK* in devices (don't worry about changing offsets, just about reporting where the requested offset is), and then have a common layer do the translation from llseek(...,offs,SEEK_HOLE) into a 2-step llseek(...,llseek(...,offs,SEEK_PEEK_HOLE),SEEK_SET) if that makes life easier under the hood.
Quoted 4 lines
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.
BIG caveat here: the SCSI spec does not necessarily guarantee that unmapped regions read as all zeroes; compare the difference between FALLOC_FL_ZERO_RANGE and FALLOC_FL_PUNCH_HOLE. While lseek(SEEK_HOLE) on a regular file guarantees that future read() in that hole will see NUL bytes, I'm not sure whether we want to make that guarantee for block devices. This may be yet another case where we might want to add new SEEK_* constants to the *seek() family of functions that lets the caller indicate whether they want offsets that are guaranteed to read as zero, vs. merely offsets that are not allocated but may or may not read as zero. Skipping unallocated portions, even when you don't know if the contents reliably read as zero, is still a useful goal in some userspace programs.
Quoted 1 line
- NBD has
NBD_CMD_BLOCK_STATUSfor querying whether blocks are present.
However, utilizing it in nbd.ko would require teaching the kernel to handle structured or extended headers (right now, that is an extension only supported in user-space implementations of the NBD protocol). I can see why you did not tackle that in this RFC series, even though you mention it in the cover letter.
Quoted 72 lines
- 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_HOLEbut 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/5609With 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 structblock_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 provideseek_hole_data()callbacks.I'm unfamiliar with much of this code and have probably missed locking requirements. Since
llseek()executes synchronously likeioctl()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 duringllseek()?).To run the tests:
# make TARGETS=block_seek_hole -C tools/testing/selftests run_testsThe code is also available here:
https://gitlab.com/stefanha/linux/-/tree/block-seek-holePlease take a look and let me know your thoughts. Thanks!
Stefan Hajnoczi (9):
block: addllseek(SEEK_HOLE/SEEK_DATA)support
loop: addllseek(SEEK_HOLE/SEEK_DATA)support
selftests:block_seek_hole: add loop block driver tests
dm: addllseek(SEEK_HOLE/SEEK_DATA)support
selftests:block_seek_hole: add dm-zero test
dm-linear: addllseek(SEEK_HOLE/SEEK_DATA)support
selftests:block_seek_hole: add dm-linear test dm thin: addllseek(SEEK_HOLE/SEEK_DATA)support
selftests:block_seek_hole: add dm-thin testtools/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.pySignature · 1 line
2.44.0
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Replying to myself,
Quoted 8 lines · Eric Blake
Quoted 6 lines · Stefan Hajnoczi
cp(1) and backup tools use
llseek(SEEK_HOLE/SEEK_DATA)to skip holes in files.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.
Quoted 14 lines
BIG caveat here: the SCSI spec does not necessarily guarantee that unmapped regions read as all zeroes; compare the difference between
FALLOC_FL_ZERO_RANGEandFALLOC_FL_PUNCH_HOLE. Whilelseek(SEEK_HOLE)on a regular file guarantees that futureread()in that hole will see NUL bytes, I'm not sure whether we want to make that guarantee for block devices. This may be yet another case where we might want to add new SEEK_* constants to the*seek()family of functions that lets the caller indicate whether they want offsets that are guaranteed to read as zero, vs. merely offsets that are not allocated but may or may not read as zero. Skipping unallocated portions, even when you don't know if the contents reliably read as zero, is still a useful goal in some userspace programs.Quoted 1 line
- NBD has
NBD_CMD_BLOCK_STATUSfor querying whether blocks are present.
The upstream NBD spec[1] took the time to represent two bits of information per extent, _because_ of the knowledge that not all SCSI devices with TRIM support actually guarantee a read of zeroes after trimming. That is, NBD chose to convey both:
NBD_STATE_HOLE: 1<<0 if region is unallocated, 0 if region has not been trimmedNBD_STATE_ZERO: 1<<1 if region reads as zeroes, 0 if region contents might be nonzero
it is always safe to describe an extent as value 0 (both bits clear), whether or not lseek(SEEK_DATA) returns the same offset; meanwhile, traditional lseek(SEEK_HOLE) on filesystems generally translates to a status of 3 (both bits set), but as it is (sometimes) possible to determine that allocated data still reads as zero, or that unallocated data may not necessarily read as zero, it is also possible to implement NBD servers that don't report both bits in parallel.
If we are going to enhance llseek(2) to expose more information about underlying block devices, possibly by adding more SEEK_ constants for use in the entire family of *seek() API, it may be worth thinking about whether it is worth userspace being able to query this additional distinction between unallocated vs reads-as-zero.
[1] https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md#baseallocation-metadata-context
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Quoted 11 lines · Eric Blake
Quoted 6 lines · Stefan Hajnoczi
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.One of your open issues was whether adjusting the offset of the block device itself should also adjust the file offset of the underlying file (at least in the case of loopback and dm-linear). What would the
Only the loop block driver has this issue. The dm-linear driver uses blkdev_seek_hole_data(), which does not update the file offset because it operates on a struct block_device instead of a struct file.
Quoted 6 lines
Quoted 5 lines
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.
Quoted 12 lines
BIG caveat here: the SCSI spec does not necessarily guarantee that unmapped regions read as all zeroes; compare the difference between
FALLOC_FL_ZERO_RANGEandFALLOC_FL_PUNCH_HOLE. Whilelseek(SEEK_HOLE)on a regular file guarantees that futureread()in that hole will see NUL bytes, I'm not sure whether we want to make that guarantee for block devices. This may be yet another case where we might want to add new SEEK_* constants to the*seek()family of functions that lets the caller indicate whether they want offsets that are guaranteed to read as zero, vs. merely offsets that are not allocated but may or may not read as zero. Skipping unallocated portions, even when you don't know if the contents reliably read as zero, is still a useful goal in some userspace programs.
SCSI initiators can check the Logical Block Provisioning Read Zeroes (LBPRZ) field to determine whether or not zeroes are guaranteed. The sd driver would only rely on the device when LPBRZ indicates that zeroes will be read. Otherwise the driver would report that the device is filled with data.
Quoted 8 lines
Quoted 2 lines
- NBD has
NBD_CMD_BLOCK_STATUSfor querying whether blocks are present.However, utilizing it in nbd.ko would require teaching the kernel to handle structured or extended headers (right now, that is an extension only supported in user-space implementations of the NBD protocol). I can see why you did not tackle that in this RFC series, even though you mention it in the cover letter.
Yes, I'm mostly interested in dm-thin. The loop block driver and dm-linear are useful for testing so I modified them. I didn't try SCSI or NBD.
Thanks,
Stefan
Quoted 3 lines · Stefan Hajnoczi
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.
But for SCSI (and ATA and NVMe) unmapped/delallocated/etc blocks do not have to return zeroes. They could also return some other initialization pattern pattern. So they are (unfortunately) not a 1:1 mapping to holes in sparse files.
Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Stefan Hajnoczi
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.But for SCSI (and ATA and NVMe) unmapped/delallocated/etc blocks do not have to return zeroes. They could also return some other initialization pattern pattern. So they are (unfortunately) not a 1:1 mapping to holes in sparse files.
Hi Christoph,
There is a 1:1 mapping when when the Logical Block Provisioning Read Zeroes (LBPRZ) field is set to xx1b in the Logical Block Provisioning VPD page.
Otherwise SEEK_HOLE/SEEK_DATA has to treat the device as filled with data because it doesn't know where the holes are.
Stefan
Quoted 4 lines · Stefan Hajnoczi
Hi Christoph,
There is a 1:1 mapping when when the Logical Block Provisioning Read Zeroes (LBPRZ) field is set to xx1b in the Logical Block Provisioning VPD page.
Yes. NVMe also has a similar field, but ATA does not.
Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Stefan Hajnoczi
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.But for SCSI (and ATA and NVMe) unmapped/delallocated/etc blocks do not have to return zeroes. They could also return some other initialization pattern pattern. So they are (unfortunately) not a 1:1 mapping to holes in sparse files.
Yes, and Stefan already answered that:
Quoted 5 lines
Quoted 5 lines
SCSI initiators can check the Logical Block Provisioning Read Zeroes (LBPRZ) field to determine whether or not zeroes are guaranteed. The sd driver would only rely on the device when LPBRZ indicates that zeroes will be read. Otherwise the driver would report that the device is filled with data.
As well as my question on whether the community would be open to introducing new SEEK_* constants to allow orthogonality between searching for zeroes (known to read as zero, whether or not it was allocated) vs. sparseness (known to be unallocated, whether or not it reads as zero), where the existing SEEK_HOLE seeks for both properties at once.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Quoted 6 lines · Eric Blake
As well as my question on whether the community would be open to introducing new SEEK_* constants to allow orthogonality between searching for zeroes (known to read as zero, whether or not it was allocated) vs. sparseness (known to be unallocated, whether or not it reads as zero), where the existing
SEEK_HOLEseeks for both properties at once.
That seems like quite an effort. Is is worth it?