[systemd-commits] 2 commits - src/core src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Fri Aug 15 02:58:59 PDT 2014


 src/core/cgroup.c        |   30 ++++++++++--------------------
 src/shared/cgroup-util.c |   12 ++++++------
 src/shared/fileio.c      |   22 ++++++++++++++++++++++
 src/shared/fileio.h      |    1 +
 4 files changed, 39 insertions(+), 26 deletions(-)

New commits:
commit 6b2f67b31c7d7d4cf39d037fd295a4565efc7186
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 15 11:56:36 2014 +0200

    cgroup: downgrade log messages about non-existant cgroup attributes to LOG_DEBUG

diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index a52de2d..42bf09f 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -199,8 +199,7 @@ static int whitelist_device(const char *path, const char *node, const char *acc)
                 acc);
 
         r = cg_set_attribute("devices", path, "devices.allow", buf);
-        if (r < 0)
-                log_warning("Failed to set devices.allow on %s: %s", path, strerror(-r));
+        log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to set devices.allow on %s: %s", path, strerror(-r));
 
         return r;
 }
@@ -271,8 +270,7 @@ static int whitelist_major(const char *path, const char *name, char type, const
                         acc);
 
                 r = cg_set_attribute("devices", path, "devices.allow", buf);
-                if (r < 0)
-                        log_warning("Failed to set devices.allow on %s: %s", path, strerror(-r));
+                log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to set devices.allow on %s: %s", path, strerror(-r));
         }
 
         return 0;
@@ -303,21 +301,18 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
                         state == MANAGER_STARTING && c->startup_cpu_shares != (unsigned long) -1 ? c->startup_cpu_shares :
                         c->cpu_shares != (unsigned long) -1 ? c->cpu_shares : 1024);
                 r = cg_set_attribute("cpu", path, "cpu.shares", buf);
-                if (r < 0)
-                        log_warning("Failed to set cpu.shares on %s: %s", path, strerror(-r));
+                log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to set cpu.shares on %s: %s", path, strerror(-r));
 
                 sprintf(buf, USEC_FMT "\n", CGROUP_CPU_QUOTA_PERIOD_USEC);
                 r = cg_set_attribute("cpu", path, "cpu.cfs_period_us", buf);
-                if (r < 0)
-                        log_warning("Failed to set cpu.cfs_period_us on %s: %s", path, strerror(-r));
+                log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to set cpu.cfs_period_us on %s: %s", path, strerror(-r));
 
                 if (c->cpu_quota_per_sec_usec != USEC_INFINITY) {
                         sprintf(buf, USEC_FMT "\n", c->cpu_quota_per_sec_usec * CGROUP_CPU_QUOTA_PERIOD_USEC / USEC_PER_SEC);
                         r = cg_set_attribute("cpu", path, "cpu.cfs_quota_us", buf);
                 } else
                         r = cg_set_attribute("cpu", path, "cpu.cfs_quota_us", "-1");
-                if (r < 0)
-                        log_warning("Failed to set cpu.cfs_quota_us on %s: %s", path, strerror(-r));
+                log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to set cpu.cfs_quota_us on %s: %s", path, strerror(-r));
         }
 
         if (mask & CGROUP_BLKIO) {
@@ -331,8 +326,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
                         sprintf(buf, "%lu\n", state == MANAGER_STARTING && c->startup_blockio_weight != (unsigned long) -1 ? c->startup_blockio_weight :
                                 c->blockio_weight != (unsigned long) -1 ? c->blockio_weight : 1000);
                         r = cg_set_attribute("blkio", path, "blkio.weight", buf);
-                        if (r < 0)
-                                log_warning("Failed to set blkio.weight on %s: %s", path, strerror(-r));
+                        log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to set blkio.weight on %s: %s", path, strerror(-r));
 
                         /* FIXME: no way to reset this list */
                         LIST_FOREACH(device_weights, w, c->blockio_device_weights) {
@@ -344,8 +338,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
 
                                 sprintf(buf, "%u:%u %lu", major(dev), minor(dev), w->weight);
                                 r = cg_set_attribute("blkio", path, "blkio.weight_device", buf);
-                                if (r < 0)
-                                        log_error("Failed to set blkio.weight_device on %s: %s", path, strerror(-r));
+                                log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to set blkio.weight_device on %s: %s", path, strerror(-r));
                         }
                 }
 
@@ -362,8 +355,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
 
                         sprintf(buf, "%u:%u %" PRIu64 "\n", major(dev), minor(dev), b->bandwidth);
                         r = cg_set_attribute("blkio", path, a, buf);
-                        if (r < 0)
-                                log_error("Failed to set %s on %s: %s", a, path, strerror(-r));
+                        log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to set %s on %s: %s", a, path, strerror(-r));
                 }
         }
 
@@ -376,8 +368,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
                 } else
                         r = cg_set_attribute("memory", path, "memory.limit_in_bytes", "-1");
 
-                if (r < 0)
-                        log_error("Failed to set memory.limit_in_bytes on %s: %s", path, strerror(-r));
+                log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to set memory.limit_in_bytes on %s: %s", path, strerror(-r));
         }
 
         if ((mask & CGROUP_DEVICE) && !is_root) {
@@ -387,8 +378,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
                         r = cg_set_attribute("devices", path, "devices.deny", "a");
                 else
                         r = cg_set_attribute("devices", path, "devices.allow", "a");
-                if (r < 0)
-                        log_warning("Failed to reset devices.list on %s: %s", path, strerror(-r));
+                log_full(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, "Failed to reset devices.list on %s: %s", path, strerror(-r));
 
                 if (c->device_policy == CGROUP_CLOSED ||
                     (c->device_policy == CGROUP_AUTO && c->device_allow)) {

commit 70c949a42b2b0d0c9a2a567890483940cdc5f72c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 15 11:55:43 2014 +0200

    cgroup: never try to create files in cgroupfs, only open them for writing
    
    This should have the benefit that cg_set_attribute() returns ENOENT
    instead of EACCESS when we use it for non-existing attributes.

diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index f683ae9..e8cb9c7 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -643,7 +643,7 @@ int cg_attach(const char *controller, const char *path, pid_t pid) {
 
         snprintf(c, sizeof(c), PID_FMT"\n", pid);
 
-        return write_string_file(fs, c);
+        return write_string_file_no_create(fs, c);
 }
 
 int cg_attach_fallback(const char *controller, const char *path, pid_t pid) {
@@ -817,7 +817,7 @@ int cg_install_release_agent(const char *controller, const char *agent) {
 
         sc = strstrip(contents);
         if (sc[0] == 0) {
-                r = write_string_file(fs, agent);
+                r = write_string_file_no_create(fs, agent);
                 if (r < 0)
                         return r;
         } else if (!streq(sc, agent))
@@ -837,7 +837,7 @@ int cg_install_release_agent(const char *controller, const char *agent) {
 
         sc = strstrip(contents);
         if (streq(sc, "0")) {
-                r = write_string_file(fs, "1");
+                r = write_string_file_no_create(fs, "1");
                 if (r < 0)
                         return r;
 
@@ -858,7 +858,7 @@ int cg_uninstall_release_agent(const char *controller) {
         if (r < 0)
                 return r;
 
-        r = write_string_file(fs, "0");
+        r = write_string_file_no_create(fs, "0");
         if (r < 0)
                 return r;
 
@@ -869,7 +869,7 @@ int cg_uninstall_release_agent(const char *controller) {
         if (r < 0)
                 return r;
 
-        r = write_string_file(fs, "");
+        r = write_string_file_no_create(fs, "");
         if (r < 0)
                 return r;
 
@@ -1591,7 +1591,7 @@ int cg_set_attribute(const char *controller, const char *path, const char *attri
         if (r < 0)
                 return r;
 
-        return write_string_file(p, value);
+        return write_string_file_no_create(p, value);
 }
 
 static const char mask_names[] =
diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index cbb40c2..18960ab 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -58,6 +58,28 @@ int write_string_file(const char *fn, const char *line) {
         return write_string_stream(f, line);
 }
 
+int write_string_file_no_create(const char *fn, const char *line) {
+        _cleanup_fclose_ FILE *f = NULL;
+        int fd;
+
+        assert(fn);
+        assert(line);
+
+        /* We manually build our own version of fopen(..., "we") that
+         * without O_CREAT */
+        fd = open(fn, O_WRONLY|O_CLOEXEC|O_NOCTTY);
+        if (fd < 0)
+                return -errno;
+
+        f = fdopen(fd, "we");
+        if (!f) {
+                safe_close(fd);
+                return -errno;
+        }
+
+        return write_string_stream(f, line);
+}
+
 int write_string_file_atomic(const char *fn, const char *line) {
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_free_ char *p = NULL;
diff --git a/src/shared/fileio.h b/src/shared/fileio.h
index 5122a9a..c256915 100644
--- a/src/shared/fileio.h
+++ b/src/shared/fileio.h
@@ -27,6 +27,7 @@
 
 int write_string_stream(FILE *f, const char *line);
 int write_string_file(const char *fn, const char *line);
+int write_string_file_no_create(const char *fn, const char *line);
 int write_string_file_atomic(const char *fn, const char *line);
 
 int read_one_line_file(const char *fn, char **line);



More information about the systemd-commits mailing list