Skip to content

Commit

Permalink
dm persistent data: create new dm_block_manager struct
Browse files Browse the repository at this point in the history
This patch introduces a separate struct for the block_manager.
It also uses IS_ERR to check the return value of dm_bufio_client_create
instead of testing incorrectly for NULL.

Prior to this patch a struct dm_block_manager was really an alias for
a struct dm_bufio_client.  We want to add some functionality to the
block manager that will require extra fields, so this one to one
mapping is no longer valid.

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
  • Loading branch information
Joe Thornber authored and Alasdair G Kergon committed Jul 27, 2012
1 parent 41675ae commit 51a0f65
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
6 changes: 3 additions & 3 deletions drivers/md/dm-thin-metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,11 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
bm = dm_block_manager_create(bdev, THIN_METADATA_BLOCK_SIZE,
THIN_METADATA_CACHE_SIZE,
THIN_MAX_CONCURRENT_LOCKS);
if (!bm) {
if (IS_ERR(bm)) {
r = PTR_ERR(bm);
DMERR("could not create block manager");
kfree(pmd);
return ERR_PTR(-ENOMEM);
return ERR_PTR(r);
}

r = superblock_all_zeroes(bm, &create);
Expand All @@ -694,7 +695,6 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
return ERR_PTR(r);
}


r = init_pmd(pmd, bm, 0, create);
if (r) {
dm_block_manager_destroy(bm);
Expand Down
58 changes: 38 additions & 20 deletions drivers/md/persistent-data/dm-block-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,6 @@ static struct dm_buffer *to_buffer(struct dm_block *b)
return (struct dm_buffer *) b;
}

static struct dm_bufio_client *to_bufio(struct dm_block_manager *bm)
{
return (struct dm_bufio_client *) bm;
}

dm_block_t dm_block_location(struct dm_block *b)
{
return dm_bufio_get_block_number(to_buffer(b));
Expand Down Expand Up @@ -367,34 +362,57 @@ static void dm_block_manager_write_callback(struct dm_buffer *buf)
/*----------------------------------------------------------------
* Public interface
*--------------------------------------------------------------*/
struct dm_block_manager {
struct dm_bufio_client *bufio;
};

struct dm_block_manager *dm_block_manager_create(struct block_device *bdev,
unsigned block_size,
unsigned cache_size,
unsigned max_held_per_thread)
{
return (struct dm_block_manager *)
dm_bufio_client_create(bdev, block_size, max_held_per_thread,
sizeof(struct buffer_aux),
dm_block_manager_alloc_callback,
dm_block_manager_write_callback);
int r;
struct dm_block_manager *bm;

bm = kmalloc(sizeof(*bm), GFP_KERNEL);
if (!bm) {
r = -ENOMEM;
goto bad;
}

bm->bufio = dm_bufio_client_create(bdev, block_size, max_held_per_thread,
sizeof(struct buffer_aux),
dm_block_manager_alloc_callback,
dm_block_manager_write_callback);
if (IS_ERR(bm->bufio)) {
r = PTR_ERR(bm->bufio);
kfree(bm);
goto bad;
}

return bm;

bad:
return ERR_PTR(r);
}
EXPORT_SYMBOL_GPL(dm_block_manager_create);

void dm_block_manager_destroy(struct dm_block_manager *bm)
{
return dm_bufio_client_destroy(to_bufio(bm));
dm_bufio_client_destroy(bm->bufio);
kfree(bm);
}
EXPORT_SYMBOL_GPL(dm_block_manager_destroy);

unsigned dm_bm_block_size(struct dm_block_manager *bm)
{
return dm_bufio_get_block_size(to_bufio(bm));
return dm_bufio_get_block_size(bm->bufio);
}
EXPORT_SYMBOL_GPL(dm_bm_block_size);

dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm)
{
return dm_bufio_get_device_size(to_bufio(bm));
return dm_bufio_get_device_size(bm->bufio);
}

static int dm_bm_validate_buffer(struct dm_block_manager *bm,
Expand All @@ -406,7 +424,7 @@ static int dm_bm_validate_buffer(struct dm_block_manager *bm,
int r;
if (!v)
return 0;
r = v->check(v, (struct dm_block *) buf, dm_bufio_get_block_size(to_bufio(bm)));
r = v->check(v, (struct dm_block *) buf, dm_bufio_get_block_size(bm->bufio));
if (unlikely(r))
return r;
aux->validator = v;
Expand All @@ -430,7 +448,7 @@ int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
void *p;
int r;

p = dm_bufio_read(to_bufio(bm), b, (struct dm_buffer **) result);
p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p)))
return PTR_ERR(p);

Expand Down Expand Up @@ -463,7 +481,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm,
void *p;
int r;

p = dm_bufio_read(to_bufio(bm), b, (struct dm_buffer **) result);
p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p)))
return PTR_ERR(p);

Expand Down Expand Up @@ -496,7 +514,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm,
void *p;
int r;

p = dm_bufio_get(to_bufio(bm), b, (struct dm_buffer **) result);
p = dm_bufio_get(bm->bufio, b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p)))
return PTR_ERR(p);
if (unlikely(!p))
Expand Down Expand Up @@ -529,7 +547,7 @@ int dm_bm_write_lock_zero(struct dm_block_manager *bm,
struct buffer_aux *aux;
void *p;

p = dm_bufio_new(to_bufio(bm), b, (struct dm_buffer **) result);
p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p)))
return PTR_ERR(p);

Expand Down Expand Up @@ -586,15 +604,15 @@ int dm_bm_flush_and_unlock(struct dm_block_manager *bm,
{
int r;

r = dm_bufio_write_dirty_buffers(to_bufio(bm));
r = dm_bufio_write_dirty_buffers(bm->bufio);
if (unlikely(r)) {
dm_bm_unlock(superblock);
return r;
}

dm_bm_unlock(superblock);

return dm_bufio_write_dirty_buffers(to_bufio(bm));
return dm_bufio_write_dirty_buffers(bm->bufio);
}

u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor)
Expand Down

0 comments on commit 51a0f65

Please sign in to comment.