block_dev: Convert to new API
PATCH 1/1 block_dev: Convert to new API
---
Tested against v6.11
--- .../block/block_dev_kernel/ltp_block_dev.c | 1 - .../block/block_dev_user/block_dev.c | 78 +++++++++------------- 2 files changed, 32 insertions(+), 47 deletions(-)
testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c +0 -1
@@ -12,7 +12,6 @@#include <linux/module.h> #include <linux/device.h> #include <linux/fs.h> -#include <linux/genhd.h> #include <linux/blkdev.h> MODULE_AUTHOR ("Márton Németh <[email protected]>" );
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +32 -46
109 lines not on this page · raw message
---
base-commit: 47aff4decc81ac837fd745278def6883fc2f197b
change-id: 20241018-block_dev-c322152e03ad
Best regards,
Signature · 5 lines
Ricardo B. Marliere <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 9 lines
.../block/block_dev_kernel/ltp_block_dev.c | 1 - .../block/block_dev_user/block_dev.c | 78 +++++++++------------- 2 files changed, 32 insertions(+), 47 deletions(-)testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c +0
-0
testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c line 15
Quoted 5 lines
testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c +0
-1@@ -12,7 +12,6 @@#include <linux/module.h> #include <linux/device.h> #include <linux/fs.h> -#include <linux/genhd.h> #include <linux/blkdev.h>
Technically LTP is supposed to support kernel 4.4 and newer, looking into kernel git the genhd.h content was moved into blkdev.h in 5.18 so ideally we should make it work for both. I suppose that we can make use of one of the macros that were moved into blkdev.h and do something as:
#include <linux/blkdev.h>
#ifndef DISK_NAME_LEN
# include <linux/genhd.h> #endif
Quoted 14 lines
testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c +0
-0MODULE_AUTHOR ("Márton Németh <[email protected]>" );testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +1
-0@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. * @@ -26,74 +27,59 @@#include <unistd.h> #include <string.h>
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c line 36
Quoted 10 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +5
-3-#include "test.h" -#include "safe_macros.h" -#include "old_module.h" +#include "tst_test.h" +#include "tst_module.h" + +#define MODULE_NAME "ltp_block_dev" +#define MODULE_NAME_KO MODULE_NAME ".ko"char *TCID ="block_dev" ;
Isn't this unused as well?
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c line 42
Quoted 12 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +2
-6-int TST_TOTAL =9 ; -static const char module_name[] ="ltp_block_dev.ko" ;static const char dev_result[] ="/sys/devices/ltp_block_dev/result" ;static const char dev_tcase[] ="/sys/devices/ltp_block_dev/tcase" ; -static int module_loaded; -static int run_all_testcases; -static const option_t options[] = { - {"a" , &run_all_testcases,NULL }, +static int module_loaded; +static char * run_all_testcases;
The whitespaces around the asterisk here are wrong. Have fixed all the errors and warnings reported by 'make check'?
Quoted 26 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +3
-15+static struct tst_option options[] = { + {"a" , &run_all_testcases,"-a\tRun all test-cases (can crash the kernel)" }, {NULL ,NULL ,NULL } };static void cleanup (void ) {if (module_loaded) -tst_module_unload (NULL , module_name); -} - -static void help (void ) -{ -printf (" -a Run all test-cases (can crash the kernel)\n" ); -} - -void setup (int argc,char *argv[]) -{ -tst_parse_opts (argc, argv, options, help); - -tst_require_root (); - -tst_sig (FORK ,DEF_HANDLER , cleanup); +tst_module_unload (MODULE_NAME_KO ); }
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c line 61
Quoted 10 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +1
-2-static void test_run (void ) +static void run (unsigned int n) { -int off =0 ;/* * test-cases #8 and #9 can crash the kernel. * We have to wait for kernel fix where register_blkdev() & * unregister_blkdev() checks the input device name parameter * against NULL pointer. */
Is this still true?
Quoted 25 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +4
-19-if (!run_all_testcases) - off =2 ; - -tst_module_load (cleanup, module_name,NULL ); - module_loaded =1 ; - -int i, pass =0 ; -for (i =0 ; i <TST_TOTAL - off; ++i) { -SAFE_FILE_PRINTF (cleanup, dev_tcase,"%d" , i +1 ); -SAFE_FILE_SCANF (cleanup, dev_result,"%d" , &pass); -tst_resm ((pass) ?TPASS :TFAIL ,"Test-case '%d'" , i +1 ); + n++; +if (!run_all_testcases && (n ==8 || n ==9 )) { +tst_res (TCONF ,"Skipped n = %d" , n); +return ; } -} - -int main (int argc,char *argv[]) -{ -setup (argc, argv); - -test_run (); -cleanup ();
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c line 76
Quoted 10 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +8
-1+if (!module_loaded) { +tst_module_load (MODULE_NAME_KO ,NULL ); + module_loaded =1 ; + } -tst_exit (); +int pass =0 ; +SAFE_FILE_PRINTF (dev_tcase,"%d" , n); +SAFE_FILE_SCANF (dev_result,"%d" , &pass); +tst_res ((pass) ?TPASS :TFAIL ,"Test-case '%d'" , n);
It would be way better if we printed a menaningful information about the test here as well, but that would probably require having a third file exported by the test module and should ideally be done in an subsequent patch.
Quoted 21 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +8
-1} + +static struct tst_test test = { + .needs_root =1 , + .cleanup = cleanup, + .test = run, + .tcnt =9 , + .options = options, +}; ---base-commit:
47aff4decc81ac837fd745278def6883fc2f197b
change-id: 20241018-block_dev-c322152e03adBest regards,
Signature · 5 lines
Ricardo B. Marliere <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
Quoted 21 lines · Cyril Hrubis
Hi!
Quoted 9 lines
.../block/block_dev_kernel/ltp_block_dev.c | 1 - .../block/block_dev_user/block_dev.c | 78 +++++++++------------- 2 files changed, 32 insertions(+), 47 deletions(-)testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c +0
-0testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c line 15
Quoted 5 lines
testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c +0
-1@@ -12,7 +12,6 @@#include <linux/module.h> #include <linux/device.h> #include <linux/fs.h> -#include <linux/genhd.h> #include <linux/blkdev.h> Technically LTP is supposed to support kernel 4.4 and newer, looking into kernel git the
genhd.hcontent was moved intoblkdev.hin 5.18 so ideally we should make it work for both. I suppose that we can make use of one of the macros that were moved intoblkdev.hand do something as:
Quoted 5 lines
#include <
linux/blkdev.h>
#ifndefDISK_NAME_LEN# include <linux/genhd.h> #endif
Good tip, thanks, will add in v2. I was unsure what to do regarding this and my goal was to compile against v6.11.
Quoted 23 lines
Quoted 23 lines
testcases/kernel/device-drivers/block/block_dev_kernel/ltp_block_dev.c +0
-0MODULE_AUTHOR ("Márton Németh <[email protected]>" );testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +6
-3@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. * @@ -26,74 +27,59 @@#include <unistd.h> #include <string.h> -#include "test.h" -#include "safe_macros.h" -#include "old_module.h" +#include "tst_test.h" +#include "tst_module.h" + +#define MODULE_NAME "ltp_block_dev" +#define MODULE_NAME_KO MODULE_NAME ".ko"
Quoted 4 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c line 36
Quoted 1 line
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +0
-0char *TCID ="block_dev" ;Isn't this unused as well?
Yes, indeed!
Quoted 7 lines
Quoted 7 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +0
-3-int TST_TOTAL =9 ; -static const char module_name[] ="ltp_block_dev.ko" ;static const char dev_result[] ="/sys/devices/ltp_block_dev/result" ;static const char dev_tcase[] ="/sys/devices/ltp_block_dev/tcase" ; -static int module_loaded;
Quoted 9 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c line 42
Quoted 5 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +2
-3-static int run_all_testcases; -static const option_t options[] = { - {"a" , &run_all_testcases,NULL }, +static int module_loaded; +static char * run_all_testcases;The whitespaces around the asterisk here are wrong. Have fixed all the errors and warnings reported by 'make check'?
I was not aware of the check target, will fix in v2.
Quoted 26 lines
Quoted 26 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +3
-15+static struct tst_option options[] = { + {"a" , &run_all_testcases,"-a\tRun all test-cases (can crash the kernel)" }, {NULL ,NULL ,NULL } };static void cleanup (void ) {if (module_loaded) -tst_module_unload (NULL , module_name); -} - -static void help (void ) -{ -printf (" -a Run all test-cases (can crash the kernel)\n" ); -} - -void setup (int argc,char *argv[]) -{ -tst_parse_opts (argc, argv, options, help); - -tst_require_root (); - -tst_sig (FORK ,DEF_HANDLER , cleanup); +tst_module_unload (MODULE_NAME_KO ); }
Quoted 13 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c line 61
Quoted 10 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +1
-2-static void test_run (void ) +static void run (unsigned int n) { -int off =0 ;/* * test-cases #8 and #9 can crash the kernel. * We have to wait for kernel fix where register_blkdev() & * unregister_blkdev() checks the input device name parameter * against NULL pointer. */ Is this still true?
Yes. Hence why I kept the same logic and why added "n++".
Quoted 30 lines
Quoted 30 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +8
-19-if (!run_all_testcases) - off =2 ; - -tst_module_load (cleanup, module_name,NULL ); - module_loaded =1 ; - -int i, pass =0 ; -for (i =0 ; i <TST_TOTAL - off; ++i) { -SAFE_FILE_PRINTF (cleanup, dev_tcase,"%d" , i +1 ); -SAFE_FILE_SCANF (cleanup, dev_result,"%d" , &pass); -tst_resm ((pass) ?TPASS :TFAIL ,"Test-case '%d'" , i +1 ); + n++; +if (!run_all_testcases && (n ==8 || n ==9 )) { +tst_res (TCONF ,"Skipped n = %d" , n); +return ; } -} - -int main (int argc,char *argv[]) -{ -setup (argc, argv); - -test_run (); -cleanup (); +if (!module_loaded) { +tst_module_load (MODULE_NAME_KO ,NULL ); + module_loaded =1 ; + }
Quoted 12 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c line 76
Quoted 5 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +4
-1-tst_exit (); +int pass =0 ; +SAFE_FILE_PRINTF (dev_tcase,"%d" , n); +SAFE_FILE_SCANF (dev_result,"%d" , &pass); +tst_res ((pass) ?TPASS :TFAIL ,"Test-case '%d'" , n);It would be way better if we printed a menaningful information about the test here as well, but that would probably require having a third file exported by the test module and should ideally be done in an subsequent patch.
Quoted 1 line
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +0
-0}
As per your suggestion, I'm sending v2 without that and then we can discuss how that can be made better. I chose to do this conversion so as to learn about LTP and the overall process and it seemed very straight forward. :)
Thanks for reviewing,
- Ricardo.
Quoted 24 lines
Quoted 20 lines
testcases/kernel/device-drivers/block/block_dev_user/block_dev.c +8
-1+ +static struct tst_test test = { + .needs_root =1 , + .cleanup = cleanup, + .test = run, + .tcnt =9 , + .options = options, +}; ---base-commit:
47aff4decc81ac837fd745278def6883fc2f197b
change-id: 20241018-block_dev-c322152e03adBest regards,
Signature · 5 lines
Ricardo B. Marliere <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltpSignature · 2 lines
Cyril Hrubis [email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp