cgroup.h revision e7ab4d1ac9f8d99eecd5e2d22eb482a1fb0fbf23
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#pragma once
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen/***
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen This file is part of systemd.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Copyright 2013 Lennart Poettering
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen systemd is free software; you can redistribute it and/or modify it
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen under the terms of the GNU Lesser General Public License as published by
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen (at your option) any later version.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen systemd is distributed in the hope that it will be useful, but
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Lesser General Public License for more details.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen You should have received a copy of the GNU Lesser General Public License
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen***/
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#include <stdbool.h>
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#include "list.h"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#include "time-util.h"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersentypedef struct CGroupContext CGroupContext;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersentypedef struct CGroupDeviceAllow CGroupDeviceAllow;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersentypedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersentypedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersentypedef enum CGroupDevicePolicy {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /* When devices listed, will allow those, plus built-in ones,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if none are listed will allow everything. */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen CGROUP_AUTO,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /* Everything forbidden, except built-in ones and listed ones. */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen CGROUP_CLOSED,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /* Everythings forbidden, except for the listed devices */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen CGROUP_STRICT,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen _CGROUP_DEVICE_POLICY_MAX,
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen _CGROUP_DEVICE_POLICY_INVALID = -1
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen} CGroupDevicePolicy;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstruct CGroupDeviceAllow {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen LIST_FIELDS(CGroupDeviceAllow, device_allow);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *path;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool r:1;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool w:1;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool m:1;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen};
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstruct CGroupBlockIODeviceWeight {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *path;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t weight;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen};
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstruct CGroupBlockIODeviceBandwidth {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen char *path;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t bandwidth;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool read;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen};
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstruct CGroupContext {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool cpu_accounting;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool blockio_accounting;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool memory_accounting;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool tasks_accounting;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t cpu_shares;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t startup_cpu_shares;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen usec_t cpu_quota_per_sec_usec;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t blockio_weight;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t startup_blockio_weight;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t memory_limit;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen CGroupDevicePolicy device_policy;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen LIST_HEAD(CGroupDeviceAllow, device_allow);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen uint64_t tasks_max;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen bool delegate;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen};
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#include "unit.h"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen#include "cgroup-util.h"
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid cgroup_context_init(CGroupContext *c);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid cgroup_context_done(CGroupContext *c);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, ManagerState state);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenCGroupMask cgroup_context_get_mask(CGroupContext *c);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenCGroupMask unit_get_own_mask(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenCGroupMask unit_get_siblings_mask(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenCGroupMask unit_get_members_mask(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenCGroupMask unit_get_subtree_mask(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenCGroupMask unit_get_target_mask(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenCGroupMask unit_get_enable_mask(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid unit_update_cgroup_members_masks(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenchar *unit_default_cgroup_path(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_set_cgroup_path(Unit *u, const char *path);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_realize_cgroup(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid unit_release_cgroup(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid unit_prune_cgroup(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_watch_cgroup(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_attach_pids_to_cgroup(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint manager_setup_cgroup(Manager *m);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid manager_shutdown_cgroup(Manager *m, bool delete);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenunsigned manager_dispatch_cgroup_queue(Manager *m);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenUnit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenUnit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenUnit* manager_get_unit_by_pid(Manager *m, pid_t pid);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_search_main_pid(Unit *u, pid_t *ret);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_watch_all_pids(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_get_memory_current(Unit *u, uint64_t *ret);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_get_tasks_current(Unit *u, uint64_t *ret);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_get_cpu_usage(Unit *u, nsec_t *ret);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_reset_cpu_usage(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenbool unit_cgroup_delegate(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint unit_notify_cgroup_empty(Unit *u);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint manager_notify_cgroup_empty(Manager *m, const char *group);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid unit_invalidate_cgroup(Unit *u, CGroupMask m);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenvoid manager_invalidate_startup_units(Manager *m);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenconst char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom GundersenCGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen