API/cgroup: Whitespace fixes
Subsystems (2)
PATCH 1/5 API/cgroup: Whitespace fixes
Reduce make check noise
Signed-off-by Richard Palethorpe <[email protected]>
--- lib/tst_cgroup.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
lib/tst_cgroup.c +9 -6
@@ -199,7 +199,8 @@ static struct cgroup_ctrl controllers[] = {static const struct tst_cgroup_opts default_opts = {0 };/* We should probably allow these to be set in environment -* variables */ +* variables +*/ static const char *ltp_cgroup_dir ="ltp" ;static const char *ltp_cgroup_drain_dir ="drain" ;static char test_cgroup_dir[NAME_MAX +1 ];
@@ -798,7 +799,8 @@ void tst_cgroup_cleanup(void)continue ;/* This probably does not result in the CGroup root -* being destroyed */ +* being destroyed +*/ if (umount2 (root->mnt_path,MNT_DETACH ))continue ;
@@ -817,7 +819,7 @@ clear_data:memset (roots,0 ,sizeof (roots)); } -__attribute__ ((nonnull (1 ))) +__attribute__((nonnull (1 )))static void cgroup_group_init (struct tst_cgroup_group *const cg,const char *const group_name) {
@@ -832,7 +834,7 @@ static void cgroup_group_init(struct tst_cgroup_group *const cg,strcpy (cg->group_name, group_name); } -__attribute__((nonnull (2 ,3 ))) +__attribute__((nonnull (2 ,3 )))static void cgroup_group_add_dir (const struct tst_cgroup_group *const parent,struct tst_cgroup_group *const cg,struct cgroup_dir *const dir)
@@ -856,7 +858,8 @@ static void cgroup_group_add_dir(const struct tst_cgroup_group *const parent, "+%s", ctrl->ctrl_name); } -for (i =0 ; cg->dirs[i]; i++); +for (i =0 ; cg->dirs[i]; i++) + ; cg->dirs[i] = dir; }
@@ -923,7 +926,7 @@ static const struct cgroup_file *cgroup_file_find(const char *const file,memcpy (ctrl_name, file_name, len); ctrl_name[len] ='\0' ; - ctrl =cgroup_find_ctrl (ctrl_name); + ctrl =cgroup_find_ctrl (ctrl_name);if (!ctrl) { tst_brk_(file, lineno, TBROK,
Signature · 5 lines
2.34.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/5 API/cgroup: Remove typedef
Angers make check and is not helpful anymore.
Signed-off-by Richard Palethorpe <[email protected]>
--- lib/tst_cgroup.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
lib/tst_cgroup.c +5 -7
@@ -141,10 +141,7 @@ struct tst_cgroup_group {/* Always use first item for unified hierarchy */ static struct cgroup_root roots[ROOTS_MAX +1 ]; -/* Lookup tree for item names. */ -typedef struct cgroup_file files_t []; - -static const files_t cgroup_ctrl_files = { +static const struct cgroup_file cgroup_ctrl_files[] = {/* procs exists on V1, however it was read-only until kernel v3.0. */ {"cgroup.procs" ,"tasks" ,0 }, {"cgroup.subtree_control" ,NULL ,0 },
@@ -152,7 +149,7 @@ static const files_t cgroup_ctrl_files = { { } }; -static const files_t memory_ctrl_files = { +static const struct cgroup_file memory_ctrl_files[] = { {"memory.current" ,"memory.usage_in_bytes" ,CTRL_MEMORY }, {"memory.max" ,"memory.limit_in_bytes" ,CTRL_MEMORY }, {"memory.swappiness" ,"memory.swappiness" ,CTRL_MEMORY },
@@ -163,7 +160,7 @@ static const files_t memory_ctrl_files = { { } }; -static const files_t cpu_ctrl_files = { +static const struct cgroup_file cpu_ctrl_files[] = {/* The V1 quota and period files were combined in the V2 max * file. The quota is in the first column and if we just print * a single value to the file, it will be treated as the
@@ -175,13 +172,14 @@ static const files_t cpu_ctrl_files = { { } }; -static const files_t cpuset_ctrl_files = { +static const struct cgroup_file cpuset_ctrl_files[] = { {"cpuset.cpus" ,"cpuset.cpus" ,CTRL_CPUSET }, {"cpuset.mems" ,"cpuset.mems" ,CTRL_CPUSET }, {"cpuset.memory_migrate" ,"cpuset.memory_migrate" ,CTRL_CPUSET }, { } }; +/* Lookup tree for item names. */ static struct cgroup_ctrl controllers[] = { [0 ] = {"cgroup" , cgroup_ctrl_files,0 ,NULL ,0 }, [CTRL_MEMORY ] = {
Signature · 5 lines
2.34.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/5 API/cgroup: Lift out assignments in if statements
In reply to Richard Palethorpe via ltpcheckpatch.pl forbids this; for good reason because it can mask accidental use of '=' instead of '=='. Also included is a script to automatically fix occurrences of this.
Signed-off-by Richard Palethorpe <[email protected]>
--- lib/tst_cgroup.c | 22 ++++++++++------ scripts/coccinelle/fix-if-assignment.cocci | 30 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 scripts/coccinelle/fix-if-assignment.cocci
lib/tst_cgroup.c +14 -8
@@ -370,7 +370,8 @@ static void cgroup_root_scan(const char *const mnt_type,SAFE_FILE_READAT (mnt_dfd,"cgroup.controllers" , buf,sizeof (buf));for (tok =strtok (buf," " ); tok; tok =strtok (NULL ," " )) { -if ((const_ctrl =cgroup_find_ctrl (tok))) + const_ctrl =cgroup_find_ctrl (tok); +if (const_ctrl)add_ctrl (&ctrl_field, const_ctrl); }
@@ -386,7 +387,8 @@ static void cgroup_root_scan(const char *const mnt_type, v1:for (tok =strtok (mnt_opts,"," ); tok; tok =strtok (NULL ,"," )) { -if ((const_ctrl =cgroup_find_ctrl (tok))) + const_ctrl =cgroup_find_ctrl (tok); +if (const_ctrl)add_ctrl (&ctrl_field, const_ctrl); no_prefix |= !strcmp ("noprefix" , tok);
@@ -1008,8 +1010,9 @@ int safe_cgroup_has(const char *const file, const int lineno,return 0 ;for_each_dir (cg, cfile->ctrl_indx, dir) { -if (!(alias =cgroup_file_alias (cfile, *dir))) -continue ; + alias =cgroup_file_alias (cfile, *dir); +if (!alias) +continue ;if (!faccessat ((*dir)->dir_fd, alias,F_OK ,0 ))return 1 ;
@@ -1077,7 +1080,8 @@ ssize_t safe_cgroup_read(const char *const file, const int lineno,ssize_t read_ret =0 ;for_each_dir (cg, cfile->ctrl_indx, dir) { -if (!(alias =cgroup_file_alias (cfile, *dir))) + alias =cgroup_file_alias (cfile, *dir); +if (!alias)continue ;if (prev_len)
@@ -1115,8 +1119,9 @@ void safe_cgroup_printf(const char *const file, const int lineno,va_list va;for_each_dir (cg, cfile->ctrl_indx, dir) { -if (!(alias =cgroup_file_alias (cfile, *dir))) -continue ; + alias =cgroup_file_alias (cfile, *dir); +if (!alias) +continue ;va_start (va, fmt); safe_file_vprintfat(file, lineno,
@@ -1141,7 +1146,8 @@ void safe_cgroup_scanf(const char *const file, const int lineno,return ;va_start (va, fmt); -if ((ret =vsscanf (buf, fmt, va)) <1 ) { + ret =vsscanf (buf, fmt, va); +if (ret <1 ) {tst_brk_ (file, lineno,TBROK |TERRNO ,"'%s': vsscanf('%s', '%s', ...)" , file_name, buf, fmt); }
scripts/coccinelle/fix-if-assignment.cocci new file +30 -0
@@ -0,0 +1,30 @@ +@@ +expression V, E; +@@ + ++ V = E; + if ( +- (V = E) ++ V + ) { ... } + +@@ +expression V, E; +@@ + ++ V = E; + if (! +- (V = E) ++ V + ) { ... } + +@@ +expression V, E; +binary operator B; +@@ + ++ V = E; + if ( +- (V = E) ++ V + B ...) { ... }
Signature · 5 lines
2.34.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/5 API/cgroup: remove ltp_ prefix from static vars
In reply to Richard Palethorpe via ltpLTP-003 reserves this prefix for use in public symbols. Also it tends to be used in parts of the old API. The new API uses tst_.
Signed-off-by Richard Palethorpe <[email protected]>
--- lib/tst_cgroup.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
lib/tst_cgroup.c +11 -11
@@ -199,11 +199,11 @@ static const struct tst_cgroup_opts default_opts = { 0 };/* We should probably allow these to be set in environment * variables */ -static const char *ltp_cgroup_dir ="ltp" ; -static const char *ltp_cgroup_drain_dir ="drain" ; -static char test_cgroup_dir[NAME_MAX +1 ]; -static const char *ltp_mount_prefix ="/tmp/cgroup_" ; -static const char *ltp_v2_mount ="unified" ; +static const char *cgroup_ltp_dir ="ltp" ; +static const char *cgroup_ltp_drain_dir ="drain" ; +static char cgroup_test_dir[NAME_MAX +1 ]; +static const char *cgroup_mount_ltp_prefix ="/tmp/cgroup_" ; +static const char *cgroup_v2_ltp_mount ="unified" ;#define first_root \ (roots[0].ver ? roots : roots + 1)
@@ -464,7 +464,7 @@ static void cgroup_mount_v2(void) {char mnt_path[PATH_MAX ]; -sprintf (mnt_path,"%s%s" , ltp_mount_prefix, ltp_v2_mount); +sprintf (mnt_path,"%s%s" , cgroup_mount_ltp_prefix, cgroup_v2_ltp_mount);if (!mkdir (mnt_path,0777 )) { roots[0 ].mnt_dir.we_created_it =1 ;
@@ -506,7 +506,7 @@ static void cgroup_mount_v1(struct cgroup_ctrl *const ctrl)char mnt_path[PATH_MAX ];int made_dir =0 ; -sprintf (mnt_path,"%s%s" , ltp_mount_prefix, ctrl->ctrl_name); +sprintf (mnt_path,"%s%s" , cgroup_mount_ltp_prefix, ctrl->ctrl_name);if (!mkdir (mnt_path,0777 )) { made_dir =1 ;
@@ -653,7 +653,7 @@ mkdirs: }if (!root->ltp_dir.dir_fd) -cgroup_dir_mk (&root->mnt_dir, ltp_cgroup_dir, &root->ltp_dir); +cgroup_dir_mk (&root->mnt_dir, cgroup_ltp_dir, &root->ltp_dir);else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field;
@@ -668,10 +668,10 @@ mkdirs:cgroup_copy_cpuset (root); } -cgroup_dir_mk (&root->ltp_dir, ltp_cgroup_drain_dir, &root->drain_dir); +cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir); -sprintf (test_cgroup_dir,"test-%d" ,getpid ()); -cgroup_dir_mk (&root->ltp_dir, test_cgroup_dir, &root->test_dir); +sprintf (cgroup_test_dir,"test-%d" ,getpid ()); +cgroup_dir_mk (&root->ltp_dir, cgroup_test_dir, &root->test_dir); } static void cgroup_drain(const enum tst_cgroup_ver ver,
Signature · 5 lines
2.34.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/5 API/cgroup: Use __func__ in tst_cgroup_require
In reply to Richard Palethorpe via ltpRequired by checkpatch.pl.
Signed-off-by Richard Palethorpe <[email protected]>
--- lib/tst_cgroup.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
lib/tst_cgroup.c +3 -4
@@ -609,10 +609,9 @@ void tst_cgroup_require(const char *const ctrl_name,if (!options) options = &default_opts; -if (ctrl->we_require_it) { -tst_res (TWARN ,"Duplicate tst_cgroup_require(%s, )" , - ctrl->ctrl_name); - } +if (ctrl->we_require_it) +tst_res (TWARN ,"Duplicate %s(%s, )" , __func__, ctrl->ctrl_name); + ctrl->we_require_it =1 ;if (ctrl->ctrl_root)
Signature · 5 lines
2.34.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
The whole patchset is obviously fine:
Reviewed-by Cyril Hrubis <[email protected]>
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp