Commit 3664ff82 authored by Yangtao Li's avatar Yangtao Li Committed by Mike Snitzer

dm: add helper macro for simple DM target module init and exit

Eliminate duplicate boilerplate code for simple modules that contain
a single DM target driver without any additional setup code.

Add a new module_dm() macro, which replaces the module_init() and
module_exit() with template functions that call dm_register_target()
and dm_unregister_target() respectively.
Signed-off-by: default avatarYangtao Li <frank.li@vivo.com>
Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
parent 306fbc2e
...@@ -3659,19 +3659,7 @@ static struct target_type crypt_target = { ...@@ -3659,19 +3659,7 @@ static struct target_type crypt_target = {
.iterate_devices = crypt_iterate_devices, .iterate_devices = crypt_iterate_devices,
.io_hints = crypt_io_hints, .io_hints = crypt_io_hints,
}; };
module_dm(crypt);
static int __init dm_crypt_init(void)
{
return dm_register_target(&crypt_target);
}
static void __exit dm_crypt_exit(void)
{
dm_unregister_target(&crypt_target);
}
module_init(dm_crypt_init);
module_exit(dm_crypt_exit);
MODULE_AUTHOR("Jana Saout <jana@saout.de>"); MODULE_AUTHOR("Jana Saout <jana@saout.de>");
MODULE_DESCRIPTION(DM_NAME " target for transparent encryption / decryption"); MODULE_DESCRIPTION(DM_NAME " target for transparent encryption / decryption");
......
...@@ -367,20 +367,7 @@ static struct target_type delay_target = { ...@@ -367,20 +367,7 @@ static struct target_type delay_target = {
.status = delay_status, .status = delay_status,
.iterate_devices = delay_iterate_devices, .iterate_devices = delay_iterate_devices,
}; };
module_dm(delay);
static int __init dm_delay_init(void)
{
return dm_register_target(&delay_target);
}
static void __exit dm_delay_exit(void)
{
dm_unregister_target(&delay_target);
}
/* Module hooks */
module_init(dm_delay_init);
module_exit(dm_delay_exit);
MODULE_DESCRIPTION(DM_NAME " delay target"); MODULE_DESCRIPTION(DM_NAME " delay target");
MODULE_AUTHOR("Heinz Mauelshagen <mauelshagen@redhat.com>"); MODULE_AUTHOR("Heinz Mauelshagen <mauelshagen@redhat.com>");
......
...@@ -570,19 +570,7 @@ static struct target_type dust_target = { ...@@ -570,19 +570,7 @@ static struct target_type dust_target = {
.status = dust_status, .status = dust_status,
.prepare_ioctl = dust_prepare_ioctl, .prepare_ioctl = dust_prepare_ioctl,
}; };
module_dm(dust);
static int __init dm_dust_init(void)
{
return dm_register_target(&dust_target);
}
static void __exit dm_dust_exit(void)
{
dm_unregister_target(&dust_target);
}
module_init(dm_dust_init);
module_exit(dm_dust_exit);
MODULE_DESCRIPTION(DM_NAME " dust test target"); MODULE_DESCRIPTION(DM_NAME " dust test target");
MODULE_AUTHOR("Bryan Gurney <dm-devel@redhat.com>"); MODULE_AUTHOR("Bryan Gurney <dm-devel@redhat.com>");
......
...@@ -452,19 +452,7 @@ static struct target_type ebs_target = { ...@@ -452,19 +452,7 @@ static struct target_type ebs_target = {
.prepare_ioctl = ebs_prepare_ioctl, .prepare_ioctl = ebs_prepare_ioctl,
.iterate_devices = ebs_iterate_devices, .iterate_devices = ebs_iterate_devices,
}; };
module_dm(ebs);
static int __init dm_ebs_init(void)
{
return dm_register_target(&ebs_target);
}
static void dm_ebs_exit(void)
{
dm_unregister_target(&ebs_target);
}
module_init(dm_ebs_init);
module_exit(dm_ebs_exit);
MODULE_AUTHOR("Heinz Mauelshagen <dm-devel@redhat.com>"); MODULE_AUTHOR("Heinz Mauelshagen <dm-devel@redhat.com>");
MODULE_DESCRIPTION(DM_NAME " emulated block size target"); MODULE_DESCRIPTION(DM_NAME " emulated block size target");
......
...@@ -1753,19 +1753,7 @@ static struct target_type era_target = { ...@@ -1753,19 +1753,7 @@ static struct target_type era_target = {
.iterate_devices = era_iterate_devices, .iterate_devices = era_iterate_devices,
.io_hints = era_io_hints .io_hints = era_io_hints
}; };
module_dm(era);
static int __init dm_era_init(void)
{
return dm_register_target(&era_target);
}
static void __exit dm_era_exit(void)
{
dm_unregister_target(&era_target);
}
module_init(dm_era_init);
module_exit(dm_era_exit);
MODULE_DESCRIPTION(DM_NAME " era target"); MODULE_DESCRIPTION(DM_NAME " era target");
MODULE_AUTHOR("Joe Thornber <ejt@redhat.com>"); MODULE_AUTHOR("Joe Thornber <ejt@redhat.com>");
......
...@@ -506,20 +506,7 @@ static struct target_type flakey_target = { ...@@ -506,20 +506,7 @@ static struct target_type flakey_target = {
.prepare_ioctl = flakey_prepare_ioctl, .prepare_ioctl = flakey_prepare_ioctl,
.iterate_devices = flakey_iterate_devices, .iterate_devices = flakey_iterate_devices,
}; };
module_dm(flakey);
static int __init dm_flakey_init(void)
{
return dm_register_target(&flakey_target);
}
static void __exit dm_flakey_exit(void)
{
dm_unregister_target(&flakey_target);
}
/* Module hooks */
module_init(dm_flakey_init);
module_exit(dm_flakey_exit);
MODULE_DESCRIPTION(DM_NAME " flakey target"); MODULE_DESCRIPTION(DM_NAME " flakey target");
MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>"); MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
......
...@@ -937,19 +937,7 @@ static struct target_type log_writes_target = { ...@@ -937,19 +937,7 @@ static struct target_type log_writes_target = {
.dax_zero_page_range = log_writes_dax_zero_page_range, .dax_zero_page_range = log_writes_dax_zero_page_range,
.dax_recovery_write = log_writes_dax_recovery_write, .dax_recovery_write = log_writes_dax_recovery_write,
}; };
module_dm(log_writes);
static int __init dm_log_writes_init(void)
{
return dm_register_target(&log_writes_target);
}
static void __exit dm_log_writes_exit(void)
{
dm_unregister_target(&log_writes_target);
}
module_init(dm_log_writes_init);
module_exit(dm_log_writes_exit);
MODULE_DESCRIPTION(DM_NAME " log writes target"); MODULE_DESCRIPTION(DM_NAME " log writes target");
MODULE_AUTHOR("Josef Bacik <jbacik@fb.com>"); MODULE_AUTHOR("Josef Bacik <jbacik@fb.com>");
......
...@@ -4077,23 +4077,7 @@ static struct target_type raid_target = { ...@@ -4077,23 +4077,7 @@ static struct target_type raid_target = {
.preresume = raid_preresume, .preresume = raid_preresume,
.resume = raid_resume, .resume = raid_resume,
}; };
module_dm(raid);
static int __init dm_raid_init(void)
{
DMINFO("Loading target version %u.%u.%u",
raid_target.version[0],
raid_target.version[1],
raid_target.version[2]);
return dm_register_target(&raid_target);
}
static void __exit dm_raid_exit(void)
{
dm_unregister_target(&raid_target);
}
module_init(dm_raid_init);
module_exit(dm_raid_exit);
module_param(devices_handle_discard_safely, bool, 0644); module_param(devices_handle_discard_safely, bool, 0644);
MODULE_PARM_DESC(devices_handle_discard_safely, MODULE_PARM_DESC(devices_handle_discard_safely,
......
...@@ -565,19 +565,7 @@ static struct target_type switch_target = { ...@@ -565,19 +565,7 @@ static struct target_type switch_target = {
.prepare_ioctl = switch_prepare_ioctl, .prepare_ioctl = switch_prepare_ioctl,
.iterate_devices = switch_iterate_devices, .iterate_devices = switch_iterate_devices,
}; };
module_dm(switch);
static int __init dm_switch_init(void)
{
return dm_register_target(&switch_target);
}
static void __exit dm_switch_exit(void)
{
dm_unregister_target(&switch_target);
}
module_init(dm_switch_init);
module_exit(dm_switch_exit);
MODULE_DESCRIPTION(DM_NAME " dynamic path switching target"); MODULE_DESCRIPTION(DM_NAME " dynamic path switching target");
MODULE_AUTHOR("Kevin D. O'Kelley <Kevin_OKelley@dell.com>"); MODULE_AUTHOR("Kevin D. O'Kelley <Kevin_OKelley@dell.com>");
......
...@@ -192,19 +192,7 @@ static struct target_type unstripe_target = { ...@@ -192,19 +192,7 @@ static struct target_type unstripe_target = {
.iterate_devices = unstripe_iterate_devices, .iterate_devices = unstripe_iterate_devices,
.io_hints = unstripe_io_hints, .io_hints = unstripe_io_hints,
}; };
module_dm(unstripe);
static int __init dm_unstripe_init(void)
{
return dm_register_target(&unstripe_target);
}
static void __exit dm_unstripe_exit(void)
{
dm_unregister_target(&unstripe_target);
}
module_init(dm_unstripe_init);
module_exit(dm_unstripe_exit);
MODULE_DESCRIPTION(DM_NAME " unstriped target"); MODULE_DESCRIPTION(DM_NAME " unstriped target");
MODULE_ALIAS("dm-unstriped"); MODULE_ALIAS("dm-unstriped");
......
...@@ -1514,19 +1514,7 @@ static struct target_type verity_target = { ...@@ -1514,19 +1514,7 @@ static struct target_type verity_target = {
.iterate_devices = verity_iterate_devices, .iterate_devices = verity_iterate_devices,
.io_hints = verity_io_hints, .io_hints = verity_io_hints,
}; };
module_dm(verity);
static int __init dm_verity_init(void)
{
return dm_register_target(&verity_target);
}
static void __exit dm_verity_exit(void)
{
dm_unregister_target(&verity_target);
}
module_init(dm_verity_init);
module_exit(dm_verity_exit);
MODULE_AUTHOR("Mikulas Patocka <mpatocka@redhat.com>"); MODULE_AUTHOR("Mikulas Patocka <mpatocka@redhat.com>");
MODULE_AUTHOR("Mandeep Baines <msb@chromium.org>"); MODULE_AUTHOR("Mandeep Baines <msb@chromium.org>");
......
...@@ -2773,19 +2773,7 @@ static struct target_type writecache_target = { ...@@ -2773,19 +2773,7 @@ static struct target_type writecache_target = {
.iterate_devices = writecache_iterate_devices, .iterate_devices = writecache_iterate_devices,
.io_hints = writecache_io_hints, .io_hints = writecache_io_hints,
}; };
module_dm(writecache);
static int __init dm_writecache_init(void)
{
return dm_register_target(&writecache_target);
}
static void __exit dm_writecache_exit(void)
{
dm_unregister_target(&writecache_target);
}
module_init(dm_writecache_init);
module_exit(dm_writecache_exit);
MODULE_DESCRIPTION(DM_NAME " writecache target"); MODULE_DESCRIPTION(DM_NAME " writecache target");
MODULE_AUTHOR("Mikulas Patocka <dm-devel@redhat.com>"); MODULE_AUTHOR("Mikulas Patocka <dm-devel@redhat.com>");
......
...@@ -75,19 +75,7 @@ static struct target_type zero_target = { ...@@ -75,19 +75,7 @@ static struct target_type zero_target = {
.map = zero_map, .map = zero_map,
.io_hints = zero_io_hints, .io_hints = zero_io_hints,
}; };
module_dm(zero);
static int __init dm_zero_init(void)
{
return dm_register_target(&zero_target);
}
static void __exit dm_zero_exit(void)
{
dm_unregister_target(&zero_target);
}
module_init(dm_zero_init)
module_exit(dm_zero_exit)
MODULE_AUTHOR("Jana Saout <jana@saout.de>"); MODULE_AUTHOR("Jana Saout <jana@saout.de>");
MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros"); MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
......
...@@ -1138,7 +1138,7 @@ static int dmz_message(struct dm_target *ti, unsigned int argc, char **argv, ...@@ -1138,7 +1138,7 @@ static int dmz_message(struct dm_target *ti, unsigned int argc, char **argv,
return r; return r;
} }
static struct target_type dmz_type = { static struct target_type zoned_target = {
.name = "zoned", .name = "zoned",
.version = {2, 0, 0}, .version = {2, 0, 0},
.features = DM_TARGET_SINGLETON | DM_TARGET_MIXED_ZONED_MODEL, .features = DM_TARGET_SINGLETON | DM_TARGET_MIXED_ZONED_MODEL,
...@@ -1154,19 +1154,7 @@ static struct target_type dmz_type = { ...@@ -1154,19 +1154,7 @@ static struct target_type dmz_type = {
.status = dmz_status, .status = dmz_status,
.message = dmz_message, .message = dmz_message,
}; };
module_dm(zoned);
static int __init dmz_init(void)
{
return dm_register_target(&dmz_type);
}
static void __exit dmz_exit(void)
{
dm_unregister_target(&dmz_type);
}
module_init(dmz_init);
module_exit(dmz_exit);
MODULE_DESCRIPTION(DM_NAME " target for zoned block devices"); MODULE_DESCRIPTION(DM_NAME " target for zoned block devices");
MODULE_AUTHOR("Damien Le Moal <damien.lemoal@wdc.com>"); MODULE_AUTHOR("Damien Le Moal <damien.lemoal@wdc.com>");
......
...@@ -631,6 +631,26 @@ void dm_destroy_crypto_profile(struct blk_crypto_profile *profile); ...@@ -631,6 +631,26 @@ void dm_destroy_crypto_profile(struct blk_crypto_profile *profile);
DMEMIT("target_name=%s,target_version=%u.%u.%u", \ DMEMIT("target_name=%s,target_version=%u.%u.%u", \
(y)->name, (y)->version[0], (y)->version[1], (y)->version[2]) (y)->name, (y)->version[0], (y)->version[1], (y)->version[2])
/**
* module_dm() - Helper macro for DM targets that don't do anything
* special in their module_init and module_exit.
* Each module may only use this macro once, and calling it replaces
* module_init() and module_exit().
*
* @name: DM target's name
*/
#define module_dm(name) \
static int __init dm_##name##_init(void) \
{ \
return dm_register_target(&(name##_target)); \
} \
module_init(dm_##name##_init) \
static void __exit dm_##name##_exit(void) \
{ \
dm_unregister_target(&(name##_target)); \
} \
module_exit(dm_##name##_exit)
/* /*
* Definitions of return values from target end_io function. * Definitions of return values from target end_io function.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment