summaryrefslogtreecommitdiff
path: root/src/core/cgroup.h
diff options
context:
space:
mode:
authorSven Eden <yamakuzure@gmx.net>2017-01-26 08:21:20 +0100
committerSven Eden <yamakuzure@gmx.net>2017-03-14 10:23:02 +0100
commit56c4f5eceb1e77ac537960e255076712fcd0e7e5 (patch)
tree3f739e0e41b14aa7d5e8f1e9a9e99444134c6c53 /src/core/cgroup.h
parent35ed426f81eb72dc23ce2dcc625ea88be1c95990 (diff)
[Patch 2/3] Add cgroups initialization and handling
Add a highly reduced src/core/cgroup.[hc] to enable elogind to setup cgroups for proper usage.
Diffstat (limited to 'src/core/cgroup.h')
-rw-r--r--src/core/cgroup.h150
1 files changed, 150 insertions, 0 deletions
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
new file mode 100644
index 000000000..767eea2fb
--- /dev/null
+++ b/src/core/cgroup.h
@@ -0,0 +1,150 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ 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
+ (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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stdbool.h>
+
+#include "list.h"
+#include "time-util.h"
+#include "logind.h"
+
+typedef struct CGroupContext CGroupContext;
+typedef struct CGroupDeviceAllow CGroupDeviceAllow;
+typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
+typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
+
+typedef enum CGroupDevicePolicy {
+
+ /* When devices listed, will allow those, plus built-in ones,
+ if none are listed will allow everything. */
+ CGROUP_AUTO,
+
+ /* Everything forbidden, except built-in ones and listed ones. */
+ CGROUP_CLOSED,
+
+ /* Everythings forbidden, except for the listed devices */
+ CGROUP_STRICT,
+
+ _CGROUP_DEVICE_POLICY_MAX,
+ _CGROUP_DEVICE_POLICY_INVALID = -1
+} CGroupDevicePolicy;
+
+struct CGroupDeviceAllow {
+ LIST_FIELDS(CGroupDeviceAllow, device_allow);
+ char *path;
+ bool r:1;
+ bool w:1;
+ bool m:1;
+};
+
+struct CGroupBlockIODeviceWeight {
+ LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights);
+ char *path;
+ unsigned long weight;
+};
+
+struct CGroupBlockIODeviceBandwidth {
+ LIST_FIELDS(CGroupBlockIODeviceBandwidth, device_bandwidths);
+ char *path;
+ uint64_t bandwidth;
+ bool read;
+};
+
+struct CGroupContext {
+ bool cpu_accounting;
+ bool blockio_accounting;
+ bool memory_accounting;
+
+ unsigned long cpu_shares;
+ unsigned long startup_cpu_shares;
+ usec_t cpu_quota_per_sec_usec;
+
+ unsigned long blockio_weight;
+ unsigned long startup_blockio_weight;
+ LIST_HEAD(CGroupBlockIODeviceWeight, blockio_device_weights);
+ LIST_HEAD(CGroupBlockIODeviceBandwidth, blockio_device_bandwidths);
+
+ uint64_t memory_limit;
+
+ CGroupDevicePolicy device_policy;
+ LIST_HEAD(CGroupDeviceAllow, device_allow);
+
+ bool delegate;
+};
+
+// #include "unit.h"
+#include "cgroup-util.h"
+
+void cgroup_context_init(CGroupContext *c);
+void cgroup_context_done(CGroupContext *c);
+// UNNEEDED void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix);
+// UNNEEDED void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, ManagerState state);
+
+CGroupMask cgroup_context_get_mask(CGroupContext *c);
+
+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);
+
+// UNNEEDED CGroupMask unit_get_own_mask(Unit *u);
+// UNNEEDED CGroupMask unit_get_siblings_mask(Unit *u);
+// UNNEEDED CGroupMask unit_get_members_mask(Unit *u);
+// UNNEEDED CGroupMask unit_get_subtree_mask(Unit *u);
+
+// UNNEEDED vCGroupMask unit_get_target_mask(Unit *u);
+// UNNEEDED CGroupMask unit_get_enable_mask(Unit *u);
+
+// UNNEEDED void unit_update_cgroup_members_masks(Unit *u);
+
+// UNNEEDED har *unit_default_cgroup_path(Unit *u);
+// UNNEEDED int unit_set_cgroup_path(Unit *u, const char *path);
+
+// UNNEEDED int unit_realize_cgroup(Unit *u);
+// UNNEEDED void unit_release_cgroup(Unit *u);
+// UNNEEDED void unit_prune_cgroup(Unit *u);
+// UNNEEDED int unit_watch_cgroup(Unit *u);
+
+// UNNEEDED int unit_attach_pids_to_cgroup(Unit *u);
+
+int manager_setup_cgroup(Manager *m);
+void manager_shutdown_cgroup(Manager *m, bool delete);
+
+// UNNEEDED unsigned manager_dispatch_cgroup_queue(Manager *m);
+
+// UNNEEDED Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
+// UNNEEDED Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid);
+// UNNEEDED Unit* manager_get_unit_by_pid(Manager *m, pid_t pid);
+
+// UNNEEDED int unit_search_main_pid(Unit *u, pid_t *ret);
+// UNNEEDED int unit_watch_all_pids(Unit *u);
+
+// UNNEEDED int unit_get_memory_current(Unit *u, uint64_t *ret);
+// UNNEEDED int unit_get_cpu_usage(Unit *u, nsec_t *ret);
+// UNNEEDED int unit_reset_cpu_usage(Unit *u);
+
+// UNNEEDED bool unit_cgroup_delegate(Unit *u);
+
+// UNNEEDED int unit_notify_cgroup_empty(Unit *u);
+// UNNEEDED int manager_notify_cgroup_empty(Manager *m, const char *group);
+
+const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
+CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;