aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2012-07-27 10:08:08 -0400
committerAlasdair G Kergon <agk@redhat.com>2012-07-27 10:08:08 -0400
commit51a0f659c03ccc8ec407c7a9f9701d1b4618d515 (patch)
tree21b05e433e1f513079e51d3ccec1da6b1ea1008f /drivers
parent41675aea32949786cf002c4ab179b85144d3423b (diff)
dm persistent data: create new dm_block_manager struct
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/md/dm-thin-metadata.c6
-rw-r--r--drivers/md/persistent-data/dm-block-manager.c58
2 files changed, 41 insertions, 23 deletions
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index 82b82c318f14..afd84cacca4b 100644
--- a/drivers/md/dm-thin-metadata.c
+++ b/drivers/md/dm-thin-metadata.c
@@ -681,10 +681,11 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
681 bm = dm_block_manager_create(bdev, THIN_METADATA_BLOCK_SIZE, 681 bm = dm_block_manager_create(bdev, THIN_METADATA_BLOCK_SIZE,
682 THIN_METADATA_CACHE_SIZE, 682 THIN_METADATA_CACHE_SIZE,
683 THIN_MAX_CONCURRENT_LOCKS); 683 THIN_MAX_CONCURRENT_LOCKS);
684 if (!bm) { 684 if (IS_ERR(bm)) {
685 r = PTR_ERR(bm);
685 DMERR("could not create block manager"); 686 DMERR("could not create block manager");
686 kfree(pmd); 687 kfree(pmd);
687 return ERR_PTR(-ENOMEM); 688 return ERR_PTR(r);
688 } 689 }
689 690
690 r = superblock_all_zeroes(bm, &create); 691 r = superblock_all_zeroes(bm, &create);
@@ -694,7 +695,6 @@ struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
694 return ERR_PTR(r); 695 return ERR_PTR(r);
695 } 696 }
696 697
697
698 r = init_pmd(pmd, bm, 0, create); 698 r = init_pmd(pmd, bm, 0, create);
699 if (r) { 699 if (r) {
700 dm_block_manager_destroy(bm); 700 dm_block_manager_destroy(bm);
diff --git a/drivers/md/persistent-data/dm-block-manager.c b/drivers/md/persistent-data/dm-block-manager.c
index 8ec46dd511f9..c70ad6e303d3 100644
--- a/drivers/md/persistent-data/dm-block-manager.c
+++ b/drivers/md/persistent-data/dm-block-manager.c
@@ -325,11 +325,6 @@ static struct dm_buffer *to_buffer(struct dm_block *b)
325 return (struct dm_buffer *) b; 325 return (struct dm_buffer *) b;
326} 326}
327 327
328static struct dm_bufio_client *to_bufio(struct dm_block_manager *bm)
329{
330 return (struct dm_bufio_client *) bm;
331}
332
333dm_block_t dm_block_location(struct dm_block *b) 328dm_block_t dm_block_location(struct dm_block *b)
334{ 329{
335 return dm_bufio_get_block_number(to_buffer(b)); 330 return dm_bufio_get_block_number(to_buffer(b));
@@ -367,34 +362,57 @@ static void dm_block_manager_write_callback(struct dm_buffer *buf)
367/*---------------------------------------------------------------- 362/*----------------------------------------------------------------
368 * Public interface 363 * Public interface
369 *--------------------------------------------------------------*/ 364 *--------------------------------------------------------------*/
365struct dm_block_manager {
366 struct dm_bufio_client *bufio;
367};
368
370struct dm_block_manager *dm_block_manager_create(struct block_device *bdev, 369struct dm_block_manager *dm_block_manager_create(struct block_device *bdev,
371 unsigned block_size, 370 unsigned block_size,
372 unsigned cache_size, 371 unsigned cache_size,
373 unsigned max_held_per_thread) 372 unsigned max_held_per_thread)
374{ 373{
375 return (struct dm_block_manager *) 374 int r;
376 dm_bufio_client_create(bdev, block_size, max_held_per_thread, 375 struct dm_block_manager *bm;
377 sizeof(struct buffer_aux), 376
378 dm_block_manager_alloc_callback, 377 bm = kmalloc(sizeof(*bm), GFP_KERNEL);
379 dm_block_manager_write_callback); 378 if (!bm) {
379 r = -ENOMEM;
380 goto bad;
381 }
382
383 bm->bufio = dm_bufio_client_create(bdev, block_size, max_held_per_thread,
384 sizeof(struct buffer_aux),
385 dm_block_manager_alloc_callback,
386 dm_block_manager_write_callback);
387 if (IS_ERR(bm->bufio)) {
388 r = PTR_ERR(bm->bufio);
389 kfree(bm);
390 goto bad;
391 }
392
393 return bm;
394
395bad:
396 return ERR_PTR(r);
380} 397}
381EXPORT_SYMBOL_GPL(dm_block_manager_create); 398EXPORT_SYMBOL_GPL(dm_block_manager_create);
382 399
383void dm_block_manager_destroy(struct dm_block_manager *bm) 400void dm_block_manager_destroy(struct dm_block_manager *bm)
384{ 401{
385 return dm_bufio_client_destroy(to_bufio(bm)); 402 dm_bufio_client_destroy(bm->bufio);
403 kfree(bm);
386} 404}
387EXPORT_SYMBOL_GPL(dm_block_manager_destroy); 405EXPORT_SYMBOL_GPL(dm_block_manager_destroy);
388 406
389unsigned dm_bm_block_size(struct dm_block_manager *bm) 407unsigned dm_bm_block_size(struct dm_block_manager *bm)
390{ 408{
391 return dm_bufio_get_block_size(to_bufio(bm)); 409 return dm_bufio_get_block_size(bm->bufio);
392} 410}
393EXPORT_SYMBOL_GPL(dm_bm_block_size); 411EXPORT_SYMBOL_GPL(dm_bm_block_size);
394 412
395dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm) 413dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm)
396{ 414{
397 return dm_bufio_get_device_size(to_bufio(bm)); 415 return dm_bufio_get_device_size(bm->bufio);
398} 416}
399 417
400static int dm_bm_validate_buffer(struct dm_block_manager *bm, 418static int dm_bm_validate_buffer(struct dm_block_manager *bm,
@@ -406,7 +424,7 @@ static int dm_bm_validate_buffer(struct dm_block_manager *bm,
406 int r; 424 int r;
407 if (!v) 425 if (!v)
408 return 0; 426 return 0;
409 r = v->check(v, (struct dm_block *) buf, dm_bufio_get_block_size(to_bufio(bm))); 427 r = v->check(v, (struct dm_block *) buf, dm_bufio_get_block_size(bm->bufio));
410 if (unlikely(r)) 428 if (unlikely(r))
411 return r; 429 return r;
412 aux->validator = v; 430 aux->validator = v;
@@ -430,7 +448,7 @@ int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
430 void *p; 448 void *p;
431 int r; 449 int r;
432 450
433 p = dm_bufio_read(to_bufio(bm), b, (struct dm_buffer **) result); 451 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
434 if (unlikely(IS_ERR(p))) 452 if (unlikely(IS_ERR(p)))
435 return PTR_ERR(p); 453 return PTR_ERR(p);
436 454
@@ -463,7 +481,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm,
463 void *p; 481 void *p;
464 int r; 482 int r;
465 483
466 p = dm_bufio_read(to_bufio(bm), b, (struct dm_buffer **) result); 484 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
467 if (unlikely(IS_ERR(p))) 485 if (unlikely(IS_ERR(p)))
468 return PTR_ERR(p); 486 return PTR_ERR(p);
469 487
@@ -496,7 +514,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm,
496 void *p; 514 void *p;
497 int r; 515 int r;
498 516
499 p = dm_bufio_get(to_bufio(bm), b, (struct dm_buffer **) result); 517 p = dm_bufio_get(bm->bufio, b, (struct dm_buffer **) result);
500 if (unlikely(IS_ERR(p))) 518 if (unlikely(IS_ERR(p)))
501 return PTR_ERR(p); 519 return PTR_ERR(p);
502 if (unlikely(!p)) 520 if (unlikely(!p))
@@ -529,7 +547,7 @@ int dm_bm_write_lock_zero(struct dm_block_manager *bm,
529 struct buffer_aux *aux; 547 struct buffer_aux *aux;
530 void *p; 548 void *p;
531 549
532 p = dm_bufio_new(to_bufio(bm), b, (struct dm_buffer **) result); 550 p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result);
533 if (unlikely(IS_ERR(p))) 551 if (unlikely(IS_ERR(p)))
534 return PTR_ERR(p); 552 return PTR_ERR(p);
535 553
@@ -586,7 +604,7 @@ int dm_bm_flush_and_unlock(struct dm_block_manager *bm,
586{ 604{
587 int r; 605 int r;
588 606
589 r = dm_bufio_write_dirty_buffers(to_bufio(bm)); 607 r = dm_bufio_write_dirty_buffers(bm->bufio);
590 if (unlikely(r)) { 608 if (unlikely(r)) {
591 dm_bm_unlock(superblock); 609 dm_bm_unlock(superblock);
592 return r; 610 return r;
@@ -594,7 +612,7 @@ int dm_bm_flush_and_unlock(struct dm_block_manager *bm,
594 612
595 dm_bm_unlock(superblock); 613 dm_bm_unlock(superblock);
596 614
597 return dm_bufio_write_dirty_buffers(to_bufio(bm)); 615 return dm_bufio_write_dirty_buffers(bm->bufio);
598} 616}
599 617
600u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor) 618u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor)