2010-08-17 03:33:07 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2010-03-31 16:29:55 +02:00
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
Copyright 2013 Lennart Poettering
|
2010-03-31 16:29:55 +02:00
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2010-03-31 16:29:55 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2010-03-31 16:29:55 +02:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2015-02-10 12:56:53 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
#include "list.h"
|
2015-02-10 12:56:53 +01:00
|
|
|
#include "time-util.h"
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
typedef struct CGroupContext CGroupContext;
|
|
|
|
typedef struct CGroupDeviceAllow CGroupDeviceAllow;
|
|
|
|
typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
|
|
|
|
typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
typedef enum CGroupDevicePolicy {
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
/* When devices listed, will allow those, plus built-in ones,
|
|
|
|
if none are listed will allow everything. */
|
|
|
|
CGROUP_AUTO,
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
/* Everything forbidden, except built-in ones and listed ones. */
|
|
|
|
CGROUP_CLOSED,
|
2010-04-21 04:01:24 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
/* Everythings forbidden, except for the listed devices */
|
|
|
|
CGROUP_STRICT,
|
2010-04-21 04:01:24 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
_CGROUP_DEVICE_POLICY_MAX,
|
|
|
|
_CGROUP_DEVICE_POLICY_INVALID = -1
|
|
|
|
} CGroupDevicePolicy;
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
struct CGroupDeviceAllow {
|
|
|
|
LIST_FIELDS(CGroupDeviceAllow, device_allow);
|
|
|
|
char *path;
|
|
|
|
bool r:1;
|
|
|
|
bool w:1;
|
|
|
|
bool m:1;
|
|
|
|
};
|
2010-06-21 23:27:18 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
struct CGroupBlockIODeviceWeight {
|
|
|
|
LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights);
|
|
|
|
char *path;
|
|
|
|
unsigned long weight;
|
2010-03-31 16:29:55 +02:00
|
|
|
};
|
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
struct CGroupBlockIODeviceBandwidth {
|
|
|
|
LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths);
|
|
|
|
char *path;
|
|
|
|
uint64_t bandwidth;
|
|
|
|
bool read;
|
|
|
|
};
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
struct CGroupContext {
|
|
|
|
bool cpu_accounting;
|
|
|
|
bool blockio_accounting;
|
|
|
|
bool memory_accounting;
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
unsigned long cpu_shares;
|
2014-05-15 17:09:34 +02:00
|
|
|
unsigned long startup_cpu_shares;
|
2014-04-25 13:27:25 +02:00
|
|
|
usec_t cpu_quota_per_sec_usec;
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
unsigned long blockio_weight;
|
2014-05-15 17:09:34 +02:00
|
|
|
unsigned long startup_blockio_weight;
|
2013-06-27 04:14:27 +02:00
|
|
|
LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights);
|
|
|
|
LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
|
2013-01-12 04:24:12 +01:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
uint64_t memory_limit;
|
2011-06-30 00:11:25 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
CGroupDevicePolicy device_policy;
|
|
|
|
LIST_HEAD(CGroupDeviceAllow, device_allow);
|
2014-11-05 17:57:23 +01:00
|
|
|
|
|
|
|
bool delegate;
|
2013-06-27 04:14:27 +02:00
|
|
|
};
|
2011-06-30 00:11:25 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
#include "unit.h"
|
|
|
|
#include "cgroup-util.h"
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
void cgroup_context_init(CGroupContext *c);
|
|
|
|
void cgroup_context_done(CGroupContext *c);
|
|
|
|
void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
|
2014-05-22 00:06:16 +02:00
|
|
|
void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const char *path, ManagerState state);
|
2014-02-14 19:11:07 +01:00
|
|
|
|
2014-05-22 00:06:16 +02:00
|
|
|
CGroupControllerMask cgroup_context_get_mask(CGroupContext *c);
|
2010-07-10 17:34:42 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a);
|
|
|
|
void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
|
|
|
|
void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2014-02-14 19:11:07 +01:00
|
|
|
CGroupControllerMask unit_get_cgroup_mask(Unit *u);
|
|
|
|
CGroupControllerMask unit_get_siblings_mask(Unit *u);
|
|
|
|
CGroupControllerMask unit_get_members_mask(Unit *u);
|
|
|
|
CGroupControllerMask unit_get_target_mask(Unit *u);
|
|
|
|
|
|
|
|
void unit_update_cgroup_members_masks(Unit *u);
|
2013-06-30 23:55:36 +02:00
|
|
|
int unit_realize_cgroup(Unit *u);
|
2014-12-09 02:31:42 +01:00
|
|
|
void unit_destroy_cgroup_if_empty(Unit *u);
|
2014-12-10 22:06:44 +01:00
|
|
|
int unit_attach_pids_to_cgroup(Unit *u);
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
int manager_setup_cgroup(Manager *m);
|
|
|
|
void manager_shutdown_cgroup(Manager *m, bool delete);
|
2010-04-18 03:04:54 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
unsigned manager_dispatch_cgroup_queue(Manager *m);
|
2010-10-27 03:16:49 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
|
|
|
|
Unit* manager_get_unit_by_pid(Manager *m, pid_t pid);
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
pid_t unit_search_main_pid(Unit *u);
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
int manager_notify_cgroup_empty(Manager *m, const char *group);
|
2010-03-31 16:29:55 +02:00
|
|
|
|
2015-03-01 16:24:19 +01:00
|
|
|
int unit_get_memory_current(Unit *u, uint64_t *ret);
|
|
|
|
int unit_get_cpu_usage(Unit *u, nsec_t *ret);
|
|
|
|
int unit_reset_cpu_usage(Unit *u);
|
|
|
|
|
2015-09-01 17:25:59 +02:00
|
|
|
bool unit_cgroup_delegate(Unit *u);
|
|
|
|
|
2013-06-27 04:14:27 +02:00
|
|
|
const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
|
|
|
|
CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;
|