security communication with openssl and simplify netio

This commit is contained in:
Rongsong Shen 2025-11-18 11:21:24 +08:00
parent 2a7b7c39bb
commit 8f796b3109
20 changed files with 1176 additions and 922 deletions

View file

@ -53,6 +53,9 @@ int xcecli_ctx_init(xcecli_ctx_t* c, xce_client_config_t* cfg)
endpoint_init(&(ctx->ep), AF_INET, SOCK_STREAM, 0, 0);
/* set information for endpoint */
endpoint_set_peer(&(ctx->ep), &(ctx->ctx.myinfo));
xce_ctx_set_endpoint(&(ctx->ctx), &(ctx->ep));
*c = (void*)ctx;
@ -68,7 +71,7 @@ void xcecli_ctx_fini(xcecli_ctx_t c)
}
xce_ctx_fini(&(ctx->ctx));
endpoint_deref(&(ctx->ep));
endpoint_fini(&(ctx->ep));
free(ctx);
}
@ -118,11 +121,13 @@ int xcecli_start(xcecli_ctx_t c)
rc = endpoint_connect(&(ctx->ep), ctx->conf->masters[0],
ctx->conf->master_ports[0]);
if (rc < 0) {
endpoint_deref(&(ctx->ep));
endpoint_fini(&(ctx->ep));
return rc;
}
return xce_ctx_start(&(ctx->ctx));
rc = xce_ctx_start(&(ctx->ctx));
return rc;
}
int xcecli_stop(xcecli_ctx_t c)
@ -134,7 +139,7 @@ int xcecli_stop(xcecli_ctx_t c)
}
xce_ctx_stop(&(ctx->ctx));
endpoint_deref(&(ctx->ep));
endpoint_fini(&(ctx->ep));
return 0;
}

View file

@ -41,8 +41,9 @@ thread_dep = dependency('threads')
c_capnproto_dep = dependency('c-capnproto')
tinylog_dep = dependency('tinylog')
unity_dep = dependency('unity')
ssl_dep = dependency('openssl')
libxce_deps = [c_capnproto_dep, tinylog_dep, thread_dep]
libxce_deps = [c_capnproto_dep, ssl_dep, tinylog_dep, thread_dep]
libxce = static_library('xce',
libxce_src,

File diff suppressed because it is too large Load diff

View file

@ -11,134 +11,94 @@
#include "utils.h"
#include "xce/types.h"
ioctx_t* ioctx_alloc(endpoint_t* ep, xce_peerinfo_t* peer)
{
ioctx_t* ctx;
ctx = (ioctx_t*)calloc(1, sizeof(*ctx));
if (ctx == NULL) {
errno = -ENOMEM;
return NULL;
}
ctx->ep = endpoint_ref(ep);
ctx->from = peer;
ctx->nrefs++;
return ctx;
}
int ioctx_ref(ioctx_t* ctx)
{
int old = ctx->nrefs;
ctx->nrefs++;
return old;
}
static void ioctx_kill(ioctx_t* ctx, int free_ctx)
{
if (ctx == NULL) {
return;
}
endpoint_deref(ctx->ep);
free_packet(&(ctx->pkt));
capn_free(&(ctx->c));
if (free_ctx) {
free(ctx);
}
}
void ioctx_deref(ioctx_t* ctx, int free_ctx)
{
if (ctx == NULL) {
return;
}
if (ctx->nrefs == 0) {
WARN("Something wrong. Have you forgotten to call ioctx_ref()?");
return;
}
ctx->nrefs--;
if (ctx->nrefs == 0) {
ioctx_kill(ctx, free_ctx);
}
}
int ioctx_encode(ioctx_t* ctx, xce_request_t* req)
int xce_encode(xce_request_t* req, io_packet_t* pkt)
{
struct capn c;
struct Request rq;
struct capn_segment* cs;
Request_ptr rp;
int rc;
capn_init_malloc(&(ctx->c));
cs = capn_root(&(ctx->c)).seg;
TRACE("%s request op %d seq %ld", __func__, req->opcode, req->seq);
encode_Request(cs, &(ctx->rq), req);
capn_init_malloc(&c);
cs = capn_root(&c).seg;
cs = capn_root(&(ctx->c)).seg;
encode_Request(cs, &rq, req);
cs = capn_root(&c).seg;
rp = new_Request(cs);
write_Request(&(ctx->rq), rp);
write_Request(&rq, rp);
capn_setp(capn_root(&(ctx->c)), 0, rp.p);
capn_setp(capn_root(&c), 0, rp.p);
ctx->pkt.sz = capn_size(&(ctx->c));
rc = alloc_packet(&(ctx->pkt));
pkt->sz = capn_size(&c);
rc = alloc_packet(pkt);
if (rc < 0) {
return rc;
capn_free(&c);
return -errno;
}
capn_write_mem(&(ctx->c), (uint8_t*)ctx->pkt.data, ctx->pkt.sz, 0);
return 0;
capn_write_mem(&c, (uint8_t*)pkt->data, pkt->sz, 0);
capn_free(&c);
return 1;
}
int ioctx_decode(ioctx_t* ctx, xce_request_t* req)
int xce_decode(io_packet_t* pkt, xce_request_t* req)
{
Request_ptr rp;
struct capn c;
struct Request rq;
Request_ptr rp;
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);
capn_init_mem(&c, (const uint8_t*)pkt->data, pkt->sz, 0);
rp.p = capn_getp(capn_root(&c), 0, 1);
read_Request(&(ctx->rq), rp);
read_Request(&rq, rp);
decode_Request(req, &(ctx->rq));
decode_Request(req, &rq);
TRACE("%s request opcode %d seq %ld", __func__, req->opcode, req->seq);
capn_free(&c);
free_packet(pkt);
FREEUP(pkt);
return 0;
}
int ioctx_flush(ioctx_t* ctx, int fd)
{
int rc;
rc = write_packet(fd, &(ctx->pkt));
return rc;
}
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(endpoint_t* ep, xce_request_t* req)
{
int rc;
int rc;
io_packet_t* pkt;
req->seq = endpoint_getseq(ctx->ep);
req->from = ctx->from;
pkt = (io_packet_t*)calloc(1, sizeof(*pkt));
if (pkt == NULL) {
return -ENOMEM;
}
rc = ioctx_encode(ctx, req);
req->seq = endpoint_getseq(ep);
req->from = ep->peer;
rc = xce_encode(req, pkt);
if (rc < 0) {
free_packet(pkt);
free(pkt);
return rc;
}
endpoint_enq(ctx->ep, &(ctx->link));
endpoint_enq(ep, &(pkt->link));
return 0;
}
int xce_reply_with_ctx(ioctx_t* ctx, xce_peerinfo_t* from, xce_reply_t* reply)
int xce_reply(endpoint_t* ep, xce_peerinfo_t* from, xce_reply_t* reply)
{
/* clang-format off */
xce_request_t request = {
@ -146,50 +106,47 @@ int xce_reply_with_ctx(ioctx_t* ctx, xce_peerinfo_t* from, xce_reply_t* reply)
.body_which = Request_body_replymsg,
};
/* clang-format on */
int rc;
int rc;
io_packet_t* pkt;
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;
request.seq = endpoint_getseq(ctx->ep);
rc = ioctx_encode(ctx, &request);
if (rc < 0) {
return rc;
}
endpoint_enq(ctx->ep, &(ctx->link));
return 0;
}
int xce_reply(endpoint_t* ep, xce_peerinfo_t* from, xce_reply_t* reply)
{
ioctx_t* ctx;
ctx = ioctx_alloc(ep, from);
if (ctx == NULL) {
pkt = (io_packet_t*)calloc(1, sizeof(*pkt));
if (pkt == NULL) {
return -ENOMEM;
}
return xce_reply_with_ctx(ctx, from, reply);
request.from = from;
request.body.replymsg = reply;
request.seq = endpoint_getseq(ep);
rc = xce_encode(&request, pkt);
if (rc < 0) {
free_packet(pkt);
free(pkt);
return rc;
}
endpoint_enq(ep, &(pkt->link));
return 0;
}
int xce_nop_req(ioctx_t* ctx)
int xce_nop_req(endpoint_t* ep)
{
xce_request_t request
= { .opcode = OPCode_nop, .body_which = Request_body_nomsg };
if (ctx == NULL) {
if (ep == NULL) {
return -EINVAL;
}
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_hello_req(ioctx_t* ctx, char* msg)
int xce_hello_req(endpoint_t* ep, char* msg)
{
/* clang-format off */
xce_request_t request = {
@ -201,13 +158,13 @@ int xce_hello_req(ioctx_t* ctx, char* msg)
};
/* clang-format on */
if ((ctx == NULL) || (msg == NULL)) {
if ((ep == NULL) || (msg == NULL)) {
return -EINVAL;
}
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_join_req(ioctx_t* ctx, int role, hostattrs_t* attrs)
int xce_join_req(endpoint_t* ep, int role, hostattrs_t* attrs)
{
/* clang-format off */
xce_joindata_t joinmsg = {
@ -222,8 +179,8 @@ int xce_join_req(ioctx_t* ctx, int role, hostattrs_t* attrs)
};
if ((role != HostRole_client) &&
(role != HostRole_worker) &&
(role != HostRole_scheduler)) {
(role != HostRole_worker) &&
(role != HostRole_scheduler)) {
return -EINVAL;
}
/* clang-format on */
@ -236,26 +193,26 @@ int xce_join_req(ioctx_t* ctx, int role, hostattrs_t* attrs)
joinmsg.data_which = JoinData_data_attrs;
joinmsg.data.attrs = attrs;
}
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_shutdown_req(ioctx_t* ctx)
int xce_shutdown_req(endpoint_t* ep)
{
int rc;
dataq_t* outq;
xce_request_t request
= { .opcode = OPCode_shutdown, .body_which = Request_body_nomsg };
if (ctx == NULL) {
if (ep == NULL) {
return -EINVAL;
}
rc = xce_request(ctx, &request);
rc = xce_request(ep, &request);
if (rc < 0) {
return rc;
}
outq = &(ctx->ep->outq);
outq = &(ep->outq);
while (!DATAQ_EMPTY(outq)) {
sleep(1);
@ -267,30 +224,25 @@ int xce_shutdown_req(ioctx_t* ctx)
int xce_pushconfig_req(endpoint_t* ep, xce_peerinfo_t* from,
xce_configdata_t* config)
{
int rc = 0;
int rc = 0;
/* clang-format off */
xce_request_t request
= { .opcode = OPCode_push, .body_which = Request_body_configpushmsg };
ioctx_t* ctx = NULL;
/* clang-format on */
if ((ep == NULL) || (config == NULL)) {
return -EINVAL;
}
ctx = ioctx_alloc(ep, from);
if (ctx == NULL) {
return -ENOMEM;
}
request.body.configpushmsg = config;
rc = xce_request(ctx, &request);
rc = xce_request(ep, &request);
return rc;
}
static int xce_push_req(endpoint_t* ep, xce_peerinfo_t* from, xce_data_t* data)
{
int rc = 0;
ioctx_t* ctx = NULL;
int rc = 0;
xce_request_t request
= { .opcode = OPCode_push, .body_which = Request_body_pushmsg };
@ -298,14 +250,9 @@ static int xce_push_req(endpoint_t* ep, xce_peerinfo_t* from, xce_data_t* data)
return -EINVAL;
}
ctx = ioctx_alloc(ep, from);
if (ctx == NULL) {
return -ENOMEM;
}
request.body.pushmsg = data;
rc = xce_request(ctx, &request);
rc = xce_request(ep, &request);
return rc;
}
@ -416,7 +363,7 @@ int xce_push_data_req(endpoint_t* ep, xce_peerinfo_t* from, xce_data_t* data,
return rc;
}
int xce_get_req(ioctx_t* ctx, xce_get_t* get)
int xce_get_req(endpoint_t* ep, xce_get_t* get)
{
/* clang-format off */
xce_request_t request = {
@ -428,7 +375,7 @@ int xce_get_req(ioctx_t* ctx, xce_get_t* get)
};
/* clang-format on */
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_reply_get(endpoint_t* ep, xce_peerinfo_t* from, xce_reply_t* reply,
@ -699,7 +646,7 @@ int extract_data(dataset_t* dataset, xce_data_t* getdata)
return 1;
}
int xce_jobdispatch_req(ioctx_t* ctx, xce_job_dispatch_t* info)
int xce_jobdispatch_req(endpoint_t* ep, xce_job_dispatch_t* info)
{
/* clang-format off */
xce_request_t request = {
@ -712,16 +659,16 @@ int xce_jobdispatch_req(ioctx_t* ctx, xce_job_dispatch_t* info)
/* clang-format on */
/* clang-format off */
if ((ctx == NULL) ||
(info == NULL)) {
if ((ep == NULL) ||
(info == NULL)) {
return -EINVAL;
}
/* clang-format on */
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_notify_req(ioctx_t* ctx, xce_notify_data_t* data)
int xce_notify_req(endpoint_t* ep, xce_notify_data_t* data)
{
/* clang-format off */
xce_request_t request = {
@ -731,17 +678,16 @@ int xce_notify_req(ioctx_t* ctx, xce_notify_data_t* data)
.notifymsg = data
}
};
/* clang-forn on */
/* clang-format on */
if ((ctx == NULL) || (data == NULL)) {
return -EINVAL;
if ((ep == NULL) || (data == NULL)) {
return -EINVAL;
}
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_jobsubmit_req(ioctx_t* ctx,
xce_job_submit_t* submit)
int xce_jobsubmit_req(endpoint_t* ep, xce_job_submit_t* submit)
{
/* clang-format off */
xce_request_t request = {
@ -754,16 +700,16 @@ int xce_jobsubmit_req(ioctx_t* ctx,
/*clang-format on*/
/* clang-format off */
if ((ctx == NULL) ||
(submit == NULL)) {
return -EINVAL;
if ((ep == NULL) ||
(submit == NULL)) {
return -EINVAL;
}
/* clang-format on */
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_startjob_req(ioctx_t* ctx, xce_job_exec_t* execinfo)
int xce_startjob_req(endpoint_t* ep, xce_job_exec_t* execinfo)
{
/* clang-format off */
xce_request_t request = {
@ -775,10 +721,10 @@ int xce_startjob_req(ioctx_t* ctx, xce_job_exec_t* execinfo)
};
/* clang-format on */
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_clusterconf_req(ioctx_t* ctx)
int xce_clusterconf_req(endpoint_t* ep)
{
/* clang-format off */
xce_request_t request = {
@ -787,10 +733,10 @@ int xce_clusterconf_req(ioctx_t* ctx)
};
/* clang-format on */
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_update_req(ioctx_t* ctx, xce_update_data_t* data)
int xce_update_req(endpoint_t* ep, xce_update_data_t* data)
{
/* clang-format off */
xce_request_t request = {
@ -802,14 +748,14 @@ int xce_update_req(ioctx_t* ctx, xce_update_data_t* data)
};
/* clang-format on */
if ((ctx == NULL) || (data == NULL)) {
if ((ep == NULL) || (data == NULL)) {
return -EINVAL;
}
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_jobctrl_req(ioctx_t* ctx, xce_jobctrl_t* ctrinfo)
int xce_jobctrl_req(endpoint_t* ep, xce_jobctrl_t* ctrinfo)
{
/* clang-format off */
xce_request_t request = {
@ -821,7 +767,7 @@ int xce_jobctrl_req(ioctx_t* ctx, xce_jobctrl_t* ctrinfo)
};
/* clang-format on */
if ((ctx == NULL) || (ctrinfo == NULL)) {
if ((ep == NULL) || (ctrinfo == NULL)) {
return -EINVAL;
}
@ -841,10 +787,10 @@ int xce_jobctrl_req(ioctx_t* ctx, xce_jobctrl_t* ctrinfo)
return -EINVAL;
break;
}
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_queuectrl_req(ioctx_t* ctx, xce_queuectrl_t* ctrlinfo)
int xce_queuectrl_req(endpoint_t* ep, xce_queuectrl_t* ctrlinfo)
{
/* clang-format off */
xce_request_t request = {
@ -856,7 +802,7 @@ int xce_queuectrl_req(ioctx_t* ctx, xce_queuectrl_t* ctrlinfo)
};
/* clang-format on */
if ((ctx == NULL) || (ctrlinfo == NULL)) {
if ((ep == NULL) || (ctrlinfo == NULL)) {
return -EINVAL;
}
@ -872,10 +818,10 @@ int xce_queuectrl_req(ioctx_t* ctx, xce_queuectrl_t* ctrlinfo)
return -EINVAL;
}
return xce_request(ctx, &request);
return xce_request(ep, &request);
}
int xce_runtask_req(ioctx_t* ctx, xce_taskrun_t* runinfo)
int xce_runtask_req(endpoint_t* ep, xce_taskrun_t* runinfo)
{
/* clang-format off */
xce_request_t request = {
@ -887,7 +833,7 @@ int xce_runtask_req(ioctx_t* ctx, xce_taskrun_t* runinfo)
};
/* clang-format on */
if ((ctx == NULL) || (runinfo == NULL)) {
if ((ep == NULL) || (runinfo == NULL)) {
return -EINVAL;
}
@ -895,5 +841,5 @@ int xce_runtask_req(ioctx_t* ctx, xce_taskrun_t* runinfo)
return -EINVAL;
}
return xce_request(ctx, &request);
return xce_request(ep, &request);
}

View file

@ -58,7 +58,7 @@ static void test_idgen_array(void)
for (k = 0; k < 5; k++) {
rc = idgen(&ctx, 0x0, 0x0, i + 1, &idx);
TEST_ASSERT_TRUE(rc >= 0);
if ( i >= 1) {
if (i >= 1) {
TEST_ASSERT_TRUE((idx & MAX_ARRAY_IDX) == 0);
}
printf("\tidx = %lx\n", idx);

View file

@ -18,22 +18,14 @@ 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, void* data)
{
int rc;
task->entry = entry;
task->vcpu = -1;
task->data = data;
task->owner = NULL;
task->entry = entry;
task->vcpu = -1;
task->ctx.ep = endpoint_ref(ep);
rc = read_packet(ep->fd, &(task->ctx.pkt));
if (rc < 0) {
free_packet(&(task->ctx.pkt));
endpoint_deref(task->ctx.ep);
task->ctx.ep = NULL;
}
return rc;
return 0;
}
void vtask_fini(vtask_t* task)
@ -42,7 +34,7 @@ void vtask_fini(vtask_t* task)
return;
}
ioctx_deref(&(task->ctx), 0);
FREEUP(task->data);
return;
}
@ -59,13 +51,22 @@ void vcpu_idle(vcpu_t* vcpu)
void run_task(vtask_t* task)
{
vtaskmgr_t* vtaskmgr;
vtaskmgr_t* vtaskmgr;
vtask_data_t* data;
if (task->entry != NULL) {
(task->entry)(task);
}
endpoint_unblock_tasks(task->ctx.ep);
data = task->data;
if ((data != NULL) && (data->vtype == VTASK_IO)) {
endpoint_t* ep = data->u.iodata.ep;
if (ep != NULL) {
endpoint_unblock_tasks(ep);
}
}
vtaskmgr = (vtaskmgr_t*)task->owner;
if (vtaskmgr != NULL) {
/* wake up dispatcher */
@ -201,15 +202,21 @@ static vcpu_t* pick_idle_vcpu(vtaskmgr_t* vtaskmgr)
static int vtask_eligible(data_item_t* data)
{
vtask_t* task = ITPTR_TO_VTASK(data);
int eligible = 0;
vtask_t* task = ITPTR_TO_VTASK(data);
int eligible = 0;
vtask_data_t* vdata;
if (task->ctx.ep == NULL) {
vdata = task->data;
if ((vdata == NULL) || (vdata->vtype != VTASK_IO)) {
return 1;
}
if (vdata->u.iodata.ep == NULL) {
WARN("no endpoint for task 0x%p", task);
return 0;
}
eligible = !(endpoint_is_task_blocked(task->ctx.ep));
eligible = !(endpoint_is_task_blocked(vdata->u.iodata.ep));
TRACE("%s vtask %p is %s", __func__, task,
eligible ? "eligible" : "not eligible");
@ -236,7 +243,11 @@ static int bind_vtask(vtask_t* task, vcpu_t* vcpu)
TRACE("binding task %p to cpu#%d\n", task, vcpu->cpuid);
if (task != NULL) {
endpoint_block_tasks(task->ctx.ep);
vtask_data_t* data = (vtask_data_t*)task->data;
if ((data->vtype == VTASK_IO) && (data->u.iodata.ep != NULL)) {
endpoint_block_tasks(data->u.iodata.ep);
}
task->vcpu = vcpu->cpuid;
}
@ -331,9 +342,8 @@ void vtaskmgr_fini(vtaskmgr_t* vtaskmgr)
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->link));
if (rc >= 0) {
/* wake up task dispatcher */
task->owner = vtaskmgr;
@ -342,3 +352,37 @@ int vtask_enq(vtaskmgr_t* vtaskmgr, vtask_t* task)
return rc;
}
int vtask_handle_msg(vtaskmgr_t* mgr, vtask_func_t entry, void* arg)
{
endpoint_t* ep = (endpoint_t*)arg;
vtask_data_t* data;
vtask_t* task;
if (ep == NULL) {
return -EINVAL;
}
if ((ep->fsm_in.state != FSM_STATE_DONE) || (ep->fsm_in.pkt == NULL)) {
return -EINVAL;
}
data = (vtask_data_t*)calloc(1, sizeof(*data));
if (data == NULL) {
return -ENOMEM;
}
task = (vtask_t*)calloc(1, sizeof(*task));
if (task == NULL) {
free(data);
return -ENOMEM;
}
data->vtype = VTASK_IO;
data->u.iodata.ep = ep;
data->u.iodata.pkt = ep->fsm_in.pkt;
vtask_init(task, entry, data);
return vtask_enq(mgr, task);
}

View file

@ -5,8 +5,7 @@
int xce_hello(xce_ctx_t* ctx, char* msg)
{
ioctx_t* ioctx;
int rc, status;
int rc, status;
if (ctx == NULL) {
return -EINVAL;
@ -16,12 +15,7 @@ int xce_hello(xce_ctx_t* ctx, char* msg)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_hello_req(ioctx, msg);
rc = xce_hello_req(ctx->ep, msg);
if (rc < 0) {
return rc;
}
@ -35,9 +29,7 @@ int xce_hello(xce_ctx_t* ctx, char* msg)
int xce_shutdown(xce_ctx_t* ctx)
{
ioctx_t* ioctx;
int rc;
int status;
int rc;
if (ctx == NULL) {
return -EINVAL;
@ -47,27 +39,14 @@ int xce_shutdown(xce_ctx_t* ctx)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_shutdown_req(ctx->ep);
rc = xce_shutdown_req(ioctx);
if (rc < 0) {
return rc;
}
rc = cbuf_get(&(ctx->wbuf), &status);
if (rc < 0) {
return rc;
}
return status;
/* do not need wait controller back as it will be shutdown */
return rc;
}
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 };
@ -82,13 +61,8 @@ int xce_get(xce_ctx_t* ctx, int table, void*** data)
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);
rc = xce_get_req(ctx->ep, &get);
if (rc < 0) {
return rc;
}
@ -119,28 +93,27 @@ int xce_reslist(xce_ctx_t* ctx, xce_resource_t*** res)
int xce_resval(xce_ctx_t* ctx, char* host, char* res, xce_resval_t*** vals)
{
ioctx_t* ioctx;
int rc;
int status;
int rc;
int status;
/* clang-format off */
xce_reskey_t reskey = {
.resname = res,
.hostname = host
.resname = res,
.hostname = host
};
xce_match_t condition = {
.type = MatchCondition_condition_matchreskey,
.condition = {
.reskey = &reskey
}
.type = MatchCondition_condition_matchreskey,
.condition = {
.reskey = &reskey
}
};
xce_get_t get = {
.table = Data_data_resvals,
.condition = &condition
.table = Data_data_resvals,
.condition = &condition
};
dataset_t getreply = {
.table = Data_data_resvals,
.nrows = 0,
.rows = NULL
.table = Data_data_resvals,
.nrows = 0,
.rows = NULL
};
/* clang-format on */
@ -152,13 +125,8 @@ int xce_resval(xce_ctx_t* ctx, char* host, char* res, xce_resval_t*** vals)
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);
rc = xce_get_req(ctx->ep, &get);
if (rc < 0) {
return rc;
}
@ -182,8 +150,7 @@ int xce_resval(xce_ctx_t* ctx, char* host, char* res, xce_resval_t*** vals)
int xce_join(xce_ctx_t* ctx, int role, hostattrs_t* attrs)
{
ioctx_t* ioctx;
int rc, status;
int rc, status;
if (ctx == NULL) {
return -EINVAL;
@ -193,12 +160,7 @@ int xce_join(xce_ctx_t* ctx, int role, hostattrs_t* attrs)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_join_req(ioctx, role, attrs);
rc = xce_join_req(ctx->ep, role, attrs);
if (rc < 0) {
return rc;
}
@ -221,8 +183,7 @@ 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;
int rc, status;
if (ctx == NULL) {
return -EINVAL;
@ -232,12 +193,7 @@ int xce_jobdispatch(xce_ctx_t* ctx, xce_job_dispatch_t* info)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_jobdispatch_req(ioctx, info);
rc = xce_jobdispatch_req(ctx->ep, info);
if (rc < 0) {
return rc;
}
@ -252,8 +208,7 @@ int xce_jobdispatch(xce_ctx_t* ctx, xce_job_dispatch_t* info)
int xce_notify(xce_ctx_t* ctx, xce_notify_data_t* data)
{
ioctx_t* ioctx;
int rc;
int rc;
if (ctx == NULL) {
return -EINVAL;
@ -263,20 +218,14 @@ int xce_notify(xce_ctx_t* ctx, xce_notify_data_t* data)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_notify_req(ioctx, data);
rc = xce_notify_req(ctx->ep, data);
return rc;
}
int xce_jobsubmit(xce_ctx_t* ctx, xce_job_submit_t* submit, uint64_t* jobid)
{
ioctx_t* ioctx;
int rc, status;
int rc, status;
if (ctx == NULL) {
return -EINVAL;
@ -286,12 +235,7 @@ int xce_jobsubmit(xce_ctx_t* ctx, xce_job_submit_t* submit, uint64_t* jobid)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_jobsubmit_req(ioctx, submit);
rc = xce_jobsubmit_req(ctx->ep, submit);
if (rc < 0) {
return rc;
}
@ -393,8 +337,7 @@ int xce_free_groups(int ngroups, xce_group_t* groups)
int xce_clusterconf(xce_ctx_t* ctx, xce_clusterconf_t** conf)
{
ioctx_t* ioctx;
int rc, status;
int rc, status;
if ((ctx == NULL) || (conf == NULL)) {
return -EINVAL;
@ -404,12 +347,7 @@ int xce_clusterconf(xce_ctx_t* ctx, xce_clusterconf_t** conf)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_clusterconf_req(ioctx);
rc = xce_clusterconf_req(ctx->ep);
if (rc < 0) {
return rc;
}
@ -429,9 +367,8 @@ int xce_clusterconf(xce_ctx_t* ctx, xce_clusterconf_t** conf)
int xce_update_resvals(xce_ctx_t* ctx, int count, xce_resval_t** vals)
{
ioctx_t* ioctx;
int rc;
int status;
int rc;
int status;
/* clang-format off */
xce_resval_list_t valist = {
@ -454,12 +391,7 @@ int xce_update_resvals(xce_ctx_t* ctx, int count, xce_resval_t** vals)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_update_req(ioctx, &data);
rc = xce_update_req(ctx->ep, &data);
if (rc < 0) {
return rc;
}
@ -475,9 +407,8 @@ int xce_update_resvals(xce_ctx_t* ctx, int count, xce_resval_t** vals)
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;
int rc;
int status;
/* clang-format off */
xce_job_rusages_t rusages = {
@ -503,12 +434,7 @@ int xce_update_jusage(xce_ctx_t* ctx, uint64_t jobid, int npids, int* pids,
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_update_req(ioctx, &data);
rc = xce_update_req(ctx->ep, &data);
if (rc < 0) {
return rc;
}
@ -523,9 +449,8 @@ int xce_update_jusage(xce_ctx_t* ctx, uint64_t jobid, int npids, int* pids,
int xce_jobctrl(xce_ctx_t* ctx, xce_jobctrl_t* ctrl)
{
ioctx_t* ioctx;
int rc;
int status;
int rc;
int status;
if (ctx == NULL) {
return -EINVAL;
@ -535,12 +460,7 @@ int xce_jobctrl(xce_ctx_t* ctx, xce_jobctrl_t* ctrl)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_jobctrl_req(ioctx, ctrl);
rc = xce_jobctrl_req(ctx->ep, ctrl);
if (rc < 0) {
return rc;
}
@ -555,9 +475,8 @@ int xce_jobctrl(xce_ctx_t* ctx, xce_jobctrl_t* ctrl)
int xce_queuectrl(xce_ctx_t* ctx, xce_queuectrl_t* ctrl)
{
ioctx_t* ioctx;
int rc;
int status;
int rc;
int status;
if (ctx == NULL) {
return -EINVAL;
@ -567,12 +486,7 @@ int xce_queuectrl(xce_ctx_t* ctx, xce_queuectrl_t* ctrl)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_queuectrl_req(ioctx, ctrl);
rc = xce_queuectrl_req(ctx->ep, ctrl);
if (rc < 0) {
return rc;
}
@ -587,9 +501,8 @@ int xce_queuectrl(xce_ctx_t* ctx, xce_queuectrl_t* ctrl)
int xce_runtask(xce_ctx_t* ctx, xce_taskrun_t* runinfo)
{
ioctx_t* ioctx;
int rc;
int status;
int rc;
int status;
if (ctx == NULL) {
return -EINVAL;
@ -599,12 +512,7 @@ int xce_runtask(xce_ctx_t* ctx, xce_taskrun_t* runinfo)
return -EINVAL;
}
ioctx = ioctx_alloc(ctx->ep, &(ctx->myinfo));
if (ioctx == NULL) {
return -ENOMEM;
}
rc = xce_runtask_req(ioctx, runinfo);
rc = xce_runtask_req(ctx->ep, runinfo);
if (rc < 0) {
return rc;
}

View file

@ -59,10 +59,11 @@ static int handle_reply(xce_ctx_t* ctx, xce_reply_t* reply)
static int vtask_entry(vtask_t* task)
{
endpoint_t* ep = task->ctx.ep;
xce_ctx_t* ctx = NULL;
int rc = 0;
xce_request_t request;
io_task_data_t* data = (io_task_data_t*)&(task->data->u.iodata);
endpoint_t* ep = data->ep;
xce_ctx_t* ctx = NULL;
int rc = 0;
xce_request_t request;
if (ep == NULL) {
return -EINVAL;
@ -73,7 +74,7 @@ static int vtask_entry(vtask_t* task)
return -EINVAL;
}
rc = ioctx_decode(&(task->ctx), &request);
rc = xce_decode(data->pkt, &request);
if (rc < 0) {
return rc;
}
@ -114,91 +115,28 @@ static int vtask_entry(vtask_t* task)
return 0;
}
static int handle_input(endpoint_t* ep)
static int handle_msg(endpoint_t* ep)
{
xce_ctx_t* ctx = (xce_ctx_t*)ep->owner;
vtask_t* task;
int rc = 0;
xce_ctx_t* ctx = NULL;
task = vtask_alloc();
if (task == NULL) {
return -ENOMEM;
if (ep == NULL) {
return -EINVAL;
}
rc = vtask_init(task, (vtask_func_t)&vtask_entry, ep);
if (rc < 0) {
SET_ERROR(-rc);
if (rc == -EPIPE) {
/* connection broken */
TRACE("broken pipe, ep %p", ep);
}
FREEUP(task);
return rc;
ctx = (xce_ctx_t*)ep->owner;
if (ctx == NULL) {
return -EINVAL;
}
rc = vtask_enq(&(ctx->vtaskmgr), task);
if (rc < 0) {
return rc;
}
return 0;
}
static int handle_output(endpoint_t* ep)
{
data_item_t* it;
ioctx_t* ctx;
int rc;
it = endpoint_deq(ep);
if (it == NULL) {
return 0;
}
ctx = ITPTR_TO_IOCTX(it);
rc = ioctx_flush(ctx, ep->fd);
ioctx_deref(ctx, 1);
return rc;
}
static int handle_io(struct epoll_event* p)
{
endpoint_t* ep = (endpoint_t*)p->data.ptr;
int rc = 0;
if ((p->events & EPOLLIN) != 0) {
rc = handle_input(ep);
}
if (rc >= 0) {
if ((p->events & EPOLLOUT) != 0) {
rc = handle_output(ep);
}
}
if (rc < 0) {
xce_ctx_t* ctx = (xce_ctx_t*)ep->owner;
iomgr_t* iomgr = &(ctx->iomgr);
iomgr_unmonitor(iomgr, ep);
endpoint_deref(ep);
xce_try_wakeup(ctx, -EIO);
ctx->state = XCE_CTX_DOWN;
return rc;
}
return 0;
return vtask_handle_msg(&(ctx->vtaskmgr), (vtask_func_t)vtask_entry,
(void*)ep);
}
int xce_ctx_init(xce_ctx_t* ctx, char* name, char* key)
{
int rc;
int rc;
SSL_CTX* ssl_ctx = NULL;
if ((ctx == NULL) || (name == NULL) || (key == NULL)) {
return -EINVAL;
@ -215,14 +153,24 @@ int xce_ctx_init(xce_ctx_t* ctx, char* name, char* key)
return -ENOMEM;
}
initialize_openssl();
ssl_ctx = create_ssl_context(NULL, NULL);
if (ssl_ctx == NULL) {
return -errno;
}
rc = cbuf_init(&(ctx->wbuf), 1, sizeof(int));
if (rc < 0) {
FREEUP(ctx->myinfo.name);
FREEUP(ctx->myinfo.key);
cleanup_openssl();
return rc;
}
iomgr_init(&(ctx->iomgr));
iomgr_set_ssl_ctx(&(ctx->iomgr), ssl_ctx);
vtaskmgr_init(&(ctx->vtaskmgr), 4);
ctx->ep = NULL;
@ -245,6 +193,8 @@ void xce_ctx_fini(xce_ctx_t* ctx)
FREEUP(ctx->myinfo.name);
FREEUP(ctx->myinfo.key);
cleanup_openssl();
return;
}
@ -264,7 +214,9 @@ int xce_ctx_set_endpoint(xce_ctx_t* ctx, endpoint_t* ep)
return -EINVAL;
}
ctx->ep = ep;
ctx->ep = ep;
ctx->ep->iomgr = &(ctx->iomgr);
return 0;
}
@ -280,8 +232,9 @@ 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_owner(ctx->ep, ctx);
endpoint_set_msg_handler(ctx->ep, (msg_handler_t)handle_msg);
rc = iomgr_monitor(ctx->ep);
if (rc < 0) {
ctx->state = XCE_CTX_ERR;
return rc;