CONFDB: add confdb_object_name_get()

This is useful when tracking object changes.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
Reviewed-by: Seven Dake <sdake@redhat.com>
This commit is contained in:
Angus Salkeld 2011-01-12 13:27:35 +11:00 committed by Steven Dake
parent 34cb488999
commit 89e4c1c048
6 changed files with 111 additions and 0 deletions

View File

@ -194,6 +194,12 @@ cs_error_t confdb_object_parent_get (
hdb_handle_t object_handle,
hdb_handle_t *parent_object_handle);
cs_error_t confdb_object_name_get (
confdb_handle_t handle,
hdb_handle_t object_handle,
char *object_name,
size_t *object_name_len);
/*
* Manipulate keys
*/

View File

@ -59,6 +59,7 @@ enum req_confdb_types {
MESSAGE_REQ_CONFDB_KEY_CREATE_TYPED = 17,
MESSAGE_REQ_CONFDB_KEY_GET_TYPED = 18,
MESSAGE_REQ_CONFDB_KEY_ITER_TYPED = 19,
MESSAGE_REQ_CONFDB_OBJECT_NAME_GET = 20,
};
enum res_confdb_types {
@ -85,6 +86,7 @@ enum res_confdb_types {
MESSAGE_RES_CONFDB_KEY_GET_TYPED = 20,
MESSAGE_RES_CONFDB_KEY_ITER_TYPED = 21,
MESSAGE_RES_CONFDB_RELOAD_CALLBACK = 22,
MESSAGE_RES_CONFDB_OBJECT_NAME_GET = 23,
};
@ -114,6 +116,15 @@ struct res_lib_confdb_object_parent_get {
mar_uint64_t parent_object_handle __attribute__((aligned(8)));
};
struct req_lib_confdb_object_name_get {
coroipc_request_header_t header __attribute__((aligned(8)));
mar_uint64_t object_handle __attribute__((aligned(8)));
};
struct res_lib_confdb_object_name_get {
coroipc_response_header_t header __attribute__((aligned(8)));
mar_name_t object_name __attribute__((aligned(8)));
};
struct req_lib_confdb_key_create {
coroipc_request_header_t header __attribute__((aligned(8)));

View File

@ -575,6 +575,61 @@ error_exit:
return (error);
}
cs_error_t confdb_object_name_get (
confdb_handle_t handle,
hdb_handle_t object_handle,
char *object_name,
size_t *object_name_len)
{
cs_error_t error;
struct confdb_inst *confdb_inst;
struct iovec iov;
struct req_lib_confdb_object_name_get request;
struct res_lib_confdb_object_name_get response;
error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
if (error != CS_OK) {
return (error);
}
if (confdb_inst->standalone) {
error = CS_OK;
if (confdb_sa_object_name_get(object_handle, object_name, object_name_len))
error = CS_ERR_ACCESS;
goto error_exit;
}
request.header.size = sizeof (struct req_lib_confdb_object_name_get);
request.header.id = MESSAGE_REQ_CONFDB_OBJECT_NAME_GET;
request.object_handle = object_handle;
iov.iov_base = (char *)&request;
iov.iov_len = sizeof (struct req_lib_confdb_object_name_get);
error = coroipcc_msg_send_reply_receive (
confdb_inst->handle,
&iov,
1,
&response,
sizeof (struct res_lib_confdb_object_name_get));
if (error != CS_OK) {
goto error_exit;
}
error = response.header.error;
if (error == CS_OK) {
*object_name_len = response.object_name.length;
memcpy(object_name, response.object_name.value, *object_name_len);
}
error_exit:
(void)hdb_handle_put (&confdb_handle_t_db, handle);
return (error);
}
static cs_error_t do_find_destroy(
struct confdb_inst *confdb_inst,
hdb_handle_t find_handle)

View File

@ -186,6 +186,14 @@ int confdb_sa_object_parent_get (
return objdb->object_parent_get(object_handle, parent_object_handle);
}
int confdb_sa_object_name_get(
hdb_handle_t object_handle,
char *object_name,
size_t *object_name_len)
{
return objdb->object_name_get(object_handle, object_name, object_name_len);
}
int confdb_sa_key_create (
hdb_handle_t parent_object_handle,
const void *key_name,

View File

@ -40,6 +40,9 @@ extern int confdb_sa_object_create(hdb_handle_t parent_object_handle,
extern int confdb_sa_object_destroy(hdb_handle_t object_handle);
extern int confdb_sa_object_parent_get(hdb_handle_t object_handle,
hdb_handle_t *parent_object_handle);
extern int confdb_sa_object_name_get(hdb_handle_t object_handle,
char *object_name,
size_t *object_name_len);
extern int confdb_sa_key_create(hdb_handle_t parent_object_handle,
const void *key_name,
size_t key_name_len,

View File

@ -107,6 +107,8 @@ static void message_handler_req_lib_confdb_object_find (void *conn,
static void message_handler_req_lib_confdb_object_parent_get (void *conn,
const void *message);
static void message_handler_req_lib_confdb_object_name_get (void *conn,
const void *message);
static void message_handler_req_lib_confdb_write (void *conn,
const void *message);
static void message_handler_req_lib_confdb_reload (void *conn,
@ -227,6 +229,10 @@ static struct corosync_lib_handler confdb_lib_engine[] =
.lib_handler_fn = message_handler_req_lib_confdb_key_iter_typed,
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
},
{ /* 20 */
.lib_handler_fn = message_handler_req_lib_confdb_object_name_get,
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
},
};
@ -570,6 +576,28 @@ static void message_handler_req_lib_confdb_object_parent_get (void *conn,
api->ipc_response_send(conn, &res_lib_confdb_object_parent_get, sizeof(res_lib_confdb_object_parent_get));
}
static void message_handler_req_lib_confdb_object_name_get (void *conn,
const void *message)
{
const struct req_lib_confdb_object_name_get *request = message;
struct res_lib_confdb_object_name_get response;
int ret = CS_OK;
char object_name[CS_MAX_NAME_LENGTH];
size_t object_name_len;
if (api->object_name_get(request->object_handle,
object_name, &object_name_len)) {
ret = CS_ERR_ACCESS;
}
response.object_name.length = object_name_len;
strncpy((char*)response.object_name.value, object_name, CS_MAX_NAME_LENGTH);
response.object_name.value[CS_MAX_NAME_LENGTH-1] = '\0';
response.header.size = sizeof(response);
response.header.id = MESSAGE_RES_CONFDB_OBJECT_NAME_GET;
response.header.error = ret;
api->ipc_response_send(conn, &response, sizeof(response));
}
static void message_handler_req_lib_confdb_key_iter (void *conn,
const void *message)