cgroup.c revision cd7affaeea16d3904354b810a292e594dfef25dd
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley This file is part of systemd.
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley Copyright 2013 Lennart Poettering
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley systemd is free software; you can redistribute it and/or modify it
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley under the terms of the GNU Lesser General Public License as published by
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley the Free Software Foundation; either version 2.1 of the License, or
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley (at your option) any later version.
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley systemd is distributed in the hope that it will be useful, but
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley WITHOUT ANY WARRANTY; without even the implied warranty of
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley Lesser General Public License for more details.
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley You should have received a copy of the GNU Lesser General Public License
e9f58f98089a4e4670e5ee2d3df315561084786eRich Riley along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include "path-util.h"
#include "special.h"
#include "cgroup-util.h"
#include "cgroup.h"
assert(c);
assert(c);
assert(a);
free(a);
assert(c);
assert(w);
free(w);
void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b) {
assert(c);
assert(b);
free(b);
assert(c);
while (c->blockio_device_weights)
while (c->blockio_device_bandwidths)
while (c->device_allow)
assert(c);
return c->cpu_quota_usec;
assert(c);
return c->cpu_quota_per_sec_usec;
assert(c);
assert(f);
fprintf(f,
fprintf(f,
a->path,
fprintf(f,
w->path,
w->weight);
fprintf(f,
b->path,
assert(p);
return -errno;
log_warning("%s is not a block device and file system block device cannot be determined or is not local.", p);
return -ENODEV;
return -errno;
return -ENODEV;
acc);
bool good = false;
return -errno;
unsigned maj;
good = true;
good = true;
good = false;
if (!good)
if (maj <= 0)
type,
maj,
acc);
fail:
return -errno;
bool is_root;
assert(c);
if (mask == 0)
usec_t q;
if (!is_root) {
static const char auto_devices[] =
acc[k++] = 0;
if (c->cpu_accounting ||
if (c->blockio_accounting ||
c->blockio_device_weights ||
if (c->memory_accounting ||
return mask;
CGroupContext *c;
c = unit_get_cgroup_context(u);
return cgroup_context_get_mask(c);
assert(u);
if (u->cgroup_members_mask_valid)
return u->cgroup_members_mask;
u->cgroup_members_mask = 0;
Iterator i;
if (member == u)
u->cgroup_members_mask |=
u->cgroup_members_mask_valid = true;
return u->cgroup_members_mask;
assert(u);
return mask;
bool more;
assert(u);
more =
((m & ~u->cgroup_subtree_mask) != 0) &&
((~m & u->cgroup_subtree_mask) == 0);
u->cgroup_subtree_mask = m;
u->cgroup_subtree_mask_valid = true;
if (more)
s->cgroup_members_mask |= m;
s->cgroup_members_mask_valid = false;
assert(u);
if (u->cgroup_path &&
u->cgroup_realized &&
return u->cgroup_path;
return NULL;
assert(u);
if (!path)
return log_oom();
log_error(r == -EEXIST ? "cgroup %s exists already: %s" : "hashmap_put failed for %s: %s", path, strerror(-r));
u->cgroup_realized = true;
r = cg_migrate_everywhere(u->manager->cgroup_supported, u->cgroup_path, u->cgroup_path, migrate_callback, u);
assert(u);
assert(u);
if (u->in_cgroup_queue) {
u->in_cgroup_queue = false;
if (u->in_cgroup_queue)
u->in_cgroup_queue = true;
Unit *i;
while ((i = m->cgroup_queue)) {
r = unit_realize_cgroup_now(i);
Iterator i;
Unit *m;
u = slice;
CGroupContext *c;
assert(u);
c = unit_get_cgroup_context(u);
return unit_realize_cgroup_now(u);
assert(u);
if (!u->cgroup_path)
r = cg_trim_everywhere(u->manager->cgroup_supported, u->cgroup_path, !unit_has_name(u, SPECIAL_ROOT_SLICE));
u->cgroup_realized = false;
u->cgroup_realized_mask = 0;
assert(u);
if (!u->cgroup_path)
if (pid != 0) {
pid = 0;
return pid;
assert(m);
/* LEGACY: Already in /system.slice? If so, let's cut this
m->cgroup_root[0] = 0;
log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER ". File system hierarchy is at %s.", path);
if (m->pin_cgroupfs_fd < 0) {
return -errno;
assert(m);
Unit *u;
assert(m);
return NULL;
assert(m);
return NULL;
return NULL;
Unit *u;
assert(m);