use nix build & meson & zlog
This commit is contained in:
parent
0123623742
commit
346768a144
60 changed files with 13739 additions and 0 deletions
667
src/lib/xceapi.c
Normal file
667
src/lib/xceapi.c
Normal file
|
|
@ -0,0 +1,667 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "xceapi.h"
|
||||
|
||||
int xce_hello(xce_ctx_t* ctx,
|
||||
char* msg)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc, status;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_hello_req(ioctx, msg);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int xce_shutdown(xce_ctx_t* ctx)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc;
|
||||
int status;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_shutdown_req(ioctx);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ctx->reply.u.get = &getreply;
|
||||
rc = xce_get_req(ioctx, &get);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (status >= 0) {
|
||||
*data = getreply.rows;
|
||||
rc = getreply.nrows;
|
||||
} else {
|
||||
rc = status;
|
||||
}
|
||||
|
||||
ctx->reply.u.get = NULL;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc;
|
||||
int status;
|
||||
/* clang-format off */
|
||||
xce_reskey_t reskey = {
|
||||
.resname = res,
|
||||
.hostname = host
|
||||
};
|
||||
xce_match_t condition = {
|
||||
.type = MatchCondition_condition_matchreskey,
|
||||
.condition = {
|
||||
.reskey = &reskey
|
||||
}
|
||||
};
|
||||
xce_get_t get = {
|
||||
.table = Data_data_resvals,
|
||||
.condition = &condition
|
||||
};
|
||||
dataset_t getreply = {
|
||||
.table = Data_data_resvals,
|
||||
.nrows = 0,
|
||||
.rows = NULL
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ctx->reply.u.get = &getreply;
|
||||
rc = xce_get_req(ioctx, &get);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (status >= 0) {
|
||||
*vals = (xce_resval_t**)getreply.rows;
|
||||
rc = getreply.nrows;
|
||||
} else {
|
||||
rc = status;
|
||||
}
|
||||
|
||||
ctx->reply.u.get = NULL;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int xce_join(xce_ctx_t* ctx,
|
||||
int role,
|
||||
hostattrs_t* attrs)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc, status;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_join_req(ioctx, role, attrs);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
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_jobdispatch(xce_ctx_t* ctx,
|
||||
xce_job_dispatch_t* info)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc, status;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_jobdispatch_req(ioctx, info);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int xce_notify(xce_ctx_t* ctx,
|
||||
xce_notify_data_t* data)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_notify_req(ioctx, data);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int xce_jobsubmit(xce_ctx_t* ctx,
|
||||
xce_job_submit_t* submit,
|
||||
uint64_t* jobid)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc, status;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_jobsubmit_req(ioctx, submit);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (status >= 0) {
|
||||
*jobid = ctx->reply.u.jobid;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int xce_joblist_ex(xce_ctx_t* ctx,
|
||||
int sched,
|
||||
xce_job_t*** jobs)
|
||||
{
|
||||
int table;
|
||||
|
||||
if (sched) {
|
||||
table = Data_data_schedjobs;
|
||||
} else {
|
||||
table = Data_data_jobs;
|
||||
}
|
||||
|
||||
return xce_get(ctx, table, (void***)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)
|
||||
{
|
||||
return xce_joblist_ex(ctx, 0, jobs);
|
||||
}
|
||||
|
||||
int xce_varlist(xce_ctx_t* ctx,
|
||||
xce_config_t*** vars)
|
||||
{
|
||||
#if 0
|
||||
int table = XCETables_conf;
|
||||
|
||||
return xce_get(ctx, table, (void***)vars);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xce_queuelist(xce_ctx_t* ctx,
|
||||
xce_queue_t*** queues)
|
||||
{
|
||||
#if 0
|
||||
int table = XCETables_queues;
|
||||
|
||||
return xce_get(ctx, table, (void***)queues);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int xce_free_queues(int nqueues,
|
||||
xce_queue_t* queues)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (queues == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < nqueues; i++) {
|
||||
FREEUP(queues[i].resreq);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xce_grouplist(xce_ctx_t* ctx,
|
||||
int group_type,
|
||||
xce_group_t*** groups)
|
||||
{
|
||||
#if 0
|
||||
int table;
|
||||
|
||||
switch (group_type) {
|
||||
case 0:
|
||||
table = XCETables_ugroups;
|
||||
break;
|
||||
default:
|
||||
table = XCETables_hgroups;
|
||||
break;
|
||||
}
|
||||
|
||||
return xce_get(ctx, table, (void***)groups);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int xce_free_groups(int ngroups,
|
||||
xce_group_t* groups)
|
||||
{
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xce_clusterconf(xce_ctx_t* ctx,
|
||||
xce_clusterconf_t** conf)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc, status;
|
||||
|
||||
if ((ctx == NULL) || (conf == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_clusterconf_req(ioctx);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (status < 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
MOVE_PTR((*conf), ctx->reply.u.clusterconf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xce_update_resvals(xce_ctx_t* ctx,
|
||||
int count,
|
||||
xce_resval_t** vals)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc;
|
||||
int status;
|
||||
|
||||
/* clang-format off */
|
||||
xce_resval_list_t valist = {
|
||||
.count = count,
|
||||
.vals = vals
|
||||
};
|
||||
xce_update_data_t data = {
|
||||
.table = Update_data_resvals,
|
||||
.data = {
|
||||
.resvals = &valist
|
||||
}
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_update_req(ioctx, &data);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc;
|
||||
int status;
|
||||
|
||||
/* clang-format off */
|
||||
xce_job_rusages_t rusages = {
|
||||
.jobid = jobid,
|
||||
.npids = npids,
|
||||
.pids = pids,
|
||||
.pgids = pgids,
|
||||
.count = nusage,
|
||||
.usages = usages
|
||||
};
|
||||
xce_update_data_t data = {
|
||||
.table = Update_data_jobrusages,
|
||||
.data = {
|
||||
.jobrusages = &rusages }
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_update_req(ioctx, &data);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int xce_jobctrl(xce_ctx_t* ctx,
|
||||
xce_jobctrl_t* ctrl)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc;
|
||||
int status;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_jobctrl_req(ioctx, ctrl);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int xce_queuectrl(xce_ctx_t* ctx,
|
||||
xce_queuectrl_t* ctrl)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc;
|
||||
int status;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_queuectrl_req(ioctx, ctrl);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int xce_runtask(xce_ctx_t* ctx,
|
||||
xce_taskrun_t* runinfo)
|
||||
{
|
||||
ioctx_t* ioctx;
|
||||
int rc;
|
||||
int status;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->state != XCE_CTX_RUN) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
|
||||
if (ioctx == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
rc = xce_runtask_req(ioctx, runinfo);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cbuf_get(&(ctx->wbuf), &status);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue