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

@ -26,8 +26,7 @@ typedef struct {
xce_ctx_t ctx;
} api_ctx_t;
int xcecli_ctx_init(xcecli_ctx_t* c,
xce_client_config_t* cfg)
int xcecli_ctx_init(xcecli_ctx_t* c, xce_client_config_t* cfg)
{
api_ctx_t* ctx;
int rc;
@ -46,16 +45,13 @@ int xcecli_ctx_init(xcecli_ctx_t* c,
}
ctx->conf = cfg;
rc = xce_ctx_init(&(ctx->ctx),
ctx->conf->from,
ctx->conf->key);
rc = xce_ctx_init(&(ctx->ctx), ctx->conf->from, ctx->conf->key);
if (rc < 0) {
free(ctx);
return rc;
}
endpoint_init(&(ctx->ep), AF_INET,
SOCK_STREAM, 0, 0);
endpoint_init(&(ctx->ep), AF_INET, SOCK_STREAM, 0, 0);
xce_ctx_set_endpoint(&(ctx->ctx), &(ctx->ep));
@ -77,8 +73,7 @@ void xcecli_ctx_fini(xcecli_ctx_t c)
free(ctx);
}
int xcecli_set_handler(xcecli_ctx_t c,
xce_request_handler_t handler)
int xcecli_set_handler(xcecli_ctx_t c, xce_request_handler_t handler)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -89,8 +84,7 @@ int xcecli_set_handler(xcecli_ctx_t c,
return xce_ctx_set_handler(&(ctx->ctx), handler);
}
int xcecli_wakeup(xcecli_ctx_t c,
int status)
int xcecli_wakeup(xcecli_ctx_t c, int status)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -101,8 +95,7 @@ int xcecli_wakeup(xcecli_ctx_t c,
return xce_wakeup(&(ctx->ctx), status);
}
int xcecli_try_wakeup(xcecli_ctx_t c,
int status)
int xcecli_try_wakeup(xcecli_ctx_t c, int status)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -122,8 +115,7 @@ int xcecli_start(xcecli_ctx_t c)
return -EINVAL;
}
rc = endpoint_connect(&(ctx->ep),
ctx->conf->masters[0],
rc = endpoint_connect(&(ctx->ep), ctx->conf->masters[0],
ctx->conf->master_ports[0]);
if (rc < 0) {
endpoint_deref(&(ctx->ep));
@ -169,8 +161,7 @@ xce_peerinfo_t* xcecli_get_myinfo(xcecli_ctx_t c)
return &(ctx->ctx.myinfo);
}
int xcecli_hello(xcecli_ctx_t c,
char* msg)
int xcecli_hello(xcecli_ctx_t c, char* msg)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -192,8 +183,7 @@ int xcecli_shutdown(xcecli_ctx_t c)
return xce_shutdown(&(ctx->ctx));
}
int xcecli_reslist(xcecli_ctx_t c,
xce_resource_t*** res)
int xcecli_reslist(xcecli_ctx_t c, xce_resource_t*** res)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -204,9 +194,7 @@ int xcecli_reslist(xcecli_ctx_t c,
return xce_reslist(&(ctx->ctx), res);
}
int xcecli_join(xcecli_ctx_t c,
int role,
hostattrs_t* attrs)
int xcecli_join(xcecli_ctx_t c, int role, hostattrs_t* attrs)
{
api_ctx_t* ctx = (api_ctx_t*)c;
if (ctx == NULL) {
@ -216,8 +204,7 @@ int xcecli_join(xcecli_ctx_t c,
return xce_join(&(ctx->ctx), role, attrs);
}
int xcecli_workerlist(xcecli_ctx_t c,
xce_worker_t*** workers)
int xcecli_workerlist(xcecli_ctx_t c, xce_worker_t*** workers)
{
api_ctx_t* ctx = (api_ctx_t*)c;
if (ctx == NULL) {
@ -227,8 +214,7 @@ int xcecli_workerlist(xcecli_ctx_t c,
return xce_workerlist(&(ctx->ctx), workers);
}
int xcecli_jobdispatch(xcecli_ctx_t c,
xce_job_dispatch_t* info)
int xcecli_jobdispatch(xcecli_ctx_t c, xce_job_dispatch_t* info)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -239,9 +225,7 @@ int xcecli_jobdispatch(xcecli_ctx_t c,
return xce_jobdispatch(&(ctx->ctx), info);
}
int xcecli_jobsubmit(xcecli_ctx_t c,
xce_job_submit_t* submit,
uint64_t* jobid)
int xcecli_jobsubmit(xcecli_ctx_t c, xce_job_submit_t* submit, uint64_t* jobid)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -252,8 +236,7 @@ int xcecli_jobsubmit(xcecli_ctx_t c,
return xce_jobsubmit(&(ctx->ctx), submit, jobid);
}
int xcecli_joblist(xcecli_ctx_t c,
xce_job_t*** jobs)
int xcecli_joblist(xcecli_ctx_t c, xce_job_t*** jobs)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -264,8 +247,7 @@ int xcecli_joblist(xcecli_ctx_t c,
return xce_joblist(&(ctx->ctx), jobs);
}
int xcecli_clusterconf(xcecli_ctx_t c,
xce_clusterconf_t** conf)
int xcecli_clusterconf(xcecli_ctx_t c, xce_clusterconf_t** conf)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -276,8 +258,7 @@ int xcecli_clusterconf(xcecli_ctx_t c,
return xce_clusterconf(&(ctx->ctx), conf);
}
int xcecli_notify_jobfinish(xcecli_ctx_t c,
xce_jobfinish_t* jfinish)
int xcecli_notify_jobfinish(xcecli_ctx_t c, xce_jobfinish_t* jfinish)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */
@ -300,9 +281,7 @@ int xcecli_notify_jobfinish(xcecli_ctx_t c,
return xcecli_notify(ctx, &data);
}
int xcecli_update_resvals(xcecli_ctx_t c,
int nres,
xce_resval_t** vals)
int xcecli_update_resvals(xcecli_ctx_t c, int nres, xce_resval_t** vals)
{
api_ctx_t* ctx = (api_ctx_t*)c;
int rc;
@ -316,13 +295,8 @@ int xcecli_update_resvals(xcecli_ctx_t c,
return rc;
}
int xcecli_update_jusage(xcecli_ctx_t c,
uint64_t jobid,
int npids,
int* pids,
int npgids,
int* pgids,
int nusage,
int xcecli_update_jusage(xcecli_ctx_t c, uint64_t jobid, int npids, int* pids,
int npgids, int* pgids, int nusage,
xce_rusage_t** usages)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -332,17 +306,13 @@ int xcecli_update_jusage(xcecli_ctx_t c,
return -EINVAL;
}
rc = xce_update_jusage(&(ctx->ctx), jobid,
npids, pids, npgids, pgids,
rc = xce_update_jusage(&(ctx->ctx), jobid, npids, pids, npgids, pgids,
nusage, usages);
return rc;
}
int xcecli_resval(xcecli_ctx_t c,
char* host,
char* res,
xce_resval_t*** val)
int xcecli_resval(xcecli_ctx_t c, char* host, char* res, xce_resval_t*** val)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -357,8 +327,7 @@ int xcecli_resval(xcecli_ctx_t c,
return xce_resval(&(ctx->ctx), host, res, val);
}
int xcecli_notify(xcecli_ctx_t c,
xce_notify_data_t* data)
int xcecli_notify(xcecli_ctx_t c, xce_notify_data_t* data)
{
api_ctx_t* ctx = (api_ctx_t*)c;
@ -373,8 +342,7 @@ int xcecli_notify(xcecli_ctx_t c,
return xce_notify(&(ctx->ctx), data);
}
int xcecli_notify_jobstart(xcecli_ctx_t c,
job_pidinfo_t* pidinfo)
int xcecli_notify_jobstart(xcecli_ctx_t c, job_pidinfo_t* pidinfo)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */
@ -393,8 +361,7 @@ int xcecli_notify_jobstart(xcecli_ctx_t c,
return xcecli_notify(ctx, &data);
}
int xcecli_notify_jobfail(xcecli_ctx_t c,
job_failinfo_t* failinfo)
int xcecli_notify_jobfail(xcecli_ctx_t c, job_failinfo_t* failinfo)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */
@ -413,8 +380,7 @@ int xcecli_notify_jobfail(xcecli_ctx_t c,
return xcecli_notify(ctx, &data);
}
int xcecli_jobctrl(xcecli_ctx_t c,
xce_jobctrl_t* ctrlinfo)
int xcecli_jobctrl(xcecli_ctx_t c, xce_jobctrl_t* ctrlinfo)
{
api_ctx_t* ctx = (api_ctx_t*)c;
int rc;
@ -428,8 +394,7 @@ int xcecli_jobctrl(xcecli_ctx_t c,
return rc;
}
int xcecli_notify_jobstop(xcecli_ctx_t c,
uint64_t jobid)
int xcecli_notify_jobstop(xcecli_ctx_t c, uint64_t jobid)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */
@ -448,8 +413,7 @@ int xcecli_notify_jobstop(xcecli_ctx_t c,
return xcecli_notify(ctx, &data);
}
int xcecli_notify_jobresume(xcecli_ctx_t c,
uint64_t jobid)
int xcecli_notify_jobresume(xcecli_ctx_t c, uint64_t jobid)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */
@ -468,9 +432,7 @@ int xcecli_notify_jobresume(xcecli_ctx_t c,
return xcecli_notify(ctx, &data);
}
int xcecli_notify_jobchkpt(xcecli_ctx_t c,
uint64_t jobid,
char* info)
int xcecli_notify_jobchkpt(xcecli_ctx_t c, uint64_t jobid, char* info)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */
@ -493,8 +455,7 @@ int xcecli_notify_jobchkpt(xcecli_ctx_t c,
return xcecli_notify(ctx, &data);
}
int xcecli_notify_jobpostdone(xcecli_ctx_t c,
uint64_t jobid)
int xcecli_notify_jobpostdone(xcecli_ctx_t c, uint64_t jobid)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */
@ -513,8 +474,7 @@ int xcecli_notify_jobpostdone(xcecli_ctx_t c,
return xcecli_notify(ctx, &data);
}
int xcecli_queuectrl(xcecli_ctx_t c,
xce_queuectrl_t* ctrlinfo)
int xcecli_queuectrl(xcecli_ctx_t c, xce_queuectrl_t* ctrlinfo)
{
api_ctx_t* ctx = (api_ctx_t*)c;
int rc;
@ -528,8 +488,7 @@ int xcecli_queuectrl(xcecli_ctx_t c,
return rc;
}
int xcecli_runtask(xcecli_ctx_t c,
xce_taskrun_t* info)
int xcecli_runtask(xcecli_ctx_t c, xce_taskrun_t* info)
{
api_ctx_t* ctx = (api_ctx_t*)c;
int rc;
@ -547,8 +506,7 @@ int xcecli_runtask(xcecli_ctx_t c,
return rc;
}
int xcecli_notify_taskstart(xcecli_ctx_t c,
xce_task_pidinfo_t* pidinfo)
int xcecli_notify_taskstart(xcecli_ctx_t c, xce_task_pidinfo_t* pidinfo)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */
@ -567,8 +525,7 @@ int xcecli_notify_taskstart(xcecli_ctx_t c,
return xcecli_notify(ctx, &data);
}
int xcecli_notify_taskfail(xcecli_ctx_t c,
xce_task_failinfo_t* failinfo)
int xcecli_notify_taskfail(xcecli_ctx_t c, xce_task_failinfo_t* failinfo)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */
@ -587,8 +544,7 @@ int xcecli_notify_taskfail(xcecli_ctx_t c,
return xcecli_notify(ctx, &data);
}
int xcecli_notify_taskfinish(xcecli_ctx_t c,
xce_task_finish_t* info)
int xcecli_notify_taskfinish(xcecli_ctx_t c, xce_task_finish_t* info)
{
api_ctx_t* ctx = (api_ctx_t*)c;
/* clang-format off */

View file

@ -2,8 +2,7 @@
#include "dataq.h"
int dataq_init(dataq_t* q,
data_item_killer_t killer)
int dataq_init(dataq_t* q, data_item_killer_t killer)
{
q->head = q->tail = NULL;
q->killer = killer;
@ -28,8 +27,7 @@ static data_item_t* dataq_deq_head(dataq_t* q)
return NULL;
}
static data_item_t* dataq_deq_first_match(dataq_t* q,
data_item_match_fn_t f)
static data_item_t* dataq_deq_first_match(dataq_t* q, data_item_match_fn_t f)
{
data_item_t* prev = NULL;
data_item_t* curr = q->head;
@ -64,8 +62,7 @@ static data_item_t* dataq_deq_first_match(dataq_t* q,
return NULL;
}
data_item_t* dataq_deq(dataq_t* q,
data_item_match_fn_t f)
data_item_t* dataq_deq(dataq_t* q, data_item_match_fn_t f)
{
data_item_t* b = NULL;

View file

@ -5,8 +5,7 @@
#include "hook.h"
#include "utils.h"
int xce_hook_init(hooksys_t* s,
int maxtypes)
int xce_hook_init(hooksys_t* s, int maxtypes)
{
int i;
if ((s == NULL) || (maxtypes <= 0)) {
@ -26,10 +25,7 @@ int xce_hook_init(hooksys_t* s,
return 0;
}
int xce_add_hook(hooksys_t* s,
int typ,
hook_fn_t fn,
void* data)
int xce_add_hook(hooksys_t* s, int typ, hook_fn_t fn, void* data)
{
hook_item_t* it;
@ -62,11 +58,7 @@ int xce_add_hook(hooksys_t* s,
* negative value will cause
* fail
*/
int xce_run_hooks(hooksys_t* s,
int type,
int situation,
int detail,
...)
int xce_run_hooks(hooksys_t* s, int type, int situation, int detail, ...)
{
xlist_t* l;
int i;
@ -91,8 +83,7 @@ int xce_run_hooks(hooksys_t* s,
}
va_start(ap, detail);
rc = (*(it->fn))(type, situation, detail,
it->data, ap);
rc = (*(it->fn))(type, situation, detail, it->data, ap);
va_end(ap);
if ((situation == HOOK_BEFORE_EVENT) && (rc < 0)) {
@ -103,8 +94,7 @@ int xce_run_hooks(hooksys_t* s,
return rc;
}
static int free_hook_item(void* data1,
void* data2)
static int free_hook_item(void* data1, void* data2)
{
if (data1 == NULL) {
return -EINVAL;
@ -127,9 +117,7 @@ void xce_hook_fini(hooksys_t* s)
}
for (i = 0; i < s->maxtypes; i++) {
xlist_iter(&(s->hooks[i]),
(xlist_iter_fn_t)free_hook_item,
NULL);
xlist_iter(&(s->hooks[i]), (xlist_iter_fn_t)free_hook_item, NULL);
xlist_fini(&(s->hooks[i]));
}

View file

@ -5,20 +5,20 @@
#include "htab.h"
#include "utils.h"
#define HASH_KEY_HASH(t, key) \
#define HASH_KEY_HASH(t, key) \
(((t)->fn.hash != NULL) ? ((t)->fn.hash)(key) : (unsigned long)key)
#define HASH_KEY_CMP(t, k1, k2) \
#define HASH_KEY_CMP(t, k1, k2) \
(((t)->fn.cmp != NULL) ? ((t)->fn.cmp)((k1), (k2)) : ((k1) != (k2)))
#define HASH_KEY_COPY(t, key) \
#define HASH_KEY_COPY(t, key) \
(((t)->fn.copy != NULL) ? ((t)->fn.copy)(key) : (key))
#define HASH_KEY_FREE(t, key) \
do { \
if (((t)->fn.free != NULL) && ((key) != NULL)) { \
(t)->fn.free(key); \
} \
#define HASH_KEY_FREE(t, key) \
do { \
if (((t)->fn.free != NULL) && ((key) != NULL)) { \
(t)->fn.free(key); \
} \
} while (0)
static unsigned int hash_code(const char* key)
@ -38,16 +38,12 @@ static unsigned int string_hash(void* data)
return hash_code((const char*)data);
}
static int string_cmp(void* d1,
void* d2)
static int string_cmp(void* d1, void* d2)
{
return (int)strcmp((char*)d1, (char*)d2);
}
static void* string_dup(void* data)
{
return (void*)strdup((char*)data);
}
static void* string_dup(void* data) { return (void*)strdup((char*)data); }
static void string_free(void* data)
{
@ -56,23 +52,15 @@ static void string_free(void* data)
}
}
hash_key_fn_t string_hash_key = {
.hash = (hash_key_hash_fn_t)string_hash,
.cmp = (hash_key_cmp_fn_t)string_cmp,
.copy = (hash_key_copy_fn_t)string_dup,
.free = (hash_key_free_fn_t)string_free
};
hash_key_fn_t string_hash_key = { .hash = (hash_key_hash_fn_t)string_hash,
.cmp = (hash_key_cmp_fn_t)string_cmp,
.copy = (hash_key_copy_fn_t)string_dup,
.free = (hash_key_free_fn_t)string_free };
hash_key_fn_t int_hash_key = {
.hash = NULL,
.cmp = NULL,
.copy = NULL,
.free = NULL
};
hash_key_fn_t int_hash_key
= { .hash = NULL, .cmp = NULL, .copy = NULL, .free = NULL };
int ht_init(htab_t* t,
int nslots,
hash_key_fn_t fn)
int ht_init(htab_t* t, int nslots, hash_key_fn_t fn)
{
if ((t == NULL) || (nslots <= 1)) {
return -EINVAL;
@ -112,8 +100,7 @@ void ht_fini(htab_t* t)
return;
}
hent_t* ht_get(htab_t* t,
void* key)
hent_t* ht_get(htab_t* t, void* key)
{
unsigned int hc;
hent_t* e;
@ -140,8 +127,7 @@ hent_t* ht_get(htab_t* t,
return e;
}
hent_t* ht_add(htab_t* t,
void* key)
hent_t* ht_add(htab_t* t, void* key)
{
unsigned int hc;
hent_t* e;
@ -177,8 +163,7 @@ hent_t* ht_add(htab_t* t,
return e;
}
int ht_del(htab_t* t,
void* key)
int ht_del(htab_t* t, void* key)
{
unsigned int hc;
hent_t** e;

View file

@ -9,10 +9,7 @@
#include "xce/types.h"
#include "zarray.h"
int kvmgr_init(kvmgr_t* mgr,
hash_key_fn_t keyfn,
int nslots,
int delta,
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);
@ -28,9 +25,7 @@ void kvmgr_fini(kvmgr_t* mgr)
mylock_fini(&(mgr->lock));
}
static void* kvmgr_lock_(kvmgr_t* mgr,
void* key,
int op)
static void* kvmgr_lock_(kvmgr_t* mgr, void* key, int op)
{
hent_t* e = NULL;
int32_t idx;
@ -53,9 +48,7 @@ static void* kvmgr_lock_(kvmgr_t* mgr,
return obj_ref(ptr, op);
}
void* kvmgr_lock(kvmgr_t* mgr,
void* key,
int op)
void* kvmgr_lock(kvmgr_t* mgr, void* key, int op)
{
void* ptr = NULL;
@ -80,9 +73,7 @@ void* kvmgr_lock(kvmgr_t* mgr,
return ptr;
}
static int32_t kvmgr_add_(kvmgr_t* mgr,
void* key,
void* p)
static int32_t kvmgr_add_(kvmgr_t* mgr, void* key, void* p)
{
hent_t* e = NULL;
int idx;
@ -97,8 +88,7 @@ static int32_t kvmgr_add_(kvmgr_t* mgr,
return idx;
}
e = ht_add(&(mgr->htab),
(void*)key);
e = ht_add(&(mgr->htab), (void*)key);
if (e == NULL) {
zarray_del(&(mgr->data), idx);
return -errno;
@ -108,9 +98,7 @@ static int32_t kvmgr_add_(kvmgr_t* mgr,
return idx;
}
int32_t kvmgr_add(kvmgr_t* mgr,
void* key,
void* p)
int32_t kvmgr_add(kvmgr_t* mgr, void* key, void* p)
{
int32_t idx;
@ -125,8 +113,7 @@ int32_t kvmgr_add(kvmgr_t* mgr,
return idx;
}
static void kvmgr_del_(kvmgr_t* mgr,
void* key)
static void kvmgr_del_(kvmgr_t* mgr, void* key)
{
hent_t* e = NULL;
int idx;
@ -146,8 +133,7 @@ static void kvmgr_del_(kvmgr_t* mgr,
return;
}
void kvmgr_del(kvmgr_t* mgr,
void* key)
void kvmgr_del(kvmgr_t* mgr, void* key)
{
if (mgr == NULL) {
return;
@ -169,9 +155,7 @@ static int add_config_(xlist_t* l, void* data)
return xlist_store(l, config);
}
int kvmgr_publish(kvmgr_t* mgr,
xlist_action_fn_t fn,
void* arg)
int kvmgr_publish(kvmgr_t* mgr, xlist_action_fn_t fn, void* arg)
{
xlist_t l;
int rc = 0;
@ -180,9 +164,7 @@ int kvmgr_publish(kvmgr_t* mgr,
xlist_init(&l, 128);
mylock_lock(&(mgr->lock));
zarray_iter(&(mgr->data),
(zarray_iter_fn_t)add_config_,
&l);
zarray_iter(&(mgr->data), (zarray_iter_fn_t)add_config_, &l);
mylock_unlock(&(mgr->lock));
rc = (*fn)(&l, arg);
@ -197,9 +179,7 @@ int kvmgr_publish(kvmgr_t* mgr,
return rc;
}
int kvmgr_iter(kvmgr_t* mgr,
xlist_t* l,
void* arg)
int kvmgr_iter(kvmgr_t* mgr, xlist_t* l, void* arg)
{
int rc = 0;

View file

@ -25,7 +25,8 @@ libxce_src = [ gen_srcs[0],
'xcectx.c',
'xlist.c',
'xstring.c',
'zarray.c'
'zarray.c',
'wrap.c'
]
incdir = include_directories('../include')
@ -56,7 +57,8 @@ libxce_test_src = ['testsuite/test.c',
'testsuite/test_htab_int.c',
'testsuite/test_utils.c',
'testsuite/test_xstring.c',
'testsuite/test_zarray.c'
'testsuite/test_zarray.c',
'testsuite/test_config.c'
]
libxce_test_deps = [libxce_deps, unity_dep, libxce_dep]

View file

@ -48,9 +48,7 @@ int mylock_unlock(mylock_t* l)
return pthread_mutex_unlock(l);
}
int cbuf_init(cbuf_t* b,
int cap,
int isize)
int cbuf_init(cbuf_t* b, int cap, int isize)
{
if ((b == NULL) || (cap <= 0) || (isize <= 0)) {
return -EINVAL;
@ -90,8 +88,7 @@ void cbuf_fini(cbuf_t* b)
pthread_cond_destroy(&(b->condget));
}
int cbuf_put(cbuf_t* b,
void* it)
int cbuf_put(cbuf_t* b, void* it)
{
int i;
@ -101,14 +98,12 @@ int cbuf_put(cbuf_t* b,
pthread_mutex_lock(&(b->mutex));
while (b->len == b->ncap) {
pthread_cond_wait(&(b->condput),
&(b->mutex));
pthread_cond_wait(&(b->condput), &(b->mutex));
}
i = (b->head + b->len) % b->ncap;
memcpy((void*)((char*)b->data) + b->isize * i,
it, b->isize);
memcpy((void*)((char*)b->data) + b->isize * i, it, b->isize);
b->len++;
@ -118,8 +113,7 @@ int cbuf_put(cbuf_t* b,
return 0;
}
int cbuf_tryput(cbuf_t* b,
void* it)
int cbuf_tryput(cbuf_t* b, void* it)
{
int i;
int rc = 0;
@ -132,8 +126,7 @@ int cbuf_tryput(cbuf_t* b,
if (b->len < b->ncap) {
i = (b->head + b->len) % b->ncap;
memcpy((void*)((char*)b->data) + b->isize * i,
it, b->isize);
memcpy((void*)((char*)b->data) + b->isize * i, it, b->isize);
b->len++;
@ -146,8 +139,7 @@ int cbuf_tryput(cbuf_t* b,
return rc;
}
int cbuf_get(cbuf_t* b,
void* it)
int cbuf_get(cbuf_t* b, void* it)
{
if ((b == NULL) || (it == NULL)) {
return -EINVAL;
@ -155,12 +147,10 @@ int cbuf_get(cbuf_t* b,
pthread_mutex_lock(&(b->mutex));
while (b->len == 0) {
pthread_cond_wait(&(b->condget),
&(b->mutex));
pthread_cond_wait(&(b->condget), &(b->mutex));
}
memcpy(it, (void*)((char*)b->data) + b->isize * b->head,
b->isize);
memcpy(it, (void*)((char*)b->data) + b->isize * b->head, b->isize);
b->head = (b->head + 1) % b->ncap;
b->len--;

View file

@ -17,10 +17,7 @@
static int iomgr_update_poll(iomgr_t*, endpoint_t*, int);
static void endpoint_fini(endpoint_t*);
static int socket_create(int domain,
int type,
int port,
int backlog)
static int socket_create(int domain, int type, int port, int backlog)
{
int sock;
int opt = 1;
@ -38,7 +35,9 @@ static int socket_create(int domain,
fcntl(sock, F_SETFD, (fcntl(sock, F_GETFD) | FD_CLOEXEC));
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt,
sizeof(opt))
< 0) {
close(sock);
return -1;
}
@ -79,9 +78,7 @@ static int socket_create(int domain,
return sock;
}
static int socket_connect(int sock,
char* host,
int port)
static int socket_connect(int sock, char* host, int port)
{
struct sockaddr_in server;
struct hostent* hp;
@ -130,9 +127,7 @@ static int socket_accept(int sock)
return s;
}
int netio_write(int fd,
char* data,
int sz)
int netio_write(int fd, char* data, int sz)
{
int nc = 0;
@ -152,9 +147,7 @@ int netio_write(int fd,
return nc;
}
int netio_read(int fd,
char* data,
int sz)
int netio_read(int fd, char* data, int sz)
{
int nc = 0;
@ -182,13 +175,11 @@ int netio_read(int fd,
return nc;
}
int write_packet(int fd,
io_packet_t* pkt)
int write_packet(int fd, io_packet_t* pkt)
{
int rc;
rc = netio_write(fd, (char*)&(pkt->sz),
sizeof(pkt->sz));
rc = netio_write(fd, (char*)&(pkt->sz), sizeof(pkt->sz));
if (rc < 0) {
return -errno;
}
@ -217,13 +208,11 @@ int alloc_packet(io_packet_t* pkt)
return 1;
}
int read_packet(int fd,
io_packet_t* pkt)
int read_packet(int fd, io_packet_t* pkt)
{
int rc;
rc = netio_read(fd, (char*)&(pkt->sz),
sizeof(pkt->sz));
rc = netio_read(fd, (char*)&(pkt->sz), sizeof(pkt->sz));
if (rc < 0) {
return rc;
}
@ -260,8 +249,7 @@ static void* io_worker(void* args)
int i;
struct epoll_event events[MAX_EPOLL_EVENTS];
nfds = epoll_wait(iomgr->epoll_fd, events,
MAX_EPOLL_EVENTS, -1);
nfds = epoll_wait(iomgr->epoll_fd, events, MAX_EPOLL_EVENTS, -1);
if (nfds == -1) {
if (errno == EINTR) {
continue;
@ -326,11 +314,7 @@ static void outq_item_killer(data_item_t* it)
ioctx_deref(ctx, 1);
}
}
int endpoint_init(endpoint_t* ep,
int domain,
int type,
int port,
int backlog)
int endpoint_init(endpoint_t* ep, int domain, int type, int port, int backlog)
{
int fd = -1;
@ -340,8 +324,7 @@ int endpoint_init(endpoint_t* ep,
return -EINVAL;
}
fd = socket_create(domain, type,
port, backlog);
fd = socket_create(domain, type, port, backlog);
if (fd < 0) {
return -errno;
}
@ -354,8 +337,7 @@ int endpoint_init(endpoint_t* ep,
ep->busy = 0;
ep->needfree = 0;
dataq_init(&(ep->outq),
outq_item_killer);
dataq_init(&(ep->outq), outq_item_killer);
mylock_init(&(ep->lock));
endpoint_ref(ep);
@ -363,9 +345,7 @@ int endpoint_init(endpoint_t* ep,
return fd;
}
int endpoint_connect(endpoint_t* ep,
char* host,
int port)
int endpoint_connect(endpoint_t* ep, char* host, int port)
{
int rc = -1;
@ -378,8 +358,7 @@ int endpoint_connect(endpoint_t* ep,
return rc;
}
int endpoint_accept(endpoint_t* ep,
endpoint_t* ep2)
int endpoint_accept(endpoint_t* ep, endpoint_t* ep2)
{
int sock = -1;
@ -394,9 +373,7 @@ int endpoint_accept(endpoint_t* ep,
return sock;
}
int endpoint_set_handler(endpoint_t* ep,
msghandler_t h,
void* owner)
int endpoint_set_handler(endpoint_t* ep, msghandler_t h, void* owner)
{
if (ep->fd < 0) {
SET_ERROR(EINVAL);
@ -412,8 +389,7 @@ int endpoint_set_handler(endpoint_t* ep,
return 1;
}
int endpoint_enq(endpoint_t* ep,
data_item_t* it)
int endpoint_enq(endpoint_t* ep, data_item_t* it)
{
int rc = 0;
int flags;
@ -433,8 +409,7 @@ int endpoint_enq(endpoint_t* ep,
int rc1;
mylock_lock(&(ep->iomgr->lock));
rc1 = iomgr_update_poll(ep->iomgr,
ep, flags);
rc1 = iomgr_update_poll(ep->iomgr, ep, flags);
mylock_unlock(&(ep->iomgr->lock));
if (rc1 >= 0) {
@ -468,8 +443,7 @@ data_item_t* endpoint_deq(endpoint_t* ep)
int rc;
mylock_lock(&(ep->iomgr->lock));
rc = iomgr_update_poll(ep->iomgr,
ep, flags);
rc = iomgr_update_poll(ep->iomgr, ep, flags);
mylock_unlock(&(ep->iomgr->lock));
if (rc >= 0) {
@ -519,8 +493,7 @@ uint64_t endpoint_getseq(endpoint_t* ep)
void endpoint_block_tasks(endpoint_t* ep)
{
TRACE("%s[%ld] block tasks for endpoint %p",
__func__, pthread_self(), ep);
TRACE("%s[%ld] block tasks for endpoint %p", __func__, pthread_self(), ep);
mylock_lock(&(ep->lock));
ep->busy = 1;
mylock_unlock(&(ep->lock));
@ -528,8 +501,8 @@ void endpoint_block_tasks(endpoint_t* ep)
void endpoint_unblock_tasks(endpoint_t* ep)
{
TRACE("%s[%ld] unblock tasks for endpoint %p",
__func__, pthread_self(), ep);
TRACE("%s[%ld] unblock tasks for endpoint %p", __func__, pthread_self(),
ep);
mylock_lock(&(ep->lock));
ep->busy = 0;
mylock_unlock(&(ep->lock));
@ -543,9 +516,8 @@ int endpoint_is_task_blocked(endpoint_t* ep)
busy = ep->busy;
mylock_unlock(&(ep->lock));
TRACE("%s[%ld] endpoint %p task %s",
__func__, pthread_self(),
ep, (busy != 0) ? "blocked" : "not blocked");
TRACE("%s[%ld] endpoint %p task %s", __func__, pthread_self(), ep,
(busy != 0) ? "blocked" : "not blocked");
return (busy != 0);
}
@ -583,22 +555,17 @@ int iomgr_init(iomgr_t* iomgr)
return 0;
}
static int iomgr_update_poll(iomgr_t* iomgr,
endpoint_t* ep,
int flags)
static int iomgr_update_poll(iomgr_t* iomgr, endpoint_t* ep, int flags)
{
struct epoll_event ev;
ev.events = flags;
ev.data.ptr = ep;
return epoll_ctl(iomgr->epoll_fd,
EPOLL_CTL_MOD,
ep->fd, &ev);
return epoll_ctl(iomgr->epoll_fd, EPOLL_CTL_MOD, ep->fd, &ev);
}
int iomgr_monitor(iomgr_t* iomgr,
endpoint_t* ep)
int iomgr_monitor(iomgr_t* iomgr, endpoint_t* ep)
{
struct epoll_event ev;
int rc;
@ -611,8 +578,7 @@ int iomgr_monitor(iomgr_t* iomgr,
mylock_lock(&(ep->lock));
ep->iomgr = iomgr;
mylock_lock(&(iomgr->lock));
rc = epoll_ctl(iomgr->epoll_fd, EPOLL_CTL_ADD,
ep->fd, &ev);
rc = epoll_ctl(iomgr->epoll_fd, EPOLL_CTL_ADD, ep->fd, &ev);
mylock_unlock(&(iomgr->lock));
if (rc >= 0) {
@ -624,14 +590,12 @@ int iomgr_monitor(iomgr_t* iomgr,
return rc;
}
int iomgr_unmonitor(iomgr_t* iomgr,
endpoint_t* ep)
int iomgr_unmonitor(iomgr_t* iomgr, endpoint_t* ep)
{
int rc;
mylock_lock(&(iomgr->lock));
rc = epoll_ctl(iomgr->epoll_fd, EPOLL_CTL_DEL,
ep->fd, NULL);
rc = epoll_ctl(iomgr->epoll_fd, EPOLL_CTL_DEL, ep->fd, NULL);
if (rc < 0) {
SET_ERROR(errno);
@ -650,10 +614,7 @@ int iomgr_start(iomgr_t* iomgr)
return rc;
}
int iomgr_fini(iomgr_t* iomgr)
{
return 0;
}
int iomgr_fini(iomgr_t* iomgr) { return 0; }
int iomgr_stop(iomgr_t* iomgr)
{

View file

@ -29,10 +29,8 @@ int objmgr_init(objmgr_t* mgr)
mylock_init(&(mgr->lock));
ht_init(&(mgr->names), 32,
string_hash_key);
zarray_init(&(mgr->types), 32,
(zarray_item_killer_t)objtype_killer);
ht_init(&(mgr->names), 32, string_hash_key);
zarray_init(&(mgr->types), 32, (zarray_item_killer_t)objtype_killer);
return 0;
}
@ -48,8 +46,7 @@ void objmgr_fini(objmgr_t* mgr)
mylock_fini(&(mgr->lock));
}
static int objmgr_register_internal(objmgr_t* mgr,
objtype_t* type)
static int objmgr_register_internal(objmgr_t* mgr, objtype_t* type)
{
hent_t* e = NULL;
int idx;
@ -74,10 +71,7 @@ static int objmgr_register_internal(objmgr_t* mgr,
return idx;
}
int obj_init(objmgr_t* mgr,
objtype_t* type,
int32_t exdata,
myobj_t* obj)
int obj_init(objmgr_t* mgr, objtype_t* type, int32_t exdata, myobj_t* obj)
{
obj->type = type;
obj->nref = 1;
@ -92,8 +86,7 @@ int obj_init(objmgr_t* mgr,
return 1;
}
int objmgr_register(objmgr_t* mgr,
objtype_t* type)
int objmgr_register(objmgr_t* mgr, objtype_t* type)
{
int rc = 0;
@ -115,9 +108,7 @@ int objmgr_register(objmgr_t* mgr,
return rc;
}
static void* create_obj_ex(objmgr_t* mgr,
int type,
va_list ap)
static void* create_obj_ex(objmgr_t* mgr, int type, va_list ap)
{
objtype_t* typeval = NULL;
void* obj;
@ -138,9 +129,7 @@ static void* create_obj_ex(objmgr_t* mgr,
return obj;
}
void* create_obj_by_typeid(objmgr_t* mgr,
int type,
...)
void* create_obj_by_typeid(objmgr_t* mgr, int type, ...)
{
va_list ap;
void* p = NULL;
@ -154,9 +143,7 @@ void* create_obj_by_typeid(objmgr_t* mgr,
return p;
}
void* create_obj_by_typename(objmgr_t* mgr,
char* type,
...)
void* create_obj_by_typename(objmgr_t* mgr, char* type, ...)
{
hent_t* e;
va_list ap;
@ -185,8 +172,7 @@ void* create_obj_by_typename(objmgr_t* mgr,
return p;
}
int typeid_of_name(objmgr_t* mgr,
char* type)
int typeid_of_name(objmgr_t* mgr, char* type)
{
hent_t* e;
int typeid;
@ -298,10 +284,7 @@ void obj_deref(void* obj)
return;
}
objmgr_t* objmgr_get_default()
{
return objmgr_default;
}
objmgr_t* objmgr_get_default() { return objmgr_default; }
int objmgr_set_default(objmgr_t* mgr)
{

View file

@ -11,8 +11,7 @@
#include "utils.h"
#include "xce/types.h"
ioctx_t* ioctx_alloc(endpoint_t* ep,
xce_peerinfo_t* peer)
ioctx_t* ioctx_alloc(endpoint_t* ep, xce_peerinfo_t* peer)
{
ioctx_t* ctx;
@ -37,8 +36,7 @@ int ioctx_ref(ioctx_t* ctx)
return old;
}
static void ioctx_kill(ioctx_t* ctx,
int free_ctx)
static void ioctx_kill(ioctx_t* ctx, int free_ctx)
{
if (ctx == NULL) {
return;
@ -53,8 +51,7 @@ static void ioctx_kill(ioctx_t* ctx,
}
}
void ioctx_deref(ioctx_t* ctx,
int free_ctx)
void ioctx_deref(ioctx_t* ctx, int free_ctx)
{
if (ctx == NULL) {
return;
@ -70,8 +67,7 @@ void ioctx_deref(ioctx_t* ctx,
}
}
int ioctx_encode(ioctx_t* ctx,
xce_request_t* req)
int ioctx_encode(ioctx_t* ctx, xce_request_t* req)
{
struct capn_segment* cs;
Request_ptr rp;
@ -94,19 +90,15 @@ int ioctx_encode(ioctx_t* ctx,
return rc;
}
capn_write_mem(&(ctx->c),
(uint8_t*)ctx->pkt.data,
ctx->pkt.sz, 0);
capn_write_mem(&(ctx->c), (uint8_t*)ctx->pkt.data, ctx->pkt.sz, 0);
return 0;
}
int ioctx_decode(ioctx_t* ctx,
xce_request_t* req)
int ioctx_decode(ioctx_t* ctx, xce_request_t* req)
{
Request_ptr rp;
capn_init_mem(&(ctx->c), (const uint8_t*)ctx->pkt.data,
ctx->pkt.sz, 0);
capn_init_mem(&(ctx->c), (const uint8_t*)ctx->pkt.data, ctx->pkt.sz, 0);
rp.p = capn_getp(capn_root(&(ctx->c)), 0, 1);
read_Request(&(ctx->rq), rp);
@ -124,15 +116,13 @@ int ioctx_flush(ioctx_t* ctx, int fd)
return rc;
}
void init_reply_by_req(xce_reply_t* reply,
xce_request_t* req)
void init_reply_by_req(xce_reply_t* reply, xce_request_t* req)
{
reply->seq = req->seq;
reply->opcode = req->opcode;
}
int xce_request(ioctx_t* ctx,
xce_request_t* req)
int xce_request(ioctx_t* ctx, xce_request_t* req)
{
int rc;
@ -148,9 +138,7 @@ int xce_request(ioctx_t* ctx,
return 0;
}
int xce_reply_with_ctx(ioctx_t* ctx,
xce_peerinfo_t* from,
xce_reply_t* reply)
int xce_reply_with_ctx(ioctx_t* ctx, xce_peerinfo_t* from, xce_reply_t* reply)
{
/* clang-format off */
xce_request_t request = {
@ -160,9 +148,8 @@ int xce_reply_with_ctx(ioctx_t* ctx,
/* clang-format on */
int rc;
TRACE("%s seq %lu opcode %d status %d data which %d",
__func__, reply->seq, reply->opcode,
reply->status, reply->data_which);
TRACE("%s seq %lu opcode %d status %d data which %d", __func__, reply->seq,
reply->opcode, reply->status, reply->data_which);
request.from = from;
request.body.replymsg = reply;
@ -178,9 +165,7 @@ int xce_reply_with_ctx(ioctx_t* ctx,
return 0;
}
int xce_reply(endpoint_t* ep,
xce_peerinfo_t* from,
xce_reply_t* reply)
int xce_reply(endpoint_t* ep, xce_peerinfo_t* from, xce_reply_t* reply)
{
ioctx_t* ctx;
@ -194,10 +179,8 @@ int xce_reply(endpoint_t* ep,
int xce_nop_req(ioctx_t* ctx)
{
xce_request_t request = {
.opcode = OPCode_nop,
.body_which = Request_body_nomsg
};
xce_request_t request
= { .opcode = OPCode_nop, .body_which = Request_body_nomsg };
if (ctx == NULL) {
return -EINVAL;
@ -206,8 +189,7 @@ int xce_nop_req(ioctx_t* ctx)
return xce_request(ctx, &request);
}
int xce_hello_req(ioctx_t* ctx,
char* msg)
int xce_hello_req(ioctx_t* ctx, char* msg)
{
/* clang-format off */
xce_request_t request = {
@ -225,9 +207,7 @@ int xce_hello_req(ioctx_t* ctx,
return xce_request(ctx, &request);
}
int xce_join_req(ioctx_t* ctx,
int role,
hostattrs_t* attrs)
int xce_join_req(ioctx_t* ctx, int role, hostattrs_t* attrs)
{
/* clang-format off */
xce_joindata_t joinmsg = {
@ -263,10 +243,8 @@ int xce_shutdown_req(ioctx_t* ctx)
{
int rc;
dataq_t* outq;
xce_request_t request = {
.opcode = OPCode_shutdown,
.body_which = Request_body_nomsg
};
xce_request_t request
= { .opcode = OPCode_shutdown, .body_which = Request_body_nomsg };
if (ctx == NULL) {
return -EINVAL;
@ -286,15 +264,12 @@ int xce_shutdown_req(ioctx_t* ctx)
return 0;
}
int xce_pushconfig_req(endpoint_t* ep,
xce_peerinfo_t* from,
int xce_pushconfig_req(endpoint_t* ep, xce_peerinfo_t* from,
xce_configdata_t* config)
{
int rc = 0;
xce_request_t request = {
.opcode = OPCode_push,
.body_which = Request_body_configpushmsg
};
int rc = 0;
xce_request_t request
= { .opcode = OPCode_push, .body_which = Request_body_configpushmsg };
ioctx_t* ctx = NULL;
if ((ep == NULL) || (config == NULL)) {
@ -312,16 +287,12 @@ int xce_pushconfig_req(endpoint_t* ep,
return rc;
}
static int xce_push_req(endpoint_t* ep,
xce_peerinfo_t* from,
xce_data_t* data)
static int xce_push_req(endpoint_t* ep, xce_peerinfo_t* from, xce_data_t* data)
{
int rc = 0;
ioctx_t* ctx = NULL;
xce_request_t request = {
.opcode = OPCode_push,
.body_which = Request_body_pushmsg
};
int rc = 0;
ioctx_t* ctx = NULL;
xce_request_t request
= { .opcode = OPCode_push, .body_which = Request_body_pushmsg };
if ((ep == NULL) || (from == NULL) || (data == NULL)) {
return -EINVAL;
@ -338,12 +309,8 @@ static int xce_push_req(endpoint_t* ep,
return rc;
}
int xce_push_data_req(endpoint_t* ep,
xce_peerinfo_t* from,
xce_data_t* data,
xce_check_fn_t checkf,
void* checkarg,
int pktlimit)
int xce_push_data_req(endpoint_t* ep, xce_peerinfo_t* from, xce_data_t* data,
xce_check_fn_t checkf, void* checkarg, int pktlimit)
{
int nrows = 0;
int pos = 0;
@ -365,8 +332,9 @@ int xce_push_data_req(endpoint_t* ep,
}
break;
case Data_data_schedworkers:
nrows = data->data.workers->n_total;
data1.data.workers = (xce_workers_data_t*)calloc(1, sizeof(xce_workers_data_t));
nrows = data->data.workers->n_total;
data1.data.workers
= (xce_workers_data_t*)calloc(1, sizeof(xce_workers_data_t));
if (data1.data.workers == NULL) {
rc = -ENOMEM;
}
@ -416,7 +384,8 @@ int xce_push_data_req(endpoint_t* ep,
if (nc == 0) {
data1.data.workers->workers = NULL;
} else {
data1.data.workers->workers = &(data->data.workers->workers[pos]);
data1.data.workers->workers
= &(data->data.workers->workers[pos]);
}
break;
default:
@ -447,8 +416,7 @@ int xce_push_data_req(endpoint_t* ep,
return rc;
}
int xce_get_req(ioctx_t* ctx,
xce_get_t* get)
int xce_get_req(ioctx_t* ctx, xce_get_t* get)
{
/* clang-format off */
xce_request_t request = {
@ -463,12 +431,8 @@ int xce_get_req(ioctx_t* ctx,
return xce_request(ctx, &request);
}
int xce_reply_get(endpoint_t* ep,
xce_peerinfo_t* from,
xce_reply_t* reply,
xce_check_fn_t checkf,
void* checkarg,
int pktlimit)
int xce_reply_get(endpoint_t* ep, xce_peerinfo_t* from, xce_reply_t* reply,
xce_check_fn_t checkf, void* checkarg, int pktlimit)
{
int rc = 0;
int nrows = 0;
@ -497,21 +461,25 @@ int xce_reply_get(endpoint_t* ep,
switch (getdata.table) {
case Data_data_schedjobs:
case Data_data_jobs:
nrows = data->data.jobs->n_total;
getdata.data.jobs = (xce_jobs_data_t*)calloc(1, sizeof(xce_jobs_data_t));
nrows = data->data.jobs->n_total;
getdata.data.jobs
= (xce_jobs_data_t*)calloc(1, sizeof(xce_jobs_data_t));
break;
case Data_data_schedworkers:
case Data_data_workers:
nrows = data->data.workers->n_total;
getdata.data.workers = (xce_workers_data_t*)calloc(1, sizeof(xce_workers_data_t));
nrows = data->data.workers->n_total;
getdata.data.workers
= (xce_workers_data_t*)calloc(1, sizeof(xce_workers_data_t));
break;
case Data_data_resources:
nrows = data->data.resources->n_total;
getdata.data.resources = (xce_resource_data_t*)calloc(1, sizeof(xce_resource_data_t));
nrows = data->data.resources->n_total;
getdata.data.resources
= (xce_resource_data_t*)calloc(1, sizeof(xce_resource_data_t));
break;
case Data_data_resvals:
nrows = data->data.resvals->n_total;
getdata.data.resvals = (xce_resval_data_t*)calloc(1, sizeof(xce_resval_data_t));
nrows = data->data.resvals->n_total;
getdata.data.resvals
= (xce_resval_data_t*)calloc(1, sizeof(xce_resval_data_t));
break;
default:
rc = -EINVAL;
@ -562,7 +530,8 @@ int xce_reply_get(endpoint_t* ep,
if (nc == 0) {
getdata.data.workers->workers = NULL;
} else {
getdata.data.workers->workers = &(data->data.workers->workers[pos]);
getdata.data.workers->workers
= &(data->data.workers->workers[pos]);
}
break;
case Data_data_resources:
@ -572,7 +541,8 @@ int xce_reply_get(endpoint_t* ep,
if (nc == 0) {
getdata.data.resources->resources = NULL;
} else {
getdata.data.resources->resources = &(data->data.resources->resources[pos]);
getdata.data.resources->resources
= &(data->data.resources->resources[pos]);
}
break;
case Data_data_resvals:
@ -620,8 +590,7 @@ int xce_reply_get(endpoint_t* ep,
return rc;
}
int extract_data(dataset_t* dataset,
xce_data_t* getdata)
int extract_data(dataset_t* dataset, xce_data_t* getdata)
{
int ntotal;
int rc = 0;
@ -659,7 +628,8 @@ int extract_data(dataset_t* dataset,
ntotal = getdata->data.workers->n_total;
if (dataset->rows == NULL) {
dataset->rows = (xce_worker_t**)calloc(ntotal, sizeof(xce_worker_t*));
dataset->rows
= (xce_worker_t**)calloc(ntotal, sizeof(xce_worker_t*));
dataset->nrows = 0;
}
pos = getdata->data.workers->pos;
@ -667,7 +637,8 @@ int extract_data(dataset_t* dataset,
memcpy((void*)(((char*)dataset->rows) + sizeof(xce_worker_t*) * pos),
getdata->data.workers->workers, count * sizeof(xce_worker_t*));
memset(getdata->data.workers->workers, 0x0, count * sizeof(xce_worker_t*));
memset(getdata->data.workers->workers, 0x0,
count * sizeof(xce_worker_t*));
break;
case Data_data_resources:
@ -677,16 +648,19 @@ int extract_data(dataset_t* dataset,
ntotal = getdata->data.resources->n_total;
if (dataset->rows == NULL) {
dataset->rows = (xce_resource_t**)calloc(ntotal, sizeof(xce_resource_t*));
dataset->rows
= (xce_resource_t**)calloc(ntotal, sizeof(xce_resource_t*));
dataset->nrows = 0;
}
pos = getdata->data.resources->pos;
count = getdata->data.resources->count;
memcpy((void*)(((char*)dataset->rows) + sizeof(xce_resource_t*) * pos),
getdata->data.resources->resources, count * sizeof(xce_resource_t*));
getdata->data.resources->resources,
count * sizeof(xce_resource_t*));
memset(getdata->data.resources->resources, 0x0, count * sizeof(xce_resource_t*));
memset(getdata->data.resources->resources, 0x0,
count * sizeof(xce_resource_t*));
break;
case Data_data_resvals:
if (getdata->data.resvals->count <= 0) {
@ -695,7 +669,8 @@ int extract_data(dataset_t* dataset,
ntotal = getdata->data.resvals->n_total;
if (dataset->rows == NULL) {
dataset->rows = (xce_resval_t**)calloc(ntotal, sizeof(xce_resval_t*));
dataset->rows
= (xce_resval_t**)calloc(ntotal, sizeof(xce_resval_t*));
dataset->nrows = 0;
}
@ -724,8 +699,7 @@ int extract_data(dataset_t* dataset,
return 1;
}
int xce_jobdispatch_req(ioctx_t* ctx,
xce_job_dispatch_t* info)
int xce_jobdispatch_req(ioctx_t* ctx, xce_job_dispatch_t* info)
{
/* clang-format off */
xce_request_t request = {
@ -747,8 +721,7 @@ int xce_jobdispatch_req(ioctx_t* ctx,
return xce_request(ctx, &request);
}
int xce_notify_req(ioctx_t* ctx,
xce_notify_data_t* data)
int xce_notify_req(ioctx_t* ctx, xce_notify_data_t* data)
{
/* clang-format off */
xce_request_t request = {
@ -790,8 +763,7 @@ int xce_jobsubmit_req(ioctx_t* ctx,
return xce_request(ctx, &request);
}
int xce_startjob_req(ioctx_t* ctx,
xce_job_exec_t* execinfo)
int xce_startjob_req(ioctx_t* ctx, xce_job_exec_t* execinfo)
{
/* clang-format off */
xce_request_t request = {
@ -818,8 +790,7 @@ int xce_clusterconf_req(ioctx_t* ctx)
return xce_request(ctx, &request);
}
int xce_update_req(ioctx_t* ctx,
xce_update_data_t* data)
int xce_update_req(ioctx_t* ctx, xce_update_data_t* data)
{
/* clang-format off */
xce_request_t request = {
@ -838,8 +809,7 @@ int xce_update_req(ioctx_t* ctx,
return xce_request(ctx, &request);
}
int xce_jobctrl_req(ioctx_t* ctx,
xce_jobctrl_t* ctrinfo)
int xce_jobctrl_req(ioctx_t* ctx, xce_jobctrl_t* ctrinfo)
{
/* clang-format off */
xce_request_t request = {
@ -874,8 +844,7 @@ int xce_jobctrl_req(ioctx_t* ctx,
return xce_request(ctx, &request);
}
int xce_queuectrl_req(ioctx_t* ctx,
xce_queuectrl_t* ctrlinfo)
int xce_queuectrl_req(ioctx_t* ctx, xce_queuectrl_t* ctrlinfo)
{
/* clang-format off */
xce_request_t request = {
@ -906,8 +875,7 @@ int xce_queuectrl_req(ioctx_t* ctx,
return xce_request(ctx, &request);
}
int xce_runtask_req(ioctx_t* ctx,
xce_taskrun_t* runinfo)
int xce_runtask_req(ioctx_t* ctx, xce_taskrun_t* runinfo)
{
/* clang-format off */
xce_request_t request = {

View file

@ -10,20 +10,16 @@ extern void test_ht_string(void);
extern void test_ht_int(void);
extern void test_error(void);
extern void test_utils(void);
extern void test_config(void);
void setUp(void)
{
return;
}
void setUp(void) { return; }
void tearDown(void)
{
return;
}
void tearDown(void) { return; }
int main(int argc, char* argv[])
{
UNITY_BEGIN();
test_config();
test_ht_string();
test_ht_int();
test_zarray();

View file

@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unity/unity.h>
#include "config.h"
static void test_cluster_id(void)
{
TEST_ASSERT_TRUE(MAX_CLUSTER_ID == 63);
TEST_ASSERT_TRUE(CLUSTER_ID_SHIFT == 58);
}
static void test_apiserver_id(void)
{
TEST_ASSERT_TRUE(MAX_APISERVER_ID == 15);
TEST_ASSERT_TRUE(APISERVER_ID_SHIFT == 54);
}
static void test_timestamp(void) { TEST_ASSERT_TRUE(TIMESTAMP_SHIFT == 22); }
static void test_tag(void) { TEST_ASSERT_TRUE(TAG_SHIFT == 20); }
static void test_array(void)
{
TEST_ASSERT_TRUE(SEQUENCE_HIGH_SHIFT == 15);
TEST_ASSERT_TRUE(MAX_ARRAY_IDX == 32767);
}
void test_config(void)
{
printf("\n>> config test\n\n");
RUN_TEST(test_cluster_id);
RUN_TEST(test_apiserver_id);
RUN_TEST(test_timestamp);
RUN_TEST(test_tag);
RUN_TEST(test_array);
}

View file

@ -83,14 +83,10 @@ void test_dup_threshold()
TEST_ASSERT_TRUE(strcmp(threshold[0]->name, threshold2[0]->name) == 0);
TEST_ASSERT_TRUE(strcmp(threshold[1]->name, threshold2[1]->name) == 0);
TEST_ASSERT_TRUE(float_equal(threshold[0]->sched,
threshold2[0]->sched));
TEST_ASSERT_TRUE(float_equal(threshold[0]->stop,
threshold2[0]->stop));
TEST_ASSERT_TRUE(float_equal(threshold[1]->sched,
threshold2[1]->sched));
TEST_ASSERT_TRUE(float_equal(threshold[1]->stop,
threshold2[1]->stop));
TEST_ASSERT_TRUE(float_equal(threshold[0]->sched, threshold2[0]->sched));
TEST_ASSERT_TRUE(float_equal(threshold[0]->stop, threshold2[0]->stop));
TEST_ASSERT_TRUE(float_equal(threshold[1]->sched, threshold2[1]->sched));
TEST_ASSERT_TRUE(float_equal(threshold[1]->stop, threshold2[1]->stop));
free_resource_thresholds(threshold2, 2);
return;

View file

@ -40,8 +40,7 @@ void test_xstring_ref(void)
register_xstring(&mgr, 4, 4);
TEST_ASSERT_EQUAL(1, mgr.types.count);
s1 = create_obj_by_typename(&mgr, "xstring",
"Hello,world");
s1 = create_obj_by_typename(&mgr, "xstring", "Hello,world");
TEST_ASSERT_NOT_NULL(s1);
obj = TO_MYOBJ(s1);

View file

@ -5,8 +5,7 @@
#include "xce/errnox.h"
#include "xce/types.h"
static void kill_thresholds(xce_res_threshold_t** thresholds,
int count)
static void kill_thresholds(xce_res_threshold_t** thresholds, int count)
{
int i;
@ -30,8 +29,7 @@ static void kill_thresholds(xce_res_threshold_t** thresholds,
FREEUP(thresholds);
}
void free_resource_thresholds(xce_res_threshold_t** thresholds,
int count)
void free_resource_thresholds(xce_res_threshold_t** thresholds, int count)
{
kill_thresholds(thresholds, count);
}
@ -47,7 +45,8 @@ xce_res_threshold_t** dup_resource_thresholds(xce_res_threshold_t** src,
return NULL;
}
thresholds = (xce_res_threshold_t**)calloc(count, sizeof(xce_res_threshold_t*));
thresholds
= (xce_res_threshold_t**)calloc(count, sizeof(xce_res_threshold_t*));
if (thresholds == NULL) {
errno = ENOMEM;
return NULL;

View file

@ -25,73 +25,52 @@
#include "xce/errnox.h"
#include "xce/types.h"
static capn_text chars_to_text_internal(const char* chars)
{
capn_text data = {
.len = strlen(chars),
.str = chars,
.seg = NULL,
};
return data;
}
capn_text chars_to_text(const char* chars)
{
if (chars == NULL) {
chars = "";
}
return chars_to_text_internal(chars);
}
#define ARGV_INCR_DELTA (16)
#define FILL_ARGV(rc, argv, argc, maxargc, delta, s) \
do { \
(rc) = 0; \
char* s1; \
if (((argc) >= (maxargc))) { \
char** p; \
int nc, i; \
nc = (maxargc) + (delta); \
p = (char**)realloc((argv), nc * sizeof(char*)); \
if (p == NULL) { \
(rc) = -ENOMEM; \
break; \
} \
for (i = (maxargc); i < nc; i++) { \
p[i] = NULL; \
} \
(argv) = p; \
(maxargc) = nc; \
} \
s1 = strdup(s); \
if (s1 == NULL) { \
(rc) = -ENOMEM; \
break; \
} \
(argv)[argc] = s1; \
(argc)++; \
#define FILL_ARGV(rc, argv, argc, maxargc, delta, s) \
do { \
(rc) = 0; \
char* s1; \
if (((argc) >= (maxargc))) { \
char** p; \
int nc, i; \
nc = (maxargc) + (delta); \
p = (char**)realloc((argv), nc * sizeof(char*)); \
if (p == NULL) { \
(rc) = -ENOMEM; \
break; \
} \
for (i = (maxargc); i < nc; i++) { \
p[i] = NULL; \
} \
(argv) = p; \
(maxargc) = nc; \
} \
s1 = strdup(s); \
if (s1 == NULL) { \
(rc) = -ENOMEM; \
break; \
} \
(argv)[argc] = s1; \
(argc)++; \
} while (0)
#define FREE_ARGV(argv, argc) \
do { \
int i; \
if ((argv) == NULL) { \
break; \
} \
for (i = 0; i < (argc); i++) { \
if ((argv)[i] != NULL) { \
free((argv)[i]); \
(argv)[i] = NULL; \
} \
} \
free(argv); \
#define FREE_ARGV(argv, argc) \
do { \
int i; \
if ((argv) == NULL) { \
break; \
} \
for (i = 0; i < (argc); i++) { \
if ((argv)[i] != NULL) { \
free((argv)[i]); \
(argv)[i] = NULL; \
} \
} \
free(argv); \
} while (0)
int parse_argv(char* input,
char*** argv)
int parse_argv(char* input, char*** argv)
{
int max_argc = 0;
char* arg = NULL;
@ -124,8 +103,7 @@ int parse_argv(char* input,
if (isspace(*input)) {
if (i > 0) {
arg[i] = '\0';
FILL_ARGV(rc, *argv, argc, max_argc,
ARGV_INCR_DELTA, arg);
FILL_ARGV(rc, *argv, argc, max_argc, ARGV_INCR_DELTA, arg);
if (rc < 0) {
FREE_ARGV(*argv, argc);
free(arg);
@ -150,8 +128,7 @@ int parse_argv(char* input,
if (i > 0) {
arg[i] = '\0';
FILL_ARGV(rc, *argv, argc, max_argc,
ARGV_INCR_DELTA, arg);
FILL_ARGV(rc, *argv, argc, max_argc, ARGV_INCR_DELTA, arg);
if (rc < 0) {
FREE_ARGV(*argv, argc);
free(arg);
@ -163,32 +140,9 @@ int parse_argv(char* input,
return argc;
}
void free_argv(char** argv, int argc)
{
FREE_ARGV(argv, argc);
}
void free_argv(char** argv, int argc) { FREE_ARGV(argv, argc); }
#if 0
void freeup_kvs(int count,
xce_kv_t* vals)
{
int i;
if (vals == NULL) {
return;
}
for (i = 0; i < count; i++) {
if (vals[i].value.which != XceFieldValue_data_svalue) {
continue;
}
FREEUP(vals[i].value.u.svalue);
}
FREEUP(vals);
}
#endif
int get_myname(char* name, size_t size) { return gethostname(name, size); }
char* frame_symbol(int k)
{
@ -217,8 +171,7 @@ int xce_vprintf(const char* fmt, va_list ap)
if (tlog_get_root() == NULL) {
rc = vfprintf(stdout, fmt, ap);
} else {
rc = tlog_vext(TLOG_INFO, __FILE__, __LINE__,
__func__, NULL, fmt, ap);
rc = tlog_vext(TLOG_INFO, __FILE__, __LINE__, __func__, NULL, fmt, ap);
}
return rc;
}
@ -250,12 +203,8 @@ int name_to_level(char* lvlname)
return TLOG_INFO;
}
static int my_tlog_format(char* buff,
int maxlen,
struct tlog_loginfo* info,
void* userptr,
const char* fmt,
va_list ap)
static int my_tlog_format(char* buff, int maxlen, struct tlog_loginfo* info,
void* userptr, const char* fmt, va_list ap)
{
int len = 0;
int total_len = 0;
@ -265,13 +214,19 @@ static int my_tlog_format(char* buff,
/* format prefix */
if (info->level < TLOG_INFO) {
len = snprintf(buff, maxlen, "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d] [%5d] [%6s] [%17s:%-4d] ",
tm->year, tm->mon, tm->mday, tm->hour, tm->min, tm->sec, tm->usec / 1000, getpid(),
tlog_get_level_string(info->level), info->file, info->line);
len = snprintf(
buff, maxlen,
"[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d] [%5d] [%6s] [%17s:%-4d] ",
tm->year, tm->mon, tm->mday, tm->hour, tm->min, tm->sec,
tm->usec / 1000, getpid(), tlog_get_level_string(info->level),
info->file, info->line);
} else {
len = snprintf(buff, maxlen, "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d] [%5d] [%6s] [%22s] ",
tm->year, tm->mon, tm->mday, tm->hour, tm->min, tm->sec, tm->usec / 1000, getpid(),
tlog_get_level_string(info->level), info->func);
len = snprintf(
buff, maxlen,
"[%.4d-%.2d-%.2d %.2d:%.2d:%.2d,%.3d] [%5d] [%6s] [%22s] ",
tm->year, tm->mon, tm->mday, tm->hour, tm->min, tm->sec,
tm->usec / 1000, getpid(), tlog_get_level_string(info->level),
info->func);
}
if (len < 0 || len >= maxlen) {
@ -292,20 +247,16 @@ static int my_tlog_format(char* buff,
/* return total length */
return total_len;
}
int mylog_init(char* logfile,
char* loglvl,
int max_log_size,
int max_log_count)
int mylog_init(char* logfile, char* loglvl, int max_log_size, int max_log_count)
{
int flag = 0;
int rc = 0;
int flag = 0;
int rc = 0;
if (isatty(STDERR_FILENO)) {
flag = TLOG_SCREEN_COLOR;
}
rc = tlog_init(logfile, max_log_size,
max_log_count, 0, flag);
rc = tlog_init(logfile, max_log_size, max_log_count, 0, flag);
if (rc >= 0) {
rc = tlog_setlevel(name_to_level(loglvl));
}
@ -315,22 +266,13 @@ int mylog_init(char* logfile,
return rc;
}
int mylog_setlevel(char* level)
{
return tlog_setlevel(name_to_level(level));
}
int mylog_setlevel(char* level) { return tlog_setlevel(name_to_level(level)); }
void mylog_fini()
{
tlog_exit();
}
void mylog_fini() { tlog_exit(); }
static _Thread_local ectx_t ectx;
void set_error(char* file,
char* func,
int line,
int code)
void set_error(char* file, char* func, int line, int code)
{
ectx.file = file;
ectx.func = func;
@ -339,28 +281,21 @@ void set_error(char* file,
errno = code;
}
ectx_t* get_ectx()
{
return &ectx;
}
ectx_t* get_ectx() { return &ectx; }
static char* xce_err_str[] = {
"invalid job",
"invalid worker",
"duplicated jobs",
"duplicated workers",
"bad opcode",
"unknown role",
"unknown resource",
"unknown queue",
"unknown group",
"internal error",
NULL
};
static char* xce_err_str[] = { "invalid job",
"invalid worker",
"duplicated jobs",
"duplicated workers",
"bad opcode",
"unknown role",
"unknown resource",
"unknown queue",
"unknown group",
"internal error",
NULL };
int xce_strerror_r(int errnum,
char* buf,
size_t bufsize)
int xce_strerror_r(int errnum, char* buf, size_t bufsize)
{
if (errnum < XCE_ERRNO_BASE) {
return strerror_r(errnum, buf, bufsize);
@ -371,14 +306,11 @@ int xce_strerror_r(int errnum,
return -1;
}
strncpy(buf, xce_err_str[errnum - XCE_ERRNO_BASE],
bufsize);
strncpy(buf, xce_err_str[errnum - XCE_ERRNO_BASE], bufsize);
return 0;
}
int copy_int_list(int** dst,
int* src,
int count)
int copy_int_list(int** dst, int* src, int count)
{
int i;
@ -399,8 +331,7 @@ int copy_int_list(int** dst,
return count;
}
int copy_strlist(xce_strlist_t* dst,
xce_strlist_t src)
int copy_strlist(xce_strlist_t* dst, xce_strlist_t src)
{
if (!dst) {
return -1;
@ -428,8 +359,7 @@ int copy_strlist(xce_strlist_t* dst,
}
return 0;
}
void free_resval_with_idx_list(xce_val_with_idx_t*** vals,
int count)
void free_resval_with_idx_list(xce_val_with_idx_t*** vals, int count)
{
xce_val_with_idx_t** resvals = *vals;
int i;

View file

@ -18,9 +18,7 @@ vtask_t* vtask_alloc()
return task;
}
int vtask_init(vtask_t* task,
vtask_func_t entry,
endpoint_t* ep)
int vtask_init(vtask_t* task, vtask_func_t entry, endpoint_t* ep)
{
int rc;
@ -54,10 +52,8 @@ void vcpu_idle(vcpu_t* vcpu)
vtaskmgr_t* vtaskmgr = (vtaskmgr_t*)vcpu->owner;
vcpu->task = NULL;
cbuf_put(&(vtaskmgr->wbuf),
(void*)&(vcpu->cpuid));
cbuf_get(&(vcpu->wbuf),
(void*)&(vcpu->task));
cbuf_put(&(vtaskmgr->wbuf), (void*)&(vcpu->cpuid));
cbuf_get(&(vcpu->wbuf), (void*)&(vcpu->task));
return;
}
@ -104,9 +100,7 @@ static void* vcpu_entry(void* arg)
return NULL;
}
int vcpu_init(vcpu_t* vcpu,
int cpuid,
void* owner)
int vcpu_init(vcpu_t* vcpu, int cpuid, void* owner)
{
vcpu->state = VCPU_IDLE;
vcpu->vcpu = 0;
@ -122,8 +116,7 @@ int vcpu_start(vcpu_t* vcpu)
{
int rc;
rc = pthread_create(&(vcpu->vcpu), NULL,
&vcpu_entry, vcpu);
rc = pthread_create(&(vcpu->vcpu), NULL, &vcpu_entry, vcpu);
if (rc != 0) {
vcpu->state = VCPU_ERR;
return -errno;
@ -166,8 +159,7 @@ static void taskq_item_killer(data_item_t* it)
}
}
int vtaskmgr_init(vtaskmgr_t* vtaskmgr,
int nvcpus)
int vtaskmgr_init(vtaskmgr_t* vtaskmgr, int nvcpus)
{
int i;
@ -177,23 +169,18 @@ int vtaskmgr_init(vtaskmgr_t* vtaskmgr,
vtaskmgr->dispatcher = 0;
vtaskmgr->n_vcpus = nvcpus;
vtaskmgr->vcpus = (vcpu_t*)calloc(nvcpus,
sizeof(vcpu_t));
vtaskmgr->vcpus = (vcpu_t*)calloc(nvcpus, sizeof(vcpu_t));
if (vtaskmgr->vcpus == NULL) {
return -ENOMEM;
}
for (i = 0; i < nvcpus; i++) {
vcpu_init(&(vtaskmgr->vcpus[i]),
i, vtaskmgr);
vcpu_init(&(vtaskmgr->vcpus[i]), i, vtaskmgr);
}
cbuf_init(&(vtaskmgr->wbuf),
nvcpus, sizeof(int));
cbuf_init(&(vtaskmgr->wtbuf),
1, sizeof(int));
cbuf_init(&(vtaskmgr->wbuf), nvcpus, sizeof(int));
cbuf_init(&(vtaskmgr->wtbuf), 1, sizeof(int));
dataq_init(&(vtaskmgr->taskq),
taskq_item_killer);
dataq_init(&(vtaskmgr->taskq), taskq_item_killer);
return 0;
}
@ -207,8 +194,7 @@ static vcpu_t* pick_idle_vcpu(vtaskmgr_t* vtaskmgr)
return NULL;
}
TRACE("%s pick idle cpu #%d",
__func__, i);
TRACE("%s pick idle cpu #%d", __func__, i);
return &(vtaskmgr->vcpus[i]);
}
@ -224,8 +210,7 @@ static int vtask_eligible(data_item_t* data)
}
eligible = !(endpoint_is_task_blocked(task->ctx.ep));
TRACE("%s vtask %p is %s",
__func__, task,
TRACE("%s vtask %p is %s", __func__, task,
eligible ? "eligible" : "not eligible");
return eligible;
@ -246,11 +231,9 @@ static vtask_t* pick_eligible_task(vtaskmgr_t* vtaskmgr)
return task;
}
static int bind_vtask(vtask_t* task,
vcpu_t* vcpu)
static int bind_vtask(vtask_t* task, vcpu_t* vcpu)
{
TRACE("binding task %p to cpu#%d\n",
task, vcpu->cpuid);
TRACE("binding task %p to cpu#%d\n", task, vcpu->cpuid);
if (task != NULL) {
endpoint_block_tasks(task->ctx.ep);
@ -294,8 +277,8 @@ int vtaskmgr_start(vtaskmgr_t* vtaskmgr)
{
int i, rc;
rc = pthread_create(&(vtaskmgr->dispatcher), NULL,
&vdispatcher_entry, vtaskmgr);
rc = pthread_create(&(vtaskmgr->dispatcher), NULL, &vdispatcher_entry,
vtaskmgr);
if (rc != 0) {
return -errno;
}
@ -345,14 +328,12 @@ void vtaskmgr_fini(vtaskmgr_t* vtaskmgr)
return;
}
int vtask_enq(vtaskmgr_t* vtaskmgr,
vtask_t* task)
int vtask_enq(vtaskmgr_t* vtaskmgr, vtask_t* task)
{
int rc = 0;
ioctx_ref(&(task->ctx));
rc = dataq_enq(&(vtaskmgr->taskq),
&(task->ctx.link));
rc = dataq_enq(&(vtaskmgr->taskq), &(task->ctx.link));
if (rc >= 0) {
/* wake up task dispatcher */
task->owner = vtaskmgr;

View file

@ -5,10 +5,7 @@
#include "xce/errnox.h"
#include "xce/types.h"
static void kill_timewindow_time(xce_timewindow_time_t* t)
{
FREEUP(t);
}
static void kill_timewindow_time(xce_timewindow_time_t* t) { FREEUP(t); }
static void kill_timewindow_seg_config(xce_timewindow_seg_config_t* s)
{
@ -49,7 +46,8 @@ void free_timewindow_config(xce_timewindow_config_t* w)
kill_timewindow_config(w);
}
static xce_timewindow_seg_config_t* dup_timewindow_seg_config(xce_timewindow_seg_config_t* src)
static xce_timewindow_seg_config_t*
dup_timewindow_seg_config(xce_timewindow_seg_config_t* src)
{
xce_timewindow_seg_config_t* seg = NULL;
@ -72,8 +70,10 @@ static xce_timewindow_seg_config_t* dup_timewindow_seg_config(xce_timewindow_seg
return NULL;
}
seg->open = (xce_timewindow_time_t*)calloc(1, sizeof(xce_timewindow_time_t));
seg->close = (xce_timewindow_time_t*)calloc(1, sizeof(xce_timewindow_time_t));
seg->open
= (xce_timewindow_time_t*)calloc(1, sizeof(xce_timewindow_time_t));
seg->close
= (xce_timewindow_time_t*)calloc(1, sizeof(xce_timewindow_time_t));
if ((seg->open == NULL) || (seg->close == NULL)) {
kill_timewindow_seg_config(seg);
errno = ENOMEM;
@ -103,8 +103,8 @@ xce_timewindow_config_t* dup_timewindow_config(xce_timewindow_config_t* src)
return NULL;
}
w->segs = (xce_timewindow_seg_config_t**)calloc(src->nsegs,
sizeof(xce_timewindow_seg_config_t*));
w->segs = (xce_timewindow_seg_config_t**)calloc(
src->nsegs, sizeof(xce_timewindow_seg_config_t*));
if (w->segs == NULL) {
kill_timewindow_config(w);
errno = ENOMEM;

51
src/lib/wrap.c Normal file
View file

@ -0,0 +1,51 @@
#include <string.h>
#include "utils.h"
#include "xce/errnox.h"
int __wrap___xpg_strerror_r(int errnum, char* buf, size_t bufsize)
{
return xce_strerror_r(errnum, buf, bufsize);
}
static void xce_perror_(const char* s, int errnum)
{
char buf[XCE_MAX_ERRMSG_LEN];
ectx_t* ectx = get_ectx();
xce_strerror_r(errnum, buf, sizeof(buf));
if (tlog_get_root() == NULL) {
if ((ectx->file != NULL) && (ectx->func != NULL) && (ectx->line > 0)
&& (ectx->code == errnum)) {
fprintf(stderr, "%s: %s at %s:%d %s\n", s, buf, ectx->file,
ectx->line, ectx->func);
} else {
fprintf(stderr, "%s: %s", s, buf);
}
} else {
if ((ectx->file != NULL) && (ectx->func != NULL) && (ectx->line > 0)
&& (ectx->code == errnum)) {
tlog_error("%s: %s at %s:%d %s\n", s, buf, ectx->file, ectx->line,
ectx->func);
} else {
tlog_error("%s: %s", s, buf);
}
}
}
void xce_perror(const char* s) { xce_perror_(s, errno); }
void __wrap_perror(const char* s) { xce_perror(s); }
int __wrap_printf(const char* fmt, ...)
{
va_list ap;
int rc;
va_start(ap, fmt);
rc = xce_vprintf(fmt, ap);
va_end(ap);
return rc;
}

View file

@ -3,8 +3,7 @@
#include "utils.h"
#include "xceapi.h"
int xce_hello(xce_ctx_t* ctx,
char* msg)
int xce_hello(xce_ctx_t* ctx, char* msg)
{
ioctx_t* ioctx;
int rc, status;
@ -66,25 +65,14 @@ int xce_shutdown(xce_ctx_t* ctx)
return status;
}
int xce_get(xce_ctx_t* ctx,
int table,
void*** data)
int xce_get(xce_ctx_t* ctx, int table, void*** data)
{
ioctx_t* ioctx;
int rc;
int status;
xce_match_t condition = {
.type = MatchCondition_condition_matchall
};
xce_get_t get = {
.table = table,
.condition = &condition
};
dataset_t getreply = {
.table = table,
.nrows = 0,
.rows = NULL
};
xce_match_t condition = { .type = MatchCondition_condition_matchall };
xce_get_t get = { .table = table, .condition = &condition };
dataset_t getreply = { .table = table, .nrows = 0, .rows = NULL };
if (ctx == NULL) {
return -EINVAL;
@ -122,18 +110,14 @@ int xce_get(xce_ctx_t* ctx,
return rc;
}
int xce_reslist(xce_ctx_t* ctx,
xce_resource_t*** res)
int xce_reslist(xce_ctx_t* ctx, xce_resource_t*** res)
{
int table = Data_data_resources;
return xce_get(ctx, table, (void***)res);
}
int xce_resval(xce_ctx_t* ctx,
char* host,
char* res,
xce_resval_t*** vals)
int xce_resval(xce_ctx_t* ctx, char* host, char* res, xce_resval_t*** vals)
{
ioctx_t* ioctx;
int rc;
@ -196,9 +180,7 @@ int xce_resval(xce_ctx_t* ctx,
return rc;
}
int xce_join(xce_ctx_t* ctx,
int role,
hostattrs_t* attrs)
int xce_join(xce_ctx_t* ctx, int role, hostattrs_t* attrs)
{
ioctx_t* ioctx;
int rc, status;
@ -228,22 +210,16 @@ int xce_join(xce_ctx_t* ctx,
return status;
}
int xce_workerlist(xce_ctx_t* ctx,
xce_worker_t*** workers)
int xce_workerlist(xce_ctx_t* ctx, xce_worker_t*** workers)
{
int table = Data_data_workers;
return xce_get(ctx, table, (void***)workers);
}
int xce_free_workers(int nworkers,
xce_worker_t* workers)
{
return 0;
}
int xce_free_workers(int nworkers, xce_worker_t* workers) { return 0; }
int xce_jobdispatch(xce_ctx_t* ctx,
xce_job_dispatch_t* info)
int xce_jobdispatch(xce_ctx_t* ctx, xce_job_dispatch_t* info)
{
ioctx_t* ioctx;
int rc, status;
@ -274,8 +250,7 @@ int xce_jobdispatch(xce_ctx_t* ctx,
return status;
}
int xce_notify(xce_ctx_t* ctx,
xce_notify_data_t* data)
int xce_notify(xce_ctx_t* ctx, xce_notify_data_t* data)
{
ioctx_t* ioctx;
int rc;
@ -298,9 +273,7 @@ int xce_notify(xce_ctx_t* ctx,
return rc;
}
int xce_jobsubmit(xce_ctx_t* ctx,
xce_job_submit_t* submit,
uint64_t* jobid)
int xce_jobsubmit(xce_ctx_t* ctx, xce_job_submit_t* submit, uint64_t* jobid)
{
ioctx_t* ioctx;
int rc, status;
@ -334,9 +307,7 @@ int xce_jobsubmit(xce_ctx_t* ctx,
return status;
}
int xce_joblist_ex(xce_ctx_t* ctx,
int sched,
xce_job_t*** jobs)
int xce_joblist_ex(xce_ctx_t* ctx, int sched, xce_job_t*** jobs)
{
int table;
@ -349,20 +320,17 @@ int xce_joblist_ex(xce_ctx_t* ctx,
return xce_get(ctx, table, (void***)jobs);
}
int xce_sched_joblist(xce_ctx_t* ctx,
xce_job_t*** jobs)
int xce_sched_joblist(xce_ctx_t* ctx, xce_job_t*** jobs)
{
return xce_joblist_ex(ctx, 1, jobs);
}
int xce_joblist(xce_ctx_t* ctx,
xce_job_t*** jobs)
int xce_joblist(xce_ctx_t* ctx, xce_job_t*** jobs)
{
return xce_joblist_ex(ctx, 0, jobs);
}
int xce_varlist(xce_ctx_t* ctx,
xce_config_t*** vars)
int xce_varlist(xce_ctx_t* ctx, xce_config_t*** vars)
{
#if 0
int table = XCETables_conf;
@ -372,8 +340,7 @@ int xce_varlist(xce_ctx_t* ctx,
return 0;
}
int xce_queuelist(xce_ctx_t* ctx,
xce_queue_t*** queues)
int xce_queuelist(xce_ctx_t* ctx, xce_queue_t*** queues)
{
#if 0
int table = XCETables_queues;
@ -384,8 +351,7 @@ int xce_queuelist(xce_ctx_t* ctx,
#endif
}
int xce_free_queues(int nqueues,
xce_queue_t* queues)
int xce_free_queues(int nqueues, xce_queue_t* queues)
{
int i;
@ -399,9 +365,7 @@ int xce_free_queues(int nqueues,
return 0;
}
int xce_grouplist(xce_ctx_t* ctx,
int group_type,
xce_group_t*** groups)
int xce_grouplist(xce_ctx_t* ctx, int group_type, xce_group_t*** groups)
{
#if 0
int table;
@ -421,15 +385,13 @@ int xce_grouplist(xce_ctx_t* ctx,
#endif
}
int xce_free_groups(int ngroups,
xce_group_t* groups)
int xce_free_groups(int ngroups, xce_group_t* groups)
{
/* TODO */
return 0;
}
int xce_clusterconf(xce_ctx_t* ctx,
xce_clusterconf_t** conf)
int xce_clusterconf(xce_ctx_t* ctx, xce_clusterconf_t** conf)
{
ioctx_t* ioctx;
int rc, status;
@ -465,9 +427,7 @@ int xce_clusterconf(xce_ctx_t* ctx,
return 0;
}
int xce_update_resvals(xce_ctx_t* ctx,
int count,
xce_resval_t** vals)
int xce_update_resvals(xce_ctx_t* ctx, int count, xce_resval_t** vals)
{
ioctx_t* ioctx;
int rc;
@ -512,14 +472,8 @@ int xce_update_resvals(xce_ctx_t* ctx,
return status;
}
int xce_update_jusage(xce_ctx_t* ctx,
uint64_t jobid,
int npids,
int* pids,
int ngids,
int* pgids,
int nusage,
xce_rusage_t** usages)
int xce_update_jusage(xce_ctx_t* ctx, uint64_t jobid, int npids, int* pids,
int ngids, int* pgids, int nusage, xce_rusage_t** usages)
{
ioctx_t* ioctx;
int rc;
@ -567,8 +521,7 @@ int xce_update_jusage(xce_ctx_t* ctx,
return status;
}
int xce_jobctrl(xce_ctx_t* ctx,
xce_jobctrl_t* ctrl)
int xce_jobctrl(xce_ctx_t* ctx, xce_jobctrl_t* ctrl)
{
ioctx_t* ioctx;
int rc;
@ -600,8 +553,7 @@ int xce_jobctrl(xce_ctx_t* ctx,
return status;
}
int xce_queuectrl(xce_ctx_t* ctx,
xce_queuectrl_t* ctrl)
int xce_queuectrl(xce_ctx_t* ctx, xce_queuectrl_t* ctrl)
{
ioctx_t* ioctx;
int rc;
@ -633,8 +585,7 @@ int xce_queuectrl(xce_ctx_t* ctx,
return status;
}
int xce_runtask(xce_ctx_t* ctx,
xce_taskrun_t* runinfo)
int xce_runtask(xce_ctx_t* ctx, xce_taskrun_t* runinfo)
{
ioctx_t* ioctx;
int rc;

View file

@ -9,8 +9,7 @@
#include "utils.h"
#include "xcectx.h"
static int handle_get_reply(xce_ctx_t* ctx,
xce_reply_t* reply)
static int handle_get_reply(xce_ctx_t* ctx, xce_reply_t* reply)
{
xce_data_t* getdata = reply->data.getdata;
dataset_t* dataset = ctx->reply.u.get;
@ -18,8 +17,7 @@ static int handle_get_reply(xce_ctx_t* ctx,
return extract_data(dataset, getdata);
}
static int handle_sub_reply(xce_ctx_t* ctx,
xce_reply_t* reply)
static int handle_sub_reply(xce_ctx_t* ctx, xce_reply_t* reply)
{
if (reply->data_which != RequestReply_data_jobid) {
return -1;
@ -29,8 +27,7 @@ static int handle_sub_reply(xce_ctx_t* ctx,
return 1;
}
static int handle_reply(xce_ctx_t* ctx,
xce_reply_t* reply)
static int handle_reply(xce_ctx_t* ctx, xce_reply_t* reply)
{
int rc = 0;
@ -48,8 +45,7 @@ static int handle_reply(xce_ctx_t* ctx,
case OPCode_clusterconf:
rc = -1;
if (reply->data_which == RequestReply_data_clusterconf) {
MOVE_PTR(ctx->reply.u.clusterconf,
reply->data.clusterconf);
MOVE_PTR(ctx->reply.u.clusterconf, reply->data.clusterconf);
rc = 1;
}
break;
@ -93,15 +89,15 @@ static int vtask_entry(vtask_t* task)
} else {
int callnext = 1;
if ((request.opcode == OPCode_push) && (request.body_which == Request_body_pushmsg)) {
if ((request.opcode == OPCode_push)
&& (request.body_which == Request_body_pushmsg)) {
if (ctx->dataset == NULL) {
ctx->dataset = (dataset_t*)calloc(1, sizeof(dataset_t));
ctx->dataset->table = request.body.pushmsg->table;
}
callnext = extract_data(ctx->dataset,
request.body.pushmsg);
callnext = extract_data(ctx->dataset, request.body.pushmsg);
if (callnext) {
FREEUP(request.body.pushmsg);
request.body_which = Request_body_datamsg;
@ -200,9 +196,7 @@ static int handle_io(struct epoll_event* p)
return 0;
}
int xce_ctx_init(xce_ctx_t* ctx,
char* name,
char* key)
int xce_ctx_init(xce_ctx_t* ctx, char* name, char* key)
{
int rc;
@ -254,8 +248,7 @@ void xce_ctx_fini(xce_ctx_t* ctx)
return;
}
int xce_ctx_set_handler(xce_ctx_t* ctx,
xce_request_handler_t handler)
int xce_ctx_set_handler(xce_ctx_t* ctx, xce_request_handler_t handler)
{
if ((ctx == NULL) || (handler == NULL)) {
return -EINVAL;
@ -265,8 +258,7 @@ int xce_ctx_set_handler(xce_ctx_t* ctx,
return 0;
}
int xce_ctx_set_endpoint(xce_ctx_t* ctx,
endpoint_t* ep)
int xce_ctx_set_endpoint(xce_ctx_t* ctx, endpoint_t* ep)
{
if ((ctx == NULL) || (ep == NULL)) {
return -EINVAL;
@ -288,10 +280,8 @@ int xce_ctx_start(xce_ctx_t* ctx)
return -EINVAL;
}
endpoint_set_handler(ctx->ep,
handle_io, ctx);
rc = iomgr_monitor(&(ctx->iomgr),
ctx->ep);
endpoint_set_handler(ctx->ep, handle_io, ctx);
rc = iomgr_monitor(&(ctx->iomgr), ctx->ep);
if (rc < 0) {
ctx->state = XCE_CTX_ERR;
return rc;
@ -312,8 +302,7 @@ int xce_ctx_stop(xce_ctx_t* ctx)
}
if (ctx->ep != NULL) {
iomgr_unmonitor(&(ctx->iomgr),
ctx->ep);
iomgr_unmonitor(&(ctx->iomgr), ctx->ep);
ctx->ep = NULL;
}
iomgr_stop(&(ctx->iomgr));
@ -323,8 +312,7 @@ int xce_ctx_stop(xce_ctx_t* ctx)
return 0;
}
int xce_wakeup(xce_ctx_t* ctx,
int status)
int xce_wakeup(xce_ctx_t* ctx, int status)
{
int rc = 0;
@ -341,8 +329,7 @@ int xce_wakeup(xce_ctx_t* ctx,
return rc;
}
int xce_try_wakeup(xce_ctx_t* ctx,
int status)
int xce_try_wakeup(xce_ctx_t* ctx, int status)
{
if (ctx == NULL) {
return -EINVAL;

View file

@ -4,8 +4,7 @@
#include "utils.h"
#include "xlist.h"
int xlist_init(xlist_t* l,
int delta)
int xlist_init(xlist_t* l, int delta)
{
if ((l == NULL) || (delta <= 0)) {
return -EINVAL;
@ -44,8 +43,7 @@ static int xlist_ensure(xlist_t* l)
return 1;
}
int xlist_store(xlist_t* l,
void* data)
int xlist_store(xlist_t* l, void* data)
{
int rc;
@ -73,9 +71,7 @@ void xlist_clear(xlist_t* l)
l->count = 0;
}
int xlist_iter(xlist_t* l,
xlist_iter_fn_t fn,
void* data)
int xlist_iter(xlist_t* l, xlist_iter_fn_t fn, void* data)
{
int i;

View file

@ -13,13 +13,12 @@ static void xstring_type_fini(objtype_t*);
static xstring_typedata_t xstring_typedata;
static objtype_t xstring = {
.type = "xstring",
.fn_create = (obj_create_fn_t)xstring_create,
.fn_fini = xstring_fini,
.fn_type_fini = (objtype_fini_fn_t)xstring_type_fini,
.typedata = &xstring_typedata
};
static objtype_t xstring
= { .type = "xstring",
.fn_create = (obj_create_fn_t)xstring_create,
.fn_fini = xstring_fini,
.fn_type_fini = (objtype_fini_fn_t)xstring_type_fini,
.typedata = &xstring_typedata };
static void xstring_obj_killer(myobj_t* obj)
{
@ -31,21 +30,16 @@ static void xstring_obj_killer(myobj_t* obj)
free(obj);
}
int register_xstring(objmgr_t* mgr,
int nslots,
int delta)
int register_xstring(objmgr_t* mgr, int nslots, int delta)
{
ht_init(&(xstring_typedata.tab), nslots,
string_hash_key);
ht_init(&(xstring_typedata.tab), nslots, string_hash_key);
zarray_init(&(xstring_typedata.strings), delta,
(zarray_item_killer_t)xstring_obj_killer);
return objmgr_register(mgr, &xstring);
}
static void* xstring_create(objmgr_t* mgr,
objtype_t* type,
va_list ap)
static void* xstring_create(objmgr_t* mgr, objtype_t* type, va_list ap)
{
char* s = va_arg(ap, char*);
char* p = NULL;

View file

@ -5,9 +5,7 @@
#include "utils.h"
#include "zarray.h"
int zarray_init(zarray_t* array,
int delta,
zarray_item_killer_t killer)
int zarray_init(zarray_t* array, int delta, zarray_item_killer_t killer)
{
if ((array == NULL) || (delta <= 0)) {
return -EINVAL;
@ -24,8 +22,7 @@ int zarray_init(zarray_t* array,
return 0;
}
static int zarray_ensure_items(zarray_t* array,
int mincap)
static int zarray_ensure_items(zarray_t* array, int mincap)
{
int nc, i;
void* p;
@ -58,8 +55,7 @@ static int zarray_ensure_items(zarray_t* array,
return 1;
}
int zarray_store(zarray_t* array,
void* data)
int zarray_store(zarray_t* array, void* data)
{
int rc, i;
@ -99,8 +95,7 @@ int zarray_store(zarray_t* array,
return rc;
}
int zarray_clear(zarray_t* array,
int idx)
int zarray_clear(zarray_t* array, int idx)
{
if (array == NULL) {
return -EINVAL;
@ -141,9 +136,7 @@ void zarray_fini(zarray_t* array)
}
}
int zarray_iter_ex(zarray_t* array,
xlist_t* l,
void* arg)
int zarray_iter_ex(zarray_t* array, xlist_t* l, void* arg)
{
int i, j;
@ -169,9 +162,7 @@ int zarray_iter_ex(zarray_t* array,
return 0;
}
int zarray_iter(zarray_t* array,
zarray_iter_fn_t f,
void* arg)
int zarray_iter(zarray_t* array, zarray_iter_fn_t f, void* arg)
{
int rc;
xlist_t l;
@ -189,8 +180,7 @@ int zarray_iter(zarray_t* array,
return rc;
}
int zarray_del(zarray_t* array,
int idx)
int zarray_del(zarray_t* array, int idx)
{
void* ptr = NULL;
@ -222,9 +212,7 @@ int zarray_del(zarray_t* array,
return 0;
}
int zarray_put(zarray_t* array,
int idx,
void* data)
int zarray_put(zarray_t* array, int idx, void* data)
{
int rc = 0;
@ -255,8 +243,7 @@ int zarray_put(zarray_t* array,
return rc;
}
void* zarray_get(zarray_t* array,
int idx)
void* zarray_get(zarray_t* array, int idx)
{
void* ptr = NULL;