History

Merge branch 'md-next' of git://github.com/goldwynr/linux into for-next

md-cluster: A better way for METADATA_UPDATED processing The processing of METADATA_UPDATED message is too simple and prone to errors. Besides, it would not update the internal data structures as required. This set of patches reads the superblock from one of the device of the MD and checks for changes in the in-memory data structures. If there is a change, it performs the necessary actions to keep the internal data structures as it would be in the primary node. An example is if a devices turns faulty. The algorithm is: 1. The initiator node marks the device as faulty and updates the superblock 2. The initiator node sends METADATA_UPDATED with an advisory device number to the rest of the nodes. 3. The receiving node on receiving the METADATA_UPDATED message 3.1 Reads the superblock 3.2 Detects a device has failed by comparing with memory structure 3.3 Calls the necessary functions to record the failure and get the device out of the active array. 3.4 Acknowledges the message. The patch series also fixes adding the disk which was impacted because of the changes. Patches can also be found at https://github.com/goldwynr/linux branch md-next Changes since V2: - Fix status synchrnoization after --add and --re-add operations - Included Guoqing's patches on endian correctness, zeroing cmsg etc - Restructure add_new_disk() and cancel()

NeilBrown committed 11 years ago

Commit c2a06c32 parents 25cb62b 23b63f911 files · +421 −214Browse files

Unified · Split

11 files
  1. drivers/md/bitmap.c +6 −8
  2. drivers/md/bitmap.h +3 −1
  3. drivers/md/md-cluster.c +114 −84
  4. drivers/md/md-cluster.h +6 −6
  5. drivers/md/md.c +248 −111
  6. drivers/md/md.h +1 −1
  7. drivers/md/raid1.c +32 −1
  8. drivers/md/raid1.h +7 −0
  9. drivers/md/raid10.c +1 −1
  10. drivers/md/raid5.c +1 −1
  11. include/uapi/linux/raid/md_p.h +2 −0
drivers/md/bitmap.c+6−8
@@ -613,12 +613,10 @@ re_read: · 612 unmodified lines
613613 daemon_sleep = le32_to_cpu(sb->daemon_sleep) * HZ;
614614 write_behind = le32_to_cpu(sb->write_behind);
615615 sectors_reserved = le32_to_cpu(sb->sectors_reserved);
616− /* XXX: This is a hack to ensure that we don't use clustering
617− * in case:
618− * - dm-raid is in use and
619− * - the nodes written in bitmap_sb is erroneous.
616+ /* Setup nodes/clustername only if bitmap version is
617+ * cluster-compatible
620618 */
621− if (!bitmap->mddev->sync_super) {
619+ if (sb->version == cpu_to_le32(BITMAP_MAJOR_CLUSTERED)) {
622620 nodes = le32_to_cpu(sb->nodes);
623621 strlcpy(bitmap->mddev->bitmap_info.cluster_name,
624622 sb->cluster_name, 64);
@@ -628,7 +626,7 @@ re_read: · 3 unmodified lines
628626 if (sb->magic != cpu_to_le32(BITMAP_MAGIC))
629627 reason = "bad magic";
630628 else if (le32_to_cpu(sb->version) < BITMAP_MAJOR_LO ||
631− le32_to_cpu(sb->version) > BITMAP_MAJOR_HI)
629+ le32_to_cpu(sb->version) > BITMAP_MAJOR_CLUSTERED)
632630 reason = "unrecognized superblock version";
633631 else if (chunksize < 512)
634632 reason = "bitmap chunksize too small";
@@ -1572,7 +1570,7 @@ void bitmap_close_sync(struct bitmap *bitmap) · 937 unmodified lines
15721570 }
15731571 EXPORT_SYMBOL(bitmap_close_sync);
15741572
1575−void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector)
1573+void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force)
15761574 {
15771575 sector_t s = 0;
15781576 sector_t blocks;
@@ -1583,7 +1581,7 @@ void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector) · 4 unmodified lines
15831581 bitmap->last_end_sync = jiffies;
15841582 return;
15851583 }
1586− if (time_before(jiffies, (bitmap->last_end_sync
1584+ if (!force && time_before(jiffies, (bitmap->last_end_sync
15871585 + bitmap->mddev->bitmap_info.daemon_sleep)))
15881586 return;
15891587 wait_event(bitmap->mddev->recovery_wait,
drivers/md/bitmap.h+3−1
@@ -9,8 +9,10 @@ · 8 unmodified lines
99 #define BITMAP_MAJOR_LO 3
1010 /* version 4 insists the bitmap is in little-endian order
1111 * with version 3, it is host-endian which is non-portable
12+ * Version 5 is currently set only for clustered devices
1213 */
1314 #define BITMAP_MAJOR_HI 4
15+#define BITMAP_MAJOR_CLUSTERED 5
1416 #define BITMAP_MAJOR_HOSTENDIAN 3
1517
1618 /*
@@ -255,7 +257,7 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, · 238 unmodified lines
255257 int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int degraded);
256258 void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted);
257259 void bitmap_close_sync(struct bitmap *bitmap);
258−void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector);
260+void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force);
259261
260262 void bitmap_unplug(struct bitmap *bitmap);
261263 void bitmap_daemon_work(struct mddev *mddev);
drivers/md/md-cluster.c+114−84
@@ -28,6 +28,7 @@ struct dlm_lock_resource { · 27 unmodified lines
2828 struct completion completion; /* completion for synchronized locking */
2929 void (*bast)(void *arg, int mode); /* blocking AST function pointer*/
3030 struct mddev *mddev; /* pointing back to mddev. */
31+ int mode;
3132 };
3233
3334 struct suspend_info {
@@ -55,6 +56,7 @@ struct md_cluster_info { · 21 unmodified lines
5556 struct completion completion;
5657 struct mutex sb_mutex;
5758 struct dlm_lock_resource *bitmap_lockres;
59+ struct dlm_lock_resource *resync_lockres;
5860 struct list_head suspend_list;
5961 spinlock_t suspend_lock;
6062 struct md_thread *recovery_thread;
@@ -106,6 +108,8 @@ static int dlm_lock_sync(struct dlm_lock_resource *res, int mode) · 45 unmodified lines
106108 if (ret)
107109 return ret;
108110 wait_for_completion(&res->completion);
111+ if (res->lksb.sb_status == 0)
112+ res->mode = mode;
109113 return res->lksb.sb_status;
110114 }
111115
@@ -127,6 +131,7 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev, · 15 unmodified lines
127131 init_completion(&res->completion);
128132 res->ls = cinfo->lockspace;
129133 res->mddev = mddev;
134+ res->mode = DLM_LOCK_IV;
130135 namelen = strlen(name);
131136 res->name = kzalloc(namelen + 1, GFP_KERNEL);
132137 if (!res->name) {
@@ -358,29 +363,32 @@ static void __remove_suspend_info(struct md_cluster_info *cinfo, int slot) · 225 unmodified lines
358363
359364 list_for_each_entry_safe(s, tmp, &cinfo->suspend_list, list)
360365 if (slot == s->slot) {
361− pr_info("%s:%d Deleting suspend_info: %d\n",
362− __func__, __LINE__, slot);
363366 list_del(&s->list);
364367 kfree(s);
365368 break;
366369 }
367370 }
368371
369−static void remove_suspend_info(struct md_cluster_info *cinfo, int slot)
372+static void remove_suspend_info(struct mddev *mddev, int slot)
370373 {
374+ struct md_cluster_info *cinfo = mddev->cluster_info;
371375 spin_lock_irq(&cinfo->suspend_lock);
372376 __remove_suspend_info(cinfo, slot);
373377 spin_unlock_irq(&cinfo->suspend_lock);
378+ mddev->pers->quiesce(mddev, 2);
374379 }
375380
376381
377−static void process_suspend_info(struct md_cluster_info *cinfo,
382+static void process_suspend_info(struct mddev *mddev,
378383 int slot, sector_t lo, sector_t hi)
379384 {
385+ struct md_cluster_info *cinfo = mddev->cluster_info;
380386 struct suspend_info *s;
381387
382388 if (!hi) {
383− remove_suspend_info(cinfo, slot);
389+ remove_suspend_info(mddev, slot);
390+ set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
391+ md_wakeup_thread(mddev->thread);
384392 return;
385393 }
386394 s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL);
@@ -389,11 +397,14 @@ static void process_suspend_info(struct md_cluster_info *cinfo, · 2 unmodified lines
389397 s->slot = slot;
390398 s->lo = lo;
391399 s->hi = hi;
400+ mddev->pers->quiesce(mddev, 1);
401+ mddev->pers->quiesce(mddev, 0);
392402 spin_lock_irq(&cinfo->suspend_lock);
393403 /* Remove existing entry (if exists) before adding */
394404 __remove_suspend_info(cinfo, slot);
395405 list_add(&s->list, &cinfo->suspend_list);
396406 spin_unlock_irq(&cinfo->suspend_lock);
407+ mddev->pers->quiesce(mddev, 2);
397408 }
398409
399410 static void process_add_new_disk(struct mddev *mddev, struct cluster_msg *cmsg)
@@ -407,7 +418,7 @@ static void process_add_new_disk(struct mddev *mddev, struct cluster_msg *cmsg) · 7 unmodified lines
407418
408419 len = snprintf(disk_uuid, 64, "DEVICE_UUID=");
409420 sprintf(disk_uuid + len, "%pU", cmsg->uuid);
410− snprintf(raid_slot, 16, "RAID_DISK=%d", cmsg->raid_slot);
421+ snprintf(raid_slot, 16, "RAID_DISK=%d", le32_to_cpu(cmsg->raid_slot));
411422 pr_info("%s:%d Sending kobject change with %s and %s\n", __func__, __LINE__, disk_uuid, raid_slot);
412423 init_completion(&cinfo->newdisk_completion);
413424 set_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state);
@@ -421,63 +432,57 @@ static void process_add_new_disk(struct mddev *mddev, struct cluster_msg *cmsg) · 7 unmodified lines
421432 static void process_metadata_update(struct mddev *mddev, struct cluster_msg *msg)
422433 {
423434 struct md_cluster_info *cinfo = mddev->cluster_info;
424−
425− md_reload_sb(mddev);
435+ md_reload_sb(mddev, le32_to_cpu(msg->raid_slot));
426436 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR);
427437 }
428438
429439 static void process_remove_disk(struct mddev *mddev, struct cluster_msg *msg)
430440 {
431− struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev, msg->raid_slot);
441+ struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev,
442+ le32_to_cpu(msg->raid_slot));
432443
433444 if (rdev)
434445 md_kick_rdev_from_array(rdev);
435446 else
436− pr_warn("%s: %d Could not find disk(%d) to REMOVE\n", __func__, __LINE__, msg->raid_slot);
447+ pr_warn("%s: %d Could not find disk(%d) to REMOVE\n",
448+ __func__, __LINE__, le32_to_cpu(msg->raid_slot));
437449 }
438450
439451 static void process_readd_disk(struct mddev *mddev, struct cluster_msg *msg)
440452 {
441− struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev, msg->raid_slot);
453+ struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev,
454+ le32_to_cpu(msg->raid_slot));
442455
443456 if (rdev && test_bit(Faulty, &rdev->flags))
444457 clear_bit(Faulty, &rdev->flags);
445458 else
446− pr_warn("%s: %d Could not find disk(%d) which is faulty", __func__, __LINE__, msg->raid_slot);
459+ pr_warn("%s: %d Could not find disk(%d) which is faulty",
460+ __func__, __LINE__, le32_to_cpu(msg->raid_slot));
447461 }
448462
449463 static void process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg)
450464 {
465+ if (WARN(mddev->cluster_info->slot_number - 1 == le32_to_cpu(msg->slot),
466+ "node %d received it's own msg\n", le32_to_cpu(msg->slot)))
467+ return;
451468 switch (msg->type) {
452469 case METADATA_UPDATED:
453− pr_info("%s: %d Received message: METADATA_UPDATE from %d\n",
454− __func__, __LINE__, msg->slot);
455470 process_metadata_update(mddev, msg);
456471 break;
457472 case RESYNCING:
458− pr_info("%s: %d Received message: RESYNCING from %d\n",
459− __func__, __LINE__, msg->slot);
460− process_suspend_info(mddev->cluster_info, msg->slot,
473+ process_suspend_info(mddev, msg->slot,
461474 msg->low, msg->high);
462475 break;
463476 case NEWDISK:
464− pr_info("%s: %d Received message: NEWDISK from %d\n",
465− __func__, __LINE__, msg->slot);
466477 process_add_new_disk(mddev, msg);
467478 break;
468479 case REMOVE:
469− pr_info("%s: %d Received REMOVE from %d\n",
470− __func__, __LINE__, msg->slot);
471480 process_remove_disk(mddev, msg);
472481 break;
473482 case RE_ADD:
474− pr_info("%s: %d Received RE_ADD from %d\n",
475− __func__, __LINE__, msg->slot);
476483 process_readd_disk(mddev, msg);
477484 break;
478485 case BITMAP_NEEDS_SYNC:
479− pr_info("%s: %d Received BITMAP_NEEDS_SYNC from %d\n",
480− __func__, __LINE__, msg->slot);
481486 __recover_slot(mddev, msg->slot);
482487 break;
483488 default:
@@ -528,11 +533,17 @@ static void recv_daemon(struct md_thread *thread) · 44 unmodified lines
528533 /* lock_comm()
529534 * Takes the lock on the TOKEN lock resource so no other
530535 * node can communicate while the operation is underway.
536+ * If called again, and the TOKEN lock is alread in EX mode
537+ * return success. However, care must be taken that unlock_comm()
538+ * is called only once.
531539 */
532540 static int lock_comm(struct md_cluster_info *cinfo)
533541 {
534542 int error;
535543
544+ if (cinfo->token_lockres->mode == DLM_LOCK_EX)
545+ return 0;
546+
536547 error = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX);
537548 if (error)
538549 pr_err("md-cluster(%s:%d): failed to get EX on TOKEN (%d)\n",
@@ -542,6 +553,7 @@ static int lock_comm(struct md_cluster_info *cinfo) · 3 unmodified lines
542553
543554 static void unlock_comm(struct md_cluster_info *cinfo)
544555 {
556+ WARN_ON(cinfo->token_lockres->mode != DLM_LOCK_EX);
545557 dlm_unlock_sync(cinfo->token_lockres);
546558 }
547559
@@ -753,6 +765,10 @@ static int join(struct mddev *mddev, int nodes) · 205 unmodified lines
753765 goto err;
754766 }
755767
768+ cinfo->resync_lockres = lockres_init(mddev, "resync", NULL, 0);
769+ if (!cinfo->resync_lockres)
770+ goto err;
771+
756772 ret = gather_all_resync_info(mddev, nodes);
757773 if (ret)
758774 goto err;
@@ -763,6 +779,7 @@ err: · 4 unmodified lines
763779 lockres_free(cinfo->token_lockres);
764780 lockres_free(cinfo->ack_lockres);
765781 lockres_free(cinfo->no_new_dev_lockres);
782+ lockres_free(cinfo->resync_lockres);
766783 lockres_free(cinfo->bitmap_lockres);
767784 if (cinfo->lockspace)
768785 dlm_release_lockspace(cinfo->lockspace, 2);
@@ -771,12 +788,32 @@ err: · 2 unmodified lines
771788 return ret;
772789 }
773790
791+static void resync_bitmap(struct mddev *mddev)
792+{
793+ struct md_cluster_info *cinfo = mddev->cluster_info;
794+ struct cluster_msg cmsg = {0};
795+ int err;
796+
797+ cmsg.type = cpu_to_le32(BITMAP_NEEDS_SYNC);
798+ err = sendmsg(cinfo, &cmsg);
799+ if (err)
800+ pr_err("%s:%d: failed to send BITMAP_NEEDS_SYNC message (%d)\n",
801+ __func__, __LINE__, err);
802+}
803+
774804 static int leave(struct mddev *mddev)
775805 {
776806 struct md_cluster_info *cinfo = mddev->cluster_info;
777807
778808 if (!cinfo)
779809 return 0;
810+
811+ /* BITMAP_NEEDS_SYNC message should be sent when node
812+ * is leaving the cluster with dirty bitmap, also we
813+ * can only deliver it when dlm connection is available */
814+ if (cinfo->slot_number > 0 && mddev->recovery_cp != MaxSector)
815+ resync_bitmap(mddev);
816+
780817 md_unregister_thread(&cinfo->recovery_thread);
781818 md_unregister_thread(&cinfo->recv_thread);
782819 lockres_free(cinfo->message_lockres);
@@ -799,15 +836,6 @@ static int slot_number(struct mddev *mddev) · 16 unmodified lines
799836 return cinfo->slot_number - 1;
800837 }
801838
802−static void resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi)
803−{
804− struct md_cluster_info *cinfo = mddev->cluster_info;
805−
806− add_resync_info(mddev, cinfo->bitmap_lockres, lo, hi);
807− /* Re-acquire the lock to refresh LVB */
808− dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW);
809−}
810−
811839 static int metadata_update_start(struct mddev *mddev)
812840 {
813841 return lock_comm(mddev->cluster_info);
@@ -817,59 +845,61 @@ static int metadata_update_finish(struct mddev *mddev) · 3 unmodified lines
817845 {
818846 struct md_cluster_info *cinfo = mddev->cluster_info;
819847 struct cluster_msg cmsg;
820− int ret;
848+ struct md_rdev *rdev;
849+ int ret = 0;
821850
822851 memset(&cmsg, 0, sizeof(cmsg));
823852 cmsg.type = cpu_to_le32(METADATA_UPDATED);
824− ret = __sendmsg(cinfo, &cmsg);
853+ cmsg.raid_slot = -1;
854+ /* Pick up a good active device number to send.
855+ */
856+ rdev_for_each(rdev, mddev)
857+ if (rdev->raid_disk > -1 && !test_bit(Faulty, &rdev->flags)) {
858+ cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
859+ break;
860+ }
861+ if (cmsg.raid_slot >= 0)
862+ ret = __sendmsg(cinfo, &cmsg);
863+ else
864+ pr_warn("md-cluster: No good device id found to send\n");
825865 unlock_comm(cinfo);
826866 return ret;
827867 }
828868
829−static int metadata_update_cancel(struct mddev *mddev)
869+static void metadata_update_cancel(struct mddev *mddev)
830870 {
831871 struct md_cluster_info *cinfo = mddev->cluster_info;
872+ unlock_comm(cinfo);
873+}
832874
833− return dlm_unlock_sync(cinfo->token_lockres);
875+static int resync_start(struct mddev *mddev)
876+{
877+ struct md_cluster_info *cinfo = mddev->cluster_info;
878+ cinfo->resync_lockres->flags |= DLM_LKF_NOQUEUE;
879+ return dlm_lock_sync(cinfo->resync_lockres, DLM_LOCK_EX);
834880 }
835881
836−static int resync_send(struct mddev *mddev, enum msg_type type,
837− sector_t lo, sector_t hi)
882+static int resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi)
838883 {
839884 struct md_cluster_info *cinfo = mddev->cluster_info;
840− struct cluster_msg cmsg;
841− int slot = cinfo->slot_number - 1;
885+ struct cluster_msg cmsg = {0};
842886
843− pr_info("%s:%d lo: %llu hi: %llu\n", __func__, __LINE__,
844− (unsigned long long)lo,
845− (unsigned long long)hi);
846− resync_info_update(mddev, lo, hi);
847− cmsg.type = cpu_to_le32(type);
848− cmsg.slot = cpu_to_le32(slot);
887+ add_resync_info(mddev, cinfo->bitmap_lockres, lo, hi);
888+ /* Re-acquire the lock to refresh LVB */
889+ dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW);
890+ cmsg.type = cpu_to_le32(RESYNCING);
849891 cmsg.low = cpu_to_le64(lo);
850892 cmsg.high = cpu_to_le64(hi);
851− return sendmsg(cinfo, &cmsg);
852−}
853893
854−static int resync_start(struct mddev *mddev, sector_t lo, sector_t hi)
855−{
856− pr_info("%s:%d\n", __func__, __LINE__);
857− return resync_send(mddev, RESYNCING, lo, hi);
894+ return sendmsg(cinfo, &cmsg);
858895 }
859896
860−static void resync_finish(struct mddev *mddev)
897+static int resync_finish(struct mddev *mddev)
861898 {
862899 struct md_cluster_info *cinfo = mddev->cluster_info;
863− struct cluster_msg cmsg;
864− int slot = cinfo->slot_number - 1;
865−
866− pr_info("%s:%d\n", __func__, __LINE__);
867− resync_send(mddev, RESYNCING, 0, 0);
868− if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
869− cmsg.type = cpu_to_le32(BITMAP_NEEDS_SYNC);
870− cmsg.slot = cpu_to_le32(slot);
871− sendmsg(cinfo, &cmsg);
872− }
900+ cinfo->resync_lockres->flags &= ~DLM_LKF_NOQUEUE;
901+ dlm_unlock_sync(cinfo->resync_lockres);
902+ return resync_info_update(mddev, 0, 0);
873903 }
874904
875905 static int area_resyncing(struct mddev *mddev, int direction,
@@ -896,7 +926,11 @@ out: · 20 unmodified lines
896926 return ret;
897927 }
898928
899−static int add_new_disk_start(struct mddev *mddev, struct md_rdev *rdev)
929+/* add_new_disk() - initiates a disk add
930+ * However, if this fails before writing md_update_sb(),
931+ * add_new_disk_cancel() must be called to release token lock
932+ */
933+static int add_new_disk(struct mddev *mddev, struct md_rdev *rdev)
900934 {
901935 struct md_cluster_info *cinfo = mddev->cluster_info;
902936 struct cluster_msg cmsg;
@@ -907,7 +941,7 @@ static int add_new_disk_start(struct mddev *mddev, struct md_rdev *rdev) · 4 unmodified lines
907941 memset(&cmsg, 0, sizeof(cmsg));
908942 cmsg.type = cpu_to_le32(NEWDISK);
909943 memcpy(cmsg.uuid, uuid, 16);
910− cmsg.raid_slot = rdev->desc_nr;
944+ cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
911945 lock_comm(cinfo);
912946 ret = __sendmsg(cinfo, &cmsg);
913947 if (ret)
@@ -918,22 +952,17 @@ static int add_new_disk_start(struct mddev *mddev, struct md_rdev *rdev) · 4 unmodified lines
918952 /* Some node does not "see" the device */
919953 if (ret == -EAGAIN)
920954 ret = -ENOENT;
955+ if (ret)
956+ unlock_comm(cinfo);
921957 else
922958 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR);
923959 return ret;
924960 }
925961
926−static int add_new_disk_finish(struct mddev *mddev)
962+static void add_new_disk_cancel(struct mddev *mddev)
927963 {
928− struct cluster_msg cmsg;
929964 struct md_cluster_info *cinfo = mddev->cluster_info;
930− int ret;
931− /* Write sb and inform others */
932− md_update_sb(mddev, 1);
933− cmsg.type = METADATA_UPDATED;
934− ret = __sendmsg(cinfo, &cmsg);
935965 unlock_comm(cinfo);
936− return ret;
937966 }
938967
939968 static int new_disk_ack(struct mddev *mddev, bool ack)
@@ -953,10 +982,10 @@ static int new_disk_ack(struct mddev *mddev, bool ack) · 13 unmodified lines
953982
954983 static int remove_disk(struct mddev *mddev, struct md_rdev *rdev)
955984 {
956− struct cluster_msg cmsg;
985+ struct cluster_msg cmsg = {0};
957986 struct md_cluster_info *cinfo = mddev->cluster_info;
958− cmsg.type = REMOVE;
959− cmsg.raid_slot = rdev->desc_nr;
987+ cmsg.type = cpu_to_le32(REMOVE);
988+ cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
960989 return __sendmsg(cinfo, &cmsg);
961990 }
962991
@@ -964,12 +993,12 @@ static int gather_bitmaps(struct md_rdev *rdev) · 1 unmodified line
964993 {
965994 int sn, err;
966995 sector_t lo, hi;
967− struct cluster_msg cmsg;
996+ struct cluster_msg cmsg = {0};
968997 struct mddev *mddev = rdev->mddev;
969998 struct md_cluster_info *cinfo = mddev->cluster_info;
970999
971− cmsg.type = RE_ADD;
972− cmsg.raid_slot = rdev->desc_nr;
1000+ cmsg.type = cpu_to_le32(RE_ADD);
1001+ cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
9731002 err = sendmsg(cinfo, &cmsg);
9741003 if (err)
9751004 goto out;
@@ -993,15 +1022,15 @@ static struct md_cluster_operations cluster_ops = { · 17 unmodified lines
9931022 .join = join,
9941023 .leave = leave,
9951024 .slot_number = slot_number,
996− .resync_info_update = resync_info_update,
9971025 .resync_start = resync_start,
9981026 .resync_finish = resync_finish,
1027+ .resync_info_update = resync_info_update,
9991028 .metadata_update_start = metadata_update_start,
10001029 .metadata_update_finish = metadata_update_finish,
10011030 .metadata_update_cancel = metadata_update_cancel,
10021031 .area_resyncing = area_resyncing,
1003− .add_new_disk_start = add_new_disk_start,
1004− .add_new_disk_finish = add_new_disk_finish,
1032+ .add_new_disk = add_new_disk,
1033+ .add_new_disk_cancel = add_new_disk_cancel,
10051034 .new_disk_ack = new_disk_ack,
10061035 .remove_disk = remove_disk,
10071036 .gather_bitmaps = gather_bitmaps,
@@ -1022,5 +1051,6 @@ static void cluster_exit(void) · 14 unmodified lines
10221051
10231052 module_init(cluster_init);
10241053 module_exit(cluster_exit);
1054+MODULE_AUTHOR("SUSE");
10251055 MODULE_LICENSE("GPL");
10261056 MODULE_DESCRIPTION("Clustering support for MD");
drivers/md/md-cluster.h+6−6
@@ -12,15 +12,15 @@ struct md_cluster_operations { · 11 unmodified lines
1212 int (*join)(struct mddev *mddev, int nodes);
1313 int (*leave)(struct mddev *mddev);
1414 int (*slot_number)(struct mddev *mddev);
15− void (*resync_info_update)(struct mddev *mddev, sector_t lo, sector_t hi);
16− int (*resync_start)(struct mddev *mddev, sector_t lo, sector_t hi);
17− void (*resync_finish)(struct mddev *mddev);
15+ int (*resync_info_update)(struct mddev *mddev, sector_t lo, sector_t hi);
1816 int (*metadata_update_start)(struct mddev *mddev);
1917 int (*metadata_update_finish)(struct mddev *mddev);
20− int (*metadata_update_cancel)(struct mddev *mddev);
18+ void (*metadata_update_cancel)(struct mddev *mddev);
19+ int (*resync_start)(struct mddev *mddev);
20+ int (*resync_finish)(struct mddev *mddev);
2121 int (*area_resyncing)(struct mddev *mddev, int direction, sector_t lo, sector_t hi);
22− int (*add_new_disk_start)(struct mddev *mddev, struct md_rdev *rdev);
23− int (*add_new_disk_finish)(struct mddev *mddev);
22+ int (*add_new_disk)(struct mddev *mddev, struct md_rdev *rdev);
23+ void (*add_new_disk_cancel)(struct mddev *mddev);
2424 int (*new_disk_ack)(struct mddev *mddev, bool ack);
2525 int (*remove_disk)(struct mddev *mddev, struct md_rdev *rdev);
2626 int (*gather_bitmaps)(struct md_rdev *rdev);
drivers/md/md.c+248−111
@@ -1735,6 +1735,9 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev) · 1734 unmodified lines
17351735 }
17361736 }
17371737
1738+ if (mddev_is_clustered(mddev))
1739+ sb->feature_map |= cpu_to_le32(MD_FEATURE_CLUSTERED);
1740+
17381741 if (rdev->badblocks.count == 0)
17391742 /* Nothing to do for bad blocks*/ ;
17401743 else if (sb->bblog_offset == 0)
@@ -2196,18 +2199,72 @@ static void sync_sbs(struct mddev *mddev, int nospares) · 455 unmodified lines
21962199 }
21972200 }
21982201
2202+static bool does_sb_need_changing(struct mddev *mddev)
2203+{
2204+ struct md_rdev *rdev;
2205+ struct mdp_superblock_1 *sb;
2206+ int role;
2207+
2208+ /* Find a good rdev */
2209+ rdev_for_each(rdev, mddev)
2210+ if ((rdev->raid_disk >= 0) && !test_bit(Faulty, &rdev->flags))
2211+ break;
2212+
2213+ /* No good device found. */
2214+ if (!rdev)
2215+ return false;
2216+
2217+ sb = page_address(rdev->sb_page);
2218+ /* Check if a device has become faulty or a spare become active */
2219+ rdev_for_each(rdev, mddev) {
2220+ role = le16_to_cpu(sb->dev_roles[rdev->desc_nr]);
2221+ /* Device activated? */
2222+ if (role == 0xffff && rdev->raid_disk >=0 &&
2223+ !test_bit(Faulty, &rdev->flags))
2224+ return true;
2225+ /* Device turned faulty? */
2226+ if (test_bit(Faulty, &rdev->flags) && (role < 0xfffd))
2227+ return true;
2228+ }
2229+
2230+ /* Check if any mddev parameters have changed */
2231+ if ((mddev->dev_sectors != le64_to_cpu(sb->size)) ||
2232+ (mddev->reshape_position != le64_to_cpu(sb->reshape_position)) ||
2233+ (mddev->recovery_cp != le64_to_cpu(sb->resync_offset)) ||
2234+ (mddev->layout != le64_to_cpu(sb->layout)) ||
2235+ (mddev->raid_disks != le32_to_cpu(sb->raid_disks)) ||
2236+ (mddev->chunk_sectors != le32_to_cpu(sb->chunksize)))
2237+ return true;
2238+
2239+ return false;
2240+}
2241+
21992242 void md_update_sb(struct mddev *mddev, int force_change)
22002243 {
22012244 struct md_rdev *rdev;
22022245 int sync_req;
22032246 int nospares = 0;
22042247 int any_badblocks_changed = 0;
2248+ int ret = -1;
22052249
22062250 if (mddev->ro) {
22072251 if (force_change)
22082252 set_bit(MD_CHANGE_DEVS, &mddev->flags);
22092253 return;
22102254 }
2255+
2256+ if (mddev_is_clustered(mddev)) {
2257+ if (test_and_clear_bit(MD_CHANGE_DEVS, &mddev->flags))
2258+ force_change = 1;
2259+ ret = md_cluster_ops->metadata_update_start(mddev);
2260+ /* Has someone else has updated the sb */
2261+ if (!does_sb_need_changing(mddev)) {
2262+ if (ret == 0)
2263+ md_cluster_ops->metadata_update_cancel(mddev);
2264+ clear_bit(MD_CHANGE_PENDING, &mddev->flags);
2265+ return;
2266+ }
2267+ }
22112268 repeat:
22122269 /* First make sure individual recovery_offsets are correct */
22132270 rdev_for_each(rdev, mddev) {
@@ -2356,6 +2413,9 @@ repeat: · 142 unmodified lines
23562413 clear_bit(BlockedBadBlocks, &rdev->flags);
23572414 wake_up(&rdev->blocked_wait);
23582415 }
2416+
2417+ if (mddev_is_clustered(mddev) && ret == 0)
2418+ md_cluster_ops->metadata_update_finish(mddev);
23592419 }
23602420 EXPORT_SYMBOL(md_update_sb);
23612421
@@ -2490,17 +2550,16 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) · 128 unmodified lines
24902550 err = -EBUSY;
24912551 else {
24922552 struct mddev *mddev = rdev->mddev;
2493− if (mddev_is_clustered(mddev))
2494− md_cluster_ops->remove_disk(mddev, rdev);
2495− md_kick_rdev_from_array(rdev);
2496− if (mddev_is_clustered(mddev))
2497− md_cluster_ops->metadata_update_start(mddev);
2498− if (mddev->pers)
2499− md_update_sb(mddev, 1);
2500− md_new_event(mddev);
2501− if (mddev_is_clustered(mddev))
2502− md_cluster_ops->metadata_update_finish(mddev);
25032553 err = 0;
2554+ if (mddev_is_clustered(mddev))
2555+ err = md_cluster_ops->remove_disk(mddev, rdev);
2556+
2557+ if (err == 0) {
2558+ md_kick_rdev_from_array(rdev);
2559+ if (mddev->pers)
2560+ md_update_sb(mddev, 1);
2561+ md_new_event(mddev);
2562+ }
25042563 }
25052564 } else if (cmd_match(buf, "writemostly")) {
25062565 set_bit(WriteMostly, &rdev->flags);
@@ -2688,15 +2747,9 @@ slot_store(struct md_rdev *rdev, const char *buf, size_t len) · 181 unmodified lines
26882747 rdev->saved_raid_disk = -1;
26892748 clear_bit(In_sync, &rdev->flags);
26902749 clear_bit(Bitmap_sync, &rdev->flags);
2691− err = rdev->mddev->pers->
2692− hot_add_disk(rdev->mddev, rdev);
2693− if (err) {
2694− rdev->raid_disk = -1;
2695− return err;
2696− } else
2697− sysfs_notify_dirent_safe(rdev->sysfs_state);
2698− if (sysfs_link_rdev(rdev->mddev, rdev))
2699− /* failure here is OK */;
2750+ remove_and_add_spares(rdev->mddev, rdev);
2751+ if (rdev->raid_disk == -1)
2752+ return -EBUSY;
27002753 /* don't wakeup anyone, leave that to userspace. */
27012754 } else {
27022755 if (slot >= rdev->mddev->raid_disks &&
@@ -3198,14 +3251,6 @@ static void analyze_sbs(struct mddev *mddev) · 495 unmodified lines
31983251 md_kick_rdev_from_array(rdev);
31993252 continue;
32003253 }
3201− /* No device should have a Candidate flag
3202− * when reading devices
3203− */
3204− if (test_bit(Candidate, &rdev->flags)) {
3205− pr_info("md: kicking Cluster Candidate %s from array!\n",
3206− bdevname(rdev->bdev, b));
3207− md_kick_rdev_from_array(rdev);
3208− }
32093254 }
32103255 if (mddev->level == LEVEL_MULTIPATH) {
32113256 rdev->desc_nr = i++;
@@ -4066,12 +4111,8 @@ size_store(struct mddev *mddev, const char *buf, size_t len) · 854 unmodified lines
40664111 if (err)
40674112 return err;
40684113 if (mddev->pers) {
4069− if (mddev_is_clustered(mddev))
4070− md_cluster_ops->metadata_update_start(mddev);
40714114 err = update_size(mddev, sectors);
40724115 md_update_sb(mddev, 1);
4073− if (mddev_is_clustered(mddev))
4074− md_cluster_ops->metadata_update_finish(mddev);
40754116 } else {
40764117 if (mddev->dev_sectors == 0 ||
40774118 mddev->dev_sectors > sectors)
@@ -5309,8 +5350,6 @@ static void md_clean(struct mddev *mddev) · 1231 unmodified lines
53095350
53105351 static void __md_stop_writes(struct mddev *mddev)
53115352 {
5312− if (mddev_is_clustered(mddev))
5313− md_cluster_ops->metadata_update_start(mddev);
53145353 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
53155354 flush_workqueue(md_misc_wq);
53165355 if (mddev->sync_thread) {
@@ -5329,8 +5368,6 @@ static void __md_stop_writes(struct mddev *mddev) · 12 unmodified lines
53295368 mddev->in_sync = 1;
53305369 md_update_sb(mddev, 1);
53315370 }
5332− if (mddev_is_clustered(mddev))
5333− md_cluster_ops->metadata_update_finish(mddev);
53345371 }
53355372
53365373 void md_stop_writes(struct mddev *mddev)
@@ -5910,19 +5947,12 @@ static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info) · 573 unmodified lines
59105947 * check whether the device shows up in other nodes
59115948 */
59125949 if (mddev_is_clustered(mddev)) {
5913− if (info->state & (1 << MD_DISK_CANDIDATE)) {
5914− /* Through --cluster-confirm */
5950+ if (info->state & (1 << MD_DISK_CANDIDATE))
59155951 set_bit(Candidate, &rdev->flags);
5916− err = md_cluster_ops->new_disk_ack(mddev, true);
5917− if (err) {
5918− export_rdev(rdev);
5919− return err;
5920− }
5921− } else if (info->state & (1 << MD_DISK_CLUSTER_ADD)) {
5952+ else if (info->state & (1 << MD_DISK_CLUSTER_ADD)) {
59225953 /* --add initiated by this node */
5923− err = md_cluster_ops->add_new_disk_start(mddev, rdev);
5954+ err = md_cluster_ops->add_new_disk(mddev, rdev);
59245955 if (err) {
5925− md_cluster_ops->add_new_disk_finish(mddev);
59265956 export_rdev(rdev);
59275957 return err;
59285958 }
@@ -5931,13 +5961,23 @@ static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info) · 2 unmodified lines
59315961
59325962 rdev->raid_disk = -1;
59335963 err = bind_rdev_to_array(rdev, mddev);
5964+
59345965 if (err)
59355966 export_rdev(rdev);
5936− else
5967+
5968+ if (mddev_is_clustered(mddev)) {
5969+ if (info->state & (1 << MD_DISK_CANDIDATE))
5970+ md_cluster_ops->new_disk_ack(mddev, (err == 0));
5971+ else {
5972+ if (err)
5973+ md_cluster_ops->add_new_disk_cancel(mddev);
5974+ else
5975+ err = add_bound_rdev(rdev);
5976+ }
5977+
5978+ } else if (!err)
59375979 err = add_bound_rdev(rdev);
5938− if (mddev_is_clustered(mddev) &&
5939− (info->state & (1 << MD_DISK_CLUSTER_ADD)))
5940− md_cluster_ops->add_new_disk_finish(mddev);
5980+
59415981 return err;
59425982 }
59435983
@@ -5993,13 +6033,17 @@ static int hot_remove_disk(struct mddev *mddev, dev_t dev) · 49 unmodified lines
59936033 {
59946034 char b[BDEVNAME_SIZE];
59956035 struct md_rdev *rdev;
6036+ int ret = -1;
59966037
59976038 rdev = find_rdev(mddev, dev);
59986039 if (!rdev)
59996040 return -ENXIO;
60006041
60016042 if (mddev_is_clustered(mddev))
6002− md_cluster_ops->metadata_update_start(mddev);
6043+ ret = md_cluster_ops->metadata_update_start(mddev);
6044+
6045+ if (rdev->raid_disk < 0)
6046+ goto kick_rdev;
60036047
60046048 clear_bit(Blocked, &rdev->flags);
60056049 remove_and_add_spares(mddev, rdev);
@@ -6007,20 +6051,19 @@ static int hot_remove_disk(struct mddev *mddev, dev_t dev) · 1 unmodified line
60076051 if (rdev->raid_disk >= 0)
60086052 goto busy;
60096053
6010− if (mddev_is_clustered(mddev))
6054+kick_rdev:
6055+ if (mddev_is_clustered(mddev) && ret == 0)
60116056 md_cluster_ops->remove_disk(mddev, rdev);
60126057
60136058 md_kick_rdev_from_array(rdev);
60146059 md_update_sb(mddev, 1);
60156060 md_new_event(mddev);
60166061
6017− if (mddev_is_clustered(mddev))
6018− md_cluster_ops->metadata_update_finish(mddev);
6019−
60206062 return 0;
60216063 busy:
6022− if (mddev_is_clustered(mddev))
6064+ if (mddev_is_clustered(mddev) && ret == 0)
60236065 md_cluster_ops->metadata_update_cancel(mddev);
6066+
60246067 printk(KERN_WARNING "md: cannot remove active disk %s from %s ...\n",
60256068 bdevname(rdev->bdev,b), mdname(mddev));
60266069 return -EBUSY;
@@ -6071,14 +6114,12 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev) · 44 unmodified lines
60716114 goto abort_export;
60726115 }
60736116
6074− if (mddev_is_clustered(mddev))
6075− md_cluster_ops->metadata_update_start(mddev);
60766117 clear_bit(In_sync, &rdev->flags);
60776118 rdev->desc_nr = -1;
60786119 rdev->saved_raid_disk = -1;
60796120 err = bind_rdev_to_array(rdev, mddev);
60806121 if (err)
6081− goto abort_clustered;
6122+ goto abort_export;
60826123
60836124 /*
60846125 * The rest should better be atomic, we can have disk failures
@@ -6088,9 +6129,6 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev) · 3 unmodified lines
60886129 rdev->raid_disk = -1;
60896130
60906131 md_update_sb(mddev, 1);
6091−
6092− if (mddev_is_clustered(mddev))
6093− md_cluster_ops->metadata_update_finish(mddev);
60946132 /*
60956133 * Kick recovery, maybe this spare has to be added to the
60966134 * array immediately.
@@ -6100,9 +6138,6 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev) · 3 unmodified lines
61006138 md_new_event(mddev);
61016139 return 0;
61026140
6103−abort_clustered:
6104− if (mddev_is_clustered(mddev))
6105− md_cluster_ops->metadata_update_cancel(mddev);
61066141 abort_export:
61076142 export_rdev(rdev);
61086143 return err;
@@ -6420,8 +6455,6 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · 311 unmodified lines
64206455 return rv;
64216456 }
64226457 }
6423− if (mddev_is_clustered(mddev))
6424− md_cluster_ops->metadata_update_start(mddev);
64256458 if (info->size >= 0 && mddev->dev_sectors / 2 != info->size)
64266459 rv = update_size(mddev, (sector_t)info->size * 2);
64276460
@@ -6479,12 +6512,8 @@ static int update_array_info(struct mddev *mddev, mdu_array_info_t *info) · 51 unmodified lines
64796512 }
64806513 }
64816514 md_update_sb(mddev, 1);
6482− if (mddev_is_clustered(mddev))
6483− md_cluster_ops->metadata_update_finish(mddev);
64846515 return rv;
64856516 err:
6486− if (mddev_is_clustered(mddev))
6487− md_cluster_ops->metadata_update_cancel(mddev);
64886517 return rv;
64896518 }
64906519
@@ -7597,11 +7626,7 @@ int md_allow_write(struct mddev *mddev) · 1106 unmodified lines
75977626 mddev->safemode == 0)
75987627 mddev->safemode = 1;
75997628 spin_unlock(&mddev->lock);
7600− if (mddev_is_clustered(mddev))
7601− md_cluster_ops->metadata_update_start(mddev);
76027629 md_update_sb(mddev, 0);
7603− if (mddev_is_clustered(mddev))
7604− md_cluster_ops->metadata_update_finish(mddev);
76057630 sysfs_notify_dirent_safe(mddev->sysfs_state);
76067631 } else
76077632 spin_unlock(&mddev->lock);
@@ -7633,6 +7658,7 @@ void md_do_sync(struct md_thread *thread) · 25 unmodified lines
76337658 struct md_rdev *rdev;
76347659 char *desc, *action = NULL;
76357660 struct blk_plug plug;
7661+ bool cluster_resync_finished = false;
76367662
76377663 /* just incase thread restarts... */
76387664 if (test_bit(MD_RECOVERY_DONE, &mddev->recovery))
@@ -7802,9 +7828,6 @@ void md_do_sync(struct md_thread *thread) · 163 unmodified lines
78027828 md_new_event(mddev);
78037829 update_time = jiffies;
78047830
7805− if (mddev_is_clustered(mddev))
7806− md_cluster_ops->resync_start(mddev, j, max_sectors);
7807−
78087831 blk_start_plug(&plug);
78097832 while (j < max_sectors) {
78107833 sector_t sectors;
@@ -7868,8 +7891,6 @@ void md_do_sync(struct md_thread *thread) · 57 unmodified lines
78687891 j = max_sectors;
78697892 if (j > 2)
78707893 mddev->curr_resync = j;
7871− if (mddev_is_clustered(mddev))
7872− md_cluster_ops->resync_info_update(mddev, j, max_sectors);
78737894 mddev->curr_mark_cnt = io_sectors;
78747895 if (last_check == 0)
78757896 /* this is the earliest that rebuild will be
@@ -7940,7 +7961,11 @@ void md_do_sync(struct md_thread *thread) · 64 unmodified lines
79407961 mddev->curr_resync_completed = mddev->curr_resync;
79417962 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
79427963 }
7943− /* tell personality that we are finished */
7964+ /* tell personality and other nodes that we are finished */
7965+ if (mddev_is_clustered(mddev)) {
7966+ md_cluster_ops->resync_finish(mddev);
7967+ cluster_resync_finished = true;
7968+ }
79447969 mddev->pers->sync_request(mddev, max_sectors, &skipped);
79457970
79467971 if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) &&
@@ -7976,11 +8001,13 @@ void md_do_sync(struct md_thread *thread) · 29 unmodified lines
79768001 }
79778002 }
79788003 skip:
7979− if (mddev_is_clustered(mddev))
7980− md_cluster_ops->resync_finish(mddev);
7981−
79828004 set_bit(MD_CHANGE_DEVS, &mddev->flags);
79838005
8006+ if (mddev_is_clustered(mddev) &&
8007+ test_bit(MD_RECOVERY_INTR, &mddev->recovery) &&
8008+ !cluster_resync_finished)
8009+ md_cluster_ops->resync_finish(mddev);
8010+
79848011 spin_lock(&mddev->lock);
79858012 if (!test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
79868013 /* We completed so min/max setting can be forgotten if used. */
@@ -8023,10 +8050,14 @@ static int remove_and_add_spares(struct mddev *mddev, · 36 unmodified lines
80238050 if (removed && mddev->kobj.sd)
80248051 sysfs_notify(&mddev->kobj, NULL, "degraded");
80258052
8026− if (this)
8053+ if (this && removed)
80278054 goto no_add;
80288055
80298056 rdev_for_each(rdev, mddev) {
8057+ if (this && this != rdev)
8058+ continue;
8059+ if (test_bit(Candidate, &rdev->flags))
8060+ continue;
80308061 if (rdev->raid_disk >= 0 &&
80318062 !test_bit(In_sync, &rdev->flags) &&
80328063 !test_bit(Faulty, &rdev->flags))
@@ -8060,14 +8091,25 @@ no_add: · 27 unmodified lines
80608091 static void md_start_sync(struct work_struct *ws)
80618092 {
80628093 struct mddev *mddev = container_of(ws, struct mddev, del_work);
8094+ int ret = 0;
8095+
8096+ if (mddev_is_clustered(mddev)) {
8097+ ret = md_cluster_ops->resync_start(mddev);
8098+ if (ret) {
8099+ mddev->sync_thread = NULL;
8100+ goto out;
8101+ }
8102+ }
80638103
80648104 mddev->sync_thread = md_register_thread(md_do_sync,
80658105 mddev,
80668106 "resync");
8107+out:
80678108 if (!mddev->sync_thread) {
8068− printk(KERN_ERR "%s: could not start resync"
8069− " thread...\n",
8070− mdname(mddev));
8109+ if (!(mddev_is_clustered(mddev) && ret == -EAGAIN))
8110+ printk(KERN_ERR "%s: could not start resync"
8111+ " thread...\n",
8112+ mdname(mddev));
80718113 /* leave the spares where they are, it shouldn't hurt */
80728114 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
80738115 clear_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
@@ -8186,13 +8228,8 @@ void md_check_recovery(struct mddev *mddev) · 112 unmodified lines
81868228 sysfs_notify_dirent_safe(mddev->sysfs_state);
81878229 }
81888230
8189− if (mddev->flags & MD_UPDATE_SB_FLAGS) {
8190− if (mddev_is_clustered(mddev))
8191− md_cluster_ops->metadata_update_start(mddev);
8231+ if (mddev->flags & MD_UPDATE_SB_FLAGS)
81928232 md_update_sb(mddev, 0);
8193− if (mddev_is_clustered(mddev))
8194− md_cluster_ops->metadata_update_finish(mddev);
8195− }
81968233
81978234 if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&
81988235 !test_bit(MD_RECOVERY_DONE, &mddev->recovery)) {
@@ -8290,8 +8327,6 @@ void md_reap_sync_thread(struct mddev *mddev) · 91 unmodified lines
82908327 set_bit(MD_CHANGE_DEVS, &mddev->flags);
82918328 }
82928329 }
8293− if (mddev_is_clustered(mddev))
8294− md_cluster_ops->metadata_update_start(mddev);
82958330 if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
82968331 mddev->pers->finish_reshape)
82978332 mddev->pers->finish_reshape(mddev);
@@ -8304,8 +8339,6 @@ void md_reap_sync_thread(struct mddev *mddev) · 6 unmodified lines
83048339 rdev->saved_raid_disk = -1;
83058340
83068341 md_update_sb(mddev, 1);
8307− if (mddev_is_clustered(mddev))
8308− md_cluster_ops->metadata_update_finish(mddev);
83098342 clear_bit(MD_RECOVERY_RUNNING, &mddev->recovery);
83108343 clear_bit(MD_RECOVERY_DONE, &mddev->recovery);
83118344 clear_bit(MD_RECOVERY_SYNC, &mddev->recovery);
@@ -8928,25 +8961,129 @@ err_wq: · 616 unmodified lines
89288961 return ret;
89298962 }
89308963
8931−void md_reload_sb(struct mddev *mddev)
8964+static void check_sb_changes(struct mddev *mddev, struct md_rdev *rdev)
89328965 {
8933− struct md_rdev *rdev, *tmp;
8966+ struct mdp_superblock_1 *sb = page_address(rdev->sb_page);
8967+ struct md_rdev *rdev2;
8968+ int role, ret;
8969+ char b[BDEVNAME_SIZE];
89348970
8935− rdev_for_each_safe(rdev, tmp, mddev) {
8936− rdev->sb_loaded = 0;
8937− ClearPageUptodate(rdev->sb_page);
8971+ /* Check for change of roles in the active devices */
8972+ rdev_for_each(rdev2, mddev) {
8973+ if (test_bit(Faulty, &rdev2->flags))
8974+ continue;
8975+
8976+ /* Check if the roles changed */
8977+ role = le16_to_cpu(sb->dev_roles[rdev2->desc_nr]);
8978+
8979+ if (test_bit(Candidate, &rdev2->flags)) {
8980+ if (role == 0xfffe) {
8981+ pr_info("md: Removing Candidate device %s because add failed\n", bdevname(rdev2->bdev,b));
8982+ md_kick_rdev_from_array(rdev2);
8983+ continue;
8984+ }
8985+ else
8986+ clear_bit(Candidate, &rdev2->flags);
8987+ }
8988+
8989+ if (role != rdev2->raid_disk) {
8990+ /* got activated */
8991+ if (rdev2->raid_disk == -1 && role != 0xffff) {
8992+ rdev2->saved_raid_disk = role;
8993+ ret = remove_and_add_spares(mddev, rdev2);
8994+ pr_info("Activated spare: %s\n",
8995+ bdevname(rdev2->bdev,b));
8996+ continue;
8997+ }
8998+ /* device faulty
8999+ * We just want to do the minimum to mark the disk
9000+ * as faulty. The recovery is performed by the
9001+ * one who initiated the error.
9002+ */
9003+ if ((role == 0xfffe) || (role == 0xfffd)) {
9004+ md_error(mddev, rdev2);
9005+ clear_bit(Blocked, &rdev2->flags);
9006+ }
9007+ }
89389008 }
8939− mddev->raid_disks = 0;
8940− analyze_sbs(mddev);
8941− rdev_for_each_safe(rdev, tmp, mddev) {
8942− struct mdp_superblock_1 *sb = page_address(rdev->sb_page);
8943− /* since we don't write to faulty devices, we figure out if the
8944− * disk is faulty by comparing events
8945− */
8946− if (mddev->events > sb->events)
8947− set_bit(Faulty, &rdev->flags);
9009+
9010+ /* recovery_cp changed */
9011+ if (le64_to_cpu(sb->resync_offset) != mddev->recovery_cp)
9012+ mddev->recovery_cp = le64_to_cpu(sb->resync_offset);
9013+
9014+ /* Finally set the event to be up to date */
9015+ mddev->events = le64_to_cpu(sb->events);
9016+}
9017+
9018+static int read_rdev(struct mddev *mddev, struct md_rdev *rdev)
9019+{
9020+ int err;
9021+ struct page *swapout = rdev->sb_page;
9022+ struct mdp_superblock_1 *sb;
9023+
9024+ /* Store the sb page of the rdev in the swapout temporary
9025+ * variable in case we err in the future
9026+ */
9027+ rdev->sb_page = NULL;
9028+ alloc_disk_sb(rdev);
9029+ ClearPageUptodate(rdev->sb_page);
9030+ rdev->sb_loaded = 0;
9031+ err = super_types[mddev->major_version].load_super(rdev, NULL, mddev->minor_version);
9032+
9033+ if (err < 0) {
9034+ pr_warn("%s: %d Could not reload rdev(%d) err: %d. Restoring old values\n",
9035+ __func__, __LINE__, rdev->desc_nr, err);
9036+ put_page(rdev->sb_page);
9037+ rdev->sb_page = swapout;
9038+ rdev->sb_loaded = 1;
9039+ return err;
9040+ }
9041+
9042+ sb = page_address(rdev->sb_page);
9043+ /* Read the offset unconditionally, even if MD_FEATURE_RECOVERY_OFFSET
9044+ * is not set
9045+ */
9046+
9047+ if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RECOVERY_OFFSET))
9048+ rdev->recovery_offset = le64_to_cpu(sb->recovery_offset);
9049+
9050+ /* The other node finished recovery, call spare_active to set
9051+ * device In_sync and mddev->degraded
9052+ */
9053+ if (rdev->recovery_offset == MaxSector &&
9054+ !test_bit(In_sync, &rdev->flags) &&
9055+ mddev->pers->spare_active(mddev))
9056+ sysfs_notify(&mddev->kobj, NULL, "degraded");
9057+
9058+ put_page(swapout);
9059+ return 0;
9060+}
9061+
9062+void md_reload_sb(struct mddev *mddev, int nr)
9063+{
9064+ struct md_rdev *rdev;
9065+ int err;
9066+
9067+ /* Find the rdev */
9068+ rdev_for_each_rcu(rdev, mddev) {
9069+ if (rdev->desc_nr == nr)
9070+ break;
9071+ }
9072+
9073+ if (!rdev || rdev->desc_nr != nr) {
9074+ pr_warn("%s: %d Could not find rdev with nr %d\n", __func__, __LINE__, nr);
9075+ return;
89489076 }
89499077
9078+ err = read_rdev(mddev, rdev);
9079+ if (err < 0)
9080+ return;
9081+
9082+ check_sb_changes(mddev, rdev);
9083+
9084+ /* Read all rdev's to update recovery_offset */
9085+ rdev_for_each_rcu(rdev, mddev)
9086+ read_rdev(mddev, rdev);
89509087 }
89519088 EXPORT_SYMBOL(md_reload_sb);
89529089
drivers/md/md.h+1−1
@@ -658,7 +658,7 @@ extern struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs, · 657 unmodified lines
658658 struct mddev *mddev);
659659
660660 extern void md_unplug(struct blk_plug_cb *cb, bool from_schedule);
661−extern void md_reload_sb(struct mddev *mddev);
661+extern void md_reload_sb(struct mddev *mddev, int raid_disk);
662662 extern void md_update_sb(struct mddev *mddev, int force);
663663 extern void md_kick_rdev_from_array(struct md_rdev * rdev);
664664 struct md_rdev *md_find_rdev_nr_rcu(struct mddev *mddev, int nr);
drivers/md/raid1.c+32−1
@@ -90,6 +90,8 @@ static void r1bio_pool_free(void *r1_bio, void *data) · 89 unmodified lines
9090 #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
9191 #define RESYNC_WINDOW (RESYNC_BLOCK_SIZE * RESYNC_DEPTH)
9292 #define RESYNC_WINDOW_SECTORS (RESYNC_WINDOW >> 9)
93+#define CLUSTER_RESYNC_WINDOW (16 * RESYNC_WINDOW)
94+#define CLUSTER_RESYNC_WINDOW_SECTORS (CLUSTER_RESYNC_WINDOW >> 9)
9395 #define NEXT_NORMALIO_DISTANCE (3 * RESYNC_WINDOW_SECTORS)
9496
9597 static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
@@ -1590,6 +1592,15 @@ static int raid1_add_disk(struct mddev *mddev, struct md_rdev *rdev) · 1494 unmodified lines
15901592 if (rdev->raid_disk >= 0)
15911593 first = last = rdev->raid_disk;
15921594
1595+ /*
1596+ * find the disk ... but prefer rdev->saved_raid_disk
1597+ * if possible.
1598+ */
1599+ if (rdev->saved_raid_disk >= 0 &&
1600+ rdev->saved_raid_disk >= first &&
1601+ conf->mirrors[rdev->saved_raid_disk].rdev == NULL)
1602+ first = last = rdev->saved_raid_disk;
1603+
15931604 for (mirror = first; mirror <= last; mirror++) {
15941605 p = conf->mirrors+mirror;
15951606 if (!p->rdev) {
@@ -2488,6 +2499,11 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp · 892 unmodified lines
24882499
24892500 bitmap_close_sync(mddev->bitmap);
24902501 close_sync(conf);
2502+
2503+ if (mddev_is_clustered(mddev)) {
2504+ conf->cluster_sync_low = 0;
2505+ conf->cluster_sync_high = 0;
2506+ }
24912507 return 0;
24922508 }
24932509
@@ -2508,7 +2524,12 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp · 14 unmodified lines
25082524 return sync_blocks;
25092525 }
25102526
2511− bitmap_cond_end_sync(mddev->bitmap, sector_nr);
2527+ /* we are incrementing sector_nr below. To be safe, we check against
2528+ * sector_nr + two times RESYNC_SECTORS
2529+ */
2530+
2531+ bitmap_cond_end_sync(mddev->bitmap, sector_nr,
2532+ mddev_is_clustered(mddev) && (sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high));
25122533 r1_bio = mempool_alloc(conf->r1buf_pool, GFP_NOIO);
25132534
25142535 raise_barrier(conf, sector_nr);
@@ -2699,6 +2720,16 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp · 184 unmodified lines
26992720 bio_full:
27002721 r1_bio->sectors = nr_sectors;
27012722
2723+ if (mddev_is_clustered(mddev) &&
2724+ conf->cluster_sync_high < sector_nr + nr_sectors) {
2725+ conf->cluster_sync_low = mddev->curr_resync_completed;
2726+ conf->cluster_sync_high = conf->cluster_sync_low + CLUSTER_RESYNC_WINDOW_SECTORS;
2727+ /* Send resync message */
2728+ md_cluster_ops->resync_info_update(mddev,
2729+ conf->cluster_sync_low,
2730+ conf->cluster_sync_high);
2731+ }
2732+
27022733 /* For a user-requested sync, we read all readable devices and do a
27032734 * compare
27042735 */
drivers/md/raid1.h+7−0
@@ -111,6 +111,13 @@ struct r1conf { · 110 unmodified lines
111111 * the new thread here until we fully activate the array.
112112 */
113113 struct md_thread *thread;
114+
115+ /* Keep track of cluster resync window to send to other
116+ * nodes.
117+ */
118+ sector_t cluster_sync_low;
119+ sector_t cluster_sync_high;
120+
114121 };
115122
116123 /*
drivers/md/raid10.c+1−1
@@ -3137,7 +3137,7 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, · 3136 unmodified lines
31373137 /* resync. Schedule a read for every block at this virt offset */
31383138 int count = 0;
31393139
3140− bitmap_cond_end_sync(mddev->bitmap, sector_nr);
3140+ bitmap_cond_end_sync(mddev->bitmap, sector_nr, 0);
31413141
31423142 if (!bitmap_start_sync(mddev->bitmap, sector_nr,
31433143 &sync_blocks, mddev->degraded) &&
drivers/md/raid5.c+1−1
@@ -5613,7 +5613,7 @@ static inline sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int · 5612 unmodified lines
56135613 return sync_blocks * STRIPE_SECTORS; /* keep things rounded to whole stripes */
56145614 }
56155615
5616− bitmap_cond_end_sync(mddev->bitmap, sector_nr);
5616+ bitmap_cond_end_sync(mddev->bitmap, sector_nr, false);
56175617
56185618 sh = get_active_stripe(conf, sector_nr, 0, 1, 0);
56195619 if (sh == NULL) {
include/uapi/linux/raid/md_p.h+2−0
@@ -302,6 +302,7 @@ struct mdp_superblock_1 { · 301 unmodified lines
302302 #define MD_FEATURE_RECOVERY_BITMAP 128 /* recovery that is happening
303303 * is guided by bitmap.
304304 */
305+#define MD_FEATURE_CLUSTERED 256 /* clustered MD */
305306 #define MD_FEATURE_ALL (MD_FEATURE_BITMAP_OFFSET \
306307 |MD_FEATURE_RECOVERY_OFFSET \
307308 |MD_FEATURE_RESHAPE_ACTIVE \
@@ -310,6 +311,7 @@ struct mdp_superblock_1 { · 2 unmodified lines
310311 |MD_FEATURE_RESHAPE_BACKWARDS \
311312 |MD_FEATURE_NEW_OFFSET \
312313 |MD_FEATURE_RECOVERY_BITMAP \
314+ |MD_FEATURE_CLUSTERED \
313315 )
314316
315317 #endif