Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Device-mapper Development (http://www.linux-archive.org/device-mapper-development/)
-   -   Fix a race between reading a new block and having it recycled. (http://www.linux-archive.org/device-mapper-development/559814-fix-race-between-reading-new-block-having-recycled.html)

Joe Thornber 08-02-2011 02:36 PM

Fix a race between reading a new block and having it recycled.
 
---
drivers/md/persistent-data/dm-block-manager.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/drivers/md/persistent-data/dm-block-manager.c b/drivers/md/persistent-data/dm-block-manager.c
index c9fb132..b68be88 100644
--- a/drivers/md/persistent-data/dm-block-manager.c
+++ b/drivers/md/persistent-data/dm-block-manager.c
@@ -447,6 +447,7 @@ static int recycle_block(struct dm_block_manager *bm, dm_block_t where,
* Wait for a block to appear on the empty or clean lists.
*/
spin_lock_irqsave(&bm->lock, flags);
+retry:
while (1) {
/*
* Once we can lock and do io concurrently then we should
@@ -486,7 +487,11 @@ static int recycle_block(struct dm_block_manager *bm, dm_block_t where,
spin_lock_irqsave(&bm->lock, flags);
__wait_io(b, &flags);

- /* FIXME: Can b have been recycled between io completion and here? */
+ /*
+ * Has b been recycled whilst we were unlocked?
+ */
+ if (b->where != where)
+ goto retry;

/*
* Did the io succeed?
--
1.7.4.1

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel


All times are GMT. The time now is 03:17 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.