Commit d4c208b86b8be4254eba0e74071496e599f94639
Committed by
Jens Axboe
1 parent
08e8138ade
Exists in
master
and in
7 other branches
block: use the passed in @bdev when claiming if partno is zero
6b4517a791 (block: implement bd_claiming and claiming block) introduced claiming block to support O_EXCL blkdev opens properly. bd_start_claiming() looks up the part 0 bdev and starts claiming block. The function assumed that there is only one part 0 bdev and always used bdget_disk(disk, 0) to look it up; unfortunately, this isn't true for some drivers (floppy) which use multiple block devices to denote different operating parameters for the same physical device. There can be multiple part 0 bdev's for the same device number. This incorrect assumption caused the wrong bdev to be used during claiming leading to unbalanced bd_holders as reported in the following bug. https://bugzilla.kernel.org/show_bug.cgi?id=28522 This patch updates bd_start_claiming() such that it uses the bdev specified as argument if its partno is zero. Note that this means that different bdev's can be used for the same device and O_EXCL check can be effectively bypassed. It has always been broken that way and floppy is fortunately on its way out. Leave that breakage alone. Signed-off-by: Tejun Heo <tj@kernel.org> Reported-by: Alex Villacis Lasso <avillaci@ceibo.fiec.espol.edu.ec> Tested-by: Alex Villacis Lasso <avillaci@ceibo.fiec.espol.edu.ec> Cc: stable@kernel.org # >= v2.6.36 Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Showing 1 changed file with 13 additions and 1 deletions Side-by-side Diff
fs/block_dev.c
... | ... | @@ -762,7 +762,19 @@ |
762 | 762 | if (!disk) |
763 | 763 | return ERR_PTR(-ENXIO); |
764 | 764 | |
765 | - whole = bdget_disk(disk, 0); | |
765 | + /* | |
766 | + * Normally, @bdev should equal what's returned from bdget_disk() | |
767 | + * if partno is 0; however, some drivers (floppy) use multiple | |
768 | + * bdev's for the same physical device and @bdev may be one of the | |
769 | + * aliases. Keep @bdev if partno is 0. This means claimer | |
770 | + * tracking is broken for those devices but it has always been that | |
771 | + * way. | |
772 | + */ | |
773 | + if (partno) | |
774 | + whole = bdget_disk(disk, 0); | |
775 | + else | |
776 | + whole = bdgrab(bdev); | |
777 | + | |
766 | 778 | module_put(disk->fops->owner); |
767 | 779 | put_disk(disk); |
768 | 780 | if (!whole) |