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