Skip to content

Commit

Permalink
dm bio prison: introduce support for locking ranges of blocks
Browse files Browse the repository at this point in the history
Ranges will be placed in the same cell if they overlap.

Range locking is a prerequisite for more efficient multi-block discard
support in both the cache and thin-provisioning targets.

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
Joe Thornber authored and Mike Snitzer committed Nov 10, 2014
1 parent f1afb36 commit 5f274d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions drivers/md/dm-bio-prison.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ static int cmp_keys(struct dm_cell_key *lhs,
if (lhs->dev > rhs->dev)
return 1;

if (lhs->block < rhs->block)
if (lhs->block_end <= rhs->block_begin)
return -1;

if (lhs->block > rhs->block)
if (lhs->block_begin >= rhs->block_end)
return 1;

return 0;
Expand Down
12 changes: 8 additions & 4 deletions drivers/md/dm-bio-prison.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
*/
struct dm_bio_prison;

/* FIXME: this needs to be more abstract */
/*
* Keys define a range of blocks within either a virtual or physical
* device.
*/
struct dm_cell_key {
int virtual;
dm_thin_id dev;
dm_block_t block;
dm_block_t block_begin, block_end;
};

/*
Expand Down Expand Up @@ -59,7 +62,7 @@ void dm_bio_prison_free_cell(struct dm_bio_prison *prison,
struct dm_bio_prison_cell *cell);

/*
* Creates, or retrieves a cell for the given key.
* Creates, or retrieves a cell that overlaps the given key.
*
* Returns 1 if pre-existing cell returned, zero if new cell created using
* @cell_prealloc.
Expand All @@ -70,7 +73,8 @@ int dm_get_cell(struct dm_bio_prison *prison,
struct dm_bio_prison_cell **cell_result);

/*
* An atomic op that combines retrieving a cell, and adding a bio to it.
* An atomic op that combines retrieving or creating a cell, and adding a
* bio to it.
*
* Returns 1 if the cell was already held, 0 if @inmate is the new holder.
*/
Expand Down
3 changes: 2 additions & 1 deletion drivers/md/dm-cache-target.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ static void build_key(dm_oblock_t oblock, struct dm_cell_key *key)
{
key->virtual = 0;
key->dev = 0;
key->block = from_oblock(oblock);
key->block_begin = from_oblock(oblock);
key->block_end = key->block_begin + 1ULL;
}

/*
Expand Down
6 changes: 4 additions & 2 deletions drivers/md/dm-thin.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,17 @@ static void build_data_key(struct dm_thin_device *td,
{
key->virtual = 0;
key->dev = dm_thin_dev_id(td);
key->block = b;
key->block_begin = b;
key->block_end = b + 1ULL;
}

static void build_virtual_key(struct dm_thin_device *td, dm_block_t b,
struct dm_cell_key *key)
{
key->virtual = 1;
key->dev = dm_thin_dev_id(td);
key->block = b;
key->block_begin = b;
key->block_end = b + 1ULL;
}

/*----------------------------------------------------------------*/
Expand Down

0 comments on commit 5f274d8

Please sign in to comment.