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 | |
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')
-rw-r--r-- | drivers/md/dm-ioctl.c | 34 | ||||
-rw-r--r-- | drivers/md/dm-table.c | 55 | ||||
-rw-r--r-- | drivers/md/dm.h | 1 |
3 files changed, 52 insertions, 38 deletions
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index ed8585954a3a..4d4ced8e4307 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c | |||
@@ -1131,28 +1131,9 @@ static int populate_table(struct dm_table *table, | |||
1131 | next = spec->next; | 1131 | next = spec->next; |
1132 | } | 1132 | } |
1133 | 1133 | ||
1134 | r = dm_table_set_type(table); | ||
1135 | if (r) { | ||
1136 | DMWARN("unable to set table type"); | ||
1137 | return r; | ||
1138 | } | ||
1139 | |||
1140 | return dm_table_complete(table); | 1134 | return dm_table_complete(table); |
1141 | } | 1135 | } |
1142 | 1136 | ||
1143 | static int table_prealloc_integrity(struct dm_table *t, | ||
1144 | struct mapped_device *md) | ||
1145 | { | ||
1146 | struct list_head *devices = dm_table_get_devices(t); | ||
1147 | struct dm_dev_internal *dd; | ||
1148 | |||
1149 | list_for_each_entry(dd, devices, list) | ||
1150 | if (bdev_get_integrity(dd->dm_dev.bdev)) | ||
1151 | return blk_integrity_register(dm_disk(md), NULL); | ||
1152 | |||
1153 | return 0; | ||
1154 | } | ||
1155 | |||
1156 | static int table_load(struct dm_ioctl *param, size_t param_size) | 1137 | static int table_load(struct dm_ioctl *param, size_t param_size) |
1157 | { | 1138 | { |
1158 | int r; | 1139 | int r; |
@@ -1174,21 +1155,6 @@ static int table_load(struct dm_ioctl *param, size_t param_size) | |||
1174 | goto out; | 1155 | goto out; |
1175 | } | 1156 | } |
1176 | 1157 | ||
1177 | r = table_prealloc_integrity(t, md); | ||
1178 | if (r) { | ||
1179 | DMERR("%s: could not register integrity profile.", | ||
1180 | dm_device_name(md)); | ||
1181 | dm_table_destroy(t); | ||
1182 | goto out; | ||
1183 | } | ||
1184 | |||
1185 | r = dm_table_alloc_md_mempools(t); | ||
1186 | if (r) { | ||
1187 | DMWARN("unable to allocate mempools for this table"); | ||
1188 | dm_table_destroy(t); | ||
1189 | goto out; | ||
1190 | } | ||
1191 | |||
1192 | /* Protect md->type and md->queue against concurrent table loads. */ | 1158 | /* Protect md->type and md->queue against concurrent table loads. */ |
1193 | dm_lock_md_type(md); | 1159 | dm_lock_md_type(md); |
1194 | if (dm_get_md_type(md) == DM_TYPE_NONE) | 1160 | if (dm_get_md_type(md) == DM_TYPE_NONE) |
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) |
diff --git a/drivers/md/dm.h b/drivers/md/dm.h index 450fbd98c48c..0d7b374c5dc2 100644 --- a/drivers/md/dm.h +++ b/drivers/md/dm.h | |||
@@ -59,7 +59,6 @@ void dm_table_postsuspend_targets(struct dm_table *t); | |||
59 | int dm_table_resume_targets(struct dm_table *t); | 59 | int dm_table_resume_targets(struct dm_table *t); |
60 | int dm_table_any_congested(struct dm_table *t, int bdi_bits); | 60 | int dm_table_any_congested(struct dm_table *t, int bdi_bits); |
61 | int dm_table_any_busy_target(struct dm_table *t); | 61 | int dm_table_any_busy_target(struct dm_table *t); |
62 | int dm_table_set_type(struct dm_table *t); | ||
63 | unsigned dm_table_get_type(struct dm_table *t); | 62 | unsigned dm_table_get_type(struct dm_table *t); |
64 | bool dm_table_request_based(struct dm_table *t); | 63 | bool dm_table_request_based(struct dm_table *t); |
65 | int dm_table_alloc_md_mempools(struct dm_table *t); | 64 | int dm_table_alloc_md_mempools(struct dm_table *t); |