* [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes
@ 2021-12-14 10:36 Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 2/5] API/cgroup: Remove typedef Richard Palethorpe via ltp
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Richard Palethorpe via ltp @ 2021-12-14 10:36 UTC (permalink / raw)
To: ltp; +Cc: Richard Palethorpe
Reduce make check noise
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
lib/tst_cgroup.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 61cc02fa7..2dcfbc8ff 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -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,
--
2.34.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/5] API/cgroup: Remove typedef
2021-12-14 10:36 [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes Richard Palethorpe via ltp
@ 2021-12-14 10:36 ` Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 3/5] API/cgroup: Lift out assignments in if statements Richard Palethorpe via ltp
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Richard Palethorpe via ltp @ 2021-12-14 10:36 UTC (permalink / raw)
To: ltp; +Cc: Richard Palethorpe
Angers make check and is not helpful anymore.
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
lib/tst_cgroup.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 2dcfbc8ff..d9d74faa8 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -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] = {
--
2.34.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 3/5] API/cgroup: Lift out assignments in if statements
2021-12-14 10:36 [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 2/5] API/cgroup: Remove typedef Richard Palethorpe via ltp
@ 2021-12-14 10:36 ` Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 4/5] API/cgroup: remove ltp_ prefix from static vars Richard Palethorpe via ltp
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Richard Palethorpe via ltp @ 2021-12-14 10:36 UTC (permalink / raw)
To: ltp; +Cc: Richard Palethorpe
checkpatch.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 <rpalethorpe@suse.com>
---
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
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index d9d74faa8..8eeb98a26 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -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);
}
diff --git a/scripts/coccinelle/fix-if-assignment.cocci b/scripts/coccinelle/fix-if-assignment.cocci
new file mode 100644
index 000000000..4dad22fe0
--- /dev/null
+++ b/scripts/coccinelle/fix-if-assignment.cocci
@@ -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 ...) { ... }
--
2.34.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 4/5] API/cgroup: remove ltp_ prefix from static vars
2021-12-14 10:36 [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 2/5] API/cgroup: Remove typedef Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 3/5] API/cgroup: Lift out assignments in if statements Richard Palethorpe via ltp
@ 2021-12-14 10:36 ` Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 5/5] API/cgroup: Use __func__ in tst_cgroup_require Richard Palethorpe via ltp
2021-12-14 11:48 ` [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes Cyril Hrubis
4 siblings, 0 replies; 6+ messages in thread
From: Richard Palethorpe via ltp @ 2021-12-14 10:36 UTC (permalink / raw)
To: ltp; +Cc: Richard Palethorpe
LTP-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 <rpalethorpe@suse.com>
---
lib/tst_cgroup.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 8eeb98a26..c22f5b32c 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -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,
--
2.34.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 5/5] API/cgroup: Use __func__ in tst_cgroup_require
2021-12-14 10:36 [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes Richard Palethorpe via ltp
` (2 preceding siblings ...)
2021-12-14 10:36 ` [LTP] [PATCH 4/5] API/cgroup: remove ltp_ prefix from static vars Richard Palethorpe via ltp
@ 2021-12-14 10:36 ` Richard Palethorpe via ltp
2021-12-14 11:48 ` [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes Cyril Hrubis
4 siblings, 0 replies; 6+ messages in thread
From: Richard Palethorpe via ltp @ 2021-12-14 10:36 UTC (permalink / raw)
To: ltp; +Cc: Richard Palethorpe
Required by checkpatch.pl.
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
lib/tst_cgroup.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index c22f5b32c..7c4de34c6 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -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)
--
2.34.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes
2021-12-14 10:36 [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes Richard Palethorpe via ltp
` (3 preceding siblings ...)
2021-12-14 10:36 ` [LTP] [PATCH 5/5] API/cgroup: Use __func__ in tst_cgroup_require Richard Palethorpe via ltp
@ 2021-12-14 11:48 ` Cyril Hrubis
4 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2021-12-14 11:48 UTC (permalink / raw)
To: Richard Palethorpe; +Cc: ltp
Hi!
The whole patchset is obviously fine:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-12-14 11:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 10:36 [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 2/5] API/cgroup: Remove typedef Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 3/5] API/cgroup: Lift out assignments in if statements Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 4/5] API/cgroup: remove ltp_ prefix from static vars Richard Palethorpe via ltp
2021-12-14 10:36 ` [LTP] [PATCH 5/5] API/cgroup: Use __func__ in tst_cgroup_require Richard Palethorpe via ltp
2021-12-14 11:48 ` [LTP] [PATCH 1/5] API/cgroup: Whitespace fixes Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).