2 * Copyright (C) 2015, SUSE
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
12 #include <linux/module.h>
13 #include <linux/dlm.h>
14 #include <linux/sched.h>
15 #include <linux/raid/md_p.h>
18 #include "md-cluster.h"
21 #define NEW_DEV_TIMEOUT 5000
23 struct dlm_lock_resource {
26 char *name; /* lock name. */
27 uint32_t flags; /* flags to pass to dlm_lock() */
28 struct completion completion; /* completion for synchronized locking */
29 void (*bast)(void *arg, int mode); /* blocking AST function pointer*/
30 struct mddev *mddev; /* pointing back to mddev. */
37 struct list_head list;
45 /* md_cluster_info flags */
46 #define MD_CLUSTER_WAITING_FOR_NEWDISK 1
49 struct md_cluster_info {
50 /* dlm lock space and resources for clustered raid. */
51 dlm_lockspace_t *lockspace;
53 struct completion completion;
54 struct dlm_lock_resource *sb_lock;
55 struct mutex sb_mutex;
56 struct dlm_lock_resource *bitmap_lockres;
57 struct list_head suspend_list;
58 spinlock_t suspend_lock;
59 struct md_thread *recovery_thread;
60 unsigned long recovery_map;
61 /* communication loc resources */
62 struct dlm_lock_resource *ack_lockres;
63 struct dlm_lock_resource *message_lockres;
64 struct dlm_lock_resource *token_lockres;
65 struct dlm_lock_resource *no_new_dev_lockres;
66 struct md_thread *recv_thread;
67 struct completion newdisk_completion;
81 /* TODO: Unionize this for smaller footprint */
88 static void sync_ast(void *arg)
90 struct dlm_lock_resource *res;
92 res = (struct dlm_lock_resource *) arg;
93 complete(&res->completion);
96 static int dlm_lock_sync(struct dlm_lock_resource *res, int mode)
100 init_completion(&res->completion);
101 ret = dlm_lock(res->ls, mode, &res->lksb,
102 res->flags, res->name, strlen(res->name),
103 0, sync_ast, res, res->bast);
106 wait_for_completion(&res->completion);
107 return res->lksb.sb_status;
110 static int dlm_unlock_sync(struct dlm_lock_resource *res)
112 return dlm_lock_sync(res, DLM_LOCK_NL);
115 static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
116 char *name, void (*bastfn)(void *arg, int mode), int with_lvb)
118 struct dlm_lock_resource *res = NULL;
120 struct md_cluster_info *cinfo = mddev->cluster_info;
122 res = kzalloc(sizeof(struct dlm_lock_resource), GFP_KERNEL);
125 res->ls = cinfo->lockspace;
127 namelen = strlen(name);
128 res->name = kzalloc(namelen + 1, GFP_KERNEL);
130 pr_err("md-cluster: Unable to allocate resource name for resource %s\n", name);
133 strlcpy(res->name, name, namelen + 1);
135 res->lksb.sb_lvbptr = kzalloc(LVB_SIZE, GFP_KERNEL);
136 if (!res->lksb.sb_lvbptr) {
137 pr_err("md-cluster: Unable to allocate LVB for resource %s\n", name);
140 res->flags = DLM_LKF_VALBLK;
146 res->flags |= DLM_LKF_EXPEDITE;
148 ret = dlm_lock_sync(res, DLM_LOCK_NL);
150 pr_err("md-cluster: Unable to lock NL on new lock resource %s\n", name);
153 res->flags &= ~DLM_LKF_EXPEDITE;
154 res->flags |= DLM_LKF_CONVERT;
158 kfree(res->lksb.sb_lvbptr);
164 static void lockres_free(struct dlm_lock_resource *res)
169 init_completion(&res->completion);
170 dlm_unlock(res->ls, res->lksb.sb_lkid, 0, &res->lksb, res);
171 wait_for_completion(&res->completion);
174 kfree(res->lksb.sb_lvbptr);
178 static char *pretty_uuid(char *dest, char *src)
182 for (i = 0; i < 16; i++) {
183 if (i == 4 || i == 6 || i == 8 || i == 10)
184 len += sprintf(dest + len, "-");
185 len += sprintf(dest + len, "%02x", (__u8)src[i]);
190 static void add_resync_info(struct mddev *mddev, struct dlm_lock_resource *lockres,
191 sector_t lo, sector_t hi)
193 struct resync_info *ri;
195 ri = (struct resync_info *)lockres->lksb.sb_lvbptr;
196 ri->lo = cpu_to_le64(lo);
197 ri->hi = cpu_to_le64(hi);
200 static struct suspend_info *read_resync_info(struct mddev *mddev, struct dlm_lock_resource *lockres)
202 struct resync_info ri;
203 struct suspend_info *s = NULL;
206 dlm_lock_sync(lockres, DLM_LOCK_CR);
207 memcpy(&ri, lockres->lksb.sb_lvbptr, sizeof(struct resync_info));
208 hi = le64_to_cpu(ri.hi);
210 s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL);
214 s->lo = le64_to_cpu(ri.lo);
216 dlm_unlock_sync(lockres);
221 static void recover_bitmaps(struct md_thread *thread)
223 struct mddev *mddev = thread->mddev;
224 struct md_cluster_info *cinfo = mddev->cluster_info;
225 struct dlm_lock_resource *bm_lockres;
228 struct suspend_info *s, *tmp;
231 while (cinfo->recovery_map) {
232 slot = fls64((u64)cinfo->recovery_map) - 1;
234 /* Clear suspend_area associated with the bitmap */
235 spin_lock_irq(&cinfo->suspend_lock);
236 list_for_each_entry_safe(s, tmp, &cinfo->suspend_list, list)
237 if (slot == s->slot) {
241 spin_unlock_irq(&cinfo->suspend_lock);
243 snprintf(str, 64, "bitmap%04d", slot);
244 bm_lockres = lockres_init(mddev, str, NULL, 1);
246 pr_err("md-cluster: Cannot initialize bitmaps\n");
250 ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
252 pr_err("md-cluster: Could not DLM lock %s: %d\n",
256 ret = bitmap_copy_from_slot(mddev, slot, &lo, &hi);
258 pr_err("md-cluster: Could not copy data from bitmap %d\n", slot);
262 /* TODO:Wait for current resync to get over */
263 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
264 if (lo < mddev->recovery_cp)
265 mddev->recovery_cp = lo;
266 md_check_recovery(mddev);
269 dlm_unlock_sync(bm_lockres);
271 clear_bit(slot, &cinfo->recovery_map);
275 static void recover_prep(void *arg)
279 static void recover_slot(void *arg, struct dlm_slot *slot)
281 struct mddev *mddev = arg;
282 struct md_cluster_info *cinfo = mddev->cluster_info;
284 pr_info("md-cluster: %s Node %d/%d down. My slot: %d. Initiating recovery.\n",
285 mddev->bitmap_info.cluster_name,
286 slot->nodeid, slot->slot,
288 set_bit(slot->slot - 1, &cinfo->recovery_map);
289 if (!cinfo->recovery_thread) {
290 cinfo->recovery_thread = md_register_thread(recover_bitmaps,
292 if (!cinfo->recovery_thread) {
293 pr_warn("md-cluster: Could not create recovery thread\n");
297 md_wakeup_thread(cinfo->recovery_thread);
300 static void recover_done(void *arg, struct dlm_slot *slots,
301 int num_slots, int our_slot,
304 struct mddev *mddev = arg;
305 struct md_cluster_info *cinfo = mddev->cluster_info;
307 cinfo->slot_number = our_slot;
308 complete(&cinfo->completion);
311 static const struct dlm_lockspace_ops md_ls_ops = {
312 .recover_prep = recover_prep,
313 .recover_slot = recover_slot,
314 .recover_done = recover_done,
318 * The BAST function for the ack lock resource
319 * This function wakes up the receive thread in
320 * order to receive and process the message.
322 static void ack_bast(void *arg, int mode)
324 struct dlm_lock_resource *res = (struct dlm_lock_resource *)arg;
325 struct md_cluster_info *cinfo = res->mddev->cluster_info;
327 if (mode == DLM_LOCK_EX)
328 md_wakeup_thread(cinfo->recv_thread);
331 static void __remove_suspend_info(struct md_cluster_info *cinfo, int slot)
333 struct suspend_info *s, *tmp;
335 list_for_each_entry_safe(s, tmp, &cinfo->suspend_list, list)
336 if (slot == s->slot) {
337 pr_info("%s:%d Deleting suspend_info: %d\n",
338 __func__, __LINE__, slot);
345 static void remove_suspend_info(struct md_cluster_info *cinfo, int slot)
347 spin_lock_irq(&cinfo->suspend_lock);
348 __remove_suspend_info(cinfo, slot);
349 spin_unlock_irq(&cinfo->suspend_lock);
353 static void process_suspend_info(struct md_cluster_info *cinfo,
354 int slot, sector_t lo, sector_t hi)
356 struct suspend_info *s;
359 remove_suspend_info(cinfo, slot);
362 s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL);
368 spin_lock_irq(&cinfo->suspend_lock);
369 /* Remove existing entry (if exists) before adding */
370 __remove_suspend_info(cinfo, slot);
371 list_add(&s->list, &cinfo->suspend_list);
372 spin_unlock_irq(&cinfo->suspend_lock);
375 static void process_add_new_disk(struct mddev *mddev, struct cluster_msg *cmsg)
378 struct md_cluster_info *cinfo = mddev->cluster_info;
379 char event_name[] = "EVENT=ADD_DEVICE";
381 char *envp[] = {event_name, disk_uuid, raid_slot, NULL};
384 len = snprintf(disk_uuid, 64, "DEVICE_UUID=");
385 pretty_uuid(disk_uuid + len, cmsg->uuid);
386 snprintf(raid_slot, 16, "RAID_DISK=%d", cmsg->raid_slot);
387 pr_info("%s:%d Sending kobject change with %s and %s\n", __func__, __LINE__, disk_uuid, raid_slot);
388 init_completion(&cinfo->newdisk_completion);
389 set_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state);
390 kobject_uevent_env(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE, envp);
391 wait_for_completion_timeout(&cinfo->newdisk_completion,
393 clear_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state);
397 static void process_metadata_update(struct mddev *mddev, struct cluster_msg *msg)
399 struct md_cluster_info *cinfo = mddev->cluster_info;
402 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR);
405 static void process_remove_disk(struct mddev *mddev, struct cluster_msg *msg)
407 struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev, msg->raid_slot);
410 md_kick_rdev_from_array(rdev);
412 pr_warn("%s: %d Could not find disk(%d) to REMOVE\n", __func__, __LINE__, msg->raid_slot);
415 static void process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg)
418 case METADATA_UPDATED:
419 pr_info("%s: %d Received message: METADATA_UPDATE from %d\n",
420 __func__, __LINE__, msg->slot);
421 process_metadata_update(mddev, msg);
424 pr_info("%s: %d Received message: RESYNCING from %d\n",
425 __func__, __LINE__, msg->slot);
426 process_suspend_info(mddev->cluster_info, msg->slot,
427 msg->low, msg->high);
430 pr_info("%s: %d Received message: NEWDISK from %d\n",
431 __func__, __LINE__, msg->slot);
432 process_add_new_disk(mddev, msg);
435 pr_info("%s: %d Received REMOVE from %d\n",
436 __func__, __LINE__, msg->slot);
437 process_remove_disk(mddev, msg);
440 pr_warn("%s:%d Received unknown message from %d\n",
441 __func__, __LINE__, msg->slot);
446 * thread for receiving message
448 static void recv_daemon(struct md_thread *thread)
450 struct md_cluster_info *cinfo = thread->mddev->cluster_info;
451 struct dlm_lock_resource *ack_lockres = cinfo->ack_lockres;
452 struct dlm_lock_resource *message_lockres = cinfo->message_lockres;
453 struct cluster_msg msg;
455 /*get CR on Message*/
456 if (dlm_lock_sync(message_lockres, DLM_LOCK_CR)) {
457 pr_err("md/raid1:failed to get CR on MESSAGE\n");
461 /* read lvb and wake up thread to process this message_lockres */
462 memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(struct cluster_msg));
463 process_recvd_msg(thread->mddev, &msg);
465 /*release CR on ack_lockres*/
466 dlm_unlock_sync(ack_lockres);
467 /*up-convert to EX on message_lockres*/
468 dlm_lock_sync(message_lockres, DLM_LOCK_EX);
469 /*get CR on ack_lockres again*/
470 dlm_lock_sync(ack_lockres, DLM_LOCK_CR);
471 /*release CR on message_lockres*/
472 dlm_unlock_sync(message_lockres);
476 * Takes the lock on the TOKEN lock resource so no other
477 * node can communicate while the operation is underway.
479 static int lock_comm(struct md_cluster_info *cinfo)
483 error = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX);
485 pr_err("md-cluster(%s:%d): failed to get EX on TOKEN (%d)\n",
486 __func__, __LINE__, error);
490 static void unlock_comm(struct md_cluster_info *cinfo)
492 dlm_unlock_sync(cinfo->token_lockres);
496 * This function performs the actual sending of the message. This function is
497 * usually called after performing the encompassing operation
499 * 1. Grabs the message lockresource in EX mode
500 * 2. Copies the message to the message LVB
501 * 3. Downconverts message lockresource to CR
502 * 4. Upconverts ack lock resource from CR to EX. This forces the BAST on other nodes
503 * and the other nodes read the message. The thread will wait here until all other
504 * nodes have released ack lock resource.
505 * 5. Downconvert ack lockresource to CR
507 static int __sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg)
510 int slot = cinfo->slot_number - 1;
512 cmsg->slot = cpu_to_le32(slot);
513 /*get EX on Message*/
514 error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_EX);
516 pr_err("md-cluster: failed to get EX on MESSAGE (%d)\n", error);
520 memcpy(cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg,
521 sizeof(struct cluster_msg));
522 /*down-convert EX to CR on Message*/
523 error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CR);
525 pr_err("md-cluster: failed to convert EX to CR on MESSAGE(%d)\n",
530 /*up-convert CR to EX on Ack*/
531 error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_EX);
533 pr_err("md-cluster: failed to convert CR to EX on ACK(%d)\n",
538 /*down-convert EX to CR on Ack*/
539 error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR);
541 pr_err("md-cluster: failed to convert EX to CR on ACK(%d)\n",
547 dlm_unlock_sync(cinfo->message_lockres);
552 static int sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg)
557 ret = __sendmsg(cinfo, cmsg);
562 static int gather_all_resync_info(struct mddev *mddev, int total_slots)
564 struct md_cluster_info *cinfo = mddev->cluster_info;
566 struct dlm_lock_resource *bm_lockres;
567 struct suspend_info *s;
571 for (i = 0; i < total_slots; i++) {
572 memset(str, '\0', 64);
573 snprintf(str, 64, "bitmap%04d", i);
574 bm_lockres = lockres_init(mddev, str, NULL, 1);
577 if (i == (cinfo->slot_number - 1))
580 bm_lockres->flags |= DLM_LKF_NOQUEUE;
581 ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
582 if (ret == -EAGAIN) {
583 memset(bm_lockres->lksb.sb_lvbptr, '\0', LVB_SIZE);
584 s = read_resync_info(mddev, bm_lockres);
586 pr_info("%s:%d Resync[%llu..%llu] in progress on %d\n",
588 (unsigned long long) s->lo,
589 (unsigned long long) s->hi, i);
590 spin_lock_irq(&cinfo->suspend_lock);
592 list_add(&s->list, &cinfo->suspend_list);
593 spin_unlock_irq(&cinfo->suspend_lock);
596 lockres_free(bm_lockres);
601 /* TODO: Read the disk bitmap sb and check if it needs recovery */
602 dlm_unlock_sync(bm_lockres);
603 lockres_free(bm_lockres);
609 static int join(struct mddev *mddev, int nodes)
611 struct md_cluster_info *cinfo;
615 if (!try_module_get(THIS_MODULE))
618 cinfo = kzalloc(sizeof(struct md_cluster_info), GFP_KERNEL);
622 init_completion(&cinfo->completion);
624 mutex_init(&cinfo->sb_mutex);
625 mddev->cluster_info = cinfo;
628 pretty_uuid(str, mddev->uuid);
629 ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name,
630 DLM_LSFL_FS, LVB_SIZE,
631 &md_ls_ops, mddev, &ops_rv, &cinfo->lockspace);
634 wait_for_completion(&cinfo->completion);
635 if (nodes < cinfo->slot_number) {
636 pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).",
637 cinfo->slot_number, nodes);
641 cinfo->sb_lock = lockres_init(mddev, "cmd-super",
643 if (!cinfo->sb_lock) {
647 /* Initiate the communication resources */
649 cinfo->recv_thread = md_register_thread(recv_daemon, mddev, "cluster_recv");
650 if (!cinfo->recv_thread) {
651 pr_err("md-cluster: cannot allocate memory for recv_thread!\n");
654 cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1);
655 if (!cinfo->message_lockres)
657 cinfo->token_lockres = lockres_init(mddev, "token", NULL, 0);
658 if (!cinfo->token_lockres)
660 cinfo->ack_lockres = lockres_init(mddev, "ack", ack_bast, 0);
661 if (!cinfo->ack_lockres)
663 cinfo->no_new_dev_lockres = lockres_init(mddev, "no-new-dev", NULL, 0);
664 if (!cinfo->no_new_dev_lockres)
667 /* get sync CR lock on ACK. */
668 if (dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR))
669 pr_err("md-cluster: failed to get a sync CR lock on ACK!(%d)\n",
671 /* get sync CR lock on no-new-dev. */
672 if (dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR))
673 pr_err("md-cluster: failed to get a sync CR lock on no-new-dev!(%d)\n", ret);
676 pr_info("md-cluster: Joined cluster %s slot %d\n", str, cinfo->slot_number);
677 snprintf(str, 64, "bitmap%04d", cinfo->slot_number - 1);
678 cinfo->bitmap_lockres = lockres_init(mddev, str, NULL, 1);
679 if (!cinfo->bitmap_lockres)
681 if (dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW)) {
682 pr_err("Failed to get bitmap lock\n");
687 INIT_LIST_HEAD(&cinfo->suspend_list);
688 spin_lock_init(&cinfo->suspend_lock);
690 ret = gather_all_resync_info(mddev, nodes);
696 lockres_free(cinfo->message_lockres);
697 lockres_free(cinfo->token_lockres);
698 lockres_free(cinfo->ack_lockres);
699 lockres_free(cinfo->no_new_dev_lockres);
700 lockres_free(cinfo->bitmap_lockres);
701 lockres_free(cinfo->sb_lock);
702 if (cinfo->lockspace)
703 dlm_release_lockspace(cinfo->lockspace, 2);
704 mddev->cluster_info = NULL;
706 module_put(THIS_MODULE);
710 static int leave(struct mddev *mddev)
712 struct md_cluster_info *cinfo = mddev->cluster_info;
716 md_unregister_thread(&cinfo->recovery_thread);
717 md_unregister_thread(&cinfo->recv_thread);
718 lockres_free(cinfo->message_lockres);
719 lockres_free(cinfo->token_lockres);
720 lockres_free(cinfo->ack_lockres);
721 lockres_free(cinfo->no_new_dev_lockres);
722 lockres_free(cinfo->sb_lock);
723 lockres_free(cinfo->bitmap_lockres);
724 dlm_release_lockspace(cinfo->lockspace, 2);
728 /* slot_number(): Returns the MD slot number to use
729 * DLM starts the slot numbers from 1, wheras cluster-md
730 * wants the number to be from zero, so we deduct one
732 static int slot_number(struct mddev *mddev)
734 struct md_cluster_info *cinfo = mddev->cluster_info;
736 return cinfo->slot_number - 1;
739 static void resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi)
741 struct md_cluster_info *cinfo = mddev->cluster_info;
743 add_resync_info(mddev, cinfo->bitmap_lockres, lo, hi);
744 /* Re-acquire the lock to refresh LVB */
745 dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW);
748 static int metadata_update_start(struct mddev *mddev)
750 return lock_comm(mddev->cluster_info);
753 static int metadata_update_finish(struct mddev *mddev)
755 struct md_cluster_info *cinfo = mddev->cluster_info;
756 struct cluster_msg cmsg;
759 memset(&cmsg, 0, sizeof(cmsg));
760 cmsg.type = cpu_to_le32(METADATA_UPDATED);
761 ret = __sendmsg(cinfo, &cmsg);
766 static int metadata_update_cancel(struct mddev *mddev)
768 struct md_cluster_info *cinfo = mddev->cluster_info;
770 return dlm_unlock_sync(cinfo->token_lockres);
773 static int resync_send(struct mddev *mddev, enum msg_type type,
774 sector_t lo, sector_t hi)
776 struct md_cluster_info *cinfo = mddev->cluster_info;
777 struct cluster_msg cmsg;
778 int slot = cinfo->slot_number - 1;
780 pr_info("%s:%d lo: %llu hi: %llu\n", __func__, __LINE__,
781 (unsigned long long)lo,
782 (unsigned long long)hi);
783 resync_info_update(mddev, lo, hi);
784 cmsg.type = cpu_to_le32(type);
785 cmsg.slot = cpu_to_le32(slot);
786 cmsg.low = cpu_to_le64(lo);
787 cmsg.high = cpu_to_le64(hi);
788 return sendmsg(cinfo, &cmsg);
791 static int resync_start(struct mddev *mddev, sector_t lo, sector_t hi)
793 pr_info("%s:%d\n", __func__, __LINE__);
794 return resync_send(mddev, RESYNCING, lo, hi);
797 static void resync_finish(struct mddev *mddev)
799 pr_info("%s:%d\n", __func__, __LINE__);
800 resync_send(mddev, RESYNCING, 0, 0);
803 static int area_resyncing(struct mddev *mddev, sector_t lo, sector_t hi)
805 struct md_cluster_info *cinfo = mddev->cluster_info;
807 struct suspend_info *s;
809 spin_lock_irq(&cinfo->suspend_lock);
810 if (list_empty(&cinfo->suspend_list))
812 list_for_each_entry(s, &cinfo->suspend_list, list)
813 if (hi > s->lo && lo < s->hi) {
818 spin_unlock_irq(&cinfo->suspend_lock);
822 static int add_new_disk_start(struct mddev *mddev, struct md_rdev *rdev)
824 struct md_cluster_info *cinfo = mddev->cluster_info;
825 struct cluster_msg cmsg;
827 struct mdp_superblock_1 *sb = page_address(rdev->sb_page);
828 char *uuid = sb->device_uuid;
830 memset(&cmsg, 0, sizeof(cmsg));
831 cmsg.type = cpu_to_le32(NEWDISK);
832 memcpy(cmsg.uuid, uuid, 16);
833 cmsg.raid_slot = rdev->desc_nr;
835 ret = __sendmsg(cinfo, &cmsg);
838 cinfo->no_new_dev_lockres->flags |= DLM_LKF_NOQUEUE;
839 ret = dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_EX);
840 cinfo->no_new_dev_lockres->flags &= ~DLM_LKF_NOQUEUE;
841 /* Some node does not "see" the device */
845 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR);
849 static int add_new_disk_finish(struct mddev *mddev)
851 struct cluster_msg cmsg;
852 struct md_cluster_info *cinfo = mddev->cluster_info;
854 /* Write sb and inform others */
855 md_update_sb(mddev, 1);
856 cmsg.type = METADATA_UPDATED;
857 ret = __sendmsg(cinfo, &cmsg);
862 static int new_disk_ack(struct mddev *mddev, bool ack)
864 struct md_cluster_info *cinfo = mddev->cluster_info;
866 if (!test_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state)) {
867 pr_warn("md-cluster(%s): Spurious cluster confirmation\n", mdname(mddev));
872 dlm_unlock_sync(cinfo->no_new_dev_lockres);
873 complete(&cinfo->newdisk_completion);
877 static int remove_disk(struct mddev *mddev, struct md_rdev *rdev)
879 struct cluster_msg cmsg;
880 struct md_cluster_info *cinfo = mddev->cluster_info;
882 cmsg.raid_slot = rdev->desc_nr;
883 return __sendmsg(cinfo, &cmsg);
886 static struct md_cluster_operations cluster_ops = {
889 .slot_number = slot_number,
890 .resync_info_update = resync_info_update,
891 .resync_start = resync_start,
892 .resync_finish = resync_finish,
893 .metadata_update_start = metadata_update_start,
894 .metadata_update_finish = metadata_update_finish,
895 .metadata_update_cancel = metadata_update_cancel,
896 .area_resyncing = area_resyncing,
897 .add_new_disk_start = add_new_disk_start,
898 .add_new_disk_finish = add_new_disk_finish,
899 .new_disk_ack = new_disk_ack,
900 .remove_disk = remove_disk,
903 static int __init cluster_init(void)
905 pr_warn("md-cluster: EXPERIMENTAL. Use with caution\n");
906 pr_info("Registering Cluster MD functions\n");
907 register_md_cluster_operations(&cluster_ops, THIS_MODULE);
911 static void cluster_exit(void)
913 unregister_md_cluster_operations();
916 module_init(cluster_init);
917 module_exit(cluster_exit);
918 MODULE_LICENSE("GPL");
919 MODULE_DESCRIPTION("Clustering support for MD");