Lines Matching +full:cluster +full:- +full:mode
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
46 /* If cluster operations (such as adding a disk) must lock the
54 /* We should receive message after node joined cluster and
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 cinfo->recovery_thread = md_register_thread(recover_bitmaps, 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()
397 /* completion is only need to be complete when node join cluster, 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()
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()
514 sprintf(disk_uuid + len, "%pU", cmsg->uuid); in process_add_new_disk()
515 snprintf(raid_slot, 16, "RAID_DISK=%d", le32_to_cpu(cmsg->raid_slot)); in process_add_new_disk()
517 init_completion(&cinfo->newdisk_completion); in process_add_new_disk()
518 set_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state); in process_add_new_disk()
519 kobject_uevent_env(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE, envp); in process_add_new_disk()
520 wait_for_completion_timeout(&cinfo->newdisk_completion, in process_add_new_disk()
522 clear_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state); in process_add_new_disk()
529 struct md_cluster_info *cinfo = mddev->cluster_info; in process_metadata_update()
530 mddev->good_device_nr = le32_to_cpu(msg->raid_slot); in process_metadata_update()
532 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR); in process_metadata_update()
533 wait_event(mddev->thread->wqueue, in process_metadata_update()
535 test_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state)); in process_metadata_update()
536 md_reload_sb(mddev, mddev->good_device_nr); in process_metadata_update()
546 rdev = md_find_rdev_nr_rcu(mddev, le32_to_cpu(msg->raid_slot)); in process_remove_disk()
548 set_bit(ClusterRemove, &rdev->flags); in process_remove_disk()
549 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); in process_remove_disk()
550 md_wakeup_thread(mddev->thread); in process_remove_disk()
554 __func__, __LINE__, le32_to_cpu(msg->raid_slot)); in process_remove_disk()
563 rdev = md_find_rdev_nr_rcu(mddev, le32_to_cpu(msg->raid_slot)); in process_readd_disk()
564 if (rdev && test_bit(Faulty, &rdev->flags)) in process_readd_disk()
565 clear_bit(Faulty, &rdev->flags); in process_readd_disk()
568 __func__, __LINE__, le32_to_cpu(msg->raid_slot)); in process_readd_disk()
576 if (WARN(mddev->cluster_info->slot_number - 1 == le32_to_cpu(msg->slot), in process_recvd_msg()
577 "node %d received its own msg\n", le32_to_cpu(msg->slot))) in process_recvd_msg()
578 return -1; in process_recvd_msg()
579 switch (le32_to_cpu(msg->type)) { in process_recvd_msg()
584 set_capacity_and_notify(mddev->gendisk, mddev->array_sectors); in process_recvd_msg()
587 set_bit(MD_RESYNCING_REMOTE, &mddev->recovery); in process_recvd_msg()
588 process_suspend_info(mddev, le32_to_cpu(msg->slot), in process_recvd_msg()
589 le64_to_cpu(msg->low), in process_recvd_msg()
590 le64_to_cpu(msg->high)); in process_recvd_msg()
602 __recover_slot(mddev, le32_to_cpu(msg->slot)); in process_recvd_msg()
605 if (le64_to_cpu(msg->high) != mddev->pers->size(mddev, 0, 0)) in process_recvd_msg()
606 ret = md_bitmap_resize(mddev->bitmap, in process_recvd_msg()
607 le64_to_cpu(msg->high), 0, 0); in process_recvd_msg()
610 ret = -1; in process_recvd_msg()
612 __func__, __LINE__, msg->slot); in process_recvd_msg()
622 struct md_cluster_info *cinfo = thread->mddev->cluster_info; in recv_daemon()
623 struct dlm_lock_resource *ack_lockres = cinfo->ack_lockres; in recv_daemon()
624 struct dlm_lock_resource *message_lockres = cinfo->message_lockres; in recv_daemon()
628 mutex_lock(&cinfo->recv_mutex); in recv_daemon()
632 mutex_unlock(&cinfo->recv_mutex); in recv_daemon()
637 memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(struct cluster_msg)); in recv_daemon()
638 ret = process_recvd_msg(thread->mddev, &msg); in recv_daemon()
646 /*up-convert to PR on message_lockres*/ in recv_daemon()
659 mutex_unlock(&cinfo->recv_mutex); in recv_daemon()
670 error = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX); in lock_token()
672 pr_err("md-cluster(%s:%d): failed to get EX on TOKEN (%d)\n", in lock_token()
676 mutex_lock(&cinfo->recv_mutex); in lock_token()
687 struct mddev *mddev = cinfo->mddev; in lock_comm()
696 &cinfo->state)) { in lock_comm()
698 &cinfo->state); in lock_comm()
700 md_wakeup_thread(mddev->thread); in lock_comm()
704 wait_event(cinfo->wait, in lock_comm()
705 !test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state)); in lock_comm()
708 clear_bit_unlock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in lock_comm()
714 WARN_ON(cinfo->token_lockres->mode != DLM_LOCK_EX); in unlock_comm()
715 mutex_unlock(&cinfo->recv_mutex); in unlock_comm()
716 dlm_unlock_sync(cinfo->token_lockres); in unlock_comm()
717 clear_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state); in unlock_comm()
718 wake_up(&cinfo->wait); in unlock_comm()
725 * 1. Grabs the message lockresource in EX mode
736 int slot = cinfo->slot_number - 1; in __sendmsg()
738 cmsg->slot = cpu_to_le32(slot); in __sendmsg()
740 error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_EX); in __sendmsg()
742 pr_err("md-cluster: failed to get EX on MESSAGE (%d)\n", error); in __sendmsg()
746 memcpy(cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg, in __sendmsg()
748 /*down-convert EX to CW on Message*/ in __sendmsg()
749 error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CW); in __sendmsg()
751 pr_err("md-cluster: failed to convert EX to CW on MESSAGE(%d)\n", in __sendmsg()
756 /*up-convert CR to EX on Ack*/ in __sendmsg()
757 error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_EX); in __sendmsg()
759 pr_err("md-cluster: failed to convert CR to EX on ACK(%d)\n", in __sendmsg()
764 /*down-convert EX to CR on Ack*/ in __sendmsg()
765 error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR); in __sendmsg()
767 pr_err("md-cluster: failed to convert EX to CR on ACK(%d)\n", in __sendmsg()
773 error = dlm_unlock_sync(cinfo->message_lockres); in __sendmsg()
775 pr_err("md-cluster: failed convert to NL on MESSAGE(%d)\n", in __sendmsg()
799 struct md_cluster_info *cinfo = mddev->cluster_info; in gather_all_resync_info()
811 return -ENOMEM; in gather_all_resync_info()
812 if (i == (cinfo->slot_number - 1)) { in gather_all_resync_info()
817 bm_lockres->flags |= DLM_LKF_NOQUEUE; in gather_all_resync_info()
819 if (ret == -EAGAIN) { in gather_all_resync_info()
823 (unsigned long long) cinfo->suspend_lo, in gather_all_resync_info()
824 (unsigned long long) cinfo->suspend_hi, in gather_all_resync_info()
826 cinfo->suspend_from = i; in gather_all_resync_info()
840 pr_warn("md-cluster: Could not gather bitmaps from slot %d", i); in gather_all_resync_info()
844 if ((hi > 0) && (lo < mddev->recovery_cp)) { in gather_all_resync_info()
845 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); in gather_all_resync_info()
846 mddev->recovery_cp = lo; in gather_all_resync_info()
864 return -ENOMEM; in join()
866 INIT_LIST_HEAD(&cinfo->suspend_list); in join()
867 spin_lock_init(&cinfo->suspend_lock); in join()
868 init_completion(&cinfo->completion); in join()
869 set_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state); in join()
870 init_waitqueue_head(&cinfo->wait); in join()
871 mutex_init(&cinfo->recv_mutex); in join()
873 mddev->cluster_info = cinfo; in join()
874 cinfo->mddev = mddev; in join()
877 sprintf(str, "%pU", mddev->uuid); in join()
878 ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name, in join()
880 &ops_rv, &cinfo->lockspace); in join()
883 wait_for_completion(&cinfo->completion); in join()
884 if (nodes < cinfo->slot_number) { in join()
885 pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).", in join()
886 cinfo->slot_number, nodes); in join()
887 ret = -ERANGE; in join()
891 ret = -ENOMEM; in join()
892 cinfo->recv_thread = md_register_thread(recv_daemon, mddev, "cluster_recv"); in join()
893 if (!cinfo->recv_thread) { in join()
894 pr_err("md-cluster: cannot allocate memory for recv_thread!\n"); in join()
897 cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1); in join()
898 if (!cinfo->message_lockres) in join()
900 cinfo->token_lockres = lockres_init(mddev, "token", NULL, 0); in join()
901 if (!cinfo->token_lockres) in join()
903 cinfo->no_new_dev_lockres = lockres_init(mddev, "no-new-dev", NULL, 0); in join()
904 if (!cinfo->no_new_dev_lockres) in join()
907 ret = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX); in join()
909 ret = -EAGAIN; in join()
910 pr_err("md-cluster: can't join cluster to avoid lock issue\n"); in join()
913 cinfo->ack_lockres = lockres_init(mddev, "ack", ack_bast, 0); in join()
914 if (!cinfo->ack_lockres) { in join()
915 ret = -ENOMEM; in join()
919 if (dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR)) in join()
920 pr_err("md-cluster: failed to get a sync CR lock on ACK!(%d)\n", in join()
922 dlm_unlock_sync(cinfo->token_lockres); in join()
923 /* get sync CR lock on no-new-dev. */ in join()
924 if (dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR)) in join()
925 pr_err("md-cluster: failed to get a sync CR lock on no-new-dev!(%d)\n", ret); in join()
928 pr_info("md-cluster: Joined cluster %s slot %d\n", str, cinfo->slot_number); in join()
929 snprintf(str, 64, "bitmap%04d", cinfo->slot_number - 1); in join()
930 cinfo->bitmap_lockres = lockres_init(mddev, str, NULL, 1); in join()
931 if (!cinfo->bitmap_lockres) { in join()
932 ret = -ENOMEM; in join()
935 if (dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW)) { in join()
937 ret = -EINVAL; in join()
941 cinfo->resync_lockres = lockres_init(mddev, "resync", NULL, 0); in join()
942 if (!cinfo->resync_lockres) { in join()
943 ret = -ENOMEM; in join()
949 set_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in join()
950 md_unregister_thread(&cinfo->recovery_thread); in join()
951 md_unregister_thread(&cinfo->recv_thread); in join()
952 lockres_free(cinfo->message_lockres); in join()
953 lockres_free(cinfo->token_lockres); in join()
954 lockres_free(cinfo->ack_lockres); in join()
955 lockres_free(cinfo->no_new_dev_lockres); in join()
956 lockres_free(cinfo->resync_lockres); in join()
957 lockres_free(cinfo->bitmap_lockres); in join()
958 if (cinfo->lockspace) in join()
959 dlm_release_lockspace(cinfo->lockspace, 2); in join()
960 mddev->cluster_info = NULL; in join()
967 struct md_cluster_info *cinfo = mddev->cluster_info; in load_bitmaps()
971 pr_err("md-cluster: failed to gather all resyn infos\n"); in load_bitmaps()
972 set_bit(MD_CLUSTER_ALREADY_IN_CLUSTER, &cinfo->state); in load_bitmaps()
974 if (test_and_clear_bit(MD_CLUSTER_PENDING_RECV_EVENT, &cinfo->state)) in load_bitmaps()
975 md_wakeup_thread(cinfo->recv_thread); in load_bitmaps()
980 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_bitmap()
994 struct md_cluster_info *cinfo = mddev->cluster_info; in leave()
1001 * is leaving the cluster with dirty bitmap, also we in leave()
1007 if ((cinfo->slot_number > 0 && mddev->recovery_cp != MaxSector) || in leave()
1008 (mddev->reshape_position != MaxSector && in leave()
1009 test_bit(MD_CLOSING, &mddev->flags))) in leave()
1012 set_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in leave()
1013 md_unregister_thread(&cinfo->recovery_thread); in leave()
1014 md_unregister_thread(&cinfo->recv_thread); in leave()
1015 lockres_free(cinfo->message_lockres); in leave()
1016 lockres_free(cinfo->token_lockres); in leave()
1017 lockres_free(cinfo->ack_lockres); in leave()
1018 lockres_free(cinfo->no_new_dev_lockres); in leave()
1019 lockres_free(cinfo->resync_lockres); in leave()
1020 lockres_free(cinfo->bitmap_lockres); in leave()
1022 dlm_release_lockspace(cinfo->lockspace, 2); in leave()
1028 * DLM starts the slot numbers from 1, wheras cluster-md
1033 struct md_cluster_info *cinfo = mddev->cluster_info; in slot_number()
1035 return cinfo->slot_number - 1; in slot_number()
1041 * If it is already locked, token is in EX mode, and hence lock_token()
1046 struct md_cluster_info *cinfo = mddev->cluster_info; in metadata_update_start()
1054 &cinfo->state); in metadata_update_start()
1056 md_wakeup_thread(mddev->thread); in metadata_update_start()
1058 wait_event(cinfo->wait, in metadata_update_start()
1059 !test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state) || in metadata_update_start()
1060 test_and_clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state)); in metadata_update_start()
1063 if (cinfo->token_lockres->mode == DLM_LOCK_EX) { in metadata_update_start()
1064 clear_bit_unlock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in metadata_update_start()
1069 clear_bit_unlock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state); in metadata_update_start()
1075 struct md_cluster_info *cinfo = mddev->cluster_info; in metadata_update_finish()
1079 int raid_slot = -1; in metadata_update_finish()
1086 if (rdev->raid_disk > -1 && !test_bit(Faulty, &rdev->flags)) { in metadata_update_finish()
1087 raid_slot = rdev->desc_nr; in metadata_update_finish()
1094 pr_warn("md-cluster: No good device id found to send\n"); in metadata_update_finish()
1095 clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); in metadata_update_finish()
1102 struct md_cluster_info *cinfo = mddev->cluster_info; in metadata_update_cancel()
1103 clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); in metadata_update_cancel()
1109 struct md_cluster_info *cinfo = mddev->cluster_info; in update_bitmap_size()
1127 struct bitmap *bitmap = mddev->bitmap; in resize_bitmaps()
1128 unsigned long my_pages = bitmap->counts.pages; in resize_bitmaps()
1139 for (i = 0; i < mddev->bitmap_info.nodes; i++) { in resize_bitmaps()
1140 if (i == md_cluster_ops->slot_number(mddev)) in resize_bitmaps()
1149 counts = &bitmap->counts; in resize_bitmaps()
1161 bm_lockres->flags |= DLM_LKF_NOQUEUE; in resize_bitmaps()
1164 counts->pages = my_pages; in resize_bitmaps()
1167 if (my_pages != counts->pages) in resize_bitmaps()
1180 return -1; in resize_bitmaps()
1191 int node_num = mddev->bitmap_info.nodes; in cluster_check_sync_size()
1192 int current_slot = md_cluster_ops->slot_number(mddev); in cluster_check_sync_size()
1193 struct bitmap *bitmap = mddev->bitmap; in cluster_check_sync_size()
1197 sb = kmap_atomic(bitmap->storage.sb_page); in cluster_check_sync_size()
1198 my_sync_size = sb->sync_size; in cluster_check_sync_size()
1208 return -1; in cluster_check_sync_size()
1218 pr_err("md-cluster: Cannot initialize %s\n", str); in cluster_check_sync_size()
1220 return -1; in cluster_check_sync_size()
1222 bm_lockres->flags |= DLM_LKF_NOQUEUE; in cluster_check_sync_size()
1228 sb = kmap_atomic(bitmap->storage.sb_page); in cluster_check_sync_size()
1230 sync_size = sb->sync_size; in cluster_check_sync_size()
1231 else if (sync_size != sb->sync_size) { in cluster_check_sync_size()
1234 return -1; in cluster_check_sync_size()
1240 return (my_sync_size == sync_size) ? 0 : -1; in cluster_check_sync_size()
1244 * Update the size for cluster raid is a little more complex, we perform it
1255 struct md_cluster_info *cinfo = mddev->cluster_info; in update_size()
1259 int raid_slot = -1; in update_size()
1270 if (rdev->raid_disk >= 0 && !test_bit(Faulty, &rdev->flags)) { in update_size()
1271 raid_slot = rdev->desc_nr; in update_size()
1289 pr_err("md-cluster: No good device id found to send\n"); in update_size()
1306 set_capacity_and_notify(mddev->gendisk, mddev->array_sectors); in update_size()
1309 ret = mddev->pers->resize(mddev, old_dev_sectors); in update_size()
1320 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_start()
1321 return dlm_lock_sync_interruptible(cinfo->resync_lockres, DLM_LOCK_EX, mddev); in resync_start()
1326 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_info_get()
1328 spin_lock_irq(&cinfo->suspend_lock); in resync_info_get()
1329 *lo = cinfo->suspend_lo; in resync_info_get()
1330 *hi = cinfo->suspend_hi; in resync_info_get()
1331 spin_unlock_irq(&cinfo->suspend_lock); in resync_info_get()
1336 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_info_update()
1342 memcpy(&ri, cinfo->bitmap_lockres->lksb.sb_lvbptr, sizeof(struct resync_info)); in resync_info_update()
1347 add_resync_info(cinfo->bitmap_lockres, lo, hi); in resync_info_update()
1348 /* Re-acquire the lock to refresh LVB */ in resync_info_update()
1349 dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW); in resync_info_update()
1356 * resync_finish (md_reap_sync_thread -> resync_finish) in resync_info_update()
1366 struct md_cluster_info *cinfo = mddev->cluster_info; in resync_finish()
1369 clear_bit(MD_RESYNCING_REMOTE, &mddev->recovery); in resync_finish()
1375 if (!test_bit(MD_CLOSING, &mddev->flags)) in resync_finish()
1377 dlm_unlock_sync(cinfo->resync_lockres); in resync_finish()
1384 struct md_cluster_info *cinfo = mddev->cluster_info; in area_resyncing()
1388 test_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state)) in area_resyncing()
1391 spin_lock_irq(&cinfo->suspend_lock); in area_resyncing()
1392 if (hi > cinfo->suspend_lo && lo < cinfo->suspend_hi) in area_resyncing()
1394 spin_unlock_irq(&cinfo->suspend_lock); in area_resyncing()
1398 /* add_new_disk() - initiates a disk add
1404 struct md_cluster_info *cinfo = mddev->cluster_info; in add_new_disk()
1407 struct mdp_superblock_1 *sb = page_address(rdev->sb_page); in add_new_disk()
1408 char *uuid = sb->device_uuid; in add_new_disk()
1413 cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); in add_new_disk()
1415 return -EAGAIN; in add_new_disk()
1421 cinfo->no_new_dev_lockres->flags |= DLM_LKF_NOQUEUE; in add_new_disk()
1422 ret = dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_EX); in add_new_disk()
1423 cinfo->no_new_dev_lockres->flags &= ~DLM_LKF_NOQUEUE; in add_new_disk()
1425 if (ret == -EAGAIN) in add_new_disk()
1426 ret = -ENOENT; in add_new_disk()
1430 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR); in add_new_disk()
1434 * md_wakeup_thread(mddev->thread) in add_new_disk()
1435 * -> conf->thread (raid1d) in add_new_disk()
1436 * -> md_check_recovery -> md_update_sb in add_new_disk()
1437 * -> metadata_update_start/finish in add_new_disk()
1443 set_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); in add_new_disk()
1444 wake_up(&cinfo->wait); in add_new_disk()
1451 struct md_cluster_info *cinfo = mddev->cluster_info; in add_new_disk_cancel()
1452 clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); in add_new_disk_cancel()
1458 struct md_cluster_info *cinfo = mddev->cluster_info; in new_disk_ack()
1460 if (!test_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state)) { in new_disk_ack()
1461 pr_warn("md-cluster(%s): Spurious cluster confirmation\n", mdname(mddev)); in new_disk_ack()
1462 return -EINVAL; in new_disk_ack()
1466 dlm_unlock_sync(cinfo->no_new_dev_lockres); in new_disk_ack()
1467 complete(&cinfo->newdisk_completion); in new_disk_ack()
1474 struct md_cluster_info *cinfo = mddev->cluster_info; in remove_disk()
1476 cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); in remove_disk()
1484 struct md_cluster_info *cinfo = mddev->cluster_info; in lock_all_bitmaps()
1486 cinfo->other_bitmap_lockres = in lock_all_bitmaps()
1487 kcalloc(mddev->bitmap_info.nodes - 1, in lock_all_bitmaps()
1489 if (!cinfo->other_bitmap_lockres) { in lock_all_bitmaps()
1495 for (slot = 0; slot < mddev->bitmap_info.nodes; slot++) { in lock_all_bitmaps()
1501 cinfo->other_bitmap_lockres[i] = lockres_init(mddev, str, NULL, 1); in lock_all_bitmaps()
1502 if (!cinfo->other_bitmap_lockres[i]) in lock_all_bitmaps()
1503 return -ENOMEM; in lock_all_bitmaps()
1505 cinfo->other_bitmap_lockres[i]->flags |= DLM_LKF_NOQUEUE; in lock_all_bitmaps()
1506 ret = dlm_lock_sync(cinfo->other_bitmap_lockres[i], DLM_LOCK_PW); in lock_all_bitmaps()
1508 held = -1; in lock_all_bitmaps()
1517 struct md_cluster_info *cinfo = mddev->cluster_info; in unlock_all_bitmaps()
1521 if (cinfo->other_bitmap_lockres) { in unlock_all_bitmaps()
1522 for (i = 0; i < mddev->bitmap_info.nodes - 1; i++) { in unlock_all_bitmaps()
1523 if (cinfo->other_bitmap_lockres[i]) { in unlock_all_bitmaps()
1524 lockres_free(cinfo->other_bitmap_lockres[i]); in unlock_all_bitmaps()
1527 kfree(cinfo->other_bitmap_lockres); in unlock_all_bitmaps()
1528 cinfo->other_bitmap_lockres = NULL; in unlock_all_bitmaps()
1537 struct mddev *mddev = rdev->mddev; in gather_bitmaps()
1538 struct md_cluster_info *cinfo = mddev->cluster_info; in gather_bitmaps()
1541 cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); in gather_bitmaps()
1546 for (sn = 0; sn < mddev->bitmap_info.nodes; sn++) { in gather_bitmaps()
1547 if (sn == (cinfo->slot_number - 1)) in gather_bitmaps()
1551 pr_warn("md-cluster: Could not gather bitmaps from slot %d", sn); in gather_bitmaps()
1554 if ((hi > 0) && (lo < mddev->recovery_cp)) in gather_bitmaps()
1555 mddev->recovery_cp = lo; in gather_bitmaps()
1587 pr_warn("md-cluster: support raid1 and raid10 (limited support)\n"); in cluster_init()
1588 pr_info("Registering Cluster MD functions\n"); in cluster_init()