save works

This commit is contained in:
Rongsong Shen 2026-03-03 16:49:26 +08:00
parent f4b1ba4cd7
commit acfbec875b
51 changed files with 622 additions and 1175 deletions

View file

@ -64,10 +64,10 @@ Host gitea.shenrs.eu
cd xce/src
# for build debug version
nix build --option sandbox false .#xce_debug
nix build --option sandbox false .#xcecore_debug
# for normal build
nix build --option sandbox false .#xce
nix build --option sandbox false .#xcecore
```
You can find the generated binaries at =result= directory
@ -88,6 +88,15 @@ meson compile -C build
# The generated files will be in build/
```
## 3.5 build AppImage package
```sh
cd xce/src
nix bundle --bundler github:ralismark/nix-appimage --option sandbox false .#xce
```
This will create all in one AppImage file which contains everything for package delivery.
# 4. misc
## 4.1. Windows remap ctrl and alt key
create a reg file, e.g. remapkey.reg

View file

@ -60,7 +60,7 @@ go_env.set('ENVARS', 'CURRENT_SOURCE_DIR BUILD_ROOT')
apiserver = custom_target('apiserver',
input: 'cmd/main.go',
output: 'apiserver',
output: 'xce_apiserver',
command: [env_program,
'CURRENT_SOURCE_DIR="@CURRENT_SOURCE_DIR@"',
'BUILD_ROOT="@BUILD_ROOT@"',

View file

@ -3,7 +3,6 @@
#include "cluster.h"
#include "controller.capnp.h"
#include "objmgr.h"
#include "request.h"
#include "xce/types.h"
#include "xstring.h"
@ -27,16 +26,19 @@ static int xce_apiserver_push_workers(cluster_t* c, endpoint_t* ep)
xce_data_t data;
xce_workers_data_t workers
= { .n_total = 0, .pos = 0, .count = 0, .workers = NULL };
int i, rc = 0;
int i, rc = 0;
xlist_t wlist;
memset(&data, 0x0, sizeof(data));
xlist_init(&wlist, 8192);
data.table = Data_data_workers;
data.data.workers = &workers;
collect_workers(c, (collect_check_fn_t)check_worker_, &(workers.n_total),
&(workers.workers));
workers.count = workers.n_total;
collect_workers(c, (collect_check_fn_t)check_worker_, &wlist);
workers.n_total = wlist.count;
workers.workers = (xce_worker_t**)wlist.data;
workers.count = workers.n_total;
rc = xce_push_data_req(ep, c->myhost, &data, check_controller, c, 100);
@ -49,7 +51,8 @@ static int xce_apiserver_push_workers(cluster_t* c, endpoint_t* ep)
free_resval_with_idx_list(&(w->resvals_to_sched), w->nresvals_to_sched);
}
deref_objs(workers.n_total, (void**)workers.workers);
unlock_collect_workers(&wlist);
FREEUP(workers.workers);
return rc;
@ -69,18 +72,23 @@ static int xce_apiserver_push_jobs(cluster_t* c, endpoint_t* ep)
xce_data_t data;
xce_jobs_data_t jobs = { .n_total = 0, .pos = 0, .count = 0, .jobs = NULL };
int rc = 0;
xlist_t jlist;
memset(&data, 0x0, sizeof(data));
xlist_init(&jlist, 1024 * 1024);
data.table = Data_data_jobs;
data.data.jobs = &jobs;
collect_jobs(c, (collect_check_fn_t)check_job_, &(jobs.n_total),
&(jobs.jobs));
jobs.count = jobs.n_total;
collect_jobs(c, (collect_check_fn_t)check_job_, &jlist);
jobs.n_total = jlist.count;
jobs.jobs = (xce_job_t**)jlist.data;
jobs.count = jobs.n_total;
rc = xce_push_data_req(ep, c->myhost, &data, check_controller, c, 100);
deref_objs(jobs.n_total, (void**)jobs.jobs);
unlock_collect_jobs(&jlist);
FREEUP(jobs.jobs);
return rc;
@ -256,7 +264,7 @@ static int apiserver_job_update_fun(int type, int situation, void* data,
int rc;
xce_notify_data_t xdata
= { .event = NotifyData_data_updateJob,
.data = { .update_job = &(job->job) } };
.data = { .update_job = &(job->job) } };
rc = notify(c, c->apiservers[i].ep, &xdata);
if (rc < 0) {
@ -349,13 +357,16 @@ static int apiserver_push_workerlist(cluster_t* c, endpoint_t* ep, xlist_t* l)
static int apiserver_worker_change(int type, int situation, void* data,
cluster_t* c, worker_t* w)
{
int i;
int i;
xlist_t resvalist;
TRACE("%s worker %s idx %d situation %d", __func__, w->host.name, w->idx,
situation);
collect_resval_with_idx(&(w->host.resvals), &(w->host.nresvals_to_sched),
&(w->host.resvals_to_sched));
xlist_init(&resvalist, 256);
collect_resval_with_idx(&(w->host.resvals), &resvalist);
w->host.nresvals_to_sched = resvalist.count;
w->host.resvals_to_sched = (xce_val_with_idx_t**)resvalist.data;
switch (situation) {
case HOOK_AFTER_EVENT:
@ -383,8 +394,11 @@ static int apiserver_worker_change(int type, int situation, void* data,
break;
}
#if 0
free_resval_with_idx_list(&(w->host.resvals_to_sched),
w->host.nresvals_to_sched);
#endif
xlist_fini(&resvalist);
return 0;
}
@ -514,7 +528,7 @@ static int apiserver_queue_hook_fun(int type, int situation, int detail,
int rc;
xce_notify_data_t xdata
= { .event = NotifyData_data_schedUpdateQueue,
.data = { .sched_update_queue = &(q->queue) } };
.data = { .sched_update_queue = &(q->queue) } };
rc = notify(c, c->apiservers[i].ep, &xdata);
if (rc < 0) {
@ -585,7 +599,6 @@ int handle_apiserver_leave(cluster_t* c, endpoint_t* ep)
}
if (c->apiservers[i].name != NULL) {
obj_deref(c->apiservers[i].name);
c->apiservers[i].ep = NULL;
}

View file

@ -22,6 +22,7 @@
#include "worker.h"
#include "xce/errnox.h"
#include "xstring.h"
#include "jobj.h"
static xce_peerinfo_t from_controller
= { .name = "controller", .key = "keepSecret" };
@ -371,7 +372,7 @@ int cluster_build_resources(cluster_t* c)
for (i = 0; i < c->myconf->cluster_config->nres; i++) {
xce_resource_t* res;
res = makeResource(c->myconf->cluster_config->resources[i]);
res = makeResource(c->resmgr, c->myconf->cluster_config->resources[i]);
if (res == NULL) {
return -errno;
}
@ -568,7 +569,6 @@ int cluster_init(cluster_t* c)
c->configmgr = makeInstance(&xkvmgr_type, &config_mgr_params);
objmgr_init(&(c->objmgr));
c->jobmgr = makeInstance(&xkvmgr_type, &jobmgr_params);
c->resmgr = makeInstance(&xkvmgr_type, &resmgr_params);
zarray_init(&(c->sharedinst), c->myconf->cluster_config->resmgr->inst_delta,
@ -580,6 +580,7 @@ int cluster_init(cluster_t* c)
iomgr_set_ssl_ctx(&(c->iomgr), ssl_ctx);
xstring_table_init(c->myconf->cluster_config->xstrings->nhash_slots);
job_obj_init(5381, 5381);
zarray_init(&(c->endpoints), 16, endpoint_killer);
@ -775,12 +776,12 @@ void cluster_fini(cluster_t* c)
zarray_fini(&(c->endpoints));
zarray_fini(&(c->configs));
objmgr_fini(&(c->objmgr));
xce_hook_fini(&(c->hooksys));
cleanup_openssl();
job_obj_fini();
xstring_table_fini();
return;

View file

@ -4,6 +4,7 @@
#include "request.h"
#include "xce/cluster_def.h"
#include "xce/types.h"
#include "xlist.h"
typedef int (*check_fn_t)(void*);
@ -18,35 +19,9 @@ int check_controller(void* arg)
return 1;
}
static int collect_resval_with_idx_(zarray_t* array, int* nres,
xce_val_with_idx_t*** resvals)
static int collect_resval_with_idx_(zarray_t* array, xlist_t* l)
{
int nc;
int i, j;
xce_val_with_idx_t** vals;
nc = 0;
for (i = 0; i < array->caps; i++) {
if (array->data[i] == NULL) {
continue;
}
nc++;
}
if (nc == 0) {
*nres = 0;
*resvals = NULL;
return 0;
}
vals = (xce_val_with_idx_t**)calloc(nc, sizeof(xce_val_with_idx_t*));
if (vals == NULL) {
return -ENOMEM;
}
j = 0;
int i;
for (i = 0; i < array->caps; i++) {
xce_val_with_idx_t* val;
@ -58,17 +33,12 @@ static int collect_resval_with_idx_(zarray_t* array, int* nres,
val = (xce_val_with_idx_t*)calloc(1, sizeof(*val));
if (val == NULL) {
free_resval_with_idx_list(&vals, j);
return -ENOMEM;
}
vals[j] = val;
j++;
val->idx = i;
val->val = (xce_val_t*)calloc(1, sizeof(xce_val_t));
if (val->val == NULL) {
free_resval_with_idx_list(&vals, j);
return -ENOMEM;
}
@ -82,43 +52,36 @@ static int collect_resval_with_idx_(zarray_t* array, int* nres,
} else {
memcpy(val->val, array->data[i], sizeof(xce_val_t));
}
xlist_store(l, val);
}
*nres = j;
*resvals = vals;
return j;
return l->count;
}
int collect_resval_with_idx(zarray_t* array, int* nres,
xce_val_with_idx_t*** resvals)
int collect_resval_with_idx(zarray_t* array, xlist_t* l)
{
int rc = 0;
mylock_lock(&(array->lock));
rc = collect_resval_with_idx_(array, nres, resvals);
rc = collect_resval_with_idx_(array, l);
mylock_unlock(&(array->lock));
return rc;
}
void collect_confvars(cluster_t* c, collect_check_fn_t fn, int* nconfig,
xce_config_t*** configs)
void collect_confvars(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int nc = 0, idx;
int rc;
*nconfig = 0;
*configs = NULL;
rc = iter_make(&it, c->configmgr);
if (rc < 0) {
return;
}
nc = 0;
for (;;) {
xce_config_t* config = NULL;
@ -127,124 +90,60 @@ void collect_confvars(cluster_t* c, collect_check_fn_t fn, int* nconfig,
break;
}
if (config != NULL) {
nc++;
}
}
if (rc < 0) {
iter_destroy(&it);
return;
}
if (nc == 0) {
iter_destroy(&it);
return;
}
iter_reset(&it);
*configs = (xce_config_t**)calloc(nc, sizeof(xce_config_t*));
if ((*configs) == NULL) {
return;
}
idx = 0;
for (;;) {
xce_config_t* config = NULL;
rc = iter_next(&it, (void**)&config);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
if (config == NULL) {
continue;
}
if (config != NULL) {
(*configs)[idx] = config;
idx++;
if ((fn == NULL) || (fn(config))) {
xlist_store(l, config);
}
}
iter_destroy(&it);
return;
}
void collect_queues(cluster_t* c, collect_check_fn_t fn, int* nqueues,
xce_queue_t*** queues)
void collect_queues(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int count;
int rc;
int nc;
*nqueues = 0;
*queues = NULL;
rc = iter_make(&it, c->qmgr);
if (rc < 0) {
return;
}
count = 0;
for (;;) {
xce_queue_t* q = NULL;
queue_t* q = NULL;
rc = iter_next(&it, (void**)&q);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
}
if (q != NULL) {
count++;
if (q == NULL) {
continue;
}
if ((fn != NULL) || fn(q)) {
lock(q, RTTI_LOCK_READ);
xlist_store(l, &(q->queue));
}
}
if (rc < 0) {
return;
}
*queues = (xce_queue_t**)calloc(count, sizeof(xce_queue_t*));
if ((*queues) == NULL) {
iter_destroy(&it);
return;
}
iter_reset(&it);
nc = 0;
for (;;) {
xce_queue_t* q = NULL;
rc = iter_next(&it, (void**)&q);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
}
if (q != NULL) {
(*queues)[nc] = q;
nc++;
}
}
*nqueues = nc;
iter_destroy(&it);
}
void collect_resources(cluster_t* c, collect_check_fn_t fn, int* nresources,
xce_resource_t*** resources)
void collect_resources(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int rc;
int i, nc;
*nresources = 0;
*resources = NULL;
rc = iter_make(&it, c->resmgr);
if (rc < 0) {
return;
}
nc = 0;
for (;;) {
xce_resource_t* r = NULL;
@ -253,186 +152,145 @@ void collect_resources(cluster_t* c, collect_check_fn_t fn, int* nresources,
break;
}
if (r != NULL) {
nc++;
}
}
if ((rc < 0) || (nc == 0)) {
iter_destroy(&it);
return;
}
*resources = calloc(nc, sizeof(xce_resource_t));
if ((*resources) == NULL) {
iter_destroy(&it);
return;
}
iter_reset(&it);
i = 0;
for (;;) {
xce_resource_t* r = NULL;
rc = iter_next(&it, (void**)&r);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
if (r == NULL) {
continue;
}
if (r != NULL) {
(*resources)[i] = r;
i++;
if ((fn == NULL) || (fn(r))) {
xlist_store(l, r);
}
}
*nresources = i;
iter_destroy(&it);
return;
}
void collect_jobs(cluster_t* c, collect_check_fn_t fn, int* njobs,
xce_job_t*** jobs)
void collect_jobs(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int nc, i;
int rc = 0;
*njobs = 0;
*jobs = NULL;
rc = iter_make(&it, c->jobmgr);
if (rc < 0) {
return;
}
nc = 0;
for (;;) {
xce_job_t* j = NULL;
job_t* j = NULL;
rc = iter_next(&it, (void**)&j);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
}
if (j != NULL) {
nc++;
}
}
if ((rc < 0) || (nc == 0)) {
iter_destroy(&it);
return;
}
iter_reset(&it);
i = 0;
for (;;) {
xce_job_t* j = NULL;
rc = iter_next(&it, (void**)&j);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
if (j == NULL) {
continue;
}
if (j != NULL) {
(*jobs)[i] = j;
i++;
if ((fn == NULL) || (fn(j))) {
lock(j, RTTI_LOCK_READ);
xlist_store(l, &(j->job));
}
}
*njobs = i;
iter_destroy(&it);
return;
}
void collect_workers(cluster_t* c, collect_check_fn_t fn, int* nworkers,
xce_worker_t*** workers)
void collect_workers(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
iterator_t it;
int i, nc;
int rc = 0;
*nworkers = 0;
*workers = NULL;
rc = iter_make(&it, c->workermgr);
if (rc < 0) {
return;
}
nc = 0;
for (;;) {
xce_worker_t* w = NULL;
worker_t* w = NULL;
rc = iter_next(&it, (void**)&w);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
}
if (w != NULL) {
nc++;
}
}
if ((rc < 0) || (nc == 0)) {
iter_destroy(&it);
return;
}
iter_reset(&it);
i = 0;
for (;;) {
xce_worker_t* w = NULL;
rc = iter_next(&it, (void**)&w);
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
break;
if (w == NULL) {
continue;
}
if (w != NULL) {
(*workers)[i] = w;
i++;
if ((fn == NULL) || (fn(w))) {
lock(w, RTTI_LOCK_READ);
xlist_store(l, &(w->host));
}
}
*nworkers = i;
iter_destroy(&it);
return;
}
void collect_shared_resvals(cluster_t* c, collect_check_fn_t fn, int* nres,
xce_val_with_idx_t*** resvals)
void collect_shared_resvals(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
{
collect_resval_with_idx(&(c->sharedinst), nres, resvals);
collect_resval_with_idx(&(c->sharedinst), l);
return;
}
void deref_objs(int count, void** objs)
{
int i;
for (i = 0; i < count; i++) {
void* obj = objs[i];
if (obj == NULL) {
continue;
}
DEREF_OBJ(obj);
}
}
int notify(cluster_t* c, endpoint_t* ep, xce_notify_data_t* data)
{
return xce_notify_req(ep, data);
}
void unlock_collect_queues(xlist_t* l)
{
int i;
for (i = 0; i < l->count; i++) {
xce_queue_t* q = (xce_queue_t*)xlist_get(l, i);
queue_t* q1;
if (q == NULL) {
continue;
}
q1 = CONTAINER_OF(q, queue_t, queue);
unlock(q1);
}
}
void unlock_collect_workers(xlist_t* l)
{
int i;
for (i = 0; i < l->count; i++) {
xce_worker_t* w = (xce_worker_t*)xlist_get(l, i);
worker_t* w1;
if (w == NULL) {
continue;
}
w1 = CONTAINER_OF(w, worker_t, host);
unlock(w1);
}
}
void unlock_collect_jobs(xlist_t* l)
{
int i;
for (i = 0; i < l->count; i++) {
xce_job_t* j = (xce_job_t*)xlist_get(l, i);
job_t* j1;
if (j == NULL) {
continue;
}
j1 = CONTAINER_OF(j, job_t, job);
unlock(j1);
}
}

View file

@ -12,7 +12,6 @@
#include "myconf.h"
#include "mylock.h"
#include "netio.h"
#include "objmgr.h"
#include "vtaskmgr.h"
#include "worker.h"
#include "xce/cluster_def.h"
@ -47,24 +46,20 @@ extern queue_t* create_queue(cluster_t*, xce_queue_t*);
extern int build_queues(void*);
extern void queue_fini(queue_t*);
extern int queue_ctrl(cluster_t*, xce_queuectrl_t*);
extern queue_t* qmgr_lockq(qmgr_t*, char*, int);
extern int xce_update_data(endpoint_t*, cluster_t*, int, int, int*, int,
xce_kv_t*);
extern int on_scheduler_join(cluster_t*);
extern int on_apiserver_join(cluster_t*, endpoint_t*);
extern int xce_push_reslist(endpoint_t*, cluster_t*, int, xce_resource_t**);
extern int xce_push_confvars(endpoint_t*, cluster_t*, int, xce_config_t**);
extern int xce_push_workerlist(endpoint_t*, cluster_t*, int, xce_worker_t**);
extern int xce_push_joblist(endpoint_t*, cluster_t*, int, xce_job_t**);
extern int xce_push_queuelist(endpoint_t*, cluster_t*, int, xce_queue_t**);
extern int xcesched_push_job(cluster_t*, uint64_t);
extern int on_worker_join(void*, endpoint_t*);
extern int get_resval(cluster_t*, char*, char*, xce_val_t*);
extern job_t* jobmgr_lockjob(jobmgr_t*, uint64_t, int);
extern int32_t jobmgr_add_job(jobmgr_t*, job_t*);
extern void jobmgr_del_job(jobmgr_t*, job_t*);
extern int xce_push_reslist(endpoint_t*, cluster_t*, int, xce_resource_t**);
extern int xce_push_confvars(endpoint_t*, cluster_t*, int, xce_config_t**);
extern int xce_push_workerlist(endpoint_t*, cluster_t*, int, xce_worker_t**);
extern int xce_push_joblist(endpoint_t*, cluster_t*, int, xce_job_t**);
extern int xce_push_queuelist(endpoint_t*, cluster_t*, int, xce_queue_t**);
extern int xcesched_push_job(cluster_t*, uint64_t);
extern int on_worker_join(void*, endpoint_t*);
extern int get_resval(cluster_t*, char*, char*, xce_val_t*);
extern int handle_push(struct capn*, cluster_t*, endpoint_t*, struct Request*);
extern int do_get_op(cluster_t*, endpoint_t*, xce_request_t*);
extern int do_update_op(cluster_t*, endpoint_t*, xce_request_t*);
@ -78,19 +73,15 @@ extern int mark_worker_back(cluster_t*, worker_t*);
extern int handle_scheduler_leave(cluster_t*);
extern int handle_clusterconf(cluster_t*, endpoint_t*, xce_request_t*);
extern void collect_confvars(cluster_t*, collect_check_fn_t, int*,
xce_config_t***);
extern void collect_queues(cluster_t*, collect_check_fn_t, int*,
xce_queue_t***);
extern void collect_resources(cluster_t*, collect_check_fn_t, int*,
xce_resource_t***);
extern void collect_jobs(cluster_t*, collect_check_fn_t, int*, xce_job_t***);
extern void collect_workers(cluster_t*, collect_check_fn_t, int*,
xce_worker_t***);
extern void deref_objs(int, void**);
extern void collect_confvars(cluster_t*, collect_check_fn_t, xlist_t*);
extern void collect_queues(cluster_t*, collect_check_fn_t, xlist_t*);
extern void collect_resources(cluster_t*, collect_check_fn_t, xlist_t*);
extern void collect_jobs(cluster_t*, collect_check_fn_t, xlist_t*);
extern void collect_workers(cluster_t*, collect_check_fn_t, xlist_t*);
extern int get_queue_exec(cluster_t*, char*, char**, char**);
extern int jobmgr_iter(jobmgr_t*, xlist_t*, void*);
extern int workermgr_iter(workermgr_t*, xlist_t*, void*);
extern void unlock_collect_queues(xlist_t*);
extern void unlock_collect_jobs(xlist_t*);
extern void unlock_collect_workers(xlist_t*);
extern int on_job_start(cluster_t*, job_pidinfo_t*);
extern int on_job_finish(cluster_t*, xce_jobfinish_t*);
@ -125,7 +116,7 @@ extern int on_task_finish(cluster_t*, xce_task_finish_t*);
extern int xce_controller_res_init(cluster_t*);
extern int map_resource_to_host(char*, cluster_t*);
extern int release_resource_from_worker(char*, cluster_t*);
extern int collect_resval_with_idx(zarray_t*, int*, xce_val_with_idx_t***);
extern int collect_resval_with_idx(zarray_t*, xlist_t*);
extern int do_set_preason(cluster_t*, endpoint_t*, xce_request_t*);
extern int do_clr_preason(cluster_t*, endpoint_t*, xce_request_t*);
extern int handle_apiserver_leave(cluster_t*, endpoint_t*);

View file

@ -170,7 +170,6 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
nc = alloc->nhosts;
if (nc <= 0) {
obj_deref(j);
return -EINVAL;
}
@ -188,7 +187,6 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
if (w == NULL) {
free_launchinfo(&launchinfo);
obj_deref(j);
return -errno;
}
@ -197,9 +195,6 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
w->host.name, w->host.status, w->ep);
free_launchinfo(&launchinfo);
obj_deref(w);
obj_deref(j);
SET_ERROR(E_XCE_BAD_WORKER);
return -errno;
}
@ -211,17 +206,13 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
rc = get_queue_exec(c, j->job.submit->queue, &q_pre_exec, &q_post_exec);
if (rc < 0) {
obj_deref(j);
obj_deref(w);
return rc;
}
if (j->job.submit->start_info->q_pre_exec != NULL) {
obj_deref(j->job.submit->start_info->q_pre_exec);
}
if (j->job.submit->start_info->q_post_exec != NULL) {
obj_deref(j->job.submit->start_info->q_post_exec);
}
j->job.submit->start_info->q_pre_exec = q_pre_exec;
@ -245,8 +236,6 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
MOVE_PTR(j->job.allocs->allocs, allocs);
alloc->allocs = NULL;
DEREF_OBJ(w);
DEREF_OBJ(j);
if (rc < 0) {
SET_ERROR(-rc);
@ -299,7 +288,6 @@ int job_ctrl(cluster_t* c, xce_jobctrl_t* ctrinfo)
w->host.name, w->host.status, w->ep);
rc = -errno;
}
obj_deref(w);
} else {
rc = -errno;
}
@ -365,7 +353,6 @@ int job_ctrl(cluster_t* c, xce_jobctrl_t* ctrinfo)
}
}
obj_deref(j);
return rc;
}
@ -424,8 +411,6 @@ int handle_jobdispatch(cluster_t* c, endpoint_t* ep, xce_request_t* request)
static int xlist_deref_job_item_(job_t* j, void* arg)
{
obj_deref(j);
return 0;
}
@ -481,7 +466,6 @@ int handle_jobsubmit(cluster_t* c, endpoint_t* ep, xce_request_t* request)
} else {
if (xlist_store(&jlist, j) < 0) {
PERROR("xlist_store");
obj_deref(j);
}
}
}
@ -748,7 +732,6 @@ int on_job_ckpt(cluster_t* c, endpoint_t* ep, xce_ckptinfo_t* ckptinfo)
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
HOOK_DETAIL_JOB_CKPT, c, j);
if (j->job.ckptinfo != NULL) {
obj_deref(j->job.ckptinfo);
}
j->job.ckptinfo = makeString(info);
@ -756,8 +739,6 @@ int on_job_ckpt(cluster_t* c, endpoint_t* ep, xce_ckptinfo_t* ckptinfo)
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
HOOK_DETAIL_JOB_CKPT, c, j);
obj_deref(j);
return 0;
}
@ -796,13 +777,10 @@ int update_job_rusages(cluster_t* c, endpoint_t* ep, xce_request_t* request)
w = get_ep_worker(c, ep);
if (w == NULL) {
obj_deref(j);
return errno;
}
host = makeString(w->host.name);
obj_deref(w);
if (host == NULL) {
return -ENOMEM;
}
@ -825,7 +803,6 @@ int update_job_rusages(cluster_t* c, endpoint_t* ep, xce_request_t* request)
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
HOOK_DETAIL_JOB_UPDATE, c, j);
obj_deref(j);
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
HOOK_DETAIL_JOB_RUSAGE_UPDATE, c, rusages);
@ -923,7 +900,6 @@ int do_clr_preason(cluster_t* c, endpoint_t* ep, xce_request_t* request)
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
HOOK_DETAIL_CLRPREASON, c, j);
obj_deref(j);
}
return 0;

View file

@ -2,7 +2,6 @@
#include <stdlib.h>
#include "cluster.h"
#include "objmgr.h"
#include "worker.h"
#include "xce/types.h"
#include "xlist.h"

View file

@ -4,10 +4,9 @@
#include <string.h>
#include <tlog.h>
#include "configobj.h"
#include "controller.capnp.h"
#include "myconf.h"
#include "configobj.h"
#include "objmgr.h"
#include "utils.h"
#include "xce/cluster_def.h"
#include "xce/types.h"
@ -18,7 +17,7 @@ int add_config(void* c, char* name, char* value)
xce_config_t cvar = { .name = name, .value = value };
xce_config_t* cv = NULL;
cv = makeConfig(&cvar);
cv = makeConfig(cls->configmgr, &cvar);
if (cv == NULL) {
return -errno;
}

View file

@ -17,9 +17,14 @@ static int do_reply_reslist(cluster_t* c, endpoint_t* ep,
xce_data_t getdata = { .table = request->body.getmsg->table,
.data = { .resources = &resdata } };
int rc = 0;
xlist_t rlist;
init_reply_by_req(&reply, request);
collect_resources(c, NULL, &(resdata.n_total), &(resdata.resources));
xlist_init(&rlist, 512);
collect_resources(c, NULL, &rlist);
resdata.n_total = rlist.count;
resdata.resources = (xce_resource_t**)rlist.data;
reply.status = 0;
reply.data_which = RequestReply_data_getdata;
@ -27,8 +32,7 @@ static int do_reply_reslist(cluster_t* c, endpoint_t* ep,
rc = xce_reply_get(ep, c->myhost, &reply, NULL, NULL, -1);
deref_objs(resdata.n_total, (void**)resdata.resources);
FREEUP(resdata.resources);
xlist_fini(&rlist);
return rc;
}
@ -101,12 +105,16 @@ static int do_reply_workerlist(cluster_t* c, endpoint_t* ep,
.workers = &workerdata }
};
/* clang-format on */
int rc = 0;
int i;
int rc = 0;
int i;
xlist_t wlist;
init_reply_by_req(&reply, request);
collect_workers(c, (collect_check_fn_t)check_worker_, &(workerdata.n_total),
&(workerdata.workers));
xlist_init(&wlist, 1024);
collect_workers(c, (collect_check_fn_t)check_worker_, &wlist);
workerdata.n_total = wlist.count;
workerdata.workers = (xce_worker_t**)wlist.data;
reply.status = 0;
reply.data_which = RequestReply_data_getdata;
@ -120,21 +128,13 @@ static int do_reply_workerlist(cluster_t* c, endpoint_t* ep,
free_resval_with_idx_list(&(w->resvals_to_sched), w->nresvals_to_sched);
}
deref_objs(workerdata.n_total, (void**)workerdata.workers);
FREEUP(workerdata.workers);
unlock_collect_workers(&wlist);
xlist_fini(&wlist);
return rc;
}
static int check_job_(xce_job_t* j)
{
if (j == NULL) {
return 0;
}
return 1;
}
static int do_reply_joblist(cluster_t* c, endpoint_t* ep,
xce_request_t* request)
{
@ -144,9 +144,12 @@ static int do_reply_joblist(cluster_t* c, endpoint_t* ep,
.data = { .jobs = &jobdata } };
int rc = 0;
xce_match_t* match = request->body.getmsg->condition;
xlist_t jlist;
init_reply_by_req(&reply, request);
xlist_init(&jlist, 1024*1024);
if (match->type == MatchCondition_condition_matchjid) {
job_t* j = NULL;
@ -155,24 +158,25 @@ static int do_reply_joblist(cluster_t* c, endpoint_t* ep,
rc = key_find(c->jobmgr, (void*)match->condition.jobid, (void**)&j);
if (rc > 0) {
jobdata.jobs = (xce_job_t**)calloc(1, sizeof(xce_job_t*));
if (jobdata.jobs != NULL) {
jobdata.jobs[0] = &(j->job);
jobdata.n_total = 1;
}
lock(j, RTTI_LOCK_WRITE);
xlist_store(&jlist, &(j->job));
}
} else {
collect_jobs(c, (collect_check_fn_t)check_job_, &(jobdata.n_total),
&(jobdata.jobs));
collect_jobs(c, NULL, &jlist);
}
jobdata.n_total = jlist.count;
jobdata.jobs = (xce_job_t**)jlist.data;
reply.status = 0;
reply.data_which = RequestReply_data_getdata;
reply.data.getdata = &getdata;
rc = xce_reply_get(ep, c->myhost, &reply, check_controller, c, 100);
deref_objs(jobdata.n_total, (void**)jobdata.jobs);
unlock_collect_jobs(&jlist);
FREEUP(jobdata.jobs);
return rc;

View file

@ -39,7 +39,6 @@ static int do_update_resvals(cluster_t* c, endpoint_t* ep,
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_RESOURCE,
HOOK_AFTER_EVENT, HOOK_DETAIL_RESOURCE_UPDATE, c,
resvals);
DEREF_OBJ(w);
}
}
}

View file

@ -99,7 +99,6 @@ int queue_ctrl(cluster_t* c, xce_queuectrl_t* ctrl)
HOOK_AFTER_EVENT, HOOK_DETAIL_QUEUE_UPDATE, c, q);
}
clean:
obj_deref(q);
return rc;
}
@ -154,7 +153,5 @@ int get_queue_exec(cluster_t* c, char* queue, char** pre_exec, char** post_exec)
*post_exec = NULL;
}
obj_deref(q);
return 0;
}

View file

@ -28,7 +28,8 @@ int handle_clusterconf(cluster_t* c, endpoint_t* ep, xce_request_t* request)
}
};
/* clang-format on */
int i;
int i;
xlist_t clist, qlist, rlist, wlist;
init_reply_by_req(&reply, request);
@ -36,14 +37,26 @@ int handle_clusterconf(cluster_t* c, endpoint_t* ep, xce_request_t* request)
reply.data_which = RequestReply_data_clusterconf;
reply.data.clusterconf = &clusterconf;
collect_confvars(c, NULL, &(clusterconf.cfglist.count),
&(clusterconf.cfglist.configs));
collect_queues(c, NULL, &(clusterconf.qlist.count),
&(clusterconf.qlist.queues));
collect_resources(c, NULL, &(clusterconf.reslist.count),
&(clusterconf.reslist.res));
collect_workers(c, (collect_check_fn_t)check_worker_,
&(clusterconf.wlist.count), &(clusterconf.wlist.workers));
xlist_init(&clist, 256);
xlist_init(&qlist, 64);
xlist_init(&rlist, 1024);
xlist_init(&wlist, 10240);
collect_confvars(c, NULL, &clist);
clusterconf.cfglist.count = clist.count;
clusterconf.cfglist.configs = (xce_config_t**)clist.data;
collect_queues(c, NULL, &qlist);
clusterconf.qlist.count = qlist.count;
clusterconf.qlist.queues = (xce_queue_t**)qlist.data;
collect_resources(c, NULL, &rlist);
clusterconf.reslist.count = rlist.count;
clusterconf.reslist.res = (xce_resource_t**)rlist.data;
collect_workers(c, (collect_check_fn_t)check_worker_, &wlist);
clusterconf.wlist.count = wlist.count;
clusterconf.wlist.workers = (xce_worker_t**)wlist.data;
xce_reply(ep, c->myhost, &reply);
@ -53,15 +66,13 @@ int handle_clusterconf(cluster_t* c, endpoint_t* ep, xce_request_t* request)
free_resval_with_idx_list(&(w->resvals_to_sched), w->nresvals_to_sched);
}
deref_objs(clusterconf.cfglist.count, (void**)clusterconf.cfglist.configs);
deref_objs(clusterconf.qlist.count, (void**)clusterconf.qlist.queues);
deref_objs(clusterconf.reslist.count, (void**)clusterconf.reslist.res);
deref_objs(clusterconf.wlist.count, (void**)clusterconf.wlist.workers);
unlock_collect_queues(&qlist);
unlock_collect_workers(&wlist);
FREEUP(clusterconf.cfglist.configs);
FREEUP(clusterconf.qlist.queues);
FREEUP(clusterconf.reslist.res);
FREEUP(clusterconf.wlist.workers);
xlist_fini(&clist);
xlist_fini(&qlist);
xlist_fini(&rlist);
xlist_fini(&wlist);
return rc;
}

View file

@ -3,15 +3,13 @@
#include "cluster.h"
#include "controller.capnp.h"
#include "objmgr.h"
#include "request.h"
#include "worker.h"
#include "xce/cluster_def.h"
#include "xce/types.h"
#include "xcelimit.h"
extern void collect_shared_resvals(cluster_t*, collect_check_fn_t, int*,
xce_val_with_idx_t***);
extern void collect_shared_resvals(cluster_t*, collect_check_fn_t, xlist_t*);
static int xcesched_push_joblist(cluster_t* c, xlist_t* l)
{
@ -91,6 +89,10 @@ static int xcesched_push_configs(cluster_t* c)
};
xce_limit_config_t* limits[] = { &limit1_config, &limit2_config };
int nlimits = 2;
xlist_t clist;
xlist_t qlist;
xlist_t rlist;
xlist_t xreslist;
memset(&configdata, 0x0, sizeof(configdata));
@ -100,14 +102,22 @@ static int xcesched_push_configs(cluster_t* c)
return -ENOMEM;
}
collect_confvars(c, NULL, &(configdata.data.conf4sched->n_confvars),
&(configdata.data.conf4sched->confvars));
collect_queues(c, NULL, &(configdata.data.conf4sched->n_queues),
&(configdata.data.conf4sched->queues));
collect_resources(c, NULL, &(configdata.data.conf4sched->n_resources),
&(configdata.data.conf4sched->resources));
collect_shared_resvals(c, NULL, &(configdata.data.conf4sched->nresvals),
&(configdata.data.conf4sched->resvals));
xlist_init(&clist, 64);
xlist_init(&qlist, 64);
xlist_init(&rlist, 256);
xlist_init(&xreslist, 256);
collect_confvars(c, NULL, &clist);
configdata.data.conf4sched->n_confvars = clist.count;
configdata.data.conf4sched->confvars = (xce_config_t**)clist.data;
collect_queues(c, NULL, &qlist);
configdata.data.conf4sched->n_queues = qlist.count;
configdata.data.conf4sched->queues = (xce_queue_t**)qlist.data;
collect_resources(c, NULL, &rlist);
configdata.data.conf4sched->n_resources = rlist.count;
configdata.data.conf4sched->resources = (xce_resource_t**)rlist.data;
collect_shared_resvals(c, NULL, &xreslist);
configdata.data.conf4sched->nresvals = xreslist.count;
configdata.data.conf4sched->resvals = (xce_val_with_idx_t**)xreslist.data;
configdata.data.conf4sched->n_ugroups = c->myconf->cluster_config->nugroups;
configdata.data.conf4sched->ugroups = c->myconf->cluster_config->ugroups;
@ -135,19 +145,15 @@ static int xcesched_push_configs(cluster_t* c)
free_resval_with_idx_list(&(configdata.data.conf4sched->resvals),
configdata.data.conf4sched->nresvals);
deref_objs(configdata.data.conf4sched->n_confvars,
(void**)configdata.data.conf4sched->confvars);
deref_objs(configdata.data.conf4sched->n_queues,
(void**)configdata.data.conf4sched->queues);
deref_objs(configdata.data.conf4sched->n_resources,
(void**)configdata.data.conf4sched->resources);
FREEUP(configdata.data.conf4sched->confvars);
FREEUP(configdata.data.conf4sched->queues);
FREEUP(configdata.data.conf4sched->resources);
FREEUP(configdata.data.conf4sched);
unlock_collect_queues(&qlist);
xlist_fini(&clist);
xlist_fini(&qlist);
xlist_fini(&rlist);
xlist_fini(&xreslist);
return rc;
}
@ -165,19 +171,22 @@ static int xcesched_push_jobs(cluster_t* c)
xce_data_t data;
xce_jobs_data_t jobs = { .n_total = 0, .pos = 0, .count = 0, .jobs = NULL };
int rc = 0;
xlist_t jlist;
memset(&data, 0x0, sizeof(data));
xlist_init(&jlist, 1024 * 1024);
data.table = Data_data_schedjobs;
data.data.jobs = &jobs;
collect_jobs(c, (collect_check_fn_t)check_job_, &(jobs.n_total),
&(jobs.jobs));
jobs.count = jobs.n_total;
collect_jobs(c, (collect_check_fn_t)check_job_, &jlist);
jobs.n_total = jlist.count;
jobs.jobs = (xce_job_t**)jlist.data;
jobs.count = jobs.n_total;
rc = xce_push_data_req(c->sched.ep, c->myhost, &data, check_controller, c,
100);
deref_objs(jobs.n_total, (void**)jobs.jobs);
FREEUP(jobs.jobs);
return rc;
@ -188,17 +197,20 @@ static int xcesched_push_workers(cluster_t* c)
xce_data_t data;
xce_workers_data_t workers
= { .n_total = 0, .pos = 0, .count = 0, .workers = NULL };
int rc = 0;
int i;
int rc = 0;
int i;
xlist_t wlist;
memset(&data, 0x0, sizeof(data));
xlist_init(&wlist, 8192);
data.table = Data_data_schedworkers;
data.data.workers = &workers;
collect_workers(c, (collect_check_fn_t)check_worker_, &(workers.n_total),
&(workers.workers));
workers.count = workers.n_total;
collect_workers(c, (collect_check_fn_t)check_worker_, &wlist);
workers.n_total = wlist.count;
workers.workers = (xce_worker_t**)wlist.data;
workers.count = workers.n_total;
rc = xce_push_data_req(c->sched.ep, c->myhost, &data, check_controller, c,
100);
@ -212,7 +224,6 @@ static int xcesched_push_workers(cluster_t* c)
free_resval_with_idx_list(&(w->resvals_to_sched), w->nresvals_to_sched);
}
deref_objs(workers.n_total, (void**)workers.workers);
FREEUP(workers.workers);
return rc;
@ -418,12 +429,15 @@ static int sched_worker_change(int type, int situation, void* data,
{
int rc = 0;
xlist_t wlist;
xlist_t resvalist;
TRACE("%s worker %s idx %d situation %d", __func__, w->host.name, w->idx,
situation);
collect_resval_with_idx(&(w->host.resvals), &(w->host.nresvals_to_sched),
&(w->host.resvals_to_sched));
xlist_init(&resvalist, 256);
collect_resval_with_idx(&(w->host.resvals), &resvalist);
w->host.nresvals_to_sched = resvalist.count;
w->host.resvals_to_sched = (xce_val_with_idx_t**)resvalist.data;
mylock_lock(&(c->sched.lock));
if (c->sched.ep != NULL) {
@ -440,8 +454,12 @@ static int sched_worker_change(int type, int situation, void* data,
}
mylock_unlock(&(c->sched.lock));
#if 0
/*FIXME*/
free_resval_with_idx_list(&(w->host.resvals_to_sched),
w->host.nresvals_to_sched);
#endif
xlist_fini(&resvalist);
return rc;
}
@ -469,9 +487,6 @@ static int sched_worker_join(int type, int situation, void* data, va_list ap)
rc = sched_worker_change(type, situation, data, c, w);
/* FIXME: need to mark the jobs in this worker */
obj_deref(w);
return rc;
}

View file

@ -27,14 +27,11 @@ static int run_tasks_on_host(cluster_t* c, endpoint_t* ep, uint64_t jobid,
}
if ((w->ep == NULL) || (IS_WORKER_UNAVAIL(w->host.status))) {
obj_deref(w);
return -EINVAL;
}
rc = xce_runtask_req(w->ep, &runmsg);
obj_deref(w);
return rc;
}

View file

@ -350,8 +350,6 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
mark_host_res(c, w, hconfig->resources[i]);
}
DEREF_OBJ(w); /* release update lock */
return idx;
}
@ -373,8 +371,6 @@ int restore_worker(void* cls, xce_worker_t host)
idx = w->idx;
w->host.status |= XCE_WORKER_UNAVAIL;
DEREF_OBJ(w);
return idx;
}
@ -396,30 +392,32 @@ static int worker_push_config(cluster_t* c, endpoint_t* ep)
{
xce_configdata_t configdata;
int rc = 0;
xlist_t clist;
memset(&configdata, 0x0, sizeof(configdata));
configdata.data.conf4worker
= (xce_conf4worker_t*)calloc(1, sizeof(xce_conf4worker_t));
configdata.data.conf4worker = calloc(1, sizeof(xce_conf4worker_t));
if (configdata.data.conf4worker == NULL) {
return -ENOMEM;
}
collect_confvars(c, (collect_check_fn_t)check_conf4worker_,
&(configdata.data.conf4worker->n_confvars),
&(configdata.data.conf4worker->confvars));
configdata.data_which = ConfigData_data_workerconfig;
xlist_init(&clist, 256);
collect_confvars(c, (collect_check_fn_t)check_conf4worker_, &clist);
configdata.data.conf4worker->n_confvars = clist.count;
configdata.data.conf4worker->confvars = (xce_config_t**)clist.data;
configdata.data_which = ConfigData_data_workerconfig;
configdata.data.conf4worker->clustername
= c->myconf->cluster_config->clustername;
rc = xce_pushconfig_req(ep, c->myhost, &configdata);
deref_objs(configdata.data.conf4worker->n_confvars,
(void**)configdata.data.conf4worker->confvars);
FREEUP(configdata.data.conf4worker->confvars);
FREEUP(configdata.data.conf4worker);
xlist_fini(&clist);
return rc;
}
@ -453,7 +451,6 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
if ((r->flags & XCE_RESF_SHARED) == 0) {
if ((host == NULL) || (strlen(host) == 0)) {
obj_deref(r);
return -EINVAL;
}
@ -537,7 +534,6 @@ int handle_worker_leave(cluster_t* c, int idx)
mark_worker_unavail(c, w);
obj_deref(w);
return 0;
}
@ -584,6 +580,5 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
HOOK_AFTER_EVENT, HOOK_DETAIL_WORKER_UPDATE, c, w);
}
clean:
obj_deref(w);
return rc;
}

108
src/docs/xce.md Normal file
View file

@ -0,0 +1,108 @@
# 1. commit 规则
- 每个人 fork 自己的 branch, 从自己的 branch 做 PR,review 完再 commit
# 2. code format
## 2.1. C
推荐使用 clang-format,公共配置放在源码里面 xce/.clang-format
(理论上直接使用源码里面 xce/.clang-format 文件格式不会变)
### 2.1.1. vscode 可以在配置中加上如下内容
```
"C_Cpp.clang_format_style": "WebKit",
"C_Cpp.clang_format_fallbackStyle": "WebKit",
```
### 2.1.2. vim & emacs
clang-format -style="{BasedOnStyle: webkit}" -i XX.c
## 2.2. golang
使用默认 gofmt
# 3. build environment and build (example of ubuntu)
## 3.1 build environment
- Install nix package management tool
```sh
sh <(curl -L https://nixos.org/nix/install) --daemon
```
- Edit /etc/nix/nix.conf to make sure
```
experimental-features = nix-command flakes
sandbox = true
sandbox-fallback = false
substituters = https://mirrors.ustc.edu.cn/nix-channels/store https://cache.nixos.org https://cache.nixos.org/
trusted-users = root <your account>
```
make sure that you have restarted nix-daemon service after you have changed /etc/nix/nix.conf
- Install socat and config ssh (for clone by ssh protocol)
```sh
nix profile add nixpkgs#socat
```
.ssh/config
```
Host gitea.shenrs.eu
HostName gitea.shenrs.eu
IdentityFile ~/.ssh/id_ed25519
ProxyCommand socat - openssl-connect:gitea.shenrs.eu:2022,snihost=gitea.shenrs.eu,verify=0
```
## 3.2 checkout source code
## 3.3 build (for package and release)
```sh
cd xce/src
# for build debug version
nix build --option sandbox false .#xcecore_debug
# for normal build
nix build --option sandbox false .#xcecore
```
You can find the generated binaries at =result= directory
## 3.4 build (for daily develop)
```sh
cd xce/src
nix develop
# using meson to generated build configuration (debug and address sanitize)
meson setup build --buildtype=debug -Db_sanitize=address
# run meson to build
meson compile -C build
# The generated files will be in build/
```
## 3.5 build AppImage package
```sh
cd xce/src
nix bundle --bundler github:ralismark/nix-appimage --option sandbox false .#xce
```
This will create all in one AppImage file which contains everything for package delivery.
# 4. misc
## 4.1. Windows remap ctrl and alt key
create a reg file, e.g. remapkey.reg
```
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,05,00,00,00,38,00,1d,00,1d,00,38,00,38,e0,1d,e0,1d,e0,38,e0,00,00,00,00
```
then double click remapkey.reg to import it. Restart OS.

View file

@ -27,11 +27,35 @@
xpkgs = import ./nixSupport/default.nix {
inherit pkgs myCommitId;
};
appImageScriptContent = builtins.readFile ./tools/appimage/entry.sh;
appImageEntryPackage = pkgs.writeShellApplication {
name = "xce";
runtimeInputs = with pkgs; [
xpkgs.xcecore
coreutils-full
which
bash
gzip
glow
haproxy
];
text = appImageScriptContent;
derivationArgs = {
postInstall = ''
mkdir -p $out/share
cp docs/* $out/share/
'';
};
meta = {
mainProgram = "xce";
};
};
in rec {
packages = pkgs // xpkgs;
defaultPackage = xpkgs.xce_debug;
packages = pkgs // xpkgs // { xce = appImageEntryPackage; };
defaultPackage = xpkgs.xcecore_debug;
devShells.default = pkgs.mkShell {
nativeBuildInputs = xpkgs.xce.nativeBuildInputs;
nativeBuildInputs = xpkgs.xcecore.nativeBuildInputs;
};
devShell = self.devShells.${system}.default;

View file

@ -6,6 +6,6 @@
#include "xce/types.h"
extern xce_config_t *makeConfig(xce_config_t *);
extern xce_config_t* makeConfig(var, xce_config_t*);
#endif

View file

@ -9,10 +9,6 @@
#include "xlist.h"
#include "zarray.h"
typedef struct {
kvmgr_t groups;
} groupmgr_t;
extern xce_group_t* makeGroup(var, xce_group_config_t*, char*);
extern int groupmgr_init(var*, int, int);
extern void groupmgr_fini(var);

View file

@ -13,63 +13,6 @@ typedef enum {
KVMGR_KEY_STRING
} kvmgr_key_type_t;
typedef struct {
mylock_t lock;
htab_t htab;
zarray_t data;
} kvmgr_t;
typedef struct {
kvmgr_t resdef;
int nshared;
int nunshared;
} resmgr_t;
typedef struct {
kvmgr_t queues;
} qmgr_t;
typedef struct {
kvmgr_t jobs;
} jobmgr_t;
typedef struct {
kvmgr_t workers;
} workermgr_t;
extern int kvmgr_init(kvmgr_t*, hash_key_fn_t, int, int, zarray_item_killer_t);
extern void kvmgr_fini(kvmgr_t*);
extern void* kvmgr_lock(kvmgr_t*, void*, int);
extern void* kvmgr_lock_byid(kvmgr_t*, int, int);
extern int32_t kvmgr_add(kvmgr_t*, void*, void*);
extern int32_t kvmgr_put(kvmgr_t*, void*, int, void*);
extern void kvmgr_del(kvmgr_t*, void*);
extern int kvmgr_iter(kvmgr_t*, zarray_iter_skip_fn_t, xlist_t*, void*);
extern int resmgr_init(resmgr_t*, int, int, zarray_item_killer_t);
extern void resmgr_fini(resmgr_t*);
extern int32_t resmgr_add_res(resmgr_t*, xce_resource_t*);
extern xce_resource_t* resmgr_lockres(resmgr_t*, char*, int);
extern xce_resource_t* resmgr_lock_byid(resmgr_t*, int, int);
extern void resmgr_del_res(resmgr_t*, xce_resource_t*);
extern int resmgr_iter(resmgr_t*, xlist_t*, void*);
extern void qmgr_fini(qmgr_t*);
extern int qmgr_init(qmgr_t*, int, int, zarray_item_killer_t);
extern int qmgr_add(qmgr_t*, queue_t*);
extern queue_t* qmgr_lockq(qmgr_t*, char*, int);
extern void qmgr_delq(qmgr_t*, queue_t*);
extern int qmgr_iter(qmgr_t*, xlist_t*, void*);
extern int jobmgr_init(jobmgr_t*, int, int, zarray_item_killer_t);
extern void jobmgr_fini(jobmgr_t*);
extern int workermgr_init(workermgr_t*, int, int, zarray_item_killer_t);
extern void workermgr_fini(workermgr_t*);
extern int workermgr_add(workermgr_t*, worker_t*);
extern worker_t* workermgr_lock(workermgr_t*, char*, int);
extern worker_t* workermgr_lock_byid(workermgr_t*, int, int);
extern void workermgr_del(workermgr_t*, worker_t*);
typedef struct {
kvmgr_key_type_t key_type;
unsigned int dynamic : 1;

View file

@ -1,76 +0,0 @@
#if !defined(__OBJMGR_H__)
#define __OBJMGR_H__
#include "config.h"
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include "htab.h"
#include "mylock.h"
#include "zarray.h"
#define OBJ_MAGIC (0x4a424f58)
#define OBJREF_NOP \
(0) /* ref obj without lock, \
* just keep object alive */
#define OBJREF_READ (1) /* ref obj with read lock */
#define OBJREF_UPDATE (2) /* ref obj with write lock */
typedef void* (*obj_create_fn_t)(void*, void*, va_list);
typedef void (*obj_fini_fn_t)(void*);
typedef void (*objtype_fini_fn_t)(void*);
typedef struct {
char* type; /* name of type */
mylock_t lock;
obj_create_fn_t fn_create; /* function to initialize object */
obj_fini_fn_t fn_fini; /* function to finalize obj */
objtype_fini_fn_t fn_type_fini; /* function to finalize typeinfo */
void* typedata; /* extra information for type */
} objtype_t;
typedef struct {
uint32_t magic;
uint32_t nref;
my_rwlock_t rwlock;
mylock_t lock;
objtype_t* type;
int32_t exdata;
uint32_t nread : 28;
uint32_t nwrite : 4;
} myobj_t;
typedef struct {
mylock_t lock;
htab_t names;
zarray_t types;
} objmgr_t;
#define MYOBJ_TO_OBJ(type, myobj) ((type)(((char*)myobj) + sizeof(myobj_t)))
#define TO_MYOBJ(obj) ((myobj_t*)(((char*)obj) - sizeof(myobj_t)))
#define DEREF_OBJ(obj) \
if ((obj) != NULL) { \
obj_deref(obj); \
(obj) = NULL; \
}
extern int objmgr_init(objmgr_t*);
extern void objmgr_fini(objmgr_t*);
extern int objmgr_register(objmgr_t*, objtype_t*);
extern int obj_init(objmgr_t*, objtype_t*, int32_t, myobj_t*);
extern void* create_obj_by_typeid(objmgr_t*, int, ...);
extern void* create_obj_by_typename(objmgr_t*, char*, ...);
extern void* obj_ref(void*, int);
extern void obj_deref(void*);
extern int typeid_of_name(objmgr_t*, char*);
extern objmgr_t* objmgr_get_default();
extern int objmgr_set_default(objmgr_t*);
extern myobj_t* obj_alloc(size_t);
#endif

View file

@ -6,6 +6,6 @@
#include "xce/types.h"
extern xce_resource_t* makeResource(xce_resource_t*);
extern xce_resource_t* makeResource(var, xce_resource_t*);
#endif

View file

@ -14,6 +14,8 @@
#include "xce/errnox.h"
#include "xce/types.h"
#define CONTAINER_OF(P, T, F) ((T*)(((char*)(P)) - offsetof(T, F)))
#define MAKE_JOBID(cluster, apiserver, timestamp, tag, sequence) \
((((uint64_t)cluster) << CLUSTER_ID_SHIFT) \
| (((uint64_t)apiserver) << APISERVER_ID_SHIFT) \

View file

@ -14,7 +14,6 @@
#include "myconf.h"
#include "mylock.h"
#include "netio.h"
#include "objmgr.h"
#include "vtaskmgr.h"
#include "xce/types.h"
#include "xlist.h"
@ -94,7 +93,6 @@ typedef struct {
xce_peerinfo_t* myhost;
hooksys_t hooksys;
iomgr_t iomgr;
objmgr_t objmgr;
zarray_t endpoints;
endpoint_t ep;
zarray_t configs;
@ -111,8 +109,6 @@ typedef struct {
var workermgr;
var qmgr;
var configmgr;
kvmgr_t ugmgr;
kvmgr_t hgmgr;
vtaskmgr_t vtaskmgr;
cbuf_t wbuf;
int running;

View file

@ -11,11 +11,10 @@
#include "kvmgr.h"
#include "xce/types.h"
extern int build_consumer(xce_consumer_t**, groupmgr_t*, xce_consumer_type_t,
int, xce_group_config_t*, char*);
extern int build_consumer(xce_consumer_t**, var, xce_consumer_type_t, int,
xce_group_config_t*, char*);
extern void kill_consumer(xce_consumer_t*);
extern int build_limit(xce_limit_t**, groupmgr_t*, groupmgr_t*, groupmgr_t*,
groupmgr_t*, xce_limit_config_t*);
extern int build_limit(xce_limit_t**, var, var, var, var, xce_limit_config_t*);
extern int match_limit(xce_limit_t*, int, ...);
extern int build_vres_name(char**, xce_limit_t*, char*, char*, char*);
extern int is_host_based_limit(var, xce_limit_t*);

View file

@ -4,25 +4,6 @@
#include <rtti.h>
#include "objmgr.h"
typedef struct {
htab_t tab;
zarray_t strings;
} xstring_typedata_t;
#define XSTRING_OBJ_TYPE_HTAB(obj) \
(((xstring_typedata_t*)obj->type->typedata)->tab)
#define XSTRING_OBJ_TYPE_STRINGS(obj) \
(((xstring_typedata_t*)obj->type->typedata)->strings)
#define XSTRING_TYPE_HTAB(type) (((xstring_typedata_t*)type->typedata)->tab)
#define XSTRING_TYPE_STRINGS(type) \
(((xstring_typedata_t*)type->typedata)->strings)
extern int register_xstring(objmgr_t*, int, int);
extern int xstring_table_init(int);
extern void xstring_table_fini();
extern char* makeString(char*);

View file

@ -48,9 +48,32 @@ static typeinfo_t xconfig_type = {
.destroy = (obj_destroy_fn_t)xconfig_destroy,
};
xce_config_t* makeConfig(xce_config_t* c)
xce_config_t* makeConfig(var configmgr, xce_config_t* c)
{
xce_config_t* c1 = makeInstance(&xconfig_type, c);
xce_config_t* c1 = NULL;
int rc = 0;
rc = key_find(configmgr, (void*)c->name, (void**)&c1);
if ((rc < 0) && (rc != -ENOENT)) {
errno = -rc;
return NULL;
}
if (rc > 0) {
errno = EEXIST;
return NULL;
}
c1 = makeInstance(&xconfig_type, c);
if (c1 != NULL) {
rc = key_add(configmgr, (void*)c1->name, (void*)c1);
if (rc < 0) {
destroy(c1);
errno = -rc;
return NULL;
}
}
return c1;
}

View file

@ -5,7 +5,6 @@
#include "group.h"
#include "kvmgr.h"
#include "objmgr.h"
#include "utils.h"
#include "xce/types.h"
#include "xstring.h"

View file

@ -676,8 +676,30 @@ static typeinfo_t job_type = {
job_t* makeJob(var jobmgr, xce_job_t* j)
{
job_t* job = makeInstance(&job_type, j);
/* FIXME */
job_t* job = NULL;
int rc = 0;
rc = key_find(jobmgr, (void *)j->jobid, (void **)&job);
if ((rc < 0) && (rc != -ENOENT)) {
errno = -rc;
return NULL;
}
if (rc > 0) {
errno = EEXIST;
return NULL;
}
job = makeInstance(&job_type, j);
if (job != NULL) {
rc = key_add(jobmgr, (void *)job->job.jobid, (void **)job);
if (rc < 0) {
destroy(job);
errno = -rc;
return NULL;
}
}
return job;
}

View file

@ -7,237 +7,12 @@
#include "kv.h"
#include "kvmgr.h"
#include "mylock.h"
#include "objmgr.h"
#include "utils.h"
#include "xce/types.h"
#include "zarray.h"
#include "controller.capnp.h"
int kvmgr_init(kvmgr_t* mgr, hash_key_fn_t keyfn, int nslots, int delta,
zarray_item_killer_t killer)
{
ht_init(&(mgr->htab), nslots, keyfn);
zarray_init(&(mgr->data), delta, killer);
mylock_init(&(mgr->lock));
return 0;
}
void kvmgr_fini(kvmgr_t* mgr)
{
ht_fini(&(mgr->htab));
zarray_fini(&(mgr->data));
mylock_fini(&(mgr->lock));
}
static void* kvmgr_lock_(kvmgr_t* mgr, void* key, int op)
{
hent_t* e = NULL;
int32_t idx;
void* ptr;
e = ht_get(&(mgr->htab), key);
if (e == NULL) {
SET_ERROR(ENOENT);
return NULL;
}
idx = e->data;
if (idx < 0) {
SET_ERROR(ENOENT);
return NULL;
}
ptr = (void*)zarray_get(&(mgr->data), idx);
if (ptr == NULL) {
return NULL;
}
if (op == OBJREF_NOP) {
return ptr;
}
return obj_ref(ptr, op);
}
void* kvmgr_lock(kvmgr_t* mgr, void* key, int op)
{
void* ptr = NULL;
if (mgr == NULL) {
SET_ERROR(EINVAL);
return NULL;
}
if ((op != OBJREF_NOP) && (op != OBJREF_READ) && (op != OBJREF_UPDATE)) {
SET_ERROR(EINVAL);
return NULL;
}
mylock_lock(&(mgr->lock));
ptr = kvmgr_lock_(mgr, key, op);
mylock_unlock(&(mgr->lock));
return ptr;
}
void* kvmgr_lock_byid(kvmgr_t* mgr, int idx, int op)
{
void* ptr = NULL;
if (mgr == NULL) {
SET_ERROR(-EINVAL);
return NULL;
}
if ((idx < 0) || (idx >= mgr->data.caps)) {
SET_ERROR(-EINVAL);
return NULL;
}
if ((op != OBJREF_NOP) && (op != OBJREF_READ) && (op != OBJREF_UPDATE)) {
SET_ERROR(-EINVAL);
return NULL;
}
mylock_lock(&(mgr->lock));
ptr = (void*)zarray_get(&(mgr->data), idx);
mylock_unlock(&(mgr->lock));
if (ptr == NULL) {
return NULL;
}
if (op == OBJREF_NOP) {
return ptr;
}
return obj_ref(ptr, op);
}
static int32_t kvmgr_add_(kvmgr_t* mgr, void* key, void* p)
{
hent_t* e = NULL;
int idx;
e = ht_get(&(mgr->htab), key);
if (e != NULL) {
return -EEXIST;
}
idx = zarray_store(&(mgr->data), p);
if (idx < 0) {
return idx;
}
e = ht_add(&(mgr->htab), (void*)key);
if (e == NULL) {
zarray_del(&(mgr->data), idx);
return -errno;
}
e->data = idx;
return idx;
}
int32_t kvmgr_add(kvmgr_t* mgr, void* key, void* p)
{
int32_t idx;
if ((mgr == NULL) || (p == NULL)) {
return -EINVAL;
}
mylock_lock(&(mgr->lock));
idx = kvmgr_add_(mgr, key, p);
mylock_unlock(&(mgr->lock));
return idx;
}
static int32_t kvmgr_put_(kvmgr_t* mgr, void* key, int idx, void* p)
{
hent_t* e = NULL;
int idx1 = -1;
e = ht_get(&(mgr->htab), key);
if (e != NULL) {
idx1 = e->data;
if (idx1 >= 0) {
zarray_del(&(mgr->data), idx1);
}
} else {
e = ht_add(&(mgr->htab), (void*)key);
if (e == NULL) {
return -ENOMEM;
}
}
if (idx1 != idx) {
zarray_del(&(mgr->data), idx);
}
e->data = idx;
return zarray_put(&(mgr->data), idx, p);
}
int32_t kvmgr_put(kvmgr_t* mgr, void* key, int idx, void* p)
{
int rc;
if ((mgr == NULL) || (key == NULL) || (p == NULL) || (idx < 0)) {
return -EINVAL;
}
mylock_lock(&(mgr->lock));
rc = kvmgr_put_(mgr, key, idx, p);
mylock_unlock(&(mgr->lock));
return rc;
}
static void kvmgr_del_(kvmgr_t* mgr, void* key)
{
hent_t* e = NULL;
int idx;
e = ht_get(&(mgr->htab), key);
if (e == NULL) {
return;
}
idx = e->data;
if (idx < 0) {
return;
}
zarray_del(&(mgr->data), idx);
return;
}
void kvmgr_del(kvmgr_t* mgr, void* key)
{
if (mgr == NULL) {
return;
}
mylock_lock(&(mgr->lock));
kvmgr_del_(mgr, key);
mylock_unlock(&(mgr->lock));
}
int kvmgr_iter(kvmgr_t* mgr, zarray_iter_skip_fn_t skipfn, xlist_t* l,
void* arg)
{
int rc = 0;
mylock_lock(&(mgr->lock));
rc = zarray_iter_ex(&(mgr->data), skipfn, l, arg);
mylock_unlock(&(mgr->lock));
return rc;
}
typedef struct {
my_rwlock_t lock;
} xkvmgr_private_t;
@ -433,6 +208,13 @@ static int xkvmgr_iter_next(iterator_t* iter, void** data)
return iter_next(it, data);
}
static int xkvmgr_iter_reset(iterator_t* iter)
{
iterator_t* it = (iterator_t*)iter->data;
return iter_reset(it);
}
static void xkvmgr_iter_destroy(iterator_t* iter)
{
iterator_t* it = iter->data;
@ -546,7 +328,7 @@ typeinfo_t xkvmgr_type = {
.iter
= &(intf_iterator_t) { .make = (iter_make_fn_t)xkvmgr_make_iter,
.next = (iter_next_fn_t)xkvmgr_iter_next,
.reset = (iter_reset_fn_t)NULL,
.reset = (iter_reset_fn_t)xkvmgr_iter_reset,
.destroy
= (iter_destroy_fn_t)xkvmgr_iter_destroy } }
};

View file

@ -59,7 +59,6 @@ libxce_src = [ gen_srcs[0],
'kvmgr.c',
'mylock.c',
'netio.c',
'objmgr.c',
'request.c',
'threshold.c',
'utils.c',

View file

@ -1,306 +0,0 @@
#include <errno.h>
#include <stdlib.h>
#include "htab.h"
#include "objmgr.h"
#include "utils.h"
#include "zarray.h"
static objmgr_t* objmgr_default = NULL;
static void objtype_killer(objtype_t* typeval)
{
if (typeval == NULL) {
return;
}
if (typeval->fn_type_fini == NULL) {
return;
}
typeval->fn_type_fini(typeval);
}
int objmgr_init(objmgr_t* mgr)
{
if (mgr == NULL) {
return -EINVAL;
}
mylock_init(&(mgr->lock));
ht_init(&(mgr->names), 32, string_hash_key);
zarray_init(&(mgr->types), 32, (zarray_item_killer_t)objtype_killer);
return 0;
}
void objmgr_fini(objmgr_t* mgr)
{
if (mgr == NULL) {
return;
}
zarray_fini(&(mgr->types));
ht_fini(&(mgr->names));
mylock_fini(&(mgr->lock));
}
static int objmgr_register_internal(objmgr_t* mgr, objtype_t* type)
{
hent_t* e = NULL;
int idx;
e = ht_get(&(mgr->names), (void*)type->type);
if (e != NULL) {
return e->data;
}
e = ht_add(&(mgr->names), (void*)type->type);
if (e == NULL) {
return -ENOMEM;
}
idx = zarray_store(&(mgr->types), type);
if (idx < 0) {
ht_del(&(mgr->names), (void*)type->type);
return idx;
}
e->data = idx;
return idx;
}
int obj_init(objmgr_t* mgr, objtype_t* type, int32_t exdata, myobj_t* obj)
{
obj->type = type;
obj->nref = 1;
obj->nread = 0;
obj->nwrite = 0;
obj->exdata = exdata;
obj->magic = OBJ_MAGIC;
my_rwlock_init(&(obj->rwlock));
mylock_init(&(obj->lock));
return 1;
}
int objmgr_register(objmgr_t* mgr, objtype_t* type)
{
int rc = 0;
/* clang-format off */
if ((mgr == NULL) ||
(type == NULL) ||
(type->type == NULL) ||
(type->fn_create == NULL)) {
return -EINVAL;
}
/* clang-format on */
mylock_init(&(type->lock));
mylock_lock(&(mgr->lock));
rc = objmgr_register_internal(mgr, type);
mylock_unlock(&(mgr->lock));
return rc;
}
static void* create_obj_ex(objmgr_t* mgr, int type, va_list ap)
{
objtype_t* typeval = NULL;
void* obj;
if ((type < 0) || (type >= mgr->types.caps)) {
SET_ERROR(EINVAL);
return NULL;
}
typeval = (objtype_t*)zarray_get(&(mgr->types), type);
if (typeval == NULL) {
SET_ERROR(EINVAL);
return NULL;
}
obj = typeval->fn_create(mgr, typeval, ap);
return obj;
}
void* create_obj_by_typeid(objmgr_t* mgr, int type, ...)
{
va_list ap;
void* p = NULL;
va_start(ap, type);
p = create_obj_ex(mgr, type, ap);
va_end(ap);
return p;
}
void* create_obj_by_typename(objmgr_t* mgr, char* type, ...)
{
hent_t* e;
va_list ap;
void* p = NULL;
mylock_lock(&(mgr->lock));
e = ht_get(&(mgr->names), (void*)type);
mylock_unlock(&(mgr->lock));
if (e == NULL) {
SET_ERROR(EINVAL);
return NULL;
}
if (e->data < 0) {
SET_ERROR(EINVAL);
return NULL;
}
va_start(ap, type);
p = create_obj_ex(mgr, e->data, ap);
va_end(ap);
return p;
}
int typeid_of_name(objmgr_t* mgr, char* type)
{
hent_t* e;
int typeid;
mylock_lock(&(mgr->lock));
e = ht_get(&(mgr->names), (void*)type);
if (e == NULL) {
typeid = -ENOENT;
} else {
typeid = e->data;
}
mylock_unlock(&(mgr->lock));
return typeid;
}
void* obj_ref(void* obj, int op)
{
myobj_t* myobj;
if (obj == NULL) {
SET_ERROR(EINVAL);
return NULL;
}
myobj = TO_MYOBJ(obj);
if (myobj->magic != OBJ_MAGIC) {
SET_ERROR(EINVAL);
return NULL;
}
switch (op) {
case OBJREF_READ:
my_rwlock_rlock(&(myobj->rwlock));
break;
case OBJREF_UPDATE:
my_rwlock_wlock(&(myobj->rwlock));
break;
default:
break;
}
mylock_lock(&(myobj->lock));
switch (op) {
case OBJREF_READ:
myobj->nread++;
break;
case OBJREF_UPDATE:
myobj->nwrite++;
break;
default:
break;
}
myobj->nref++;
mylock_unlock(&(myobj->lock));
return obj;
}
void obj_deref(void* obj)
{
myobj_t* myobj;
int nc;
objtype_t* typeval;
int release_rwlock = 0;
if (obj == NULL) {
SET_ERROR(EINVAL);
return;
}
myobj = TO_MYOBJ(obj);
if (myobj->magic != OBJ_MAGIC) {
SET_ERROR(EINVAL);
return;
}
/* the object lock should be held */
mylock_lock(&(myobj->lock));
myobj->nref--;
nc = myobj->nref;
if ((myobj->nread > 0) || (myobj->nwrite > 0)) {
release_rwlock = 1;
if (myobj->nread > 0) {
myobj->nread--;
} else {
myobj->nwrite--;
}
}
mylock_unlock(&(myobj->lock));
if (release_rwlock) {
my_rwlock_unlock(&(myobj->rwlock));
}
if (nc > 0) {
return;
}
typeval = myobj->type;
if (typeval == NULL) {
return;
}
if (typeval->fn_fini != NULL) {
typeval->fn_fini(obj);
}
return;
}
objmgr_t* objmgr_get_default() { return objmgr_default; }
int objmgr_set_default(objmgr_t* mgr)
{
objmgr_default = mgr;
return 0;
}
myobj_t* obj_alloc(size_t size)
{
myobj_t* obj;
if (size <= 0) {
SET_ERROR(EINVAL);
return NULL;
}
obj = (myobj_t*)calloc(1, sizeof(*obj) + size);
return obj;
}

View file

@ -105,7 +105,7 @@ static int queue_reference(meta_obj_t* obj)
static void queue_dereference(meta_obj_t* obj)
{
queue_private_t* priv = (queue_private_t*)RTTI_OBJ_TO_PRIV(obj);
xce_queue_t* w = RTTI_OBJ_TO_DATA(xce_queue_t, obj);
queue_t* w = RTTI_OBJ_TO_DATA(queue_t, obj);
uint64_t count = 0;
my_rwlock_wlock(&(priv->lock));
@ -163,9 +163,33 @@ static typeinfo_t queue_type = {
.unlock = (unlock_fn_t)queue_unlock } }
};
queue_t* makeQueue(var qmgr, xce_queue_t* w)
queue_t* makeQueue(var qmgr, xce_queue_t* q)
{
/* FIMXE: */
queue_t* queue = makeInstance(&queue_type, w);
queue_t* queue = NULL;
int rc = 0;
rc = key_find(qmgr, (void*)q->queue, (void**)&queue);
if ((rc < 0) && (rc != -ENOENT)) {
errno = -rc;
return NULL;
}
if (rc > 0) {
errno = EEXIST;
return NULL;
}
queue = makeInstance(&queue_type, q);
if (queue != NULL) {
reference(queue);
rc = key_add(qmgr, (void*)q->queue, (void*)queue);
if (rc < 0) {
destroy(queue);
errno = -rc;
return NULL;
}
}
return queue;
}

View file

@ -112,8 +112,33 @@ static typeinfo_t resobj_type
.reference = (reference_fn_t)resobj_reference,
.dereference = (dereference_fn_t)resobj_dereference } } };
xce_resource_t* makeResource(xce_resource_t* w)
xce_resource_t* makeResource(var resmgr, xce_resource_t* r)
{
xce_resource_t* resobj = makeInstance(&resobj_type, w);
xce_resource_t* resobj = NULL;
int rc;
rc = key_find(resmgr, (void*)r->name, (void**)&resobj);
if ((rc < 0) && (rc != -ENOENT)) {
errno = -rc;
return NULL;
}
if (rc > 0) {
errno = EEXIST;
return NULL;
}
resobj = makeInstance(&resobj_type, r);
if (resobj != NULL) {
reference(resobj);
rc = key_add(resmgr, (void*)resobj->name, (void*)resobj);
if (rc < 0) {
destroy(resobj);
errno = -rc;
return NULL;
}
}
return resobj;
}

View file

@ -4,7 +4,6 @@
#include <string.h>
#include "kvmgr.h"
#include "objmgr.h"
#include "resreq.h"
#include "rusage.h"
#include "section.h"

View file

@ -1,15 +1,15 @@
#include <rtti.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <rtti.h>
#include <unity/unity.h>
#include "kvmgr.h"
#include "qobj.h"
#include "utils.h"
#include "xstring.h"
#include "kvmgr.h"
static void test_queue_create(void)
{
@ -17,10 +17,14 @@ static void test_queue_create(void)
kvmgr_params_t params = { .key_type = KVMGR_KEY_STRING,
.nslots = 32,
.delta = 32,
.datakiller = destroy };
.datakiller = dereference };
var qmgr;
xce_queue_t q1 = { 0 };
xce_queue_t q1 = { .queue = "xce",
.resreq = "type == any",
.pre_exec = NULL,
.post_exec = NULL,
.autopscaler = NULL };
queue_t* q = NULL;
rc = xstring_table_init(32);
@ -33,7 +37,7 @@ static void test_queue_create(void)
TEST_ASSERT_TRUE(q != NULL);
destroy(q);
dereference(q);
destroy(qmgr);
xstring_table_fini();

View file

@ -16,7 +16,7 @@ static void test_worker_create(void)
kvmgr_params_t params = { .key_type = KVMGR_KEY_STRING,
.nslots = 32,
.delta = 32,
.datakiller = destroy };
.datakiller = dereference };
var workermgr;
hostattrs_t attrs1 = { .hosttype = "LINUX64",
.hostmodel = "linux-gnu-x86_64",
@ -48,7 +48,6 @@ static void test_worker_create(void)
&& (w->host.attrs->maxcpus == attrs1.maxcpus));
dereference(w);
destroy(workermgr);
xstring_table_fini();

View file

@ -3,7 +3,6 @@
#include <string.h>
#include <unity/unity.h>
#include "objmgr.h"
#include "utils.h"
#include "xstring.h"

View file

@ -161,7 +161,31 @@ static typeinfo_t worker_type = {
worker_t* makeWorker(var workermgr, xce_worker_t* w)
{
worker_t* worker = makeInstance(&worker_type, w);
/* fIXME */
worker_t* worker = NULL;
int rc = 0;
rc = key_find(workermgr, (void*)w->name, (void**)&worker);
if ((rc < 0) && (rc != -ENOENT)) {
errno = -rc;
return NULL;
}
if (rc > 0) {
errno = EEXIST;
return NULL;
}
worker = makeInstance(&worker_type, w);
if (worker != NULL) {
reference(worker);
rc = key_add(workermgr, (void*)worker->host.name, (void*)worker);
if (rc < 0) {
destroy(worker);
errno = -rc;
return NULL;
}
}
return worker;
}

View file

@ -8,7 +8,6 @@
#include "group.h"
#include "kvmgr.h"
#include "objmgr.h"
#include "utils.h"
#include "xce/types.h"
#include "xcelimit.h"
@ -58,7 +57,7 @@ int fmt_consumer(char* buf, int len, xce_consumer_t* c)
return -EINVAL;
}
int build_consumer(xce_consumer_t** pconsumer, groupmgr_t* mgr,
int build_consumer(xce_consumer_t** pconsumer, var mgr,
xce_consumer_type_t type, int per_consumer,
xce_group_config_t* g_config, char* default_name_prefix)
{
@ -193,9 +192,8 @@ void kill_limit(xce_limit_t* limit)
FREEUP(limit);
}
int build_limit(xce_limit_t** plimit, groupmgr_t* ugmgr, groupmgr_t* qgmgr,
groupmgr_t* hgmgr, groupmgr_t* pgmgr,
xce_limit_config_t* config)
int build_limit(xce_limit_t** plimit, var ugmgr, var qgmgr, var hgmgr,
var pgmgr, xce_limit_config_t* config)
{
xce_limit_t* limit = NULL;
int rc = 0;

View file

@ -63,7 +63,7 @@ subdir('apiserver')
configure_file(
input: 'tools/appimage/entry.sh',
output: 'xcerun',
output: 'xce',
copy: true,
install: true,
install_dir: 'bin',

View file

@ -4,18 +4,18 @@
...
}:
let
xce = pkgs.callPackage ./xce.nix {
xcecore = pkgs.callPackage ./xce.nix {
inherit pkgs myCommitId;
withDebug = false;
withAsan = false;
};
xce_debug = pkgs.callPackage ./xce.nix {
xcecore_debug = pkgs.callPackage ./xce.nix {
inherit pkgs myCommitId;
withDebug = true;
withAsan = true;
};
in
{
xce = xce;
xce_debug = xce_debug;
xcecore = xcecore;
xcecore_debug = xcecore_debug;
}

View file

@ -10,7 +10,7 @@
stdenv.mkDerivation {
pname = "xce";
pname = "xcecore";
version = "0.0.1";
src = ./..;
@ -56,13 +56,8 @@ stdenv.mkDerivation {
(extralib.overrideAttrs (oldAttrs: {
separateDebugInfo = true;
}))
(librtti.overrideAttrs (oldAttrs: {
separateDebugInfo = true;
}))
packcc
cowsay
fortune
];
] ++ (if withDebug then [librtti_debug] else [librtti]);
build-system = [ pkgs.meson ];
@ -77,8 +72,4 @@ stdenv.mkDerivation {
("-Dcommit_id=" + myCommitId)
# (lib.optional (!with_debug) "-Dbuildtype=release")
];
meta = {
mainProgram = "xcerun";
};
}

View file

@ -5,7 +5,6 @@
#include <stdlib.h>
#include "kvmgr.h"
#include "objmgr.h"
#include "plugin.h"
#include "sched/types.h"
#include "scheduler.h"

View file

@ -6,7 +6,6 @@
#include "decision.h"
#include "kvmgr.h"
#include "objmgr.h"
#include "plugin.h"
#include "preason.h"
#include "scheduler.h"

View file

@ -7,7 +7,6 @@
#include "decision.h"
#include "kvmgr.h"
#include "objmgr.h"
#include "plugin.h"
#include "preason.h"
#include "scheduler.h"

View file

@ -3,7 +3,6 @@
#include <stdlib.h>
#include "kvmgr.h"
#include "objmgr.h"
#include "plugin.h"
#include "preason.h"
#include "sched/types.h"

View file

@ -5,7 +5,6 @@
#include "controller.capnp.h"
#include "kvmgr.h"
#include "objmgr.h"
#include "sched/types.h"
#include "scheduler.h"
#include "utils.h"

View file

@ -11,7 +11,6 @@
#include "decision.h"
#include "kvmgr.h"
#include "misc.h"
#include "objmgr.h"
#include "plugin.h"
#include "preason.h"
#include "scheduler.h"

View file

@ -1,14 +1,48 @@
#!/usr/bin/env bash
APP="$0"
usage() {
local _f
_f=$(dirname "$APP")/share/xce.md
if [ ! -f "$_f" ]; then
echo no document found
else
glow -p ${_f}
fi
}
debug=${DEBUG:-no}
if [ "${debug}" = "yes" ]; then
set -x
fi
case "$1" in
hello)
controller)
shift
cowsay "Hello, $*"
$(which xce_controller) "$@"
;;
fortune)
fortune
worker)
shift
$(which xcecd) "$@"
;;
scheduler)
shift
$(which xce_scheduler) "$@"
;;
apiserver)
shift
$(which xce_apiserver) "$@"
;;
shell)
shift
bash -i
;;
*)
echo "Usage: $0 {hello <message>|fortune}"
usage
exit 1
;;
esac