Re: [PATCH] raid5: refactor raid5 personality definition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
  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)
  {




[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux