public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: use the passed in @bdev when claiming if partno is zero
@ 2011-06-13 10:44 Tejun Heo
  2011-06-13 12:44 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Tejun Heo @ 2011-06-13 10:44 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, stable, avillaci

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
---
 fs/block_dev.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 1a2421f..610e8e0 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -762,7 +762,19 @@ static struct block_device *bd_start_claiming(struct block_device *bdev,
 	if (!disk)
 		return ERR_PTR(-ENXIO);
 
-	whole = bdget_disk(disk, 0);
+	/*
+	 * Normally, @bdev should equal what's returned from bdget_disk()
+	 * if partno is 0; however, some drivers (floppy) use multiple
+	 * bdev's for the same physical device and @bdev may be one of the
+	 * aliases.  Keep @bdev if partno is 0.  This means claimer
+	 * tracking is broken for those devices but it has always been that
+	 * way.
+	 */
+	if (partno)
+		whole = bdget_disk(disk, 0);
+	else
+		whole = bdgrab(bdev);
+
 	module_put(disk->fops->owner);
 	put_disk(disk);
 	if (!whole)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] block: use the passed in @bdev when claiming if partno is  zero
  2011-06-13 10:44 [PATCH] block: use the passed in @bdev when claiming if partno is zero Tejun Heo
@ 2011-06-13 12:44 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2011-06-13 12:44 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-kernel, stable, avillaci

On 2011-06-13 12:44, Tejun Heo wrote:
> 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.

Thanks, applied for 3.0.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-13 12:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-13 10:44 [PATCH] block: use the passed in @bdev when claiming if partno is zero Tejun Heo
2011-06-13 12:44 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox