summaryrefslogtreecommitdiff
path: root/drivers/md/dm-bio-prison.c
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2015-05-15 17:23:35 +0300
committerMike Snitzer <snitzer@redhat.com>2015-05-29 21:19:06 +0300
commit3cdf93f9d85979b22b6abfd4ab19350860e4dfac (patch)
tree4e77c76a3def3bb6aac401047ee7e8566642026a /drivers/md/dm-bio-prison.c
parent451b9e0071b2833744db7f518115bc085bc7b23c (diff)
downloadlinux-3cdf93f9d85979b22b6abfd4ab19350860e4dfac.tar.xz
dm bio prison: add dm_cell_promote_or_release()
Rather than always releasing the prisoners in a cell, the client may want to promote one of them to be the new holder. There is a race here though between releasing an empty cell, and other threads adding new inmates. So this function makes the decision with its lock held. This function can have two outcomes: i) An inmate is promoted to be the holder of the cell (return value of 0). ii) The cell has no inmate for promotion and is released (return value of 1). Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md/dm-bio-prison.c')
-rw-r--r--drivers/md/dm-bio-prison.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/md/dm-bio-prison.c b/drivers/md/dm-bio-prison.c
index be065300e93c..cd6d1d21e057 100644
--- a/drivers/md/dm-bio-prison.c
+++ b/drivers/md/dm-bio-prison.c
@@ -255,6 +255,32 @@ void dm_cell_visit_release(struct dm_bio_prison *prison,
}
EXPORT_SYMBOL_GPL(dm_cell_visit_release);
+static int __promote_or_release(struct dm_bio_prison *prison,
+ struct dm_bio_prison_cell *cell)
+{
+ if (bio_list_empty(&cell->bios)) {
+ rb_erase(&cell->node, &prison->cells);
+ return 1;
+ }
+
+ cell->holder = bio_list_pop(&cell->bios);
+ return 0;
+}
+
+int dm_cell_promote_or_release(struct dm_bio_prison *prison,
+ struct dm_bio_prison_cell *cell)
+{
+ int r;
+ unsigned long flags;
+
+ spin_lock_irqsave(&prison->lock, flags);
+ r = __promote_or_release(prison, cell);
+ spin_unlock_irqrestore(&prison->lock, flags);
+
+ return r;
+}
+EXPORT_SYMBOL_GPL(dm_cell_promote_or_release);
+
/*----------------------------------------------------------------*/
#define DEFERRED_SET_SIZE 64