Skip to content

Commit 9aa3e5e

Browse files
committed
user-record: add rebalanceWeight field
1 parent 993b905 commit 9aa3e5e

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

docs/USER_RECORD.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,12 @@ the size configured in `diskSize` automatically at login time. If set to
507507
`shrink-and-grown` the home area is also shrunk to the minimal size possible
508508
(as dictated by used disk space and file system constraints) on logout.
509509

510+
`rebalanceWeight` → An unsigned integer, `null` or a boolean. Configures the
511+
free disk space rebalancing weight for the home area. The integer must be in
512+
the range 1…10000 to configure an explicit weight. If unset, or set to `null`
513+
or `true` the default weight of 100 is implied. If set to 0 or `false`
514+
rebalancing is turned off for this home area.
515+
510516
`service` → A string declaring the service that defines or manages this user
511517
record. It is recommended to use reverse domain name notation for this. For
512518
example, if `systemd-homed` manages a user a string of `io.systemd.Home` is
@@ -729,9 +735,10 @@ that may be used in this section are identical to the equally named ones in the
729735
`fileSystemUuid`, `luksDiscard`, `luksOfflineDiscard`, `luksCipher`,
730736
`luksCipherMode`, `luksVolumeKeySize`, `luksPbkdfHashAlgorithm`,
731737
`luksPbkdfType`, `luksPbkdfTimeCostUSec`, `luksPbkdfMemoryCost`,
732-
`luksPbkdfParallelThreads`, `rateLimitIntervalUSec`, `rateLimitBurst`,
733-
`enforcePasswordPolicy`, `autoLogin`, `stopDelayUSec`, `killProcesses`,
734-
`passwordChangeMinUSec`, `passwordChangeMaxUSec`, `passwordChangeWarnUSec`,
738+
`luksPbkdfParallelThreads`, `autoResizeMode`, `rebalanceWeight`,
739+
`rateLimitIntervalUSec`, `rateLimitBurst`, `enforcePasswordPolicy`,
740+
`autoLogin`, `stopDelayUSec`, `killProcesses`, `passwordChangeMinUSec`,
741+
`passwordChangeMaxUSec`, `passwordChangeWarnUSec`,
735742
`passwordChangeInactiveUSec`, `passwordChangeNow`, `pkcs11TokenUri`,
736743
`fido2HmacCredential`.
737744

src/shared/user-record-show.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,16 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) {
447447
if (hr->auto_resize_mode >= 0)
448448
printf(" Auto Resize: %s\n", auto_resize_mode_to_string(user_record_auto_resize_mode(hr)));
449449

450+
if (hr->rebalance_weight != REBALANCE_WEIGHT_UNSET) {
451+
uint64_t rb;
452+
453+
rb = user_record_rebalance_weight(hr);
454+
if (rb == REBALANCE_WEIGHT_OFF)
455+
printf(" Rebalance: off\n");
456+
else
457+
printf(" Rebalance: weight %" PRIu64 "\n", rb);
458+
}
459+
450460
if (!strv_isempty(hr->ssh_authorized_keys))
451461
printf("SSH Pub. Key: %zu\n", strv_length(hr->ssh_authorized_keys));
452462

src/shared/user-record.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ UserRecord* user_record_new(void) {
8585
.fido2_user_verification_permitted = -1,
8686
.drop_caches = -1,
8787
.auto_resize_mode = _AUTO_RESIZE_MODE_INVALID,
88+
.rebalance_weight = REBALANCE_WEIGHT_UNSET,
8889
};
8990

9091
return h;
@@ -984,6 +985,36 @@ static int dispatch_auto_resize_mode(const char *name, JsonVariant *variant, Jso
984985
return 0;
985986
}
986987

988+
static int dispatch_rebalance_weight(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
989+
uint64_t *rebalance_weight = userdata;
990+
uintmax_t u;
991+
992+
assert_se(rebalance_weight);
993+
994+
if (json_variant_is_null(variant)) {
995+
*rebalance_weight = REBALANCE_WEIGHT_UNSET;
996+
return 0;
997+
}
998+
999+
if (json_variant_is_boolean(variant)) {
1000+
*rebalance_weight = json_variant_boolean(variant) ? REBALANCE_WEIGHT_DEFAULT : REBALANCE_WEIGHT_OFF;
1001+
return 0;
1002+
}
1003+
1004+
if (!json_variant_is_unsigned(variant))
1005+
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an unsigned integer, boolean or null.", strna(name));
1006+
1007+
u = json_variant_unsigned(variant);
1008+
if (u >= REBALANCE_WEIGHT_MIN && u <= REBALANCE_WEIGHT_MAX)
1009+
*rebalance_weight = (uint64_t) u;
1010+
else if (u == 0)
1011+
*rebalance_weight = REBALANCE_WEIGHT_OFF;
1012+
else
1013+
return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), "Rebalance weight is out of valid range %" PRIu64 "…%" PRIu64 ".", REBALANCE_WEIGHT_MIN, REBALANCE_WEIGHT_MAX);
1014+
1015+
return 0;
1016+
}
1017+
9871018
static int dispatch_privileged(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
9881019

9891020
static const JsonDispatch privileged_dispatch_table[] = {
@@ -1177,6 +1208,7 @@ static int dispatch_per_machine(const char *name, JsonVariant *variant, JsonDisp
11771208
{ "luksExtraMountOptions", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, luks_extra_mount_options), 0 },
11781209
{ "dropCaches", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, drop_caches), 0 },
11791210
{ "autoResizeMode", _JSON_VARIANT_TYPE_INVALID, dispatch_auto_resize_mode, offsetof(UserRecord, auto_resize_mode), 0 },
1211+
{ "rebalanceWeight", _JSON_VARIANT_TYPE_INVALID, dispatch_rebalance_weight, offsetof(UserRecord, rebalance_weight), 0 },
11801212
{ "rateLimitIntervalUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, ratelimit_interval_usec), 0 },
11811213
{ "rateLimitBurst", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, ratelimit_burst), 0 },
11821214
{ "enforcePasswordPolicy", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, enforce_password_policy), 0 },
@@ -1528,6 +1560,7 @@ int user_record_load(UserRecord *h, JsonVariant *v, UserRecordLoadFlags load_fla
15281560
{ "luksExtraMountOptions", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, luks_extra_mount_options), 0 },
15291561
{ "dropCaches", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, drop_caches), 0 },
15301562
{ "autoResizeMode", _JSON_VARIANT_TYPE_INVALID, dispatch_auto_resize_mode, offsetof(UserRecord, auto_resize_mode), 0 },
1563+
{ "rebalanceWeight", _JSON_VARIANT_TYPE_INVALID, dispatch_rebalance_weight, offsetof(UserRecord, rebalance_weight), 0 },
15311564
{ "service", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, service), JSON_SAFE },
15321565
{ "rateLimitIntervalUSec", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, ratelimit_interval_usec), 0 },
15331566
{ "rateLimitBurst", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, offsetof(UserRecord, ratelimit_burst), 0 },
@@ -1939,6 +1972,15 @@ AutoResizeMode user_record_auto_resize_mode(UserRecord *h) {
19391972
return user_record_storage(h) == USER_LUKS ? AUTO_RESIZE_SHRINK_AND_GROW : AUTO_RESIZE_OFF;
19401973
}
19411974

1975+
uint64_t user_record_rebalance_weight(UserRecord *h) {
1976+
assert(h);
1977+
1978+
if (h->rebalance_weight == REBALANCE_WEIGHT_UNSET)
1979+
return REBALANCE_WEIGHT_DEFAULT;
1980+
1981+
return h->rebalance_weight;
1982+
}
1983+
19421984
uint64_t user_record_ratelimit_next_try(UserRecord *h) {
19431985
assert(h);
19441986

src/shared/user-record.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ typedef enum AutoResizeMode {
221221
_AUTO_RESIZE_MODE_INVALID = -EINVAL,
222222
} AutoResizeMode;
223223

224+
#define REBALANCE_WEIGHT_OFF UINT64_C(0)
225+
#define REBALANCE_WEIGHT_DEFAULT UINT64_C(100)
226+
#define REBALANCE_WEIGHT_MIN UINT64_C(1)
227+
#define REBALANCE_WEIGHT_MAX UINT64_C(10000)
228+
#define REBALANCE_WEIGHT_UNSET UINT64_MAX
229+
224230
typedef struct UserRecord {
225231
/* The following three fields are not part of the JSON record */
226232
unsigned n_ref;
@@ -258,6 +264,7 @@ typedef struct UserRecord {
258264
char *skeleton_directory;
259265
mode_t access_mode;
260266
AutoResizeMode auto_resize_mode;
267+
uint64_t rebalance_weight;
261268

262269
uint64_t tasks_max;
263270
uint64_t memory_high;
@@ -397,6 +404,7 @@ uint64_t user_record_ratelimit_burst(UserRecord *h);
397404
bool user_record_can_authenticate(UserRecord *h);
398405
bool user_record_drop_caches(UserRecord *h);
399406
AutoResizeMode user_record_auto_resize_mode(UserRecord *h);
407+
uint64_t user_record_rebalance_weight(UserRecord *h);
400408

401409
int user_record_build_image_path(UserStorage storage, const char *user_name_and_realm, char **ret);
402410

0 commit comments

Comments
 (0)