From: Zbigniew Jędrzejewski-Szmek Date: Mon, 12 Jan 2026 10:43:06 +0000 (+0100) Subject: homectl: split out helper parse_rebalance_weight X-Git-Tag: v260-rc1~391^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c2199b4cc37be83d6845b47f32ba1b30a251ada;p=thirdparty%2Fsystemd.git homectl: split out helper parse_rebalance_weight --- diff --git a/src/home/homectl.c b/src/home/homectl.c index aa6bbec1458..9df62d6dd7b 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -3373,6 +3373,41 @@ static int parse_auto_resize_mode_field(sd_json_variant **identity, const char * return parse_string_field(identity, field, arg); } +static int parse_rebalance_weight(sd_json_variant **identity, const char *field, const char *arg) { + int r; + + assert(identity); + assert(field); + + if (isempty(arg)) + return drop_from_identity(field); + + uint64_t u; + if (streq(arg, "off")) + u = REBALANCE_WEIGHT_OFF; + else { + r = safe_atou64(arg, &u); + if (r < 0) + return log_error_errno(r, "Failed to parse rebalance weight parameter: %s", arg); + + if (u < REBALANCE_WEIGHT_MIN || u > REBALANCE_WEIGHT_MAX) + return log_error_errno(SYNTHETIC_ERRNO(ERANGE), + "Rebalancing weight out of valid range %" PRIu64 "%s%" PRIu64 ": %s", + REBALANCE_WEIGHT_MIN, glyph(GLYPH_ELLIPSIS), REBALANCE_WEIGHT_MAX, + arg); + } + + /* Drop from per machine stuff and everywhere */ + r = drop_from_identity(field); + if (r < 0) + return r; + + r = sd_json_variant_set_field_unsigned(identity, field, u); + if (r < 0) + return log_error_errno(r, "Failed to set %s field: %m", field); + return 0; +} + static int parse_rlimit_field(sd_json_variant **identity, const char *field, const char *arg) { int r; @@ -4636,40 +4671,12 @@ static int parse_argv(int argc, char *argv[]) { return r; break; - case ARG_REBALANCE_WEIGHT: { - uint64_t u; - - if (isempty(optarg)) { - r = drop_from_identity("rebalanceWeight"); - if (r < 0) - return r; - break; - } - - if (streq(optarg, "off")) - u = REBALANCE_WEIGHT_OFF; - else { - r = safe_atou64(optarg, &u); - if (r < 0) - return log_error_errno(r, "Failed to parse --rebalance-weight= argument: %s", optarg); - - if (u < REBALANCE_WEIGHT_MIN || u > REBALANCE_WEIGHT_MAX) - return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "Rebalancing weight out of valid range %" PRIu64 "%s%" PRIu64 ": %s", - REBALANCE_WEIGHT_MIN, glyph(GLYPH_ELLIPSIS), REBALANCE_WEIGHT_MAX, optarg); - } - - /* Drop from per machine stuff and everywhere */ - r = drop_from_identity("rebalanceWeight"); + case ARG_REBALANCE_WEIGHT: + r = parse_rebalance_weight(match_identity ?: &arg_identity_extra, + "rebalanceWeight", optarg); if (r < 0) return r; - - /* Add to main identity */ - r = sd_json_variant_set_field_unsigned(match_identity ?: &arg_identity_extra, "rebalanceWeight", u); - if (r < 0) - return log_error_errno(r, "Failed to set rebalanceWeight field: %m"); - break; - } case 'j': arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;