save_restore: Introduce new struct field for flags
PATCH 1/1 save_restore: Introduce new struct field for flags
Tests using the .save_restore functionality currently cannot run without root privileges at all because the test will write into the path at least at the end and trigger error, even when the config paths are flagged as optional.
Introduce new tst_path_val field for flags and replace path prefix flags with bit flags. Also introduce new flags to control handling of read/write errors and read-only sysfiles and rewrite save_restore implementation accordingly.
---
This is technically a v2 for
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
I'll send a follow-up patchset to replace setup() code which requires root privileges without good reason after this patch gets merged. Here I've kept test changes to the minimum needed to maintain current save_restore behavior with the new flags system. The only change in behavior is the use of read-only handling flags where it's clear that the change is desired.
Though a few tests should get closer attention during review:
- all KSM tests
- add_key05
- migrate_pages02
doc/c-test-api.txt | 38 ++++---- include/tst_sys_conf.h | 15 ++- lib/tst_sys_conf.c | 97 ++++++++++++------- lib/tst_test.c | 3 +- testcases/cve/icmp_rate_limit01.c | 2 +- testcases/kernel/containers/userns/userns08.c | 2 +- testcases/kernel/kvm/kvm_pagefault01.c | 3 +- testcases/kernel/mem/ksm/ksm01.c | 10 +- testcases/kernel/mem/ksm/ksm02.c | 10 +- testcases/kernel/mem/ksm/ksm03.c | 10 +- testcases/kernel/mem/ksm/ksm04.c | 10 +- testcases/kernel/mem/ksm/ksm05.c | 2 +- testcases/kernel/mem/ksm/ksm06.c | 9 +- testcases/kernel/syscalls/add_key/add_key05.c | 7 +- testcases/kernel/syscalls/bind/bind06.c | 2 +- testcases/kernel/syscalls/fork/fork13.c | 2 +- .../kernel/syscalls/ipc/msgget/msgget03.c | 2 +- testcases/kernel/syscalls/madvise/madvise06.c | 2 +- testcases/kernel/syscalls/madvise/madvise08.c | 2 +- .../syscalls/migrate_pages/migrate_pages02.c | 2 +- testcases/kernel/syscalls/sendto/sendto03.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt05.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt06.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt07.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt08.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt09.c | 2 +- testcases/kernel/syscalls/syslog/syslog11.c | 2 +- 27 files changed, 142 insertions(+), 102 deletions(-)
doc/c-test-api.txt +18 -20
@@ -1602,35 +1602,33 @@ LTP library can be instructed to save and restore value of specified field 'save_restore'. It is a NULL-terminated array of struct 'tst_path_val' where each tst_path_val.path represents a file, whose value is saved at the beginning and restored at the end of the test. -If non-NULL value is passed it is written to the respective file at -the beginning of the test. Only the first line of a specified file -is saved and restored. - -Pathnames can be optionally prefixed to specify how strictly (during -'store') are handled errors: - -* (no prefix) - test ends with 'TCONF', if file doesn't exist -* '?' - test prints info message and continues, - if file doesn't exist or open/read fails -* '!' - test ends with 'TBROK', if file doesn't exist +If non-NULL string is passed in tst_path_val.val, it is written +to the respective file at the beginning of the test. Only the first line +of a specified file is saved and restored. + +By default, the test will end with TCONF if the file is read-only or +does not exist. If the optional write of new value fails, the test will end +with 'TBROK'. This behavior can be changed using tst_path_val.flags: + +* 'TST_SR_FAIL_MISSING' – End test with 'TBROK' if the file does not exist +* 'TST_SR_IGNORE_MISSING' – Continue without saving the file if it does not exist +* 'TST_SR_FAIL_RO' – End test with 'TBROK' if the file is read-only +* 'TST_SR_IGNORE_RO' – Continue without saving the file if it is read-only +* 'TST_SR_IGNORE_ERR' – Ignore errors when writing new value into the file +* 'TST_SR_REQUIRED' – Equivalent to 'TST_SR_FAIL_MISSING | TST_SR_FAIL_RO' +* 'TST_SR_IF_ACCESS' – Equivalent to 'TST_SR_IGNORE_MISSING | TST_SR_IGNORE_RO' 'restore' is always strict and will TWARN if it encounters any error. [source,c] ------------------------------------------------------------------------------- -static void setup(void) -{ - FILE_PRINTF("/proc/sys/kernel/core_pattern", "/mypath"); - SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10); -} - static struct tst_test test = { ... .setup = setup, .save_restore = (const struct tst_path_val[]) { - {"/proc/sys/kernel/core_pattern", NULL}, - {"?/proc/sys/user/max_user_namespaces", NULL}, - {"!/sys/kernel/mm/ksm/run", "1"}, + {"/proc/sys/kernel/core_pattern", NULL, 0}, + {"/proc/sys/user/max_user_namespaces", NULL, TST_SR_IF_ACCESS}, + {"/sys/kernel/mm/ksm/run", "1", TST_SR_REQUIRED}, {} }, };
include/tst_sys_conf.h +12 -3
@@ -5,14 +5,23 @@#ifndef TST_SYS_CONF_H__ #define TST_SYS_CONF_H__ +#define TST_SR_FAIL_MISSING 0x1 +#define TST_SR_IGNORE_MISSING 0x2 +#define TST_SR_FAIL_RO 0x4 +#define TST_SR_IGNORE_RO 0x8 +#define TST_SR_IGNORE_ERR 0x10 + +#define TST_SR_REQUIRED (TST_SR_FAIL_MISSING | TST_SR_FAIL_RO) +#define TST_SR_IF_ACCESS (TST_SR_IGNORE_MISSING | TST_SR_IGNORE_RO) +struct tst_path_val {const char *path;const char *val; +unsigned int flags; }; -int tst_sys_conf_save_str (const char *path,const char *value); -int tst_sys_conf_save (const char *path); -void tst_sys_conf_set (const char *path,const char *value); +void tst_sys_conf_save_str (const char *path,const char *value); +int tst_sys_conf_save (const struct tst_path_val *conf);void tst_sys_conf_restore (int verbose);void tst_sys_conf_dump (void );
lib/tst_sys_conf.c +60 -37
142 lines not on this page · raw message
lib/tst_test.c +1 -2
@@ -1181,8 +1181,7 @@ static void do_setup(int argc, char *argv[])const struct tst_path_val *pvl = tst_test->save_restore;while (pvl->path) { -if (!tst_sys_conf_save (pvl->path)) -tst_sys_conf_set (pvl->path, pvl->val); +tst_sys_conf_save (pvl); pvl++; } }
testcases/cve/icmp_rate_limit01.c +1 -1
@@ -269,7 +269,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/containers/userns/userns08.c +1 -1
@@ -135,7 +135,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/kvm/kvm_pagefault01.c +2 -1
@@ -217,7 +217,8 @@ static struct tst_test test = { .cleanup = tst_kvm_cleanup, .needs_root = 1, .save_restore = (const struct tst_path_val []) { - {"?/sys/module/kvm/parameters/tdp_mmu" ,"0" }, + {"/sys/module/kvm/parameters/tdp_mmu" ,"0" , +TST_SR_IGNORE_MISSING }, {} }, .supported_archs = (const char *const []) {
testcases/kernel/mem/ksm/ksm01.c +6 -4
@@ -80,10 +80,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"?/sys/kernel/mm/ksm/merge_across_nodes" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} }, .needs_kconfigs = (const char *const []){
testcases/kernel/mem/ksm/ksm02.c +6 -4
@@ -101,10 +101,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"?/sys/kernel/mm/ksm/merge_across_nodes" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} }, .needs_kconfigs = (const char *const []){
testcases/kernel/mem/ksm/ksm03.c +6 -4
@@ -83,10 +83,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"?/sys/kernel/mm/ksm/merge_across_nodes" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} }, .needs_kconfigs = (const char *const []){
testcases/kernel/mem/ksm/ksm04.c +6 -4
@@ -103,10 +103,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"?/sys/kernel/mm/ksm/merge_across_nodes" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} }, .needs_kconfigs = (const char *const []){
testcases/kernel/mem/ksm/ksm05.c +1 -1
@@ -89,7 +89,7 @@ static struct tst_test test = { .test_all = test_ksm, .min_kver = "2.6.32", .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,"1" ,TST_SR_REQUIRED }, {} }, .needs_kconfigs = (const char *const []){
testcases/kernel/mem/ksm/ksm06.c +5 -4
@@ -137,10 +137,11 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"/sys/kernel/mm/ksm/merge_across_nodes" ,NULL }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,NULL ,0 }, {} }, .needs_kconfigs = (const char *const []){
testcases/kernel/syscalls/add_key/add_key05.c +4 -3
@@ -220,9 +220,10 @@ static struct tst_test test = { .forks_child = 1, .cleanup = cleanup, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/kernel/keys/gc_delay" ,"1" }, - {"?/proc/sys/kernel/keys/maxkeys" ,"200" }, - {"?/proc/sys/kernel/keys/maxbytes" ,"20000" }, + {"/proc/sys/kernel/keys/gc_delay" ,"1" ,TST_SR_IGNORE_MISSING }, + {"/proc/sys/kernel/keys/maxkeys" ,"200" ,TST_SR_IGNORE_MISSING }, + {"/proc/sys/kernel/keys/maxbytes" ,"20000" , +TST_SR_IGNORE_MISSING }, {} }, .bufs = (struct tst_buffers []) {
testcases/kernel/syscalls/bind/bind06.c +1 -1
@@ -110,7 +110,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/syscalls/fork/fork13.c +1 -1
@@ -113,7 +113,7 @@ static struct tst_test test = { .max_runtime = 600, .test_all = check, .save_restore = (const struct tst_path_val []) { - {"!/proc/sys/kernel/pid_max" ,PID_MAX_STR }, + {"/proc/sys/kernel/pid_max" ,PID_MAX_STR ,TST_SR_REQUIRED }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/syscalls/ipc/msgget/msgget03.c +1 -1
@@ -76,7 +76,7 @@ static struct tst_test test = { .cleanup = cleanup, .test_all = verify_msgget, .save_restore = (const struct tst_path_val []){ - {"/proc/sys/kernel/msgmni" ,NULL }, + {"/proc/sys/kernel/msgmni" ,NULL ,0 }, {} } };
testcases/kernel/syscalls/madvise/madvise06.c +1 -1
@@ -239,7 +239,7 @@ static struct tst_test test = { .needs_tmpdir = 1, .needs_root = 1, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/vm/swappiness" ,NULL }, + {"/proc/sys/vm/swappiness" ,NULL ,TST_SR_IGNORE_MISSING }, {} }, .needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
testcases/kernel/syscalls/madvise/madvise08.c +1 -1
@@ -213,7 +213,7 @@ static struct tst_test test = { .needs_root = 1, .forks_child = 1, .save_restore = (const struct tst_path_val []) { - {CORE_PATTERN ,NULL }, + {CORE_PATTERN ,NULL ,0 }, {} }, };
testcases/kernel/syscalls/migrate_pages/migrate_pages02.c +1 -1
@@ -327,7 +327,7 @@ static struct tst_test test = { .test_all = run, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/kernel/numa_balancing" ,"0" }, + {"/proc/sys/kernel/numa_balancing" ,"0" ,TST_SR_IGNORE_MISSING }, {} }, };
testcases/kernel/syscalls/sendto/sendto03.c +1 -1
@@ -218,7 +218,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/syscalls/setsockopt/setsockopt05.c +1 -1
@@ -102,7 +102,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/syscalls/setsockopt/setsockopt06.c +1 -1
@@ -130,7 +130,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/syscalls/setsockopt/setsockopt07.c +1 -1
@@ -143,7 +143,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/syscalls/setsockopt/setsockopt08.c +1 -1
@@ -159,7 +159,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/syscalls/setsockopt/setsockopt09.c +1 -1
@@ -124,7 +124,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {
testcases/kernel/syscalls/syslog/syslog11.c +1 -1
@@ -58,7 +58,7 @@ static void run(unsigned int n)static struct tst_test test = { .test = run, .save_restore = (const struct tst_path_val []) { - {"!/proc/sys/kernel/printk" ,NULL }, + {"/proc/sys/kernel/printk" ,NULL ,TST_SR_REQUIRED }, {} }, .needs_root =1 ,
Signature · 5 lines
2.37.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 17 lines · Martin Doucha
Tests using the .save_restore functionality currently cannot run without root privileges at all because the test will write into the path at least at the end and trigger error, even when the config paths are flagged as optional.
Introduce new
tst_path_valfield for flags and replace path prefix flags with bit flags. Also introduce new flags to control handling of read/write errors and read-only sysfiles and rewritesave_restoreimplementation accordingly.Signed-off-by Martin Doucha <[email protected]>---
This is technically a v2 for
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Quoted 8 lines
I'll send a follow-up patchset to replace
setup()code which requires root privileges without good reason after this patch gets merged. Here I've kept test changes to the minimum needed to maintain currentsave_restorebehavior with the new flags system. The only change in behavior is the use of read-only handling flags where it's clear that the change is desired.Though a few tests should get closer attention during review:
- all KSM tests
I CC-ed Li, but it looked OK to me.
Quoted 2 lines
-
add_key05
-migrate_pages02
This looks OK to me. Though I added some notes to tests that currently don't haveneeds_root = 1 and where this patch introduced TST_SR_IGNORE_RO.
Quoted 52 lines
doc/c-test-api.txt | 38 ++++---- include/tst_sys_conf.h | 15 ++- lib/tst_sys_conf.c | 97 ++++++++++++------- lib/tst_test.c | 3 +- testcases/cve/icmp_rate_limit01.c | 2 +- testcases/kernel/containers/userns/userns08.c | 2 +- testcases/kernel/kvm/kvm_pagefault01.c | 3 +- testcases/kernel/mem/ksm/ksm01.c | 10 +- testcases/kernel/mem/ksm/ksm02.c | 10 +- testcases/kernel/mem/ksm/ksm03.c | 10 +- testcases/kernel/mem/ksm/ksm04.c | 10 +- testcases/kernel/mem/ksm/ksm05.c | 2 +- testcases/kernel/mem/ksm/ksm06.c | 9 +- testcases/kernel/syscalls/add_key/add_key05.c | 7 +- testcases/kernel/syscalls/bind/bind06.c | 2 +- testcases/kernel/syscalls/fork/fork13.c | 2 +- .../kernel/syscalls/ipc/msgget/msgget03.c | 2 +- testcases/kernel/syscalls/madvise/madvise06.c | 2 +- testcases/kernel/syscalls/madvise/madvise08.c | 2 +- .../syscalls/migrate_pages/migrate_pages02.c | 2 +- testcases/kernel/syscalls/sendto/sendto03.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt05.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt06.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt07.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt08.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt09.c | 2 +- testcases/kernel/syscalls/syslog/syslog11.c | 2 +- 27 files changed, 142 insertions(+), 102 deletions(-)doc/c-test-api.txt +3
-11@@ -1602,35 +1602,33 @@ LTP library can be instructed to save and restore value of specified field 'save_restore'. It is a NULL-terminated array of struct 'tst_path_val' where each tst_path_val.path represents a file, whose value is saved at the beginning and restored at the end of the test. -If non-NULL value is passed it is written to the respective file at -the beginning of the test. Only the first line of a specified file -is saved and restored. - -Pathnames can be optionally prefixed to specify how strictly (during -'store') are handled errors: - -* (no prefix) - test ends with 'TCONF', if file doesn't exist -* '?' - test prints info message and continues, - if file doesn't exist or open/read fails -* '!' - test ends with 'TBROK', if file doesn't exist +If non-NULL string is passed in tst_path_val.val, it is written +to the respective file at the beginning of the test. Only the first line +of a specified file is saved and restored.
doc/c-test-api.txt LTP library can be instructed to save and restore value of specified · line 1617
Quoted 10 lines
doc/c-test-api.txt +10
-0+ +By default, the test will end with TCONF if the file is read-only or +does not exist. If the optional write of new value fails, the test will end +with 'TBROK'. This behavior can be changed using tst_path_val.flags: + +* 'TST_SR_FAIL_MISSING' – End test with 'TBROK' if the file does not exist +* 'TST_SR_IGNORE_MISSING' – Continue without saving the file if it does not exist +* 'TST_SR_FAIL_RO' – End test with 'TBROK' if the file is read-only +* 'TST_SR_IGNORE_RO' – Continue without saving the file if it is read-only +* 'TST_SR_IGNORE_ERR' – Ignore errors when writing new value into the file
Maybe split this list into low/high-level flags? I would hope for most tests it would be
sufficient to pick one of high-level flags defined below. There will likely be some
frequently used combinations.
doc/c-test-api.txt LTP library can be instructed to save and restore value of specified · line 1619
Quoted 2 lines
doc/c-test-api.txt +2
-0+* 'TST_SR_REQUIRED' – Equivalent to 'TST_SR_FAIL_MISSING | TST_SR_FAIL_RO' +* 'TST_SR_IF_ACCESS' – Equivalent to 'TST_SR_IGNORE_MISSING | TST_SR_IGNORE_RO'
If this should work as opposite to REQUIRED, maybe 'TST_SR_IF_AVAIL' would fit as name better?
Quoted 42 lines
doc/c-test-api.txt +3
-9'restore' is always strict and will TWARN if it encounters any error. [source,c] ------------------------------------------------------------------------------- -static void setup(void) -{ - FILE_PRINTF("/proc/sys/kernel/core_pattern", "/mypath"); - SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10); -} - static struct tst_test test = { .setup = setup, .save_restore = (const struct tst_path_val[]) { - {"/proc/sys/kernel/core_pattern", NULL}, - {"?/proc/sys/user/max_user_namespaces", NULL}, - {"!/sys/kernel/mm/ksm/run", "1"}, + {"/proc/sys/kernel/core_pattern", NULL, 0}, + {"/proc/sys/user/max_user_namespaces", NULL, TST_SR_IF_ACCESS}, + {"/sys/kernel/mm/ksm/run", "1", TST_SR_REQUIRED}, {} }, };include/tst_sys_conf.h +9
-0@@ -5,14 +5,23 @@#ifndef TST_SYS_CONF_H__ #define TST_SYS_CONF_H__ +#define TST_SR_FAIL_MISSING 0x1 +#define TST_SR_IGNORE_MISSING 0x2 +#define TST_SR_FAIL_RO 0x4 +#define TST_SR_IGNORE_RO 0x8 +#define TST_SR_IGNORE_ERR 0x10 + +#define TST_SR_REQUIRED (TST_SR_FAIL_MISSING | TST_SR_FAIL_RO) +#define TST_SR_IF_ACCESS (TST_SR_IGNORE_MISSING | TST_SR_IGNORE_RO) + struct tst_path_val {
include/tst_sys_conf.h line 24
Quoted 10 lines
include/tst_sys_conf.h +3
-3const char *path;const char *val; +unsigned int flags; }; -int tst_sys_conf_save_str (const char *path,const char *value); -int tst_sys_conf_save (const char *path); -void tst_sys_conf_set (const char *path,const char *value); +void tst_sys_conf_save_str (const char *path,const char *value); +int tst_sys_conf_save (const struct tst_path_val *conf);
Are you planning on using return value in follow-up patch? It does appear to be unused after this patch. Other than that, lib changes look OK.
Quoted 172 lines
include/tst_sys_conf.h +0
-0void tst_sys_conf_restore (int verbose);void tst_sys_conf_dump (void );lib/tst_sys_conf.c +60
-37@@ -20,6 +20,14 @@ struct tst_sys_conf {static struct tst_sys_conf *save_restore_data; +static void print_error (int info_only,const char *err,const char *path) +{ +if (info_only) +tst_res (TINFO , err, path); +else +tst_brk (TBROK |TERRNO , err, path); +} +void tst_sys_conf_dump (void ) {struct tst_sys_conf *i;@@ -28,7 +36,7 @@ void tst_sys_conf_dump(void)tst_res (TINFO ,"%s = %s" , i->path, i->value); } -int tst_sys_conf_save_str (const char *path,const char *value) +void tst_sys_conf_save_str (const char *path,const char *value) {struct tst_sys_conf *n =SAFE_MALLOC (sizeof (*n));@@ -40,45 +48,43 @@ int tst_sys_conf_save_str(const char *path, const char *value) n->next = save_restore_data; save_restore_data = n; - -return 0 ; } -int tst_sys_conf_save (const char *path) +int tst_sys_conf_save (const struct tst_path_val *conf) {char line[PATH_MAX ]; +int ttype, iret;FILE *fp;void *ret; -char flag; -if (!path) +if (!conf || !conf->path)tst_brk (TBROK ,"path is empty" ); - flag = path[0 ]; -if (flag =='?' || flag =='!' ) - path++; - -if (access (path,F_OK ) !=0 ) { -switch (flag) { -case '?' : -tst_res (TINFO ,"Path not found: '%s'" , path); -break ; -case '!' : -tst_brk (TBROK |TERRNO ,"Path not found: '%s'" , path); -break ; -default : -tst_brk (TCONF |TERRNO ,"Path not found: '%s'" , path); +if (access (conf->path,F_OK ) !=0 ) { +if (conf->flags &TST_SR_IGNORE_MISSING ) { +tst_res (TINFO ,"Path not found: %s" , conf->path); +return 1 ; } -return 1 ; + + ttype = (conf->flags &TST_SR_FAIL_MISSING ) ?TBROK :TCONF ; +tst_brk (ttype |TERRNO ,"Path not found: %s" , conf->path); } - fp =fopen (path,"r" ); -if (fp ==NULL ) { -if (flag =='?' ) +if (access (conf->path,W_OK ) !=0 ) { +if (conf->flags &TST_SR_IGNORE_RO ) { +tst_res (TINFO ,"Path is not writable: %s" , conf->path);return 1 ; + } -tst_brk (TBROK |TERRNO ,"Failed to open FILE '%s' for reading" , - path); + ttype = (conf->flags &TST_SR_FAIL_RO ) ?TBROK :TCONF ; +tst_brk (ttype |TERRNO ,"Path is not writable: %s" , conf->path); + } + + fp =fopen (conf->path,"r" ); + +if (fp ==NULL ) { +print_error (conf->flags &TST_SR_IGNORE_ERR , +"Failed to open '%s' for reading" , conf->path);return 1 ; }@@ -86,24 +92,41 @@ int tst_sys_conf_save(const char *path)fclose (fp);if (ret ==NULL ) { -if (flag =='?' ) +if (conf->flags &TST_SR_IGNORE_ERR )return 1 ;tst_brk (TBROK |TERRNO ,"Failed to read anything from '%s'" , - path); + conf->path); } -return tst_sys_conf_save_str (path, line); -} +tst_sys_conf_save_str (conf->path, line); -void tst_sys_conf_set (const char *path,const char *value) -{ -char flag = path[0 ]; -if (flag =='?' || flag =='!' ) - path++; +if (!conf->val) +return 0 ; + + fp =fopen (conf->path,"w" ); + +if (fp ==NULL ) { +print_error (conf->flags &TST_SR_IGNORE_ERR , +"Failed to open '%s' for writing" , conf->path); +return 0 ; + } + + iret =fputs (conf->val, fp); -if (value) -SAFE_FILE_PRINTF (path,"%s" , value); +if (iret <0 ) { +print_error (conf->flags &TST_SR_IGNORE_ERR , +"Failed to write into '%s'" , conf->path); + } + + iret =fclose (fp); + +if (iret <0 ) { +print_error (conf->flags &TST_SR_IGNORE_ERR , +"Failed to close '%s'" , conf->path); + } + +return 0 ; }void tst_sys_conf_restore (int verbose)lib/tst_test.c +1
-2@@ -1181,8 +1181,7 @@ static void do_setup(int argc, char *argv[])const struct tst_path_val *pvl = tst_test->save_restore;while (pvl->path) { -if (!tst_sys_conf_save (pvl->path)) -tst_sys_conf_set (pvl->path, pvl->val); +tst_sys_conf_save (pvl); pvl++; } }testcases/cve/icmp_rate_limit01.c +0
-0
testcases/cve/icmp_rate_limit01.c static struct tst_test test = { · line 272
Quoted 5 lines
testcases/cve/icmp_rate_limit01.c +1
-1@@ -269,7 +269,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS },
This test currently does not have needs_root = 1. Using TST_SR_IGNORE_RO implies that it can work without writing to 'max_user_namespaces', which raises question, why not drop it from save_restore if test can work without it?
In current form, SAFE_TRY_FILE_PRINTF will TBROK for unprivileged user. So this should probably be for now needs_root =1 and TST_SR_IGNORE_MISSING.
Quoted 170 lines
testcases/cve/icmp_rate_limit01.c +0
-0{} }, .tags = (const struct tst_tag[]) {testcases/kernel/containers/userns/userns08.c +1
-1@@ -135,7 +135,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {testcases/kernel/kvm/kvm_pagefault01.c +2
-1@@ -217,7 +217,8 @@ static struct tst_test test = { .cleanup = tst_kvm_cleanup, .needs_root = 1, .save_restore = (const struct tst_path_val []) { - {"?/sys/module/kvm/parameters/tdp_mmu" ,"0" }, + {"/sys/module/kvm/parameters/tdp_mmu" ,"0" , +TST_SR_IGNORE_MISSING }, {} }, .supported_archs = (const char *const []) {testcases/kernel/mem/ksm/ksm01.c +6
-4@@ -80,10 +80,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"?/sys/kernel/mm/ksm/merge_across_nodes" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} }, .needs_kconfigs = (const char *const []){testcases/kernel/mem/ksm/ksm02.c +6
-4@@ -101,10 +101,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"?/sys/kernel/mm/ksm/merge_across_nodes" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} }, .needs_kconfigs = (const char *const []){testcases/kernel/mem/ksm/ksm03.c +6
-4@@ -83,10 +83,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"?/sys/kernel/mm/ksm/merge_across_nodes" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} }, .needs_kconfigs = (const char *const []){testcases/kernel/mem/ksm/ksm04.c +6
-4@@ -103,10 +103,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"?/sys/kernel/mm/ksm/merge_across_nodes" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} }, .needs_kconfigs = (const char *const []){testcases/kernel/mem/ksm/ksm05.c +1
-1@@ -89,7 +89,7 @@ static struct tst_test test = { .test_all = test_ksm, .min_kver = "2.6.32", .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,"1" ,TST_SR_REQUIRED }, {} }, .needs_kconfigs = (const char *const []){testcases/kernel/mem/ksm/ksm06.c +5
-4@@ -137,10 +137,11 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"?/sys/kernel/mm/ksm/max_page_sharing" ,NULL }, - {"!/sys/kernel/mm/ksm/run" ,NULL }, - {"!/sys/kernel/mm/ksm/sleep_millisecs" ,NULL }, - {"/sys/kernel/mm/ksm/merge_across_nodes" ,NULL }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,NULL ,0 }, {} }, .needs_kconfigs = (const char *const []){testcases/kernel/syscalls/add_key/add_key05.c +4
-3@@ -220,9 +220,10 @@ static struct tst_test test = { .forks_child = 1, .cleanup = cleanup, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/kernel/keys/gc_delay" ,"1" }, - {"?/proc/sys/kernel/keys/maxkeys" ,"200" }, - {"?/proc/sys/kernel/keys/maxbytes" ,"20000" }, + {"/proc/sys/kernel/keys/gc_delay" ,"1" ,TST_SR_IGNORE_MISSING }, + {"/proc/sys/kernel/keys/maxkeys" ,"200" ,TST_SR_IGNORE_MISSING }, + {"/proc/sys/kernel/keys/maxbytes" ,"20000" , +TST_SR_IGNORE_MISSING }, {} }, .bufs = (struct tst_buffers []) {testcases/kernel/syscalls/bind/bind06.c +0
-0
testcases/kernel/syscalls/bind/bind06.c static struct tst_test test = { · line 113
Quoted 5 lines
testcases/kernel/syscalls/bind/bind06.c +1
-1@@ -110,7 +110,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS },
same as icmp_rate_limit01
Quoted 73 lines
testcases/kernel/syscalls/bind/bind06.c +0
-0{} }, .tags = (const struct tst_tag[]) {testcases/kernel/syscalls/fork/fork13.c +1
-1@@ -113,7 +113,7 @@ static struct tst_test test = { .max_runtime = 600, .test_all = check, .save_restore = (const struct tst_path_val []) { - {"!/proc/sys/kernel/pid_max" ,PID_MAX_STR }, + {"/proc/sys/kernel/pid_max" ,PID_MAX_STR ,TST_SR_REQUIRED }, {} }, .tags = (const struct tst_tag []) {testcases/kernel/syscalls/ipc/msgget/msgget03.c +1
-1@@ -76,7 +76,7 @@ static struct tst_test test = { .cleanup = cleanup, .test_all = verify_msgget, .save_restore = (const struct tst_path_val []){ - {"/proc/sys/kernel/msgmni" ,NULL }, + {"/proc/sys/kernel/msgmni" ,NULL ,0 }, {} } };testcases/kernel/syscalls/madvise/madvise06.c +1
-1@@ -239,7 +239,7 @@ static struct tst_test test = { .needs_tmpdir = 1, .needs_root = 1, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/vm/swappiness" ,NULL }, + {"/proc/sys/vm/swappiness" ,NULL ,TST_SR_IGNORE_MISSING }, {} }, .needs_cgroup_ctrls = (const char *const []){ "memory", NULL },testcases/kernel/syscalls/madvise/madvise08.c +1
-1@@ -213,7 +213,7 @@ static struct tst_test test = { .needs_root = 1, .forks_child = 1, .save_restore = (const struct tst_path_val []) { - {CORE_PATTERN ,NULL }, + {CORE_PATTERN ,NULL ,0 }, {} }, };testcases/kernel/syscalls/migrate_pages/migrate_pages02.c +1
-1@@ -327,7 +327,7 @@ static struct tst_test test = { .test_all = run, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/kernel/numa_balancing" ,"0" }, + {"/proc/sys/kernel/numa_balancing" ,"0" ,TST_SR_IGNORE_MISSING }, {} }, };testcases/kernel/syscalls/sendto/sendto03.c +0
-0
testcases/kernel/syscalls/sendto/sendto03.c static struct tst_test test = { · line 221
Quoted 5 lines
testcases/kernel/syscalls/sendto/sendto03.c +1
-1@@ -218,7 +218,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS },
same here and for all setsockopt tests
Quoted 84 lines
testcases/kernel/syscalls/sendto/sendto03.c +0
-0{} }, .tags = (const struct tst_tag[]) {testcases/kernel/syscalls/setsockopt/setsockopt05.c +1
-1@@ -102,7 +102,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {testcases/kernel/syscalls/setsockopt/setsockopt06.c +1
-1@@ -130,7 +130,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {testcases/kernel/syscalls/setsockopt/setsockopt07.c +1
-1@@ -143,7 +143,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {testcases/kernel/syscalls/setsockopt/setsockopt08.c +1
-1@@ -159,7 +159,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {testcases/kernel/syscalls/setsockopt/setsockopt09.c +1
-1@@ -124,7 +124,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} }, .tags = (const struct tst_tag []) {testcases/kernel/syscalls/syslog/syslog11.c +1
-2@@ -58,7 +58,7 @@ static void run(unsigned int n)static struct tst_test test = { .test = run, .save_restore = (const struct tst_path_val []) { - {"!/proc/sys/kernel/printk" ,NULL }, + {"/proc/sys/kernel/printk" ,NULL ,TST_SR_REQUIRED }, {} }, .needs_root =1 , --2.37.3
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 94 lines · Jan Stancek
Quoted 17 lines · Martin Doucha
Tests using the .save_restore functionality currently cannot run without root privileges at all because the test will write into the path at least at the end and trigger error, even when the config paths are flagged as optional.
Introduce new
tst_path_valfield for flags and replace path prefix flags with bit flags. Also introduce new flags to control handling of read/write errors and read-only sysfiles and rewritesave_restoreimplementation accordingly.Signed-off-by Martin Doucha <[email protected]>---
This is technically a v2 for
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/Quoted 8 lines
I'll send a follow-up patchset to replace
setup()code which requires root privileges without good reason after this patch gets merged. Here I've kept test changes to the minimum needed to maintain currentsave_restorebehavior with the new flags system. The only change in behavior is the use of read-only handling flags where it's clear that the change is desired.Though a few tests should get closer attention during review:
- all KSM testsI CC-ed Li, but it looked OK to me.
Quoted 2 lines
-
add_key05
-migrate_pages02This looks OK to me. Though I added some notes to tests that currently don't have
needs_root= 1 and where this patch introducedTST_SR_IGNORE_RO.Quoted 60 lines
doc/c-test-api.txt | 38 ++++---- include/tst_sys_conf.h | 15 ++- lib/tst_sys_conf.c | 97 ++++++++++++------- lib/tst_test.c | 3 +- testcases/cve/icmp_rate_limit01.c | 2 +- testcases/kernel/containers/userns/userns08.c | 2 +- testcases/kernel/kvm/kvm_pagefault01.c | 3 +- testcases/kernel/mem/ksm/ksm01.c | 10 +- testcases/kernel/mem/ksm/ksm02.c | 10 +- testcases/kernel/mem/ksm/ksm03.c | 10 +- testcases/kernel/mem/ksm/ksm04.c | 10 +- testcases/kernel/mem/ksm/ksm05.c | 2 +- testcases/kernel/mem/ksm/ksm06.c | 9 +- testcases/kernel/syscalls/add_key/add_key05.c | 7 +- testcases/kernel/syscalls/bind/bind06.c | 2 +- testcases/kernel/syscalls/fork/fork13.c | 2 +- .../kernel/syscalls/ipc/msgget/msgget03.c | 2 +- testcases/kernel/syscalls/madvise/madvise06.c | 2 +- testcases/kernel/syscalls/madvise/madvise08.c | 2 +- .../syscalls/migrate_pages/migrate_pages02.c | 2 +- testcases/kernel/syscalls/sendto/sendto03.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt05.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt06.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt07.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt08.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt09.c | 2 +- testcases/kernel/syscalls/syslog/syslog11.c | 2 +- 27 files changed, 142 insertions(+), 102 deletions(-)doc/c-test-api.txt +11
-11@@ -1602,35 +1602,33 @@ LTP library can be instructed to save and restore value of specified field 'save_restore'. It is a NULL-terminated array of struct 'tst_path_val' where each tst_path_val.path represents a file, whose value is saved at the beginning and restored at the end of the test. -If non-NULL value is passed it is written to the respective file at -the beginning of the test. Only the first line of a specified file -is saved and restored. - -Pathnames can be optionally prefixed to specify how strictly (during -'store') are handled errors: - -* (no prefix) - test ends with 'TCONF', if file doesn't exist -* '?' - test prints info message and continues, - if file doesn't exist or open/read fails -* '!' - test ends with 'TBROK', if file doesn't exist +If non-NULL string is passed in tst_path_val.val, it is written +to the respective file at the beginning of the test. Only the first line +of a specified file is saved and restored. + +By default, the test will end with TCONF if the file is read-only or +does not exist. If the optional write of new value fails, the test will end +with 'TBROK'. This behavior can be changed using tst_path_val.flags: + +* 'TST_SR_FAIL_MISSING' – End test with 'TBROK' if the file does not exist +* 'TST_SR_IGNORE_MISSING' – Continue without saving the file if it does not exist +* 'TST_SR_FAIL_RO' – End test with 'TBROK' if the file is read-only
Quoted 8 lines
doc/c-test-api.txt LTP library can be instructed to save and restore value of specified · line 1617
Quoted 2 lines
doc/c-test-api.txt +2
-0+* 'TST_SR_IGNORE_RO' – Continue without saving the file if it is read-only +* 'TST_SR_IGNORE_ERR' – Ignore errors when writing new value into the fileMaybe split this list into low/high-level flags? I would hope for most tests it would be
sufficient to pick one of high-level flags defined below. There will likely be some
frequently used combinations.
Splitting the list might help if more entries get added later but for now the number of flags is fairly short so let's keep it simple.
Quoted 5 lines
doc/c-test-api.txt LTP library can be instructed to save and restore value of specified · line 1619
Quoted 2 lines
doc/c-test-api.txt +2
-0+* 'TST_SR_REQUIRED' – Equivalent to 'TST_SR_FAIL_MISSING | TST_SR_FAIL_RO' +* 'TST_SR_IF_ACCESS' – Equivalent to 'TST_SR_IGNORE_MISSING | TST_SR_IGNORE_RO'If this should work as opposite to REQUIRED, maybe '
TST_SR_IF_AVAIL' would fit as name better?
I thought about something like TST_SR_IF_AVAIL while writing this patch but it sounds too much like a synonym for TST_SR_IGNORE_MISSING. Naming it TST_SR_IF_ACCESS puts more emphasis on access permission checks.
Quoted 8 lines
doc/c-test-api.txt LTP library can be instructed to save and restore value of specified · line 1621
Quoted 5 lines
doc/c-test-api.txt +2
-3-int tst_sys_conf_save_str(const char *path, const char *value); -int tst_sys_conf_save(const char *path); -void tst_sys_conf_set(const char *path, const char *value); +void tst_sys_conf_save_str(const char *path, const char *value); +int tst_sys_conf_save(const struct tst_path_val *conf);Are you planning on using return value in follow-up patch? It does appear to be unused after this patch. Other than that, lib changes look OK.
I have no plans to use the return value myself so feel free to change the return type to void during merge. I've kept the old return value just in case it'll be used for something in the future.
Quoted 15 lines
testcases/cve/icmp_rate_limit01.c static struct tst_test test = { · line 272
Quoted 10 lines
testcases/cve/icmp_rate_limit01.c +1
-1@@ -269,7 +269,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS },This test currently does not have
needs_root= 1. UsingTST_SR_IGNORE_ROimplies that it can work without writing to 'max_user_namespaces', which raises question, why not drop it fromsave_restoreif test can work without it?
Quoted 2 lines
In current form,
SAFE_TRY_FILE_PRINTFwill TBROK for unprivileged user. So this should probably be for nowneeds_root=1 andTST_SR_IGNORE_MISSING.
As I've explained right under the commit message, the setup() code for max_user_namespaces will be the subject of my follow-up patchset. In this patch, I'm doing only the minimum necessary API update that preserves current behavior. TCONF on read-only sysfile is not desirable in these network tests.
Signature · 11 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 129 lines · Martin Doucha
Tests using the .save_restore functionality currently cannot run without root privileges at all because the test will write into the path at least at the end and trigger error, even when the config paths are flagged as optional.
Introduce new
tst_path_valfield for flags and replace path prefix flags with bit flags. Also introduce new flags to control handling of read/write errors and read-only sysfiles and rewritesave_restoreimplementation accordingly.Signed-off-by Martin Doucha <[email protected]>---
This is technically a v2 for
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
I'll send a follow-up patchset to replace
setup()code which requires root privileges without good reason after this patch gets merged. Here I've kept test changes to the minimum needed to maintain currentsave_restorebehavior
with the new flags system. The only change in behavior is the use of read-only
handling flags where it's clear that the change is desired.Though a few tests should get closer attention during review:
- all KSM tests
-add_key05
-migrate_pages02doc/c-test-api.txt | 38 ++++---- include/tst_sys_conf.h | 15 ++- lib/tst_sys_conf.c | 97 ++++++++++++------- lib/tst_test.c | 3 +- testcases/cve/icmp_rate_limit01.c | 2 +- testcases/kernel/containers/userns/userns08.c | 2 +- testcases/kernel/kvm/kvm_pagefault01.c | 3 +- testcases/kernel/mem/ksm/ksm01.c | 10 +- testcases/kernel/mem/ksm/ksm02.c | 10 +- testcases/kernel/mem/ksm/ksm03.c | 10 +- testcases/kernel/mem/ksm/ksm04.c | 10 +- testcases/kernel/mem/ksm/ksm05.c | 2 +- testcases/kernel/mem/ksm/ksm06.c | 9 +- testcases/kernel/syscalls/add_key/add_key05.c | 7 +- testcases/kernel/syscalls/bind/bind06.c | 2 +- testcases/kernel/syscalls/fork/fork13.c | 2 +- .../kernel/syscalls/ipc/msgget/msgget03.c | 2 +- testcases/kernel/syscalls/madvise/madvise06.c | 2 +- testcases/kernel/syscalls/madvise/madvise08.c | 2 +- .../syscalls/migrate_pages/migrate_pages02.c | 2 +- testcases/kernel/syscalls/sendto/sendto03.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt05.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt06.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt07.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt08.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt09.c | 2 +- testcases/kernel/syscalls/syslog/syslog11.c | 2 +- 27 files changed, 142 insertions(+), 102 deletions(-)doc/c-test-api.txt +0
-0@@ -1602,35 +1602,33 @@ LTP library can be instructed to save and restorevalue of specified
field 'save_restore'. It is a NULL-terminated array of struct 'tst_path_val' where each tst_path_val.path represents a file, whose value is saved at the beginning and restored at the end of the test.doc/c-test-api.txt +6
-11-If non-NULL value is passed it is written to the respective file at -the beginning of the test. Only the first line of a specified file -is saved and restored. - -Pathnames can be optionally prefixed to specify how strictly (during -'store') are handled errors: - -* (no prefix) - test ends with 'TCONF', if file doesn't exist -* '?' - test prints info message and continues, - if file doesn't exist or open/read fails -* '!' - test ends with 'TBROK', if file doesn't exist +If non-NULL string is passed in tst_path_val.val, it is written +to the respective file at the beginning of the test. Only the first line +of a specified file is saved and restored. + +By default, the test will end with TCONF if the file is read-only or +does not exist. If the optional write of new value fails, the test willend
doc/c-test-api.txt +4
-0+with 'TBROK'. This behavior can be changed using tst_path_val.flags: + +* 'TST_SR_FAIL_MISSING' – End test with 'TBROK' if the file does not exist +* 'TST_SR_IGNORE_MISSING' – Continue without saving the file if it doesnot exist
doc/c-test-api.txt +5
-0+* 'TST_SR_FAIL_RO' – End test with 'TBROK' if the file is read-only +* 'TST_SR_IGNORE_RO' – Continue without saving the file if it is read-only +* 'TST_SR_IGNORE_ERR' – Ignore errors when writing new value into the file +* 'TST_SR_REQUIRED' – Equivalent to 'TST_SR_FAIL_MISSING | TST_SR_FAIL_RO' +* 'TST_SR_IF_ACCESS' – Equivalent to 'TST_SR_IGNORE_MISSING |
TST_SR_IGNORE_RO''restore' is always strict and will TWARN if it encounters any error.
[source,c]
-------------------------------------------------------------------------------
doc/c-test-api.txt +0
-4-static void setup(void) -{ - FILE_PRINTF("/proc/sys/kernel/core_pattern", "/mypath"); - SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d",10);
doc/c-test-api.txt +2
-5-} - static struct tst_test test = { .setup = setup, .save_restore = (const struct tst_path_val[]) { - {"/proc/sys/kernel/core_pattern", NULL}, - {"?/proc/sys/user/max_user_namespaces", NULL}, - {"!/sys/kernel/mm/ksm/run", "1"}, + {"/proc/sys/kernel/core_pattern", NULL, 0}, + {"/proc/sys/user/max_user_namespaces", NULL,
TST_SR_IF_ACCESS},doc/c-test-api.txt +1
-0+ {"/sys/kernel/mm/ksm/run", "1", TST_SR_REQUIRED}, {} }, };include/tst_sys_conf.h +0
-0
include/tst_sys_conf.h line 13
Quoted 9 lines
include/tst_sys_conf.h +5
-0@@ -5,14 +5,23 @@#ifndef TST_SYS_CONF_H__ #define TST_SYS_CONF_H__ +#define TST_SR_FAIL_MISSING 0x1 +#define TST_SR_IGNORE_MISSING 0x2 +#define TST_SR_FAIL_RO 0x4 +#define TST_SR_IGNORE_RO 0x8 +#define TST_SR_IGNORE_ERR 0x10
This is a good thought to split the permission and respectively handle them, but I feel that these names are a bit ambiguous.
For example TST_SR_IGNORE_RO, I was puzzled a while when reading it in the below code, it can be thought of as ignoring the READ_ONLY permission if just from the literal meaning.
We need to find more precise names.
include/tst_sys_conf.h line 22
Quoted 4 lines
include/tst_sys_conf.h +3
-0+ +#define TST_SR_REQUIRED (TST_SR_FAIL_MISSING | TST_SR_FAIL_RO) +#define TST_SR_IF_ACCESS (TST_SR_IGNORE_MISSING | TST_SR_IGNORE_RO)
Here as well, especially these two will be more frequently used in testcase writing.
Quoted 4 lines
include/tst_sys_conf.h +1
-0+struct tst_path_val {const char *path;
include/tst_sys_conf.h
Quoted 10 lines
include/tst_sys_conf.h +1
-3const char *val; +unsigned int flags; }; -int tst_sys_conf_save_str (const char *path,const char *value); -int tst_sys_conf_save (const char *path); -void tst_sys_conf_set (const char *path,const char *value);
I made it an external function for wide use by users, but seems that's a bit redundant, we have SAFE_FILE_PRINTF instead, so here I'm OK with removing it.
+void tst_sys_conf_save_str(const char *path, const char *value);
Quoted 1 line
Do we have any other place to use tst_sys_conf_save_str? If no, I would suggest declaring it only as a static function in the tst_sys_conf.c
Anyway, the basic method of this patch is what I liked, and the rest part (+ fixed with Jan's comments) looks good.
Quoted 567 lines
include/tst_sys_conf.h +1
-0+int tst_sys_conf_save (const struct tst_path_val *conf);void tst_sys_conf_restore (int verbose);void tst_sys_conf_dump (void );lib/tst_sys_conf.c +23
-25@@ -20,6 +20,14 @@ struct tst_sys_conf {static struct tst_sys_conf *save_restore_data; +static void print_error (int info_only,const char *err,const char *path) +{ +if (info_only) +tst_res (TINFO , err, path); +else +tst_brk (TBROK |TERRNO , err, path); +} +void tst_sys_conf_dump (void ) {struct tst_sys_conf *i;@@ -28,7 +36,7 @@ void tst_sys_conf_dump(void)tst_res (TINFO ,"%s = %s" , i->path, i->value); } -int tst_sys_conf_save_str (const char *path,const char *value) +void tst_sys_conf_save_str (const char *path,const char *value) {struct tst_sys_conf *n =SAFE_MALLOC (sizeof (*n));@@ -40,45 +48,43 @@ int tst_sys_conf_save_str(const char *path, const char *value) n->next = save_restore_data; save_restore_data = n; - -return 0 ; } -int tst_sys_conf_save (const char *path) +int tst_sys_conf_save (const struct tst_path_val *conf) {char line[PATH_MAX ]; +int ttype, iret;FILE *fp;void *ret; -char flag; -if (!path) +if (!conf || !conf->path)tst_brk (TBROK ,"path is empty" ); - flag = path[0 ]; -if (flag =='?' || flag =='!' ) - path++; - -if (access (path,F_OK ) !=0 ) { -switch (flag) { -case '?' : -tst_res (TINFO ,"Path not found: '%s'" , path); -break ; -case '!' : -tst_brk (TBROK |TERRNO ,"Path not found: '%s'" , path); -break ; -default : -tst_brk (TCONF |TERRNO ,"Path not found: '%s'" , path); +if (access (conf->path,F_OK ) !=0 ) { +if (conf->flags &TST_SR_IGNORE_MISSING ) { +tst_res (TINFO ,"Path not found: %s" , conf->path); +return 1 ; } -return 1 ; + + ttype = (conf->flags &TST_SR_FAIL_MISSING ) ?TBROK :TCONF ; +tst_brk (ttype |TERRNO ,"Path not found: %s" , conf->path); } - fp =fopen (path,"r" ); -if (fp ==NULL ) { -if (flag =='?' ) +if (access (conf->path,W_OK ) !=0 ) { +if (conf->flags &TST_SR_IGNORE_RO ) { +tst_res (TINFO ,"Path is not writable: %s" , conf->path);return 1 ; + } - tst_brk(TBROK | TERRNO, "Failed to open FILE '%s' forreading",
lib/tst_sys_conf.c +2
-1- path); + ttype = (conf->flags &TST_SR_FAIL_RO ) ?TBROK :TCONF ; + tst_brk(ttype | TERRNO, "Path is not writable: %s",
conf->path);lib/tst_sys_conf.c +35
-11+ } + + fp =fopen (conf->path,"r" ); + +if (fp ==NULL ) { +print_error (conf->flags &TST_SR_IGNORE_ERR , +"Failed to open '%s' for reading" , conf->path);return 1 ; }@@ -86,24 +92,41 @@ int tst_sys_conf_save(const char *path)fclose (fp);if (ret ==NULL ) { -if (flag =='?' ) +if (conf->flags &TST_SR_IGNORE_ERR )return 1 ; tst_brk(TBROK | TERRNO, "Failed to read anything from '%s'", - path); + conf->path); } -return tst_sys_conf_save_str (path, line); -} +tst_sys_conf_save_str (conf->path, line); -void tst_sys_conf_set (const char *path,const char *value) -{ -char flag = path[0 ]; -if (flag =='?' || flag =='!' ) - path++; +if (!conf->val) +return 0 ; + + fp =fopen (conf->path,"w" ); + +if (fp ==NULL ) { +print_error (conf->flags &TST_SR_IGNORE_ERR , +"Failed to open '%s' for writing" , conf->path); +return 0 ; + } + + iret =fputs (conf->val, fp); -if (value) -SAFE_FILE_PRINTF (path,"%s" , value); +if (iret <0 ) { +print_error (conf->flags &TST_SR_IGNORE_ERR , +"Failed to write into '%s'" , conf->path); + } + + iret =fclose (fp); + +if (iret <0 ) { +print_error (conf->flags &TST_SR_IGNORE_ERR , +"Failed to close '%s'" , conf->path); + } + +return 0 ; }void
tst_sys_conf_restore(int verbose)lib/tst_test.c +1
-2@@ -1181,8 +1181,7 @@ static void do_setup(int argc, char *argv[])const struct tst_path_val *pvl = tst_test->save_restore;while (pvl->path) { -if (!tst_sys_conf_save (pvl->path)) -tst_sys_conf_set (pvl->path, pvl->val); +tst_sys_conf_save (pvl); pvl++; } }testcases/cve/icmp_rate_limit01.c +1
-1@@ -269,7 +269,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} },.tags = (const struct tst_tag[]) {testcases/kernel/containers/userns/userns08.c +1
-1@@ -135,7 +135,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} },.tags = (const struct tst_tag[]) {testcases/kernel/kvm/kvm_pagefault01.c +2
-1@@ -217,7 +217,8 @@ static struct tst_test test = { .cleanup = tst_kvm_cleanup, .needs_root = 1, .save_restore = (const struct tst_path_val []) { - {"?/sys/module/kvm/parameters/tdp_mmu" ,"0" }, + {"/sys/module/kvm/parameters/tdp_mmu" ,"0" , +TST_SR_IGNORE_MISSING }, {} }, .supported_archs = (const char *const []) {testcases/kernel/mem/ksm/ksm01.c +6
-4@@ -80,10 +80,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run", NULL}, - {"!/sys/kernel/mm/ksm/sleep_millisecs", NULL}, - {"?/sys/kernel/mm/ksm/max_page_sharing", NULL}, - {"?/sys/kernel/mm/ksm/merge_across_nodes", "1"}, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} },.needs_kconfigs = (const char *const[]){testcases/kernel/mem/ksm/ksm02.c +6
-4@@ -101,10 +101,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run", NULL}, - {"!/sys/kernel/mm/ksm/sleep_millisecs", NULL}, - {"?/sys/kernel/mm/ksm/max_page_sharing", NULL}, - {"?/sys/kernel/mm/ksm/merge_across_nodes", "1"}, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} },.needs_kconfigs = (const char *const[]){testcases/kernel/mem/ksm/ksm03.c +6
-4@@ -83,10 +83,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run", NULL}, - {"!/sys/kernel/mm/ksm/sleep_millisecs", NULL}, - {"?/sys/kernel/mm/ksm/max_page_sharing", NULL}, - {"?/sys/kernel/mm/ksm/merge_across_nodes", "1"}, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} },.needs_kconfigs = (const char *const[]){testcases/kernel/mem/ksm/ksm04.c +6
-4@@ -103,10 +103,12 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run", NULL}, - {"!/sys/kernel/mm/ksm/sleep_millisecs", NULL}, - {"?/sys/kernel/mm/ksm/max_page_sharing", NULL}, - {"?/sys/kernel/mm/ksm/merge_across_nodes", "1"}, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,"1" , +TST_SR_IGNORE_MISSING }, {} },.needs_kconfigs = (const char *const[]){testcases/kernel/mem/ksm/ksm05.c +1
-1@@ -89,7 +89,7 @@ static struct tst_test test = { .test_all = test_ksm, .min_kver = "2.6.32", .save_restore = (const struct tst_path_val []) { - {"!/sys/kernel/mm/ksm/run" ,"1" }, + {"/sys/kernel/mm/ksm/run" ,"1" ,TST_SR_REQUIRED }, {} }, .needs_kconfigs = (const char *const []){testcases/kernel/mem/ksm/ksm06.c +5
-4@@ -137,10 +137,11 @@ static struct tst_test test = { }, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"?/sys/kernel/mm/ksm/max_page_sharing", NULL}, - {"!/sys/kernel/mm/ksm/run", NULL}, - {"!/sys/kernel/mm/ksm/sleep_millisecs", NULL}, - {"/sys/kernel/mm/ksm/merge_across_nodes", NULL}, + {"/sys/kernel/mm/ksm/max_page_sharing" ,NULL , +TST_SR_IGNORE_MISSING }, + {"/sys/kernel/mm/ksm/run" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/sleep_millisecs" ,NULL ,TST_SR_REQUIRED }, + {"/sys/kernel/mm/ksm/merge_across_nodes" ,NULL ,0 }, {} },.needs_kconfigs = (const char *const[]){testcases/kernel/syscalls/add_key/add_key05.c +4
-3@@ -220,9 +220,10 @@ static struct tst_test test = { .forks_child = 1, .cleanup = cleanup, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/kernel/keys/gc_delay" ,"1" }, - {"?/proc/sys/kernel/keys/maxkeys" ,"200" }, - {"?/proc/sys/kernel/keys/maxbytes" ,"20000" }, + {"/proc/sys/kernel/keys/gc_delay" ,"1" ,TST_SR_IGNORE_MISSING }, + {"/proc/sys/kernel/keys/maxkeys" ,"200" ,TST_SR_IGNORE_MISSING }, + {"/proc/sys/kernel/keys/maxbytes" ,"20000" , +TST_SR_IGNORE_MISSING }, {}}, .bufs = (struct tst_buffers []) {testcases/kernel/syscalls/bind/bind06.c +1
-1@@ -110,7 +110,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} },.tags = (const struct tst_tag[]) {testcases/kernel/syscalls/fork/fork13.c +1
-1@@ -113,7 +113,7 @@ static struct tst_test test = { .max_runtime = 600, .test_all = check, .save_restore = (const struct tst_path_val []) { - {"!/proc/sys/kernel/pid_max" ,PID_MAX_STR }, + {"/proc/sys/kernel/pid_max" ,PID_MAX_STR ,TST_SR_REQUIRED }, {} }, .tags = (const struct tst_tag []) {testcases/kernel/syscalls/ipc/msgget/msgget03.c +1
-1@@ -76,7 +76,7 @@ static struct tst_test test = { .cleanup = cleanup, .test_all = verify_msgget, .save_restore = (const struct tst_path_val []){ - {"/proc/sys/kernel/msgmni" ,NULL }, + {"/proc/sys/kernel/msgmni" ,NULL ,0 }, {} } };testcases/kernel/syscalls/madvise/madvise06.c +1
-1@@ -239,7 +239,7 @@ static struct tst_test test = { .needs_tmpdir = 1, .needs_root = 1, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/vm/swappiness" ,NULL }, + {"/proc/sys/vm/swappiness" ,NULL ,TST_SR_IGNORE_MISSING }, {} }, .needs_cgroup_ctrls = (const char *const []){ "memory", NULL },testcases/kernel/syscalls/madvise/madvise08.c +1
-1@@ -213,7 +213,7 @@ static struct tst_test test = { .needs_root = 1, .forks_child = 1, .save_restore = (const struct tst_path_val []) { - {CORE_PATTERN ,NULL }, + {CORE_PATTERN ,NULL ,0 }, {} }, };testcases/kernel/syscalls/migrate_pages/migrate_pages02.c +1
-1@@ -327,7 +327,7 @@ static struct tst_test test = { .test_all = run, .setup = setup, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/kernel/numa_balancing", "0"}, + {"/proc/sys/kernel/numa_balancing" ,"0" ,TST_SR_IGNORE_MISSING }, {} },};
testcases/kernel/syscalls/sendto/sendto03.c +1
-1@@ -218,7 +218,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} },.tags = (const struct tst_tag[]) {testcases/kernel/syscalls/setsockopt/setsockopt05.c +1
-1@@ -102,7 +102,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} },.tags = (const struct tst_tag[]) {testcases/kernel/syscalls/setsockopt/setsockopt06.c +1
-1@@ -130,7 +130,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} },.tags = (const struct tst_tag[]) {testcases/kernel/syscalls/setsockopt/setsockopt07.c +1
-1@@ -143,7 +143,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} },.tags = (const struct tst_tag[]) {testcases/kernel/syscalls/setsockopt/setsockopt08.c +1
-1@@ -159,7 +159,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} },.tags = (const struct tst_tag[]) {testcases/kernel/syscalls/setsockopt/setsockopt09.c +1
-1@@ -124,7 +124,7 @@ static struct tst_test test = {NULL }, .save_restore = (const struct tst_path_val []) { - {"?/proc/sys/user/max_user_namespaces" ,NULL }, + {"/proc/sys/user/max_user_namespaces" ,NULL ,TST_SR_IF_ACCESS }, {} },.tags = (const struct tst_tag[]) {testcases/kernel/syscalls/syslog/syslog11.c +1
-2@@ -58,7 +58,7 @@ static void run(unsigned int n)static struct tst_test test = { .test = run, .save_restore = (const struct tst_path_val []) { - {"!/proc/sys/kernel/printk" ,NULL }, + {"/proc/sys/kernel/printk" ,NULL ,TST_SR_REQUIRED }, {} }, .needs_root =1 , --2.37.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 6 lines · Li Wang
This is a good thought to split the permission and respectively handle them, but I feel that these names are a bit ambiguous.
For example
TST_SR_IGNORE_RO, I was puzzled a while when reading it in the below code, it can be thought of as ignoring theREAD_ONLYpermission if just from the literal meaning.
The only sensible way to ignore read-only permissions is to skip writing into the file. Especially when the test can run without root privileges.
Quoted 8 lines
We need to find more precise names.
+
+#defineTST_SR_REQUIRED(TST_SR_FAIL_MISSING|TST_SR_FAIL_RO) +#defineTST_SR_IF_ACCESS(TST_SR_IGNORE_MISSING|TST_SR_IGNORE_RO)Here as well, especially these two will be more frequently used in testcase writing.
I am open to suggestions.
Quoted 6 lines
+void tst_sys_conf_save_str(const char *path, const char *value);Do we have any other place to use
tst_sys_conf_save_str? If no, I would suggest declaring it only as a static function in thetst_sys_conf.c
I'm not sure such change belongs in this patch but feel free to submit another patch for it.
Signature · 11 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Jan Stancek
Acked-byQuoted 137 lines · Li Wang
Quoted 120 lines · Martin Doucha
Tests using the .save_restore functionality currently cannot run without root privileges at all because the test will write into the path at least at the end and trigger error, even when the config paths are flagged as optional.
Introduce new
tst_path_valfield for flags and replace path prefix flags with bit flags. Also introduce new flags to control handling of read/write errors and read-only sysfiles and rewritesave_restoreimplementation accordingly.Signed-off-by Martin Doucha <[email protected]>---
This is technically a v2 for
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/I'll send a follow-up patchset to replace
setup()code which requires root privileges without good reason after this patch gets merged. Here I've kept test changes to the minimum needed to maintain currentsave_restorebehavior with the new flags system. The only change in behavior is the use of read-only handling flags where it's clear that the change is desired.Though a few tests should get closer attention during review:
- all KSM tests
-add_key05
-migrate_pages02doc/c-test-api.txt | 38 ++++---- include/tst_sys_conf.h | 15 ++- lib/tst_sys_conf.c | 97 ++++++++++++------- lib/tst_test.c | 3 +- testcases/cve/icmp_rate_limit01.c | 2 +- testcases/kernel/containers/userns/userns08.c | 2 +- testcases/kernel/kvm/kvm_pagefault01.c | 3 +- testcases/kernel/mem/ksm/ksm01.c | 10 +- testcases/kernel/mem/ksm/ksm02.c | 10 +- testcases/kernel/mem/ksm/ksm03.c | 10 +- testcases/kernel/mem/ksm/ksm04.c | 10 +- testcases/kernel/mem/ksm/ksm05.c | 2 +- testcases/kernel/mem/ksm/ksm06.c | 9 +- testcases/kernel/syscalls/add_key/add_key05.c | 7 +- testcases/kernel/syscalls/bind/bind06.c | 2 +- testcases/kernel/syscalls/fork/fork13.c | 2 +- .../kernel/syscalls/ipc/msgget/msgget03.c | 2 +- testcases/kernel/syscalls/madvise/madvise06.c | 2 +- testcases/kernel/syscalls/madvise/madvise08.c | 2 +- .../syscalls/migrate_pages/migrate_pages02.c | 2 +- testcases/kernel/syscalls/sendto/sendto03.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt05.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt06.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt07.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt08.c | 2 +- .../kernel/syscalls/setsockopt/setsockopt09.c | 2 +- testcases/kernel/syscalls/syslog/syslog11.c | 2 +- 27 files changed, 142 insertions(+), 102 deletions(-)doc/c-test-api.txt +18
-20@@ -1602,35 +1602,33 @@ LTP library can be instructed to save and restore value of specified field 'save_restore'. It is a NULL-terminated array of struct 'tst_path_val' where each tst_path_val.path represents a file, whose value is saved at the beginning and restored at the end of the test. -If non-NULL value is passed it is written to the respective file at -the beginning of the test. Only the first line of a specified file -is saved and restored. - -Pathnames can be optionally prefixed to specify how strictly (during -'store') are handled errors: - -* (no prefix) - test ends with 'TCONF', if file doesn't exist -* '?' - test prints info message and continues, - if file doesn't exist or open/read fails -* '!' - test ends with 'TBROK', if file doesn't exist +If non-NULL string is passed in tst_path_val.val, it is written +to the respective file at the beginning of the test. Only the first line +of a specified file is saved and restored. + +By default, the test will end with TCONF if the file is read-only or +does not exist. If the optional write of new value fails, the test will end +with 'TBROK'. This behavior can be changed using tst_path_val.flags: + +* 'TST_SR_FAIL_MISSING' – End test with 'TBROK' if the file does not exist +* 'TST_SR_IGNORE_MISSING' – Continue without saving the file if it does not exist +* 'TST_SR_FAIL_RO' – End test with 'TBROK' if the file is read-only +* 'TST_SR_IGNORE_RO' – Continue without saving the file if it is read-only +* 'TST_SR_IGNORE_ERR' – Ignore errors when writing new value into the file +* 'TST_SR_REQUIRED' – Equivalent to 'TST_SR_FAIL_MISSING | TST_SR_FAIL_RO' +* 'TST_SR_IF_ACCESS' – Equivalent to 'TST_SR_IGNORE_MISSING | TST_SR_IGNORE_RO' 'restore' is always strict and will TWARN if it encounters any error. [source,c] ------------------------------------------------------------------------------- -static void setup(void) -{ - FILE_PRINTF("/proc/sys/kernel/core_pattern", "/mypath"); - SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10); -} - static struct tst_test test = { .setup = setup, .save_restore = (const struct tst_path_val[]) { - {"/proc/sys/kernel/core_pattern", NULL}, - {"?/proc/sys/user/max_user_namespaces", NULL}, - {"!/sys/kernel/mm/ksm/run", "1"}, + {"/proc/sys/kernel/core_pattern", NULL, 0}, + {"/proc/sys/user/max_user_namespaces", NULL, TST_SR_IF_ACCESS}, + {"/sys/kernel/mm/ksm/run", "1", TST_SR_REQUIRED}, {} }, };include/tst_sys_conf.h +0
-0include/tst_sys_conf.h line 12
Quoted 8 lines
include/tst_sys_conf.h +5
-0@@ -5,14 +5,23 @@#ifndef TST_SYS_CONF_H__ #define TST_SYS_CONF_H__ +#define TST_SR_FAIL_MISSING 0x1 +#define TST_SR_IGNORE_MISSING 0x2 +#define TST_SR_FAIL_RO 0x4 +#define TST_SR_IGNORE_RO 0x8 +#define TST_SR_IGNORE_ERR 0x10This is a good thought to split the permission and respectively handle them, but I feel that these names are a bit ambiguous.
Quoted 5 lines
For example
TST_SR_IGNORE_RO, I was puzzled a while when reading it in the below code, it can be thought of as ignoring theREAD_ONLYpermission if just from the literal meaning.We need to find more precise names.
Would TST_SR_SKIP_RO be clearer?
Quoted 9 lines
include/tst_sys_conf.h line 15
Quoted 6 lines
include/tst_sys_conf.h +3
-0+ +#define TST_SR_REQUIRED (TST_SR_FAIL_MISSING | TST_SR_FAIL_RO) +#define TST_SR_IF_ACCESS (TST_SR_IGNORE_MISSING | TST_SR_IGNORE_RO)Here as well, especially these two will be more frequently used in testcase writing.
Maybe TST_SR_COND_ACCESS - which slightly longer
Anyway, moving from prefix to flags is desired change, so:
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 8 lines · Jan Stancek
Quoted 5 lines
For example
TST_SR_IGNORE_RO, I was puzzled a while when reading it in the below code, it can be thought of as ignoring theREAD_ONLYpermission if just from the literal meaning.We need to find more precise names.
Would
TST_SR_SKIP_RObe clearer?
Quoted 7 lines
Quoted 5 lines
include/tst_sys_conf.h line 15
Quoted 3 lines
include/tst_sys_conf.h +3
-0+ +#define TST_SR_REQUIRED (TST_SR_FAIL_MISSING | TST_SR_FAIL_RO) +#define TST_SR_IF_ACCESS (TST_SR_IGNORE_MISSING | TST_SR_IGNORE_RO)Here as well, especially these two will be more frequently used in testcase writing.
Maybe
TST_SR_COND_ACCESS- which slightly longer
Sounds good, I'll send v2 with both flag changes shortly.
Signature · 11 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 22 lines · Martin Doucha
Tests using the .save_restore functionality currently cannot run without root privileges at all because the test will write into the path at least at the end and trigger error, even when the config paths are flagged as optional.
Introduce new
tst_path_valfield for flags and replace path prefix flags with bit flags. Also introduce new flags to control handling of read/write errors and read-only sysfiles and rewritesave_restoreimplementation accordingly.Signed-off-by Martin Doucha <[email protected]>---
This is technically a v2 for
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/I'll send a follow-up patchset to replace
setup()code which requires root privileges without good reason after this patch gets merged. Here I've kept test changes to the minimum needed to maintain currentsave_restorebehavior with the new flags system. The only change in behavior is the use of read-only handling flags where it's clear that the change is desired.
Quoted 4 lines
Though a few tests should get closer attention during review:
- all KSM tests
-add_key05
-migrate_pages02
Does anybody have any change requests? Or can we merge this so that I can send the follow-up patchset?
Signature · 11 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp