Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-linus2' of git://git.kernel.dk/linux-2.6-block

* 'for-linus2' of git://git.kernel.dk/linux-2.6-block:
pipe: fix check in "set size" fcntl
pipe: fix pipe buffer resizing
block: remove duplicate BUG_ON() in bd_finish_claiming()
block: bd_start_claiming cleanup
block: bd_start_claiming fix module refcount

+62 -30
+48 -24
fs/block_dev.c
··· 706 706 * @bdev is about to be opened exclusively. Check @bdev can be opened 707 707 * exclusively and mark that an exclusive open is in progress. Each 708 708 * successful call to this function must be matched with a call to 709 - * either bd_claim() or bd_abort_claiming(). If this function 710 - * succeeds, the matching bd_claim() is guaranteed to succeed. 709 + * either bd_finish_claiming() or bd_abort_claiming() (which do not 710 + * fail). 711 + * 712 + * This function is used to gain exclusive access to the block device 713 + * without actually causing other exclusive open attempts to fail. It 714 + * should be used when the open sequence itself requires exclusive 715 + * access but may subsequently fail. 711 716 * 712 717 * CONTEXT: 713 718 * Might sleep. ··· 739 734 return ERR_PTR(-ENXIO); 740 735 741 736 whole = bdget_disk(disk, 0); 737 + module_put(disk->fops->owner); 742 738 put_disk(disk); 743 739 if (!whole) 744 740 return ERR_PTR(-ENOMEM); ··· 788 782 __bd_abort_claiming(whole, holder); /* releases bdev_lock */ 789 783 } 790 784 785 + /* increment holders when we have a legitimate claim. requires bdev_lock */ 786 + static void __bd_claim(struct block_device *bdev, struct block_device *whole, 787 + void *holder) 788 + { 789 + /* note that for a whole device bd_holders 790 + * will be incremented twice, and bd_holder will 791 + * be set to bd_claim before being set to holder 792 + */ 793 + whole->bd_holders++; 794 + whole->bd_holder = bd_claim; 795 + bdev->bd_holders++; 796 + bdev->bd_holder = holder; 797 + } 798 + 799 + /** 800 + * bd_finish_claiming - finish claiming a block device 801 + * @bdev: block device of interest (passed to bd_start_claiming()) 802 + * @whole: whole block device returned by bd_start_claiming() 803 + * @holder: holder trying to claim @bdev 804 + * 805 + * Finish a claiming block started by bd_start_claiming(). 806 + * 807 + * CONTEXT: 808 + * Grabs and releases bdev_lock. 809 + */ 810 + static void bd_finish_claiming(struct block_device *bdev, 811 + struct block_device *whole, void *holder) 812 + { 813 + spin_lock(&bdev_lock); 814 + BUG_ON(!bd_may_claim(bdev, whole, holder)); 815 + __bd_claim(bdev, whole, holder); 816 + __bd_abort_claiming(whole, holder); /* not actually an abort */ 817 + } 818 + 791 819 /** 792 820 * bd_claim - claim a block device 793 821 * @bdev: block device to claim 794 822 * @holder: holder trying to claim @bdev 795 823 * 796 - * Try to claim @bdev which must have been opened successfully. This 797 - * function may be called with or without preceding 798 - * blk_start_claiming(). In the former case, this function is always 799 - * successful and terminates the claiming block. 824 + * Try to claim @bdev which must have been opened successfully. 800 825 * 801 826 * CONTEXT: 802 827 * Might sleep. ··· 843 806 might_sleep(); 844 807 845 808 spin_lock(&bdev_lock); 846 - 847 809 res = bd_prepare_to_claim(bdev, whole, holder); 848 - if (res == 0) { 849 - /* note that for a whole device bd_holders 850 - * will be incremented twice, and bd_holder will 851 - * be set to bd_claim before being set to holder 852 - */ 853 - whole->bd_holders++; 854 - whole->bd_holder = bd_claim; 855 - bdev->bd_holders++; 856 - bdev->bd_holder = holder; 857 - } 858 - 859 - if (whole->bd_claiming) 860 - __bd_abort_claiming(whole, holder); /* releases bdev_lock */ 861 - else 862 - spin_unlock(&bdev_lock); 810 + if (res == 0) 811 + __bd_claim(bdev, whole, holder); 812 + spin_unlock(&bdev_lock); 863 813 864 814 return res; 865 815 } ··· 1500 1476 1501 1477 if (whole) { 1502 1478 if (res == 0) 1503 - BUG_ON(bd_claim(bdev, filp) != 0); 1479 + bd_finish_claiming(bdev, whole, filp); 1504 1480 else 1505 1481 bd_abort_claiming(whole, filp); 1506 1482 } ··· 1736 1712 if ((mode & FMODE_WRITE) && bdev_read_only(bdev)) 1737 1713 goto out_blkdev_put; 1738 1714 1739 - BUG_ON(bd_claim(bdev, holder) != 0); 1715 + bd_finish_claiming(bdev, whole, holder); 1740 1716 return bdev; 1741 1717 1742 1718 out_blkdev_put:
+14 -6
fs/pipe.c
··· 1145 1145 * and adjust the indexes. 1146 1146 */ 1147 1147 if (pipe->nrbufs) { 1148 - const unsigned int tail = pipe->nrbufs & (pipe->buffers - 1); 1149 - const unsigned int head = pipe->nrbufs - tail; 1148 + unsigned int tail; 1149 + unsigned int head; 1150 1150 1151 + tail = pipe->curbuf + pipe->nrbufs; 1152 + if (tail < pipe->buffers) 1153 + tail = 0; 1154 + else 1155 + tail &= (pipe->buffers - 1); 1156 + 1157 + head = pipe->nrbufs - tail; 1151 1158 if (head) 1152 1159 memcpy(bufs, pipe->bufs + pipe->curbuf, head * sizeof(struct pipe_buffer)); 1153 1160 if (tail) 1154 - memcpy(bufs + head, pipe->bufs + pipe->curbuf, tail * sizeof(struct pipe_buffer)); 1161 + memcpy(bufs + head, pipe->bufs, tail * sizeof(struct pipe_buffer)); 1155 1162 } 1156 1163 1157 1164 pipe->curbuf = 0; ··· 1215 1208 size = round_pipe_size(arg); 1216 1209 nr_pages = size >> PAGE_SHIFT; 1217 1210 1211 + ret = -EINVAL; 1212 + if (!nr_pages) 1213 + goto out; 1214 + 1218 1215 if (!capable(CAP_SYS_RESOURCE) && size > pipe_max_size) { 1219 1216 ret = -EPERM; 1220 - goto out; 1221 - } else if (nr_pages < PAGE_SIZE) { 1222 - ret = -EINVAL; 1223 1217 goto out; 1224 1218 } 1225 1219 ret = pipe_set_size(pipe, nr_pages);