This patch removes the disliked *_from calls from the objdb and recasts
the confdb library to use the new find_create/find_next/find_destroy API
calls instead.
I've kept the libcondfb API the same as before with the single change of
adding a confdb_object_find_destroy to tidy up the find handle after
use. If you don't call this then libcondfb will do it for you when
confdb_finalize is called.
NOTE: the confdb plugin does NOT keep a track of find handles at the
moment ... but then object_find destroy does nothing either so it's not
exacerbating anything ;-)
Chrissie
Index: include/corosync/confdb.h
===================================================================
--- include/corosync/confdb.h (revision 1632)
+++ include/corosync/confdb.h (working copy)
@@ -251,6 +251,10 @@
void *object_name,
int *object_name_len);
+confdb_error_t confdb_object_find_destroy(
+ confdb_handle_t handle,
+ unsigned int parent_object_handle);
+
/*
* Key iterator
*/
Index: include/corosync/engine/coroapi.h
===================================================================
--- include/corosync/engine/coroapi.h (revision 1632)
+++ include/corosync/engine/coroapi.h (working copy)
@@ -35,9 +35,6 @@
#define COROAPI_H_DEFINED
#include <stdio.h>
-#ifdef OPENAIS_BSD
-#include <sys/uio.h>
-#endif
typedef void * corosync_timer_handle_t;
@@ -238,6 +235,11 @@
unsigned int object_handle,
unsigned int *parent_handle);
+ int (*object_name_get) (
+ unsigned int object_handle,
+ char *object_name,
+ int *object_name_len);
+
int (*object_dump) (
unsigned int object_handle,
FILE *file);
Index: include/corosync/engine/objdb.h
===================================================================
--- include/corosync/engine/objdb.h (revision 1632)
+++ include/corosync/engine/objdb.h (working copy)
@@ -175,25 +175,15 @@
unsigned int object_handle,
unsigned int *parent_handle);
+ int (*object_name_get) (
+ unsigned int object_handle,
+ char *object_name,
+ int *object_name_len);
+
int (*object_dump) (
unsigned int object_handle,
FILE *file);
- int (*object_find_from) (
- unsigned int parent_object_handle,
- unsigned int start_pos,
- void *object_name,
- int object_name_len,
- unsigned int *object_handle,
- unsigned int *next_pos);
-
- int (*object_iter_from) (
- unsigned int parent_object_handle,
- unsigned int start_pos,
- void **object_name,
- int *name_len,
- unsigned int *object_handle);
-
int (*object_key_iter_from) (
unsigned int parent_object_handle,
unsigned int start_pos,
Index: include/corosync/ipc_confdb.h
===================================================================
--- include/corosync/ipc_confdb.h (revision 1632)
+++ include/corosync/ipc_confdb.h (working copy)
@@ -52,7 +52,8 @@
MESSAGE_REQ_CONFDB_TRACK_START = 10,
MESSAGE_REQ_CONFDB_TRACK_STOP = 11,
MESSAGE_REQ_CONFDB_WRITE = 12,
- MESSAGE_REQ_CONFDB_RELOAD = 13
+ MESSAGE_REQ_CONFDB_RELOAD = 13,
+ MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY = 14
};
enum res_confdb_types {
@@ -72,7 +73,8 @@
MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK = 13,
MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK = 14,
MESSAGE_RES_CONFDB_WRITE = 15,
- MESSAGE_RES_CONFDB_RELOAD = 16
+ MESSAGE_RES_CONFDB_RELOAD = 16,
+ MESSAGE_RES_CONFDB_OBJECT_FIND_DESTROY = 17
};
@@ -129,25 +131,26 @@
mar_req_header_t header __attribute__((aligned(8)));
mar_uint32_t parent_object_handle __attribute__((aligned(8)));
mar_name_t object_name __attribute__((aligned(8)));
- mar_uint32_t next_entry __attribute__((aligned(8)));
+ mar_uint32_t find_handle __attribute__((aligned(8)));
};
struct res_lib_confdb_object_find {
mar_res_header_t header __attribute__((aligned(8)));
mar_uint32_t object_handle __attribute__((aligned(8)));
- mar_uint32_t next_entry __attribute__((aligned(8)));
+ mar_uint32_t find_handle __attribute__((aligned(8)));
};
struct req_lib_confdb_object_iter {
mar_req_header_t header __attribute__((aligned(8)));
mar_uint32_t parent_object_handle __attribute__((aligned(8)));
- mar_uint32_t next_entry __attribute__((aligned(8)));
+ mar_uint32_t find_handle __attribute__((aligned(8)));
};
struct res_lib_confdb_object_iter {
mar_res_header_t header __attribute__((aligned(8)));
mar_name_t object_name __attribute__((aligned(8)));
mar_uint32_t object_handle __attribute__((aligned(8)));
+ mar_uint32_t find_handle __attribute__((aligned(8)));
};
struct req_lib_confdb_key_iter {
@@ -168,6 +171,11 @@
mar_name_t key_name __attribute__((aligned(8)));
};
+struct req_lib_confdb_object_find_destroy {
+ mar_req_header_t header __attribute__((aligned(8)));
+ mar_uint32_t find_handle __attribute__((aligned(8)));
+};
+
struct res_lib_confdb_key_get {
mar_res_header_t header __attribute__((aligned(8)));
mar_name_t value __attribute__((aligned(8)));
Index: services/confdb.c
===================================================================
--- services/confdb.c (revision 1632)
+++ services/confdb.c (working copy)
@@ -61,6 +61,7 @@
static void message_handler_req_lib_confdb_object_create (void *conn, void *message);
static void message_handler_req_lib_confdb_object_destroy (void *conn, void *message);
+static void message_handler_req_lib_confdb_object_find_destroy (void *conn, void *message);
static void message_handler_req_lib_confdb_key_create (void *conn, void *message);
static void message_handler_req_lib_confdb_key_get (void *conn, void *message);
@@ -182,6 +183,12 @@
.response_id = MESSAGE_RES_CONFDB_RELOAD,
.flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
},
+ { /* 14 */
+ .lib_handler_fn = message_handler_req_lib_confdb_object_find_destroy,
+ .response_size = sizeof (mar_res_header_t),
+ .response_id = MESSAGE_RES_CONFDB_OBJECT_FIND_DESTROY,
+ .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
+ },
};
@@ -252,7 +259,6 @@
static int confdb_lib_exit_fn (void *conn)
{
-
log_printf(LOG_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
/* cleanup the object trackers for this client. */
api->object_track_stop(confdb_notify_lib_of_key_change,
@@ -292,12 +298,29 @@
ret = SA_AIS_ERR_ACCESS;
res.size = sizeof(res);
- res.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
+ res.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY;
res.error = ret;
api->ipc_conn_send_response(conn, &res, sizeof(res));
}
+static void message_handler_req_lib_confdb_object_find_destroy (void *conn, void *message)
+{
+ struct req_lib_confdb_object_find_destroy *req_lib_confdb_object_find_destroy = (struct req_lib_confdb_object_find_destroy *)message;
+ mar_res_header_t res;
+ int ret = SA_AIS_OK;
+ log_printf(LOG_LEVEL_DEBUG, "object_find_destroy for conn=%p, %d\n", conn, req_lib_confdb_object_find_destroy->find_handle);
+
+ if (api->object_find_destroy(req_lib_confdb_object_find_destroy->find_handle))
+ ret = SA_AIS_ERR_ACCESS;
+
+ res.size = sizeof(res);
+ res.id = MESSAGE_RES_CONFDB_OBJECT_FIND_DESTROY;
+ res.error = ret;
+ api->ipc_conn_send_response(conn, &res, sizeof(res));
+}
+
+
static void message_handler_req_lib_confdb_key_create (void *conn, void *message)
{
struct req_lib_confdb_key_create *req_lib_confdb_key_create = (struct req_lib_confdb_key_create *)message;
@@ -435,19 +458,26 @@
{
struct req_lib_confdb_object_iter *req_lib_confdb_object_iter = (struct req_lib_confdb_object_iter *)message;
struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
- void *object_name;
int object_name_len;
int ret = SA_AIS_OK;
- if (api->object_iter_from(req_lib_confdb_object_iter->parent_object_handle,
- req_lib_confdb_object_iter->next_entry,
- &object_name,
- &object_name_len,
- &res_lib_confdb_object_iter.object_handle))
+ if (!req_lib_confdb_object_iter->find_handle) {
+ api->object_find_create(req_lib_confdb_object_iter->parent_object_handle,
+ NULL, 0,
+ &res_lib_confdb_object_iter.find_handle);
+ }
+ else
+ res_lib_confdb_object_iter.find_handle = req_lib_confdb_object_iter->find_handle;
+
+ if (api->object_find_next(res_lib_confdb_object_iter.find_handle,
+ &res_lib_confdb_object_iter.object_handle))
ret = SA_AIS_ERR_ACCESS;
else {
+ api->object_name_get(res_lib_confdb_object_iter.object_handle,
+ (char *)res_lib_confdb_object_iter.object_name.value,
+ &object_name_len);
+
res_lib_confdb_object_iter.object_name.length = object_name_len;
- memcpy(res_lib_confdb_object_iter.object_name.value, object_name, object_name_len);
}
res_lib_confdb_object_iter.header.size = sizeof(res_lib_confdb_object_iter);
res_lib_confdb_object_iter.header.id = MESSAGE_RES_CONFDB_OBJECT_ITER;
@@ -462,18 +492,24 @@
struct res_lib_confdb_object_find res_lib_confdb_object_find;
int ret = SA_AIS_OK;
- if (api->object_find_from(req_lib_confdb_object_find->parent_object_handle,
- req_lib_confdb_object_find->next_entry,
- req_lib_confdb_object_find->object_name.value,
- req_lib_confdb_object_find->object_name.length,
- &res_lib_confdb_object_find.object_handle,
- &res_lib_confdb_object_find.next_entry))
+ if (!req_lib_confdb_object_find->find_handle) {
+ api->object_find_create(req_lib_confdb_object_find->parent_object_handle,
+ req_lib_confdb_object_find->object_name.value,
+ req_lib_confdb_object_find->object_name.length,
+ &res_lib_confdb_object_find.find_handle);
+ }
+ else
+ res_lib_confdb_object_find.find_handle = req_lib_confdb_object_find->find_handle;
+
+ if (api->object_find_next(res_lib_confdb_object_find.find_handle,
+ &res_lib_confdb_object_find.object_handle))
ret = SA_AIS_ERR_ACCESS;
res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find);
res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND;
res_lib_confdb_object_find.header.error = ret;
+
api->ipc_conn_send_response(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find));
}
@@ -618,3 +654,6 @@
}
+
+
+
Index: exec/objdb.c
===================================================================
--- exec/objdb.c (revision 1632)
+++ exec/objdb.c (working copy)
@@ -696,12 +696,13 @@
object_instance = list_entry (list, struct object_instance,
child_list);
- if ((object_instance->object_name_len ==
- object_find_instance->object_len) &&
+ if (object_find_instance->object_len == 0 ||
+ ((object_instance->object_name_len ==
+ object_find_instance->object_len) &&
- (memcmp (object_instance->object_name,
- object_find_instance->object_name,
- object_find_instance->object_len) == 0)) {
+ (memcmp (object_instance->object_name,
+ object_find_instance->object_name,
+ object_find_instance->object_len) == 0))) {
found = 1;
break;
@@ -1001,25 +1002,6 @@
}
-static int object_key_iter_reset(unsigned int object_handle)
-{
- unsigned int res;
- struct object_instance *instance;
-
- res = hdb_handle_get (&object_instance_database,
- object_handle, (void *)&instance);
- if (res != 0) {
- goto error_exit;
- }
- instance->iter_key_list = &instance->key_head;
-
- hdb_handle_put (&object_instance_database, object_handle);
- return (0);
-
-error_exit:
- return (-1);
-}
-
static int object_key_iter(unsigned int parent_object_handle,
void **key_name,
int *key_len,
@@ -1064,163 +1046,6 @@
return (-1);
}
-static int object_iter_reset(unsigned int parent_object_handle)
-{
- unsigned int res;
- struct object_instance *instance;
-
- res = hdb_handle_get (&object_instance_database,
- parent_object_handle, (void *)&instance);
- if (res != 0) {
- goto error_exit;
- }
- instance->iter_list = &instance->child_head;
-
- hdb_handle_put (&object_instance_database, parent_object_handle);
- return (0);
-
-error_exit:
- return (-1);
-}
-
-static int object_iter(unsigned int parent_object_handle,
- void **object_name,
- int *name_len,
- unsigned int *object_handle)
-{
- unsigned int res;
- struct object_instance *instance;
- struct object_instance *find_instance = NULL;
- struct list_head *list;
- unsigned int found = 0;
-
- res = hdb_handle_get (&object_instance_database,
- parent_object_handle, (void *)&instance);
- if (res != 0) {
- goto error_exit;
- }
- res = -ENOENT;
- list = instance->iter_list->next;
- if (list != &instance->child_head) {
-
- find_instance = list_entry (list, struct object_instance,
- child_list);
- found = 1;
- }
- instance->iter_list = list;
-
- if (found) {
- *object_handle = find_instance->object_handle;
- *object_name = find_instance->object_name;
- *name_len = find_instance->object_name_len;
- res = 0;
- }
- else {
- res = -1;
- }
-
- return (res);
-
-error_exit:
- return (-1);
-}
-
-
-static int object_find_from(unsigned int parent_object_handle,
- unsigned int start_pos,
- void *object_name,
- int object_name_len,
- unsigned int *object_handle,
- unsigned int *next_pos)
-{
- unsigned int res;
- unsigned int pos = 0;
- struct object_instance *instance;
- struct object_instance *find_instance = NULL;
- struct list_head *list;
- unsigned int found = 0;
-
- res = hdb_handle_get (&object_instance_database,
- parent_object_handle, (void *)&instance);
- if (res != 0) {
- goto error_exit;
- }
- res = -ENOENT;
- for (list = instance->child_head.next;
- list != &instance->child_head; list = list->next) {
-
- find_instance = list_entry (list, struct object_instance,
- child_list);
-
- if ((find_instance->object_name_len == object_name_len) &&
- (memcmp (find_instance->object_name, object_name,
- object_name_len) == 0)) {
- if (pos++ == start_pos) {
- found = 1;
- break;
- }
- }
- }
-
- hdb_handle_put (&object_instance_database, parent_object_handle);
- if (found) {
- *object_handle = find_instance->object_handle;
- res = 0;
- }
- *next_pos = pos;
- return (res);
-
-error_exit:
- return (-1);
-}
-
-static int object_iter_from(unsigned int parent_object_handle,
- unsigned int start_pos,
- void **object_name,
- int *name_len,
- unsigned int *object_handle)
-{
- unsigned int res;
- unsigned int pos = 0;
- struct object_instance *instance;
- struct object_instance *find_instance = NULL;
- struct list_head *list;
- unsigned int found = 0;
-
- res = hdb_handle_get (&object_instance_database,
- parent_object_handle, (void *)&instance);
- if (res != 0) {
- goto error_exit;
- }
- res = -ENOENT;
-
- for (list = instance->child_head.next;
- list != &instance->child_head; list = list->next) {
-
- find_instance = list_entry (list, struct object_instance,
- child_list);
- if (pos++ == start_pos) {
- found = 1;
- break;
- }
- }
-
- if (found) {
- *object_handle = find_instance->object_handle;
- *object_name = find_instance->object_name;
- *name_len = find_instance->object_name_len;
- res = 0;
- }
- else {
- res = -1;
- }
-
- return (res);
-
-error_exit:
- return (-1);
-}
-
static int object_key_iter_from(unsigned int parent_object_handle,
unsigned int start_pos,
void **key_name,
@@ -1296,7 +1121,28 @@
return (0);
}
+static int object_name_get(unsigned int object_handle,
+ char *object_name,
+ int *object_name_len)
+{
+ struct object_instance *instance;
+ unsigned int res;
+ res = hdb_handle_get (&object_instance_database,
+ object_handle, (void *)&instance);
+ if (res != 0) {
+ return (res);
+ }
+
+ memcpy(object_name, instance->object_name, instance->object_name_len);
+ *object_name_len = instance->object_name_len;
+
+ hdb_handle_put (&object_instance_database, object_handle);
+
+ return (0);
+}
+
+
static int object_track_start(unsigned int object_handle,
object_track_depth_t depth,
object_key_change_notify_fn_t key_change_notify_fn,
@@ -1449,16 +1295,12 @@
.object_find_create = object_find_create,
.object_find_next = object_find_next,
.object_find_destroy = object_find_destroy,
- .object_find_from = object_find_from,
.object_key_get = object_key_get,
.object_key_iter = object_key_iter,
- .object_key_iter_reset = object_key_iter_reset,
.object_key_iter_from = object_key_iter_from,
- .object_iter = object_iter,
- .object_iter_reset = object_iter_reset,
- .object_iter_from = object_iter_from,
.object_priv_get = object_priv_get,
.object_parent_get = object_parent_get,
+ .object_name_get = object_name_get,
.object_track_start = object_track_start,
.object_track_stop = object_track_stop,
.object_dump = object_dump,
Index: exec/apidef.c
===================================================================
--- exec/apidef.c (revision 1632)
+++ exec/apidef.c (working copy)
@@ -117,9 +117,8 @@
apidef_corosync_api_v1.object_iter = objdb->object_iter;
apidef_corosync_api_v1.object_key_iter = objdb->object_key_iter;
apidef_corosync_api_v1.object_parent_get = objdb->object_parent_get;
+ apidef_corosync_api_v1.object_name_get = objdb->object_name_get;
apidef_corosync_api_v1.object_dump = objdb->object_dump;
- apidef_corosync_api_v1.object_find_from = objdb->object_find_from;
- apidef_corosync_api_v1.object_iter_from = objdb->object_iter_from;
apidef_corosync_api_v1.object_key_iter_from = objdb->object_key_iter_from;
apidef_corosync_api_v1.object_track_start = objdb->object_track_start;
apidef_corosync_api_v1.object_track_stop = objdb->object_track_stop;
Index: lib/sa-confdb.h
===================================================================
--- lib/sa-confdb.h (revision 1632)
+++ lib/sa-confdb.h (working copy)
@@ -40,8 +40,8 @@
extern int confdb_sa_key_delete(unsigned int parent_object_handle, void *key_name, int key_name_len, void *value, int value_len);
extern int confdb_sa_key_get(unsigned int parent_object_handle, void *key_name, int key_name_len, void *value, int *value_len);
extern int confdb_sa_key_replace(unsigned int parent_object_handle, void *key_name, int key_name_len, void *old_value, int old_value_len, void *new_value, int new_value_len);
-extern int confdb_sa_object_find(unsigned int parent_object_handle, unsigned int start_pos, void *object_name, int object_name_len, unsigned int *object_handle, unsigned int *next_pos);
-extern int confdb_sa_object_iter(unsigned int parent_object_handle, unsigned int start_pos, unsigned int *object_handle, void *object_name, int *object_name_len);
+extern int confdb_sa_object_find(unsigned int parent_object_handle, unsigned int *find_handle, unsigned int *object_handle, void *object_name, int *object_name_len, int copy_name);
extern int confdb_sa_key_iter(unsigned int parent_object_handle, unsigned int start_pos, void *key_name, int *key_name_len, void *value, int *value_len);
+extern int confdb_sa_find_destroy(unsigned int find_handle);
extern int confdb_sa_write(char *error_text);
extern int confdb_sa_reload(int flush, char *error_text);
Index: lib/confdb.c
===================================================================
--- lib/confdb.c (revision 1632)
+++ lib/confdb.c (working copy)
@@ -57,7 +57,8 @@
struct iter_context {
struct list_head list;
uint32_t parent_object_handle;
- uint32_t context;
+ uint32_t find_handle;
+ uint32_t next_entry;
};
struct confdb_inst {
@@ -84,8 +85,12 @@
.handleInstanceDestructor = confdb_instance_destructor
};
+
+static confdb_error_t do_find_destroy(struct confdb_inst *confdb_inst, unsigned int find_handle);
+
+
/* Safely tidy one iterator context list */
-static void free_context_list(struct list_head *list)
+static void free_context_list(struct confdb_inst *confdb_inst, struct list_head *list)
{
struct iter_context *context;
struct list_head *iter, *tmp;
@@ -94,6 +99,7 @@
iter != list; iter = tmp, tmp = iter->next) {
context = list_entry (iter, struct iter_context, list);
+ do_find_destroy(confdb_inst, context->find_handle);
free(context);
}
}
@@ -148,7 +154,7 @@
goto error_destroy;
}
- if (getenv("OPENAIS_DEFAULT_CONFIG_IFACE")) {
+ if (getenv("COROSYNC_DEFAULT_CONFIG_IFACE")) {
error = confdb_sa_init();
confdb_inst->standalone = 1;
}
@@ -210,9 +216,9 @@
saHandleDestroy (&confdb_handle_t_db, handle);
/* Free saved context handles */
- free_context_list(&confdb_inst->object_find_head);
- free_context_list(&confdb_inst->object_iter_head);
- free_context_list(&confdb_inst->key_iter_head);
+ free_context_list(confdb_inst, &confdb_inst->object_find_head);
+ free_context_list(confdb_inst, &confdb_inst->object_iter_head);
+ free_context_list(confdb_inst, &confdb_inst->key_iter_head);
if (!confdb_inst->standalone) {
/*
@@ -622,7 +628,76 @@
return (error);
}
+#include <stdio.h>
+static confdb_error_t do_find_destroy(
+ struct confdb_inst *confdb_inst,
+ unsigned int find_handle)
+{
+ confdb_error_t error;
+ struct iovec iov[2];
+ struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
+ mar_res_header_t res;
+ if (!find_handle)
+ return SA_AIS_OK;
+
+ if (confdb_inst->standalone) {
+ error = SA_AIS_OK;
+
+ if (confdb_sa_find_destroy(find_handle))
+ error = SA_AIS_ERR_ACCESS;
+ goto error_exit;
+ }
+
+ req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
+ req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
+ req_lib_confdb_object_find_destroy.find_handle = find_handle;
+
+ iov[0].iov_base = (char *)&req_lib_confdb_object_find_destroy;
+ iov[0].iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
+
+ pthread_mutex_lock (&confdb_inst->response_mutex);
+
+ error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
+ &res, sizeof (mar_res_header_t));
+
+ pthread_mutex_unlock (&confdb_inst->response_mutex);
+ if (error != SA_AIS_OK) {
+ goto error_exit;
+ }
+
+ error = res.error;
+
+error_exit:
+
+ return (error);
+}
+
+confdb_error_t object_find_destroy(
+ confdb_handle_t handle,
+ unsigned int parent_object_handle)
+{
+ struct iter_context *context;
+ confdb_error_t error;
+ struct confdb_inst *confdb_inst;
+
+ error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
+ if (error != SA_AIS_OK) {
+ return (error);
+ }
+
+ context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
+ error = do_find_destroy(confdb_inst, context->find_handle);
+ if (error == SA_AIS_OK) {
+ list_del(&context->list);
+ free(context);
+ }
+
+ saHandleInstancePut (&confdb_handle_t_db, handle);
+ return error;
+}
+
+
confdb_error_t confdb_key_create (
confdb_handle_t handle,
unsigned int parent_object_handle,
@@ -883,10 +958,15 @@
goto ret;
}
context->parent_object_handle = object_handle;
+ context->find_handle = 0;
list_add(&context->list, &confdb_inst->object_iter_head);
}
- context->context = 0;
+ /* Start a new find context */
+ if (context->find_handle) {
+ do_find_destroy(confdb_inst, context->find_handle);
+ context->find_handle = 0;
+ }
saHandleInstancePut (&confdb_handle_t_db, handle);
@@ -918,7 +998,8 @@
list_add(&context->list, &confdb_inst->key_iter_head);
}
- context->context = 0;
+ context->find_handle = 0;
+ context->next_entry = 0;
saHandleInstancePut (&confdb_handle_t_db, handle);
@@ -946,12 +1027,16 @@
error = CONFDB_ERR_NO_MEMORY;
goto ret;
}
+ context->find_handle = 0;
context->parent_object_handle = parent_object_handle;
list_add(&context->list, &confdb_inst->object_find_head);
}
+ /* Start a new find context */
+ if (context->find_handle) {
+ do_find_destroy(confdb_inst, context->find_handle);
+ context->find_handle = 0;
+ }
- context->context = 0;
-
saHandleInstancePut (&confdb_handle_t_db, handle);
ret:
@@ -988,10 +1073,10 @@
error = SA_AIS_OK;
if (confdb_sa_object_find(parent_object_handle,
- context->context,
- object_name, object_name_len,
+ &context->find_handle,
object_handle,
- &context->context))
+ object_name, &object_name_len,
+ 0))
error = SA_AIS_ERR_ACCESS;
goto error_exit;
}
@@ -999,7 +1084,7 @@
req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
- req_lib_confdb_object_find.next_entry = context->context;
+ req_lib_confdb_object_find.find_handle = context->find_handle;
memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
req_lib_confdb_object_find.object_name.length = object_name_len;
@@ -1018,7 +1103,7 @@
error = res_lib_confdb_object_find.header.error;
*object_handle = res_lib_confdb_object_find.object_handle;
- context->context = res_lib_confdb_object_find.next_entry;
+ context->find_handle = res_lib_confdb_object_find.find_handle;
error_exit:
saHandleInstancePut (&confdb_handle_t_db, handle);
@@ -1056,10 +1141,12 @@
if (confdb_inst->standalone) {
error = SA_AIS_OK;
- if (confdb_sa_object_iter(parent_object_handle,
- context->context,
+ *object_name_len = 0;
+ if (confdb_sa_object_find(parent_object_handle,
+ &context->find_handle,
object_handle,
- object_name, object_name_len))
+ object_name, object_name_len,
+ 1))
error = SA_AIS_ERR_ACCESS;
goto sa_exit;
}
@@ -1067,7 +1154,7 @@
req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
- req_lib_confdb_object_iter.next_entry = context->context;
+ req_lib_confdb_object_iter.find_handle = context->find_handle;
iov[0].iov_base = (char *)&req_lib_confdb_object_iter;
iov[0].iov_len = sizeof (struct req_lib_confdb_object_iter);
@@ -1087,9 +1174,9 @@
*object_name_len = res_lib_confdb_object_iter.object_name.length;
memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
*object_handle = res_lib_confdb_object_iter.object_handle;
+ context->find_handle = res_lib_confdb_object_iter.find_handle;
}
sa_exit:
- context->context++;
error_exit:
saHandleInstancePut (&confdb_handle_t_db, handle);
@@ -1128,7 +1215,7 @@
error = SA_AIS_OK;
if (confdb_sa_key_iter(parent_object_handle,
- context->context,
+ context->next_entry,
key_name, key_name_len,
value, value_len))
error = SA_AIS_ERR_ACCESS;
@@ -1138,7 +1225,7 @@
req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
- req_lib_confdb_key_iter.next_entry = context->context;
+ req_lib_confdb_key_iter.next_entry= context->next_entry;
iov[0].iov_base = (char *)&req_lib_confdb_key_iter;
iov[0].iov_len = sizeof (struct req_lib_confdb_key_iter);
@@ -1162,7 +1249,7 @@
}
sa_exit:
- context->context++;
+ context->next_entry++;
error_exit:
saHandleInstancePut (&confdb_handle_t_db, handle);
Index: lib/sa-confdb.c
===================================================================
--- lib/sa-confdb.c (revision 1632)
+++ lib/sa-confdb.c (working copy)
@@ -266,22 +266,6 @@
new_value, new_value_len);
}
-int confdb_sa_object_find (
- unsigned int parent_object_handle,
- unsigned int start_pos,
- void *object_name,
- int object_name_len,
- unsigned int *object_handle,
- unsigned int *next_pos)
-{
- return objdb->object_find_from(parent_object_handle,
- start_pos,
- object_name,
- object_name_len,
- object_handle,
- next_pos);
-}
-
int confdb_sa_write (
unsigned int parent_object_handle,
char *error_text)
@@ -311,22 +295,28 @@
return ret;
}
-int confdb_sa_object_iter (
+int confdb_sa_object_find (
unsigned int parent_object_handle,
- unsigned int start_pos,
+ unsigned int *find_handle,
unsigned int *object_handle,
void *object_name,
- int *object_name_len)
+ int *object_name_len,
+ int copy_name)
{
int res;
- void *objname;
- res = objdb->object_iter_from(parent_object_handle,
- start_pos,
- &objname, object_name_len,
+ if (!*find_handle) {
+ objdb->object_find_create(parent_object_handle,
+ object_name, *object_name_len,
+ find_handle);
+ }
+
+ res = objdb->object_find_next(*find_handle,
object_handle);
- if (!res) {
- memcpy(object_name, objname, *object_name_len);
+ /* Return object name if we were called as _iter */
+ if (copy_name && !res) {
+ objdb->object_name_get(*object_handle,
+ object_name, object_name_len);
}
return res;
}
@@ -353,3 +343,8 @@
}
return res;
}
+
+int confdb_sa_find_destroy(unsigned int find_handle)
+{
+ return objdb->object_find_destroy(find_handle);
+}
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais