]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
bindings: port cpuview to new cgroup getters
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 24 Feb 2020 11:01:07 +0000 (12:01 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 24 Feb 2020 11:07:13 +0000 (12:07 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
bindings.c
bindings.h
cgroups/cgfsng.c
cgroups/cgroup.h
sysfs_fuse.c

index 7ac3ff1218ede1899ccd6e59a2465379dc617fd8..ce9a511b4147bf3feb59eed79fde9b11731d6df1 100644 (file)
@@ -412,7 +412,7 @@ static void lock_mutex(pthread_mutex_t *l)
        }
 }
 
-static struct cgroup_ops *cgroup_ops;
+struct cgroup_ops *cgroup_ops;
 
 static int cgroup_mount_ns_fd = -1;
 
@@ -3667,24 +3667,6 @@ static double exact_cpu_count(const char *cg)
        return rv;
 }
 
-/*
- * Determine whether CPU views should be used or not.
- */
-bool use_cpuview(const char *cg)
-{
-       int cfd;
-
-       cfd = find_mounted_controller("cpu");
-       if (cfd < 0)
-               return false;
-
-       cfd = find_mounted_controller("cpuacct");
-       if (cfd < 0)
-               return false;
-
-       return true;
-}
-
 /*
  * check whether this is a '^processor" line in /proc/cpuinfo
  */
@@ -3736,8 +3718,7 @@ static int proc_cpuinfo_read(char *buf, size_t size, off_t offset,
        if (!cpuset)
                goto err;
 
-       use_view = use_cpuview(cg);
-
+       use_view = cgroup_ops->can_use_cpuview(cgroup_ops);
        if (use_view)
                max_cpus = max_cpu_count(cg);
 
@@ -4865,7 +4846,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
                goto err;
        }
 
-       if (use_cpuview(cg) && cg_cpu_usage) {
+       if (cgroup_ops->can_use_cpuview(cgroup_ops) && cg_cpu_usage) {
                total_len = cpuview_proc_stat(cg, cpuset, cg_cpu_usage, cg_cpu_usage_size,
                                f, d->buf, d->buflen);
                goto out;
index 229d64cafeff4a44e149aa575a070b69b864c12a..d41994ff7b582cf679fbcf96f10a92ef7ce53959 100644 (file)
@@ -79,7 +79,6 @@ extern int read_file_fuse(const char *path, char *buf, size_t size,
                          struct file_info *d);
 extern void prune_init_slice(char *cg);
 extern char *get_cpuset(const char *cg);
-extern bool use_cpuview(const char *cg);
 extern int max_cpu_count(const char *cg);
 extern void do_release_file_info(struct fuse_file_info *fi);
 extern int cpu_number_in_cpuset(const char *cpuset);
index 60ac136cbd3ab6c1718e50649d2cc736dd90ca41..8d972b7d820dd6898b19910a6a5d4c5062f7781b 100644 (file)
@@ -794,6 +794,24 @@ static int cgfsng_get_io_wait_time(struct cgroup_ops *ops, const char *cgroup,
        return cgfsng_get_io(ops, cgroup, "blkio.io_wait_time_recursive", value);
 }
 
+static bool cgfsng_can_use_cpuview(struct cgroup_ops *ops)
+{
+       struct hierarchy *cpu, *cpuacct;
+
+       if (pure_unified_layout(ops))
+               return false;
+
+       cpu = ops->get_hierarchy(ops, "cpu");
+       if (!cpu || is_unified_hierarchy(cpu))
+               return false;
+
+       cpuacct = ops->get_hierarchy(ops, "cpuacct");
+       if (!cpuacct || is_unified_hierarchy(cpuacct))
+               return false;
+
+       return true;
+}
+
 /* At startup, parse_hierarchies finds all the info we need about cgroup
  * mountpoints and current cgroups, and stores it in @d.
  */
@@ -999,6 +1017,7 @@ struct cgroup_ops *cgfsng_ops_init(void)
 
        /* cpuset */
        cgfsng_ops->get_cpuset_cpus = cgfsng_get_cpuset_cpus;
+       cgfsng_ops->can_use_cpuview = cgfsng_can_use_cpuview;
 
        /* blkio */
        cgfsng_ops->get_io_service_bytes        = cgfsng_get_io_service_bytes;
index 422122158e41427b6931460971b77195529dcb64..e955e7538399289d04062edde5ae18ec71059b3f 100644 (file)
@@ -138,6 +138,7 @@ struct cgroup_ops {
        /* cpuset */
        int (*get_cpuset_cpus)(struct cgroup_ops *ops, const char *cgroup,
                               char **value);
+       bool (*can_use_cpuview)(struct cgroup_ops *ops);
 
        /* io */
        int (*get_io_service_bytes)(struct cgroup_ops *ops, const char *cgroup,
@@ -152,6 +153,8 @@ struct cgroup_ops {
                                char **value);
 };
 
+extern struct cgroup_ops *cgroup_ops;
+
 extern struct cgroup_ops *cgroup_init(void);
 extern void cgroup_exit(struct cgroup_ops *ops);
 
index d2b187bfedaeca443d3981a2d207e6cc7f3b6093..f6bf203b4ec337de5e45f12ebfb544e3c9d15391 100644 (file)
@@ -31,7 +31,8 @@
 #include <sys/vfs.h>
 
 #include "bindings.h"
-#include "config.h" // for VERSION
+#include "cgroups/cgroup.h"
+#include "config.h"
 #include "sysfs_fuse.h"
 
 static int sys_devices_system_cpu_online_read(char *buf, size_t size,
@@ -72,8 +73,7 @@ static int sys_devices_system_cpu_online_read(char *buf, size_t size,
        if (!cpuset)
                goto err;
 
-       use_view = use_cpuview(cg);
-
+       use_view = cgroup_ops->can_use_cpuview(cgroup_ops);
        if (use_view)
                max_cpus = max_cpu_count(cg);