update controller code
This commit is contained in:
parent
2836d196da
commit
41f56fa6ed
54 changed files with 9688 additions and 214 deletions
172
src/controller/jobmgr.c
Normal file
172
src/controller/jobmgr.c
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cluster.h"
|
||||
#include "htab.h"
|
||||
#include "xce/cluster_def.h"
|
||||
#include "xce/errnox.h"
|
||||
#include "xstring.h"
|
||||
|
||||
int jobmgr_init(jobmgr_t* mgr,
|
||||
int nhslots,
|
||||
int delta)
|
||||
{
|
||||
ht_init(&(mgr->htab), nhslots,
|
||||
int_hash_key);
|
||||
zarray_init(&(mgr->jobs), delta,
|
||||
(zarray_item_killer_t)job_obj_killer);
|
||||
mylock_init(&(mgr->lock));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void jobmgr_fini(jobmgr_t* mgr)
|
||||
{
|
||||
ht_fini(&(mgr->htab));
|
||||
zarray_fini(&(mgr->jobs));
|
||||
mylock_fini(&(mgr->lock));
|
||||
}
|
||||
|
||||
job_t* jobmgr_lockjob_(jobmgr_t* mgr,
|
||||
uint64_t jobid,
|
||||
int op)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
int idx;
|
||||
job_t* job = NULL;
|
||||
|
||||
e = ht_get(&(mgr->htab), (void*)jobid);
|
||||
if (e == NULL) {
|
||||
SET_ERROR(E_XCE_BAD_JOB);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idx = e->data;
|
||||
|
||||
if (idx < 0) {
|
||||
SET_ERROR(E_XCE_BAD_JOB);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
job = (job_t*)zarray_get(&(mgr->jobs), idx);
|
||||
|
||||
return obj_ref(job, op);
|
||||
}
|
||||
|
||||
job_t* jobmgr_lockjob(jobmgr_t* mgr,
|
||||
uint64_t jobid,
|
||||
int op)
|
||||
{
|
||||
job_t* job = NULL;
|
||||
|
||||
if (mgr == NULL) {
|
||||
SET_ERROR(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
if ((op != OBJREF_NOP) &&
|
||||
(op != OBJREF_READ) &&
|
||||
(op != OBJREF_UPDATE)) {
|
||||
SET_ERROR(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
/* clang-format on */
|
||||
|
||||
mylock_lock(&(mgr->lock));
|
||||
job = jobmgr_lockjob_(mgr, jobid, op);
|
||||
mylock_unlock(&(mgr->lock));
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
static int32_t jobmgr_add_job_(jobmgr_t* mgr,
|
||||
job_t* job)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
int idx;
|
||||
|
||||
e = ht_get(&(mgr->htab),
|
||||
(void*)job->job.jobid);
|
||||
if (e != NULL) {
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
idx = zarray_store(&(mgr->jobs), job);
|
||||
if (idx < 0) {
|
||||
return idx;
|
||||
}
|
||||
|
||||
e = ht_add(&(mgr->htab),
|
||||
(void*)job->job.jobid);
|
||||
if (e == NULL) {
|
||||
zarray_del(&(mgr->jobs), idx);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
e->data = idx;
|
||||
return idx;
|
||||
}
|
||||
|
||||
int32_t jobmgr_add_job(jobmgr_t* mgr,
|
||||
job_t* job)
|
||||
{
|
||||
int32_t idx;
|
||||
|
||||
if ((mgr == NULL) || (job == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mylock_lock(&(mgr->lock));
|
||||
idx = jobmgr_add_job_(mgr, job);
|
||||
mylock_unlock(&(mgr->lock));
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
static void jobmgr_del_job_(jobmgr_t* mgr,
|
||||
job_t* job)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
int idx;
|
||||
|
||||
e = ht_get(&(mgr->htab),
|
||||
(void*)job->job.jobid);
|
||||
if (e == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
idx = e->data;
|
||||
if (idx < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
zarray_del(&(mgr->jobs), idx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void jobmgr_del_job(jobmgr_t* mgr,
|
||||
job_t* job)
|
||||
{
|
||||
if ((mgr == NULL) || (job == NULL)) {
|
||||
return;
|
||||
}
|
||||
mylock_lock(&(mgr->lock));
|
||||
jobmgr_del_job_(mgr, job);
|
||||
mylock_unlock(&(mgr->lock));
|
||||
}
|
||||
|
||||
int jobmgr_iter(jobmgr_t* mgr,
|
||||
xlist_t* l,
|
||||
void* arg)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
mylock_lock(&(mgr->lock));
|
||||
rc = zarray_iter_ex(&(mgr->jobs), l, arg);
|
||||
mylock_unlock(&(mgr->lock));
|
||||
|
||||
return rc;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue