loop.c (1b1dcc1b57a49136f118a0f16367256ff9994a69) | loop.c (11b751ae8c8ca3fa24c85bd5a3e51dd9f95cda17) |
---|---|
1/* 2 * linux/drivers/block/loop.c 3 * 4 * Written by Theodore Ts'o, 3/29/93 5 * 6 * Copyright 1993 by Theodore Ts'o. Redistribution of this file is 7 * permitted under the GNU General Public License. 8 * --- 513 unchanged lines hidden (view full) --- 522 spin_lock_irq(&lo->lo_lock); 523 if (lo->lo_state != Lo_bound) 524 goto out; 525 if (unlikely(rw == WRITE && (lo->lo_flags & LO_FLAGS_READ_ONLY))) 526 goto out; 527 lo->lo_pending++; 528 loop_add_bio(lo, old_bio); 529 spin_unlock_irq(&lo->lo_lock); | 1/* 2 * linux/drivers/block/loop.c 3 * 4 * Written by Theodore Ts'o, 3/29/93 5 * 6 * Copyright 1993 by Theodore Ts'o. Redistribution of this file is 7 * permitted under the GNU General Public License. 8 * --- 513 unchanged lines hidden (view full) --- 522 spin_lock_irq(&lo->lo_lock); 523 if (lo->lo_state != Lo_bound) 524 goto out; 525 if (unlikely(rw == WRITE && (lo->lo_flags & LO_FLAGS_READ_ONLY))) 526 goto out; 527 lo->lo_pending++; 528 loop_add_bio(lo, old_bio); 529 spin_unlock_irq(&lo->lo_lock); |
530 up(&lo->lo_bh_mutex); | 530 complete(&lo->lo_bh_done); |
531 return 0; 532 533out: 534 if (lo->lo_pending == 0) | 531 return 0; 532 533out: 534 if (lo->lo_pending == 0) |
535 up(&lo->lo_bh_mutex); | 535 complete(&lo->lo_bh_done); |
536 spin_unlock_irq(&lo->lo_lock); 537 bio_io_error(old_bio, old_bio->bi_size); 538 return 0; 539} 540 541/* 542 * kick off io on the underlying address space 543 */ --- 44 unchanged lines hidden (view full) --- 588 current->flags |= PF_NOFREEZE; 589 590 set_user_nice(current, -20); 591 592 lo->lo_state = Lo_bound; 593 lo->lo_pending = 1; 594 595 /* | 536 spin_unlock_irq(&lo->lo_lock); 537 bio_io_error(old_bio, old_bio->bi_size); 538 return 0; 539} 540 541/* 542 * kick off io on the underlying address space 543 */ --- 44 unchanged lines hidden (view full) --- 588 current->flags |= PF_NOFREEZE; 589 590 set_user_nice(current, -20); 591 592 lo->lo_state = Lo_bound; 593 lo->lo_pending = 1; 594 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 600 for (;;) { 601 int pending; 602 | 599 600 for (;;) { 601 int pending; 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 continue; 608 609 spin_lock_irq(&lo->lo_lock); 610 611 /* | 604 continue; 605 606 spin_lock_irq(&lo->lo_lock); 607 608 /* |
612 * could be upped because of tear-down, not pending work | 609 * could be completed because of tear-down, not pending work |
613 */ 614 if (unlikely(!lo->lo_pending)) { 615 spin_unlock_irq(&lo->lo_lock); 616 break; 617 } 618 619 bio = loop_get_bio(lo); 620 lo->lo_pending--; --- 6 unchanged lines hidden (view full) --- 627 /* 628 * upped both for pending work and tear-down, lo_pending 629 * will hit zero then 630 */ 631 if (unlikely(!pending)) 632 break; 633 } 634 | 610 */ 611 if (unlikely(!lo->lo_pending)) { 612 spin_unlock_irq(&lo->lo_lock); 613 break; 614 } 615 616 bio = loop_get_bio(lo); 617 lo->lo_pending--; --- 6 unchanged lines hidden (view full) --- 624 /* 625 * upped both for pending work and tear-down, lo_pending 626 * will hit zero then 627 */ 628 if (unlikely(!pending)) 629 break; 630 } 631 |
635 up(&lo->lo_sem); | 632 complete(&lo->lo_done); |
636 return 0; 637} 638 639/* 640 * loop_switch performs the hard work of switching a backing store. 641 * First it needs to flush existing IO, it does this by sending a magic 642 * BIO down the pipe. The completion of this BIO does the actual switch. 643 */ --- 194 unchanged lines hidden (view full) --- 838 lo->lo_queue->unplug_fn = loop_unplug; 839 840 set_capacity(disks[lo->lo_number], size); 841 bd_set_size(bdev, size << 9); 842 843 set_blocksize(bdev, lo_blocksize); 844 845 kernel_thread(loop_thread, lo, CLONE_KERNEL); | 633 return 0; 634} 635 636/* 637 * loop_switch performs the hard work of switching a backing store. 638 * First it needs to flush existing IO, it does this by sending a magic 639 * BIO down the pipe. The completion of this BIO does the actual switch. 640 */ --- 194 unchanged lines hidden (view full) --- 835 lo->lo_queue->unplug_fn = loop_unplug; 836 837 set_capacity(disks[lo->lo_number], size); 838 bd_set_size(bdev, size << 9); 839 840 set_blocksize(bdev, lo_blocksize); 841 842 kernel_thread(loop_thread, lo, CLONE_KERNEL); |
846 down(&lo->lo_sem); | 843 wait_for_completion(&lo->lo_done); |
847 return 0; 848 849 out_putf: 850 fput(file); 851 out: 852 /* This is safe: open() is still holding a reference. */ 853 module_put(THIS_MODULE); 854 return error; --- 49 unchanged lines hidden (view full) --- 904 905 if (filp == NULL) 906 return -EINVAL; 907 908 spin_lock_irq(&lo->lo_lock); 909 lo->lo_state = Lo_rundown; 910 lo->lo_pending--; 911 if (!lo->lo_pending) | 844 return 0; 845 846 out_putf: 847 fput(file); 848 out: 849 /* This is safe: open() is still holding a reference. */ 850 module_put(THIS_MODULE); 851 return error; --- 49 unchanged lines hidden (view full) --- 901 902 if (filp == NULL) 903 return -EINVAL; 904 905 spin_lock_irq(&lo->lo_lock); 906 lo->lo_state = Lo_rundown; 907 lo->lo_pending--; 908 if (!lo->lo_pending) |
912 up(&lo->lo_bh_mutex); | 909 complete(&lo->lo_bh_done); |
913 spin_unlock_irq(&lo->lo_lock); 914 | 910 spin_unlock_irq(&lo->lo_lock); 911 |
915 down(&lo->lo_sem); | 912 wait_for_completion(&lo->lo_done); |
916 917 lo->lo_backing_file = NULL; 918 919 loop_release_xfer(lo); 920 lo->transfer = NULL; 921 lo->ioctl = NULL; 922 lo->lo_device = NULL; 923 lo->lo_encryption = NULL; --- 360 unchanged lines hidden (view full) --- 1284 struct loop_device *lo = &loop_dev[i]; 1285 struct gendisk *disk = disks[i]; 1286 1287 memset(lo, 0, sizeof(*lo)); 1288 lo->lo_queue = blk_alloc_queue(GFP_KERNEL); 1289 if (!lo->lo_queue) 1290 goto out_mem4; 1291 init_MUTEX(&lo->lo_ctl_mutex); | 913 914 lo->lo_backing_file = NULL; 915 916 loop_release_xfer(lo); 917 lo->transfer = NULL; 918 lo->ioctl = NULL; 919 lo->lo_device = NULL; 920 lo->lo_encryption = NULL; --- 360 unchanged lines hidden (view full) --- 1281 struct loop_device *lo = &loop_dev[i]; 1282 struct gendisk *disk = disks[i]; 1283 1284 memset(lo, 0, sizeof(*lo)); 1285 lo->lo_queue = blk_alloc_queue(GFP_KERNEL); 1286 if (!lo->lo_queue) 1287 goto out_mem4; 1288 init_MUTEX(&lo->lo_ctl_mutex); |
1292 init_MUTEX_LOCKED(&lo->lo_sem); 1293 init_MUTEX_LOCKED(&lo->lo_bh_mutex); | 1289 init_completion(&lo->lo_done); 1290 init_completion(&lo->lo_bh_done); |
1294 lo->lo_number = i; 1295 spin_lock_init(&lo->lo_lock); 1296 disk->major = LOOP_MAJOR; 1297 disk->first_minor = i; 1298 disk->fops = &lo_fops; 1299 sprintf(disk->disk_name, "loop%d", i); 1300 sprintf(disk->devfs_name, "loop/%d", i); 1301 disk->private_data = lo; --- 55 unchanged lines hidden --- | 1291 lo->lo_number = i; 1292 spin_lock_init(&lo->lo_lock); 1293 disk->major = LOOP_MAJOR; 1294 disk->first_minor = i; 1295 disk->fops = &lo_fops; 1296 sprintf(disk->disk_name, "loop%d", i); 1297 sprintf(disk->devfs_name, "loop/%d", i); 1298 disk->private_data = lo; --- 55 unchanged lines hidden --- |