linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] raid5: refactor raid5 personality definition
@ 2020-09-21  6:38 Jason Yan
  2020-09-29  1:03 ` Jason Yan
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Yan @ 2020-09-21  6:38 UTC (permalink / raw)
  To: song, yuyufen, linux-raid; +Cc: Jason Yan

The definition of md personality for raid4/raid5/raid6 is almost the same.
So introduce a macro 'RAID5_PERSONALITY_ATTR' to help define the
personality. This can help us reduce some duplicated code.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
---
 drivers/md/raid5.c | 104 ++++++++++++++-------------------------------
 1 file changed, 31 insertions(+), 73 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 225380efd1e2..b56ebc45fb53 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -8492,79 +8492,37 @@ static int raid5_start(struct mddev *mddev)
 	return r5l_start(conf->log);
 }
 
-static struct md_personality raid6_personality =
-{
-	.name		= "raid6",
-	.level		= 6,
-	.owner		= THIS_MODULE,
-	.make_request	= raid5_make_request,
-	.run		= raid5_run,
-	.start		= raid5_start,
-	.free		= raid5_free,
-	.status		= raid5_status,
-	.error_handler	= raid5_error,
-	.hot_add_disk	= raid5_add_disk,
-	.hot_remove_disk= raid5_remove_disk,
-	.spare_active	= raid5_spare_active,
-	.sync_request	= raid5_sync_request,
-	.resize		= raid5_resize,
-	.size		= raid5_size,
-	.check_reshape	= raid6_check_reshape,
-	.start_reshape  = raid5_start_reshape,
-	.finish_reshape = raid5_finish_reshape,
-	.quiesce	= raid5_quiesce,
-	.takeover	= raid6_takeover,
-	.change_consistency_policy = raid5_change_consistency_policy,
-};
-static struct md_personality raid5_personality =
-{
-	.name		= "raid5",
-	.level		= 5,
-	.owner		= THIS_MODULE,
-	.make_request	= raid5_make_request,
-	.run		= raid5_run,
-	.start		= raid5_start,
-	.free		= raid5_free,
-	.status		= raid5_status,
-	.error_handler	= raid5_error,
-	.hot_add_disk	= raid5_add_disk,
-	.hot_remove_disk= raid5_remove_disk,
-	.spare_active	= raid5_spare_active,
-	.sync_request	= raid5_sync_request,
-	.resize		= raid5_resize,
-	.size		= raid5_size,
-	.check_reshape	= raid5_check_reshape,
-	.start_reshape  = raid5_start_reshape,
-	.finish_reshape = raid5_finish_reshape,
-	.quiesce	= raid5_quiesce,
-	.takeover	= raid5_takeover,
-	.change_consistency_policy = raid5_change_consistency_policy,
-};
-
-static struct md_personality raid4_personality =
-{
-	.name		= "raid4",
-	.level		= 4,
-	.owner		= THIS_MODULE,
-	.make_request	= raid5_make_request,
-	.run		= raid5_run,
-	.start		= raid5_start,
-	.free		= raid5_free,
-	.status		= raid5_status,
-	.error_handler	= raid5_error,
-	.hot_add_disk	= raid5_add_disk,
-	.hot_remove_disk= raid5_remove_disk,
-	.spare_active	= raid5_spare_active,
-	.sync_request	= raid5_sync_request,
-	.resize		= raid5_resize,
-	.size		= raid5_size,
-	.check_reshape	= raid5_check_reshape,
-	.start_reshape  = raid5_start_reshape,
-	.finish_reshape = raid5_finish_reshape,
-	.quiesce	= raid5_quiesce,
-	.takeover	= raid4_takeover,
-	.change_consistency_policy = raid5_change_consistency_policy,
-};
+#define RAID5_PERSONALITY_ATTR(__name, __level)			\
+static struct md_personality __name##_personality =		\
+{								\
+	.name		= #__name,				\
+	.level		= __level,				\
+	.owner		= THIS_MODULE,				\
+	.make_request	= raid5_make_request,			\
+	.run		= raid5_run,				\
+	.start		= raid5_start,				\
+	.free		= raid5_free,				\
+	.status		= raid5_status,				\
+	.error_handler	= raid5_error,				\
+	.hot_add_disk	= raid5_add_disk,			\
+	.hot_remove_disk= raid5_remove_disk,			\
+	.spare_active	= raid5_spare_active,			\
+	.sync_request	= raid5_sync_request,			\
+	.resize		= raid5_resize,				\
+	.size		= raid5_size,				\
+	.start_reshape  = raid5_start_reshape,			\
+	.finish_reshape = raid5_finish_reshape,			\
+	.quiesce	= raid5_quiesce,			\
+	.change_consistency_policy = raid5_change_consistency_policy,	\
+	.check_reshape	= __name##_check_reshape,		\
+	.takeover	= __name##_takeover,			\
+}
+
+#define raid4_check_reshape raid5_check_reshape
+
+RAID5_PERSONALITY_ATTR(raid4, 4);
+RAID5_PERSONALITY_ATTR(raid5, 5);
+RAID5_PERSONALITY_ATTR(raid6, 6);
 
 static int __init raid5_init(void)
 {
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] raid5: refactor raid5 personality definition
  2020-09-21  6:38 [PATCH] raid5: refactor raid5 personality definition Jason Yan
@ 2020-09-29  1:03 ` Jason Yan
  2020-09-30 22:44   ` Song Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Yan @ 2020-09-29  1:03 UTC (permalink / raw)
  To: song, yuyufen, linux-raid

Hi all, any comments?

在 2020/9/21 14:38, Jason Yan 写道:
> The definition of md personality for raid4/raid5/raid6 is almost the same.
> So introduce a macro 'RAID5_PERSONALITY_ATTR' to help define the
> personality. This can help us reduce some duplicated code.
> 
> Signed-off-by: Jason Yan <yanaijie@huawei.com>
> ---
>   drivers/md/raid5.c | 104 ++++++++++++++-------------------------------
>   1 file changed, 31 insertions(+), 73 deletions(-)
> 
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index 225380efd1e2..b56ebc45fb53 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -8492,79 +8492,37 @@ static int raid5_start(struct mddev *mddev)
>   	return r5l_start(conf->log);
>   }
>   
> -static struct md_personality raid6_personality =
> -{
> -	.name		= "raid6",
> -	.level		= 6,
> -	.owner		= THIS_MODULE,
> -	.make_request	= raid5_make_request,
> -	.run		= raid5_run,
> -	.start		= raid5_start,
> -	.free		= raid5_free,
> -	.status		= raid5_status,
> -	.error_handler	= raid5_error,
> -	.hot_add_disk	= raid5_add_disk,
> -	.hot_remove_disk= raid5_remove_disk,
> -	.spare_active	= raid5_spare_active,
> -	.sync_request	= raid5_sync_request,
> -	.resize		= raid5_resize,
> -	.size		= raid5_size,
> -	.check_reshape	= raid6_check_reshape,
> -	.start_reshape  = raid5_start_reshape,
> -	.finish_reshape = raid5_finish_reshape,
> -	.quiesce	= raid5_quiesce,
> -	.takeover	= raid6_takeover,
> -	.change_consistency_policy = raid5_change_consistency_policy,
> -};
> -static struct md_personality raid5_personality =
> -{
> -	.name		= "raid5",
> -	.level		= 5,
> -	.owner		= THIS_MODULE,
> -	.make_request	= raid5_make_request,
> -	.run		= raid5_run,
> -	.start		= raid5_start,
> -	.free		= raid5_free,
> -	.status		= raid5_status,
> -	.error_handler	= raid5_error,
> -	.hot_add_disk	= raid5_add_disk,
> -	.hot_remove_disk= raid5_remove_disk,
> -	.spare_active	= raid5_spare_active,
> -	.sync_request	= raid5_sync_request,
> -	.resize		= raid5_resize,
> -	.size		= raid5_size,
> -	.check_reshape	= raid5_check_reshape,
> -	.start_reshape  = raid5_start_reshape,
> -	.finish_reshape = raid5_finish_reshape,
> -	.quiesce	= raid5_quiesce,
> -	.takeover	= raid5_takeover,
> -	.change_consistency_policy = raid5_change_consistency_policy,
> -};
> -
> -static struct md_personality raid4_personality =
> -{
> -	.name		= "raid4",
> -	.level		= 4,
> -	.owner		= THIS_MODULE,
> -	.make_request	= raid5_make_request,
> -	.run		= raid5_run,
> -	.start		= raid5_start,
> -	.free		= raid5_free,
> -	.status		= raid5_status,
> -	.error_handler	= raid5_error,
> -	.hot_add_disk	= raid5_add_disk,
> -	.hot_remove_disk= raid5_remove_disk,
> -	.spare_active	= raid5_spare_active,
> -	.sync_request	= raid5_sync_request,
> -	.resize		= raid5_resize,
> -	.size		= raid5_size,
> -	.check_reshape	= raid5_check_reshape,
> -	.start_reshape  = raid5_start_reshape,
> -	.finish_reshape = raid5_finish_reshape,
> -	.quiesce	= raid5_quiesce,
> -	.takeover	= raid4_takeover,
> -	.change_consistency_policy = raid5_change_consistency_policy,
> -};
> +#define RAID5_PERSONALITY_ATTR(__name, __level)			\
> +static struct md_personality __name##_personality =		\
> +{								\
> +	.name		= #__name,				\
> +	.level		= __level,				\
> +	.owner		= THIS_MODULE,				\
> +	.make_request	= raid5_make_request,			\
> +	.run		= raid5_run,				\
> +	.start		= raid5_start,				\
> +	.free		= raid5_free,				\
> +	.status		= raid5_status,				\
> +	.error_handler	= raid5_error,				\
> +	.hot_add_disk	= raid5_add_disk,			\
> +	.hot_remove_disk= raid5_remove_disk,			\
> +	.spare_active	= raid5_spare_active,			\
> +	.sync_request	= raid5_sync_request,			\
> +	.resize		= raid5_resize,				\
> +	.size		= raid5_size,				\
> +	.start_reshape  = raid5_start_reshape,			\
> +	.finish_reshape = raid5_finish_reshape,			\
> +	.quiesce	= raid5_quiesce,			\
> +	.change_consistency_policy = raid5_change_consistency_policy,	\
> +	.check_reshape	= __name##_check_reshape,		\
> +	.takeover	= __name##_takeover,			\
> +}
> +
> +#define raid4_check_reshape raid5_check_reshape
> +
> +RAID5_PERSONALITY_ATTR(raid4, 4);
> +RAID5_PERSONALITY_ATTR(raid5, 5);
> +RAID5_PERSONALITY_ATTR(raid6, 6);
>   
>   static int __init raid5_init(void)
>   {
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] raid5: refactor raid5 personality definition
  2020-09-29  1:03 ` Jason Yan
@ 2020-09-30 22:44   ` Song Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Song Liu @ 2020-09-30 22:44 UTC (permalink / raw)
  To: Jason Yan; +Cc: Yufen Yu, linux-raid

On Mon, Sep 28, 2020 at 6:03 PM Jason Yan <yanaijie@huawei.com> wrote:
>
> Hi all, any comments?

Sorry for the late reply. I somehow missed the first email.

>
> 在 2020/9/21 14:38, Jason Yan 写道:
> > The definition of md personality for raid4/raid5/raid6 is almost the same.
> > So introduce a macro 'RAID5_PERSONALITY_ATTR' to help define the
> > personality. This can help us reduce some duplicated code.
> >
> > Signed-off-by: Jason Yan <yanaijie@huawei.com>
[...]
> > +}
> > +
> > +#define raid4_check_reshape raid5_check_reshape
> > +
> > +RAID5_PERSONALITY_ATTR(raid4, 4);
> > +RAID5_PERSONALITY_ATTR(raid5, 5);
> > +RAID5_PERSONALITY_ATTR(raid6, 6);

I don't think we benefit much from this change. It doesn't make the code
easier to read. Instead, this change adds another level of marco to the code.
I would rather keep this code as-is.

Thanks,
Song

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-30 22:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21  6:38 [PATCH] raid5: refactor raid5 personality definition Jason Yan
2020-09-29  1:03 ` Jason Yan
2020-09-30 22:44   ` Song Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).