From: Daan De Meyer Date: Thu, 19 Oct 2023 14:35:52 +0000 (+0200) Subject: core: Add two more to_string() functions X-Git-Tag: v255-rc1~182^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=435996e63fa4a9d5653e4b3c7df3d5581b07a18c;p=thirdparty%2Fsystemd.git core: Add two more to_string() functions --- diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 65851ae6e82..2199b94d245 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -4543,3 +4543,21 @@ static const char* const cgroup_pressure_watch_table[_CGROUP_PRESSURE_WATCH_MAX] }; DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(cgroup_pressure_watch, CGroupPressureWatch, CGROUP_PRESSURE_WATCH_ON); + +static const char* const cgroup_ip_accounting_metric_table[_CGROUP_IP_ACCOUNTING_METRIC_MAX] = { + [CGROUP_IP_INGRESS_BYTES] = "IPIngressBytes", + [CGROUP_IP_EGRESS_BYTES] = "IPEgressBytes", + [CGROUP_IP_INGRESS_PACKETS] = "IPIngressPackets", + [CGROUP_IP_EGRESS_PACKETS] = "IPEgressPackets", +}; + +DEFINE_STRING_TABLE_LOOKUP(cgroup_ip_accounting_metric, CGroupIPAccountingMetric); + +static const char* const cgroup_io_accounting_metric_table[_CGROUP_IO_ACCOUNTING_METRIC_MAX] = { + [CGROUP_IO_READ_BYTES] = "IOReadBytes", + [CGROUP_IO_WRITE_BYTES] = "IOWriteBytes", + [CGROUP_IO_READ_OPERATIONS] = "IOReadOperations", + [CGROUP_IO_WRITE_OPERATIONS] = "IOWriteOperations", +}; + +DEFINE_STRING_TABLE_LOOKUP(cgroup_io_accounting_metric, CGroupIOAccountingMetric); diff --git a/src/core/cgroup.h b/src/core/cgroup.h index e043c639f89..9816966dbb2 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -399,3 +399,9 @@ CGroupPressureWatch cgroup_pressure_watch_from_string(const char *s) _pure_; const char *cgroup_device_permissions_to_string(CGroupDevicePermissions p) _const_; CGroupDevicePermissions cgroup_device_permissions_from_string(const char *s) _pure_; + +const char* cgroup_ip_accounting_metric_to_string(CGroupIPAccountingMetric m) _const_; +CGroupIPAccountingMetric cgroup_ip_accounting_metric_from_string(const char *s) _pure_; + +const char* cgroup_io_accounting_metric_to_string(CGroupIOAccountingMetric m) _const_; +CGroupIOAccountingMetric cgroup_io_accounting_metric_from_string(const char *s) _pure_; diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 8c9ad0ef9f0..ab72b4e0948 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1397,22 +1397,15 @@ static int property_get_ip_counter( void *userdata, sd_bus_error *error) { - static const char *const table[_CGROUP_IP_ACCOUNTING_METRIC_MAX] = { - [CGROUP_IP_INGRESS_BYTES] = "IPIngressBytes", - [CGROUP_IP_EGRESS_BYTES] = "IPEgressBytes", - [CGROUP_IP_INGRESS_PACKETS] = "IPIngressPackets", - [CGROUP_IP_EGRESS_PACKETS] = "IPEgressPackets", - }; - uint64_t value = UINT64_MAX; Unit *u = ASSERT_PTR(userdata); - ssize_t metric; + CGroupIPAccountingMetric metric; assert(bus); assert(reply); assert(property); - assert_se((metric = string_table_lookup(table, ELEMENTSOF(table), property)) >= 0); + assert_se((metric = cgroup_ip_accounting_metric_from_string(property)) >= 0); (void) unit_get_ip_accounting(u, metric, &value); return sd_bus_message_append(reply, "t", value); } @@ -1426,13 +1419,6 @@ static int property_get_io_counter( void *userdata, sd_bus_error *error) { - static const char *const table[_CGROUP_IO_ACCOUNTING_METRIC_MAX] = { - [CGROUP_IO_READ_BYTES] = "IOReadBytes", - [CGROUP_IO_WRITE_BYTES] = "IOWriteBytes", - [CGROUP_IO_READ_OPERATIONS] = "IOReadOperations", - [CGROUP_IO_WRITE_OPERATIONS] = "IOWriteOperations", - }; - uint64_t value = UINT64_MAX; Unit *u = ASSERT_PTR(userdata); ssize_t metric; @@ -1441,8 +1427,8 @@ static int property_get_io_counter( assert(reply); assert(property); - assert_se((metric = string_table_lookup(table, ELEMENTSOF(table), property)) >= 0); - (void) unit_get_io_accounting(u, metric, false, &value); + assert_se((metric = cgroup_io_accounting_metric_from_string(property)) >= 0); + (void) unit_get_io_accounting(u, metric, /* allow_cache= */ false, &value); return sd_bus_message_append(reply, "t", value); }