On Sun, Mar 15, 2020 at 03:13:19PM -0700, Bart Van Assche wrote: > Introduce a function for creating a null_blk device instance through > configfs. > > Suggested-by: Chaitanya Kulkarni <Chaitanya.Kulkarni@xxxxxxx> > Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx> > --- > common/multipath-over-rdma | 17 +++++------------ > common/null_blk | 14 ++++++++++++++ > tests/block/029 | 16 ++-------------- > 3 files changed, 21 insertions(+), 26 deletions(-) > > diff --git a/common/multipath-over-rdma b/common/multipath-over-rdma > index a56e7a8269db..7e610a0ccbbb 100644 > --- a/common/multipath-over-rdma > +++ b/common/multipath-over-rdma > @@ -620,18 +620,11 @@ run_fio() { > configure_null_blk() { > local i > > - ( > - cd /sys/kernel/config/nullb || return $? > - for i in nullb0 nullb1; do ( > - { mkdir -p $i && > - cd $i && > - echo 0 > completion_nsec && > - echo 512 > blocksize && > - echo $((ramdisk_size>>20)) > size && > - echo 1 > memory_backed && > - echo 1 > power; } || exit $? > - ) done > - ) > + for i in nullb0 nullb1; do > + _configure_null_blk nullb$i completion_nsec=0 blocksize=512 \ > + size=$((ramdisk_size>>20)) memory_backed=1 \ > + power=1 || return $? > + done > ls -l /dev/nullb* &>>"$FULL" > } > > diff --git a/common/null_blk b/common/null_blk > index 6a5f99aaae9d..3c31db1ed4ac 100644 > --- a/common/null_blk > +++ b/common/null_blk > @@ -28,6 +28,20 @@ _init_null_blk() { > return 0 > } > > +# Configure one null_blk instance with name $1 and parameters $2..${$#}. > +_configure_null_blk() { > + local nullb=/sys/kernel/config/nullb/$1 param val > + > + shift > + mkdir "$nullb" && Just make this mkdir "$nullb" || return $? > + while [ -n "$1" ]; do The intention is clearer with while [[ $# > 0 ]] > + param="${1//=*}" > + val="${1#${param}=}" These are all arcane bash incantations, but the following seem slighly clearer to me: param="${1%%=*}" val="${1#*=}" I.e., for param we remove the equal sign and everything after it, and for val we remove everything up to the equal sign. > + shift > + echo "$val" > "$nullb/$param" || return $? > + done > +} > +