kernel/uevent: Adjust the number of uevents dynamically in uevent02
PATCH v2 1/1 kernel/uevent: Adjust the number of uevents dynamically in uevent02
When CONFIG_SMP is not selected, CONFIG_RPS will not be enabled. Causes the kernel to not create rx queues in sysfs[1] when creating tun devices. Uevent02 will check if the rx queue exists, adjust the uevents dynamically in setup() to pass this test.
--- testcases/kernel/uevents/uevent02.c | 168 ++++++++++++++++------------ 1 file changed, 96 insertions(+), 72 deletions(-)
testcases/kernel/uevents/uevent02.c +96 -72
@@ -18,11 +18,77 @@#include <linux/if.h> #include <linux/if_tun.h> +#include "tst_kconfig.h" #include "tst_test.h" #include "uevent.h" #define TUN_PATH "/dev/net/tun" +#define CONFIG_RPS "CONFIG_RPS" +#define MAX_UEVENTS 7 + +struct uevent_desc add = { + .msg ="add@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; + +struct uevent_desc add_rx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; + +struct uevent_desc add_tx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; + +struct uevent_desc rem_rx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; + +struct uevent_desc rem_tx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; + +struct uevent_desc rem = { + .msg ="remove@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; +const struct uevent_desc *uevents[MAX_UEVENTS ];static void generate_tun_uevents (void ) {
@@ -44,78 +110,6 @@ static void verify_uevent(void) {int pid, fd; -struct uevent_desc add = { - .msg ="add@/devices/virtual/net/ltp-tun0" , - .value_cnt =4 , - .values = (const char *[]) { -"ACTION=add" , -"DEVPATH=/devices/virtual/net/ltp-tun0" , -"SUBSYSTEM=net" , -"INTERFACE=ltp-tun0" , - } - }; - -struct uevent_desc add_rx = { - .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=add" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc add_tx = { - .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=add" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc rem_rx = { - .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=remove" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc rem_tx = { - .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=remove" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc rem = { - .msg ="remove@/devices/virtual/net/ltp-tun0" , - .value_cnt =4 , - .values = (const char *[]) { -"ACTION=remove" , -"DEVPATH=/devices/virtual/net/ltp-tun0" , -"SUBSYSTEM=net" , -"INTERFACE=ltp-tun0" , - } - }; - -const struct uevent_desc *const uevents[] = { - &add, - &add_rx, - &add_tx, - &rem_rx, - &rem_tx, - &rem, -NULL - }; - pid =SAFE_FORK ();if (!pid) { fd =open_uevent_netlink ();
@@ -131,7 +125,37 @@ static void verify_uevent(void)wait_for_pid (pid); } +static void setup (void ) +{ +struct tst_kconfig_var kconfig = { + .id =CONFIG_RPS , + .id_len =sizeof (CONFIG_RPS )-1 , + }; +int i =0 ; + +tst_kconfig_read (&kconfig,1 ); + +if (kconfig.choice !='y' ) { +tst_res (TINFO ,"CONFIG_RPS not supported by kernel" ); + uevents[i++] = &add; + uevents[i++] = &add_tx; + uevents[i++] = &rem_tx; + uevents[i++] = &rem; + uevents[i++] =NULL ; + }else { +tst_res (TINFO ,"CONFIG_RPS supported by kernel" ); + uevents[i++] = &add; + uevents[i++] = &add_rx; + uevents[i++] = &add_tx; + uevents[i++] = &rem_rx; + uevents[i++] = &rem_tx; + uevents[i++] = &rem; + uevents[i++] =NULL ; + } +} +static struct tst_test test = { + .setup = setup, .test_all = verify_uevent, .forks_child =1 , .needs_checkpoints =1 ,
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 81 lines
When
CONFIG_SMPis not selected,CONFIG_RPSwill not be enabled. Causes the kernel to not create rx queues in sysfs[1] when creating tun devices. Uevent02 will check if the rx queue exists, adjust the uevents dynamically insetup()to pass this test.Signed-off-by Dylan Jhong <[email protected]>--- testcases/kernel/uevents/uevent02.c | 168 ++++++++++++++++------------ 1 file changed, 96 insertions(+), 72 deletions(-)testcases/kernel/uevents/uevent02.c +56
-0@@ -18,11 +18,77 @@#include <linux/if.h> #include <linux/if_tun.h> +#include "tst_kconfig.h" #include "tst_test.h" #include "uevent.h" #define TUN_PATH "/dev/net/tun" +#define CONFIG_RPS "CONFIG_RPS" +#define MAX_UEVENTS 7 + +struct uevent_desc add = { + .msg ="add@/devices/virtual/net/ltp-tun0" , + .value_cnt =4 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; + +struct uevent_desc add_rx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; + +struct uevent_desc add_tx = { + .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=add" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; + +struct uevent_desc rem_rx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , +"SUBSYSTEM=queues" , + } +}; + +struct uevent_desc rem_tx = { + .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , + .value_cnt =3 , + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , +"SUBSYSTEM=queues" , + } +}; + +struct uevent_desc rem = {
testcases/kernel/uevents/uevent02.c line 91
Quoted 10 lines
testcases/kernel/uevents/uevent02.c +10
-0+ .msg = "remove@/devices/virtual/net/ltp-tun0", + .value_cnt = 4, + .values = (const char *[]) { +"ACTION=remove" , +"DEVPATH=/devices/virtual/net/ltp-tun0" , +"SUBSYSTEM=net" , +"INTERFACE=ltp-tun0" , + } +}; +const struct uevent_desc *uevents[MAX_UEVENTS ];
Now it makes sense to keep them here, but please make them all static.
Quoted 102 lines
testcases/kernel/uevents/uevent02.c +17
-72static void generate_tun_uevents (void ) {@@ -44,78 +110,6 @@ static void verify_uevent(void) {int pid, fd; -struct uevent_desc add = { - .msg ="add@/devices/virtual/net/ltp-tun0" , - .value_cnt =4 , - .values = (const char *[]) { -"ACTION=add" , -"DEVPATH=/devices/virtual/net/ltp-tun0" , -"SUBSYSTEM=net" , -"INTERFACE=ltp-tun0" , - } - }; - -struct uevent_desc add_rx = { - .msg ="add@/devices/virtual/net/ltp-tun0/queues/rx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=add" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc add_tx = { - .msg ="add@/devices/virtual/net/ltp-tun0/queues/tx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=add" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc rem_rx = { - .msg ="remove@/devices/virtual/net/ltp-tun0/queues/rx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=remove" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc rem_tx = { - .msg ="remove@/devices/virtual/net/ltp-tun0/queues/tx-0" , - .value_cnt =3 , - .values = (const char *[]) { -"ACTION=remove" , -"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0" , -"SUBSYSTEM=queues" , - } - }; - -struct uevent_desc rem = { - .msg ="remove@/devices/virtual/net/ltp-tun0" , - .value_cnt =4 , - .values = (const char *[]) { -"ACTION=remove" , -"DEVPATH=/devices/virtual/net/ltp-tun0" , -"SUBSYSTEM=net" , -"INTERFACE=ltp-tun0" , - } - }; - -const struct uevent_desc *const uevents[] = { - &add, - &add_rx, - &add_tx, - &rem_rx, - &rem_tx, - &rem, -NULL - }; - pid =SAFE_FORK ();if (!pid) { fd =open_uevent_netlink ();@@ -131,7 +125,37 @@ static void verify_uevent(void)wait_for_pid (pid); } +static void setup (void ) +{ +struct tst_kconfig_var kconfig = { + .id =CONFIG_RPS , + .id_len =sizeof (CONFIG_RPS )-1 , + }; +int i =0 ; + +tst_kconfig_read (&kconfig,1 ); + +if (kconfig.choice !='y' ) { +tst_res (TINFO ,"CONFIG_RPS not supported by kernel" ); + uevents[i++] = &add; + uevents[i++] = &add_tx; + uevents[i++] = &rem_tx; + uevents[i++] = &rem; + uevents[i++] =NULL ;
testcases/kernel/uevents/uevent02.c static void verify_uevent(void) · line 154
Quoted 10 lines
testcases/kernel/uevents/uevent02.c +10
-0+ }else { +tst_res (TINFO ,"CONFIG_RPS supported by kernel" ); + uevents[i++] = &add; + uevents[i++] = &add_rx; + uevents[i++] = &add_tx; + uevents[i++] = &rem_rx; + uevents[i++] = &rem_tx; + uevents[i++] = &rem; + uevents[i++] =NULL ; + }
I actually liked the version where we had the two ifs in the middle of the initialization a bit better, since it was obviously clear what the difference between the two cases is.
Quoted 10 lines
testcases/kernel/uevents/uevent02.c +3
-0+} +static struct tst_test test = { + .setup = setup, .test_all = verify_uevent, .forks_child =1 , .needs_checkpoints =1 ,Signature · 1 line
2.34.1
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp