cgroups: non-functional changes

parent 4742cd9a
...@@ -37,8 +37,7 @@ extern struct cgroup_ops *cgfs_ops_init(void); ...@@ -37,8 +37,7 @@ extern struct cgroup_ops *cgfs_ops_init(void);
extern struct cgroup_ops *cgfsng_ops_init(void); extern struct cgroup_ops *cgfsng_ops_init(void);
extern struct cgroup_ops *cgm_ops_init(void); extern struct cgroup_ops *cgm_ops_init(void);
__attribute__((constructor)) __attribute__((constructor)) void cgroup_ops_init(void)
void cgroup_ops_init(void)
{ {
if (ops) { if (ops) {
INFO("cgroup driver %s", ops->name); INFO("cgroup driver %s", ops->name);
...@@ -46,9 +45,9 @@ void cgroup_ops_init(void) ...@@ -46,9 +45,9 @@ void cgroup_ops_init(void)
} }
DEBUG("cgroup_init"); DEBUG("cgroup_init");
#if HAVE_CGMANAGER #if HAVE_CGMANAGER
ops = cgm_ops_init(); ops = cgm_ops_init();
#endif #endif
if (!ops) if (!ops)
ops = cgfsng_ops_init(); ops = cgfsng_ops_init();
if (!ops) if (!ops)
...@@ -60,7 +59,7 @@ void cgroup_ops_init(void) ...@@ -60,7 +59,7 @@ void cgroup_ops_init(void)
bool cgroup_init(struct lxc_handler *handler) bool cgroup_init(struct lxc_handler *handler)
{ {
if (handler->cgroup_data) { if (handler->cgroup_data) {
ERROR("cgroup_init called on already inited handler"); ERROR("cgroup_init called on already initialized handler");
return true; return true;
} }
...@@ -68,6 +67,7 @@ bool cgroup_init(struct lxc_handler *handler) ...@@ -68,6 +67,7 @@ bool cgroup_init(struct lxc_handler *handler)
INFO("cgroup driver %s initing for %s", ops->name, handler->name); INFO("cgroup driver %s initing for %s", ops->name, handler->name);
handler->cgroup_data = ops->init(handler->name); handler->cgroup_data = ops->init(handler->name);
} }
return handler->cgroup_data != NULL; return handler->cgroup_data != NULL;
} }
...@@ -79,22 +79,21 @@ void cgroup_destroy(struct lxc_handler *handler) ...@@ -79,22 +79,21 @@ void cgroup_destroy(struct lxc_handler *handler)
} }
} }
/* Create the container cgroups for all requested controllers */ /* Create the container cgroups for all requested controllers. */
bool cgroup_create(struct lxc_handler *handler) bool cgroup_create(struct lxc_handler *handler)
{ {
if (ops) if (ops)
return ops->create(handler->cgroup_data); return ops->create(handler->cgroup_data);
return false; return false;
} }
/* /* Enter the container init into its new cgroups for all requested controllers. */
* Enter the container init into its new cgroups for all
* requested controllers
*/
bool cgroup_enter(struct lxc_handler *handler) bool cgroup_enter(struct lxc_handler *handler)
{ {
if (ops) if (ops)
return ops->enter(handler->cgroup_data, handler->pid); return ops->enter(handler->cgroup_data, handler->pid);
return false; return false;
} }
...@@ -102,13 +101,16 @@ bool cgroup_create_legacy(struct lxc_handler *handler) ...@@ -102,13 +101,16 @@ bool cgroup_create_legacy(struct lxc_handler *handler)
{ {
if (ops && ops->create_legacy) if (ops && ops->create_legacy)
return ops->create_legacy(handler->cgroup_data, handler->pid); return ops->create_legacy(handler->cgroup_data, handler->pid);
return true; return true;
} }
const char *cgroup_get_cgroup(struct lxc_handler *handler, const char *subsystem) const char *cgroup_get_cgroup(struct lxc_handler *handler,
const char *subsystem)
{ {
if (ops) if (ops)
return ops->get_cgroup(handler->cgroup_data, subsystem); return ops->get_cgroup(handler->cgroup_data, subsystem);
return NULL; return NULL;
} }
...@@ -116,6 +118,7 @@ bool cgroup_escape(struct lxc_handler *handler) ...@@ -116,6 +118,7 @@ bool cgroup_escape(struct lxc_handler *handler)
{ {
if (ops) if (ops)
return ops->escape(handler->cgroup_data); return ops->escape(handler->cgroup_data);
return false; return false;
} }
...@@ -139,6 +142,7 @@ bool cgroup_unfreeze(struct lxc_handler *handler) ...@@ -139,6 +142,7 @@ bool cgroup_unfreeze(struct lxc_handler *handler)
{ {
if (ops) if (ops)
return ops->unfreeze(handler->cgroup_data); return ops->unfreeze(handler->cgroup_data);
return false; return false;
} }
...@@ -147,6 +151,7 @@ bool cgroup_setup_limits(struct lxc_handler *handler, bool with_devices) ...@@ -147,6 +151,7 @@ bool cgroup_setup_limits(struct lxc_handler *handler, bool with_devices)
if (ops) if (ops)
return ops->setup_limits(handler->cgroup_data, return ops->setup_limits(handler->cgroup_data,
&handler->conf->cgroup, with_devices); &handler->conf->cgroup, with_devices);
return false; return false;
} }
...@@ -154,14 +159,15 @@ bool cgroup_chown(struct lxc_handler *handler) ...@@ -154,14 +159,15 @@ bool cgroup_chown(struct lxc_handler *handler)
{ {
if (ops && ops->chown) if (ops && ops->chown)
return ops->chown(handler->cgroup_data, handler->conf); return ops->chown(handler->cgroup_data, handler->conf);
return true; return true;
} }
bool cgroup_mount(const char *root, struct lxc_handler *handler, int type) bool cgroup_mount(const char *root, struct lxc_handler *handler, int type)
{ {
if (ops) { if (ops)
return ops->mount_cgroup(handler->cgroup_data, root, type); return ops->mount_cgroup(handler->cgroup_data, root, type);
}
return false; return false;
} }
...@@ -171,8 +177,9 @@ int cgroup_nrtasks(struct lxc_handler *handler) ...@@ -171,8 +177,9 @@ int cgroup_nrtasks(struct lxc_handler *handler)
if (ops->nrtasks) if (ops->nrtasks)
return ops->nrtasks(handler->cgroup_data); return ops->nrtasks(handler->cgroup_data);
else else
WARN("CGROUP driver %s doesn't implement nrtasks", ops->name); WARN("cgroup driver \"%s\" doesn't implement nrtasks", ops->name);
} }
return -1; return -1;
} }
...@@ -180,25 +187,29 @@ bool cgroup_attach(const char *name, const char *lxcpath, pid_t pid) ...@@ -180,25 +187,29 @@ bool cgroup_attach(const char *name, const char *lxcpath, pid_t pid)
{ {
if (ops) if (ops)
return ops->attach(name, lxcpath, pid); return ops->attach(name, lxcpath, pid);
return false; return false;
} }
int lxc_cgroup_set(const char *filename, const char *value, const char *name, const char *lxcpath) int lxc_cgroup_set(const char *filename, const char *value, const char *name,
const char *lxcpath)
{ {
if (ops) if (ops)
return ops->set(filename, value, name, lxcpath); return ops->set(filename, value, name, lxcpath);
return -1; return -1;
} }
int lxc_cgroup_get(const char *filename, char *value, size_t len, const char *name, const char *lxcpath) int lxc_cgroup_get(const char *filename, char *value, size_t len,
const char *name, const char *lxcpath)
{ {
if (ops) if (ops)
return ops->get(filename, value, len, name, lxcpath); return ops->get(filename, value, len, name, lxcpath);
return -1; return -1;
} }
void cgroup_disconnect(void) void cgroup_disconnect(void) {
{
if (ops && ops->disconnect) if (ops && ops->disconnect)
ops->disconnect(); ops->disconnect();
} }
...@@ -219,30 +230,32 @@ void prune_init_scope(char *cg) ...@@ -219,30 +230,32 @@ void prune_init_scope(char *cg)
point = cg + strlen(cg) - strlen(INIT_SCOPE); point = cg + strlen(cg) - strlen(INIT_SCOPE);
if (point < cg) if (point < cg)
return; return;
if (strcmp(point, INIT_SCOPE) == 0) { if (strcmp(point, INIT_SCOPE) == 0) {
if (point == cg) if (point == cg)
*(point+1) = '\0'; *(point + 1) = '\0';
else else
*point = '\0'; *point = '\0';
} }
} }
/* /* Return true if this is a subsystem which we cannot do without.
* Return true if this is a subsystem which we cannot do
* without.
* *
* systemd is questionable here. The way callers currently * systemd is questionable here. The way callers currently use this, if systemd
* use this, if systemd is not mounted then it will be ignored. * is not mounted then it will be ignored. But if systemd is mounted, then it
* But if systemd is mounted, then it must be setup so that lxc * must be setup so that lxc can create cgroups in it, else containers will
* can create cgroups in it, else containers will fail. * fail.
*/ */
bool is_crucial_cgroup_subsystem(const char *s) bool is_crucial_cgroup_subsystem(const char *s)
{ {
if (strcmp(s, "systemd") == 0) if (strcmp(s, "systemd") == 0)
return true; return true;
if (strcmp(s, "name=systemd") == 0) if (strcmp(s, "name=systemd") == 0)
return true; return true;
if (strcmp(s, "freezer") == 0) if (strcmp(s, "freezer") == 0)
return true; return true;
return false; return false;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment