Goldwyn Rodrigues | 8e854e9 | 2014-03-07 11:21:15 -0600 | [diff] [blame] | 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> |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 13 | #include <linux/dlm.h> |
| 14 | #include <linux/sched.h> |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 15 | #include <linux/raid/md_p.h> |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 16 | #include "md.h" |
Goldwyn Rodrigues | e94987d | 2014-06-07 00:45:22 -0500 | [diff] [blame] | 17 | #include "bitmap.h" |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 18 | #include "md-cluster.h" |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 19 | |
| 20 | #define LVB_SIZE 64 |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 21 | #define NEW_DEV_TIMEOUT 5000 |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 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() */ |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 28 | struct completion completion; /* completion for synchronized locking */ |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 29 | void (*bast)(void *arg, int mode); /* blocking AST function pointer*/ |
| 30 | struct mddev *mddev; /* pointing back to mddev. */ |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 31 | int mode; |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 32 | }; |
| 33 | |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 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 | |
Goldwyn Rodrigues | fa8259d | 2015-03-02 10:55:49 -0600 | [diff] [blame] | 46 | /* md_cluster_info flags */ |
| 47 | #define MD_CLUSTER_WAITING_FOR_NEWDISK 1 |
Goldwyn Rodrigues | 90382ed | 2015-06-24 09:30:32 -0500 | [diff] [blame] | 48 | #define MD_CLUSTER_SUSPEND_READ_BALANCING 2 |
Guoqing Jiang | eece075 | 2015-07-10 17:01:21 +0800 | [diff] [blame] | 49 | #define MD_CLUSTER_BEGIN_JOIN_CLUSTER 3 |
Goldwyn Rodrigues | fa8259d | 2015-03-02 10:55:49 -0600 | [diff] [blame] | 50 | |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 51 | /* 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 Jiang | e19508f | 2015-12-21 10:51:01 +1100 | [diff] [blame] | 56 | /* 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 Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 62 | */ |
| 63 | #define MD_CLUSTER_SEND_LOCKED_ALREADY 5 |
Guoqing Jiang | 51e453a | 2016-05-04 02:17:09 -0400 | [diff] [blame] | 64 | /* 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 Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 68 | |
Goldwyn Rodrigues | fa8259d | 2015-03-02 10:55:49 -0600 | [diff] [blame] | 69 | |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 70 | struct md_cluster_info { |
| 71 | /* dlm lock space and resources for clustered raid. */ |
| 72 | dlm_lockspace_t *lockspace; |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 73 | int slot_number; |
| 74 | struct completion completion; |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 75 | struct mutex recv_mutex; |
Goldwyn Rodrigues | 54519c5 | 2014-06-06 12:12:32 -0500 | [diff] [blame] | 76 | struct dlm_lock_resource *bitmap_lockres; |
Guoqing Jiang | f6a2dc6 | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 77 | struct dlm_lock_resource **other_bitmap_lockres; |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 78 | struct dlm_lock_resource *resync_lockres; |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 79 | struct list_head suspend_list; |
| 80 | spinlock_t suspend_lock; |
Goldwyn Rodrigues | e94987d | 2014-06-07 00:45:22 -0500 | [diff] [blame] | 81 | struct md_thread *recovery_thread; |
| 82 | unsigned long recovery_map; |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 83 | /* 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 Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 87 | struct dlm_lock_resource *no_new_dev_lockres; |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 88 | struct md_thread *recv_thread; |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 89 | struct completion newdisk_completion; |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 90 | wait_queue_head_t wait; |
Goldwyn Rodrigues | fa8259d | 2015-03-02 10:55:49 -0600 | [diff] [blame] | 91 | unsigned long state; |
Guoqing Jiang | 18c9ff7 | 2016-05-02 11:50:12 -0400 | [diff] [blame] | 92 | /* record the region in RESYNCING message */ |
| 93 | sector_t sync_low; |
| 94 | sector_t sync_hi; |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | enum msg_type { |
| 98 | METADATA_UPDATED = 0, |
| 99 | RESYNCING, |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 100 | NEWDISK, |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 101 | REMOVE, |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 102 | RE_ADD, |
Guoqing Jiang | dc737d7 | 2015-07-10 16:54:04 +0800 | [diff] [blame] | 103 | BITMAP_NEEDS_SYNC, |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | struct cluster_msg { |
Guoqing Jiang | cf97a34 | 2015-10-16 15:40:22 +0800 | [diff] [blame] | 107 | __le32 type; |
| 108 | __le32 slot; |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 109 | /* TODO: Unionize this for smaller footprint */ |
Guoqing Jiang | cf97a34 | 2015-10-16 15:40:22 +0800 | [diff] [blame] | 110 | __le64 low; |
| 111 | __le64 high; |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 112 | char uuid[16]; |
Guoqing Jiang | cf97a34 | 2015-10-16 15:40:22 +0800 | [diff] [blame] | 113 | __le32 raid_slot; |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | static void sync_ast(void *arg) |
| 117 | { |
| 118 | struct dlm_lock_resource *res; |
| 119 | |
NeilBrown | 2e2a7cd | 2015-10-19 15:42:18 +1100 | [diff] [blame] | 120 | res = arg; |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 121 | complete(&res->completion); |
| 122 | } |
| 123 | |
| 124 | static int dlm_lock_sync(struct dlm_lock_resource *res, int mode) |
| 125 | { |
| 126 | int ret = 0; |
| 127 | |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 128 | 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 Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 134 | if (res->lksb.sb_status == 0) |
| 135 | res->mode = mode; |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 136 | return res->lksb.sb_status; |
| 137 | } |
| 138 | |
| 139 | static int dlm_unlock_sync(struct dlm_lock_resource *res) |
| 140 | { |
| 141 | return dlm_lock_sync(res, DLM_LOCK_NL); |
| 142 | } |
| 143 | |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 144 | static struct dlm_lock_resource *lockres_init(struct mddev *mddev, |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 145 | char *name, void (*bastfn)(void *arg, int mode), int with_lvb) |
| 146 | { |
| 147 | struct dlm_lock_resource *res = NULL; |
| 148 | int ret, namelen; |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 149 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 150 | |
| 151 | res = kzalloc(sizeof(struct dlm_lock_resource), GFP_KERNEL); |
| 152 | if (!res) |
| 153 | return NULL; |
Guoqing Jiang | b83d51c | 2015-07-10 17:01:16 +0800 | [diff] [blame] | 154 | init_completion(&res->completion); |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 155 | res->ls = cinfo->lockspace; |
| 156 | res->mddev = mddev; |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 157 | res->mode = DLM_LOCK_IV; |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 158 | 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; |
| 188 | out_err: |
| 189 | kfree(res->lksb.sb_lvbptr); |
| 190 | kfree(res->name); |
| 191 | kfree(res); |
| 192 | return NULL; |
| 193 | } |
| 194 | |
| 195 | static void lockres_free(struct dlm_lock_resource *res) |
| 196 | { |
Guoqing Jiang | b5ef567 | 2015-07-10 17:01:17 +0800 | [diff] [blame] | 197 | int ret; |
| 198 | |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 199 | if (!res) |
| 200 | return; |
| 201 | |
Guoqing Jiang | b5ef567 | 2015-07-10 17:01:17 +0800 | [diff] [blame] | 202 | /* cancel a lock request or a conversion request that is blocked */ |
| 203 | res->flags |= DLM_LKF_CANCEL; |
| 204 | retry: |
| 205 | ret = dlm_unlock(res->ls, res->lksb.sb_lkid, 0, &res->lksb, res); |
| 206 | if (unlikely(ret != 0)) { |
| 207 | pr_info("%s: failed to unlock %s return %d\n", __func__, res->name, ret); |
| 208 | |
| 209 | /* if a lock conversion is cancelled, then the lock is put |
| 210 | * back to grant queue, need to ensure it is unlocked */ |
| 211 | if (ret == -DLM_ECANCEL) |
| 212 | goto retry; |
| 213 | } |
| 214 | res->flags &= ~DLM_LKF_CANCEL; |
Goldwyn Rodrigues | 47741b7 | 2014-03-07 13:49:26 -0600 | [diff] [blame] | 215 | wait_for_completion(&res->completion); |
| 216 | |
| 217 | kfree(res->name); |
| 218 | kfree(res->lksb.sb_lvbptr); |
| 219 | kfree(res); |
| 220 | } |
Goldwyn Rodrigues | 8e854e9 | 2014-03-07 11:21:15 -0600 | [diff] [blame] | 221 | |
NeilBrown | 30661b4 | 2015-10-19 15:44:00 +1100 | [diff] [blame] | 222 | static void add_resync_info(struct dlm_lock_resource *lockres, |
| 223 | sector_t lo, sector_t hi) |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 224 | { |
| 225 | struct resync_info *ri; |
| 226 | |
| 227 | ri = (struct resync_info *)lockres->lksb.sb_lvbptr; |
| 228 | ri->lo = cpu_to_le64(lo); |
| 229 | ri->hi = cpu_to_le64(hi); |
| 230 | } |
| 231 | |
| 232 | static struct suspend_info *read_resync_info(struct mddev *mddev, struct dlm_lock_resource *lockres) |
| 233 | { |
| 234 | struct resync_info ri; |
| 235 | struct suspend_info *s = NULL; |
| 236 | sector_t hi = 0; |
| 237 | |
| 238 | dlm_lock_sync(lockres, DLM_LOCK_CR); |
| 239 | memcpy(&ri, lockres->lksb.sb_lvbptr, sizeof(struct resync_info)); |
| 240 | hi = le64_to_cpu(ri.hi); |
Guoqing Jiang | cf97a34 | 2015-10-16 15:40:22 +0800 | [diff] [blame] | 241 | if (hi > 0) { |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 242 | s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL); |
| 243 | if (!s) |
| 244 | goto out; |
| 245 | s->hi = hi; |
| 246 | s->lo = le64_to_cpu(ri.lo); |
| 247 | } |
| 248 | dlm_unlock_sync(lockres); |
| 249 | out: |
| 250 | return s; |
| 251 | } |
| 252 | |
kbuild test robot | 6dc69c9 | 2015-02-28 07:04:37 +0800 | [diff] [blame] | 253 | static void recover_bitmaps(struct md_thread *thread) |
Goldwyn Rodrigues | e94987d | 2014-06-07 00:45:22 -0500 | [diff] [blame] | 254 | { |
| 255 | struct mddev *mddev = thread->mddev; |
| 256 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 257 | struct dlm_lock_resource *bm_lockres; |
| 258 | char str[64]; |
| 259 | int slot, ret; |
| 260 | struct suspend_info *s, *tmp; |
| 261 | sector_t lo, hi; |
| 262 | |
| 263 | while (cinfo->recovery_map) { |
| 264 | slot = fls64((u64)cinfo->recovery_map) - 1; |
| 265 | |
| 266 | /* Clear suspend_area associated with the bitmap */ |
| 267 | spin_lock_irq(&cinfo->suspend_lock); |
| 268 | list_for_each_entry_safe(s, tmp, &cinfo->suspend_list, list) |
| 269 | if (slot == s->slot) { |
| 270 | list_del(&s->list); |
| 271 | kfree(s); |
| 272 | } |
| 273 | spin_unlock_irq(&cinfo->suspend_lock); |
| 274 | |
| 275 | snprintf(str, 64, "bitmap%04d", slot); |
| 276 | bm_lockres = lockres_init(mddev, str, NULL, 1); |
| 277 | if (!bm_lockres) { |
| 278 | pr_err("md-cluster: Cannot initialize bitmaps\n"); |
| 279 | goto clear_bit; |
| 280 | } |
| 281 | |
| 282 | ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW); |
| 283 | if (ret) { |
| 284 | pr_err("md-cluster: Could not DLM lock %s: %d\n", |
| 285 | str, ret); |
| 286 | goto clear_bit; |
| 287 | } |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 288 | ret = bitmap_copy_from_slot(mddev, slot, &lo, &hi, true); |
Goldwyn Rodrigues | 4b26a08 | 2014-06-07 00:52:29 -0500 | [diff] [blame] | 289 | if (ret) { |
Goldwyn Rodrigues | e94987d | 2014-06-07 00:45:22 -0500 | [diff] [blame] | 290 | pr_err("md-cluster: Could not copy data from bitmap %d\n", slot); |
Goldwyn Rodrigues | 4b26a08 | 2014-06-07 00:52:29 -0500 | [diff] [blame] | 291 | goto dlm_unlock; |
| 292 | } |
| 293 | if (hi > 0) { |
Goldwyn Rodrigues | 4b26a08 | 2014-06-07 00:52:29 -0500 | [diff] [blame] | 294 | if (lo < mddev->recovery_cp) |
| 295 | mddev->recovery_cp = lo; |
Guoqing Jiang | eb315cd | 2016-05-02 11:33:10 -0400 | [diff] [blame] | 296 | /* wake up thread to continue resync in case resync |
| 297 | * is not finished */ |
| 298 | if (mddev->recovery_cp != MaxSector) { |
| 299 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 300 | md_wakeup_thread(mddev->thread); |
| 301 | } |
Goldwyn Rodrigues | 4b26a08 | 2014-06-07 00:52:29 -0500 | [diff] [blame] | 302 | } |
| 303 | dlm_unlock: |
Goldwyn Rodrigues | e94987d | 2014-06-07 00:45:22 -0500 | [diff] [blame] | 304 | dlm_unlock_sync(bm_lockres); |
| 305 | clear_bit: |
Shaohua Li | 4ac7a65 | 2016-01-22 15:54:42 -0800 | [diff] [blame] | 306 | lockres_free(bm_lockres); |
Goldwyn Rodrigues | e94987d | 2014-06-07 00:45:22 -0500 | [diff] [blame] | 307 | clear_bit(slot, &cinfo->recovery_map); |
| 308 | } |
| 309 | } |
| 310 | |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 311 | static void recover_prep(void *arg) |
| 312 | { |
Goldwyn Rodrigues | 90382ed | 2015-06-24 09:30:32 -0500 | [diff] [blame] | 313 | struct mddev *mddev = arg; |
| 314 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 315 | set_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state); |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 316 | } |
| 317 | |
Guoqing Jiang | 05cd0e5 | 2015-07-10 16:54:03 +0800 | [diff] [blame] | 318 | static void __recover_slot(struct mddev *mddev, int slot) |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 319 | { |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 320 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 321 | |
Guoqing Jiang | 05cd0e5 | 2015-07-10 16:54:03 +0800 | [diff] [blame] | 322 | set_bit(slot, &cinfo->recovery_map); |
Goldwyn Rodrigues | e94987d | 2014-06-07 00:45:22 -0500 | [diff] [blame] | 323 | if (!cinfo->recovery_thread) { |
| 324 | cinfo->recovery_thread = md_register_thread(recover_bitmaps, |
| 325 | mddev, "recover"); |
| 326 | if (!cinfo->recovery_thread) { |
| 327 | pr_warn("md-cluster: Could not create recovery thread\n"); |
| 328 | return; |
| 329 | } |
| 330 | } |
| 331 | md_wakeup_thread(cinfo->recovery_thread); |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 332 | } |
| 333 | |
Guoqing Jiang | 05cd0e5 | 2015-07-10 16:54:03 +0800 | [diff] [blame] | 334 | static void recover_slot(void *arg, struct dlm_slot *slot) |
| 335 | { |
| 336 | struct mddev *mddev = arg; |
| 337 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 338 | |
| 339 | pr_info("md-cluster: %s Node %d/%d down. My slot: %d. Initiating recovery.\n", |
| 340 | mddev->bitmap_info.cluster_name, |
| 341 | slot->nodeid, slot->slot, |
| 342 | cinfo->slot_number); |
| 343 | /* deduct one since dlm slot starts from one while the num of |
| 344 | * cluster-md begins with 0 */ |
| 345 | __recover_slot(mddev, slot->slot - 1); |
| 346 | } |
| 347 | |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 348 | static void recover_done(void *arg, struct dlm_slot *slots, |
| 349 | int num_slots, int our_slot, |
| 350 | uint32_t generation) |
| 351 | { |
| 352 | struct mddev *mddev = arg; |
| 353 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 354 | |
| 355 | cinfo->slot_number = our_slot; |
Guoqing Jiang | eece075 | 2015-07-10 17:01:21 +0800 | [diff] [blame] | 356 | /* completion is only need to be complete when node join cluster, |
| 357 | * it doesn't need to run during another node's failure */ |
| 358 | if (test_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state)) { |
| 359 | complete(&cinfo->completion); |
| 360 | clear_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state); |
| 361 | } |
Goldwyn Rodrigues | 90382ed | 2015-06-24 09:30:32 -0500 | [diff] [blame] | 362 | clear_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state); |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 363 | } |
| 364 | |
Guoqing Jiang | eece075 | 2015-07-10 17:01:21 +0800 | [diff] [blame] | 365 | /* the ops is called when node join the cluster, and do lock recovery |
| 366 | * if node failure occurs */ |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 367 | static const struct dlm_lockspace_ops md_ls_ops = { |
| 368 | .recover_prep = recover_prep, |
| 369 | .recover_slot = recover_slot, |
| 370 | .recover_done = recover_done, |
| 371 | }; |
| 372 | |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 373 | /* |
| 374 | * The BAST function for the ack lock resource |
| 375 | * This function wakes up the receive thread in |
| 376 | * order to receive and process the message. |
| 377 | */ |
| 378 | static void ack_bast(void *arg, int mode) |
| 379 | { |
NeilBrown | 2e2a7cd | 2015-10-19 15:42:18 +1100 | [diff] [blame] | 380 | struct dlm_lock_resource *res = arg; |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 381 | struct md_cluster_info *cinfo = res->mddev->cluster_info; |
| 382 | |
Guoqing Jiang | 51e453a | 2016-05-04 02:17:09 -0400 | [diff] [blame] | 383 | if (mode == DLM_LOCK_EX) { |
| 384 | if (test_bit(MD_CLUSTER_ALREADY_IN_CLUSTER, &cinfo->state)) |
| 385 | md_wakeup_thread(cinfo->recv_thread); |
| 386 | else |
| 387 | set_bit(MD_CLUSTER_PENDING_RECV_EVENT, &cinfo->state); |
| 388 | } |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 389 | } |
| 390 | |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 391 | static void __remove_suspend_info(struct md_cluster_info *cinfo, int slot) |
| 392 | { |
| 393 | struct suspend_info *s, *tmp; |
| 394 | |
| 395 | list_for_each_entry_safe(s, tmp, &cinfo->suspend_list, list) |
| 396 | if (slot == s->slot) { |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 397 | list_del(&s->list); |
| 398 | kfree(s); |
| 399 | break; |
| 400 | } |
| 401 | } |
| 402 | |
Goldwyn Rodrigues | b8ca846 | 2015-10-09 11:27:01 -0500 | [diff] [blame] | 403 | static void remove_suspend_info(struct mddev *mddev, int slot) |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 404 | { |
Goldwyn Rodrigues | b8ca846 | 2015-10-09 11:27:01 -0500 | [diff] [blame] | 405 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 406 | spin_lock_irq(&cinfo->suspend_lock); |
| 407 | __remove_suspend_info(cinfo, slot); |
| 408 | spin_unlock_irq(&cinfo->suspend_lock); |
Goldwyn Rodrigues | b8ca846 | 2015-10-09 11:27:01 -0500 | [diff] [blame] | 409 | mddev->pers->quiesce(mddev, 2); |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | |
Goldwyn Rodrigues | 9ed38ff5 | 2015-08-14 12:19:40 -0500 | [diff] [blame] | 413 | static void process_suspend_info(struct mddev *mddev, |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 414 | int slot, sector_t lo, sector_t hi) |
| 415 | { |
Goldwyn Rodrigues | 9ed38ff5 | 2015-08-14 12:19:40 -0500 | [diff] [blame] | 416 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 417 | struct suspend_info *s; |
| 418 | |
| 419 | if (!hi) { |
Goldwyn Rodrigues | b8ca846 | 2015-10-09 11:27:01 -0500 | [diff] [blame] | 420 | remove_suspend_info(mddev, slot); |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 421 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 422 | md_wakeup_thread(mddev->thread); |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 423 | return; |
| 424 | } |
Guoqing Jiang | 18c9ff7 | 2016-05-02 11:50:12 -0400 | [diff] [blame] | 425 | |
| 426 | /* |
| 427 | * The bitmaps are not same for different nodes |
| 428 | * if RESYNCING is happening in one node, then |
| 429 | * the node which received the RESYNCING message |
| 430 | * probably will perform resync with the region |
| 431 | * [lo, hi] again, so we could reduce resync time |
| 432 | * a lot if we can ensure that the bitmaps among |
| 433 | * different nodes are match up well. |
| 434 | * |
| 435 | * sync_low/hi is used to record the region which |
| 436 | * arrived in the previous RESYNCING message, |
| 437 | * |
| 438 | * Call bitmap_sync_with_cluster to clear |
| 439 | * NEEDED_MASK and set RESYNC_MASK since |
| 440 | * resync thread is running in another node, |
| 441 | * so we don't need to do the resync again |
| 442 | * with the same section */ |
| 443 | bitmap_sync_with_cluster(mddev, cinfo->sync_low, |
| 444 | cinfo->sync_hi, |
| 445 | lo, hi); |
| 446 | cinfo->sync_low = lo; |
| 447 | cinfo->sync_hi = hi; |
| 448 | |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 449 | s = kzalloc(sizeof(struct suspend_info), GFP_KERNEL); |
| 450 | if (!s) |
| 451 | return; |
| 452 | s->slot = slot; |
| 453 | s->lo = lo; |
| 454 | s->hi = hi; |
Goldwyn Rodrigues | 9ed38ff5 | 2015-08-14 12:19:40 -0500 | [diff] [blame] | 455 | mddev->pers->quiesce(mddev, 1); |
| 456 | mddev->pers->quiesce(mddev, 0); |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 457 | spin_lock_irq(&cinfo->suspend_lock); |
| 458 | /* Remove existing entry (if exists) before adding */ |
| 459 | __remove_suspend_info(cinfo, slot); |
| 460 | list_add(&s->list, &cinfo->suspend_list); |
| 461 | spin_unlock_irq(&cinfo->suspend_lock); |
Goldwyn Rodrigues | b8ca846 | 2015-10-09 11:27:01 -0500 | [diff] [blame] | 462 | mddev->pers->quiesce(mddev, 2); |
Goldwyn Rodrigues | e59721c | 2014-06-07 02:30:30 -0500 | [diff] [blame] | 463 | } |
| 464 | |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 465 | static void process_add_new_disk(struct mddev *mddev, struct cluster_msg *cmsg) |
| 466 | { |
| 467 | char disk_uuid[64]; |
| 468 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 469 | char event_name[] = "EVENT=ADD_DEVICE"; |
| 470 | char raid_slot[16]; |
| 471 | char *envp[] = {event_name, disk_uuid, raid_slot, NULL}; |
| 472 | int len; |
| 473 | |
| 474 | len = snprintf(disk_uuid, 64, "DEVICE_UUID="); |
Guoqing Jiang | b89f704 | 2015-07-10 16:54:02 +0800 | [diff] [blame] | 475 | sprintf(disk_uuid + len, "%pU", cmsg->uuid); |
Guoqing Jiang | faeff83 | 2015-10-12 17:21:21 +0800 | [diff] [blame] | 476 | snprintf(raid_slot, 16, "RAID_DISK=%d", le32_to_cpu(cmsg->raid_slot)); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 477 | pr_info("%s:%d Sending kobject change with %s and %s\n", __func__, __LINE__, disk_uuid, raid_slot); |
| 478 | init_completion(&cinfo->newdisk_completion); |
Goldwyn Rodrigues | fa8259d | 2015-03-02 10:55:49 -0600 | [diff] [blame] | 479 | set_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 480 | kobject_uevent_env(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE, envp); |
| 481 | wait_for_completion_timeout(&cinfo->newdisk_completion, |
| 482 | NEW_DEV_TIMEOUT); |
Goldwyn Rodrigues | fa8259d | 2015-03-02 10:55:49 -0600 | [diff] [blame] | 483 | clear_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | |
| 487 | static void process_metadata_update(struct mddev *mddev, struct cluster_msg *msg) |
| 488 | { |
| 489 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Guoqing Jiang | 15858fa | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 490 | mddev->good_device_nr = le32_to_cpu(msg->raid_slot); |
| 491 | set_bit(MD_RELOAD_SB, &mddev->flags); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 492 | dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR); |
Guoqing Jiang | 15858fa | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 493 | md_wakeup_thread(mddev->thread); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 494 | } |
| 495 | |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 496 | static void process_remove_disk(struct mddev *mddev, struct cluster_msg *msg) |
| 497 | { |
Guoqing Jiang | faeff83 | 2015-10-12 17:21:21 +0800 | [diff] [blame] | 498 | struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev, |
| 499 | le32_to_cpu(msg->raid_slot)); |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 500 | |
Guoqing Jiang | 659b254 | 2015-12-21 10:50:59 +1100 | [diff] [blame] | 501 | if (rdev) { |
| 502 | set_bit(ClusterRemove, &rdev->flags); |
| 503 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 504 | md_wakeup_thread(mddev->thread); |
| 505 | } |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 506 | else |
Guoqing Jiang | faeff83 | 2015-10-12 17:21:21 +0800 | [diff] [blame] | 507 | pr_warn("%s: %d Could not find disk(%d) to REMOVE\n", |
| 508 | __func__, __LINE__, le32_to_cpu(msg->raid_slot)); |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 509 | } |
| 510 | |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 511 | static void process_readd_disk(struct mddev *mddev, struct cluster_msg *msg) |
| 512 | { |
Guoqing Jiang | faeff83 | 2015-10-12 17:21:21 +0800 | [diff] [blame] | 513 | struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev, |
| 514 | le32_to_cpu(msg->raid_slot)); |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 515 | |
| 516 | if (rdev && test_bit(Faulty, &rdev->flags)) |
| 517 | clear_bit(Faulty, &rdev->flags); |
| 518 | else |
Guoqing Jiang | faeff83 | 2015-10-12 17:21:21 +0800 | [diff] [blame] | 519 | pr_warn("%s: %d Could not find disk(%d) which is faulty", |
| 520 | __func__, __LINE__, le32_to_cpu(msg->raid_slot)); |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 521 | } |
| 522 | |
Guoqing Jiang | 1fa9a1a | 2016-05-03 22:22:15 -0400 | [diff] [blame] | 523 | static int process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg) |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 524 | { |
Guoqing Jiang | 1fa9a1a | 2016-05-03 22:22:15 -0400 | [diff] [blame] | 525 | int ret = 0; |
| 526 | |
Guoqing Jiang | 256f5b2 | 2015-10-12 17:21:23 +0800 | [diff] [blame] | 527 | if (WARN(mddev->cluster_info->slot_number - 1 == le32_to_cpu(msg->slot), |
| 528 | "node %d received it's own msg\n", le32_to_cpu(msg->slot))) |
Guoqing Jiang | 1fa9a1a | 2016-05-03 22:22:15 -0400 | [diff] [blame] | 529 | return -1; |
Guoqing Jiang | cf97a34 | 2015-10-16 15:40:22 +0800 | [diff] [blame] | 530 | switch (le32_to_cpu(msg->type)) { |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 531 | case METADATA_UPDATED: |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 532 | process_metadata_update(mddev, msg); |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 533 | break; |
| 534 | case RESYNCING: |
Guoqing Jiang | cf97a34 | 2015-10-16 15:40:22 +0800 | [diff] [blame] | 535 | process_suspend_info(mddev, le32_to_cpu(msg->slot), |
| 536 | le64_to_cpu(msg->low), |
| 537 | le64_to_cpu(msg->high)); |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 538 | break; |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 539 | case NEWDISK: |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 540 | process_add_new_disk(mddev, msg); |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 541 | break; |
| 542 | case REMOVE: |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 543 | process_remove_disk(mddev, msg); |
| 544 | break; |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 545 | case RE_ADD: |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 546 | process_readd_disk(mddev, msg); |
| 547 | break; |
Guoqing Jiang | dc737d7 | 2015-07-10 16:54:04 +0800 | [diff] [blame] | 548 | case BITMAP_NEEDS_SYNC: |
Guoqing Jiang | cf97a34 | 2015-10-16 15:40:22 +0800 | [diff] [blame] | 549 | __recover_slot(mddev, le32_to_cpu(msg->slot)); |
Guoqing Jiang | dc737d7 | 2015-07-10 16:54:04 +0800 | [diff] [blame] | 550 | break; |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 551 | default: |
Guoqing Jiang | 1fa9a1a | 2016-05-03 22:22:15 -0400 | [diff] [blame] | 552 | ret = -1; |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 553 | pr_warn("%s:%d Received unknown message from %d\n", |
| 554 | __func__, __LINE__, msg->slot); |
kbuild test robot | 09dd1af | 2015-02-28 09:16:08 +0800 | [diff] [blame] | 555 | } |
Guoqing Jiang | 1fa9a1a | 2016-05-03 22:22:15 -0400 | [diff] [blame] | 556 | return ret; |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* |
| 560 | * thread for receiving message |
| 561 | */ |
| 562 | static void recv_daemon(struct md_thread *thread) |
| 563 | { |
| 564 | struct md_cluster_info *cinfo = thread->mddev->cluster_info; |
| 565 | struct dlm_lock_resource *ack_lockres = cinfo->ack_lockres; |
| 566 | struct dlm_lock_resource *message_lockres = cinfo->message_lockres; |
| 567 | struct cluster_msg msg; |
Guoqing Jiang | b5ef567 | 2015-07-10 17:01:17 +0800 | [diff] [blame] | 568 | int ret; |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 569 | |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 570 | mutex_lock(&cinfo->recv_mutex); |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 571 | /*get CR on Message*/ |
| 572 | if (dlm_lock_sync(message_lockres, DLM_LOCK_CR)) { |
| 573 | pr_err("md/raid1:failed to get CR on MESSAGE\n"); |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 574 | mutex_unlock(&cinfo->recv_mutex); |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 575 | return; |
| 576 | } |
| 577 | |
| 578 | /* read lvb and wake up thread to process this message_lockres */ |
| 579 | memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(struct cluster_msg)); |
Guoqing Jiang | 1fa9a1a | 2016-05-03 22:22:15 -0400 | [diff] [blame] | 580 | ret = process_recvd_msg(thread->mddev, &msg); |
| 581 | if (ret) |
| 582 | goto out; |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 583 | |
| 584 | /*release CR on ack_lockres*/ |
Guoqing Jiang | b5ef567 | 2015-07-10 17:01:17 +0800 | [diff] [blame] | 585 | ret = dlm_unlock_sync(ack_lockres); |
| 586 | if (unlikely(ret != 0)) |
| 587 | pr_info("unlock ack failed return %d\n", ret); |
Guoqing Jiang | 66099bb | 2015-07-10 17:01:15 +0800 | [diff] [blame] | 588 | /*up-convert to PR on message_lockres*/ |
Guoqing Jiang | b5ef567 | 2015-07-10 17:01:17 +0800 | [diff] [blame] | 589 | ret = dlm_lock_sync(message_lockres, DLM_LOCK_PR); |
| 590 | if (unlikely(ret != 0)) |
| 591 | pr_info("lock PR on msg failed return %d\n", ret); |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 592 | /*get CR on ack_lockres again*/ |
Guoqing Jiang | b5ef567 | 2015-07-10 17:01:17 +0800 | [diff] [blame] | 593 | ret = dlm_lock_sync(ack_lockres, DLM_LOCK_CR); |
| 594 | if (unlikely(ret != 0)) |
| 595 | pr_info("lock CR on ack failed return %d\n", ret); |
Guoqing Jiang | 1fa9a1a | 2016-05-03 22:22:15 -0400 | [diff] [blame] | 596 | out: |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 597 | /*release CR on message_lockres*/ |
Guoqing Jiang | b5ef567 | 2015-07-10 17:01:17 +0800 | [diff] [blame] | 598 | ret = dlm_unlock_sync(message_lockres); |
| 599 | if (unlikely(ret != 0)) |
| 600 | pr_info("unlock msg failed return %d\n", ret); |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 601 | mutex_unlock(&cinfo->recv_mutex); |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 602 | } |
| 603 | |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 604 | /* lock_token() |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 605 | * Takes the lock on the TOKEN lock resource so no other |
| 606 | * node can communicate while the operation is underway. |
| 607 | */ |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 608 | static int lock_token(struct md_cluster_info *cinfo) |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 609 | { |
| 610 | int error; |
| 611 | |
| 612 | error = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX); |
| 613 | if (error) |
| 614 | pr_err("md-cluster(%s:%d): failed to get EX on TOKEN (%d)\n", |
| 615 | __func__, __LINE__, error); |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 616 | |
| 617 | /* Lock the receive sequence */ |
| 618 | mutex_lock(&cinfo->recv_mutex); |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 619 | return error; |
| 620 | } |
| 621 | |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 622 | /* lock_comm() |
| 623 | * Sets the MD_CLUSTER_SEND_LOCK bit to lock the send channel. |
| 624 | */ |
| 625 | static int lock_comm(struct md_cluster_info *cinfo) |
| 626 | { |
| 627 | wait_event(cinfo->wait, |
| 628 | !test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state)); |
| 629 | |
| 630 | return lock_token(cinfo); |
| 631 | } |
| 632 | |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 633 | static void unlock_comm(struct md_cluster_info *cinfo) |
| 634 | { |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 635 | WARN_ON(cinfo->token_lockres->mode != DLM_LOCK_EX); |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 636 | mutex_unlock(&cinfo->recv_mutex); |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 637 | dlm_unlock_sync(cinfo->token_lockres); |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 638 | clear_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state); |
| 639 | wake_up(&cinfo->wait); |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /* __sendmsg() |
| 643 | * This function performs the actual sending of the message. This function is |
| 644 | * usually called after performing the encompassing operation |
| 645 | * The function: |
| 646 | * 1. Grabs the message lockresource in EX mode |
| 647 | * 2. Copies the message to the message LVB |
Guoqing Jiang | 66099bb | 2015-07-10 17:01:15 +0800 | [diff] [blame] | 648 | * 3. Downconverts message lockresource to CW |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 649 | * 4. Upconverts ack lock resource from CR to EX. This forces the BAST on other nodes |
| 650 | * and the other nodes read the message. The thread will wait here until all other |
| 651 | * nodes have released ack lock resource. |
| 652 | * 5. Downconvert ack lockresource to CR |
| 653 | */ |
| 654 | static int __sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg) |
| 655 | { |
| 656 | int error; |
| 657 | int slot = cinfo->slot_number - 1; |
| 658 | |
| 659 | cmsg->slot = cpu_to_le32(slot); |
| 660 | /*get EX on Message*/ |
| 661 | error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_EX); |
| 662 | if (error) { |
| 663 | pr_err("md-cluster: failed to get EX on MESSAGE (%d)\n", error); |
| 664 | goto failed_message; |
| 665 | } |
| 666 | |
| 667 | memcpy(cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg, |
| 668 | sizeof(struct cluster_msg)); |
Guoqing Jiang | 66099bb | 2015-07-10 17:01:15 +0800 | [diff] [blame] | 669 | /*down-convert EX to CW on Message*/ |
| 670 | error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CW); |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 671 | if (error) { |
Guoqing Jiang | 66099bb | 2015-07-10 17:01:15 +0800 | [diff] [blame] | 672 | pr_err("md-cluster: failed to convert EX to CW on MESSAGE(%d)\n", |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 673 | error); |
Guoqing Jiang | 66099bb | 2015-07-10 17:01:15 +0800 | [diff] [blame] | 674 | goto failed_ack; |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /*up-convert CR to EX on Ack*/ |
| 678 | error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_EX); |
| 679 | if (error) { |
| 680 | pr_err("md-cluster: failed to convert CR to EX on ACK(%d)\n", |
| 681 | error); |
| 682 | goto failed_ack; |
| 683 | } |
| 684 | |
| 685 | /*down-convert EX to CR on Ack*/ |
| 686 | error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR); |
| 687 | if (error) { |
| 688 | pr_err("md-cluster: failed to convert EX to CR on ACK(%d)\n", |
| 689 | error); |
| 690 | goto failed_ack; |
| 691 | } |
| 692 | |
| 693 | failed_ack: |
Guoqing Jiang | b5ef567 | 2015-07-10 17:01:17 +0800 | [diff] [blame] | 694 | error = dlm_unlock_sync(cinfo->message_lockres); |
| 695 | if (unlikely(error != 0)) { |
| 696 | pr_err("md-cluster: failed convert to NL on MESSAGE(%d)\n", |
| 697 | error); |
| 698 | /* in case the message can't be released due to some reason */ |
| 699 | goto failed_ack; |
| 700 | } |
Goldwyn Rodrigues | 601b515 | 2014-06-07 01:28:53 -0500 | [diff] [blame] | 701 | failed_message: |
| 702 | return error; |
| 703 | } |
| 704 | |
| 705 | static int sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg) |
| 706 | { |
| 707 | int ret; |
| 708 | |
| 709 | lock_comm(cinfo); |
| 710 | ret = __sendmsg(cinfo, cmsg); |
| 711 | unlock_comm(cinfo); |
| 712 | return ret; |
| 713 | } |
| 714 | |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 715 | static int gather_all_resync_info(struct mddev *mddev, int total_slots) |
| 716 | { |
| 717 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 718 | int i, ret = 0; |
| 719 | struct dlm_lock_resource *bm_lockres; |
| 720 | struct suspend_info *s; |
| 721 | char str[64]; |
Guoqing Jiang | abb9b22 | 2015-07-10 17:01:22 +0800 | [diff] [blame] | 722 | sector_t lo, hi; |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 723 | |
| 724 | |
| 725 | for (i = 0; i < total_slots; i++) { |
| 726 | memset(str, '\0', 64); |
| 727 | snprintf(str, 64, "bitmap%04d", i); |
| 728 | bm_lockres = lockres_init(mddev, str, NULL, 1); |
| 729 | if (!bm_lockres) |
| 730 | return -ENOMEM; |
Shaohua Li | 4ac7a65 | 2016-01-22 15:54:42 -0800 | [diff] [blame] | 731 | if (i == (cinfo->slot_number - 1)) { |
| 732 | lockres_free(bm_lockres); |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 733 | continue; |
Shaohua Li | 4ac7a65 | 2016-01-22 15:54:42 -0800 | [diff] [blame] | 734 | } |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 735 | |
| 736 | bm_lockres->flags |= DLM_LKF_NOQUEUE; |
| 737 | ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW); |
| 738 | if (ret == -EAGAIN) { |
| 739 | memset(bm_lockres->lksb.sb_lvbptr, '\0', LVB_SIZE); |
| 740 | s = read_resync_info(mddev, bm_lockres); |
| 741 | if (s) { |
| 742 | pr_info("%s:%d Resync[%llu..%llu] in progress on %d\n", |
| 743 | __func__, __LINE__, |
| 744 | (unsigned long long) s->lo, |
| 745 | (unsigned long long) s->hi, i); |
| 746 | spin_lock_irq(&cinfo->suspend_lock); |
| 747 | s->slot = i; |
| 748 | list_add(&s->list, &cinfo->suspend_list); |
| 749 | spin_unlock_irq(&cinfo->suspend_lock); |
| 750 | } |
| 751 | ret = 0; |
| 752 | lockres_free(bm_lockres); |
| 753 | continue; |
| 754 | } |
Guoqing Jiang | 6e6d9f2 | 2015-07-10 17:01:20 +0800 | [diff] [blame] | 755 | if (ret) { |
| 756 | lockres_free(bm_lockres); |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 757 | goto out; |
Guoqing Jiang | 6e6d9f2 | 2015-07-10 17:01:20 +0800 | [diff] [blame] | 758 | } |
Guoqing Jiang | abb9b22 | 2015-07-10 17:01:22 +0800 | [diff] [blame] | 759 | |
| 760 | /* Read the disk bitmap sb and check if it needs recovery */ |
| 761 | ret = bitmap_copy_from_slot(mddev, i, &lo, &hi, false); |
| 762 | if (ret) { |
| 763 | pr_warn("md-cluster: Could not gather bitmaps from slot %d", i); |
| 764 | lockres_free(bm_lockres); |
| 765 | continue; |
| 766 | } |
| 767 | if ((hi > 0) && (lo < mddev->recovery_cp)) { |
| 768 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
| 769 | mddev->recovery_cp = lo; |
| 770 | md_check_recovery(mddev); |
| 771 | } |
| 772 | |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 773 | dlm_unlock_sync(bm_lockres); |
| 774 | lockres_free(bm_lockres); |
| 775 | } |
| 776 | out: |
| 777 | return ret; |
| 778 | } |
| 779 | |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 780 | static int join(struct mddev *mddev, int nodes) |
| 781 | { |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 782 | struct md_cluster_info *cinfo; |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 783 | int ret, ops_rv; |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 784 | char str[64]; |
| 785 | |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 786 | cinfo = kzalloc(sizeof(struct md_cluster_info), GFP_KERNEL); |
| 787 | if (!cinfo) |
| 788 | return -ENOMEM; |
| 789 | |
Guoqing Jiang | 9e3072e | 2015-07-10 17:01:18 +0800 | [diff] [blame] | 790 | INIT_LIST_HEAD(&cinfo->suspend_list); |
| 791 | spin_lock_init(&cinfo->suspend_lock); |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 792 | init_completion(&cinfo->completion); |
Guoqing Jiang | eece075 | 2015-07-10 17:01:21 +0800 | [diff] [blame] | 793 | set_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state); |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 794 | init_waitqueue_head(&cinfo->wait); |
| 795 | mutex_init(&cinfo->recv_mutex); |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 796 | |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 797 | mddev->cluster_info = cinfo; |
| 798 | |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 799 | memset(str, 0, 64); |
Guoqing Jiang | b89f704 | 2015-07-10 16:54:02 +0800 | [diff] [blame] | 800 | sprintf(str, "%pU", mddev->uuid); |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 801 | ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name, |
| 802 | DLM_LSFL_FS, LVB_SIZE, |
| 803 | &md_ls_ops, mddev, &ops_rv, &cinfo->lockspace); |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 804 | if (ret) |
| 805 | goto err; |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 806 | wait_for_completion(&cinfo->completion); |
Guoqing Jiang | 8c58f02 | 2015-04-21 11:25:52 -0500 | [diff] [blame] | 807 | if (nodes < cinfo->slot_number) { |
| 808 | pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).", |
| 809 | cinfo->slot_number, nodes); |
Goldwyn Rodrigues | b97e9257 | 2014-06-06 11:50:56 -0500 | [diff] [blame] | 810 | ret = -ERANGE; |
| 811 | goto err; |
| 812 | } |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 813 | /* Initiate the communication resources */ |
| 814 | ret = -ENOMEM; |
| 815 | cinfo->recv_thread = md_register_thread(recv_daemon, mddev, "cluster_recv"); |
| 816 | if (!cinfo->recv_thread) { |
| 817 | pr_err("md-cluster: cannot allocate memory for recv_thread!\n"); |
| 818 | goto err; |
| 819 | } |
| 820 | cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1); |
| 821 | if (!cinfo->message_lockres) |
| 822 | goto err; |
| 823 | cinfo->token_lockres = lockres_init(mddev, "token", NULL, 0); |
| 824 | if (!cinfo->token_lockres) |
| 825 | goto err; |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 826 | cinfo->no_new_dev_lockres = lockres_init(mddev, "no-new-dev", NULL, 0); |
| 827 | if (!cinfo->no_new_dev_lockres) |
| 828 | goto err; |
| 829 | |
Guoqing Jiang | 1535212 | 2016-05-02 11:33:12 -0400 | [diff] [blame] | 830 | ret = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX); |
| 831 | if (ret) { |
| 832 | ret = -EAGAIN; |
| 833 | pr_err("md-cluster: can't join cluster to avoid lock issue\n"); |
| 834 | goto err; |
| 835 | } |
| 836 | cinfo->ack_lockres = lockres_init(mddev, "ack", ack_bast, 0); |
| 837 | if (!cinfo->ack_lockres) |
| 838 | goto err; |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 839 | /* get sync CR lock on ACK. */ |
| 840 | if (dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR)) |
| 841 | pr_err("md-cluster: failed to get a sync CR lock on ACK!(%d)\n", |
| 842 | ret); |
Guoqing Jiang | 1535212 | 2016-05-02 11:33:12 -0400 | [diff] [blame] | 843 | dlm_unlock_sync(cinfo->token_lockres); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 844 | /* get sync CR lock on no-new-dev. */ |
| 845 | if (dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR)) |
| 846 | pr_err("md-cluster: failed to get a sync CR lock on no-new-dev!(%d)\n", ret); |
| 847 | |
Goldwyn Rodrigues | 54519c5 | 2014-06-06 12:12:32 -0500 | [diff] [blame] | 848 | |
| 849 | pr_info("md-cluster: Joined cluster %s slot %d\n", str, cinfo->slot_number); |
| 850 | snprintf(str, 64, "bitmap%04d", cinfo->slot_number - 1); |
| 851 | cinfo->bitmap_lockres = lockres_init(mddev, str, NULL, 1); |
| 852 | if (!cinfo->bitmap_lockres) |
| 853 | goto err; |
| 854 | if (dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW)) { |
| 855 | pr_err("Failed to get bitmap lock\n"); |
| 856 | ret = -EINVAL; |
| 857 | goto err; |
| 858 | } |
| 859 | |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 860 | cinfo->resync_lockres = lockres_init(mddev, "resync", NULL, 0); |
| 861 | if (!cinfo->resync_lockres) |
| 862 | goto err; |
| 863 | |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 864 | return 0; |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 865 | err: |
Guoqing Jiang | 5b0fb33 | 2016-05-02 11:33:11 -0400 | [diff] [blame] | 866 | md_unregister_thread(&cinfo->recovery_thread); |
| 867 | md_unregister_thread(&cinfo->recv_thread); |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 868 | lockres_free(cinfo->message_lockres); |
| 869 | lockres_free(cinfo->token_lockres); |
| 870 | lockres_free(cinfo->ack_lockres); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 871 | lockres_free(cinfo->no_new_dev_lockres); |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 872 | lockres_free(cinfo->resync_lockres); |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 873 | lockres_free(cinfo->bitmap_lockres); |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 874 | if (cinfo->lockspace) |
| 875 | dlm_release_lockspace(cinfo->lockspace, 2); |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 876 | mddev->cluster_info = NULL; |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 877 | kfree(cinfo); |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 878 | return ret; |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 879 | } |
| 880 | |
Guoqing Jiang | 51e453a | 2016-05-04 02:17:09 -0400 | [diff] [blame] | 881 | static void load_bitmaps(struct mddev *mddev, int total_slots) |
| 882 | { |
| 883 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 884 | |
| 885 | /* load all the node's bitmap info for resync */ |
| 886 | if (gather_all_resync_info(mddev, total_slots)) |
| 887 | pr_err("md-cluster: failed to gather all resyn infos\n"); |
| 888 | set_bit(MD_CLUSTER_ALREADY_IN_CLUSTER, &cinfo->state); |
| 889 | /* wake up recv thread in case something need to be handled */ |
| 890 | if (test_and_clear_bit(MD_CLUSTER_PENDING_RECV_EVENT, &cinfo->state)) |
| 891 | md_wakeup_thread(cinfo->recv_thread); |
| 892 | } |
| 893 | |
Guoqing Jiang | 0999541 | 2015-10-01 00:09:18 +0800 | [diff] [blame] | 894 | static void resync_bitmap(struct mddev *mddev) |
| 895 | { |
| 896 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 897 | struct cluster_msg cmsg = {0}; |
| 898 | int err; |
| 899 | |
| 900 | cmsg.type = cpu_to_le32(BITMAP_NEEDS_SYNC); |
| 901 | err = sendmsg(cinfo, &cmsg); |
| 902 | if (err) |
| 903 | pr_err("%s:%d: failed to send BITMAP_NEEDS_SYNC message (%d)\n", |
| 904 | __func__, __LINE__, err); |
| 905 | } |
| 906 | |
Guoqing Jiang | f6a2dc6 | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 907 | static void unlock_all_bitmaps(struct mddev *mddev); |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 908 | static int leave(struct mddev *mddev) |
| 909 | { |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 910 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 911 | |
| 912 | if (!cinfo) |
| 913 | return 0; |
Guoqing Jiang | 0999541 | 2015-10-01 00:09:18 +0800 | [diff] [blame] | 914 | |
| 915 | /* BITMAP_NEEDS_SYNC message should be sent when node |
| 916 | * is leaving the cluster with dirty bitmap, also we |
| 917 | * can only deliver it when dlm connection is available */ |
| 918 | if (cinfo->slot_number > 0 && mddev->recovery_cp != MaxSector) |
| 919 | resync_bitmap(mddev); |
| 920 | |
Goldwyn Rodrigues | e94987d | 2014-06-07 00:45:22 -0500 | [diff] [blame] | 921 | md_unregister_thread(&cinfo->recovery_thread); |
Goldwyn Rodrigues | 4664680 | 2014-06-07 01:08:29 -0500 | [diff] [blame] | 922 | md_unregister_thread(&cinfo->recv_thread); |
| 923 | lockres_free(cinfo->message_lockres); |
| 924 | lockres_free(cinfo->token_lockres); |
| 925 | lockres_free(cinfo->ack_lockres); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 926 | lockres_free(cinfo->no_new_dev_lockres); |
Shaohua Li | 4ac7a65 | 2016-01-22 15:54:42 -0800 | [diff] [blame] | 927 | lockres_free(cinfo->resync_lockres); |
Goldwyn Rodrigues | 54519c5 | 2014-06-06 12:12:32 -0500 | [diff] [blame] | 928 | lockres_free(cinfo->bitmap_lockres); |
Guoqing Jiang | f6a2dc6 | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 929 | unlock_all_bitmaps(mddev); |
Goldwyn Rodrigues | c4ce867 | 2014-03-29 10:20:02 -0500 | [diff] [blame] | 930 | dlm_release_lockspace(cinfo->lockspace, 2); |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 931 | return 0; |
| 932 | } |
| 933 | |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 934 | /* slot_number(): Returns the MD slot number to use |
| 935 | * DLM starts the slot numbers from 1, wheras cluster-md |
| 936 | * wants the number to be from zero, so we deduct one |
| 937 | */ |
| 938 | static int slot_number(struct mddev *mddev) |
| 939 | { |
| 940 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 941 | |
| 942 | return cinfo->slot_number - 1; |
| 943 | } |
| 944 | |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 945 | /* |
| 946 | * Check if the communication is already locked, else lock the communication |
| 947 | * channel. |
| 948 | * If it is already locked, token is in EX mode, and hence lock_token() |
| 949 | * should not be called. |
| 950 | */ |
Goldwyn Rodrigues | 293467a | 2014-06-07 01:44:51 -0500 | [diff] [blame] | 951 | static int metadata_update_start(struct mddev *mddev) |
| 952 | { |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 953 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 954 | |
| 955 | wait_event(cinfo->wait, |
| 956 | !test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state) || |
| 957 | test_and_clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state)); |
| 958 | |
| 959 | /* If token is already locked, return 0 */ |
| 960 | if (cinfo->token_lockres->mode == DLM_LOCK_EX) |
| 961 | return 0; |
| 962 | |
| 963 | return lock_token(cinfo); |
Goldwyn Rodrigues | 293467a | 2014-06-07 01:44:51 -0500 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | static int metadata_update_finish(struct mddev *mddev) |
| 967 | { |
| 968 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 969 | struct cluster_msg cmsg; |
Goldwyn Rodrigues | 70bcecd | 2015-08-21 10:33:39 -0500 | [diff] [blame] | 970 | struct md_rdev *rdev; |
| 971 | int ret = 0; |
NeilBrown | ba2746b | 2015-10-16 13:48:35 +1100 | [diff] [blame] | 972 | int raid_slot = -1; |
Goldwyn Rodrigues | 293467a | 2014-06-07 01:44:51 -0500 | [diff] [blame] | 973 | |
| 974 | memset(&cmsg, 0, sizeof(cmsg)); |
| 975 | cmsg.type = cpu_to_le32(METADATA_UPDATED); |
Goldwyn Rodrigues | 70bcecd | 2015-08-21 10:33:39 -0500 | [diff] [blame] | 976 | /* Pick up a good active device number to send. |
| 977 | */ |
| 978 | rdev_for_each(rdev, mddev) |
| 979 | if (rdev->raid_disk > -1 && !test_bit(Faulty, &rdev->flags)) { |
NeilBrown | ba2746b | 2015-10-16 13:48:35 +1100 | [diff] [blame] | 980 | raid_slot = rdev->desc_nr; |
Goldwyn Rodrigues | 70bcecd | 2015-08-21 10:33:39 -0500 | [diff] [blame] | 981 | break; |
| 982 | } |
NeilBrown | ba2746b | 2015-10-16 13:48:35 +1100 | [diff] [blame] | 983 | if (raid_slot >= 0) { |
| 984 | cmsg.raid_slot = cpu_to_le32(raid_slot); |
Goldwyn Rodrigues | 70bcecd | 2015-08-21 10:33:39 -0500 | [diff] [blame] | 985 | ret = __sendmsg(cinfo, &cmsg); |
NeilBrown | ba2746b | 2015-10-16 13:48:35 +1100 | [diff] [blame] | 986 | } else |
Goldwyn Rodrigues | 70bcecd | 2015-08-21 10:33:39 -0500 | [diff] [blame] | 987 | pr_warn("md-cluster: No good device id found to send\n"); |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 988 | clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); |
Goldwyn Rodrigues | 293467a | 2014-06-07 01:44:51 -0500 | [diff] [blame] | 989 | unlock_comm(cinfo); |
| 990 | return ret; |
| 991 | } |
| 992 | |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 993 | static void metadata_update_cancel(struct mddev *mddev) |
Goldwyn Rodrigues | 293467a | 2014-06-07 01:44:51 -0500 | [diff] [blame] | 994 | { |
| 995 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 996 | clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 997 | unlock_comm(cinfo); |
Goldwyn Rodrigues | 293467a | 2014-06-07 01:44:51 -0500 | [diff] [blame] | 998 | } |
| 999 | |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 1000 | static int resync_start(struct mddev *mddev) |
| 1001 | { |
| 1002 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 1003 | return dlm_lock_sync(cinfo->resync_lockres, DLM_LOCK_EX); |
| 1004 | } |
| 1005 | |
Goldwyn Rodrigues | c40f341 | 2015-08-19 08:14:42 +1000 | [diff] [blame] | 1006 | static int resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi) |
Goldwyn Rodrigues | 965400e | 2014-06-07 02:16:58 -0500 | [diff] [blame] | 1007 | { |
| 1008 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Goldwyn Rodrigues | ac277c6 | 2015-12-21 10:50:59 +1100 | [diff] [blame] | 1009 | struct resync_info ri; |
Guoqing Jiang | aee177a | 2015-10-12 17:21:24 +0800 | [diff] [blame] | 1010 | struct cluster_msg cmsg = {0}; |
Goldwyn Rodrigues | 965400e | 2014-06-07 02:16:58 -0500 | [diff] [blame] | 1011 | |
Goldwyn Rodrigues | ac277c6 | 2015-12-21 10:50:59 +1100 | [diff] [blame] | 1012 | /* do not send zero again, if we have sent before */ |
| 1013 | if (hi == 0) { |
| 1014 | memcpy(&ri, cinfo->bitmap_lockres->lksb.sb_lvbptr, sizeof(struct resync_info)); |
| 1015 | if (le64_to_cpu(ri.hi) == 0) |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
NeilBrown | 30661b4 | 2015-10-19 15:44:00 +1100 | [diff] [blame] | 1019 | add_resync_info(cinfo->bitmap_lockres, lo, hi); |
Goldwyn Rodrigues | c40f341 | 2015-08-19 08:14:42 +1000 | [diff] [blame] | 1020 | /* Re-acquire the lock to refresh LVB */ |
| 1021 | dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW); |
Goldwyn Rodrigues | c40f341 | 2015-08-19 08:14:42 +1000 | [diff] [blame] | 1022 | cmsg.type = cpu_to_le32(RESYNCING); |
Goldwyn Rodrigues | 965400e | 2014-06-07 02:16:58 -0500 | [diff] [blame] | 1023 | cmsg.low = cpu_to_le64(lo); |
| 1024 | cmsg.high = cpu_to_le64(hi); |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 1025 | |
Goldwyn Rodrigues | 965400e | 2014-06-07 02:16:58 -0500 | [diff] [blame] | 1026 | return sendmsg(cinfo, &cmsg); |
| 1027 | } |
| 1028 | |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 1029 | static int resync_finish(struct mddev *mddev) |
| 1030 | { |
| 1031 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 1032 | dlm_unlock_sync(cinfo->resync_lockres); |
| 1033 | return resync_info_update(mddev, 0, 0); |
| 1034 | } |
| 1035 | |
Goldwyn Rodrigues | 90382ed | 2015-06-24 09:30:32 -0500 | [diff] [blame] | 1036 | static int area_resyncing(struct mddev *mddev, int direction, |
| 1037 | sector_t lo, sector_t hi) |
Goldwyn Rodrigues | 589a1c4 | 2014-06-07 02:39:37 -0500 | [diff] [blame] | 1038 | { |
| 1039 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 1040 | int ret = 0; |
| 1041 | struct suspend_info *s; |
| 1042 | |
Goldwyn Rodrigues | 90382ed | 2015-06-24 09:30:32 -0500 | [diff] [blame] | 1043 | if ((direction == READ) && |
| 1044 | test_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state)) |
| 1045 | return 1; |
| 1046 | |
Goldwyn Rodrigues | 589a1c4 | 2014-06-07 02:39:37 -0500 | [diff] [blame] | 1047 | spin_lock_irq(&cinfo->suspend_lock); |
| 1048 | if (list_empty(&cinfo->suspend_list)) |
| 1049 | goto out; |
| 1050 | list_for_each_entry(s, &cinfo->suspend_list, list) |
| 1051 | if (hi > s->lo && lo < s->hi) { |
| 1052 | ret = 1; |
| 1053 | break; |
| 1054 | } |
| 1055 | out: |
| 1056 | spin_unlock_irq(&cinfo->suspend_lock); |
| 1057 | return ret; |
| 1058 | } |
| 1059 | |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 1060 | /* add_new_disk() - initiates a disk add |
| 1061 | * However, if this fails before writing md_update_sb(), |
| 1062 | * add_new_disk_cancel() must be called to release token lock |
| 1063 | */ |
| 1064 | static int add_new_disk(struct mddev *mddev, struct md_rdev *rdev) |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1065 | { |
| 1066 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 1067 | struct cluster_msg cmsg; |
| 1068 | int ret = 0; |
| 1069 | struct mdp_superblock_1 *sb = page_address(rdev->sb_page); |
| 1070 | char *uuid = sb->device_uuid; |
| 1071 | |
| 1072 | memset(&cmsg, 0, sizeof(cmsg)); |
| 1073 | cmsg.type = cpu_to_le32(NEWDISK); |
| 1074 | memcpy(cmsg.uuid, uuid, 16); |
Guoqing Jiang | faeff83 | 2015-10-12 17:21:21 +0800 | [diff] [blame] | 1075 | cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1076 | lock_comm(cinfo); |
| 1077 | ret = __sendmsg(cinfo, &cmsg); |
| 1078 | if (ret) |
| 1079 | return ret; |
| 1080 | cinfo->no_new_dev_lockres->flags |= DLM_LKF_NOQUEUE; |
| 1081 | ret = dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_EX); |
| 1082 | cinfo->no_new_dev_lockres->flags &= ~DLM_LKF_NOQUEUE; |
| 1083 | /* Some node does not "see" the device */ |
| 1084 | if (ret == -EAGAIN) |
| 1085 | ret = -ENOENT; |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 1086 | if (ret) |
| 1087 | unlock_comm(cinfo); |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 1088 | else { |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1089 | dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR); |
Guoqing Jiang | e19508f | 2015-12-21 10:51:01 +1100 | [diff] [blame] | 1090 | /* Since MD_CHANGE_DEVS will be set in add_bound_rdev which |
| 1091 | * will run soon after add_new_disk, the below path will be |
| 1092 | * invoked: |
| 1093 | * md_wakeup_thread(mddev->thread) |
| 1094 | * -> conf->thread (raid1d) |
| 1095 | * -> md_check_recovery -> md_update_sb |
| 1096 | * -> metadata_update_start/finish |
| 1097 | * MD_CLUSTER_SEND_LOCKED_ALREADY will be cleared eventually. |
| 1098 | * |
| 1099 | * For other failure cases, metadata_update_cancel and |
| 1100 | * add_new_disk_cancel also clear below bit as well. |
| 1101 | * */ |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 1102 | set_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); |
| 1103 | wake_up(&cinfo->wait); |
| 1104 | } |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1105 | return ret; |
| 1106 | } |
| 1107 | |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 1108 | static void add_new_disk_cancel(struct mddev *mddev) |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1109 | { |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 1110 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Guoqing Jiang | 8b9277c | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 1111 | clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state); |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 1112 | unlock_comm(cinfo); |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1113 | } |
| 1114 | |
Goldwyn Rodrigues | fa8259d | 2015-03-02 10:55:49 -0600 | [diff] [blame] | 1115 | static int new_disk_ack(struct mddev *mddev, bool ack) |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1116 | { |
| 1117 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 1118 | |
Goldwyn Rodrigues | fa8259d | 2015-03-02 10:55:49 -0600 | [diff] [blame] | 1119 | if (!test_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state)) { |
| 1120 | pr_warn("md-cluster(%s): Spurious cluster confirmation\n", mdname(mddev)); |
| 1121 | return -EINVAL; |
| 1122 | } |
| 1123 | |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1124 | if (ack) |
| 1125 | dlm_unlock_sync(cinfo->no_new_dev_lockres); |
| 1126 | complete(&cinfo->newdisk_completion); |
Goldwyn Rodrigues | fa8259d | 2015-03-02 10:55:49 -0600 | [diff] [blame] | 1127 | return 0; |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1128 | } |
| 1129 | |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 1130 | static int remove_disk(struct mddev *mddev, struct md_rdev *rdev) |
| 1131 | { |
Guoqing Jiang | aee177a | 2015-10-12 17:21:24 +0800 | [diff] [blame] | 1132 | struct cluster_msg cmsg = {0}; |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 1133 | struct md_cluster_info *cinfo = mddev->cluster_info; |
Guoqing Jiang | faeff83 | 2015-10-12 17:21:21 +0800 | [diff] [blame] | 1134 | cmsg.type = cpu_to_le32(REMOVE); |
| 1135 | cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); |
Goldwyn Rodrigues | 54a8839 | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 1136 | return sendmsg(cinfo, &cmsg); |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 1137 | } |
| 1138 | |
Guoqing Jiang | f6a2dc6 | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 1139 | static int lock_all_bitmaps(struct mddev *mddev) |
| 1140 | { |
| 1141 | int slot, my_slot, ret, held = 1, i = 0; |
| 1142 | char str[64]; |
| 1143 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 1144 | |
| 1145 | cinfo->other_bitmap_lockres = kzalloc((mddev->bitmap_info.nodes - 1) * |
| 1146 | sizeof(struct dlm_lock_resource *), |
| 1147 | GFP_KERNEL); |
| 1148 | if (!cinfo->other_bitmap_lockres) { |
| 1149 | pr_err("md: can't alloc mem for other bitmap locks\n"); |
| 1150 | return 0; |
| 1151 | } |
| 1152 | |
| 1153 | my_slot = slot_number(mddev); |
| 1154 | for (slot = 0; slot < mddev->bitmap_info.nodes; slot++) { |
| 1155 | if (slot == my_slot) |
| 1156 | continue; |
| 1157 | |
| 1158 | memset(str, '\0', 64); |
| 1159 | snprintf(str, 64, "bitmap%04d", slot); |
| 1160 | cinfo->other_bitmap_lockres[i] = lockres_init(mddev, str, NULL, 1); |
| 1161 | if (!cinfo->other_bitmap_lockres[i]) |
| 1162 | return -ENOMEM; |
| 1163 | |
| 1164 | cinfo->other_bitmap_lockres[i]->flags |= DLM_LKF_NOQUEUE; |
| 1165 | ret = dlm_lock_sync(cinfo->other_bitmap_lockres[i], DLM_LOCK_PW); |
| 1166 | if (ret) |
| 1167 | held = -1; |
| 1168 | i++; |
| 1169 | } |
| 1170 | |
| 1171 | return held; |
| 1172 | } |
| 1173 | |
| 1174 | static void unlock_all_bitmaps(struct mddev *mddev) |
| 1175 | { |
| 1176 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 1177 | int i; |
| 1178 | |
| 1179 | /* release other node's bitmap lock if they are existed */ |
| 1180 | if (cinfo->other_bitmap_lockres) { |
| 1181 | for (i = 0; i < mddev->bitmap_info.nodes - 1; i++) { |
| 1182 | if (cinfo->other_bitmap_lockres[i]) { |
| 1183 | dlm_unlock_sync(cinfo->other_bitmap_lockres[i]); |
| 1184 | lockres_free(cinfo->other_bitmap_lockres[i]); |
| 1185 | } |
| 1186 | } |
| 1187 | kfree(cinfo->other_bitmap_lockres); |
| 1188 | } |
| 1189 | } |
| 1190 | |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 1191 | static int gather_bitmaps(struct md_rdev *rdev) |
| 1192 | { |
| 1193 | int sn, err; |
| 1194 | sector_t lo, hi; |
Guoqing Jiang | aee177a | 2015-10-12 17:21:24 +0800 | [diff] [blame] | 1195 | struct cluster_msg cmsg = {0}; |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 1196 | struct mddev *mddev = rdev->mddev; |
| 1197 | struct md_cluster_info *cinfo = mddev->cluster_info; |
| 1198 | |
Guoqing Jiang | faeff83 | 2015-10-12 17:21:21 +0800 | [diff] [blame] | 1199 | cmsg.type = cpu_to_le32(RE_ADD); |
| 1200 | cmsg.raid_slot = cpu_to_le32(rdev->desc_nr); |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 1201 | err = sendmsg(cinfo, &cmsg); |
| 1202 | if (err) |
| 1203 | goto out; |
| 1204 | |
| 1205 | for (sn = 0; sn < mddev->bitmap_info.nodes; sn++) { |
| 1206 | if (sn == (cinfo->slot_number - 1)) |
| 1207 | continue; |
| 1208 | err = bitmap_copy_from_slot(mddev, sn, &lo, &hi, false); |
| 1209 | if (err) { |
| 1210 | pr_warn("md-cluster: Could not gather bitmaps from slot %d", sn); |
| 1211 | goto out; |
| 1212 | } |
| 1213 | if ((hi > 0) && (lo < mddev->recovery_cp)) |
| 1214 | mddev->recovery_cp = lo; |
| 1215 | } |
| 1216 | out: |
| 1217 | return err; |
| 1218 | } |
| 1219 | |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 1220 | static struct md_cluster_operations cluster_ops = { |
| 1221 | .join = join, |
| 1222 | .leave = leave, |
Goldwyn Rodrigues | cf921cc | 2014-03-30 00:42:49 -0500 | [diff] [blame] | 1223 | .slot_number = slot_number, |
Goldwyn Rodrigues | c186b12 | 2015-09-30 13:20:35 -0500 | [diff] [blame] | 1224 | .resync_start = resync_start, |
| 1225 | .resync_finish = resync_finish, |
Goldwyn Rodrigues | 96ae923 | 2014-06-06 12:35:34 -0500 | [diff] [blame] | 1226 | .resync_info_update = resync_info_update, |
Goldwyn Rodrigues | 293467a | 2014-06-07 01:44:51 -0500 | [diff] [blame] | 1227 | .metadata_update_start = metadata_update_start, |
| 1228 | .metadata_update_finish = metadata_update_finish, |
| 1229 | .metadata_update_cancel = metadata_update_cancel, |
Goldwyn Rodrigues | 589a1c4 | 2014-06-07 02:39:37 -0500 | [diff] [blame] | 1230 | .area_resyncing = area_resyncing, |
Goldwyn Rodrigues | dbb64f8 | 2015-10-01 13:20:27 -0500 | [diff] [blame] | 1231 | .add_new_disk = add_new_disk, |
| 1232 | .add_new_disk_cancel = add_new_disk_cancel, |
Goldwyn Rodrigues | 1aee41f | 2014-10-29 18:51:31 -0500 | [diff] [blame] | 1233 | .new_disk_ack = new_disk_ack, |
Goldwyn Rodrigues | 88bcfef | 2015-04-14 10:44:44 -0500 | [diff] [blame] | 1234 | .remove_disk = remove_disk, |
Guoqing Jiang | 51e453a | 2016-05-04 02:17:09 -0400 | [diff] [blame] | 1235 | .load_bitmaps = load_bitmaps, |
Goldwyn Rodrigues | 97f6cd3 | 2015-04-14 10:45:42 -0500 | [diff] [blame] | 1236 | .gather_bitmaps = gather_bitmaps, |
Guoqing Jiang | f6a2dc6 | 2015-12-21 10:51:00 +1100 | [diff] [blame] | 1237 | .lock_all_bitmaps = lock_all_bitmaps, |
| 1238 | .unlock_all_bitmaps = unlock_all_bitmaps, |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 1239 | }; |
| 1240 | |
Goldwyn Rodrigues | 8e854e9 | 2014-03-07 11:21:15 -0600 | [diff] [blame] | 1241 | static int __init cluster_init(void) |
| 1242 | { |
| 1243 | pr_warn("md-cluster: EXPERIMENTAL. Use with caution\n"); |
| 1244 | pr_info("Registering Cluster MD functions\n"); |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 1245 | register_md_cluster_operations(&cluster_ops, THIS_MODULE); |
Goldwyn Rodrigues | 8e854e9 | 2014-03-07 11:21:15 -0600 | [diff] [blame] | 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | static void cluster_exit(void) |
| 1250 | { |
Goldwyn Rodrigues | edb39c9 | 2014-03-29 10:01:53 -0500 | [diff] [blame] | 1251 | unregister_md_cluster_operations(); |
Goldwyn Rodrigues | 8e854e9 | 2014-03-07 11:21:15 -0600 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | module_init(cluster_init); |
| 1255 | module_exit(cluster_exit); |
Guoqing Jiang | 86b5727 | 2015-10-12 17:21:25 +0800 | [diff] [blame] | 1256 | MODULE_AUTHOR("SUSE"); |
Goldwyn Rodrigues | 8e854e9 | 2014-03-07 11:21:15 -0600 | [diff] [blame] | 1257 | MODULE_LICENSE("GPL"); |
| 1258 | MODULE_DESCRIPTION("Clustering support for MD"); |