Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

md-cluster: add the support for resize

To update size for cluster raid, we need to make
sure all nodes can perform the change successfully.
However, it is possible that some of them can't do
it due to failure (bitmap_resize could fail). So
we need to consider the issue before we set the
capacity unconditionally, and we use below steps
to perform sanity check.

1. A change the size, then broadcast METADATA_UPDATED
msg.
2. B and C receive METADATA_UPDATED change the size
excepts call set_capacity, sync_size is not update
if the change failed. Also call bitmap_update_sb
to sync sb to disk.
3. A checks other node's sync_size, if sync_size has
been updated in all nodes, then send CHANGE_CAPACITY
msg otherwise send msg to revert previous change.
4. B and C call set_capacity if receive CHANGE_CAPACITY
msg, otherwise pers->resize will be called to restore
the old value.

Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>

authored by

Guoqing Jiang and committed by
Shaohua Li
818da59f b98938d1

+94 -6
+1 -1
Documentation/md/md-cluster.txt
··· 321 321 322 322 There are somethings which are not supported by cluster MD yet. 323 323 324 - - update size and change array_sectors. 324 + - change array_sectors.
+76
drivers/md/md-cluster.c
··· 1151 1151 return (my_sync_size == sync_size) ? 0 : -1; 1152 1152 } 1153 1153 1154 + /* 1155 + * Update the size for cluster raid is a little more complex, we perform it 1156 + * by the steps: 1157 + * 1. hold token lock and update superblock in initiator node. 1158 + * 2. send METADATA_UPDATED msg to other nodes. 1159 + * 3. The initiator node continues to check each bitmap's sync_size, if all 1160 + * bitmaps have the same value of sync_size, then we can set capacity and 1161 + * let other nodes to perform it. If one node can't update sync_size 1162 + * accordingly, we need to revert to previous value. 1163 + */ 1164 + static void update_size(struct mddev *mddev, sector_t old_dev_sectors) 1165 + { 1166 + struct md_cluster_info *cinfo = mddev->cluster_info; 1167 + struct cluster_msg cmsg; 1168 + struct md_rdev *rdev; 1169 + int ret = 0; 1170 + int raid_slot = -1; 1171 + 1172 + md_update_sb(mddev, 1); 1173 + lock_comm(cinfo, 1); 1174 + 1175 + memset(&cmsg, 0, sizeof(cmsg)); 1176 + cmsg.type = cpu_to_le32(METADATA_UPDATED); 1177 + rdev_for_each(rdev, mddev) 1178 + if (rdev->raid_disk >= 0 && !test_bit(Faulty, &rdev->flags)) { 1179 + raid_slot = rdev->desc_nr; 1180 + break; 1181 + } 1182 + if (raid_slot >= 0) { 1183 + cmsg.raid_slot = cpu_to_le32(raid_slot); 1184 + /* 1185 + * We can only change capiticy after all the nodes can do it, 1186 + * so need to wait after other nodes already received the msg 1187 + * and handled the change 1188 + */ 1189 + ret = __sendmsg(cinfo, &cmsg); 1190 + if (ret) { 1191 + pr_err("%s:%d: failed to send METADATA_UPDATED msg\n", 1192 + __func__, __LINE__); 1193 + unlock_comm(cinfo); 1194 + return; 1195 + } 1196 + } else { 1197 + pr_err("md-cluster: No good device id found to send\n"); 1198 + unlock_comm(cinfo); 1199 + return; 1200 + } 1201 + 1202 + /* 1203 + * check the sync_size from other node's bitmap, if sync_size 1204 + * have already updated in other nodes as expected, send an 1205 + * empty metadata msg to permit the change of capacity 1206 + */ 1207 + if (cluster_check_sync_size(mddev) == 0) { 1208 + memset(&cmsg, 0, sizeof(cmsg)); 1209 + cmsg.type = cpu_to_le32(CHANGE_CAPACITY); 1210 + ret = __sendmsg(cinfo, &cmsg); 1211 + if (ret) 1212 + pr_err("%s:%d: failed to send CHANGE_CAPACITY msg\n", 1213 + __func__, __LINE__); 1214 + set_capacity(mddev->gendisk, mddev->array_sectors); 1215 + revalidate_disk(mddev->gendisk); 1216 + } else { 1217 + /* revert to previous sectors */ 1218 + ret = mddev->pers->resize(mddev, old_dev_sectors); 1219 + if (!ret) 1220 + revalidate_disk(mddev->gendisk); 1221 + ret = __sendmsg(cinfo, &cmsg); 1222 + if (ret) 1223 + pr_err("%s:%d: failed to send METADATA_UPDATED msg\n", 1224 + __func__, __LINE__); 1225 + } 1226 + unlock_comm(cinfo); 1227 + } 1228 + 1154 1229 static int resync_start(struct mddev *mddev) 1155 1230 { 1156 1231 struct md_cluster_info *cinfo = mddev->cluster_info; ··· 1471 1396 .gather_bitmaps = gather_bitmaps, 1472 1397 .lock_all_bitmaps = lock_all_bitmaps, 1473 1398 .unlock_all_bitmaps = unlock_all_bitmaps, 1399 + .update_size = update_size, 1474 1400 }; 1475 1401 1476 1402 static int __init cluster_init(void)
+1
drivers/md/md-cluster.h
··· 27 27 int (*gather_bitmaps)(struct md_rdev *rdev); 28 28 int (*lock_all_bitmaps)(struct mddev *mddev); 29 29 void (*unlock_all_bitmaps)(struct mddev *mddev); 30 + void (*update_size)(struct mddev *mddev, sector_t old_dev_sectors); 30 31 }; 31 32 32 33 #endif /* _MD_CLUSTER_H */
+16 -5
drivers/md/md.c
··· 6493 6493 struct md_rdev *rdev; 6494 6494 int rv; 6495 6495 int fit = (num_sectors == 0); 6496 - 6497 - /* cluster raid doesn't support update size */ 6498 - if (mddev_is_clustered(mddev)) 6499 - return -EINVAL; 6496 + sector_t old_dev_sectors = mddev->dev_sectors; 6500 6497 6501 6498 if (mddev->pers->resize == NULL) 6502 6499 return -EINVAL; ··· 6522 6525 } 6523 6526 rv = mddev->pers->resize(mddev, num_sectors); 6524 6527 if (!rv) { 6525 - if (mddev->queue) { 6528 + if (mddev_is_clustered(mddev)) 6529 + md_cluster_ops->update_size(mddev, old_dev_sectors); 6530 + else if (mddev->queue) { 6526 6531 set_capacity(mddev->gendisk, mddev->array_sectors); 6527 6532 revalidate_disk(mddev->gendisk); 6528 6533 } ··· 8741 8742 struct md_rdev *rdev2; 8742 8743 int role, ret; 8743 8744 char b[BDEVNAME_SIZE]; 8745 + 8746 + /* 8747 + * If size is changed in another node then we need to 8748 + * do resize as well. 8749 + */ 8750 + if (mddev->dev_sectors != le64_to_cpu(sb->size)) { 8751 + ret = mddev->pers->resize(mddev, le64_to_cpu(sb->size)); 8752 + if (ret) 8753 + pr_info("md-cluster: resize failed\n"); 8754 + else 8755 + bitmap_update_sb(mddev->bitmap); 8756 + } 8744 8757 8745 8758 /* Check for change of roles in the active devices */ 8746 8759 rdev_for_each(rdev2, mddev) {