From 91a7221964e32ec4f727e7be5ee892b451affe28 Mon Sep 17 00:00:00 2001 From: Costa Tsaousis Date: Sat, 30 Apr 2016 14:36:38 +0300 Subject: [PATCH] support for newer kernels that show cgroups mountinfo at super_options --- src/proc_self_mountinfo.c | 39 +++++++++++++++++++++++++++++++++++++-- src/proc_self_mountinfo.h | 1 + src/sys_fs_cgroup.c | 3 +++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/proc_self_mountinfo.c b/src/proc_self_mountinfo.c index fa407967..a2a9e09a 100644 --- a/src/proc_self_mountinfo.c +++ b/src/proc_self_mountinfo.c @@ -33,13 +33,48 @@ struct mountinfo *mountinfo_find_by_filesystem_mount_source(struct mountinfo *ro uint32_t filesystem_hash = simple_hash(filesystem), mount_source_hash = simple_hash(mount_source); for(mi = root; mi ; mi = mi->next) - if(mi->filesystem_hash == filesystem_hash && mi->mount_source_hash == mount_source_hash - && !strcmp(mi->filesystem, filesystem) && !strcmp(mi->mount_source, mount_source)) + if(mi->filesystem + && mi->mount_source + && mi->filesystem_hash == filesystem_hash + && mi->mount_source_hash == mount_source_hash + && !strcmp(mi->filesystem, filesystem) + && !strcmp(mi->mount_source, mount_source)) return mi; return NULL; } +struct mountinfo *mountinfo_find_by_filesystem_super_option(struct mountinfo *root, const char *filesystem, const char *super_options) { + struct mountinfo *mi; + uint32_t filesystem_hash = simple_hash(filesystem); + + size_t solen = strlen(super_options); + + for(mi = root; mi ; mi = mi->next) + if(mi->filesystem + && mi->super_options + && mi->filesystem_hash == filesystem_hash + && !strcmp(mi->filesystem, filesystem)) { + + // super_options is a comma separated list + char *s = mi->super_options, *e; + while(*s) { + e = ++s; + while(*e && *e != ',') e++; + + size_t len = e - s; + if(len == solen && !strncmp(s, super_options, len)) + return mi; + + if(*e == ',') s = ++e; + else s = e; + } + } + + return NULL; +} + + // free a linked list of mountinfo structures void mountinfo_free(struct mountinfo *mi) { if(unlikely(!mi)) diff --git a/src/proc_self_mountinfo.h b/src/proc_self_mountinfo.h index 8c212749..51712a58 100644 --- a/src/proc_self_mountinfo.h +++ b/src/proc_self_mountinfo.h @@ -34,6 +34,7 @@ struct mountinfo { extern struct mountinfo *mountinfo_find(struct mountinfo *root, unsigned long major, unsigned long minor); extern struct mountinfo *mountinfo_find_by_filesystem_mount_source(struct mountinfo *root, const char *filesystem, const char *mount_source); +extern struct mountinfo *mountinfo_find_by_filesystem_super_option(struct mountinfo *root, const char *filesystem, const char *super_options); extern void mountinfo_free(struct mountinfo *mi); extern struct mountinfo *mountinfo_read(); diff --git a/src/sys_fs_cgroup.c b/src/sys_fs_cgroup.c index fbaf1318..6c2fdb03 100644 --- a/src/sys_fs_cgroup.c +++ b/src/sys_fs_cgroup.c @@ -47,18 +47,21 @@ void read_cgroup_plugin_configuration() { struct mountinfo *mi, *root = mountinfo_read(); mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "cpuacct"); + if(!mi) mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "cpuacct"); if(!mi) s = "/sys/fs/cgroup/cpuacct"; else s = mi->mount_point; snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, s); cgroup_cpuacct_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/cpuacct", filename); mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "blkio"); + if(!mi) mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "blkio"); if(!mi) s = "/sys/fs/cgroup/blkio"; else s = mi->mount_point; snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, s); cgroup_blkio_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/blkio", filename); mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "memory"); + if(!mi) mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "memory"); if(!mi) s = "/sys/fs/cgroup/memory"; else s = mi->mount_point; snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, s); -- 2.39.2