From 1cf4a685ad334d85dc5c0e61928577d76ca76311 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Koutn=C3=BD?= Date: Tue, 29 Mar 2022 17:42:19 +0200 Subject: [PATCH] core/cgroup: Refactor device weight property name Use arithmetic over explicit list of existing property names. --- src/core/cgroup.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 35edeac2adf..10081a0f9af 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1064,6 +1064,12 @@ static uint64_t cgroup_weight_io_to_blkio(uint64_t io_weight) { } static void set_bfq_weight(Unit *u, const char *controller, dev_t dev, uint64_t io_weight) { + static const char * const prop_names[] = { + "IOWeight", + "BlockIOWeight", + "IODeviceWeight", + "BlockIODeviceWeight", + }; char buf[DECIMAL_STR_MAX(dev_t)*2+2+DECIMAL_STR_MAX(uint64_t)+STRLEN("\n")]; const char *p; uint64_t bfq_weight; @@ -1081,9 +1087,8 @@ static void set_bfq_weight(Unit *u, const char *controller, dev_t dev, uint64_t xsprintf(buf, "%" PRIu64 "\n", bfq_weight); if (set_attribute_and_warn(u, controller, p, buf) >= 0 && io_weight != bfq_weight) - log_unit_debug(u, "%sIO%sWeight=%" PRIu64 " scaled to %s=%" PRIu64, - streq(controller, "blkio") ? "Block" : "", - major(dev) > 0 ? "Device" : "", + log_unit_debug(u, "%s=%" PRIu64 " scaled to %s=%" PRIu64, + prop_names[2*(major(dev) > 0) + streq(controller, "blkio")], io_weight, p, bfq_weight); } -- 2.47.3