Просмотр исходного кода

More updates to make event conform to B spec.

(Logical change 1.193)


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@633 fd59a12c-fef9-0310-b244-a6a79926bd2f
Mark Haverkamp 21 лет назад
Родитель
Сommit
2b18ac9b77
4 измененных файлов с 108 добавлено и 69 удалено
  1. 32 13
      exec/evt.c
  2. 23 3
      lib/evt.c
  3. 52 52
      lib/util.c
  4. 1 1
      test/testevt.c

+ 32 - 13
exec/evt.c

@@ -2258,7 +2258,7 @@ static int lib_evt_unlink_channel(struct conn_info *conn_info, void *message)
 	if (!ucp) {
 		log_printf(LOG_LEVEL_ERROR,
 				"saEvtChannelUnlink: Memory allocation failure\n");
-		error = SA_AIS_ERR_NO_MEMORY;
+		error = SA_AIS_ERR_TRY_AGAIN;
 		goto evt_unlink_err;
 	}
 
@@ -2465,7 +2465,7 @@ static int lib_evt_event_unsubscribe(struct conn_info *conn_info,
 	 */
 	ecs = find_subscr(eco, req->icu_sub_id); 
 	if (!ecs) {
-		error = SA_AIS_ERR_INVALID_PARAM;
+		error = SA_AIS_ERR_NOT_EXIST;
 		goto unsubr_put;
 	}
 
@@ -2569,7 +2569,9 @@ static int lib_evt_event_clear_retentiontime(struct conn_info *conn_info,
 	struct res_evt_event_clear_retentiontime res;
 	struct req_evt_chan_command cpkt;
 	struct iovec rtn_iovec;
-	SaErrorT error = SA_AIS_OK;
+	struct event_data *edp;
+	struct list_head *l, *nxt;
+	SaErrorT error = SA_AIS_ERR_NOT_EXIST;
 	int ret;
 
 	req = message;
@@ -2581,16 +2583,33 @@ static int lib_evt_event_clear_retentiontime(struct conn_info *conn_info,
 			req->iec_event_id,
 			req->iec_channel_handle);
 
-	memset(&cpkt, 0, sizeof(cpkt));
-	cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
-	cpkt.chc_head.size = sizeof(cpkt);
-	cpkt.chc_op = EVT_CLEAR_RET_OP;
-	cpkt.u.chc_event_id = req->iec_event_id;
-	rtn_iovec.iov_base = &cpkt;
-	rtn_iovec.iov_len = cpkt.chc_head.size;
-	ret = totempg_mcast (&rtn_iovec, 1, TOTEMPG_AGREED);
-	if (ret != 0) {
-			error = SA_AIS_ERR_LIBRARY;
+	/*
+	 * Make sure that the event really exists first
+	 */
+	for (l = retained_list.next; l != &retained_list; l = nxt) {
+		nxt = l->next;
+		edp = list_entry(l, struct event_data, ed_retained);
+		if (edp->ed_event.led_event_id == req->iec_event_id) {
+		error = SA_AIS_OK;
+				break;
+		}
+	}
+
+	/*
+	 * Then, if it's OK, send the clear request
+	 */
+	if (error == SA_AIS_OK) {
+		memset(&cpkt, 0, sizeof(cpkt));
+		cpkt.chc_head.id = MESSAGE_REQ_EXEC_EVT_CHANCMD;
+		cpkt.chc_head.size = sizeof(cpkt);
+		cpkt.chc_op = EVT_CLEAR_RET_OP;
+		cpkt.u.chc_event_id = req->iec_event_id;
+		rtn_iovec.iov_base = &cpkt;
+		rtn_iovec.iov_len = cpkt.chc_head.size;
+		ret = totempg_mcast (&rtn_iovec, 1, TOTEMPG_AGREED);
+		if (ret != 0) {
+				error = SA_AIS_ERR_LIBRARY;
+		}
 	}
 
 	res.iec_head.size = sizeof(res);

+ 23 - 3
lib/evt.c

@@ -292,6 +292,9 @@ saEvtInitialize(
 	error = saHandleInstanceGet(&evt_instance_handle_db, *evtHandle,
 			(void*)&evti);
 	if (error != SA_AIS_OK) {
+		if (error == SA_AIS_ERR_BAD_HANDLE) {
+			error = SA_AIS_ERR_LIBRARY;
+		}
 		goto error_handle_free;
 	}
 	memset(evti, 0, sizeof(*evti));
@@ -382,6 +385,9 @@ static SaAisErrorT make_event(SaEvtEventHandleT *event_handle,
 	error = saHandleCreate(&event_handle_db, sizeof(*edi), 
 		(void*)event_handle);
 	if (error != SA_AIS_OK) {
+		if (error == SA_AIS_ERR_NO_MEMORY) {
+			error = SA_AIS_ERR_LIBRARY;
+		}
 			goto make_evt_done;
 	}
 
@@ -424,7 +430,7 @@ static SaAisErrorT make_event(SaEvtEventHandleT *event_handle,
 		edi->edi_patterns.patterns[i].pattern = malloc(pat->patternSize);
 		if (!edi->edi_patterns.patterns[i].pattern) {
 			printf("make_event: couldn't alloc %lld bytes\n", pat->patternSize);
-			error =  SA_AIS_ERR_NO_MEMORY;
+			error =  SA_AIS_ERR_LIBRARY;
 			break;
 		}
 		memcpy(edi->edi_patterns.patterns[i].pattern,
@@ -1373,17 +1379,28 @@ saEvtEventAttributesGet(
 	 * pattern count of the event.  This way the caller can tell
 	 * if it got all the possible patterns. If the returned number
 	 * is more that the number supplied, then some available patterns
-	 * were not returned.
+	 * were not returned. We indicate that by returning SA_AIS_ERR_NO_SPACE.
 	 *
 	 * The same thing happens when copying the pattern strings.
 	 */
+	if (patternArray->patternsNumber < edi->edi_patterns.patternsNumber) {
+		error = SA_AIS_ERR_NO_SPACE;
+	}
+
 	patternArray->patternsNumber = edi->edi_patterns.patternsNumber;
 
 	for (i = 0; i < npats; i++) {
+
 		memcpy(patternArray->patterns[i].pattern,
 			edi->edi_patterns.patterns[i].pattern,
 			min(patternArray->patterns[i].patternSize,
 				edi->edi_patterns.patterns[i].patternSize));
+
+		if (patternArray->patterns[i].patternSize < 
+								edi->edi_patterns.patterns[i].patternSize) {
+			error = SA_AIS_ERR_NO_SPACE;
+		}
+
 		patternArray->patterns[i].patternSize = 
 			edi->edi_patterns.patterns[i].patternSize;
 	}
@@ -1424,6 +1441,9 @@ saEvtEventDataGet(
 	if (edi->edi_event_data && edi->edi_event_data_size) {
 		xfsize = min(*eventDataSize, edi->edi_event_data_size);
 		*eventDataSize = edi->edi_event_data_size;
+		if (*eventDataSize < edi->edi_event_data_size) {
+			error = SA_AIS_ERR_NO_SPACE;
+		}
 		memcpy(eventData, edi->edi_event_data, xfsize);
 	} else {
 		*eventDataSize = 0;
@@ -1737,7 +1757,7 @@ saEvtEventSubscribe(
 	 * See if we can subscribe to this channel
 	 */
 	if (!(eci->eci_open_flags & SA_EVT_CHANNEL_SUBSCRIBER)) {
-		error = SA_AIS_ERR_INVALID_PARAM;
+		error = SA_AIS_ERR_ACCESS;
 		goto subscribe_put2;
 	}
 

+ 52 - 52
lib/util.c

@@ -90,11 +90,11 @@ saServiceConnect (
 	strcpy (address.sun_path + 1, "libais.socket");
 	fd = socket (PF_UNIX, SOCK_STREAM, 0);
 	if (fd == -1) {
-		return (SA_ERR_SYSTEM);
+		return (SA_AIS_ERR_NO_RESOURCES);
 	}
 	result = connect (fd, (struct sockaddr *)&address, sizeof (address));
 	if (result == -1) {
-		return (SA_ERR_TRY_AGAIN);
+		return (SA_AIS_ERR_TRY_AGAIN);
 	}
 
 	req_lib_response_init.resdis_header.size = sizeof (req_lib_response_init);
@@ -103,25 +103,25 @@ saServiceConnect (
 
 	error = saSendRetry (fd, &req_lib_response_init,
 		sizeof (struct req_lib_response_init), MSG_NOSIGNAL);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit;
 	}
 	error = saRecvRetry (fd, &res_lib_response_init,
 		sizeof (struct res_lib_response_init), MSG_WAITALL | MSG_NOSIGNAL);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit;
 	}
 
 	/*
 	 * Check for security errors
 	 */
-	if (res_lib_response_init.header.error != SA_OK) {
+	if (res_lib_response_init.header.error != SA_AIS_OK) {
 		error = res_lib_response_init.header.error;
 		goto error_exit;
 	}
 
 	*fdOut = fd;
-	return (SA_OK);
+	return (SA_AIS_OK);
 error_exit:
 	close (fd);
 	return (error);
@@ -155,11 +155,11 @@ saServiceConnectTwo (
 	strcpy (address.sun_path + 1, "libais.socket");
 	responseFD = socket (PF_UNIX, SOCK_STREAM, 0);
 	if (responseFD == -1) {
-		return (SA_ERR_SYSTEM);
+		return (SA_AIS_ERR_NO_RESOURCES);
 	}
 	result = connect (responseFD, (struct sockaddr *)&address, sizeof (address));
 	if (result == -1) {
-		return (SA_ERR_TRY_AGAIN);
+		return (SA_AIS_ERR_TRY_AGAIN);
 	}
 
 	req_lib_response_init.resdis_header.size = sizeof (req_lib_response_init);
@@ -169,20 +169,20 @@ saServiceConnectTwo (
 	error = saSendRetry (responseFD, &req_lib_response_init,
 		sizeof (struct req_lib_response_init),
 		MSG_NOSIGNAL);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit;
 	}
 	error = saRecvRetry (responseFD, &res_lib_response_init,
 		sizeof (struct res_lib_response_init),
 		MSG_WAITALL | MSG_NOSIGNAL);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit;
 	}
 
 	/*
 	 * Check for security errors
 	 */
-	if (res_lib_response_init.header.error != SA_OK) {
+	if (res_lib_response_init.header.error != SA_AIS_OK) {
 		error = res_lib_response_init.header.error;
 		goto error_exit;
 	}
@@ -192,11 +192,11 @@ saServiceConnectTwo (
 /* if I comment out the 4 lines below the executive crashes */
 	callbackFD = socket (PF_UNIX, SOCK_STREAM, 0);
 	if (callbackFD == -1) {
-		return (SA_ERR_SYSTEM);
+		return (SA_AIS_ERR_NO_RESOURCES);
 	}
 	result = connect (callbackFD, (struct sockaddr *)&address, sizeof (address));
 	if (result == -1) {
-		return (SA_ERR_TRY_AGAIN);
+		return (SA_AIS_ERR_TRY_AGAIN);
 	}
 
 	req_lib_dispatch_init.resdis_header.size = sizeof (req_lib_dispatch_init);
@@ -208,26 +208,26 @@ saServiceConnectTwo (
 	error = saSendRetry (callbackFD, &req_lib_dispatch_init,
 		sizeof (struct req_lib_dispatch_init),
 		MSG_NOSIGNAL);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit_two;
 	}
 	error = saRecvRetry (callbackFD, &res_lib_dispatch_init,
 		sizeof (struct res_lib_dispatch_init),
 		MSG_WAITALL | MSG_NOSIGNAL);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit_two;
 	}
 
 	/*
 	 * Check for security errors
 	 */
-	if (res_lib_dispatch_init.header.error != SA_OK) {
+	if (res_lib_dispatch_init.header.error != SA_AIS_OK) {
 		error = res_lib_dispatch_init.header.error;
 		goto error_exit;
 	}
 
 	*callbackOut = callbackFD;
-	return (SA_OK);
+	return (SA_AIS_OK);
 
 error_exit_two:
 	close (callbackFD);
@@ -243,7 +243,7 @@ saRecvRetry (
 	size_t len,
 	int flags)
 {
-	SaErrorT error = SA_OK;
+	SaErrorT error = SA_AIS_OK;
 	int result;
 	struct msghdr msg_recv;
 	struct iovec iov_recv;
@@ -267,7 +267,7 @@ retry_recv:
 		goto retry_recv;
 	}
 	if (result == -1 || result == 0) {
-		error = SA_ERR_MESSAGE_ERROR;
+		error = SA_AIS_ERR_LIBRARY;
 		goto error_exit;
 	}
 	processed += result;
@@ -291,7 +291,7 @@ saSendRetry (
 	size_t len,
 	int flags)
 {
-	SaErrorT error = SA_OK;
+	SaErrorT error = SA_AIS_OK;
 	int result;
 
 	struct msghdr msg_send;
@@ -314,7 +314,7 @@ retry_send:
 		goto retry_send;
 	}
 	if (result == -1) {
-		error = SA_ERR_SYSTEM;
+		error = SA_AIS_ERR_LIBRARY;
 	}
 	return (error);
 }
@@ -324,7 +324,7 @@ SaErrorT saSendMsgRetry (
         struct iovec *iov,
         int iov_len)
 {
-	SaErrorT error = SA_OK;
+	SaErrorT error = SA_AIS_OK;
 	int result;
 
 	struct msghdr msg_send;
@@ -343,7 +343,7 @@ retry_send:
 		goto retry_send;
 	}
 	if (result == -1) {
-		error = SA_ERR_SYSTEM;
+		error = SA_AIS_ERR_LIBRARY;
 	}
 	return (error);
 }
@@ -355,16 +355,16 @@ SaErrorT saSendMsgReceiveReply (
         void *responseMessage,
         int responseLen)
 {
-	SaErrorT error = SA_OK;
+	SaErrorT error = SA_AIS_OK;
 
 	error = saSendMsgRetry (s, iov, iov_len);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit;
 	}
 	
 	error = saRecvRetry (s, responseMessage, responseLen,
 		MSG_WAITALL | MSG_NOSIGNAL);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit;
 	}
 
@@ -379,17 +379,17 @@ SaErrorT saSendReceiveReply (
         void *responseMessage,
         int responseLen)
 {
-	SaErrorT error = SA_OK;
+	SaErrorT error = SA_AIS_OK;
 
 	error = saSendRetry (s, requestMessage, requestLen,
 		MSG_NOSIGNAL);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit;
 	}
 	
 	error = saRecvRetry (s, responseMessage, responseLen,
 		MSG_WAITALL | MSG_NOSIGNAL);
-	if (error != SA_OK) {
+	if (error != SA_AIS_OK) {
 		goto error_exit;
 	}
 
@@ -405,7 +405,7 @@ saSelectRetry (
 	fd_set *exceptfds,
 	struct timeval *timeout)
 {
-	SaErrorT error = SA_OK;
+	SaErrorT error = SA_AIS_OK;
 	int result;
 
 retry_select:
@@ -414,7 +414,7 @@ retry_select:
 		goto retry_select;
 	}
 	if (result == -1) {
-		error = SA_ERR_SYSTEM;
+		error = SA_AIS_ERR_LIBRARY;
 	}
 
 	return (error);
@@ -426,7 +426,7 @@ saPollRetry (
         unsigned int nfds,
         int timeout) 
 {
-	SaErrorT error = SA_OK;
+	SaErrorT error = SA_AIS_OK;
 	int result;
 
 retry_poll:
@@ -435,7 +435,7 @@ retry_poll:
 		goto retry_poll;
 	}
 	if (result == -1) {
-		error = SA_ERR_SYSTEM;
+		error = SA_AIS_ERR_LIBRARY;
 	}
 
 	return (error);
@@ -468,14 +468,14 @@ saHandleCreate (
 			sizeof (struct saHandle) * handleDatabase->handleCount);
 		if (newHandles == 0) {
 			pthread_mutex_unlock (&handleDatabase->mutex);
-			return (SA_ERR_NO_MEMORY);
+			return (SA_AIS_ERR_NO_MEMORY);
 		}
 		handleDatabase->handles = newHandles;
 	}
 
 	instance = malloc (instanceSize);
 	if (instance == 0) {
-		return (SA_ERR_NO_MEMORY);
+		return (SA_AIS_ERR_NO_MEMORY);
 	}
 	memset (instance, 0, instanceSize);
 
@@ -489,7 +489,7 @@ saHandleCreate (
 
 	pthread_mutex_unlock (&handleDatabase->mutex);
 
-	return (SA_OK);
+	return (SA_AIS_OK);
 }
 
 
@@ -503,7 +503,7 @@ saHandleDestroy (
 	pthread_mutex_unlock (&handleDatabase->mutex);
 	saHandleInstancePut (handleDatabase, handle);
 
-	return (SA_OK);
+	return (SA_AIS_OK);
 }
 
 
@@ -513,15 +513,15 @@ saHandleInstanceGet (
 	SaUint64T handle,
 	void **instance)
 { 
-	SaErrorT error = SA_OK;
+	SaErrorT error = SA_AIS_OK;
 	pthread_mutex_lock (&handleDatabase->mutex);
 
 	if (handle >= (SaUint64T)handleDatabase->handleCount) {
-		error = SA_ERR_BAD_HANDLE;
+		error = SA_AIS_ERR_BAD_HANDLE;
 		goto error_exit;
 	}
 	if (handleDatabase->handles[handle].state != SA_HANDLE_STATE_ACTIVE) {
-		error = SA_ERR_BAD_HANDLE;
+		error = SA_AIS_ERR_BAD_HANDLE;
 		goto error_exit;
 	}
 
@@ -557,7 +557,7 @@ saHandleInstancePut (
 
 	pthread_mutex_unlock (&handleDatabase->mutex);
 
-	return (SA_OK);
+	return (SA_AIS_OK);
 }
 
 
@@ -570,7 +570,7 @@ saVersionVerify (
 	int i;
 
 	if (version == 0) {
-		return (SA_ERR_VERSION);
+		return (SA_AIS_ERR_VERSION);
 	}
 
 	for (i = 0; i < versionDatabase->versionCount; i++) {
@@ -579,7 +579,7 @@ saVersionVerify (
 			break;
 		}
 	}
-	return (found ? SA_OK : SA_ERR_VERSION);
+	return (found ? SA_AIS_OK : SA_AIS_ERR_VERSION);
 }
 
 
@@ -597,10 +597,10 @@ saQueueInit (
 	queue->bytesPerItem = bytesPerItem;
 	queue->items = (void *)malloc (queueItems * bytesPerItem);
 	if (queue->items == 0) {
-		return (SA_ERR_NO_MEMORY);
+		return (SA_AIS_ERR_NO_MEMORY);
 	}
 	memset (queue->items, 0, queueItems * bytesPerItem);
-	return (SA_OK);
+	return (SA_AIS_OK);
 }
 
 SaErrorT
@@ -609,7 +609,7 @@ saQueueIsFull (
 	int *isFull)
 {
 	*isFull = ((queue->size - 1) == queue->used);
-	return (SA_OK);
+	return (SA_AIS_OK);
 }
 
 
@@ -619,7 +619,7 @@ saQueueIsEmpty (
 	int *isEmpty)
 {
 	*isEmpty = (queue->used == 0);
-	return (SA_OK);
+	return (SA_AIS_OK);
 }
 
 
@@ -638,14 +638,14 @@ saQueueItemAdd (
 
 	assert (queue->tail != queue->head);
 	if (queue->tail == queue->head) {
-		return (SA_ERR_LIBRARY);
+		return (SA_AIS_ERR_LIBRARY);
 	}
 	queue->head = (queue->head + 1) % queue->size;
 	queue->used++;
 	if (queue->used > queue->usedhw) {
 		queue->usedhw = queue->used;
 	}
-	return (SA_OK);
+	return (SA_AIS_OK);
 }
 
 SaErrorT
@@ -658,7 +658,7 @@ saQueueItemGet (struct queue *queue, void **item)
 	queueItem = queue->items;
 	queueItem += queuePosition * queue->bytesPerItem;
 	*item = (void *)queueItem;
-	return (SA_OK);
+	return (SA_AIS_OK);
 }
 
 SaErrorT
@@ -666,10 +666,10 @@ saQueueItemRemove (struct queue *queue)
 {
 	queue->tail = (queue->tail + 1) % queue->size;
 	if (queue->tail == queue->head) {
-		return (SA_ERR_LIBRARY);
+		return (SA_AIS_ERR_LIBRARY);
 	}
 	queue->used--;
-	return (SA_OK);
+	return (SA_AIS_OK);
 }
 
 /*

+ 1 - 1
test/testevt.c

@@ -557,7 +557,7 @@ test_channel()
 		result = saEvtEventUnsubscribe(channel_handle, 
 				subscription_id+2);
 	} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
-	if (result != SA_AIS_ERR_INVALID_PARAM) {
+	if (result != SA_AIS_ERR_NOT_EXIST) {
 		get_sa_error(result, result_buf, result_buf_len);
 		printf("ERROR: event unsubscribe result: %s\n", result_buf);
 		do {