core: Add two more to_string() functions
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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_;
|
||||
|
||||
+4
-18
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user