Skip to contentSkip to conversation

log issues

PATCH Benjamin Marzinski 2 participants 2 messages Jul 26, 2005 – Jul 27, 2005 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

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

multipathd/log.c +7 -7
diff -urpN mp-devel/multipathd/log.c mp-devel-patched/multipathd/log.c
@@ -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;
 
#1 lore raw

Many thanks for this much needed one.
Applied.

Quoted 55 lines · Benjamin Marzinski

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

multipathd/log.c +7 -8
@@ -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;
 
 
--

dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel