* [PATCH] src/seek_sanity_test: Fix for filesystems without unwritten extent support
@ 2017-06-23 13:32 Andreas Gruenbacher
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Gruenbacher @ 2017-06-23 13:32 UTC (permalink / raw)
To: fstests, 'Eryu Guan '; +Cc: Andreas Gruenbacher
src/seek_sanity_test assumes that after preallocating space in a file
with fallocate, fseek SEEK_HOLE / SEEK_DATA will still report the
allocated space as a hole. On filesystems without unwritten extent
support, that space will be reported as data, though. On such
filesystems, skip the unwritten extent tests.
Tested on ext4, xfs, and gfs2 + patches for fseek SEEK_HOLE / SEEK_DATA
support.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
src/seek_sanity_test.c | 130 ++++++++++++++++++++++++++-----------------------
1 file changed, 69 insertions(+), 61 deletions(-)
diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c
index 95984b6..a58ec36 100644
--- a/src/seek_sanity_test.c
+++ b/src/seek_sanity_test.c
@@ -37,6 +37,7 @@
static blksize_t alloc_size;
int default_behavior = 0;
+int unwritten_extents = 0;
char *base_file_path;
static void get_file_system(int fd)
@@ -128,13 +129,9 @@ static int do_fallocate(int fd, off_t offset, off_t length, int mode)
int ret;
ret = fallocate(fd, mode, offset, length);
- if (ret) {
- /* Don't warn about a filesystem w/o fallocate support */
- if (errno == EOPNOTSUPP)
- return ret;
+ if (ret)
fprintf(stderr, " ERROR %d: Failed to preallocate "
"space to %ld bytes\n", errno, (long) length);
- }
return ret;
}
@@ -284,6 +281,11 @@ static int test17(int fd, int testnum)
int bufsz, filsz;
int ret = 0;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
if (pagesz < 4 * alloc_size) {
fprintf(stdout, "Test skipped as page size (%d) is less than "
"four times allocation size (%d).\n",
@@ -301,14 +303,8 @@ static int test17(int fd, int testnum)
memset(buf, 'a', bufsz);
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
@@ -355,6 +351,11 @@ static int test16(int fd, int testnum)
int bufsz = sysconf(_SC_PAGE_SIZE);
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
@@ -364,14 +365,8 @@ static int test16(int fd, int testnum)
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
@@ -406,6 +401,11 @@ static int test15(int fd, int testnum)
int bufsz = sysconf(_SC_PAGE_SIZE);
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
@@ -415,14 +415,8 @@ static int test15(int fd, int testnum)
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
@@ -459,6 +453,11 @@ static int test14(int fd, int testnum)
int bufsz = sysconf(_SC_PAGE_SIZE) * 14;
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
@@ -468,14 +467,8 @@ static int test14(int fd, int testnum)
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
@@ -509,6 +502,11 @@ static int test13(int fd, int testnum)
int bufsz = sysconf(_SC_PAGE_SIZE) * 14;
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
@@ -518,14 +516,8 @@ static int test13(int fd, int testnum)
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
@@ -579,6 +571,11 @@ static int test09(int fd, int testnum)
int bufsz = alloc_size;
int filsz = bufsz * 100 + bufsz;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/*
* HOLE - unwritten DATA in dirty page - HOLE -
* unwritten DATA in writeback page
@@ -592,14 +589,8 @@ static int test09(int fd, int testnum)
/* preallocate 8M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, bufsz * 10);
if (!ret) {
@@ -635,6 +626,11 @@ static int test08(int fd, int testnum)
int bufsz = alloc_size;
int filsz = bufsz * 10 + bufsz;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in writeback page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
@@ -644,14 +640,8 @@ static int test08(int fd, int testnum)
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, bufsz * 10);
if (ret)
@@ -684,6 +674,11 @@ static int test07(int fd, int testnum)
int bufsz = alloc_size;
int filsz = bufsz * 10 + bufsz;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
@@ -693,14 +688,8 @@ static int test07(int fd, int testnum)
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, bufsz * 10);
if (ret)
@@ -1050,6 +1039,25 @@ static int test_basic_support(void)
fprintf(stderr, "File system supports the default behavior.\n");
}
+ ftruncate(fd, 0);
+ if (fallocate(fd, 0, 0, alloc_size) == -1) {
+ if (errno == EOPNOTSUPP)
+ fprintf(stderr, "File system does not support fallocate.");
+ else {
+ fprintf(stderr, "ERROR %d: Failed to preallocate "
+ "space to %ld bytes. Aborting.\n", errno, (long) alloc_size);
+ ret = -1;
+ }
+ goto out;
+ }
+
+ pos = lseek(fd, 0, SEEK_DATA);
+ if (pos == 0) {
+ fprintf(stderr, "File system does not support unwritten extents.\n");
+ goto out;
+ }
+ unwritten_extents = 1;
+
printf("\n");
out:
--
2.7.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] src/seek_sanity_test: Fix for filesystems without unwritten extent support
2017-05-12 5:09 ` Eryu Guan
@ 2017-06-23 13:30 ` Andreas Gruenbacher
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Gruenbacher @ 2017-06-23 13:30 UTC (permalink / raw)
To: Eryu Guan; +Cc: fstests
On Fri, May 12, 2017 at 7:09 AM, Eryu Guan <eguan@redhat.com> wrote:
> On Thu, May 11, 2017 at 01:35:07PM +0200, Andreas Gruenbacher wrote:
>> src/seek_sanity_test (test generic/285) assumes that after preallocating
>> space in a file with fallocate, fseek SEEK_HOLE / SEEK_DATA will still
>> report the allocated space as a hole. On filesystems without unwritten
>> extent support, that space will be reported as data, though.
>>
>> Tested on ext4, xfs, and gfs2 + patches for fseek SEEK_HOLE / SEEK_DATA
>> support.
>
> The idea seems fine to me, but I'm not that familiar with SEEK_DATA/HOLE
> support, it'd be great if someone else could help review this patch.
>
> Some of my thoughts inline.
>
>>
>> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
>> ---
>> src/seek_sanity_test.c | 35 +++++++++++++++++++++++++++++++++++
>> 1 file changed, 35 insertions(+)
>>
>> diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c
>> index a6dd48c..0d7fa0a 100644
>> --- a/src/seek_sanity_test.c
>> +++ b/src/seek_sanity_test.c
>> @@ -37,6 +37,7 @@
>>
>> static blksize_t alloc_size;
>> int default_behavior = 0;
>> +int unwritten_extents = 0;
>> char *base_file_path;
>>
>> static void get_file_system(int fd)
>> @@ -282,6 +283,11 @@ static int test09(int fd, int testnum)
>> int bufsz = alloc_size;
>> int filsz = 8 << 20;
>>
>> + if (!unwritten_extents) {
>> + fprintf(stdout, "Test skipped\n");
>> + goto out;
>> + }
>> +
>> /*
>> * HOLE - unwritten DATA in dirty page - HOLE -
>> * unwritten DATA in writeback page
>> @@ -338,6 +344,11 @@ static int test08(int fd, int testnum)
>> int bufsz = alloc_size;
>> int filsz = 4 << 20;
>>
>> + if (!unwritten_extents) {
>> + fprintf(stdout, "Test skipped\n");
>> + goto out;
>> + }
>> +
>> /* HOLE - unwritten DATA in writeback page */
>> /* Each unit is bufsz */
>> buf = do_malloc(bufsz);
>> @@ -387,6 +398,11 @@ static int test07(int fd, int testnum)
>> int bufsz = alloc_size;
>> int filsz = 4 << 20;
>>
>> + if (!unwritten_extents) {
>> + fprintf(stdout, "Test skipped\n");
>> + goto out;
>> + }
>> +
>> /* HOLE - unwritten DATA in dirty page */
>> /* Each unit is bufsz */
>> buf = do_malloc(bufsz);
>> @@ -776,6 +792,25 @@ static int test_basic_support(void)
>> fprintf(stderr, "File system supports the default behavior.\n");
>> }
>>
>> + ftruncate(fd, 0);
>> + if (fallocate(fd, 0, 0, alloc_size) == -1) {
>> + if (errno == EOPNOTSUPP) {
>> + fprintf(stderr, "File system does not support fallocate.");
>> + } else {
>> + fprintf(stderr, "ERROR %d: Failed to preallocate "
>> + "space to %ld bytes.", errno, (long) alloc_size);
>> + }
>
> Use do_fallocate here? It already did the EOPNOTSUPP check. And
> introduce another flag, e.g. prealloc, to save the fallocate support
> status? So that test0[7-9] don't have to do the EOPNOTSUPP check again.
In fact unwritten extent support implies fallocate support, so we can
get rid of the redundant checks for missing fallocate support.
>> + fprintf(stderr, " Skipping unwritten extent tests.\n");
>> + goto out;
>> + } else {
>> + pos = lseek(fd, 0, SEEK_DATA);
>
> Hmm, it's hard to tell if it's a bug in lseek or the fs doesn't support
> unwritten extents, because we're going to test lseek SEEK_DATA/HOLE
> interface.
>
> How about using fiemap and check the FIEMAP_EXTENT_UNWRITTEN flag? Only
> falling back to lseek if fiemap is not supported?
Wouldn't this only complicate and open things up to fiemap bugs in addition?
I'll send an updated patch.
Thanks,
Andreas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] src/seek_sanity_test: Fix for filesystems without unwritten extent support
2017-05-11 11:35 Andreas Gruenbacher
@ 2017-05-12 5:09 ` Eryu Guan
2017-06-23 13:30 ` Andreas Gruenbacher
0 siblings, 1 reply; 4+ messages in thread
From: Eryu Guan @ 2017-05-12 5:09 UTC (permalink / raw)
To: Andreas Gruenbacher; +Cc: fstests
On Thu, May 11, 2017 at 01:35:07PM +0200, Andreas Gruenbacher wrote:
> src/seek_sanity_test (test generic/285) assumes that after preallocating
> space in a file with fallocate, fseek SEEK_HOLE / SEEK_DATA will still
> report the allocated space as a hole. On filesystems without unwritten
> extent support, that space will be reported as data, though.
>
> Tested on ext4, xfs, and gfs2 + patches for fseek SEEK_HOLE / SEEK_DATA
> support.
The idea seems fine to me, but I'm not that familiar with SEEK_DATA/HOLE
support, it'd be great if someone else could help review this patch.
Some of my thoughts inline.
>
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> ---
> src/seek_sanity_test.c | 35 +++++++++++++++++++++++++++++++++++
> 1 file changed, 35 insertions(+)
>
> diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c
> index a6dd48c..0d7fa0a 100644
> --- a/src/seek_sanity_test.c
> +++ b/src/seek_sanity_test.c
> @@ -37,6 +37,7 @@
>
> static blksize_t alloc_size;
> int default_behavior = 0;
> +int unwritten_extents = 0;
> char *base_file_path;
>
> static void get_file_system(int fd)
> @@ -282,6 +283,11 @@ static int test09(int fd, int testnum)
> int bufsz = alloc_size;
> int filsz = 8 << 20;
>
> + if (!unwritten_extents) {
> + fprintf(stdout, "Test skipped\n");
> + goto out;
> + }
> +
> /*
> * HOLE - unwritten DATA in dirty page - HOLE -
> * unwritten DATA in writeback page
> @@ -338,6 +344,11 @@ static int test08(int fd, int testnum)
> int bufsz = alloc_size;
> int filsz = 4 << 20;
>
> + if (!unwritten_extents) {
> + fprintf(stdout, "Test skipped\n");
> + goto out;
> + }
> +
> /* HOLE - unwritten DATA in writeback page */
> /* Each unit is bufsz */
> buf = do_malloc(bufsz);
> @@ -387,6 +398,11 @@ static int test07(int fd, int testnum)
> int bufsz = alloc_size;
> int filsz = 4 << 20;
>
> + if (!unwritten_extents) {
> + fprintf(stdout, "Test skipped\n");
> + goto out;
> + }
> +
> /* HOLE - unwritten DATA in dirty page */
> /* Each unit is bufsz */
> buf = do_malloc(bufsz);
> @@ -776,6 +792,25 @@ static int test_basic_support(void)
> fprintf(stderr, "File system supports the default behavior.\n");
> }
>
> + ftruncate(fd, 0);
> + if (fallocate(fd, 0, 0, alloc_size) == -1) {
> + if (errno == EOPNOTSUPP) {
> + fprintf(stderr, "File system does not support fallocate.");
> + } else {
> + fprintf(stderr, "ERROR %d: Failed to preallocate "
> + "space to %ld bytes.", errno, (long) alloc_size);
> + }
Use do_fallocate here? It already did the EOPNOTSUPP check. And
introduce another flag, e.g. prealloc, to save the fallocate support
status? So that test0[7-9] don't have to do the EOPNOTSUPP check again.
> + fprintf(stderr, " Skipping unwritten extent tests.\n");
> + goto out;
> + } else {
> + pos = lseek(fd, 0, SEEK_DATA);
Hmm, it's hard to tell if it's a bug in lseek or the fs doesn't support
unwritten extents, because we're going to test lseek SEEK_DATA/HOLE
interface.
How about using fiemap and check the FIEMAP_EXTENT_UNWRITTEN flag? Only
falling back to lseek if fiemap is not supported?
Thanks,
Eryu
> + if (pos == 0) {
> + fprintf(stderr, "File system does not support unwritten extents.\n");
> + goto out;
> + }
> + }
> + unwritten_extents = 1;
> +
> printf("\n");
>
> out:
> --
> 2.7.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] src/seek_sanity_test: Fix for filesystems without unwritten extent support
@ 2017-05-11 11:35 Andreas Gruenbacher
2017-05-12 5:09 ` Eryu Guan
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Gruenbacher @ 2017-05-11 11:35 UTC (permalink / raw)
To: fstests; +Cc: Andreas Gruenbacher
src/seek_sanity_test (test generic/285) assumes that after preallocating
space in a file with fallocate, fseek SEEK_HOLE / SEEK_DATA will still
report the allocated space as a hole. On filesystems without unwritten
extent support, that space will be reported as data, though.
Tested on ext4, xfs, and gfs2 + patches for fseek SEEK_HOLE / SEEK_DATA
support.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
src/seek_sanity_test.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c
index a6dd48c..0d7fa0a 100644
--- a/src/seek_sanity_test.c
+++ b/src/seek_sanity_test.c
@@ -37,6 +37,7 @@
static blksize_t alloc_size;
int default_behavior = 0;
+int unwritten_extents = 0;
char *base_file_path;
static void get_file_system(int fd)
@@ -282,6 +283,11 @@ static int test09(int fd, int testnum)
int bufsz = alloc_size;
int filsz = 8 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped\n");
+ goto out;
+ }
+
/*
* HOLE - unwritten DATA in dirty page - HOLE -
* unwritten DATA in writeback page
@@ -338,6 +344,11 @@ static int test08(int fd, int testnum)
int bufsz = alloc_size;
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in writeback page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
@@ -387,6 +398,11 @@ static int test07(int fd, int testnum)
int bufsz = alloc_size;
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
@@ -776,6 +792,25 @@ static int test_basic_support(void)
fprintf(stderr, "File system supports the default behavior.\n");
}
+ ftruncate(fd, 0);
+ if (fallocate(fd, 0, 0, alloc_size) == -1) {
+ if (errno == EOPNOTSUPP) {
+ fprintf(stderr, "File system does not support fallocate.");
+ } else {
+ fprintf(stderr, "ERROR %d: Failed to preallocate "
+ "space to %ld bytes.", errno, (long) alloc_size);
+ }
+ fprintf(stderr, " Skipping unwritten extent tests.\n");
+ goto out;
+ } else {
+ pos = lseek(fd, 0, SEEK_DATA);
+ if (pos == 0) {
+ fprintf(stderr, "File system does not support unwritten extents.\n");
+ goto out;
+ }
+ }
+ unwritten_extents = 1;
+
printf("\n");
out:
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-06-23 13:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-23 13:32 [PATCH] src/seek_sanity_test: Fix for filesystems without unwritten extent support Andreas Gruenbacher
-- strict thread matches above, loose matches on Subject: below --
2017-05-11 11:35 Andreas Gruenbacher
2017-05-12 5:09 ` Eryu Guan
2017-06-23 13:30 ` Andreas Gruenbacher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.