There are several instances where magic numbers are used in md.c instead
of the defined constants in md_p.h. This patch set improves code
readability by replacing all occurrences of 0xffff, 0xfffe, and 0xfffd when
relating to md roles with their equivalent defined constant.
Signed-off-by: David Sloan <[email protected]>
Reviewed-by: Logan Gunthorpe <[email protected]>
---
drivers/md/md.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 309b3af906ad..b34b72fc5887 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2645,11 +2645,12 @@ static bool does_sb_need_changing(struct mddev *mddev)
rdev_for_each(rdev, mddev) {
role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]);
/* Device activated? */
- if (role == 0xffff && rdev->raid_disk >=0 &&
+ if (role == MD_DISK_ROLE_SPARE && rdev->raid_disk >= 0 &&
!test_bit(Faulty, &rdev->flags))
return true;
/* Device turned faulty? */
- if (test_bit(Faulty, &rdev->flags) && (role < 0xfffd))
+ if (test_bit(Faulty, &rdev->flags) &&
+ role < MD_DISK_ROLE_JOURNAL)
return true;
}
@@ -9671,7 +9672,7 @@ static void check_sb_changes(struct mddev *mddev, struct md_rdev *rdev)
role = le16_to_cpu(sb->dev_roles[rdev2->desc_nr]);
if (test_bit(Candidate, &rdev2->flags)) {
- if (role == 0xfffe) {
+ if (role == MD_DISK_ROLE_FAULTY) {
pr_info("md: Removing Candidate device %s because add failed\n", bdevname(rdev2->bdev,b));
md_kick_rdev_from_array(rdev2);
continue;
@@ -9684,7 +9685,8 @@ static void check_sb_changes(struct mddev *mddev, struct md_rdev *rdev)
/*
* got activated except reshape is happening.
*/
- if (rdev2->raid_disk == -1 && role != 0xffff &&
+ if (rdev2->raid_disk == -1 &&
+ role != MD_DISK_ROLE_SPARE &&
!(le32_to_cpu(sb->feature_map) &
MD_FEATURE_RESHAPE_ACTIVE)) {
rdev2->saved_raid_disk = role;
@@ -9701,7 +9703,8 @@ static void check_sb_changes(struct mddev *mddev, struct md_rdev *rdev)
* as faulty. The recovery is performed by the
* one who initiated the error.
*/
- if ((role == 0xfffe) || (role == 0xfffd)) {
+ if (role == MD_DISK_ROLE_FAULTY ||
+ role == MD_DISK_ROLE_JOURNAL) {
md_error(mddev, rdev2);
clear_bit(Blocked, &rdev2->flags);
}
base-commit: b2d229d4ddb17db541098b83524d901257e93845
--
2.17.1
On Thu, Apr 21, 2022 at 12:46 PM David Sloan <[email protected]> wrote:
>
> There are several instances where magic numbers are used in md.c instead
> of the defined constants in md_p.h. This patch set improves code
> readability by replacing all occurrences of 0xffff, 0xfffe, and 0xfffd when
> relating to md roles with their equivalent defined constant.
>
> Signed-off-by: David Sloan <[email protected]>
> Reviewed-by: Logan Gunthorpe <[email protected]>
Thanks for the clean up!
> ---
> drivers/md/md.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 309b3af906ad..b34b72fc5887 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -2645,11 +2645,12 @@ static bool does_sb_need_changing(struct mddev *mddev)
> rdev_for_each(rdev, mddev) {
> role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]);
> /* Device activated? */
> - if (role == 0xffff && rdev->raid_disk >=0 &&
> + if (role == MD_DISK_ROLE_SPARE && rdev->raid_disk >= 0 &&
> !test_bit(Faulty, &rdev->flags))
> return true;
> /* Device turned faulty? */
> - if (test_bit(Faulty, &rdev->flags) && (role < 0xfffd))
> + if (test_bit(Faulty, &rdev->flags) &&
> + role < MD_DISK_ROLE_JOURNAL)
I changed this to role < MD_DISK_ROLE_MAX.
Also made some minor style changes, and applied it to md-next.
Thanks,
Song
> return true;
> }
[...]