From 4f8a2329ef626675895974d53a6afad68a0d255a Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Wed, 10 Feb 2016 15:44:01 +0100 Subject: [PATCH] cgroup: remove support for NetClass= directive Support for net_cls.class_id through the NetClass= configuration directive has been added in v227 in preparation for a per-unit packet filter mechanism. However, it turns out the kernel people have decided to deprecate the net_cls and net_prio controllers in v2. Tejun provides a comprehensive justification for this in his commit, which has landed during the merge window for kernel v4.5: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=bd1060a1d671 As we're aiming for full support for the v2 cgroup hierarchy, we can no longer support this feature. Userspace tool such as nftables are moving over to setting rules that are specific to the full cgroup path of a task, which obsoletes these controllers anyway. This commit removes support for tweaking details in the net_cls controller, but keeps the NetClass= directive around for legacy compatibility reasons. --- src/basic/cgroup-util.c | 1 - src/basic/cgroup-util.h | 2 - src/core/cgroup.c | 117 +--------------------------------------- 3 files changed, 2 insertions(+), 118 deletions(-) diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 708e566a6..4d89043ab 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -2333,7 +2333,6 @@ static const char *cgroup_controller_table[_CGROUP_CONTROLLER_MAX] = { [CGROUP_CONTROLLER_MEMORY] = "memory", [CGROUP_CONTROLLER_DEVICES] = "devices", [CGROUP_CONTROLLER_PIDS] = "pids", - [CGROUP_CONTROLLER_NET_CLS] = "net_cls", }; DEFINE_STRING_TABLE_LOOKUP(cgroup_controller, CGroupController); diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index cee04479e..e8fce8353 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -34,7 +34,6 @@ typedef enum CGroupController { CGROUP_CONTROLLER_MEMORY, CGROUP_CONTROLLER_DEVICES, CGROUP_CONTROLLER_PIDS, - CGROUP_CONTROLLER_NET_CLS, _CGROUP_CONTROLLER_MAX, _CGROUP_CONTROLLER_INVALID = -1, } CGroupController; @@ -49,7 +48,6 @@ typedef enum CGroupMask { CGROUP_MASK_MEMORY = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_MEMORY), CGROUP_MASK_DEVICES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_DEVICES), CGROUP_MASK_PIDS = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_PIDS), - CGROUP_MASK_NET_CLS = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_NET_CLS), _CGROUP_MASK_ALL = CGROUP_CONTROLLER_TO_MASK(_CGROUP_CONTROLLER_MAX) - 1 } CGroupMask; diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 76a3d2d25..8d7d57e7a 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -54,8 +54,6 @@ void cgroup_context_init(CGroupContext *c) { c->startup_blockio_weight = CGROUP_BLKIO_WEIGHT_INVALID; c->tasks_max = (uint64_t) -1; - - c->netclass_type = CGROUP_NETCLASS_TYPE_NONE; } void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a) { @@ -300,7 +298,7 @@ fail: return -errno; } -void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, uint32_t netclass, ManagerState state) { +void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, ManagerState state) { bool is_root; int r; @@ -498,17 +496,6 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set pids.max on %s: %m", path); } - - if (mask & CGROUP_MASK_NET_CLS) { - char buf[DECIMAL_STR_MAX(uint32_t)]; - - sprintf(buf, "%" PRIu32, netclass); - - r = cg_set_attribute("net_cls", path, "net_cls.classid", buf); - if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, - "Failed to set net_cls.classid on %s: %m", path); - } } CGroupMask cgroup_context_get_mask(CGroupContext *c) { @@ -541,9 +528,6 @@ CGroupMask cgroup_context_get_mask(CGroupContext *c) { c->tasks_max != (uint64_t) -1) mask |= CGROUP_MASK_PIDS; - if (c->netclass_type != CGROUP_NETCLASS_TYPE_NONE) - mask |= CGROUP_MASK_NET_CLS; - return mask; } @@ -911,103 +895,6 @@ static bool unit_has_mask_realized(Unit *u, CGroupMask target_mask) { return u->cgroup_realized && u->cgroup_realized_mask == target_mask; } -static int unit_find_free_netclass_cgroup(Unit *u, uint32_t *ret) { - - uint32_t start, i; - Manager *m; - - assert(u); - - m = u->manager; - - i = start = m->cgroup_netclass_registry_last; - - do { - i++; - - if (!hashmap_get(m->cgroup_netclass_registry, UINT_TO_PTR(i))) { - m->cgroup_netclass_registry_last = i; - *ret = i; - return 0; - } - - if (i == UINT32_MAX) - i = CGROUP_NETCLASS_FIXED_MAX; - - } while (i != start); - - return -ENOBUFS; -} - -int unit_add_to_netclass_cgroup(Unit *u) { - - CGroupContext *cc; - Unit *first; - void *key; - int r; - - assert(u); - - cc = unit_get_cgroup_context(u); - if (!cc) - return 0; - - switch (cc->netclass_type) { - case CGROUP_NETCLASS_TYPE_NONE: - return 0; - - case CGROUP_NETCLASS_TYPE_FIXED: - u->cgroup_netclass_id = cc->netclass_id; - break; - - case CGROUP_NETCLASS_TYPE_AUTO: - /* Allocate a new ID in case it was requested and not done yet */ - if (u->cgroup_netclass_id == 0) { - r = unit_find_free_netclass_cgroup(u, &u->cgroup_netclass_id); - if (r < 0) - return r; - - log_debug("Dynamically assigned netclass cgroup id %" PRIu32 " to %s", u->cgroup_netclass_id, u->id); - } - - break; - } - - r = hashmap_ensure_allocated(&u->manager->cgroup_netclass_registry, &trivial_hash_ops); - if (r < 0) - return r; - - key = UINT32_TO_PTR(u->cgroup_netclass_id); - first = hashmap_get(u->manager->cgroup_netclass_registry, key); - - if (first) { - LIST_PREPEND(cgroup_netclass, first, u); - return hashmap_replace(u->manager->cgroup_netclass_registry, key, u); - } - - return hashmap_put(u->manager->cgroup_netclass_registry, key, u); -} - -int unit_remove_from_netclass_cgroup(Unit *u) { - - Unit *head; - void *key; - - assert(u); - - key = UINT32_TO_PTR(u->cgroup_netclass_id); - - LIST_FIND_HEAD(cgroup_netclass, u, head); - LIST_REMOVE(cgroup_netclass, head, u); - - if (head) - return hashmap_replace(u->manager->cgroup_netclass_registry, key, head); - - hashmap_remove(u->manager->cgroup_netclass_registry, key); - - return 0; -} - /* Check if necessary controllers and attributes for a unit are in place. * * If so, do nothing. @@ -1043,7 +930,7 @@ static int unit_realize_cgroup_now(Unit *u, ManagerState state) { return r; /* Finally, apply the necessary attributes. */ - cgroup_context_apply(unit_get_cgroup_context(u), target_mask, u->cgroup_path, u->cgroup_netclass_id, state); + cgroup_context_apply(unit_get_cgroup_context(u), target_mask, u->cgroup_path, state); return 0; } -- 2.30.2