fstests: introduce MKFS_BCACHEFS_PROG for bcachefs
PATCH v2 1/2 fstests: introduce MKFS_BCACHEFS_PROG for bcachefs
mkfs.bcachefs supports force overwrite when option '-f' is given:
$ mkfs.bcachefs --help | grep force -f, --force
There are some tests which call _scratch_mkfs multiple times e.g. tests/generic/171. Without '-f' in MKFS_OPTIONS, these tests just hang in overwrite confirmation. After this commit, MKFS_BCACHEFS_PROG will contains ' -f' so we don't have to add '-f' to MKFS_OPTIONS manually to make these tests pass.
It also fixes generic/466 which unsets MKFS_OPTIONS causing that test hangs in mfks.bcachefs waiting for confirmation of the force overwrite.
---
changelog:
v2:
Add more details about why MKFS_BCACHEFS_PROG should contain '-f'.
--- common/config | 3 ++- common/rc | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-)
common/config +2 -1
@@ -105,7 +105,7 @@ set_mkfs_prog_path_with_opts() # Note: mkfs.f2fs doesn't support the --help option yet, but it doesn't # matter since it also prints the help when an invalid option is given. if [ "$p" != "" ] && \ - $p --help |& grep -q "[[:space:]]-f[[:space:]|]"; then + $p --help |& grep -q "[[:space:]]-f[[:space:]|,]"; then echo "$p -f" else echo $p
@@ -313,6 +313,7 @@ export MKFS_REISER4_PROG=$(type -P mkfs.reiser4) export E2FSCK_PROG=$(type -P e2fsck) export TUNE2FS_PROG=$(type -P tune2fs) export FSCK_OVERLAY_PROG=$(type -P fsck.overlay) +export MKFS_BCACHEFS_PROG=$(set_mkfs_prog_path_with_opts bcachefs) # SELinux adds extra xattrs which can mess up our expected output. # So, mount with a context, and they won't be created.
common/rc +9 -3
@@ -611,6 +611,9 @@ _test_mkfs() xfs) $MKFS_PROG -t $FSTYP -- -f $MKFS_OPTIONS $* $TEST_DEV ;; + bcachefs) + $MKFS_BCACHEFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null + ;; *) yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV ;;
@@ -753,6 +756,10 @@ _scratch_mkfs() mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --" mkfs_filter="grep -v -e ^mkfs\.ocfs2" ;; + bcachefs) + mkfs_cmd="$MKFS_BCACHEFS_PROG" + mkfs_filter="cat" + ;; *) mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --" mkfs_filter="cat"
@@ -1044,7 +1051,7 @@ _scratch_mkfs_sized() export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS" ;; bcachefs) - $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS --fs_size=$fssize --block_size=$blocksize $SCRATCH_DEV + $MKFS_BCACHEFS_PROG $MKFS_OPTIONS --fs_size=$fssize --block_size=$blocksize $SCRATCH_DEV ;; *) _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
@@ -1128,8 +1135,7 @@ _scratch_mkfs_blocksized() -C $blocksize $SCRATCH_DEV ;; bcachefs) - ${MKFS_PROG} -t $FSTYP $MKFS_OPTIONS --block_size=$blocksize \ - $SCRATCH_DEV + _scratch_mkfs --block_size=$blocksize ;; udf) _scratch_mkfs -b $blocksize
Signature · 1 line
2.43.0
PATCH v2 2/2 common/rc: improve block size support for bcachefs
For bcachefs, def_blksz is never assigned even MKFS_OPTIONS contains option '--block_size'. So block size of bcachefs on scratch dev is always 4096 if _scratch_mkfs_sized is called without second parameter.
Add the pattern to set def_blksz if '--block_size' is given in MKFS_OPTIONS.
---
changelog:
v2:
Born.
--- common/rc | 3 +++ 1 file changed, 3 insertions(+)
common/rc +3 -0
@@ -950,6 +950,9 @@ _scratch_mkfs_sized() jfs) def_blksz=4096 ;; + bcachefs) + def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*(--block_size)[ =]?+([0-9]+).*/\2/p'` + ;; esac [ -n "$def_blksz" ] && blocksize=$def_blksz
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] common/rc: improve block size support for bcachefs
Quoted 20 lines · Su Yue
For bcachefs,
def_blkszis never assigned evenMKFS_OPTIONScontains option '--block_size'. So block size of bcachefs on scratch dev is always 4096 if_scratch_mkfs_sizedis called without second parameter.Add the pattern to set
def_blkszif '--block_size' is given inMKFS_OPTIONS.Signed-off-by Su Yue <[email protected]>---
changelog:
v2:
Born.--- common/rc | 3 +++ 1 file changed, 3 insertions(+)common/rc +0
-0
common/rc _scratch_mkfs_sized() · line 955
Quoted 6 lines
common/rc +3
-0@@ -950,6 +950,9 @@ _scratch_mkfs_sized() jfs) def_blksz=4096 ;; + bcachefs) + def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*(--block_size)[ =]?+([0-9]+).*/\2/p'` + ;;
So if the default bcachefs block size is 512b, I wonder if this should do something like what the udf branch does a few lines above and override the hardcoded default of 4k. ISTM this whole thing would be more robust if it just elided the param in the default cases and let the associated mkfs tool use its own default, but that's probably a separate issue. Hm?
Brian
Quoted 6 lines
common/rc +0
-0esac [ -n "$def_blksz" ] && blocksize=$def_blkszSignature · 1 line
2.43.0
Re: [PATCH v2 2/2] common/rc: improve block size support for bcachefs
Quoted 16 lines · Brian Foster
Quoted 15 lines · Su Yue
For bcachefs,
def_blkszis never assigned evenMKFS_OPTIONScontains option '--block_size'. So block size of bcachefs on scratch dev is always 4096 if_scratch_mkfs_sizedis called without second parameter.Add the pattern to set
def_blkszif '--block_size' is given inMKFS_OPTIONS.Signed-off-by Su Yue <[email protected]>---
changelog:
v2:
Born.--- common/rc | 3 +++ 1 file changed, 3 insertions(+)
Quoted 16 lines
common/rc _scratch_mkfs_sized() · line 955
Quoted 12 lines
common/rc +2
-0@@ -950,6 +950,9 @@ _scratch_mkfs_sized() jfs) def_blksz=4096 ;; + bcachefs) + def_blksz=`echo $MKFS_OPTIONS | sed -rn's/.*(--block_size)[ =]?+([0-9]+).*/\2/p'`
common/rc +1
-0+ ;;So if the default bcachefs block size is 512b, I wonder if this should do something like what the udf branch does a few lines above and
mkfs.bcachefs decides block size by querying statbuf.st_blksize or BLKPBSZGET from the device if the option is not given.
Quoted 5 lines
override the hardcoded default of 4k. ISTM this whole thing would be more robust if it just elided the param in the default cases and let the associated mkfs tool use its own default, but that's probably a separate issue. Hm?
Since there is no default block size of bcachefs, maybe we can let mkfs.bcachefs decide on its own but it will make chaos when somebody reports an unreproducible BUG due to the different block_size even we have same local.config. It just happened...
So for now, I think 4096 is a resonable value of bcachefs block size.
--
Su
Quoted 9 lines
Brian
Quoted 6 lines
common/rc +0
-1esac [ -n "$def_blksz" ] && blocksize=$def_blksz --2.43.0
Re: [PATCH v2 2/2] common/rc: improve block size support for bcachefs
Quoted 46 lines · Su Yue
Quoted 19 lines · Brian Foster
Quoted 18 lines · Su Yue
For bcachefs,
def_blkszis never assigned evenMKFS_OPTIONScontains option
'--block_size'. So block size of bcachefs on scratch dev is always 4096
if_scratch_mkfs_sizedis called without second parameter.Add the pattern to set
def_blkszif '--block_size' is given inMKFS_OPTIONS.Signed-off-by Su Yue <[email protected]>---
changelog:
v2:
Born.--- common/rc | 3 +++ 1 file changed, 3 insertions(+)Quoted 16 lines
common/rc _scratch_mkfs_sized() · line 955
Quoted 12 lines
common/rc +2
-0@@ -950,6 +950,9 @@ _scratch_mkfs_sized() jfs) def_blksz=4096 ;; + bcachefs) + def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*(--block_size)[=]?+([0-9]+).*/\2/p'`
common/rc +1
-0+ ;;So if the default bcachefs block size is 512b, I wonder if this should do something like what the udf branch does a few lines above and
mkfs.bcachefs decides block size by querying statbuf.st_blksize or BLKPBSZGET from the device if the option is not given.
Quoted 5 lines
override the hardcoded default of 4k. ISTM this whole thing would be more robust if it just elided the param in the default cases and let the associated mkfs tool use its own default, but that's probably a separate issue. Hm?
Quoted 6 lines
Since there is no default block size of bcachefs, maybe we can let mkfs.bcachefs decide on its own but it will make chaos when somebody reports an unreproducible BUG due to the different
block_sizeeven we have same local.config. It just happened...
So for now, I think 4096 is a resonable value of bcachefs block size.
I think we run into this no matter what if we pick a size out of a hat, regardless of what the value is. If somebody is testing with default blocksize (i.e. based on mkfs) on a filesystem where the default isn't actually 4k, then it seems quite unexpected that _scratch_mkfs_sized would use something different from _scratch_mkfs when a block size isn't explicitly specified. That's exactly the situation we ran into with the generic/361 thing where I would have expected this test to use 512b blocks.
ISTM that the 4k value in _scratch_mkfs_sized() is mainly a last resort default value so the $blocks calculation can work for any filesystem that might not be properly supported by the function. The function looks a little wonky overall, but I think there are at least a couple options to improve things for bcachefs. FWIW, it also looks to me that nothing actually passes a blocksize param to _scratch_mkfs_sized, so perhaps we could just drop that blocksize=$2 parameter across the board as a simplification?
With that, I think bcache could either:
1. Do something like def_blksize=blockdev --getpbsz $SCRATCH_DEV in the first switch if no block size is specified in MKFS_OPTIONS (or whatever best mimics mkfs logic).
OR
2. Do something like the following in the last switch:
[ -n $def_blksize ] && def_blksize="--block_size=$def_blksize" $MKFS_BCACHEFS_PROG ... $def_blksize $SCRATCH_DEV
... to allow mkfs to determine the block size. I _think_ that works because the bcachefs format doesn't depend on $blocks at all, so whatever $blocksize was set to is irrelevent unless $def_blksize was set above, but I could be missing something. That also assumes blocksize wasn't set to something by the caller.
If correct, option #2 seems a little cleaner to me, but other thoughts/ideas?
Brian
Quoted 12 lines
--
SuQuoted 9 lines
Brian
Quoted 6 lines
common/rc +0
-1esac [ -n "$def_blksz" ] && blocksize=$def_blksz --2.43.0
Re: [PATCH v2 2/2] common/rc: improve block size support for bcachefs
Quoted 64 lines · Brian Foster
Quoted 47 lines · Su Yue
Quoted 19 lines · Brian Foster
Quoted 18 lines · Su Yue
For bcachefs,
def_blkszis never assigned evenMKFS_OPTIONScontains option
'--block_size'. So block size of bcachefs on scratch dev is always 4096
if_scratch_mkfs_sizedis called without second parameter.Add the pattern to set
def_blkszif '--block_size' is given inMKFS_OPTIONS.Signed-off-by Su Yue <[email protected]>---
changelog:
v2:
Born.--- common/rc | 3 +++ 1 file changed, 3 insertions(+)Quoted 17 lines
common/rc _scratch_mkfs_sized() · line 955
Quoted 13 lines
common/rc +2
-0@@ -950,6 +950,9 @@ _scratch_mkfs_sized() jfs) def_blksz=4096 ;; + bcachefs) + def_blksz=`echo $MKFS_OPTIONS | sed -rn's/.*(--block_size)[
=]?+([0-9]+).*/\2/p'`common/rc +1
-0+ ;;So if the default bcachefs block size is 512b, I wonder if this should do something like what the udf branch does a few lines above and
mkfs.bcachefs decides block size by querying statbuf.st_blksize or BLKPBSZGET from the device if the option is not given.
Quoted 5 lines
override the hardcoded default of 4k. ISTM this whole thing would be more robust if it just elided the param in the default cases and let the associated mkfs tool use its own default, but that's probably a separate issue. Hm?
Quoted 6 lines
Since there is no default block size of bcachefs, maybe we can let mkfs.bcachefs decide on its own but it will make chaos when somebody reports an unreproducible BUG due to the different
block_sizeeven we have same local.config. It just happened...
So for now, I think 4096 is a resonable value of bcachefs block size.I think we run into this no matter what if we pick a size out of a hat, regardless of what the value is. If somebody is testing with default blocksize (i.e. based on mkfs) on a filesystem where the default isn't actually 4k, then it seems quite unexpected that
_scratch_mkfs_sizedwould use something different from_scratch_mkfswhen a block size isn't explicitly specified. That's exactly the situation we ran into with the generic/361 thing where I would have expected this test to use 512b blocks.
Quoted 9 lines
ISTM that the 4k value in
_scratch_mkfs_sized()is mainly a last resort default value so the $blocks calculation can work for any filesystem that might not be properly supported by the function. The function looks a little wonky overall, but I think there are at least a couple options to improve things for bcachefs. FWIW, it also looks to me that nothing actually passes a blocksize param to_scratch_mkfs_sized, so perhaps we could just drop that blocksize=$2 parameter across the board as a simplification?
Maybe it can be dropped. The only user is generic/466
Quoted 13 lines
With that, I think bcache could either:
1. Do something like def_blksize=
blockdev --getpbsz $SCRATCH_DEVin the first switch if no block size is specified inMKFS_OPTIONS(or whatever best mimics mkfs logic).OR
2. Do something like the following in the last switch:
[ -n $def_blksize ] && def_blksize="--block_size=$def_blksize" $MKFS_BCACHEFS_PROG ... $def_blksize $SCRATCH_DEV
Quoted 9 lines
... to allow mkfs to determine the block size. I _think_ that works because the bcachefs format doesn't depend on $blocks at all, so whatever $blocksize was set to is irrelevent unless $def_blksize was set above, but I could be missing something. That also assumes blocksize wasn't set to something by the caller.
If correct, option #2 seems a little cleaner to me, but other thoughts/ideas?
Option 2 is preferable. I would code it as(on more varaiable for readability):
local blocksize_opt
[ -n $def_blksize ] && blockzie_opt="--block_size=$def_blksize" $MKFS_BCACHEFS_PROG ... $blocksize_opt $SCRATCH_DEV
--
Su
Quoted 15 lines
Brian
Quoted 12 lines
--
SuQuoted 9 lines
Brian
Quoted 6 lines
common/rc +0
-1esac [ -n "$def_blksz" ] && blocksize=$def_blksz --2.43.0
Re: [PATCH v2 2/2] common/rc: improve block size support for bcachefs
Quoted 85 lines · Su Yue
Quoted 73 lines · Brian Foster
Quoted 53 lines · Su Yue
Quoted 2 lines · Brian Foster
Quoted 1 line · Su Yue
For bcachefs,
def_blkszis never assigned evenMKFS_OPTIONS> >contains
Quoted 2 lines
Quoted 2 lines
option
'--block_size'. So block size of bcachefs on scratch dev is > >always
Quoted 4 lines
Quoted 4 lines
4096
if_scratch_mkfs_sizedis called without second parameter.Add the pattern to set
def_blkszif '--block_size' is given > >in
Quoted 11 lines
Quoted 11 lines
MKFS_OPTIONS.Signed-off-by Su Yue <[email protected]>---
changelog:
v2:
Born.--- common/rc | 3 +++ 1 file changed, 3 insertions(+)Quoted 10 lines
common/rc _scratch_mkfs_sized() · line 954
Quoted 10 lines
common/rc +2
-0@@ -950,6 +950,9 @@ _scratch_mkfs_sized() jfs) def_blksz=4096 ;; + bcachefs) + def_blksz=`echo $MKFS_OPTIONS | sed -rn > >'s/.*(--block_size)[
Quoted 4 lines
common/rc _scratch_mkfs_sized() · line 955
Quoted 2 lines
=]?+([0-9]+).*/\2/p'`
common/rc +1
-0+ ;;So if the default bcachefs block size is 512b, I wonder if > this
should
Quoted 2 lines
do something like what the udf branch does a few lines above > and
mkfs.bcachefs decides block size by querying statbuf.st_blksize or BLKPBSZGET from the device if the option is not given.
Quoted 1 line
override the hardcoded default of 4k. ISTM this whole thing >
would be
Quoted 1 line
more robust if it just elided the param in the default cases > and
let the
Quoted 1 line
associated mkfs tool use its own default, but that's probably > a
separate
Quoted 9 lines
Quoted 2 lines
issue. Hm?
Since there is no default block size of bcachefs, maybe we can let mkfs.bcachefs decide on its own but it will make chaos when somebody reports an unreproducible BUG due to the different
block_sizeeven we have same local.config. It just happened...
So for now, I think 4096 is a resonable value of bcachefs block size.I think we run into this no matter what if we pick a size out of a hat, regardless of what the value is. If somebody is testing with default blocksize (i.e. based on mkfs) on a filesystem where the default isn't actually 4k, then it seems quite unexpected that
_scratch_mkfs_sizedwould use something different from_scratch_mkfswhen a block size isn't explicitly specified. That's exactly the situation we ran into with the generic/361 thing where I would have expected this test to use 512b blocks.Quoted 9 lines
ISTM that the 4k value in
_scratch_mkfs_sized()is mainly a last resort default value so the $blocks calculation can work for any filesystem that might not be properly supported by the function. The function looks a little wonky overall, but I think there are at least a couple options to improve things for bcachefs. FWIW, it also looks to me that nothing actually passes a blocksize param to_scratch_mkfs_sized, so perhaps we could just drop that blocksize=$2 parameter across the board as a simplification?
Quoted 2 lines
Maybe it can be dropped. The only user is generic/466
Ah, good point.
So generic/466 clears MKFS_OPTIONS so the function will use the provided block size over whatever exists in the config, yet generic/466 is the only user of this param in the first place.
I wonder if a more useful change might be to change the _scratch_mkfs_sized logic to prefer the provided block size over whatever is in the config, but then again that might require further changes for any of the places that continue to use MKFS_OPTIONS. :/
Quoted 22 lines
Quoted 13 lines
With that, I think bcache could either:
1. Do something like def_blksize=
blockdev --getpbsz $SCRATCH_DEVin the first switch if no block size is specified inMKFS_OPTIONS(or whatever best mimics mkfs logic).OR
2. Do something like the following in the last switch:
[ -n $def_blksize ] && def_blksize="--block_size=$def_blksize" $MKFS_BCACHEFS_PROG ... $def_blksize $SCRATCH_DEVQuoted 9 lines
... to allow mkfs to determine the block size. I _think_ that works because the bcachefs format doesn't depend on $blocks at all, so whatever $blocksize was set to is irrelevent unless $def_blksize was set above, but I could be missing something. That also assumes blocksize wasn't set to something by the caller.
If correct, option #2 seems a little cleaner to me, but other thoughts/ideas?
Quoted 8 lines
Option 2 is preferable. I would code it as(on more varaiable for readability):
local
blocksize_opt[ -n $def_blksize ] && blockzie_opt="--block_size=$def_blksize" $MKFS_BCACHEFS_PROG ... $blocksize_opt $SCRATCH_DEV
That seems reasonable to me. The only caveat is this was assuming the blocksize param would go away and so could be ignored for bcachefs.
Without getting too far into the weeds on the higher level parameter handling, I wonder if the blocksize parameter was initially put into a separate variable (i.e. blocksize_param or some such), if that would at least help bcachefs determine between the case where 4096 was requested by the caller vs. picked out of a hat by the default handling logic earlier in the function, and thus correctly determine when to set a blocksize vs. use the mkfs (non-4k) default.
So then IOW the logic might look something like this..?
[ -n $blocksize_param ] && blocksize_opt="--block_size=$blocksize_param" [ -n $def_blksize ] && blocksize_opt="--block_size=$def_blksize" mkfs ...
Brian
Quoted 18 lines
--
SuQuoted 15 lines
Brian
Quoted 12 lines
--
SuQuoted 9 lines
Brian
Quoted 6 lines
common/rc +0
-1esac [ -n "$def_blksz" ] && blocksize=$def_blksz --2.43.0
Re: [PATCH v2 2/2] common/rc: improve block size support for bcachefs
Quoted 86 lines · Brian Foster
Quoted 85 lines · Su Yue
Quoted 82 lines · Brian Foster
Quoted 53 lines · Su Yue
Quoted 2 lines · Brian Foster
Quoted 1 line · Su Yue
For bcachefs,
def_blkszis never assigned evenMKFS_OPTIONS> >contains
Quoted 2 lines
Quoted 2 lines
option
'--block_size'. So block size of bcachefs on scratch dev is > >always
Quoted 4 lines
Quoted 4 lines
4096
if_scratch_mkfs_sizedis called without second parameter.Add the pattern to set
def_blkszif '--block_size' is given > >in
Quoted 11 lines
Quoted 11 lines
MKFS_OPTIONS.Signed-off-by Su Yue <[email protected]>---
changelog:
v2:
Born.--- common/rc | 3 +++ 1 file changed, 3 insertions(+)Quoted 10 lines
common/rc _scratch_mkfs_sized() · line 954
Quoted 10 lines
common/rc +2
-0@@ -950,6 +950,9 @@ _scratch_mkfs_sized() jfs) def_blksz=4096 ;; + bcachefs) + def_blksz=`echo $MKFS_OPTIONS | sed -rn > >'s/.*(--block_size)[
Quoted 4 lines
common/rc _scratch_mkfs_sized() · line 955
Quoted 2 lines
=]?+([0-9]+).*/\2/p'`
common/rc +1
-0+ ;;So if the default bcachefs block size is 512b, I wonder if > this
should
Quoted 2 lines
do something like what the udf branch does a few lines above > and
mkfs.bcachefs decides block size by querying statbuf.st_blksize or BLKPBSZGET from the device if the option is not given.
Quoted 1 line
override the hardcoded default of 4k. ISTM this whole thing >
would be
Quoted 1 line
more robust if it just elided the param in the default cases > and
let the
Quoted 1 line
associated mkfs tool use its own default, but that's probably > a
separate
Quoted 9 lines
Quoted 2 lines
issue. Hm?
Since there is no default block size of bcachefs, maybe we can let mkfs.bcachefs decide on its own but it will make chaos when somebody reports an unreproducible BUG due to the different
block_sizeeven we have same local.config. It just happened...
So for now, I think 4096 is a resonable value of bcachefs block size.I think we run into this no matter what if we pick a size out of a hat, regardless of what the value is. If somebody is testing with default blocksize (i.e. based on mkfs) on a filesystem where the default isn't actually 4k, then it seems quite unexpected that
_scratch_mkfs_sizedwould use something different from_scratch_mkfswhen a block size isn't explicitly specified. That's exactly the situation we ran into with the generic/361 thing where I would have expected this test to use 512b blocks.ISTM that the 4k value in
_scratch_mkfs_sized()is mainly a last resort default value so the $blocks calculation can work for any filesystem that might not be properly supported by the function. The function looks a little wonky overall, but I think there are at least a couple options to improve things for bcachefs. FWIW, it also looks to me that nothing actually passes a blocksize param to_scratch_mkfs_sized, so perhaps we could just drop that blocksize=$2 parameter across the board as a simplification?
Quoted 5 lines
Quoted 2 lines
Maybe it can be dropped. The only user is generic/466
Ah, good point.
Sorry for the late reply, was busy with other works.
Quoted 9 lines
So generic/466 clears
MKFS_OPTIONSso the function will use the provided block size over whatever exists in the config, yet generic/466 is the only user of this param in the first place.I wonder if a more useful change might be to change the
_scratch_mkfs_sizedlogic to prefer the provided block size over whatever is in the config, but then again that might require further changes for any of the places that continue to useMKFS_OPTIONS. :/
I am wondering too...
Quoted 35 lines
Quoted 23 lines
Quoted 14 lines
With that, I think bcache could either:
1. Do something like def_blksize=
blockdev --getpbsz $SCRATCH_DEVin the first switch if no block size is specified inMKFS_OPTIONS(or whatever best mimics mkfs logic).OR
2. Do something like the following in the last switch:
[ -n $def_blksize ] &&def_blksize="--block_size=$def_blksize"
$MKFS_BCACHEFS_PROG ... $def_blksize $SCRATCH_DEVQuoted 9 lines
... to allow mkfs to determine the block size. I _think_ that works because the bcachefs format doesn't depend on $blocks at all, so whatever $blocksize was set to is irrelevent unless $def_blksize was set above, but I could be missing something. That also assumes blocksize wasn't set to something by the caller.
If correct, option #2 seems a little cleaner to me, but other thoughts/ideas?
Quoted 8 lines
Option 2 is preferable. I would code it as(on more varaiable for readability):
local
blocksize_opt[ -n $def_blksize ] && blockzie_opt="--block_size=$def_blksize" $MKFS_BCACHEFS_PROG ... $blocksize_opt $SCRATCH_DEV
That seems reasonable to me. The only caveat is this was assuming the blocksize param would go away and so could be ignored for bcachefs.
Quoted 8 lines
Without getting too far into the weeds on the higher level parameter handling, I wonder if the blocksize parameter was initially put into a separate variable (i.e.
blocksize_paramor some such), if that would at least help bcachefs determine between the case where 4096 was requested by the caller vs. picked out of a hat by the default handling logic earlier in the function, and thus correctly determine when to set a blocksize vs. use the mkfs (non-4k) default.
After going through the call stack of _scratch_mkfs quickly, I did not found something global to describe blocksize.
So I think blocksize_param is unnecessary?
--
Su
Quoted 28 lines
So then IOW the logic might look something like this..?
[ -n $blocksize_param ] && blocksize_opt="--block_size=$blocksize_param" [ -n $def_blksize ] && blocksize_opt="--block_size=$def_blksize" mkfs ...Brian
Quoted 18 lines
--
SuQuoted 15 lines
Brian
Quoted 12 lines
--
SuQuoted 9 lines
Brian
Quoted 6 lines
common/rc +0
-1esac [ -n "$def_blksz" ] && blocksize=$def_blksz --2.43.0
Re: [PATCH v2 2/2] common/rc: improve block size support for bcachefs
Quoted 117 lines · Su Yue
Quoted 114 lines · Brian Foster
Quoted 113 lines · Su Yue
Quoted 3 lines · Brian Foster
Quoted 2 lines · Su Yue
On Wed 17 Jan 2024 at 12:55, Brian Foster > >
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines · wrote:
Quoted 1 line · Su Yue
For bcachefs,
def_blkszis never assigned even > > > >
MKFS_OPTIONS> >Quoted 3 lines
Quoted 3 lines
contains
Quoted 2 lines
Quoted 2 lines
option
'--block_size'. So block size of bcachefs on scratch > > > >dev is > >
Quoted 3 lines
Quoted 3 lines
always
Quoted 2 lines
Quoted 2 lines
4096
if_scratch_mkfs_sizedis called without second > > > >parameter.
Quoted 30 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Add the pattern to set
def_blkszif '--block_size' is > > >given > >
Quoted 27 lines
in
Quoted 11 lines
Quoted 11 lines
MKFS_OPTIONS.Signed-off-by Su Yue <[email protected]>---
changelog:
v2:
Born.--- common/rc | 3 +++ 1 file changed, 3 insertions(+)Quoted 10 lines
common/rc _scratch_mkfs_sized() · line 954
Quoted 10 lines
common/rc +2
-0@@ -950,6 +950,9 @@ _scratch_mkfs_sized() jfs) def_blksz=4096 ;; + bcachefs) + def_blksz=`echo $MKFS_OPTIONS | sed -rn > >'s/.*(--block_size)[
Quoted 4 lines
common/rc
Quoted 2 lines
=]?+([0-9]+).*/\2/p'`
common/rc +1
-0+ ;;So if the default bcachefs block size is 512b, I wonder > > >
if > this
Quoted 2 lines
Quoted 2 lines
should
Quoted 1 line
do something like what the udf branch does a few lines > > >
above > and
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
mkfs.bcachefs decides block size by querying > >
statbuf.st_blksize or
Quoted 3 lines
Quoted 3 lines
BLKPBSZGET from the device if the option is not given.
Quoted 1 line
override the hardcoded default of 4k. ISTM this whole > > >
thing >
Quoted 2 lines
Quoted 2 lines
would be
Quoted 1 line
more robust if it just elided the param in the default > > >
cases > and
Quoted 2 lines
Quoted 2 lines
let the
Quoted 1 line
associated mkfs tool use its own default, but that's > > >
probably > a
Quoted 4 lines
Quoted 4 lines
separate
Quoted 2 lines
issue. Hm?
Since there is no default block size of bcachefs, maybe we > >
can let
Quoted 1 line
Quoted 1 line
mkfs.bcachefs decide on its own but it will make chaos when > >
somebody
Quoted 1 line
Quoted 1 line
reports an unreproducible BUG due to the different > >
block_sizeevenQuoted 2 lines
Quoted 2 lines
we have same local.config. It just happened...
So for now, I think 4096 is a resonable value of bcachefs > >block
Quoted 4 lines
Quoted 2 lines
size.
I think we run into this no matter what if we pick a size out > of
a hat,
Quoted 1 line
regardless of what the value is. If somebody is testing with >
default
Quoted 1 line
blocksize (i.e. based on mkfs) on a filesystem where the > default
isn't
Quoted 1 line
actually 4k, then it seems quite unexpected that >
_scratch_mkfs_sizedQuoted 1 line
would use something different from
_scratch_mkfswhen a block >size isn't
Quoted 1 line
explicitly specified. That's exactly the situation we ran > into
with the
Quoted 1 line
generic/361 thing where I would have expected this test to > use
512b
Quoted 3 lines
blocks.
ISTM that the 4k value in
_scratch_mkfs_sized()is mainly a > lastresort
Quoted 1 line
default value so the $blocks calculation can work for any >
filesystem
Quoted 1 line
that might not be properly supported by the function. The >
function looks
Quoted 1 line
a little wonky overall, but I think there are at least a > couple
options
Quoted 1 line
to improve things for bcachefs. FWIW, it also looks to me > that
nothing
Quoted 1 line
actually passes a blocksize param to
_scratch_mkfs_sized, so >perhaps we
Quoted 1 line
could just drop that blocksize=$2 parameter across the board > as
a
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
simplification?
Maybe it can be dropped. The only user is generic/466
Ah, good point.
Sorry for the late reply, was busy with other works.
No worries, same..
Quoted 58 lines
Quoted 9 lines
So generic/466 clears
MKFS_OPTIONSso the function will use the provided block size over whatever exists in the config, yet generic/466 is the only user of this param in the first place.I wonder if a more useful change might be to change the
_scratch_mkfs_sizedlogic to prefer the provided block size over whatever is in the config, but then again that might require further changes for any of the places that continue to useMKFS_OPTIONS. :/I am wondering too...
Quoted 39 lines
Quoted 27 lines
Quoted 3 lines
With that, I think bcache could either:
1. Do something like def_blksize=`blockdev --getpbsz >
$SCRATCH_DEV` in
Quoted 1 line
the first switch if no block size is specified in >
MKFS_OPTIONS(or
Quoted 10 lines
whatever best mimics mkfs logic).
OR
2. Do something like the following in the last switch:
[ -n $def_blksize ] && > def_blksize="--block_size=$def_blksize" $MKFS_BCACHEFS_PROG ... $def_blksize $SCRATCH_DEV... to allow mkfs to determine the block size. I _think_ that >
works
Quoted 2 lines
because the bcachefs format doesn't depend on $blocks at all, > so whatever $blocksize was set to is irrelevent unless > $def_blksize
was set
Quoted 1 line
above, but I could be missing something. That also assumes >
blocksize
Quoted 5 lines
wasn't set to something by the caller.
If correct, option #2 seems a little cleaner to me, but other thoughts/ideas?
Quoted 8 lines
Option 2 is preferable. I would code it as(on more varaiable for readability):
local
blocksize_opt[ -n $def_blksize ] && blockzie_opt="--block_size=$def_blksize" $MKFS_BCACHEFS_PROG ... $blocksize_opt $SCRATCH_DEV
That seems reasonable to me. The only caveat is this was assuming the blocksize param would go away and so could be ignored for bcachefs.
Quoted 8 lines
Without getting too far into the weeds on the higher level parameter handling, I wonder if the blocksize parameter was initially put into a separate variable (i.e.
blocksize_paramor some such), if that would at least help bcachefs determine between the case where 4096 was requested by the caller vs. picked out of a hat by the default handling logic earlier in the function, and thus correctly determine when to set a blocksize vs. use the mkfs (non-4k) default.
Quoted 4 lines
After going through the call stack of
_scratch_mkfsquickly, I did not found something global to describe blocksize.
So I thinkblocksize_paramis unnecessary?
My concern was more that I think the original logic I posted didn't properly handle the case where a blocksize param is passed in (and thus my version removed the parameter, which was incorrect due to not realizing that generic/466 used it), but it's also possible I confused myself between the various options that have been discussed or am just not expressing the concern clearly enough.
It's probably not worth getting further hung up on this point here. If you have a patch along the lines of your most recent example, that sounds like a good direction to me and so I can just take a fresh look from there...
Brian
Quoted 31 lines
--
SuQuoted 27 lines
So then IOW the logic might look something like this..?
[ -n $blocksize_param ] && blocksize_opt="--block_size=$blocksize_param" [ -n $def_blksize ] && blocksize_opt="--block_size=$def_blksize" mkfs ...Brian
Quoted 18 lines
--
SuQuoted 15 lines
Brian
Quoted 12 lines
--
SuQuoted 9 lines
Brian
Quoted 6 lines
common/rc +0
-1esac [ -n "$def_blksz" ] && blocksize=$def_blksz --2.43.0
Quoted 51 lines · Su Yue
mkfs.bcachefs supports force overwrite when option '-f' is given:
$ mkfs.bcachefs --help | grep force -f, --forceThere are some tests which call
_scratch_mkfsmultiple times e.g. tests/generic/171. Without '-f' inMKFS_OPTIONS, these tests just hang in overwrite confirmation. After this commit,MKFS_BCACHEFS_PROGwill contains ' -f' so we don't have to add '-f' toMKFS_OPTIONSmanually to make these tests pass.It also fixes generic/466 which unsets
MKFS_OPTIONScausing that test hangs in mfks.bcachefs waiting for confirmation of the force overwrite.Signed-off-by Su Yue <[email protected]>---
changelog:
v2:
Add more details about whyMKFS_BCACHEFS_PROGshould contain '-f'.--- common/config | 3 ++- common/rc | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-)common/config +2
-1@@ -105,7 +105,7 @@ set_mkfs_prog_path_with_opts() # Note: mkfs.f2fs doesn't support the --help option yet, but it doesn't # matter since it also prints the help when an invalid option is given. if [ "$p" != "" ] && \ - $p --help |& grep -q "[[:space:]]-f[[:space:]|]"; then + $p --help |& grep -q "[[:space:]]-f[[:space:]|,]"; then echo "$p -f" else echo $p@@ -313,6 +313,7 @@ export MKFS_REISER4_PROG=$(type -P mkfs.reiser4) export E2FSCK_PROG=$(type -P e2fsck) export TUNE2FS_PROG=$(type -P tune2fs) export FSCK_OVERLAY_PROG=$(type -P fsck.overlay) +export MKFS_BCACHEFS_PROG=$(set_mkfs_prog_path_with_opts bcachefs) # SELinux adds extra xattrs which can mess up our expected output. # So, mount with a context, and they won't be created.common/rc +0
-0
common/rc _test_mkfs() · line 615
Quoted 5 lines
common/rc +2
-0@@ -611,6 +611,9 @@ _test_mkfs() xfs) $MKFS_PROG -t $FSTYP -- -f $MKFS_OPTIONS $* $TEST_DEV ;; + bcachefs) + $MKFS_BCACHEFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null
Whitespace looks off on this line, but I suppose the maintainer can fix that up if desired. That aside this LGTM:
Quoted 37 lines
common/rc +7
-3+ ;; *) yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV ;;@@ -753,6 +756,10 @@ _scratch_mkfs() mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --" mkfs_filter="grep -v -e ^mkfs\.ocfs2" ;; + bcachefs) + mkfs_cmd="$MKFS_BCACHEFS_PROG" + mkfs_filter="cat" + ;; *) mkfs_cmd="yes | $MKFS_PROG -t $FSTYP --" mkfs_filter="cat"@@ -1044,7 +1051,7 @@ _scratch_mkfs_sized() export MOUNT_OPTIONS="-o size=$fssize $TMPFS_MOUNT_OPTIONS" ;; bcachefs) - $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS --fs_size=$fssize --block_size=$blocksize $SCRATCH_DEV + $MKFS_BCACHEFS_PROG $MKFS_OPTIONS --fs_size=$fssize --block_size=$blocksize $SCRATCH_DEV ;; *) _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"@@ -1128,8 +1135,7 @@ _scratch_mkfs_blocksized() -C $blocksize $SCRATCH_DEV ;; bcachefs) - ${MKFS_PROG} -t $FSTYP $MKFS_OPTIONS --block_size=$blocksize \ - $SCRATCH_DEV + _scratch_mkfs --block_size=$blocksize ;; udf) _scratch_mkfs -b $blocksizeSignature · 1 line
2.43.0