return NULL;
}
+// find the mount info with the given filesystem and mount_source
+// in the supplied linked list of mountinfo structures
+struct mountinfo *mountinfo_find_by_filesystem_mount_source(struct mountinfo *root, const char *filesystem, const char *mount_source) {
+ struct mountinfo *mi;
+ 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))
+ return mi;
+
+ return NULL;
+}
+
// free a linked list of mountinfo structures
void mountinfo_free(struct mountinfo *mi) {
if(unlikely(!mi))
struct mountinfo *root = NULL, *last = NULL, *mi = NULL;
unsigned long l, lines = procfile_lines(ff);
- error("MOUNTINFO: file has %u lines", lines);
for(l = 0; l < lines ;l++) {
if(procfile_linewords(ff, l) < 5)
continue;
mi->root = strdup(procfile_lineword(ff, l, w)); w++;
if(unlikely(!mi->root)) fatal("Cannot allocate memory");
+ mi->root_hash = simple_hash(mi->root);
mi->mount_point = strdup(procfile_lineword(ff, l, w)); w++;
if(unlikely(!mi->mount_point)) fatal("Cannot allocate memory");
+ mi->mount_point_hash = simple_hash(mi->mount_point);
mi->mount_options = strdup(procfile_lineword(ff, l, w)); w++;
if(unlikely(!mi->mount_options)) fatal("Cannot allocate memory");
mi->optional_fields = NULL;
if(likely(*s == '-')) {
+ w++;
+
mi->filesystem = strdup(procfile_lineword(ff, l, w)); w++;
if(!mi->filesystem) fatal("Cannot allocate memory");
+ mi->filesystem_hash = simple_hash(mi->filesystem);
mi->mount_source = strdup(procfile_lineword(ff, l, w)); w++;
if(!mi->mount_source) fatal("Cannot allocate memory");
+ mi->mount_source_hash = simple_hash(mi->mount_source);
mi->super_options = strdup(procfile_lineword(ff, l, w)); w++;
if(!mi->super_options) fatal("Cannot allocate memory");
mi->super_options = NULL;
}
- //info("MOUNTINFO: %u %u %u:%u root '%s', mount point '%s', mount options '%s', filesystem '%s', mount source '%s', super options '%s'",
- // mi->id,
- // mi->parentid,
- // mi->major,
- // mi->minor,
- // mi->root,
- // mi->mount_point,
- // mi->mount_options,
- // mi->filesystem,
- // mi->mount_source,
- // mi->super_options
- //);
+/*
+ info("MOUNTINFO: %u %u %u:%u root '%s', mount point '%s', mount options '%s', filesystem '%s', mount source '%s', super options '%s'",
+ mi->id,
+ mi->parentid,
+ mi->major,
+ mi->minor,
+ mi->root,
+ mi->mount_point,
+ mi->mount_options,
+ mi->filesystem,
+ mi->mount_source,
+ mi->super_options
+ );
+*/
}
procfile_close(ff);
unsigned long minor;
char *root; // root: root of the mount within the filesystem.
+ uint32_t root_hash;
+
char *mount_point; // mount point: mount point relative to the process's root.
+ uint32_t mount_point_hash;
+
char *mount_options; // mount options: per-mount options.
int optional_fields_count;
char **optional_fields; // optional fields: zero or more fields of the form "tag[:value]".
char *filesystem; // filesystem type: name of filesystem in the form "type[.subtype]".
+ uint32_t filesystem_hash;
+
char *mount_source; // mount source: filesystem-specific information or "none".
+ uint32_t mount_source_hash;
+
char *super_options; // super options: per-superblock options.
struct mountinfo *next;
};
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 void mountinfo_free(struct mountinfo *mi);
extern struct mountinfo *mountinfo_read();
#include "rrd.h"
#include "main.h"
#include "popen.h"
+#include "proc_self_mountinfo.h"
// ----------------------------------------------------------------------------
// cgroup globals
cgroup_enable_memory = config_get_boolean_ondemand("plugin:cgroups", "enable memory", cgroup_enable_memory);
cgroup_enable_blkio = config_get_boolean_ondemand("plugin:cgroups", "enable blkio", cgroup_enable_blkio);
- char filename[FILENAME_MAX + 1];
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/fs/cgroup/cpuacct");
+ char filename[FILENAME_MAX + 1], *s;
+ struct mountinfo *mi, *root = mountinfo_read();
+
+ mi = mountinfo_find_by_filesystem_mount_source(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);
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/fs/cgroup/blkio");
+ mi = mountinfo_find_by_filesystem_mount_source(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);
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/fs/cgroup/memory");
+ mi = mountinfo_find_by_filesystem_mount_source(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);
cgroup_memory_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/memory", filename);
cgroup_root_max = config_get_number("plugin:cgroups", "max cgroups to allow", cgroup_root_max);
cgroup_max_depth = config_get_number("plugin:cgroups", "max cgroups depth to monitor", cgroup_max_depth);
cgroup_enable_new_cgroups_detected_at_runtime = config_get_boolean("plugin:cgroups", "enable new cgroups detected at run time", cgroup_enable_new_cgroups_detected_at_runtime);
+
+ mountinfo_free(root);
}
// ----------------------------------------------------------------------------