Skip to contentSkip to conversation

Fix race in worker_loop

PATCH In review Amit Gud 2 participants 2 messages Mar 22, 2009 – Mar 23, 2009 Btrfs file system

lore
Share & tools
lore

Amit Gud

author
#0 lore raw

PATCH 1/1 Fix race in worker_loop

Hello Chris,

Experiencing sporadic hangs during umount(2) on UML. Patch below seem to fix it if not already fixed. Based on 2.6.29-rc8. Tested with mounting and umounting iteratively 100 times. Without the fix, the race is hit within 10 tries.

AG

Signature · 2 lines
May the source be with you.
http://www.cis.ksu.edu/~gud

Need to check kthread_should_stop after schedule_timeout() before calling schedule(). This causes threads to sleep with potentially no one to wake them up causing mount(2) to hang in btrfs_stop_workers waiting for threads to stop. Race, IMO, is more evident on UP than on SMP.

fs/btrfs/async-thread.c +3 -0
index c84ca1f..4c1f3e5 100644
@@ -195,6 +195,9 @@ again_locked:
 				if (!list_empty(&worker->pending))
 					continue;
 
+				if (kthread_should_stop())
+					return 0;
+
 				/* still no more work?, sleep for real */
 				spin_lock_irq(&worker->lock);
 				set_current_state(TASK_INTERRUPTIBLE);
#1 lore raw
Quoted 6 lines · Amit Gud

Hello Chris,

Experiencing sporadic hangs during umount(2) on UML. Patch below seem to fix it if not already fixed. Based on 2.6.29-rc8. Tested with mounting and umounting iteratively 100 times. Without the fix, the race is hit within 10 tries.

Thanks for finding this one!

-chris