feat: P0-2a C-side plumbing for host control

Add the full call chain for host control operations from the Go API
server through the C library to the controller:

- schema/controller.capnp: HostControl struct + hostctrlmsg @21
  in Request.body union
- include/typemap.h: xce_hostctrl_t* hostctrlmsg in body union
  (placed after @20 clrpreasonmsg, matching capnp ordinal)
- include/client.h, xceapi.h, request.h: declarations for
  xcecli_hostctrl, xce_hostctrl, xce_hostctrl_req
- lib/client.c: xcecli_hostctrl (validate + delegate to xce_hostctrl)
- lib/xceapi.c: xce_hostctrl (validate ctx state + send + wait reply)
- lib/request.c: xce_hostctrl_req (validate hostname/empty/nil,
  accept only HOST_OPEN/HOST_CLOSE, reject HOST_TAG/UNTAG)
- lib/helper.c: Request_body_hostctrlmsg cases in
  xce_request_body() and xce_request_msg_name()
- controller/cluster.c: OPCode_hostcontrol dispatch
- controller/include/cluster.h: do_hostcontrol_op declaration
- controller/worker.c: do_hostcontrol_op + fix pre-existing
  goto-clean bug in worker_ctrl that leaked write lock and
  reference on HOST_OPEN/HOST_CLOSE no-op paths

TDD: 8 xce_hostctrl_req validation tests (null ep, null ctrl,
null/empty hostname, HOST_DO_NONE no-op, HOST_TAG/UNTAG reject,
negative action reject, HOST_OPEN/CLOSE accept via xce_request).

116/116 xcelib tests pass. CGO_ENABLED=0 Go backend tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-04-17 07:46:41 +00:00
parent ac7ac99ced
commit dcb1b4fe25
15 changed files with 187 additions and 4 deletions

View file

@ -189,6 +189,9 @@ static int myreq_handler(vtask_t* task)
case OPCode_queuecontrol:
rc = do_queuecontrol_op(c, ep, &request);
break;
case OPCode_hostcontrol:
rc = do_hostcontrol_op(c, ep, &request);
break;
case OPCode_runtasks:
rc = do_runtasks(c, ep, &request);
break;

View file

@ -108,6 +108,7 @@ extern int update_resval_list(cluster_t*, worker_t*, xce_resval_list_t*);
extern int do_jobcontrol_op(cluster_t*, endpoint_t*, xce_request_t*);
extern int job_ctrl(cluster_t*, xce_jobctrl_t*);
extern int do_queuecontrol_op(cluster_t*, endpoint_t*, xce_request_t*);
extern int do_hostcontrol_op(cluster_t*, endpoint_t*, xce_request_t*);
extern int do_runtasks(cluster_t*, endpoint_t*, xce_request_t*);
extern int on_task_start(cluster_t*, xce_task_pidinfo_t*);
extern int on_task_fail(cluster_t*, xce_task_failinfo_t*);

View file

@ -626,10 +626,23 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
HOOK_AFTER_EVENT, HOOK_DETAIL_WORKER_UPDATE, c, w);
}
unlock(w);
dereference(w);
clean:
unlock(w);
dereference(w);
return rc;
}
int do_hostcontrol_op(cluster_t* c, endpoint_t* ep, xce_request_t* request)
{
int rc = 0;
xce_reply_t reply;
init_reply_by_req(&reply, request);
rc = worker_ctrl(c, request->body.hostctrlmsg);
reply.status = rc;
reply.data_which = RequestReply_data_nodata;
xce_reply(ep, c->myhost, &reply);
return rc;
}