Expose confdb write to the library.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1536 fd59a12c-fef9-0310-b244-a6a79926bd2f
This commit is contained in:
Patrick Caulfield 2008-05-07 07:27:37 +00:00
parent cbae863c4b
commit fef53eb2c4
8 changed files with 113 additions and 3 deletions

View File

@ -73,6 +73,7 @@ static void message_handler_req_lib_confdb_object_iter (void *conn, void *messag
static void message_handler_req_lib_confdb_object_find (void *conn, void *message);
static void message_handler_req_lib_confdb_object_parent_get (void *conn, void *message);
static void message_handler_req_lib_confdb_write (void *conn, void *message);
static void message_handler_req_lib_confdb_track_start (void *conn, void *message);
static void message_handler_req_lib_confdb_track_stop (void *conn, void *message);
@ -155,6 +156,12 @@ static struct openais_lib_handler confdb_lib_service[] =
.response_id = MESSAGE_RES_CONFDB_TRACK_START,
.flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
},
{ /* 12 */
.lib_handler_fn = message_handler_req_lib_confdb_write,
.response_size = sizeof (struct res_lib_confdb_write),
.response_id = MESSAGE_RES_CONFDB_WRITE,
.flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
},
};
@ -444,6 +451,24 @@ static void message_handler_req_lib_confdb_object_find (void *conn, void *messag
openais_conn_send_response(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find));
}
static void message_handler_req_lib_confdb_write (void *conn, void *message)
{
struct res_lib_confdb_write res_lib_confdb_write;
int ret = SA_AIS_OK;
char *error_string;
if (global_objdb->object_write_config(&error_string))
ret = SA_AIS_ERR_ACCESS;
res_lib_confdb_write.header.size = sizeof(res_lib_confdb_write);
res_lib_confdb_write.header.id = MESSAGE_RES_CONFDB_WRITE;
res_lib_confdb_write.header.error = ret;
strcpy((char *)res_lib_confdb_write.error.value, error_string);
res_lib_confdb_write.error.length = strlen(error_string) + 1;
openais_conn_send_response(conn, &res_lib_confdb_write, sizeof(res_lib_confdb_write));
}
/* TODO: when we have notification in the objdb. */
static void message_handler_req_lib_confdb_track_start (void *conn, void *message)
{
@ -465,3 +490,4 @@ static void message_handler_req_lib_confdb_track_stop (void *conn, void *message
openais_conn_send_response(conn, &res, sizeof(res));
}

View File

@ -96,6 +96,14 @@ confdb_error_t confdb_initialize (
confdb_error_t confdb_finalize (
confdb_handle_t handle);
/*
* Write back the configuration
*/
confdb_error_t confdb_write (
confdb_handle_t handle,
char *error_text);
/*
* Get a file descriptor on which to poll. confdb_handle_t is NOT a
* file descriptor and may not be used directly.

View File

@ -50,7 +50,8 @@ enum req_confdb_types {
MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET = 8,
MESSAGE_REQ_CONFDB_KEY_ITER = 9,
MESSAGE_REQ_CONFDB_TRACK_START = 10,
MESSAGE_REQ_CONFDB_TRACK_STOP = 11
MESSAGE_REQ_CONFDB_TRACK_STOP = 11,
MESSAGE_REQ_CONFDB_WRITE = 12
};
enum res_confdb_types {
@ -66,7 +67,8 @@ enum res_confdb_types {
MESSAGE_RES_CONFDB_KEY_ITER = 9,
MESSAGE_RES_CONFDB_TRACK_START = 10,
MESSAGE_RES_CONFDB_TRACK_STOP = 11,
MESSAGE_RES_CONFDB_CHANGE_CALLBACK = 12
MESSAGE_RES_CONFDB_CHANGE_CALLBACK = 12,
MESSAGE_RES_CONFDB_WRITE = 13
};
@ -167,6 +169,11 @@ struct res_lib_confdb_key_get {
mar_name_t value __attribute__((aligned(8)));
};
struct res_lib_confdb_write {
mar_res_header_t header __attribute__((aligned(8)));
mar_name_t error __attribute__((aligned(8)));
};
struct res_lib_confdb_change_callback {
mar_res_header_t header __attribute__((aligned(8)));
mar_uint32_t parent_object_handle __attribute__((aligned(8)));

View File

@ -1089,3 +1089,53 @@ error_exit:
return (error);
}
confdb_error_t confdb_write (
confdb_handle_t handle,
char *error_text)
{
confdb_error_t error;
struct confdb_inst *confdb_inst;
struct iovec iov[2];
mar_req_header_t req;
struct res_lib_confdb_write res_lib_confdb_write;
error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
if (error != SA_AIS_OK) {
return (error);
}
if (confdb_inst->standalone) {
error = SA_AIS_OK;
if (confdb_sa_write(error_text))
error = SA_AIS_ERR_ACCESS;
goto error_exit;
}
req.size = sizeof (mar_req_header_t);
req.id = MESSAGE_REQ_CONFDB_WRITE;
iov[0].iov_base = (char *)&req;
iov[0].iov_len = sizeof (mar_req_header_t);
pthread_mutex_lock (&confdb_inst->response_mutex);
error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1,
&res_lib_confdb_write, sizeof ( struct res_lib_confdb_write));
pthread_mutex_unlock (&confdb_inst->response_mutex);
if (error != SA_AIS_OK) {
goto error_exit;
}
error = res_lib_confdb_write.header.error;
memcpy(error_text, res_lib_confdb_write.error.value, res_lib_confdb_write.error.length);
error_exit:
saHandleInstancePut (&confdb_handle_t_db, handle);
return (error);
}

View File

@ -270,6 +270,20 @@ int confdb_sa_object_find (
next_pos);
}
int confdb_sa_write (
unsigned int parent_object_handle,
char *error_text)
{
char *errtext;
int ret;
ret = objdb->object_write_config(&errtext);
if (!ret)
strcpy(error_text, errtext);
return ret;
}
int confdb_sa_object_iter (
unsigned int parent_object_handle,

View File

@ -42,3 +42,4 @@ extern int confdb_sa_key_replace(unsigned int parent_object_handle, void *key_na
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_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_write(char *error_text);

View File

@ -155,7 +155,7 @@ cpgbench: cpgbench.o $(LIBRARIES)
$(CC) $(LDFLAGS) -o cpgbench cpgbench.o $(LIBS)
testconfdb: testconfdb.o $(LIBRARIES)
$(CC) $(LDFLAGS) -o testconfdb testconfdb.o $(LIBS)# -rdynamic
$(CC) $(LDFLAGS) -o testconfdb testconfdb.o $(LIBS) -rdynamic
openais-cfgtool: openais-cfgtool.o $(LIBRARIES)
$(CC) $(LDFLAGS) -o openais-cfgtool openais-cfgtool.o $(LIBS)

View File

@ -108,6 +108,7 @@ static void do_write_tests(confdb_handle_t handle)
{
int res;
unsigned int object_handle;
char error_string[1024];
/* Add a scratch object and put some keys into it */
res = confdb_object_create(handle, OBJECT_PARENT_HANDLE, (void *)"testconfdb", strlen("testconfdb"), &object_handle);
@ -153,6 +154,9 @@ static void do_write_tests(confdb_handle_t handle)
printf( "error destroying 'testconfdb' object: %d\n", res);
return;
}
res = confdb_write(handle, error_string);
printf("confdb_write returned %d: %s\n", res, error_string);
}