* [patch] block: bd_start_claiming fix module refcount
@ 2010-05-25 15:50 Nick Piggin
2010-05-25 15:51 ` [patch] block: bd_start_claiming cleanup Nick Piggin
2010-05-25 17:03 ` [patch] block: bd_start_claiming fix module refcount Tejun Heo
0 siblings, 2 replies; 4+ messages in thread
From: Nick Piggin @ 2010-05-25 15:50 UTC (permalink / raw)
To: linux-fsdevel, Tejun Heo, Jens Axboe, Andrew Morton
bd_start_claiming has an unbalanced module_put introduced in 6b4517a79.
Signed-off-by: Nick Piggin <npiggin@suse.de>
---
Index: linux-2.6/fs/block_dev.c
===================================================================
--- linux-2.6.orig/fs/block_dev.c
+++ linux-2.6/fs/block_dev.c
@@ -738,6 +738,7 @@ static struct block_device *bd_start_cla
return ERR_PTR(-ENXIO);
whole = bdget_disk(disk, 0);
+ module_put(disk->fops->owner);
put_disk(disk);
if (!whole)
return ERR_PTR(-ENOMEM);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [patch] block: bd_start_claiming cleanup
2010-05-25 15:50 [patch] block: bd_start_claiming fix module refcount Nick Piggin
@ 2010-05-25 15:51 ` Nick Piggin
2010-05-25 17:30 ` Tejun Heo
2010-05-25 17:03 ` [patch] block: bd_start_claiming fix module refcount Tejun Heo
1 sibling, 1 reply; 4+ messages in thread
From: Nick Piggin @ 2010-05-25 15:51 UTC (permalink / raw)
To: linux-fsdevel, Tejun Heo, Jens Axboe, Andrew Morton
I don't like the subtle multi-context code in bd_claim (ie. detects where it
has been called based on bd_claiming). It seems clearer to just require a new
function to finish a 2-part claim.
Also improve commentary in bd_start_claiming as to how it should
be used.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Index: linux-2.6/fs/block_dev.c
===================================================================
--- linux-2.6.orig/fs/block_dev.c
+++ linux-2.6/fs/block_dev.c
@@ -710,8 +710,13 @@ retry:
* @bdev is about to be opened exclusively. Check @bdev can be opened
* exclusively and mark that an exclusive open is in progress. Each
* successful call to this function must be matched with a call to
- * either bd_claim() or bd_abort_claiming(). If this function
- * succeeds, the matching bd_claim() is guaranteed to succeed.
+ * either bd_finish_claiming() or bd_abort_claiming() (which do not
+ * fail).
+ *
+ * This function is used to gain exclusive access to the block device
+ * without actually causing other exclusive open attempts to fail. It
+ * should be used when the open sequence itself requires exclusive
+ * access but may subsequently fail.
*
* CONTEXT:
* Might sleep.
@@ -787,15 +792,47 @@ static void bd_abort_claiming(struct blo
__bd_abort_claiming(whole, holder); /* releases bdev_lock */
}
+/* increment holders when we have a legitimate claim. requires bdev_lock */
+static void __bd_claim(struct block_device *bdev, struct block_device *whole,
+ void *holder)
+{
+ /* note that for a whole device bd_holders
+ * will be incremented twice, and bd_holder will
+ * be set to bd_claim before being set to holder
+ */
+ whole->bd_holders++;
+ whole->bd_holder = bd_claim;
+ bdev->bd_holders++;
+ bdev->bd_holder = holder;
+}
+
+/**
+ * bd_finish_claiming - finish claiming a block device
+ * @bdev: block device of interest (passed to bd_start_claiming())
+ * @whole: whole block device returned by bd_start_claiming()
+ * @holder: holder trying to claim @bdev
+ *
+ * Finish a claiming block started by bd_start_claiming().
+ *
+ * CONTEXT:
+ * Grabs and releases bdev_lock.
+ */
+static void bd_finish_claiming(struct block_device *bdev,
+ struct block_device *whole, void *holder)
+{
+ spin_lock(&bdev_lock);
+ BUG_ON(whole->bd_claiming != holder);
+ BUG_ON(!bd_may_claim(bdev, whole, holder));
+ __bd_claim(bdev, whole, holder);
+ __bd_abort_claiming(whole, holder); /* not actually an abort */
+}
+
/**
* bd_claim - claim a block device
* @bdev: block device to claim
* @holder: holder trying to claim @bdev
*
- * Try to claim @bdev which must have been opened successfully. This
- * function may be called with or without preceding
- * blk_start_claiming(). In the former case, this function is always
- * successful and terminates the claiming block.
+ * Try to claim @bdev which must have been opened successfully.
*
* CONTEXT:
* Might sleep.
@@ -811,23 +848,10 @@ int bd_claim(struct block_device *bdev,
might_sleep();
spin_lock(&bdev_lock);
-
res = bd_prepare_to_claim(bdev, whole, holder);
- if (res == 0) {
- /* note that for a whole device bd_holders
- * will be incremented twice, and bd_holder will
- * be set to bd_claim before being set to holder
- */
- whole->bd_holders++;
- whole->bd_holder = bd_claim;
- bdev->bd_holders++;
- bdev->bd_holder = holder;
- }
-
- if (whole->bd_claiming)
- __bd_abort_claiming(whole, holder); /* releases bdev_lock */
- else
- spin_unlock(&bdev_lock);
+ if (res == 0)
+ __bd_claim(bdev, whole, holder);
+ spin_unlock(&bdev_lock);
return res;
}
@@ -1481,7 +1505,7 @@ static int blkdev_open(struct inode * in
if (whole) {
if (res == 0)
- BUG_ON(bd_claim(bdev, filp) != 0);
+ bd_finish_claiming(bdev, whole, filp);
else
bd_abort_claiming(whole, filp);
}
@@ -1717,7 +1741,7 @@ struct block_device *open_bdev_exclusive
if ((mode & FMODE_WRITE) && bdev_read_only(bdev))
goto out_blkdev_put;
- BUG_ON(bd_claim(bdev, holder) != 0);
+ bd_finish_claiming(bdev, whole, holder);
return bdev;
out_blkdev_put:
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] block: bd_start_claiming fix module refcount
2010-05-25 15:50 [patch] block: bd_start_claiming fix module refcount Nick Piggin
2010-05-25 15:51 ` [patch] block: bd_start_claiming cleanup Nick Piggin
@ 2010-05-25 17:03 ` Tejun Heo
1 sibling, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2010-05-25 17:03 UTC (permalink / raw)
To: Nick Piggin; +Cc: linux-fsdevel, Jens Axboe, Andrew Morton
Hello,
On 05/25/2010 05:50 PM, Nick Piggin wrote:
>
> bd_start_claiming has an unbalanced module_put introduced in 6b4517a79.
>
> Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Tejun Heo <tj@kernel.org>
I think it might be a good idea to rename get_disk().
get_disk/put_disk() pair is somewhat deceptive.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] block: bd_start_claiming cleanup
2010-05-25 15:51 ` [patch] block: bd_start_claiming cleanup Nick Piggin
@ 2010-05-25 17:30 ` Tejun Heo
0 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2010-05-25 17:30 UTC (permalink / raw)
To: Nick Piggin; +Cc: linux-fsdevel, Jens Axboe, Andrew Morton
Hello, Nick.
On 05/25/2010 05:51 PM, Nick Piggin wrote:
> I don't like the subtle multi-context code in bd_claim (ie. detects where it
> has been called based on bd_claiming). It seems clearer to just require a new
> function to finish a 2-part claim.
Oh yeah, that looks much better. What was I thinking? :-)
> Also improve commentary in bd_start_claiming as to how it should
> be used.
>
> Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Tejun Heo <tj@kernel.org>
but one small nit.
> +static void bd_finish_claiming(struct block_device *bdev,
> + struct block_device *whole, void *holder)
> +{
> + spin_lock(&bdev_lock);
> + BUG_ON(whole->bd_claiming != holder);
The above test is already done in __bd_abort_claiming().
> + BUG_ON(!bd_may_claim(bdev, whole, holder));
> + __bd_claim(bdev, whole, holder);
> + __bd_abort_claiming(whole, holder); /* not actually an abort */
> +}
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-05-25 17:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-25 15:50 [patch] block: bd_start_claiming fix module refcount Nick Piggin
2010-05-25 15:51 ` [patch] block: bd_start_claiming cleanup Nick Piggin
2010-05-25 17:30 ` Tejun Heo
2010-05-25 17:03 ` [patch] block: bd_start_claiming fix module refcount Tejun Heo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.