Hi guys,

this is the port to corosync of the patch I previosly posted for openais.

It implements the whole confdb_reload bits and as previously discussed a double pass when invoking plugins with verifyconfig first and reloadconfig after.

also fix the IPC table for confdb because MESSAGE_REQ_CONFDB_XPATH_EVAL_EXPRESSION = 12, hitted include/ipc_confdb.h without having an associated call. Thanks Chrissie for spotting this.

Please apply

Fabio

--
I'm going to make him an offer he can't refuse.
Index: test/testconfdb.c
===================================================================
--- test/testconfdb.c   (revision 1628)
+++ test/testconfdb.c   (working copy)
@@ -178,6 +178,15 @@
        if (argv[1] && strcmp(argv[1], "write")==0)
                do_write_tests(handle);
 
+       if (argv[1] && strcmp(argv[1], "reload")==0) {
+               /* Test reload interface */
+               result = confdb_reload(handle, 0, key_value);
+               printf ("Try to reload the config (noflush): %d (should be 
1)\n", result);
+
+               result = confdb_reload(handle, 1, key_value);
+               printf ("Try to reload the config (flush): %d (should be 1)\n", 
result);
+       }
+
        /* Test iterators */
        print_config_tree(handle, OBJECT_PARENT_HANDLE, 0);
 
Index: include/confdb.h
===================================================================
--- include/confdb.h    (revision 1628)
+++ include/confdb.h    (working copy)
@@ -131,6 +131,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/coroapi.h
===================================================================
--- include/coroapi.h   (revision 1628)
+++ include/coroapi.h   (working copy)
@@ -278,6 +278,9 @@
 
        int (*object_write_config) (char **error_string);
 
+       int (*object_reload_config) (int flush,
+                                    char **error_string);
+
        /*
         * Time and timer APIs
         */
Index: include/ipc_confdb.h
===================================================================
--- include/ipc_confdb.h        (revision 1628)
+++ include/ipc_confdb.h        (working copy)
@@ -51,8 +51,8 @@
        MESSAGE_REQ_CONFDB_KEY_ITER = 9,
        MESSAGE_REQ_CONFDB_TRACK_START = 10,
        MESSAGE_REQ_CONFDB_TRACK_STOP = 11,
-       MESSAGE_REQ_CONFDB_XPATH_EVAL_EXPRESSION = 12,
-       MESSAGE_REQ_CONFDB_WRITE = 13
+       MESSAGE_REQ_CONFDB_WRITE = 12,
+       MESSAGE_REQ_CONFDB_RELOAD = 13
 };
 
 enum res_confdb_types {
@@ -71,7 +71,8 @@
        MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK = 12,
        MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK = 13,
        MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK = 14,
-       MESSAGE_RES_CONFDB_WRITE = 15
+       MESSAGE_RES_CONFDB_WRITE = 15,
+       MESSAGE_RES_CONFDB_RELOAD = 16
 };
 
 
@@ -177,6 +178,16 @@
        mar_name_t error __attribute__((aligned(8)));
 };
 
+struct req_lib_confdb_reload {
+       mar_res_header_t header __attribute__((aligned(8)));
+       mar_int32_t flush __attribute__((aligned(8)));
+};
+
+struct res_lib_confdb_reload {
+       mar_res_header_t header __attribute__((aligned(8)));
+       mar_name_t error __attribute__((aligned(8)));
+};
+
 struct res_lib_confdb_key_change_callback {
        mar_res_header_t header __attribute__((aligned(8)));
        mar_uint32_t change_type __attribute__((aligned(8)));
Index: services/confdb.c
===================================================================
--- services/confdb.c   (revision 1628)
+++ services/confdb.c   (working copy)
@@ -70,6 +70,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);
@@ -172,6 +173,12 @@
                .response_id                            = 
MESSAGE_RES_CONFDB_WRITE,
                .flow_control                           = 
COROSYNC_LIB_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                           = 
COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
+       },
 };
 
 
@@ -488,6 +495,29 @@
        api->ipc_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 req_lib_confdb_reload *req_lib_confdb_reload = (struct 
req_lib_confdb_reload *)message;
+       struct res_lib_confdb_reload res_lib_confdb_reload;
+       int ret = SA_AIS_OK;
+       char *error_string = NULL;
+
+       if (api->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;
+
+       if(error_string) {
+               strcpy((char *)res_lib_confdb_reload.error.value, error_string);
+               res_lib_confdb_reload.error.length = strlen(error_string) + 1;
+       } else
+               res_lib_confdb_reload.error.length = 0;
+
+       api->ipc_conn_send_response(conn, &res_lib_confdb_reload, 
sizeof(res_lib_confdb_reload));
+}
+
 static void confdb_notify_lib_of_key_change(object_change_type_t change_type,
                                                                                
          unsigned int parent_object_handle,
                                                                                
          unsigned int object_handle,
Index: exec/config.h
===================================================================
--- exec/config.h       (revision 1628)
+++ exec/config.h       (working copy)
@@ -38,6 +38,8 @@
 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_verifyconfig) (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 1628)
+++ exec/objdb.c        (working copy)
@@ -1415,6 +1415,36 @@
        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);
+
+       /* phase 1. Each module should verify that it can reload the config
+        * and error out here if possible at all
+        */
+       for (i=0; i<num_modules; i++) {
+               if (modules[i]->config_verifyconfig) {
+                       res = modules[i]->config_verifyconfig(&objdb_iface, 
error_string);
+                       if (res)
+                               return res;
+               }
+       }
+       /* phase 2. Do it.. */
+       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,
@@ -1442,6 +1472,7 @@
        .object_track_stop      = object_track_stop,
        .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 1628)
+++ exec/objdb.h        (working copy)
@@ -217,6 +217,10 @@
                void * priv_data_pt);
 
        int (*object_write_config) (char **error_string);
+
+       int (*object_reload_config) (
+               int flush,
+               char **error_string);
 };
 
 #endif /* OBJDB_H_DEFINED */
Index: exec/apidef.c
===================================================================
--- exec/apidef.c       (revision 1628)
+++ exec/apidef.c       (working copy)
@@ -124,6 +124,7 @@
        apidef_corosync_api_v1.object_track_start = objdb->object_track_start;
        apidef_corosync_api_v1.object_track_stop = objdb->object_track_stop;
        apidef_corosync_api_v1.object_write_config = objdb->object_write_config;
+       apidef_corosync_api_v1.object_reload_config = 
objdb->object_reload_config;
 }
 
 struct corosync_api_v1 *apidef_get (void)
Index: lib/sa-confdb.h
===================================================================
--- lib/sa-confdb.h     (revision 1628)
+++ lib/sa-confdb.h     (working copy)
@@ -44,3 +44,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 1628)
+++ lib/confdb.c        (working copy)
@@ -1219,6 +1219,58 @@
        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];
+       struct res_lib_confdb_reload res_lib_confdb_reload;
+       struct req_lib_confdb_reload req_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_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
+       req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
+       req_lib_confdb_reload.flush = flush;
+
+       iov[0].iov_base = (char *)&req_lib_confdb_reload;
+       iov[0].iov_len = sizeof (req_lib_confdb_reload);
+
+       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;
+       if(res_lib_confdb_reload.error.length)
+               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);
+}
+
 confdb_error_t confdb_track_changes (
        confdb_handle_t handle,
        unsigned int object_handle,
Index: lib/sa-confdb.c
===================================================================
--- lib/sa-confdb.c     (revision 1628)
+++ lib/sa-confdb.c     (working copy)
@@ -296,7 +296,21 @@
        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
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to