From: Yu Watanabe Date: Mon, 7 Apr 2025 16:50:50 +0000 (+0900) Subject: nspawn/oci: replace use of deprecated BlockIOWeight/BlockIODeviceWeight with IOWeight... X-Git-Tag: v258-rc1~874^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F37038%2Fhead;p=thirdparty%2Fsystemd.git nspawn/oci: replace use of deprecated BlockIOWeight/BlockIODeviceWeight with IOWeight/IODeviceWeight --- diff --git a/src/nspawn/nspawn-oci.c b/src/nspawn/nspawn-oci.c index f10ae930a26..1e339e0208a 100644 --- a/src/nspawn/nspawn-oci.c +++ b/src/nspawn/nspawn-oci.c @@ -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); }