dbus-cgroup.c revision a931ad47a8623163a29d898224d8a8c1177ffdaf
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
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 "bus-util.h"
#include "path-util.h"
#include "cgroup-util.h"
#include "cgroup.h"
#include "dbus-cgroup.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_device_policy, CGroupDevicePolicy);
static int property_get_blockio_device_weight(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
CGroupContext *c = userdata;
int r;
assert(c);
if (r < 0)
return r;
if (r < 0)
return r;
}
return sd_bus_message_close_container(reply);
}
static int property_get_blockio_device_bandwidths(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
CGroupContext *c = userdata;
int r;
assert(c);
if (r < 0)
return r;
continue;
if (r < 0)
return r;
}
return sd_bus_message_close_container(reply);
}
static int property_get_device_allow(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
CGroupContext *c = userdata;
int r;
assert(c);
if (r < 0)
return r;
unsigned k = 0;
char rwm[4];
if (a->r)
rwm[k++] = 'r';
if (a->w)
rwm[k++] = 'w';
if (a->m)
rwm[k++] = 'm';
rwm[k] = 0;
if (r < 0)
return r;
}
return sd_bus_message_close_container(reply);
}
static int property_get_ulong_as_u64(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
return sd_bus_message_append(reply, "t", *ul == (unsigned long) -1 ? (uint64_t) -1 : (uint64_t) *ul);
}
const sd_bus_vtable bus_cgroup_vtable[] = {
SD_BUS_PROPERTY("CPUAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, cpu_accounting), 0),
SD_BUS_PROPERTY("CPUShares", "t", property_get_ulong_as_u64, offsetof(CGroupContext, cpu_shares), 0),
SD_BUS_PROPERTY("StartupCPUShares", "t", property_get_ulong_as_u64, offsetof(CGroupContext, startup_cpu_shares), 0),
SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_per_sec_usec), 0),
SD_BUS_PROPERTY("BlockIOAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, blockio_accounting), 0),
SD_BUS_PROPERTY("BlockIOWeight", "t", property_get_ulong_as_u64, offsetof(CGroupContext, blockio_weight), 0),
SD_BUS_PROPERTY("StartupBlockIOWeight", "t", property_get_ulong_as_u64, offsetof(CGroupContext, startup_blockio_weight), 0),
SD_BUS_PROPERTY("MemoryAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, memory_accounting), 0),
SD_BUS_PROPERTY("DevicePolicy", "s", property_get_cgroup_device_policy, offsetof(CGroupContext, device_policy), 0),
};
static int bus_cgroup_set_transient_property(
Unit *u,
CGroupContext *c,
const char *name,
sd_bus_error *error) {
int r;
assert(u);
assert(c);
int b;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->delegate = b;
}
return 1;
}
return 0;
}
Unit *u,
CGroupContext *c,
const char *name,
sd_bus_error *error) {
int r;
assert(u);
assert(c);
int b;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->cpu_accounting = b;
u->cgroup_realized_mask &= ~CGROUP_CPUACCT;
}
return 1;
unsigned long ul;
if (r < 0)
return r;
ul = (unsigned long) -1;
else {
}
if (mode != UNIT_CHECK) {
c->cpu_shares = ul;
u->cgroup_realized_mask &= ~CGROUP_CPU;
}
return 1;
unsigned long ul;
if (r < 0)
return r;
ul = (unsigned long) -1;
else {
}
if (mode != UNIT_CHECK) {
c->startup_cpu_shares = ul;
u->cgroup_realized_mask &= ~CGROUP_CPU;
}
return 1;
if (r < 0)
return r;
if (u64 <= 0)
if (mode != UNIT_CHECK) {
c->cpu_quota_per_sec_usec = u64;
u->cgroup_realized_mask &= ~CGROUP_CPU;
unit_write_drop_in_private_format(u, mode, "CPUQuota", "CPUQuota=%0.f%%", (double) (c->cpu_quota_per_sec_usec / 10000));
}
return 1;
int b;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->blockio_accounting = b;
u->cgroup_realized_mask &= ~CGROUP_BLKIO;
}
return 1;
unsigned long ul;
if (r < 0)
return r;
ul = (unsigned long) -1;
else {
}
if (mode != UNIT_CHECK) {
c->blockio_weight = ul;
u->cgroup_realized_mask &= ~CGROUP_BLKIO;
}
return 1;
unsigned long ul;
if (r < 0)
return r;
ul = (unsigned long) -1;
else {
}
if (mode != UNIT_CHECK) {
c->startup_blockio_weight = ul;
u->cgroup_realized_mask &= ~CGROUP_BLKIO;
}
return 1;
const char *path;
bool read = true;
unsigned n = 0;
read = false;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
CGroupBlockIODeviceBandwidth *a = NULL, *b;
a = b;
break;
}
}
if (!a) {
if (!a)
return -ENOMEM;
if (!a->path) {
free(a);
return -ENOMEM;
}
}
}
n++;
}
if (r < 0)
return r;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
if (n == 0) {
}
u->cgroup_realized_mask &= ~CGROUP_BLKIO;
if (!f)
return -ENOMEM;
if (read) {
fputs("BlockIOReadBandwidth=\n", f);
if (a->read)
} else {
fputs("BlockIOWriteBandwidth=\n", f);
if (!a->read)
}
fflush(f);
}
return 1;
const char *path;
unsigned n = 0;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
CGroupBlockIODeviceWeight *a = NULL, *b;
a = b;
break;
}
}
if (!a) {
if (!a)
return -ENOMEM;
if (!a->path) {
free(a);
return -ENOMEM;
}
}
}
n++;
}
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
if (n == 0) {
while (c->blockio_device_weights)
}
u->cgroup_realized_mask &= ~CGROUP_BLKIO;
if (!f)
return -ENOMEM;
fputs("BlockIODeviceWeight=\n", f);
fflush(f);
}
return 1;
int b;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->memory_accounting = b;
u->cgroup_realized_mask &= ~CGROUP_MEMORY;
}
return 1;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->memory_limit = limit;
u->cgroup_realized_mask &= ~CGROUP_MEMORY;
}
return 1;
const char *policy;
if (r < 0)
return r;
if (p < 0)
return -EINVAL;
if (mode != UNIT_CHECK) {
char *buf;
c->device_policy = p;
u->cgroup_realized_mask &= ~CGROUP_DEVICE;
}
return 1;
unsigned n = 0;
if (r < 0)
return r;
rwm = "rwm";
if (mode != UNIT_CHECK) {
CGroupDeviceAllow *a = NULL, *b;
a = b;
break;
}
}
if (!a) {
if (!a)
return -ENOMEM;
if (!a->path) {
free(a);
return -ENOMEM;
}
}
}
n++;
}
if (r < 0)
return r;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
if (n == 0) {
while (c->device_allow)
}
u->cgroup_realized_mask &= ~CGROUP_DEVICE;
if (!f)
return -ENOMEM;
fputs("DeviceAllow=\n", f);
fflush(f);
}
return 1;
}
if (r != 0)
return r;
}
return 0;
}