support for newer kernels that show cgroups mountinfo at super_options
Costa Tsaousis committed
Apr 30, 2016 at 14:36 UTC
91a7221964e32ec4f727e7be5ee892b451affe28
3 files changed
+41
-2
src/proc_self_mountinfo.c
+37
-2
@@ -33,13 +33,48 @@ struct mountinfo *mountinfo_find_by_filesystem_mount_source(struct mountinfo *ro
33
uint32_t filesystem_hash = simple_hash(filesystem), mount_source_hash = simple_hash(mount_source);
34
35
for(mi = root; mi ; mi = mi->next)
36
- if(mi->filesystem_hash == filesystem_hash && mi->mount_source_hash == mount_source_hash
37
- && !strcmp(mi->filesystem, filesystem) && !strcmp(mi->mount_source, mount_source))
36
+ if(mi->filesystem
37
+ && mi->mount_source
38
+ && mi->filesystem_hash == filesystem_hash
39
+ && mi->mount_source_hash == mount_source_hash
40
+ && !strcmp(mi->filesystem, filesystem)
41
+ && !strcmp(mi->mount_source, mount_source))
42
return mi;
43
44
return NULL;
45
}
46
47
+struct mountinfo *mountinfo_find_by_filesystem_super_option(struct mountinfo *root, const char *filesystem, const char *super_options) {
48
+ struct mountinfo *mi;
49
+ uint32_t filesystem_hash = simple_hash(filesystem);
50
+
51
+ size_t solen = strlen(super_options);
52
+
53
+ for(mi = root; mi ; mi = mi->next)
54
+ if(mi->filesystem
55
+ && mi->super_options
56
+ && mi->filesystem_hash == filesystem_hash
57
+ && !strcmp(mi->filesystem, filesystem)) {
58
+
59
+ // super_options is a comma separated list
60
+ char *s = mi->super_options, *e;
61
+ while(*s) {
62
+ e = ++s;
63
+ while(*e && *e != ',') e++;
64
+
65
+ size_t len = e - s;
66
+ if(len == solen && !strncmp(s, super_options, len))
67
+ return mi;
68
+
69
+ if(*e == ',') s = ++e;
70
+ else s = e;
71
+ }
72
+ }
73
+
74
+ return NULL;
75
+}
76
+
77
+
78
// free a linked list of mountinfo structures
79
void mountinfo_free(struct mountinfo *mi) {
80
if(unlikely(!mi))
src/proc_self_mountinfo.h
+1
@@ -34,6 +34,7 @@ struct mountinfo {
34
35
extern struct mountinfo *mountinfo_find(struct mountinfo *root, unsigned long major, unsigned long minor);
36
extern struct mountinfo *mountinfo_find_by_filesystem_mount_source(struct mountinfo *root, const char *filesystem, const char *mount_source);
37
+extern struct mountinfo *mountinfo_find_by_filesystem_super_option(struct mountinfo *root, const char *filesystem, const char *super_options);
38
39
extern void mountinfo_free(struct mountinfo *mi);
40
extern struct mountinfo *mountinfo_read();
src/sys_fs_cgroup.c
+3
@@ -47,18 +47,21 @@ void read_cgroup_plugin_configuration() {
47
struct mountinfo *mi, *root = mountinfo_read();
48
49
mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "cpuacct");
50
+ if(!mi) mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "cpuacct");
51
if(!mi) s = "/sys/fs/cgroup/cpuacct";
52
else s = mi->mount_point;
53
snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
54
cgroup_cpuacct_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/cpuacct", filename);
55
56
mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "blkio");
57
+ if(!mi) mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "blkio");
58
if(!mi) s = "/sys/fs/cgroup/blkio";
59
else s = mi->mount_point;
60
snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
61
cgroup_blkio_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/blkio", filename);
62
63
mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "memory");
64
+ if(!mi) mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "memory");
65
if(!mi) s = "/sys/fs/cgroup/memory";
66
else s = mi->mount_point;
67
snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);