diff options
author | Mikulas Patocka <mpatocka@redhat.com> | 2009-01-05 22:04:58 -0500 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2009-01-05 22:04:58 -0500 |
commit | 10d3bd09a3c25df114f74f7f86e1b58d070bef32 (patch) | |
tree | a44e2fe5ccc5950b87a1d31849e5f0ac24fdcc16 | |
parent | d460c65a6a9ec9e0d284864ec3a9a2d1b73f0e43 (diff) |
dm: consolidate target deregistration error handling
Change dm_unregister_target to return void and use BUG() for error
reporting.
dm_unregister_target can only fail because of programming bug in the
target driver. It can't fail because of user's behavior or disk errors.
This patch changes unregister_target to return void and use BUG if
someone tries to unregister non-registered target or unregister target
that is in use.
This patch removes code duplication (testing of error codes in all dm
targets) and reports bugs in just one place, in dm_unregister_target. In
some target drivers, these return codes were ignored, which could lead
to a situation where bugs could be missed.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
-rw-r--r-- | drivers/md/dm-crypt.c | 6 | ||||
-rw-r--r-- | drivers/md/dm-delay.c | 6 | ||||
-rw-r--r-- | drivers/md/dm-linear.c | 5 | ||||
-rw-r--r-- | drivers/md/dm-mpath.c | 6 | ||||
-rw-r--r-- | drivers/md/dm-raid1.c | 6 | ||||
-rw-r--r-- | drivers/md/dm-snap.c | 11 | ||||
-rw-r--r-- | drivers/md/dm-stripe.c | 4 | ||||
-rw-r--r-- | drivers/md/dm-target.c | 15 | ||||
-rw-r--r-- | drivers/md/dm-zero.c | 5 | ||||
-rw-r--r-- | include/linux/device-mapper.h | 6 |
10 files changed, 20 insertions, 50 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 3326750ec02c..35bda49796fb 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c | |||
@@ -1322,11 +1322,7 @@ static int __init dm_crypt_init(void) | |||
1322 | 1322 | ||
1323 | static void __exit dm_crypt_exit(void) | 1323 | static void __exit dm_crypt_exit(void) |
1324 | { | 1324 | { |
1325 | int r = dm_unregister_target(&crypt_target); | 1325 | dm_unregister_target(&crypt_target); |
1326 | |||
1327 | if (r < 0) | ||
1328 | DMERR("unregister failed %d", r); | ||
1329 | |||
1330 | kmem_cache_destroy(_crypt_io_pool); | 1326 | kmem_cache_destroy(_crypt_io_pool); |
1331 | } | 1327 | } |
1332 | 1328 | ||
diff --git a/drivers/md/dm-delay.c b/drivers/md/dm-delay.c index 848b381f1173..59ee1b015d2d 100644 --- a/drivers/md/dm-delay.c +++ b/drivers/md/dm-delay.c | |||
@@ -364,11 +364,7 @@ bad_queue: | |||
364 | 364 | ||
365 | static void __exit dm_delay_exit(void) | 365 | static void __exit dm_delay_exit(void) |
366 | { | 366 | { |
367 | int r = dm_unregister_target(&delay_target); | 367 | dm_unregister_target(&delay_target); |
368 | |||
369 | if (r < 0) | ||
370 | DMERR("unregister failed %d", r); | ||
371 | |||
372 | kmem_cache_destroy(delayed_cache); | 368 | kmem_cache_destroy(delayed_cache); |
373 | destroy_workqueue(kdelayd_wq); | 369 | destroy_workqueue(kdelayd_wq); |
374 | } | 370 | } |
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index 44042becad8a..79fb53e51c70 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c | |||
@@ -156,8 +156,5 @@ int __init dm_linear_init(void) | |||
156 | 156 | ||
157 | void dm_linear_exit(void) | 157 | void dm_linear_exit(void) |
158 | { | 158 | { |
159 | int r = dm_unregister_target(&linear_target); | 159 | dm_unregister_target(&linear_target); |
160 | |||
161 | if (r < 0) | ||
162 | DMERR("unregister failed %d", r); | ||
163 | } | 160 | } |
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c index 3d7f4923cd13..345a26047ae0 100644 --- a/drivers/md/dm-mpath.c +++ b/drivers/md/dm-mpath.c | |||
@@ -1495,14 +1495,10 @@ static int __init dm_multipath_init(void) | |||
1495 | 1495 | ||
1496 | static void __exit dm_multipath_exit(void) | 1496 | static void __exit dm_multipath_exit(void) |
1497 | { | 1497 | { |
1498 | int r; | ||
1499 | |||
1500 | destroy_workqueue(kmpath_handlerd); | 1498 | destroy_workqueue(kmpath_handlerd); |
1501 | destroy_workqueue(kmultipathd); | 1499 | destroy_workqueue(kmultipathd); |
1502 | 1500 | ||
1503 | r = dm_unregister_target(&multipath_target); | 1501 | dm_unregister_target(&multipath_target); |
1504 | if (r < 0) | ||
1505 | DMERR("target unregister failed %d", r); | ||
1506 | kmem_cache_destroy(_mpio_cache); | 1502 | kmem_cache_destroy(_mpio_cache); |
1507 | } | 1503 | } |
1508 | 1504 | ||
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c index d0fed2b21b08..250f401668d5 100644 --- a/drivers/md/dm-raid1.c +++ b/drivers/md/dm-raid1.c | |||
@@ -1300,11 +1300,7 @@ static int __init dm_mirror_init(void) | |||
1300 | 1300 | ||
1301 | static void __exit dm_mirror_exit(void) | 1301 | static void __exit dm_mirror_exit(void) |
1302 | { | 1302 | { |
1303 | int r; | 1303 | dm_unregister_target(&mirror_target); |
1304 | |||
1305 | r = dm_unregister_target(&mirror_target); | ||
1306 | if (r < 0) | ||
1307 | DMERR("unregister failed %d", r); | ||
1308 | } | 1304 | } |
1309 | 1305 | ||
1310 | /* Module hooks */ | 1306 | /* Module hooks */ |
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 4ceedd4f22af..a8005b43a06b 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c | |||
@@ -1470,17 +1470,10 @@ static int __init dm_snapshot_init(void) | |||
1470 | 1470 | ||
1471 | static void __exit dm_snapshot_exit(void) | 1471 | static void __exit dm_snapshot_exit(void) |
1472 | { | 1472 | { |
1473 | int r; | ||
1474 | |||
1475 | destroy_workqueue(ksnapd); | 1473 | destroy_workqueue(ksnapd); |
1476 | 1474 | ||
1477 | r = dm_unregister_target(&snapshot_target); | 1475 | dm_unregister_target(&snapshot_target); |
1478 | if (r) | 1476 | dm_unregister_target(&origin_target); |
1479 | DMERR("snapshot unregister failed %d", r); | ||
1480 | |||
1481 | r = dm_unregister_target(&origin_target); | ||
1482 | if (r) | ||
1483 | DMERR("origin unregister failed %d", r); | ||
1484 | 1477 | ||
1485 | exit_origin_hash(); | 1478 | exit_origin_hash(); |
1486 | kmem_cache_destroy(pending_cache); | 1479 | kmem_cache_destroy(pending_cache); |
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c index 9e4ef88d421e..41569bc60abc 100644 --- a/drivers/md/dm-stripe.c +++ b/drivers/md/dm-stripe.c | |||
@@ -337,9 +337,7 @@ int __init dm_stripe_init(void) | |||
337 | 337 | ||
338 | void dm_stripe_exit(void) | 338 | void dm_stripe_exit(void) |
339 | { | 339 | { |
340 | if (dm_unregister_target(&stripe_target)) | 340 | dm_unregister_target(&stripe_target); |
341 | DMWARN("target unregistration failed"); | ||
342 | |||
343 | destroy_workqueue(kstriped); | 341 | destroy_workqueue(kstriped); |
344 | 342 | ||
345 | return; | 343 | return; |
diff --git a/drivers/md/dm-target.c b/drivers/md/dm-target.c index 835cf95b857f..7decf10006e4 100644 --- a/drivers/md/dm-target.c +++ b/drivers/md/dm-target.c | |||
@@ -130,26 +130,26 @@ int dm_register_target(struct target_type *t) | |||
130 | return rv; | 130 | return rv; |
131 | } | 131 | } |
132 | 132 | ||
133 | int dm_unregister_target(struct target_type *t) | 133 | void dm_unregister_target(struct target_type *t) |
134 | { | 134 | { |
135 | struct tt_internal *ti; | 135 | struct tt_internal *ti; |
136 | 136 | ||
137 | down_write(&_lock); | 137 | down_write(&_lock); |
138 | if (!(ti = __find_target_type(t->name))) { | 138 | if (!(ti = __find_target_type(t->name))) { |
139 | up_write(&_lock); | 139 | DMCRIT("Unregistering unrecognised target: %s", t->name); |
140 | return -EINVAL; | 140 | BUG(); |
141 | } | 141 | } |
142 | 142 | ||
143 | if (ti->use) { | 143 | if (ti->use) { |
144 | up_write(&_lock); | 144 | DMCRIT("Attempt to unregister target still in use: %s", |
145 | return -ETXTBSY; | 145 | t->name); |
146 | BUG(); | ||
146 | } | 147 | } |
147 | 148 | ||
148 | list_del(&ti->list); | 149 | list_del(&ti->list); |
149 | kfree(ti); | 150 | kfree(ti); |
150 | 151 | ||
151 | up_write(&_lock); | 152 | up_write(&_lock); |
152 | return 0; | ||
153 | } | 153 | } |
154 | 154 | ||
155 | /* | 155 | /* |
@@ -187,8 +187,7 @@ int __init dm_target_init(void) | |||
187 | 187 | ||
188 | void dm_target_exit(void) | 188 | void dm_target_exit(void) |
189 | { | 189 | { |
190 | if (dm_unregister_target(&error_target)) | 190 | dm_unregister_target(&error_target); |
191 | DMWARN("error target unregistration failed"); | ||
192 | } | 191 | } |
193 | 192 | ||
194 | EXPORT_SYMBOL(dm_register_target); | 193 | EXPORT_SYMBOL(dm_register_target); |
diff --git a/drivers/md/dm-zero.c b/drivers/md/dm-zero.c index cdbf126ec106..bbc97030c0c2 100644 --- a/drivers/md/dm-zero.c +++ b/drivers/md/dm-zero.c | |||
@@ -69,10 +69,7 @@ static int __init dm_zero_init(void) | |||
69 | 69 | ||
70 | static void __exit dm_zero_exit(void) | 70 | static void __exit dm_zero_exit(void) |
71 | { | 71 | { |
72 | int r = dm_unregister_target(&zero_target); | 72 | dm_unregister_target(&zero_target); |
73 | |||
74 | if (r < 0) | ||
75 | DMERR("unregister failed %d", r); | ||
76 | } | 73 | } |
77 | 74 | ||
78 | module_init(dm_zero_init) | 75 | module_init(dm_zero_init) |
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index c17fd334e574..89ff2df40240 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h | |||
@@ -157,8 +157,7 @@ struct dm_target { | |||
157 | }; | 157 | }; |
158 | 158 | ||
159 | int dm_register_target(struct target_type *t); | 159 | int dm_register_target(struct target_type *t); |
160 | int dm_unregister_target(struct target_type *t); | 160 | void dm_unregister_target(struct target_type *t); |
161 | |||
162 | 161 | ||
163 | /*----------------------------------------------------------------- | 162 | /*----------------------------------------------------------------- |
164 | * Functions for creating and manipulating mapped devices. | 163 | * Functions for creating and manipulating mapped devices. |
@@ -276,6 +275,9 @@ void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size); | |||
276 | *---------------------------------------------------------------*/ | 275 | *---------------------------------------------------------------*/ |
277 | #define DM_NAME "device-mapper" | 276 | #define DM_NAME "device-mapper" |
278 | 277 | ||
278 | #define DMCRIT(f, arg...) \ | ||
279 | printk(KERN_CRIT DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) | ||
280 | |||
279 | #define DMERR(f, arg...) \ | 281 | #define DMERR(f, arg...) \ |
280 | printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) | 282 | printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg) |
281 | #define DMERR_LIMIT(f, arg...) \ | 283 | #define DMERR_LIMIT(f, arg...) \ |