File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 99#include <linux/zalloc.h>
1010#include <sys/types.h>
1111#include <sys/stat.h>
12+ #include <sys/statfs.h>
1213#include <fcntl.h>
1314#include <stdlib.h>
1415#include <string.h>
@@ -70,6 +71,24 @@ int read_cgroup_id(struct cgroup *cgrp)
7071}
7172#endif /* HAVE_FILE_HANDLE */
7273
74+ #ifndef CGROUP2_SUPER_MAGIC
75+ #define CGROUP2_SUPER_MAGIC 0x63677270
76+ #endif
77+
78+ int cgroup_is_v2 (const char * subsys )
79+ {
80+ char mnt [PATH_MAX + 1 ];
81+ struct statfs stbuf ;
82+
83+ if (cgroupfs_find_mountpoint (mnt , PATH_MAX + 1 , subsys ))
84+ return -1 ;
85+
86+ if (statfs (mnt , & stbuf ) < 0 )
87+ return -1 ;
88+
89+ return (stbuf .f_type == CGROUP2_SUPER_MAGIC );
90+ }
91+
7392static struct cgroup * evlist__find_cgroup (struct evlist * evlist , const char * str )
7493{
7594 struct evsel * counter ;
Original file line number Diff line number Diff line change @@ -48,4 +48,6 @@ static inline int read_cgroup_id(struct cgroup *cgrp __maybe_unused)
4848}
4949#endif /* HAVE_FILE_HANDLE */
5050
51+ int cgroup_is_v2 (const char * subsys );
52+
5153#endif /* __CGROUP_H__ */
You can’t perform that action at this time.
0 commit comments