XFS TESTS: Add Punch Hole to FSX
PATCH v3 1/3 XFS TESTS: Add Punch Hole to FSX
This patch adds punch hole tests to the fsx stress test. The test is performed through the fallocate call by randomly choosing to use the punch hole flag when running the fallocate test. Regions that have
been punched out should contain zeros, so the expected file contents buffer is updated to contain zeros when a hole is punched out.
---
v0 -> v1:
Corrections to the Makefile have been backed out. This patch needs to be applied on top of
the "xfstests: clean up fallocate configuration tests" patch
The punch hole tests can be disabled with the -H flag, and will also be disabled if it is detected that the filesystem does not support punch hole
:100644 100644 fe072d3... 8978ef1... M ltp/fsx.c
ltp/fsx.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 96 insertions(+), 15 deletions(-)
ltp/fsx.c +96 -15
@@ -110,6 +110,7 @@ int randomoplen = 1; /* -O flag disables it */int seed =1 ;/* -S flag */ int mapped_writes =1 ;/* -W flag disables */ int fallocate_calls =1 ;/* -F flag disables */ +int punch_hole_calls =1 ;/* -H flag disables */ int mapped_reads =1 ;/* -R flag disables it */ int fsxgoodfd =0 ;int o_direct;/* -Z */
@@ -207,7 +208,8 @@ logdump(void) {int i, count, down;struct log_entry *lp; -char *falloc_type[3 ] = {"PAST_EOF" ,"EXTENDING" ,"INTERIOR" }; +char *falloc_type[4 ] = {"PAST_EOF" ,"EXTENDING" ,"INTERIOR" , +"PUNCH_HOLE" };prt ("LOG DUMP (%d total operations):\n" , logcount);if (logcount <LOGSIZE ) {
@@ -791,6 +793,11 @@ dofallocate(unsigned offset, unsigned length) {unsigned end_offset;int keep_size; +int max_offset =0 ; +int max_len =0 ; +int mode =0 ; +char *op_name; +int punch_hole =0 ;if (length ==0 ) {if (!quiet && testcalls > simulatedopcount)
@@ -799,11 +806,37 @@ dofallocate(unsigned offset, unsigned length)return ; } +#ifdef FALLOC_FL_PUNCH_HOLE +if (fallocate_calls && !punch_hole_calls) + punch_hole =0 ; +else if (!fallocate_calls && punch_hole_calls) + punch_hole =1 ; +else + punch_hole =random () %2 ; + +/* Keep size must be set for punch hole */ +if (punch_hole) { + keep_size =1 ; + mode =FALLOC_FL_PUNCH_HOLE ; + }else + keep_size =random () %2 ; +#else keep_size =random () %2 ; +#endif + +if (keep_size) + mode |=FALLOC_FL_KEEP_SIZE ; + +if (punch_hole && file_size <= (loff_t )offset) { +if (!quiet && testcalls > simulatedopcount) +prt ("skipping hole punch off the end of the file\n" ); +log4 (OP_SKIPPED ,OP_FALLOCATE , offset, length); +return ; + } end_offset = keep_size ?0 : offset + length; -if (end_offset > biggest) { +if ((end_offset > biggest) && !punch_hole) { biggest = end_offset;if (!quiet && testcalls > simulatedopcount)prt ("fallocating to largest ever: 0x%x\n" , end_offset);
@@ -811,13 +844,15 @@ dofallocate(unsigned offset, unsigned length)/* * last arg: -* 1: allocate past EOF -* 2: extending prealloc -* 3: interior prealloc +* 0: allocate past EOF +* 1: extending prealloc +* 2: interior prealloc +* 3: punch hole */ -log4 (OP_FALLOCATE , offset, length, (end_offset > file_size) ? (keep_size ?1 :2 ) :3 ); +log4 (OP_FALLOCATE , offset, length, punch_hole ?3 : + (end_offset > file_size) ? (keep_size ?0 :1 ) :2 ); -if (end_offset > file_size) { +if (((loff_t )end_offset > file_size) && !punch_hole) {memset (good_buf + file_size,'\0' , end_offset - file_size); file_size = end_offset; }
@@ -827,13 +862,35 @@ dofallocate(unsigned offset, unsigned length)if ((progressinterval && testcalls % progressinterval ==0 ) || (debug && (monitorstart ==-1 || monitorend ==-1 || - end_offset <= monitorend))) -prt ("%lu falloc\tfrom 0x%x to 0x%x\n" , testcalls, offset, length); -if (fallocate (fd, keep_size ?FALLOC_FL_KEEP_SIZE :0 , (loff_t )offset, (loff_t )length) ==-1 ) { -prt ("fallocate: %x to %x\n" , offset, length); + end_offset <= monitorend))) { +#ifdef FALLOC_FL_PUNCH_HOLE + op_name = (mode &FALLOC_FL_PUNCH_HOLE ) ? +"punch hole" :"falloc" ; +#else + op_name ="falloc" ; +#endif +prt ("%lu %s\tfrom 0x%x to 0x%x, (0x%x bytes)\n" , testcalls, + op_name, offset, offset+length, length); + } +if (fallocate (fd, mode, (loff_t )offset, (loff_t )length) ==-1 ) { +#ifdef FALLOC_FL_PUNCH_HOLE + op_name = (mode &FALLOC_FL_PUNCH_HOLE ) ? +"punch hole" :"fallocate" ; +#else + op_name ="fallocate" ; +#endif + +prt ("%s: %x to %x\n" , op_name, offset, length);prterr ("dofallocate: fallocate" );report_failure (161 ); } + +if (punch_hole) { + max_offset = offset < file_size ? offset : file_size; + max_len = max_offset + length <= file_size ? length : + file_size - max_offset; +memset (good_buf + max_offset,'\0' , max_len); + } }#else void
@@ -895,8 +952,8 @@ test(void)unsigned long offset;unsigned long size = maxoplen;unsigned long rv =random (); -unsigned long op = rv % (3 + !lite + mapped_writes + fallocate_calls); - +unsigned long op = rv % (3 + !lite + mapped_writes + + (fallocate_calls || punch_hole_calls));/* turn off the map read if necessary */ if (op ==2 && !mapped_reads)
@@ -1013,6 +1070,9 @@ usage(void)#ifdef FALLOCATE " -F: Do not use fallocate (preallocation) calls\n"#endif +#ifdef FALLOC_FL_PUNCH_HOLE +" -H: Do not use punch hole calls\n" +#endif" -L: fsxLite - no file creations & no file size changes\n\ -N numops: total # operations to do (default infinity)\n\ -O: use oplen (see -o flag) for every op (default random)\n\
@@ -1179,7 +1239,7 @@ main(int argc, char **argv)setvbuf (stdout, (char *)0 , _IOLBF,0 );/* line buffered stdout */ -while ((ch =getopt (argc, argv,"b:c:dfl:m:no:p:qr:s:t:w:xyAD:FLN:OP:RS:WZ" )) +while ((ch =getopt (argc, argv,"b:c:dfl:m:no:p:qr:s:t:w:xyAD:FHLN:OP:RS:WZ" )) !=EOF )switch (ch) {case 'b' :
@@ -1276,6 +1336,9 @@ main(int argc, char **argv)case 'F' : fallocate_calls =0 ;break ; +case 'H' : + punch_hole_calls =0 ; +break ;case 'L' : lite =1 ;break ;
@@ -1426,8 +1489,26 @@ main(int argc, char **argv)if (fallocate (fd,0 ,0 ,1 ) && errno ==EOPNOTSUPP ) {warn ("main: filesystem does not support fallocate, disabling" ); fallocate_calls =0 ; - }else +/* +* punch hole depends on fallocate, +* so turn punch hole off too +*/ + punch_hole_calls =0 ; + }else { +#ifdef FALLOC_FL_PUNCH_HOLE +if (fallocate (fd, +FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE , +0 ,1 ) && errno ==EOPNOTSUPP ) { +warn ("main: filesystem does not support" +" fallocate punch hole, disabling" ); + punch_hole_calls =0 ; + } +#else + punch_hole_calls =0 ; +#endif +ftruncate (fd,0 ); + } }#else /* ! FALLOCATE */ fallocate_calls =0 ;
Signature · 1 line
1.7.1
Quoted 72 lines · Allison Henderson
This patch adds punch hole tests to the fsx stress test. The test is performed through the fallocate call by randomly choosing to use the punch hole flag when running the fallocate test. Regions that have
been punched out should contain zeros, so the expected file contents buffer is updated to contain zeros when a hole is punched out.Signed-off-by Allison Henderson <[email protected]>---
v0 -> v1:
Corrections to theMakefilehave been backed out. This patch needs to be applied on top of
the "xfstests: clean up fallocate configuration tests" patchThe punch hole tests can be disabled with the -H flag, and will also be disabled if it is detected that the filesystem does not support punch hole
:100644 100644 fe072d3... 8978ef1... M
ltp/fsx.cltp/fsx.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 96 insertions(+), 15 deletions(-)ltp/fsx.c +15
-1@@ -110,6 +110,7 @@ int randomoplen = 1; /* -O flag disables it */int seed =1 ;/* -S flag */ int mapped_writes =1 ;/* -W flag disables */ int fallocate_calls =1 ;/* -F flag disables */ +int punch_hole_calls =1 ;/* -H flag disables */ int mapped_reads =1 ;/* -R flag disables it */ int fsxgoodfd =0 ;int o_direct;/* -Z */ @@ -207,7 +208,8 @@ logdump(void) {int i, count, down;struct log_entry *lp; -char *falloc_type[3 ] = {"PAST_EOF" ,"EXTENDING" ,"INTERIOR" }; +char *falloc_type[4 ] = {"PAST_EOF" ,"EXTENDING" ,"INTERIOR" , +"PUNCH_HOLE" };prt ("LOG DUMP (%d total operations):\n" , logcount);if (logcount <LOGSIZE ) {@@ -791,6 +793,11 @@ dofallocate(unsigned offset, unsigned length) {unsigned end_offset;int keep_size; +int max_offset =0 ; +int max_len =0 ; +int mode =0 ; +char *op_name; +int punch_hole =0 ;if (length ==0 ) {if (!quiet && testcalls > simulatedopcount)@@ -799,11 +806,37 @@ dofallocate(unsigned offset, unsigned length)return ; } +#ifdef FALLOC_FL_PUNCH_HOLE +if (fallocate_calls && !punch_hole_calls) + punch_hole =0 ; +else if (!fallocate_calls && punch_hole_calls) + punch_hole =1 ; +else + punch_hole =random () %2 ;
ltp/fsx.c dofallocate(unsigned offset, unsigned length) · line 825
Quoted 10 lines
ltp/fsx.c +9
-0+ +/* Keep size must be set for punch hole */ +if (punch_hole) { + keep_size =1 ; + mode =FALLOC_FL_PUNCH_HOLE ; + }else + keep_size =random () %2 ; +#else keep_size =random () %2 ; +#endif
Ugh. Can you please separate hole punching out into it's own function? i.e. do_fallocate() gets renamed to do_preallocate(), and this new functionality goes into do_hole_punch()? The fact that they both use the fallocate() system call is no reason for complicating the logic like this....
Quoted 18 lines
ltp/fsx.c +13
-1@@ -1426,8 +1489,26 @@ main(int argc, char **argv)if (fallocate (fd,0 ,0 ,1 ) && errno ==EOPNOTSUPP ) {warn ("main: filesystem does not support fallocate, disabling" ); fallocate_calls =0 ; - }else +/* +* punch hole depends on fallocate, +* so turn punch hole off too +*/ + punch_hole_calls =0 ; + }else { +#ifdef FALLOC_FL_PUNCH_HOLE +if (fallocate (fd, +FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE , +0 ,1 ) && errno ==EOPNOTSUPP ) { +warn ("main: filesystem does not support" +" fallocate punch hole, disabling" ); + punch_hole_calls =0 ;
ltp/fsx.c main(int argc, char **argv) · line 1514
Quoted 10 lines
ltp/fsx.c +6
-0+ } +#else + punch_hole_calls =0 ; +#endif +ftruncate (fd,0 ); + } }#else /* ! FALLOCATE */ fallocate_calls =0 ;
And these functionality tests would probably be better in their own function, too.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]