Message ID | 1639552849-2251-2-git-send-email-xuyang2018.jy@fujitsu.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [v4,1/4] swapping01: skip test if zram-swap is being used | expand |
Hi Xu, > If zram-generator package is installed and works, then we can not remove zram module > because zram swap is being used. This case needs a clean zram environment, change this > test by using hot_add/hot_remove interface[1]. So even zram device is being used, we > still can add zram device and remove them in cleanup. BTW this was added in v4.2-rc1 (6 years ago, 6566d1a32bf7 ("zram: add dynamic device add/remove functionality")). Hopefully anybody still supporting older kernels is using old LTP for it. > Also, zram01,02 case are adjuested to adapt the situation that CONFIG_ZRAM=y. Very nice, thanks! Reviewed-by: Petr Vorel <pvorel@suse.cz> > 1]https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html#add-remove-zram-devices nit: [1] https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html#add-remove-zram-devices ... > - modprobe zram num_devices=$dev_num || \ > - tst_brk TBROK "failed to insert zram module" > + if [ ! -d "/sys/class/zram-control" ]; then > + modprobe zram num_devices=$dev_num > + module_load=1 > + dev_start=0 > + dev_end=$(($dev_num - 1)) > + tst_res TPASS "all zram devices(/dev/zram0~$dev_end) successfully created" nit: please all zram devices (/dev/zram0~$dev_end) ... (add space after devices) > + return > + fi > - dev_num_created=$(ls /dev/zram* | wc -w) > + dev_start=$(ls /dev/zram* | wc -w) > + dev_end=$(($dev_start + $dev_num - 1)) > - if [ "$dev_num_created" -ne "$dev_num" ]; then > - tst_brk TFAIL "unexpected num of devices: $dev_num_created" > - fi > + for i in $(seq $dev_start $dev_end); do > + cat /sys/class/zram-control/hot_add > /dev/null > + done > - tst_res TPASS "all zram devices successfully created" > + tst_res TPASS "all zram devices(/dev/zram$dev_start~$dev_end) successfully created" and here. Kind regards, Petr
> If zram-generator package is installed and works, then we can not remove zram module > because zram swap is being used. This case needs a clean zram environment, change this > test by using hot_add/hot_remove interface[1]. So even zram device is being used, we > still can add zram device and remove them in cleanup. BTW this also helped to run zram01.sh simultaneously, which is nice. Thank you. Kind regards, Petr
Hi Petr > Hi Xu, > >> If zram-generator package is installed and works, then we can not remove zram module >> because zram swap is being used. This case needs a clean zram environment, change this >> test by using hot_add/hot_remove interface[1]. So even zram device is being used, we >> still can add zram device and remove them in cleanup. > > BTW this was added in v4.2-rc1 (6 years ago, 6566d1a32bf7 ("zram: add dynamic > device add/remove functionality")). Hopefully anybody still supporting older > kernels is using old LTP for it. Oh, I don't realize it before. I tested it on centos7 then I think this control interface maybe introduced long time ago. To be honst, I don't want to make this case more complex. How about adding /sys/class/zram-control check after load zram module. If not, just report case needs to use hot_add/hot_remove interface . Old kernel can use old ltp since it is 4.2 not like 4.4 4.19(they are long stable branch, we should consider them). > >> Also, zram01,02 case are adjuested to adapt the situation that CONFIG_ZRAM=y. > Very nice, thanks! > > Reviewed-by: Petr Vorel<pvorel@suse.cz> > >> 1]https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html#add-remove-zram-devices > nit: [1] https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html#add-remove-zram-devices > > ... >> - modprobe zram num_devices=$dev_num || \ >> - tst_brk TBROK "failed to insert zram module" >> + if [ ! -d "/sys/class/zram-control" ]; then >> + modprobe zram num_devices=$dev_num >> + module_load=1 >> + dev_start=0 >> + dev_end=$(($dev_num - 1)) >> + tst_res TPASS "all zram devices(/dev/zram0~$dev_end) successfully created" > nit: please all zram devices (/dev/zram0~$dev_end) ... (add space after devices) OK >> + return >> + fi > >> - dev_num_created=$(ls /dev/zram* | wc -w) >> + dev_start=$(ls /dev/zram* | wc -w) >> + dev_end=$(($dev_start + $dev_num - 1)) > >> - if [ "$dev_num_created" -ne "$dev_num" ]; then >> - tst_brk TFAIL "unexpected num of devices: $dev_num_created" >> - fi >> + for i in $(seq $dev_start $dev_end); do >> + cat /sys/class/zram-control/hot_add> /dev/null >> + done > >> - tst_res TPASS "all zram devices successfully created" >> + tst_res TPASS "all zram devices(/dev/zram$dev_start~$dev_end) successfully created" > and here. OK Best Regards Yang Xu > > Kind regards, > Petr
Hi Xu, > >> If zram-generator package is installed and works, then we can not remove zram module > >> because zram swap is being used. This case needs a clean zram environment, change this > >> test by using hot_add/hot_remove interface[1]. So even zram device is being used, we > >> still can add zram device and remove them in cleanup. > > BTW this was added in v4.2-rc1 (6 years ago, 6566d1a32bf7 ("zram: add dynamic > > device add/remove functionality")). Hopefully anybody still supporting older > > kernels is using old LTP for it. > Oh, I don't realize it before. I tested it on centos7 then I think this > control interface maybe introduced long time ago. > To be honst, I don't want to make this case more complex. How about > adding /sys/class/zram-control check after load zram module. If not, > just report case needs to use hot_add/hot_remove interface . Would it work something like this? ZRAM_SYSCTL_KERNEL_VERSION="4.2" ... zram_cleanup() { ... if tst_kvcmp -lt $ZRAM_SYSCTL_KERNEL_VERSION; then for i in $(seq $dev_start $dev_end); do echo $i > /sys/class/zram-control/hot_remove done fi zram_load() { ... if [ ! -d "/sys/class/zram-control" ]; then modprobe zram num_devices=$dev_num module_load=1 dev_start=0 dev_end=$(($dev_num - 1)) tst_res TPASS "all zram devices(/dev/zram0~$dev_end) successfully created" return fi tst_kvcmp -lt $ZRAM_SYSCTL_KERNEL_VERSION && \ tst_brk TCONF "test requires kernel $ZRAM_SYSCTL_KERNEL_VERSION+" dev_start=$(ls /dev/zram* | wc -w) dev_end=$(($dev_start + $dev_num - 1)) for i in $(seq $dev_start $dev_end); do cat /sys/class/zram-control/hot_add > /dev/null done Kind regards, Petr
Hi Petr > Hi Xu, > >>>> If zram-generator package is installed and works, then we can not remove zram module >>>> because zram swap is being used. This case needs a clean zram environment, change this >>>> test by using hot_add/hot_remove interface[1]. So even zram device is being used, we >>>> still can add zram device and remove them in cleanup. > >>> BTW this was added in v4.2-rc1 (6 years ago, 6566d1a32bf7 ("zram: add dynamic >>> device add/remove functionality")). Hopefully anybody still supporting older >>> kernels is using old LTP for it. >> Oh, I don't realize it before. I tested it on centos7 then I think this >> control interface maybe introduced long time ago. > >> To be honst, I don't want to make this case more complex. How about >> adding /sys/class/zram-control check after load zram module. If not, >> just report case needs to use hot_add/hot_remove interface . > > Would it work something like this? I don't want to use kernel version check because the hot_add/hot_remove interface is easy to backport. I will send a v5 1) new kernel and not load zram kernel module, then modprobe and rmmod is enough, doesn't need to use hot_add/hot_remove 2) new kernel and load zram kernel module or built in kernel, use hot_add/hot_remove 3) old kernel and can be modprobe and rmmod, work as 1) 4)old kernel but is being used or built in kernel, then skip this case like patch v3 does Best Regards Yang Xu > > ZRAM_SYSCTL_KERNEL_VERSION="4.2" > ... > zram_cleanup() > { > ... > if tst_kvcmp -lt $ZRAM_SYSCTL_KERNEL_VERSION; then > for i in $(seq $dev_start $dev_end); do > echo $i> /sys/class/zram-control/hot_remove > done > fi > > zram_load() > { > ... > if [ ! -d "/sys/class/zram-control" ]; then > modprobe zram num_devices=$dev_num > module_load=1 > dev_start=0 > dev_end=$(($dev_num - 1)) > tst_res TPASS "all zram devices(/dev/zram0~$dev_end) successfully created" > return > fi > > tst_kvcmp -lt $ZRAM_SYSCTL_KERNEL_VERSION&& \ > tst_brk TCONF "test requires kernel $ZRAM_SYSCTL_KERNEL_VERSION+" > > dev_start=$(ls /dev/zram* | wc -w) > dev_end=$(($dev_start + $dev_num - 1)) > > for i in $(seq $dev_start $dev_end); do > cat /sys/class/zram-control/hot_add> /dev/null > done > > Kind regards, > Petr
> Hi Petr > > Hi Xu, > >>>> If zram-generator package is installed and works, then we can not remove zram module > >>>> because zram swap is being used. This case needs a clean zram environment, change this > >>>> test by using hot_add/hot_remove interface[1]. So even zram device is being used, we > >>>> still can add zram device and remove them in cleanup. > >>> BTW this was added in v4.2-rc1 (6 years ago, 6566d1a32bf7 ("zram: add dynamic > >>> device add/remove functionality")). Hopefully anybody still supporting older > >>> kernels is using old LTP for it. > >> Oh, I don't realize it before. I tested it on centos7 then I think this > >> control interface maybe introduced long time ago. > >> To be honst, I don't want to make this case more complex. How about > >> adding /sys/class/zram-control check after load zram module. If not, > >> just report case needs to use hot_add/hot_remove interface . > > Would it work something like this? > I don't want to use kernel version check because the hot_add/hot_remove > interface is easy to backport. I will send a v5 > 1) new kernel and not load zram kernel module, then modprobe and rmmod > is enough, doesn't need to use hot_add/hot_remove > 2) new kernel and load zram kernel module or built in kernel, use > hot_add/hot_remove > 3) old kernel and can be modprobe and rmmod, work as 1) > 4)old kernel but is being used or built in kernel, then skip this case > like patch v3 does Sure, make sense (although you didn't avoid more complexity). Thanks working on this! Kind regards, Petr
diff --git a/testcases/kernel/device-drivers/zram/zram01.sh b/testcases/kernel/device-drivers/zram/zram01.sh index ad9a9a2be..5e13f387c 100755 --- a/testcases/kernel/device-drivers/zram/zram01.sh +++ b/testcases/kernel/device-drivers/zram/zram01.sh @@ -69,7 +69,7 @@ setup() zram_makefs() { - local i=0 + local i=$dev_start local fs for fs in $zram_filesystems; do @@ -90,7 +90,7 @@ zram_mount() { local i=0 - for i in $(seq 0 $(($dev_num - 1))); do + for i in $(seq $dev_start $dev_end); do tst_res TINFO "mount /dev/zram$i" mkdir zram$i ROD mount /dev/zram$i zram$i @@ -102,7 +102,7 @@ zram_mount() zram_fill_fs() { - for i in $(seq 0 $(($dev_num - 1))); do + for i in $(seq $dev_start $dev_end); do tst_res TINFO "filling zram$i (it can take long time)" local b=0 while true; do diff --git a/testcases/kernel/device-drivers/zram/zram02.sh b/testcases/kernel/device-drivers/zram/zram02.sh index f0421ce7f..c980fce76 100755 --- a/testcases/kernel/device-drivers/zram/zram02.sh +++ b/testcases/kernel/device-drivers/zram/zram02.sh @@ -29,7 +29,7 @@ zram_makeswap() tst_require_cmds mkswap swapon swapoff local i=0 - for i in $(seq 0 $(($dev_num - 1))); do + for i in $(seq $dev_start $dev_end); do ROD mkswap /dev/zram$i ROD swapon /dev/zram$i tst_res TINFO "done with /dev/zram$i" @@ -44,7 +44,7 @@ zram_swapoff() tst_require_cmds swapoff local i - for i in $(seq 0 $dev_makeswap); do + for i in $(seq $dev_start $dev_end); do ROD swapoff /dev/zram$i done dev_makeswap=-1 diff --git a/testcases/kernel/device-drivers/zram/zram_lib.sh b/testcases/kernel/device-drivers/zram/zram_lib.sh index fe9c915c3..db9552501 100755 --- a/testcases/kernel/device-drivers/zram/zram_lib.sh +++ b/testcases/kernel/device-drivers/zram/zram_lib.sh @@ -5,6 +5,9 @@ dev_makeswap=-1 dev_mounted=-1 +dev_start=-1 +dev_end=-1 +module_load=-1 TST_NEEDS_TMPDIR=1 TST_NEEDS_ROOT=1 @@ -17,19 +20,25 @@ zram_cleanup() { local i - for i in $(seq 0 $dev_makeswap); do + for i in $(seq $dev_start $dev_makeswap); do swapoff /dev/zram$i done - for i in $(seq 0 $dev_mounted); do + for i in $(seq $dev_start $dev_mounted); do umount /dev/zram$i done - for i in $(seq 0 $(($dev_num - 1))); do + for i in $(seq $dev_start $dev_end); do echo 1 > /sys/block/zram${i}/reset done - rmmod zram > /dev/null 2>&1 + for i in $(seq $dev_start $dev_end); do + echo $i > /sys/class/zram-control/hot_remove + done + + if [ $module_load -eq 1 ]; then + rmmod zram > /dev/null 2>&1 + fi } zram_load() @@ -51,16 +60,23 @@ zram_load() tst_res TINFO "create '$dev_num' zram device(s)" - modprobe zram num_devices=$dev_num || \ - tst_brk TBROK "failed to insert zram module" + if [ ! -d "/sys/class/zram-control" ]; then + modprobe zram num_devices=$dev_num + module_load=1 + dev_start=0 + dev_end=$(($dev_num - 1)) + tst_res TPASS "all zram devices(/dev/zram0~$dev_end) successfully created" + return + fi - dev_num_created=$(ls /dev/zram* | wc -w) + dev_start=$(ls /dev/zram* | wc -w) + dev_end=$(($dev_start + $dev_num - 1)) - if [ "$dev_num_created" -ne "$dev_num" ]; then - tst_brk TFAIL "unexpected num of devices: $dev_num_created" - fi + for i in $(seq $dev_start $dev_end); do + cat /sys/class/zram-control/hot_add > /dev/null + done - tst_res TPASS "all zram devices successfully created" + tst_res TPASS "all zram devices(/dev/zram$dev_start~$dev_end) successfully created" } zram_max_streams() @@ -73,7 +89,7 @@ zram_max_streams() tst_res TINFO "set max_comp_streams to zram device(s)" - local i=0 + local i=$dev_start for max_s in $zram_max_streams; do local sys_path="/sys/block/zram${i}/max_comp_streams" @@ -85,7 +101,7 @@ zram_max_streams() tst_brk TFAIL "can't set max_streams '$max_s', get $max_stream" i=$(($i + 1)) - tst_res TINFO "$sys_path = '$max_streams' ($i/$dev_num)" + tst_res TINFO "$sys_path = '$max_streams'" done tst_res TPASS "test succeeded" @@ -100,20 +116,18 @@ zram_compress_alg() return fi - local i=0 + local i=$dev_start tst_res TINFO "test that we can set compression algorithm" - local algs="$(sed 's/[][]//g' /sys/block/zram0/comp_algorithm)" + local algs="$(sed 's/[][]//g' /sys/block/zram${i}/comp_algorithm)" tst_res TINFO "supported algs: $algs" - local dev_max=$(($dev_num - 1)) - - for i in $(seq 0 $dev_max); do + for i in $(seq $dev_start $dev_end); do for alg in $algs; do local sys_path="/sys/block/zram${i}/comp_algorithm" echo "$alg" > $sys_path || \ tst_brk TFAIL "can't set '$alg' to $sys_path" - tst_res TINFO "$sys_path = '$alg' ($i/$dev_max)" + tst_res TINFO "$sys_path = '$alg'" done done @@ -122,7 +136,7 @@ zram_compress_alg() zram_set_disksizes() { - local i=0 + local i=$dev_start local ds tst_res TINFO "set disk size to zram device(s)" @@ -132,7 +146,7 @@ zram_set_disksizes() tst_brk TFAIL "can't set '$ds' to $sys_path" i=$(($i + 1)) - tst_res TINFO "$sys_path = '$ds' ($i/$dev_num)" + tst_res TINFO "$sys_path = '$ds'" done tst_res TPASS "test succeeded" @@ -147,7 +161,7 @@ zram_set_memlimit() return fi - local i=0 + local i=$dev_start local ds tst_res TINFO "set memory limit to zram device(s)" @@ -158,7 +172,7 @@ zram_set_memlimit() tst_brk TFAIL "can't set '$ds' to $sys_path" i=$(($i + 1)) - tst_res TINFO "$sys_path = '$ds' ($i/$dev_num)" + tst_res TINFO "$sys_path = '$ds'" done tst_res TPASS "test succeeded"
If zram-generator package is installed and works, then we can not remove zram module because zram swap is being used. This case needs a clean zram environment, change this test by using hot_add/hot_remove interface[1]. So even zram device is being used, we still can add zram device and remove them in cleanup. Also, zram01,02 case are adjuested to adapt the situation that CONFIG_ZRAM=y. 1]https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html#add-remove-zram-devices Fixes: #888 Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com> --- .../kernel/device-drivers/zram/zram01.sh | 6 +- .../kernel/device-drivers/zram/zram02.sh | 4 +- .../kernel/device-drivers/zram/zram_lib.sh | 60 ++++++++++++------- 3 files changed, 42 insertions(+), 28 deletions(-)