save works
This commit is contained in:
parent
f4b1ba4cd7
commit
acfbec875b
51 changed files with 622 additions and 1175 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include "request.h"
|
||||
#include "xce/cluster_def.h"
|
||||
#include "xce/types.h"
|
||||
#include "xlist.h"
|
||||
|
||||
typedef int (*check_fn_t)(void*);
|
||||
|
||||
|
|
@ -18,35 +19,9 @@ int check_controller(void* arg)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int collect_resval_with_idx_(zarray_t* array, int* nres,
|
||||
xce_val_with_idx_t*** resvals)
|
||||
static int collect_resval_with_idx_(zarray_t* array, xlist_t* l)
|
||||
{
|
||||
int nc;
|
||||
int i, j;
|
||||
xce_val_with_idx_t** vals;
|
||||
|
||||
nc = 0;
|
||||
|
||||
for (i = 0; i < array->caps; i++) {
|
||||
if (array->data[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nc++;
|
||||
}
|
||||
|
||||
if (nc == 0) {
|
||||
*nres = 0;
|
||||
*resvals = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
vals = (xce_val_with_idx_t**)calloc(nc, sizeof(xce_val_with_idx_t*));
|
||||
if (vals == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < array->caps; i++) {
|
||||
xce_val_with_idx_t* val;
|
||||
|
|
@ -58,17 +33,12 @@ static int collect_resval_with_idx_(zarray_t* array, int* nres,
|
|||
|
||||
val = (xce_val_with_idx_t*)calloc(1, sizeof(*val));
|
||||
if (val == NULL) {
|
||||
free_resval_with_idx_list(&vals, j);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
vals[j] = val;
|
||||
j++;
|
||||
|
||||
val->idx = i;
|
||||
val->val = (xce_val_t*)calloc(1, sizeof(xce_val_t));
|
||||
if (val->val == NULL) {
|
||||
free_resval_with_idx_list(&vals, j);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
|
|
@ -82,43 +52,36 @@ static int collect_resval_with_idx_(zarray_t* array, int* nres,
|
|||
} else {
|
||||
memcpy(val->val, array->data[i], sizeof(xce_val_t));
|
||||
}
|
||||
|
||||
xlist_store(l, val);
|
||||
}
|
||||
|
||||
*nres = j;
|
||||
*resvals = vals;
|
||||
return j;
|
||||
return l->count;
|
||||
}
|
||||
|
||||
int collect_resval_with_idx(zarray_t* array, int* nres,
|
||||
xce_val_with_idx_t*** resvals)
|
||||
int collect_resval_with_idx(zarray_t* array, xlist_t* l)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
mylock_lock(&(array->lock));
|
||||
|
||||
rc = collect_resval_with_idx_(array, nres, resvals);
|
||||
rc = collect_resval_with_idx_(array, l);
|
||||
|
||||
mylock_unlock(&(array->lock));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void collect_confvars(cluster_t* c, collect_check_fn_t fn, int* nconfig,
|
||||
xce_config_t*** configs)
|
||||
void collect_confvars(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
|
||||
{
|
||||
iterator_t it;
|
||||
int nc = 0, idx;
|
||||
int rc;
|
||||
|
||||
*nconfig = 0;
|
||||
*configs = NULL;
|
||||
|
||||
rc = iter_make(&it, c->configmgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
nc = 0;
|
||||
for (;;) {
|
||||
xce_config_t* config = NULL;
|
||||
|
||||
|
|
@ -127,124 +90,60 @@ void collect_confvars(cluster_t* c, collect_check_fn_t fn, int* nconfig,
|
|||
break;
|
||||
}
|
||||
|
||||
if (config != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc < 0) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (config != NULL) {
|
||||
(*configs)[idx] = config;
|
||||
idx++;
|
||||
if ((fn == NULL) || (fn(config))) {
|
||||
xlist_store(l, config);
|
||||
}
|
||||
}
|
||||
|
||||
iter_destroy(&it);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void collect_queues(cluster_t* c, collect_check_fn_t fn, int* nqueues,
|
||||
xce_queue_t*** queues)
|
||||
void collect_queues(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
|
||||
{
|
||||
iterator_t it;
|
||||
int count;
|
||||
int rc;
|
||||
int nc;
|
||||
|
||||
*nqueues = 0;
|
||||
*queues = NULL;
|
||||
|
||||
rc = iter_make(&it, c->qmgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
for (;;) {
|
||||
xce_queue_t* q = NULL;
|
||||
queue_t* q = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&q);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (q != NULL) {
|
||||
count++;
|
||||
if (q == NULL) {
|
||||
continue;
|
||||
}
|
||||
if ((fn != NULL) || fn(q)) {
|
||||
lock(q, RTTI_LOCK_READ);
|
||||
xlist_store(l, &(q->queue));
|
||||
}
|
||||
}
|
||||
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
*queues = (xce_queue_t**)calloc(count, sizeof(xce_queue_t*));
|
||||
if ((*queues) == NULL) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
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)
|
||||
void collect_resources(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
|
||||
{
|
||||
iterator_t it;
|
||||
int rc;
|
||||
int i, nc;
|
||||
|
||||
*nresources = 0;
|
||||
*resources = NULL;
|
||||
|
||||
rc = iter_make(&it, c->resmgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
nc = 0;
|
||||
for (;;) {
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
|
|
@ -253,186 +152,145 @@ void collect_resources(cluster_t* c, collect_check_fn_t fn, int* nresources,
|
|||
break;
|
||||
}
|
||||
|
||||
if (r != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((rc < 0) || (nc == 0)) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
*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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (r != NULL) {
|
||||
(*resources)[i] = r;
|
||||
i++;
|
||||
if ((fn == NULL) || (fn(r))) {
|
||||
xlist_store(l, r);
|
||||
}
|
||||
}
|
||||
|
||||
*nresources = i;
|
||||
|
||||
iter_destroy(&it);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void collect_jobs(cluster_t* c, collect_check_fn_t fn, int* njobs,
|
||||
xce_job_t*** jobs)
|
||||
void collect_jobs(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
|
||||
{
|
||||
iterator_t it;
|
||||
int nc, i;
|
||||
int rc = 0;
|
||||
|
||||
*njobs = 0;
|
||||
*jobs = NULL;
|
||||
|
||||
rc = iter_make(&it, c->jobmgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
nc = 0;
|
||||
for (;;) {
|
||||
xce_job_t* j = NULL;
|
||||
job_t* j = NULL;
|
||||
|
||||
rc = iter_next(&it, (void**)&j);
|
||||
if ((rc < 0) || (rc == RTTI_ITER_NO_DATA)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (j != NULL) {
|
||||
nc++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((rc < 0) || (nc == 0)) {
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
if (j == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (j != NULL) {
|
||||
(*jobs)[i] = j;
|
||||
i++;
|
||||
if ((fn == NULL) || (fn(j))) {
|
||||
lock(j, RTTI_LOCK_READ);
|
||||
xlist_store(l, &(j->job));
|
||||
}
|
||||
}
|
||||
|
||||
*njobs = i;
|
||||
|
||||
iter_destroy(&it);
|
||||
return;
|
||||
}
|
||||
|
||||
void collect_workers(cluster_t* c, collect_check_fn_t fn, int* nworkers,
|
||||
xce_worker_t*** workers)
|
||||
void collect_workers(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
|
||||
{
|
||||
iterator_t it;
|
||||
int i, nc;
|
||||
int rc = 0;
|
||||
|
||||
*nworkers = 0;
|
||||
*workers = NULL;
|
||||
|
||||
rc = iter_make(&it, c->workermgr);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
nc = 0;
|
||||
for (;;) {
|
||||
xce_worker_t* w = NULL;
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (w != NULL) {
|
||||
(*workers)[i] = w;
|
||||
i++;
|
||||
if ((fn == NULL) || (fn(w))) {
|
||||
lock(w, RTTI_LOCK_READ);
|
||||
xlist_store(l, &(w->host));
|
||||
}
|
||||
}
|
||||
|
||||
*nworkers = i;
|
||||
|
||||
iter_destroy(&it);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void collect_shared_resvals(cluster_t* c, collect_check_fn_t fn, int* nres,
|
||||
xce_val_with_idx_t*** resvals)
|
||||
void collect_shared_resvals(cluster_t* c, collect_check_fn_t fn, xlist_t* l)
|
||||
{
|
||||
|
||||
collect_resval_with_idx(&(c->sharedinst), nres, resvals);
|
||||
collect_resval_with_idx(&(c->sharedinst), l);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void deref_objs(int count, void** objs)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
void* obj = objs[i];
|
||||
|
||||
if (obj == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DEREF_OBJ(obj);
|
||||
}
|
||||
}
|
||||
|
||||
int notify(cluster_t* c, endpoint_t* ep, xce_notify_data_t* data)
|
||||
{
|
||||
return xce_notify_req(ep, data);
|
||||
}
|
||||
|
||||
void unlock_collect_queues(xlist_t* l)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < l->count; i++) {
|
||||
xce_queue_t* q = (xce_queue_t*)xlist_get(l, i);
|
||||
queue_t* q1;
|
||||
|
||||
if (q == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
q1 = CONTAINER_OF(q, queue_t, queue);
|
||||
unlock(q1);
|
||||
}
|
||||
}
|
||||
|
||||
void unlock_collect_workers(xlist_t* l)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < l->count; i++) {
|
||||
xce_worker_t* w = (xce_worker_t*)xlist_get(l, i);
|
||||
worker_t* w1;
|
||||
|
||||
if (w == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
w1 = CONTAINER_OF(w, worker_t, host);
|
||||
unlock(w1);
|
||||
}
|
||||
}
|
||||
|
||||
void unlock_collect_jobs(xlist_t* l)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < l->count; i++) {
|
||||
xce_job_t* j = (xce_job_t*)xlist_get(l, i);
|
||||
job_t* j1;
|
||||
|
||||
if (j == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
j1 = CONTAINER_OF(j, job_t, job);
|
||||
unlock(j1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue