summaryrefslogtreecommitdiff
path: root/src/cgtop
diff options
context:
space:
mode:
authorTejun Heo <htejun@fb.com>2016-11-21 14:45:53 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-18 17:51:13 -0500
commit415fc41ceaeada2e32639f24f134b1c248b9e43f (patch)
tree5e8a3a3af6bfaec96c4653ad36e8090f81d86a30 /src/cgtop
parentbd15ab41a1347fed8266845f875842d1502e02a6 (diff)
downloadsystemd-415fc41ceaeada2e32639f24f134b1c248b9e43f.tar.gz
core: simplify cg_[all_]unified()
cg_[all_]unified() test whether a specific controller or all controllers are on the unified hierarchy. While what's being asked is a simple binary question, the callers must assume that the functions may fail any time, which unnecessarily complicates their usages. This complication is unnecessary. Internally, the test result is cached anyway and there are only a few places where the test actually needs to be performed. This patch simplifies cg_[all_]unified(). * cg_[all_]unified() are updated to return bool. If the result can't be decided, assertion failure is triggered. Error handlings from their callers are dropped. * cg_unified_flush() is updated to calculate the new result synchrnously and return whether it succeeded or not. Places which need to flush the test result are updated to test for failure. This ensures that all the following cg_[all_]unified() tests succeed. * Places which expected possible cg_[all_]unified() failures are updated to call and test cg_unified_flush() before calling cg_[all_]unified(). This includes functions used while setting up mounts during boot and manager_setup_cgroup().
Diffstat (limited to 'src/cgtop')
-rw-r--r--src/cgtop/cgtop.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index 50ac6a58b0..45c050c9c3 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -214,7 +214,7 @@ static int process(
uint64_t new_usage;
nsec_t timestamp;
- if (cg_all_unified() > 0) {
+ if (cg_all_unified()) {
const char *keys[] = { "usage_usec", NULL };
_cleanup_free_ char *val = NULL;
@@ -274,7 +274,7 @@ static int process(
} else if (streq(controller, "memory")) {
_cleanup_free_ char *p = NULL, *v = NULL;
- if (cg_all_unified() <= 0)
+ if (!cg_all_unified())
r = cg_get_path(controller, path, "memory.usage_in_bytes", &p);
else
r = cg_get_path(controller, path, "memory.current", &p);
@@ -294,15 +294,14 @@ static int process(
if (g->memory > 0)
g->memory_valid = true;
- } else if ((streq(controller, "io") && cg_all_unified() > 0) ||
- (streq(controller, "blkio") && cg_all_unified() <= 0)) {
+ } else if ((streq(controller, "io") && cg_all_unified()) ||
+ (streq(controller, "blkio") && !cg_all_unified())) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
- bool unified = cg_all_unified() > 0;
uint64_t wr = 0, rd = 0;
nsec_t timestamp;
- r = cg_get_path(controller, path, unified ? "io.stat" : "blkio.io_service_bytes", &p);
+ r = cg_get_path(controller, path, cg_all_unified() ? "io.stat" : "blkio.io_service_bytes", &p);
if (r < 0)
return r;
@@ -325,7 +324,7 @@ static int process(
l += strcspn(l, WHITESPACE);
l += strspn(l, WHITESPACE);
- if (unified) {
+ if (cg_all_unified()) {
while (!isempty(l)) {
if (sscanf(l, "rbytes=%" SCNu64, &k))
rd += k;