md-cluster.c 32 KB

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