]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn/oci: replace use of deprecated BlockIOWeight/BlockIODeviceWeight with IOWeight... 37038/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 Apr 2025 16:50:50 +0000 (01:50 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 Apr 2025 17:08:37 +0000 (02:08 +0900)
src/nspawn/nspawn-oci.c

index f10ae930a26076b7430aa148d94cdbc1fa19311d..1e339e0208ae561912580d986384c21bda1b7d51 100644 (file)
@@ -1295,6 +1295,13 @@ static int oci_cgroup_cpu(const char *name, sd_json_variant *v, sd_json_dispatch
         return 0;
 }
 
+static uint64_t cgroup_weight_blkio_to_io(uint64_t blkio_weight) {
+        /* convert from cgroup v1 blkio.weight to v2 io.weight */
+        assert_cc(CGROUP_BLKIO_WEIGHT_MAX <= UINT64_MAX / CGROUP_WEIGHT_DEFAULT);
+        return CLAMP(blkio_weight * CGROUP_WEIGHT_DEFAULT / CGROUP_BLKIO_WEIGHT_DEFAULT,
+                     CGROUP_WEIGHT_MIN, CGROUP_WEIGHT_MAX);
+}
+
 static int oci_cgroup_block_io_weight(const char *name, sd_json_variant *v, sd_json_dispatch_flags_t flags, void *userdata) {
         Settings *s = ASSERT_PTR(userdata);
         uint64_t k;
@@ -1309,7 +1316,7 @@ static int oci_cgroup_block_io_weight(const char *name, sd_json_variant *v, sd_j
         if (r < 0)
                 return r;
 
-        r = sd_bus_message_append(s->properties, "(sv)", "BlockIOWeight", "t", (uint64_t) k);
+        r = sd_bus_message_append(s->properties, "(sv)", "IOWeight", "t", cgroup_weight_blkio_to_io(k));
         if (r < 0)
                 return bus_log_create_error(r);
 
@@ -1361,7 +1368,8 @@ static int oci_cgroup_block_io_weight_device(const char *name, sd_json_variant *
                 if (r < 0)
                         return r;
 
-                r = sd_bus_message_append(s->properties, "(sv)", "BlockIODeviceWeight", "a(st)", 1, path, (uint64_t) data.weight);
+                r = sd_bus_message_append(s->properties, "(sv)", "IODeviceWeight", "a(st)", 1,
+                                          path, cgroup_weight_blkio_to_io(data.weight));
                 if (r < 0)
                         return bus_log_create_error(r);
         }