[lxc-devel] [lxc/master] 2016 03 08/batch
hallyn on Github
lxc-bot at linuxcontainers.org
Wed Mar 9 07:36:04 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 438 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160309/7be7fd8e/attachment.bin>
-------------- next part --------------
From b4ffcca8e83ec6b70bfe5d72da6f0dd930113679 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Tue, 8 Mar 2016 23:04:46 -0800
Subject: [PATCH 1/2] cgfsng: fix real bug and fake libc realloc bug
read_file was using the wrong value for the string length. Also,
realloc on i386 is wonky with small sizes - so use a batch size
to avoid small reallocs.
Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
src/lxc/cgfsng.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/lxc/cgfsng.c b/src/lxc/cgfsng.c
index 913070e..820cd0b 100644
--- a/src/lxc/cgfsng.c
+++ b/src/lxc/cgfsng.c
@@ -621,13 +621,24 @@ static char *get_current_cgroup(char *basecginfo, char *controller)
}
}
+#define BATCH_SIZE 50
+static void batch_realloc(char **mem, size_t oldlen, size_t newlen)
+{
+ int newbatches = (newlen / BATCH_SIZE) + 1;
+ int oldbatches = (oldlen / BATCH_SIZE) + 1;
+
+ if (!*mem || newbatches > oldbatches) {
+ *mem = must_realloc(*mem, newbatches * BATCH_SIZE);
+ }
+}
+
static void append_line(char **dest, size_t oldlen, char *new, size_t newlen)
{
size_t full = oldlen + newlen;
- *dest = must_realloc(*dest, full + 1);
+ batch_realloc(dest, oldlen, full + 1);
- strcat(*dest, new);
+ memcpy(*dest + oldlen, new, newlen + 1);
}
/* Slurp in a whole file */
@@ -636,13 +647,14 @@ static char *read_file(char *fnam)
FILE *f;
char *line = NULL, *buf = NULL;
size_t len = 0, fulllen = 0;
+ int linelen;
f = fopen(fnam, "r");
if (!f)
return NULL;
- while (getline(&line, &len, f) != -1) {
- append_line(&buf, fulllen, line, len);
- fulllen += len;
+ while ((linelen = getline(&line, &len, f)) != -1) {
+ append_line(&buf, fulllen, line, linelen);
+ fulllen += linelen;
}
fclose(f);
free(line);
From d8da679e2a3b49ea389297dfd67e8c18bbb70116 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Tue, 8 Mar 2016 23:34:19 -0800
Subject: [PATCH 2/2] cgfsng: make sure a cgroup does not already exist
Our mkdir_p ignore eexist, and of course we want that for
upper path components, but the final directory itself must
not already exist.
Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
src/lxc/cgfsng.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/lxc/cgfsng.c b/src/lxc/cgfsng.c
index 820cd0b..32213bf 100644
--- a/src/lxc/cgfsng.c
+++ b/src/lxc/cgfsng.c
@@ -1031,6 +1031,8 @@ struct cgroup_ops *cgfsng_ops_init(void)
static bool create_path_for_hierarchy(struct hierarchy *h, char *cgname)
{
h->fullcgpath = must_make_path(h->mountpoint, h->base_cgroup, cgname, NULL);
+ if (dir_exists(h->fullcgpath)) // it must not already exist
+ return false;
if (!handle_cpuset_hierarchy(h, cgname))
return false;
return mkdir_p(h->fullcgpath, 0755) == 0;
More information about the lxc-devel
mailing list