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>
This commit is contained in:
committed by
Alasdair G Kergon
parent
d460c65a6a
commit
10d3bd09a3
@@ -130,26 +130,26 @@ int dm_register_target(struct target_type *t)
|
||||
return rv;
|
||||
}
|
||||
|
||||
int dm_unregister_target(struct target_type *t)
|
||||
void dm_unregister_target(struct target_type *t)
|
||||
{
|
||||
struct tt_internal *ti;
|
||||
|
||||
down_write(&_lock);
|
||||
if (!(ti = __find_target_type(t->name))) {
|
||||
up_write(&_lock);
|
||||
return -EINVAL;
|
||||
DMCRIT("Unregistering unrecognised target: %s", t->name);
|
||||
BUG();
|
||||
}
|
||||
|
||||
if (ti->use) {
|
||||
up_write(&_lock);
|
||||
return -ETXTBSY;
|
||||
DMCRIT("Attempt to unregister target still in use: %s",
|
||||
t->name);
|
||||
BUG();
|
||||
}
|
||||
|
||||
list_del(&ti->list);
|
||||
kfree(ti);
|
||||
|
||||
up_write(&_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -187,8 +187,7 @@ int __init dm_target_init(void)
|
||||
|
||||
void dm_target_exit(void)
|
||||
{
|
||||
if (dm_unregister_target(&error_target))
|
||||
DMWARN("error target unregistration failed");
|
||||
dm_unregister_target(&error_target);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(dm_register_target);
|
||||
|
Reference in New Issue
Block a user