MD: replace special disk roles with macros
authorSong Liu <songliubraving@fb.com>
Thu, 13 Aug 2015 21:31:54 +0000 (14:31 -0700)
committerNeilBrown <neilb@suse.com>
Sat, 24 Oct 2015 06:16:18 +0000 (17:16 +1100)
Add the following two macros for special roles: spare and faulty

MD_DISK_ROLE_SPARE 0xffff
MD_DISK_ROLE_FAULTY 0xfffe

Add MD_DISK_ROLE_MAX 0xff00 as the maximal possible regular role,
and minimal value of special role.

Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Shaohua Li <shli@fb.com>
Signed-off-by: NeilBrown <neilb@suse.com>
drivers/md/md.c
include/uapi/linux/raid/md_p.h

index 44d03424672365debb3091ac432eb15fedd9f641..cfe5c8704a26268c41597d9a86bd483f6d733d6a 100644 (file)
@@ -1608,7 +1608,7 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *rdev)
                ++ev1;
                if (rdev->desc_nr >= 0 &&
                    rdev->desc_nr < le32_to_cpu(sb->max_dev) &&
-                   le16_to_cpu(sb->dev_roles[rdev->desc_nr]) < 0xfffe)
+                   le16_to_cpu(sb->dev_roles[rdev->desc_nr]) < MD_DISK_ROLE_MAX)
                        if (ev1 < mddev->events)
                                return -EINVAL;
        } else if (mddev->bitmap) {
@@ -1628,14 +1628,14 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *rdev)
                int role;
                if (rdev->desc_nr < 0 ||
                    rdev->desc_nr >= le32_to_cpu(sb->max_dev)) {
-                       role = 0xffff;
+                       role = MD_DISK_ROLE_SPARE;
                        rdev->desc_nr = -1;
                } else
                        role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]);
                switch(role) {
-               case 0xffff: /* spare */
+               case MD_DISK_ROLE_SPARE: /* spare */
                        break;
-               case 0xfffe: /* faulty */
+               case MD_DISK_ROLE_FAULTY: /* faulty */
                        set_bit(Faulty, &rdev->flags);
                        break;
                default:
@@ -1788,18 +1788,18 @@ retry:
                max_dev = le32_to_cpu(sb->max_dev);
 
        for (i=0; i<max_dev;i++)
-               sb->dev_roles[i] = cpu_to_le16(0xfffe);
+               sb->dev_roles[i] = cpu_to_le16(MD_DISK_ROLE_FAULTY);
 
        rdev_for_each(rdev2, mddev) {
                i = rdev2->desc_nr;
                if (test_bit(Faulty, &rdev2->flags))
-                       sb->dev_roles[i] = cpu_to_le16(0xfffe);
+                       sb->dev_roles[i] = cpu_to_le16(MD_DISK_ROLE_FAULTY);
                else if (test_bit(In_sync, &rdev2->flags))
                        sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk);
                else if (rdev2->raid_disk >= 0)
                        sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk);
                else
-                       sb->dev_roles[i] = cpu_to_le16(0xffff);
+                       sb->dev_roles[i] = cpu_to_le16(MD_DISK_ROLE_SPARE);
        }
 
        sb->sb_csum = calc_sb_1_csum(sb);
index 867ee874fa80f9b25eb13ed112e9ccc80657b5c2..d1fc8a637368ac704bccbdc094ad0c825293a1cf 100644 (file)
                                   * dire need
                                   */
 
+#define MD_DISK_ROLE_SPARE     0xffff
+#define MD_DISK_ROLE_FAULTY    0xfffe
+#define MD_DISK_ROLE_MAX       0xff00 /* max value of regular disk role */
+
 typedef struct mdp_device_descriptor_s {
        __u32 number;           /* 0 Device number in the entire set          */
        __u32 major;            /* 1 Device major number                      */