Lines Matching +full:mode +full:- +full:recovery

1 // SPDX-License-Identifier: GPL-2.0-or-later
13 #include "md-bitmap.h"
14 #include "md-cluster.h"
26 void (*bast)(void *arg, int mode); /* blocking AST function pointer*/
28 int mode; member
120 res->sync_locking_done = true; in sync_ast()
121 wake_up(&res->sync_locking); in sync_ast()
124 static int dlm_lock_sync(struct dlm_lock_resource *res, int mode) in dlm_lock_sync() argument
128 ret = dlm_lock(res->ls, mode, &res->lksb, in dlm_lock_sync()
129 res->flags, res->name, strlen(res->name), in dlm_lock_sync()
130 0, sync_ast, res, res->bast); in dlm_lock_sync()
133 wait_event(res->sync_locking, res->sync_locking_done); in dlm_lock_sync()
134 res->sync_locking_done = false; in dlm_lock_sync()
135 if (res->lksb.sb_status == 0) in dlm_lock_sync()
136 res->mode = mode; in dlm_lock_sync()
137 return res->lksb.sb_status; in dlm_lock_sync()
149 static int dlm_lock_sync_interruptible(struct dlm_lock_resource *res, int mode, in dlm_lock_sync_interruptible() argument
154 ret = dlm_lock(res->ls, mode, &res->lksb, in dlm_lock_sync_interruptible()
155 res->flags, res->name, strlen(res->name), in dlm_lock_sync_interruptible()
156 0, sync_ast, res, res->bast); in dlm_lock_sync_interruptible()
160 wait_event(res->sync_locking, res->sync_locking_done in dlm_lock_sync_interruptible()
162 || test_bit(MD_CLOSING, &mddev->flags)); in dlm_lock_sync_interruptible()
163 if (!res->sync_locking_done) { in dlm_lock_sync_interruptible()
169 ret = dlm_unlock(res->ls, res->lksb.sb_lkid, DLM_LKF_CANCEL, in dlm_lock_sync_interruptible()
170 &res->lksb, res); in dlm_lock_sync_interruptible()
171 res->sync_locking_done = false; in dlm_lock_sync_interruptible()
174 "%s return %d\n", res->name, ret); in dlm_lock_sync_interruptible()
175 return -EPERM; in dlm_lock_sync_interruptible()
177 res->sync_locking_done = false; in dlm_lock_sync_interruptible()
178 if (res->lksb.sb_status == 0) in dlm_lock_sync_interruptible()
179 res->mode = mode; in dlm_lock_sync_interruptible()
180 return res->lksb.sb_status; in dlm_lock_sync_interruptible()
184 char *name, void (*bastfn)(void *arg, int mode), int with_lvb) in lockres_init() argument
188 struct md_cluster_info *cinfo = mddev->cluster_info; in lockres_init()
193 init_waitqueue_head(&res->sync_locking); in lockres_init()
194 res->sync_locking_done = false; in lockres_init()
195 res->ls = cinfo->lockspace; in lockres_init()
196 res->mddev = mddev; in lockres_init()
197 res->mode = DLM_LOCK_IV; in lockres_init()
199 res->name = kzalloc(namelen + 1, GFP_KERNEL); in lockres_init()
200 if (!res->name) { in lockres_init()
201 pr_err("md-cluster: Unable to allocate resource name for resource %s\n", name); in lockres_init()
204 strscpy(res->name, name, namelen + 1); in lockres_init()
206 res->lksb.sb_lvbptr = kzalloc(LVB_SIZE, GFP_KERNEL); in lockres_init()
207 if (!res->lksb.sb_lvbptr) { in lockres_init()
208 pr_err("md-cluster: Unable to allocate LVB for resource %s\n", name); in lockres_init()
211 res->flags = DLM_LKF_VALBLK; in lockres_init()
215 res->bast = bastfn; in lockres_init()
217 res->flags |= DLM_LKF_EXPEDITE; in lockres_init()
221 pr_err("md-cluster: Unable to lock NL on new lock resource %s\n", name); in lockres_init()
224 res->flags &= ~DLM_LKF_EXPEDITE; in lockres_init()
225 res->flags |= DLM_LKF_CONVERT; in lockres_init()
229 kfree(res->lksb.sb_lvbptr); in lockres_init()
230 kfree(res->name); in lockres_init()
246 ret = dlm_unlock(res->ls, res->lksb.sb_lkid, DLM_LKF_FORCEUNLOCK, in lockres_free()
247 &res->lksb, res); in lockres_free()
249 pr_err("failed to unlock %s return %d\n", res->name, ret); in lockres_free()
251 wait_event(res->sync_locking, res->sync_locking_done); in lockres_free()
253 kfree(res->name); in lockres_free()
254 kfree(res->lksb.sb_lvbptr); in lockres_free()
263 ri = (struct resync_info *)lockres->lksb.sb_lvbptr; in add_resync_info()
264 ri->lo = cpu_to_le64(lo); in add_resync_info()
265 ri->hi = cpu_to_le64(hi); in add_resync_info()
272 struct md_cluster_info *cinfo = mddev->cluster_info; in read_resync_info()
276 memcpy(&ri, lockres->lksb.sb_lvbptr, sizeof(struct resync_info)); in read_resync_info()
278 cinfo->suspend_hi = le64_to_cpu(ri.hi); in read_resync_info()
279 cinfo->suspend_lo = le64_to_cpu(ri.lo); in read_resync_info()
288 struct mddev *mddev = thread->mddev; in recover_bitmaps()
289 struct md_cluster_info *cinfo = mddev->cluster_info; in recover_bitmaps()
295 while (cinfo->recovery_map) { in recover_bitmaps()
296 slot = fls64((u64)cinfo->recovery_map) - 1; in recover_bitmaps()
301 pr_err("md-cluster: Cannot initialize bitmaps\n"); in recover_bitmaps()
307 pr_err("md-cluster: Could not DLM lock %s: %d\n", in recover_bitmaps()
313 pr_err("md-cluster: Could not copy data from bitmap %d\n", slot); in recover_bitmaps()
318 spin_lock_irq(&cinfo->suspend_lock); in recover_bitmaps()
319 cinfo->suspend_hi = 0; in recover_bitmaps()
320 cinfo->suspend_lo = 0; in recover_bitmaps()
321 cinfo->suspend_from = -1; in recover_bitmaps()
322 spin_unlock_irq(&cinfo->suspend_lock); in recover_bitmaps()
325 if (test_bit(MD_RESYNCING_REMOTE, &mddev->recovery) && in recover_bitmaps()
326 test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && in recover_bitmaps()
327 mddev->reshape_position != MaxSector) in recover_bitmaps()
328 md_wakeup_thread(mddev->sync_thread); in recover_bitmaps()
331 if (lo < mddev->recovery_cp) in recover_bitmaps()
332 mddev->recovery_cp = lo; in recover_bitmaps()
335 if (mddev->recovery_cp != MaxSector) { in recover_bitmaps()
341 &mddev->recovery); in recover_bitmaps()
342 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); in recover_bitmaps()
343 md_wakeup_thread(mddev->thread); in recover_bitmaps()
348 clear_bit(slot, &cinfo->recovery_map); in recover_bitmaps()
355 struct md_cluster_info *cinfo = mddev->cluster_info; in recover_prep()
356 set_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state); in recover_prep()
361 struct md_cluster_info *cinfo = mddev->cluster_info; in __recover_slot()
363 set_bit(slot, &cinfo->recovery_map); in __recover_slot()
364 if (!cinfo->recovery_thread) { in __recover_slot()
365 rcu_assign_pointer(cinfo->recovery_thread, in __recover_slot()
367 if (!cinfo->recovery_thread) { in __recover_slot()
368 pr_warn("md-cluster: Could not create recovery thread\n"); in __recover_slot()
372 md_wakeup_thread(cinfo->recovery_thread); in __recover_slot()
378 struct md_cluster_info *cinfo = mddev->cluster_info; in recover_slot()
380 pr_info("md-cluster: %s Node %d/%d down. My slot: %d. Initiating recovery.\n", in recover_slot()
381 mddev->bitmap_info.cluster_name, in recover_slot()
382 slot->nodeid, slot->slot, in recover_slot()
383 cinfo->slot_number); in recover_slot()
385 * cluster-md begins with 0 */ in recover_slot()
386 __recover_slot(mddev, slot->slot - 1); in recover_slot()
394 struct md_cluster_info *cinfo = mddev->cluster_info; in recover_done()
396 cinfo->slot_number = our_slot; in recover_done()
399 if (test_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state)) { in recover_done()
400 complete(&cinfo->completion); in recover_done()
401 clear_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state); in recover_done()
403 clear_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state); in recover_done()
406 /* the ops is called when node join the cluster, and do lock recovery
419 static void ack_bast(void *arg, int mode) in ack_bast() argument
422 struct md_cluster_info *cinfo = res->mddev->cluster_info; in ack_bast()
424 if (mode == DLM_LOCK_EX) { in ack_bast()
425 if (test_bit(MD_CLUSTER_ALREADY_IN_CLUSTER, &cinfo->state)) in ack_bast()
426 md_wakeup_thread(cinfo->recv_thread); in ack_bast()
428 set_bit(MD_CLUSTER_PENDING_RECV_EVENT, &cinfo->state); in ack_bast()
434 struct md_cluster_info *cinfo = mddev->cluster_info; in remove_suspend_info()
435 mddev->pers->quiesce(mddev, 1); in remove_suspend_info()
436 spin_lock_irq(&cinfo->suspend_lock); in remove_suspend_info()
437 cinfo->suspend_hi = 0; in remove_suspend_info()
438 cinfo->suspend_lo = 0; in remove_suspend_info()
439 spin_unlock_irq(&cinfo->suspend_lock); in remove_suspend_info()
440 mddev->pers->quiesce(mddev, 0); in remove_suspend_info()
446 struct md_cluster_info *cinfo = mddev->cluster_info; in process_suspend_info()
452 * clear the REMOTE flag since resync or recovery is finished in process_suspend_info()
455 clear_bit(MD_RESYNCING_REMOTE, &mddev->recovery); in process_suspend_info()
457 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); in process_suspend_info()
458 md_wakeup_thread(mddev->thread); in process_suspend_info()
463 if (rdev->raid_disk > -1 && !test_bit(Faulty, &rdev->flags)) { in process_suspend_info()
464 sb = page_address(rdev->sb_page); in process_suspend_info()
489 if (sb && !(le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) in process_suspend_info()
490 md_bitmap_sync_with_cluster(mddev, cinfo->sync_low, in process_suspend_info()
491 cinfo->sync_hi, lo, hi); in process_suspend_info()
492 cinfo->sync_low = lo; in process_suspend_info()
493 cinfo->sync_hi = hi; in process_suspend_info()
495 mddev->pers->quiesce(mddev, 1); in process_suspend_info()
496 spin_lock_irq(&cinfo->suspend_lock); in process_suspend_info()
497 cinfo->suspend_from = slot; in process_suspend_info()
498 cinfo->suspend_lo = lo; in process_suspend_info()
499 cinfo->suspend_hi = hi; in process_suspend_info()
500 spin_unlock_irq(&cinfo->suspend_lock); in process_suspend_info()
501 mddev->pers->quiesce(mddev, 0); in process_suspend_info()
507 struct md_cluster_info *cinfo = mddev->cluster_info; in process_add_new_disk()
515 sprintf(disk_uuid + len, "%pU", cmsg->uuid); in process_add_new_disk()
516 snprintf(raid_slot, 16, "RAID_DISK=%d", le32_to_cpu(cmsg->raid_slot)); in process_add_new_disk()
518 init_completion(&cinfo->newdisk_completion); in process_add_new_disk()
519 set_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state); in process_add_new_disk()
520 kobject_uevent_env(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE, envp); in process_add_new_disk()
521 if (!wait_for_completion_timeout(&cinfo->newdisk_completion, in process_add_new_disk()
523 pr_err("md-cluster(%s:%d): timeout on a new disk adding\n", in process_add_new_disk()
525 res = -1; in process_add_new_disk()
527 clear_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state); in process_add_new_disk()
536 struct md_cluster_info *cinfo = mddev->cluster_info; in process_metadata_update()
537 mddev->good_device_nr = le32_to_cpu(msg->raid_slot); in process_metadata_update()
539 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR); in process_metadata_update()
542 thread = rcu_dereference_protected(mddev->thread, true); in process_metadata_update()
543 wait_event(thread->wqueue, in process_metadata_update()
545 test_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state)); in process_metadata_update()
546 md_reload_sb(mddev, mddev->good_device_nr); in process_metadata_update()
556 rdev = md_find_rdev_nr_rcu(mddev, le32_to_cpu(msg->raid_slot)); in process_remove_disk()
558 set_bit(ClusterRemove, &rdev->flags); in process_remove_disk()
559 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); in process_remove_disk()
560 md_wakeup_thread(mddev->thread); in process_remove_disk()
564 __func__, __LINE__, le32_to_cpu(msg->raid_slot)); in process_remove_disk()
573 rdev = md_find_rdev_nr_rcu(mddev, le32_to_cpu(msg->raid_slot)); in process_readd_disk()
574 if (rdev && test_bit(Faulty, &rdev->flags)) in process_readd_disk()
575 clear_bit(Faulty, &rdev->flags); in process_readd_disk()
578 __func__, __LINE__, le32_to_cpu(msg->raid_slot)); in process_readd_disk()
586 if (WARN(mddev->cluster_info->slot_number - 1 == le32_to_cpu(msg->slot), in process_recvd_msg()
587 "node %d received its own msg\n", le32_to_cpu(msg->slot))) in process_recvd_msg()
588 return -1; in process_recvd_msg()
589 switch (le32_to_cpu(msg->type)) { in process_recvd_msg()
594 set_capacity_and_notify(mddev->gendisk, mddev->array_sectors); in process_recvd_msg()
597 set_bit(MD_RESYNCING_REMOTE, &mddev->recovery); in process_recvd_msg()
598 process_suspend_info(mddev, le32_to_cpu(msg->slot), in process_recvd_msg()
599 le64_to_cpu(msg->low), in process_recvd_msg()
600 le64_to_cpu(msg->high)); in process_recvd_msg()
604 ret = -1; in process_recvd_msg()
613 __recover_slot(mddev, le32_to_cpu(msg->slot)); in process_recvd_msg()
616 if (le64_to_cpu(msg->high) != mddev->pers->size(mddev, 0, 0)) in process_recvd_msg()
617 ret = md_bitmap_resize(mddev->bitmap, in process_recvd_msg()
618 le64_to_cpu(msg->high), 0, 0); in process_recvd_msg()
621 ret = -1; in process_recvd_msg()
623 __func__, __LINE__, msg->slot); in process_recvd_msg()
633 struct md_cluster_info *cinfo = thread->mddev->cluster_info; in recv_daemon()
634 struct dlm_lock_resource *ack_lockres = cinfo->ack_lockres; in recv_daemon()
635 struct dlm_lock_resource *message_lockres = cinfo->message_lockres; in recv_daemon()
639 mutex_lock(&cinfo->recv_mutex); in recv_daemon()
643 mutex_unlock(&cinfo->recv_mutex); in recv_daemon()
648 memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(struct cluster_msg)); in recv_daemon()
649 ret = process_recvd_msg(thread->mddev, &msg); in recv_daemon()
657 /*up-convert to PR on message_lockres*/ in recv_daemon()
670 mutex_unlock(&cinfo->recv_mutex); in recv_daemon()
681 error = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX); in lock_token()
683 pr_err("md-cluster(%s:%d): failed to get EX on TOKEN (%d)\n", in lock_token()
687 mutex_lock(&cinfo->recv_mutex); in lock_token()
698 struct mddev *mddev = cinfo->mddev; in lock_comm()
707 &cinfo->state)) { in lock_comm()
709 &cinfo->state); in lock_comm()
711 md_wakeup_thread(mddev->thread); in lock_comm()
715 wait_event(cinfo->wait, in lock_comm()
716 !test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state)); in lock_comm()
719 clear_bit_unlock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in lock_comm()
725 WARN_ON(cinfo->token_lockres->mode != DLM_LOCK_EX); in unlock_comm()
726 mutex_unlock(&cinfo->recv_mutex); in unlock_comm()
727 dlm_unlock_sync(cinfo->token_lockres); in unlock_comm()
728 clear_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state); in unlock_comm()
729 wake_up(&cinfo->wait); in unlock_comm()
736 * 1. Grabs the message lockresource in EX mode
747 int slot = cinfo->slot_number - 1; in __sendmsg()
749 cmsg->slot = cpu_to_le32(slot); in __sendmsg()
751 error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_EX); in __sendmsg()
753 pr_err("md-cluster: failed to get EX on MESSAGE (%d)\n", error); in __sendmsg()
757 memcpy(cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg, in __sendmsg()
759 /*down-convert EX to CW on Message*/ in __sendmsg()
760 error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CW); in __sendmsg()
762 pr_err("md-cluster: failed to convert EX to CW on MESSAGE(%d)\n", in __sendmsg()
767 /*up-convert CR to EX on Ack*/ in __sendmsg()
768 error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_EX); in __sendmsg()
770 pr_err("md-cluster: failed to convert CR to EX on ACK(%d)\n", in __sendmsg()
775 /*down-convert EX to CR on Ack*/ in __sendmsg()
776 error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR); in __sendmsg()
778 pr_err("md-cluster: failed to convert EX to CR on ACK(%d)\n", in __sendmsg()
784 error = dlm_unlock_sync(cinfo->message_lockres); in __sendmsg()
786 pr_err("md-cluster: failed convert to NL on MESSAGE(%d)\n", in __sendmsg()
810 struct md_cluster_info *cinfo = mddev->cluster_info; in gather_all_resync_info()
822 return -ENOMEM; in gather_all_resync_info()
823 if (i == (cinfo->slot_number - 1)) { in gather_all_resync_info()
828 bm_lockres->flags |= DLM_LKF_NOQUEUE; in gather_all_resync_info()
830 if (ret == -EAGAIN) { in gather_all_resync_info()
834 (unsigned long long) cinfo->suspend_lo, in gather_all_resync_info()
835 (unsigned long long) cinfo->suspend_hi, in gather_all_resync_info()
837 cinfo->suspend_from = i; in gather_all_resync_info()
848 /* Read the disk bitmap sb and check if it needs recovery */ in gather_all_resync_info()
851 pr_warn("md-cluster: Could not gather bitmaps from slot %d", i); in gather_all_resync_info()
855 if ((hi > 0) && (lo < mddev->recovery_cp)) { in gather_all_resync_info()
856 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); in gather_all_resync_info()
857 mddev->recovery_cp = lo; in gather_all_resync_info()
875 return -ENOMEM; in join()
877 INIT_LIST_HEAD(&cinfo->suspend_list); in join()
878 spin_lock_init(&cinfo->suspend_lock); in join()
879 init_completion(&cinfo->completion); in join()
880 set_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state); in join()
881 init_waitqueue_head(&cinfo->wait); in join()
882 mutex_init(&cinfo->recv_mutex); in join()
884 mddev->cluster_info = cinfo; in join()
885 cinfo->mddev = mddev; in join()
888 sprintf(str, "%pU", mddev->uuid); in join()
889 ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name, in join()
891 &ops_rv, &cinfo->lockspace); in join()
894 wait_for_completion(&cinfo->completion); in join()
895 if (nodes < cinfo->slot_number) { in join()
896 pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).", in join()
897 cinfo->slot_number, nodes); in join()
898 ret = -ERANGE; in join()
902 ret = -ENOMEM; in join()
903 rcu_assign_pointer(cinfo->recv_thread, in join()
905 if (!cinfo->recv_thread) { in join()
906 pr_err("md-cluster: cannot allocate memory for recv_thread!\n"); in join()
909 cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1); in join()
910 if (!cinfo->message_lockres) in join()
912 cinfo->token_lockres = lockres_init(mddev, "token", NULL, 0); in join()
913 if (!cinfo->token_lockres) in join()
915 cinfo->no_new_dev_lockres = lockres_init(mddev, "no-new-dev", NULL, 0); in join()
916 if (!cinfo->no_new_dev_lockres) in join()
919 ret = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX); in join()
921 ret = -EAGAIN; in join()
922 pr_err("md-cluster: can't join cluster to avoid lock issue\n"); in join()
925 cinfo->ack_lockres = lockres_init(mddev, "ack", ack_bast, 0); in join()
926 if (!cinfo->ack_lockres) { in join()
927 ret = -ENOMEM; in join()
931 if (dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR)) in join()
932 pr_err("md-cluster: failed to get a sync CR lock on ACK!(%d)\n", in join()
934 dlm_unlock_sync(cinfo->token_lockres); in join()
935 /* get sync CR lock on no-new-dev. */ in join()
936 if (dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR)) in join()
937 pr_err("md-cluster: failed to get a sync CR lock on no-new-dev!(%d)\n", ret); in join()
940 pr_info("md-cluster: Joined cluster %s slot %d\n", str, cinfo->slot_number); in join()
941 snprintf(str, 64, "bitmap%04d", cinfo->slot_number - 1); in join()
942 cinfo->bitmap_lockres = lockres_init(mddev, str, NULL, 1); in join()
943 if (!cinfo->bitmap_lockres) { in join()
944 ret = -ENOMEM; in join()
947 if (dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW)) { in join()
949 ret = -EINVAL; in join()
953 cinfo->resync_lockres = lockres_init(mddev, "resync", NULL, 0); in join()
954 if (!cinfo->resync_lockres) { in join()
955 ret = -ENOMEM; in join()
961 set_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in join()
962 md_unregister_thread(mddev, &cinfo->recovery_thread); in join()
963 md_unregister_thread(mddev, &cinfo->recv_thread); in join()
964 lockres_free(cinfo->message_lockres); in join()
965 lockres_free(cinfo->token_lockres); in join()
966 lockres_free(cinfo->ack_lockres); in join()
967 lockres_free(cinfo->no_new_dev_lockres); in join()
968 lockres_free(cinfo->resync_lockres); in join()
969 lockres_free(cinfo->bitmap_lockres); in join()
970 if (cinfo->lockspace) in join()
971 dlm_release_lockspace(cinfo->lockspace, 2); in join()
972 mddev->cluster_info = NULL; in join()
979 struct md_cluster_info *cinfo = mddev->cluster_info; in load_bitmaps()
983 pr_err("md-cluster: failed to gather all resyn infos\n"); in load_bitmaps()
984 set_bit(MD_CLUSTER_ALREADY_IN_CLUSTER, &cinfo->state); in load_bitmaps()
986 if (test_and_clear_bit(MD_CLUSTER_PENDING_RECV_EVENT, &cinfo->state)) in load_bitmaps()
987 md_wakeup_thread(cinfo->recv_thread); in load_bitmaps()
992 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_bitmap()
1006 struct md_cluster_info *cinfo = mddev->cluster_info; in leave()
1019 if ((cinfo->slot_number > 0 && mddev->recovery_cp != MaxSector) || in leave()
1020 (mddev->reshape_position != MaxSector && in leave()
1021 test_bit(MD_CLOSING, &mddev->flags))) in leave()
1024 set_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in leave()
1025 md_unregister_thread(mddev, &cinfo->recovery_thread); in leave()
1026 md_unregister_thread(mddev, &cinfo->recv_thread); in leave()
1027 lockres_free(cinfo->message_lockres); in leave()
1028 lockres_free(cinfo->token_lockres); in leave()
1029 lockres_free(cinfo->ack_lockres); in leave()
1030 lockres_free(cinfo->no_new_dev_lockres); in leave()
1031 lockres_free(cinfo->resync_lockres); in leave()
1032 lockres_free(cinfo->bitmap_lockres); in leave()
1034 dlm_release_lockspace(cinfo->lockspace, 2); in leave()
1040 * DLM starts the slot numbers from 1, wheras cluster-md
1045 struct md_cluster_info *cinfo = mddev->cluster_info; in slot_number()
1047 return cinfo->slot_number - 1; in slot_number()
1053 * If it is already locked, token is in EX mode, and hence lock_token()
1058 struct md_cluster_info *cinfo = mddev->cluster_info; in metadata_update_start()
1066 &cinfo->state); in metadata_update_start()
1068 md_wakeup_thread(mddev->thread); in metadata_update_start()
1070 wait_event(cinfo->wait, in metadata_update_start()
1071 !test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state) || in metadata_update_start()
1072 test_and_clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state)); in metadata_update_start()
1075 if (cinfo->token_lockres->mode == DLM_LOCK_EX) { in metadata_update_start()
1076 clear_bit_unlock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in metadata_update_start()
1081 clear_bit_unlock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in metadata_update_start()
1087 struct md_cluster_info *cinfo = mddev->cluster_info; in metadata_update_finish()
1091 int raid_slot = -1; in metadata_update_finish()
1098 if (rdev->raid_disk > -1 && !test_bit(Faulty, &rdev->flags)) { in metadata_update_finish()
1099 raid_slot = rdev->desc_nr; in metadata_update_finish()
1106 pr_warn("md-cluster: No good device id found to send\n"); in metadata_update_finish()
1107 clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); in metadata_update_finish()
1114 struct md_cluster_info *cinfo = mddev->cluster_info; in metadata_update_cancel()
1115 clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); in metadata_update_cancel()
1121 struct md_cluster_info *cinfo = mddev->cluster_info; in update_bitmap_size()
1139 struct bitmap *bitmap = mddev->bitmap; in resize_bitmaps()
1140 unsigned long my_pages = bitmap->counts.pages; in resize_bitmaps()
1151 for (i = 0; i < mddev->bitmap_info.nodes; i++) { in resize_bitmaps()
1152 if (i == md_cluster_ops->slot_number(mddev)) in resize_bitmaps()
1161 counts = &bitmap->counts; in resize_bitmaps()
1173 bm_lockres->flags |= DLM_LKF_NOQUEUE; in resize_bitmaps()
1176 counts->pages = my_pages; in resize_bitmaps()
1179 if (my_pages != counts->pages) in resize_bitmaps()
1192 return -1; in resize_bitmaps()
1203 int node_num = mddev->bitmap_info.nodes; in cluster_check_sync_size()
1204 int current_slot = md_cluster_ops->slot_number(mddev); in cluster_check_sync_size()
1205 struct bitmap *bitmap = mddev->bitmap; in cluster_check_sync_size()
1209 sb = kmap_atomic(bitmap->storage.sb_page); in cluster_check_sync_size()
1210 my_sync_size = sb->sync_size; in cluster_check_sync_size()
1220 return -1; in cluster_check_sync_size()
1230 pr_err("md-cluster: Cannot initialize %s\n", str); in cluster_check_sync_size()
1232 return -1; in cluster_check_sync_size()
1234 bm_lockres->flags |= DLM_LKF_NOQUEUE; in cluster_check_sync_size()
1240 sb = kmap_atomic(bitmap->storage.sb_page); in cluster_check_sync_size()
1242 sync_size = sb->sync_size; in cluster_check_sync_size()
1243 else if (sync_size != sb->sync_size) { in cluster_check_sync_size()
1246 return -1; in cluster_check_sync_size()
1252 return (my_sync_size == sync_size) ? 0 : -1; in cluster_check_sync_size()
1267 struct md_cluster_info *cinfo = mddev->cluster_info; in update_size()
1271 int raid_slot = -1; in update_size()
1282 if (rdev->raid_disk >= 0 && !test_bit(Faulty, &rdev->flags)) { in update_size()
1283 raid_slot = rdev->desc_nr; in update_size()
1301 pr_err("md-cluster: No good device id found to send\n"); in update_size()
1318 set_capacity_and_notify(mddev->gendisk, mddev->array_sectors); in update_size()
1321 ret = mddev->pers->resize(mddev, old_dev_sectors); in update_size()
1332 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_start()
1333 return dlm_lock_sync_interruptible(cinfo->resync_lockres, DLM_LOCK_EX, mddev); in resync_start()
1338 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_info_get()
1340 spin_lock_irq(&cinfo->suspend_lock); in resync_info_get()
1341 *lo = cinfo->suspend_lo; in resync_info_get()
1342 *hi = cinfo->suspend_hi; in resync_info_get()
1343 spin_unlock_irq(&cinfo->suspend_lock); in resync_info_get()
1348 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_info_update()
1354 memcpy(&ri, cinfo->bitmap_lockres->lksb.sb_lvbptr, sizeof(struct resync_info)); in resync_info_update()
1359 add_resync_info(cinfo->bitmap_lockres, lo, hi); in resync_info_update()
1360 /* Re-acquire the lock to refresh LVB */ in resync_info_update()
1361 dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW); in resync_info_update()
1368 * resync_finish (md_reap_sync_thread -> resync_finish) in resync_info_update()
1378 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_finish()
1381 clear_bit(MD_RESYNCING_REMOTE, &mddev->recovery); in resync_finish()
1387 if (!test_bit(MD_CLOSING, &mddev->flags)) in resync_finish()
1389 dlm_unlock_sync(cinfo->resync_lockres); in resync_finish()
1396 struct md_cluster_info *cinfo = mddev->cluster_info; in area_resyncing()
1400 test_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state)) in area_resyncing()
1403 spin_lock_irq(&cinfo->suspend_lock); in area_resyncing()
1404 if (hi > cinfo->suspend_lo && lo < cinfo->suspend_hi) in area_resyncing()
1406 spin_unlock_irq(&cinfo->suspend_lock); in area_resyncing()
1410 /* add_new_disk() - initiates a disk add
1416 struct md_cluster_info *cinfo = mddev->cluster_info; in add_new_disk()
1419 struct mdp_superblock_1 *sb = page_address(rdev->sb_page); in add_new_disk()
1420 char *uuid = sb->device_uuid; in add_new_disk()
1425 cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); in add_new_disk()
1427 return -EAGAIN; in add_new_disk()
1433 cinfo->no_new_dev_lockres->flags |= DLM_LKF_NOQUEUE; in add_new_disk()
1434 ret = dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_EX); in add_new_disk()
1435 cinfo->no_new_dev_lockres->flags &= ~DLM_LKF_NOQUEUE; in add_new_disk()
1437 if (ret == -EAGAIN) in add_new_disk()
1438 ret = -ENOENT; in add_new_disk()
1442 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR); in add_new_disk()
1446 * md_wakeup_thread(mddev->thread) in add_new_disk()
1447 * -> conf->thread (raid1d) in add_new_disk()
1448 * -> md_check_recovery -> md_update_sb in add_new_disk()
1449 * -> metadata_update_start/finish in add_new_disk()
1455 set_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); in add_new_disk()
1456 wake_up(&cinfo->wait); in add_new_disk()
1463 struct md_cluster_info *cinfo = mddev->cluster_info; in add_new_disk_cancel()
1464 clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); in add_new_disk_cancel()
1470 struct md_cluster_info *cinfo = mddev->cluster_info; in new_disk_ack()
1472 if (!test_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state)) { in new_disk_ack()
1473 pr_warn("md-cluster(%s): Spurious cluster confirmation\n", mdname(mddev)); in new_disk_ack()
1474 return -EINVAL; in new_disk_ack()
1478 dlm_unlock_sync(cinfo->no_new_dev_lockres); in new_disk_ack()
1479 complete(&cinfo->newdisk_completion); in new_disk_ack()
1486 struct md_cluster_info *cinfo = mddev->cluster_info; in remove_disk()
1488 cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); in remove_disk()
1496 struct md_cluster_info *cinfo = mddev->cluster_info; in lock_all_bitmaps()
1498 cinfo->other_bitmap_lockres = in lock_all_bitmaps()
1499 kcalloc(mddev->bitmap_info.nodes - 1, in lock_all_bitmaps()
1501 if (!cinfo->other_bitmap_lockres) { in lock_all_bitmaps()
1507 for (slot = 0; slot < mddev->bitmap_info.nodes; slot++) { in lock_all_bitmaps()
1513 cinfo->other_bitmap_lockres[i] = lockres_init(mddev, str, NULL, 1); in lock_all_bitmaps()
1514 if (!cinfo->other_bitmap_lockres[i]) in lock_all_bitmaps()
1515 return -ENOMEM; in lock_all_bitmaps()
1517 cinfo->other_bitmap_lockres[i]->flags |= DLM_LKF_NOQUEUE; in lock_all_bitmaps()
1518 ret = dlm_lock_sync(cinfo->other_bitmap_lockres[i], DLM_LOCK_PW); in lock_all_bitmaps()
1520 held = -1; in lock_all_bitmaps()
1529 struct md_cluster_info *cinfo = mddev->cluster_info; in unlock_all_bitmaps()
1533 if (cinfo->other_bitmap_lockres) { in unlock_all_bitmaps()
1534 for (i = 0; i < mddev->bitmap_info.nodes - 1; i++) { in unlock_all_bitmaps()
1535 if (cinfo->other_bitmap_lockres[i]) { in unlock_all_bitmaps()
1536 lockres_free(cinfo->other_bitmap_lockres[i]); in unlock_all_bitmaps()
1539 kfree(cinfo->other_bitmap_lockres); in unlock_all_bitmaps()
1540 cinfo->other_bitmap_lockres = NULL; in unlock_all_bitmaps()
1549 struct mddev *mddev = rdev->mddev; in gather_bitmaps()
1550 struct md_cluster_info *cinfo = mddev->cluster_info; in gather_bitmaps()
1553 cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); in gather_bitmaps()
1558 for (sn = 0; sn < mddev->bitmap_info.nodes; sn++) { in gather_bitmaps()
1559 if (sn == (cinfo->slot_number - 1)) in gather_bitmaps()
1563 pr_warn("md-cluster: Could not gather bitmaps from slot %d", sn); in gather_bitmaps()
1566 if ((hi > 0) && (lo < mddev->recovery_cp)) in gather_bitmaps()
1567 mddev->recovery_cp = lo; in gather_bitmaps()
1599 pr_warn("md-cluster: support raid1 and raid10 (limited support)\n"); in cluster_init()