refactor(controller,xceadmin): drop generic Resource.unit, hardcode bytes for maxmem

Simplification per review feedback on e3b3ffa: a generic schema-driven
unit field touched the capnp wire schema (2 structs), C structs
(xce_resource_t/xce_resval_t), resobj.c's deep-copy/destroy, opget.c's
reply-build lookup, resources.yaml/resources.schema.json, and mapping.py
-- real cross-cutting cost for a mechanism only one resource (maxmem)
actually needs today.

Reverted all of that. The controller CLI (test.c) now just knows
"maxmem" is bytes-valued via a small explicit is_bytes_valued_resource()
name list, and adaptively picks the best-fit human unit at display time
(format_bytes_human, unchanged) -- same observable behavior (resval/
workerlist render maxmem as e.g. "30.90 GB"), zero wire schema surface.
Regenerated the xceadmin golden fixture back to its pre-unit-field size
(5304 bytes, exactly matching the size right after the mxj-only fix,
confirming a clean, complete removal).

Verified: 1095/1095 controller_unit_test (3 runs; one hit the
pre-existing flaky segfault already logged as bug-1553, unrelated),
228/228 xceadmin pytest, clean rebuild of lib/controller/xceadmin/xce_test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-08-13 08:27:16 +00:00
parent e3b3ffaa97
commit 5bf123cc20
Signed by: rshen
SSH key fingerprint: SHA256:8Vf2pZ3h6rJa7EhGK+WaAQ9Mta/apZvteW6g9U/WKKk
10 changed files with 36 additions and 58 deletions

View file

@ -62,20 +62,9 @@ static int do_reply_resvals(cluster_t* c, endpoint_t* ep,
rc = get_resval(c, condition->condition.reskey->resname,
condition->condition.reskey->hostname, &val);
if (rc >= 0) {
xce_resource_t* r = NULL;
resval.val = &val;
resval.name = condition->condition.reskey->resname;
resval.host = condition->condition.reskey->hostname;
resval.unit = NULL;
lock(c->resmgr, RTTI_LOCK_READ);
key_find(c->resmgr, (void*)resval.name, (void**)&r);
unlock(c->resmgr);
if (r != NULL) {
resval.unit = r->unit;
}
resvaldata.n_total = 1;
resvaldata.vals = vals;
}

View file

@ -2036,11 +2036,40 @@ cleanup:
}
/*
* Render a raw byte count as a human-readable string (e.g. "30.90 GB").
* Only used for display -- the stored/wire value stays raw bytes always,
* this never feeds back into anything that's compared or persisted. A
* pure function so it's directly unit-testable without a live client
* connection.
* Resource names whose canonical stored/wire value is raw bytes (not a
* generic schema-driven unit system -- deliberately kept as a small,
* explicit, client-side list rather than a wire field, since exactly one
* resource needs this today and a wire-level unit hint would have grown
* every Resource/ResourceVal message regardless of whether it's used).
* CLI display picks the best-fit human unit adaptively (format_bytes_human);
* the stored value is never converted.
*/
static int is_bytes_valued_resource(const char* name)
{
static const char* const BYTES_VALUED_RESOURCES[] = { "maxmem" };
const int nres = (int)(sizeof(BYTES_VALUED_RESOURCES)
/ sizeof(BYTES_VALUED_RESOURCES[0]));
int i;
if (name == NULL) {
return 0;
}
for (i = 0; i < nres; i++) {
if (strcmp(name, BYTES_VALUED_RESOURCES[i]) == 0) {
return 1;
}
}
return 0;
}
/*
* Render a raw byte count as a human-readable string (e.g. "30.90 GB"),
* adaptively picking the smallest unit the value fits in. Only used for
* display -- the stored/wire value stays raw bytes always, this never
* feeds back into anything that's compared or persisted. A pure function
* so it's directly unit-testable without a live client connection.
*/
static void format_bytes_human(double bytes, char* buf, size_t bufsize)
{
@ -2098,7 +2127,7 @@ int cmd_resval(int argc, char* argv[])
printf("%s\n", val->val->u.svalue);
break;
case Value_u_fvalue:
if ((val->unit != NULL) && (strcmp(val->unit, "bytes") == 0)) {
if (is_bytes_valued_resource(val->name)) {
char hbuf[64];
format_bytes_human(val->val->u.fvalue, hbuf,