dm: push error reporting down to dm_register_target()

Simplifies each DM target's init method by making dm_register_target()
responsible for its error reporting (on behalf of targets).

Signed-off-by: Yangtao Li <frank.li@vivo.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
This commit is contained in:
Yangtao Li 2023-03-18 21:16:33 +08:00 committed by Mike Snitzer
parent 6b79a428c0
commit b362c733ed
18 changed files with 24 additions and 107 deletions

View File

@ -3459,7 +3459,6 @@ static int __init dm_cache_init(void)
r = dm_register_target(&cache_target);
if (r) {
DMERR("cache target registration failed: %d", r);
kmem_cache_destroy(migration_cache);
return r;
}

View File

@ -2204,7 +2204,6 @@ static int __init dm_clone_init(void)
r = dm_register_target(&clone_target);
if (r < 0) {
DMERR("Failed to register clone target");
kmem_cache_destroy(_hydration_cache);
return r;
}

View File

@ -3662,13 +3662,7 @@ static struct target_type crypt_target = {
static int __init dm_crypt_init(void)
{
int r;
r = dm_register_target(&crypt_target);
if (r < 0)
DMERR("register failed %d", r);
return r;
return dm_register_target(&crypt_target);
}
static void __exit dm_crypt_exit(void)

View File

@ -370,18 +370,7 @@ static struct target_type delay_target = {
static int __init dm_delay_init(void)
{
int r;
r = dm_register_target(&delay_target);
if (r < 0) {
DMERR("register failed %d", r);
goto bad_register;
}
return 0;
bad_register:
return r;
return dm_register_target(&delay_target);
}
static void __exit dm_delay_exit(void)

View File

@ -573,12 +573,7 @@ static struct target_type dust_target = {
static int __init dm_dust_init(void)
{
int r = dm_register_target(&dust_target);
if (r < 0)
DMERR("dm_register_target failed %d", r);
return r;
return dm_register_target(&dust_target);
}
static void __exit dm_dust_exit(void)

View File

@ -455,12 +455,7 @@ static struct target_type ebs_target = {
static int __init dm_ebs_init(void)
{
int r = dm_register_target(&ebs_target);
if (r < 0)
DMERR("register failed %d", r);
return r;
return dm_register_target(&ebs_target);
}
static void dm_ebs_exit(void)

View File

@ -1756,15 +1756,7 @@ static struct target_type era_target = {
static int __init dm_era_init(void)
{
int r;
r = dm_register_target(&era_target);
if (r) {
DMERR("era target registration failed: %d", r);
return r;
}
return 0;
return dm_register_target(&era_target);
}
static void __exit dm_era_exit(void)

View File

@ -509,12 +509,7 @@ static struct target_type flakey_target = {
static int __init dm_flakey_init(void)
{
int r = dm_register_target(&flakey_target);
if (r < 0)
DMERR("register failed %d", r);
return r;
return dm_register_target(&flakey_target);
}
static void __exit dm_flakey_exit(void)

View File

@ -4704,7 +4704,6 @@ static int __init dm_integrity_init(void)
r = dm_register_target(&integrity_target);
if (r < 0) {
DMERR("register failed %d", r);
kmem_cache_destroy(journal_io_cache);
return r;
}

View File

@ -940,12 +940,7 @@ static struct target_type log_writes_target = {
static int __init dm_log_writes_init(void)
{
int r = dm_register_target(&log_writes_target);
if (r < 0)
DMERR("register failed %d", r);
return r;
return dm_register_target(&log_writes_target);
}
static void __exit dm_log_writes_exit(void)

View File

@ -2235,11 +2235,8 @@ static int __init dm_multipath_init(void)
}
r = dm_register_target(&multipath_target);
if (r < 0) {
DMERR("request-based register failed %d", r);
r = -EINVAL;
if (r < 0)
goto bad_register_target;
}
return 0;

View File

@ -1498,23 +1498,19 @@ static struct target_type mirror_target = {
static int __init dm_mirror_init(void)
{
int r = -ENOMEM;
int r;
dm_raid1_wq = alloc_workqueue("dm_raid1_wq", 0, 0);
if (!dm_raid1_wq)
goto bad_target;
return -ENOMEM;
r = dm_register_target(&mirror_target);
if (r < 0) {
destroy_workqueue(dm_raid1_wq);
goto bad_target;
return r;
}
return 0;
bad_target:
DMERR("Failed to register mirror target");
return r;
}
static void __exit dm_mirror_exit(void)

View File

@ -2815,22 +2815,16 @@ static int __init dm_snapshot_init(void)
}
r = dm_register_target(&snapshot_target);
if (r < 0) {
DMERR("snapshot target register failed %d", r);
if (r < 0)
goto bad_register_snapshot_target;
}
r = dm_register_target(&origin_target);
if (r < 0) {
DMERR("Origin target register failed %d", r);
if (r < 0)
goto bad_register_origin_target;
}
r = dm_register_target(&merge_target);
if (r < 0) {
DMERR("Merge target register failed %d", r);
if (r < 0)
goto bad_register_merge_target;
}
return 0;

View File

@ -568,13 +568,7 @@ static struct target_type switch_target = {
static int __init dm_switch_init(void)
{
int r;
r = dm_register_target(&switch_target);
if (r < 0)
DMERR("dm_register_target() failed %d", r);
return r;
return dm_register_target(&switch_target);
}
static void __exit dm_switch_exit(void)

View File

@ -85,12 +85,15 @@ int dm_register_target(struct target_type *tt)
int rv = 0;
down_write(&_lock);
if (__find_target_type(tt->name))
if (__find_target_type(tt->name)) {
DMERR("%s: '%s' target already registered",
__func__, tt->name);
rv = -EEXIST;
else
} else {
list_add(&tt->list, &_targets);
}
up_write(&_lock);
return rv;
}
EXPORT_SYMBOL(dm_register_target);

View File

@ -1517,13 +1517,7 @@ static struct target_type verity_target = {
static int __init dm_verity_init(void)
{
int r;
r = dm_register_target(&verity_target);
if (r < 0)
DMERR("register failed %d", r);
return r;
return dm_register_target(&verity_target);
}
static void __exit dm_verity_exit(void)

View File

@ -2776,15 +2776,7 @@ static struct target_type writecache_target = {
static int __init dm_writecache_init(void)
{
int r;
r = dm_register_target(&writecache_target);
if (r < 0) {
DMERR("register failed %d", r);
return r;
}
return 0;
return dm_register_target(&writecache_target);
}
static void __exit dm_writecache_exit(void)

View File

@ -78,12 +78,7 @@ static struct target_type zero_target = {
static int __init dm_zero_init(void)
{
int r = dm_register_target(&zero_target);
if (r < 0)
DMERR("register failed %d", r);
return r;
return dm_register_target(&zero_target);
}
static void __exit dm_zero_exit(void)