[LTP] [PATCH v3 01/18] API/cgroup: Modify tst_cg_print_config for parsing and consumption

Luke Nowakowski-Krijger luke.nowakowskikrijger@canonical.com
Thu Jul 21 22:52:11 CEST 2022


Modify tst_cg_print_config to be easily parsed by sscanf so that it can
later be consumed by tst_cg_load_config.

Prints out root info of each controller found as well as the minimal
associated state needed to cleanup mounts and dirs made my tst_cg_require.

Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
v2: Remove "mounted_drain_dir" as mounting ltp dir and drain dir happen
at the same time
v3: Print config to be scanf friendly to be much easier to consume.
Rename variables to reflect the variables used in the library for
simplicity.

 include/tst_cgroup.h |  6 +++++-
 lib/tst_cgroup.c     | 25 ++++++++++++++++++-------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h
index c4bc7ae1c..7ebc2a624 100644
--- a/include/tst_cgroup.h
+++ b/include/tst_cgroup.h
@@ -110,7 +110,11 @@ extern const struct tst_cg_group *const tst_cg_drain;
  * controllers. Called automatically by tst_cg_require.
  */
 void tst_cg_scan(void);
-/* Print the config detected by tst_cg_scan */
+/* Print the config detected by tst_cg_scan and print the internal
+ * state associated with each controller. Output can be passed to
+ * tst_cg_load_config to configure the internal state to that of the
+ * config between program invocations.
+ */
 void tst_cg_print_config(void);
 
 /* Ensure the specified controller is available in the test's default
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 081dfa9c6..c56a7c6b9 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -317,24 +317,35 @@ opendir:
 				  O_PATH | O_DIRECTORY);
 }
 
+#define CONFIG_HEADER "ctrl_name ver we_require_it mnt_path we_mounted_it ltp_dir.we_created_it test_dir.dir_name"
+#define CONFIG_FORMAT "%s\t%d\t%d\t%s\t%d\t%d\t%s"
+/* Prints out the state associated with each controller to be consumed by
+ * tst_cg_load_config.
+ *
+ * The config keeps track of the minimal state needed for tst_cg_cleanup
+ * to cleanup mounts and directories made by tst_cg_require.
+ */
 void tst_cg_print_config(void)
 {
-	struct cgroup_root *root;
 	const struct cgroup_ctrl *ctrl;
 
-	tst_res(TINFO, "Detected Controllers:");
+	printf("%s\n", CONFIG_HEADER);
 
 	for_each_ctrl(ctrl) {
-		root = ctrl->ctrl_root;
+		struct cgroup_root *root = ctrl->ctrl_root;
 
 		if (!root)
 			continue;
 
-		tst_res(TINFO, "\t%.10s %s @ %s:%s",
+		printf(CONFIG_FORMAT,
 			ctrl->ctrl_name,
-			root->no_cpuset_prefix ? "[noprefix]" : "",
-			root->ver == TST_CG_V1 ? "V1" : "V2",
-			root->mnt_path);
+			root->ver,
+			ctrl->we_require_it,
+			root->mnt_path,
+			root->we_mounted_it,
+			root->ltp_dir.we_created_it,
+			root->test_dir.dir_name ? root->test_dir.dir_name : "NULL");
+		printf("\n");
 	}
 }
 
-- 
2.34.1



More information about the ltp mailing list