]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: reduce delta
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 20 Jan 2018 11:40:45 +0000 (12:40 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 20 Jan 2018 11:43:33 +0000 (12:43 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfs.c
src/lxc/cgroups/cgmanager.c
src/lxc/cgroups/cgroup.c
src/lxc/cgroups/cgroup.h

index 4931c51e814105e0ddd8cb831237389d586268c8..fc25bc9b59a87231d31250c8b3d22cfc2633edee 100644 (file)
@@ -1804,7 +1804,9 @@ static char **subsystems_from_mount_options(const char *mount_options,
                        goto out_free;
                result[result_count + 1] = NULL;
                if (strncmp(token, "name=", 5) && !lxc_string_in_array(token, (const char **)kernel_list)) {
-                       // this is eg 'systemd' but the mount will be 'name=systemd'
+                       /* this is eg 'systemd' but the mount will be
+                        * 'name=systemd'
+                        */
                        result[result_count] = malloc(strlen(token) + 6);
                        if (result[result_count])
                                sprintf(result[result_count], "name=%s", token);
@@ -2072,9 +2074,10 @@ static bool cgroup_devices_has_allow_or_deny(struct cgfs_data *d,
                NULL
        };
 
-       // XXX FIXME if users could use something other than 'lxc.devices.deny = a'.
-       // not sure they ever do, but they *could*
-       // right now, I'm assuming they do NOT
+       /* XXX FIXME if users could use something other than 'lxc.devices.deny =
+        * a'.  not sure they ever do, but they *could* right now, I'm assuming
+        * they do NOT
+        */
        if (!for_allow && strcmp(v, "a") != 0 && strcmp(v, "a *:* rwm") != 0)
                return false;
 
@@ -2344,7 +2347,7 @@ struct cgroup_ops *cgfs_ops_init(void)
        return &cgfs_ops;
 }
 
-static void *cgfs_init(const char *name)
+static void *cgfs_init(struct lxc_handler *handler)
 {
        struct cgfs_data *d;
 
@@ -2353,7 +2356,7 @@ static void *cgfs_init(const char *name)
                return NULL;
 
        memset(d, 0, sizeof(*d));
-       d->name = strdup(name);
+       d->name = strdup(handler->name);
        if (!d->name)
                goto err1;
 
index 485a16a94a92e379d390f081b6c284e9e639d601..dccc04c3ccbe36b0583e18d3aafa6c4431b41daf 100644 (file)
@@ -141,7 +141,7 @@ static bool cgm_dbus_connect(void)
 
        cgm_lock();
        if (!dbus_threads_initialized) {
-               // tell dbus to do struct locking for thread safety
+               /* tell dbus to do struct locking for thread safety */
                dbus_threads_init_default();
                dbus_threads_initialized = true;
        }
@@ -171,7 +171,7 @@ static bool cgm_dbus_connect(void)
                return false;
        }
 
-       // get the api version
+       /* get the api version */
        if (cgmanager_get_api_version_sync(NULL, cgroup_manager, &api_version) != 0) {
                NihError *nerr;
                nerr = nih_error_get();
@@ -545,7 +545,7 @@ static void cgm_remove_cgroup(const char *controller, const char *path)
                INFO("cgroup removal attempt: %s:%s did not exist", controller, path);
 }
 
-static void *cgm_init(const char *name)
+static void *cgm_init(struct lxc_handler *handler)
 {
        struct cgm_data *d;
 
@@ -559,7 +559,7 @@ static void *cgm_init(const char *name)
        }
 
        memset(d, 0, sizeof(*d));
-       d->name = strdup(name);
+       d->name = strdup(handler->name);
        if (!d->name) {
                cgm_dbus_disconnect();
                goto err1;
@@ -567,7 +567,7 @@ static void *cgm_init(const char *name)
 
        d->cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
 
-       // cgm_create immediately gets called so keep the connection open
+       /* cgm_create immediately gets called so keep the connection open */
        return d;
 
 err1:
@@ -625,10 +625,10 @@ static inline bool cgm_create(void *hdata)
 
        if (!d)
                return false;
-// XXX we should send a hint to the cgmanager that when these
-// cgroups become empty they should be deleted.  Requires a cgmanager
-// extension
 
+       /* XXX we should send a hint to the cgmanager that when these cgroups
+        * become empty they should be deleted. Requires a cgmanager extension.
+        */
        memset(result, 0, MAXPATHLEN);
        tmp = lxc_string_replace("%n", d->name, d->cgroup_pattern);
        if (!tmp)
@@ -644,7 +644,7 @@ static inline bool cgm_create(void *hdata)
        while (*tmp == '/')
                tmp++;
 again:
-       if (index == 100) { // turn this into a warn later
+       if (index == 100) { /* turn this into a warn later */
                ERROR("cgroup error?  100 cgroups with this name already running");
                goto bad;
        }
@@ -667,7 +667,7 @@ again:
                if (existed == 1)
                        goto next;
        }
-       // success
+       /* success */
        cgroup_path = strdup(tmp);
        if (!cgroup_path) {
                cleanup_cgroups(tmp);
@@ -952,7 +952,7 @@ static int cgm_get(const char *filename, char *value, size_t len, const char *na
                close(p[1]);
                return -1;
        }
-       if (!pid) // do_cgm_get exits
+       if (!pid) /* do_cgm_get exits */
                do_cgm_get(name, lxcpath, filename, p[1], len && value);
        close(p[1]);
        ret = read(p[0], &newlen, sizeof(newlen));
@@ -967,12 +967,12 @@ static int cgm_get(const char *filename, char *value, size_t len, const char *na
                goto out;
        }
        memset(value, 0, len);
-       if (newlen < 0) { // child is reporting an error
+       if (newlen < 0) { /* child is reporting an error */
                close(p[0]);
                ret = -1;
                goto out;
        }
-       if (newlen == 0) { // empty read
+       if (newlen == 0) { /* empty read */
                close(p[0]);
                ret = 0;
                goto out;
@@ -988,7 +988,7 @@ static int cgm_get(const char *filename, char *value, size_t len, const char *na
                value[len-1] = '\0';
                newlen = len-1;
        } else if (newlen+1 < len) {
-               // cgmanager doesn't add eol to last entry
+               /* cgmanager doesn't add eol to last entry */
                value[newlen++] = '\n';
                value[newlen] = '\0';
        }
@@ -1002,7 +1002,7 @@ out:
 static void do_cgm_set(const char *name, const char *lxcpath, const char *filename, const char *value, int outp)
 {
        char *controller, *key, *cgroup = NULL;
-       int retval = 0;  // value we are sending to the parent over outp
+       int retval = 0;  /* value we are sending to the parent over outp */
        int ret;
        char *cglast;
 
@@ -1088,7 +1088,7 @@ static int cgm_set(const char *filename, const char *value, const char *name, co
                close(p[0]);
                return -1;
        }
-       if (!pid) // do_cgm_set exits
+       if (!pid) /* do_cgm_set exits */
                do_cgm_set(name, lxcpath, filename, value, p[1]);
        close(p[1]);
        ret = read(p[0], &v, sizeof(v));
@@ -1333,7 +1333,7 @@ static bool collect_subsystems(void)
        size_t sz = 0;
        FILE *f = NULL;
 
-       if (subsystems) // already initialized
+       if (subsystems) /* already initialized */
                return true;
 
        subsystems_inone = malloc(2 * sizeof(char *));
@@ -1444,7 +1444,7 @@ struct cgroup_ops *cgm_ops_init(void)
        if (api_version < CGM_SUPPORTS_MULT_CONTROLLERS)
                cgm_all_controllers_same = false;
 
-       // if root, try to escape to root cgroup
+       /* if root, try to escape to root cgroup */
        if (geteuid() == 0 && !cgm_escape(NULL)) {
                free_subsystems();
                return NULL;
@@ -1507,7 +1507,7 @@ static bool cgm_setup_limits(void *hdata, struct lxc_list *cgroup_settings, bool
                cg = iterator->elem;
                if (do_devices != !strncmp("devices", cg->subsystem, 7))
                        continue;
-               if (strlen(cg->subsystem) > 100) // i smell a rat
+               if (strlen(cg->subsystem) > 100) /* i smell a rat */
                        goto out;
                strcpy(controller, cg->subsystem);
                p = strchr(controller, '.');
@@ -1564,7 +1564,7 @@ static bool cgm_chown(void *hdata, struct lxc_conf *conf)
 }
 
 /*
- * TODO: this should be re-written to use the get_config_item("lxc.id_map")
+ * TODO: this should be re-written to use the get_config_item("lxc.idmap")
  * cmd api instead of getting the idmap from c->lxc_conf.  The reason is
  * that the id_maps may be different if the container was started with a
  * -f or -s argument.
@@ -1653,7 +1653,7 @@ static bool cgm_mount_cgroup(void *hdata, const char *root, int type)
                return cgm_bind_dir(root, CGMANAGER_LOWER_SOCK);
        if (dir_exists(CGMANAGER_UPPER_SOCK))
                return cgm_bind_dir(root, CGMANAGER_UPPER_SOCK);
-       // Host doesn't have cgmanager running?  Then how did we get here?
+       /* Host doesn't have cgmanager running?  Then how did we get here? */
        return false;
 }
 
index 780bc8bc936cdfec8364932ac6bd9cd73afd9dfe..36a665b1c2cc8eedad7dfe3afcd7663826071e52 100644 (file)
@@ -65,7 +65,7 @@ bool cgroup_init(struct lxc_handler *handler)
 
        if (ops) {
                INFO("cgroup driver %s initing for %s", ops->name, handler->name);
-               handler->cgroup_data = ops->init(handler->name);
+               handler->cgroup_data = ops->init(handler);
        }
 
        return handler->cgroup_data != NULL;
@@ -209,7 +209,8 @@ int lxc_cgroup_get(const char *filename, char *value, size_t len,
        return -1;
 }
 
-void cgroup_disconnect(void) {
+void cgroup_disconnect(void)
+{
        if (ops && ops->disconnect)
                ops->disconnect();
 }
index 11b251e698edb0f2ea0f8c8890d26cb56e4fbf8b..f17a6abe0adc2b69191966f2cc599738fbc7510c 100644 (file)
@@ -41,7 +41,7 @@ typedef enum {
 struct cgroup_ops {
        const char *name;
 
-       void *(*init)(const char *name);
+       void *(*init)(struct lxc_handler *handler);
        void (*destroy)(void *hdata, struct lxc_conf *conf);
        bool (*create)(void *hdata);
        bool (*enter)(void *hdata, pid_t pid);