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

[dm-devel] race bugs



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
--- mp-devel/multipathd/main.c	2005-07-18 10:21:17.000000000 -0500
+++ mp-devel-patched/multipathd/main.c	2005-07-18 17:52:46.385426160 -0500
@@ -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);

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