Skip to contentSkip to conversation

race bugs

PATCH Applied Benjamin Marzinski 2 participants 2 messages Jul 18, 2005 – Jul 20, 2005 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

I was looking at the waitevent thread, and I noticed some issues. Since the cancellation type is asynchronous, the thread can get cancelled at any moment. This can cause bugs. For instance, the double removal of the dm task structure that just got fixed can still show up if the thread were cancelled after it was freed but before it was set to NULL, there were other issues like this in update_multpath. It seems like the easiest way to fix this is to set some defined cancellation points. So that's what this does.

-Ben

multipathd/main.c +2 -2
diff -urpN mp-devel/multipathd/main.c mp-devel-patched/multipathd/main.c
@@ -350,7 +350,6 @@ waiteventloop (struct event_thread * wai
 
 	dm_task_no_open_count(waiter->dmt);
 
-	pthread_testcancel();
 	dm_task_run(waiter->dmt);
 	pthread_testcancel();
 	dm_task_destroy(waiter->dmt);
@@ -404,7 +403,6 @@ waitevent (void * et)
 	mlockall(MCL_CURRENT | MCL_FUTURE);
 
 	waiter = (struct event_thread *)et;
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 	pthread_cleanup_push(free_waiter, et);
 
 	while (1) {
@@ -413,7 +411,9 @@ waitevent (void * et)
 		if (r < 0)
 			break;
 
+		pthread_testcancel();
 		sleep(r);
+		pthread_testcancel();
 	}
 
 	pthread_cleanup_pop(1);
#1 lore raw

applied, thanks.

Quoted 45 lines · Benjamin Marzinski

I was looking at the waitevent thread, and I noticed some issues. Since the cancellation type is asynchronous, the thread can get cancelled at any moment. This can cause bugs. For instance, the double removal of the dm task structure that just got fixed can still show up if the thread were cancelled after it was freed but before it was set to NULL, there were other issues like this in update_multpath. It seems like the easiest way to fix this is to set some defined cancellation points. So that's what this does.

-Ben

diff -urpN mp-devel/multipathd/main.c mp-devel-patched/multipathd/main.c

multipathd/main.c +2 -3
@@ -350,7 +350,6 @@ waiteventloop (struct event_thread * wai
 
 	dm_task_no_open_count(waiter->dmt);
 
-	pthread_testcancel();
 	dm_task_run(waiter->dmt);
 	pthread_testcancel();
 	dm_task_destroy(waiter->dmt);
@@ -404,7 +403,6 @@ waitevent (void * et)
 	mlockall(MCL_CURRENT | MCL_FUTURE);
 
 	waiter = (struct event_thread *)et;
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 	pthread_cleanup_push(free_waiter, et);
 
 	while (1) {
@@ -413,7 +411,9 @@ waitevent (void * et)
 		if (r < 0)
 			break;
 
+		pthread_testcancel();
 		sleep(r);
+		pthread_testcancel();
 	}
 
 	pthread_cleanup_pop(1);
 
--

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