diff options
author | Will Drewry <wad@chromium.org> | 2010-08-11 23:14:03 -0400 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2010-08-11 23:14:03 -0400 |
commit | 26803b9f06d365122fae82e7554a66ef8278e0bb (patch) | |
tree | 83f77be2b09bbaa6d97105509d54955b2eec7147 /drivers/md/dm-table.c | |
parent | b1d5552838334c600b068c9c8cc18638e5a8cb47 (diff) |
dm ioctl: refactor dm_table_complete
This change unifies the various checks and finalization that occurs on a
table prior to use. By doing so, it allows table construction without
traversing the dm-ioctl interface.
Signed-off-by: Will Drewry <wad@chromium.org>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md/dm-table.c')
-rw-r--r-- | drivers/md/dm-table.c | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 9924ea23032d..bc60ef77a0d8 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c | |||
@@ -245,7 +245,7 @@ void dm_table_destroy(struct dm_table *t) | |||
245 | msleep(1); | 245 | msleep(1); |
246 | smp_mb(); | 246 | smp_mb(); |
247 | 247 | ||
248 | /* free the indexes (see dm_table_complete) */ | 248 | /* free the indexes */ |
249 | if (t->depth >= 2) | 249 | if (t->depth >= 2) |
250 | vfree(t->index[t->depth - 2]); | 250 | vfree(t->index[t->depth - 2]); |
251 | 251 | ||
@@ -778,7 +778,7 @@ int dm_table_add_target(struct dm_table *t, const char *type, | |||
778 | return r; | 778 | return r; |
779 | } | 779 | } |
780 | 780 | ||
781 | int dm_table_set_type(struct dm_table *t) | 781 | static int dm_table_set_type(struct dm_table *t) |
782 | { | 782 | { |
783 | unsigned i; | 783 | unsigned i; |
784 | unsigned bio_based = 0, request_based = 0; | 784 | unsigned bio_based = 0, request_based = 0; |
@@ -900,7 +900,7 @@ static int setup_indexes(struct dm_table *t) | |||
900 | /* | 900 | /* |
901 | * Builds the btree to index the map. | 901 | * Builds the btree to index the map. |
902 | */ | 902 | */ |
903 | int dm_table_complete(struct dm_table *t) | 903 | static int dm_table_build_index(struct dm_table *t) |
904 | { | 904 | { |
905 | int r = 0; | 905 | int r = 0; |
906 | unsigned int leaf_nodes; | 906 | unsigned int leaf_nodes; |
@@ -919,6 +919,55 @@ int dm_table_complete(struct dm_table *t) | |||
919 | return r; | 919 | return r; |
920 | } | 920 | } |
921 | 921 | ||
922 | /* | ||
923 | * Register the mapped device for blk_integrity support if | ||
924 | * the underlying devices support it. | ||
925 | */ | ||
926 | static int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device *md) | ||
927 | { | ||
928 | struct list_head *devices = dm_table_get_devices(t); | ||
929 | struct dm_dev_internal *dd; | ||
930 | |||
931 | list_for_each_entry(dd, devices, list) | ||
932 | if (bdev_get_integrity(dd->dm_dev.bdev)) | ||
933 | return blk_integrity_register(dm_disk(md), NULL); | ||
934 | |||
935 | return 0; | ||
936 | } | ||
937 | |||
938 | /* | ||
939 | * Prepares the table for use by building the indices, | ||
940 | * setting the type, and allocating mempools. | ||
941 | */ | ||
942 | int dm_table_complete(struct dm_table *t) | ||
943 | { | ||
944 | int r; | ||
945 | |||
946 | r = dm_table_set_type(t); | ||
947 | if (r) { | ||
948 | DMERR("unable to set table type"); | ||
949 | return r; | ||
950 | } | ||
951 | |||
952 | r = dm_table_build_index(t); | ||
953 | if (r) { | ||
954 | DMERR("unable to build btrees"); | ||
955 | return r; | ||
956 | } | ||
957 | |||
958 | r = dm_table_prealloc_integrity(t, t->md); | ||
959 | if (r) { | ||
960 | DMERR("could not register integrity profile."); | ||
961 | return r; | ||
962 | } | ||
963 | |||
964 | r = dm_table_alloc_md_mempools(t); | ||
965 | if (r) | ||
966 | DMERR("unable to allocate mempools"); | ||
967 | |||
968 | return r; | ||
969 | } | ||
970 | |||
922 | static DEFINE_MUTEX(_event_lock); | 971 | static DEFINE_MUTEX(_event_lock); |
923 | void dm_table_event_callback(struct dm_table *t, | 972 | void dm_table_event_callback(struct dm_table *t, |
924 | void (*fn)(void *), void *context) | 973 | void (*fn)(void *), void *context) |