improve resmgr
This commit is contained in:
parent
4db6b039c5
commit
1f1e4fdaba
10 changed files with 107 additions and 221 deletions
|
|
@ -500,7 +500,9 @@ int cluster_init(cluster_t* c)
|
|||
c->myconf->cluster_config->jobmgr->delta);
|
||||
resmgr_init(&(c->resmgr), c->myconf->cluster_config->resmgr->nhash_slots,
|
||||
c->myconf->cluster_config->resmgr->delta,
|
||||
c->myconf->cluster_config->resmgr->inst_delta);
|
||||
(zarray_item_killer_t)res_obj_killer);
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -464,7 +464,7 @@ void collect_shared_resvals(cluster_t* c, collect_check_fn_t fn, int* nres,
|
|||
xce_val_with_idx_t*** resvals)
|
||||
{
|
||||
|
||||
collect_resval_with_idx(&(c->resmgr.sharedinst), nres, resvals);
|
||||
collect_resval_with_idx(&(c->sharedinst), nres, resvals);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,17 +49,10 @@ 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 resource_killer(void*);
|
||||
extern int add_resource(void*, char*, char*, int, xce_order_t, int, int);
|
||||
extern int resmgr_init(resmgr_t*, int, int, int);
|
||||
extern void resmgr_fini(resmgr_t*);
|
||||
extern int32_t resmgr_add_res(resmgr_t*, xce_resource_t*);
|
||||
extern xce_resource_t* resmgr_lockres(resmgr_t* mgr, char*, int);
|
||||
extern void res_obj_killer(xce_resource_t*);
|
||||
extern void resmgr_del_res(resmgr_t*, xce_resource_t*);
|
||||
extern int resmgr_iter(resmgr_t*, xlist_t*, void*);
|
||||
|
||||
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*);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ controller_src = [
|
|||
'qmgr.c',
|
||||
'queue.c',
|
||||
'reply.c',
|
||||
'resmgr.c',
|
||||
'resources.c',
|
||||
'sched.c',
|
||||
'task.c',
|
||||
|
|
|
|||
|
|
@ -1,191 +0,0 @@
|
|||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cluster.h"
|
||||
#include "htab.h"
|
||||
#include "utils.h"
|
||||
#include "xce/cluster_def.h"
|
||||
#include "xce/errnox.h"
|
||||
#include "xstring.h"
|
||||
|
||||
extern void res_obj_killer(xce_resource_t*);
|
||||
extern void resval_obj_killer(xce_resval_t*);
|
||||
|
||||
int resmgr_init(resmgr_t* mgr, int nslots, int delta, int inst_delta)
|
||||
{
|
||||
TRACE("%s nslots %d delta %d inst_delta %d", __func__, nslots, delta,
|
||||
inst_delta);
|
||||
|
||||
mylock_init(&(mgr->lock));
|
||||
|
||||
ht_init(&(mgr->htab), nslots, string_hash_key);
|
||||
zarray_init(&(mgr->defs), delta, (zarray_item_killer_t)res_obj_killer);
|
||||
zarray_init(&(mgr->sharedinst), inst_delta,
|
||||
(zarray_item_killer_t)resval_obj_killer);
|
||||
mgr->nshared = 0;
|
||||
mgr->nunshared = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void resmgr_fini(resmgr_t* mgr)
|
||||
{
|
||||
|
||||
zarray_fini(&(mgr->sharedinst));
|
||||
zarray_fini(&(mgr->defs));
|
||||
ht_fini(&(mgr->htab));
|
||||
mylock_fini(&(mgr->lock));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int32_t resmgr_add_res_(resmgr_t* mgr, xce_resource_t* res)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
int idx;
|
||||
|
||||
e = ht_get(&(mgr->htab), (void*)res->name);
|
||||
if (e != NULL) {
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
idx = zarray_store(&(mgr->defs), res);
|
||||
if (idx < 0) {
|
||||
return idx;
|
||||
}
|
||||
|
||||
e = ht_add(&(mgr->htab), (void*)res->name);
|
||||
if (e == NULL) {
|
||||
zarray_del(&(mgr->defs), idx);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
e->data = idx;
|
||||
if (res->flags & XCE_RESF_SHARED) {
|
||||
res->idx = mgr->nshared;
|
||||
mgr->nshared++;
|
||||
} else {
|
||||
res->idx = mgr->nunshared;
|
||||
mgr->nunshared++;
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
int32_t resmgr_add_res(resmgr_t* mgr, xce_resource_t* res)
|
||||
{
|
||||
int32_t idx;
|
||||
|
||||
if ((mgr == NULL) || (res == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mylock_lock(&(mgr->lock));
|
||||
idx = resmgr_add_res_(mgr, res);
|
||||
mylock_unlock(&(mgr->lock));
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
static xce_resource_t* resmgr_lockres_(resmgr_t* mgr, char* resname, int op)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
int idx;
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
e = ht_get(&(mgr->htab), (void*)resname);
|
||||
if (e == NULL) {
|
||||
SET_ERROR(E_XCE_BAD_RES);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idx = e->data;
|
||||
if (idx < 0) {
|
||||
SET_ERROR(E_XCE_INTERNAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
r = (xce_resource_t*)zarray_get(&(mgr->defs), idx);
|
||||
if (r == NULL) {
|
||||
SET_ERROR(E_XCE_INTERNAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return obj_ref(r, op);
|
||||
}
|
||||
xce_resource_t* resmgr_lockres(resmgr_t* mgr, char* resname, int op)
|
||||
{
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
if (mgr == NULL) {
|
||||
SET_ERROR(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (resname == NULL) {
|
||||
SET_ERROR(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
if ((op != OBJREF_NOP) &&
|
||||
(op != OBJREF_READ) &&
|
||||
(op != OBJREF_UPDATE)) {
|
||||
SET_ERROR(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
/* clang-format on */
|
||||
|
||||
mylock_lock(&(mgr->lock));
|
||||
r = resmgr_lockres_(mgr, resname, op);
|
||||
mylock_unlock(&(mgr->lock));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void resmgr_del_res_(resmgr_t* mgr, xce_resource_t* r)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
int idx;
|
||||
|
||||
e = ht_get(&(mgr->htab), (void*)r->name);
|
||||
if (e == NULL) {
|
||||
SET_ERROR(E_XCE_BAD_RES);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
idx = e->data;
|
||||
if (idx < 0) {
|
||||
SET_ERROR(E_XCE_INTERNAL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
zarray_del(&(mgr->defs), idx);
|
||||
}
|
||||
|
||||
void resmgr_del_res(resmgr_t* mgr, xce_resource_t* r)
|
||||
{
|
||||
if ((mgr == NULL) || (r == NULL)) {
|
||||
SET_ERROR(EINVAL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mylock_lock(&(mgr->lock));
|
||||
resmgr_del_res_(mgr, r);
|
||||
mylock_unlock(&(mgr->lock));
|
||||
}
|
||||
|
||||
int resmgr_iter(resmgr_t* mgr, xlist_t* l, void* arg)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
mylock_lock(&(mgr->lock));
|
||||
rc = zarray_iter_ex(&(mgr->defs), NULL, l, arg);
|
||||
mylock_unlock(&(mgr->lock));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ static int update_val_res(cluster_t* c, worker_t* w, xce_resource_t* r,
|
|||
|
||||
if (r->flags & XCE_RESF_SHARED) {
|
||||
/* update shared resource */
|
||||
array = &(c->resmgr.sharedinst);
|
||||
array = &(c->sharedinst);
|
||||
} else {
|
||||
/* update host based resource */
|
||||
array = &(w->host.resvals);
|
||||
|
|
@ -457,7 +457,7 @@ int get_resval(cluster_t* c, char* resname, char* host, xce_val_t* val)
|
|||
|
||||
array = &(w->host.resvals);
|
||||
} else {
|
||||
array = &(c->resmgr.sharedinst);
|
||||
array = &(c->sharedinst);
|
||||
}
|
||||
|
||||
if (r->idx < array->caps) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue