]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: relax checks for block device cgroup settings
authorLennart Poettering <lennart@poettering.net>
Mon, 11 Jun 2018 10:19:01 +0000 (12:19 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 11 Jun 2018 16:01:06 +0000 (18:01 +0200)
This drops needless safety checks that ensure we only reference block
devices for blockio/io settings. The backing code was already able to
accept regular file system paths too, in which case the backing device
node of that file system would be used. Hence, let's drop the artificial
restrictions and open up this underlying functionality.

src/core/dbus-cgroup.c
src/core/load-fragment.c

index d170f6ad9f2b7fa2ddde2477d4de200a48d8c6c5..194b5379dc9f11446ce3bde8d87d4317a0c59c4e 100644 (file)
@@ -687,9 +687,8 @@ int bus_cgroup_set_property(
 
                 while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
 
-                        if (!path_startswith(path, "/dev") &&
-                            !path_startswith(path, "/run/systemd/inaccessible/"))
-                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s specified in %s= is not a device file in /dev", name, path);
+                        if (!path_is_normalized(path))
+                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path);
 
                         if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                                 CGroupIODeviceLimit *a = NULL, *b;
@@ -775,9 +774,8 @@ int bus_cgroup_set_property(
 
                 while ((r = sd_bus_message_read(message, "(st)", &path, &weight)) > 0) {
 
-                        if (!path_startswith(path, "/dev") &&
-                            !path_startswith(path, "/run/systemd/inaccessible/"))
-                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s specified in %s= is not a device file in /dev", name, path);
+                        if (!path_is_normalized(path))
+                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path);
 
                         if (!CGROUP_WEIGHT_IS_OK(weight) || weight == CGROUP_WEIGHT_INVALID)
                                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "IODeviceWeight= value out of range");
@@ -861,9 +859,8 @@ int bus_cgroup_set_property(
 
                 while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
 
-                        if (!path_startswith(path, "/dev") &&
-                            !path_startswith(path, "/run/systemd/inaccessible/"))
-                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s specified in %s= is not a device file in /dev", name, path);
+                        if (!path_is_normalized(path))
+                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path);
 
                         if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
                                 CGroupBlockIODeviceBandwidth *a = NULL, *b;
@@ -961,9 +958,8 @@ int bus_cgroup_set_property(
 
                 while ((r = sd_bus_message_read(message, "(st)", &path, &weight)) > 0) {
 
-                        if (!path_startswith(path, "/dev") &&
-                            !path_startswith(path, "/run/systemd/inaccessible/"))
-                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path %s specified in %s= is not a device file in /dev", name, path);
+                        if (!path_is_normalized(path))
+                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path);
 
                         if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight) || weight == CGROUP_BLKIO_WEIGHT_INVALID)
                                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "BlockIODeviceWeight= out of range");
index fb5b742fcfe7d101ff2f6f8dd241702400c1b1cf..2d8525c4bd10986aa09f3c3eed260645db8120c8 100644 (file)
@@ -3317,12 +3317,6 @@ int config_parse_io_device_weight(
         if (r < 0)
                 return 0;
 
-        if (!path_startswith(resolved, "/dev") &&
-            !path_startswith(resolved, "/run/systemd/inaccessible/")) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid device node path '%s', ignoring.", resolved);
-                return 0;
-        }
-
         r = cg_weight_parse(p, &u);
         if (r < 0) {
                 log_syntax(unit, LOG_ERR, filename, line, r, "IO weight '%s' invalid, ignoring: %m", p);
@@ -3400,15 +3394,9 @@ int config_parse_io_limit(
         if (r < 0)
                 return 0;
 
-        if (!path_startswith(resolved, "/dev") &&
-            !path_startswith(resolved, "/run/systemd/inaccessible/")) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid device node path '%s', ignoring.", resolved);
-                return 0;
-        }
-
-        if (streq("infinity", p)) {
+        if (streq("infinity", p))
                 num = CGROUP_LIMIT_MAX;
-        else {
+        else {
                 r = parse_size(p, 1000, &num);
                 if (r < 0 || num <= 0) {
                         log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid IO limit '%s', ignoring.", p);
@@ -3497,12 +3485,6 @@ int config_parse_blockio_device_weight(
         if (r < 0)
                 return 0;
 
-        if (!path_startswith(resolved, "/dev") &&
-            !path_startswith(resolved, "/run/systemd/inaccessible/")) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid device node path '%s'. Ignoring.", resolved);
-                return 0;
-        }
-
         r = cg_blkio_weight_parse(p, &u);
         if (r < 0) {
                 log_syntax(unit, LOG_ERR, filename, line, r, "Invalid block IO weight '%s', ignoring: %m", p);
@@ -3581,12 +3563,6 @@ int config_parse_blockio_bandwidth(
         if (r < 0)
                 return 0;
 
-        if (!path_startswith(resolved, "/dev") &&
-            !path_startswith(resolved, "/run/systemd/inaccessible/")) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid device node path '%s', ignoring.", resolved);
-                return 0;
-        }
-
         r = parse_size(p, 1000, &bytes);
         if (r < 0 || bytes <= 0) {
                 log_syntax(unit, LOG_ERR, filename, line, r, "Invalid Block IO Bandwidth '%s', ignoring.", p);