Commit | Line | Data |
---|---|---|
8e854e9c GR |
1 | /* |
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> | |
47741b7c GR |
13 | #include <linux/dlm.h> |
14 | #include <linux/sched.h> | |
1aee41f6 | 15 | #include <linux/raid/md_p.h> |
47741b7c | 16 | #include "md.h" |
e94987db | 17 | #include "bitmap.h" |
edb39c9d | 18 | #include "md-cluster.h" |
47741b7c GR |
19 | |
20 | #define LVB_SIZE 64 | |
1aee41f6 | 21 | #define NEW_DEV_TIMEOUT 5000 |
47741b7c GR |
22 | |
23 | struct 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() */ | |
47741b7c | 28 | struct completion completion; /* completion for synchronized locking */ |
c4ce867f GR |
29 | void (*bast)(void *arg, int mode); /* blocking AST function pointer*/ |
30 | struct mddev *mddev; /* pointing back to mddev. */ | |
dbb64f86 | 31 | int mode; |
c4ce867f GR |
32 | }; |
33 | ||
96ae923a GR |
34 | struct suspend_info { |
35 | int slot; | |
36 | sector_t lo; | |
37 | sector_t hi; | |
38 | struct list_head list; | |
39 | }; | |
40 | ||
41 | struct resync_info { | |
42 | __le64 lo; | |
43 | __le64 hi; | |
44 | }; | |
45 | ||
fa8259da GR |
46 | /* md_cluster_info flags */ |
47 | #define MD_CLUSTER_WAITING_FOR_NEWDISK 1 | |
90382ed9 | 48 | #define MD_CLUSTER_SUSPEND_READ_BALANCING 2 |
eece075c | 49 | #define MD_CLUSTER_BEGIN_JOIN_CLUSTER 3 |
fa8259da GR |
50 | |
51 | ||
c4ce867f GR |
52 | struct md_cluster_info { |
53 | /* dlm lock space and resources for clustered raid. */ | |
54 | dlm_lockspace_t *lockspace; | |
cf921cc1 GR |
55 | int slot_number; |
56 | struct completion completion; | |
c4ce867f | 57 | struct mutex sb_mutex; |
54519c5f | 58 | struct dlm_lock_resource *bitmap_lockres; |
c186b128 | 59 | struct dlm_lock_resource *resync_lockres; |
96ae923a GR |
60 | struct list_head suspend_list; |
61 | spinlock_t suspend_lock; | |
e94987db GR |
62 | struct md_thread *recovery_thread; |
63 | unsigned long recovery_map; | |
4664680c GR |
64 | /* communication loc resources */ |
65 | struct dlm_lock_resource *ack_lockres; | |
66 | struct dlm_lock_resource *message_lockres; | |
67 | struct dlm_lock_resource *token_lockres; | |
1aee41f6 | 68 | struct dlm_lock_resource *no_new_dev_lockres; |
4664680c | 69 | struct md_thread *recv_thread; |
1aee41f6 | 70 | struct completion newdisk_completion; |
fa8259da | 71 | unsigned long state; |
4664680c GR |
72 | }; |
73 | ||
74 | enum msg_type { | |
75 | METADATA_UPDATED = 0, | |
76 | RESYNCING, | |
1aee41f6 | 77 | NEWDISK, |
88bcfef7 | 78 | REMOVE, |
97f6cd39 | 79 | RE_ADD, |
dc737d7c | 80 | BITMAP_NEEDS_SYNC, |
4664680c GR |
81 | }; |
82 | ||
83 | struct cluster_msg { | |
84 | int type; | |
85 | int slot; | |
1aee41f6 | 86 | /* TODO: Unionize this for smaller footprint */ |
4664680c GR |
87 | sector_t low; |
88 | sector_t high; | |
1aee41f6 GR |
89 | char uuid[16]; |
90 | int raid_slot; | |
47741b7c GR |
91 | }; |
92 | ||
93 | static void sync_ast(void *arg) | |
94 | { | |
95 | struct dlm_lock_resource *res; | |
96 | ||
97 | res = (struct dlm_lock_resource *) arg; | |
98 | complete(&res->completion); | |
99 | } | |
100 | ||
101 | static int dlm_lock_sync(struct dlm_lock_resource *res, int mode) | |
102 | { | |
103 | int ret = 0; | |
104 | ||
47741b7c GR |
105 | ret = dlm_lock(res->ls, mode, &res->lksb, |
106 | res->flags, res->name, strlen(res->name), | |
107 | 0, sync_ast, res, res->bast); | |
108 | if (ret) | |
109 | return ret; | |
110 | wait_for_completion(&res->completion); | |
dbb64f86 GR |
111 | if (res->lksb.sb_status == 0) |
112 | res->mode = mode; | |
47741b7c GR |
113 | return res->lksb.sb_status; |
114 | } | |
115 | ||
116 | static int dlm_unlock_sync(struct dlm_lock_resource *res) | |
117 | { | |
118 | return dlm_lock_sync(res, DLM_LOCK_NL); | |
119 | } | |
120 | ||
c4ce867f | 121 | static struct dlm_lock_resource *lockres_init(struct mddev *mddev, |
47741b7c GR |
122 | char *name, void (*bastfn)(void *arg, int mode), int with_lvb) |
123 | { | |
124 | struct dlm_lock_resource *res = NULL; | |
125 | int ret, namelen; | |
c4ce867f | 126 | struct md_cluster_info *cinfo = mddev->cluster_info; |
47741b7c GR |
127 | |
128 | res = kzalloc(sizeof(struct dlm_lock_resource), GFP_KERNEL); | |
129 | if (!res) | |
130 | return NULL; | |
b83d51c0 | 131 | init_completion(&res->completion); |
c4ce867f GR |
132 | res->ls = cinfo->lockspace; |
133 | res->mddev = mddev; | |
dbb64f86 | 134 | res->mode = DLM_LOCK_IV; |
47741b7c GR |
135 | namelen = strlen(name); |
136 | res->name = kzalloc(namelen + 1, GFP_KERNEL); | |
137 | if (!res->name) { | |
138 | pr_err("md-cluster: Unable to allocate resource name for resource %s\n", name); | |
139 | goto out_err; | |
140 | } | |
141 | strlcpy(res->name, name, namelen + 1); | |
142 | if (with_lvb) { | |
143 | res->lksb.sb_lvbptr = kzalloc(LVB_SIZE, GFP_KERNEL); | |
144 | if (!res->lksb.sb_lvbptr) { | |
145 | pr_err("md-cluster: Unable to allocate LVB for resource %s\n", name); | |
146 | goto out_err; | |
147 | } | |
148 | res->flags = DLM_LKF_VALBLK; | |
149 | } | |
150 | ||
151 | if (bastfn) | |
152 | res->bast = bastfn; | |
153 | ||
154 | res->flags |= DLM_LKF_EXPEDITE; | |
155 | ||
156 | ret = dlm_lock_sync(res, DLM_LOCK_NL); | |
157 | if (ret) { | |
158 | pr_err("md-cluster: Unable to lock NL on new lock resource %s\n", name); | |
159 | goto out_err; | |
160 | } | |
161 | res->flags &= ~DLM_LKF_EXPEDITE; | |
162 | res->flags |= DLM_LKF_CONVERT; | |
163 | ||
164 | return res; | |
165 | out_err: | |
166 | kfree(res->lksb.sb_lvbptr); | |
167 | kfree(res->name); | |
168 | kfree(res); | |
169 | return NULL; | |
170 | } | |
171 | ||
172 | static void lockres_free(struct dlm_lock_resource *res) | |
173 | { | |
b5ef5678 GJ |
174 | int ret; |
175 | ||
47741b7c GR |
176 | if (!res) |
177 | return; | |
178 | ||
b5ef5678 GJ |
179 | /* cancel a lock request or a conversion request that is blocked */ |
180 | res->flags |= DLM_LKF_CANCEL; | |
181 | retry: | |
182 | ret = dlm_unlock(res->ls, res->lksb.sb_lkid, 0, &res->lksb, res); | |
183 | if (unlikely(ret != 0)) { | |
184 | pr_info("%s: failed to unlock %s return %d\n", __func__, res->name, ret); | |
185 | ||
186 | /* if a lock conversion is cancelled, then the lock is put | |
187 | * back to grant queue, need to ensure it is unlocked */ | |
188 | if (ret == -DLM_ECANCEL) | |
189 | goto retry; | |
190 | } | |
191 | res->flags &= ~DLM_LKF_CANCEL; | |
47741b7c GR |
192 | wait_for_completion(&res->completion); |
193 | ||
194 | kfree(res->name); | |
195 | kfree(res->lksb.sb_lvbptr); | |
196 | kfree(res); | |
197 | } | |
8e854e9c | 198 | |
96ae923a GR |
199 | static void add_resync_info(struct mddev *mddev, struct dlm_lock_resource *lockres, |
200 | sector_t lo, sector_t hi) | |
201 | { | |
202 | struct resync_info *ri; | |
203 | ||
204 | ri = (struct resync_info *)lockres->lksb.sb_lvbptr; | |
205 | ri->lo = cpu_to_le64(lo); | |
206 | ri->hi = cpu_to_le64(hi); | |
207 | } | |
208 | ||
209 | static struct suspend_info *read_resync_info(struct mddev *mddev, struct dlm_lock_resource *lockres) | |
210 | { | |
211 | struct resync_info ri; | |
212 | struct suspend_info *s = NULL; | |
213 | sector_t hi = 0; | |
214 | ||
215 | dlm_lock_sync(lockres, DLM_LOCK_CR); | |
216 | memcpy(&ri, lockres->lksb.sb_lvbptr, sizeof(struct resync_info)); | |
217 | hi = le64_to_cpu(ri.hi); | |
218 | if (ri.hi > 0) { | |
219 | s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL); | |
220 | if (!s) | |
221 | goto out; | |
222 | s->hi = hi; | |
223 | s->lo = le64_to_cpu(ri.lo); | |
224 | } | |
225 | dlm_unlock_sync(lockres); | |
226 | out: | |
227 | return s; | |
228 | } | |
229 | ||
6dc69c9c | 230 | static void recover_bitmaps(struct md_thread *thread) |
e94987db GR |
231 | { |
232 | struct mddev *mddev = thread->mddev; | |
233 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
234 | struct dlm_lock_resource *bm_lockres; | |
235 | char str[64]; | |
236 | int slot, ret; | |
237 | struct suspend_info *s, *tmp; | |
238 | sector_t lo, hi; | |
239 | ||
240 | while (cinfo->recovery_map) { | |
241 | slot = fls64((u64)cinfo->recovery_map) - 1; | |
242 | ||
243 | /* Clear suspend_area associated with the bitmap */ | |
244 | spin_lock_irq(&cinfo->suspend_lock); | |
245 | list_for_each_entry_safe(s, tmp, &cinfo->suspend_list, list) | |
246 | if (slot == s->slot) { | |
247 | list_del(&s->list); | |
248 | kfree(s); | |
249 | } | |
250 | spin_unlock_irq(&cinfo->suspend_lock); | |
251 | ||
252 | snprintf(str, 64, "bitmap%04d", slot); | |
253 | bm_lockres = lockres_init(mddev, str, NULL, 1); | |
254 | if (!bm_lockres) { | |
255 | pr_err("md-cluster: Cannot initialize bitmaps\n"); | |
256 | goto clear_bit; | |
257 | } | |
258 | ||
259 | ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW); | |
260 | if (ret) { | |
261 | pr_err("md-cluster: Could not DLM lock %s: %d\n", | |
262 | str, ret); | |
263 | goto clear_bit; | |
264 | } | |
97f6cd39 | 265 | ret = bitmap_copy_from_slot(mddev, slot, &lo, &hi, true); |
4b26a08a | 266 | if (ret) { |
e94987db | 267 | pr_err("md-cluster: Could not copy data from bitmap %d\n", slot); |
4b26a08a GR |
268 | goto dlm_unlock; |
269 | } | |
270 | if (hi > 0) { | |
271 | /* TODO:Wait for current resync to get over */ | |
272 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | |
273 | if (lo < mddev->recovery_cp) | |
274 | mddev->recovery_cp = lo; | |
275 | md_check_recovery(mddev); | |
276 | } | |
277 | dlm_unlock: | |
e94987db GR |
278 | dlm_unlock_sync(bm_lockres); |
279 | clear_bit: | |
280 | clear_bit(slot, &cinfo->recovery_map); | |
281 | } | |
282 | } | |
283 | ||
cf921cc1 GR |
284 | static void recover_prep(void *arg) |
285 | { | |
90382ed9 GR |
286 | struct mddev *mddev = arg; |
287 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
288 | set_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state); | |
cf921cc1 GR |
289 | } |
290 | ||
05cd0e51 | 291 | static void __recover_slot(struct mddev *mddev, int slot) |
cf921cc1 | 292 | { |
cf921cc1 GR |
293 | struct md_cluster_info *cinfo = mddev->cluster_info; |
294 | ||
05cd0e51 | 295 | set_bit(slot, &cinfo->recovery_map); |
e94987db GR |
296 | if (!cinfo->recovery_thread) { |
297 | cinfo->recovery_thread = md_register_thread(recover_bitmaps, | |
298 | mddev, "recover"); | |
299 | if (!cinfo->recovery_thread) { | |
300 | pr_warn("md-cluster: Could not create recovery thread\n"); | |
301 | return; | |
302 | } | |
303 | } | |
304 | md_wakeup_thread(cinfo->recovery_thread); | |
cf921cc1 GR |
305 | } |
306 | ||
05cd0e51 GJ |
307 | static void recover_slot(void *arg, struct dlm_slot *slot) |
308 | { | |
309 | struct mddev *mddev = arg; | |
310 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
311 | ||
312 | pr_info("md-cluster: %s Node %d/%d down. My slot: %d. Initiating recovery.\n", | |
313 | mddev->bitmap_info.cluster_name, | |
314 | slot->nodeid, slot->slot, | |
315 | cinfo->slot_number); | |
316 | /* deduct one since dlm slot starts from one while the num of | |
317 | * cluster-md begins with 0 */ | |
318 | __recover_slot(mddev, slot->slot - 1); | |
319 | } | |
320 | ||
cf921cc1 GR |
321 | static void recover_done(void *arg, struct dlm_slot *slots, |
322 | int num_slots, int our_slot, | |
323 | uint32_t generation) | |
324 | { | |
325 | struct mddev *mddev = arg; | |
326 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
327 | ||
328 | cinfo->slot_number = our_slot; | |
eece075c GJ |
329 | /* completion is only need to be complete when node join cluster, |
330 | * it doesn't need to run during another node's failure */ | |
331 | if (test_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state)) { | |
332 | complete(&cinfo->completion); | |
333 | clear_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state); | |
334 | } | |
90382ed9 | 335 | clear_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state); |
cf921cc1 GR |
336 | } |
337 | ||
eece075c GJ |
338 | /* the ops is called when node join the cluster, and do lock recovery |
339 | * if node failure occurs */ | |
cf921cc1 GR |
340 | static const struct dlm_lockspace_ops md_ls_ops = { |
341 | .recover_prep = recover_prep, | |
342 | .recover_slot = recover_slot, | |
343 | .recover_done = recover_done, | |
344 | }; | |
345 | ||
4664680c GR |
346 | /* |
347 | * The BAST function for the ack lock resource | |
348 | * This function wakes up the receive thread in | |
349 | * order to receive and process the message. | |
350 | */ | |
351 | static void ack_bast(void *arg, int mode) | |
352 | { | |
353 | struct dlm_lock_resource *res = (struct dlm_lock_resource *)arg; | |
354 | struct md_cluster_info *cinfo = res->mddev->cluster_info; | |
355 | ||
356 | if (mode == DLM_LOCK_EX) | |
357 | md_wakeup_thread(cinfo->recv_thread); | |
358 | } | |
359 | ||
e59721cc GR |
360 | static void __remove_suspend_info(struct md_cluster_info *cinfo, int slot) |
361 | { | |
362 | struct suspend_info *s, *tmp; | |
363 | ||
364 | list_for_each_entry_safe(s, tmp, &cinfo->suspend_list, list) | |
365 | if (slot == s->slot) { | |
e59721cc GR |
366 | list_del(&s->list); |
367 | kfree(s); | |
368 | break; | |
369 | } | |
370 | } | |
371 | ||
b8ca846e | 372 | static void remove_suspend_info(struct mddev *mddev, int slot) |
e59721cc | 373 | { |
b8ca846e | 374 | struct md_cluster_info *cinfo = mddev->cluster_info; |
e59721cc GR |
375 | spin_lock_irq(&cinfo->suspend_lock); |
376 | __remove_suspend_info(cinfo, slot); | |
377 | spin_unlock_irq(&cinfo->suspend_lock); | |
b8ca846e | 378 | mddev->pers->quiesce(mddev, 2); |
e59721cc GR |
379 | } |
380 | ||
381 | ||
9ed38ff5 | 382 | static void process_suspend_info(struct mddev *mddev, |
e59721cc GR |
383 | int slot, sector_t lo, sector_t hi) |
384 | { | |
9ed38ff5 | 385 | struct md_cluster_info *cinfo = mddev->cluster_info; |
e59721cc GR |
386 | struct suspend_info *s; |
387 | ||
388 | if (!hi) { | |
b8ca846e | 389 | remove_suspend_info(mddev, slot); |
c186b128 GR |
390 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
391 | md_wakeup_thread(mddev->thread); | |
e59721cc GR |
392 | return; |
393 | } | |
394 | s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL); | |
395 | if (!s) | |
396 | return; | |
397 | s->slot = slot; | |
398 | s->lo = lo; | |
399 | s->hi = hi; | |
9ed38ff5 GR |
400 | mddev->pers->quiesce(mddev, 1); |
401 | mddev->pers->quiesce(mddev, 0); | |
e59721cc GR |
402 | spin_lock_irq(&cinfo->suspend_lock); |
403 | /* Remove existing entry (if exists) before adding */ | |
404 | __remove_suspend_info(cinfo, slot); | |
405 | list_add(&s->list, &cinfo->suspend_list); | |
406 | spin_unlock_irq(&cinfo->suspend_lock); | |
b8ca846e | 407 | mddev->pers->quiesce(mddev, 2); |
e59721cc GR |
408 | } |
409 | ||
1aee41f6 GR |
410 | static void process_add_new_disk(struct mddev *mddev, struct cluster_msg *cmsg) |
411 | { | |
412 | char disk_uuid[64]; | |
413 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
414 | char event_name[] = "EVENT=ADD_DEVICE"; | |
415 | char raid_slot[16]; | |
416 | char *envp[] = {event_name, disk_uuid, raid_slot, NULL}; | |
417 | int len; | |
418 | ||
419 | len = snprintf(disk_uuid, 64, "DEVICE_UUID="); | |
b89f704a | 420 | sprintf(disk_uuid + len, "%pU", cmsg->uuid); |
1aee41f6 GR |
421 | snprintf(raid_slot, 16, "RAID_DISK=%d", cmsg->raid_slot); |
422 | pr_info("%s:%d Sending kobject change with %s and %s\n", __func__, __LINE__, disk_uuid, raid_slot); | |
423 | init_completion(&cinfo->newdisk_completion); | |
fa8259da | 424 | set_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state); |
1aee41f6 GR |
425 | kobject_uevent_env(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE, envp); |
426 | wait_for_completion_timeout(&cinfo->newdisk_completion, | |
427 | NEW_DEV_TIMEOUT); | |
fa8259da | 428 | clear_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state); |
1aee41f6 GR |
429 | } |
430 | ||
431 | ||
432 | static void process_metadata_update(struct mddev *mddev, struct cluster_msg *msg) | |
433 | { | |
434 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
70bcecdb | 435 | md_reload_sb(mddev, le32_to_cpu(msg->raid_slot)); |
1aee41f6 GR |
436 | dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR); |
437 | } | |
438 | ||
88bcfef7 GR |
439 | static void process_remove_disk(struct mddev *mddev, struct cluster_msg *msg) |
440 | { | |
441 | struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev, msg->raid_slot); | |
442 | ||
443 | if (rdev) | |
444 | md_kick_rdev_from_array(rdev); | |
445 | else | |
446 | pr_warn("%s: %d Could not find disk(%d) to REMOVE\n", __func__, __LINE__, msg->raid_slot); | |
447 | } | |
448 | ||
97f6cd39 GR |
449 | static void process_readd_disk(struct mddev *mddev, struct cluster_msg *msg) |
450 | { | |
451 | struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev, msg->raid_slot); | |
452 | ||
453 | if (rdev && test_bit(Faulty, &rdev->flags)) | |
454 | clear_bit(Faulty, &rdev->flags); | |
455 | else | |
456 | pr_warn("%s: %d Could not find disk(%d) which is faulty", __func__, __LINE__, msg->raid_slot); | |
457 | } | |
458 | ||
4664680c GR |
459 | static void process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg) |
460 | { | |
461 | switch (msg->type) { | |
462 | case METADATA_UPDATED: | |
1aee41f6 | 463 | process_metadata_update(mddev, msg); |
4664680c GR |
464 | break; |
465 | case RESYNCING: | |
9ed38ff5 | 466 | process_suspend_info(mddev, msg->slot, |
e59721cc | 467 | msg->low, msg->high); |
4664680c | 468 | break; |
1aee41f6 | 469 | case NEWDISK: |
1aee41f6 | 470 | process_add_new_disk(mddev, msg); |
88bcfef7 GR |
471 | break; |
472 | case REMOVE: | |
88bcfef7 GR |
473 | process_remove_disk(mddev, msg); |
474 | break; | |
97f6cd39 | 475 | case RE_ADD: |
97f6cd39 GR |
476 | process_readd_disk(mddev, msg); |
477 | break; | |
dc737d7c | 478 | case BITMAP_NEEDS_SYNC: |
dc737d7c GJ |
479 | __recover_slot(mddev, msg->slot); |
480 | break; | |
88bcfef7 GR |
481 | default: |
482 | pr_warn("%s:%d Received unknown message from %d\n", | |
483 | __func__, __LINE__, msg->slot); | |
09dd1af2 | 484 | } |
4664680c GR |
485 | } |
486 | ||
487 | /* | |
488 | * thread for receiving message | |
489 | */ | |
490 | static void recv_daemon(struct md_thread *thread) | |
491 | { | |
492 | struct md_cluster_info *cinfo = thread->mddev->cluster_info; | |
493 | struct dlm_lock_resource *ack_lockres = cinfo->ack_lockres; | |
494 | struct dlm_lock_resource *message_lockres = cinfo->message_lockres; | |
495 | struct cluster_msg msg; | |
b5ef5678 | 496 | int ret; |
4664680c GR |
497 | |
498 | /*get CR on Message*/ | |
499 | if (dlm_lock_sync(message_lockres, DLM_LOCK_CR)) { | |
500 | pr_err("md/raid1:failed to get CR on MESSAGE\n"); | |
501 | return; | |
502 | } | |
503 | ||
504 | /* read lvb and wake up thread to process this message_lockres */ | |
505 | memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(struct cluster_msg)); | |
506 | process_recvd_msg(thread->mddev, &msg); | |
507 | ||
508 | /*release CR on ack_lockres*/ | |
b5ef5678 GJ |
509 | ret = dlm_unlock_sync(ack_lockres); |
510 | if (unlikely(ret != 0)) | |
511 | pr_info("unlock ack failed return %d\n", ret); | |
66099bb0 | 512 | /*up-convert to PR on message_lockres*/ |
b5ef5678 GJ |
513 | ret = dlm_lock_sync(message_lockres, DLM_LOCK_PR); |
514 | if (unlikely(ret != 0)) | |
515 | pr_info("lock PR on msg failed return %d\n", ret); | |
4664680c | 516 | /*get CR on ack_lockres again*/ |
b5ef5678 GJ |
517 | ret = dlm_lock_sync(ack_lockres, DLM_LOCK_CR); |
518 | if (unlikely(ret != 0)) | |
519 | pr_info("lock CR on ack failed return %d\n", ret); | |
4664680c | 520 | /*release CR on message_lockres*/ |
b5ef5678 GJ |
521 | ret = dlm_unlock_sync(message_lockres); |
522 | if (unlikely(ret != 0)) | |
523 | pr_info("unlock msg failed return %d\n", ret); | |
4664680c GR |
524 | } |
525 | ||
601b515c GR |
526 | /* lock_comm() |
527 | * Takes the lock on the TOKEN lock resource so no other | |
528 | * node can communicate while the operation is underway. | |
dbb64f86 GR |
529 | * If called again, and the TOKEN lock is alread in EX mode |
530 | * return success. However, care must be taken that unlock_comm() | |
531 | * is called only once. | |
601b515c GR |
532 | */ |
533 | static int lock_comm(struct md_cluster_info *cinfo) | |
534 | { | |
535 | int error; | |
536 | ||
dbb64f86 GR |
537 | if (cinfo->token_lockres->mode == DLM_LOCK_EX) |
538 | return 0; | |
539 | ||
601b515c GR |
540 | error = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX); |
541 | if (error) | |
542 | pr_err("md-cluster(%s:%d): failed to get EX on TOKEN (%d)\n", | |
543 | __func__, __LINE__, error); | |
544 | return error; | |
545 | } | |
546 | ||
547 | static void unlock_comm(struct md_cluster_info *cinfo) | |
548 | { | |
dbb64f86 | 549 | WARN_ON(cinfo->token_lockres->mode != DLM_LOCK_EX); |
601b515c GR |
550 | dlm_unlock_sync(cinfo->token_lockres); |
551 | } | |
552 | ||
553 | /* __sendmsg() | |
554 | * This function performs the actual sending of the message. This function is | |
555 | * usually called after performing the encompassing operation | |
556 | * The function: | |
557 | * 1. Grabs the message lockresource in EX mode | |
558 | * 2. Copies the message to the message LVB | |
66099bb0 | 559 | * 3. Downconverts message lockresource to CW |
601b515c GR |
560 | * 4. Upconverts ack lock resource from CR to EX. This forces the BAST on other nodes |
561 | * and the other nodes read the message. The thread will wait here until all other | |
562 | * nodes have released ack lock resource. | |
563 | * 5. Downconvert ack lockresource to CR | |
564 | */ | |
565 | static int __sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg) | |
566 | { | |
567 | int error; | |
568 | int slot = cinfo->slot_number - 1; | |
569 | ||
570 | cmsg->slot = cpu_to_le32(slot); | |
571 | /*get EX on Message*/ | |
572 | error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_EX); | |
573 | if (error) { | |
574 | pr_err("md-cluster: failed to get EX on MESSAGE (%d)\n", error); | |
575 | goto failed_message; | |
576 | } | |
577 | ||
578 | memcpy(cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg, | |
579 | sizeof(struct cluster_msg)); | |
66099bb0 GJ |
580 | /*down-convert EX to CW on Message*/ |
581 | error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CW); | |
601b515c | 582 | if (error) { |
66099bb0 | 583 | pr_err("md-cluster: failed to convert EX to CW on MESSAGE(%d)\n", |
601b515c | 584 | error); |
66099bb0 | 585 | goto failed_ack; |
601b515c GR |
586 | } |
587 | ||
588 | /*up-convert CR to EX on Ack*/ | |
589 | error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_EX); | |
590 | if (error) { | |
591 | pr_err("md-cluster: failed to convert CR to EX on ACK(%d)\n", | |
592 | error); | |
593 | goto failed_ack; | |
594 | } | |
595 | ||
596 | /*down-convert EX to CR on Ack*/ | |
597 | error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR); | |
598 | if (error) { | |
599 | pr_err("md-cluster: failed to convert EX to CR on ACK(%d)\n", | |
600 | error); | |
601 | goto failed_ack; | |
602 | } | |
603 | ||
604 | failed_ack: | |
b5ef5678 GJ |
605 | error = dlm_unlock_sync(cinfo->message_lockres); |
606 | if (unlikely(error != 0)) { | |
607 | pr_err("md-cluster: failed convert to NL on MESSAGE(%d)\n", | |
608 | error); | |
609 | /* in case the message can't be released due to some reason */ | |
610 | goto failed_ack; | |
611 | } | |
601b515c GR |
612 | failed_message: |
613 | return error; | |
614 | } | |
615 | ||
616 | static int sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg) | |
617 | { | |
618 | int ret; | |
619 | ||
620 | lock_comm(cinfo); | |
621 | ret = __sendmsg(cinfo, cmsg); | |
622 | unlock_comm(cinfo); | |
623 | return ret; | |
624 | } | |
625 | ||
96ae923a GR |
626 | static int gather_all_resync_info(struct mddev *mddev, int total_slots) |
627 | { | |
628 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
629 | int i, ret = 0; | |
630 | struct dlm_lock_resource *bm_lockres; | |
631 | struct suspend_info *s; | |
632 | char str[64]; | |
abb9b22a | 633 | sector_t lo, hi; |
96ae923a GR |
634 | |
635 | ||
636 | for (i = 0; i < total_slots; i++) { | |
637 | memset(str, '\0', 64); | |
638 | snprintf(str, 64, "bitmap%04d", i); | |
639 | bm_lockres = lockres_init(mddev, str, NULL, 1); | |
640 | if (!bm_lockres) | |
641 | return -ENOMEM; | |
642 | if (i == (cinfo->slot_number - 1)) | |
643 | continue; | |
644 | ||
645 | bm_lockres->flags |= DLM_LKF_NOQUEUE; | |
646 | ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW); | |
647 | if (ret == -EAGAIN) { | |
648 | memset(bm_lockres->lksb.sb_lvbptr, '\0', LVB_SIZE); | |
649 | s = read_resync_info(mddev, bm_lockres); | |
650 | if (s) { | |
651 | pr_info("%s:%d Resync[%llu..%llu] in progress on %d\n", | |
652 | __func__, __LINE__, | |
653 | (unsigned long long) s->lo, | |
654 | (unsigned long long) s->hi, i); | |
655 | spin_lock_irq(&cinfo->suspend_lock); | |
656 | s->slot = i; | |
657 | list_add(&s->list, &cinfo->suspend_list); | |
658 | spin_unlock_irq(&cinfo->suspend_lock); | |
659 | } | |
660 | ret = 0; | |
661 | lockres_free(bm_lockres); | |
662 | continue; | |
663 | } | |
6e6d9f2c GJ |
664 | if (ret) { |
665 | lockres_free(bm_lockres); | |
96ae923a | 666 | goto out; |
6e6d9f2c | 667 | } |
abb9b22a GJ |
668 | |
669 | /* Read the disk bitmap sb and check if it needs recovery */ | |
670 | ret = bitmap_copy_from_slot(mddev, i, &lo, &hi, false); | |
671 | if (ret) { | |
672 | pr_warn("md-cluster: Could not gather bitmaps from slot %d", i); | |
673 | lockres_free(bm_lockres); | |
674 | continue; | |
675 | } | |
676 | if ((hi > 0) && (lo < mddev->recovery_cp)) { | |
677 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | |
678 | mddev->recovery_cp = lo; | |
679 | md_check_recovery(mddev); | |
680 | } | |
681 | ||
96ae923a GR |
682 | dlm_unlock_sync(bm_lockres); |
683 | lockres_free(bm_lockres); | |
684 | } | |
685 | out: | |
686 | return ret; | |
687 | } | |
688 | ||
edb39c9d GR |
689 | static int join(struct mddev *mddev, int nodes) |
690 | { | |
c4ce867f | 691 | struct md_cluster_info *cinfo; |
cf921cc1 | 692 | int ret, ops_rv; |
c4ce867f GR |
693 | char str[64]; |
694 | ||
c4ce867f GR |
695 | cinfo = kzalloc(sizeof(struct md_cluster_info), GFP_KERNEL); |
696 | if (!cinfo) | |
697 | return -ENOMEM; | |
698 | ||
9e3072e3 GJ |
699 | INIT_LIST_HEAD(&cinfo->suspend_list); |
700 | spin_lock_init(&cinfo->suspend_lock); | |
cf921cc1 | 701 | init_completion(&cinfo->completion); |
eece075c | 702 | set_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state); |
cf921cc1 GR |
703 | |
704 | mutex_init(&cinfo->sb_mutex); | |
705 | mddev->cluster_info = cinfo; | |
706 | ||
c4ce867f | 707 | memset(str, 0, 64); |
b89f704a | 708 | sprintf(str, "%pU", mddev->uuid); |
cf921cc1 GR |
709 | ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name, |
710 | DLM_LSFL_FS, LVB_SIZE, | |
711 | &md_ls_ops, mddev, &ops_rv, &cinfo->lockspace); | |
c4ce867f GR |
712 | if (ret) |
713 | goto err; | |
cf921cc1 | 714 | wait_for_completion(&cinfo->completion); |
8c58f02e GJ |
715 | if (nodes < cinfo->slot_number) { |
716 | pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).", | |
717 | cinfo->slot_number, nodes); | |
b97e9257 GR |
718 | ret = -ERANGE; |
719 | goto err; | |
720 | } | |
4664680c GR |
721 | /* Initiate the communication resources */ |
722 | ret = -ENOMEM; | |
723 | cinfo->recv_thread = md_register_thread(recv_daemon, mddev, "cluster_recv"); | |
724 | if (!cinfo->recv_thread) { | |
725 | pr_err("md-cluster: cannot allocate memory for recv_thread!\n"); | |
726 | goto err; | |
727 | } | |
728 | cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1); | |
729 | if (!cinfo->message_lockres) | |
730 | goto err; | |
731 | cinfo->token_lockres = lockres_init(mddev, "token", NULL, 0); | |
732 | if (!cinfo->token_lockres) | |
733 | goto err; | |
734 | cinfo->ack_lockres = lockres_init(mddev, "ack", ack_bast, 0); | |
735 | if (!cinfo->ack_lockres) | |
736 | goto err; | |
1aee41f6 GR |
737 | cinfo->no_new_dev_lockres = lockres_init(mddev, "no-new-dev", NULL, 0); |
738 | if (!cinfo->no_new_dev_lockres) | |
739 | goto err; | |
740 | ||
4664680c GR |
741 | /* get sync CR lock on ACK. */ |
742 | if (dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR)) | |
743 | pr_err("md-cluster: failed to get a sync CR lock on ACK!(%d)\n", | |
744 | ret); | |
1aee41f6 GR |
745 | /* get sync CR lock on no-new-dev. */ |
746 | if (dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR)) | |
747 | pr_err("md-cluster: failed to get a sync CR lock on no-new-dev!(%d)\n", ret); | |
748 | ||
54519c5f GR |
749 | |
750 | pr_info("md-cluster: Joined cluster %s slot %d\n", str, cinfo->slot_number); | |
751 | snprintf(str, 64, "bitmap%04d", cinfo->slot_number - 1); | |
752 | cinfo->bitmap_lockres = lockres_init(mddev, str, NULL, 1); | |
753 | if (!cinfo->bitmap_lockres) | |
754 | goto err; | |
755 | if (dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW)) { | |
756 | pr_err("Failed to get bitmap lock\n"); | |
757 | ret = -EINVAL; | |
758 | goto err; | |
759 | } | |
760 | ||
c186b128 GR |
761 | cinfo->resync_lockres = lockres_init(mddev, "resync", NULL, 0); |
762 | if (!cinfo->resync_lockres) | |
763 | goto err; | |
764 | ||
96ae923a GR |
765 | ret = gather_all_resync_info(mddev, nodes); |
766 | if (ret) | |
767 | goto err; | |
768 | ||
edb39c9d | 769 | return 0; |
c4ce867f | 770 | err: |
4664680c GR |
771 | lockres_free(cinfo->message_lockres); |
772 | lockres_free(cinfo->token_lockres); | |
773 | lockres_free(cinfo->ack_lockres); | |
1aee41f6 | 774 | lockres_free(cinfo->no_new_dev_lockres); |
c186b128 | 775 | lockres_free(cinfo->resync_lockres); |
96ae923a | 776 | lockres_free(cinfo->bitmap_lockres); |
c4ce867f GR |
777 | if (cinfo->lockspace) |
778 | dlm_release_lockspace(cinfo->lockspace, 2); | |
cf921cc1 | 779 | mddev->cluster_info = NULL; |
c4ce867f | 780 | kfree(cinfo); |
c4ce867f | 781 | return ret; |
edb39c9d GR |
782 | } |
783 | ||
09995411 GJ |
784 | static void resync_bitmap(struct mddev *mddev) |
785 | { | |
786 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
787 | struct cluster_msg cmsg = {0}; | |
788 | int err; | |
789 | ||
790 | cmsg.type = cpu_to_le32(BITMAP_NEEDS_SYNC); | |
791 | err = sendmsg(cinfo, &cmsg); | |
792 | if (err) | |
793 | pr_err("%s:%d: failed to send BITMAP_NEEDS_SYNC message (%d)\n", | |
794 | __func__, __LINE__, err); | |
795 | } | |
796 | ||
edb39c9d GR |
797 | static int leave(struct mddev *mddev) |
798 | { | |
c4ce867f GR |
799 | struct md_cluster_info *cinfo = mddev->cluster_info; |
800 | ||
801 | if (!cinfo) | |
802 | return 0; | |
09995411 GJ |
803 | |
804 | /* BITMAP_NEEDS_SYNC message should be sent when node | |
805 | * is leaving the cluster with dirty bitmap, also we | |
806 | * can only deliver it when dlm connection is available */ | |
807 | if (cinfo->slot_number > 0 && mddev->recovery_cp != MaxSector) | |
808 | resync_bitmap(mddev); | |
809 | ||
e94987db | 810 | md_unregister_thread(&cinfo->recovery_thread); |
4664680c GR |
811 | md_unregister_thread(&cinfo->recv_thread); |
812 | lockres_free(cinfo->message_lockres); | |
813 | lockres_free(cinfo->token_lockres); | |
814 | lockres_free(cinfo->ack_lockres); | |
1aee41f6 | 815 | lockres_free(cinfo->no_new_dev_lockres); |
54519c5f | 816 | lockres_free(cinfo->bitmap_lockres); |
c4ce867f | 817 | dlm_release_lockspace(cinfo->lockspace, 2); |
edb39c9d GR |
818 | return 0; |
819 | } | |
820 | ||
cf921cc1 GR |
821 | /* slot_number(): Returns the MD slot number to use |
822 | * DLM starts the slot numbers from 1, wheras cluster-md | |
823 | * wants the number to be from zero, so we deduct one | |
824 | */ | |
825 | static int slot_number(struct mddev *mddev) | |
826 | { | |
827 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
828 | ||
829 | return cinfo->slot_number - 1; | |
830 | } | |
831 | ||
293467aa GR |
832 | static int metadata_update_start(struct mddev *mddev) |
833 | { | |
834 | return lock_comm(mddev->cluster_info); | |
835 | } | |
836 | ||
837 | static int metadata_update_finish(struct mddev *mddev) | |
838 | { | |
839 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
840 | struct cluster_msg cmsg; | |
70bcecdb GR |
841 | struct md_rdev *rdev; |
842 | int ret = 0; | |
293467aa GR |
843 | |
844 | memset(&cmsg, 0, sizeof(cmsg)); | |
845 | cmsg.type = cpu_to_le32(METADATA_UPDATED); | |
70bcecdb GR |
846 | cmsg.raid_slot = -1; |
847 | /* Pick up a good active device number to send. | |
848 | */ | |
849 | rdev_for_each(rdev, mddev) | |
850 | if (rdev->raid_disk > -1 && !test_bit(Faulty, &rdev->flags)) { | |
851 | cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); | |
852 | break; | |
853 | } | |
854 | if (cmsg.raid_slot >= 0) | |
855 | ret = __sendmsg(cinfo, &cmsg); | |
856 | else | |
857 | pr_warn("md-cluster: No good device id found to send\n"); | |
293467aa GR |
858 | unlock_comm(cinfo); |
859 | return ret; | |
860 | } | |
861 | ||
dbb64f86 | 862 | static void metadata_update_cancel(struct mddev *mddev) |
293467aa GR |
863 | { |
864 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
dbb64f86 | 865 | unlock_comm(cinfo); |
293467aa GR |
866 | } |
867 | ||
c186b128 GR |
868 | static int resync_start(struct mddev *mddev) |
869 | { | |
870 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
871 | cinfo->resync_lockres->flags |= DLM_LKF_NOQUEUE; | |
872 | return dlm_lock_sync(cinfo->resync_lockres, DLM_LOCK_EX); | |
873 | } | |
874 | ||
c40f341f | 875 | static int resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi) |
965400eb GR |
876 | { |
877 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
878 | struct cluster_msg cmsg; | |
879 | int slot = cinfo->slot_number - 1; | |
880 | ||
c40f341f GR |
881 | add_resync_info(mddev, cinfo->bitmap_lockres, lo, hi); |
882 | /* Re-acquire the lock to refresh LVB */ | |
883 | dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW); | |
c40f341f | 884 | cmsg.type = cpu_to_le32(RESYNCING); |
965400eb GR |
885 | cmsg.slot = cpu_to_le32(slot); |
886 | cmsg.low = cpu_to_le64(lo); | |
887 | cmsg.high = cpu_to_le64(hi); | |
c186b128 | 888 | |
965400eb GR |
889 | return sendmsg(cinfo, &cmsg); |
890 | } | |
891 | ||
c186b128 GR |
892 | static int resync_finish(struct mddev *mddev) |
893 | { | |
894 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
895 | cinfo->resync_lockres->flags &= ~DLM_LKF_NOQUEUE; | |
896 | dlm_unlock_sync(cinfo->resync_lockres); | |
897 | return resync_info_update(mddev, 0, 0); | |
898 | } | |
899 | ||
90382ed9 GR |
900 | static int area_resyncing(struct mddev *mddev, int direction, |
901 | sector_t lo, sector_t hi) | |
589a1c49 GR |
902 | { |
903 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
904 | int ret = 0; | |
905 | struct suspend_info *s; | |
906 | ||
90382ed9 GR |
907 | if ((direction == READ) && |
908 | test_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state)) | |
909 | return 1; | |
910 | ||
589a1c49 GR |
911 | spin_lock_irq(&cinfo->suspend_lock); |
912 | if (list_empty(&cinfo->suspend_list)) | |
913 | goto out; | |
914 | list_for_each_entry(s, &cinfo->suspend_list, list) | |
915 | if (hi > s->lo && lo < s->hi) { | |
916 | ret = 1; | |
917 | break; | |
918 | } | |
919 | out: | |
920 | spin_unlock_irq(&cinfo->suspend_lock); | |
921 | return ret; | |
922 | } | |
923 | ||
dbb64f86 GR |
924 | /* add_new_disk() - initiates a disk add |
925 | * However, if this fails before writing md_update_sb(), | |
926 | * add_new_disk_cancel() must be called to release token lock | |
927 | */ | |
928 | static int add_new_disk(struct mddev *mddev, struct md_rdev *rdev) | |
1aee41f6 GR |
929 | { |
930 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
931 | struct cluster_msg cmsg; | |
932 | int ret = 0; | |
933 | struct mdp_superblock_1 *sb = page_address(rdev->sb_page); | |
934 | char *uuid = sb->device_uuid; | |
935 | ||
936 | memset(&cmsg, 0, sizeof(cmsg)); | |
937 | cmsg.type = cpu_to_le32(NEWDISK); | |
938 | memcpy(cmsg.uuid, uuid, 16); | |
939 | cmsg.raid_slot = rdev->desc_nr; | |
940 | lock_comm(cinfo); | |
941 | ret = __sendmsg(cinfo, &cmsg); | |
942 | if (ret) | |
943 | return ret; | |
944 | cinfo->no_new_dev_lockres->flags |= DLM_LKF_NOQUEUE; | |
945 | ret = dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_EX); | |
946 | cinfo->no_new_dev_lockres->flags &= ~DLM_LKF_NOQUEUE; | |
947 | /* Some node does not "see" the device */ | |
948 | if (ret == -EAGAIN) | |
949 | ret = -ENOENT; | |
dbb64f86 GR |
950 | if (ret) |
951 | unlock_comm(cinfo); | |
1aee41f6 GR |
952 | else |
953 | dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR); | |
954 | return ret; | |
955 | } | |
956 | ||
dbb64f86 | 957 | static void add_new_disk_cancel(struct mddev *mddev) |
1aee41f6 | 958 | { |
dbb64f86 GR |
959 | struct md_cluster_info *cinfo = mddev->cluster_info; |
960 | unlock_comm(cinfo); | |
1aee41f6 GR |
961 | } |
962 | ||
fa8259da | 963 | static int new_disk_ack(struct mddev *mddev, bool ack) |
1aee41f6 GR |
964 | { |
965 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
966 | ||
fa8259da GR |
967 | if (!test_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state)) { |
968 | pr_warn("md-cluster(%s): Spurious cluster confirmation\n", mdname(mddev)); | |
969 | return -EINVAL; | |
970 | } | |
971 | ||
1aee41f6 GR |
972 | if (ack) |
973 | dlm_unlock_sync(cinfo->no_new_dev_lockres); | |
974 | complete(&cinfo->newdisk_completion); | |
fa8259da | 975 | return 0; |
1aee41f6 GR |
976 | } |
977 | ||
88bcfef7 GR |
978 | static int remove_disk(struct mddev *mddev, struct md_rdev *rdev) |
979 | { | |
980 | struct cluster_msg cmsg; | |
981 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
982 | cmsg.type = REMOVE; | |
983 | cmsg.raid_slot = rdev->desc_nr; | |
984 | return __sendmsg(cinfo, &cmsg); | |
985 | } | |
986 | ||
97f6cd39 GR |
987 | static int gather_bitmaps(struct md_rdev *rdev) |
988 | { | |
989 | int sn, err; | |
990 | sector_t lo, hi; | |
991 | struct cluster_msg cmsg; | |
992 | struct mddev *mddev = rdev->mddev; | |
993 | struct md_cluster_info *cinfo = mddev->cluster_info; | |
994 | ||
995 | cmsg.type = RE_ADD; | |
996 | cmsg.raid_slot = rdev->desc_nr; | |
997 | err = sendmsg(cinfo, &cmsg); | |
998 | if (err) | |
999 | goto out; | |
1000 | ||
1001 | for (sn = 0; sn < mddev->bitmap_info.nodes; sn++) { | |
1002 | if (sn == (cinfo->slot_number - 1)) | |
1003 | continue; | |
1004 | err = bitmap_copy_from_slot(mddev, sn, &lo, &hi, false); | |
1005 | if (err) { | |
1006 | pr_warn("md-cluster: Could not gather bitmaps from slot %d", sn); | |
1007 | goto out; | |
1008 | } | |
1009 | if ((hi > 0) && (lo < mddev->recovery_cp)) | |
1010 | mddev->recovery_cp = lo; | |
1011 | } | |
1012 | out: | |
1013 | return err; | |
1014 | } | |
1015 | ||
edb39c9d GR |
1016 | static struct md_cluster_operations cluster_ops = { |
1017 | .join = join, | |
1018 | .leave = leave, | |
cf921cc1 | 1019 | .slot_number = slot_number, |
c186b128 GR |
1020 | .resync_start = resync_start, |
1021 | .resync_finish = resync_finish, | |
96ae923a | 1022 | .resync_info_update = resync_info_update, |
293467aa GR |
1023 | .metadata_update_start = metadata_update_start, |
1024 | .metadata_update_finish = metadata_update_finish, | |
1025 | .metadata_update_cancel = metadata_update_cancel, | |
589a1c49 | 1026 | .area_resyncing = area_resyncing, |
dbb64f86 GR |
1027 | .add_new_disk = add_new_disk, |
1028 | .add_new_disk_cancel = add_new_disk_cancel, | |
1aee41f6 | 1029 | .new_disk_ack = new_disk_ack, |
88bcfef7 | 1030 | .remove_disk = remove_disk, |
97f6cd39 | 1031 | .gather_bitmaps = gather_bitmaps, |
edb39c9d GR |
1032 | }; |
1033 | ||
8e854e9c GR |
1034 | static int __init cluster_init(void) |
1035 | { | |
1036 | pr_warn("md-cluster: EXPERIMENTAL. Use with caution\n"); | |
1037 | pr_info("Registering Cluster MD functions\n"); | |
edb39c9d | 1038 | register_md_cluster_operations(&cluster_ops, THIS_MODULE); |
8e854e9c GR |
1039 | return 0; |
1040 | } | |
1041 | ||
1042 | static void cluster_exit(void) | |
1043 | { | |
edb39c9d | 1044 | unregister_md_cluster_operations(); |
8e854e9c GR |
1045 | } |
1046 | ||
1047 | module_init(cluster_init); | |
1048 | module_exit(cluster_exit); | |
1049 | MODULE_LICENSE("GPL"); | |
1050 | MODULE_DESCRIPTION("Clustering support for MD"); |