fio icon indicating copy to clipboard operation
fio copied to clipboard

Fix: parse.c opt_len() to use minimal distance to delimiter to determine option length

Open leonid-kozlov opened this issue 6 months ago • 4 comments

Use minimal distance to delimiter to determine option length

Current implementation of opt_len() function is using array of possible delimiters for option name search. They are {',', ':'}.

The loop at https://github.com/axboe/fio/blob/813445e7129240d51216e396a5ba8e19296b6581/parse.c#L484 takes first found delimiter and return without trying to search by the rest of possibilities.

This causes __handle_option() function to falsely include into option name all chars up to first ',' ignoring any ':' chars. Resulting not possible to parse options like zoned:50/5:30/15:20/,50/10:50/90.

Fixes: https://github.com/axboe/fio/issues/1923

Signed-off-by: Leonid Kozlov [email protected]

leonid-kozlov avatar Jun 18 '25 08:06 leonid-kozlov

Tested by running following options:

  • with multiple zones as in example: ./fio --debug=parse --parse-only --random_distribution=zoned:50/5:30/15:20/,50/10:50/90
fio: set debug option parse
parse    190666 handle_option=random_distribution, ptr=zoned:50/5:30/15:20/,50/10:50/90
parse    190666 __handle_option=random_distribution, type=OPT_STR, ptr=zoned:50/5:30/15:20/,50/10:50/90
parse    190666 zone ddir 0 (nr=3): 
parse    190666         0: 50/5
parse    190666         1: 30/15
parse    190666         2: 20/80
parse    190666 zone ddir 1 (nr=2): 
parse    190666         0: 50/10
parse    190666         1: 50/90
parse    190666 zone ddir 2 (nr=2): 
parse    190666         0: 50/10
parse    190666         1: 50/90
parse    190666 free options
parse    190666 free options
  • with only one zone: ./fio --debug=parse --parse-only --random_distribution=zoned:50/5:30/15:20/
fio: set debug option parse
parse    191537 handle_option=random_distribution, ptr=zoned:50/5:30/15:20/
parse    191537 __handle_option=random_distribution, type=OPT_STR, ptr=zoned:50/5:30/15:20/
parse    191537 zone ddir 0 (nr=3): 
parse    191537         0: 50/5
parse    191537         1: 30/15
parse    191537         2: 20/80
parse    191537 zone ddir 1 (nr=3): 
parse    191537         0: 50/5
parse    191537         1: 30/15
parse    191537         2: 20/80
parse    191537 zone ddir 2 (nr=3): 
parse    191537         0: 50/5
parse    191537         1: 30/15
parse    191537         2: 20/80
parse    191537 free options
parse    191537 free options
  • with all 3 zones: ./fio --debug=parse --parse-only --random_distribution=zoned:50/5:30/15:20/,50/10:50/90,10/20:10/20:10/20:70/
fio: set debug option parse
parse    190843 handle_option=random_distribution, ptr=zoned:50/5:30/15:20/,50/10:50/90,10/20:10/20:10/20:70/
parse    190843 __handle_option=random_distribution, type=OPT_STR, ptr=zoned:50/5:30/15:20/,50/10:50/90,10/20:10/20:10/20:70/
parse    190843 zone ddir 0 (nr=3): 
parse    190843         0: 50/5
parse    190843         1: 30/15
parse    190843         2: 20/80
parse    190843 zone ddir 1 (nr=2): 
parse    190843         0: 50/10
parse    190843         1: 50/90
parse    190843 zone ddir 2 (nr=4): 
parse    190843         0: 10/20
parse    190843         1: 10/20
parse    190843         2: 10/20
parse    190843         3: 70/40
parse    190843 free options
parse    190843 free options
  • with same options as in https://github.com/axboe/fio/pull/1307 : ./fio --debug=parse --parse-only --sync_file_range=wait_before,write:8
fio: set debug option parse
parse    190946 handle_option=sync_file_range, ptr=wait_before,write:8
parse    190946 __handle_option=sync_file_range, type=OPT_STR_MULTI, ptr=wait_before,write:8
parse    190946 __handle_option=sync_file_range, type=OPT_STR_MULTI, ptr=write:8
parse    190946 free options
parse    190946 free options
  • with regular options: ./fio --debug=parse --parse-only --rw=randrw --rwmixread=65 --bssplit=8k/5:32k/10:64k/15:128k/60:256k:10
fio: set debug option parse
parse    191232 handle_option=rw, ptr=randrw
parse    191232 __handle_option=rw, type=OPT_STR, ptr=randrw
parse    191232 handle_option=rwmixread, ptr=65
parse    191232 __handle_option=rwmixread, type=OPT_INT, ptr=65
parse    191232   ret=0, out=65
parse    191232 handle_option=bssplit, ptr=8k/5:32k/10:64k/15:128k/60:256k:10
parse    191232 __handle_option=bssplit, type=OPT_STR_ULL, ptr=8k/5:32k/10:64k/15:128k/60:256k:10
parse    191232 free options
parse    191232 free options

leonid-kozlov avatar Jun 18 '25 08:06 leonid-kozlov

(Please don't worry about the Windows build failures. It looks like Cygwin now provides functions for nanosleep and clock_gettime (when it didn't in the past) so we'll have to think about how to test for those such that we only provide the fallbacks if they aren't implemented. nanosleep will be easy enough but clock_gettime will be trickier)

sitsofe avatar Jun 18 '25 15:06 sitsofe

Unnecessary commits are squashed and commit message cleaned

leonid-kozlov avatar Jun 19 '25 14:06 leonid-kozlov

Fixed commit signature

leonid-kozlov avatar Jun 19 '25 23:06 leonid-kozlov

Thanks to @leonid-kozlov for the fix and to @sitsofe for reviewing!

vincentkfu avatar Jun 23 '25 18:06 vincentkfu