blob: 67a7358406397ab2eb02d62857b2e4cbd4797778 [file] [log] [blame]
Goldwyn Rodrigues8e854e92014-03-07 11:21:15 -06001/*
2 * Copyright (C) 2015, SUSE
3 *
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)
7 * any later version.
8 *
9 */
10
11
12#include <linux/module.h>
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -060013#include <linux/dlm.h>
14#include <linux/sched.h>
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -050015#include <linux/raid/md_p.h>
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -060016#include "md.h"
Goldwyn Rodriguese94987d2014-06-07 00:45:22 -050017#include "bitmap.h"
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -050018#include "md-cluster.h"
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -060019
20#define LVB_SIZE 64
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -050021#define NEW_DEV_TIMEOUT 5000
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -060022
23struct dlm_lock_resource {
24 dlm_lockspace_t *ls;
25 struct dlm_lksb lksb;
26 char *name; /* lock name. */
27 uint32_t flags; /* flags to pass to dlm_lock() */
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -060028 struct completion completion; /* completion for synchronized locking */
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -050029 void (*bast)(void *arg, int mode); /* blocking AST function pointer*/
30 struct mddev *mddev; /* pointing back to mddev. */
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -050031 int mode;
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -050032};
33
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -050034struct suspend_info {
35 int slot;
36 sector_t lo;
37 sector_t hi;
38 struct list_head list;
39};
40
41struct resync_info {
42 __le64 lo;
43 __le64 hi;
44};
45
Goldwyn Rodriguesfa8259d2015-03-02 10:55:49 -060046/* md_cluster_info flags */
47#define MD_CLUSTER_WAITING_FOR_NEWDISK 1
Goldwyn Rodrigues90382ed2015-06-24 09:30:32 -050048#define MD_CLUSTER_SUSPEND_READ_BALANCING 2
Guoqing Jiangeece0752015-07-10 17:01:21 +080049#define MD_CLUSTER_BEGIN_JOIN_CLUSTER 3
Goldwyn Rodriguesfa8259d2015-03-02 10:55:49 -060050
Guoqing Jiang8b9277c2015-12-21 10:51:00 +110051/* Lock the send communication. This is done through
52 * bit manipulation as opposed to a mutex in order to
53 * accomodate lock and hold. See next comment.
54 */
55#define MD_CLUSTER_SEND_LOCK 4
Guoqing Jiange19508f2015-12-21 10:51:01 +110056/* If cluster operations (such as adding a disk) must lock the
57 * communication channel, so as to perform extra operations
58 * (update metadata) and no other operation is allowed on the
59 * MD. Token needs to be locked and held until the operation
60 * completes witha md_update_sb(), which would eventually release
61 * the lock.
Guoqing Jiang8b9277c2015-12-21 10:51:00 +110062 */
63#define MD_CLUSTER_SEND_LOCKED_ALREADY 5
Guoqing Jiang51e453a2016-05-04 02:17:09 -040064/* We should receive message after node joined cluster and
65 * set up all the related infos such as bitmap and personality */
66#define MD_CLUSTER_ALREADY_IN_CLUSTER 6
67#define MD_CLUSTER_PENDING_RECV_EVENT 7
Guoqing Jiang8b9277c2015-12-21 10:51:00 +110068
Goldwyn Rodriguesfa8259d2015-03-02 10:55:49 -060069
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -050070struct md_cluster_info {
71 /* dlm lock space and resources for clustered raid. */
72 dlm_lockspace_t *lockspace;
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -050073 int slot_number;
74 struct completion completion;
Guoqing Jiang8b9277c2015-12-21 10:51:00 +110075 struct mutex recv_mutex;
Goldwyn Rodrigues54519c52014-06-06 12:12:32 -050076 struct dlm_lock_resource *bitmap_lockres;
Guoqing Jiangf6a2dc62015-12-21 10:51:00 +110077 struct dlm_lock_resource **other_bitmap_lockres;
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -050078 struct dlm_lock_resource *resync_lockres;
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -050079 struct list_head suspend_list;
80 spinlock_t suspend_lock;
Goldwyn Rodriguese94987d2014-06-07 00:45:22 -050081 struct md_thread *recovery_thread;
82 unsigned long recovery_map;
Goldwyn Rodrigues46646802014-06-07 01:08:29 -050083 /* communication loc resources */
84 struct dlm_lock_resource *ack_lockres;
85 struct dlm_lock_resource *message_lockres;
86 struct dlm_lock_resource *token_lockres;
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -050087 struct dlm_lock_resource *no_new_dev_lockres;
Goldwyn Rodrigues46646802014-06-07 01:08:29 -050088 struct md_thread *recv_thread;
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -050089 struct completion newdisk_completion;
Guoqing Jiang8b9277c2015-12-21 10:51:00 +110090 wait_queue_head_t wait;
Goldwyn Rodriguesfa8259d2015-03-02 10:55:49 -060091 unsigned long state;
Guoqing Jiang18c9ff72016-05-02 11:50:12 -040092 /* record the region in RESYNCING message */
93 sector_t sync_low;
94 sector_t sync_hi;
Goldwyn Rodrigues46646802014-06-07 01:08:29 -050095};
96
97enum msg_type {
98 METADATA_UPDATED = 0,
99 RESYNCING,
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500100 NEWDISK,
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -0500101 REMOVE,
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -0500102 RE_ADD,
Guoqing Jiangdc737d72015-07-10 16:54:04 +0800103 BITMAP_NEEDS_SYNC,
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500104};
105
106struct cluster_msg {
Guoqing Jiangcf97a342015-10-16 15:40:22 +0800107 __le32 type;
108 __le32 slot;
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500109 /* TODO: Unionize this for smaller footprint */
Guoqing Jiangcf97a342015-10-16 15:40:22 +0800110 __le64 low;
111 __le64 high;
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500112 char uuid[16];
Guoqing Jiangcf97a342015-10-16 15:40:22 +0800113 __le32 raid_slot;
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -0600114};
115
116static void sync_ast(void *arg)
117{
118 struct dlm_lock_resource *res;
119
NeilBrown2e2a7cd2015-10-19 15:42:18 +1100120 res = arg;
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -0600121 complete(&res->completion);
122}
123
124static int dlm_lock_sync(struct dlm_lock_resource *res, int mode)
125{
126 int ret = 0;
127
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -0600128 ret = dlm_lock(res->ls, mode, &res->lksb,
129 res->flags, res->name, strlen(res->name),
130 0, sync_ast, res, res->bast);
131 if (ret)
132 return ret;
133 wait_for_completion(&res->completion);
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -0500134 if (res->lksb.sb_status == 0)
135 res->mode = mode;
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -0600136 return res->lksb.sb_status;
137}
138
139static int dlm_unlock_sync(struct dlm_lock_resource *res)
140{
141 return dlm_lock_sync(res, DLM_LOCK_NL);
142}
143
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500144static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -0600145 char *name, void (*bastfn)(void *arg, int mode), int with_lvb)
146{
147 struct dlm_lock_resource *res = NULL;
148 int ret, namelen;
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500149 struct md_cluster_info *cinfo = mddev->cluster_info;
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -0600150
151 res = kzalloc(sizeof(struct dlm_lock_resource), GFP_KERNEL);
152 if (!res)
153 return NULL;
Guoqing Jiangb83d51c2015-07-10 17:01:16 +0800154 init_completion(&res->completion);
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500155 res->ls = cinfo->lockspace;
156 res->mddev = mddev;
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -0500157 res->mode = DLM_LOCK_IV;
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -0600158 namelen = strlen(name);
159 res->name = kzalloc(namelen + 1, GFP_KERNEL);
160 if (!res->name) {
161 pr_err("md-cluster: Unable to allocate resource name for resource %s\n", name);
162 goto out_err;
163 }
164 strlcpy(res->name, name, namelen + 1);
165 if (with_lvb) {
166 res->lksb.sb_lvbptr = kzalloc(LVB_SIZE, GFP_KERNEL);
167 if (!res->lksb.sb_lvbptr) {
168 pr_err("md-cluster: Unable to allocate LVB for resource %s\n", name);
169 goto out_err;
170 }
171 res->flags = DLM_LKF_VALBLK;
172 }
173
174 if (bastfn)
175 res->bast = bastfn;
176
177 res->flags |= DLM_LKF_EXPEDITE;
178
179 ret = dlm_lock_sync(res, DLM_LOCK_NL);
180 if (ret) {
181 pr_err("md-cluster: Unable to lock NL on new lock resource %s\n", name);
182 goto out_err;
183 }
184 res->flags &= ~DLM_LKF_EXPEDITE;
185 res->flags |= DLM_LKF_CONVERT;
186
187 return res;
188out_err:
189 kfree(res->lksb.sb_lvbptr);
190 kfree(res->name);
191 kfree(res);
192 return NULL;
193}
194
195static void lockres_free(struct dlm_lock_resource *res)
196{
Guoqing Jiang400cb452016-08-12 13:42:35 +0800197 int ret = 0;
Guoqing Jiangb5ef5672015-07-10 17:01:17 +0800198
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -0600199 if (!res)
200 return;
201
Guoqing Jiang400cb452016-08-12 13:42:35 +0800202 /*
203 * use FORCEUNLOCK flag, so we can unlock even the lock is on the
204 * waiting or convert queue
205 */
206 ret = dlm_unlock(res->ls, res->lksb.sb_lkid, DLM_LKF_FORCEUNLOCK,
207 &res->lksb, res);
208 if (unlikely(ret != 0))
209 pr_err("failed to unlock %s return %d\n", res->name, ret);
210 else
211 wait_for_completion(&res->completion);
Goldwyn Rodrigues47741b72014-03-07 13:49:26 -0600212
213 kfree(res->name);
214 kfree(res->lksb.sb_lvbptr);
215 kfree(res);
216}
Goldwyn Rodrigues8e854e92014-03-07 11:21:15 -0600217
NeilBrown30661b42015-10-19 15:44:00 +1100218static void add_resync_info(struct dlm_lock_resource *lockres,
219 sector_t lo, sector_t hi)
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -0500220{
221 struct resync_info *ri;
222
223 ri = (struct resync_info *)lockres->lksb.sb_lvbptr;
224 ri->lo = cpu_to_le64(lo);
225 ri->hi = cpu_to_le64(hi);
226}
227
228static struct suspend_info *read_resync_info(struct mddev *mddev, struct dlm_lock_resource *lockres)
229{
230 struct resync_info ri;
231 struct suspend_info *s = NULL;
232 sector_t hi = 0;
233
234 dlm_lock_sync(lockres, DLM_LOCK_CR);
235 memcpy(&ri, lockres->lksb.sb_lvbptr, sizeof(struct resync_info));
236 hi = le64_to_cpu(ri.hi);
Guoqing Jiangcf97a342015-10-16 15:40:22 +0800237 if (hi > 0) {
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -0500238 s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL);
239 if (!s)
240 goto out;
241 s->hi = hi;
242 s->lo = le64_to_cpu(ri.lo);
243 }
244 dlm_unlock_sync(lockres);
245out:
246 return s;
247}
248
kbuild test robot6dc69c9c2015-02-28 07:04:37 +0800249static void recover_bitmaps(struct md_thread *thread)
Goldwyn Rodriguese94987d2014-06-07 00:45:22 -0500250{
251 struct mddev *mddev = thread->mddev;
252 struct md_cluster_info *cinfo = mddev->cluster_info;
253 struct dlm_lock_resource *bm_lockres;
254 char str[64];
255 int slot, ret;
256 struct suspend_info *s, *tmp;
257 sector_t lo, hi;
258
259 while (cinfo->recovery_map) {
260 slot = fls64((u64)cinfo->recovery_map) - 1;
261
262 /* Clear suspend_area associated with the bitmap */
263 spin_lock_irq(&cinfo->suspend_lock);
264 list_for_each_entry_safe(s, tmp, &cinfo->suspend_list, list)
265 if (slot == s->slot) {
266 list_del(&s->list);
267 kfree(s);
268 }
269 spin_unlock_irq(&cinfo->suspend_lock);
270
271 snprintf(str, 64, "bitmap%04d", slot);
272 bm_lockres = lockres_init(mddev, str, NULL, 1);
273 if (!bm_lockres) {
274 pr_err("md-cluster: Cannot initialize bitmaps\n");
275 goto clear_bit;
276 }
277
278 ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
279 if (ret) {
280 pr_err("md-cluster: Could not DLM lock %s: %d\n",
281 str, ret);
282 goto clear_bit;
283 }
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -0500284 ret = bitmap_copy_from_slot(mddev, slot, &lo, &hi, true);
Goldwyn Rodrigues4b26a082014-06-07 00:52:29 -0500285 if (ret) {
Goldwyn Rodriguese94987d2014-06-07 00:45:22 -0500286 pr_err("md-cluster: Could not copy data from bitmap %d\n", slot);
Guoqing Jiange3f924d2016-08-12 13:42:36 +0800287 goto clear_bit;
Goldwyn Rodrigues4b26a082014-06-07 00:52:29 -0500288 }
289 if (hi > 0) {
Goldwyn Rodrigues4b26a082014-06-07 00:52:29 -0500290 if (lo < mddev->recovery_cp)
291 mddev->recovery_cp = lo;
Guoqing Jiangeb315cd2016-05-02 11:33:10 -0400292 /* wake up thread to continue resync in case resync
293 * is not finished */
294 if (mddev->recovery_cp != MaxSector) {
295 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
296 md_wakeup_thread(mddev->thread);
297 }
Goldwyn Rodrigues4b26a082014-06-07 00:52:29 -0500298 }
Goldwyn Rodriguese94987d2014-06-07 00:45:22 -0500299clear_bit:
Shaohua Li4ac7a652016-01-22 15:54:42 -0800300 lockres_free(bm_lockres);
Goldwyn Rodriguese94987d2014-06-07 00:45:22 -0500301 clear_bit(slot, &cinfo->recovery_map);
302 }
303}
304
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500305static void recover_prep(void *arg)
306{
Goldwyn Rodrigues90382ed2015-06-24 09:30:32 -0500307 struct mddev *mddev = arg;
308 struct md_cluster_info *cinfo = mddev->cluster_info;
309 set_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state);
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500310}
311
Guoqing Jiang05cd0e52015-07-10 16:54:03 +0800312static void __recover_slot(struct mddev *mddev, int slot)
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500313{
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500314 struct md_cluster_info *cinfo = mddev->cluster_info;
315
Guoqing Jiang05cd0e52015-07-10 16:54:03 +0800316 set_bit(slot, &cinfo->recovery_map);
Goldwyn Rodriguese94987d2014-06-07 00:45:22 -0500317 if (!cinfo->recovery_thread) {
318 cinfo->recovery_thread = md_register_thread(recover_bitmaps,
319 mddev, "recover");
320 if (!cinfo->recovery_thread) {
321 pr_warn("md-cluster: Could not create recovery thread\n");
322 return;
323 }
324 }
325 md_wakeup_thread(cinfo->recovery_thread);
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500326}
327
Guoqing Jiang05cd0e52015-07-10 16:54:03 +0800328static void recover_slot(void *arg, struct dlm_slot *slot)
329{
330 struct mddev *mddev = arg;
331 struct md_cluster_info *cinfo = mddev->cluster_info;
332
333 pr_info("md-cluster: %s Node %d/%d down. My slot: %d. Initiating recovery.\n",
334 mddev->bitmap_info.cluster_name,
335 slot->nodeid, slot->slot,
336 cinfo->slot_number);
337 /* deduct one since dlm slot starts from one while the num of
338 * cluster-md begins with 0 */
339 __recover_slot(mddev, slot->slot - 1);
340}
341
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500342static void recover_done(void *arg, struct dlm_slot *slots,
343 int num_slots, int our_slot,
344 uint32_t generation)
345{
346 struct mddev *mddev = arg;
347 struct md_cluster_info *cinfo = mddev->cluster_info;
348
349 cinfo->slot_number = our_slot;
Guoqing Jiangeece0752015-07-10 17:01:21 +0800350 /* completion is only need to be complete when node join cluster,
351 * it doesn't need to run during another node's failure */
352 if (test_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state)) {
353 complete(&cinfo->completion);
354 clear_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state);
355 }
Goldwyn Rodrigues90382ed2015-06-24 09:30:32 -0500356 clear_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state);
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500357}
358
Guoqing Jiangeece0752015-07-10 17:01:21 +0800359/* the ops is called when node join the cluster, and do lock recovery
360 * if node failure occurs */
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500361static const struct dlm_lockspace_ops md_ls_ops = {
362 .recover_prep = recover_prep,
363 .recover_slot = recover_slot,
364 .recover_done = recover_done,
365};
366
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500367/*
368 * The BAST function for the ack lock resource
369 * This function wakes up the receive thread in
370 * order to receive and process the message.
371 */
372static void ack_bast(void *arg, int mode)
373{
NeilBrown2e2a7cd2015-10-19 15:42:18 +1100374 struct dlm_lock_resource *res = arg;
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500375 struct md_cluster_info *cinfo = res->mddev->cluster_info;
376
Guoqing Jiang51e453a2016-05-04 02:17:09 -0400377 if (mode == DLM_LOCK_EX) {
378 if (test_bit(MD_CLUSTER_ALREADY_IN_CLUSTER, &cinfo->state))
379 md_wakeup_thread(cinfo->recv_thread);
380 else
381 set_bit(MD_CLUSTER_PENDING_RECV_EVENT, &cinfo->state);
382 }
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500383}
384
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500385static void __remove_suspend_info(struct md_cluster_info *cinfo, int slot)
386{
387 struct suspend_info *s, *tmp;
388
389 list_for_each_entry_safe(s, tmp, &cinfo->suspend_list, list)
390 if (slot == s->slot) {
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500391 list_del(&s->list);
392 kfree(s);
393 break;
394 }
395}
396
Goldwyn Rodriguesb8ca8462015-10-09 11:27:01 -0500397static void remove_suspend_info(struct mddev *mddev, int slot)
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500398{
Goldwyn Rodriguesb8ca8462015-10-09 11:27:01 -0500399 struct md_cluster_info *cinfo = mddev->cluster_info;
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500400 spin_lock_irq(&cinfo->suspend_lock);
401 __remove_suspend_info(cinfo, slot);
402 spin_unlock_irq(&cinfo->suspend_lock);
Goldwyn Rodriguesb8ca8462015-10-09 11:27:01 -0500403 mddev->pers->quiesce(mddev, 2);
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500404}
405
406
Goldwyn Rodrigues9ed38ff52015-08-14 12:19:40 -0500407static void process_suspend_info(struct mddev *mddev,
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500408 int slot, sector_t lo, sector_t hi)
409{
Goldwyn Rodrigues9ed38ff52015-08-14 12:19:40 -0500410 struct md_cluster_info *cinfo = mddev->cluster_info;
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500411 struct suspend_info *s;
412
413 if (!hi) {
Goldwyn Rodriguesb8ca8462015-10-09 11:27:01 -0500414 remove_suspend_info(mddev, slot);
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -0500415 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
416 md_wakeup_thread(mddev->thread);
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500417 return;
418 }
Guoqing Jiang18c9ff72016-05-02 11:50:12 -0400419
420 /*
421 * The bitmaps are not same for different nodes
422 * if RESYNCING is happening in one node, then
423 * the node which received the RESYNCING message
424 * probably will perform resync with the region
425 * [lo, hi] again, so we could reduce resync time
426 * a lot if we can ensure that the bitmaps among
427 * different nodes are match up well.
428 *
429 * sync_low/hi is used to record the region which
430 * arrived in the previous RESYNCING message,
431 *
432 * Call bitmap_sync_with_cluster to clear
433 * NEEDED_MASK and set RESYNC_MASK since
434 * resync thread is running in another node,
435 * so we don't need to do the resync again
436 * with the same section */
437 bitmap_sync_with_cluster(mddev, cinfo->sync_low,
438 cinfo->sync_hi,
439 lo, hi);
440 cinfo->sync_low = lo;
441 cinfo->sync_hi = hi;
442
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500443 s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL);
444 if (!s)
445 return;
446 s->slot = slot;
447 s->lo = lo;
448 s->hi = hi;
Goldwyn Rodrigues9ed38ff52015-08-14 12:19:40 -0500449 mddev->pers->quiesce(mddev, 1);
450 mddev->pers->quiesce(mddev, 0);
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500451 spin_lock_irq(&cinfo->suspend_lock);
452 /* Remove existing entry (if exists) before adding */
453 __remove_suspend_info(cinfo, slot);
454 list_add(&s->list, &cinfo->suspend_list);
455 spin_unlock_irq(&cinfo->suspend_lock);
Goldwyn Rodriguesb8ca8462015-10-09 11:27:01 -0500456 mddev->pers->quiesce(mddev, 2);
Goldwyn Rodriguese59721c2014-06-07 02:30:30 -0500457}
458
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500459static void process_add_new_disk(struct mddev *mddev, struct cluster_msg *cmsg)
460{
461 char disk_uuid[64];
462 struct md_cluster_info *cinfo = mddev->cluster_info;
463 char event_name[] = "EVENT=ADD_DEVICE";
464 char raid_slot[16];
465 char *envp[] = {event_name, disk_uuid, raid_slot, NULL};
466 int len;
467
468 len = snprintf(disk_uuid, 64, "DEVICE_UUID=");
Guoqing Jiangb89f7042015-07-10 16:54:02 +0800469 sprintf(disk_uuid + len, "%pU", cmsg->uuid);
Guoqing Jiangfaeff832015-10-12 17:21:21 +0800470 snprintf(raid_slot, 16, "RAID_DISK=%d", le32_to_cpu(cmsg->raid_slot));
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500471 pr_info("%s:%d Sending kobject change with %s and %s\n", __func__, __LINE__, disk_uuid, raid_slot);
472 init_completion(&cinfo->newdisk_completion);
Goldwyn Rodriguesfa8259d2015-03-02 10:55:49 -0600473 set_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state);
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500474 kobject_uevent_env(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE, envp);
475 wait_for_completion_timeout(&cinfo->newdisk_completion,
476 NEW_DEV_TIMEOUT);
Goldwyn Rodriguesfa8259d2015-03-02 10:55:49 -0600477 clear_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state);
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500478}
479
480
481static void process_metadata_update(struct mddev *mddev, struct cluster_msg *msg)
482{
483 struct md_cluster_info *cinfo = mddev->cluster_info;
Guoqing Jiang15858fa2015-12-21 10:51:00 +1100484 mddev->good_device_nr = le32_to_cpu(msg->raid_slot);
485 set_bit(MD_RELOAD_SB, &mddev->flags);
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500486 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR);
Guoqing Jiang15858fa2015-12-21 10:51:00 +1100487 md_wakeup_thread(mddev->thread);
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500488}
489
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -0500490static void process_remove_disk(struct mddev *mddev, struct cluster_msg *msg)
491{
Guoqing Jiangfaeff832015-10-12 17:21:21 +0800492 struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev,
493 le32_to_cpu(msg->raid_slot));
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -0500494
Guoqing Jiang659b2542015-12-21 10:50:59 +1100495 if (rdev) {
496 set_bit(ClusterRemove, &rdev->flags);
497 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
498 md_wakeup_thread(mddev->thread);
499 }
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -0500500 else
Guoqing Jiangfaeff832015-10-12 17:21:21 +0800501 pr_warn("%s: %d Could not find disk(%d) to REMOVE\n",
502 __func__, __LINE__, le32_to_cpu(msg->raid_slot));
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -0500503}
504
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -0500505static void process_readd_disk(struct mddev *mddev, struct cluster_msg *msg)
506{
Guoqing Jiangfaeff832015-10-12 17:21:21 +0800507 struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev,
508 le32_to_cpu(msg->raid_slot));
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -0500509
510 if (rdev && test_bit(Faulty, &rdev->flags))
511 clear_bit(Faulty, &rdev->flags);
512 else
Guoqing Jiangfaeff832015-10-12 17:21:21 +0800513 pr_warn("%s: %d Could not find disk(%d) which is faulty",
514 __func__, __LINE__, le32_to_cpu(msg->raid_slot));
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -0500515}
516
Guoqing Jiang1fa9a1a2016-05-03 22:22:15 -0400517static int process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg)
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500518{
Guoqing Jiang1fa9a1a2016-05-03 22:22:15 -0400519 int ret = 0;
520
Guoqing Jiang256f5b22015-10-12 17:21:23 +0800521 if (WARN(mddev->cluster_info->slot_number - 1 == le32_to_cpu(msg->slot),
522 "node %d received it's own msg\n", le32_to_cpu(msg->slot)))
Guoqing Jiang1fa9a1a2016-05-03 22:22:15 -0400523 return -1;
Guoqing Jiangcf97a342015-10-16 15:40:22 +0800524 switch (le32_to_cpu(msg->type)) {
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500525 case METADATA_UPDATED:
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500526 process_metadata_update(mddev, msg);
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500527 break;
528 case RESYNCING:
Guoqing Jiangcf97a342015-10-16 15:40:22 +0800529 process_suspend_info(mddev, le32_to_cpu(msg->slot),
530 le64_to_cpu(msg->low),
531 le64_to_cpu(msg->high));
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500532 break;
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500533 case NEWDISK:
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500534 process_add_new_disk(mddev, msg);
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -0500535 break;
536 case REMOVE:
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -0500537 process_remove_disk(mddev, msg);
538 break;
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -0500539 case RE_ADD:
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -0500540 process_readd_disk(mddev, msg);
541 break;
Guoqing Jiangdc737d72015-07-10 16:54:04 +0800542 case BITMAP_NEEDS_SYNC:
Guoqing Jiangcf97a342015-10-16 15:40:22 +0800543 __recover_slot(mddev, le32_to_cpu(msg->slot));
Guoqing Jiangdc737d72015-07-10 16:54:04 +0800544 break;
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -0500545 default:
Guoqing Jiang1fa9a1a2016-05-03 22:22:15 -0400546 ret = -1;
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -0500547 pr_warn("%s:%d Received unknown message from %d\n",
548 __func__, __LINE__, msg->slot);
kbuild test robot09dd1af2015-02-28 09:16:08 +0800549 }
Guoqing Jiang1fa9a1a2016-05-03 22:22:15 -0400550 return ret;
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500551}
552
553/*
554 * thread for receiving message
555 */
556static void recv_daemon(struct md_thread *thread)
557{
558 struct md_cluster_info *cinfo = thread->mddev->cluster_info;
559 struct dlm_lock_resource *ack_lockres = cinfo->ack_lockres;
560 struct dlm_lock_resource *message_lockres = cinfo->message_lockres;
561 struct cluster_msg msg;
Guoqing Jiangb5ef5672015-07-10 17:01:17 +0800562 int ret;
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500563
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100564 mutex_lock(&cinfo->recv_mutex);
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500565 /*get CR on Message*/
566 if (dlm_lock_sync(message_lockres, DLM_LOCK_CR)) {
567 pr_err("md/raid1:failed to get CR on MESSAGE\n");
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100568 mutex_unlock(&cinfo->recv_mutex);
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500569 return;
570 }
571
572 /* read lvb and wake up thread to process this message_lockres */
573 memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(struct cluster_msg));
Guoqing Jiang1fa9a1a2016-05-03 22:22:15 -0400574 ret = process_recvd_msg(thread->mddev, &msg);
575 if (ret)
576 goto out;
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500577
578 /*release CR on ack_lockres*/
Guoqing Jiangb5ef5672015-07-10 17:01:17 +0800579 ret = dlm_unlock_sync(ack_lockres);
580 if (unlikely(ret != 0))
581 pr_info("unlock ack failed return %d\n", ret);
Guoqing Jiang66099bb2015-07-10 17:01:15 +0800582 /*up-convert to PR on message_lockres*/
Guoqing Jiangb5ef5672015-07-10 17:01:17 +0800583 ret = dlm_lock_sync(message_lockres, DLM_LOCK_PR);
584 if (unlikely(ret != 0))
585 pr_info("lock PR on msg failed return %d\n", ret);
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500586 /*get CR on ack_lockres again*/
Guoqing Jiangb5ef5672015-07-10 17:01:17 +0800587 ret = dlm_lock_sync(ack_lockres, DLM_LOCK_CR);
588 if (unlikely(ret != 0))
589 pr_info("lock CR on ack failed return %d\n", ret);
Guoqing Jiang1fa9a1a2016-05-03 22:22:15 -0400590out:
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500591 /*release CR on message_lockres*/
Guoqing Jiangb5ef5672015-07-10 17:01:17 +0800592 ret = dlm_unlock_sync(message_lockres);
593 if (unlikely(ret != 0))
594 pr_info("unlock msg failed return %d\n", ret);
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100595 mutex_unlock(&cinfo->recv_mutex);
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500596}
597
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100598/* lock_token()
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500599 * Takes the lock on the TOKEN lock resource so no other
600 * node can communicate while the operation is underway.
601 */
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100602static int lock_token(struct md_cluster_info *cinfo)
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500603{
604 int error;
605
606 error = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX);
607 if (error)
608 pr_err("md-cluster(%s:%d): failed to get EX on TOKEN (%d)\n",
609 __func__, __LINE__, error);
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100610
611 /* Lock the receive sequence */
612 mutex_lock(&cinfo->recv_mutex);
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500613 return error;
614}
615
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100616/* lock_comm()
617 * Sets the MD_CLUSTER_SEND_LOCK bit to lock the send channel.
618 */
619static int lock_comm(struct md_cluster_info *cinfo)
620{
621 wait_event(cinfo->wait,
622 !test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state));
623
624 return lock_token(cinfo);
625}
626
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500627static void unlock_comm(struct md_cluster_info *cinfo)
628{
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -0500629 WARN_ON(cinfo->token_lockres->mode != DLM_LOCK_EX);
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100630 mutex_unlock(&cinfo->recv_mutex);
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500631 dlm_unlock_sync(cinfo->token_lockres);
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100632 clear_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state);
633 wake_up(&cinfo->wait);
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500634}
635
636/* __sendmsg()
637 * This function performs the actual sending of the message. This function is
638 * usually called after performing the encompassing operation
639 * The function:
640 * 1. Grabs the message lockresource in EX mode
641 * 2. Copies the message to the message LVB
Guoqing Jiang66099bb2015-07-10 17:01:15 +0800642 * 3. Downconverts message lockresource to CW
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500643 * 4. Upconverts ack lock resource from CR to EX. This forces the BAST on other nodes
644 * and the other nodes read the message. The thread will wait here until all other
645 * nodes have released ack lock resource.
646 * 5. Downconvert ack lockresource to CR
647 */
648static int __sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg)
649{
650 int error;
651 int slot = cinfo->slot_number - 1;
652
653 cmsg->slot = cpu_to_le32(slot);
654 /*get EX on Message*/
655 error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_EX);
656 if (error) {
657 pr_err("md-cluster: failed to get EX on MESSAGE (%d)\n", error);
658 goto failed_message;
659 }
660
661 memcpy(cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg,
662 sizeof(struct cluster_msg));
Guoqing Jiang66099bb2015-07-10 17:01:15 +0800663 /*down-convert EX to CW on Message*/
664 error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CW);
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500665 if (error) {
Guoqing Jiang66099bb2015-07-10 17:01:15 +0800666 pr_err("md-cluster: failed to convert EX to CW on MESSAGE(%d)\n",
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500667 error);
Guoqing Jiang66099bb2015-07-10 17:01:15 +0800668 goto failed_ack;
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500669 }
670
671 /*up-convert CR to EX on Ack*/
672 error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_EX);
673 if (error) {
674 pr_err("md-cluster: failed to convert CR to EX on ACK(%d)\n",
675 error);
676 goto failed_ack;
677 }
678
679 /*down-convert EX to CR on Ack*/
680 error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR);
681 if (error) {
682 pr_err("md-cluster: failed to convert EX to CR on ACK(%d)\n",
683 error);
684 goto failed_ack;
685 }
686
687failed_ack:
Guoqing Jiangb5ef5672015-07-10 17:01:17 +0800688 error = dlm_unlock_sync(cinfo->message_lockres);
689 if (unlikely(error != 0)) {
690 pr_err("md-cluster: failed convert to NL on MESSAGE(%d)\n",
691 error);
692 /* in case the message can't be released due to some reason */
693 goto failed_ack;
694 }
Goldwyn Rodrigues601b5152014-06-07 01:28:53 -0500695failed_message:
696 return error;
697}
698
699static int sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg)
700{
701 int ret;
702
703 lock_comm(cinfo);
704 ret = __sendmsg(cinfo, cmsg);
705 unlock_comm(cinfo);
706 return ret;
707}
708
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -0500709static int gather_all_resync_info(struct mddev *mddev, int total_slots)
710{
711 struct md_cluster_info *cinfo = mddev->cluster_info;
712 int i, ret = 0;
713 struct dlm_lock_resource *bm_lockres;
714 struct suspend_info *s;
715 char str[64];
Guoqing Jiangabb9b222015-07-10 17:01:22 +0800716 sector_t lo, hi;
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -0500717
718
719 for (i = 0; i < total_slots; i++) {
720 memset(str, '\0', 64);
721 snprintf(str, 64, "bitmap%04d", i);
722 bm_lockres = lockres_init(mddev, str, NULL, 1);
723 if (!bm_lockres)
724 return -ENOMEM;
Shaohua Li4ac7a652016-01-22 15:54:42 -0800725 if (i == (cinfo->slot_number - 1)) {
726 lockres_free(bm_lockres);
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -0500727 continue;
Shaohua Li4ac7a652016-01-22 15:54:42 -0800728 }
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -0500729
730 bm_lockres->flags |= DLM_LKF_NOQUEUE;
731 ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
732 if (ret == -EAGAIN) {
733 memset(bm_lockres->lksb.sb_lvbptr, '\0', LVB_SIZE);
734 s = read_resync_info(mddev, bm_lockres);
735 if (s) {
736 pr_info("%s:%d Resync[%llu..%llu] in progress on %d\n",
737 __func__, __LINE__,
738 (unsigned long long) s->lo,
739 (unsigned long long) s->hi, i);
740 spin_lock_irq(&cinfo->suspend_lock);
741 s->slot = i;
742 list_add(&s->list, &cinfo->suspend_list);
743 spin_unlock_irq(&cinfo->suspend_lock);
744 }
745 ret = 0;
746 lockres_free(bm_lockres);
747 continue;
748 }
Guoqing Jiang6e6d9f22015-07-10 17:01:20 +0800749 if (ret) {
750 lockres_free(bm_lockres);
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -0500751 goto out;
Guoqing Jiang6e6d9f22015-07-10 17:01:20 +0800752 }
Guoqing Jiangabb9b222015-07-10 17:01:22 +0800753
754 /* Read the disk bitmap sb and check if it needs recovery */
755 ret = bitmap_copy_from_slot(mddev, i, &lo, &hi, false);
756 if (ret) {
757 pr_warn("md-cluster: Could not gather bitmaps from slot %d", i);
758 lockres_free(bm_lockres);
759 continue;
760 }
761 if ((hi > 0) && (lo < mddev->recovery_cp)) {
762 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
763 mddev->recovery_cp = lo;
764 md_check_recovery(mddev);
765 }
766
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -0500767 lockres_free(bm_lockres);
768 }
769out:
770 return ret;
771}
772
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -0500773static int join(struct mddev *mddev, int nodes)
774{
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500775 struct md_cluster_info *cinfo;
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500776 int ret, ops_rv;
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500777 char str[64];
778
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500779 cinfo = kzalloc(sizeof(struct md_cluster_info), GFP_KERNEL);
780 if (!cinfo)
781 return -ENOMEM;
782
Guoqing Jiang9e3072e2015-07-10 17:01:18 +0800783 INIT_LIST_HEAD(&cinfo->suspend_list);
784 spin_lock_init(&cinfo->suspend_lock);
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500785 init_completion(&cinfo->completion);
Guoqing Jiangeece0752015-07-10 17:01:21 +0800786 set_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state);
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100787 init_waitqueue_head(&cinfo->wait);
788 mutex_init(&cinfo->recv_mutex);
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500789
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500790 mddev->cluster_info = cinfo;
791
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500792 memset(str, 0, 64);
Guoqing Jiangb89f7042015-07-10 16:54:02 +0800793 sprintf(str, "%pU", mddev->uuid);
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500794 ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name,
795 DLM_LSFL_FS, LVB_SIZE,
796 &md_ls_ops, mddev, &ops_rv, &cinfo->lockspace);
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500797 if (ret)
798 goto err;
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500799 wait_for_completion(&cinfo->completion);
Guoqing Jiang8c58f022015-04-21 11:25:52 -0500800 if (nodes < cinfo->slot_number) {
801 pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).",
802 cinfo->slot_number, nodes);
Goldwyn Rodriguesb97e92572014-06-06 11:50:56 -0500803 ret = -ERANGE;
804 goto err;
805 }
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500806 /* Initiate the communication resources */
807 ret = -ENOMEM;
808 cinfo->recv_thread = md_register_thread(recv_daemon, mddev, "cluster_recv");
809 if (!cinfo->recv_thread) {
810 pr_err("md-cluster: cannot allocate memory for recv_thread!\n");
811 goto err;
812 }
813 cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1);
814 if (!cinfo->message_lockres)
815 goto err;
816 cinfo->token_lockres = lockres_init(mddev, "token", NULL, 0);
817 if (!cinfo->token_lockres)
818 goto err;
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500819 cinfo->no_new_dev_lockres = lockres_init(mddev, "no-new-dev", NULL, 0);
820 if (!cinfo->no_new_dev_lockres)
821 goto err;
822
Guoqing Jiang15352122016-05-02 11:33:12 -0400823 ret = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX);
824 if (ret) {
825 ret = -EAGAIN;
826 pr_err("md-cluster: can't join cluster to avoid lock issue\n");
827 goto err;
828 }
829 cinfo->ack_lockres = lockres_init(mddev, "ack", ack_bast, 0);
Wei Yongjun0f6187d2016-08-21 14:42:25 +0000830 if (!cinfo->ack_lockres) {
831 ret = -ENOMEM;
Guoqing Jiang15352122016-05-02 11:33:12 -0400832 goto err;
Wei Yongjun0f6187d2016-08-21 14:42:25 +0000833 }
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500834 /* get sync CR lock on ACK. */
835 if (dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR))
836 pr_err("md-cluster: failed to get a sync CR lock on ACK!(%d)\n",
837 ret);
Guoqing Jiang15352122016-05-02 11:33:12 -0400838 dlm_unlock_sync(cinfo->token_lockres);
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500839 /* get sync CR lock on no-new-dev. */
840 if (dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR))
841 pr_err("md-cluster: failed to get a sync CR lock on no-new-dev!(%d)\n", ret);
842
Goldwyn Rodrigues54519c52014-06-06 12:12:32 -0500843
844 pr_info("md-cluster: Joined cluster %s slot %d\n", str, cinfo->slot_number);
845 snprintf(str, 64, "bitmap%04d", cinfo->slot_number - 1);
846 cinfo->bitmap_lockres = lockres_init(mddev, str, NULL, 1);
Wei Yongjun0f6187d2016-08-21 14:42:25 +0000847 if (!cinfo->bitmap_lockres) {
848 ret = -ENOMEM;
Goldwyn Rodrigues54519c52014-06-06 12:12:32 -0500849 goto err;
Wei Yongjun0f6187d2016-08-21 14:42:25 +0000850 }
Goldwyn Rodrigues54519c52014-06-06 12:12:32 -0500851 if (dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW)) {
852 pr_err("Failed to get bitmap lock\n");
853 ret = -EINVAL;
854 goto err;
855 }
856
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -0500857 cinfo->resync_lockres = lockres_init(mddev, "resync", NULL, 0);
Wei Yongjun0f6187d2016-08-21 14:42:25 +0000858 if (!cinfo->resync_lockres) {
859 ret = -ENOMEM;
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -0500860 goto err;
Wei Yongjun0f6187d2016-08-21 14:42:25 +0000861 }
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -0500862
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -0500863 return 0;
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500864err:
Guoqing Jiang5b0fb332016-05-02 11:33:11 -0400865 md_unregister_thread(&cinfo->recovery_thread);
866 md_unregister_thread(&cinfo->recv_thread);
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500867 lockres_free(cinfo->message_lockres);
868 lockres_free(cinfo->token_lockres);
869 lockres_free(cinfo->ack_lockres);
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500870 lockres_free(cinfo->no_new_dev_lockres);
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -0500871 lockres_free(cinfo->resync_lockres);
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -0500872 lockres_free(cinfo->bitmap_lockres);
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500873 if (cinfo->lockspace)
874 dlm_release_lockspace(cinfo->lockspace, 2);
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500875 mddev->cluster_info = NULL;
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500876 kfree(cinfo);
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500877 return ret;
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -0500878}
879
Guoqing Jiang51e453a2016-05-04 02:17:09 -0400880static void load_bitmaps(struct mddev *mddev, int total_slots)
881{
882 struct md_cluster_info *cinfo = mddev->cluster_info;
883
884 /* load all the node's bitmap info for resync */
885 if (gather_all_resync_info(mddev, total_slots))
886 pr_err("md-cluster: failed to gather all resyn infos\n");
887 set_bit(MD_CLUSTER_ALREADY_IN_CLUSTER, &cinfo->state);
888 /* wake up recv thread in case something need to be handled */
889 if (test_and_clear_bit(MD_CLUSTER_PENDING_RECV_EVENT, &cinfo->state))
890 md_wakeup_thread(cinfo->recv_thread);
891}
892
Guoqing Jiang09995412015-10-01 00:09:18 +0800893static void resync_bitmap(struct mddev *mddev)
894{
895 struct md_cluster_info *cinfo = mddev->cluster_info;
896 struct cluster_msg cmsg = {0};
897 int err;
898
899 cmsg.type = cpu_to_le32(BITMAP_NEEDS_SYNC);
900 err = sendmsg(cinfo, &cmsg);
901 if (err)
902 pr_err("%s:%d: failed to send BITMAP_NEEDS_SYNC message (%d)\n",
903 __func__, __LINE__, err);
904}
905
Guoqing Jiangf6a2dc62015-12-21 10:51:00 +1100906static void unlock_all_bitmaps(struct mddev *mddev);
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -0500907static int leave(struct mddev *mddev)
908{
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500909 struct md_cluster_info *cinfo = mddev->cluster_info;
910
911 if (!cinfo)
912 return 0;
Guoqing Jiang09995412015-10-01 00:09:18 +0800913
914 /* BITMAP_NEEDS_SYNC message should be sent when node
915 * is leaving the cluster with dirty bitmap, also we
916 * can only deliver it when dlm connection is available */
917 if (cinfo->slot_number > 0 && mddev->recovery_cp != MaxSector)
918 resync_bitmap(mddev);
919
Goldwyn Rodriguese94987d2014-06-07 00:45:22 -0500920 md_unregister_thread(&cinfo->recovery_thread);
Goldwyn Rodrigues46646802014-06-07 01:08:29 -0500921 md_unregister_thread(&cinfo->recv_thread);
922 lockres_free(cinfo->message_lockres);
923 lockres_free(cinfo->token_lockres);
924 lockres_free(cinfo->ack_lockres);
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -0500925 lockres_free(cinfo->no_new_dev_lockres);
Shaohua Li4ac7a652016-01-22 15:54:42 -0800926 lockres_free(cinfo->resync_lockres);
Goldwyn Rodrigues54519c52014-06-06 12:12:32 -0500927 lockres_free(cinfo->bitmap_lockres);
Guoqing Jiangf6a2dc62015-12-21 10:51:00 +1100928 unlock_all_bitmaps(mddev);
Goldwyn Rodriguesc4ce8672014-03-29 10:20:02 -0500929 dlm_release_lockspace(cinfo->lockspace, 2);
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -0500930 return 0;
931}
932
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -0500933/* slot_number(): Returns the MD slot number to use
934 * DLM starts the slot numbers from 1, wheras cluster-md
935 * wants the number to be from zero, so we deduct one
936 */
937static int slot_number(struct mddev *mddev)
938{
939 struct md_cluster_info *cinfo = mddev->cluster_info;
940
941 return cinfo->slot_number - 1;
942}
943
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100944/*
945 * Check if the communication is already locked, else lock the communication
946 * channel.
947 * If it is already locked, token is in EX mode, and hence lock_token()
948 * should not be called.
949 */
Goldwyn Rodrigues293467a2014-06-07 01:44:51 -0500950static int metadata_update_start(struct mddev *mddev)
951{
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100952 struct md_cluster_info *cinfo = mddev->cluster_info;
953
954 wait_event(cinfo->wait,
955 !test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state) ||
956 test_and_clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state));
957
958 /* If token is already locked, return 0 */
959 if (cinfo->token_lockres->mode == DLM_LOCK_EX)
960 return 0;
961
962 return lock_token(cinfo);
Goldwyn Rodrigues293467a2014-06-07 01:44:51 -0500963}
964
965static int metadata_update_finish(struct mddev *mddev)
966{
967 struct md_cluster_info *cinfo = mddev->cluster_info;
968 struct cluster_msg cmsg;
Goldwyn Rodrigues70bcecd2015-08-21 10:33:39 -0500969 struct md_rdev *rdev;
970 int ret = 0;
NeilBrownba2746b2015-10-16 13:48:35 +1100971 int raid_slot = -1;
Goldwyn Rodrigues293467a2014-06-07 01:44:51 -0500972
973 memset(&cmsg, 0, sizeof(cmsg));
974 cmsg.type = cpu_to_le32(METADATA_UPDATED);
Goldwyn Rodrigues70bcecd2015-08-21 10:33:39 -0500975 /* Pick up a good active device number to send.
976 */
977 rdev_for_each(rdev, mddev)
978 if (rdev->raid_disk > -1 && !test_bit(Faulty, &rdev->flags)) {
NeilBrownba2746b2015-10-16 13:48:35 +1100979 raid_slot = rdev->desc_nr;
Goldwyn Rodrigues70bcecd2015-08-21 10:33:39 -0500980 break;
981 }
NeilBrownba2746b2015-10-16 13:48:35 +1100982 if (raid_slot >= 0) {
983 cmsg.raid_slot = cpu_to_le32(raid_slot);
Goldwyn Rodrigues70bcecd2015-08-21 10:33:39 -0500984 ret = __sendmsg(cinfo, &cmsg);
NeilBrownba2746b2015-10-16 13:48:35 +1100985 } else
Goldwyn Rodrigues70bcecd2015-08-21 10:33:39 -0500986 pr_warn("md-cluster: No good device id found to send\n");
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100987 clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state);
Goldwyn Rodrigues293467a2014-06-07 01:44:51 -0500988 unlock_comm(cinfo);
989 return ret;
990}
991
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -0500992static void metadata_update_cancel(struct mddev *mddev)
Goldwyn Rodrigues293467a2014-06-07 01:44:51 -0500993{
994 struct md_cluster_info *cinfo = mddev->cluster_info;
Guoqing Jiang8b9277c2015-12-21 10:51:00 +1100995 clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state);
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -0500996 unlock_comm(cinfo);
Goldwyn Rodrigues293467a2014-06-07 01:44:51 -0500997}
998
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -0500999static int resync_start(struct mddev *mddev)
1000{
1001 struct md_cluster_info *cinfo = mddev->cluster_info;
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -05001002 return dlm_lock_sync(cinfo->resync_lockres, DLM_LOCK_EX);
1003}
1004
Goldwyn Rodriguesc40f3412015-08-19 08:14:42 +10001005static int resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi)
Goldwyn Rodrigues965400e2014-06-07 02:16:58 -05001006{
1007 struct md_cluster_info *cinfo = mddev->cluster_info;
Goldwyn Rodriguesac277c62015-12-21 10:50:59 +11001008 struct resync_info ri;
Guoqing Jiangaee177a2015-10-12 17:21:24 +08001009 struct cluster_msg cmsg = {0};
Goldwyn Rodrigues965400e2014-06-07 02:16:58 -05001010
Goldwyn Rodriguesac277c62015-12-21 10:50:59 +11001011 /* do not send zero again, if we have sent before */
1012 if (hi == 0) {
1013 memcpy(&ri, cinfo->bitmap_lockres->lksb.sb_lvbptr, sizeof(struct resync_info));
1014 if (le64_to_cpu(ri.hi) == 0)
1015 return 0;
1016 }
1017
NeilBrown30661b42015-10-19 15:44:00 +11001018 add_resync_info(cinfo->bitmap_lockres, lo, hi);
Goldwyn Rodriguesc40f3412015-08-19 08:14:42 +10001019 /* Re-acquire the lock to refresh LVB */
1020 dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW);
Goldwyn Rodriguesc40f3412015-08-19 08:14:42 +10001021 cmsg.type = cpu_to_le32(RESYNCING);
Goldwyn Rodrigues965400e2014-06-07 02:16:58 -05001022 cmsg.low = cpu_to_le64(lo);
1023 cmsg.high = cpu_to_le64(hi);
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -05001024
Goldwyn Rodrigues965400e2014-06-07 02:16:58 -05001025 return sendmsg(cinfo, &cmsg);
1026}
1027
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -05001028static int resync_finish(struct mddev *mddev)
1029{
1030 struct md_cluster_info *cinfo = mddev->cluster_info;
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -05001031 dlm_unlock_sync(cinfo->resync_lockres);
1032 return resync_info_update(mddev, 0, 0);
1033}
1034
Goldwyn Rodrigues90382ed2015-06-24 09:30:32 -05001035static int area_resyncing(struct mddev *mddev, int direction,
1036 sector_t lo, sector_t hi)
Goldwyn Rodrigues589a1c42014-06-07 02:39:37 -05001037{
1038 struct md_cluster_info *cinfo = mddev->cluster_info;
1039 int ret = 0;
1040 struct suspend_info *s;
1041
Goldwyn Rodrigues90382ed2015-06-24 09:30:32 -05001042 if ((direction == READ) &&
1043 test_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state))
1044 return 1;
1045
Goldwyn Rodrigues589a1c42014-06-07 02:39:37 -05001046 spin_lock_irq(&cinfo->suspend_lock);
1047 if (list_empty(&cinfo->suspend_list))
1048 goto out;
1049 list_for_each_entry(s, &cinfo->suspend_list, list)
1050 if (hi > s->lo && lo < s->hi) {
1051 ret = 1;
1052 break;
1053 }
1054out:
1055 spin_unlock_irq(&cinfo->suspend_lock);
1056 return ret;
1057}
1058
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -05001059/* add_new_disk() - initiates a disk add
1060 * However, if this fails before writing md_update_sb(),
1061 * add_new_disk_cancel() must be called to release token lock
1062 */
1063static int add_new_disk(struct mddev *mddev, struct md_rdev *rdev)
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001064{
1065 struct md_cluster_info *cinfo = mddev->cluster_info;
1066 struct cluster_msg cmsg;
1067 int ret = 0;
1068 struct mdp_superblock_1 *sb = page_address(rdev->sb_page);
1069 char *uuid = sb->device_uuid;
1070
1071 memset(&cmsg, 0, sizeof(cmsg));
1072 cmsg.type = cpu_to_le32(NEWDISK);
1073 memcpy(cmsg.uuid, uuid, 16);
Guoqing Jiangfaeff832015-10-12 17:21:21 +08001074 cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001075 lock_comm(cinfo);
1076 ret = __sendmsg(cinfo, &cmsg);
1077 if (ret)
1078 return ret;
1079 cinfo->no_new_dev_lockres->flags |= DLM_LKF_NOQUEUE;
1080 ret = dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_EX);
1081 cinfo->no_new_dev_lockres->flags &= ~DLM_LKF_NOQUEUE;
1082 /* Some node does not "see" the device */
1083 if (ret == -EAGAIN)
1084 ret = -ENOENT;
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -05001085 if (ret)
1086 unlock_comm(cinfo);
Guoqing Jiang8b9277c2015-12-21 10:51:00 +11001087 else {
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001088 dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR);
Guoqing Jiange19508f2015-12-21 10:51:01 +11001089 /* Since MD_CHANGE_DEVS will be set in add_bound_rdev which
1090 * will run soon after add_new_disk, the below path will be
1091 * invoked:
1092 * md_wakeup_thread(mddev->thread)
1093 * -> conf->thread (raid1d)
1094 * -> md_check_recovery -> md_update_sb
1095 * -> metadata_update_start/finish
1096 * MD_CLUSTER_SEND_LOCKED_ALREADY will be cleared eventually.
1097 *
1098 * For other failure cases, metadata_update_cancel and
1099 * add_new_disk_cancel also clear below bit as well.
1100 * */
Guoqing Jiang8b9277c2015-12-21 10:51:00 +11001101 set_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state);
1102 wake_up(&cinfo->wait);
1103 }
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001104 return ret;
1105}
1106
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -05001107static void add_new_disk_cancel(struct mddev *mddev)
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001108{
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -05001109 struct md_cluster_info *cinfo = mddev->cluster_info;
Guoqing Jiang8b9277c2015-12-21 10:51:00 +11001110 clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state);
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -05001111 unlock_comm(cinfo);
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001112}
1113
Goldwyn Rodriguesfa8259d2015-03-02 10:55:49 -06001114static int new_disk_ack(struct mddev *mddev, bool ack)
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001115{
1116 struct md_cluster_info *cinfo = mddev->cluster_info;
1117
Goldwyn Rodriguesfa8259d2015-03-02 10:55:49 -06001118 if (!test_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state)) {
1119 pr_warn("md-cluster(%s): Spurious cluster confirmation\n", mdname(mddev));
1120 return -EINVAL;
1121 }
1122
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001123 if (ack)
1124 dlm_unlock_sync(cinfo->no_new_dev_lockres);
1125 complete(&cinfo->newdisk_completion);
Goldwyn Rodriguesfa8259d2015-03-02 10:55:49 -06001126 return 0;
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001127}
1128
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -05001129static int remove_disk(struct mddev *mddev, struct md_rdev *rdev)
1130{
Guoqing Jiangaee177a2015-10-12 17:21:24 +08001131 struct cluster_msg cmsg = {0};
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -05001132 struct md_cluster_info *cinfo = mddev->cluster_info;
Guoqing Jiangfaeff832015-10-12 17:21:21 +08001133 cmsg.type = cpu_to_le32(REMOVE);
1134 cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
Goldwyn Rodrigues54a88392015-12-21 10:51:00 +11001135 return sendmsg(cinfo, &cmsg);
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -05001136}
1137
Guoqing Jiangf6a2dc62015-12-21 10:51:00 +11001138static int lock_all_bitmaps(struct mddev *mddev)
1139{
1140 int slot, my_slot, ret, held = 1, i = 0;
1141 char str[64];
1142 struct md_cluster_info *cinfo = mddev->cluster_info;
1143
1144 cinfo->other_bitmap_lockres = kzalloc((mddev->bitmap_info.nodes - 1) *
1145 sizeof(struct dlm_lock_resource *),
1146 GFP_KERNEL);
1147 if (!cinfo->other_bitmap_lockres) {
1148 pr_err("md: can't alloc mem for other bitmap locks\n");
1149 return 0;
1150 }
1151
1152 my_slot = slot_number(mddev);
1153 for (slot = 0; slot < mddev->bitmap_info.nodes; slot++) {
1154 if (slot == my_slot)
1155 continue;
1156
1157 memset(str, '\0', 64);
1158 snprintf(str, 64, "bitmap%04d", slot);
1159 cinfo->other_bitmap_lockres[i] = lockres_init(mddev, str, NULL, 1);
1160 if (!cinfo->other_bitmap_lockres[i])
1161 return -ENOMEM;
1162
1163 cinfo->other_bitmap_lockres[i]->flags |= DLM_LKF_NOQUEUE;
1164 ret = dlm_lock_sync(cinfo->other_bitmap_lockres[i], DLM_LOCK_PW);
1165 if (ret)
1166 held = -1;
1167 i++;
1168 }
1169
1170 return held;
1171}
1172
1173static void unlock_all_bitmaps(struct mddev *mddev)
1174{
1175 struct md_cluster_info *cinfo = mddev->cluster_info;
1176 int i;
1177
1178 /* release other node's bitmap lock if they are existed */
1179 if (cinfo->other_bitmap_lockres) {
1180 for (i = 0; i < mddev->bitmap_info.nodes - 1; i++) {
1181 if (cinfo->other_bitmap_lockres[i]) {
Guoqing Jiangf6a2dc62015-12-21 10:51:00 +11001182 lockres_free(cinfo->other_bitmap_lockres[i]);
1183 }
1184 }
1185 kfree(cinfo->other_bitmap_lockres);
1186 }
1187}
1188
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -05001189static int gather_bitmaps(struct md_rdev *rdev)
1190{
1191 int sn, err;
1192 sector_t lo, hi;
Guoqing Jiangaee177a2015-10-12 17:21:24 +08001193 struct cluster_msg cmsg = {0};
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -05001194 struct mddev *mddev = rdev->mddev;
1195 struct md_cluster_info *cinfo = mddev->cluster_info;
1196
Guoqing Jiangfaeff832015-10-12 17:21:21 +08001197 cmsg.type = cpu_to_le32(RE_ADD);
1198 cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -05001199 err = sendmsg(cinfo, &cmsg);
1200 if (err)
1201 goto out;
1202
1203 for (sn = 0; sn < mddev->bitmap_info.nodes; sn++) {
1204 if (sn == (cinfo->slot_number - 1))
1205 continue;
1206 err = bitmap_copy_from_slot(mddev, sn, &lo, &hi, false);
1207 if (err) {
1208 pr_warn("md-cluster: Could not gather bitmaps from slot %d", sn);
1209 goto out;
1210 }
1211 if ((hi > 0) && (lo < mddev->recovery_cp))
1212 mddev->recovery_cp = lo;
1213 }
1214out:
1215 return err;
1216}
1217
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -05001218static struct md_cluster_operations cluster_ops = {
1219 .join = join,
1220 .leave = leave,
Goldwyn Rodriguescf921cc2014-03-30 00:42:49 -05001221 .slot_number = slot_number,
Goldwyn Rodriguesc186b122015-09-30 13:20:35 -05001222 .resync_start = resync_start,
1223 .resync_finish = resync_finish,
Goldwyn Rodrigues96ae9232014-06-06 12:35:34 -05001224 .resync_info_update = resync_info_update,
Goldwyn Rodrigues293467a2014-06-07 01:44:51 -05001225 .metadata_update_start = metadata_update_start,
1226 .metadata_update_finish = metadata_update_finish,
1227 .metadata_update_cancel = metadata_update_cancel,
Goldwyn Rodrigues589a1c42014-06-07 02:39:37 -05001228 .area_resyncing = area_resyncing,
Goldwyn Rodriguesdbb64f82015-10-01 13:20:27 -05001229 .add_new_disk = add_new_disk,
1230 .add_new_disk_cancel = add_new_disk_cancel,
Goldwyn Rodrigues1aee41f2014-10-29 18:51:31 -05001231 .new_disk_ack = new_disk_ack,
Goldwyn Rodrigues88bcfef2015-04-14 10:44:44 -05001232 .remove_disk = remove_disk,
Guoqing Jiang51e453a2016-05-04 02:17:09 -04001233 .load_bitmaps = load_bitmaps,
Goldwyn Rodrigues97f6cd32015-04-14 10:45:42 -05001234 .gather_bitmaps = gather_bitmaps,
Guoqing Jiangf6a2dc62015-12-21 10:51:00 +11001235 .lock_all_bitmaps = lock_all_bitmaps,
1236 .unlock_all_bitmaps = unlock_all_bitmaps,
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -05001237};
1238
Goldwyn Rodrigues8e854e92014-03-07 11:21:15 -06001239static int __init cluster_init(void)
1240{
1241 pr_warn("md-cluster: EXPERIMENTAL. Use with caution\n");
1242 pr_info("Registering Cluster MD functions\n");
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -05001243 register_md_cluster_operations(&cluster_ops, THIS_MODULE);
Goldwyn Rodrigues8e854e92014-03-07 11:21:15 -06001244 return 0;
1245}
1246
1247static void cluster_exit(void)
1248{
Goldwyn Rodriguesedb39c92014-03-29 10:01:53 -05001249 unregister_md_cluster_operations();
Goldwyn Rodrigues8e854e92014-03-07 11:21:15 -06001250}
1251
1252module_init(cluster_init);
1253module_exit(cluster_exit);
Guoqing Jiang86b57272015-10-12 17:21:25 +08001254MODULE_AUTHOR("SUSE");
Goldwyn Rodrigues8e854e92014-03-07 11:21:15 -06001255MODULE_LICENSE("GPL");
1256MODULE_DESCRIPTION("Clustering support for MD");