save works
This commit is contained in:
parent
b1faeb94b6
commit
b748e30d20
35 changed files with 1247 additions and 2149 deletions
|
|
@ -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 };
|
||||
int rc;
|
||||
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;
|
||||
|
||||
if (arg->count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
rc = iter_next(&it, (void**)&config);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
arg->data = p;
|
||||
if (config != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
p[arg->idx] = (xce_queue_t*)obj_ref(arg2, OBJREF_READ);
|
||||
arg->idx++;
|
||||
if (rc < 0) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
if (nc == 0) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
iter_reset(&it);
|
||||
*configs = (xce_config_t**)calloc(nc, sizeof(xce_config_t*));
|
||||
if ((*configs) == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
idx = 0;
|
||||
for (;;) {
|
||||
xce_config_t* config = NULL;
|
||||
|
||||
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 };
|
||||
int rc;
|
||||
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;
|
||||
|
||||
if (arg->count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
rc = iter_next(&it, (void**)&q);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
arg->data = p;
|
||||
if (q != NULL) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
p[arg->idx] = (xce_resource_t*)obj_ref(arg2, OBJREF_READ);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
arg->idx++;
|
||||
*queues = (xce_queue_t**)calloc(count, sizeof(xce_queue_t*));
|
||||
if ((*queues) == NULL) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
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;
|
||||
}
|
||||
|
||||
if (q != NULL) {
|
||||
(*queues)[nc] = q;
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
*nqueues = nc;
|
||||
|
||||
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 };
|
||||
int rc;
|
||||
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;
|
||||
|
||||
if (arg->count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
rc = iter_next(&it, (void**)&r);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
arg->data = p;
|
||||
if (r != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
p[arg->idx] = (xce_job_t*)obj_ref(arg2, OBJREF_READ);
|
||||
arg->idx++;
|
||||
if ((rc < 0) || (nc == 0)) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
*resources = calloc(nc, sizeof(xce_resource_t));
|
||||
if ((*resources) == NULL) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (r != NULL) {
|
||||
(*resources)[i] = r;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
*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 };
|
||||
int rc = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
nc = 0;
|
||||
for (;;) {
|
||||
xce_job_t* j = NULL;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (arg->count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(arg->checkfn(arg2))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
rc = iter_next(&it, (void**)&j);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
arg->data = p;
|
||||
if (j != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
w = (xce_worker_t*)obj_ref(arg2, OBJREF_READ);
|
||||
if ((rc < 0) || (nc == 0)) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
collect_resval_with_idx(&(w->resvals), &(w->nresvals_to_sched),
|
||||
&(w->resvals_to_sched));
|
||||
iter_reset(&it);
|
||||
i = 0;
|
||||
|
||||
p[arg->idx] = w;
|
||||
arg->idx++;
|
||||
for (;;) {
|
||||
xce_job_t* j = NULL;
|
||||
|
||||
return 1;
|
||||
rc = iter_next(&it, (void**)&j);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (j != NULL) {
|
||||
(*jobs)[i] = j;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
*njobs = i;
|
||||
|
||||
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 };
|
||||
int rc = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue