summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYangtao Li <frank.li@vivo.com>2023-03-18 21:16:33 +0800
committerMike Snitzer <snitzer@kernel.org>2023-04-11 12:01:01 -0400
commitb362c733ed7bf312ed729847bc26ba89febc556e (patch)
tree3aca88e86af3babc68dbdc97eaf13fad0e569efe
parent6b79a428c02769f2a11f8ae76bf866226d134887 (diff)
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>
-rw-r--r--drivers/md/dm-cache-target.c1
-rw-r--r--drivers/md/dm-clone-target.c1
-rw-r--r--drivers/md/dm-crypt.c8
-rw-r--r--drivers/md/dm-delay.c13
-rw-r--r--drivers/md/dm-dust.c7
-rw-r--r--drivers/md/dm-ebs-target.c7
-rw-r--r--drivers/md/dm-era-target.c10
-rw-r--r--drivers/md/dm-flakey.c7
-rw-r--r--drivers/md/dm-integrity.c1
-rw-r--r--drivers/md/dm-log-writes.c7
-rw-r--r--drivers/md/dm-mpath.c5
-rw-r--r--drivers/md/dm-raid1.c10
-rw-r--r--drivers/md/dm-snap.c12
-rw-r--r--drivers/md/dm-switch.c8
-rw-r--r--drivers/md/dm-target.c9
-rw-r--r--drivers/md/dm-verity-target.c8
-rw-r--r--drivers/md/dm-writecache.c10
-rw-r--r--drivers/md/dm-zero.c7
18 files changed, 24 insertions, 107 deletions
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index dbbcfa580078..872896218550 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -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;
}
diff --git a/drivers/md/dm-clone-target.c b/drivers/md/dm-clone-target.c
index fc30ebd67622..f467cdb5a022 100644
--- a/drivers/md/dm-clone-target.c
+++ b/drivers/md/dm-clone-target.c
@@ -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;
}
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 3ba53dc3cc3f..52615a258e13 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -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)
diff --git a/drivers/md/dm-delay.c b/drivers/md/dm-delay.c
index a425046f88c7..00d18b2070a5 100644
--- a/drivers/md/dm-delay.c
+++ b/drivers/md/dm-delay.c
@@ -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)
diff --git a/drivers/md/dm-dust.c b/drivers/md/dm-dust.c
index 7ae9936752de..9bf3cdf548de 100644
--- a/drivers/md/dm-dust.c
+++ b/drivers/md/dm-dust.c
@@ -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)
diff --git a/drivers/md/dm-ebs-target.c b/drivers/md/dm-ebs-target.c
index b1068a68bc46..38da4de3ecbf 100644
--- a/drivers/md/dm-ebs-target.c
+++ b/drivers/md/dm-ebs-target.c
@@ -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)
diff --git a/drivers/md/dm-era-target.c b/drivers/md/dm-era-target.c
index c2e7780cdd2d..554d234fca18 100644
--- a/drivers/md/dm-era-target.c
+++ b/drivers/md/dm-era-target.c
@@ -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)
diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c
index 5b7556d2a9d9..14179355e6a1 100644
--- a/drivers/md/dm-flakey.c
+++ b/drivers/md/dm-flakey.c
@@ -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)
diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index 54830b07b829..ed612bf38b83 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -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;
}
diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c
index cbd0f81f4a35..0ce9b01d1393 100644
--- a/drivers/md/dm-log-writes.c
+++ b/drivers/md/dm-log-writes.c
@@ -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)
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 61ab1a8d2c9c..bea3cda9938e 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -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;
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index bc417a5e5b89..3e947655746c 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -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)
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index f766c21408f1..9c49f53760d0 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -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;
diff --git a/drivers/md/dm-switch.c b/drivers/md/dm-switch.c
index ee2432927e90..5a5976b0cfb8 100644
--- a/drivers/md/dm-switch.c
+++ b/drivers/md/dm-switch.c
@@ -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)
diff --git a/drivers/md/dm-target.c b/drivers/md/dm-target.c
index 97a75f3eed93..27e2992ff249 100644
--- a/drivers/md/dm-target.c
+++ b/drivers/md/dm-target.c
@@ -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);
diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index b2f0c3c0abdb..260f04d12982 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -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)
diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index 3aa5874f0aef..81b60b75a9fa 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -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)
diff --git a/drivers/md/dm-zero.c b/drivers/md/dm-zero.c
index 6215d8eb7e41..884ac726a743 100644
--- a/drivers/md/dm-zero.c
+++ b/drivers/md/dm-zero.c
@@ -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)