mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-05 21:04:23 +00:00
Merge pull request #2668 from brauner/2018-10-02/cgroups_monitor_fixes
cgfsng: do not reuse another monitor's cgroup
This commit is contained in:
commit
54b38b25b1
@ -1257,22 +1257,55 @@ on_error:
|
||||
return bret;
|
||||
}
|
||||
|
||||
static int mkdir_eexist_on_last(const char *dir, mode_t mode)
|
||||
{
|
||||
const char *tmp = dir;
|
||||
const char *orig = dir;
|
||||
size_t orig_len;
|
||||
|
||||
orig_len = strlen(dir);
|
||||
do {
|
||||
int ret;
|
||||
size_t cur_len;
|
||||
char *makeme;
|
||||
|
||||
dir = tmp + strspn(tmp, "/");
|
||||
tmp = dir + strcspn(dir, "/");
|
||||
|
||||
errno = ENOMEM;
|
||||
cur_len = dir - orig;
|
||||
makeme = strndup(orig, cur_len);
|
||||
if (!makeme)
|
||||
return -1;
|
||||
|
||||
ret = mkdir(makeme, mode);
|
||||
if (ret < 0) {
|
||||
if ((errno != EEXIST) || (orig_len == cur_len)) {
|
||||
SYSERROR("Failed to create directory \"%s\"", makeme);
|
||||
free(makeme);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
free(makeme);
|
||||
|
||||
} while (tmp != dir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool monitor_create_path_for_hierarchy(struct hierarchy *h, char *cgname)
|
||||
{
|
||||
int ret;
|
||||
|
||||
h->monitor_full_path = must_make_path(h->mountpoint, h->container_base_path, cgname, NULL);
|
||||
if (dir_exists(h->monitor_full_path))
|
||||
return true;
|
||||
|
||||
if (!cg_legacy_handle_cpuset_hierarchy(h, cgname)) {
|
||||
ERROR("Failed to handle legacy cpuset controller");
|
||||
ret = mkdir_eexist_on_last(h->monitor_full_path, 0755);
|
||||
if (ret < 0) {
|
||||
ERROR("Failed to create cgroup \"%s\"", h->monitor_full_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = mkdir_p(h->monitor_full_path, 0755);
|
||||
if (ret < 0) {
|
||||
ERROR("Failed to create cgroup \"%s\"", h->monitor_full_path);
|
||||
if (!cg_legacy_handle_cpuset_hierarchy(h, cgname)) {
|
||||
ERROR("Failed to handle legacy cpuset controller");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1284,8 +1317,9 @@ static bool container_create_path_for_hierarchy(struct hierarchy *h, char *cgnam
|
||||
int ret;
|
||||
|
||||
h->container_full_path = must_make_path(h->mountpoint, h->container_base_path, cgname, NULL);
|
||||
if (dir_exists(h->container_full_path)) {
|
||||
ERROR("The cgroup \"%s\" already existed", h->container_full_path);
|
||||
ret = mkdir_eexist_on_last(h->container_full_path, 0755);
|
||||
if (ret < 0) {
|
||||
ERROR("Failed to create cgroup \"%s\"", h->container_full_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1294,12 +1328,6 @@ static bool container_create_path_for_hierarchy(struct hierarchy *h, char *cgnam
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = mkdir_p(h->container_full_path, 0755);
|
||||
if (ret < 0) {
|
||||
ERROR("Failed to create cgroup \"%s\"", h->container_full_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
return cg_unified_create_cgroup(h, cgname);
|
||||
}
|
||||
|
||||
|
@ -221,26 +221,31 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int mkdir_p(const char *dir, mode_t mode)
|
||||
int mkdir_p(const char *dir, mode_t mode)
|
||||
{
|
||||
const char *tmp = dir;
|
||||
const char *orig = dir;
|
||||
char *makeme;
|
||||
|
||||
do {
|
||||
int ret;
|
||||
char *makeme;
|
||||
|
||||
dir = tmp + strspn(tmp, "/");
|
||||
tmp = dir + strcspn(dir, "/");
|
||||
|
||||
errno = ENOMEM;
|
||||
makeme = strndup(orig, dir - orig);
|
||||
if (*makeme) {
|
||||
if (mkdir(makeme, mode) && errno != EEXIST) {
|
||||
SYSERROR("failed to create directory '%s'", makeme);
|
||||
free(makeme);
|
||||
return -1;
|
||||
}
|
||||
if (!makeme)
|
||||
return -1;
|
||||
|
||||
ret = mkdir(makeme, mode);
|
||||
if (ret < 0 && errno != EEXIST) {
|
||||
SYSERROR("Failed to create directory \"%s\"", makeme);
|
||||
free(makeme);
|
||||
return -1;
|
||||
}
|
||||
free(makeme);
|
||||
} while(tmp != dir);
|
||||
|
||||
} while (tmp != dir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user