dbus-cgroup.c revision 718db96199eb307751264e4163555662c9a389fa
/*-*- 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) {
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) {
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) {
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);
}
const sd_bus_vtable bus_cgroup_vtable[] = {
SD_BUS_PROPERTY("CPUAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, cpu_accounting), 0),
SD_BUS_PROPERTY("BlockIOAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, blockio_accounting), 0),
SD_BUS_PROPERTY("BlockIOWeight", "t", bus_property_get_ulong, offsetof(CGroupContext, 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),
};
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;
}
return 1;
unsigned long ul;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->cpu_shares = ul;
}
return 1;
int b;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->blockio_accounting = b;
}
return 1;
unsigned long ul;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->blockio_weight = ul;
}
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 (mode != UNIT_CHECK) {
if (n == 0) {
}
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;
unsigned long ul;
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 (mode != UNIT_CHECK) {
if (n == 0) {
while (c->blockio_device_weights)
}
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;
}
return 1;
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->memory_limit = limit;
}
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;
}
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 (mode != UNIT_CHECK) {
if (n == 0) {
while (c->device_allow)
}
if (!f)
return -ENOMEM;
fputs("DeviceAllow=\n", f);
fflush(f);
}
return 1;
}
return 0;
}