diff options
author | Joe Thornber <ejt@redhat.com> | 2012-07-27 10:08:12 -0400 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2012-07-27 10:08:12 -0400 |
commit | e4d2205cdf2094eb9f7246a4474f8df63806c1d3 (patch) | |
tree | b7e202a32d0ae8ee19d55dc895d3009345addd3e /drivers/md | |
parent | d6332814e343c76097ff10ed8225069e6392022f (diff) |
dm thin metadata: split __open or format metadata
Split __open_or_format_metadata into __format_metadata and __open_metadata in
dm-thin-metadata.
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/md')
-rw-r--r-- | drivers/md/dm-thin-metadata.c | 124 |
1 files changed, 74 insertions, 50 deletions
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c index dceec441ef30..31d21bfc8cb4 100644 --- a/drivers/md/dm-thin-metadata.c +++ b/drivers/md/dm-thin-metadata.c | |||
@@ -485,57 +485,22 @@ bad_locked: | |||
485 | return r; | 485 | return r; |
486 | } | 486 | } |
487 | 487 | ||
488 | static int __open_or_format_metadata(struct dm_pool_metadata *pmd, | 488 | static int __format_metadata(struct dm_pool_metadata *pmd, dm_block_t nr_blocks) |
489 | dm_block_t nr_blocks, int create) | ||
490 | { | 489 | { |
491 | int r; | 490 | int r; |
492 | struct dm_block *sblock; | ||
493 | 491 | ||
494 | if (create) { | 492 | r = dm_tm_create_with_sm(pmd->bm, THIN_SUPERBLOCK_LOCATION, |
495 | r = dm_tm_create_with_sm(pmd->bm, THIN_SUPERBLOCK_LOCATION, | 493 | &pmd->tm, &pmd->metadata_sm); |
496 | &pmd->tm, &pmd->metadata_sm); | 494 | if (r < 0) { |
497 | if (r < 0) { | 495 | DMERR("tm_create_with_sm failed"); |
498 | DMERR("tm_create_with_sm failed"); | 496 | return r; |
499 | return r; | 497 | } |
500 | } | ||
501 | |||
502 | pmd->data_sm = dm_sm_disk_create(pmd->tm, nr_blocks); | ||
503 | if (IS_ERR(pmd->data_sm)) { | ||
504 | DMERR("sm_disk_create failed"); | ||
505 | r = PTR_ERR(pmd->data_sm); | ||
506 | goto bad; | ||
507 | } | ||
508 | } else { | ||
509 | struct thin_disk_superblock *disk_super; | ||
510 | |||
511 | r = dm_bm_read_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, | ||
512 | &sb_validator, &sblock); | ||
513 | if (r < 0) { | ||
514 | DMERR("couldn't read superblock"); | ||
515 | return r; | ||
516 | } | ||
517 | |||
518 | disk_super = dm_block_data(sblock); | ||
519 | r = dm_tm_open_with_sm(pmd->bm, THIN_SUPERBLOCK_LOCATION, | ||
520 | disk_super->metadata_space_map_root, | ||
521 | sizeof(disk_super->metadata_space_map_root), | ||
522 | &pmd->tm, &pmd->metadata_sm); | ||
523 | if (r < 0) { | ||
524 | DMERR("tm_open_with_sm failed"); | ||
525 | dm_bm_unlock(sblock); | ||
526 | return r; | ||
527 | } | ||
528 | |||
529 | pmd->data_sm = dm_sm_disk_open(pmd->tm, disk_super->data_space_map_root, | ||
530 | sizeof(disk_super->data_space_map_root)); | ||
531 | if (IS_ERR(pmd->data_sm)) { | ||
532 | DMERR("sm_disk_open failed"); | ||
533 | dm_bm_unlock(sblock); | ||
534 | r = PTR_ERR(pmd->data_sm); | ||
535 | goto bad; | ||
536 | } | ||
537 | 498 | ||
538 | dm_bm_unlock(sblock); | 499 | pmd->data_sm = dm_sm_disk_create(pmd->tm, nr_blocks); |
500 | if (IS_ERR(pmd->data_sm)) { | ||
501 | DMERR("sm_disk_create failed"); | ||
502 | r = PTR_ERR(pmd->data_sm); | ||
503 | goto bad; | ||
539 | } | 504 | } |
540 | 505 | ||
541 | pmd->nb_tm = dm_tm_create_non_blocking_clone(pmd->tm); | 506 | pmd->nb_tm = dm_tm_create_non_blocking_clone(pmd->tm); |
@@ -552,9 +517,6 @@ static int __open_or_format_metadata(struct dm_pool_metadata *pmd, | |||
552 | pmd->trans_id = 0; | 517 | pmd->trans_id = 0; |
553 | pmd->flags = 0; | 518 | pmd->flags = 0; |
554 | 519 | ||
555 | if (!create) | ||
556 | return 0; | ||
557 | |||
558 | r = dm_btree_empty(&pmd->info, &pmd->root); | 520 | r = dm_btree_empty(&pmd->info, &pmd->root); |
559 | if (r < 0) | 521 | if (r < 0) |
560 | goto bad_data_sm; | 522 | goto bad_data_sm; |
@@ -580,6 +542,68 @@ bad: | |||
580 | return r; | 542 | return r; |
581 | } | 543 | } |
582 | 544 | ||
545 | static int __open_metadata(struct dm_pool_metadata *pmd) | ||
546 | { | ||
547 | int r; | ||
548 | struct dm_block *sblock; | ||
549 | struct thin_disk_superblock *disk_super; | ||
550 | |||
551 | r = dm_bm_read_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION, | ||
552 | &sb_validator, &sblock); | ||
553 | if (r < 0) { | ||
554 | DMERR("couldn't read superblock"); | ||
555 | return r; | ||
556 | } | ||
557 | |||
558 | disk_super = dm_block_data(sblock); | ||
559 | r = dm_tm_open_with_sm(pmd->bm, THIN_SUPERBLOCK_LOCATION, | ||
560 | disk_super->metadata_space_map_root, | ||
561 | sizeof(disk_super->metadata_space_map_root), | ||
562 | &pmd->tm, &pmd->metadata_sm); | ||
563 | if (r < 0) { | ||
564 | DMERR("tm_open_with_sm failed"); | ||
565 | dm_bm_unlock(sblock); | ||
566 | return r; | ||
567 | } | ||
568 | |||
569 | pmd->data_sm = dm_sm_disk_open(pmd->tm, disk_super->data_space_map_root, | ||
570 | sizeof(disk_super->data_space_map_root)); | ||
571 | if (IS_ERR(pmd->data_sm)) { | ||
572 | DMERR("sm_disk_open failed"); | ||
573 | dm_bm_unlock(sblock); | ||
574 | r = PTR_ERR(pmd->data_sm); | ||
575 | goto bad; | ||
576 | } | ||
577 | |||
578 | dm_bm_unlock(sblock); | ||
579 | |||
580 | pmd->nb_tm = dm_tm_create_non_blocking_clone(pmd->tm); | ||
581 | if (!pmd->nb_tm) { | ||
582 | DMERR("could not create clone tm"); | ||
583 | r = -ENOMEM; | ||
584 | goto bad_data_sm; | ||
585 | } | ||
586 | |||
587 | __setup_btree_details(pmd); | ||
588 | |||
589 | bad_data_sm: | ||
590 | dm_sm_destroy(pmd->data_sm); | ||
591 | bad: | ||
592 | dm_tm_destroy(pmd->tm); | ||
593 | dm_sm_destroy(pmd->metadata_sm); | ||
594 | |||
595 | return r; | ||
596 | } | ||
597 | |||
598 | static int __open_or_format_metadata(struct dm_pool_metadata *pmd, | ||
599 | dm_block_t nr_blocks, int create) | ||
600 | { | ||
601 | if (create) | ||
602 | return __format_metadata(pmd, nr_blocks); | ||
603 | else | ||
604 | return __open_metadata(pmd); | ||
605 | } | ||
606 | |||
583 | static int __create_persistent_data_objects(struct dm_pool_metadata *pmd, | 607 | static int __create_persistent_data_objects(struct dm_pool_metadata *pmd, |
584 | dm_block_t nr_blocks, int *create) | 608 | dm_block_t nr_blocks, int *create) |
585 | { | 609 | { |