]>
| Commit | Line | Data |
|---|---|---|
| db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| a016b922 | 2 | |
| 9ca16f6f | 3 | #include "bus-get-properties.h" |
| 4ad49000 | 4 | #include "dbus-cgroup.h" |
| 4ad49000 | 5 | #include "dbus-slice.h" |
| 9ca16f6f | 6 | #include "dbus-util.h" |
| cf0fbc49 | 7 | #include "slice.h" |
| 836e4e7e | 8 | #include "string-util.h" |
| cf0fbc49 | 9 | #include "unit.h" |
| a016b922 | 10 | |
| 9ca16f6f LP |
11 | static int property_get_currently_active( |
| 12 | sd_bus *bus, | |
| 13 | const char *path, | |
| 14 | const char *interface, | |
| 15 | const char *property, | |
| 16 | sd_bus_message *reply, | |
| 17 | void *userdata, | |
| 18 | sd_bus_error *error) { | |
| 19 | ||
| 20 | Slice *s = ASSERT_PTR(userdata); | |
| 21 | ||
| 22 | assert(bus); | |
| 23 | assert(reply); | |
| 24 | ||
| 25 | return sd_bus_message_append( | |
| 26 | reply, | |
| 27 | "u", | |
| 28 | (uint32_t) slice_get_currently_active(s, /* ignore= */ NULL, /* with_pending= */ false)); | |
| 29 | } | |
| 30 | ||
| 718db961 LP |
31 | const sd_bus_vtable bus_slice_vtable[] = { |
| 32 | SD_BUS_VTABLE_START(0), | |
| 9ca16f6f LP |
33 | /* The following are currently constant, but we should change that eventually (i.e. open them up via |
| 34 | * systemctl set-property), hence they aren't marked as constant */ | |
| 35 | SD_BUS_PROPERTY("ConcurrencyHardMax", "u", bus_property_get_unsigned, offsetof(Slice, concurrency_hard_max), 0), | |
| 36 | SD_BUS_PROPERTY("ConcurrencySoftMax", "u", bus_property_get_unsigned, offsetof(Slice, concurrency_soft_max), 0), | |
| 37 | SD_BUS_PROPERTY("NCurrentlyActive", "u", property_get_currently_active, 0, 0), | |
| 718db961 LP |
38 | SD_BUS_VTABLE_END |
| 39 | }; | |
| 8e2af478 | 40 | |
| 9ca16f6f LP |
41 | static int bus_slice_set_transient_property( |
| 42 | Slice *s, | |
| 43 | const char *name, | |
| 44 | sd_bus_message *message, | |
| 45 | UnitWriteFlags flags, | |
| 46 | sd_bus_error *error) { | |
| 47 | ||
| 48 | Unit *u = UNIT(s); | |
| 49 | ||
| 50 | assert(s); | |
| 51 | assert(name); | |
| 52 | assert(message); | |
| 53 | ||
| 54 | flags |= UNIT_PRIVATE; | |
| 55 | ||
| 56 | if (streq(name, "ConcurrencyHardMax")) | |
| 57 | return bus_set_transient_unsigned(u, name, &s->concurrency_hard_max, message, flags, error); | |
| 58 | ||
| 59 | if (streq(name, "ConcurrencySoftMax")) | |
| 60 | return bus_set_transient_unsigned(u, name, &s->concurrency_soft_max, message, flags, error); | |
| 61 | ||
| 62 | return 0; | |
| 63 | } | |
| 64 | ||
| 8e2af478 LP |
65 | int bus_slice_set_property( |
| 66 | Unit *u, | |
| 67 | const char *name, | |
| 718db961 | 68 | sd_bus_message *message, |
| 2e59b241 | 69 | UnitWriteFlags flags, |
| 718db961 | 70 | sd_bus_error *error) { |
| 8e2af478 LP |
71 | |
| 72 | Slice *s = SLICE(u); | |
| 9ca16f6f | 73 | int r; |
| 8e2af478 LP |
74 | |
| 75 | assert(name); | |
| 76 | assert(u); | |
| 8e2af478 | 77 | |
| 9ca16f6f LP |
78 | r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, flags, error); |
| 79 | if (r != 0) | |
| 80 | return r; | |
| 81 | ||
| 82 | if (u->transient && u->load_state == UNIT_STUB) { | |
| 83 | /* This is a transient unit, let's allow a little more */ | |
| 84 | ||
| 85 | r = bus_slice_set_transient_property(s, name, message, flags, error); | |
| 86 | if (r != 0) | |
| 87 | return r; | |
| 88 | } | |
| 89 | ||
| 90 | return 0; | |
| 8e2af478 LP |
91 | } |
| 92 | ||
| 93 | int bus_slice_commit_properties(Unit *u) { | |
| 94 | assert(u); | |
| 95 | ||
| 8d178f70 | 96 | (void) unit_realize_cgroup(u); |
| bc432dc7 | 97 | |
| 8e2af478 LP |
98 | return 0; |
| 99 | } |