Skip to content

Commit bac624f

Browse files
liu-song-6NeilBrown
authored andcommitted
MD: add a new disk role to present write journal device
Next patches will use a disk as raid5/6 journaling. We need a new disk role to present the journal device and add MD_FEATURE_JOURNAL to feature_map for backward compability. Signed-off-by: Song Liu <songliubraving@fb.com> Signed-off-by: Shaohua Li <shli@fb.com> Signed-off-by: NeilBrown <neilb@suse.com>
1 parent c4d4c91 commit bac624f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

drivers/md/md.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,15 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *rdev)
16381638
case MD_DISK_ROLE_FAULTY: /* faulty */
16391639
set_bit(Faulty, &rdev->flags);
16401640
break;
1641+
case MD_DISK_ROLE_JOURNAL: /* journal device */
1642+
if (!(le32_to_cpu(sb->feature_map) & MD_FEATURE_JOURNAL)) {
1643+
/* journal device without journal feature */
1644+
printk(KERN_WARNING
1645+
"md: journal device provided without journal feature, ignoring the device\n");
1646+
return -EINVAL;
1647+
}
1648+
set_bit(Journal, &rdev->flags);
1649+
break;
16411650
default:
16421651
rdev->saved_raid_disk = role;
16431652
if ((le32_to_cpu(sb->feature_map) &
@@ -1796,7 +1805,10 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
17961805
sb->dev_roles[i] = cpu_to_le16(MD_DISK_ROLE_FAULTY);
17971806
else if (test_bit(In_sync, &rdev2->flags))
17981807
sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk);
1799-
else if (rdev2->raid_disk >= 0)
1808+
else if (test_bit(Journal, &rdev2->flags)) {
1809+
sb->dev_roles[i] = cpu_to_le16(MD_DISK_ROLE_JOURNAL);
1810+
sb->feature_map |= cpu_to_le32(MD_FEATURE_JOURNAL);
1811+
} else if (rdev2->raid_disk >= 0)
18001812
sb->dev_roles[i] = cpu_to_le16(rdev2->raid_disk);
18011813
else
18021814
sb->dev_roles[i] = cpu_to_le16(MD_DISK_ROLE_SPARE);
@@ -5840,7 +5852,8 @@ static int get_disk_info(struct mddev *mddev, void __user * arg)
58405852
else if (test_bit(In_sync, &rdev->flags)) {
58415853
info.state |= (1<<MD_DISK_ACTIVE);
58425854
info.state |= (1<<MD_DISK_SYNC);
5843-
}
5855+
} else if (test_bit(Journal, &rdev->flags))
5856+
info.state |= (1<<MD_DISK_JOURNAL);
58445857
if (test_bit(WriteMostly, &rdev->flags))
58455858
info.state |= (1<<MD_DISK_WRITEMOSTLY);
58465859
} else {
@@ -5955,6 +5968,8 @@ static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info)
59555968
else
59565969
clear_bit(WriteMostly, &rdev->flags);
59575970

5971+
if (info->state & (1<<MD_DISK_JOURNAL))
5972+
set_bit(Journal, &rdev->flags);
59585973
/*
59595974
* check whether the device shows up in other nodes
59605975
*/
@@ -7330,6 +7345,10 @@ static int md_seq_show(struct seq_file *seq, void *v)
73307345
seq_printf(seq, "(F)");
73317346
continue;
73327347
}
7348+
if (test_bit(Journal, &rdev->flags)) {
7349+
seq_printf(seq, "(J)");
7350+
continue;
7351+
}
73337352
if (rdev->raid_disk < 0)
73347353
seq_printf(seq, "(S)"); /* spare */
73357354
if (test_bit(Replacement, &rdev->flags))

drivers/md/md.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ enum flag_bits {
172172
* This device is seen locally but not
173173
* by the whole cluster
174174
*/
175+
Journal, /* This device is used as journal for
176+
* raid-5/6.
177+
* Usually, this device should be faster
178+
* than other devices in the array
179+
*/
175180
};
176181

177182
#define BB_LEN_MASK (0x00000000000001FFULL)

include/uapi/linux/raid/md_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@
8989
* read requests will only be sent here in
9090
* dire need
9191
*/
92+
#define MD_DISK_JOURNAL 18 /* disk is used as the write journal in RAID-5/6 */
9293

9394
#define MD_DISK_ROLE_SPARE 0xffff
9495
#define MD_DISK_ROLE_FAULTY 0xfffe
96+
#define MD_DISK_ROLE_JOURNAL 0xfffd
9597
#define MD_DISK_ROLE_MAX 0xff00 /* max value of regular disk role */
9698

9799
typedef struct mdp_device_descriptor_s {
@@ -307,6 +309,7 @@ struct mdp_superblock_1 {
307309
* is guided by bitmap.
308310
*/
309311
#define MD_FEATURE_CLUSTERED 256 /* clustered MD */
312+
#define MD_FEATURE_JOURNAL 512 /* support write cache */
310313
#define MD_FEATURE_ALL (MD_FEATURE_BITMAP_OFFSET \
311314
|MD_FEATURE_RECOVERY_OFFSET \
312315
|MD_FEATURE_RESHAPE_ACTIVE \

0 commit comments

Comments
 (0)