[PATCH] mutex subsystem, semaphore to completion: drivers/block/loop.c

convert the block loop device from semaphores to completions.

Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by

Ingo Molnar and committed by
Ingo Molnar
11b751ae f36d4024

+14 -17
+12 -15
drivers/block/loop.c
··· 527 527 lo->lo_pending++; 528 528 loop_add_bio(lo, old_bio); 529 529 spin_unlock_irq(&lo->lo_lock); 530 - up(&lo->lo_bh_mutex); 530 + complete(&lo->lo_bh_done); 531 531 return 0; 532 532 533 533 out: 534 534 if (lo->lo_pending == 0) 535 - up(&lo->lo_bh_mutex); 535 + complete(&lo->lo_bh_done); 536 536 spin_unlock_irq(&lo->lo_lock); 537 537 bio_io_error(old_bio, old_bio->bi_size); 538 538 return 0; ··· 593 593 lo->lo_pending = 1; 594 594 595 595 /* 596 - * up sem, we are running 596 + * complete it, we are running 597 597 */ 598 - up(&lo->lo_sem); 598 + complete(&lo->lo_done); 599 599 600 600 for (;;) { 601 601 int pending; 602 602 603 - /* 604 - * interruptible just to not contribute to load avg 605 - */ 606 - if (down_interruptible(&lo->lo_bh_mutex)) 603 + if (wait_for_completion_interruptible(&lo->lo_bh_done)) 607 604 continue; 608 605 609 606 spin_lock_irq(&lo->lo_lock); 610 607 611 608 /* 612 - * could be upped because of tear-down, not pending work 609 + * could be completed because of tear-down, not pending work 613 610 */ 614 611 if (unlikely(!lo->lo_pending)) { 615 612 spin_unlock_irq(&lo->lo_lock); ··· 629 632 break; 630 633 } 631 634 632 - up(&lo->lo_sem); 635 + complete(&lo->lo_done); 633 636 return 0; 634 637 } 635 638 ··· 840 843 set_blocksize(bdev, lo_blocksize); 841 844 842 845 kernel_thread(loop_thread, lo, CLONE_KERNEL); 843 - down(&lo->lo_sem); 846 + wait_for_completion(&lo->lo_done); 844 847 return 0; 845 848 846 849 out_putf: ··· 906 909 lo->lo_state = Lo_rundown; 907 910 lo->lo_pending--; 908 911 if (!lo->lo_pending) 909 - up(&lo->lo_bh_mutex); 912 + complete(&lo->lo_bh_done); 910 913 spin_unlock_irq(&lo->lo_lock); 911 914 912 - down(&lo->lo_sem); 915 + wait_for_completion(&lo->lo_done); 913 916 914 917 lo->lo_backing_file = NULL; 915 918 ··· 1286 1289 if (!lo->lo_queue) 1287 1290 goto out_mem4; 1288 1291 init_MUTEX(&lo->lo_ctl_mutex); 1289 - init_MUTEX_LOCKED(&lo->lo_sem); 1290 - init_MUTEX_LOCKED(&lo->lo_bh_mutex); 1292 + init_completion(&lo->lo_done); 1293 + init_completion(&lo->lo_bh_done); 1291 1294 lo->lo_number = i; 1292 1295 spin_lock_init(&lo->lo_lock); 1293 1296 disk->major = LOOP_MAJOR;
+2 -2
include/linux/loop.h
··· 58 58 struct bio *lo_bio; 59 59 struct bio *lo_biotail; 60 60 int lo_state; 61 - struct semaphore lo_sem; 61 + struct completion lo_done; 62 + struct completion lo_bh_done; 62 63 struct semaphore lo_ctl_mutex; 63 - struct semaphore lo_bh_mutex; 64 64 int lo_pending; 65 65 66 66 request_queue_t *lo_queue;