reformat code and job array

This commit is contained in:
Rongsong Shen 2025-11-07 16:14:27 +08:00
parent a665ccd4fe
commit 9ff857db9f
64 changed files with 1497 additions and 2476 deletions

View file

@ -6,8 +6,7 @@
#include "xce/cluster_def.h"
#include "xce/errnox.h"
static int hostmatched(const char* pattern,
const char* name)
static int hostmatched(const char* pattern, const char* name)
{
if (strcmp(pattern, name) == 0) {
return 1;
@ -16,8 +15,7 @@ static int hostmatched(const char* pattern,
return 0;
}
static xce_hostconfig_t* find_matched_hostconfig(cluster_t* c,
const char* name)
static xce_hostconfig_t* find_matched_hostconfig(cluster_t* c, const char* name)
{
xce_hostconfig_t* defaultconfig = NULL;
xce_hostconfig_t** hconfigs = NULL;
@ -56,10 +54,8 @@ static xce_hostconfig_t* find_matched_hostconfig(cluster_t* c,
return defaultconfig;
}
static int update_val_res(cluster_t* c,
worker_t* w,
xce_resource_t* r,
xce_val_t* val)
static int update_val_res(cluster_t* c, worker_t* w, xce_resource_t* r,
xce_val_t* val)
{
int idx;
zarray_t* array = NULL;
@ -97,26 +93,20 @@ static int update_val_res(cluster_t* c,
return 0;
}
static int update_resval(cluster_t* c,
worker_t* w,
xce_resval_t* val)
static int update_resval(cluster_t* c, worker_t* w, xce_resval_t* val)
{
xce_resource_t* r;
xce_val_t* v = NULL;
int rc;
r = resmgr_lockres(&(c->resmgr),
val->name,
OBJREF_READ);
r = resmgr_lockres(&(c->resmgr), val->name, OBJREF_READ);
if (r == NULL) {
ERROR("resource `%s' can not be found",
val->name);
ERROR("resource `%s' can not be found", val->name);
return -errno;
}
if (r->idx < 0) {
ERROR("invalid resource definition for %s",
val->name);
ERROR("invalid resource definition for %s", val->name);
return -EINVAL;
}
@ -129,10 +119,7 @@ static int update_resval(cluster_t* c,
return rc;
}
int update_resvals(cluster_t* c,
worker_t* w,
int nres,
xce_resval_t* vals)
int update_resvals(cluster_t* c, worker_t* w, int nres, xce_resval_t* vals)
{
int rc = 0;
int i;
@ -147,9 +134,7 @@ int update_resvals(cluster_t* c,
return 0;
}
int update_resval_list(cluster_t* c,
worker_t* w,
xce_resval_list_t* l)
int update_resval_list(cluster_t* c, worker_t* w, xce_resval_list_t* l)
{
int rc = 0;
int i;
@ -164,9 +149,7 @@ int update_resval_list(cluster_t* c,
return 0;
}
static int mark_host_res(cluster_t* c,
worker_t* w,
xce_config_t* config)
static int mark_host_res(cluster_t* c, worker_t* w, xce_config_t* config)
{
xce_resource_t* r;
char* n = config->name;
@ -177,14 +160,12 @@ static int mark_host_res(cluster_t* c,
r = resmgr_lockres(&(c->resmgr), n, OBJREF_READ);
if (r == NULL) {
ERROR("resource `%s' can not be found",
n);
ERROR("resource `%s' can not be found", n);
return -ENOENT;
}
if (r->idx < 0) {
ERROR("invalid resource definition for `%s'",
n);
ERROR("invalid resource definition for `%s'", n);
return -EINVAL;
}
@ -222,19 +203,20 @@ static int mark_host_res(cluster_t* c,
return rc;
}
static int add_hostattrs_resvals(cluster_t* c,
worker_t* w)
static int add_hostattrs_resvals(cluster_t* c, worker_t* w)
{
#define N_HOST_ATTRS (8)
xce_val_t values[N_HOST_ATTRS] = {
{ .which = Value_u_svalue, .u = { .svalue = w->host.attrs->hosttype } },
{ .which = Value_u_svalue, .u = { .svalue = w->host.attrs->hostmodel } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->cpufactor } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxcpus } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxmem } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxswap } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxtmp } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->ndisks } }
{ .which = Value_u_svalue, .u = { .svalue = w->host.attrs->hosttype } },
{ .which = Value_u_svalue,
.u = { .svalue = w->host.attrs->hostmodel } },
{ .which = Value_u_fvalue,
.u = { .fvalue = w->host.attrs->cpufactor } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxcpus } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxmem } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxswap } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxtmp } },
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->ndisks } }
};
xce_resval_t resvals[N_HOST_ATTRS] = {
{ .name = "type", .val = &values[0] },
@ -247,13 +229,10 @@ static int add_hostattrs_resvals(cluster_t* c,
{ .name = "ndisks", .val = &values[7] }
};
return update_resvals(c, w, N_HOST_ATTRS,
&(resvals[0]));
return update_resvals(c, w, N_HOST_ATTRS, &(resvals[0]));
}
static int set_host_slots(cluster_t* c,
worker_t* w,
int nslots)
static int set_host_slots(cluster_t* c, worker_t* w, int nslots)
{
/* clang-format off */
xce_val_t values[1] = {
@ -275,10 +254,7 @@ static int set_host_slots(cluster_t* c,
return update_resvals(c, w, 1, &(resvals[0]));
}
int add_worker(void* cls,
endpoint_t* ep,
const char* host,
hostattrs_t* attrs)
int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
{
cluster_t* c = (cluster_t*)cls;
/* clang-format off */
@ -317,17 +293,15 @@ int add_worker(void* cls,
/* override host type? */
if (strcmp(hconfig->hosttype, "!") != 0) {
obj_deref(w->host.attrs->hosttype);
w->host.attrs->hosttype = create_obj_by_typename(&(c->objmgr),
"xstring",
hconfig->hosttype);
w->host.attrs->hosttype = create_obj_by_typename(
&(c->objmgr), "xstring", hconfig->hosttype);
}
/* override host model */
if (strcmp(hconfig->hostmodel, "!") != 0) {
obj_deref(w->host.attrs->hostmodel);
w->host.attrs->hostmodel = create_obj_by_typename(&(c->objmgr),
"xstring",
hconfig->hostmodel);
w->host.attrs->hostmodel = create_obj_by_typename(
&(c->objmgr), "xstring", hconfig->hostmodel);
}
add_hostattrs_resvals(c, w);
idx = w->idx;
@ -346,12 +320,12 @@ int add_worker(void* cls,
}
if (hconfig->dispatchwindow != NULL) {
w->host.dispatch_window_config = dup_timewindow_config(hconfig->dispatchwindow);
w->host.dispatch_window_config
= dup_timewindow_config(hconfig->dispatchwindow);
}
if (w->host.thresholds != NULL) {
free_resource_thresholds(w->host.thresholds,
w->host.nthresholds);
free_resource_thresholds(w->host.thresholds, w->host.nthresholds);
w->host.nthresholds = 0;
w->host.thresholds = NULL;
}
@ -372,8 +346,7 @@ int add_worker(void* cls,
return idx;
}
int restore_worker(void* cls,
xce_worker_t host)
int restore_worker(void* cls, xce_worker_t host)
{
cluster_t* c = (cluster_t*)cls;
int idx = 0;
@ -415,15 +388,15 @@ static int check_conf4worker_(xce_config_t* c)
return 0;
}
static int worker_push_config(cluster_t* c,
endpoint_t* ep)
static int worker_push_config(cluster_t* c, endpoint_t* ep)
{
xce_configdata_t configdata;
int rc = 0;
memset(&configdata, 0x0, sizeof(configdata));
configdata.data.conf4worker = (xce_conf4worker_t*)calloc(1, sizeof(xce_conf4worker_t));
configdata.data.conf4worker
= (xce_conf4worker_t*)calloc(1, sizeof(xce_conf4worker_t));
if (configdata.data.conf4worker == NULL) {
return -ENOMEM;
}
@ -431,8 +404,9 @@ static int worker_push_config(cluster_t* c,
collect_confvars(c, (collect_check_fn_t)check_conf4worker_,
&(configdata.data.conf4worker->n_confvars),
&(configdata.data.conf4worker->confvars));
configdata.data_which = ConfigData_data_workerconfig;
configdata.data.conf4worker->clustername = c->myconf->cluster_config->clustername;
configdata.data_which = ConfigData_data_workerconfig;
configdata.data.conf4worker->clustername
= c->myconf->cluster_config->clustername;
rc = xce_pushconfig_req(ep, c->myhost, &configdata);
@ -446,8 +420,7 @@ static int worker_push_config(cluster_t* c,
}
/* consider to push jobs on hosts to */
int on_worker_join(void* cls,
endpoint_t* ep)
int on_worker_join(void* cls, endpoint_t* ep)
{
cluster_t* c = (cluster_t*)cls;
int rc = 0;
@ -457,19 +430,14 @@ int on_worker_join(void* cls,
return rc;
}
int get_resval(cluster_t* c,
char* resname,
char* host,
xce_val_t* val)
int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
{
xce_resource_t* r;
zarray_t* array = NULL;
xce_val_t* v = NULL;
worker_t* w = NULL;
r = resmgr_lockres(&(c->resmgr),
resname,
OBJREF_READ);
r = resmgr_lockres(&(c->resmgr), resname, OBJREF_READ);
if (r == NULL) {
return -ENOENT;
}
@ -481,8 +449,7 @@ int get_resval(cluster_t* c,
return -EINVAL;
}
w = workermgr_lock(&(c->workermgr),
host, OBJREF_READ);
w = workermgr_lock(&(c->workermgr), host, OBJREF_READ);
if (w == NULL) {
DEREF_OBJ(r);
return -ENOENT;
@ -509,13 +476,11 @@ int get_resval(cluster_t* c,
return 1;
}
int handle_worker_leave(cluster_t* c,
int idx)
int handle_worker_leave(cluster_t* c, int idx)
{
worker_t* w = NULL;
TRACE("%s worker %d broken connection",
__func__, idx);
TRACE("%s worker %d broken connection", __func__, idx);
if (c == NULL) {
SET_ERROR(EINVAL);
@ -527,27 +492,20 @@ int handle_worker_leave(cluster_t* c,
return -errno;
}
w = workermgr_lock_byid(&(c->workermgr),
idx, OBJREF_UPDATE);
w = workermgr_lock_byid(&(c->workermgr), idx, OBJREF_UPDATE);
if (w == NULL) {
ERROR("fail to find worker by id %d", idx);
SET_ERROR(E_XCE_BAD_WORKER);
return -errno;
}
xce_run_hooks(&(c->hooksys),
XCE_CONTROLLER_HOOK_WORKER,
HOOK_BEFORE_EVENT,
HOOK_DETAIL_WORKER_DEAD,
c, w);
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_BEFORE_EVENT,
HOOK_DETAIL_WORKER_DEAD, c, w);
w->host.status |= XCE_WORKER_UNAVAIL;
w->ep = NULL;
xce_run_hooks(&(c->hooksys),
XCE_CONTROLLER_HOOK_WORKER,
HOOK_AFTER_EVENT,
HOOK_DETAIL_WORKER_DEAD,
c, w);
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT,
HOOK_DETAIL_WORKER_DEAD, c, w);
obj_deref(w);
return 0;
}
@ -587,11 +545,8 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
break;
}
if (rc == 0) {
xce_run_hooks(&(c->hooksys),
XCE_CONTROLLER_HOOK_WORKER,
HOOK_AFTER_EVENT,
HOOK_DETAIL_WORKER_UPDATE,
c, w);
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER,
HOOK_AFTER_EVENT, HOOK_DETAIL_WORKER_UPDATE, c, w);
}
clean:
obj_deref(w);