|
16 | 16 | #include "limits-util.h" |
17 | 17 | #include "path-util.h" |
18 | 18 |
|
| 19 | +BUS_DEFINE_PROPERTY_GET(bus_property_get_tasks_max, "t", TasksMax, tasks_max_resolve); |
| 20 | + |
19 | 21 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_device_policy, CGroupDevicePolicy); |
20 | 22 |
|
21 | 23 | static int property_get_cgroup_mask( |
@@ -382,7 +384,7 @@ const sd_bus_vtable bus_cgroup_vtable[] = { |
382 | 384 | SD_BUS_PROPERTY("DevicePolicy", "s", property_get_cgroup_device_policy, offsetof(CGroupContext, device_policy), 0), |
383 | 385 | SD_BUS_PROPERTY("DeviceAllow", "a(ss)", property_get_device_allow, 0, 0), |
384 | 386 | SD_BUS_PROPERTY("TasksAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, tasks_accounting), 0), |
385 | | - SD_BUS_PROPERTY("TasksMax", "t", NULL, offsetof(CGroupContext, tasks_max), 0), |
| 387 | + SD_BUS_PROPERTY("TasksMax", "t", bus_property_get_tasks_max, offsetof(CGroupContext, tasks_max), 0), |
386 | 388 | SD_BUS_PROPERTY("IPAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, ip_accounting), 0), |
387 | 389 | SD_BUS_PROPERTY("IPAddressAllow", "a(iayu)", property_get_ip_address_access, offsetof(CGroupContext, ip_address_allow), 0), |
388 | 390 | SD_BUS_PROPERTY("IPAddressDeny", "a(iayu)", property_get_ip_address_access, offsetof(CGroupContext, ip_address_deny), 0), |
@@ -715,9 +717,76 @@ BUS_DEFINE_SET_CGROUP_WEIGHT(blockio_weight, CGROUP_MASK_BLKIO, CGROUP_BLKIO_WEI |
715 | 717 | BUS_DEFINE_SET_CGROUP_LIMIT(memory, CGROUP_MASK_MEMORY, physical_memory_scale, 1); |
716 | 718 | BUS_DEFINE_SET_CGROUP_LIMIT(memory_protection, CGROUP_MASK_MEMORY, physical_memory_scale, 0); |
717 | 719 | BUS_DEFINE_SET_CGROUP_LIMIT(swap, CGROUP_MASK_MEMORY, physical_memory_scale, 0); |
718 | | -BUS_DEFINE_SET_CGROUP_LIMIT(tasks_max, CGROUP_MASK_PIDS, system_tasks_max_scale, 1); |
719 | 720 | #pragma GCC diagnostic pop |
720 | 721 |
|
| 722 | +static int bus_cgroup_set_tasks_max( |
| 723 | + Unit *u, |
| 724 | + const char *name, |
| 725 | + TasksMax *p, |
| 726 | + sd_bus_message *message, |
| 727 | + UnitWriteFlags flags, |
| 728 | + sd_bus_error *error) { |
| 729 | + |
| 730 | + uint64_t v; |
| 731 | + int r; |
| 732 | + |
| 733 | + assert(p); |
| 734 | + |
| 735 | + r = sd_bus_message_read(message, "t", &v); |
| 736 | + if (r < 0) |
| 737 | + return r; |
| 738 | + |
| 739 | + if (v < 1) |
| 740 | + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
| 741 | + "Value specified in %s is out of range", name); |
| 742 | + |
| 743 | + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
| 744 | + *p = (TasksMax) { .value = v, .scale = 0 }; /* When .scale==0, .value is the absolute value */ |
| 745 | + unit_invalidate_cgroup(u, CGROUP_MASK_PIDS); |
| 746 | + |
| 747 | + if (v == CGROUP_LIMIT_MAX) |
| 748 | + unit_write_settingf(u, flags, name, |
| 749 | + "%s=infinity", name); |
| 750 | + else |
| 751 | + unit_write_settingf(u, flags, name, |
| 752 | + "%s=%" PRIu64, name, v); |
| 753 | + } |
| 754 | + |
| 755 | + return 1; |
| 756 | +} |
| 757 | + |
| 758 | +static int bus_cgroup_set_tasks_max_scale( |
| 759 | + Unit *u, |
| 760 | + const char *name, |
| 761 | + TasksMax *p, |
| 762 | + sd_bus_message *message, |
| 763 | + UnitWriteFlags flags, |
| 764 | + sd_bus_error *error) { |
| 765 | + |
| 766 | + uint32_t v; |
| 767 | + int r; |
| 768 | + |
| 769 | + assert(p); |
| 770 | + |
| 771 | + r = sd_bus_message_read(message, "u", &v); |
| 772 | + if (r < 0) |
| 773 | + return r; |
| 774 | + |
| 775 | + if (v < 1 || v >= UINT32_MAX) |
| 776 | + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, |
| 777 | + "Value specified in %s is out of range", name); |
| 778 | + |
| 779 | + if (!UNIT_WRITE_FLAGS_NOOP(flags)) { |
| 780 | + *p = (TasksMax) { v, UINT32_MAX }; /* .scale is not 0, so this is interpreted as v/UINT32_MAX. */ |
| 781 | + unit_invalidate_cgroup(u, CGROUP_MASK_PIDS); |
| 782 | + |
| 783 | + unit_write_settingf(u, flags, name, "%s=%" PRIu32 "%%", "TasksMax", |
| 784 | + (uint32_t) (DIV_ROUND_UP((uint64_t) v * 100U, (uint64_t) UINT32_MAX))); |
| 785 | + } |
| 786 | + |
| 787 | + return 1; |
| 788 | +} |
| 789 | + |
721 | 790 | int bus_cgroup_set_property( |
722 | 791 | Unit *u, |
723 | 792 | CGroupContext *c, |
|
0 commit comments