Commit a3289423 by Tycho Andersen Committed by Stéphane Graber

Initialize cgroups on lxc-checkpoint -r

With cgmanager, the cgroups are polled on demand, so these steps aren't needed. However, with cgfs, lxc doesn't know about the cgroups for a container and so it can't report any of the statistics about e.g. how much memory or CPU a container is using. Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent c49ecd78
...@@ -2376,6 +2376,18 @@ static bool lxc_cgroupfs_attach(const char *name, const char *lxcpath, pid_t pid ...@@ -2376,6 +2376,18 @@ static bool lxc_cgroupfs_attach(const char *name, const char *lxcpath, pid_t pid
return true; return true;
} }
static bool cgfs_parse_existing_cgroups(void *hdata, pid_t init)
{
struct cgfs_data *d = hdata;
if (!d)
return false;
d->info = lxc_cgroup_process_info_get(init, d->meta);
return !!(d->info);
}
static struct cgroup_ops cgfs_ops = { static struct cgroup_ops cgfs_ops = {
.init = cgfs_init, .init = cgfs_init,
.destroy = cgfs_destroy, .destroy = cgfs_destroy,
...@@ -2390,6 +2402,7 @@ static struct cgroup_ops cgfs_ops = { ...@@ -2390,6 +2402,7 @@ static struct cgroup_ops cgfs_ops = {
.name = "cgroupfs", .name = "cgroupfs",
.attach = lxc_cgroupfs_attach, .attach = lxc_cgroupfs_attach,
.chown = NULL, .chown = NULL,
.parse_existing_cgroups = cgfs_parse_existing_cgroups,
.mount_cgroup = cgroupfs_mount_cgroup, .mount_cgroup = cgroupfs_mount_cgroup,
.nrtasks = cgfs_nrtasks, .nrtasks = cgfs_nrtasks,
}; };
...@@ -1313,6 +1313,7 @@ static struct cgroup_ops cgmanager_ops = { ...@@ -1313,6 +1313,7 @@ static struct cgroup_ops cgmanager_ops = {
.setup_limits = cgm_setup_limits, .setup_limits = cgm_setup_limits,
.name = "cgmanager", .name = "cgmanager",
.chown = cgm_chown, .chown = cgm_chown,
.parse_existing_cgroups = NULL,
.attach = cgm_attach, .attach = cgm_attach,
.mount_cgroup = cgm_mount_cgroup, .mount_cgroup = cgm_mount_cgroup,
.nrtasks = cgm_get_nrtasks, .nrtasks = cgm_get_nrtasks,
......
...@@ -128,6 +128,15 @@ bool cgroup_chown(struct lxc_handler *handler) ...@@ -128,6 +128,15 @@ bool cgroup_chown(struct lxc_handler *handler)
return true; return true;
} }
bool cgroup_parse_existing_cgroups(struct lxc_handler *handler)
{
if (ops && ops->parse_existing_cgroups)
return ops->parse_existing_cgroups(handler->cgroup_data, handler->pid);
/* cgmanager does this automatically */
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) {
......
...@@ -46,6 +46,7 @@ struct cgroup_ops { ...@@ -46,6 +46,7 @@ struct cgroup_ops {
bool (*unfreeze)(void *hdata); bool (*unfreeze)(void *hdata);
bool (*setup_limits)(void *hdata, struct lxc_list *cgroup_conf, bool with_devices); bool (*setup_limits)(void *hdata, struct lxc_list *cgroup_conf, bool with_devices);
bool (*chown)(void *hdata, struct lxc_conf *conf); bool (*chown)(void *hdata, struct lxc_conf *conf);
bool (*parse_existing_cgroups)(void *hdata, pid_t pid);
bool (*attach)(const char *name, const char *lxcpath, pid_t pid); bool (*attach)(const char *name, const char *lxcpath, pid_t pid);
bool (*mount_cgroup)(void *hdata, const char *root, int type); bool (*mount_cgroup)(void *hdata, const char *root, int type);
int (*nrtasks)(void *hdata); int (*nrtasks)(void *hdata);
...@@ -59,6 +60,7 @@ extern bool cgroup_init(struct lxc_handler *handler); ...@@ -59,6 +60,7 @@ extern bool cgroup_init(struct lxc_handler *handler);
extern bool cgroup_create(struct lxc_handler *handler); extern bool cgroup_create(struct lxc_handler *handler);
extern bool cgroup_setup_limits(struct lxc_handler *handler, bool with_devices); extern bool cgroup_setup_limits(struct lxc_handler *handler, bool with_devices);
extern bool cgroup_chown(struct lxc_handler *handler); extern bool cgroup_chown(struct lxc_handler *handler);
extern bool cgroup_parse_existing_cgroups(struct lxc_handler *handler);
extern bool cgroup_enter(struct lxc_handler *handler); extern bool cgroup_enter(struct lxc_handler *handler);
extern void cgroup_cleanup(struct lxc_handler *handler); extern void cgroup_cleanup(struct lxc_handler *handler);
extern bool cgroup_create_legacy(struct lxc_handler *handler); extern bool cgroup_create_legacy(struct lxc_handler *handler);
......
...@@ -3895,6 +3895,17 @@ static bool lxcapi_restore(struct lxc_container *c, char *directory, bool verbos ...@@ -3895,6 +3895,17 @@ static bool lxcapi_restore(struct lxc_container *c, char *directory, bool verbos
goto out_fini_handler; goto out_fini_handler;
} }
if (!cgroup_init(handler)) {
error = true;
ERROR("failed initing cgroups");
goto out_fini_handler;
}
if (!cgroup_parse_existing_cgroups(handler)) {
ERROR("failed creating cgroups");
goto out_fini_handler;
}
if (container_mem_lock(c)) { if (container_mem_lock(c)) {
error = true; error = true;
goto out_fini_handler; goto out_fini_handler;
......
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