core/cgroup: add a helper macro for a common pattern (#6926)
This commit is contained in:
committed by
Lennart Poettering
parent
dab9698e1d
commit
2e4025c0f9
+4
-32
@@ -2088,16 +2088,12 @@ int manager_notify_cgroup_empty(Manager *m, const char *cgroup) {
|
||||
|
||||
int unit_get_memory_current(Unit *u, uint64_t *ret) {
|
||||
_cleanup_free_ char *v = NULL;
|
||||
CGroupContext *cc;
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
assert(ret);
|
||||
|
||||
cc = unit_get_cgroup_context(u);
|
||||
if (!cc)
|
||||
return -ENODATA;
|
||||
if (!cc->memory_accounting)
|
||||
if (!UNIT_CGROUP_BOOL(u, memory_accounting))
|
||||
return -ENODATA;
|
||||
|
||||
if (!u->cgroup_path)
|
||||
@@ -2123,16 +2119,12 @@ int unit_get_memory_current(Unit *u, uint64_t *ret) {
|
||||
|
||||
int unit_get_tasks_current(Unit *u, uint64_t *ret) {
|
||||
_cleanup_free_ char *v = NULL;
|
||||
CGroupContext *cc;
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
assert(ret);
|
||||
|
||||
cc = unit_get_cgroup_context(u);
|
||||
if (!cc)
|
||||
return -ENODATA;
|
||||
if (!cc->tasks_accounting)
|
||||
if (!UNIT_CGROUP_BOOL(u, tasks_accounting))
|
||||
return -ENODATA;
|
||||
|
||||
if (!u->cgroup_path)
|
||||
@@ -2201,7 +2193,6 @@ static int unit_get_cpu_usage_raw(Unit *u, nsec_t *ret) {
|
||||
}
|
||||
|
||||
int unit_get_cpu_usage(Unit *u, nsec_t *ret) {
|
||||
CGroupContext *cc;
|
||||
nsec_t ns;
|
||||
int r;
|
||||
|
||||
@@ -2211,10 +2202,7 @@ int unit_get_cpu_usage(Unit *u, nsec_t *ret) {
|
||||
* started. If the cgroup has been removed already, returns the last cached value. To cache the value, simply
|
||||
* call this function with a NULL return value. */
|
||||
|
||||
cc = unit_get_cgroup_context(u);
|
||||
if (!cc)
|
||||
return -ENODATA;
|
||||
if (!cc->cpu_accounting)
|
||||
if (!UNIT_CGROUP_BOOL(u, cpu_accounting))
|
||||
return -ENODATA;
|
||||
|
||||
r = unit_get_cpu_usage_raw(u, &ns);
|
||||
@@ -2246,7 +2234,6 @@ int unit_get_ip_accounting(
|
||||
CGroupIPAccountingMetric metric,
|
||||
uint64_t *ret) {
|
||||
|
||||
CGroupContext *cc;
|
||||
uint64_t value;
|
||||
int fd, r;
|
||||
|
||||
@@ -2262,10 +2249,7 @@ int unit_get_ip_accounting(
|
||||
if (u->type == UNIT_SLICE)
|
||||
return -ENODATA;
|
||||
|
||||
cc = unit_get_cgroup_context(u);
|
||||
if (!cc)
|
||||
return -ENODATA;
|
||||
if (!cc->ip_accounting)
|
||||
if (!UNIT_CGROUP_BOOL(u, ip_accounting))
|
||||
return -ENODATA;
|
||||
|
||||
fd = IN_SET(metric, CGROUP_IP_INGRESS_BYTES, CGROUP_IP_INGRESS_PACKETS) ?
|
||||
@@ -2325,18 +2309,6 @@ int unit_reset_ip_accounting(Unit *u) {
|
||||
return r < 0 ? r : q;
|
||||
}
|
||||
|
||||
bool unit_cgroup_delegate(Unit *u) {
|
||||
CGroupContext *c;
|
||||
|
||||
assert(u);
|
||||
|
||||
c = unit_get_cgroup_context(u);
|
||||
if (!c)
|
||||
return false;
|
||||
|
||||
return c->delegate;
|
||||
}
|
||||
|
||||
void unit_invalidate_cgroup(Unit *u, CGroupMask m) {
|
||||
assert(u);
|
||||
|
||||
|
||||
+5
-1
@@ -194,7 +194,11 @@ int unit_get_ip_accounting(Unit *u, CGroupIPAccountingMetric metric, uint64_t *r
|
||||
int unit_reset_cpu_accounting(Unit *u);
|
||||
int unit_reset_ip_accounting(Unit *u);
|
||||
|
||||
bool unit_cgroup_delegate(Unit *u);
|
||||
#define UNIT_CGROUP_BOOL(u, name) \
|
||||
({ \
|
||||
CGroupContext *cc = unit_get_cgroup_context(u); \
|
||||
cc ? cc->name : false; \
|
||||
})
|
||||
|
||||
int unit_notify_cgroup_empty(Unit *u);
|
||||
int manager_notify_cgroup_empty(Manager *m, const char *group);
|
||||
|
||||
+2
-2
@@ -4205,7 +4205,7 @@ int unit_kill_context(
|
||||
* them. */
|
||||
|
||||
if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0 ||
|
||||
(detect_container() == 0 && !unit_cgroup_delegate(u)))
|
||||
(detect_container() == 0 && !UNIT_CGROUP_BOOL(u, delegate)))
|
||||
wait_for_exit = true;
|
||||
|
||||
if (send_sighup) {
|
||||
@@ -4644,7 +4644,7 @@ void unit_set_exec_params(Unit *u, ExecParameters *p) {
|
||||
assert(p);
|
||||
|
||||
p->cgroup_path = u->cgroup_path;
|
||||
SET_FLAG(p->flags, EXEC_CGROUP_DELEGATE, unit_cgroup_delegate(u));
|
||||
SET_FLAG(p->flags, EXEC_CGROUP_DELEGATE, UNIT_CGROUP_BOOL(u, delegate));
|
||||
}
|
||||
|
||||
int unit_fork_helper_process(Unit *u, pid_t *ret) {
|
||||
|
||||
Reference in New Issue
Block a user