This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

master - ccs: libccs implement reload operations


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=03a62e13247fcea9190e2dac61a7e4cc410599c0
Commit:        03a62e13247fcea9190e2dac61a7e4cc410599c0
Parent:        90c6340891ae9bffd09f3a2e31a1d10b3dda8200
Author:        Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate:    Tue Nov 4 12:31:53 2008 +0100
Committer:     Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Tue Nov 4 12:34:02 2008 +0100

ccs: libccs implement reload operations

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
 config/libs/libccsconfdb/ccs.h          |    3 +-
 config/libs/libccsconfdb/ccs_internal.h |    9 ++-
 config/libs/libccsconfdb/fullxpath.c    |   25 ++++++-
 config/libs/libccsconfdb/libccs.c       |  124 ++++++++++++++++++++++++++++++-
 config/libs/libccsconfdb/xpathlite.c    |   19 +++++-
 5 files changed, 170 insertions(+), 10 deletions(-)

diff --git a/config/libs/libccsconfdb/ccs.h b/config/libs/libccsconfdb/ccs.h
index e8a8306..7f8a7c3 100644
--- a/config/libs/libccsconfdb/ccs.h
+++ b/config/libs/libccsconfdb/ccs.h
@@ -12,7 +12,8 @@ int ccs_get(int desc, const char *query, char **rtn);
 int ccs_get_list(int desc, const char *query, char **rtn);
 int ccs_set(int desc, const char *path, char *val);
 int ccs_lookup_nodename(int desc, const char *nodename, char **rtn);
-void ccs_read_logging(int desc, char *name, int *debug, int *mode, int *facility, int *priority, char *file);
+void ccs_read_logging(int desc, char *name, int *debug, int *mode,
+		      int *facility, int *priority, char *file);
 
 extern int fullxpath;
 
diff --git a/config/libs/libccsconfdb/ccs_internal.h b/config/libs/libccsconfdb/ccs_internal.h
index a0f5b79..00e30af 100644
--- a/config/libs/libccsconfdb/ccs_internal.h
+++ b/config/libs/libccsconfdb/ccs_internal.h
@@ -12,17 +12,20 @@ int get_previous_query(confdb_handle_t handle, unsigned int connection_handle,
 int set_previous_query(confdb_handle_t handle, unsigned int connection_handle,
 		       char *previous_query, unsigned int query_handle)
     __attribute__ ((visibility("hidden")));
+int set_stored_config_version(confdb_handle_t handle,
+			      unsigned int connection_handle, int need_reload)
+    __attribute__ ((visibility("hidden")));
 
 /* from xpathlite.c */
 char *_ccs_get_xpathlite(confdb_handle_t handle, unsigned int connection_handle,
-			 const char *query, int list)
+			 const char *query, int list, int need_reload)
     __attribute__ ((visibility("hidden")));
 
 /* from fullxpath.c */
 char *_ccs_get_fullxpath(confdb_handle_t handle, unsigned int connection_handle,
-			 const char *query, int list)
+			 const char *query, int list, int need_reload)
     __attribute__ ((visibility("hidden")));
-int xpathfull_init(confdb_handle_t handle, int ccs_handle)
+int xpathfull_init(confdb_handle_t handle)
     __attribute__ ((visibility("hidden")));
 void xpathfull_finish() __attribute__ ((visibility("hidden")));
 
diff --git a/config/libs/libccsconfdb/fullxpath.c b/config/libs/libccsconfdb/fullxpath.c
index fb6fce3..926c79b 100644
--- a/config/libs/libccsconfdb/fullxpath.c
+++ b/config/libs/libccsconfdb/fullxpath.c
@@ -153,7 +153,7 @@ static int dump_objdb_buff(confdb_handle_t dump_handle,
 	return 0;
 }
 
-int xpathfull_init(confdb_handle_t handle, int ccs_handle)
+int xpathfull_init(confdb_handle_t handle)
 {
 	int size = XMLBUFSIZE;
 	char *buffer, *newbuf;
@@ -205,6 +205,23 @@ void xpathfull_finish()
 	return;
 }
 
+static int full_xpath_reload(confdb_handle_t handle,
+			     unsigned int connection_handle, int need_reload)
+{
+	xpathfull_finish();
+	if (xpathfull_init(handle))
+		return -1;
+
+	reset_iterator(handle, connection_handle);
+	if (set_previous_query(handle, connection_handle, "", 0))
+		return -1;
+
+	if (set_stored_config_version(handle, connection_handle, need_reload))
+		return -1;
+
+	return 0;
+}
+
 /**
  * _ccs_get_fullxpath
  * @desc:
@@ -219,7 +236,7 @@ void xpathfull_finish()
  * Returns: 0 on success, < 0 on failure
  */
 char *_ccs_get_fullxpath(confdb_handle_t handle, unsigned int connection_handle,
-			 const char *query, int list)
+			 const char *query, int list, int need_reload)
 {
 	xmlXPathObjectPtr obj = NULL;
 	char realquery[PATH_MAX + 16];
@@ -231,6 +248,10 @@ char *_ccs_get_fullxpath(confdb_handle_t handle, unsigned int connection_handle,
 
 	errno = 0;
 
+	if (need_reload)
+		if (full_xpath_reload(handle, connection_handle, need_reload))
+			return NULL;
+
 	if (strncmp(query, "/", 1)) {
 		errno = EINVAL;
 		goto fail;
diff --git a/config/libs/libccsconfdb/libccs.c b/config/libs/libccsconfdb/libccs.c
index 1e65d38..5f70a87 100644
--- a/config/libs/libccsconfdb/libccs.c
+++ b/config/libs/libccsconfdb/libccs.c
@@ -122,11 +122,106 @@ static int destroy_ccs_handle(confdb_handle_t handle,
 	return 0;
 }
 
+static int get_running_config_version(confdb_handle_t handle)
+{
+	unsigned int cluster_handle;
+	char data[128];
+	int datalen = 0;
+	int ret = -1;
+
+	if (confdb_object_find_start(handle, OBJECT_PARENT_HANDLE) != SA_AIS_OK) {
+		errno = ENOMEM;
+		return -1;
+	}
+
+	if (confdb_object_find
+	    (handle, OBJECT_PARENT_HANDLE, "cluster", strlen("cluster"),
+	     &cluster_handle) == SA_AIS_OK) {
+		memset(data, 0, sizeof(data));
+		if (confdb_key_get
+		    (handle, cluster_handle, "config_version",
+		     strlen("config_version"), data, &datalen) == SA_AIS_OK) {
+			ret = atoi(data);
+		}
+	}
+
+	confdb_object_find_destroy(handle, OBJECT_PARENT_HANDLE);
+
+	if (ret < 0)
+		errno = ENODATA;
+
+	return ret;
+}
+
+static int get_stored_config_version(confdb_handle_t handle,
+				     unsigned int connection_handle)
+{
+	char data[128];
+	int datalen = 0;
+	int ret = -1;
+
+	if (confdb_key_get
+	    (handle, connection_handle, "config_version",
+	     strlen("config_version"), data, &datalen) == SA_AIS_OK) {
+		ret = atoi(data);
+	}
+
+	if (ret < 0)
+		errno = ENODATA;
+
+	return ret;
+}
+
+int set_stored_config_version(confdb_handle_t handle,
+			      unsigned int connection_handle, int new_version)
+{
+	char temp[PATH_MAX];
+	int templen = 0;
+	char data[128];
+
+	memset(data, 0, sizeof(data));
+	snprintf(data, sizeof(data), "%d", new_version);
+
+	if (confdb_key_get
+	    (handle, connection_handle, "config_version",
+	     strlen("config_version"), temp, &templen) == SA_AIS_OK) {
+		if (confdb_key_replace
+		    (handle, connection_handle, "config_version",
+		     strlen("config_version"), temp, templen, data,
+		     strlen(data) + 1) == SA_AIS_OK) {
+			return 0;
+		}
+	}
+
+	return -1;
+}
+
+static int compare_config_versions(confdb_handle_t handle,
+				   unsigned int connection_handle)
+{
+	int running_version;
+	int stored_version;
+
+	running_version = get_running_config_version(handle);
+	if (running_version < 0)
+		return -1;
+
+	stored_version = get_stored_config_version(handle, connection_handle);
+	if (stored_version < 0)
+		return -1;
+
+	if (running_version != stored_version)
+		return running_version;
+
+	return 0;
+}
+
 static unsigned int create_ccs_handle(confdb_handle_t handle, int ccs_handle,
 				      int fullxpath)
 {
 	unsigned int libccs_handle = 0, connection_handle = 0;
 	char buf[128];
+	int config_version = 0;
 #ifdef EXPERIMENTAL_BUILD
 	time_t current_time;
 #endif
@@ -135,6 +230,10 @@ static unsigned int create_ccs_handle(confdb_handle_t handle, int ccs_handle,
 	if (libccs_handle == -1)
 		return -1;
 
+	config_version = get_running_config_version(handle);
+	if (config_version < 0)
+		return -1;
+
 	if (confdb_object_create
 	    (handle, libccs_handle, "connection", strlen("connection"),
 	     &connection_handle) != SA_AIS_OK) {
@@ -153,6 +252,16 @@ static unsigned int create_ccs_handle(confdb_handle_t handle, int ccs_handle,
 	}
 
 	memset(buf, 0, sizeof(buf));
+	snprintf(buf, sizeof(buf), "%d", config_version);
+	if (confdb_key_create
+	    (handle, connection_handle, "config_version",
+	     strlen("config_version"), buf, strlen(buf) + 1) != SA_AIS_OK) {
+		destroy_ccs_handle(handle, connection_handle);
+		errno = ENOMEM;
+		return -1;
+	}
+
+	memset(buf, 0, sizeof(buf));
 	snprintf(buf, sizeof(buf), "%d", fullxpath);
 	if (confdb_key_create
 	    (handle, connection_handle, "fullxpath", strlen("fullxpath"), buf,
@@ -379,6 +488,8 @@ static int check_cluster_name(int ccs_handle, const char *cluster_name)
 		}
 	}
 
+	confdb_object_find_destroy(handle, OBJECT_PARENT_HANDLE);
+
 	confdb_disconnect(handle);
 
 	if (found) {
@@ -409,6 +520,7 @@ static int _ccs_get(int desc, const char *query, char **rtn, int list)
 	char data[128];
 	int datalen = 0;
 	int fullxpathint = 0;
+	int need_reload = 0;
 
 	handle = confdb_connect();
 	if (handle <= 0)
@@ -418,6 +530,10 @@ static int _ccs_get(int desc, const char *query, char **rtn, int list)
 	if (connection_handle == -1)
 		return -1;
 
+	need_reload = compare_config_versions(handle, connection_handle);
+	if (need_reload < 0)
+		return need_reload;
+
 	memset(data, 0, sizeof(data));
 	if (confdb_key_get
 	    (handle, connection_handle, "fullxpath", strlen("fullxpath"), &data,
@@ -429,10 +545,12 @@ static int _ccs_get(int desc, const char *query, char **rtn, int list)
 
 	if (!fullxpathint)
 		*rtn =
-		    _ccs_get_xpathlite(handle, connection_handle, query, list);
+		    _ccs_get_xpathlite(handle, connection_handle, query, list,
+				       need_reload);
 	else
 		*rtn =
-		    _ccs_get_fullxpath(handle, connection_handle, query, list);
+		    _ccs_get_fullxpath(handle, connection_handle, query, list,
+				       need_reload);
 
 	confdb_disconnect(handle);
 
@@ -467,7 +585,7 @@ int ccs_connect(void)
 		goto fail;
 
 	if (fullxpath) {
-		if (xpathfull_init(handle, ccs_handle)) {
+		if (xpathfull_init(handle)) {
 			ccs_disconnect(ccs_handle);
 			return -1;
 		}
diff --git a/config/libs/libccsconfdb/xpathlite.c b/config/libs/libccsconfdb/xpathlite.c
index 7a2bc8d..1cf83f7 100644
--- a/config/libs/libccsconfdb/xpathlite.c
+++ b/config/libs/libccsconfdb/xpathlite.c
@@ -348,6 +348,19 @@ fail:
 	return -1;
 }
 
+static int xpathlite_reload(confdb_handle_t handle,
+			    unsigned int connection_handle, int need_reload)
+{
+	reset_iterator(handle, connection_handle);
+	if (set_previous_query(handle, connection_handle, "", 0))
+		return -1;
+
+	if (set_stored_config_version(handle, connection_handle, need_reload))
+		return -1;
+
+	return 0;
+}
+
 /**
  * _ccs_get_xpathlite
  * @handle:
@@ -362,7 +375,7 @@ fail:
  * Returns: 0 on success, < 0 on failure
  */
 char *_ccs_get_xpathlite(confdb_handle_t handle, unsigned int connection_handle,
-			 const char *query, int list)
+			 const char *query, int list, int need_reload)
 {
 	char current_query[PATH_MAX];
 	char *datapos, *rtn;
@@ -372,6 +385,10 @@ char *_ccs_get_xpathlite(confdb_handle_t handle, unsigned int connection_handle,
 	int prev = 0, is_oldlist = 0;
 	int tokens, i;
 
+	if (need_reload)
+		if (xpathlite_reload(handle, connection_handle, need_reload))
+			return NULL;
+
 	memset(current_query, 0, PATH_MAX);
 	strncpy(current_query, query, PATH_MAX - 1);
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]