This patch simply allows users of libconfdb to call the objdb's
write_config() method. ... for when we ever get around to implementing a
writeable store :-)

Chrissie
Index: test/testconfdb.c
===================================================================
--- test/testconfdb.c	(revision 1531)
+++ test/testconfdb.c	(working copy)
@@ -108,6 +108,7 @@
 {
 	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 @@
 		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);
 }
 
 
Index: include/confdb.h
===================================================================
--- include/confdb.h	(revision 1531)
+++ include/confdb.h	(working copy)
@@ -96,7 +96,15 @@
 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.
  */
Index: include/ipc_confdb.h
===================================================================
--- include/ipc_confdb.h	(revision 1531)
+++ include/ipc_confdb.h	(working copy)
@@ -50,7 +50,8 @@
 	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 @@
 	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 @@
 	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)));
Index: exec/confdb.c
===================================================================
--- exec/confdb.c	(revision 1531)
+++ exec/confdb.c	(working copy)
@@ -73,6 +73,7 @@
 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 @@
 		.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 @@
 	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 @@
 	openais_conn_send_response(conn, &res, sizeof(res));
 }
 
+
Index: lib/sa-confdb.h
===================================================================
--- lib/sa-confdb.h	(revision 1531)
+++ lib/sa-confdb.h	(working copy)
@@ -42,3 +42,4 @@
 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);
Index: lib/confdb.c
===================================================================
--- lib/confdb.c	(revision 1531)
+++ lib/confdb.c	(working copy)
@@ -1089,3 +1089,53 @@
 
 	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);
+}
+
+
Index: lib/sa-confdb.c
===================================================================
--- lib/sa-confdb.c	(revision 1531)
+++ lib/sa-confdb.c	(working copy)
@@ -270,7 +270,21 @@
 				       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,
 	unsigned int start_pos,
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to