save works
This commit is contained in:
parent
b1faeb94b6
commit
b748e30d20
35 changed files with 1247 additions and 2149 deletions
|
|
@ -256,7 +256,7 @@ static int apiserver_job_update_fun(int type, int situation, void* data,
|
|||
int rc;
|
||||
xce_notify_data_t xdata
|
||||
= { .event = NotifyData_data_updateJob,
|
||||
.data = { .update_job = &(job->job) } };
|
||||
.data = { .update_job = job->job } };
|
||||
|
||||
rc = notify(c, c->apiservers[i].ep, &xdata);
|
||||
if (rc < 0) {
|
||||
|
|
@ -351,11 +351,11 @@ static int apiserver_worker_change(int type, int situation, void* data,
|
|||
{
|
||||
int i;
|
||||
|
||||
TRACE("%s worker %s idx %d situation %d", __func__, w->host.name, w->idx,
|
||||
TRACE("%s worker %s idx %d situation %d", __func__, w->host->name, w->idx,
|
||||
situation);
|
||||
|
||||
collect_resval_with_idx(&(w->host.resvals), &(w->host.nresvals_to_sched),
|
||||
&(w->host.resvals_to_sched));
|
||||
collect_resval_with_idx(&(w->host->resvals), &(w->host->nresvals_to_sched),
|
||||
&(w->host->resvals_to_sched));
|
||||
|
||||
switch (situation) {
|
||||
case HOOK_AFTER_EVENT:
|
||||
|
|
@ -383,8 +383,8 @@ static int apiserver_worker_change(int type, int situation, void* data,
|
|||
break;
|
||||
}
|
||||
|
||||
free_resval_with_idx_list(&(w->host.resvals_to_sched),
|
||||
w->host.nresvals_to_sched);
|
||||
free_resval_with_idx_list(&(w->host->resvals_to_sched),
|
||||
w->host->nresvals_to_sched);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -402,12 +402,18 @@ static int apiserver_worker_join(int type, int situation, void* data,
|
|||
return 0;
|
||||
}
|
||||
|
||||
w = workermgr_lock(&(c->workermgr), name, OBJREF_READ);
|
||||
rc = key_find(c->workermgr, (void *)name, (void **)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
rc = apiserver_worker_change(type, situation, data, c, w);
|
||||
|
||||
/* FIXME: need to mark the jobs in this worker */
|
||||
obj_deref(w);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -508,7 +514,7 @@ static int apiserver_queue_hook_fun(int type, int situation, int detail,
|
|||
int rc;
|
||||
xce_notify_data_t xdata
|
||||
= { .event = NotifyData_data_schedUpdateQueue,
|
||||
.data = { .sched_update_queue = &(q->queue) } };
|
||||
.data = { .sched_update_queue = q->queue } };
|
||||
|
||||
rc = notify(c, c->apiservers[i].ep, &xdata);
|
||||
if (rc < 0) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <rtti.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cluster.h"
|
||||
#include "dataq.h"
|
||||
#include "htab.h"
|
||||
#include "kvmgr.h"
|
||||
#include "mylock.h"
|
||||
#include "request.h"
|
||||
#include "vtaskmgr.h"
|
||||
|
|
@ -15,6 +17,7 @@
|
|||
|
||||
#include "xce/types.h"
|
||||
|
||||
#include "resobj.h"
|
||||
#include "utils.h"
|
||||
#include "worker.h"
|
||||
#include "xce/errnox.h"
|
||||
|
|
@ -368,8 +371,7 @@ int cluster_build_resources(cluster_t* c)
|
|||
for (i = 0; i < c->myconf->cluster_config->nres; i++) {
|
||||
xce_resource_t* res;
|
||||
|
||||
res = create_obj_by_typename(&(c->objmgr), "xresource",
|
||||
c->myconf->cluster_config->resources[i]);
|
||||
res = makeResource(c->myconf->cluster_config->resources[i]);
|
||||
if (res == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
|
@ -458,10 +460,82 @@ static int run_delay_tasks(delay_task_entry_fn_t entry, void* arg)
|
|||
return entry(arg);
|
||||
}
|
||||
|
||||
static void res_obj_killer(xce_resource_t* r)
|
||||
{
|
||||
if (r == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void job_obj_killer(void* arg)
|
||||
{
|
||||
if (arg == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void worker_obj_killer(void* arg)
|
||||
{
|
||||
if (arg == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void queue_obj_killer(void* arg)
|
||||
{
|
||||
if (arg == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void resval_obj_killer(void* arg)
|
||||
{
|
||||
if (arg == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void config_obj_killer(void* arg)
|
||||
{
|
||||
if (arg == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int cluster_init(cluster_t* c)
|
||||
{
|
||||
int i, rc;
|
||||
SSL_CTX* ssl_ctx = NULL;
|
||||
kvmgr_params_t config_mgr_params
|
||||
= { .key_type = KVMGR_KEY_STRING,
|
||||
.dynamic = 1,
|
||||
.nslots = 128,
|
||||
.delta = 128,
|
||||
.datakiller = (destroy_fn_t)config_obj_killer };
|
||||
kvmgr_params_t resmgr_params
|
||||
= { .key_type = KVMGR_KEY_STRING,
|
||||
.dynamic = 1,
|
||||
.nslots = c->myconf->cluster_config->resmgr->nhash_slots,
|
||||
.delta = c->myconf->cluster_config->resmgr->delta,
|
||||
.datakiller = (destroy_fn_t)res_obj_killer };
|
||||
kvmgr_params_t jobmgr_params
|
||||
= { .key_type = KVMGR_KEY_INT,
|
||||
.dynamic = 1,
|
||||
.nslots = c->myconf->cluster_config->jobmgr->nhash_slots,
|
||||
.delta = c->myconf->cluster_config->jobmgr->delta,
|
||||
.datakiller = (destroy_fn_t)job_obj_killer };
|
||||
kvmgr_params_t workermgr_params
|
||||
= { .key_type = KVMGR_KEY_STRING,
|
||||
.dynamic = 1,
|
||||
.nslots = c->myconf->cluster_config->workermgr->nhash_slots,
|
||||
.delta = c->myconf->cluster_config->workermgr->delta,
|
||||
.datakiller = (destroy_fn_t)worker_obj_killer };
|
||||
kvmgr_params_t qmgr_params
|
||||
= { .key_type = KVMGR_KEY_STRING,
|
||||
.dynamic = 0,
|
||||
.nslots = c->myconf->cluster_config->qmgr->nhash_slots,
|
||||
.delta = c->myconf->cluster_config->qmgr->delta,
|
||||
.datakiller = (destroy_fn_t)queue_obj_killer };
|
||||
|
||||
if (c == NULL) {
|
||||
return -EINVAL;
|
||||
|
|
@ -491,36 +565,21 @@ int cluster_init(cluster_t* c)
|
|||
return -errno;
|
||||
}
|
||||
|
||||
kvmgr_init(&(c->configmgr), string_hash_key, 128, 128,
|
||||
(zarray_item_killer_t)config_obj_killer);
|
||||
c->configmgr = makeInstance(&xkvmgr_type, &config_mgr_params);
|
||||
|
||||
objmgr_init(&(c->objmgr));
|
||||
jobmgr_init(&(c->jobmgr), c->myconf->cluster_config->jobmgr->nhash_slots,
|
||||
c->myconf->cluster_config->jobmgr->delta,
|
||||
(zarray_item_killer_t)job_obj_killer);
|
||||
resmgr_init(&(c->resmgr), c->myconf->cluster_config->resmgr->nhash_slots,
|
||||
c->myconf->cluster_config->resmgr->delta,
|
||||
(zarray_item_killer_t)res_obj_killer);
|
||||
c->jobmgr = makeInstance(&xkvmgr_type, &jobmgr_params);
|
||||
c->resmgr = makeInstance(&xkvmgr_type, &resmgr_params);
|
||||
zarray_init(&(c->sharedinst), c->myconf->cluster_config->resmgr->inst_delta,
|
||||
(zarray_item_killer_t)resval_obj_killer);
|
||||
workermgr_init(&(c->workermgr),
|
||||
c->myconf->cluster_config->workermgr->nhash_slots,
|
||||
c->myconf->cluster_config->workermgr->delta,
|
||||
(zarray_item_killer_t)worker_obj_killer);
|
||||
qmgr_init(&(c->qmgr), c->myconf->cluster_config->qmgr->nhash_slots,
|
||||
c->myconf->cluster_config->qmgr->delta,
|
||||
(zarray_item_killer_t)queue_obj_killer);
|
||||
c->workermgr = makeInstance(&xkvmgr_type, &workermgr_params);
|
||||
c->qmgr = makeInstance(&xkvmgr_type, &qmgr_params);
|
||||
iomgr_init(&(c->iomgr));
|
||||
|
||||
iomgr_set_ssl_ctx(&(c->iomgr), ssl_ctx);
|
||||
|
||||
xstring_table_init(c->myconf->cluster_config->xstrings->nhash_slots);
|
||||
|
||||
register_xstring(&(c->objmgr),
|
||||
c->myconf->cluster_config->xstrings->nhash_slots,
|
||||
c->myconf->cluster_config->xstrings->delta);
|
||||
register_types(c);
|
||||
|
||||
zarray_init(&(c->endpoints), 16, endpoint_killer);
|
||||
|
||||
rc = endpoint_init(&(c->ep), AF_INET, SOCK_STREAM,
|
||||
|
|
@ -557,10 +616,8 @@ static int make_heartbeat(cluster_t* c, endpoint_t* ep)
|
|||
return xce_nop_req(ep);
|
||||
}
|
||||
|
||||
static int check_worker_timeout_(void* arg1, void* arg2)
|
||||
static int check_worker_timeout_(cluster_t* c, worker_t* w)
|
||||
{
|
||||
cluster_t* c = (cluster_t*)arg1;
|
||||
worker_t* w = (worker_t*)arg2;
|
||||
worker_t* w1 = NULL;
|
||||
endpoint_t* ep;
|
||||
time_t now = time(NULL);
|
||||
|
|
@ -581,24 +638,19 @@ static int check_worker_timeout_(void* arg1, void* arg2)
|
|||
}
|
||||
|
||||
/* grab lock on worker */
|
||||
w1 = obj_ref(w, OBJREF_UPDATE);
|
||||
if (w1 == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
config = c->myconf->cluster_config;
|
||||
timeout = config->heartbeat_interval * config->inactive_heartbeat_count;
|
||||
|
||||
if (now - ep->ts_last_in > timeout) {
|
||||
TRACE("%s worker %s becomes UNAVAIL as heartbeat timeout", __func__,
|
||||
w->host.name);
|
||||
w->host->name);
|
||||
|
||||
mark_worker_unavail(c, w);
|
||||
obj_deref(w1);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
if (IS_WORKER_UNAVAIL(w->host.status)) {
|
||||
if (IS_WORKER_UNAVAIL(w->host->status)) {
|
||||
mark_worker_back(c, w);
|
||||
}
|
||||
}
|
||||
|
|
@ -607,34 +659,49 @@ static int check_worker_timeout_(void* arg1, void* arg2)
|
|||
if (DATAQ_EMPTY(&(ep->outq))) {
|
||||
int rc = 0;
|
||||
|
||||
TRACE("%s send heartbeat to %s", __func__, w->host.name);
|
||||
TRACE("%s send heartbeat to %s", __func__, w->host->name);
|
||||
|
||||
rc = make_heartbeat(c, ep);
|
||||
|
||||
if (rc < 0) {
|
||||
ERROR("%s make_heartbeat to %s failed", __func__, w->host.name);
|
||||
ERROR("%s make_heartbeat to %s failed", __func__,
|
||||
w->host->name);
|
||||
|
||||
obj_deref(w1);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
obj_deref(w1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int check_workers_timeout(void* args)
|
||||
{
|
||||
xlist_t lst;
|
||||
int rc;
|
||||
iterator_t it;
|
||||
cluster_t* c = (cluster_t*)args;
|
||||
int rc = 0;
|
||||
|
||||
xlist_init(&lst, 3);
|
||||
xlist_store(&lst, check_worker_timeout_);
|
||||
rc = workermgr_iter(&(c->workermgr), &lst, c);
|
||||
rc = iter_make(&it, c->workermgr);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
xlist_fini(&lst);
|
||||
for (;;) {
|
||||
worker_t* w = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&w);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
check_worker_timeout_(c, w);
|
||||
}
|
||||
|
||||
if (rc == RTTI_ITER_NO_DATA) {
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
iter_destroy(&it);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -698,11 +765,11 @@ void cluster_fini(cluster_t* c)
|
|||
cbuf_fini(&(c->wbuf));
|
||||
iomgr_fini(&(c->iomgr));
|
||||
|
||||
jobmgr_fini(&(c->jobmgr));
|
||||
workermgr_fini(&(c->workermgr));
|
||||
qmgr_fini(&(c->qmgr));
|
||||
resmgr_fini(&(c->resmgr));
|
||||
kvmgr_fini(&(c->configmgr));
|
||||
destroy(c->jobmgr);
|
||||
destroy(c->workermgr);
|
||||
destroy(c->qmgr);
|
||||
destroy(c->resmgr);
|
||||
destroy(c->configmgr);
|
||||
mylock_fini(&(c->sched.lock));
|
||||
|
||||
zarray_fini(&(c->endpoints));
|
||||
|
|
|
|||
|
|
@ -18,22 +18,6 @@ int check_controller(void* arg)
|
|||
return 1;
|
||||
}
|
||||
|
||||
struct intern_array_ {
|
||||
int count;
|
||||
int idx;
|
||||
void* data;
|
||||
check_fn_t checkfn;
|
||||
};
|
||||
|
||||
int not_null_check(void* arg)
|
||||
{
|
||||
if (arg == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int collect_resval_with_idx_(zarray_t* array, int* nres,
|
||||
xce_val_with_idx_t*** resvals)
|
||||
{
|
||||
|
|
@ -118,345 +102,309 @@ int collect_resval_with_idx(zarray_t* array, int* nres,
|
|||
|
||||
return rc;
|
||||
}
|
||||
static int count_(void* arg1, void* arg2)
|
||||
{
|
||||
struct intern_array_* arg = (struct intern_array_*)arg1;
|
||||
|
||||
if ((arg == NULL) || (arg->checkfn == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
arg->count++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add_confvar_(void* arg1, void* arg2)
|
||||
{
|
||||
struct intern_array_* arg = (struct intern_array_*)arg1;
|
||||
xce_config_t** p = NULL;
|
||||
|
||||
if ((arg == NULL) || (arg->count < 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (arg->count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = (xce_config_t**)arg->data;
|
||||
if (p == NULL) {
|
||||
p = (xce_config_t**)calloc(arg->count, sizeof(xce_config_t*));
|
||||
if (p == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
arg->data = p;
|
||||
}
|
||||
|
||||
p[arg->idx] = (xce_config_t*)obj_ref(arg2, OBJREF_READ);
|
||||
arg->idx++;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void collect_confvars(cluster_t* c, collect_check_fn_t fn, int* nconfig,
|
||||
xce_config_t*** configs)
|
||||
{
|
||||
xlist_t lst;
|
||||
struct intern_array_ args
|
||||
= { .count = 0,
|
||||
.idx = 0,
|
||||
.data = NULL,
|
||||
.checkfn = (fn == NULL) ? not_null_check : fn };
|
||||
iterator_t it;
|
||||
int nc = 0, idx;
|
||||
int rc;
|
||||
|
||||
*nconfig = 0;
|
||||
*configs = NULL;
|
||||
|
||||
xlist_init(&lst, 3);
|
||||
xlist_store(&lst, count_);
|
||||
xlist_store(&lst, add_confvar_);
|
||||
|
||||
rc = kvmgr_iter(&(c->configmgr), NULL, &lst, &args);
|
||||
|
||||
xlist_fini(&lst);
|
||||
|
||||
if (rc >= 0) {
|
||||
*nconfig = args.count;
|
||||
*configs = args.data;
|
||||
}
|
||||
}
|
||||
|
||||
static int add_queue_(void* arg1, void* arg2)
|
||||
{
|
||||
struct intern_array_* arg = (struct intern_array_*)arg1;
|
||||
xce_queue_t** p = NULL;
|
||||
|
||||
if (arg == NULL) {
|
||||
return -EINVAL;
|
||||
rc = iter_make(&it, c->configmgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg->count < 0) {
|
||||
return -EINVAL;
|
||||
nc = 0;
|
||||
for (;;) {
|
||||
xce_config_t* config = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&config);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (arg->count == 0) {
|
||||
return 0;
|
||||
if (config != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
if (rc < 0) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
p = (xce_queue_t**)arg->data;
|
||||
if (p == NULL) {
|
||||
p = (xce_queue_t**)calloc(arg->count, sizeof(xce_queue_t*));
|
||||
if (p == NULL) {
|
||||
return -ENOMEM;
|
||||
if (nc == 0) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
arg->data = p;
|
||||
iter_reset(&it);
|
||||
*configs = (xce_config_t**)calloc(nc, sizeof(xce_config_t*));
|
||||
if ((*configs) == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
p[arg->idx] = (xce_queue_t*)obj_ref(arg2, OBJREF_READ);
|
||||
arg->idx++;
|
||||
idx = 0;
|
||||
for (;;) {
|
||||
xce_config_t* config = NULL;
|
||||
|
||||
return 1;
|
||||
rc = iter_next(&it, (void**)&config);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (config != NULL) {
|
||||
(*configs)[idx] = config;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
iter_destroy(&it);
|
||||
}
|
||||
|
||||
void collect_queues(cluster_t* c, collect_check_fn_t fn, int* nqueues,
|
||||
xce_queue_t*** queues)
|
||||
{
|
||||
xlist_t lst;
|
||||
struct intern_array_ args
|
||||
= { .count = 0,
|
||||
.idx = 0,
|
||||
.data = NULL,
|
||||
.checkfn = (fn == NULL) ? not_null_check : fn };
|
||||
iterator_t it;
|
||||
int count;
|
||||
int rc;
|
||||
int nc;
|
||||
|
||||
*nqueues = 0;
|
||||
*queues = NULL;
|
||||
|
||||
xlist_init(&lst, 3);
|
||||
xlist_store(&lst, count_);
|
||||
xlist_store(&lst, add_queue_);
|
||||
|
||||
rc = qmgr_iter(&(c->qmgr), &lst, &args);
|
||||
|
||||
xlist_fini(&lst);
|
||||
|
||||
if (rc >= 0) {
|
||||
*nqueues = args.count;
|
||||
*queues = args.data;
|
||||
}
|
||||
}
|
||||
|
||||
static int add_resource_(void* arg1, void* arg2)
|
||||
{
|
||||
struct intern_array_* arg = (struct intern_array_*)arg1;
|
||||
xce_resource_t** p = NULL;
|
||||
|
||||
if (arg == NULL) {
|
||||
return -EINVAL;
|
||||
rc = iter_make(&it, c->qmgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg->count < 0) {
|
||||
return -EINVAL;
|
||||
count = 0;
|
||||
for (;;) {
|
||||
xce_queue_t* q = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&q);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (arg->count == 0) {
|
||||
return 0;
|
||||
if (q != NULL) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
p = (xce_resource_t**)arg->data;
|
||||
if (p == NULL) {
|
||||
p = (xce_resource_t**)calloc(arg->count, sizeof(xce_resource_t*));
|
||||
if (p == NULL) {
|
||||
return -ENOMEM;
|
||||
*queues = (xce_queue_t**)calloc(count, sizeof(xce_queue_t*));
|
||||
if ((*queues) == NULL) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
arg->data = p;
|
||||
iter_reset(&it);
|
||||
|
||||
nc = 0;
|
||||
|
||||
for (;;) {
|
||||
xce_queue_t* q = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&q);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
p[arg->idx] = (xce_resource_t*)obj_ref(arg2, OBJREF_READ);
|
||||
if (q != NULL) {
|
||||
(*queues)[nc] = q;
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
arg->idx++;
|
||||
*nqueues = nc;
|
||||
|
||||
return 1;
|
||||
iter_destroy(&it);
|
||||
}
|
||||
|
||||
void collect_resources(cluster_t* c, collect_check_fn_t fn, int* nresources,
|
||||
xce_resource_t*** resources)
|
||||
{
|
||||
xlist_t lst;
|
||||
struct intern_array_ args
|
||||
= { .count = 0,
|
||||
.idx = 0,
|
||||
.data = NULL,
|
||||
.checkfn = (fn == NULL) ? not_null_check : fn };
|
||||
iterator_t it;
|
||||
int rc;
|
||||
int i, nc;
|
||||
|
||||
*nresources = 0;
|
||||
*resources = NULL;
|
||||
|
||||
xlist_init(&lst, 3);
|
||||
xlist_store(&lst, count_);
|
||||
xlist_store(&lst, add_resource_);
|
||||
|
||||
rc = resmgr_iter(&(c->resmgr), &lst, &args);
|
||||
|
||||
xlist_fini(&lst);
|
||||
|
||||
if (rc >= 0) {
|
||||
*nresources = args.count;
|
||||
*resources = args.data;
|
||||
}
|
||||
}
|
||||
|
||||
static int add_job_(void* arg1, void* arg2)
|
||||
{
|
||||
struct intern_array_* arg = (struct intern_array_*)arg1;
|
||||
xce_job_t** p = NULL;
|
||||
|
||||
if (arg == NULL) {
|
||||
return -EINVAL;
|
||||
rc = iter_make(&it, c->resmgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg->count < 0) {
|
||||
return -EINVAL;
|
||||
nc = 0;
|
||||
for (;;) {
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&r);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (arg->count == 0) {
|
||||
return 0;
|
||||
if (r != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
if ((rc < 0) || (nc == 0)) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
p = (xce_job_t**)arg->data;
|
||||
if (p == NULL) {
|
||||
p = (xce_job_t**)calloc(arg->count, sizeof(xce_job_t*));
|
||||
if (p == NULL) {
|
||||
return -ENOMEM;
|
||||
*resources = calloc(nc, sizeof(xce_resource_t));
|
||||
if ((*resources) == NULL) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
arg->data = p;
|
||||
iter_reset(&it);
|
||||
|
||||
i = 0;
|
||||
for (;;) {
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&r);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
p[arg->idx] = (xce_job_t*)obj_ref(arg2, OBJREF_READ);
|
||||
arg->idx++;
|
||||
if (r != NULL) {
|
||||
(*resources)[i] = r;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
*nresources = i;
|
||||
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
void collect_jobs(cluster_t* c, collect_check_fn_t fn, int* njobs,
|
||||
xce_job_t*** jobs)
|
||||
{
|
||||
xlist_t lst;
|
||||
struct intern_array_ args
|
||||
= { .count = 0, .idx = 0, .data = NULL, .checkfn = (check_fn_t)fn };
|
||||
iterator_t it;
|
||||
int nc, i;
|
||||
int rc = 0;
|
||||
|
||||
*njobs = 0;
|
||||
*jobs = NULL;
|
||||
|
||||
xlist_init(&lst, 3);
|
||||
xlist_store(&lst, count_);
|
||||
xlist_store(&lst, add_job_);
|
||||
|
||||
rc = jobmgr_iter(&(c->jobmgr), &lst, &args);
|
||||
xlist_fini(&lst);
|
||||
|
||||
if (rc >= 0) {
|
||||
*njobs = args.count;
|
||||
*jobs = args.data;
|
||||
}
|
||||
|
||||
rc = iter_make(&it, c->jobmgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
static int add_worker_(void* arg1, void* arg2)
|
||||
{
|
||||
struct intern_array_* arg = (struct intern_array_*)arg1;
|
||||
xce_worker_t** p = NULL;
|
||||
xce_worker_t* w;
|
||||
|
||||
if (arg == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (arg->count < 0) {
|
||||
return -EINVAL;
|
||||
nc = 0;
|
||||
for (;;) {
|
||||
xce_job_t* j = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&j);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (arg->count == 0) {
|
||||
return 0;
|
||||
if (j != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
if ((rc < 0) || (nc == 0)) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
p = (xce_worker_t**)arg->data;
|
||||
if (p == NULL) {
|
||||
p = (xce_worker_t**)calloc(arg->count, sizeof(xce_worker_t*));
|
||||
if (p == NULL) {
|
||||
return -ENOMEM;
|
||||
iter_reset(&it);
|
||||
i = 0;
|
||||
|
||||
for (;;) {
|
||||
xce_job_t* j = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&j);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
arg->data = p;
|
||||
if (j != NULL) {
|
||||
(*jobs)[i] = j;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
w = (xce_worker_t*)obj_ref(arg2, OBJREF_READ);
|
||||
*njobs = i;
|
||||
|
||||
collect_resval_with_idx(&(w->resvals), &(w->nresvals_to_sched),
|
||||
&(w->resvals_to_sched));
|
||||
|
||||
p[arg->idx] = w;
|
||||
arg->idx++;
|
||||
|
||||
return 1;
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
void collect_workers(cluster_t* c, collect_check_fn_t fn, int* nworkers,
|
||||
xce_worker_t*** workers)
|
||||
{
|
||||
xlist_t lst;
|
||||
struct intern_array_ args
|
||||
= { .count = 0, .idx = 0, .data = NULL, .checkfn = (check_fn_t)fn };
|
||||
iterator_t it;
|
||||
int i, nc;
|
||||
int rc = 0;
|
||||
|
||||
*nworkers = 0;
|
||||
*workers = NULL;
|
||||
|
||||
xlist_init(&lst, 3);
|
||||
xlist_store(&lst, count_);
|
||||
xlist_store(&lst, add_worker_);
|
||||
|
||||
rc = workermgr_iter(&(c->workermgr), &lst, &args);
|
||||
|
||||
xlist_fini(&lst);
|
||||
|
||||
if (rc >= 0) {
|
||||
*nworkers = args.count;
|
||||
*workers = args.data;
|
||||
rc = iter_make(&it, c->workermgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
nc = 0;
|
||||
for (;;) {
|
||||
xce_worker_t* w = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&w);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (w != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((rc < 0) || (nc == 0)) {
|
||||
iter_destroy(&it);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
iter_reset(&it);
|
||||
|
||||
i = 0;
|
||||
for (;;) {
|
||||
xce_worker_t* w = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&w);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (w != NULL) {
|
||||
(*workers)[i] = w;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
*nworkers = i;
|
||||
|
||||
iter_destroy(&it);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,12 +34,8 @@ extern int add_to_xlist(xlist_t*, void*);
|
|||
extern int add_worker_to_xlist(xlist_t*, void*);
|
||||
extern int add_queue_to_xlist(xlist_t*, void*);
|
||||
extern int add_job_to_xlist(xlist_t*, void*);
|
||||
extern void queue_obj_killer(queue_t*);
|
||||
extern void res_obj_killer(xce_resource_t*);
|
||||
extern void resval_obj_killer(xce_resval_t*);
|
||||
extern void resource_killer(void*);
|
||||
extern int add_resource(void*, char*, char*, int, xce_order_t, int, int);
|
||||
extern void config_obj_killer(xce_config_t*);
|
||||
|
||||
extern int update_resvals(cluster_t*, worker_t*, int, xce_resval_t*);
|
||||
|
||||
|
|
@ -69,8 +65,6 @@ extern int get_resval(cluster_t*, char*, char*, xce_val_t*);
|
|||
extern job_t* jobmgr_lockjob(jobmgr_t*, uint64_t, int);
|
||||
extern int32_t jobmgr_add_job(jobmgr_t*, job_t*);
|
||||
extern void jobmgr_del_job(jobmgr_t*, job_t*);
|
||||
extern void job_obj_killer(job_t*);
|
||||
extern void worker_obj_killer(worker_t*);
|
||||
extern int handle_push(struct capn*, cluster_t*, endpoint_t*, struct Request*);
|
||||
extern int do_get_op(cluster_t*, endpoint_t*, xce_request_t*);
|
||||
extern int do_update_op(cluster_t*, endpoint_t*, xce_request_t*);
|
||||
|
|
@ -106,7 +100,6 @@ extern int on_job_resume(cluster_t*, uint64_t);
|
|||
extern int on_job_postdone(cluster_t*, endpoint_t*, uint64_t);
|
||||
extern int on_job_ckpt(cluster_t*, endpoint_t*, xce_ckptinfo_t*);
|
||||
extern int notify(cluster_t*, endpoint_t*, xce_notify_data_t*);
|
||||
extern int not_null_check(void*);
|
||||
extern int check_worker_(xce_worker_t*);
|
||||
extern int update_resval_list(cluster_t*, worker_t*, xce_resval_list_t*);
|
||||
extern int do_jobcontrol_op(cluster_t*, endpoint_t*, xce_request_t*);
|
||||
|
|
@ -117,9 +110,8 @@ extern int update_host_runusage(xce_job_runusage_t**, char*, int,
|
|||
extern int update_pids(job_pidinfo_t**, int, int*);
|
||||
extern int update_pgids(job_pidinfo_t**, int, int*);
|
||||
extern int get_ep_role(endpoint_t*);
|
||||
extern worker_t* get_ep_worker(cluster_t*, endpoint_t*, int);
|
||||
extern worker_t* get_ep_worker(cluster_t*, endpoint_t*);
|
||||
|
||||
extern int not_null_check(void*);
|
||||
extern int check_worker_(xce_worker_t*);
|
||||
extern int update_resval_list(cluster_t*, worker_t*, xce_resval_list_t*);
|
||||
extern int do_jobcontrol_op(cluster_t*, endpoint_t*, xce_request_t*);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@
|
|||
#include <time.h>
|
||||
|
||||
#include "cluster.h"
|
||||
#include "jobj.h"
|
||||
#include "preason.h"
|
||||
#include "xce/cluster_def.h"
|
||||
#include "xce/errnox.h"
|
||||
#include "xce/types.h"
|
||||
#include "xstring.h"
|
||||
|
||||
static int mark_job_start(cluster_t*, job_t*, job_pidinfo_t*);
|
||||
static int mark_job_finish(cluster_t*, job_t*, xce_jobfinish_t*);
|
||||
|
|
@ -20,19 +22,14 @@ uint64_t jobid = 100;
|
|||
static job_t* create_job(cluster_t* c, xce_job_t* j)
|
||||
{
|
||||
job_t* job = NULL;
|
||||
static int typeid = -1;
|
||||
|
||||
if (typeid < 0) {
|
||||
typeid = typeid_of_name(&(c->objmgr), "xjob");
|
||||
TRACE("%s type %s id %d", __func__, "xjob", typeid);
|
||||
}
|
||||
|
||||
if (typeid < 0) {
|
||||
SET_ERROR(-typeid);
|
||||
job = calloc(1, sizeof(*job));
|
||||
if (job == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
job = create_obj_by_typeid(&(c->objmgr), typeid, j);
|
||||
/* FIXME: */
|
||||
job->job = makeJob(j);
|
||||
|
||||
return job;
|
||||
}
|
||||
|
|
@ -157,8 +154,8 @@ static int mk_launchinfo(xce_launch_t* launch, xce_job_alloc_t* alloc)
|
|||
static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
|
||||
{
|
||||
int rc = 0;
|
||||
job_t* j;
|
||||
worker_t* w;
|
||||
job_t* j = NULL;
|
||||
worker_t* w = NULL;
|
||||
xce_host_alloc_t** allocs;
|
||||
int nc;
|
||||
xce_job_exec_t einfo;
|
||||
|
|
@ -166,7 +163,10 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
|
|||
|
||||
TRACE("%s jobid %ld", __func__, alloc->jobid);
|
||||
|
||||
j = jobmgr_lockjob(&(c->jobmgr), alloc->jobid, OBJREF_UPDATE);
|
||||
rc = key_find(c->jobmgr, (void*)alloc->jobid, (void**)&j);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (j == NULL) {
|
||||
PERROR("jobmgr_lockjob");
|
||||
|
|
@ -187,17 +187,20 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
|
|||
|
||||
allocs = (xce_host_alloc_t**)alloc->allocs;
|
||||
/* using head node of job */
|
||||
w = workermgr_lock(&(c->workermgr), allocs[0]->host, OBJREF_READ);
|
||||
rc = key_find(c->workermgr, (void*)allocs[0]->host, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (w == NULL) {
|
||||
PERROR("workermgr_lock");
|
||||
free_launchinfo(&launchinfo);
|
||||
obj_deref(j);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if ((w->ep == NULL) || (w->host.status != 0)) {
|
||||
if ((w->ep == NULL) || (w->host->status != 0)) {
|
||||
ERROR("worker %s is not in correct state, status %x ep %p",
|
||||
w->host.name, w->host.status, w->ep);
|
||||
w->host->name, w->host->status, w->ep);
|
||||
free_launchinfo(&launchinfo);
|
||||
|
||||
obj_deref(w);
|
||||
|
|
@ -212,40 +215,41 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
|
|||
char* q_pre_exec;
|
||||
char* q_post_exec;
|
||||
|
||||
rc = get_queue_exec(c, j->job.submit->queue, &q_pre_exec, &q_post_exec);
|
||||
rc = get_queue_exec(c, j->job->submit->queue, &q_pre_exec,
|
||||
&q_post_exec);
|
||||
if (rc < 0) {
|
||||
obj_deref(j);
|
||||
obj_deref(w);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (j->job.submit->start_info->q_pre_exec != NULL) {
|
||||
obj_deref(j->job.submit->start_info->q_pre_exec);
|
||||
if (j->job->submit->start_info->q_pre_exec != NULL) {
|
||||
obj_deref(j->job->submit->start_info->q_pre_exec);
|
||||
}
|
||||
|
||||
if (j->job.submit->start_info->q_post_exec != NULL) {
|
||||
obj_deref(j->job.submit->start_info->q_post_exec);
|
||||
if (j->job->submit->start_info->q_post_exec != NULL) {
|
||||
obj_deref(j->job->submit->start_info->q_post_exec);
|
||||
}
|
||||
|
||||
j->job.submit->start_info->q_pre_exec = q_pre_exec;
|
||||
j->job.submit->start_info->q_post_exec = q_post_exec;
|
||||
j->job->submit->start_info->q_pre_exec = q_pre_exec;
|
||||
j->job->submit->start_info->q_post_exec = q_post_exec;
|
||||
}
|
||||
|
||||
einfo.jobid = alloc->jobid;
|
||||
einfo.start_info = j->job.submit->start_info;
|
||||
einfo.start_info = j->job->submit->start_info;
|
||||
einfo.launchinfo = &launchinfo;
|
||||
|
||||
rc = xce_startjob_req(w->ep, &einfo);
|
||||
|
||||
free_launchinfo(&launchinfo);
|
||||
|
||||
if (j->job.allocs != NULL) {
|
||||
free_JobAlloc_ptr(&(j->job.allocs));
|
||||
if (j->job->allocs != NULL) {
|
||||
free_JobAlloc_ptr(&(j->job->allocs));
|
||||
}
|
||||
j->job.allocs = (xce_job_alloc_t*)calloc(1, sizeof(xce_job_alloc_t));
|
||||
j->job.allocs->jobid = alloc->jobid;
|
||||
j->job.allocs->nhosts = nc;
|
||||
MOVE_PTR(j->job.allocs->allocs, allocs);
|
||||
j->job->allocs = (xce_job_alloc_t*)calloc(1, sizeof(xce_job_alloc_t));
|
||||
j->job->allocs->jobid = alloc->jobid;
|
||||
j->job->allocs->nhosts = nc;
|
||||
MOVE_PTR(j->job->allocs->allocs, allocs);
|
||||
alloc->allocs = NULL;
|
||||
|
||||
DEREF_OBJ(w);
|
||||
|
|
@ -263,40 +267,47 @@ static int dispatch_a_job_(cluster_t* c, endpoint_t* ep, xce_job_alloc_t* alloc)
|
|||
int job_ctrl(cluster_t* c, xce_jobctrl_t* ctrinfo)
|
||||
{
|
||||
uint64_t jobid = ctrinfo->jobid;
|
||||
job_t* j;
|
||||
job_t* j = NULL;
|
||||
int rc = 0;
|
||||
|
||||
TRACE("%s job_ctrl job %ld", __func__, jobid);
|
||||
j = jobmgr_lockjob(&(c->jobmgr), jobid, OBJREF_UPDATE);
|
||||
|
||||
rc = key_find(c->jobmgr, (void*)jobid, (void**)&j);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (j == NULL) {
|
||||
PERROR("jobmgr_lockjob");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (j->job.allocs != NULL) {
|
||||
xce_host_alloc_t** allocs = j->job.allocs->allocs;
|
||||
worker_t* w;
|
||||
if (j->job->allocs != NULL) {
|
||||
xce_host_alloc_t** allocs = j->job->allocs->allocs;
|
||||
worker_t* w = NULL;
|
||||
|
||||
/* job control command will be sent to first node
|
||||
* for parallel jobs
|
||||
*/
|
||||
w = workermgr_lock(&(c->workermgr), allocs[0]->host, OBJREF_READ);
|
||||
rc = key_find(c->workermgr, (void*)allocs[0]->host, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
if (w != NULL) {
|
||||
/* FIXME: better method to check host status */
|
||||
if ((w->ep != NULL) && (w->host.status == 0)) {
|
||||
if ((w->ep != NULL) && (w->host->status == 0)) {
|
||||
rc = xce_jobctrl_req(w->ep, ctrinfo);
|
||||
if (rc < 0) {
|
||||
ERROR("job ctrl %ld on host %s returns %d", jobid,
|
||||
w->host.name, rc);
|
||||
w->host->name, rc);
|
||||
}
|
||||
} else {
|
||||
ERROR("worker %s is not in correct state, status %x ep %p",
|
||||
w->host.name, w->host.status, w->ep);
|
||||
w->host->name, w->host->status, w->ep);
|
||||
rc = -errno;
|
||||
}
|
||||
obj_deref(w);
|
||||
} else {
|
||||
PERROR("workermgr_lock");
|
||||
rc = -errno;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -311,9 +322,9 @@ int job_ctrl(cluster_t* c, xce_jobctrl_t* ctrinfo)
|
|||
case JobControl_u_siginfo:
|
||||
switch (ctrinfo->u.siginfo->signo) {
|
||||
case SIGCONT:
|
||||
if (j->job.state
|
||||
if (j->job->state
|
||||
& (JOB_STAT_PSUSP | JOB_STAT_USUSP | JOB_STAT_SSUSP)) {
|
||||
int state = j->job.state;
|
||||
int state = j->job->state;
|
||||
|
||||
/* resume suspend job? */
|
||||
state &= ~(JOB_STAT_PSUSP | JOB_STAT_USUSP);
|
||||
|
|
@ -322,9 +333,9 @@ int job_ctrl(cluster_t* c, xce_jobctrl_t* ctrinfo)
|
|||
break;
|
||||
case SIGSTOP:
|
||||
case SIGTSTP:
|
||||
if (!(j->job.state
|
||||
if (!(j->job->state
|
||||
& (JOB_STAT_PSUSP | JOB_STAT_USUSP | JOB_STAT_SSUSP))) {
|
||||
int state = j->job.state;
|
||||
int state = j->job->state;
|
||||
|
||||
state |= JOB_STAT_PSUSP;
|
||||
mark_job_update(c, j, state);
|
||||
|
|
@ -333,7 +344,7 @@ int job_ctrl(cluster_t* c, xce_jobctrl_t* ctrinfo)
|
|||
case SIGKILL:
|
||||
case SIGTERM:
|
||||
default:
|
||||
if (j->job.state
|
||||
if (j->job->state
|
||||
& (JOB_STAT_DONE | JOB_STAT_EXIT | JOB_STAT_ERR)) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -346,7 +357,8 @@ int job_ctrl(cluster_t* c, xce_jobctrl_t* ctrinfo)
|
|||
}
|
||||
break;
|
||||
case JobControl_u_ckptoption:
|
||||
if (j->job.state & (JOB_STAT_DONE | JOB_STAT_EXIT | JOB_STAT_ERR)) {
|
||||
if (j->job->state
|
||||
& (JOB_STAT_DONE | JOB_STAT_EXIT | JOB_STAT_ERR)) {
|
||||
ERROR("job <%ld> has been finished, no checkpoint can be done.",
|
||||
jobid);
|
||||
} else {
|
||||
|
|
@ -433,6 +445,7 @@ int handle_jobsubmit(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
|||
xlist_t jlist;
|
||||
job_t* j = NULL;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
submit = request->body.jobsubmsg;
|
||||
|
||||
|
|
@ -467,8 +480,8 @@ int handle_jobsubmit(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
|||
|
||||
for (i = 0; i < submit->array_size; i++) {
|
||||
/* Run hooks to tell scheduler */
|
||||
j = jobmgr_lockjob(&(c->jobmgr), jobid + i, OBJREF_READ);
|
||||
if (j == NULL) {
|
||||
rc = key_find(c->jobmgr, (void*)(jobid + i), (void**)&j);
|
||||
if ((rc <= 0) || (j == NULL)) {
|
||||
char idstring[128];
|
||||
|
||||
fmt_jobid(idstring, sizeof(idstring) - 1, jobid);
|
||||
|
|
@ -496,21 +509,20 @@ static int mark_job_start(cluster_t* c, job_t* job, job_pidinfo_t* info)
|
|||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_JOB_START, c, info, job);
|
||||
/* update job information */
|
||||
job->job.state = JOB_STAT_RUN;
|
||||
job->job.start_time = time(NULL);
|
||||
if (job->job.pidinfo == NULL) {
|
||||
job->job.pidinfo = (job_pidinfo_t*)calloc(1, sizeof(job_pidinfo_t));
|
||||
job->job->state = JOB_STAT_RUN;
|
||||
job->job->start_time = time(NULL);
|
||||
if (job->job->pidinfo == NULL) {
|
||||
job->job->pidinfo = (job_pidinfo_t*)calloc(1, sizeof(job_pidinfo_t));
|
||||
}
|
||||
|
||||
job->job.pidinfo->npids = copy_int_list((int**)&(job->job.pidinfo->pids),
|
||||
job->job->pidinfo->npids = copy_int_list((int**)&(job->job->pidinfo->pids),
|
||||
(int*)info->pids, info->npids);
|
||||
job->job.pidinfo->npgids = copy_int_list((int**)&(job->job.pidinfo->pgids),
|
||||
(int*)info->pgids, info->npgids);
|
||||
job->job->pidinfo->npgids = copy_int_list(
|
||||
(int**)&(job->job->pidinfo->pgids), (int*)info->pgids, info->npgids);
|
||||
if (info->exdata != NULL) {
|
||||
job->job.pidinfo->exdata
|
||||
= create_obj_by_typename(&(c->objmgr), "xstring", info->exdata);
|
||||
job->job->pidinfo->exdata = makeString(info->exdata);
|
||||
} else {
|
||||
job->job.pidinfo->exdata = NULL;
|
||||
job->job->pidinfo->exdata = NULL;
|
||||
}
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
|
||||
|
|
@ -522,20 +534,19 @@ static int mark_job_start(cluster_t* c, job_t* job, job_pidinfo_t* info)
|
|||
int on_job_start(cluster_t* c, job_pidinfo_t* info)
|
||||
{
|
||||
job_t* job = NULL;
|
||||
int rc;
|
||||
|
||||
TRACE("%s jobid %ld", __func__, info->jobid);
|
||||
|
||||
job = jobmgr_lockjob(&(c->jobmgr), info->jobid, OBJREF_UPDATE);
|
||||
if (job == NULL) {
|
||||
rc = key_find(c->jobmgr, (void*)info->jobid, (void**)&job);
|
||||
|
||||
if ((rc <= 0) || (job == NULL)) {
|
||||
ERROR("can not find job %ld", info->jobid);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
mark_job_start(c, job, info);
|
||||
|
||||
/* unlock the job */
|
||||
DEREF_OBJ(job);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -545,23 +556,24 @@ static int mark_job_finish(cluster_t* c, job_t* job, xce_jobfinish_t* finish)
|
|||
HOOK_DETAIL_JOB_EXIT, c, finish, job);
|
||||
/* update job information */
|
||||
if (finish->exit_code == 0) {
|
||||
job->job.state = JOB_STAT_DONE;
|
||||
job->job->state = JOB_STAT_DONE;
|
||||
} else {
|
||||
job->job.state = JOB_STAT_EXIT;
|
||||
job->job->state = JOB_STAT_EXIT;
|
||||
}
|
||||
job->job.finish_time = time(NULL);
|
||||
job->job->finish_time = time(NULL);
|
||||
|
||||
/* fill job run time/rusage information */
|
||||
|
||||
if (job->job.exit_info == NULL) {
|
||||
job->job.exit_info = (job_exitinfo_t*)calloc(1, sizeof(job_exitinfo_t));
|
||||
if (job->job->exit_info == NULL) {
|
||||
job->job->exit_info
|
||||
= (job_exitinfo_t*)calloc(1, sizeof(job_exitinfo_t));
|
||||
}
|
||||
|
||||
if (job->job.exit_info != NULL) {
|
||||
job->job.exit_info->exitcode = finish->exit_code;
|
||||
if (job->job->exit_info != NULL) {
|
||||
job->job->exit_info->exitcode = finish->exit_code;
|
||||
}
|
||||
|
||||
job->job.run_time = job->job.finish_time - job->job.start_time;
|
||||
job->job->run_time = job->job->finish_time - job->job->start_time;
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_JOB_EXIT, c, finish, job);
|
||||
|
|
@ -576,7 +588,8 @@ int on_job_finish(cluster_t* c, xce_jobfinish_t* finish)
|
|||
TRACE("%s job finish jobid %ld exit code %d", __func__, finish->jobid,
|
||||
finish->exit_code);
|
||||
|
||||
job = jobmgr_lockjob(&(c->jobmgr), finish->jobid, OBJREF_UPDATE);
|
||||
key_find(c->jobmgr, (void*)finish->jobid, (void**)&job);
|
||||
|
||||
if (job == NULL) {
|
||||
ERROR("can not find job %ld", finish->jobid);
|
||||
return -errno;
|
||||
|
|
@ -584,9 +597,6 @@ int on_job_finish(cluster_t* c, xce_jobfinish_t* finish)
|
|||
|
||||
mark_job_finish(c, job, finish);
|
||||
|
||||
/* unlock the job */
|
||||
DEREF_OBJ(job);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -599,20 +609,20 @@ static int mark_job_fail(cluster_t* c, job_t* job, job_failinfo_t* failinfo)
|
|||
switch (failinfo->stage) {
|
||||
case JOB_EXEC_STAGE_Q_POST_EXEC:
|
||||
case JOB_EXEC_STAGE_POST_EXEC:
|
||||
if ((job->job.state & (JOB_STAT_EXIT | JOB_STAT_DONE)) == 0) {
|
||||
if ((job->job->state & (JOB_STAT_EXIT | JOB_STAT_DONE)) == 0) {
|
||||
WARN("job %ld got post exec fail notification but job's exit "
|
||||
"status has not been set",
|
||||
job->job.jobid);
|
||||
job->job.state |= JOB_STAT_EXIT;
|
||||
job->job->jobid);
|
||||
job->job->state |= JOB_STAT_EXIT;
|
||||
}
|
||||
job->job.state |= JOB_STAT_PERR;
|
||||
job->job->state |= JOB_STAT_PERR;
|
||||
break;
|
||||
default:
|
||||
job->job.state = JOB_STAT_EXIT;
|
||||
job->job->state = JOB_STAT_EXIT;
|
||||
break;
|
||||
}
|
||||
|
||||
job->job.finish_time = time(NULL);
|
||||
job->job->finish_time = time(NULL);
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_JOB_FAIL, c, failinfo, job);
|
||||
|
|
@ -625,7 +635,7 @@ static int mark_job_update(cluster_t* c, job_t* job, int state)
|
|||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_JOB_UPDATE, c, job);
|
||||
/* update job state */
|
||||
job->job.state = state;
|
||||
job->job->state = state;
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_JOB_UPDATE, c, job);
|
||||
|
|
@ -640,7 +650,7 @@ int on_job_fail(cluster_t* c, job_failinfo_t* failinfo)
|
|||
TRACE("%s job fail jobid %ld code %d", __func__, failinfo->jobid,
|
||||
failinfo->code);
|
||||
|
||||
job = jobmgr_lockjob(&(c->jobmgr), failinfo->jobid, OBJREF_UPDATE);
|
||||
key_find(c->jobmgr, (void*)failinfo->jobid, (void**)&job);
|
||||
if (job == NULL) {
|
||||
ERROR("can not find job %ld", failinfo->jobid);
|
||||
return -errno;
|
||||
|
|
@ -648,9 +658,6 @@ int on_job_fail(cluster_t* c, job_failinfo_t* failinfo)
|
|||
|
||||
mark_job_fail(c, job, failinfo);
|
||||
|
||||
/* unlock the job */
|
||||
DEREF_OBJ(job);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -661,20 +668,17 @@ int on_job_stop(cluster_t* c, uint64_t jobid)
|
|||
|
||||
TRACE("%s job stop jobid %ld", __func__, jobid);
|
||||
|
||||
job = jobmgr_lockjob(&(c->jobmgr), jobid, OBJREF_UPDATE);
|
||||
key_find(c->jobmgr, (void*)jobid, (void**)&job);
|
||||
if (job == NULL) {
|
||||
ERROR("can not find job %ld", jobid);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
state = job->job.state;
|
||||
state = job->job->state;
|
||||
|
||||
state |= JOB_STAT_USUSP;
|
||||
mark_job_update(c, job, state);
|
||||
|
||||
/* unlock the job */
|
||||
DEREF_OBJ(job);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -685,19 +689,16 @@ int on_job_resume(cluster_t* c, uint64_t jobid)
|
|||
|
||||
TRACE("%s job resume jobid %ld", __func__, jobid);
|
||||
|
||||
job = jobmgr_lockjob(&(c->jobmgr), jobid, OBJREF_UPDATE);
|
||||
key_find(c->jobmgr, (void*)jobid, (void**)&job);
|
||||
if (job == NULL) {
|
||||
ERROR("can not find job %ld", jobid);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
state = job->job.state;
|
||||
state = job->job->state;
|
||||
state &= ~JOB_STAT_USUSP;
|
||||
mark_job_update(c, job, state);
|
||||
|
||||
/* unlock the job */
|
||||
DEREF_OBJ(job);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -708,28 +709,25 @@ int on_job_postdone(cluster_t* c, endpoint_t* ep, uint64_t jobid)
|
|||
|
||||
TRACE("%s job post done jobid %ld", __func__, jobid);
|
||||
|
||||
job = jobmgr_lockjob(&(c->jobmgr), jobid, OBJREF_UPDATE);
|
||||
key_find(c->jobmgr, (void*)jobid, (void**)&job);
|
||||
if (job == NULL) {
|
||||
ERROR("can not find job %ld", jobid);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
state = job->job.state;
|
||||
state = job->job->state;
|
||||
if ((state & (JOB_STAT_EXIT | JOB_STAT_DONE)) == 0) {
|
||||
WARN("job %ld got post exec fail notification but job's exit status "
|
||||
"has not been set",
|
||||
job->job.jobid);
|
||||
job->job->jobid);
|
||||
state |= JOB_STAT_EXIT;
|
||||
/* ensure that job finish time has been set */
|
||||
job->job.finish_time = time(NULL);
|
||||
job->job->finish_time = time(NULL);
|
||||
}
|
||||
|
||||
state |= JOB_STAT_PDONE;
|
||||
mark_job_update(c, job, state);
|
||||
|
||||
/* unlock the job */
|
||||
DEREF_OBJ(job);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -737,7 +735,7 @@ int on_job_ckpt(cluster_t* c, endpoint_t* ep, xce_ckptinfo_t* ckptinfo)
|
|||
{
|
||||
uint64_t jobid;
|
||||
char* info = NULL;
|
||||
job_t* j;
|
||||
job_t* j = NULL;
|
||||
|
||||
if (ckptinfo == NULL) {
|
||||
ERROR("%s ckptinfo should not be NULL", __func__);
|
||||
|
|
@ -749,7 +747,8 @@ int on_job_ckpt(cluster_t* c, endpoint_t* ep, xce_ckptinfo_t* ckptinfo)
|
|||
|
||||
TRACE("%s job %ld ckptinfo %s", __func__, jobid, info);
|
||||
|
||||
j = jobmgr_lockjob(&(c->jobmgr), jobid, OBJREF_UPDATE);
|
||||
key_find(c->jobmgr, (void*)jobid, (void**)&j);
|
||||
|
||||
if (j == NULL) {
|
||||
ERROR("%s can not find job %ld", __func__, jobid);
|
||||
return -errno;
|
||||
|
|
@ -757,11 +756,12 @@ int on_job_ckpt(cluster_t* c, endpoint_t* ep, xce_ckptinfo_t* ckptinfo)
|
|||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_JOB_CKPT, c, j);
|
||||
if (j->job.ckptinfo != NULL) {
|
||||
obj_deref(j->job.ckptinfo);
|
||||
if (j->job->ckptinfo != NULL) {
|
||||
obj_deref(j->job->ckptinfo);
|
||||
}
|
||||
|
||||
j->job.ckptinfo = create_obj_by_typename(&(c->objmgr), "xstring", info);
|
||||
j->job->ckptinfo = makeString(info);
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_JOB_CKPT, c, j);
|
||||
|
||||
|
|
@ -788,8 +788,8 @@ int do_jobcontrol_op(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
|||
int update_job_rusages(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
||||
{
|
||||
xce_job_rusages_t* rusages = request->body.updatemsg->data.jobrusages;
|
||||
job_t* j;
|
||||
worker_t* w;
|
||||
job_t* j = NULL;
|
||||
worker_t* w = NULL;
|
||||
char* host = NULL;
|
||||
|
||||
TRACE("%s trying to update job(%ld) rusage", __func__, rusages->jobid);
|
||||
|
|
@ -797,19 +797,19 @@ int update_job_rusages(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
|||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_JOB_RUSAGE_UPDATE, c, rusages);
|
||||
|
||||
j = jobmgr_lockjob(&(c->jobmgr), rusages->jobid, OBJREF_UPDATE);
|
||||
key_find(c->jobmgr, (void*)rusages->jobid, (void**)&j);
|
||||
if (j == NULL) {
|
||||
PERROR("jobmgr_lockjob");
|
||||
return -errno;
|
||||
}
|
||||
|
||||
w = get_ep_worker(c, ep, OBJREF_READ);
|
||||
w = get_ep_worker(c, ep);
|
||||
if (w == NULL) {
|
||||
obj_deref(j);
|
||||
return errno;
|
||||
}
|
||||
|
||||
host = create_obj_by_typename(&(c->objmgr), "xstring", w->host.name);
|
||||
host = makeString(w->host->name);
|
||||
obj_deref(w);
|
||||
|
||||
if (host == NULL) {
|
||||
|
|
@ -821,12 +821,12 @@ int update_job_rusages(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
|||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_JOB_UPDATE, c, j);
|
||||
update_host_runusage(&(j->job.run_usage), host, rusages->count,
|
||||
update_host_runusage(&(j->job->run_usage), host, rusages->count,
|
||||
rusages->usages);
|
||||
|
||||
update_pids(&(j->job.pidinfo), rusages->npids, rusages->pids);
|
||||
update_pids(&(j->job->pidinfo), rusages->npids, rusages->pids);
|
||||
|
||||
update_pgids(&(j->job.pidinfo), rusages->npgids, rusages->pgids);
|
||||
update_pgids(&(j->job->pidinfo), rusages->npgids, rusages->pgids);
|
||||
|
||||
/* FIXME
|
||||
* update other fields of job rusage later
|
||||
|
|
@ -843,12 +843,12 @@ int update_job_rusages(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
|||
|
||||
static int set_preason(cluster_t* c, xce_pendreason_t* reasons)
|
||||
{
|
||||
job_t* j;
|
||||
xce_job_t* job;
|
||||
job_t* j = NULL;
|
||||
xce_job_t* job = NULL;
|
||||
|
||||
TRACE("%s jobid %ld", __func__, reasons->jobid);
|
||||
|
||||
j = jobmgr_lockjob(&(c->jobmgr), reasons->jobid, OBJREF_UPDATE);
|
||||
key_find(c->jobmgr, (void*)reasons->jobid, (void**)&j);
|
||||
if (j == NULL) {
|
||||
PERROR("jobmgr_lockjob");
|
||||
return -ENOENT;
|
||||
|
|
@ -856,7 +856,7 @@ static int set_preason(cluster_t* c, xce_pendreason_t* reasons)
|
|||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_SETPREASON, c, j);
|
||||
job = &(j->job);
|
||||
job = j->job;
|
||||
if (job->pend_reasons != NULL) {
|
||||
erase_job_preason(job->pend_reasons);
|
||||
FREEUP(job->pend_reasons);
|
||||
|
|
@ -865,7 +865,6 @@ static int set_preason(cluster_t* c, xce_pendreason_t* reasons)
|
|||
MOVE_PTR(job->pend_reasons, reasons->reasons);
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_SETPREASON, c, j);
|
||||
obj_deref(j);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -915,7 +914,7 @@ int do_clr_preason(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
|||
job_t* j;
|
||||
xce_job_t* job;
|
||||
|
||||
j = jobmgr_lockjob(&(c->jobmgr), jobid, OBJREF_UPDATE);
|
||||
key_find(c->jobmgr, (void*)jobid, (void**)&j);
|
||||
if (j == NULL) {
|
||||
PERROR("jobmgr_lockjob");
|
||||
continue;
|
||||
|
|
@ -924,7 +923,7 @@ int do_clr_preason(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
|||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_JOB, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_CLRPREASON, c, j);
|
||||
|
||||
job = &(j->job);
|
||||
job = j->job;
|
||||
if (job->pend_reasons != NULL) {
|
||||
erase_job_preason(job->pend_reasons);
|
||||
FREEUP(job->pend_reasons);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ controller_src = [
|
|||
'sched.c',
|
||||
'task.c',
|
||||
'worker.c',
|
||||
'xceobjs.c',
|
||||
'apiserver.c',
|
||||
'myconf.c',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -47,10 +47,11 @@ int get_ep_role(endpoint_t* ep)
|
|||
return priv->role;
|
||||
}
|
||||
|
||||
worker_t* get_ep_worker(cluster_t* c, endpoint_t* ep, int op)
|
||||
worker_t* get_ep_worker(cluster_t* c, endpoint_t* ep)
|
||||
{
|
||||
int role, idx;
|
||||
worker_t* w = NULL;
|
||||
int rc = 0;
|
||||
|
||||
role = get_ep_role(ep);
|
||||
if (role != HostRole_worker) {
|
||||
|
|
@ -64,7 +65,11 @@ worker_t* get_ep_worker(cluster_t* c, endpoint_t* ep, int op)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
w = workermgr_lock_byid(&(c->workermgr), idx, op);
|
||||
rc = key_find(c->workermgr, (void*)idx, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (w == NULL) {
|
||||
ERROR("can not find worker with id (%d)", idx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "controller.capnp.h"
|
||||
#include "myconf.h"
|
||||
#include "configobj.h"
|
||||
#include "objmgr.h"
|
||||
#include "utils.h"
|
||||
#include "xce/cluster_def.h"
|
||||
|
|
@ -17,7 +18,7 @@ int add_config(void* c, char* name, char* value)
|
|||
xce_config_t cvar = { .name = name, .value = value };
|
||||
xce_config_t* cv = NULL;
|
||||
|
||||
cv = create_obj_by_typename(&(cls->objmgr), "xconfig", &cvar);
|
||||
cv = makeConfig(&cvar);
|
||||
if (cv == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,16 +148,16 @@ static int do_reply_joblist(cluster_t* c, endpoint_t* ep,
|
|||
init_reply_by_req(&reply, request);
|
||||
|
||||
if (match->type == MatchCondition_condition_matchjid) {
|
||||
job_t* j;
|
||||
job_t* j = NULL;
|
||||
|
||||
jobdata.n_total = 0;
|
||||
jobdata.jobs = NULL;
|
||||
|
||||
j = jobmgr_lockjob(&(c->jobmgr), match->condition.jobid, OBJREF_READ);
|
||||
if (j != NULL) {
|
||||
rc = key_find(c->jobmgr, (void*)match->condition.jobid, (void**)&j);
|
||||
if (rc > 0) {
|
||||
jobdata.jobs = (xce_job_t**)calloc(1, sizeof(xce_job_t*));
|
||||
if (jobdata.jobs != NULL) {
|
||||
jobdata.jobs[0] = &(j->job);
|
||||
jobdata.jobs[0] = j->job;
|
||||
jobdata.n_total = 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ static int do_update_resvals(cluster_t* c, endpoint_t* ep,
|
|||
int idx = priv->u.idx;
|
||||
|
||||
if ((priv->role == HostRole_worker) && (idx >= 0)) {
|
||||
worker_t* w;
|
||||
worker_t* w = NULL;
|
||||
|
||||
w = workermgr_lock_byid(&(c->workermgr), idx, OBJREF_UPDATE);
|
||||
rc = vget(c->workermgr, idx, (void**)&w);
|
||||
if (w == NULL) {
|
||||
rc = -E_XCE_BAD_WORKER;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "cluster.h"
|
||||
#include "qobj.h"
|
||||
#include "xce/cluster_def.h"
|
||||
#include "xce/types.h"
|
||||
#include "xstring.h"
|
||||
|
||||
void queue_fini(queue_t* q)
|
||||
{
|
||||
|
|
@ -15,12 +17,14 @@ void queue_fini(queue_t* q)
|
|||
|
||||
queue_t* create_queue(cluster_t* c, xce_queue_t* p)
|
||||
{
|
||||
queue_t q1;
|
||||
queue_t* q;
|
||||
|
||||
memcpy(&(q1.queue), p, sizeof(q1.queue));
|
||||
q = calloc(1, sizeof(*q));
|
||||
if (q == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
q = create_obj_by_typename(&(c->objmgr), "xqueue", &q1);
|
||||
q->queue = makeQueue(p);
|
||||
return q;
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +60,11 @@ int queue_ctrl(cluster_t* c, xce_queuectrl_t* ctrl)
|
|||
return -EINVAL;
|
||||
}
|
||||
TRACE("%s queue_ctrl queue %s", __func__, ctrl->queue);
|
||||
q = qmgr_lockq(&(c->qmgr), ctrl->queue, OBJREF_UPDATE);
|
||||
rc = key_find(c->qmgr, (void*)ctrl->queue, (void**)&q);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (q == NULL) {
|
||||
PERROR("qmgr_lockq");
|
||||
return -ENOENT;
|
||||
|
|
@ -64,28 +72,28 @@ int queue_ctrl(cluster_t* c, xce_queuectrl_t* ctrl)
|
|||
|
||||
switch (ctrl->action) {
|
||||
case QUEUE_OPEN:
|
||||
if (!(q->queue.status & QUEUE_STAT_CLOSED)) {
|
||||
if (!(q->queue->status & QUEUE_STAT_CLOSED)) {
|
||||
goto clean;
|
||||
}
|
||||
q->queue.status &= ~QUEUE_STAT_CLOSED;
|
||||
q->queue->status &= ~QUEUE_STAT_CLOSED;
|
||||
break;
|
||||
case QUEUE_CLOSE:
|
||||
if (q->queue.status & QUEUE_STAT_CLOSED) {
|
||||
if (q->queue->status & QUEUE_STAT_CLOSED) {
|
||||
goto clean;
|
||||
}
|
||||
q->queue.status |= QUEUE_STAT_CLOSED;
|
||||
q->queue->status |= QUEUE_STAT_CLOSED;
|
||||
break;
|
||||
case QUEUE_INACTIVE:
|
||||
if (q->queue.status & QUEUE_STAT_INACT_ADMIN) {
|
||||
if (q->queue->status & QUEUE_STAT_INACT_ADMIN) {
|
||||
goto clean;
|
||||
}
|
||||
q->queue.status |= QUEUE_STAT_INACT_ADMIN;
|
||||
q->queue->status |= QUEUE_STAT_INACT_ADMIN;
|
||||
break;
|
||||
case QUEUE_ACTIVE:
|
||||
if (!(q->queue.status & QUEUE_STAT_INACT_ADMIN)) {
|
||||
if (!(q->queue->status & QUEUE_STAT_INACT_ADMIN)) {
|
||||
goto clean;
|
||||
}
|
||||
q->queue.status &= ~QUEUE_STAT_INACT_ADMIN;
|
||||
q->queue->status &= ~QUEUE_STAT_INACT_ADMIN;
|
||||
break;
|
||||
default:
|
||||
rc = -1;
|
||||
|
|
@ -118,6 +126,7 @@ int do_queuecontrol_op(cluster_t* c, endpoint_t* ep, xce_request_t* request)
|
|||
int get_queue_exec(cluster_t* c, char* queue, char** pre_exec, char** post_exec)
|
||||
{
|
||||
queue_t* q = NULL;
|
||||
int rc = 0;
|
||||
|
||||
TRACE("entering %s", __func__);
|
||||
|
||||
|
|
@ -128,22 +137,24 @@ int get_queue_exec(cluster_t* c, char* queue, char** pre_exec, char** post_exec)
|
|||
|
||||
TRACE("%s queue %s", __func__, queue);
|
||||
|
||||
q = qmgr_lockq(&(c->qmgr), queue, OBJREF_READ);
|
||||
rc = key_find(c->qmgr, (void*)queue, (void**)&q);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (q == NULL) {
|
||||
PERROR("qmgr_lockq");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (q->queue.pre_exec != NULL) {
|
||||
*pre_exec = create_obj_by_typename(&(c->objmgr), "xstring",
|
||||
q->queue.pre_exec);
|
||||
if (q->queue->pre_exec != NULL) {
|
||||
*pre_exec = makeString(q->queue->pre_exec);
|
||||
} else {
|
||||
*pre_exec = NULL;
|
||||
}
|
||||
|
||||
if (q->queue.post_exec != NULL) {
|
||||
*post_exec = create_obj_by_typename(&(c->objmgr), "xstring",
|
||||
q->queue.post_exec);
|
||||
if (q->queue->post_exec != NULL) {
|
||||
*post_exec = makeString(q->queue->post_exec);
|
||||
} else {
|
||||
*post_exec = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ static int sched_job_update_fun(int type, int situation, void* data, va_list ap)
|
|||
xce_notify_data_t xdata = {
|
||||
.event = NotifyData_data_schedUpdateJob,
|
||||
.data = {
|
||||
.sched_update_job = &(job->job)
|
||||
.sched_update_job = job->job
|
||||
}
|
||||
};
|
||||
/* clang-format on */
|
||||
|
|
@ -419,11 +419,11 @@ static int sched_worker_change(int type, int situation, void* data,
|
|||
int rc = 0;
|
||||
xlist_t wlist;
|
||||
|
||||
TRACE("%s worker %s idx %d situation %d", __func__, w->host.name, w->idx,
|
||||
TRACE("%s worker %s idx %d situation %d", __func__, w->host->name, w->idx,
|
||||
situation);
|
||||
|
||||
collect_resval_with_idx(&(w->host.resvals), &(w->host.nresvals_to_sched),
|
||||
&(w->host.resvals_to_sched));
|
||||
collect_resval_with_idx(&(w->host->resvals), &(w->host->nresvals_to_sched),
|
||||
&(w->host->resvals_to_sched));
|
||||
|
||||
mylock_lock(&(c->sched.lock));
|
||||
if (c->sched.ep != NULL) {
|
||||
|
|
@ -440,8 +440,8 @@ static int sched_worker_change(int type, int situation, void* data,
|
|||
}
|
||||
mylock_unlock(&(c->sched.lock));
|
||||
|
||||
free_resval_with_idx_list(&(w->host.resvals_to_sched),
|
||||
w->host.nresvals_to_sched);
|
||||
free_resval_with_idx_list(&(w->host->resvals_to_sched),
|
||||
w->host->nresvals_to_sched);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -458,7 +458,14 @@ static int sched_worker_join(int type, int situation, void* data, va_list ap)
|
|||
return 0;
|
||||
}
|
||||
|
||||
w = workermgr_lock(&(c->workermgr), name, OBJREF_READ);
|
||||
rc = key_find(c->workermgr, (void *)name, (void **)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
rc = sched_worker_change(type, situation, data, c, w);
|
||||
|
||||
|
|
@ -551,7 +558,7 @@ static int sched_queue_update(int type,
|
|||
xce_notify_data_t xdata = {
|
||||
.event = NotifyData_data_schedUpdateQueue,
|
||||
.data = {
|
||||
.sched_update_queue = &(q->queue)
|
||||
.sched_update_queue = q->queue
|
||||
}
|
||||
};
|
||||
/* clang-format on */
|
||||
|
|
|
|||
|
|
@ -17,12 +17,16 @@ static int run_tasks_on_host(cluster_t* c, endpoint_t* ep, uint64_t jobid,
|
|||
.clientidx = ep->idx,
|
||||
.taskhosts = (xce_taskhost_t*[]) { info } };
|
||||
|
||||
w = workermgr_lock(&(c->workermgr), info->host, OBJREF_READ);
|
||||
rc = key_find(c->workermgr, (void*)info->host, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (w == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if ((w->ep == NULL) || (IS_WORKER_UNAVAIL(w->host.status))) {
|
||||
if ((w->ep == NULL) || (IS_WORKER_UNAVAIL(w->host->status))) {
|
||||
obj_deref(w);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -40,19 +44,24 @@ static int check_task_hosts(cluster_t* c, xce_taskrun_t* runmsg)
|
|||
|
||||
for (i = 0; i < runmsg->nhosts; i++) {
|
||||
worker_t* w;
|
||||
int rc = 0;
|
||||
|
||||
w = workermgr_lock(&(c->workermgr), runmsg->taskhosts[i]->host,
|
||||
OBJREF_READ);
|
||||
rc = key_find(c->workermgr, (void*)runmsg->taskhosts[i]->host,
|
||||
(void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
return -ENOENT;
|
||||
}
|
||||
if (w == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if ((w->ep == NULL) || IS_WORKER_UNAVAIL(w->host.status)) {
|
||||
obj_deref(w);
|
||||
if ((w->ep == NULL) || IS_WORKER_UNAVAIL(w->host->status)) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
obj_deref(w);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "cluster.h"
|
||||
#include "wobj.h"
|
||||
#include "worker.h"
|
||||
#include "xce/cluster_def.h"
|
||||
#include "xce/errnox.h"
|
||||
#include "xstring.h"
|
||||
|
||||
static int hostmatched(const char* pattern, const char* name)
|
||||
{
|
||||
|
|
@ -68,7 +70,7 @@ static int update_val_res(cluster_t* c, worker_t* w, xce_resource_t* r,
|
|||
array = &(c->sharedinst);
|
||||
} else {
|
||||
/* update host based resource */
|
||||
array = &(w->host.resvals);
|
||||
array = &(w->host->resvals);
|
||||
}
|
||||
|
||||
if (idx < array->caps) {
|
||||
|
|
@ -95,11 +97,14 @@ static int update_val_res(cluster_t* c, worker_t* w, xce_resource_t* r,
|
|||
|
||||
static int update_resval(cluster_t* c, worker_t* w, xce_resval_t* val)
|
||||
{
|
||||
xce_resource_t* r;
|
||||
xce_resource_t* r = NULL;
|
||||
xce_val_t* v = NULL;
|
||||
int rc;
|
||||
|
||||
r = resmgr_lockres(&(c->resmgr), val->name, OBJREF_READ);
|
||||
rc = key_find(c->resmgr, (void*)val->name, (void**)&r);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
if (r == NULL) {
|
||||
ERROR("resource `%s' can not be found", val->name);
|
||||
return -errno;
|
||||
|
|
@ -114,8 +119,6 @@ static int update_resval(cluster_t* c, worker_t* w, xce_resval_t* val)
|
|||
|
||||
rc = update_val_res(c, w, r, v);
|
||||
|
||||
obj_deref(r);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
@ -151,14 +154,18 @@ int update_resval_list(cluster_t* c, worker_t* w, xce_resval_list_t* l)
|
|||
|
||||
static int mark_host_res(cluster_t* c, worker_t* w, xce_config_t* config)
|
||||
{
|
||||
xce_resource_t* r;
|
||||
xce_resource_t* r = NULL;
|
||||
char* n = config->name;
|
||||
int rc;
|
||||
/* clang-format-off */
|
||||
xce_val_t val;
|
||||
/* clang-format-on */
|
||||
|
||||
r = resmgr_lockres(&(c->resmgr), n, OBJREF_READ);
|
||||
rc = key_find(c->resmgr, (void*)n, (void**)&r);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (r == NULL) {
|
||||
ERROR("resource `%s' can not be found", n);
|
||||
return -ENOENT;
|
||||
|
|
@ -199,7 +206,6 @@ static int mark_host_res(cluster_t* c, worker_t* w, xce_config_t* config)
|
|||
}
|
||||
rc = update_val_res(c, w, r, &val);
|
||||
|
||||
obj_deref(r);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
@ -207,16 +213,17 @@ static int add_hostattrs_resvals(cluster_t* c, worker_t* w)
|
|||
{
|
||||
#define N_HOST_ATTRS (8)
|
||||
xce_val_t values[N_HOST_ATTRS] = {
|
||||
{ .which = Value_u_svalue, .u = { .svalue = w->host.attrs->hosttype } },
|
||||
{ .which = Value_u_svalue,
|
||||
.u = { .svalue = w->host.attrs->hostmodel } },
|
||||
.u = { .svalue = w->host->attrs->hosttype } },
|
||||
{ .which = Value_u_svalue,
|
||||
.u = { .svalue = w->host->attrs->hostmodel } },
|
||||
{ .which = Value_u_fvalue,
|
||||
.u = { .fvalue = w->host.attrs->cpufactor } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxcpus } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxmem } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxswap } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->maxtmp } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host.attrs->ndisks } }
|
||||
.u = { .fvalue = w->host->attrs->cpufactor } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->maxcpus } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->maxmem } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->maxswap } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->maxtmp } },
|
||||
{ .which = Value_u_fvalue, .u = { .fvalue = w->host->attrs->ndisks } }
|
||||
};
|
||||
xce_resval_t resvals[N_HOST_ATTRS] = {
|
||||
{ .name = "type", .val = &values[0] },
|
||||
|
|
@ -259,7 +266,7 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
|
|||
cluster_t* c = (cluster_t*)cls;
|
||||
/* clang-format off */
|
||||
worker_t worker = {
|
||||
.host = {
|
||||
.host = &(xce_worker_t){
|
||||
.name = (char*)host,
|
||||
}
|
||||
};
|
||||
|
|
@ -273,35 +280,38 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
w = calloc(1, sizeof(*w));
|
||||
if (w == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
hconfig = find_matched_hostconfig(c, host);
|
||||
if (hconfig == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
worker.host.attrs = attrs;
|
||||
worker.host->attrs = attrs;
|
||||
|
||||
w = create_obj_by_typename(&(c->objmgr), "xworker", &worker);
|
||||
if (w == NULL) {
|
||||
w->host = makeWorker(worker.host);
|
||||
if (w->host == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* we should hold the update lock */
|
||||
/* If admin makes the host in locked or closed, we need keep this */
|
||||
w->host.status &= ~XCE_WORKER_UNAVAIL; /* status OK */
|
||||
w->host->status &= ~XCE_WORKER_UNAVAIL; /* status OK */
|
||||
w->ep = ep;
|
||||
|
||||
/* override host type? */
|
||||
if (strcmp(hconfig->hosttype, "!") != 0) {
|
||||
obj_deref(w->host.attrs->hosttype);
|
||||
w->host.attrs->hosttype = create_obj_by_typename(
|
||||
&(c->objmgr), "xstring", hconfig->hosttype);
|
||||
dereference(w->host->attrs->hosttype);
|
||||
w->host->attrs->hosttype = makeString(hconfig->hosttype);
|
||||
}
|
||||
|
||||
/* override host model */
|
||||
if (strcmp(hconfig->hostmodel, "!") != 0) {
|
||||
obj_deref(w->host.attrs->hostmodel);
|
||||
w->host.attrs->hostmodel = create_obj_by_typename(
|
||||
&(c->objmgr), "xstring", hconfig->hostmodel);
|
||||
dereference(w->host->attrs->hostmodel);
|
||||
w->host->attrs->hostmodel = makeString(hconfig->hostmodel);
|
||||
}
|
||||
add_hostattrs_resvals(c, w);
|
||||
idx = w->idx;
|
||||
|
|
@ -309,31 +319,31 @@ int add_worker(void* cls, endpoint_t* ep, const char* host, hostattrs_t* attrs)
|
|||
/* using auto detected or pre configured MXJ? */
|
||||
nslots = hconfig->mxj;
|
||||
if (nslots < 0) {
|
||||
nslots = w->host.attrs->maxcpus;
|
||||
nslots = w->host->attrs->maxcpus;
|
||||
}
|
||||
|
||||
set_host_slots(c, w, nslots);
|
||||
|
||||
if (w->host.dispatch_window_config != NULL) {
|
||||
free_timewindow_config(w->host.dispatch_window_config);
|
||||
w->host.dispatch_window_config = NULL;
|
||||
if (w->host->dispatch_window_config != NULL) {
|
||||
free_timewindow_config(w->host->dispatch_window_config);
|
||||
w->host->dispatch_window_config = NULL;
|
||||
}
|
||||
|
||||
if (hconfig->dispatchwindow != NULL) {
|
||||
w->host.dispatch_window_config
|
||||
w->host->dispatch_window_config
|
||||
= dup_timewindow_config(hconfig->dispatchwindow);
|
||||
}
|
||||
|
||||
if (w->host.thresholds != NULL) {
|
||||
free_resource_thresholds(w->host.thresholds, w->host.nthresholds);
|
||||
w->host.nthresholds = 0;
|
||||
w->host.thresholds = NULL;
|
||||
if (w->host->thresholds != NULL) {
|
||||
free_resource_thresholds(w->host->thresholds, w->host->nthresholds);
|
||||
w->host->nthresholds = 0;
|
||||
w->host->thresholds = NULL;
|
||||
}
|
||||
|
||||
if (hconfig->thresholds != NULL) {
|
||||
w->host.thresholds = dup_resource_thresholds(hconfig->thresholds,
|
||||
w->host->thresholds = dup_resource_thresholds(hconfig->thresholds,
|
||||
hconfig->nthresholds);
|
||||
w->host.nthresholds = hconfig->nthresholds;
|
||||
w->host->nthresholds = hconfig->nthresholds;
|
||||
}
|
||||
|
||||
/* add bool resources to host */
|
||||
|
|
@ -354,20 +364,24 @@ int restore_worker(void* cls, xce_worker_t host)
|
|||
/* do work in add_worker() doing for normal worker join */
|
||||
/* clang-format off */
|
||||
worker_t worker = {
|
||||
.host = {
|
||||
.host = &(xce_worker_t){
|
||||
.name = (char*)host.name,
|
||||
.status = host.status,
|
||||
},
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
w = create_obj_by_typename(&(c->objmgr), "xworker", &worker);
|
||||
w = calloc(1, sizeof(*w));
|
||||
if (w == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
w->host = makeWorker(worker.host);
|
||||
if (w->host == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
add_hostattrs_resvals(c, w);
|
||||
idx = w->idx;
|
||||
w->host.status |= XCE_WORKER_UNAVAIL;
|
||||
w->host->status |= XCE_WORKER_UNAVAIL;
|
||||
|
||||
DEREF_OBJ(w);
|
||||
|
||||
|
|
@ -432,12 +446,17 @@ int on_worker_join(void* cls, endpoint_t* ep)
|
|||
|
||||
int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
|
||||
{
|
||||
xce_resource_t* r;
|
||||
xce_resource_t* r = NULL;
|
||||
zarray_t* array = NULL;
|
||||
xce_val_t* v = NULL;
|
||||
worker_t* w = NULL;
|
||||
int rc = 0;
|
||||
|
||||
rc = key_find(c->resmgr, (void*)resname, (void**)&r);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
r = resmgr_lockres(&(c->resmgr), resname, OBJREF_READ);
|
||||
if (r == NULL) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
|
@ -449,13 +468,15 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
w = workermgr_lock(&(c->workermgr), host, OBJREF_READ);
|
||||
rc = key_find(c->workermgr, (void*)host, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
if (w == NULL) {
|
||||
DEREF_OBJ(r);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
array = &(w->host.resvals);
|
||||
array = &(w->host->resvals);
|
||||
} else {
|
||||
array = &(c->sharedinst);
|
||||
}
|
||||
|
|
@ -464,15 +485,11 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
|
|||
v = (xce_val_t*)array->data[r->idx];
|
||||
}
|
||||
|
||||
obj_deref(r);
|
||||
|
||||
if (v == NULL) {
|
||||
DEREF_OBJ(w);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
memcpy(val, v, sizeof(*val));
|
||||
DEREF_OBJ(w);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -480,7 +497,7 @@ int mark_worker_unavail(cluster_t* c, worker_t* w)
|
|||
{
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_WORKER_DEAD, c, w);
|
||||
w->host.status |= XCE_WORKER_UNAVAIL;
|
||||
w->host->status |= XCE_WORKER_UNAVAIL;
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_WORKER_DEAD, c, w);
|
||||
|
|
@ -491,7 +508,7 @@ int mark_worker_back(cluster_t* c, worker_t* w)
|
|||
{
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_BEFORE_EVENT,
|
||||
HOOK_DETAIL_WORKER_UPDATE, c, w);
|
||||
w->host.status &= ~XCE_WORKER_UNAVAIL;
|
||||
w->host->status &= ~XCE_WORKER_UNAVAIL;
|
||||
|
||||
xce_run_hooks(&(c->hooksys), XCE_CONTROLLER_HOOK_WORKER, HOOK_AFTER_EVENT,
|
||||
HOOK_DETAIL_WORKER_UPDATE, c, w);
|
||||
|
|
@ -501,6 +518,7 @@ int mark_worker_back(cluster_t* c, worker_t* w)
|
|||
int handle_worker_leave(cluster_t* c, int idx)
|
||||
{
|
||||
worker_t* w = NULL;
|
||||
int rc;
|
||||
|
||||
TRACE("%s worker %d broken connection", __func__, idx);
|
||||
|
||||
|
|
@ -514,7 +532,11 @@ int handle_worker_leave(cluster_t* c, int idx)
|
|||
return -errno;
|
||||
}
|
||||
|
||||
w = workermgr_lock_byid(&(c->workermgr), idx, OBJREF_UPDATE);
|
||||
rc = vget(c->workermgr, idx, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (w == NULL) {
|
||||
ERROR("fail to find worker by id %d", idx);
|
||||
SET_ERROR(E_XCE_BAD_WORKER);
|
||||
|
|
@ -539,7 +561,12 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
|
|||
return -EINVAL;
|
||||
}
|
||||
TRACE("%s worker_ctrl worker %s", __func__, ctrl->hostname);
|
||||
w = workermgr_lock(&(c->workermgr), ctrl->hostname, OBJREF_UPDATE);
|
||||
|
||||
rc = key_find(c->workermgr, (void*)ctrl->hostname, (void**)&w);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (w == NULL) {
|
||||
PERROR("workermgr_lock");
|
||||
return -ENOENT;
|
||||
|
|
@ -547,16 +574,16 @@ int worker_ctrl(cluster_t* c, xce_hostctrl_t* ctrl)
|
|||
|
||||
switch (ctrl->action) {
|
||||
case HOST_OPEN:
|
||||
if (!(w->host.status & XCE_WORKER_CLOSED)) {
|
||||
if (!(w->host->status & XCE_WORKER_CLOSED)) {
|
||||
goto clean;
|
||||
}
|
||||
w->host.status &= ~XCE_WORKER_CLOSED;
|
||||
w->host->status &= ~XCE_WORKER_CLOSED;
|
||||
break;
|
||||
case HOST_CLOSE:
|
||||
if (w->host.status & XCE_WORKER_CLOSED) {
|
||||
if (w->host->status & XCE_WORKER_CLOSED) {
|
||||
goto clean;
|
||||
}
|
||||
w->host.status |= XCE_WORKER_CLOSED;
|
||||
w->host->status |= XCE_WORKER_CLOSED;
|
||||
break;
|
||||
default:
|
||||
rc = -1;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,11 @@
|
|||
#if !defined(_CONFIGOBJ_H_)
|
||||
|
||||
#define _CONFIGOBJ_H_ 1
|
||||
|
||||
#include <rtti.h>
|
||||
|
||||
#include "xce/types.h"
|
||||
|
||||
extern xce_config_t *makeConfig(xce_config_t *);
|
||||
|
||||
#endif
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#define _GROUP_H_ 1
|
||||
|
||||
#include <rtti.h>
|
||||
|
||||
#include "kvmgr.h"
|
||||
#include "xce/types.h"
|
||||
#include "xlist.h"
|
||||
|
|
@ -11,15 +13,16 @@ typedef struct {
|
|||
kvmgr_t groups;
|
||||
} groupmgr_t;
|
||||
|
||||
extern int groupmgr_init(groupmgr_t*, int, int);
|
||||
extern void groupmgr_fini(groupmgr_t*);
|
||||
extern int groupmgr_add(groupmgr_t*, xce_group_t*);
|
||||
extern xce_group_t* groupmgr_lock(groupmgr_t*, char*, int);
|
||||
extern void groupmgr_del(groupmgr_t*, xce_group_t*);
|
||||
extern int groupmgr_iter(groupmgr_t*, xlist_t*, void*);
|
||||
extern xce_group_t* build_group(groupmgr_t*, xce_group_config_t*, char*);
|
||||
extern xce_group_t* makeGroup(var, xce_group_config_t*, char*);
|
||||
extern int groupmgr_init(var*, int, int);
|
||||
extern void groupmgr_fini(var);
|
||||
extern int groupmgr_add(var, xce_group_t*);
|
||||
extern xce_group_t* groupmgr_lock(var, char*, int);
|
||||
extern void groupmgr_del(var, xce_group_t*);
|
||||
extern int groupmgr_iter(var, xlist_t*, void*);
|
||||
extern xce_group_t* build_group(var, xce_group_config_t*, char*);
|
||||
extern int is_in_group(xce_group_t*, char*);
|
||||
extern xce_group_t* get_group(groupmgr_t*, char*);
|
||||
extern xce_group_t* get_group(var, char*);
|
||||
extern int fmt_group(char*, int, xce_group_t*);
|
||||
extern int is_group_all(xce_group_t*);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
#if !defined(_RESOBH_H_)
|
||||
|
||||
#define _RESOBJ_H_ 1
|
||||
|
||||
#include <rtti.h>
|
||||
|
||||
#include "xce/types.h"
|
||||
|
||||
extern xce_resource_t* makeResource(xce_resource_t*);
|
||||
|
||||
#endif
|
||||
|
|
@ -127,9 +127,9 @@ extern int parse_resreq_primary(xce_primary_resreq_t*, char*, char**);
|
|||
extern int parse_resreq(xce_resreq_t*, char*, char**);
|
||||
extern void kill_resreq(xce_resreq_t*);
|
||||
extern int format_resreq(char**, xce_resreq_t*);
|
||||
extern int calc_wanted_global_resvals(xvec_idval_t*, resmgr_t*, xlist_t*,
|
||||
extern int calc_wanted_global_resvals(xvec_idval_t*, var, xlist_t*,
|
||||
rusage_per_type_t, int, int);
|
||||
extern int calc_wanted_host_resvals(xvec_idval_t*, resmgr_t*, xlist_t*,
|
||||
extern int calc_wanted_host_resvals(xvec_idval_t*, var, xlist_t*,
|
||||
rusage_per_type_t, int, int);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "config.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <rtti.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "delay.h"
|
||||
|
|
@ -105,11 +106,11 @@ typedef struct {
|
|||
int ncontrollers;
|
||||
delaymgr_t delaymgr;
|
||||
scheduler_t sched;
|
||||
jobmgr_t jobmgr;
|
||||
resmgr_t resmgr;
|
||||
workermgr_t workermgr;
|
||||
qmgr_t qmgr;
|
||||
kvmgr_t configmgr;
|
||||
var jobmgr;
|
||||
var resmgr;
|
||||
var workermgr;
|
||||
var qmgr;
|
||||
var configmgr;
|
||||
kvmgr_t ugmgr;
|
||||
kvmgr_t hgmgr;
|
||||
vtaskmgr_t vtaskmgr;
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ typedef struct {
|
|||
} xce_res_account_t;
|
||||
|
||||
typedef struct {
|
||||
xce_worker_t host;
|
||||
xce_worker_t* host;
|
||||
char hostkey[XCE_MAXKEY_LEN];
|
||||
endpoint_t* ep;
|
||||
int idx;
|
||||
|
|
@ -470,7 +470,7 @@ typedef struct {
|
|||
} xce_job_t;
|
||||
|
||||
typedef struct {
|
||||
xce_job_t job;
|
||||
xce_job_t* job;
|
||||
} job_t;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -517,7 +517,7 @@ typedef struct {
|
|||
} xce_queue_t;
|
||||
|
||||
typedef struct {
|
||||
xce_queue_t queue;
|
||||
xce_queue_t* queue;
|
||||
} queue_t;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#define _XCELIMIT_H_ 1
|
||||
|
||||
#include <rtti.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -17,13 +18,13 @@ extern int build_limit(xce_limit_t**, groupmgr_t*, groupmgr_t*, groupmgr_t*,
|
|||
groupmgr_t*, xce_limit_config_t*);
|
||||
extern int match_limit(xce_limit_t*, int, ...);
|
||||
extern int build_vres_name(char**, xce_limit_t*, char*, char*, char*);
|
||||
extern int is_host_based_limit(resmgr_t*, xce_limit_t*);
|
||||
extern int is_host_based_limit(var, xce_limit_t*);
|
||||
extern int fmt_consumer(char*, int, xce_consumer_t*);
|
||||
extern int fmt_limit(char*, int, xce_limit_t*);
|
||||
extern void kill_limit(xce_limit_t*);
|
||||
extern int instantiate_limit(xce_vres_t**, resmgr_t*, xce_limit_t*, char*,
|
||||
char*, char*);
|
||||
extern int instantiate_limit(xce_vres_t**, var, xce_limit_t*, char*, char*,
|
||||
char*);
|
||||
extern void kill_vres(xce_vres_t*);
|
||||
extern int add_vres(xce_resource_t**, resmgr_t*, char*, int);
|
||||
extern int add_vres(xce_resource_t**, var, char*, int);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -4,8 +4,53 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "configobj.h"
|
||||
#include "mylock.h"
|
||||
#include "qobj.h"
|
||||
#include "utils.h"
|
||||
#include "xce/types.h"
|
||||
#include "xstring.h"
|
||||
|
||||
static size_t xconfig_datasize(va_list ap)
|
||||
{
|
||||
size_t sz = sizeof(xce_config_t);
|
||||
|
||||
return sz;
|
||||
}
|
||||
|
||||
static int xconfig_init(meta_obj_t* obj, va_list ap)
|
||||
{
|
||||
xce_config_t* dst = RTTI_OBJ_TO_DATA(xce_config_t, obj);
|
||||
xce_config_t* src = va_arg(ap, xce_config_t*);
|
||||
|
||||
if (src == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dst->name = makeString(src->name);
|
||||
dst->value = makeString(src->value);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void xconfig_destroy(meta_obj_t* obj)
|
||||
{
|
||||
xce_config_t* c = RTTI_OBJ_TO_DATA(xce_config_t, obj);
|
||||
|
||||
dereference(c->name);
|
||||
dereference(c->value);
|
||||
}
|
||||
|
||||
static typeinfo_t xconfig_type = {
|
||||
.name = "xce config item",
|
||||
.privateSize = 0,
|
||||
.dataSize = (datasize_fn_t)xconfig_datasize,
|
||||
.init = (obj_init_fn_t)xconfig_init,
|
||||
.destroy = (obj_destroy_fn_t)xconfig_destroy,
|
||||
};
|
||||
|
||||
xce_config_t* makeConfig(xce_config_t* c)
|
||||
{
|
||||
xce_config_t* c1 = makeInstance(&xconfig_type, c);
|
||||
|
||||
return c1;
|
||||
}
|
||||
|
|
|
|||
318
src/lib/group.c
318
src/lib/group.c
|
|
@ -1,4 +1,5 @@
|
|||
#include <errno.h>
|
||||
#include <rtti.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -7,6 +8,11 @@
|
|||
#include "objmgr.h"
|
||||
#include "utils.h"
|
||||
#include "xce/types.h"
|
||||
#include "xstring.h"
|
||||
|
||||
typedef struct {
|
||||
|
||||
} group_private_t;
|
||||
|
||||
static void group_killer(xce_group_t* g)
|
||||
{
|
||||
|
|
@ -20,7 +26,7 @@ static void group_killer(xce_group_t* g)
|
|||
xce_g_member_t* m = (xce_g_member_t*)xlist_get(&(g->members), i);
|
||||
|
||||
if (!m->is_group) {
|
||||
FREEUP(m->u.name);
|
||||
dereference(m->u.name);
|
||||
}
|
||||
FREEUP(m);
|
||||
}
|
||||
|
|
@ -29,7 +35,7 @@ static void group_killer(xce_group_t* g)
|
|||
xce_g_member_t* m = (xce_g_member_t*)xlist_get(&(g->ex_members), i);
|
||||
|
||||
if (!m->is_group) {
|
||||
FREEUP(m->u.name);
|
||||
dereference(m->u.name);
|
||||
}
|
||||
FREEUP(m);
|
||||
}
|
||||
|
|
@ -45,76 +51,10 @@ static void group_killer(xce_group_t* g)
|
|||
xlist_fini(&(g->ex_members));
|
||||
xlist_fini(&(g->affecteds));
|
||||
|
||||
FREEUP(g->name);
|
||||
FREEUP(g);
|
||||
dereference(g->name);
|
||||
}
|
||||
|
||||
int groupmgr_init(groupmgr_t* mgr, int nslots, int delta)
|
||||
{
|
||||
int rc = 0;
|
||||
xce_group_config_t all = { .name = "all" };
|
||||
xce_group_config_t empty = { .name = "empty" };
|
||||
xce_group_t* g = NULL;
|
||||
|
||||
memset(mgr, 0x0, sizeof(*mgr));
|
||||
|
||||
rc = kvmgr_init(&(mgr->groups), string_hash_key, nslots, delta,
|
||||
(zarray_item_killer_t)group_killer);
|
||||
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* create builtin all group */
|
||||
g = build_group(mgr, &all, NULL);
|
||||
if (g == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* create builtin empty group */
|
||||
g = build_group(mgr, &empty, NULL);
|
||||
if (g == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void groupmgr_fini(groupmgr_t* mgr) { kvmgr_fini(&(mgr->groups)); }
|
||||
|
||||
int groupmgr_add(groupmgr_t* mgr, xce_group_t* g)
|
||||
{
|
||||
return kvmgr_add(&(mgr->groups), (void*)g->name, g);
|
||||
}
|
||||
|
||||
xce_group_t* groupmgr_lock(groupmgr_t* mgr, char* name, int op)
|
||||
{
|
||||
return (xce_group_t*)kvmgr_lock(&(mgr->groups), (void*)name, op);
|
||||
}
|
||||
|
||||
void groupmgr_del(groupmgr_t* mgr, xce_group_t* g)
|
||||
{
|
||||
kvmgr_del(&(mgr->groups), (void*)g->name);
|
||||
}
|
||||
|
||||
int groupmgr_iter(groupmgr_t* mgr, xlist_t* l, void* arg)
|
||||
{
|
||||
return kvmgr_iter(&(mgr->groups), NULL, l, arg);
|
||||
}
|
||||
|
||||
xce_group_t* get_group(groupmgr_t* mgr, char* name)
|
||||
{
|
||||
xce_group_t* g = NULL;
|
||||
|
||||
if ((mgr == NULL) || (name == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g = groupmgr_lock(mgr, name, OBJREF_NOP);
|
||||
return g;
|
||||
}
|
||||
|
||||
xce_g_member_t* make_g_member(groupmgr_t* mgr, char* name)
|
||||
xce_g_member_t* make_g_member(var mgr, char* name)
|
||||
{
|
||||
xce_g_member_t* m = NULL;
|
||||
xce_group_t* g = NULL;
|
||||
|
|
@ -135,7 +75,7 @@ xce_g_member_t* make_g_member(groupmgr_t* mgr, char* name)
|
|||
m->u.g = g;
|
||||
} else {
|
||||
m->is_group = 0;
|
||||
m->u.name = strdup(name);
|
||||
m->u.name = makeString(name);
|
||||
}
|
||||
|
||||
return m;
|
||||
|
|
@ -162,6 +102,238 @@ static int update_group_dirty(xce_group_t* g)
|
|||
return count;
|
||||
}
|
||||
|
||||
static int init_group_by_config(xce_group_t* g, var mgr,
|
||||
xce_group_config_t* g_config)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_config->members.count; i++) {
|
||||
char* g_name = g_config->members.data[i];
|
||||
xce_g_member_t* m = make_g_member(mgr, g_name);
|
||||
|
||||
if (m == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xlist_store(&(g->members), m);
|
||||
if (m->is_group) {
|
||||
xlist_store(&(m->u.g->affecteds), g);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < g_config->ex_members.count; i++) {
|
||||
char* g_name = g_config->ex_members.data[i];
|
||||
xce_g_member_t* m = make_g_member(mgr, g_name);
|
||||
|
||||
if (m == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xlist_store(&(g->ex_members), m);
|
||||
if (m->is_group) {
|
||||
xlist_store(&(m->u.g->affecteds), g);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t group_datasize(va_list ap)
|
||||
{
|
||||
size_t sz = sizeof(xce_group_t);
|
||||
|
||||
return sz;
|
||||
}
|
||||
|
||||
static int group_init(meta_obj_t* obj, va_list ap)
|
||||
{
|
||||
xce_group_t* g = RTTI_OBJ_TO_DATA(xce_group_t, obj);
|
||||
var mgr = va_arg(ap, var);
|
||||
xce_group_config_t* config = va_arg(ap, xce_group_config_t*);
|
||||
char* g_name = va_arg(ap, char*);
|
||||
int rc;
|
||||
|
||||
if ((mgr == NULL) || (config == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = key_add(mgr, (void*)g_name, (void*)g);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
xlist_init(&(g->affecteds), 4);
|
||||
xlist_init(&(g->members), 4);
|
||||
xlist_init(&(g->ex_members), 4);
|
||||
|
||||
g->name = makeString(g_name);
|
||||
g->dirty = 0;
|
||||
|
||||
init_group_by_config(g, mgr, config);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void group_destroy(meta_obj_t* obj)
|
||||
{
|
||||
xce_group_t* g = RTTI_OBJ_TO_DATA(xce_group_t, obj);
|
||||
|
||||
group_killer(g);
|
||||
}
|
||||
|
||||
static typeinfo_t group_type = { .name = "group",
|
||||
.privateSize = sizeof(group_private_t),
|
||||
.dataSize = (datasize_fn_t)group_datasize,
|
||||
.init = (obj_init_fn_t)group_init,
|
||||
.destroy = (obj_destroy_fn_t)group_destroy,
|
||||
.interfaces = {} };
|
||||
|
||||
xce_group_t* makeGroup(var mgr, xce_group_config_t* config,
|
||||
char* default_g_name)
|
||||
{
|
||||
xce_group_t* g = NULL;
|
||||
char* g_name = NULL;
|
||||
int rc = 0;
|
||||
|
||||
if ((mgr == NULL) || (config == NULL)) {
|
||||
errno = EINVAL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_name = config->name;
|
||||
if ((g_name == NULL) || (strlen(g_name) == 0)) {
|
||||
g_name = default_g_name;
|
||||
}
|
||||
|
||||
if (g_name == NULL) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = key_find(mgr, (void*)g_name, (void**)&g);
|
||||
if ((rc < 0) && (rc != -ENOENT)) {
|
||||
errno = -rc;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (g != NULL) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g->members.count; i++) {
|
||||
xce_g_member_t* m = (xce_g_member_t*)xlist_get(&(g->members), i);
|
||||
if (m == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (m->is_group == 0) {
|
||||
FREEUP(m->u.name);
|
||||
}
|
||||
|
||||
FREEUP(m);
|
||||
}
|
||||
g->members.count = 0;
|
||||
|
||||
for (i = 0; i < g->ex_members.count; i++) {
|
||||
xce_g_member_t* m = (xce_g_member_t*)xlist_get(&(g->ex_members), i);
|
||||
if (m == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (m->is_group == 0) {
|
||||
FREEUP(m->u.name);
|
||||
}
|
||||
|
||||
FREEUP(m);
|
||||
}
|
||||
g->ex_members.count = 0;
|
||||
g->dirty = 1;
|
||||
|
||||
init_group_by_config(g, mgr, config);
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
g = makeInstance(&group_type, mgr, config, g_name);
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
int groupmgr_init(var* mgr, int nslots, int delta)
|
||||
{
|
||||
xce_group_config_t all = { .name = "all" };
|
||||
xce_group_config_t empty = { .name = "empty" };
|
||||
xce_group_t* g = NULL;
|
||||
kvmgr_params_t params = { .key_type = KVMGR_KEY_STRING,
|
||||
.dynamic = 1,
|
||||
.nslots = nslots,
|
||||
.delta = delta,
|
||||
.datakiller = destroy };
|
||||
|
||||
*mgr = makeInstance(&xkvmgr_type, ¶ms);
|
||||
if ((*mgr) == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* create builtin all group */
|
||||
g = makeGroup(*mgr, &all, NULL);
|
||||
if (g == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* create builtin empty group */
|
||||
g = makeGroup(*mgr, &empty, NULL);
|
||||
if (g == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int groupmgr_add(var mgr, xce_group_t* g)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
rc = key_add(mgr, (void*)g->name, (void*)g);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
xce_group_t* groupmgr_lock(var mgr, char* name, int op)
|
||||
{
|
||||
int rc;
|
||||
xce_group_t* g = NULL;
|
||||
|
||||
rc = key_find(mgr, (void*)name, (void**)&g);
|
||||
if (rc <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
void groupmgr_del(var mgr, xce_group_t* g)
|
||||
{
|
||||
key_del(mgr, (void*)g->name);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
xce_group_t* get_group(var mgr, char* name)
|
||||
{
|
||||
xce_group_t* g = NULL;
|
||||
int rc = 0;
|
||||
|
||||
if ((mgr == NULL) || (name == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = key_find(mgr, (void*)name, (void**)&g);
|
||||
if (rc <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
int fmt_group(char* buf, int len, xce_group_t* g)
|
||||
{
|
||||
int i, pos;
|
||||
|
|
@ -210,7 +382,7 @@ int fmt_group(char* buf, int len, xce_group_t* g)
|
|||
return strlen(buf);
|
||||
}
|
||||
|
||||
xce_group_t* build_group(groupmgr_t* mgr, xce_group_config_t* g_config,
|
||||
xce_group_t* build_group(var mgr, xce_group_config_t* g_config,
|
||||
char* default_group_name)
|
||||
{
|
||||
xce_group_t* g = NULL;
|
||||
|
|
@ -268,7 +440,7 @@ xce_group_t* build_group(groupmgr_t* mgr, xce_group_config_t* g_config,
|
|||
xlist_init(&(g->affecteds), 4);
|
||||
xlist_init(&(g->members), 4);
|
||||
xlist_init(&(g->ex_members), 4);
|
||||
g->name = strdup(g_name);
|
||||
g->name = makeString(g_name);
|
||||
g->dirty = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
158
src/lib/kvmgr.c
158
src/lib/kvmgr.c
|
|
@ -238,164 +238,6 @@ int kvmgr_iter(kvmgr_t* mgr, zarray_iter_skip_fn_t skipfn, xlist_t* l,
|
|||
return rc;
|
||||
}
|
||||
|
||||
int resmgr_init(resmgr_t* mgr, int nslots, int delta,
|
||||
zarray_item_killer_t killer)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
rc = kvmgr_init(&(mgr->resdef), string_hash_key, nslots, delta, killer);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
mgr->nshared = 0;
|
||||
mgr->nunshared = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void resmgr_fini(resmgr_t* mgr)
|
||||
{
|
||||
kvmgr_fini(&(mgr->resdef));
|
||||
mgr->nshared = 0;
|
||||
mgr->nunshared = 0;
|
||||
}
|
||||
|
||||
int32_t resmgr_add_res(resmgr_t* mgr, xce_resource_t* res)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
rc = kvmgr_add(&(mgr->resdef), (void*)res->name, (void*)res);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (res->flags & XCE_RESF_SHARED) {
|
||||
res->idx = mgr->nshared;
|
||||
mgr->nshared++;
|
||||
} else {
|
||||
res->idx = mgr->nunshared;
|
||||
mgr->nunshared++;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
xce_resource_t* resmgr_lockres(resmgr_t* mgr, char* resname, int op)
|
||||
{
|
||||
xce_resource_t* r = NULL;
|
||||
r = (xce_resource_t*)kvmgr_lock(&(mgr->resdef), (void*)resname, op);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
xce_resource_t* resmgr_lock_byid(resmgr_t* mgr, int idx, int op)
|
||||
{
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
r = (xce_resource_t*)kvmgr_lock_byid(&(mgr->resdef), idx, op);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void resmgr_del_res(resmgr_t* mgr, xce_resource_t* r)
|
||||
{
|
||||
kvmgr_del(&(mgr->resdef), (void*)r->name);
|
||||
}
|
||||
|
||||
int resmgr_iter(resmgr_t* mgr, xlist_t* l, void* arg)
|
||||
{
|
||||
return kvmgr_iter(&(mgr->resdef), NULL, l, arg);
|
||||
}
|
||||
|
||||
int qmgr_init(qmgr_t* mgr, int nslots, int delta, zarray_item_killer_t killer)
|
||||
{
|
||||
return kvmgr_init(&(mgr->queues), string_hash_key, nslots, delta, killer);
|
||||
}
|
||||
|
||||
void qmgr_fini(qmgr_t* mgr) { kvmgr_fini(&(mgr->queues)); }
|
||||
|
||||
int qmgr_add(qmgr_t* mgr, queue_t* q)
|
||||
{
|
||||
return kvmgr_add(&(mgr->queues), (void*)q->queue.queue, q);
|
||||
}
|
||||
|
||||
queue_t* qmgr_lockq(qmgr_t* mgr, char* name, int op)
|
||||
{
|
||||
return (queue_t*)kvmgr_lock(&(mgr->queues), (void*)name, op);
|
||||
}
|
||||
|
||||
void qmgr_delq(qmgr_t* mgr, queue_t* q)
|
||||
{
|
||||
kvmgr_del(&(mgr->queues), (void*)q->queue.queue);
|
||||
}
|
||||
|
||||
int qmgr_iter(qmgr_t* mgr, xlist_t* l, void* arg)
|
||||
{
|
||||
return kvmgr_iter(&(mgr->queues), NULL, l, arg);
|
||||
}
|
||||
|
||||
int workermgr_init(workermgr_t* mgr, int nslots, int delta,
|
||||
zarray_item_killer_t killer)
|
||||
{
|
||||
return kvmgr_init(&(mgr->workers), string_hash_key, nslots, delta, killer);
|
||||
}
|
||||
|
||||
void workermgr_fini(workermgr_t* mgr) { kvmgr_fini(&(mgr->workers)); }
|
||||
|
||||
int workermgr_add(workermgr_t* mgr, worker_t* w)
|
||||
{
|
||||
return kvmgr_add(&(mgr->workers), (void*)w->host.name, w);
|
||||
}
|
||||
|
||||
worker_t* workermgr_lock(workermgr_t* mgr, char* name, int op)
|
||||
{
|
||||
return (worker_t*)kvmgr_lock(&(mgr->workers), (void*)name, op);
|
||||
}
|
||||
|
||||
worker_t* workermgr_lock_byid(workermgr_t* mgr, int idx, int op)
|
||||
{
|
||||
return (worker_t*)kvmgr_lock_byid(&(mgr->workers), idx, op);
|
||||
}
|
||||
|
||||
void workermgr_del(workermgr_t* mgr, worker_t* w)
|
||||
{
|
||||
kvmgr_del(&(mgr->workers), (void*)w->host.name);
|
||||
}
|
||||
|
||||
int workermgr_iter(workermgr_t* mgr, xlist_t* l, void* arg)
|
||||
{
|
||||
return kvmgr_iter(&(mgr->workers), NULL, l, arg);
|
||||
}
|
||||
|
||||
int jobmgr_init(jobmgr_t* mgr, int nslots, int delta,
|
||||
zarray_item_killer_t killer)
|
||||
{
|
||||
return kvmgr_init(&(mgr->jobs), int_hash_key, nslots, delta, killer);
|
||||
}
|
||||
|
||||
void jobmgr_fini(jobmgr_t* mgr) { kvmgr_fini(&(mgr->jobs)); }
|
||||
|
||||
int jobmgr_add_job(jobmgr_t* mgr, job_t* j)
|
||||
{
|
||||
return kvmgr_add(&(mgr->jobs), (void*)j->job.jobid, j);
|
||||
}
|
||||
|
||||
job_t* jobmgr_lockjob(jobmgr_t* mgr, uint64_t jobid, int op)
|
||||
{
|
||||
return (job_t*)kvmgr_lock(&(mgr->jobs), (void*)jobid, op);
|
||||
}
|
||||
|
||||
void jobmgr_del_job(jobmgr_t* mgr, job_t* j)
|
||||
{
|
||||
kvmgr_del(&(mgr->jobs), (void*)j->job.jobid);
|
||||
}
|
||||
|
||||
int jobmgr_iter(jobmgr_t* mgr, xlist_t* l, void* arg)
|
||||
{
|
||||
return kvmgr_iter(&(mgr->jobs), NULL, l, arg);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
my_rwlock_t lock;
|
||||
} xkvmgr_private_t;
|
||||
|
|
|
|||
|
|
@ -435,7 +435,7 @@ int format_resreq(char** buf, xce_resreq_t* resreq)
|
|||
return rc;
|
||||
}
|
||||
|
||||
int calc_wanted_global_resvals(xvec_idval_t* resvals, resmgr_t* resmgr,
|
||||
int calc_wanted_global_resvals(xvec_idval_t* resvals, var resmgr,
|
||||
xlist_t* rusages, rusage_per_type_t perflag,
|
||||
int nhosts, int nslots)
|
||||
{
|
||||
|
|
@ -446,12 +446,17 @@ int calc_wanted_global_resvals(xvec_idval_t* resvals, resmgr_t* resmgr,
|
|||
xce_resource_t* r = NULL;
|
||||
float val;
|
||||
rusage_per_type_t perflag1;
|
||||
int rc = 0;
|
||||
|
||||
if (v == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
r = resmgr_lockres(resmgr, v->res, OBJREF_NOP);
|
||||
rc = key_find(resmgr, (void*)v->res, (void**)&r);
|
||||
if (rc <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (r == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -486,7 +491,7 @@ int calc_wanted_global_resvals(xvec_idval_t* resvals, resmgr_t* resmgr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int calc_wanted_host_resvals(xvec_idval_t* resvals, resmgr_t* resmgr,
|
||||
int calc_wanted_host_resvals(xvec_idval_t* resvals, var resmgr,
|
||||
xlist_t* rusages, rusage_per_type_t perflag,
|
||||
int nhosts, int nslots)
|
||||
{
|
||||
|
|
@ -497,12 +502,17 @@ int calc_wanted_host_resvals(xvec_idval_t* resvals, resmgr_t* resmgr,
|
|||
xce_resource_t* r = NULL;
|
||||
float val;
|
||||
rusage_per_type_t perflag1;
|
||||
int rc = 0;
|
||||
|
||||
if (v == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
r = resmgr_lockres(resmgr, v->res, OBJREF_NOP);
|
||||
rc = key_find(resmgr, (void*)v->res, (void**)&r);
|
||||
if (rc <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (r == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,17 @@
|
|||
|
||||
#include "group.h"
|
||||
#include "utils.h"
|
||||
#include "xstring.h"
|
||||
|
||||
static void test_all(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_t* all = NULL;
|
||||
int rc = 0;
|
||||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
all = get_group(&mgr, "all");
|
||||
all = get_group(mgr, "all");
|
||||
|
||||
TEST_ASSERT_TRUE(all != NULL);
|
||||
|
||||
|
|
@ -22,18 +23,18 @@ static void test_all(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc > 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
static void test_empty(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_t* empty = NULL;
|
||||
int rc = 0;
|
||||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
empty = get_group(&mgr, "empty");
|
||||
empty = get_group(mgr, "empty");
|
||||
|
||||
TEST_ASSERT_TRUE(empty != NULL);
|
||||
|
||||
|
|
@ -41,12 +42,12 @@ static void test_empty(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc == 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
static void test_all_1(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata = {
|
||||
.name = "g1",
|
||||
.members = { .count = 1, .data = (char*[]) { "all" } }
|
||||
|
|
@ -57,7 +58,7 @@ static void test_all_1(void)
|
|||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
g = build_group(&mgr, &gdata, NULL);
|
||||
g = makeGroup(mgr, &gdata, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
|
|
@ -65,12 +66,12 @@ static void test_all_1(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc > 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
static void test_all_2(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata = {
|
||||
.name = "g1",
|
||||
.members = { .count = 2, .data = (char*[]) { "g2", "all" } }
|
||||
|
|
@ -81,7 +82,7 @@ static void test_all_2(void)
|
|||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
g = build_group(&mgr, &gdata, NULL);
|
||||
g = makeGroup(mgr, &gdata, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
|
|
@ -89,12 +90,12 @@ static void test_all_2(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc > 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
static void test_empty_1(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata = {
|
||||
.name = "g1",
|
||||
.ex_members = { .count = 1, .data = (char*[]) { "all" } }
|
||||
|
|
@ -105,7 +106,7 @@ static void test_empty_1(void)
|
|||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
g = build_group(&mgr, &gdata, NULL);
|
||||
g = makeGroup(mgr, &gdata, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
|
|
@ -113,12 +114,12 @@ static void test_empty_1(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc == 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
static void test_empty_2(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata = {
|
||||
.name = "g1",
|
||||
.members = { .count = 1, .data = (char*[]) { "empty" } }
|
||||
|
|
@ -129,7 +130,7 @@ static void test_empty_2(void)
|
|||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
g = build_group(&mgr, &gdata, NULL);
|
||||
g = makeGroup(mgr, &gdata, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
|
|
@ -137,12 +138,12 @@ static void test_empty_2(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc == 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
static void test_include(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata = {
|
||||
.name = "g1",
|
||||
.members = { .count = 1, .data = (char*[]) { "rshen" } }
|
||||
|
|
@ -153,7 +154,7 @@ static void test_include(void)
|
|||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
g = build_group(&mgr, &gdata, NULL);
|
||||
g = makeGroup(mgr, &gdata, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
|
|
@ -161,12 +162,12 @@ static void test_include(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc > 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
static void test_exclude(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata = {
|
||||
.name = "g1",
|
||||
.members = { .count = 1, .data = (char*[]) { "all" } },
|
||||
|
|
@ -178,7 +179,7 @@ static void test_exclude(void)
|
|||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
g = build_group(&mgr, &gdata, NULL);
|
||||
g = makeGroup(mgr, &gdata, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
|
|
@ -186,12 +187,12 @@ static void test_exclude(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc == 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
static void test_nest(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata1 = {
|
||||
.name = "g1",
|
||||
.members = { .count = 1, .data = (char*[]) { "rshen" } }
|
||||
|
|
@ -206,11 +207,11 @@ static void test_nest(void)
|
|||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
g = build_group(&mgr, &gdata1, NULL);
|
||||
g = makeGroup(mgr, &gdata1, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
g = build_group(&mgr, &gdata2, NULL);
|
||||
g = makeGroup(mgr, &gdata2, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
|
|
@ -218,12 +219,12 @@ static void test_nest(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc != 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
static void test_nest2(void)
|
||||
{
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata1 = {
|
||||
.name = "g1",
|
||||
.members = { .count = 1, .data = (char*[]) { "rshen" } }
|
||||
|
|
@ -239,11 +240,11 @@ static void test_nest2(void)
|
|||
|
||||
groupmgr_init(&mgr, 16, 16);
|
||||
|
||||
g = build_group(&mgr, &gdata1, NULL);
|
||||
g = makeGroup(mgr, &gdata1, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
g = build_group(&mgr, &gdata2, NULL);
|
||||
g = makeGroup(mgr, &gdata2, NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(g != NULL);
|
||||
|
||||
|
|
@ -251,13 +252,15 @@ static void test_nest2(void)
|
|||
|
||||
TEST_ASSERT_TRUE(rc == 0);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
}
|
||||
|
||||
void test_group(void)
|
||||
{
|
||||
printf("\n>> group test\n\n");
|
||||
|
||||
xstring_table_init(139);
|
||||
|
||||
RUN_TEST(test_all);
|
||||
RUN_TEST(test_empty);
|
||||
RUN_TEST(test_all_1);
|
||||
|
|
@ -268,4 +271,6 @@ void test_group(void)
|
|||
RUN_TEST(test_exclude);
|
||||
RUN_TEST(test_nest);
|
||||
RUN_TEST(test_nest2);
|
||||
|
||||
xstring_table_fini();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#include <rtti.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -6,11 +7,12 @@
|
|||
#include "group.h"
|
||||
#include "xce/types.h"
|
||||
#include "xcelimit.h"
|
||||
#include "xstring.h"
|
||||
|
||||
static void test_build_consumer1(void)
|
||||
{
|
||||
xce_consumer_t* c = NULL;
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata = {
|
||||
.members = { .count = 2, .data = (char*[]) { "rshen", "jsxing" } }
|
||||
};
|
||||
|
|
@ -18,7 +20,7 @@ static void test_build_consumer1(void)
|
|||
char buf[1024];
|
||||
|
||||
groupmgr_init(&mgr, 4, 4);
|
||||
rc = build_consumer(&c, &mgr, CONSUMER_USER, 1, &gdata, "user_group1");
|
||||
rc = build_consumer(&c, mgr, CONSUMER_USER, 1, &gdata, "user_group1");
|
||||
|
||||
TEST_ASSERT_TRUE(rc == 1);
|
||||
|
||||
|
|
@ -29,14 +31,15 @@ static void test_build_consumer1(void)
|
|||
|
||||
kill_consumer(c);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_build_consumer2(void)
|
||||
{
|
||||
xce_consumer_t* c = NULL;
|
||||
groupmgr_t mgr;
|
||||
var mgr;
|
||||
xce_group_config_t gdata = {
|
||||
.members = { .count = 1, .data = (char*[]) { "all" } },
|
||||
.ex_members = { .count = 2, .data = (char*[]) { "rshen", "jsxing" } }
|
||||
|
|
@ -45,7 +48,7 @@ static void test_build_consumer2(void)
|
|||
char buf[1024];
|
||||
|
||||
groupmgr_init(&mgr, 4, 4);
|
||||
rc = build_consumer(&c, &mgr, CONSUMER_USER, 1, &gdata, "user_group1");
|
||||
rc = build_consumer(&c, mgr, CONSUMER_USER, 1, &gdata, "user_group1");
|
||||
|
||||
TEST_ASSERT_TRUE(rc == 1);
|
||||
|
||||
|
|
@ -57,13 +60,17 @@ static void test_build_consumer2(void)
|
|||
|
||||
kill_consumer(c);
|
||||
|
||||
groupmgr_fini(&mgr);
|
||||
destroy(mgr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_build_limit_ok1(void)
|
||||
{
|
||||
groupmgr_t umgr, qmgr, hmgr, pmgr;
|
||||
var umgr;
|
||||
var qmgr;
|
||||
var hmgr;
|
||||
var pmgr;
|
||||
xce_limit_t* limit;
|
||||
int rc;
|
||||
xce_limit_config_t limit_config = {
|
||||
|
|
@ -88,7 +95,7 @@ static void test_build_limit_ok1(void)
|
|||
groupmgr_init(&hmgr, 4, 4);
|
||||
groupmgr_init(&pmgr, 4, 4);
|
||||
|
||||
rc = build_limit(&limit, &umgr, &qmgr, &hmgr, &pmgr, &limit_config);
|
||||
rc = build_limit(&limit, umgr, qmgr, hmgr, pmgr, &limit_config);
|
||||
TEST_ASSERT_TRUE(rc == 1);
|
||||
|
||||
memset(buf, 0x0, sizeof(buf));
|
||||
|
|
@ -100,15 +107,18 @@ static void test_build_limit_ok1(void)
|
|||
|
||||
kill_limit(limit);
|
||||
|
||||
groupmgr_fini(&pmgr);
|
||||
groupmgr_fini(&hmgr);
|
||||
groupmgr_fini(&qmgr);
|
||||
groupmgr_fini(&umgr);
|
||||
destroy(pmgr);
|
||||
destroy(hmgr);
|
||||
destroy(qmgr);
|
||||
destroy(umgr);
|
||||
}
|
||||
|
||||
static void test_match_limit_ok1(void)
|
||||
{
|
||||
groupmgr_t umgr, qmgr, hmgr, pmgr;
|
||||
var umgr;
|
||||
var qmgr;
|
||||
var hmgr;
|
||||
var pmgr;
|
||||
xce_limit_t* limit;
|
||||
int rc;
|
||||
xce_limit_config_t limit_config = {
|
||||
|
|
@ -137,7 +147,7 @@ static void test_match_limit_ok1(void)
|
|||
groupmgr_init(&hmgr, 4, 4);
|
||||
groupmgr_init(&pmgr, 4, 4);
|
||||
|
||||
rc = build_limit(&limit, &umgr, &qmgr, &hmgr, &pmgr, &limit_config);
|
||||
rc = build_limit(&limit, umgr, qmgr, hmgr, pmgr, &limit_config);
|
||||
TEST_ASSERT_TRUE(rc == 1);
|
||||
|
||||
memset(buf, 0x0, sizeof(buf));
|
||||
|
|
@ -152,15 +162,18 @@ static void test_match_limit_ok1(void)
|
|||
|
||||
kill_limit(limit);
|
||||
|
||||
groupmgr_fini(&pmgr);
|
||||
groupmgr_fini(&hmgr);
|
||||
groupmgr_fini(&qmgr);
|
||||
groupmgr_fini(&umgr);
|
||||
destroy(pmgr);
|
||||
destroy(hmgr);
|
||||
destroy(qmgr);
|
||||
destroy(umgr);
|
||||
}
|
||||
|
||||
static void test_match_limit_ok2(void)
|
||||
{
|
||||
groupmgr_t umgr, qmgr, hmgr, pmgr;
|
||||
var umgr;
|
||||
var qmgr;
|
||||
var hmgr;
|
||||
var pmgr;
|
||||
xce_limit_t* limit;
|
||||
int rc;
|
||||
xce_limit_config_t limit_config = {
|
||||
|
|
@ -183,7 +196,7 @@ static void test_match_limit_ok2(void)
|
|||
groupmgr_init(&hmgr, 4, 4);
|
||||
groupmgr_init(&pmgr, 4, 4);
|
||||
|
||||
rc = build_limit(&limit, &umgr, &qmgr, &hmgr, &pmgr, &limit_config);
|
||||
rc = build_limit(&limit, umgr, qmgr, hmgr, pmgr, &limit_config);
|
||||
TEST_ASSERT_TRUE(rc == 1);
|
||||
|
||||
memset(buf, 0x0, sizeof(buf));
|
||||
|
|
@ -198,15 +211,18 @@ static void test_match_limit_ok2(void)
|
|||
|
||||
kill_limit(limit);
|
||||
|
||||
groupmgr_fini(&pmgr);
|
||||
groupmgr_fini(&hmgr);
|
||||
groupmgr_fini(&qmgr);
|
||||
groupmgr_fini(&umgr);
|
||||
destroy(pmgr);
|
||||
destroy(hmgr);
|
||||
destroy(qmgr);
|
||||
destroy(umgr);
|
||||
}
|
||||
|
||||
static void test_match_limit1(void)
|
||||
{
|
||||
groupmgr_t umgr, qmgr, hmgr, pmgr;
|
||||
var umgr;
|
||||
var qmgr;
|
||||
var hmgr;
|
||||
var pmgr;
|
||||
xce_limit_t* limit;
|
||||
int rc;
|
||||
xce_limit_config_t limit_config = {
|
||||
|
|
@ -238,7 +254,7 @@ static void test_match_limit1(void)
|
|||
groupmgr_init(&hmgr, 4, 4);
|
||||
groupmgr_init(&pmgr, 4, 4);
|
||||
|
||||
rc = build_limit(&limit, &umgr, &qmgr, &hmgr, &pmgr, &limit_config);
|
||||
rc = build_limit(&limit, umgr, qmgr, hmgr, pmgr, &limit_config);
|
||||
TEST_ASSERT_TRUE(rc == 1);
|
||||
|
||||
memset(buf, 0x0, sizeof(buf));
|
||||
|
|
@ -253,15 +269,18 @@ static void test_match_limit1(void)
|
|||
|
||||
kill_limit(limit);
|
||||
|
||||
groupmgr_fini(&pmgr);
|
||||
groupmgr_fini(&hmgr);
|
||||
groupmgr_fini(&qmgr);
|
||||
groupmgr_fini(&umgr);
|
||||
destroy(pmgr);
|
||||
destroy(hmgr);
|
||||
destroy(qmgr);
|
||||
destroy(umgr);
|
||||
}
|
||||
|
||||
static void test_match_limit2(void)
|
||||
{
|
||||
groupmgr_t umgr, qmgr, hmgr, pmgr;
|
||||
var umgr;
|
||||
var qmgr;
|
||||
var hmgr;
|
||||
var pmgr;
|
||||
xce_limit_t* limit;
|
||||
int rc;
|
||||
xce_limit_config_t limit_config = {
|
||||
|
|
@ -289,7 +308,7 @@ static void test_match_limit2(void)
|
|||
groupmgr_init(&hmgr, 4, 4);
|
||||
groupmgr_init(&pmgr, 4, 4);
|
||||
|
||||
rc = build_limit(&limit, &umgr, &qmgr, &hmgr, &pmgr, &limit_config);
|
||||
rc = build_limit(&limit, umgr, qmgr, hmgr, pmgr, &limit_config);
|
||||
TEST_ASSERT_TRUE(rc == 1);
|
||||
|
||||
memset(buf, 0x0, sizeof(buf));
|
||||
|
|
@ -304,15 +323,18 @@ static void test_match_limit2(void)
|
|||
|
||||
kill_limit(limit);
|
||||
|
||||
groupmgr_fini(&pmgr);
|
||||
groupmgr_fini(&hmgr);
|
||||
groupmgr_fini(&qmgr);
|
||||
groupmgr_fini(&umgr);
|
||||
destroy(pmgr);
|
||||
destroy(hmgr);
|
||||
destroy(qmgr);
|
||||
destroy(umgr);
|
||||
}
|
||||
|
||||
void test_limit(void)
|
||||
{
|
||||
printf("\n>> limit test\n\n");
|
||||
|
||||
xstring_table_init(139);
|
||||
|
||||
RUN_TEST(test_build_consumer1);
|
||||
RUN_TEST(test_build_consumer2);
|
||||
RUN_TEST(test_build_limit_ok1);
|
||||
|
|
@ -320,5 +342,6 @@ void test_limit(void)
|
|||
RUN_TEST(test_match_limit_ok2);
|
||||
RUN_TEST(test_match_limit1);
|
||||
RUN_TEST(test_match_limit2);
|
||||
}
|
||||
|
||||
xstring_table_fini();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include <errno.h>
|
||||
#include <rtti.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -104,12 +105,11 @@ int build_consumer(xce_consumer_t** pconsumer, groupmgr_t* mgr,
|
|||
sprintf(consumer_group_name, "%s-%s-group", default_name_prefix,
|
||||
suffix);
|
||||
default_g_name = consumer_group_name;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
default_g_name = g_config->name;
|
||||
}
|
||||
|
||||
g = build_group(mgr, g_config, default_g_name);
|
||||
g = makeGroup(mgr, g_config, default_g_name);
|
||||
if (g == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
|
@ -369,8 +369,9 @@ int build_vres_name(char** vname, xce_limit_t* limit, char* user, char* queue,
|
|||
return -ENOMEM;
|
||||
}
|
||||
|
||||
int is_host_based_limit(resmgr_t* mgr, xce_limit_t* limit)
|
||||
int is_host_based_limit(var resmgr, xce_limit_t* limit)
|
||||
{
|
||||
int rc = 0;
|
||||
xce_consumer_t* c = NULL;
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
|
|
@ -378,7 +379,11 @@ int is_host_based_limit(resmgr_t* mgr, xce_limit_t* limit)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
r = resmgr_lockres(mgr, limit->val.resname, OBJREF_NOP);
|
||||
rc = key_find(resmgr, (void*)limit->val.resname, (void**)&r);
|
||||
if (rc <= 0) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if ((r->flags & (XCE_RESF_GLOBAL | XCE_RESF_SHARED)) == 0) {
|
||||
if (limit->val.percent != 0) {
|
||||
return 1;
|
||||
|
|
@ -393,7 +398,7 @@ int is_host_based_limit(resmgr_t* mgr, xce_limit_t* limit)
|
|||
return c->per_consumer;
|
||||
}
|
||||
|
||||
int add_vres(xce_resource_t** pvres, resmgr_t* mgr, char* name, int global)
|
||||
int add_vres(xce_resource_t** pvres, var resmgr, char* name, int global)
|
||||
{
|
||||
xce_resource_t* vres = NULL;
|
||||
int rc;
|
||||
|
|
@ -417,7 +422,7 @@ int add_vres(xce_resource_t** pvres, resmgr_t* mgr, char* name, int global)
|
|||
vres->flags |= XCE_RESF_DEFAULT_HOST;
|
||||
}
|
||||
|
||||
rc = resmgr_add_res(mgr, vres);
|
||||
rc = key_add(resmgr, (void*)vres->name, (void*)vres);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -426,7 +431,7 @@ int add_vres(xce_resource_t** pvres, resmgr_t* mgr, char* name, int global)
|
|||
return rc;
|
||||
}
|
||||
|
||||
int instantiate_limit(xce_vres_t** pvres, resmgr_t* mgr, xce_limit_t* limit,
|
||||
int instantiate_limit(xce_vres_t** pvres, var resmgr, xce_limit_t* limit,
|
||||
char* user, char* queue, char* project)
|
||||
{
|
||||
xce_vres_t* vres = NULL;
|
||||
|
|
@ -434,7 +439,7 @@ int instantiate_limit(xce_vres_t** pvres, resmgr_t* mgr, xce_limit_t* limit,
|
|||
char* vresname = NULL;
|
||||
int shared = 1;
|
||||
|
||||
if ((pvres == NULL) || (mgr == NULL) || (limit == NULL) || (user == NULL)
|
||||
if ((pvres == NULL) || (resmgr == NULL) || (limit == NULL) || (user == NULL)
|
||||
|| (queue == NULL) || (project == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -448,7 +453,7 @@ int instantiate_limit(xce_vres_t** pvres, resmgr_t* mgr, xce_limit_t* limit,
|
|||
|
||||
vres->limit = limit;
|
||||
|
||||
if (is_host_based_limit(mgr, limit)) {
|
||||
if (is_host_based_limit(resmgr, limit)) {
|
||||
shared = 0;
|
||||
}
|
||||
|
||||
|
|
@ -457,9 +462,13 @@ int instantiate_limit(xce_vres_t** pvres, resmgr_t* mgr, xce_limit_t* limit,
|
|||
return rc;
|
||||
}
|
||||
|
||||
vres->vres = resmgr_lockres(mgr, vresname, OBJREF_NOP);
|
||||
if (vres->vres == NULL) {
|
||||
rc = add_vres(&(vres->vres), mgr, vresname, shared);
|
||||
rc = key_find(resmgr, (void*)vresname, (void**)&(vres->vres));
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
rc = add_vres(&(vres->vres), resmgr, vresname, shared);
|
||||
if (rc < 0) {
|
||||
FREEUP(vresname);
|
||||
return rc;
|
||||
|
|
@ -468,8 +477,12 @@ int instantiate_limit(xce_vres_t** pvres, resmgr_t* mgr, xce_limit_t* limit,
|
|||
|
||||
FREEUP(vresname);
|
||||
|
||||
vres->res = resmgr_lockres(mgr, limit->val.resname, OBJREF_NOP);
|
||||
if (vres->res == NULL) {
|
||||
rc = key_find(resmgr, (void*)limit->val.resname, (void**)&(vres->res));
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,139 +10,6 @@
|
|||
#include "utils.h"
|
||||
#include "xstring.h"
|
||||
|
||||
static void* xstring_create(objmgr_t*, objtype_t*, va_list);
|
||||
static void xstring_fini(void*);
|
||||
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 void xstring_obj_killer(myobj_t* obj)
|
||||
{
|
||||
if (obj == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
memset(obj, 0x0, sizeof(*obj));
|
||||
free(obj);
|
||||
}
|
||||
|
||||
int register_xstring(objmgr_t* mgr, int nslots, int delta)
|
||||
{
|
||||
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)
|
||||
{
|
||||
char* s = va_arg(ap, char*);
|
||||
char* p = NULL;
|
||||
myobj_t* obj = NULL;
|
||||
hent_t* e = NULL;
|
||||
xstring_typedata_t* typedata = NULL;
|
||||
int32_t idx;
|
||||
|
||||
if (s == NULL) {
|
||||
SET_ERROR(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
typedata = (xstring_typedata_t*)type->typedata;
|
||||
|
||||
e = ht_get((htab_t*)&(typedata->tab), (void*)s);
|
||||
if (e != NULL) {
|
||||
idx = e->data;
|
||||
obj = (myobj_t*)zarray_get(&(typedata->strings), idx);
|
||||
|
||||
if (obj != NULL) {
|
||||
p = MYOBJ_TO_OBJ(char*, obj);
|
||||
return obj_ref(p, OBJREF_NOP);
|
||||
}
|
||||
|
||||
SET_ERROR(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj = (myobj_t*)calloc(1, sizeof(*obj) + strlen(s) + 1);
|
||||
if (obj == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idx = zarray_store(&(typedata->strings), obj);
|
||||
if (idx < 0) {
|
||||
free(obj);
|
||||
SET_ERROR(-idx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj_init(mgr, type, idx, obj);
|
||||
|
||||
p = MYOBJ_TO_OBJ(char*, obj);
|
||||
|
||||
strcpy(p, s);
|
||||
|
||||
e = ht_add((htab_t*)&(typedata->tab), (void*)s);
|
||||
if (e == NULL) {
|
||||
obj_deref(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
e->data = idx;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/* this will ONLY be called by obj_deref() */
|
||||
static void xstring_fini(void* s)
|
||||
{
|
||||
myobj_t* myobj;
|
||||
objtype_t* typeval;
|
||||
xstring_typedata_t* typedata;
|
||||
int32_t idx;
|
||||
|
||||
if (s == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
myobj = TO_MYOBJ(s);
|
||||
typeval = myobj->type;
|
||||
typedata = (xstring_typedata_t*)typeval->typedata;
|
||||
|
||||
if (typedata == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ht_del(&(typedata->tab), (void*)s);
|
||||
|
||||
idx = (int32_t)myobj->exdata;
|
||||
if (idx >= 0) {
|
||||
zarray_del(&(typedata->strings), idx);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void xstring_type_fini(objtype_t* typeval)
|
||||
{
|
||||
xstring_typedata_t* typedata = (xstring_typedata_t*)typeval->typedata;
|
||||
|
||||
if (typedata == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ht_fini(&(typedata->tab));
|
||||
zarray_fini(&(typedata->strings));
|
||||
}
|
||||
|
||||
static struct {
|
||||
mylock_t lock;
|
||||
var xstr_table;
|
||||
|
|
|
|||
|
|
@ -66,11 +66,11 @@ typedef struct {
|
|||
void* affinity_allocator;
|
||||
void* gpu_allocator;
|
||||
dataq_t* pend_updates[2];
|
||||
resmgr_t resmgr;
|
||||
groupmgr_t ugmgr;
|
||||
groupmgr_t qgmgr;
|
||||
groupmgr_t pgmgr;
|
||||
groupmgr_t hgmgr;
|
||||
var resmgr;
|
||||
var ugmgr;
|
||||
var qgmgr;
|
||||
var pgmgr;
|
||||
var hgmgr;
|
||||
zarray_t sharedInst;
|
||||
zarray_t sharedInUse;
|
||||
var jobs;
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@ static int limit_update_config(xce_sched_plugin_t* plugin,
|
|||
int rc;
|
||||
xce_limit_t* limit;
|
||||
|
||||
rc = build_limit(&limit, &(sched->ugmgr), &(sched->qgmgr),
|
||||
&(sched->pgmgr), &(sched->hgmgr), limits[i]);
|
||||
rc = build_limit(&limit, (sched->ugmgr), (sched->qgmgr),
|
||||
(sched->pgmgr), (sched->hgmgr), limits[i]);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <rtti.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -50,6 +51,7 @@ static int seqjob_prepare_allocation(void* arg, xce_sched_ctx_t* ctx)
|
|||
xce_sched_obj_t* obj = NULL;
|
||||
xce_resource_t* r = NULL;
|
||||
xce_primary_resreq_t* primary = NULL;
|
||||
int rc = 0;
|
||||
|
||||
if ((plugin == NULL) || (ctx == NULL) || (sched == NULL)) {
|
||||
return -EINVAL;
|
||||
|
|
@ -73,15 +75,23 @@ static int seqjob_prepare_allocation(void* arg, xce_sched_ctx_t* ctx)
|
|||
if (ctx->worker == NULL) {
|
||||
ctx->nhosts = 1;
|
||||
ctx->nslots = 1;
|
||||
calc_wanted_global_resvals(&(ctx->alloc_req.shared), &(sched->resmgr),
|
||||
calc_wanted_global_resvals(&(ctx->alloc_req.shared), sched->resmgr,
|
||||
&(primary->rusages), PER_TASK, 1, 1);
|
||||
} else {
|
||||
calc_wanted_host_resvals(&(ctx->alloc_req.host), &(sched->resmgr),
|
||||
calc_wanted_host_resvals(&(ctx->alloc_req.host), sched->resmgr,
|
||||
&(primary->rusages), PER_TASK, 1, 1);
|
||||
}
|
||||
|
||||
/* add slots into requested resources */
|
||||
r = resmgr_lockres(&(sched->resmgr), "slots", OBJREF_NOP);
|
||||
rc = key_find(sched->resmgr, (void*)"slots", (void**)&r);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (r == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -123,8 +133,14 @@ static int my_alloc(xce_sched_plugin_t* plugin, xce_sched_ctx_t* ctx)
|
|||
int i;
|
||||
|
||||
for (i = 0; i < ctx->alloc_req.shared.count; i++) {
|
||||
xce_resource_t* r = resmgr_lock_byid(
|
||||
&(sched->resmgr), ((int*)ctx->unmeet.idxs.data)[i], OBJREF_NOP);
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
rc = vget(sched->resmgr, ((int*)ctx->unmeet.idxs.data)[i],
|
||||
(void**)&r);
|
||||
if (rc <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
add_job_preason(reason->reasons, PREASON_NO_RESOURCE, NULL,
|
||||
r->name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -299,20 +299,27 @@ static int sched_update_res_accounts(xce_scheduler_t* sched, zarray_t* array,
|
|||
xce_res_account_t* acct = accounts[i];
|
||||
|
||||
if (acct->residx < 0) {
|
||||
xce_resource_t* r
|
||||
= resmgr_lockres(&(sched->resmgr), acct->resname, OBJREF_NOP);
|
||||
xce_resource_t* r = NULL;
|
||||
int rc = 0;
|
||||
|
||||
rc = key_find(sched->resmgr, (void*)acct->resname, (void**)&r);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
/* It's possible that r return NULL if acct->resname is a
|
||||
* virtual resource of limit */
|
||||
if (r == NULL) {
|
||||
int rc;
|
||||
|
||||
rc = add_vres(&r, &(sched->resmgr), acct->resname, global);
|
||||
rc = add_vres(&r, sched->resmgr, acct->resname, global);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
r = resmgr_lockres(&(sched->resmgr), acct->resname, OBJREF_NOP);
|
||||
rc = key_find(sched->resmgr, (void*)acct->resname, (void**)&r);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
if (r != NULL) {
|
||||
|
|
@ -383,8 +390,13 @@ static int sched_try_alloc_on_host_(xce_sched_worker_t* w, va_list ap)
|
|||
int i;
|
||||
|
||||
for (i = 0; i < ctx->unmeet.count; i++) {
|
||||
xce_resource_t* r = resmgr_lock_byid(
|
||||
&(sched->resmgr), ((int*)ctx->unmeet.idxs.data)[i], OBJREF_NOP);
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
rc = vget(sched->resmgr, ((int*)ctx->unmeet.idxs.data)[i],
|
||||
(void**)&r);
|
||||
if (rc < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
add_job_preason(ctx->reason->reasons, PREASON_NO_RESOURCE, w->name,
|
||||
r->name);
|
||||
|
|
|
|||
|
|
@ -346,6 +346,11 @@ int sched_init(xce_scheduler_t* sched, xce_client_config_t* config,
|
|||
.nslots = 31,
|
||||
.delta = 8,
|
||||
.datakiller = (destroy_fn_t)kill_sched_project };
|
||||
kvmgr_params_t resmgr_params = { .key_type = KVMGR_KEY_STRING,
|
||||
.dynamic = 1,
|
||||
.nslots = 64,
|
||||
.delta = 8,
|
||||
.datakiller = NULL };
|
||||
|
||||
if ((sched == NULL) || (config == NULL) || (handler == NULL)) {
|
||||
return -EINVAL;
|
||||
|
|
@ -367,11 +372,8 @@ int sched_init(xce_scheduler_t* sched, xce_client_config_t* config,
|
|||
sched->pend_updates[1] = (dataq_t*)calloc(1, sizeof(dataq_t));
|
||||
dataq_init(sched->pend_updates[1], sched_pend_update_killer);
|
||||
|
||||
resmgr_init(
|
||||
&(sched->resmgr), /* slots */ 128, /* delta */ 128,
|
||||
/* should be NULL as resmgr will provide hash find by resource name, the
|
||||
real resource stored in sched->config->resources[] */
|
||||
NULL);
|
||||
sched->resmgr = makeInstance(&xkvmgr_type, &resmgr_params);
|
||||
|
||||
groupmgr_init(&(sched->ugmgr), 64, 64);
|
||||
groupmgr_init(&(sched->qgmgr), 16, 16);
|
||||
groupmgr_init(&(sched->pgmgr), 16, 16);
|
||||
|
|
@ -446,11 +448,12 @@ void sched_fini(xce_scheduler_t* sched)
|
|||
dataq_fini(sched->pend_updates[0]);
|
||||
dataq_fini(sched->pend_updates[1]);
|
||||
|
||||
resmgr_fini(&(sched->resmgr));
|
||||
groupmgr_fini(&(sched->ugmgr));
|
||||
groupmgr_fini(&(sched->qgmgr));
|
||||
groupmgr_fini(&(sched->pgmgr));
|
||||
groupmgr_fini(&(sched->hgmgr));
|
||||
destroy(sched->resmgr);
|
||||
|
||||
destroy(sched->ugmgr);
|
||||
destroy(sched->qgmgr);
|
||||
destroy(sched->pgmgr);
|
||||
destroy(sched->hgmgr);
|
||||
|
||||
mylock_fini(&(sched->lock));
|
||||
|
||||
|
|
@ -465,7 +468,7 @@ static int sched_init_resources(xce_scheduler_t* sched)
|
|||
for (i = 0; i < config->n_resources; i++) {
|
||||
xce_resource_t* r = config->resources[i];
|
||||
|
||||
resmgr_add_res(&(sched->resmgr), r);
|
||||
key_add(sched->resmgr, (void*)r->name, (void*)r);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -846,7 +849,7 @@ xce_sched_project_t* sched_get_project(xce_scheduler_t* sched, char* name)
|
|||
name = "default";
|
||||
}
|
||||
|
||||
rc = key_find(sched->projects, (void*)name, (void **)&project);
|
||||
rc = key_find(sched->projects, (void*)name, (void**)&project);
|
||||
if (rc < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -999,9 +1002,12 @@ xce_alloc_t** sched_make_allocs(xce_scheduler_t* sched, char* reserve, int nres,
|
|||
}
|
||||
|
||||
for (i = 0; i < nres; i++) {
|
||||
xce_resource_t* r = (xce_resource_t*)resmgr_lock_byid(
|
||||
&(sched->resmgr), idxs[i], OBJREF_NOP);
|
||||
int d = (duration != NULL) ? duration[i] : -1;
|
||||
xce_resource_t* r = NULL;
|
||||
int rc = 0;
|
||||
int d;
|
||||
|
||||
rc = vget(sched->resmgr, idxs[i], (void**)&r);
|
||||
d = (duration != NULL) ? duration[i] : -1;
|
||||
|
||||
allocs[i] = NULL;
|
||||
if (r == NULL) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue