[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openais
Subject:    [Openais] [PATCH] trunk: implement objdb plugin reload
From:       "Fabio M. Di Nitto" <fabbione () fabbione ! net>
Date:       2008-06-27 12:25:39
Message-ID: Pine.LNX.4.64.0806271419010.27368 () trider-g7
[Download RAW message or body]

Hi Steven,

this feature has been missing from sometime and now we are getting closer 
and closer for plugins to be able to do it (and need to do it).

So basically the patch implement the API to allow config/objdb reload.

Use case:

file.conf -> plugins load file.conf into objdb.

user updates file.conf..

now: nothing..

with patch: invoke $favourite_tool config-reload (or whatever keyword) and 
bang.. plugin is told to reload the config.

How clients are notified of the config change is a diffeernt matter with 
callbacks and so on. For now this is the first step in the right 
direction.

Please review.

Updates to the test cases will come soon so that it can be applied to 
trunk.

Thanks
Fabio

--
I'm going to make him an offer he can't refuse.
["openais-config-reload.diff" (TEXT/plain)]

Index: include/confdb.h
===================================================================
--- include/confdb.h	(revision 1568)
+++ include/confdb.h	(working copy)
@@ -105,6 +105,14 @@
 	char *error_text);
 
 /*
+ * Reload the configuration
+ */
+confdb_error_t confdb_reload (
+	confdb_handle_t handle,
+	int flush,
+	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.
  */
Index: include/ipc_confdb.h
===================================================================
--- include/ipc_confdb.h	(revision 1568)
+++ include/ipc_confdb.h	(working copy)
@@ -51,7 +51,8 @@
 	MESSAGE_REQ_CONFDB_KEY_ITER = 9,
 	MESSAGE_REQ_CONFDB_TRACK_START = 10,
 	MESSAGE_REQ_CONFDB_TRACK_STOP = 11,
-	MESSAGE_REQ_CONFDB_WRITE = 12
+	MESSAGE_REQ_CONFDB_WRITE = 12,
+	MESSAGE_REQ_CONFDB_RELOAD = 13
 };
 
 enum res_confdb_types {
@@ -68,7 +69,8 @@
 	MESSAGE_RES_CONFDB_TRACK_START = 10,
 	MESSAGE_RES_CONFDB_TRACK_STOP = 11,
 	MESSAGE_RES_CONFDB_CHANGE_CALLBACK = 12,
-	MESSAGE_RES_CONFDB_WRITE = 13
+	MESSAGE_RES_CONFDB_WRITE = 13,
+	MESSAGE_RES_CONFDB_RELOAD = 14
 };
 
 
@@ -174,6 +176,12 @@
 	mar_name_t error __attribute__((aligned(8)));
 };
 
+struct res_lib_confdb_reload {
+	mar_res_header_t header __attribute__((aligned(8)));
+	mar_int32_t flush __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)));
Index: exec/config.h
===================================================================
--- exec/config.h	(revision 1568)
+++ exec/config.h	(working copy)
@@ -38,6 +38,7 @@
 struct config_iface_ver0 {
 	int (*config_readconfig) (struct objdb_iface_ver0 *objdb, char **error_string);
 	int (*config_writeconfig) (struct objdb_iface_ver0 *objdb, char **error_string);
+	int (*config_reloadconfig) (struct objdb_iface_ver0 *objdb, int flush, char \
**error_string);  };
 
 
Index: exec/objdb.c
===================================================================
--- exec/objdb.c	(revision 1568)
+++ exec/objdb.c	(working copy)
@@ -1107,6 +1107,24 @@
 	return 0;
 }
 
+static int object_reload_config(int flush, char **error_string)
+{
+	struct config_iface_ver0 **modules;
+	int num_modules;
+	int i;
+	int res;
+
+	main_get_config_modules(&modules, &num_modules);
+	for (i=0; i<num_modules; i++) {
+		if (modules[i]->config_reloadconfig) {
+			res = modules[i]->config_reloadconfig(&objdb_iface, flush, error_string);
+			if (res)
+				return res;
+		}
+	}
+	return 0;
+}
+
 struct objdb_iface_ver0 objdb_iface = {
 	.objdb_init		= objdb_init,
 	.object_create		= object_create,
@@ -1131,6 +1149,7 @@
 	.object_parent_get	= object_parent_get,
 	.object_dump	        = object_dump,
 	.object_write_config    = object_write_config,
+	.object_reload_config   = object_reload_config,
 };
 
 struct lcr_iface objdb_iface_ver0[1] = {
Index: exec/objdb.h
===================================================================
--- exec/objdb.h	(revision 1568)
+++ exec/objdb.h	(working copy)
@@ -170,6 +170,11 @@
 		int *value_len);
 
 	int (*object_write_config) (char **error_string);
+
+	int (*object_reload_config) (
+		int flush,
+		char **error_string);
+
 };
 
 #endif /* OBJDB_H_DEFINED */
Index: exec/confdb.c
===================================================================
--- exec/confdb.c	(revision 1568)
+++ exec/confdb.c	(working copy)
@@ -74,6 +74,7 @@
 
 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_reload (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);
@@ -162,6 +163,12 @@
 		.response_id				= MESSAGE_RES_CONFDB_WRITE,
 		.flow_control				= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
 	},
+	{ /* 13 */
+		.lib_handler_fn				= message_handler_req_lib_confdb_reload,
+		.response_size				= sizeof (struct res_lib_confdb_reload),
+		.response_id				= MESSAGE_RES_CONFDB_RELOAD,
+		.flow_control				= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
+	},
 };
 
 
@@ -469,6 +476,27 @@
 	openais_conn_send_response(conn, &res_lib_confdb_write, \
sizeof(res_lib_confdb_write));  }
 
+static void message_handler_req_lib_confdb_reload (void *conn, void *message)
+{
+	struct res_lib_confdb_reload *req_lib_confdb_reload = (struct res_lib_confdb_reload \
*)message; +	struct res_lib_confdb_reload res_lib_confdb_reload;
+
+	int ret = SA_AIS_OK;
+	char *error_string;
+
+	if (global_objdb->object_reload_config(req_lib_confdb_reload->flush, \
&error_string)) +		ret = SA_AIS_ERR_ACCESS;
+
+	res_lib_confdb_reload.header.size = sizeof(res_lib_confdb_reload);
+	res_lib_confdb_reload.header.id = MESSAGE_RES_CONFDB_RELOAD;
+	res_lib_confdb_reload.header.error = ret;
+	strcpy((char *)res_lib_confdb_reload.error.value, error_string);
+	res_lib_confdb_reload.error.length = strlen(error_string) + 1;
+	res_lib_confdb_reload.flush = req_lib_confdb_reload->flush;
+
+	openais_conn_send_response(conn, &res_lib_confdb_reload, \
sizeof(res_lib_confdb_reload)); +}
+
 /* TODO: when we have notification in the objdb. */
 static void message_handler_req_lib_confdb_track_start (void *conn, void *message)
 {
Index: lib/sa-confdb.h
===================================================================
--- lib/sa-confdb.h	(revision 1568)
+++ lib/sa-confdb.h	(working copy)
@@ -43,3 +43,4 @@
 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); +extern int confdb_sa_reload(int flush, char \
                *error_text);
Index: lib/confdb.c
===================================================================
--- lib/confdb.c	(revision 1568)
+++ lib/confdb.c	(working copy)
@@ -1138,4 +1138,55 @@
 	return (error);
 }
 
+confdb_error_t confdb_reload (
+	confdb_handle_t handle,
+	int flush,
+	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_reload res_lib_confdb_reload;
 
+	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_reload(flush, error_text))
+			error = SA_AIS_ERR_ACCESS;
+		goto error_exit;
+	}
+
+	req.size = sizeof (mar_req_header_t);
+	req.id = MESSAGE_REQ_CONFDB_RELOAD;
+
+	res_lib_confdb_reload.flush = flush;
+
+	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_reload, sizeof ( struct res_lib_confdb_reload));
+
+	pthread_mutex_unlock (&confdb_inst->response_mutex);
+	if (error != SA_AIS_OK) {
+		goto error_exit;
+	}
+
+	error = res_lib_confdb_reload.header.error;
+	memcpy(error_text, res_lib_confdb_reload.error.value, \
res_lib_confdb_reload.error.length); +
+error_exit:
+	saHandleInstancePut (&confdb_handle_t_db, handle);
+
+	return (error);
+}
+
+
Index: lib/sa-confdb.c
===================================================================
--- lib/sa-confdb.c	(revision 1568)
+++ lib/sa-confdb.c	(working copy)
@@ -284,7 +284,22 @@
 	return ret;
 }
 
+int confdb_sa_reload (
+	unsigned int parent_object_handle,
+	int flush,
+	char *error_text)
+{
+	char *errtext;
+	int ret;
 
+	ret = objdb->object_reload_config(flush, &errtext);
+	if (!ret)
+		strcpy(error_text, errtext);
+
+	return ret;
+}
+
+
 int confdb_sa_object_iter (
 	unsigned int parent_object_handle,
 	unsigned int start_pos,



_______________________________________________
Openais mailing list
Openais@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/openais

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic