summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2023-01-09 10:34:15 +0000
committerZorro Lang <zlang@kernel.org>2023-01-14 21:43:44 +0800
commitfde636203ffdc796f4044234f83700c8d160a8ad (patch)
tree6bacbcdeac3074fd2f6cf6cb1c6752d62d9fb24a /src
parent2151aae2e0382bd8843cc22fc726b3ffc7fb4426 (diff)
generic: test lseek with seek data mode on a one byte file
Test that seeking for data on a 1 byte file works correctly, the returned offset should be 0 if the start offset is 0. This is a regression test motivated by a btrfs bug introduced in kernel 6.1, which got recently fixed by the following kernel commit: 2f2e84ca6066 ("btrfs: fix off-by-one in delalloc search during lseek") Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Disseldorp <ddiss@suse.de> Signed-off-by: Zorro Lang <zlang@kernel.org>
Diffstat (limited to 'src')
-rw-r--r--src/seek_sanity_test.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c
index 8a586f74..48b3ccc0 100644
--- a/src/seek_sanity_test.c
+++ b/src/seek_sanity_test.c
@@ -293,6 +293,41 @@ out:
}
/*
+ * Test seeking for data on a 1 byte file, both when there's delalloc and also
+ * after delalloc is flushed.
+ */
+static int test22(int fd, int testnum)
+{
+ const char buf = 'X';
+ int ret;
+
+ ret = do_pwrite(fd, &buf, 1, 0);
+ if (ret)
+ return ret;
+
+ /*
+ * Our file as a size of 1 byte and that byte is in delalloc. Seeking
+ * for data, with a start offset of 0, should return file offset 0.
+ */
+ ret = do_lseek(testnum, 1, fd, 1, SEEK_DATA, 0, 0);
+ if (ret)
+ return ret;
+
+ /* Flush all delalloc. */
+ ret = fsync(fd);
+ if (ret) {
+ fprintf(stderr, "fsync failed: %s (%d)\n", strerror(errno), errno);
+ return ret;
+ }
+
+ /*
+ * We should get the same result we got when we had delalloc, 0 is the
+ * offset with data.
+ */
+ return do_lseek(testnum, 2, fd, 1, SEEK_DATA, 0, 0);
+}
+
+/*
* Make sure hole size is properly reported when punched in the middle of a file
*/
static int test21(int fd, int testnum)
@@ -1131,6 +1166,7 @@ struct testrec seek_tests[] = {
{ 19, test19, "Test file SEEK_DATA from middle of a large hole" },
{ 20, test20, "Test file SEEK_DATA from middle of a huge hole" },
{ 21, test21, "Test file SEEK_HOLE that was created by PUNCH_HOLE" },
+ { 22, test22, "Test a 1 byte file" },
};
static int run_test(struct testrec *tr)