[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[dm-devel] log issues



There are two log issues that I uncovered. #1 If the log is emptied when the
tail points to the very end of the log area, and the next message needs
to roll over to the start, it doesn't pull the head around too, so the head
is pointing at an empty message, causing you to print a priority 0 message
of nothing. #2 It is possible for the log to be totally full, and on the
next enqueue, have the log tail point to the log head, which causes the entire
existing log to be lost.

This patch fixes both.

-Ben Marzinski

diff -urpN mp-devel/multipathd/log.c mp-devel-patched/multipathd/log.c
--- mp-devel/multipathd/log.c	2005-07-12 11:02:17.000000000 -0500
+++ mp-devel-patched/multipathd/log.c	2005-07-26 15:44:21.588859336 -0500
@@ -108,18 +108,18 @@ int log_enqueue (int prio, const char * 
 		la->tail += ALIGN(fwd, sizeof(void *));
 	}
 	vsnprintf(buff, MAX_MSG_SIZE, fmt, ap);
-	len = ALIGN(strlen(buff) * sizeof(char) + 1, sizeof(void *));
-
+	len = ALIGN(sizeof(struct logmsg) + strlen(buff) * sizeof(char) + 1,
+		    sizeof(void *));
 	/* not enough space on tail : rewind */
-	if (la->head <= la->tail &&
-	    (len + sizeof(struct logmsg)) > (la->end - la->tail)) {
+	if (la->head <= la->tail && len > (la->end - la->tail)) {
 		logdbg(stderr, "enqueue: rewind tail to %p\n", la->tail);
 		la->tail = la->start;
+		if (la->empty)
+			la->head = la->start;
 	}
 
 	/* not enough space on head : drop msg */
-	if (la->head > la->tail &&
-	    (len + sizeof(struct logmsg)) > (la->head - la->tail)) {
+	if (la->head > la->tail && len >= (la->head - la->tail)) {
 		logdbg(stderr, "enqueue: log area overrun, drop msg\n");
 
 		if (!la->empty)
@@ -153,7 +153,7 @@ int log_dequeue (void * buff)
 
 	if (la->empty)
 		return 1;
-	
+
 	int len = strlen((char *)&src->str) * sizeof(char) +
 		  sizeof(struct logmsg) + 1;
 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]