Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | drbd_receiver.c |
| 3 | |
| 4 | This file is part of DRBD by Philipp Reisner and Lars Ellenberg. |
| 5 | |
| 6 | Copyright (C) 2001-2008, LINBIT Information Technologies GmbH. |
| 7 | Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>. |
| 8 | Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>. |
| 9 | |
| 10 | drbd is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 2, or (at your option) |
| 13 | any later version. |
| 14 | |
| 15 | drbd is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with drbd; see the file COPYING. If not, write to |
| 22 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
| 24 | |
| 25 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 26 | #include <linux/module.h> |
| 27 | |
| 28 | #include <asm/uaccess.h> |
| 29 | #include <net/sock.h> |
| 30 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 31 | #include <linux/drbd.h> |
| 32 | #include <linux/fs.h> |
| 33 | #include <linux/file.h> |
| 34 | #include <linux/in.h> |
| 35 | #include <linux/mm.h> |
| 36 | #include <linux/memcontrol.h> |
| 37 | #include <linux/mm_inline.h> |
| 38 | #include <linux/slab.h> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 39 | #include <linux/pkt_sched.h> |
| 40 | #define __KERNEL_SYSCALLS__ |
| 41 | #include <linux/unistd.h> |
| 42 | #include <linux/vmalloc.h> |
| 43 | #include <linux/random.h> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 44 | #include <linux/string.h> |
| 45 | #include <linux/scatterlist.h> |
| 46 | #include "drbd_int.h" |
Andreas Gruenbacher | a3603a6 | 2011-05-30 11:47:37 +0200 | [diff] [blame] | 47 | #include "drbd_protocol.h" |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 48 | #include "drbd_req.h" |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 49 | #include "drbd_vli.h" |
| 50 | |
Lars Ellenberg | 20c68fd | 2014-04-28 18:43:25 +0200 | [diff] [blame] | 51 | #define PRO_FEATURES (FF_TRIM) |
| 52 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 53 | struct packet_info { |
| 54 | enum drbd_packet cmd; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 55 | unsigned int size; |
| 56 | unsigned int vnr; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 57 | void *data; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 58 | }; |
| 59 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 60 | enum finish_epoch { |
| 61 | FE_STILL_LIVE, |
| 62 | FE_DESTROYED, |
| 63 | FE_RECYCLED, |
| 64 | }; |
| 65 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 66 | static int drbd_do_features(struct drbd_connection *connection); |
| 67 | static int drbd_do_auth(struct drbd_connection *connection); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 68 | static int drbd_disconnected(struct drbd_peer_device *); |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 69 | static void conn_wait_active_ee_empty(struct drbd_connection *connection); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 70 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *, struct drbd_epoch *, enum epoch_event); |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 71 | static int e_end_block(struct drbd_work *, int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 72 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 73 | |
| 74 | #define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN) |
| 75 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 76 | /* |
| 77 | * some helper functions to deal with single linked page lists, |
| 78 | * page->private being our "next" pointer. |
| 79 | */ |
| 80 | |
| 81 | /* If at least n pages are linked at head, get n pages off. |
| 82 | * Otherwise, don't modify head, and return NULL. |
| 83 | * Locking is the responsibility of the caller. |
| 84 | */ |
| 85 | static struct page *page_chain_del(struct page **head, int n) |
| 86 | { |
| 87 | struct page *page; |
| 88 | struct page *tmp; |
| 89 | |
| 90 | BUG_ON(!n); |
| 91 | BUG_ON(!head); |
| 92 | |
| 93 | page = *head; |
Philipp Reisner | 23ce422 | 2010-05-20 13:35:31 +0200 | [diff] [blame] | 94 | |
| 95 | if (!page) |
| 96 | return NULL; |
| 97 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 98 | while (page) { |
| 99 | tmp = page_chain_next(page); |
| 100 | if (--n == 0) |
| 101 | break; /* found sufficient pages */ |
| 102 | if (tmp == NULL) |
| 103 | /* insufficient pages, don't use any of them. */ |
| 104 | return NULL; |
| 105 | page = tmp; |
| 106 | } |
| 107 | |
| 108 | /* add end of list marker for the returned list */ |
| 109 | set_page_private(page, 0); |
| 110 | /* actual return value, and adjustment of head */ |
| 111 | page = *head; |
| 112 | *head = tmp; |
| 113 | return page; |
| 114 | } |
| 115 | |
| 116 | /* may be used outside of locks to find the tail of a (usually short) |
| 117 | * "private" page chain, before adding it back to a global chain head |
| 118 | * with page_chain_add() under a spinlock. */ |
| 119 | static struct page *page_chain_tail(struct page *page, int *len) |
| 120 | { |
| 121 | struct page *tmp; |
| 122 | int i = 1; |
| 123 | while ((tmp = page_chain_next(page))) |
| 124 | ++i, page = tmp; |
| 125 | if (len) |
| 126 | *len = i; |
| 127 | return page; |
| 128 | } |
| 129 | |
| 130 | static int page_chain_free(struct page *page) |
| 131 | { |
| 132 | struct page *tmp; |
| 133 | int i = 0; |
| 134 | page_chain_for_each_safe(page, tmp) { |
| 135 | put_page(page); |
| 136 | ++i; |
| 137 | } |
| 138 | return i; |
| 139 | } |
| 140 | |
| 141 | static void page_chain_add(struct page **head, |
| 142 | struct page *chain_first, struct page *chain_last) |
| 143 | { |
| 144 | #if 1 |
| 145 | struct page *tmp; |
| 146 | tmp = page_chain_tail(chain_first, NULL); |
| 147 | BUG_ON(tmp != chain_last); |
| 148 | #endif |
| 149 | |
| 150 | /* add chain to head */ |
| 151 | set_page_private(chain_last, (unsigned long)*head); |
| 152 | *head = chain_first; |
| 153 | } |
| 154 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 155 | static struct page *__drbd_alloc_pages(struct drbd_device *device, |
Andreas Gruenbacher | 18c2d52 | 2011-04-07 21:08:50 +0200 | [diff] [blame] | 156 | unsigned int number) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 157 | { |
| 158 | struct page *page = NULL; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 159 | struct page *tmp = NULL; |
Andreas Gruenbacher | 18c2d52 | 2011-04-07 21:08:50 +0200 | [diff] [blame] | 160 | unsigned int i = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 161 | |
| 162 | /* Yes, testing drbd_pp_vacant outside the lock is racy. |
| 163 | * So what. It saves a spin_lock. */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 164 | if (drbd_pp_vacant >= number) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 165 | spin_lock(&drbd_pp_lock); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 166 | page = page_chain_del(&drbd_pp_pool, number); |
| 167 | if (page) |
| 168 | drbd_pp_vacant -= number; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 169 | spin_unlock(&drbd_pp_lock); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 170 | if (page) |
| 171 | return page; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 172 | } |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 173 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 174 | /* GFP_TRY, because we must not cause arbitrary write-out: in a DRBD |
| 175 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
| 176 | * which in turn might block on the other node at this very place. */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 177 | for (i = 0; i < number; i++) { |
| 178 | tmp = alloc_page(GFP_TRY); |
| 179 | if (!tmp) |
| 180 | break; |
| 181 | set_page_private(tmp, (unsigned long)page); |
| 182 | page = tmp; |
| 183 | } |
| 184 | |
| 185 | if (i == number) |
| 186 | return page; |
| 187 | |
| 188 | /* Not enough pages immediately available this time. |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 189 | * No need to jump around here, drbd_alloc_pages will retry this |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 190 | * function "soon". */ |
| 191 | if (page) { |
| 192 | tmp = page_chain_tail(page, NULL); |
| 193 | spin_lock(&drbd_pp_lock); |
| 194 | page_chain_add(&drbd_pp_pool, page, tmp); |
| 195 | drbd_pp_vacant += i; |
| 196 | spin_unlock(&drbd_pp_lock); |
| 197 | } |
| 198 | return NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 201 | static void reclaim_finished_net_peer_reqs(struct drbd_device *device, |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 202 | struct list_head *to_be_freed) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 203 | { |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 204 | struct drbd_peer_request *peer_req, *tmp; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 205 | |
| 206 | /* The EEs are always appended to the end of the list. Since |
| 207 | they are sent in order over the wire, they have to finish |
| 208 | in order. As soon as we see the first not finished we can |
| 209 | stop to examine the list... */ |
| 210 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 211 | list_for_each_entry_safe(peer_req, tmp, &device->net_ee, w.list) { |
Andreas Gruenbacher | 045417f | 2011-04-07 21:34:24 +0200 | [diff] [blame] | 212 | if (drbd_peer_req_has_active_page(peer_req)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 213 | break; |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 214 | list_move(&peer_req->w.list, to_be_freed); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 218 | static void drbd_kick_lo_and_reclaim_net(struct drbd_device *device) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 219 | { |
| 220 | LIST_HEAD(reclaimed); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 221 | struct drbd_peer_request *peer_req, *t; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 222 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 223 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 224 | reclaim_finished_net_peer_reqs(device, &reclaimed); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 225 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 226 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 227 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 228 | drbd_free_net_peer_req(device, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /** |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 232 | * drbd_alloc_pages() - Returns @number pages, retries forever (or until signalled) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 233 | * @device: DRBD device. |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 234 | * @number: number of pages requested |
| 235 | * @retry: whether to retry, if not enough pages are available right now |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 236 | * |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 237 | * Tries to allocate number pages, first from our own page pool, then from |
Lars Ellenberg | 0e49d7b | 2014-04-28 18:43:18 +0200 | [diff] [blame] | 238 | * the kernel. |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 239 | * Possibly retry until DRBD frees sufficient pages somewhere else. |
| 240 | * |
Lars Ellenberg | 0e49d7b | 2014-04-28 18:43:18 +0200 | [diff] [blame] | 241 | * If this allocation would exceed the max_buffers setting, we throttle |
| 242 | * allocation (schedule_timeout) to give the system some room to breathe. |
| 243 | * |
| 244 | * We do not use max-buffers as hard limit, because it could lead to |
| 245 | * congestion and further to a distributed deadlock during online-verify or |
| 246 | * (checksum based) resync, if the max-buffers, socket buffer sizes and |
| 247 | * resync-rate settings are mis-configured. |
| 248 | * |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 249 | * Returns a page chain linked via page->private. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 250 | */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 251 | struct page *drbd_alloc_pages(struct drbd_peer_device *peer_device, unsigned int number, |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 252 | bool retry) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 253 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 254 | struct drbd_device *device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 255 | struct page *page = NULL; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 256 | struct net_conf *nc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 257 | DEFINE_WAIT(wait); |
Lars Ellenberg | 0e49d7b | 2014-04-28 18:43:18 +0200 | [diff] [blame] | 258 | unsigned int mxb; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 259 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 260 | rcu_read_lock(); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 261 | nc = rcu_dereference(peer_device->connection->net_conf); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 262 | mxb = nc ? nc->max_buffers : 1000000; |
| 263 | rcu_read_unlock(); |
| 264 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 265 | if (atomic_read(&device->pp_in_use) < mxb) |
| 266 | page = __drbd_alloc_pages(device, number); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 267 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 268 | while (page == NULL) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 269 | prepare_to_wait(&drbd_pp_wait, &wait, TASK_INTERRUPTIBLE); |
| 270 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 271 | drbd_kick_lo_and_reclaim_net(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 272 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 273 | if (atomic_read(&device->pp_in_use) < mxb) { |
| 274 | page = __drbd_alloc_pages(device, number); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 275 | if (page) |
| 276 | break; |
| 277 | } |
| 278 | |
| 279 | if (!retry) |
| 280 | break; |
| 281 | |
| 282 | if (signal_pending(current)) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 283 | drbd_warn(device, "drbd_alloc_pages interrupted!\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 284 | break; |
| 285 | } |
| 286 | |
Lars Ellenberg | 0e49d7b | 2014-04-28 18:43:18 +0200 | [diff] [blame] | 287 | if (schedule_timeout(HZ/10) == 0) |
| 288 | mxb = UINT_MAX; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 289 | } |
| 290 | finish_wait(&drbd_pp_wait, &wait); |
| 291 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 292 | if (page) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 293 | atomic_add(number, &device->pp_in_use); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 294 | return page; |
| 295 | } |
| 296 | |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 297 | /* Must not be used from irq, as that may deadlock: see drbd_alloc_pages. |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 298 | * Is also used from inside an other spin_lock_irq(&resource->req_lock); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 299 | * Either links the page chain back to the global pool, |
| 300 | * or returns all pages to the system. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 301 | static void drbd_free_pages(struct drbd_device *device, struct page *page, int is_net) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 302 | { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 303 | atomic_t *a = is_net ? &device->pp_in_use_by_net : &device->pp_in_use; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 304 | int i; |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 305 | |
Lars Ellenberg | a73ff32 | 2012-06-25 19:15:38 +0200 | [diff] [blame] | 306 | if (page == NULL) |
| 307 | return; |
| 308 | |
Philipp Reisner | 81a5d60 | 2011-02-22 19:53:16 -0500 | [diff] [blame] | 309 | if (drbd_pp_vacant > (DRBD_MAX_BIO_SIZE/PAGE_SIZE) * minor_count) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 310 | i = page_chain_free(page); |
| 311 | else { |
| 312 | struct page *tmp; |
| 313 | tmp = page_chain_tail(page, &i); |
| 314 | spin_lock(&drbd_pp_lock); |
| 315 | page_chain_add(&drbd_pp_pool, page, tmp); |
| 316 | drbd_pp_vacant += i; |
| 317 | spin_unlock(&drbd_pp_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 318 | } |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 319 | i = atomic_sub_return(i, a); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 320 | if (i < 0) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 321 | drbd_warn(device, "ASSERTION FAILED: %s: %d < 0\n", |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 322 | is_net ? "pp_in_use_by_net" : "pp_in_use", i); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 323 | wake_up(&drbd_pp_wait); |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | You need to hold the req_lock: |
| 328 | _drbd_wait_ee_list_empty() |
| 329 | |
| 330 | You must not have the req_lock: |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 331 | drbd_free_peer_req() |
Andreas Gruenbacher | 0db5536 | 2011-04-06 16:09:15 +0200 | [diff] [blame] | 332 | drbd_alloc_peer_req() |
Andreas Gruenbacher | 7721f56 | 2011-04-06 17:14:02 +0200 | [diff] [blame] | 333 | drbd_free_peer_reqs() |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 334 | drbd_ee_fix_bhs() |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 335 | drbd_finish_peer_reqs() |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 336 | drbd_clear_done_ee() |
| 337 | drbd_wait_ee_list_empty() |
| 338 | */ |
| 339 | |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 340 | struct drbd_peer_request * |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 341 | drbd_alloc_peer_req(struct drbd_peer_device *peer_device, u64 id, sector_t sector, |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 342 | unsigned int data_size, bool has_payload, gfp_t gfp_mask) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 343 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 344 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 345 | struct drbd_peer_request *peer_req; |
Lars Ellenberg | a73ff32 | 2012-06-25 19:15:38 +0200 | [diff] [blame] | 346 | struct page *page = NULL; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 347 | unsigned nr_pages = (data_size + PAGE_SIZE -1) >> PAGE_SHIFT; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 348 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 349 | if (drbd_insert_fault(device, DRBD_FAULT_AL_EE)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 350 | return NULL; |
| 351 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 352 | peer_req = mempool_alloc(drbd_ee_mempool, gfp_mask & ~__GFP_HIGHMEM); |
| 353 | if (!peer_req) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 354 | if (!(gfp_mask & __GFP_NOWARN)) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 355 | drbd_err(device, "%s: allocation failed\n", __func__); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 356 | return NULL; |
| 357 | } |
| 358 | |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 359 | if (has_payload && data_size) { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 360 | page = drbd_alloc_pages(peer_device, nr_pages, (gfp_mask & __GFP_WAIT)); |
Lars Ellenberg | a73ff32 | 2012-06-25 19:15:38 +0200 | [diff] [blame] | 361 | if (!page) |
| 362 | goto fail; |
| 363 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 364 | |
Lars Ellenberg | c5a2c15 | 2014-05-08 10:08:05 +0200 | [diff] [blame] | 365 | memset(peer_req, 0, sizeof(*peer_req)); |
| 366 | INIT_LIST_HEAD(&peer_req->w.list); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 367 | drbd_clear_interval(&peer_req->i); |
| 368 | peer_req->i.size = data_size; |
| 369 | peer_req->i.sector = sector; |
Lars Ellenberg | c5a2c15 | 2014-05-08 10:08:05 +0200 | [diff] [blame] | 370 | peer_req->submit_jif = jiffies; |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 371 | peer_req->peer_device = peer_device; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 372 | peer_req->pages = page; |
Andreas Gruenbacher | 9a8e775 | 2011-01-11 14:04:09 +0100 | [diff] [blame] | 373 | /* |
| 374 | * The block_id is opaque to the receiver. It is not endianness |
| 375 | * converted, and sent back to the sender unchanged. |
| 376 | */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 377 | peer_req->block_id = id; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 378 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 379 | return peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 380 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 381 | fail: |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 382 | mempool_free(peer_req, drbd_ee_mempool); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 383 | return NULL; |
| 384 | } |
| 385 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 386 | void __drbd_free_peer_req(struct drbd_device *device, struct drbd_peer_request *peer_req, |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 387 | int is_net) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 388 | { |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 389 | might_sleep(); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 390 | if (peer_req->flags & EE_HAS_DIGEST) |
| 391 | kfree(peer_req->digest); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 392 | drbd_free_pages(device, peer_req->pages, is_net); |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 393 | D_ASSERT(device, atomic_read(&peer_req->pending_bios) == 0); |
| 394 | D_ASSERT(device, drbd_interval_empty(&peer_req->i)); |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 395 | if (!expect(!(peer_req->flags & EE_CALL_AL_COMPLETE_IO))) { |
| 396 | peer_req->flags &= ~EE_CALL_AL_COMPLETE_IO; |
| 397 | drbd_al_complete_io(device, &peer_req->i); |
| 398 | } |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 399 | mempool_free(peer_req, drbd_ee_mempool); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 402 | int drbd_free_peer_reqs(struct drbd_device *device, struct list_head *list) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 403 | { |
| 404 | LIST_HEAD(work_list); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 405 | struct drbd_peer_request *peer_req, *t; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 406 | int count = 0; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 407 | int is_net = list == &device->net_ee; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 408 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 409 | spin_lock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 410 | list_splice_init(list, &work_list); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 411 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 412 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 413 | list_for_each_entry_safe(peer_req, t, &work_list, w.list) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 414 | __drbd_free_peer_req(device, peer_req, is_net); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 415 | count++; |
| 416 | } |
| 417 | return count; |
| 418 | } |
| 419 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 420 | /* |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 421 | * See also comments in _req_mod(,BARRIER_ACKED) and receive_Barrier. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 422 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 423 | static int drbd_finish_peer_reqs(struct drbd_device *device) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 424 | { |
| 425 | LIST_HEAD(work_list); |
| 426 | LIST_HEAD(reclaimed); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 427 | struct drbd_peer_request *peer_req, *t; |
Andreas Gruenbacher | e2b3032 | 2011-03-16 17:16:12 +0100 | [diff] [blame] | 428 | int err = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 429 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 430 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 431 | reclaim_finished_net_peer_reqs(device, &reclaimed); |
| 432 | list_splice_init(&device->done_ee, &work_list); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 433 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 434 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 435 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 436 | drbd_free_net_peer_req(device, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 437 | |
| 438 | /* possible callbacks here: |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 439 | * e_end_block, and e_end_resync_block, e_send_superseded. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 440 | * all ignore the last argument. |
| 441 | */ |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 442 | list_for_each_entry_safe(peer_req, t, &work_list, w.list) { |
Andreas Gruenbacher | e2b3032 | 2011-03-16 17:16:12 +0100 | [diff] [blame] | 443 | int err2; |
| 444 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 445 | /* list_del not necessary, next/prev members not touched */ |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 446 | err2 = peer_req->w.cb(&peer_req->w, !!err); |
Andreas Gruenbacher | e2b3032 | 2011-03-16 17:16:12 +0100 | [diff] [blame] | 447 | if (!err) |
| 448 | err = err2; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 449 | drbd_free_peer_req(device, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 450 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 451 | wake_up(&device->ee_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 452 | |
Andreas Gruenbacher | e2b3032 | 2011-03-16 17:16:12 +0100 | [diff] [blame] | 453 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 456 | static void _drbd_wait_ee_list_empty(struct drbd_device *device, |
Andreas Gruenbacher | d4da153 | 2011-04-07 00:06:56 +0200 | [diff] [blame] | 457 | struct list_head *head) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 458 | { |
| 459 | DEFINE_WAIT(wait); |
| 460 | |
| 461 | /* avoids spin_lock/unlock |
| 462 | * and calling prepare_to_wait in the fast path */ |
| 463 | while (!list_empty(head)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 464 | prepare_to_wait(&device->ee_wait, &wait, TASK_UNINTERRUPTIBLE); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 465 | spin_unlock_irq(&device->resource->req_lock); |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 466 | io_schedule(); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 467 | finish_wait(&device->ee_wait, &wait); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 468 | spin_lock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 472 | static void drbd_wait_ee_list_empty(struct drbd_device *device, |
Andreas Gruenbacher | d4da153 | 2011-04-07 00:06:56 +0200 | [diff] [blame] | 473 | struct list_head *head) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 474 | { |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 475 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 476 | _drbd_wait_ee_list_empty(device, head); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 477 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 480 | static int drbd_recv_short(struct socket *sock, void *buf, size_t size, int flags) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 481 | { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 482 | struct kvec iov = { |
| 483 | .iov_base = buf, |
| 484 | .iov_len = size, |
| 485 | }; |
| 486 | struct msghdr msg = { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 487 | .msg_flags = (flags ? flags : MSG_WAITALL | MSG_NOSIGNAL) |
| 488 | }; |
Al Viro | f730c84 | 2014-02-08 21:07:38 -0500 | [diff] [blame] | 489 | return kernel_recvmsg(sock, &msg, &iov, 1, size, msg.msg_flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 492 | static int drbd_recv(struct drbd_connection *connection, void *buf, size_t size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 493 | { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 494 | int rv; |
| 495 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 496 | rv = drbd_recv_short(connection->data.socket, buf, size, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 497 | |
Philipp Reisner | dbd0820 | 2012-08-17 16:55:47 +0200 | [diff] [blame] | 498 | if (rv < 0) { |
| 499 | if (rv == -ECONNRESET) |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 500 | drbd_info(connection, "sock was reset by peer\n"); |
Philipp Reisner | dbd0820 | 2012-08-17 16:55:47 +0200 | [diff] [blame] | 501 | else if (rv != -ERESTARTSYS) |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 502 | drbd_err(connection, "sock_recvmsg returned %d\n", rv); |
Philipp Reisner | dbd0820 | 2012-08-17 16:55:47 +0200 | [diff] [blame] | 503 | } else if (rv == 0) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 504 | if (test_bit(DISCONNECT_SENT, &connection->flags)) { |
Philipp Reisner | b66623e | 2012-08-08 21:19:09 +0200 | [diff] [blame] | 505 | long t; |
| 506 | rcu_read_lock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 507 | t = rcu_dereference(connection->net_conf)->ping_timeo * HZ/10; |
Philipp Reisner | b66623e | 2012-08-08 21:19:09 +0200 | [diff] [blame] | 508 | rcu_read_unlock(); |
| 509 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 510 | t = wait_event_timeout(connection->ping_wait, connection->cstate < C_WF_REPORT_PARAMS, t); |
Philipp Reisner | b66623e | 2012-08-08 21:19:09 +0200 | [diff] [blame] | 511 | |
Philipp Reisner | 599377a | 2012-08-17 14:50:22 +0200 | [diff] [blame] | 512 | if (t) |
| 513 | goto out; |
| 514 | } |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 515 | drbd_info(connection, "sock was shut down by peer\n"); |
Philipp Reisner | 599377a | 2012-08-17 14:50:22 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 518 | if (rv != size) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 519 | conn_request_state(connection, NS(conn, C_BROKEN_PIPE), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 520 | |
Philipp Reisner | 599377a | 2012-08-17 14:50:22 +0200 | [diff] [blame] | 521 | out: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 522 | return rv; |
| 523 | } |
| 524 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 525 | static int drbd_recv_all(struct drbd_connection *connection, void *buf, size_t size) |
Andreas Gruenbacher | c696774 | 2011-03-17 17:15:20 +0100 | [diff] [blame] | 526 | { |
| 527 | int err; |
| 528 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 529 | err = drbd_recv(connection, buf, size); |
Andreas Gruenbacher | c696774 | 2011-03-17 17:15:20 +0100 | [diff] [blame] | 530 | if (err != size) { |
| 531 | if (err >= 0) |
| 532 | err = -EIO; |
| 533 | } else |
| 534 | err = 0; |
| 535 | return err; |
| 536 | } |
| 537 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 538 | static int drbd_recv_all_warn(struct drbd_connection *connection, void *buf, size_t size) |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 539 | { |
| 540 | int err; |
| 541 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 542 | err = drbd_recv_all(connection, buf, size); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 543 | if (err && !signal_pending(current)) |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 544 | drbd_warn(connection, "short read (expected size %d)\n", (int)size); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 545 | return err; |
| 546 | } |
| 547 | |
Lars Ellenberg | 5dbf167 | 2010-05-25 16:18:01 +0200 | [diff] [blame] | 548 | /* quoting tcp(7): |
| 549 | * On individual connections, the socket buffer size must be set prior to the |
| 550 | * listen(2) or connect(2) calls in order to have it take effect. |
| 551 | * This is our wrapper to do so. |
| 552 | */ |
| 553 | static void drbd_setbufsize(struct socket *sock, unsigned int snd, |
| 554 | unsigned int rcv) |
| 555 | { |
| 556 | /* open coded SO_SNDBUF, SO_RCVBUF */ |
| 557 | if (snd) { |
| 558 | sock->sk->sk_sndbuf = snd; |
| 559 | sock->sk->sk_userlocks |= SOCK_SNDBUF_LOCK; |
| 560 | } |
| 561 | if (rcv) { |
| 562 | sock->sk->sk_rcvbuf = rcv; |
| 563 | sock->sk->sk_userlocks |= SOCK_RCVBUF_LOCK; |
| 564 | } |
| 565 | } |
| 566 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 567 | static struct socket *drbd_try_connect(struct drbd_connection *connection) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 568 | { |
| 569 | const char *what; |
| 570 | struct socket *sock; |
| 571 | struct sockaddr_in6 src_in6; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 572 | struct sockaddr_in6 peer_in6; |
| 573 | struct net_conf *nc; |
| 574 | int err, peer_addr_len, my_addr_len; |
Andreas Gruenbacher | 69ef82d | 2011-05-11 14:34:35 +0200 | [diff] [blame] | 575 | int sndbuf_size, rcvbuf_size, connect_int; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 576 | int disconnect_on_error = 1; |
| 577 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 578 | rcu_read_lock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 579 | nc = rcu_dereference(connection->net_conf); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 580 | if (!nc) { |
| 581 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 582 | return NULL; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 583 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 584 | sndbuf_size = nc->sndbuf_size; |
| 585 | rcvbuf_size = nc->rcvbuf_size; |
Andreas Gruenbacher | 69ef82d | 2011-05-11 14:34:35 +0200 | [diff] [blame] | 586 | connect_int = nc->connect_int; |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 587 | rcu_read_unlock(); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 588 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 589 | my_addr_len = min_t(int, connection->my_addr_len, sizeof(src_in6)); |
| 590 | memcpy(&src_in6, &connection->my_addr, my_addr_len); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 591 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 592 | if (((struct sockaddr *)&connection->my_addr)->sa_family == AF_INET6) |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 593 | src_in6.sin6_port = 0; |
| 594 | else |
| 595 | ((struct sockaddr_in *)&src_in6)->sin_port = 0; /* AF_INET & AF_SCI */ |
| 596 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 597 | peer_addr_len = min_t(int, connection->peer_addr_len, sizeof(src_in6)); |
| 598 | memcpy(&peer_in6, &connection->peer_addr, peer_addr_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 599 | |
| 600 | what = "sock_create_kern"; |
Eric W. Biederman | eeb1bd5 | 2015-05-08 21:08:05 -0500 | [diff] [blame] | 601 | err = sock_create_kern(&init_net, ((struct sockaddr *)&src_in6)->sa_family, |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 602 | SOCK_STREAM, IPPROTO_TCP, &sock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 603 | if (err < 0) { |
| 604 | sock = NULL; |
| 605 | goto out; |
| 606 | } |
| 607 | |
| 608 | sock->sk->sk_rcvtimeo = |
Andreas Gruenbacher | 69ef82d | 2011-05-11 14:34:35 +0200 | [diff] [blame] | 609 | sock->sk->sk_sndtimeo = connect_int * HZ; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 610 | drbd_setbufsize(sock, sndbuf_size, rcvbuf_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 611 | |
| 612 | /* explicitly bind to the configured IP as source IP |
| 613 | * for the outgoing connections. |
| 614 | * This is needed for multihomed hosts and to be |
| 615 | * able to use lo: interfaces for drbd. |
| 616 | * Make sure to use 0 as port number, so linux selects |
| 617 | * a free one dynamically. |
| 618 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 619 | what = "bind before connect"; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 620 | err = sock->ops->bind(sock, (struct sockaddr *) &src_in6, my_addr_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 621 | if (err < 0) |
| 622 | goto out; |
| 623 | |
| 624 | /* connect may fail, peer not yet available. |
| 625 | * stay C_WF_CONNECTION, don't go Disconnecting! */ |
| 626 | disconnect_on_error = 0; |
| 627 | what = "connect"; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 628 | err = sock->ops->connect(sock, (struct sockaddr *) &peer_in6, peer_addr_len, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 629 | |
| 630 | out: |
| 631 | if (err < 0) { |
| 632 | if (sock) { |
| 633 | sock_release(sock); |
| 634 | sock = NULL; |
| 635 | } |
| 636 | switch (-err) { |
| 637 | /* timeout, busy, signal pending */ |
| 638 | case ETIMEDOUT: case EAGAIN: case EINPROGRESS: |
| 639 | case EINTR: case ERESTARTSYS: |
| 640 | /* peer not (yet) available, network problem */ |
| 641 | case ECONNREFUSED: case ENETUNREACH: |
| 642 | case EHOSTDOWN: case EHOSTUNREACH: |
| 643 | disconnect_on_error = 0; |
| 644 | break; |
| 645 | default: |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 646 | drbd_err(connection, "%s failed, err = %d\n", what, err); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 647 | } |
| 648 | if (disconnect_on_error) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 649 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 650 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 651 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 652 | return sock; |
| 653 | } |
| 654 | |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 655 | struct accept_wait_data { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 656 | struct drbd_connection *connection; |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 657 | struct socket *s_listen; |
| 658 | struct completion door_bell; |
| 659 | void (*original_sk_state_change)(struct sock *sk); |
| 660 | |
| 661 | }; |
| 662 | |
Andreas Gruenbacher | 715306f | 2012-08-10 17:00:30 +0200 | [diff] [blame] | 663 | static void drbd_incoming_connection(struct sock *sk) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 664 | { |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 665 | struct accept_wait_data *ad = sk->sk_user_data; |
Andreas Gruenbacher | 715306f | 2012-08-10 17:00:30 +0200 | [diff] [blame] | 666 | void (*state_change)(struct sock *sk); |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 667 | |
Andreas Gruenbacher | 715306f | 2012-08-10 17:00:30 +0200 | [diff] [blame] | 668 | state_change = ad->original_sk_state_change; |
| 669 | if (sk->sk_state == TCP_ESTABLISHED) |
| 670 | complete(&ad->door_bell); |
| 671 | state_change(sk); |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 672 | } |
| 673 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 674 | static int prepare_listen_socket(struct drbd_connection *connection, struct accept_wait_data *ad) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 675 | { |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 676 | int err, sndbuf_size, rcvbuf_size, my_addr_len; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 677 | struct sockaddr_in6 my_addr; |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 678 | struct socket *s_listen; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 679 | struct net_conf *nc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 680 | const char *what; |
| 681 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 682 | rcu_read_lock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 683 | nc = rcu_dereference(connection->net_conf); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 684 | if (!nc) { |
| 685 | rcu_read_unlock(); |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 686 | return -EIO; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 687 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 688 | sndbuf_size = nc->sndbuf_size; |
| 689 | rcvbuf_size = nc->rcvbuf_size; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 690 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 691 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 692 | my_addr_len = min_t(int, connection->my_addr_len, sizeof(struct sockaddr_in6)); |
| 693 | memcpy(&my_addr, &connection->my_addr, my_addr_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 694 | |
| 695 | what = "sock_create_kern"; |
Eric W. Biederman | eeb1bd5 | 2015-05-08 21:08:05 -0500 | [diff] [blame] | 696 | err = sock_create_kern(&init_net, ((struct sockaddr *)&my_addr)->sa_family, |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 697 | SOCK_STREAM, IPPROTO_TCP, &s_listen); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 698 | if (err) { |
| 699 | s_listen = NULL; |
| 700 | goto out; |
| 701 | } |
| 702 | |
Philipp Reisner | 9868365 | 2012-11-09 14:18:43 +0100 | [diff] [blame] | 703 | s_listen->sk->sk_reuse = SK_CAN_REUSE; /* SO_REUSEADDR */ |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 704 | drbd_setbufsize(s_listen, sndbuf_size, rcvbuf_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 705 | |
| 706 | what = "bind before listen"; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 707 | err = s_listen->ops->bind(s_listen, (struct sockaddr *)&my_addr, my_addr_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 708 | if (err < 0) |
| 709 | goto out; |
| 710 | |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 711 | ad->s_listen = s_listen; |
| 712 | write_lock_bh(&s_listen->sk->sk_callback_lock); |
| 713 | ad->original_sk_state_change = s_listen->sk->sk_state_change; |
Andreas Gruenbacher | 715306f | 2012-08-10 17:00:30 +0200 | [diff] [blame] | 714 | s_listen->sk->sk_state_change = drbd_incoming_connection; |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 715 | s_listen->sk->sk_user_data = ad; |
| 716 | write_unlock_bh(&s_listen->sk->sk_callback_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 717 | |
Philipp Reisner | 2820fd3 | 2012-07-12 10:22:48 +0200 | [diff] [blame] | 718 | what = "listen"; |
| 719 | err = s_listen->ops->listen(s_listen, 5); |
| 720 | if (err < 0) |
| 721 | goto out; |
| 722 | |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 723 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 724 | out: |
| 725 | if (s_listen) |
| 726 | sock_release(s_listen); |
| 727 | if (err < 0) { |
| 728 | if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 729 | drbd_err(connection, "%s failed, err = %d\n", what, err); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 730 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 731 | } |
| 732 | } |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 733 | |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 734 | return -EIO; |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 735 | } |
| 736 | |
Andreas Gruenbacher | 715306f | 2012-08-10 17:00:30 +0200 | [diff] [blame] | 737 | static void unregister_state_change(struct sock *sk, struct accept_wait_data *ad) |
| 738 | { |
| 739 | write_lock_bh(&sk->sk_callback_lock); |
| 740 | sk->sk_state_change = ad->original_sk_state_change; |
| 741 | sk->sk_user_data = NULL; |
| 742 | write_unlock_bh(&sk->sk_callback_lock); |
| 743 | } |
| 744 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 745 | static struct socket *drbd_wait_for_connect(struct drbd_connection *connection, struct accept_wait_data *ad) |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 746 | { |
| 747 | int timeo, connect_int, err = 0; |
| 748 | struct socket *s_estab = NULL; |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 749 | struct net_conf *nc; |
| 750 | |
| 751 | rcu_read_lock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 752 | nc = rcu_dereference(connection->net_conf); |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 753 | if (!nc) { |
| 754 | rcu_read_unlock(); |
| 755 | return NULL; |
| 756 | } |
| 757 | connect_int = nc->connect_int; |
| 758 | rcu_read_unlock(); |
| 759 | |
| 760 | timeo = connect_int * HZ; |
Akinobu Mita | 38b682b2 | 2013-04-29 16:21:31 -0700 | [diff] [blame] | 761 | /* 28.5% random jitter */ |
| 762 | timeo += (prandom_u32() & 1) ? timeo / 7 : -timeo / 7; |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 763 | |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 764 | err = wait_for_completion_interruptible_timeout(&ad->door_bell, timeo); |
| 765 | if (err <= 0) |
| 766 | return NULL; |
Philipp Reisner | 1f3e509 | 2012-07-12 11:08:34 +0200 | [diff] [blame] | 767 | |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 768 | err = kernel_accept(ad->s_listen, &s_estab, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 769 | if (err < 0) { |
| 770 | if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 771 | drbd_err(connection, "accept failed, err = %d\n", err); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 772 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 773 | } |
| 774 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 775 | |
Andreas Gruenbacher | 715306f | 2012-08-10 17:00:30 +0200 | [diff] [blame] | 776 | if (s_estab) |
| 777 | unregister_state_change(s_estab->sk, ad); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 778 | |
| 779 | return s_estab; |
| 780 | } |
| 781 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 782 | static int decode_header(struct drbd_connection *, void *, struct packet_info *); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 783 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 784 | static int send_first_packet(struct drbd_connection *connection, struct drbd_socket *sock, |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 785 | enum drbd_packet cmd) |
| 786 | { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 787 | if (!conn_prepare_command(connection, sock)) |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 788 | return -EIO; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 789 | return conn_send_command(connection, sock, cmd, 0, NULL, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 792 | static int receive_first_packet(struct drbd_connection *connection, struct socket *sock) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 793 | { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 794 | unsigned int header_size = drbd_header_size(connection); |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 795 | struct packet_info pi; |
Philipp Reisner | 4920e37 | 2014-03-18 14:40:13 +0100 | [diff] [blame] | 796 | struct net_conf *nc; |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 797 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 798 | |
Philipp Reisner | 4920e37 | 2014-03-18 14:40:13 +0100 | [diff] [blame] | 799 | rcu_read_lock(); |
| 800 | nc = rcu_dereference(connection->net_conf); |
| 801 | if (!nc) { |
| 802 | rcu_read_unlock(); |
| 803 | return -EIO; |
| 804 | } |
| 805 | sock->sk->sk_rcvtimeo = nc->ping_timeo * 4 * HZ / 10; |
| 806 | rcu_read_unlock(); |
| 807 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 808 | err = drbd_recv_short(sock, connection->data.rbuf, header_size, 0); |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 809 | if (err != header_size) { |
| 810 | if (err >= 0) |
| 811 | err = -EIO; |
| 812 | return err; |
| 813 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 814 | err = decode_header(connection, connection->data.rbuf, &pi); |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 815 | if (err) |
| 816 | return err; |
| 817 | return pi.cmd; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /** |
| 821 | * drbd_socket_okay() - Free the socket if its connection is not okay |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 822 | * @sock: pointer to the pointer to the socket. |
| 823 | */ |
Philipp Reisner | 5d0b17f | 2014-03-18 14:24:35 +0100 | [diff] [blame] | 824 | static bool drbd_socket_okay(struct socket **sock) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 825 | { |
| 826 | int rr; |
| 827 | char tb[4]; |
| 828 | |
| 829 | if (!*sock) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 830 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 831 | |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 832 | rr = drbd_recv_short(*sock, tb, 4, MSG_DONTWAIT | MSG_PEEK); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 833 | |
| 834 | if (rr > 0 || rr == -EAGAIN) { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 835 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 836 | } else { |
| 837 | sock_release(*sock); |
| 838 | *sock = NULL; |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 839 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 840 | } |
| 841 | } |
Philipp Reisner | 5d0b17f | 2014-03-18 14:24:35 +0100 | [diff] [blame] | 842 | |
| 843 | static bool connection_established(struct drbd_connection *connection, |
| 844 | struct socket **sock1, |
| 845 | struct socket **sock2) |
| 846 | { |
| 847 | struct net_conf *nc; |
| 848 | int timeout; |
| 849 | bool ok; |
| 850 | |
| 851 | if (!*sock1 || !*sock2) |
| 852 | return false; |
| 853 | |
| 854 | rcu_read_lock(); |
| 855 | nc = rcu_dereference(connection->net_conf); |
| 856 | timeout = (nc->sock_check_timeo ?: nc->ping_timeo) * HZ / 10; |
| 857 | rcu_read_unlock(); |
| 858 | schedule_timeout_interruptible(timeout); |
| 859 | |
| 860 | ok = drbd_socket_okay(sock1); |
| 861 | ok = drbd_socket_okay(sock2) && ok; |
| 862 | |
| 863 | return ok; |
| 864 | } |
| 865 | |
Philipp Reisner | 2325eb6 | 2011-03-15 16:56:18 +0100 | [diff] [blame] | 866 | /* Gets called if a connection is established, or if a new minor gets created |
| 867 | in a connection */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 868 | int drbd_connected(struct drbd_peer_device *peer_device) |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 869 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 870 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | 0829f5e | 2011-03-24 14:31:22 +0100 | [diff] [blame] | 871 | int err; |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 872 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 873 | atomic_set(&device->packet_seq, 0); |
| 874 | device->peer_seq = 0; |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 875 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 876 | device->state_mutex = peer_device->connection->agreed_pro_version < 100 ? |
| 877 | &peer_device->connection->cstate_mutex : |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 878 | &device->own_state_mutex; |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 879 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 880 | err = drbd_send_sync_param(peer_device); |
Andreas Gruenbacher | 0829f5e | 2011-03-24 14:31:22 +0100 | [diff] [blame] | 881 | if (!err) |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 882 | err = drbd_send_sizes(peer_device, 0, 0); |
Andreas Gruenbacher | 0829f5e | 2011-03-24 14:31:22 +0100 | [diff] [blame] | 883 | if (!err) |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 884 | err = drbd_send_uuids(peer_device); |
Andreas Gruenbacher | 0829f5e | 2011-03-24 14:31:22 +0100 | [diff] [blame] | 885 | if (!err) |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 886 | err = drbd_send_current_state(peer_device); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 887 | clear_bit(USE_DEGR_WFC_T, &device->flags); |
| 888 | clear_bit(RESIZE_PENDING, &device->flags); |
| 889 | atomic_set(&device->ap_in_flight, 0); |
| 890 | mod_timer(&device->request_timer, jiffies + HZ); /* just start it here. */ |
Andreas Gruenbacher | 0829f5e | 2011-03-24 14:31:22 +0100 | [diff] [blame] | 891 | return err; |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 892 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 893 | |
| 894 | /* |
| 895 | * return values: |
| 896 | * 1 yes, we have a valid connection |
| 897 | * 0 oops, did not work out, please try again |
| 898 | * -1 peer talks different language, |
| 899 | * no point in trying again, please go standalone. |
| 900 | * -2 We do not have a network config... |
| 901 | */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 902 | static int conn_connect(struct drbd_connection *connection) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 903 | { |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 904 | struct drbd_socket sock, msock; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 905 | struct drbd_peer_device *peer_device; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 906 | struct net_conf *nc; |
Philipp Reisner | 5d0b17f | 2014-03-18 14:24:35 +0100 | [diff] [blame] | 907 | int vnr, timeout, h; |
| 908 | bool discard_my_data, ok; |
Philipp Reisner | 197296f | 2012-03-26 16:47:11 +0200 | [diff] [blame] | 909 | enum drbd_state_rv rv; |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 910 | struct accept_wait_data ad = { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 911 | .connection = connection, |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 912 | .door_bell = COMPLETION_INITIALIZER_ONSTACK(ad.door_bell), |
| 913 | }; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 914 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 915 | clear_bit(DISCONNECT_SENT, &connection->flags); |
| 916 | if (conn_request_state(connection, NS(conn, C_WF_CONNECTION), CS_VERBOSE) < SS_SUCCESS) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 917 | return -2; |
| 918 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 919 | mutex_init(&sock.mutex); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 920 | sock.sbuf = connection->data.sbuf; |
| 921 | sock.rbuf = connection->data.rbuf; |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 922 | sock.socket = NULL; |
| 923 | mutex_init(&msock.mutex); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 924 | msock.sbuf = connection->meta.sbuf; |
| 925 | msock.rbuf = connection->meta.rbuf; |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 926 | msock.socket = NULL; |
| 927 | |
Andreas Gruenbacher | 0916e0e | 2011-03-21 14:10:15 +0100 | [diff] [blame] | 928 | /* Assume that the peer only understands protocol 80 until we know better. */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 929 | connection->agreed_pro_version = 80; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 930 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 931 | if (prepare_listen_socket(connection, &ad)) |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 932 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 933 | |
| 934 | do { |
Andreas Gruenbacher | 2bf8962 | 2011-03-28 16:33:12 +0200 | [diff] [blame] | 935 | struct socket *s; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 936 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 937 | s = drbd_try_connect(connection); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 938 | if (s) { |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 939 | if (!sock.socket) { |
| 940 | sock.socket = s; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 941 | send_first_packet(connection, &sock, P_INITIAL_DATA); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 942 | } else if (!msock.socket) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 943 | clear_bit(RESOLVE_CONFLICTS, &connection->flags); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 944 | msock.socket = s; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 945 | send_first_packet(connection, &msock, P_INITIAL_META); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 946 | } else { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 947 | drbd_err(connection, "Logic error in conn_connect()\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 948 | goto out_release_sockets; |
| 949 | } |
| 950 | } |
| 951 | |
Philipp Reisner | 5d0b17f | 2014-03-18 14:24:35 +0100 | [diff] [blame] | 952 | if (connection_established(connection, &sock.socket, &msock.socket)) |
| 953 | break; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 954 | |
| 955 | retry: |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 956 | s = drbd_wait_for_connect(connection, &ad); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 957 | if (s) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 958 | int fp = receive_first_packet(connection, s); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 959 | drbd_socket_okay(&sock.socket); |
| 960 | drbd_socket_okay(&msock.socket); |
Philipp Reisner | 92f1495 | 2012-08-01 11:41:01 +0200 | [diff] [blame] | 961 | switch (fp) { |
Andreas Gruenbacher | e5d6f33 | 2011-03-28 16:44:40 +0200 | [diff] [blame] | 962 | case P_INITIAL_DATA: |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 963 | if (sock.socket) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 964 | drbd_warn(connection, "initial packet S crossed\n"); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 965 | sock_release(sock.socket); |
Philipp Reisner | 80c6eed | 2012-08-01 14:53:39 +0200 | [diff] [blame] | 966 | sock.socket = s; |
| 967 | goto randomize; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 968 | } |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 969 | sock.socket = s; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 970 | break; |
Andreas Gruenbacher | e5d6f33 | 2011-03-28 16:44:40 +0200 | [diff] [blame] | 971 | case P_INITIAL_META: |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 972 | set_bit(RESOLVE_CONFLICTS, &connection->flags); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 973 | if (msock.socket) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 974 | drbd_warn(connection, "initial packet M crossed\n"); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 975 | sock_release(msock.socket); |
Philipp Reisner | 80c6eed | 2012-08-01 14:53:39 +0200 | [diff] [blame] | 976 | msock.socket = s; |
| 977 | goto randomize; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 978 | } |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 979 | msock.socket = s; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 980 | break; |
| 981 | default: |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 982 | drbd_warn(connection, "Error receiving initial packet\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 983 | sock_release(s); |
Philipp Reisner | 80c6eed | 2012-08-01 14:53:39 +0200 | [diff] [blame] | 984 | randomize: |
Akinobu Mita | 38b682b2 | 2013-04-29 16:21:31 -0700 | [diff] [blame] | 985 | if (prandom_u32() & 1) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 986 | goto retry; |
| 987 | } |
| 988 | } |
| 989 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 990 | if (connection->cstate <= C_DISCONNECTING) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 991 | goto out_release_sockets; |
| 992 | if (signal_pending(current)) { |
| 993 | flush_signals(current); |
| 994 | smp_rmb(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 995 | if (get_t_state(&connection->receiver) == EXITING) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 996 | goto out_release_sockets; |
| 997 | } |
| 998 | |
Philipp Reisner | 5d0b17f | 2014-03-18 14:24:35 +0100 | [diff] [blame] | 999 | ok = connection_established(connection, &sock.socket, &msock.socket); |
Philipp Reisner | b666dbf | 2012-07-26 14:12:59 +0200 | [diff] [blame] | 1000 | } while (!ok); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1001 | |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 1002 | if (ad.s_listen) |
| 1003 | sock_release(ad.s_listen); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1004 | |
Philipp Reisner | 9868365 | 2012-11-09 14:18:43 +0100 | [diff] [blame] | 1005 | sock.socket->sk->sk_reuse = SK_CAN_REUSE; /* SO_REUSEADDR */ |
| 1006 | msock.socket->sk->sk_reuse = SK_CAN_REUSE; /* SO_REUSEADDR */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1007 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 1008 | sock.socket->sk->sk_allocation = GFP_NOIO; |
| 1009 | msock.socket->sk->sk_allocation = GFP_NOIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1010 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 1011 | sock.socket->sk->sk_priority = TC_PRIO_INTERACTIVE_BULK; |
| 1012 | msock.socket->sk->sk_priority = TC_PRIO_INTERACTIVE; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1013 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1014 | /* NOT YET ... |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1015 | * sock.socket->sk->sk_sndtimeo = connection->net_conf->timeout*HZ/10; |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 1016 | * sock.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 1017 | * first set it to the P_CONNECTION_FEATURES timeout, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1018 | * which we set to 4x the configured ping_timeout. */ |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1019 | rcu_read_lock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1020 | nc = rcu_dereference(connection->net_conf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1021 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 1022 | sock.socket->sk->sk_sndtimeo = |
| 1023 | sock.socket->sk->sk_rcvtimeo = nc->ping_timeo*4*HZ/10; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1024 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 1025 | msock.socket->sk->sk_rcvtimeo = nc->ping_int*HZ; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1026 | timeout = nc->timeout * HZ / 10; |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 1027 | discard_my_data = nc->discard_my_data; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1028 | rcu_read_unlock(); |
| 1029 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 1030 | msock.socket->sk->sk_sndtimeo = timeout; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1031 | |
| 1032 | /* we don't want delays. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1033 | * we use TCP_CORK where appropriate, though */ |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 1034 | drbd_tcp_nodelay(sock.socket); |
| 1035 | drbd_tcp_nodelay(msock.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1036 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1037 | connection->data.socket = sock.socket; |
| 1038 | connection->meta.socket = msock.socket; |
| 1039 | connection->last_received = jiffies; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1040 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1041 | h = drbd_do_features(connection); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1042 | if (h <= 0) |
| 1043 | return h; |
| 1044 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1045 | if (connection->cram_hmac_tfm) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1046 | /* drbd_request_state(device, NS(conn, WFAuth)); */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1047 | switch (drbd_do_auth(connection)) { |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 1048 | case -1: |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 1049 | drbd_err(connection, "Authentication of peer failed\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1050 | return -1; |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 1051 | case 0: |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 1052 | drbd_err(connection, "Authentication of peer failed, trying again.\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 1053 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1057 | connection->data.socket->sk->sk_sndtimeo = timeout; |
| 1058 | connection->data.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1059 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1060 | if (drbd_send_protocol(connection) == -EOPNOTSUPP) |
Philipp Reisner | 7e2455c | 2010-04-22 14:50:23 +0200 | [diff] [blame] | 1061 | return -1; |
Philipp Reisner | 1e86ac4 | 2011-08-04 10:33:08 +0200 | [diff] [blame] | 1062 | |
Philipp Reisner | 3100774 | 2014-04-28 18:43:12 +0200 | [diff] [blame] | 1063 | /* Prevent a race between resync-handshake and |
| 1064 | * being promoted to Primary. |
| 1065 | * |
| 1066 | * Grab and release the state mutex, so we know that any current |
| 1067 | * drbd_set_role() is finished, and any incoming drbd_set_role |
| 1068 | * will see the STATE_SENT flag, and wait for it to be cleared. |
| 1069 | */ |
| 1070 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) |
| 1071 | mutex_lock(peer_device->device->state_mutex); |
| 1072 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1073 | set_bit(STATE_SENT, &connection->flags); |
Philipp Reisner | 197296f | 2012-03-26 16:47:11 +0200 | [diff] [blame] | 1074 | |
Philipp Reisner | 3100774 | 2014-04-28 18:43:12 +0200 | [diff] [blame] | 1075 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) |
| 1076 | mutex_unlock(peer_device->device->state_mutex); |
| 1077 | |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 1078 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1079 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 1080 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1081 | kref_get(&device->kref); |
Andreas Gruenbacher | 26ea8f9 | 2013-06-25 16:50:03 +0200 | [diff] [blame] | 1082 | rcu_read_unlock(); |
| 1083 | |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 1084 | if (discard_my_data) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1085 | set_bit(DISCARD_MY_DATA, &device->flags); |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 1086 | else |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1087 | clear_bit(DISCARD_MY_DATA, &device->flags); |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 1088 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1089 | drbd_connected(peer_device); |
Andreas Gruenbacher | 05a10ec | 2011-06-07 22:54:17 +0200 | [diff] [blame] | 1090 | kref_put(&device->kref, drbd_destroy_device); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 1091 | rcu_read_lock(); |
| 1092 | } |
| 1093 | rcu_read_unlock(); |
| 1094 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1095 | rv = conn_request_state(connection, NS(conn, C_WF_REPORT_PARAMS), CS_VERBOSE); |
| 1096 | if (rv < SS_SUCCESS || connection->cstate != C_WF_REPORT_PARAMS) { |
| 1097 | clear_bit(STATE_SENT, &connection->flags); |
Philipp Reisner | 1e86ac4 | 2011-08-04 10:33:08 +0200 | [diff] [blame] | 1098 | return 0; |
Philipp Reisner | a1096a6 | 2012-04-06 12:07:34 +0200 | [diff] [blame] | 1099 | } |
Philipp Reisner | 1e86ac4 | 2011-08-04 10:33:08 +0200 | [diff] [blame] | 1100 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1101 | drbd_thread_start(&connection->asender); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1102 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1103 | mutex_lock(&connection->resource->conf_update); |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 1104 | /* The discard_my_data flag is a single-shot modifier to the next |
| 1105 | * connection attempt, the handshake of which is now well underway. |
| 1106 | * No need for rcu style copying of the whole struct |
| 1107 | * just to clear a single value. */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1108 | connection->net_conf->discard_my_data = 0; |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1109 | mutex_unlock(&connection->resource->conf_update); |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 1110 | |
Philipp Reisner | d3fcb49 | 2011-04-13 14:46:05 -0700 | [diff] [blame] | 1111 | return h; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1112 | |
| 1113 | out_release_sockets: |
Philipp Reisner | 7a426fd | 2012-07-12 14:22:37 +0200 | [diff] [blame] | 1114 | if (ad.s_listen) |
| 1115 | sock_release(ad.s_listen); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 1116 | if (sock.socket) |
| 1117 | sock_release(sock.socket); |
| 1118 | if (msock.socket) |
| 1119 | sock_release(msock.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1120 | return -1; |
| 1121 | } |
| 1122 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1123 | static int decode_header(struct drbd_connection *connection, void *header, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1124 | { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1125 | unsigned int header_size = drbd_header_size(connection); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1126 | |
Andreas Gruenbacher | 0c8e36d | 2011-03-30 16:00:17 +0200 | [diff] [blame] | 1127 | if (header_size == sizeof(struct p_header100) && |
| 1128 | *(__be32 *)header == cpu_to_be32(DRBD_MAGIC_100)) { |
| 1129 | struct p_header100 *h = header; |
| 1130 | if (h->pad != 0) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 1131 | drbd_err(connection, "Header padding is not zero\n"); |
Andreas Gruenbacher | 0c8e36d | 2011-03-30 16:00:17 +0200 | [diff] [blame] | 1132 | return -EINVAL; |
| 1133 | } |
| 1134 | pi->vnr = be16_to_cpu(h->volume); |
| 1135 | pi->cmd = be16_to_cpu(h->command); |
| 1136 | pi->size = be32_to_cpu(h->length); |
| 1137 | } else if (header_size == sizeof(struct p_header95) && |
| 1138 | *(__be16 *)header == cpu_to_be16(DRBD_MAGIC_BIG)) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1139 | struct p_header95 *h = header; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1140 | pi->cmd = be16_to_cpu(h->command); |
Andreas Gruenbacher | b55d84b | 2011-03-22 13:17:47 +0100 | [diff] [blame] | 1141 | pi->size = be32_to_cpu(h->length); |
| 1142 | pi->vnr = 0; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1143 | } else if (header_size == sizeof(struct p_header80) && |
| 1144 | *(__be32 *)header == cpu_to_be32(DRBD_MAGIC)) { |
| 1145 | struct p_header80 *h = header; |
| 1146 | pi->cmd = be16_to_cpu(h->command); |
| 1147 | pi->size = be16_to_cpu(h->length); |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 1148 | pi->vnr = 0; |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 1149 | } else { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 1150 | drbd_err(connection, "Wrong magic value 0x%08x in protocol version %d\n", |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1151 | be32_to_cpu(*(__be32 *)header), |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1152 | connection->agreed_pro_version); |
Andreas Gruenbacher | 8172f3e | 2011-03-16 17:22:39 +0100 | [diff] [blame] | 1153 | return -EINVAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1154 | } |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1155 | pi->data = header + header_size; |
Andreas Gruenbacher | 8172f3e | 2011-03-16 17:22:39 +0100 | [diff] [blame] | 1156 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1159 | static int drbd_recv_header(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 1160 | { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1161 | void *buffer = connection->data.rbuf; |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 1162 | int err; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 1163 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1164 | err = drbd_recv_all_warn(connection, buffer, drbd_header_size(connection)); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1165 | if (err) |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 1166 | return err; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 1167 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1168 | err = decode_header(connection, buffer, pi); |
| 1169 | connection->last_received = jiffies; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1170 | |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 1171 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1174 | static void drbd_flush(struct drbd_connection *connection) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1175 | { |
| 1176 | int rv; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1177 | struct drbd_peer_device *peer_device; |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1178 | int vnr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1179 | |
Philipp Reisner | e952658 | 2013-11-22 15:53:41 +0100 | [diff] [blame] | 1180 | if (connection->resource->write_ordering >= WO_bdev_flush) { |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1181 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1182 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 1183 | struct drbd_device *device = peer_device->device; |
| 1184 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1185 | if (!get_ldev(device)) |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1186 | continue; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1187 | kref_get(&device->kref); |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1188 | rcu_read_unlock(); |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1189 | |
Lars Ellenberg | f418815 | 2014-05-05 23:05:47 +0200 | [diff] [blame] | 1190 | /* Right now, we have only this one synchronous code path |
| 1191 | * for flushes between request epochs. |
| 1192 | * We may want to make those asynchronous, |
| 1193 | * or at least parallelize the flushes to the volume devices. |
| 1194 | */ |
| 1195 | device->flush_jif = jiffies; |
| 1196 | set_bit(FLUSH_PENDING, &device->flags); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1197 | rv = blkdev_issue_flush(device->ldev->backing_bdev, |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1198 | GFP_NOIO, NULL); |
Lars Ellenberg | f418815 | 2014-05-05 23:05:47 +0200 | [diff] [blame] | 1199 | clear_bit(FLUSH_PENDING, &device->flags); |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1200 | if (rv) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1201 | drbd_info(device, "local disk flush failed with status %d\n", rv); |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1202 | /* would rather check on EOPNOTSUPP, but that is not reliable. |
| 1203 | * don't try again for ANY return value != 0 |
| 1204 | * if (rv == -EOPNOTSUPP) */ |
Philipp Reisner | 8fe39aa | 2013-11-22 13:22:13 +0100 | [diff] [blame] | 1205 | drbd_bump_write_ordering(connection->resource, NULL, WO_drain_io); |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1206 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1207 | put_ldev(device); |
Andreas Gruenbacher | 05a10ec | 2011-06-07 22:54:17 +0200 | [diff] [blame] | 1208 | kref_put(&device->kref, drbd_destroy_device); |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1209 | |
| 1210 | rcu_read_lock(); |
| 1211 | if (rv) |
| 1212 | break; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1213 | } |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1214 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1215 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * drbd_may_finish_epoch() - Applies an epoch_event to the epoch's state, eventually finishes it. |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1220 | * @device: DRBD device. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1221 | * @epoch: Epoch object. |
| 1222 | * @ev: Epoch event. |
| 1223 | */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1224 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connection, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1225 | struct drbd_epoch *epoch, |
| 1226 | enum epoch_event ev) |
| 1227 | { |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1228 | int epoch_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1229 | struct drbd_epoch *next_epoch; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1230 | enum finish_epoch rv = FE_STILL_LIVE; |
| 1231 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1232 | spin_lock(&connection->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1233 | do { |
| 1234 | next_epoch = NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1235 | |
| 1236 | epoch_size = atomic_read(&epoch->epoch_size); |
| 1237 | |
| 1238 | switch (ev & ~EV_CLEANUP) { |
| 1239 | case EV_PUT: |
| 1240 | atomic_dec(&epoch->active); |
| 1241 | break; |
| 1242 | case EV_GOT_BARRIER_NR: |
| 1243 | set_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1244 | break; |
| 1245 | case EV_BECAME_LAST: |
| 1246 | /* nothing to do*/ |
| 1247 | break; |
| 1248 | } |
| 1249 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1250 | if (epoch_size != 0 && |
| 1251 | atomic_read(&epoch->active) == 0 && |
Philipp Reisner | 80f9fd5 | 2011-07-18 15:45:15 +0200 | [diff] [blame] | 1252 | (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags) || ev & EV_CLEANUP)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1253 | if (!(ev & EV_CLEANUP)) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1254 | spin_unlock(&connection->epoch_lock); |
| 1255 | drbd_send_b_ack(epoch->connection, epoch->barrier_nr, epoch_size); |
| 1256 | spin_lock(&connection->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1257 | } |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1258 | #if 0 |
| 1259 | /* FIXME: dec unacked on connection, once we have |
| 1260 | * something to count pending connection packets in. */ |
Philipp Reisner | 80f9fd5 | 2011-07-18 15:45:15 +0200 | [diff] [blame] | 1261 | if (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags)) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1262 | dec_unacked(epoch->connection); |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1263 | #endif |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1264 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1265 | if (connection->current_epoch != epoch) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1266 | next_epoch = list_entry(epoch->list.next, struct drbd_epoch, list); |
| 1267 | list_del(&epoch->list); |
| 1268 | ev = EV_BECAME_LAST | (ev & EV_CLEANUP); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1269 | connection->epochs--; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1270 | kfree(epoch); |
| 1271 | |
| 1272 | if (rv == FE_STILL_LIVE) |
| 1273 | rv = FE_DESTROYED; |
| 1274 | } else { |
| 1275 | epoch->flags = 0; |
| 1276 | atomic_set(&epoch->epoch_size, 0); |
Uwe Kleine-König | 698f931 | 2010-07-02 20:41:51 +0200 | [diff] [blame] | 1277 | /* atomic_set(&epoch->active, 0); is already zero */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1278 | if (rv == FE_STILL_LIVE) |
| 1279 | rv = FE_RECYCLED; |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | if (!next_epoch) |
| 1284 | break; |
| 1285 | |
| 1286 | epoch = next_epoch; |
| 1287 | } while (1); |
| 1288 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1289 | spin_unlock(&connection->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1290 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1291 | return rv; |
| 1292 | } |
| 1293 | |
Philipp Reisner | 8fe39aa | 2013-11-22 13:22:13 +0100 | [diff] [blame] | 1294 | static enum write_ordering_e |
| 1295 | max_allowed_wo(struct drbd_backing_dev *bdev, enum write_ordering_e wo) |
| 1296 | { |
| 1297 | struct disk_conf *dc; |
| 1298 | |
| 1299 | dc = rcu_dereference(bdev->disk_conf); |
| 1300 | |
| 1301 | if (wo == WO_bdev_flush && !dc->disk_flushes) |
| 1302 | wo = WO_drain_io; |
| 1303 | if (wo == WO_drain_io && !dc->disk_drain) |
| 1304 | wo = WO_none; |
| 1305 | |
| 1306 | return wo; |
| 1307 | } |
| 1308 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1309 | /** |
| 1310 | * drbd_bump_write_ordering() - Fall back to an other write ordering method |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1311 | * @connection: DRBD connection. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1312 | * @wo: Write ordering method to try. |
| 1313 | */ |
Philipp Reisner | 8fe39aa | 2013-11-22 13:22:13 +0100 | [diff] [blame] | 1314 | void drbd_bump_write_ordering(struct drbd_resource *resource, struct drbd_backing_dev *bdev, |
| 1315 | enum write_ordering_e wo) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1316 | { |
Philipp Reisner | e952658 | 2013-11-22 15:53:41 +0100 | [diff] [blame] | 1317 | struct drbd_device *device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1318 | enum write_ordering_e pwo; |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1319 | int vnr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1320 | static char *write_ordering_str[] = { |
| 1321 | [WO_none] = "none", |
| 1322 | [WO_drain_io] = "drain", |
| 1323 | [WO_bdev_flush] = "flush", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1324 | }; |
| 1325 | |
Philipp Reisner | e952658 | 2013-11-22 15:53:41 +0100 | [diff] [blame] | 1326 | pwo = resource->write_ordering; |
Lars Ellenberg | 70df709 | 2013-12-20 11:17:02 +0100 | [diff] [blame] | 1327 | if (wo != WO_bdev_flush) |
| 1328 | wo = min(pwo, wo); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1329 | rcu_read_lock(); |
Philipp Reisner | e952658 | 2013-11-22 15:53:41 +0100 | [diff] [blame] | 1330 | idr_for_each_entry(&resource->devices, device, vnr) { |
Philipp Reisner | 8fe39aa | 2013-11-22 13:22:13 +0100 | [diff] [blame] | 1331 | if (get_ldev(device)) { |
| 1332 | wo = max_allowed_wo(device->ldev, wo); |
| 1333 | if (device->ldev == bdev) |
| 1334 | bdev = NULL; |
| 1335 | put_ldev(device); |
| 1336 | } |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1337 | } |
Philipp Reisner | 8fe39aa | 2013-11-22 13:22:13 +0100 | [diff] [blame] | 1338 | |
| 1339 | if (bdev) |
| 1340 | wo = max_allowed_wo(bdev, wo); |
| 1341 | |
Lars Ellenberg | 70df709 | 2013-12-20 11:17:02 +0100 | [diff] [blame] | 1342 | rcu_read_unlock(); |
| 1343 | |
Philipp Reisner | e952658 | 2013-11-22 15:53:41 +0100 | [diff] [blame] | 1344 | resource->write_ordering = wo; |
| 1345 | if (pwo != resource->write_ordering || wo == WO_bdev_flush) |
| 1346 | drbd_info(resource, "Method to ensure write ordering: %s\n", write_ordering_str[resource->write_ordering]); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | /** |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 1350 | * drbd_submit_peer_request() |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1351 | * @device: DRBD device. |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1352 | * @peer_req: peer request |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1353 | * @rw: flag field, see bio->bi_rw |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1354 | * |
| 1355 | * May spread the pages to multiple bios, |
| 1356 | * depending on bio_add_page restrictions. |
| 1357 | * |
| 1358 | * Returns 0 if all bios have been submitted, |
| 1359 | * -ENOMEM if we could not allocate enough bios, |
| 1360 | * -ENOSPC (any better suggestion?) if we have not been able to bio_add_page a |
| 1361 | * single page to an empty bio (which should never happen and likely indicates |
| 1362 | * that the lower level IO stack is in some way broken). This has been observed |
| 1363 | * on certain Xen deployments. |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1364 | */ |
| 1365 | /* TODO allocate from our own bio_set. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1366 | int drbd_submit_peer_request(struct drbd_device *device, |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 1367 | struct drbd_peer_request *peer_req, |
| 1368 | const unsigned rw, const int fault_type) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1369 | { |
| 1370 | struct bio *bios = NULL; |
| 1371 | struct bio *bio; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1372 | struct page *page = peer_req->pages; |
| 1373 | sector_t sector = peer_req->i.sector; |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1374 | unsigned data_size = peer_req->i.size; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1375 | unsigned n_bios = 0; |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1376 | unsigned nr_pages = (data_size + PAGE_SIZE -1) >> PAGE_SHIFT; |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1377 | int err = -ENOMEM; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1378 | |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1379 | if (peer_req->flags & EE_IS_TRIM_USE_ZEROOUT) { |
| 1380 | /* wait for all pending IO completions, before we start |
| 1381 | * zeroing things out. */ |
| 1382 | conn_wait_active_ee_empty(first_peer_device(device)->connection); |
Lars Ellenberg | 45d2933 | 2014-04-23 12:25:23 +0200 | [diff] [blame] | 1383 | /* add it to the active list now, |
| 1384 | * so we can find it to present it in debugfs */ |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 1385 | peer_req->submit_jif = jiffies; |
| 1386 | peer_req->flags |= EE_SUBMITTED; |
Lars Ellenberg | 45d2933 | 2014-04-23 12:25:23 +0200 | [diff] [blame] | 1387 | spin_lock_irq(&device->resource->req_lock); |
| 1388 | list_add_tail(&peer_req->w.list, &device->active_ee); |
| 1389 | spin_unlock_irq(&device->resource->req_lock); |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1390 | if (blkdev_issue_zeroout(device->ldev->backing_bdev, |
Martin K. Petersen | d93ba7a | 2015-01-20 20:06:30 -0500 | [diff] [blame] | 1391 | sector, data_size >> 9, GFP_NOIO, false)) |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1392 | peer_req->flags |= EE_WAS_ERROR; |
| 1393 | drbd_endio_write_sec_final(peer_req); |
| 1394 | return 0; |
| 1395 | } |
| 1396 | |
Lars Ellenberg | 54ed4ed | 2014-06-25 17:52:38 +0200 | [diff] [blame] | 1397 | /* Discards don't have any payload. |
| 1398 | * But the scsi layer still expects a bio_vec it can use internally, |
| 1399 | * see sd_setup_discard_cmnd() and blk_add_request_payload(). */ |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1400 | if (peer_req->flags & EE_IS_TRIM) |
Lars Ellenberg | 54ed4ed | 2014-06-25 17:52:38 +0200 | [diff] [blame] | 1401 | nr_pages = 1; |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1402 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1403 | /* In most cases, we will only need one bio. But in case the lower |
| 1404 | * level restrictions happen to be different at this offset on this |
| 1405 | * side than those of the sending peer, we may need to submit the |
Lars Ellenberg | 9476f39 | 2011-02-23 17:02:01 +0100 | [diff] [blame] | 1406 | * request in more than one bio. |
| 1407 | * |
| 1408 | * Plain bio_alloc is good enough here, this is no DRBD internally |
| 1409 | * generated bio, but a bio allocated on behalf of the peer. |
| 1410 | */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1411 | next_bio: |
| 1412 | bio = bio_alloc(GFP_NOIO, nr_pages); |
| 1413 | if (!bio) { |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1414 | drbd_err(device, "submit_ee: Allocation of a bio failed (nr_pages=%u)\n", nr_pages); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1415 | goto fail; |
| 1416 | } |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1417 | /* > peer_req->i.sector, unless this is the first bio */ |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1418 | bio->bi_iter.bi_sector = sector; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1419 | bio->bi_bdev = device->ldev->backing_bdev; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1420 | bio->bi_rw = rw; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1421 | bio->bi_private = peer_req; |
Andreas Gruenbacher | fcefa62 | 2011-02-17 16:46:59 +0100 | [diff] [blame] | 1422 | bio->bi_end_io = drbd_peer_request_endio; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1423 | |
| 1424 | bio->bi_next = bios; |
| 1425 | bios = bio; |
| 1426 | ++n_bios; |
| 1427 | |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1428 | if (rw & REQ_DISCARD) { |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1429 | bio->bi_iter.bi_size = data_size; |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1430 | goto submit; |
| 1431 | } |
| 1432 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1433 | page_chain_for_each(page) { |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1434 | unsigned len = min_t(unsigned, data_size, PAGE_SIZE); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1435 | if (!bio_add_page(bio, page, len, 0)) { |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1436 | /* A single page must always be possible! |
| 1437 | * But in case it fails anyways, |
| 1438 | * we deal with it, and complain (below). */ |
| 1439 | if (bio->bi_vcnt == 0) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1440 | drbd_err(device, |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1441 | "bio_add_page failed for len=%u, " |
| 1442 | "bi_vcnt=0 (bi_sector=%llu)\n", |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1443 | len, (uint64_t)bio->bi_iter.bi_sector); |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1444 | err = -ENOSPC; |
| 1445 | goto fail; |
| 1446 | } |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1447 | goto next_bio; |
| 1448 | } |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1449 | data_size -= len; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1450 | sector += len >> 9; |
| 1451 | --nr_pages; |
| 1452 | } |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1453 | D_ASSERT(device, data_size == 0); |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1454 | submit: |
| 1455 | D_ASSERT(device, page == NULL); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1456 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1457 | atomic_set(&peer_req->pending_bios, n_bios); |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 1458 | /* for debugfs: update timestamp, mark as submitted */ |
| 1459 | peer_req->submit_jif = jiffies; |
| 1460 | peer_req->flags |= EE_SUBMITTED; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1461 | do { |
| 1462 | bio = bios; |
| 1463 | bios = bios->bi_next; |
| 1464 | bio->bi_next = NULL; |
| 1465 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1466 | drbd_generic_make_request(device, fault_type, bio); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1467 | } while (bios); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1468 | return 0; |
| 1469 | |
| 1470 | fail: |
| 1471 | while (bios) { |
| 1472 | bio = bios; |
| 1473 | bios = bios->bi_next; |
| 1474 | bio_put(bio); |
| 1475 | } |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1476 | return err; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1479 | static void drbd_remove_epoch_entry_interval(struct drbd_device *device, |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1480 | struct drbd_peer_request *peer_req) |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1481 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1482 | struct drbd_interval *i = &peer_req->i; |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1483 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1484 | drbd_remove_interval(&device->write_requests, i); |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1485 | drbd_clear_interval(i); |
| 1486 | |
Andreas Gruenbacher | 6c852be | 2011-02-04 15:38:52 +0100 | [diff] [blame] | 1487 | /* Wake up any processes waiting for this peer request to complete. */ |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1488 | if (i->waiting) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1489 | wake_up(&device->misc_wait); |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1490 | } |
| 1491 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1492 | static void conn_wait_active_ee_empty(struct drbd_connection *connection) |
Philipp Reisner | 77fede5 | 2011-11-10 21:19:11 +0100 | [diff] [blame] | 1493 | { |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1494 | struct drbd_peer_device *peer_device; |
Philipp Reisner | 77fede5 | 2011-11-10 21:19:11 +0100 | [diff] [blame] | 1495 | int vnr; |
| 1496 | |
| 1497 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1498 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 1499 | struct drbd_device *device = peer_device->device; |
| 1500 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1501 | kref_get(&device->kref); |
Philipp Reisner | 77fede5 | 2011-11-10 21:19:11 +0100 | [diff] [blame] | 1502 | rcu_read_unlock(); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1503 | drbd_wait_ee_list_empty(device, &device->active_ee); |
Andreas Gruenbacher | 05a10ec | 2011-06-07 22:54:17 +0200 | [diff] [blame] | 1504 | kref_put(&device->kref, drbd_destroy_device); |
Philipp Reisner | 77fede5 | 2011-11-10 21:19:11 +0100 | [diff] [blame] | 1505 | rcu_read_lock(); |
| 1506 | } |
| 1507 | rcu_read_unlock(); |
| 1508 | } |
| 1509 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 1510 | static struct drbd_peer_device * |
| 1511 | conn_peer_device(struct drbd_connection *connection, int volume_number) |
| 1512 | { |
| 1513 | return idr_find(&connection->peer_devices, volume_number); |
| 1514 | } |
| 1515 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1516 | static int receive_Barrier(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1517 | { |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1518 | int rv; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1519 | struct p_barrier *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1520 | struct drbd_epoch *epoch; |
| 1521 | |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1522 | /* FIXME these are unacked on connection, |
| 1523 | * not a specific (peer)device. |
| 1524 | */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1525 | connection->current_epoch->barrier_nr = p->barrier; |
| 1526 | connection->current_epoch->connection = connection; |
| 1527 | rv = drbd_may_finish_epoch(connection, connection->current_epoch, EV_GOT_BARRIER_NR); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1528 | |
| 1529 | /* P_BARRIER_ACK may imply that the corresponding extent is dropped from |
| 1530 | * the activity log, which means it would not be resynced in case the |
| 1531 | * R_PRIMARY crashes now. |
| 1532 | * Therefore we must send the barrier_ack after the barrier request was |
| 1533 | * completed. */ |
Philipp Reisner | e952658 | 2013-11-22 15:53:41 +0100 | [diff] [blame] | 1534 | switch (connection->resource->write_ordering) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1535 | case WO_none: |
| 1536 | if (rv == FE_RECYCLED) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1537 | return 0; |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1538 | |
| 1539 | /* receiver context, in the writeout path of the other node. |
| 1540 | * avoid potential distributed deadlock */ |
| 1541 | epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO); |
| 1542 | if (epoch) |
| 1543 | break; |
| 1544 | else |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 1545 | drbd_warn(connection, "Allocation of an epoch failed, slowing down\n"); |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1546 | /* Fall through */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1547 | |
| 1548 | case WO_bdev_flush: |
| 1549 | case WO_drain_io: |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1550 | conn_wait_active_ee_empty(connection); |
| 1551 | drbd_flush(connection); |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1552 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1553 | if (atomic_read(&connection->current_epoch->epoch_size)) { |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1554 | epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO); |
| 1555 | if (epoch) |
| 1556 | break; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1559 | return 0; |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1560 | default: |
Philipp Reisner | e952658 | 2013-11-22 15:53:41 +0100 | [diff] [blame] | 1561 | drbd_err(connection, "Strangeness in connection->write_ordering %d\n", |
| 1562 | connection->resource->write_ordering); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1563 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | epoch->flags = 0; |
| 1567 | atomic_set(&epoch->epoch_size, 0); |
| 1568 | atomic_set(&epoch->active, 0); |
| 1569 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1570 | spin_lock(&connection->epoch_lock); |
| 1571 | if (atomic_read(&connection->current_epoch->epoch_size)) { |
| 1572 | list_add(&epoch->list, &connection->current_epoch->list); |
| 1573 | connection->current_epoch = epoch; |
| 1574 | connection->epochs++; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1575 | } else { |
| 1576 | /* The current_epoch got recycled while we allocated this one... */ |
| 1577 | kfree(epoch); |
| 1578 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1579 | spin_unlock(&connection->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1580 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1581 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | /* used from receive_RSDataReply (recv_resync_read) |
| 1585 | * and from receive_Data */ |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1586 | static struct drbd_peer_request * |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1587 | read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector, |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1588 | struct packet_info *pi) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1589 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1590 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1591 | const sector_t capacity = drbd_get_capacity(device->this_bdev); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1592 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1593 | struct page *page; |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1594 | int digest_size, err; |
| 1595 | unsigned int data_size = pi->size, ds; |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1596 | void *dig_in = peer_device->connection->int_dig_in; |
| 1597 | void *dig_vv = peer_device->connection->int_dig_vv; |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 1598 | unsigned long *data; |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1599 | struct p_trim *trim = (pi->cmd == P_TRIM) ? pi->data : NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1600 | |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1601 | digest_size = 0; |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1602 | if (!trim && peer_device->connection->peer_integrity_tfm) { |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1603 | digest_size = crypto_hash_digestsize(peer_device->connection->peer_integrity_tfm); |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 1604 | /* |
| 1605 | * FIXME: Receive the incoming digest into the receive buffer |
| 1606 | * here, together with its struct p_data? |
| 1607 | */ |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1608 | err = drbd_recv_all_warn(peer_device->connection, dig_in, digest_size); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1609 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1610 | return NULL; |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1611 | data_size -= digest_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1614 | if (trim) { |
| 1615 | D_ASSERT(peer_device, data_size == 0); |
| 1616 | data_size = be32_to_cpu(trim->size); |
| 1617 | } |
| 1618 | |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 1619 | if (!expect(IS_ALIGNED(data_size, 512))) |
| 1620 | return NULL; |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1621 | /* prepare for larger trim requests. */ |
| 1622 | if (!trim && !expect(data_size <= DRBD_MAX_BIO_SIZE)) |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 1623 | return NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1624 | |
Lars Ellenberg | 6666032 | 2010-04-06 12:15:04 +0200 | [diff] [blame] | 1625 | /* even though we trust out peer, |
| 1626 | * we sometimes have to double check. */ |
| 1627 | if (sector + (data_size>>9) > capacity) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1628 | drbd_err(device, "request from peer beyond end of local disk: " |
Lars Ellenberg | fdda654 | 2011-01-24 15:11:01 +0100 | [diff] [blame] | 1629 | "capacity: %llus < sector: %llus + size: %u\n", |
Lars Ellenberg | 6666032 | 2010-04-06 12:15:04 +0200 | [diff] [blame] | 1630 | (unsigned long long)capacity, |
| 1631 | (unsigned long long)sector, data_size); |
| 1632 | return NULL; |
| 1633 | } |
| 1634 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1635 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD |
| 1636 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
| 1637 | * which in turn might block on the other node at this very place. */ |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1638 | peer_req = drbd_alloc_peer_req(peer_device, id, sector, data_size, trim == NULL, GFP_NOIO); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1639 | if (!peer_req) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1640 | return NULL; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1641 | |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 1642 | peer_req->flags |= EE_WRITE; |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1643 | if (trim) |
Lars Ellenberg | 81a3537 | 2012-07-30 09:00:54 +0200 | [diff] [blame] | 1644 | return peer_req; |
Lars Ellenberg | a73ff32 | 2012-06-25 19:15:38 +0200 | [diff] [blame] | 1645 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1646 | ds = data_size; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1647 | page = peer_req->pages; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1648 | page_chain_for_each(page) { |
| 1649 | unsigned len = min_t(int, ds, PAGE_SIZE); |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 1650 | data = kmap(page); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1651 | err = drbd_recv_all_warn(peer_device->connection, data, len); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1652 | if (drbd_insert_fault(device, DRBD_FAULT_RECEIVE)) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1653 | drbd_err(device, "Fault injection: Corrupting data on receive\n"); |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 1654 | data[0] = data[0] ^ (unsigned long)-1; |
| 1655 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1656 | kunmap(page); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1657 | if (err) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1658 | drbd_free_peer_req(device, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1659 | return NULL; |
| 1660 | } |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1661 | ds -= len; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1664 | if (digest_size) { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1665 | drbd_csum_ee(peer_device->connection->peer_integrity_tfm, peer_req, dig_vv); |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1666 | if (memcmp(dig_in, dig_vv, digest_size)) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1667 | drbd_err(device, "Digest integrity check FAILED: %llus +%u\n", |
Lars Ellenberg | 470be44 | 2010-11-10 10:36:52 +0100 | [diff] [blame] | 1668 | (unsigned long long)sector, data_size); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1669 | drbd_free_peer_req(device, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1670 | return NULL; |
| 1671 | } |
| 1672 | } |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1673 | device->recv_cnt += data_size >> 9; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1674 | return peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | /* drbd_drain_block() just takes a data block |
| 1678 | * out of the socket input buffer, and discards it. |
| 1679 | */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1680 | static int drbd_drain_block(struct drbd_peer_device *peer_device, int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1681 | { |
| 1682 | struct page *page; |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1683 | int err = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1684 | void *data; |
| 1685 | |
Lars Ellenberg | c3470cd | 2010-04-01 16:57:19 +0200 | [diff] [blame] | 1686 | if (!data_size) |
Andreas Gruenbacher | fc5be83 | 2011-03-16 17:50:50 +0100 | [diff] [blame] | 1687 | return 0; |
Lars Ellenberg | c3470cd | 2010-04-01 16:57:19 +0200 | [diff] [blame] | 1688 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1689 | page = drbd_alloc_pages(peer_device, 1, 1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1690 | |
| 1691 | data = kmap(page); |
| 1692 | while (data_size) { |
Andreas Gruenbacher | fc5be83 | 2011-03-16 17:50:50 +0100 | [diff] [blame] | 1693 | unsigned int len = min_t(int, data_size, PAGE_SIZE); |
| 1694 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1695 | err = drbd_recv_all_warn(peer_device->connection, data, len); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1696 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1697 | break; |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1698 | data_size -= len; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1699 | } |
| 1700 | kunmap(page); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1701 | drbd_free_pages(peer_device->device, page, 0); |
Andreas Gruenbacher | fc5be83 | 2011-03-16 17:50:50 +0100 | [diff] [blame] | 1702 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1705 | static int recv_dless_read(struct drbd_peer_device *peer_device, struct drbd_request *req, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1706 | sector_t sector, int data_size) |
| 1707 | { |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1708 | struct bio_vec bvec; |
| 1709 | struct bvec_iter iter; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1710 | struct bio *bio; |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1711 | int digest_size, err, expect; |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1712 | void *dig_in = peer_device->connection->int_dig_in; |
| 1713 | void *dig_vv = peer_device->connection->int_dig_vv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1714 | |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1715 | digest_size = 0; |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1716 | if (peer_device->connection->peer_integrity_tfm) { |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1717 | digest_size = crypto_hash_digestsize(peer_device->connection->peer_integrity_tfm); |
| 1718 | err = drbd_recv_all_warn(peer_device->connection, dig_in, digest_size); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1719 | if (err) |
| 1720 | return err; |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1721 | data_size -= digest_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1724 | /* optimistically update recv_cnt. if receiving fails below, |
| 1725 | * we disconnect anyways, and counters will be reset. */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1726 | peer_device->device->recv_cnt += data_size>>9; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1727 | |
| 1728 | bio = req->master_bio; |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1729 | D_ASSERT(peer_device->device, sector == bio->bi_iter.bi_sector); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1730 | |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1731 | bio_for_each_segment(bvec, bio, iter) { |
| 1732 | void *mapped = kmap(bvec.bv_page) + bvec.bv_offset; |
| 1733 | expect = min_t(int, data_size, bvec.bv_len); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1734 | err = drbd_recv_all_warn(peer_device->connection, mapped, expect); |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 1735 | kunmap(bvec.bv_page); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1736 | if (err) |
| 1737 | return err; |
| 1738 | data_size -= expect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1741 | if (digest_size) { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1742 | drbd_csum_bio(peer_device->connection->peer_integrity_tfm, bio, dig_vv); |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 1743 | if (memcmp(dig_in, dig_vv, digest_size)) { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1744 | drbd_err(peer_device, "Digest integrity check FAILED. Broken NICs?\n"); |
Andreas Gruenbacher | 28284ce | 2011-03-16 17:54:02 +0100 | [diff] [blame] | 1745 | return -EINVAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1746 | } |
| 1747 | } |
| 1748 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1749 | D_ASSERT(peer_device->device, data_size == 0); |
Andreas Gruenbacher | 28284ce | 2011-03-16 17:54:02 +0100 | [diff] [blame] | 1750 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 1753 | /* |
| 1754 | * e_end_resync_block() is called in asender context via |
| 1755 | * drbd_finish_peer_reqs(). |
| 1756 | */ |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1757 | static int e_end_resync_block(struct drbd_work *w, int unused) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1758 | { |
Andreas Gruenbacher | 8050e6d | 2011-02-18 16:12:48 +0100 | [diff] [blame] | 1759 | struct drbd_peer_request *peer_req = |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1760 | container_of(w, struct drbd_peer_request, w); |
| 1761 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
| 1762 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1763 | sector_t sector = peer_req->i.sector; |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1764 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1765 | |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 1766 | D_ASSERT(device, drbd_interval_empty(&peer_req->i)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1767 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1768 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1769 | drbd_set_in_sync(device, sector, peer_req->i.size); |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1770 | err = drbd_send_ack(peer_device, P_RS_WRITE_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1771 | } else { |
| 1772 | /* Record failure to sync */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1773 | drbd_rs_failed_io(device, sector, peer_req->i.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1774 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1775 | err = drbd_send_ack(peer_device, P_NEG_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1776 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1777 | dec_unacked(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1778 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1779 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1782 | static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t sector, |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1783 | struct packet_info *pi) __releases(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1784 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1785 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1786 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1787 | |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1788 | peer_req = read_in_block(peer_device, ID_SYNCER, sector, pi); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1789 | if (!peer_req) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1790 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1791 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1792 | dec_rs_pending(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1793 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1794 | inc_unacked(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1795 | /* corresponding dec_unacked() in e_end_resync_block() |
| 1796 | * respective _drbd_clear_done_ee */ |
| 1797 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1798 | peer_req->w.cb = e_end_resync_block; |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 1799 | peer_req->submit_jif = jiffies; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1800 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1801 | spin_lock_irq(&device->resource->req_lock); |
Lars Ellenberg | b9ed708 | 2014-04-23 12:15:35 +0200 | [diff] [blame] | 1802 | list_add_tail(&peer_req->w.list, &device->sync_ee); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1803 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1804 | |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1805 | atomic_add(pi->size >> 9, &device->rs_sect_ev); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1806 | if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0) |
Andreas Gruenbacher | e1c1b0f | 2011-03-16 17:58:27 +0100 | [diff] [blame] | 1807 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1808 | |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1809 | /* don't care for the reason here */ |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1810 | drbd_err(device, "submit failed, triggering re-connect\n"); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1811 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1812 | list_del(&peer_req->w.list); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1813 | spin_unlock_irq(&device->resource->req_lock); |
Lars Ellenberg | 22cc37a | 2010-09-14 20:40:41 +0200 | [diff] [blame] | 1814 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1815 | drbd_free_peer_req(device, peer_req); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1816 | fail: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1817 | put_ldev(device); |
Andreas Gruenbacher | e1c1b0f | 2011-03-16 17:58:27 +0100 | [diff] [blame] | 1818 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1821 | static struct drbd_request * |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1822 | find_request(struct drbd_device *device, struct rb_root *root, u64 id, |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 1823 | sector_t sector, bool missing_ok, const char *func) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1824 | { |
| 1825 | struct drbd_request *req; |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1826 | |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 1827 | /* Request object according to our peer */ |
| 1828 | req = (struct drbd_request *)(unsigned long)id; |
Andreas Gruenbacher | 5e47226 | 2011-01-27 14:42:51 +0100 | [diff] [blame] | 1829 | if (drbd_contains_interval(root, sector, &req->i) && req->i.local) |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1830 | return req; |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 1831 | if (!missing_ok) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1832 | drbd_err(device, "%s: failed to find request 0x%lx, sector %llus\n", func, |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 1833 | (unsigned long)id, (unsigned long long)sector); |
| 1834 | } |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1835 | return NULL; |
| 1836 | } |
| 1837 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1838 | static int receive_DataReply(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1839 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 1840 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1841 | struct drbd_device *device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1842 | struct drbd_request *req; |
| 1843 | sector_t sector; |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1844 | int err; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1845 | struct p_data *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1846 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 1847 | peer_device = conn_peer_device(connection, pi->vnr); |
| 1848 | if (!peer_device) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1849 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 1850 | device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1851 | |
| 1852 | sector = be64_to_cpu(p->sector); |
| 1853 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1854 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1855 | req = find_request(device, &device->read_requests, p->block_id, sector, false, __func__); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1856 | spin_unlock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 1857 | if (unlikely(!req)) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1858 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1859 | |
Bart Van Assche | 24c4830 | 2011-05-21 18:32:29 +0200 | [diff] [blame] | 1860 | /* hlist_del(&req->collision) is done in _req_may_be_done, to avoid |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1861 | * special casing it there for the various failure cases. |
| 1862 | * still no race with drbd_fail_pending_reads */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1863 | err = recv_dless_read(peer_device, req, sector, pi->size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1864 | if (!err) |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 1865 | req_mod(req, DATA_RECEIVED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1866 | /* else: nothing. handled from drbd_disconnect... |
| 1867 | * I don't think we may complete this just yet |
| 1868 | * in case we are "on-disconnect: freeze" */ |
| 1869 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1870 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1873 | static int receive_RSDataReply(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1874 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 1875 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1876 | struct drbd_device *device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1877 | sector_t sector; |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1878 | int err; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1879 | struct p_data *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1880 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 1881 | peer_device = conn_peer_device(connection, pi->vnr); |
| 1882 | if (!peer_device) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1883 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 1884 | device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1885 | |
| 1886 | sector = be64_to_cpu(p->sector); |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 1887 | D_ASSERT(device, p->block_id == ID_SYNCER); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1888 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1889 | if (get_ldev(device)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1890 | /* data is submitted to disk within recv_resync_read. |
| 1891 | * corresponding put_ldev done below on error, |
Andreas Gruenbacher | fcefa62 | 2011-02-17 16:46:59 +0100 | [diff] [blame] | 1892 | * or in drbd_peer_request_endio. */ |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 1893 | err = recv_resync_read(peer_device, sector, pi); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1894 | } else { |
| 1895 | if (__ratelimit(&drbd_ratelimit_state)) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1896 | drbd_err(device, "Can not write resync data to local disk.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1897 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1898 | err = drbd_drain_block(peer_device, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1899 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 1900 | drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1903 | atomic_add(pi->size >> 9, &device->rs_sect_in); |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 1904 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1905 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1908 | static void restart_conflicting_writes(struct drbd_device *device, |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1909 | sector_t sector, int size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1910 | { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1911 | struct drbd_interval *i; |
| 1912 | struct drbd_request *req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1913 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1914 | drbd_for_each_overlap(i, &device->write_requests, sector, size) { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1915 | if (!i->local) |
| 1916 | continue; |
| 1917 | req = container_of(i, struct drbd_request, i); |
| 1918 | if (req->rq_state & RQ_LOCAL_PENDING || |
| 1919 | !(req->rq_state & RQ_POSTPONED)) |
| 1920 | continue; |
Lars Ellenberg | 2312f0b3 | 2011-11-24 10:36:25 +0100 | [diff] [blame] | 1921 | /* as it is RQ_POSTPONED, this will cause it to |
| 1922 | * be queued on the retry workqueue. */ |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 1923 | __req_mod(req, CONFLICT_RESOLVED, NULL); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1924 | } |
| 1925 | } |
| 1926 | |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 1927 | /* |
| 1928 | * e_end_block() is called in asender context via drbd_finish_peer_reqs(). |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1929 | */ |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1930 | static int e_end_block(struct drbd_work *w, int cancel) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1931 | { |
Andreas Gruenbacher | 8050e6d | 2011-02-18 16:12:48 +0100 | [diff] [blame] | 1932 | struct drbd_peer_request *peer_req = |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1933 | container_of(w, struct drbd_peer_request, w); |
| 1934 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
| 1935 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1936 | sector_t sector = peer_req->i.sector; |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1937 | int err = 0, pcmd; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1938 | |
Philipp Reisner | 303d144 | 2011-04-13 16:24:47 -0700 | [diff] [blame] | 1939 | if (peer_req->flags & EE_SEND_WRITE_ACK) { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1940 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1941 | pcmd = (device->state.conn >= C_SYNC_SOURCE && |
| 1942 | device->state.conn <= C_PAUSED_SYNC_T && |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1943 | peer_req->flags & EE_MAY_SET_IN_SYNC) ? |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1944 | P_RS_WRITE_ACK : P_WRITE_ACK; |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1945 | err = drbd_send_ack(peer_device, pcmd, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1946 | if (pcmd == P_RS_WRITE_ACK) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1947 | drbd_set_in_sync(device, sector, peer_req->i.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1948 | } else { |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1949 | err = drbd_send_ack(peer_device, P_NEG_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1950 | /* we expect it to be marked out of sync anyways... |
| 1951 | * maybe assert this? */ |
| 1952 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1953 | dec_unacked(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1954 | } |
Lars Ellenberg | 08d0dab | 2014-03-20 11:19:22 +0100 | [diff] [blame] | 1955 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1956 | /* we delete from the conflict detection hash _after_ we sent out the |
| 1957 | * P_WRITE_ACK / P_NEG_ACK, to get the sequence number right. */ |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 1958 | if (peer_req->flags & EE_IN_INTERVAL_TREE) { |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1959 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 1960 | D_ASSERT(device, !drbd_interval_empty(&peer_req->i)); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1961 | drbd_remove_epoch_entry_interval(device, peer_req); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1962 | if (peer_req->flags & EE_RESTART_REQUESTS) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1963 | restart_conflicting_writes(device, sector, peer_req->i.size); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1964 | spin_unlock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | bb3bfe9 | 2011-01-21 15:59:23 +0100 | [diff] [blame] | 1965 | } else |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 1966 | D_ASSERT(device, drbd_interval_empty(&peer_req->i)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1967 | |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 1968 | drbd_may_finish_epoch(first_peer_device(device)->connection, peer_req->epoch, EV_PUT + (cancel ? EV_CLEANUP : 0)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1969 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1970 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1973 | static int e_send_ack(struct drbd_work *w, enum drbd_packet ack) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1974 | { |
Andreas Gruenbacher | 8050e6d | 2011-02-18 16:12:48 +0100 | [diff] [blame] | 1975 | struct drbd_peer_request *peer_req = |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1976 | container_of(w, struct drbd_peer_request, w); |
| 1977 | struct drbd_peer_device *peer_device = peer_req->peer_device; |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1978 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1979 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1980 | err = drbd_send_ack(peer_device, ack, peer_req); |
| 1981 | dec_unacked(peer_device->device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1982 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1983 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 1986 | static int e_send_superseded(struct drbd_work *w, int unused) |
Philipp Reisner | b6a370ba | 2012-02-19 01:27:53 +0100 | [diff] [blame] | 1987 | { |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1988 | return e_send_ack(w, P_SUPERSEDED); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1989 | } |
Philipp Reisner | b6a370ba | 2012-02-19 01:27:53 +0100 | [diff] [blame] | 1990 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1991 | static int e_send_retry_write(struct drbd_work *w, int unused) |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1992 | { |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1993 | struct drbd_peer_request *peer_req = |
| 1994 | container_of(w, struct drbd_peer_request, w); |
| 1995 | struct drbd_connection *connection = peer_req->peer_device->connection; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1996 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 1997 | return e_send_ack(w, connection->agreed_pro_version >= 100 ? |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 1998 | P_RETRY_WRITE : P_SUPERSEDED); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1999 | } |
| 2000 | |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 2001 | static bool seq_greater(u32 a, u32 b) |
| 2002 | { |
| 2003 | /* |
| 2004 | * We assume 32-bit wrap-around here. |
| 2005 | * For 24-bit wrap-around, we would have to shift: |
| 2006 | * a <<= 8; b <<= 8; |
| 2007 | */ |
| 2008 | return (s32)a - (s32)b > 0; |
| 2009 | } |
| 2010 | |
| 2011 | static u32 seq_max(u32 a, u32 b) |
| 2012 | { |
| 2013 | return seq_greater(a, b) ? a : b; |
| 2014 | } |
| 2015 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2016 | static void update_peer_seq(struct drbd_peer_device *peer_device, unsigned int peer_seq) |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 2017 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2018 | struct drbd_device *device = peer_device->device; |
Lars Ellenberg | 3c13b68 | 2011-02-23 16:10:01 +0100 | [diff] [blame] | 2019 | unsigned int newest_peer_seq; |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 2020 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2021 | if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2022 | spin_lock(&device->peer_seq_lock); |
| 2023 | newest_peer_seq = seq_max(device->peer_seq, peer_seq); |
| 2024 | device->peer_seq = newest_peer_seq; |
| 2025 | spin_unlock(&device->peer_seq_lock); |
| 2026 | /* wake up only if we actually changed device->peer_seq */ |
Lars Ellenberg | 3c13b68 | 2011-02-23 16:10:01 +0100 | [diff] [blame] | 2027 | if (peer_seq == newest_peer_seq) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2028 | wake_up(&device->seq_wait); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2029 | } |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 2030 | } |
| 2031 | |
Lars Ellenberg | d93f630 | 2012-03-26 15:49:13 +0200 | [diff] [blame] | 2032 | static inline int overlaps(sector_t s1, int l1, sector_t s2, int l2) |
| 2033 | { |
| 2034 | return !((s1 + (l1>>9) <= s2) || (s1 >= s2 + (l2>>9))); |
| 2035 | } |
| 2036 | |
| 2037 | /* maybe change sync_ee into interval trees as well? */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2038 | static bool overlapping_resync_write(struct drbd_device *device, struct drbd_peer_request *peer_req) |
Lars Ellenberg | d93f630 | 2012-03-26 15:49:13 +0200 | [diff] [blame] | 2039 | { |
| 2040 | struct drbd_peer_request *rs_req; |
Philipp Reisner | b6a370ba | 2012-02-19 01:27:53 +0100 | [diff] [blame] | 2041 | bool rv = 0; |
| 2042 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2043 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2044 | list_for_each_entry(rs_req, &device->sync_ee, w.list) { |
Lars Ellenberg | d93f630 | 2012-03-26 15:49:13 +0200 | [diff] [blame] | 2045 | if (overlaps(peer_req->i.sector, peer_req->i.size, |
| 2046 | rs_req->i.sector, rs_req->i.size)) { |
Philipp Reisner | b6a370ba | 2012-02-19 01:27:53 +0100 | [diff] [blame] | 2047 | rv = 1; |
| 2048 | break; |
| 2049 | } |
| 2050 | } |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2051 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b6a370ba | 2012-02-19 01:27:53 +0100 | [diff] [blame] | 2052 | |
| 2053 | return rv; |
| 2054 | } |
| 2055 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2056 | /* Called from receive_Data. |
| 2057 | * Synchronize packets on sock with packets on msock. |
| 2058 | * |
| 2059 | * This is here so even when a P_DATA packet traveling via sock overtook an Ack |
| 2060 | * packet traveling on msock, they are still processed in the order they have |
| 2061 | * been sent. |
| 2062 | * |
| 2063 | * Note: we don't care for Ack packets overtaking P_DATA packets. |
| 2064 | * |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2065 | * In case packet_seq is larger than device->peer_seq number, there are |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2066 | * outstanding packets on the msock. We wait for them to arrive. |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2067 | * In case we are the logically next packet, we update device->peer_seq |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2068 | * ourselves. Correctly handles 32bit wrap around. |
| 2069 | * |
| 2070 | * Assume we have a 10 GBit connection, that is about 1<<30 byte per second, |
| 2071 | * about 1<<21 sectors per second. So "worst" case, we have 1<<3 == 8 seconds |
| 2072 | * for the 24bit wrap (historical atomic_t guarantee on some archs), and we have |
| 2073 | * 1<<9 == 512 seconds aka ages for the 32bit wrap around... |
| 2074 | * |
| 2075 | * returns 0 if we may process the packet, |
| 2076 | * -ERESTARTSYS if we were interrupted (by disconnect signal). */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2077 | static int wait_for_and_update_peer_seq(struct drbd_peer_device *peer_device, const u32 peer_seq) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2078 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2079 | struct drbd_device *device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2080 | DEFINE_WAIT(wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2081 | long timeout; |
Philipp Reisner | b874d23 | 2013-10-23 10:59:16 +0200 | [diff] [blame] | 2082 | int ret = 0, tp; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2083 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2084 | if (!test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags)) |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2085 | return 0; |
| 2086 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2087 | spin_lock(&device->peer_seq_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2088 | for (;;) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2089 | if (!seq_greater(peer_seq - 1, device->peer_seq)) { |
| 2090 | device->peer_seq = seq_max(device->peer_seq, peer_seq); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2091 | break; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2092 | } |
Philipp Reisner | b874d23 | 2013-10-23 10:59:16 +0200 | [diff] [blame] | 2093 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2094 | if (signal_pending(current)) { |
| 2095 | ret = -ERESTARTSYS; |
| 2096 | break; |
| 2097 | } |
Philipp Reisner | b874d23 | 2013-10-23 10:59:16 +0200 | [diff] [blame] | 2098 | |
| 2099 | rcu_read_lock(); |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 2100 | tp = rcu_dereference(first_peer_device(device)->connection->net_conf)->two_primaries; |
Philipp Reisner | b874d23 | 2013-10-23 10:59:16 +0200 | [diff] [blame] | 2101 | rcu_read_unlock(); |
| 2102 | |
| 2103 | if (!tp) |
| 2104 | break; |
| 2105 | |
| 2106 | /* Only need to wait if two_primaries is enabled */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2107 | prepare_to_wait(&device->seq_wait, &wait, TASK_INTERRUPTIBLE); |
| 2108 | spin_unlock(&device->peer_seq_lock); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2109 | rcu_read_lock(); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2110 | timeout = rcu_dereference(peer_device->connection->net_conf)->ping_timeo*HZ/10; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2111 | rcu_read_unlock(); |
Andreas Gruenbacher | 71b1c1e | 2011-03-01 15:40:43 +0100 | [diff] [blame] | 2112 | timeout = schedule_timeout(timeout); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2113 | spin_lock(&device->peer_seq_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2114 | if (!timeout) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2115 | ret = -ETIMEDOUT; |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2116 | drbd_err(device, "Timed out waiting for missing ack packets; disconnecting\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2117 | break; |
| 2118 | } |
| 2119 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2120 | spin_unlock(&device->peer_seq_lock); |
| 2121 | finish_wait(&device->seq_wait, &wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2122 | return ret; |
| 2123 | } |
| 2124 | |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 2125 | /* see also bio_flags_to_wire() |
| 2126 | * DRBD_REQ_*, because we need to semantically map the flags to data packet |
| 2127 | * flags and back. We may replicate to other kernel versions. */ |
Andreas Gruenbacher | 81f0ffd | 2011-08-30 16:22:33 +0200 | [diff] [blame] | 2128 | static unsigned long wire_flags_to_bio(u32 dpf) |
Philipp Reisner | 76d2e7e | 2010-08-25 11:58:05 +0200 | [diff] [blame] | 2129 | { |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 2130 | return (dpf & DP_RW_SYNC ? REQ_SYNC : 0) | |
| 2131 | (dpf & DP_FUA ? REQ_FUA : 0) | |
| 2132 | (dpf & DP_FLUSH ? REQ_FLUSH : 0) | |
| 2133 | (dpf & DP_DISCARD ? REQ_DISCARD : 0); |
Philipp Reisner | 76d2e7e | 2010-08-25 11:58:05 +0200 | [diff] [blame] | 2134 | } |
| 2135 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2136 | static void fail_postponed_requests(struct drbd_device *device, sector_t sector, |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2137 | unsigned int size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2138 | { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2139 | struct drbd_interval *i; |
| 2140 | |
| 2141 | repeat: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2142 | drbd_for_each_overlap(i, &device->write_requests, sector, size) { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2143 | struct drbd_request *req; |
| 2144 | struct bio_and_error m; |
| 2145 | |
| 2146 | if (!i->local) |
| 2147 | continue; |
| 2148 | req = container_of(i, struct drbd_request, i); |
| 2149 | if (!(req->rq_state & RQ_POSTPONED)) |
| 2150 | continue; |
| 2151 | req->rq_state &= ~RQ_POSTPONED; |
| 2152 | __req_mod(req, NEG_ACKED, &m); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2153 | spin_unlock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2154 | if (m.bio) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2155 | complete_master_bio(device, &m); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2156 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2157 | goto repeat; |
| 2158 | } |
| 2159 | } |
| 2160 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2161 | static int handle_write_conflicts(struct drbd_device *device, |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2162 | struct drbd_peer_request *peer_req) |
| 2163 | { |
Andreas Gruenbacher | e33b32d | 2011-08-30 15:38:04 +0200 | [diff] [blame] | 2164 | struct drbd_connection *connection = peer_req->peer_device->connection; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 2165 | bool resolve_conflicts = test_bit(RESOLVE_CONFLICTS, &connection->flags); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2166 | sector_t sector = peer_req->i.sector; |
| 2167 | const unsigned int size = peer_req->i.size; |
| 2168 | struct drbd_interval *i; |
| 2169 | bool equal; |
| 2170 | int err; |
| 2171 | |
| 2172 | /* |
| 2173 | * Inserting the peer request into the write_requests tree will prevent |
| 2174 | * new conflicting local requests from being added. |
| 2175 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2176 | drbd_insert_interval(&device->write_requests, &peer_req->i); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2177 | |
| 2178 | repeat: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2179 | drbd_for_each_overlap(i, &device->write_requests, sector, size) { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2180 | if (i == &peer_req->i) |
| 2181 | continue; |
Lars Ellenberg | 08d0dab | 2014-03-20 11:19:22 +0100 | [diff] [blame] | 2182 | if (i->completed) |
| 2183 | continue; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2184 | |
| 2185 | if (!i->local) { |
| 2186 | /* |
| 2187 | * Our peer has sent a conflicting remote request; this |
| 2188 | * should not happen in a two-node setup. Wait for the |
| 2189 | * earlier peer request to complete. |
| 2190 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2191 | err = drbd_wait_misc(device, i); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2192 | if (err) |
| 2193 | goto out; |
| 2194 | goto repeat; |
| 2195 | } |
| 2196 | |
| 2197 | equal = i->sector == sector && i->size == size; |
| 2198 | if (resolve_conflicts) { |
| 2199 | /* |
| 2200 | * If the peer request is fully contained within the |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 2201 | * overlapping request, it can be considered overwritten |
| 2202 | * and thus superseded; otherwise, it will be retried |
| 2203 | * once all overlapping requests have completed. |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2204 | */ |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 2205 | bool superseded = i->sector <= sector && i->sector + |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2206 | (i->size >> 9) >= sector + (size >> 9); |
| 2207 | |
| 2208 | if (!equal) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2209 | drbd_alert(device, "Concurrent writes detected: " |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2210 | "local=%llus +%u, remote=%llus +%u, " |
| 2211 | "assuming %s came first\n", |
| 2212 | (unsigned long long)i->sector, i->size, |
| 2213 | (unsigned long long)sector, size, |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 2214 | superseded ? "local" : "remote"); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2215 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2216 | peer_req->w.cb = superseded ? e_send_superseded : |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2217 | e_send_retry_write; |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2218 | list_add_tail(&peer_req->w.list, &device->done_ee); |
Andreas Gruenbacher | e33b32d | 2011-08-30 15:38:04 +0200 | [diff] [blame] | 2219 | wake_asender(connection); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2220 | |
| 2221 | err = -ENOENT; |
| 2222 | goto out; |
| 2223 | } else { |
| 2224 | struct drbd_request *req = |
| 2225 | container_of(i, struct drbd_request, i); |
| 2226 | |
| 2227 | if (!equal) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2228 | drbd_alert(device, "Concurrent writes detected: " |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2229 | "local=%llus +%u, remote=%llus +%u\n", |
| 2230 | (unsigned long long)i->sector, i->size, |
| 2231 | (unsigned long long)sector, size); |
| 2232 | |
| 2233 | if (req->rq_state & RQ_LOCAL_PENDING || |
| 2234 | !(req->rq_state & RQ_POSTPONED)) { |
| 2235 | /* |
| 2236 | * Wait for the node with the discard flag to |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 2237 | * decide if this request has been superseded |
| 2238 | * or needs to be retried. |
| 2239 | * Requests that have been superseded will |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2240 | * disappear from the write_requests tree. |
| 2241 | * |
| 2242 | * In addition, wait for the conflicting |
| 2243 | * request to finish locally before submitting |
| 2244 | * the conflicting peer request. |
| 2245 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2246 | err = drbd_wait_misc(device, &req->i); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2247 | if (err) { |
Andreas Gruenbacher | e33b32d | 2011-08-30 15:38:04 +0200 | [diff] [blame] | 2248 | _conn_request_state(connection, NS(conn, C_TIMEOUT), CS_HARD); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2249 | fail_postponed_requests(device, sector, size); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2250 | goto out; |
| 2251 | } |
| 2252 | goto repeat; |
| 2253 | } |
| 2254 | /* |
| 2255 | * Remember to restart the conflicting requests after |
| 2256 | * the new peer request has completed. |
| 2257 | */ |
| 2258 | peer_req->flags |= EE_RESTART_REQUESTS; |
| 2259 | } |
| 2260 | } |
| 2261 | err = 0; |
| 2262 | |
| 2263 | out: |
| 2264 | if (err) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2265 | drbd_remove_epoch_entry_interval(device, peer_req); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2266 | return err; |
| 2267 | } |
| 2268 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2269 | /* mirrored write */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 2270 | static int receive_Data(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2271 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 2272 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2273 | struct drbd_device *device; |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 2274 | struct net_conf *nc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2275 | sector_t sector; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2276 | struct drbd_peer_request *peer_req; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 2277 | struct p_data *p = pi->data; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2278 | u32 peer_seq = be32_to_cpu(p->seq_num); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2279 | int rw = WRITE; |
| 2280 | u32 dp_flags; |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 2281 | int err, tp; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2282 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 2283 | peer_device = conn_peer_device(connection, pi->vnr); |
| 2284 | if (!peer_device) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2285 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 2286 | device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2287 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2288 | if (!get_ldev(device)) { |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2289 | int err2; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2290 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2291 | err = wait_for_and_update_peer_seq(peer_device, peer_seq); |
| 2292 | drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 2293 | atomic_inc(&connection->current_epoch->epoch_size); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2294 | err2 = drbd_drain_block(peer_device, pi->size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2295 | if (!err) |
| 2296 | err = err2; |
| 2297 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Andreas Gruenbacher | fcefa62 | 2011-02-17 16:46:59 +0100 | [diff] [blame] | 2300 | /* |
| 2301 | * Corresponding put_ldev done either below (on various errors), or in |
| 2302 | * drbd_peer_request_endio, if we successfully submit the data at the |
| 2303 | * end of this function. |
| 2304 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2305 | |
| 2306 | sector = be64_to_cpu(p->sector); |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 2307 | peer_req = read_in_block(peer_device, p->block_id, sector, pi); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2308 | if (!peer_req) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2309 | put_ldev(device); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2310 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2313 | peer_req->w.cb = e_end_block; |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 2314 | peer_req->submit_jif = jiffies; |
| 2315 | peer_req->flags |= EE_APPLICATION; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2316 | |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 2317 | dp_flags = be32_to_cpu(p->dp_flags); |
Andreas Gruenbacher | 81f0ffd | 2011-08-30 16:22:33 +0200 | [diff] [blame] | 2318 | rw |= wire_flags_to_bio(dp_flags); |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 2319 | if (pi->cmd == P_TRIM) { |
| 2320 | struct request_queue *q = bdev_get_queue(device->ldev->backing_bdev); |
| 2321 | peer_req->flags |= EE_IS_TRIM; |
| 2322 | if (!blk_queue_discard(q)) |
| 2323 | peer_req->flags |= EE_IS_TRIM_USE_ZEROOUT; |
| 2324 | D_ASSERT(peer_device, peer_req->i.size > 0); |
| 2325 | D_ASSERT(peer_device, rw & REQ_DISCARD); |
| 2326 | D_ASSERT(peer_device, peer_req->pages == NULL); |
| 2327 | } else if (peer_req->pages == NULL) { |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 2328 | D_ASSERT(device, peer_req->i.size == 0); |
| 2329 | D_ASSERT(device, dp_flags & DP_FLUSH); |
Lars Ellenberg | a73ff32 | 2012-06-25 19:15:38 +0200 | [diff] [blame] | 2330 | } |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 2331 | |
| 2332 | if (dp_flags & DP_MAY_SET_IN_SYNC) |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2333 | peer_req->flags |= EE_MAY_SET_IN_SYNC; |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 2334 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 2335 | spin_lock(&connection->epoch_lock); |
| 2336 | peer_req->epoch = connection->current_epoch; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2337 | atomic_inc(&peer_req->epoch->epoch_size); |
| 2338 | atomic_inc(&peer_req->epoch->active); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 2339 | spin_unlock(&connection->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2340 | |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 2341 | rcu_read_lock(); |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 2342 | nc = rcu_dereference(peer_device->connection->net_conf); |
| 2343 | tp = nc->two_primaries; |
| 2344 | if (peer_device->connection->agreed_pro_version < 100) { |
| 2345 | switch (nc->wire_protocol) { |
| 2346 | case DRBD_PROT_C: |
| 2347 | dp_flags |= DP_SEND_WRITE_ACK; |
| 2348 | break; |
| 2349 | case DRBD_PROT_B: |
| 2350 | dp_flags |= DP_SEND_RECEIVE_ACK; |
| 2351 | break; |
| 2352 | } |
| 2353 | } |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 2354 | rcu_read_unlock(); |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 2355 | |
| 2356 | if (dp_flags & DP_SEND_WRITE_ACK) { |
| 2357 | peer_req->flags |= EE_SEND_WRITE_ACK; |
| 2358 | inc_unacked(device); |
| 2359 | /* corresponding dec_unacked() in e_end_block() |
| 2360 | * respective _drbd_clear_done_ee */ |
| 2361 | } |
| 2362 | |
| 2363 | if (dp_flags & DP_SEND_RECEIVE_ACK) { |
| 2364 | /* I really don't like it that the receiver thread |
| 2365 | * sends on the msock, but anyways */ |
| 2366 | drbd_send_ack(first_peer_device(device), P_RECV_ACK, peer_req); |
| 2367 | } |
| 2368 | |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 2369 | if (tp) { |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 2370 | /* two primaries implies protocol C */ |
| 2371 | D_ASSERT(device, dp_flags & DP_SEND_WRITE_ACK); |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 2372 | peer_req->flags |= EE_IN_INTERVAL_TREE; |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2373 | err = wait_for_and_update_peer_seq(peer_device, peer_seq); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2374 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2375 | goto out_interrupted; |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2376 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2377 | err = handle_write_conflicts(device, peer_req); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2378 | if (err) { |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2379 | spin_unlock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2380 | if (err == -ENOENT) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2381 | put_ldev(device); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2382 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2383 | } |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2384 | goto out_interrupted; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2385 | } |
Philipp Reisner | b874d23 | 2013-10-23 10:59:16 +0200 | [diff] [blame] | 2386 | } else { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2387 | update_peer_seq(peer_device, peer_seq); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2388 | spin_lock_irq(&device->resource->req_lock); |
Philipp Reisner | b874d23 | 2013-10-23 10:59:16 +0200 | [diff] [blame] | 2389 | } |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 2390 | /* if we use the zeroout fallback code, we process synchronously |
| 2391 | * and we wait for all pending requests, respectively wait for |
| 2392 | * active_ee to become empty in drbd_submit_peer_request(); |
| 2393 | * better not add ourselves here. */ |
| 2394 | if ((peer_req->flags & EE_IS_TRIM_USE_ZEROOUT) == 0) |
Lars Ellenberg | b9ed708 | 2014-04-23 12:15:35 +0200 | [diff] [blame] | 2395 | list_add_tail(&peer_req->w.list, &device->active_ee); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2396 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2397 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2398 | if (device->state.conn == C_SYNC_TARGET) |
| 2399 | wait_event(device->ee_wait, !overlapping_resync_write(device, peer_req)); |
Philipp Reisner | b6a370ba | 2012-02-19 01:27:53 +0100 | [diff] [blame] | 2400 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2401 | if (device->state.pdsk < D_INCONSISTENT) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2402 | /* In case we have the only disk of the cluster, */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2403 | drbd_set_out_of_sync(device, peer_req->i.sector, peer_req->i.size); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2404 | peer_req->flags &= ~EE_MAY_SET_IN_SYNC; |
Lars Ellenberg | 4dd726f | 2014-02-11 11:15:36 +0100 | [diff] [blame] | 2405 | drbd_al_begin_io(device, &peer_req->i); |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 2406 | peer_req->flags |= EE_CALL_AL_COMPLETE_IO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2409 | err = drbd_submit_peer_request(device, peer_req, rw, DRBD_FAULT_DT_WR); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2410 | if (!err) |
| 2411 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2412 | |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 2413 | /* don't care for the reason here */ |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2414 | drbd_err(device, "submit failed, triggering re-connect\n"); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2415 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2416 | list_del(&peer_req->w.list); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2417 | drbd_remove_epoch_entry_interval(device, peer_req); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2418 | spin_unlock_irq(&device->resource->req_lock); |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 2419 | if (peer_req->flags & EE_CALL_AL_COMPLETE_IO) { |
| 2420 | peer_req->flags &= ~EE_CALL_AL_COMPLETE_IO; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2421 | drbd_al_complete_io(device, &peer_req->i); |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 2422 | } |
Lars Ellenberg | 22cc37a | 2010-09-14 20:40:41 +0200 | [diff] [blame] | 2423 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2424 | out_interrupted: |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 2425 | drbd_may_finish_epoch(connection, peer_req->epoch, EV_PUT + EV_CLEANUP); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2426 | put_ldev(device); |
| 2427 | drbd_free_peer_req(device, peer_req); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2428 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2431 | /* We may throttle resync, if the lower device seems to be busy, |
| 2432 | * and current sync rate is above c_min_rate. |
| 2433 | * |
| 2434 | * To decide whether or not the lower device is busy, we use a scheme similar |
| 2435 | * to MD RAID is_mddev_idle(): if the partition stats reveal "significant" |
| 2436 | * (more than 64 sectors) of activity we cannot account for with our own resync |
| 2437 | * activity, it obviously is "busy". |
| 2438 | * |
| 2439 | * The current sync rate used here uses only the most recent two step marks, |
| 2440 | * to have a short time average so we can react faster. |
| 2441 | */ |
Lars Ellenberg | ad3fee7 | 2013-12-20 11:22:13 +0100 | [diff] [blame] | 2442 | bool drbd_rs_should_slow_down(struct drbd_device *device, sector_t sector, |
| 2443 | bool throttle_if_app_is_waiting) |
Lars Ellenberg | e829987 | 2014-04-28 18:43:19 +0200 | [diff] [blame] | 2444 | { |
| 2445 | struct lc_element *tmp; |
Lars Ellenberg | ad3fee7 | 2013-12-20 11:22:13 +0100 | [diff] [blame] | 2446 | bool throttle = drbd_rs_c_min_rate_throttle(device); |
Lars Ellenberg | e829987 | 2014-04-28 18:43:19 +0200 | [diff] [blame] | 2447 | |
Lars Ellenberg | ad3fee7 | 2013-12-20 11:22:13 +0100 | [diff] [blame] | 2448 | if (!throttle || throttle_if_app_is_waiting) |
| 2449 | return throttle; |
Lars Ellenberg | e829987 | 2014-04-28 18:43:19 +0200 | [diff] [blame] | 2450 | |
| 2451 | spin_lock_irq(&device->al_lock); |
| 2452 | tmp = lc_find(device->resync, BM_SECT_TO_EXT(sector)); |
| 2453 | if (tmp) { |
| 2454 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); |
| 2455 | if (test_bit(BME_PRIORITY, &bm_ext->flags)) |
| 2456 | throttle = false; |
Lars Ellenberg | ad3fee7 | 2013-12-20 11:22:13 +0100 | [diff] [blame] | 2457 | /* Do not slow down if app IO is already waiting for this extent, |
| 2458 | * and our progress is necessary for application IO to complete. */ |
Lars Ellenberg | e829987 | 2014-04-28 18:43:19 +0200 | [diff] [blame] | 2459 | } |
| 2460 | spin_unlock_irq(&device->al_lock); |
| 2461 | |
| 2462 | return throttle; |
| 2463 | } |
| 2464 | |
| 2465 | bool drbd_rs_c_min_rate_throttle(struct drbd_device *device) |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2466 | { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2467 | struct gendisk *disk = device->ldev->backing_bdev->bd_contains->bd_disk; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2468 | unsigned long db, dt, dbdt; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2469 | unsigned int c_min_rate; |
Lars Ellenberg | e829987 | 2014-04-28 18:43:19 +0200 | [diff] [blame] | 2470 | int curr_events; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2471 | |
| 2472 | rcu_read_lock(); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2473 | c_min_rate = rcu_dereference(device->ldev->disk_conf)->c_min_rate; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2474 | rcu_read_unlock(); |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2475 | |
| 2476 | /* feature disabled? */ |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2477 | if (c_min_rate == 0) |
Lars Ellenberg | e829987 | 2014-04-28 18:43:19 +0200 | [diff] [blame] | 2478 | return false; |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2479 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2480 | curr_events = (int)part_stat_read(&disk->part0, sectors[0]) + |
| 2481 | (int)part_stat_read(&disk->part0, sectors[1]) - |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2482 | atomic_read(&device->rs_sect_ev); |
Lars Ellenberg | ad3fee7 | 2013-12-20 11:22:13 +0100 | [diff] [blame] | 2483 | |
| 2484 | if (atomic_read(&device->ap_actlog_cnt) |
Lars Ellenberg | ff8bd88 | 2014-11-10 17:21:12 +0100 | [diff] [blame] | 2485 | || curr_events - device->rs_last_events > 64) { |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2486 | unsigned long rs_left; |
| 2487 | int i; |
| 2488 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2489 | device->rs_last_events = curr_events; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2490 | |
| 2491 | /* sync speed average over the last 2*DRBD_SYNC_MARK_STEP, |
| 2492 | * approx. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2493 | i = (device->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS; |
Lars Ellenberg | 2649f08 | 2010-11-05 10:05:47 +0100 | [diff] [blame] | 2494 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2495 | if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T) |
| 2496 | rs_left = device->ov_left; |
Lars Ellenberg | 2649f08 | 2010-11-05 10:05:47 +0100 | [diff] [blame] | 2497 | else |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2498 | rs_left = drbd_bm_total_weight(device) - device->rs_failed; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2499 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2500 | dt = ((long)jiffies - (long)device->rs_mark_time[i]) / HZ; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2501 | if (!dt) |
| 2502 | dt++; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2503 | db = device->rs_mark_left[i] - rs_left; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2504 | dbdt = Bit2KB(db/dt); |
| 2505 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2506 | if (dbdt > c_min_rate) |
Lars Ellenberg | e829987 | 2014-04-28 18:43:19 +0200 | [diff] [blame] | 2507 | return true; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2508 | } |
Lars Ellenberg | e829987 | 2014-04-28 18:43:19 +0200 | [diff] [blame] | 2509 | return false; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2510 | } |
| 2511 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 2512 | static int receive_DataRequest(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2513 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 2514 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2515 | struct drbd_device *device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2516 | sector_t sector; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2517 | sector_t capacity; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2518 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2519 | struct digest_info *di = NULL; |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2520 | int size, verb; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2521 | unsigned int fault_type; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 2522 | struct p_block_req *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2523 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 2524 | peer_device = conn_peer_device(connection, pi->vnr); |
| 2525 | if (!peer_device) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2526 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 2527 | device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2528 | capacity = drbd_get_capacity(device->this_bdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2529 | |
| 2530 | sector = be64_to_cpu(p->sector); |
| 2531 | size = be32_to_cpu(p->blksize); |
| 2532 | |
Andreas Gruenbacher | c670a39 | 2011-02-21 12:41:39 +0100 | [diff] [blame] | 2533 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2534 | drbd_err(device, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2535 | (unsigned long long)sector, size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2536 | return -EINVAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2537 | } |
| 2538 | if (sector + (size>>9) > capacity) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2539 | drbd_err(device, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2540 | (unsigned long long)sector, size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2541 | return -EINVAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2544 | if (!get_ldev_if_state(device, D_UP_TO_DATE)) { |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2545 | verb = 1; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2546 | switch (pi->cmd) { |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2547 | case P_DATA_REQUEST: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2548 | drbd_send_ack_rp(peer_device, P_NEG_DREPLY, p); |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2549 | break; |
| 2550 | case P_RS_DATA_REQUEST: |
| 2551 | case P_CSUM_RS_REQUEST: |
| 2552 | case P_OV_REQUEST: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2553 | drbd_send_ack_rp(peer_device, P_NEG_RS_DREPLY , p); |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2554 | break; |
| 2555 | case P_OV_REPLY: |
| 2556 | verb = 0; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2557 | dec_rs_pending(device); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2558 | drbd_send_ack_ex(peer_device, P_OV_RESULT, sector, size, ID_IN_SYNC); |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2559 | break; |
| 2560 | default: |
Andreas Gruenbacher | 49ba9b1 | 2011-03-25 00:35:45 +0100 | [diff] [blame] | 2561 | BUG(); |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2562 | } |
| 2563 | if (verb && __ratelimit(&drbd_ratelimit_state)) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2564 | drbd_err(device, "Can not satisfy peer's read request, " |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2565 | "no local data.\n"); |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2566 | |
Lars Ellenberg | a821cc4 | 2010-09-06 12:31:37 +0200 | [diff] [blame] | 2567 | /* drain possibly payload */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2568 | return drbd_drain_block(peer_device, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD |
| 2572 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
| 2573 | * which in turn might block on the other node at this very place. */ |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 2574 | peer_req = drbd_alloc_peer_req(peer_device, p->block_id, sector, size, |
| 2575 | true /* has real payload */, GFP_NOIO); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2576 | if (!peer_req) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2577 | put_ldev(device); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2578 | return -ENOMEM; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2581 | switch (pi->cmd) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2582 | case P_DATA_REQUEST: |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2583 | peer_req->w.cb = w_e_end_data_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2584 | fault_type = DRBD_FAULT_DT_RD; |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2585 | /* application IO, don't drbd_rs_begin_io */ |
Lars Ellenberg | 21ae5d7 | 2014-05-05 23:42:24 +0200 | [diff] [blame] | 2586 | peer_req->flags |= EE_APPLICATION; |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2587 | goto submit; |
| 2588 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2589 | case P_RS_DATA_REQUEST: |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2590 | peer_req->w.cb = w_e_end_rsdata_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2591 | fault_type = DRBD_FAULT_RS_RD; |
Lars Ellenberg | 5f9915b | 2010-11-09 14:15:24 +0100 | [diff] [blame] | 2592 | /* used in the sector offset progress display */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2593 | device->bm_resync_fo = BM_SECT_TO_BIT(sector); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2594 | break; |
| 2595 | |
| 2596 | case P_OV_REPLY: |
| 2597 | case P_CSUM_RS_REQUEST: |
| 2598 | fault_type = DRBD_FAULT_RS_RD; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2599 | di = kmalloc(sizeof(*di) + pi->size, GFP_NOIO); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2600 | if (!di) |
| 2601 | goto out_free_e; |
| 2602 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2603 | di->digest_size = pi->size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2604 | di->digest = (((char *)di)+sizeof(struct digest_info)); |
| 2605 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2606 | peer_req->digest = di; |
| 2607 | peer_req->flags |= EE_HAS_DIGEST; |
Lars Ellenberg | c36c3ce | 2010-08-11 20:42:55 +0200 | [diff] [blame] | 2608 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 2609 | if (drbd_recv_all(peer_device->connection, di->digest, pi->size)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2610 | goto out_free_e; |
| 2611 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2612 | if (pi->cmd == P_CSUM_RS_REQUEST) { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 2613 | D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89); |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2614 | peer_req->w.cb = w_e_end_csum_rs_req; |
Lars Ellenberg | 5f9915b | 2010-11-09 14:15:24 +0100 | [diff] [blame] | 2615 | /* used in the sector offset progress display */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2616 | device->bm_resync_fo = BM_SECT_TO_BIT(sector); |
Lars Ellenberg | aaaba34 | 2014-03-18 12:30:09 +0100 | [diff] [blame] | 2617 | /* remember to report stats in drbd_resync_finished */ |
| 2618 | device->use_csums = true; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2619 | } else if (pi->cmd == P_OV_REPLY) { |
Lars Ellenberg | 2649f08 | 2010-11-05 10:05:47 +0100 | [diff] [blame] | 2620 | /* track progress, we may need to throttle */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2621 | atomic_add(size >> 9, &device->rs_sect_in); |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2622 | peer_req->w.cb = w_e_end_ov_reply; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2623 | dec_rs_pending(device); |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2624 | /* drbd_rs_begin_io done when we sent this request, |
| 2625 | * but accounting still needs to be done. */ |
| 2626 | goto submit_for_resync; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2627 | } |
| 2628 | break; |
| 2629 | |
| 2630 | case P_OV_REQUEST: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2631 | if (device->ov_start_sector == ~(sector_t)0 && |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 2632 | peer_device->connection->agreed_pro_version >= 90) { |
Lars Ellenberg | de228bb | 2010-11-05 09:43:15 +0100 | [diff] [blame] | 2633 | unsigned long now = jiffies; |
| 2634 | int i; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2635 | device->ov_start_sector = sector; |
| 2636 | device->ov_position = sector; |
| 2637 | device->ov_left = drbd_bm_bits(device) - BM_SECT_TO_BIT(sector); |
| 2638 | device->rs_total = device->ov_left; |
Lars Ellenberg | de228bb | 2010-11-05 09:43:15 +0100 | [diff] [blame] | 2639 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2640 | device->rs_mark_left[i] = device->ov_left; |
| 2641 | device->rs_mark_time[i] = now; |
Lars Ellenberg | de228bb | 2010-11-05 09:43:15 +0100 | [diff] [blame] | 2642 | } |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2643 | drbd_info(device, "Online Verify start sector: %llu\n", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2644 | (unsigned long long)sector); |
| 2645 | } |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2646 | peer_req->w.cb = w_e_end_ov_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2647 | fault_type = DRBD_FAULT_RS_RD; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2648 | break; |
| 2649 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2650 | default: |
Andreas Gruenbacher | 49ba9b1 | 2011-03-25 00:35:45 +0100 | [diff] [blame] | 2651 | BUG(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2654 | /* Throttle, drbd_rs_begin_io and submit should become asynchronous |
| 2655 | * wrt the receiver, but it is not as straightforward as it may seem. |
| 2656 | * Various places in the resync start and stop logic assume resync |
| 2657 | * requests are processed in order, requeuing this on the worker thread |
| 2658 | * introduces a bunch of new code for synchronization between threads. |
| 2659 | * |
| 2660 | * Unlimited throttling before drbd_rs_begin_io may stall the resync |
| 2661 | * "forever", throttling after drbd_rs_begin_io will lock that extent |
| 2662 | * for application writes for the same time. For now, just throttle |
| 2663 | * here, where the rest of the code expects the receiver to sleep for |
| 2664 | * a while, anyways. |
| 2665 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2666 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2667 | /* Throttle before drbd_rs_begin_io, as that locks out application IO; |
| 2668 | * this defers syncer requests for some time, before letting at least |
| 2669 | * on request through. The resync controller on the receiving side |
| 2670 | * will adapt to the incoming rate accordingly. |
| 2671 | * |
| 2672 | * We cannot throttle here if remote is Primary/SyncTarget: |
| 2673 | * we would also throttle its application reads. |
| 2674 | * In that case, throttling is done on the SyncTarget only. |
| 2675 | */ |
Lars Ellenberg | c5a2c15 | 2014-05-08 10:08:05 +0200 | [diff] [blame] | 2676 | |
| 2677 | /* Even though this may be a resync request, we do add to "read_ee"; |
| 2678 | * "sync_ee" is only used for resync WRITEs. |
| 2679 | * Add to list early, so debugfs can find this request |
| 2680 | * even if we have to sleep below. */ |
| 2681 | spin_lock_irq(&device->resource->req_lock); |
| 2682 | list_add_tail(&peer_req->w.list, &device->read_ee); |
| 2683 | spin_unlock_irq(&device->resource->req_lock); |
| 2684 | |
Lars Ellenberg | 944410e | 2014-05-06 15:02:05 +0200 | [diff] [blame] | 2685 | update_receiver_timing_details(connection, drbd_rs_should_slow_down); |
Lars Ellenberg | ad3fee7 | 2013-12-20 11:22:13 +0100 | [diff] [blame] | 2686 | if (device->state.peer != R_PRIMARY |
| 2687 | && drbd_rs_should_slow_down(device, sector, false)) |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2688 | schedule_timeout_uninterruptible(HZ/10); |
Lars Ellenberg | 944410e | 2014-05-06 15:02:05 +0200 | [diff] [blame] | 2689 | update_receiver_timing_details(connection, drbd_rs_begin_io); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2690 | if (drbd_rs_begin_io(device, sector)) |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2691 | goto out_free_e; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2692 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2693 | submit_for_resync: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2694 | atomic_add(size >> 9, &device->rs_sect_ev); |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2695 | |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2696 | submit: |
Lars Ellenberg | 944410e | 2014-05-06 15:02:05 +0200 | [diff] [blame] | 2697 | update_receiver_timing_details(connection, drbd_submit_peer_request); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2698 | inc_unacked(device); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2699 | if (drbd_submit_peer_request(device, peer_req, READ, fault_type) == 0) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2700 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2701 | |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 2702 | /* don't care for the reason here */ |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2703 | drbd_err(device, "submit failed, triggering re-connect\n"); |
Lars Ellenberg | c5a2c15 | 2014-05-08 10:08:05 +0200 | [diff] [blame] | 2704 | |
| 2705 | out_free_e: |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2706 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | a8cd15b | 2011-08-25 15:49:40 +0200 | [diff] [blame] | 2707 | list_del(&peer_req->w.list); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 2708 | spin_unlock_irq(&device->resource->req_lock); |
Lars Ellenberg | 22cc37a | 2010-09-14 20:40:41 +0200 | [diff] [blame] | 2709 | /* no drbd_rs_complete_io(), we are dropping the connection anyways */ |
| 2710 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2711 | put_ldev(device); |
| 2712 | drbd_free_peer_req(device, peer_req); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2713 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2716 | /** |
| 2717 | * drbd_asb_recover_0p - Recover after split-brain with no remaining primaries |
| 2718 | */ |
| 2719 | static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2720 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2721 | struct drbd_device *device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2722 | int self, peer, rv = -100; |
| 2723 | unsigned long ch_self, ch_peer; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2724 | enum drbd_after_sb_p after_sb_0p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2725 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2726 | self = device->ldev->md.uuid[UI_BITMAP] & 1; |
| 2727 | peer = device->p_uuid[UI_BITMAP] & 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2728 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2729 | ch_peer = device->p_uuid[UI_SIZE]; |
| 2730 | ch_self = device->comm_bm_set; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2731 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2732 | rcu_read_lock(); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2733 | after_sb_0p = rcu_dereference(peer_device->connection->net_conf)->after_sb_0p; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2734 | rcu_read_unlock(); |
| 2735 | switch (after_sb_0p) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2736 | case ASB_CONSENSUS: |
| 2737 | case ASB_DISCARD_SECONDARY: |
| 2738 | case ASB_CALL_HELPER: |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2739 | case ASB_VIOLENTLY: |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2740 | drbd_err(device, "Configuration error.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2741 | break; |
| 2742 | case ASB_DISCONNECT: |
| 2743 | break; |
| 2744 | case ASB_DISCARD_YOUNGER_PRI: |
| 2745 | if (self == 0 && peer == 1) { |
| 2746 | rv = -1; |
| 2747 | break; |
| 2748 | } |
| 2749 | if (self == 1 && peer == 0) { |
| 2750 | rv = 1; |
| 2751 | break; |
| 2752 | } |
| 2753 | /* Else fall through to one of the other strategies... */ |
| 2754 | case ASB_DISCARD_OLDER_PRI: |
| 2755 | if (self == 0 && peer == 1) { |
| 2756 | rv = 1; |
| 2757 | break; |
| 2758 | } |
| 2759 | if (self == 1 && peer == 0) { |
| 2760 | rv = -1; |
| 2761 | break; |
| 2762 | } |
| 2763 | /* Else fall through to one of the other strategies... */ |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2764 | drbd_warn(device, "Discard younger/older primary did not find a decision\n" |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2765 | "Using discard-least-changes instead\n"); |
| 2766 | case ASB_DISCARD_ZERO_CHG: |
| 2767 | if (ch_peer == 0 && ch_self == 0) { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2768 | rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2769 | ? -1 : 1; |
| 2770 | break; |
| 2771 | } else { |
| 2772 | if (ch_peer == 0) { rv = 1; break; } |
| 2773 | if (ch_self == 0) { rv = -1; break; } |
| 2774 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2775 | if (after_sb_0p == ASB_DISCARD_ZERO_CHG) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2776 | break; |
| 2777 | case ASB_DISCARD_LEAST_CHG: |
| 2778 | if (ch_self < ch_peer) |
| 2779 | rv = -1; |
| 2780 | else if (ch_self > ch_peer) |
| 2781 | rv = 1; |
| 2782 | else /* ( ch_self == ch_peer ) */ |
| 2783 | /* Well, then use something else. */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2784 | rv = test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2785 | ? -1 : 1; |
| 2786 | break; |
| 2787 | case ASB_DISCARD_LOCAL: |
| 2788 | rv = -1; |
| 2789 | break; |
| 2790 | case ASB_DISCARD_REMOTE: |
| 2791 | rv = 1; |
| 2792 | } |
| 2793 | |
| 2794 | return rv; |
| 2795 | } |
| 2796 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2797 | /** |
| 2798 | * drbd_asb_recover_1p - Recover after split-brain with one remaining primary |
| 2799 | */ |
| 2800 | static int drbd_asb_recover_1p(struct drbd_peer_device *peer_device) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2801 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2802 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | 6184ea2 | 2010-12-09 14:23:27 +0100 | [diff] [blame] | 2803 | int hg, rv = -100; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2804 | enum drbd_after_sb_p after_sb_1p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2805 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2806 | rcu_read_lock(); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2807 | after_sb_1p = rcu_dereference(peer_device->connection->net_conf)->after_sb_1p; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2808 | rcu_read_unlock(); |
| 2809 | switch (after_sb_1p) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2810 | case ASB_DISCARD_YOUNGER_PRI: |
| 2811 | case ASB_DISCARD_OLDER_PRI: |
| 2812 | case ASB_DISCARD_LEAST_CHG: |
| 2813 | case ASB_DISCARD_LOCAL: |
| 2814 | case ASB_DISCARD_REMOTE: |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2815 | case ASB_DISCARD_ZERO_CHG: |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2816 | drbd_err(device, "Configuration error.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2817 | break; |
| 2818 | case ASB_DISCONNECT: |
| 2819 | break; |
| 2820 | case ASB_CONSENSUS: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2821 | hg = drbd_asb_recover_0p(peer_device); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2822 | if (hg == -1 && device->state.role == R_SECONDARY) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2823 | rv = hg; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2824 | if (hg == 1 && device->state.role == R_PRIMARY) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2825 | rv = hg; |
| 2826 | break; |
| 2827 | case ASB_VIOLENTLY: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2828 | rv = drbd_asb_recover_0p(peer_device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2829 | break; |
| 2830 | case ASB_DISCARD_SECONDARY: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2831 | return device->state.role == R_PRIMARY ? 1 : -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2832 | case ASB_CALL_HELPER: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2833 | hg = drbd_asb_recover_0p(peer_device); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2834 | if (hg == -1 && device->state.role == R_PRIMARY) { |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2835 | enum drbd_state_rv rv2; |
| 2836 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2837 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, |
| 2838 | * we might be here in C_WF_REPORT_PARAMS which is transient. |
| 2839 | * we do not need to wait for the after state change work either. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2840 | rv2 = drbd_change_state(device, CS_VERBOSE, NS(role, R_SECONDARY)); |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2841 | if (rv2 != SS_SUCCESS) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2842 | drbd_khelper(device, "pri-lost-after-sb"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2843 | } else { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2844 | drbd_warn(device, "Successfully gave up primary role.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2845 | rv = hg; |
| 2846 | } |
| 2847 | } else |
| 2848 | rv = hg; |
| 2849 | } |
| 2850 | |
| 2851 | return rv; |
| 2852 | } |
| 2853 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2854 | /** |
| 2855 | * drbd_asb_recover_2p - Recover after split-brain with two remaining primaries |
| 2856 | */ |
| 2857 | static int drbd_asb_recover_2p(struct drbd_peer_device *peer_device) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2858 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2859 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | 6184ea2 | 2010-12-09 14:23:27 +0100 | [diff] [blame] | 2860 | int hg, rv = -100; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2861 | enum drbd_after_sb_p after_sb_2p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2862 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2863 | rcu_read_lock(); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2864 | after_sb_2p = rcu_dereference(peer_device->connection->net_conf)->after_sb_2p; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2865 | rcu_read_unlock(); |
| 2866 | switch (after_sb_2p) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2867 | case ASB_DISCARD_YOUNGER_PRI: |
| 2868 | case ASB_DISCARD_OLDER_PRI: |
| 2869 | case ASB_DISCARD_LEAST_CHG: |
| 2870 | case ASB_DISCARD_LOCAL: |
| 2871 | case ASB_DISCARD_REMOTE: |
| 2872 | case ASB_CONSENSUS: |
| 2873 | case ASB_DISCARD_SECONDARY: |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2874 | case ASB_DISCARD_ZERO_CHG: |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2875 | drbd_err(device, "Configuration error.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2876 | break; |
| 2877 | case ASB_VIOLENTLY: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2878 | rv = drbd_asb_recover_0p(peer_device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2879 | break; |
| 2880 | case ASB_DISCONNECT: |
| 2881 | break; |
| 2882 | case ASB_CALL_HELPER: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 2883 | hg = drbd_asb_recover_0p(peer_device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2884 | if (hg == -1) { |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2885 | enum drbd_state_rv rv2; |
| 2886 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2887 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, |
| 2888 | * we might be here in C_WF_REPORT_PARAMS which is transient. |
| 2889 | * we do not need to wait for the after state change work either. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2890 | rv2 = drbd_change_state(device, CS_VERBOSE, NS(role, R_SECONDARY)); |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2891 | if (rv2 != SS_SUCCESS) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2892 | drbd_khelper(device, "pri-lost-after-sb"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2893 | } else { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2894 | drbd_warn(device, "Successfully gave up primary role.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2895 | rv = hg; |
| 2896 | } |
| 2897 | } else |
| 2898 | rv = hg; |
| 2899 | } |
| 2900 | |
| 2901 | return rv; |
| 2902 | } |
| 2903 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2904 | static void drbd_uuid_dump(struct drbd_device *device, char *text, u64 *uuid, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2905 | u64 bits, u64 flags) |
| 2906 | { |
| 2907 | if (!uuid) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2908 | drbd_info(device, "%s uuid info vanished while I was looking!\n", text); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2909 | return; |
| 2910 | } |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2911 | drbd_info(device, "%s %016llX:%016llX:%016llX:%016llX bits:%llu flags:%llX\n", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2912 | text, |
| 2913 | (unsigned long long)uuid[UI_CURRENT], |
| 2914 | (unsigned long long)uuid[UI_BITMAP], |
| 2915 | (unsigned long long)uuid[UI_HISTORY_START], |
| 2916 | (unsigned long long)uuid[UI_HISTORY_END], |
| 2917 | (unsigned long long)bits, |
| 2918 | (unsigned long long)flags); |
| 2919 | } |
| 2920 | |
| 2921 | /* |
| 2922 | 100 after split brain try auto recover |
| 2923 | 2 C_SYNC_SOURCE set BitMap |
| 2924 | 1 C_SYNC_SOURCE use BitMap |
| 2925 | 0 no Sync |
| 2926 | -1 C_SYNC_TARGET use BitMap |
| 2927 | -2 C_SYNC_TARGET set BitMap |
| 2928 | -100 after split brain, disconnect |
| 2929 | -1000 unrelated data |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2930 | -1091 requires proto 91 |
| 2931 | -1096 requires proto 96 |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2932 | */ |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 2933 | static int drbd_uuid_compare(struct drbd_device *const device, int *rule_nr) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2934 | { |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 2935 | struct drbd_peer_device *const peer_device = first_peer_device(device); |
| 2936 | struct drbd_connection *const connection = peer_device ? peer_device->connection : NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2937 | u64 self, peer; |
| 2938 | int i, j; |
| 2939 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2940 | self = device->ldev->md.uuid[UI_CURRENT] & ~((u64)1); |
| 2941 | peer = device->p_uuid[UI_CURRENT] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2942 | |
| 2943 | *rule_nr = 10; |
| 2944 | if (self == UUID_JUST_CREATED && peer == UUID_JUST_CREATED) |
| 2945 | return 0; |
| 2946 | |
| 2947 | *rule_nr = 20; |
| 2948 | if ((self == UUID_JUST_CREATED || self == (u64)0) && |
| 2949 | peer != UUID_JUST_CREATED) |
| 2950 | return -2; |
| 2951 | |
| 2952 | *rule_nr = 30; |
| 2953 | if (self != UUID_JUST_CREATED && |
| 2954 | (peer == UUID_JUST_CREATED || peer == (u64)0)) |
| 2955 | return 2; |
| 2956 | |
| 2957 | if (self == peer) { |
| 2958 | int rct, dc; /* roles at crash time */ |
| 2959 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2960 | if (device->p_uuid[UI_BITMAP] == (u64)0 && device->ldev->md.uuid[UI_BITMAP] != (u64)0) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2961 | |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 2962 | if (connection->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2963 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2964 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2965 | if ((device->ldev->md.uuid[UI_BITMAP] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START] & ~((u64)1)) && |
| 2966 | (device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START + 1] & ~((u64)1))) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2967 | drbd_info(device, "was SyncSource, missed the resync finished event, corrected myself:\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2968 | drbd_uuid_move_history(device); |
| 2969 | device->ldev->md.uuid[UI_HISTORY_START] = device->ldev->md.uuid[UI_BITMAP]; |
| 2970 | device->ldev->md.uuid[UI_BITMAP] = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2971 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2972 | drbd_uuid_dump(device, "self", device->ldev->md.uuid, |
| 2973 | device->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(device) : 0, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2974 | *rule_nr = 34; |
| 2975 | } else { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2976 | drbd_info(device, "was SyncSource (peer failed to write sync_uuid)\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2977 | *rule_nr = 36; |
| 2978 | } |
| 2979 | |
| 2980 | return 1; |
| 2981 | } |
| 2982 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2983 | if (device->ldev->md.uuid[UI_BITMAP] == (u64)0 && device->p_uuid[UI_BITMAP] != (u64)0) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2984 | |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 2985 | if (connection->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2986 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2987 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2988 | if ((device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (device->p_uuid[UI_BITMAP] & ~((u64)1)) && |
| 2989 | (device->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == (device->p_uuid[UI_HISTORY_START] & ~((u64)1))) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2990 | drbd_info(device, "was SyncTarget, peer missed the resync finished event, corrected peer:\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2991 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2992 | device->p_uuid[UI_HISTORY_START + 1] = device->p_uuid[UI_HISTORY_START]; |
| 2993 | device->p_uuid[UI_HISTORY_START] = device->p_uuid[UI_BITMAP]; |
| 2994 | device->p_uuid[UI_BITMAP] = 0UL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2995 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 2996 | drbd_uuid_dump(device, "peer", device->p_uuid, device->p_uuid[UI_SIZE], device->p_uuid[UI_FLAGS]); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2997 | *rule_nr = 35; |
| 2998 | } else { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 2999 | drbd_info(device, "was SyncTarget (failed to write sync_uuid)\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3000 | *rule_nr = 37; |
| 3001 | } |
| 3002 | |
| 3003 | return -1; |
| 3004 | } |
| 3005 | |
| 3006 | /* Common power [off|failure] */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3007 | rct = (test_bit(CRASHED_PRIMARY, &device->flags) ? 1 : 0) + |
| 3008 | (device->p_uuid[UI_FLAGS] & 2); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3009 | /* lowest bit is set when we were primary, |
| 3010 | * next bit (weight 2) is set when peer was primary */ |
| 3011 | *rule_nr = 40; |
| 3012 | |
| 3013 | switch (rct) { |
| 3014 | case 0: /* !self_pri && !peer_pri */ return 0; |
| 3015 | case 1: /* self_pri && !peer_pri */ return 1; |
| 3016 | case 2: /* !self_pri && peer_pri */ return -1; |
| 3017 | case 3: /* self_pri && peer_pri */ |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 3018 | dc = test_bit(RESOLVE_CONFLICTS, &connection->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3019 | return dc ? -1 : 1; |
| 3020 | } |
| 3021 | } |
| 3022 | |
| 3023 | *rule_nr = 50; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3024 | peer = device->p_uuid[UI_BITMAP] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3025 | if (self == peer) |
| 3026 | return -1; |
| 3027 | |
| 3028 | *rule_nr = 51; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3029 | peer = device->p_uuid[UI_HISTORY_START] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3030 | if (self == peer) { |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 3031 | if (connection->agreed_pro_version < 96 ? |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3032 | (device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == |
| 3033 | (device->p_uuid[UI_HISTORY_START + 1] & ~((u64)1)) : |
| 3034 | peer + UUID_NEW_BM_OFFSET == (device->p_uuid[UI_BITMAP] & ~((u64)1))) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3035 | /* The last P_SYNC_UUID did not get though. Undo the last start of |
| 3036 | resync as sync source modifications of the peer's UUIDs. */ |
| 3037 | |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 3038 | if (connection->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 3039 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3040 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3041 | device->p_uuid[UI_BITMAP] = device->p_uuid[UI_HISTORY_START]; |
| 3042 | device->p_uuid[UI_HISTORY_START] = device->p_uuid[UI_HISTORY_START + 1]; |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 3043 | |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3044 | drbd_info(device, "Lost last syncUUID packet, corrected:\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3045 | drbd_uuid_dump(device, "peer", device->p_uuid, device->p_uuid[UI_SIZE], device->p_uuid[UI_FLAGS]); |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 3046 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3047 | return -1; |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | *rule_nr = 60; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3052 | self = device->ldev->md.uuid[UI_CURRENT] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3053 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3054 | peer = device->p_uuid[i] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3055 | if (self == peer) |
| 3056 | return -2; |
| 3057 | } |
| 3058 | |
| 3059 | *rule_nr = 70; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3060 | self = device->ldev->md.uuid[UI_BITMAP] & ~((u64)1); |
| 3061 | peer = device->p_uuid[UI_CURRENT] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3062 | if (self == peer) |
| 3063 | return 1; |
| 3064 | |
| 3065 | *rule_nr = 71; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3066 | self = device->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3067 | if (self == peer) { |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 3068 | if (connection->agreed_pro_version < 96 ? |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3069 | (device->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == |
| 3070 | (device->p_uuid[UI_HISTORY_START] & ~((u64)1)) : |
| 3071 | self + UUID_NEW_BM_OFFSET == (device->ldev->md.uuid[UI_BITMAP] & ~((u64)1))) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3072 | /* The last P_SYNC_UUID did not get though. Undo the last start of |
| 3073 | resync as sync source modifications of our UUIDs. */ |
| 3074 | |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 3075 | if (connection->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 3076 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3077 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3078 | __drbd_uuid_set(device, UI_BITMAP, device->ldev->md.uuid[UI_HISTORY_START]); |
| 3079 | __drbd_uuid_set(device, UI_HISTORY_START, device->ldev->md.uuid[UI_HISTORY_START + 1]); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3080 | |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3081 | drbd_info(device, "Last syncUUID did not get through, corrected:\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3082 | drbd_uuid_dump(device, "self", device->ldev->md.uuid, |
| 3083 | device->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(device) : 0, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3084 | |
| 3085 | return 1; |
| 3086 | } |
| 3087 | } |
| 3088 | |
| 3089 | |
| 3090 | *rule_nr = 80; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3091 | peer = device->p_uuid[UI_CURRENT] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3092 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3093 | self = device->ldev->md.uuid[i] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3094 | if (self == peer) |
| 3095 | return 2; |
| 3096 | } |
| 3097 | |
| 3098 | *rule_nr = 90; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3099 | self = device->ldev->md.uuid[UI_BITMAP] & ~((u64)1); |
| 3100 | peer = device->p_uuid[UI_BITMAP] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3101 | if (self == peer && self != ((u64)0)) |
| 3102 | return 100; |
| 3103 | |
| 3104 | *rule_nr = 100; |
| 3105 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3106 | self = device->ldev->md.uuid[i] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3107 | for (j = UI_HISTORY_START; j <= UI_HISTORY_END; j++) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3108 | peer = device->p_uuid[j] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3109 | if (self == peer) |
| 3110 | return -100; |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | return -1000; |
| 3115 | } |
| 3116 | |
| 3117 | /* drbd_sync_handshake() returns the new conn state on success, or |
| 3118 | CONN_MASK (-1) on failure. |
| 3119 | */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3120 | static enum drbd_conns drbd_sync_handshake(struct drbd_peer_device *peer_device, |
| 3121 | enum drbd_role peer_role, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3122 | enum drbd_disk_state peer_disk) __must_hold(local) |
| 3123 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3124 | struct drbd_device *device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3125 | enum drbd_conns rv = C_MASK; |
| 3126 | enum drbd_disk_state mydisk; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 3127 | struct net_conf *nc; |
Andreas Gruenbacher | 6dff290 | 2011-06-28 14:18:12 +0200 | [diff] [blame] | 3128 | int hg, rule_nr, rr_conflict, tentative; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3129 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3130 | mydisk = device->state.disk; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3131 | if (mydisk == D_NEGOTIATING) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3132 | mydisk = device->new_state_tmp.disk; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3133 | |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3134 | drbd_info(device, "drbd_sync_handshake:\n"); |
Philipp Reisner | 9f2247b | 2012-08-16 14:25:58 +0200 | [diff] [blame] | 3135 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3136 | spin_lock_irq(&device->ldev->md.uuid_lock); |
| 3137 | drbd_uuid_dump(device, "self", device->ldev->md.uuid, device->comm_bm_set, 0); |
| 3138 | drbd_uuid_dump(device, "peer", device->p_uuid, |
| 3139 | device->p_uuid[UI_SIZE], device->p_uuid[UI_FLAGS]); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3140 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3141 | hg = drbd_uuid_compare(device, &rule_nr); |
| 3142 | spin_unlock_irq(&device->ldev->md.uuid_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3143 | |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3144 | drbd_info(device, "uuid_compare()=%d by rule %d\n", hg, rule_nr); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3145 | |
| 3146 | if (hg == -1000) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3147 | drbd_alert(device, "Unrelated data, aborting!\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3148 | return C_MASK; |
| 3149 | } |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 3150 | if (hg < -1000) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3151 | drbd_alert(device, "To resolve this both sides have to support at least protocol %d\n", -hg - 1000); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3152 | return C_MASK; |
| 3153 | } |
| 3154 | |
| 3155 | if ((mydisk == D_INCONSISTENT && peer_disk > D_INCONSISTENT) || |
| 3156 | (peer_disk == D_INCONSISTENT && mydisk > D_INCONSISTENT)) { |
| 3157 | int f = (hg == -100) || abs(hg) == 2; |
| 3158 | hg = mydisk > D_INCONSISTENT ? 1 : -1; |
| 3159 | if (f) |
| 3160 | hg = hg*2; |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3161 | drbd_info(device, "Becoming sync %s due to disk states.\n", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3162 | hg > 0 ? "source" : "target"); |
| 3163 | } |
| 3164 | |
Adam Gandelman | 3a11a48 | 2010-04-08 16:48:23 -0700 | [diff] [blame] | 3165 | if (abs(hg) == 100) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3166 | drbd_khelper(device, "initial-split-brain"); |
Adam Gandelman | 3a11a48 | 2010-04-08 16:48:23 -0700 | [diff] [blame] | 3167 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 3168 | rcu_read_lock(); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3169 | nc = rcu_dereference(peer_device->connection->net_conf); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 3170 | |
| 3171 | if (hg == 100 || (hg == -100 && nc->always_asbp)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3172 | int pcount = (device->state.role == R_PRIMARY) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3173 | + (peer_role == R_PRIMARY); |
| 3174 | int forced = (hg == -100); |
| 3175 | |
| 3176 | switch (pcount) { |
| 3177 | case 0: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3178 | hg = drbd_asb_recover_0p(peer_device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3179 | break; |
| 3180 | case 1: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3181 | hg = drbd_asb_recover_1p(peer_device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3182 | break; |
| 3183 | case 2: |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3184 | hg = drbd_asb_recover_2p(peer_device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3185 | break; |
| 3186 | } |
| 3187 | if (abs(hg) < 100) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3188 | drbd_warn(device, "Split-Brain detected, %d primaries, " |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3189 | "automatically solved. Sync from %s node\n", |
| 3190 | pcount, (hg < 0) ? "peer" : "this"); |
| 3191 | if (forced) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3192 | drbd_warn(device, "Doing a full sync, since" |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3193 | " UUIDs where ambiguous.\n"); |
| 3194 | hg = hg*2; |
| 3195 | } |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | if (hg == -100) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3200 | if (test_bit(DISCARD_MY_DATA, &device->flags) && !(device->p_uuid[UI_FLAGS]&1)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3201 | hg = -1; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3202 | if (!test_bit(DISCARD_MY_DATA, &device->flags) && (device->p_uuid[UI_FLAGS]&1)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3203 | hg = 1; |
| 3204 | |
| 3205 | if (abs(hg) < 100) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3206 | drbd_warn(device, "Split-Brain detected, manually solved. " |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3207 | "Sync from %s node\n", |
| 3208 | (hg < 0) ? "peer" : "this"); |
| 3209 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 3210 | rr_conflict = nc->rr_conflict; |
Andreas Gruenbacher | 6dff290 | 2011-06-28 14:18:12 +0200 | [diff] [blame] | 3211 | tentative = nc->tentative; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 3212 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3213 | |
| 3214 | if (hg == -100) { |
Lars Ellenberg | 580b976 | 2010-02-26 23:15:23 +0100 | [diff] [blame] | 3215 | /* FIXME this log message is not correct if we end up here |
| 3216 | * after an attempted attach on a diskless node. |
| 3217 | * We just refuse to attach -- well, we drop the "connection" |
| 3218 | * to that disk, in a way... */ |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3219 | drbd_alert(device, "Split-Brain detected but unresolved, dropping connection!\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3220 | drbd_khelper(device, "split-brain"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3221 | return C_MASK; |
| 3222 | } |
| 3223 | |
| 3224 | if (hg > 0 && mydisk <= D_INCONSISTENT) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3225 | drbd_err(device, "I shall become SyncSource, but I am inconsistent!\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3226 | return C_MASK; |
| 3227 | } |
| 3228 | |
| 3229 | if (hg < 0 && /* by intention we do not use mydisk here. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3230 | device->state.role == R_PRIMARY && device->state.disk >= D_CONSISTENT) { |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 3231 | switch (rr_conflict) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3232 | case ASB_CALL_HELPER: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3233 | drbd_khelper(device, "pri-lost"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3234 | /* fall through */ |
| 3235 | case ASB_DISCONNECT: |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3236 | drbd_err(device, "I shall become SyncTarget, but I am primary!\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3237 | return C_MASK; |
| 3238 | case ASB_VIOLENTLY: |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3239 | drbd_warn(device, "Becoming SyncTarget, violating the stable-data" |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3240 | "assumption\n"); |
| 3241 | } |
| 3242 | } |
| 3243 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3244 | if (tentative || test_bit(CONN_DRY_RUN, &peer_device->connection->flags)) { |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 3245 | if (hg == 0) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3246 | drbd_info(device, "dry-run connect: No resync, would become Connected immediately.\n"); |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 3247 | else |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3248 | drbd_info(device, "dry-run connect: Would become %s, doing a %s resync.", |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 3249 | drbd_conn_str(hg > 0 ? C_SYNC_SOURCE : C_SYNC_TARGET), |
| 3250 | abs(hg) >= 2 ? "full" : "bit-map based"); |
| 3251 | return C_MASK; |
| 3252 | } |
| 3253 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3254 | if (abs(hg) >= 2) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3255 | drbd_info(device, "Writing the whole bitmap, full sync required after drbd_sync_handshake.\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3256 | if (drbd_bitmap_io(device, &drbd_bmio_set_n_write, "set_n_write from sync_handshake", |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 3257 | BM_LOCKED_SET_ALLOWED)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3258 | return C_MASK; |
| 3259 | } |
| 3260 | |
| 3261 | if (hg > 0) { /* become sync source. */ |
| 3262 | rv = C_WF_BITMAP_S; |
| 3263 | } else if (hg < 0) { /* become sync target */ |
| 3264 | rv = C_WF_BITMAP_T; |
| 3265 | } else { |
| 3266 | rv = C_CONNECTED; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3267 | if (drbd_bm_total_weight(device)) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3268 | drbd_info(device, "No resync, but %lu bits in bitmap!\n", |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3269 | drbd_bm_total_weight(device)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | return rv; |
| 3274 | } |
| 3275 | |
Philipp Reisner | f179d76 | 2011-05-16 17:31:47 +0200 | [diff] [blame] | 3276 | static enum drbd_after_sb_p convert_after_sb(enum drbd_after_sb_p peer) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3277 | { |
| 3278 | /* ASB_DISCARD_REMOTE - ASB_DISCARD_LOCAL is valid */ |
Philipp Reisner | f179d76 | 2011-05-16 17:31:47 +0200 | [diff] [blame] | 3279 | if (peer == ASB_DISCARD_REMOTE) |
| 3280 | return ASB_DISCARD_LOCAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3281 | |
| 3282 | /* any other things with ASB_DISCARD_REMOTE or ASB_DISCARD_LOCAL are invalid */ |
Philipp Reisner | f179d76 | 2011-05-16 17:31:47 +0200 | [diff] [blame] | 3283 | if (peer == ASB_DISCARD_LOCAL) |
| 3284 | return ASB_DISCARD_REMOTE; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3285 | |
| 3286 | /* everything else is valid if they are equal on both sides. */ |
Philipp Reisner | f179d76 | 2011-05-16 17:31:47 +0200 | [diff] [blame] | 3287 | return peer; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3288 | } |
| 3289 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3290 | static int receive_protocol(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3291 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3292 | struct p_protocol *p = pi->data; |
Philipp Reisner | 036b17e | 2011-05-16 17:38:11 +0200 | [diff] [blame] | 3293 | enum drbd_after_sb_p p_after_sb_0p, p_after_sb_1p, p_after_sb_2p; |
| 3294 | int p_proto, p_discard_my_data, p_two_primaries, cf; |
| 3295 | struct net_conf *nc, *old_net_conf, *new_net_conf = NULL; |
| 3296 | char integrity_alg[SHARED_SECRET_MAX] = ""; |
Andreas Gruenbacher | accdbcc | 2011-07-15 17:41:09 +0200 | [diff] [blame] | 3297 | struct crypto_hash *peer_integrity_tfm = NULL; |
Philipp Reisner | 7aca6c7 | 2011-05-17 10:12:56 +0200 | [diff] [blame] | 3298 | void *int_dig_in = NULL, *int_dig_vv = NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3299 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3300 | p_proto = be32_to_cpu(p->protocol); |
| 3301 | p_after_sb_0p = be32_to_cpu(p->after_sb_0p); |
| 3302 | p_after_sb_1p = be32_to_cpu(p->after_sb_1p); |
| 3303 | p_after_sb_2p = be32_to_cpu(p->after_sb_2p); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3304 | p_two_primaries = be32_to_cpu(p->two_primaries); |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 3305 | cf = be32_to_cpu(p->conn_flags); |
Andreas Gruenbacher | 6139f60 | 2011-05-06 20:00:02 +0200 | [diff] [blame] | 3306 | p_discard_my_data = cf & CF_DISCARD_MY_DATA; |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 3307 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3308 | if (connection->agreed_pro_version >= 87) { |
Andreas Gruenbacher | 86db061 | 2011-04-28 15:24:18 +0200 | [diff] [blame] | 3309 | int err; |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 3310 | |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 3311 | if (pi->size > sizeof(integrity_alg)) |
Andreas Gruenbacher | 86db061 | 2011-04-28 15:24:18 +0200 | [diff] [blame] | 3312 | return -EIO; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3313 | err = drbd_recv_all(connection, integrity_alg, pi->size); |
Andreas Gruenbacher | 86db061 | 2011-04-28 15:24:18 +0200 | [diff] [blame] | 3314 | if (err) |
| 3315 | return err; |
Philipp Reisner | 036b17e | 2011-05-16 17:38:11 +0200 | [diff] [blame] | 3316 | integrity_alg[SHARED_SECRET_MAX - 1] = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3319 | if (pi->cmd != P_PROTOCOL_UPDATE) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3320 | clear_bit(CONN_DRY_RUN, &connection->flags); |
Philipp Reisner | 036b17e | 2011-05-16 17:38:11 +0200 | [diff] [blame] | 3321 | |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3322 | if (cf & CF_DRY_RUN) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3323 | set_bit(CONN_DRY_RUN, &connection->flags); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3324 | |
| 3325 | rcu_read_lock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3326 | nc = rcu_dereference(connection->net_conf); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3327 | |
| 3328 | if (p_proto != nc->wire_protocol) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3329 | drbd_err(connection, "incompatible %s settings\n", "protocol"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3330 | goto disconnect_rcu_unlock; |
| 3331 | } |
| 3332 | |
| 3333 | if (convert_after_sb(p_after_sb_0p) != nc->after_sb_0p) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3334 | drbd_err(connection, "incompatible %s settings\n", "after-sb-0pri"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3335 | goto disconnect_rcu_unlock; |
| 3336 | } |
| 3337 | |
| 3338 | if (convert_after_sb(p_after_sb_1p) != nc->after_sb_1p) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3339 | drbd_err(connection, "incompatible %s settings\n", "after-sb-1pri"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3340 | goto disconnect_rcu_unlock; |
| 3341 | } |
| 3342 | |
| 3343 | if (convert_after_sb(p_after_sb_2p) != nc->after_sb_2p) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3344 | drbd_err(connection, "incompatible %s settings\n", "after-sb-2pri"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3345 | goto disconnect_rcu_unlock; |
| 3346 | } |
| 3347 | |
| 3348 | if (p_discard_my_data && nc->discard_my_data) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3349 | drbd_err(connection, "incompatible %s settings\n", "discard-my-data"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3350 | goto disconnect_rcu_unlock; |
| 3351 | } |
| 3352 | |
| 3353 | if (p_two_primaries != nc->two_primaries) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3354 | drbd_err(connection, "incompatible %s settings\n", "allow-two-primaries"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3355 | goto disconnect_rcu_unlock; |
| 3356 | } |
| 3357 | |
| 3358 | if (strcmp(integrity_alg, nc->integrity_alg)) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3359 | drbd_err(connection, "incompatible %s settings\n", "data-integrity-alg"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3360 | goto disconnect_rcu_unlock; |
| 3361 | } |
| 3362 | |
| 3363 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3366 | if (integrity_alg[0]) { |
| 3367 | int hash_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3368 | |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3369 | /* |
| 3370 | * We can only change the peer data integrity algorithm |
| 3371 | * here. Changing our own data integrity algorithm |
| 3372 | * requires that we send a P_PROTOCOL_UPDATE packet at |
| 3373 | * the same time; otherwise, the peer has no way to |
| 3374 | * tell between which packets the algorithm should |
| 3375 | * change. |
| 3376 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3377 | |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3378 | peer_integrity_tfm = crypto_alloc_hash(integrity_alg, 0, CRYPTO_ALG_ASYNC); |
| 3379 | if (!peer_integrity_tfm) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3380 | drbd_err(connection, "peer data-integrity-alg %s not supported\n", |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3381 | integrity_alg); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3382 | goto disconnect; |
| 3383 | } |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3384 | |
| 3385 | hash_size = crypto_hash_digestsize(peer_integrity_tfm); |
| 3386 | int_dig_in = kmalloc(hash_size, GFP_KERNEL); |
| 3387 | int_dig_vv = kmalloc(hash_size, GFP_KERNEL); |
| 3388 | if (!(int_dig_in && int_dig_vv)) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3389 | drbd_err(connection, "Allocation of buffers for data integrity checking failed\n"); |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3390 | goto disconnect; |
| 3391 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3394 | new_net_conf = kmalloc(sizeof(struct net_conf), GFP_KERNEL); |
| 3395 | if (!new_net_conf) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3396 | drbd_err(connection, "Allocation of new net_conf failed\n"); |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3397 | goto disconnect; |
| 3398 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3399 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3400 | mutex_lock(&connection->data.mutex); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 3401 | mutex_lock(&connection->resource->conf_update); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3402 | old_net_conf = connection->net_conf; |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3403 | *new_net_conf = *old_net_conf; |
| 3404 | |
| 3405 | new_net_conf->wire_protocol = p_proto; |
| 3406 | new_net_conf->after_sb_0p = convert_after_sb(p_after_sb_0p); |
| 3407 | new_net_conf->after_sb_1p = convert_after_sb(p_after_sb_1p); |
| 3408 | new_net_conf->after_sb_2p = convert_after_sb(p_after_sb_2p); |
| 3409 | new_net_conf->two_primaries = p_two_primaries; |
| 3410 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3411 | rcu_assign_pointer(connection->net_conf, new_net_conf); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 3412 | mutex_unlock(&connection->resource->conf_update); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3413 | mutex_unlock(&connection->data.mutex); |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3414 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3415 | crypto_free_hash(connection->peer_integrity_tfm); |
| 3416 | kfree(connection->int_dig_in); |
| 3417 | kfree(connection->int_dig_vv); |
| 3418 | connection->peer_integrity_tfm = peer_integrity_tfm; |
| 3419 | connection->int_dig_in = int_dig_in; |
| 3420 | connection->int_dig_vv = int_dig_vv; |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3421 | |
| 3422 | if (strcmp(old_net_conf->integrity_alg, integrity_alg)) |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3423 | drbd_info(connection, "peer data-integrity-alg: %s\n", |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3424 | integrity_alg[0] ? integrity_alg : "(none)"); |
| 3425 | |
| 3426 | synchronize_rcu(); |
| 3427 | kfree(old_net_conf); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3428 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3429 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 3430 | disconnect_rcu_unlock: |
| 3431 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3432 | disconnect: |
Andreas Gruenbacher | b792c35 | 2011-07-15 16:48:49 +0200 | [diff] [blame] | 3433 | crypto_free_hash(peer_integrity_tfm); |
Philipp Reisner | 036b17e | 2011-05-16 17:38:11 +0200 | [diff] [blame] | 3434 | kfree(int_dig_in); |
| 3435 | kfree(int_dig_vv); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3436 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3437 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3438 | } |
| 3439 | |
| 3440 | /* helper function |
| 3441 | * input: alg name, feature name |
| 3442 | * return: NULL (alg name was "") |
| 3443 | * ERR_PTR(error) if something goes wrong |
| 3444 | * or the crypto hash ptr, if it worked out ok. */ |
Lars Ellenberg | 8ce953a | 2014-02-27 09:46:18 +0100 | [diff] [blame] | 3445 | static struct crypto_hash *drbd_crypto_alloc_digest_safe(const struct drbd_device *device, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3446 | const char *alg, const char *name) |
| 3447 | { |
| 3448 | struct crypto_hash *tfm; |
| 3449 | |
| 3450 | if (!alg[0]) |
| 3451 | return NULL; |
| 3452 | |
| 3453 | tfm = crypto_alloc_hash(alg, 0, CRYPTO_ALG_ASYNC); |
| 3454 | if (IS_ERR(tfm)) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3455 | drbd_err(device, "Can not allocate \"%s\" as %s (reason: %ld)\n", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3456 | alg, name, PTR_ERR(tfm)); |
| 3457 | return tfm; |
| 3458 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3459 | return tfm; |
| 3460 | } |
| 3461 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3462 | static int ignore_remaining_packet(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3463 | { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3464 | void *buffer = connection->data.rbuf; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3465 | int size = pi->size; |
| 3466 | |
| 3467 | while (size) { |
| 3468 | int s = min_t(int, size, DRBD_SOCKET_BUFFER_SIZE); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3469 | s = drbd_recv(connection, buffer, s); |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3470 | if (s <= 0) { |
| 3471 | if (s < 0) |
| 3472 | return s; |
| 3473 | break; |
| 3474 | } |
| 3475 | size -= s; |
| 3476 | } |
| 3477 | if (size) |
| 3478 | return -EIO; |
| 3479 | return 0; |
| 3480 | } |
| 3481 | |
| 3482 | /* |
| 3483 | * config_unknown_volume - device configuration command for unknown volume |
| 3484 | * |
| 3485 | * When a device is added to an existing connection, the node on which the |
| 3486 | * device is added first will send configuration commands to its peer but the |
| 3487 | * peer will not know about the device yet. It will warn and ignore these |
| 3488 | * commands. Once the device is added on the second node, the second node will |
| 3489 | * send the same device configuration commands, but in the other direction. |
| 3490 | * |
| 3491 | * (We can also end up here if drbd is misconfigured.) |
| 3492 | */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3493 | static int config_unknown_volume(struct drbd_connection *connection, struct packet_info *pi) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3494 | { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 3495 | drbd_warn(connection, "%s packet received for volume %u, which is not configured locally\n", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 3496 | cmdname(pi->cmd), pi->vnr); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3497 | return ignore_remaining_packet(connection, pi); |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3498 | } |
| 3499 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3500 | static int receive_SyncParam(struct drbd_connection *connection, struct packet_info *pi) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3501 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3502 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3503 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3504 | struct p_rs_param_95 *p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3505 | unsigned int header_size, data_size, exp_max_sz; |
| 3506 | struct crypto_hash *verify_tfm = NULL; |
| 3507 | struct crypto_hash *csums_tfm = NULL; |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3508 | struct net_conf *old_net_conf, *new_net_conf = NULL; |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3509 | struct disk_conf *old_disk_conf = NULL, *new_disk_conf = NULL; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3510 | const int apv = connection->agreed_pro_version; |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3511 | struct fifo_buffer *old_plan = NULL, *new_plan = NULL; |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 3512 | int fifo_size = 0; |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3513 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3514 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3515 | peer_device = conn_peer_device(connection, pi->vnr); |
| 3516 | if (!peer_device) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3517 | return config_unknown_volume(connection, pi); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3518 | device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3519 | |
| 3520 | exp_max_sz = apv <= 87 ? sizeof(struct p_rs_param) |
| 3521 | : apv == 88 ? sizeof(struct p_rs_param) |
| 3522 | + SHARED_SECRET_MAX |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3523 | : apv <= 94 ? sizeof(struct p_rs_param_89) |
| 3524 | : /* apv >= 95 */ sizeof(struct p_rs_param_95); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3525 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3526 | if (pi->size > exp_max_sz) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3527 | drbd_err(device, "SyncParam packet too long: received %u, expected <= %u bytes\n", |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3528 | pi->size, exp_max_sz); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3529 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | if (apv <= 88) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3533 | header_size = sizeof(struct p_rs_param); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3534 | data_size = pi->size - header_size; |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3535 | } else if (apv <= 94) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3536 | header_size = sizeof(struct p_rs_param_89); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3537 | data_size = pi->size - header_size; |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 3538 | D_ASSERT(device, data_size == 0); |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3539 | } else { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3540 | header_size = sizeof(struct p_rs_param_95); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3541 | data_size = pi->size - header_size; |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 3542 | D_ASSERT(device, data_size == 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | /* initialize verify_alg and csums_alg */ |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3546 | p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3547 | memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); |
| 3548 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3549 | err = drbd_recv_all(peer_device->connection, p, header_size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3550 | if (err) |
| 3551 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3552 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 3553 | mutex_lock(&connection->resource->conf_update); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3554 | old_net_conf = peer_device->connection->net_conf; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3555 | if (get_ldev(device)) { |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3556 | new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL); |
| 3557 | if (!new_disk_conf) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3558 | put_ldev(device); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 3559 | mutex_unlock(&connection->resource->conf_update); |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3560 | drbd_err(device, "Allocation of new disk_conf failed\n"); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3561 | return -ENOMEM; |
| 3562 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3563 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3564 | old_disk_conf = device->ldev->disk_conf; |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3565 | *new_disk_conf = *old_disk_conf; |
| 3566 | |
Andreas Gruenbacher | 6394b93 | 2011-05-11 14:29:52 +0200 | [diff] [blame] | 3567 | new_disk_conf->resync_rate = be32_to_cpu(p->resync_rate); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3568 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3569 | |
| 3570 | if (apv >= 88) { |
| 3571 | if (apv == 88) { |
Philipp Reisner | 5de7382 | 2012-03-28 10:17:32 +0200 | [diff] [blame] | 3572 | if (data_size > SHARED_SECRET_MAX || data_size == 0) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3573 | drbd_err(device, "verify-alg of wrong size, " |
Philipp Reisner | 5de7382 | 2012-03-28 10:17:32 +0200 | [diff] [blame] | 3574 | "peer wants %u, accepting only up to %u byte\n", |
| 3575 | data_size, SHARED_SECRET_MAX); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3576 | err = -EIO; |
| 3577 | goto reconnect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3578 | } |
| 3579 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3580 | err = drbd_recv_all(peer_device->connection, p->verify_alg, data_size); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3581 | if (err) |
| 3582 | goto reconnect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3583 | /* we expect NUL terminated string */ |
| 3584 | /* but just in case someone tries to be evil */ |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 3585 | D_ASSERT(device, p->verify_alg[data_size-1] == 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3586 | p->verify_alg[data_size-1] = 0; |
| 3587 | |
| 3588 | } else /* apv >= 89 */ { |
| 3589 | /* we still expect NUL terminated strings */ |
| 3590 | /* but just in case someone tries to be evil */ |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 3591 | D_ASSERT(device, p->verify_alg[SHARED_SECRET_MAX-1] == 0); |
| 3592 | D_ASSERT(device, p->csums_alg[SHARED_SECRET_MAX-1] == 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3593 | p->verify_alg[SHARED_SECRET_MAX-1] = 0; |
| 3594 | p->csums_alg[SHARED_SECRET_MAX-1] = 0; |
| 3595 | } |
| 3596 | |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3597 | if (strcmp(old_net_conf->verify_alg, p->verify_alg)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3598 | if (device->state.conn == C_WF_REPORT_PARAMS) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3599 | drbd_err(device, "Different verify-alg settings. me=\"%s\" peer=\"%s\"\n", |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3600 | old_net_conf->verify_alg, p->verify_alg); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3601 | goto disconnect; |
| 3602 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3603 | verify_tfm = drbd_crypto_alloc_digest_safe(device, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3604 | p->verify_alg, "verify-alg"); |
| 3605 | if (IS_ERR(verify_tfm)) { |
| 3606 | verify_tfm = NULL; |
| 3607 | goto disconnect; |
| 3608 | } |
| 3609 | } |
| 3610 | |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3611 | if (apv >= 89 && strcmp(old_net_conf->csums_alg, p->csums_alg)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3612 | if (device->state.conn == C_WF_REPORT_PARAMS) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3613 | drbd_err(device, "Different csums-alg settings. me=\"%s\" peer=\"%s\"\n", |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3614 | old_net_conf->csums_alg, p->csums_alg); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3615 | goto disconnect; |
| 3616 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3617 | csums_tfm = drbd_crypto_alloc_digest_safe(device, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3618 | p->csums_alg, "csums-alg"); |
| 3619 | if (IS_ERR(csums_tfm)) { |
| 3620 | csums_tfm = NULL; |
| 3621 | goto disconnect; |
| 3622 | } |
| 3623 | } |
| 3624 | |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3625 | if (apv > 94 && new_disk_conf) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3626 | new_disk_conf->c_plan_ahead = be32_to_cpu(p->c_plan_ahead); |
| 3627 | new_disk_conf->c_delay_target = be32_to_cpu(p->c_delay_target); |
| 3628 | new_disk_conf->c_fill_target = be32_to_cpu(p->c_fill_target); |
| 3629 | new_disk_conf->c_max_rate = be32_to_cpu(p->c_max_rate); |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 3630 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3631 | fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3632 | if (fifo_size != device->rs_plan_s->size) { |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3633 | new_plan = fifo_alloc(fifo_size); |
| 3634 | if (!new_plan) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3635 | drbd_err(device, "kmalloc of fifo_buffer failed"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3636 | put_ldev(device); |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 3637 | goto disconnect; |
| 3638 | } |
| 3639 | } |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3640 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3641 | |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3642 | if (verify_tfm || csums_tfm) { |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3643 | new_net_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL); |
| 3644 | if (!new_net_conf) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3645 | drbd_err(device, "Allocation of new net_conf failed\n"); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3646 | goto disconnect; |
| 3647 | } |
| 3648 | |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3649 | *new_net_conf = *old_net_conf; |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3650 | |
| 3651 | if (verify_tfm) { |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3652 | strcpy(new_net_conf->verify_alg, p->verify_alg); |
| 3653 | new_net_conf->verify_alg_len = strlen(p->verify_alg) + 1; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3654 | crypto_free_hash(peer_device->connection->verify_tfm); |
| 3655 | peer_device->connection->verify_tfm = verify_tfm; |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3656 | drbd_info(device, "using verify-alg: \"%s\"\n", p->verify_alg); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3657 | } |
| 3658 | if (csums_tfm) { |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3659 | strcpy(new_net_conf->csums_alg, p->csums_alg); |
| 3660 | new_net_conf->csums_alg_len = strlen(p->csums_alg) + 1; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3661 | crypto_free_hash(peer_device->connection->csums_tfm); |
| 3662 | peer_device->connection->csums_tfm = csums_tfm; |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3663 | drbd_info(device, "using csums-alg: \"%s\"\n", p->csums_alg); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3664 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3665 | rcu_assign_pointer(connection->net_conf, new_net_conf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3666 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3667 | } |
| 3668 | |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3669 | if (new_disk_conf) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3670 | rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf); |
| 3671 | put_ldev(device); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3672 | } |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3673 | |
| 3674 | if (new_plan) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3675 | old_plan = device->rs_plan_s; |
| 3676 | rcu_assign_pointer(device->rs_plan_s, new_plan); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3677 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3678 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 3679 | mutex_unlock(&connection->resource->conf_update); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3680 | synchronize_rcu(); |
| 3681 | if (new_net_conf) |
| 3682 | kfree(old_net_conf); |
| 3683 | kfree(old_disk_conf); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3684 | kfree(old_plan); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3685 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3686 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3687 | |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3688 | reconnect: |
| 3689 | if (new_disk_conf) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3690 | put_ldev(device); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3691 | kfree(new_disk_conf); |
| 3692 | } |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 3693 | mutex_unlock(&connection->resource->conf_update); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3694 | return -EIO; |
| 3695 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3696 | disconnect: |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3697 | kfree(new_plan); |
| 3698 | if (new_disk_conf) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3699 | put_ldev(device); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3700 | kfree(new_disk_conf); |
| 3701 | } |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 3702 | mutex_unlock(&connection->resource->conf_update); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3703 | /* just for completeness: actually not needed, |
| 3704 | * as this is not reached if csums_tfm was ok. */ |
| 3705 | crypto_free_hash(csums_tfm); |
| 3706 | /* but free the verify_tfm again, if csums_tfm did not work out */ |
| 3707 | crypto_free_hash(verify_tfm); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3708 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3709 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3712 | /* warn if the arguments differ by more than 12.5% */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3713 | static void warn_if_differ_considerably(struct drbd_device *device, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3714 | const char *s, sector_t a, sector_t b) |
| 3715 | { |
| 3716 | sector_t d; |
| 3717 | if (a == 0 || b == 0) |
| 3718 | return; |
| 3719 | d = (a > b) ? (a - b) : (b - a); |
| 3720 | if (d > (a>>3) || d > (b>>3)) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3721 | drbd_warn(device, "Considerable difference in %s: %llus vs. %llus\n", s, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3722 | (unsigned long long)a, (unsigned long long)b); |
| 3723 | } |
| 3724 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3725 | static int receive_sizes(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3726 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3727 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3728 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3729 | struct p_sizes *p = pi->data; |
Philipp Reisner | e96c963 | 2013-06-25 16:50:07 +0200 | [diff] [blame] | 3730 | enum determine_dev_size dd = DS_UNCHANGED; |
Lars Ellenberg | 6a8d68b | 2014-03-18 12:22:14 +0100 | [diff] [blame] | 3731 | sector_t p_size, p_usize, p_csize, my_usize; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3732 | int ldsc = 0; /* local disk size changed */ |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3733 | enum dds_flags ddsf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3734 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3735 | peer_device = conn_peer_device(connection, pi->vnr); |
| 3736 | if (!peer_device) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3737 | return config_unknown_volume(connection, pi); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3738 | device = peer_device->device; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3739 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3740 | p_size = be64_to_cpu(p->d_size); |
| 3741 | p_usize = be64_to_cpu(p->u_size); |
Lars Ellenberg | 6a8d68b | 2014-03-18 12:22:14 +0100 | [diff] [blame] | 3742 | p_csize = be64_to_cpu(p->c_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3743 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3744 | /* just store the peer's disk size for now. |
| 3745 | * we still need to figure out whether we accept that. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3746 | device->p_size = p_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3747 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3748 | if (get_ldev(device)) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3749 | rcu_read_lock(); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3750 | my_usize = rcu_dereference(device->ldev->disk_conf)->disk_size; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3751 | rcu_read_unlock(); |
| 3752 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3753 | warn_if_differ_considerably(device, "lower level device sizes", |
| 3754 | p_size, drbd_get_max_capacity(device->ldev)); |
| 3755 | warn_if_differ_considerably(device, "user requested size", |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3756 | p_usize, my_usize); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3757 | |
| 3758 | /* if this is the first connect, or an otherwise expected |
| 3759 | * param exchange, choose the minimum */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3760 | if (device->state.conn == C_WF_REPORT_PARAMS) |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3761 | p_usize = min_not_zero(my_usize, p_usize); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3762 | |
| 3763 | /* Never shrink a device with usable data during connect. |
| 3764 | But allow online shrinking if we are connected. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3765 | if (drbd_new_dev_size(device, device->ldev, p_usize, 0) < |
| 3766 | drbd_get_capacity(device->this_bdev) && |
| 3767 | device->state.disk >= D_OUTDATED && |
| 3768 | device->state.conn < C_CONNECTED) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3769 | drbd_err(device, "The peer's disk size is too small!\n"); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3770 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3771 | put_ldev(device); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3772 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3773 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3774 | |
| 3775 | if (my_usize != p_usize) { |
| 3776 | struct disk_conf *old_disk_conf, *new_disk_conf = NULL; |
| 3777 | |
| 3778 | new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL); |
| 3779 | if (!new_disk_conf) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3780 | drbd_err(device, "Allocation of new disk_conf failed\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3781 | put_ldev(device); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3782 | return -ENOMEM; |
| 3783 | } |
| 3784 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 3785 | mutex_lock(&connection->resource->conf_update); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3786 | old_disk_conf = device->ldev->disk_conf; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3787 | *new_disk_conf = *old_disk_conf; |
| 3788 | new_disk_conf->disk_size = p_usize; |
| 3789 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3790 | rcu_assign_pointer(device->ldev->disk_conf, new_disk_conf); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 3791 | mutex_unlock(&connection->resource->conf_update); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3792 | synchronize_rcu(); |
| 3793 | kfree(old_disk_conf); |
| 3794 | |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3795 | drbd_info(device, "Peer sets u_size to %lu sectors\n", |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3796 | (unsigned long)my_usize); |
| 3797 | } |
| 3798 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3799 | put_ldev(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3800 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3801 | |
Lars Ellenberg | 20c68fd | 2014-04-28 18:43:25 +0200 | [diff] [blame] | 3802 | device->peer_max_bio_size = be32_to_cpu(p->max_bio_size); |
Lars Ellenberg | 20c68fd | 2014-04-28 18:43:25 +0200 | [diff] [blame] | 3803 | /* Leave drbd_reconsider_max_bio_size() before drbd_determine_dev_size(). |
| 3804 | In case we cleared the QUEUE_FLAG_DISCARD from our queue in |
| 3805 | drbd_reconsider_max_bio_size(), we can be sure that after |
| 3806 | drbd_determine_dev_size() no REQ_DISCARDs are in the queue. */ |
| 3807 | |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3808 | ddsf = be16_to_cpu(p->dds_flags); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3809 | if (get_ldev(device)) { |
Philipp Reisner | 8fe39aa | 2013-11-22 13:22:13 +0100 | [diff] [blame] | 3810 | drbd_reconsider_max_bio_size(device, device->ldev); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3811 | dd = drbd_determine_dev_size(device, ddsf, NULL); |
| 3812 | put_ldev(device); |
Philipp Reisner | e96c963 | 2013-06-25 16:50:07 +0200 | [diff] [blame] | 3813 | if (dd == DS_ERROR) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3814 | return -EIO; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3815 | drbd_md_sync(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3816 | } else { |
Lars Ellenberg | 6a8d68b | 2014-03-18 12:22:14 +0100 | [diff] [blame] | 3817 | /* |
| 3818 | * I am diskless, need to accept the peer's *current* size. |
| 3819 | * I must NOT accept the peers backing disk size, |
| 3820 | * it may have been larger than mine all along... |
| 3821 | * |
| 3822 | * At this point, the peer knows more about my disk, or at |
| 3823 | * least about what we last agreed upon, than myself. |
| 3824 | * So if his c_size is less than his d_size, the most likely |
| 3825 | * reason is that *my* d_size was smaller last time we checked. |
| 3826 | * |
| 3827 | * However, if he sends a zero current size, |
| 3828 | * take his (user-capped or) backing disk size anyways. |
| 3829 | */ |
Philipp Reisner | 8fe39aa | 2013-11-22 13:22:13 +0100 | [diff] [blame] | 3830 | drbd_reconsider_max_bio_size(device, NULL); |
Lars Ellenberg | 6a8d68b | 2014-03-18 12:22:14 +0100 | [diff] [blame] | 3831 | drbd_set_my_capacity(device, p_csize ?: p_usize ?: p_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3832 | } |
| 3833 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3834 | if (get_ldev(device)) { |
| 3835 | if (device->ldev->known_size != drbd_get_capacity(device->ldev->backing_bdev)) { |
| 3836 | device->ldev->known_size = drbd_get_capacity(device->ldev->backing_bdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3837 | ldsc = 1; |
| 3838 | } |
| 3839 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3840 | put_ldev(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3841 | } |
| 3842 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3843 | if (device->state.conn > C_WF_REPORT_PARAMS) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3844 | if (be64_to_cpu(p->c_size) != |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3845 | drbd_get_capacity(device->this_bdev) || ldsc) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3846 | /* we have different sizes, probably peer |
| 3847 | * needs to know my new size... */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3848 | drbd_send_sizes(peer_device, 0, ddsf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3849 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3850 | if (test_and_clear_bit(RESIZE_PENDING, &device->flags) || |
| 3851 | (dd == DS_GREW && device->state.conn == C_CONNECTED)) { |
| 3852 | if (device->state.pdsk >= D_INCONSISTENT && |
| 3853 | device->state.disk >= D_INCONSISTENT) { |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3854 | if (ddsf & DDSF_NO_RESYNC) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3855 | drbd_info(device, "Resync of new storage suppressed with --assume-clean\n"); |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3856 | else |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3857 | resync_after_online_grow(device); |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3858 | } else |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3859 | set_bit(RESYNC_AFTER_NEG, &device->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3860 | } |
| 3861 | } |
| 3862 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3863 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3864 | } |
| 3865 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3866 | static int receive_uuids(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3867 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3868 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3869 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3870 | struct p_uuids *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3871 | u64 *p_uuid; |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3872 | int i, updated_uuids = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3873 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3874 | peer_device = conn_peer_device(connection, pi->vnr); |
| 3875 | if (!peer_device) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3876 | return config_unknown_volume(connection, pi); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3877 | device = peer_device->device; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3878 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3879 | p_uuid = kmalloc(sizeof(u64)*UI_EXTENDED_SIZE, GFP_NOIO); |
Jing Wang | 063eacf | 2012-10-25 15:00:56 +0800 | [diff] [blame] | 3880 | if (!p_uuid) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3881 | drbd_err(device, "kmalloc of p_uuid failed\n"); |
Jing Wang | 063eacf | 2012-10-25 15:00:56 +0800 | [diff] [blame] | 3882 | return false; |
| 3883 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3884 | |
| 3885 | for (i = UI_CURRENT; i < UI_EXTENDED_SIZE; i++) |
| 3886 | p_uuid[i] = be64_to_cpu(p->uuid[i]); |
| 3887 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3888 | kfree(device->p_uuid); |
| 3889 | device->p_uuid = p_uuid; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3890 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3891 | if (device->state.conn < C_CONNECTED && |
| 3892 | device->state.disk < D_INCONSISTENT && |
| 3893 | device->state.role == R_PRIMARY && |
| 3894 | (device->ed_uuid & ~((u64)1)) != (p_uuid[UI_CURRENT] & ~((u64)1))) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3895 | drbd_err(device, "Can only connect to data with current UUID=%016llX\n", |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3896 | (unsigned long long)device->ed_uuid); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3897 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3898 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3901 | if (get_ldev(device)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3902 | int skip_initial_sync = |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3903 | device->state.conn == C_CONNECTED && |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3904 | peer_device->connection->agreed_pro_version >= 90 && |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3905 | device->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3906 | (p_uuid[UI_FLAGS] & 8); |
| 3907 | if (skip_initial_sync) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 3908 | drbd_info(device, "Accepted new current UUID, preparing to skip initial sync\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3909 | drbd_bitmap_io(device, &drbd_bmio_clear_n_write, |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 3910 | "clear_n_write from receive_uuids", |
| 3911 | BM_LOCKED_TEST_ALLOWED); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3912 | _drbd_uuid_set(device, UI_CURRENT, p_uuid[UI_CURRENT]); |
| 3913 | _drbd_uuid_set(device, UI_BITMAP, 0); |
| 3914 | _drbd_set_state(_NS2(device, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE), |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3915 | CS_VERBOSE, NULL); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3916 | drbd_md_sync(device); |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3917 | updated_uuids = 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3918 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3919 | put_ldev(device); |
| 3920 | } else if (device->state.disk < D_INCONSISTENT && |
| 3921 | device->state.role == R_PRIMARY) { |
Philipp Reisner | 18a50fa | 2010-06-21 14:14:15 +0200 | [diff] [blame] | 3922 | /* I am a diskless primary, the peer just created a new current UUID |
| 3923 | for me. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3924 | updated_uuids = drbd_set_ed_uuid(device, p_uuid[UI_CURRENT]); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | /* Before we test for the disk state, we should wait until an eventually |
| 3928 | ongoing cluster wide state change is finished. That is important if |
| 3929 | we are primary and are detaching from our disk. We need to see the |
| 3930 | new disk state... */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3931 | mutex_lock(device->state_mutex); |
| 3932 | mutex_unlock(device->state_mutex); |
| 3933 | if (device->state.conn >= C_CONNECTED && device->state.disk < D_INCONSISTENT) |
| 3934 | updated_uuids |= drbd_set_ed_uuid(device, p_uuid[UI_CURRENT]); |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3935 | |
| 3936 | if (updated_uuids) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3937 | drbd_print_uuids(device, "receiver updated UUIDs to"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3938 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3939 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | /** |
| 3943 | * convert_state() - Converts the peer's view of the cluster state to our point of view |
| 3944 | * @ps: The state as seen by the peer. |
| 3945 | */ |
| 3946 | static union drbd_state convert_state(union drbd_state ps) |
| 3947 | { |
| 3948 | union drbd_state ms; |
| 3949 | |
| 3950 | static enum drbd_conns c_tab[] = { |
Philipp Reisner | 369bea6 | 2011-07-06 23:04:44 +0200 | [diff] [blame] | 3951 | [C_WF_REPORT_PARAMS] = C_WF_REPORT_PARAMS, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3952 | [C_CONNECTED] = C_CONNECTED, |
| 3953 | |
| 3954 | [C_STARTING_SYNC_S] = C_STARTING_SYNC_T, |
| 3955 | [C_STARTING_SYNC_T] = C_STARTING_SYNC_S, |
| 3956 | [C_DISCONNECTING] = C_TEAR_DOWN, /* C_NETWORK_FAILURE, */ |
| 3957 | [C_VERIFY_S] = C_VERIFY_T, |
| 3958 | [C_MASK] = C_MASK, |
| 3959 | }; |
| 3960 | |
| 3961 | ms.i = ps.i; |
| 3962 | |
| 3963 | ms.conn = c_tab[ps.conn]; |
| 3964 | ms.peer = ps.role; |
| 3965 | ms.role = ps.peer; |
| 3966 | ms.pdsk = ps.disk; |
| 3967 | ms.disk = ps.pdsk; |
| 3968 | ms.peer_isp = (ps.aftr_isp | ps.user_isp); |
| 3969 | |
| 3970 | return ms; |
| 3971 | } |
| 3972 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 3973 | static int receive_req_state(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3974 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3975 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3976 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3977 | struct p_req_state *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3978 | union drbd_state mask, val; |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 3979 | enum drbd_state_rv rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3980 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3981 | peer_device = conn_peer_device(connection, pi->vnr); |
| 3982 | if (!peer_device) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3983 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3984 | device = peer_device->device; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3985 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3986 | mask.i = be32_to_cpu(p->mask); |
| 3987 | val.i = be32_to_cpu(p->val); |
| 3988 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 3989 | if (test_bit(RESOLVE_CONFLICTS, &peer_device->connection->flags) && |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3990 | mutex_is_locked(device->state_mutex)) { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3991 | drbd_send_sr_reply(peer_device, SS_CONCURRENT_ST_CHG); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3992 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3993 | } |
| 3994 | |
| 3995 | mask = convert_state(mask); |
| 3996 | val = convert_state(val); |
| 3997 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 3998 | rv = drbd_change_state(device, CS_VERBOSE, mask, val); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 3999 | drbd_send_sr_reply(peer_device, rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4000 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4001 | drbd_md_sync(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4002 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4003 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4004 | } |
| 4005 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4006 | static int receive_req_conn_state(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4007 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4008 | struct p_req_state *p = pi->data; |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 4009 | union drbd_state mask, val; |
| 4010 | enum drbd_state_rv rv; |
| 4011 | |
| 4012 | mask.i = be32_to_cpu(p->mask); |
| 4013 | val.i = be32_to_cpu(p->val); |
| 4014 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4015 | if (test_bit(RESOLVE_CONFLICTS, &connection->flags) && |
| 4016 | mutex_is_locked(&connection->cstate_mutex)) { |
| 4017 | conn_send_sr_reply(connection, SS_CONCURRENT_ST_CHG); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4018 | return 0; |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | mask = convert_state(mask); |
| 4022 | val = convert_state(val); |
| 4023 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4024 | rv = conn_request_state(connection, mask, val, CS_VERBOSE | CS_LOCAL_ONLY | CS_IGN_OUTD_FAIL); |
| 4025 | conn_send_sr_reply(connection, rv); |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 4026 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4027 | return 0; |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 4028 | } |
| 4029 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4030 | static int receive_state(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4031 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4032 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4033 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4034 | struct p_state *p = pi->data; |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4035 | union drbd_state os, ns, peer_state; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4036 | enum drbd_disk_state real_peer_disk; |
Philipp Reisner | 65d922c | 2010-06-16 16:18:09 +0200 | [diff] [blame] | 4037 | enum chg_state_flags cs_flags; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4038 | int rv; |
| 4039 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4040 | peer_device = conn_peer_device(connection, pi->vnr); |
| 4041 | if (!peer_device) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4042 | return config_unknown_volume(connection, pi); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4043 | device = peer_device->device; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4044 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4045 | peer_state.i = be32_to_cpu(p->state); |
| 4046 | |
| 4047 | real_peer_disk = peer_state.disk; |
| 4048 | if (peer_state.disk == D_NEGOTIATING) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4049 | real_peer_disk = device->p_uuid[UI_FLAGS] & 4 ? D_INCONSISTENT : D_CONSISTENT; |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4050 | drbd_info(device, "real peer disk state = %s\n", drbd_disk_str(real_peer_disk)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 4053 | spin_lock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4054 | retry: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4055 | os = ns = drbd_read_state(device); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 4056 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4057 | |
Lars Ellenberg | 545752d | 2011-12-05 14:39:25 +0100 | [diff] [blame] | 4058 | /* If some other part of the code (asender thread, timeout) |
| 4059 | * already decided to close the connection again, |
| 4060 | * we must not "re-establish" it here. */ |
| 4061 | if (os.conn <= C_TEAR_DOWN) |
Lars Ellenberg | 58ffa58 | 2012-07-26 14:09:49 +0200 | [diff] [blame] | 4062 | return -ECONNRESET; |
Lars Ellenberg | 545752d | 2011-12-05 14:39:25 +0100 | [diff] [blame] | 4063 | |
Lars Ellenberg | 40424e4 | 2011-09-26 15:24:56 +0200 | [diff] [blame] | 4064 | /* If this is the "end of sync" confirmation, usually the peer disk |
| 4065 | * transitions from D_INCONSISTENT to D_UP_TO_DATE. For empty (0 bits |
| 4066 | * set) resync started in PausedSyncT, or if the timing of pause-/ |
| 4067 | * unpause-sync events has been "just right", the peer disk may |
| 4068 | * transition from D_CONSISTENT to D_UP_TO_DATE as well. |
| 4069 | */ |
| 4070 | if ((os.pdsk == D_INCONSISTENT || os.pdsk == D_CONSISTENT) && |
| 4071 | real_peer_disk == D_UP_TO_DATE && |
Lars Ellenberg | e9ef7bb | 2010-10-07 15:55:39 +0200 | [diff] [blame] | 4072 | os.conn > C_CONNECTED && os.disk == D_UP_TO_DATE) { |
| 4073 | /* If we are (becoming) SyncSource, but peer is still in sync |
| 4074 | * preparation, ignore its uptodate-ness to avoid flapping, it |
| 4075 | * will change to inconsistent once the peer reaches active |
| 4076 | * syncing states. |
| 4077 | * It may have changed syncer-paused flags, however, so we |
| 4078 | * cannot ignore this completely. */ |
| 4079 | if (peer_state.conn > C_CONNECTED && |
| 4080 | peer_state.conn < C_SYNC_SOURCE) |
| 4081 | real_peer_disk = D_INCONSISTENT; |
| 4082 | |
| 4083 | /* if peer_state changes to connected at the same time, |
| 4084 | * it explicitly notifies us that it finished resync. |
| 4085 | * Maybe we should finish it up, too? */ |
| 4086 | else if (os.conn >= C_SYNC_SOURCE && |
| 4087 | peer_state.conn == C_CONNECTED) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4088 | if (drbd_bm_total_weight(device) <= device->rs_failed) |
| 4089 | drbd_resync_finished(device); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4090 | return 0; |
Lars Ellenberg | e9ef7bb | 2010-10-07 15:55:39 +0200 | [diff] [blame] | 4091 | } |
| 4092 | } |
| 4093 | |
Lars Ellenberg | 02b91b5 | 2012-06-28 18:26:52 +0200 | [diff] [blame] | 4094 | /* explicit verify finished notification, stop sector reached. */ |
| 4095 | if (os.conn == C_VERIFY_T && os.disk == D_UP_TO_DATE && |
| 4096 | peer_state.conn == C_CONNECTED && real_peer_disk == D_UP_TO_DATE) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4097 | ov_out_of_sync_print(device); |
| 4098 | drbd_resync_finished(device); |
Lars Ellenberg | 58ffa58 | 2012-07-26 14:09:49 +0200 | [diff] [blame] | 4099 | return 0; |
Lars Ellenberg | 02b91b5 | 2012-06-28 18:26:52 +0200 | [diff] [blame] | 4100 | } |
| 4101 | |
Lars Ellenberg | e9ef7bb | 2010-10-07 15:55:39 +0200 | [diff] [blame] | 4102 | /* peer says his disk is inconsistent, while we think it is uptodate, |
| 4103 | * and this happens while the peer still thinks we have a sync going on, |
| 4104 | * but we think we are already done with the sync. |
| 4105 | * We ignore this to avoid flapping pdsk. |
| 4106 | * This should not happen, if the peer is a recent version of drbd. */ |
| 4107 | if (os.pdsk == D_UP_TO_DATE && real_peer_disk == D_INCONSISTENT && |
| 4108 | os.conn == C_CONNECTED && peer_state.conn > C_SYNC_SOURCE) |
| 4109 | real_peer_disk = D_UP_TO_DATE; |
| 4110 | |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4111 | if (ns.conn == C_WF_REPORT_PARAMS) |
| 4112 | ns.conn = C_CONNECTED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4113 | |
Philipp Reisner | 6753171 | 2010-10-27 12:21:30 +0200 | [diff] [blame] | 4114 | if (peer_state.conn == C_AHEAD) |
| 4115 | ns.conn = C_BEHIND; |
| 4116 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4117 | if (device->p_uuid && peer_state.disk >= D_NEGOTIATING && |
| 4118 | get_ldev_if_state(device, D_NEGOTIATING)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4119 | int cr; /* consider resync */ |
| 4120 | |
| 4121 | /* if we established a new connection */ |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4122 | cr = (os.conn < C_CONNECTED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4123 | /* if we had an established connection |
| 4124 | * and one of the nodes newly attaches a disk */ |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4125 | cr |= (os.conn == C_CONNECTED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4126 | (peer_state.disk == D_NEGOTIATING || |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4127 | os.disk == D_NEGOTIATING)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4128 | /* if we have both been inconsistent, and the peer has been |
| 4129 | * forced to be UpToDate with --overwrite-data */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4130 | cr |= test_bit(CONSIDER_RESYNC, &device->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4131 | /* if we had been plain connected, and the admin requested to |
| 4132 | * start a sync by "invalidate" or "invalidate-remote" */ |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4133 | cr |= (os.conn == C_CONNECTED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4134 | (peer_state.conn >= C_STARTING_SYNC_S && |
| 4135 | peer_state.conn <= C_WF_BITMAP_T)); |
| 4136 | |
| 4137 | if (cr) |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4138 | ns.conn = drbd_sync_handshake(peer_device, peer_state.role, real_peer_disk); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4139 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4140 | put_ldev(device); |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4141 | if (ns.conn == C_MASK) { |
| 4142 | ns.conn = C_CONNECTED; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4143 | if (device->state.disk == D_NEGOTIATING) { |
| 4144 | drbd_force_state(device, NS(disk, D_FAILED)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4145 | } else if (peer_state.disk == D_NEGOTIATING) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4146 | drbd_err(device, "Disk attach process on the peer node was aborted.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4147 | peer_state.disk = D_DISKLESS; |
Lars Ellenberg | 580b976 | 2010-02-26 23:15:23 +0100 | [diff] [blame] | 4148 | real_peer_disk = D_DISKLESS; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4149 | } else { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4150 | if (test_and_clear_bit(CONN_DRY_RUN, &peer_device->connection->flags)) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4151 | return -EIO; |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 4152 | D_ASSERT(device, os.conn == C_WF_REPORT_PARAMS); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4153 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4154 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4155 | } |
| 4156 | } |
| 4157 | } |
| 4158 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 4159 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4160 | if (os.i != drbd_read_state(device).i) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4161 | goto retry; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4162 | clear_bit(CONSIDER_RESYNC, &device->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4163 | ns.peer = peer_state.role; |
| 4164 | ns.pdsk = real_peer_disk; |
| 4165 | ns.peer_isp = (peer_state.aftr_isp | peer_state.user_isp); |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4166 | if ((ns.conn == C_CONNECTED || ns.conn == C_WF_BITMAP_S) && ns.disk == D_NEGOTIATING) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4167 | ns.disk = device->new_state_tmp.disk; |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4168 | cs_flags = CS_VERBOSE + (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED ? 0 : CS_HARD); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4169 | if (ns.pdsk == D_CONSISTENT && drbd_suspended(device) && ns.conn == C_CONNECTED && os.conn < C_CONNECTED && |
| 4170 | test_bit(NEW_CUR_UUID, &device->flags)) { |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 4171 | /* Do not allow tl_restart(RESEND) for a rebooted peer. We can only allow this |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 4172 | for temporal network outages! */ |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 4173 | spin_unlock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4174 | drbd_err(device, "Aborting Connect, can not thaw IO with an only Consistent peer\n"); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4175 | tl_clear(peer_device->connection); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4176 | drbd_uuid_new_current(device); |
| 4177 | clear_bit(NEW_CUR_UUID, &device->flags); |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4178 | conn_request_state(peer_device->connection, NS2(conn, C_PROTOCOL_ERROR, susp, 0), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4179 | return -EIO; |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 4180 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4181 | rv = _drbd_set_state(device, ns, cs_flags, NULL); |
| 4182 | ns = drbd_read_state(device); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 4183 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4184 | |
| 4185 | if (rv < SS_SUCCESS) { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4186 | conn_request_state(peer_device->connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4187 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4188 | } |
| 4189 | |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 4190 | if (os.conn > C_WF_REPORT_PARAMS) { |
| 4191 | if (ns.conn > C_CONNECTED && peer_state.conn <= C_CONNECTED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4192 | peer_state.disk != D_NEGOTIATING ) { |
| 4193 | /* we want resync, peer has not yet decided to sync... */ |
| 4194 | /* Nowadays only used when forcing a node into primary role and |
| 4195 | setting its disk to UpToDate with that */ |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4196 | drbd_send_uuids(peer_device); |
| 4197 | drbd_send_current_state(peer_device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4198 | } |
| 4199 | } |
| 4200 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4201 | clear_bit(DISCARD_MY_DATA, &device->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4202 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4203 | drbd_md_sync(device); /* update connected indicator, la_size_sect, ... */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4204 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4205 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4208 | static int receive_sync_uuid(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4209 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4210 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4211 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4212 | struct p_rs_uuid *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4213 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4214 | peer_device = conn_peer_device(connection, pi->vnr); |
| 4215 | if (!peer_device) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4216 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4217 | device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4218 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4219 | wait_event(device->misc_wait, |
| 4220 | device->state.conn == C_WF_SYNC_UUID || |
| 4221 | device->state.conn == C_BEHIND || |
| 4222 | device->state.conn < C_CONNECTED || |
| 4223 | device->state.disk < D_NEGOTIATING); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4224 | |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 4225 | /* D_ASSERT(device, device->state.conn == C_WF_SYNC_UUID ); */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4226 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4227 | /* Here the _drbd_uuid_ functions are right, current should |
| 4228 | _not_ be rotated into the history */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4229 | if (get_ldev_if_state(device, D_NEGOTIATING)) { |
| 4230 | _drbd_uuid_set(device, UI_CURRENT, be64_to_cpu(p->uuid)); |
| 4231 | _drbd_uuid_set(device, UI_BITMAP, 0UL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4232 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4233 | drbd_print_uuids(device, "updated sync uuid"); |
| 4234 | drbd_start_resync(device, C_SYNC_TARGET); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4235 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4236 | put_ldev(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4237 | } else |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4238 | drbd_err(device, "Ignoring SyncUUID packet!\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4239 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4240 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4241 | } |
| 4242 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4243 | /** |
| 4244 | * receive_bitmap_plain |
| 4245 | * |
| 4246 | * Return 0 when done, 1 when another iteration is needed, and a negative error |
| 4247 | * code upon failure. |
| 4248 | */ |
| 4249 | static int |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4250 | receive_bitmap_plain(struct drbd_peer_device *peer_device, unsigned int size, |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4251 | unsigned long *p, struct bm_xfer_ctx *c) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4252 | { |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 4253 | unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4254 | drbd_header_size(peer_device->connection); |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4255 | unsigned int num_words = min_t(size_t, data_size / sizeof(*p), |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 4256 | c->bm_words - c->word_offset); |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4257 | unsigned int want = num_words * sizeof(*p); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4258 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4259 | |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 4260 | if (want != size) { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4261 | drbd_err(peer_device, "%s:want (%u) != size (%u)\n", __func__, want, size); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4262 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4263 | } |
| 4264 | if (want == 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4265 | return 0; |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4266 | err = drbd_recv_all(peer_device->connection, p, want); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4267 | if (err) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4268 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4269 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4270 | drbd_bm_merge_lel(peer_device->device, c->word_offset, num_words, p); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4271 | |
| 4272 | c->word_offset += num_words; |
| 4273 | c->bit_offset = c->word_offset * BITS_PER_LONG; |
| 4274 | if (c->bit_offset > c->bm_bits) |
| 4275 | c->bit_offset = c->bm_bits; |
| 4276 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4277 | return 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4278 | } |
| 4279 | |
Andreas Gruenbacher | a02d124 | 2011-03-22 17:20:45 +0100 | [diff] [blame] | 4280 | static enum drbd_bitmap_code dcbp_get_code(struct p_compressed_bm *p) |
| 4281 | { |
| 4282 | return (enum drbd_bitmap_code)(p->encoding & 0x0f); |
| 4283 | } |
| 4284 | |
| 4285 | static int dcbp_get_start(struct p_compressed_bm *p) |
| 4286 | { |
| 4287 | return (p->encoding & 0x80) != 0; |
| 4288 | } |
| 4289 | |
| 4290 | static int dcbp_get_pad_bits(struct p_compressed_bm *p) |
| 4291 | { |
| 4292 | return (p->encoding >> 4) & 0x7; |
| 4293 | } |
| 4294 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4295 | /** |
| 4296 | * recv_bm_rle_bits |
| 4297 | * |
| 4298 | * Return 0 when done, 1 when another iteration is needed, and a negative error |
| 4299 | * code upon failure. |
| 4300 | */ |
| 4301 | static int |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4302 | recv_bm_rle_bits(struct drbd_peer_device *peer_device, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4303 | struct p_compressed_bm *p, |
Philipp Reisner | c6d25cf | 2011-01-19 16:13:06 +0100 | [diff] [blame] | 4304 | struct bm_xfer_ctx *c, |
| 4305 | unsigned int len) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4306 | { |
| 4307 | struct bitstream bs; |
| 4308 | u64 look_ahead; |
| 4309 | u64 rl; |
| 4310 | u64 tmp; |
| 4311 | unsigned long s = c->bit_offset; |
| 4312 | unsigned long e; |
Andreas Gruenbacher | a02d124 | 2011-03-22 17:20:45 +0100 | [diff] [blame] | 4313 | int toggle = dcbp_get_start(p); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4314 | int have; |
| 4315 | int bits; |
| 4316 | |
Andreas Gruenbacher | a02d124 | 2011-03-22 17:20:45 +0100 | [diff] [blame] | 4317 | bitstream_init(&bs, p->code, len, dcbp_get_pad_bits(p)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4318 | |
| 4319 | bits = bitstream_get_bits(&bs, &look_ahead, 64); |
| 4320 | if (bits < 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4321 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4322 | |
| 4323 | for (have = bits; have > 0; s += rl, toggle = !toggle) { |
| 4324 | bits = vli_decode_bits(&rl, look_ahead); |
| 4325 | if (bits <= 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4326 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4327 | |
| 4328 | if (toggle) { |
| 4329 | e = s + rl -1; |
| 4330 | if (e >= c->bm_bits) { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4331 | drbd_err(peer_device, "bitmap overflow (e:%lu) while decoding bm RLE packet\n", e); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4332 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4333 | } |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4334 | _drbd_bm_set_bits(peer_device->device, s, e); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | if (have < bits) { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4338 | drbd_err(peer_device, "bitmap decoding error: h:%d b:%d la:0x%08llx l:%u/%u\n", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4339 | have, bits, look_ahead, |
| 4340 | (unsigned int)(bs.cur.b - p->code), |
| 4341 | (unsigned int)bs.buf_len); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4342 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4343 | } |
Lars Ellenberg | d2da5b0 | 2013-10-23 10:59:18 +0200 | [diff] [blame] | 4344 | /* if we consumed all 64 bits, assign 0; >> 64 is "undefined"; */ |
| 4345 | if (likely(bits < 64)) |
| 4346 | look_ahead >>= bits; |
| 4347 | else |
| 4348 | look_ahead = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4349 | have -= bits; |
| 4350 | |
| 4351 | bits = bitstream_get_bits(&bs, &tmp, 64 - have); |
| 4352 | if (bits < 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4353 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4354 | look_ahead |= tmp << have; |
| 4355 | have += bits; |
| 4356 | } |
| 4357 | |
| 4358 | c->bit_offset = s; |
| 4359 | bm_xfer_ctx_bit_to_word_offset(c); |
| 4360 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4361 | return (s != c->bm_bits); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4362 | } |
| 4363 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4364 | /** |
| 4365 | * decode_bitmap_c |
| 4366 | * |
| 4367 | * Return 0 when done, 1 when another iteration is needed, and a negative error |
| 4368 | * code upon failure. |
| 4369 | */ |
| 4370 | static int |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4371 | decode_bitmap_c(struct drbd_peer_device *peer_device, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4372 | struct p_compressed_bm *p, |
Philipp Reisner | c6d25cf | 2011-01-19 16:13:06 +0100 | [diff] [blame] | 4373 | struct bm_xfer_ctx *c, |
| 4374 | unsigned int len) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4375 | { |
Andreas Gruenbacher | a02d124 | 2011-03-22 17:20:45 +0100 | [diff] [blame] | 4376 | if (dcbp_get_code(p) == RLE_VLI_Bits) |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4377 | return recv_bm_rle_bits(peer_device, p, c, len - sizeof(*p)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4378 | |
| 4379 | /* other variants had been implemented for evaluation, |
| 4380 | * but have been dropped as this one turned out to be "best" |
| 4381 | * during all our tests. */ |
| 4382 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4383 | drbd_err(peer_device, "receive_bitmap_c: unknown encoding %u\n", p->encoding); |
| 4384 | conn_request_state(peer_device->connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4385 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4386 | } |
| 4387 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4388 | void INFO_bm_xfer_stats(struct drbd_device *device, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4389 | const char *direction, struct bm_xfer_ctx *c) |
| 4390 | { |
| 4391 | /* what would it take to transfer it "plaintext" */ |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 4392 | unsigned int header_size = drbd_header_size(first_peer_device(device)->connection); |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 4393 | unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - header_size; |
| 4394 | unsigned int plain = |
| 4395 | header_size * (DIV_ROUND_UP(c->bm_words, data_size) + 1) + |
| 4396 | c->bm_words * sizeof(unsigned long); |
| 4397 | unsigned int total = c->bytes[0] + c->bytes[1]; |
| 4398 | unsigned int r; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4399 | |
| 4400 | /* total can not be zero. but just in case: */ |
| 4401 | if (total == 0) |
| 4402 | return; |
| 4403 | |
| 4404 | /* don't report if not compressed */ |
| 4405 | if (total >= plain) |
| 4406 | return; |
| 4407 | |
| 4408 | /* total < plain. check for overflow, still */ |
| 4409 | r = (total > UINT_MAX/1000) ? (total / (plain/1000)) |
| 4410 | : (1000 * total / plain); |
| 4411 | |
| 4412 | if (r > 1000) |
| 4413 | r = 1000; |
| 4414 | |
| 4415 | r = 1000 - r; |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4416 | drbd_info(device, "%s bitmap stats [Bytes(packets)]: plain %u(%u), RLE %u(%u), " |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4417 | "total %u; compression: %u.%u%%\n", |
| 4418 | direction, |
| 4419 | c->bytes[1], c->packets[1], |
| 4420 | c->bytes[0], c->packets[0], |
| 4421 | total, r/10, r % 10); |
| 4422 | } |
| 4423 | |
| 4424 | /* Since we are processing the bitfield from lower addresses to higher, |
| 4425 | it does not matter if the process it in 32 bit chunks or 64 bit |
| 4426 | chunks as long as it is little endian. (Understand it as byte stream, |
| 4427 | beginning with the lowest byte...) If we would use big endian |
| 4428 | we would need to process it from the highest address to the lowest, |
| 4429 | in order to be agnostic to the 32 vs 64 bits issue. |
| 4430 | |
| 4431 | returns 0 on failure, 1 if we successfully received it. */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4432 | static int receive_bitmap(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4433 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4434 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4435 | struct drbd_device *device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4436 | struct bm_xfer_ctx c; |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4437 | int err; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4438 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4439 | peer_device = conn_peer_device(connection, pi->vnr); |
| 4440 | if (!peer_device) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4441 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4442 | device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4443 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4444 | drbd_bm_lock(device, "receive bitmap", BM_LOCKED_SET_ALLOWED); |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 4445 | /* you are supposed to send additional out-of-sync information |
| 4446 | * if you actually set bits during this phase */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4447 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4448 | c = (struct bm_xfer_ctx) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4449 | .bm_bits = drbd_bm_bits(device), |
| 4450 | .bm_words = drbd_bm_words(device), |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4451 | }; |
| 4452 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4453 | for(;;) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4454 | if (pi->cmd == P_BITMAP) |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4455 | err = receive_bitmap_plain(peer_device, pi->size, pi->data, &c); |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4456 | else if (pi->cmd == P_COMPRESSED_BITMAP) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4457 | /* MAYBE: sanity check that we speak proto >= 90, |
| 4458 | * and the feature is enabled! */ |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4459 | struct p_compressed_bm *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4460 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4461 | if (pi->size > DRBD_SOCKET_BUFFER_SIZE - drbd_header_size(connection)) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4462 | drbd_err(device, "ReportCBitmap packet too large\n"); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4463 | err = -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4464 | goto out; |
| 4465 | } |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4466 | if (pi->size <= sizeof(*p)) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4467 | drbd_err(device, "ReportCBitmap packet too small (l:%u)\n", pi->size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4468 | err = -EIO; |
Andreas Gruenbacher | 78fcbda | 2010-12-10 22:18:27 +0100 | [diff] [blame] | 4469 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4470 | } |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4471 | err = drbd_recv_all(peer_device->connection, p, pi->size); |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4472 | if (err) |
| 4473 | goto out; |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4474 | err = decode_bitmap_c(peer_device, p, &c, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4475 | } else { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4476 | drbd_warn(device, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", pi->cmd); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4477 | err = -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4478 | goto out; |
| 4479 | } |
| 4480 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4481 | c.packets[pi->cmd == P_BITMAP]++; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4482 | c.bytes[pi->cmd == P_BITMAP] += drbd_header_size(connection) + pi->size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4483 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4484 | if (err <= 0) { |
| 4485 | if (err < 0) |
| 4486 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4487 | break; |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4488 | } |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4489 | err = drbd_recv_header(peer_device->connection, pi); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4490 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4491 | goto out; |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4492 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4493 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4494 | INFO_bm_xfer_stats(device, "receive", &c); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4495 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4496 | if (device->state.conn == C_WF_BITMAP_T) { |
Andreas Gruenbacher | de1f8e4 | 2010-12-10 21:04:00 +0100 | [diff] [blame] | 4497 | enum drbd_state_rv rv; |
| 4498 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4499 | err = drbd_send_bitmap(device); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4500 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4501 | goto out; |
| 4502 | /* Omit CS_ORDERED with this state transition to avoid deadlocks. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4503 | rv = _drbd_request_state(device, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE); |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 4504 | D_ASSERT(device, rv == SS_SUCCESS); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4505 | } else if (device->state.conn != C_WF_BITMAP_S) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4506 | /* admin may have requested C_DISCONNECTING, |
| 4507 | * other threads may have noticed network errors */ |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4508 | drbd_info(device, "unexpected cstate (%s) in receive_bitmap\n", |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4509 | drbd_conn_str(device->state.conn)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4510 | } |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4511 | err = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4512 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4513 | out: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4514 | drbd_bm_unlock(device); |
| 4515 | if (!err && device->state.conn == C_WF_BITMAP_S) |
| 4516 | drbd_start_resync(device, C_SYNC_SOURCE); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4517 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4518 | } |
| 4519 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4520 | static int receive_skip(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4521 | { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4522 | drbd_warn(connection, "skipping unknown optional packet type %d, l: %d!\n", |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4523 | pi->cmd, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4524 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4525 | return ignore_remaining_packet(connection, pi); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4526 | } |
| 4527 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4528 | static int receive_UnplugRemote(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4529 | { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4530 | /* Make sure we've acked all the TCP data associated |
| 4531 | * with the data requests being unplugged */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4532 | drbd_tcp_quickack(connection->data.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4533 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4534 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4537 | static int receive_out_of_sync(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 4538 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4539 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4540 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4541 | struct p_block_desc *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4542 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4543 | peer_device = conn_peer_device(connection, pi->vnr); |
| 4544 | if (!peer_device) |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4545 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 4546 | device = peer_device->device; |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 4547 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4548 | switch (device->state.conn) { |
Lars Ellenberg | f735e363 | 2010-12-17 21:06:18 +0100 | [diff] [blame] | 4549 | case C_WF_SYNC_UUID: |
| 4550 | case C_WF_BITMAP_T: |
| 4551 | case C_BEHIND: |
| 4552 | break; |
| 4553 | default: |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4554 | drbd_err(device, "ASSERT FAILED cstate = %s, expected: WFSyncUUID|WFBitMapT|Behind\n", |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4555 | drbd_conn_str(device->state.conn)); |
Lars Ellenberg | f735e363 | 2010-12-17 21:06:18 +0100 | [diff] [blame] | 4556 | } |
| 4557 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4558 | drbd_set_out_of_sync(device, be64_to_cpu(p->sector), be32_to_cpu(p->blksize)); |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 4559 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4560 | return 0; |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 4561 | } |
| 4562 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4563 | struct data_cmd { |
| 4564 | int expect_payload; |
| 4565 | size_t pkt_size; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4566 | int (*fn)(struct drbd_connection *, struct packet_info *); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4567 | }; |
| 4568 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4569 | static struct data_cmd drbd_cmd_handler[] = { |
| 4570 | [P_DATA] = { 1, sizeof(struct p_data), receive_Data }, |
| 4571 | [P_DATA_REPLY] = { 1, sizeof(struct p_data), receive_DataReply }, |
| 4572 | [P_RS_DATA_REPLY] = { 1, sizeof(struct p_data), receive_RSDataReply } , |
| 4573 | [P_BARRIER] = { 0, sizeof(struct p_barrier), receive_Barrier } , |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4574 | [P_BITMAP] = { 1, 0, receive_bitmap } , |
| 4575 | [P_COMPRESSED_BITMAP] = { 1, 0, receive_bitmap } , |
| 4576 | [P_UNPLUG_REMOTE] = { 0, 0, receive_UnplugRemote }, |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4577 | [P_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, |
| 4578 | [P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4579 | [P_SYNC_PARAM] = { 1, 0, receive_SyncParam }, |
| 4580 | [P_SYNC_PARAM89] = { 1, 0, receive_SyncParam }, |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4581 | [P_PROTOCOL] = { 1, sizeof(struct p_protocol), receive_protocol }, |
| 4582 | [P_UUIDS] = { 0, sizeof(struct p_uuids), receive_uuids }, |
| 4583 | [P_SIZES] = { 0, sizeof(struct p_sizes), receive_sizes }, |
| 4584 | [P_STATE] = { 0, sizeof(struct p_state), receive_state }, |
| 4585 | [P_STATE_CHG_REQ] = { 0, sizeof(struct p_req_state), receive_req_state }, |
| 4586 | [P_SYNC_UUID] = { 0, sizeof(struct p_rs_uuid), receive_sync_uuid }, |
| 4587 | [P_OV_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, |
| 4588 | [P_OV_REPLY] = { 1, sizeof(struct p_block_req), receive_DataRequest }, |
| 4589 | [P_CSUM_RS_REQUEST] = { 1, sizeof(struct p_block_req), receive_DataRequest }, |
| 4590 | [P_DELAY_PROBE] = { 0, sizeof(struct p_delay_probe93), receive_skip }, |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 4591 | [P_OUT_OF_SYNC] = { 0, sizeof(struct p_block_desc), receive_out_of_sync }, |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4592 | [P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), receive_req_conn_state }, |
Philipp Reisner | 036b17e | 2011-05-16 17:38:11 +0200 | [diff] [blame] | 4593 | [P_PROTOCOL_UPDATE] = { 1, sizeof(struct p_protocol), receive_protocol }, |
Lars Ellenberg | a0fb3c4 | 2014-04-28 18:43:23 +0200 | [diff] [blame] | 4594 | [P_TRIM] = { 0, sizeof(struct p_trim), receive_Data }, |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4595 | }; |
| 4596 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4597 | static void drbdd(struct drbd_connection *connection) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4598 | { |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4599 | struct packet_info pi; |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4600 | size_t shs; /* sub header size */ |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4601 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4602 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4603 | while (get_t_state(&connection->receiver) == RUNNING) { |
Andreas Gruenbacher | deebe19 | 2011-03-25 00:01:04 +0100 | [diff] [blame] | 4604 | struct data_cmd *cmd; |
| 4605 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4606 | drbd_thread_current_set_cpu(&connection->receiver); |
Lars Ellenberg | 944410e | 2014-05-06 15:02:05 +0200 | [diff] [blame] | 4607 | update_receiver_timing_details(connection, drbd_recv_header); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4608 | if (drbd_recv_header(connection, &pi)) |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4609 | goto err_out; |
| 4610 | |
Andreas Gruenbacher | deebe19 | 2011-03-25 00:01:04 +0100 | [diff] [blame] | 4611 | cmd = &drbd_cmd_handler[pi.cmd]; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4612 | if (unlikely(pi.cmd >= ARRAY_SIZE(drbd_cmd_handler) || !cmd->fn)) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4613 | drbd_err(connection, "Unexpected data packet %s (0x%04x)", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 4614 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4615 | goto err_out; |
Lars Ellenberg | 0b33a91 | 2009-11-16 15:58:04 +0100 | [diff] [blame] | 4616 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4617 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4618 | shs = cmd->pkt_size; |
| 4619 | if (pi.size > shs && !cmd->expect_payload) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4620 | drbd_err(connection, "No payload expected %s l:%d\n", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 4621 | cmdname(pi.cmd), pi.size); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4622 | goto err_out; |
| 4623 | } |
| 4624 | |
Lars Ellenberg | c13f7e1 | 2010-10-29 23:32:01 +0200 | [diff] [blame] | 4625 | if (shs) { |
Lars Ellenberg | 944410e | 2014-05-06 15:02:05 +0200 | [diff] [blame] | 4626 | update_receiver_timing_details(connection, drbd_recv_all_warn); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4627 | err = drbd_recv_all_warn(connection, pi.data, shs); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 4628 | if (err) |
Lars Ellenberg | c13f7e1 | 2010-10-29 23:32:01 +0200 | [diff] [blame] | 4629 | goto err_out; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4630 | pi.size -= shs; |
Lars Ellenberg | c13f7e1 | 2010-10-29 23:32:01 +0200 | [diff] [blame] | 4631 | } |
| 4632 | |
Lars Ellenberg | 944410e | 2014-05-06 15:02:05 +0200 | [diff] [blame] | 4633 | update_receiver_timing_details(connection, cmd->fn); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4634 | err = cmd->fn(connection, &pi); |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4635 | if (err) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4636 | drbd_err(connection, "error receiving %s, e: %d l: %d!\n", |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4637 | cmdname(pi.cmd), err, pi.size); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4638 | goto err_out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4639 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4640 | } |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4641 | return; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4642 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4643 | err_out: |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4644 | conn_request_state(connection, NS(conn, C_PROTOCOL_ERROR), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4645 | } |
| 4646 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4647 | static void conn_disconnect(struct drbd_connection *connection) |
Philipp Reisner | f70b3511 | 2010-06-24 14:34:40 +0200 | [diff] [blame] | 4648 | { |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 4649 | struct drbd_peer_device *peer_device; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4650 | enum drbd_conns oc; |
Philipp Reisner | 376694a | 2011-11-07 10:54:28 +0100 | [diff] [blame] | 4651 | int vnr; |
Philipp Reisner | f70b3511 | 2010-06-24 14:34:40 +0200 | [diff] [blame] | 4652 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4653 | if (connection->cstate == C_STANDALONE) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4654 | return; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4655 | |
Lars Ellenberg | 545752d | 2011-12-05 14:39:25 +0100 | [diff] [blame] | 4656 | /* We are about to start the cleanup after connection loss. |
| 4657 | * Make sure drbd_make_request knows about that. |
| 4658 | * Usually we should be in some network failure state already, |
| 4659 | * but just in case we are not, we fix it up here. |
| 4660 | */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4661 | conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD); |
Lars Ellenberg | 545752d | 2011-12-05 14:39:25 +0100 | [diff] [blame] | 4662 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4663 | /* asender does not clean up anything. it must not interfere, either */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4664 | drbd_thread_stop(&connection->asender); |
| 4665 | drbd_free_sock(connection); |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4666 | |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 4667 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 4668 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 4669 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4670 | kref_get(&device->kref); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 4671 | rcu_read_unlock(); |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4672 | drbd_disconnected(peer_device); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 4673 | kref_put(&device->kref, drbd_destroy_device); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 4674 | rcu_read_lock(); |
| 4675 | } |
| 4676 | rcu_read_unlock(); |
| 4677 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4678 | if (!list_empty(&connection->current_epoch->list)) |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4679 | drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n"); |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 4680 | /* ok, no more ee's on the fly, it is safe to reset the epoch_size */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4681 | atomic_set(&connection->current_epoch->epoch_size, 0); |
| 4682 | connection->send.seen_any_write_yet = false; |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 4683 | |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4684 | drbd_info(connection, "Connection closed\n"); |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4685 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4686 | if (conn_highest_role(connection) == R_PRIMARY && conn_highest_pdsk(connection) >= D_UNKNOWN) |
| 4687 | conn_try_outdate_peer_async(connection); |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 4688 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 4689 | spin_lock_irq(&connection->resource->req_lock); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4690 | oc = connection->cstate; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4691 | if (oc >= C_UNCONNECTED) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4692 | _conn_request_state(connection, NS(conn, C_UNCONNECTED), CS_VERBOSE); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4693 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 4694 | spin_unlock_irq(&connection->resource->req_lock); |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4695 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 4696 | if (oc == C_DISCONNECTING) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4697 | conn_request_state(connection, NS(conn, C_STANDALONE), CS_VERBOSE | CS_HARD); |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4698 | } |
| 4699 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4700 | static int drbd_disconnected(struct drbd_peer_device *peer_device) |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4701 | { |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4702 | struct drbd_device *device = peer_device->device; |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4703 | unsigned int i; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4704 | |
Philipp Reisner | 8571957 | 2010-07-21 10:20:17 +0200 | [diff] [blame] | 4705 | /* wait for current activity to cease. */ |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 4706 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4707 | _drbd_wait_ee_list_empty(device, &device->active_ee); |
| 4708 | _drbd_wait_ee_list_empty(device, &device->sync_ee); |
| 4709 | _drbd_wait_ee_list_empty(device, &device->read_ee); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 4710 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4711 | |
| 4712 | /* We do not have data structures that would allow us to |
| 4713 | * get the rs_pending_cnt down to 0 again. |
| 4714 | * * On C_SYNC_TARGET we do not have any data structures describing |
| 4715 | * the pending RSDataRequest's we have sent. |
| 4716 | * * On C_SYNC_SOURCE there is no data structure that tracks |
| 4717 | * the P_RS_DATA_REPLY blocks that we sent to the SyncTarget. |
| 4718 | * And no, it is not the sum of the reference counts in the |
| 4719 | * resync_LRU. The resync_LRU tracks the whole operation including |
| 4720 | * the disk-IO, while the rs_pending_cnt only tracks the blocks |
| 4721 | * on the fly. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4722 | drbd_rs_cancel_all(device); |
| 4723 | device->rs_total = 0; |
| 4724 | device->rs_failed = 0; |
| 4725 | atomic_set(&device->rs_pending_cnt, 0); |
| 4726 | wake_up(&device->misc_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4727 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4728 | del_timer_sync(&device->resync_timer); |
| 4729 | resync_timer_fn((unsigned long)device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4730 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4731 | /* wait for all w_e_end_data_req, w_e_end_rsdata_req, w_send_barrier, |
| 4732 | * w_make_resync_request etc. which may still be on the worker queue |
| 4733 | * to be "canceled" */ |
Andreas Gruenbacher | b5043c5 | 2011-07-28 15:56:02 +0200 | [diff] [blame] | 4734 | drbd_flush_workqueue(&peer_device->connection->sender_work); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4735 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4736 | drbd_finish_peer_reqs(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4737 | |
Philipp Reisner | d10b4ea | 2011-11-30 23:25:36 +0100 | [diff] [blame] | 4738 | /* This second workqueue flush is necessary, since drbd_finish_peer_reqs() |
| 4739 | might have issued a work again. The one before drbd_finish_peer_reqs() is |
| 4740 | necessary to reclain net_ee in drbd_finish_peer_reqs(). */ |
Andreas Gruenbacher | b5043c5 | 2011-07-28 15:56:02 +0200 | [diff] [blame] | 4741 | drbd_flush_workqueue(&peer_device->connection->sender_work); |
Philipp Reisner | d10b4ea | 2011-11-30 23:25:36 +0100 | [diff] [blame] | 4742 | |
Lars Ellenberg | 08332d7 | 2012-08-17 15:09:13 +0200 | [diff] [blame] | 4743 | /* need to do it again, drbd_finish_peer_reqs() may have populated it |
| 4744 | * again via drbd_try_clear_on_disk_bm(). */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4745 | drbd_rs_cancel_all(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4746 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4747 | kfree(device->p_uuid); |
| 4748 | device->p_uuid = NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4749 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4750 | if (!drbd_suspended(device)) |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 4751 | tl_clear(peer_device->connection); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4752 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4753 | drbd_md_sync(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4754 | |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 4755 | /* serialize with bitmap writeout triggered by the state change, |
| 4756 | * if any. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4757 | wait_event(device->misc_wait, !test_bit(BITMAP_IO, &device->flags)); |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 4758 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4759 | /* tcp_close and release of sendpage pages can be deferred. I don't |
| 4760 | * want to use SO_LINGER, because apparently it can be deferred for |
| 4761 | * more than 20 seconds (longest time I checked). |
| 4762 | * |
| 4763 | * Actually we don't care for exactly when the network stack does its |
| 4764 | * put_page(), but release our reference on these pages right here. |
| 4765 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4766 | i = drbd_free_peer_reqs(device, &device->net_ee); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4767 | if (i) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4768 | drbd_info(device, "net_ee not empty, killed %u entries\n", i); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4769 | i = atomic_read(&device->pp_in_use_by_net); |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 4770 | if (i) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4771 | drbd_info(device, "pp_in_use_by_net = %d, expected 0\n", i); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 4772 | i = atomic_read(&device->pp_in_use); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4773 | if (i) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 4774 | drbd_info(device, "pp_in_use = %d, expected 0\n", i); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4775 | |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 4776 | D_ASSERT(device, list_empty(&device->read_ee)); |
| 4777 | D_ASSERT(device, list_empty(&device->active_ee)); |
| 4778 | D_ASSERT(device, list_empty(&device->sync_ee)); |
| 4779 | D_ASSERT(device, list_empty(&device->done_ee)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4780 | |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4781 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | /* |
| 4785 | * We support PRO_VERSION_MIN to PRO_VERSION_MAX. The protocol version |
| 4786 | * we can agree on is stored in agreed_pro_version. |
| 4787 | * |
| 4788 | * feature flags and the reserved array should be enough room for future |
| 4789 | * enhancements of the handshake protocol, and possible plugins... |
| 4790 | * |
| 4791 | * for now, they are expected to be zero, but ignored. |
| 4792 | */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4793 | static int drbd_send_features(struct drbd_connection *connection) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4794 | { |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4795 | struct drbd_socket *sock; |
| 4796 | struct p_connection_features *p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4797 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4798 | sock = &connection->data; |
| 4799 | p = conn_prepare_command(connection, sock); |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4800 | if (!p) |
Andreas Gruenbacher | e8d17b0 | 2011-03-16 00:54:19 +0100 | [diff] [blame] | 4801 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4802 | memset(p, 0, sizeof(*p)); |
| 4803 | p->protocol_min = cpu_to_be32(PRO_VERSION_MIN); |
| 4804 | p->protocol_max = cpu_to_be32(PRO_VERSION_MAX); |
Lars Ellenberg | 20c68fd | 2014-04-28 18:43:25 +0200 | [diff] [blame] | 4805 | p->feature_flags = cpu_to_be32(PRO_FEATURES); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4806 | return conn_send_command(connection, sock, P_CONNECTION_FEATURES, sizeof(*p), NULL, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | /* |
| 4810 | * return values: |
| 4811 | * 1 yes, we have a valid connection |
| 4812 | * 0 oops, did not work out, please try again |
| 4813 | * -1 peer talks different language, |
| 4814 | * no point in trying again, please go standalone. |
| 4815 | */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4816 | static int drbd_do_features(struct drbd_connection *connection) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4817 | { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4818 | /* ASSERT current == connection->receiver ... */ |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4819 | struct p_connection_features *p; |
| 4820 | const int expect = sizeof(struct p_connection_features); |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4821 | struct packet_info pi; |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 4822 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4823 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4824 | err = drbd_send_features(connection); |
Andreas Gruenbacher | e8d17b0 | 2011-03-16 00:54:19 +0100 | [diff] [blame] | 4825 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4826 | return 0; |
| 4827 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4828 | err = drbd_recv_header(connection, &pi); |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4829 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4830 | return 0; |
| 4831 | |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 4832 | if (pi.cmd != P_CONNECTION_FEATURES) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4833 | drbd_err(connection, "expected ConnectionFeatures packet, received: %s (0x%04x)\n", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 4834 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4835 | return -1; |
| 4836 | } |
| 4837 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4838 | if (pi.size != expect) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4839 | drbd_err(connection, "expected ConnectionFeatures length: %u, received: %u\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4840 | expect, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4841 | return -1; |
| 4842 | } |
| 4843 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4844 | p = pi.data; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4845 | err = drbd_recv_all_warn(connection, p, expect); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 4846 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4847 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4848 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4849 | p->protocol_min = be32_to_cpu(p->protocol_min); |
| 4850 | p->protocol_max = be32_to_cpu(p->protocol_max); |
| 4851 | if (p->protocol_max == 0) |
| 4852 | p->protocol_max = p->protocol_min; |
| 4853 | |
| 4854 | if (PRO_VERSION_MAX < p->protocol_min || |
| 4855 | PRO_VERSION_MIN > p->protocol_max) |
| 4856 | goto incompat; |
| 4857 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4858 | connection->agreed_pro_version = min_t(int, PRO_VERSION_MAX, p->protocol_max); |
Lars Ellenberg | 20c68fd | 2014-04-28 18:43:25 +0200 | [diff] [blame] | 4859 | connection->agreed_features = PRO_FEATURES & be32_to_cpu(p->feature_flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4860 | |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4861 | drbd_info(connection, "Handshake successful: " |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4862 | "Agreed network protocol version %d\n", connection->agreed_pro_version); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4863 | |
Lars Ellenberg | 20c68fd | 2014-04-28 18:43:25 +0200 | [diff] [blame] | 4864 | drbd_info(connection, "Agreed to%ssupport TRIM on protocol level\n", |
| 4865 | connection->agreed_features & FF_TRIM ? " " : " not "); |
| 4866 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4867 | return 1; |
| 4868 | |
| 4869 | incompat: |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4870 | drbd_err(connection, "incompatible DRBD dialects: " |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4871 | "I support %d-%d, peer supports %d-%d\n", |
| 4872 | PRO_VERSION_MIN, PRO_VERSION_MAX, |
| 4873 | p->protocol_min, p->protocol_max); |
| 4874 | return -1; |
| 4875 | } |
| 4876 | |
| 4877 | #if !defined(CONFIG_CRYPTO_HMAC) && !defined(CONFIG_CRYPTO_HMAC_MODULE) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4878 | static int drbd_do_auth(struct drbd_connection *connection) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4879 | { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4880 | drbd_err(connection, "This kernel was build without CONFIG_CRYPTO_HMAC.\n"); |
| 4881 | drbd_err(connection, "You need to disable 'cram-hmac-alg' in drbd.conf.\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4882 | return -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4883 | } |
| 4884 | #else |
| 4885 | #define CHALLENGE_LEN 64 |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4886 | |
| 4887 | /* Return value: |
| 4888 | 1 - auth succeeded, |
| 4889 | 0 - failed, try again (network error), |
| 4890 | -1 - auth failed, don't try again. |
| 4891 | */ |
| 4892 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4893 | static int drbd_do_auth(struct drbd_connection *connection) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4894 | { |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4895 | struct drbd_socket *sock; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4896 | char my_challenge[CHALLENGE_LEN]; /* 64 Bytes... */ |
| 4897 | struct scatterlist sg; |
| 4898 | char *response = NULL; |
| 4899 | char *right_response = NULL; |
| 4900 | char *peers_ch = NULL; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 4901 | unsigned int key_len; |
| 4902 | char secret[SHARED_SECRET_MAX]; /* 64 byte */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4903 | unsigned int resp_size; |
| 4904 | struct hash_desc desc; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4905 | struct packet_info pi; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 4906 | struct net_conf *nc; |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4907 | int err, rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4908 | |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4909 | /* FIXME: Put the challenge/response into the preallocated socket buffer. */ |
| 4910 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 4911 | rcu_read_lock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4912 | nc = rcu_dereference(connection->net_conf); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 4913 | key_len = strlen(nc->shared_secret); |
| 4914 | memcpy(secret, nc->shared_secret, key_len); |
| 4915 | rcu_read_unlock(); |
| 4916 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4917 | desc.tfm = connection->cram_hmac_tfm; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4918 | desc.flags = 0; |
| 4919 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4920 | rv = crypto_hash_setkey(connection->cram_hmac_tfm, (u8 *)secret, key_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4921 | if (rv) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4922 | drbd_err(connection, "crypto_hash_setkey() failed with %d\n", rv); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4923 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4924 | goto fail; |
| 4925 | } |
| 4926 | |
| 4927 | get_random_bytes(my_challenge, CHALLENGE_LEN); |
| 4928 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4929 | sock = &connection->data; |
| 4930 | if (!conn_prepare_command(connection, sock)) { |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4931 | rv = 0; |
| 4932 | goto fail; |
| 4933 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4934 | rv = !conn_send_command(connection, sock, P_AUTH_CHALLENGE, 0, |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4935 | my_challenge, CHALLENGE_LEN); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4936 | if (!rv) |
| 4937 | goto fail; |
| 4938 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4939 | err = drbd_recv_header(connection, &pi); |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4940 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4941 | rv = 0; |
| 4942 | goto fail; |
| 4943 | } |
| 4944 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4945 | if (pi.cmd != P_AUTH_CHALLENGE) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4946 | drbd_err(connection, "expected AuthChallenge packet, received: %s (0x%04x)\n", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 4947 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4948 | rv = 0; |
| 4949 | goto fail; |
| 4950 | } |
| 4951 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4952 | if (pi.size > CHALLENGE_LEN * 2) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4953 | drbd_err(connection, "expected AuthChallenge payload too big.\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4954 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4955 | goto fail; |
| 4956 | } |
| 4957 | |
Philipp Reisner | 67cca28 | 2014-04-28 18:43:30 +0200 | [diff] [blame] | 4958 | if (pi.size < CHALLENGE_LEN) { |
| 4959 | drbd_err(connection, "AuthChallenge payload too small.\n"); |
| 4960 | rv = -1; |
| 4961 | goto fail; |
| 4962 | } |
| 4963 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4964 | peers_ch = kmalloc(pi.size, GFP_NOIO); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4965 | if (peers_ch == NULL) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4966 | drbd_err(connection, "kmalloc of peers_ch failed\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4967 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4968 | goto fail; |
| 4969 | } |
| 4970 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4971 | err = drbd_recv_all_warn(connection, peers_ch, pi.size); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 4972 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4973 | rv = 0; |
| 4974 | goto fail; |
| 4975 | } |
| 4976 | |
Philipp Reisner | 67cca28 | 2014-04-28 18:43:30 +0200 | [diff] [blame] | 4977 | if (!memcmp(my_challenge, peers_ch, CHALLENGE_LEN)) { |
| 4978 | drbd_err(connection, "Peer presented the same challenge!\n"); |
| 4979 | rv = -1; |
| 4980 | goto fail; |
| 4981 | } |
| 4982 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 4983 | resp_size = crypto_hash_digestsize(connection->cram_hmac_tfm); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4984 | response = kmalloc(resp_size, GFP_NOIO); |
| 4985 | if (response == NULL) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4986 | drbd_err(connection, "kmalloc of response failed\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4987 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4988 | goto fail; |
| 4989 | } |
| 4990 | |
| 4991 | sg_init_table(&sg, 1); |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4992 | sg_set_buf(&sg, peers_ch, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4993 | |
| 4994 | rv = crypto_hash_digest(&desc, &sg, sg.length, response); |
| 4995 | if (rv) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 4996 | drbd_err(connection, "crypto_hash_digest() failed with %d\n", rv); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4997 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4998 | goto fail; |
| 4999 | } |
| 5000 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5001 | if (!conn_prepare_command(connection, sock)) { |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 5002 | rv = 0; |
| 5003 | goto fail; |
| 5004 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5005 | rv = !conn_send_command(connection, sock, P_AUTH_RESPONSE, 0, |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 5006 | response, resp_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5007 | if (!rv) |
| 5008 | goto fail; |
| 5009 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5010 | err = drbd_recv_header(connection, &pi); |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 5011 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5012 | rv = 0; |
| 5013 | goto fail; |
| 5014 | } |
| 5015 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 5016 | if (pi.cmd != P_AUTH_RESPONSE) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5017 | drbd_err(connection, "expected AuthResponse packet, received: %s (0x%04x)\n", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 5018 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5019 | rv = 0; |
| 5020 | goto fail; |
| 5021 | } |
| 5022 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 5023 | if (pi.size != resp_size) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5024 | drbd_err(connection, "expected AuthResponse payload of wrong size\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5025 | rv = 0; |
| 5026 | goto fail; |
| 5027 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5028 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5029 | err = drbd_recv_all_warn(connection, response , resp_size); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 5030 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5031 | rv = 0; |
| 5032 | goto fail; |
| 5033 | } |
| 5034 | |
| 5035 | right_response = kmalloc(resp_size, GFP_NOIO); |
Julia Lawall | 2d1ee87 | 2009-12-27 22:27:11 +0100 | [diff] [blame] | 5036 | if (right_response == NULL) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5037 | drbd_err(connection, "kmalloc of right_response failed\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 5038 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5039 | goto fail; |
| 5040 | } |
| 5041 | |
| 5042 | sg_set_buf(&sg, my_challenge, CHALLENGE_LEN); |
| 5043 | |
| 5044 | rv = crypto_hash_digest(&desc, &sg, sg.length, right_response); |
| 5045 | if (rv) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5046 | drbd_err(connection, "crypto_hash_digest() failed with %d\n", rv); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 5047 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5048 | goto fail; |
| 5049 | } |
| 5050 | |
| 5051 | rv = !memcmp(response, right_response, resp_size); |
| 5052 | |
| 5053 | if (rv) |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5054 | drbd_info(connection, "Peer authenticated using %d bytes HMAC\n", |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5055 | resp_size); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 5056 | else |
| 5057 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5058 | |
| 5059 | fail: |
| 5060 | kfree(peers_ch); |
| 5061 | kfree(response); |
| 5062 | kfree(right_response); |
| 5063 | |
| 5064 | return rv; |
| 5065 | } |
| 5066 | #endif |
| 5067 | |
Andreas Gruenbacher | 8fe6055 | 2011-07-22 11:04:36 +0200 | [diff] [blame] | 5068 | int drbd_receiver(struct drbd_thread *thi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5069 | { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5070 | struct drbd_connection *connection = thi->connection; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5071 | int h; |
| 5072 | |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5073 | drbd_info(connection, "receiver (re)started\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5074 | |
| 5075 | do { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5076 | h = conn_connect(connection); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5077 | if (h == 0) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5078 | conn_disconnect(connection); |
Philipp Reisner | 20ee639 | 2011-01-18 15:28:59 +0100 | [diff] [blame] | 5079 | schedule_timeout_interruptible(HZ); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5080 | } |
| 5081 | if (h == -1) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5082 | drbd_warn(connection, "Discarding network configuration.\n"); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5083 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5084 | } |
| 5085 | } while (h == 0); |
| 5086 | |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 5087 | if (h > 0) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5088 | drbdd(connection); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5089 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5090 | conn_disconnect(connection); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5091 | |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5092 | drbd_info(connection, "receiver terminated\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5093 | return 0; |
| 5094 | } |
| 5095 | |
| 5096 | /* ********* acknowledge sender ******** */ |
| 5097 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5098 | static int got_conn_RqSReply(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5099 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5100 | struct p_req_state_reply *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5101 | int retcode = be32_to_cpu(p->retcode); |
| 5102 | |
| 5103 | if (retcode >= SS_SUCCESS) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5104 | set_bit(CONN_WD_ST_CHG_OKAY, &connection->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5105 | } else { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5106 | set_bit(CONN_WD_ST_CHG_FAIL, &connection->flags); |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5107 | drbd_err(connection, "Requested state change failed by peer: %s (%d)\n", |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 5108 | drbd_set_st_err_str(retcode), retcode); |
| 5109 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5110 | wake_up(&connection->ping_wait); |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 5111 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5112 | return 0; |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 5113 | } |
| 5114 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5115 | static int got_RqSReply(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5116 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5117 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5118 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5119 | struct p_req_state_reply *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5120 | int retcode = be32_to_cpu(p->retcode); |
| 5121 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5122 | peer_device = conn_peer_device(connection, pi->vnr); |
| 5123 | if (!peer_device) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5124 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5125 | device = peer_device->device; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5126 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5127 | if (test_bit(CONN_WD_ST_CHG_REQ, &connection->flags)) { |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 5128 | D_ASSERT(device, connection->agreed_pro_version < 100); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5129 | return got_conn_RqSReply(connection, pi); |
Philipp Reisner | 4d0fc3f | 2012-01-20 13:52:27 +0100 | [diff] [blame] | 5130 | } |
| 5131 | |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 5132 | if (retcode >= SS_SUCCESS) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5133 | set_bit(CL_ST_CHG_SUCCESS, &device->flags); |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 5134 | } else { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5135 | set_bit(CL_ST_CHG_FAIL, &device->flags); |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 5136 | drbd_err(device, "Requested state change failed by peer: %s (%d)\n", |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 5137 | drbd_set_st_err_str(retcode), retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5138 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5139 | wake_up(&device->state_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5140 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5141 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5144 | static int got_Ping(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5145 | { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5146 | return drbd_send_ping_ack(connection); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5147 | |
| 5148 | } |
| 5149 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5150 | static int got_PingAck(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5151 | { |
| 5152 | /* restore idle timeout */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5153 | connection->meta.socket->sk->sk_rcvtimeo = connection->net_conf->ping_int*HZ; |
| 5154 | if (!test_and_set_bit(GOT_PING_ACK, &connection->flags)) |
| 5155 | wake_up(&connection->ping_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5156 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5157 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5160 | static int got_IsInSync(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5161 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5162 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5163 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5164 | struct p_block_ack *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5165 | sector_t sector = be64_to_cpu(p->sector); |
| 5166 | int blksize = be32_to_cpu(p->blksize); |
| 5167 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5168 | peer_device = conn_peer_device(connection, pi->vnr); |
| 5169 | if (!peer_device) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5170 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5171 | device = peer_device->device; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5172 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5173 | D_ASSERT(device, peer_device->connection->agreed_pro_version >= 89); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5174 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 5175 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5176 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5177 | if (get_ldev(device)) { |
| 5178 | drbd_rs_complete_io(device, sector); |
| 5179 | drbd_set_in_sync(device, sector, blksize); |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 5180 | /* rs_same_csums is supposed to count in units of BM_BLOCK_SIZE */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5181 | device->rs_same_csum += (blksize >> BM_BLOCK_SHIFT); |
| 5182 | put_ldev(device); |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 5183 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5184 | dec_rs_pending(device); |
| 5185 | atomic_add(blksize >> 9, &device->rs_sect_in); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5186 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5187 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5188 | } |
| 5189 | |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 5190 | static int |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5191 | validate_req_change_req_state(struct drbd_device *device, u64 id, sector_t sector, |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 5192 | struct rb_root *root, const char *func, |
| 5193 | enum drbd_req_event what, bool missing_ok) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5194 | { |
| 5195 | struct drbd_request *req; |
| 5196 | struct bio_and_error m; |
| 5197 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 5198 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5199 | req = find_request(device, root, id, sector, missing_ok, func); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5200 | if (unlikely(!req)) { |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 5201 | spin_unlock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | 8599767 | 2011-04-04 13:09:15 +0200 | [diff] [blame] | 5202 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5203 | } |
| 5204 | __req_mod(req, what, &m); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 5205 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5206 | |
| 5207 | if (m.bio) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5208 | complete_master_bio(device, &m); |
Andreas Gruenbacher | 8599767 | 2011-04-04 13:09:15 +0200 | [diff] [blame] | 5209 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5210 | } |
| 5211 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5212 | static int got_BlockAck(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5213 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5214 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5215 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5216 | struct p_block_ack *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5217 | sector_t sector = be64_to_cpu(p->sector); |
| 5218 | int blksize = be32_to_cpu(p->blksize); |
| 5219 | enum drbd_req_event what; |
| 5220 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5221 | peer_device = conn_peer_device(connection, pi->vnr); |
| 5222 | if (!peer_device) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5223 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5224 | device = peer_device->device; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5225 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 5226 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5227 | |
Andreas Gruenbacher | 579b57e | 2011-01-13 18:40:57 +0100 | [diff] [blame] | 5228 | if (p->block_id == ID_SYNCER) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5229 | drbd_set_in_sync(device, sector, blksize); |
| 5230 | dec_rs_pending(device); |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5231 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5232 | } |
Andreas Gruenbacher | e05e1e5 | 2011-03-25 15:16:26 +0100 | [diff] [blame] | 5233 | switch (pi->cmd) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5234 | case P_RS_WRITE_ACK: |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 5235 | what = WRITE_ACKED_BY_PEER_AND_SIS; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5236 | break; |
| 5237 | case P_WRITE_ACK: |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 5238 | what = WRITE_ACKED_BY_PEER; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5239 | break; |
| 5240 | case P_RECV_ACK: |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 5241 | what = RECV_ACKED_BY_PEER; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5242 | break; |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 5243 | case P_SUPERSEDED: |
| 5244 | what = CONFLICT_RESOLVED; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 5245 | break; |
| 5246 | case P_RETRY_WRITE: |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 5247 | what = POSTPONE_WRITE; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5248 | break; |
| 5249 | default: |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5250 | BUG(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5251 | } |
| 5252 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5253 | return validate_req_change_req_state(device, p->block_id, sector, |
| 5254 | &device->write_requests, __func__, |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5255 | what, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5256 | } |
| 5257 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5258 | static int got_NegAck(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5259 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5260 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5261 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5262 | struct p_block_ack *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5263 | sector_t sector = be64_to_cpu(p->sector); |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 5264 | int size = be32_to_cpu(p->blksize); |
Andreas Gruenbacher | 8599767 | 2011-04-04 13:09:15 +0200 | [diff] [blame] | 5265 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5266 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5267 | peer_device = conn_peer_device(connection, pi->vnr); |
| 5268 | if (!peer_device) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5269 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5270 | device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5271 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 5272 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5273 | |
Andreas Gruenbacher | 579b57e | 2011-01-13 18:40:57 +0100 | [diff] [blame] | 5274 | if (p->block_id == ID_SYNCER) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5275 | dec_rs_pending(device); |
| 5276 | drbd_rs_failed_io(device, sector, size); |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5277 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5278 | } |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 5279 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5280 | err = validate_req_change_req_state(device, p->block_id, sector, |
| 5281 | &device->write_requests, __func__, |
Philipp Reisner | 303d144 | 2011-04-13 16:24:47 -0700 | [diff] [blame] | 5282 | NEG_ACKED, true); |
Andreas Gruenbacher | 8599767 | 2011-04-04 13:09:15 +0200 | [diff] [blame] | 5283 | if (err) { |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 5284 | /* Protocol A has no P_WRITE_ACKs, but has P_NEG_ACKs. |
| 5285 | The master bio might already be completed, therefore the |
| 5286 | request is no longer in the collision hash. */ |
| 5287 | /* In Protocol B we might already have got a P_RECV_ACK |
| 5288 | but then get a P_NEG_ACK afterwards. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5289 | drbd_set_out_of_sync(device, sector, size); |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 5290 | } |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5291 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5292 | } |
| 5293 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5294 | static int got_NegDReply(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5295 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5296 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5297 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5298 | struct p_block_ack *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5299 | sector_t sector = be64_to_cpu(p->sector); |
| 5300 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5301 | peer_device = conn_peer_device(connection, pi->vnr); |
| 5302 | if (!peer_device) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5303 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5304 | device = peer_device->device; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5305 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 5306 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 5307 | |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 5308 | drbd_err(device, "Got NegDReply; Sector %llus, len %u.\n", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5309 | (unsigned long long)sector, be32_to_cpu(p->blksize)); |
| 5310 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5311 | return validate_req_change_req_state(device, p->block_id, sector, |
| 5312 | &device->read_requests, __func__, |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5313 | NEG_ACKED, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5314 | } |
| 5315 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5316 | static int got_NegRSDReply(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5317 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5318 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5319 | struct drbd_device *device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5320 | sector_t sector; |
| 5321 | int size; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5322 | struct p_block_ack *p = pi->data; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5323 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5324 | peer_device = conn_peer_device(connection, pi->vnr); |
| 5325 | if (!peer_device) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5326 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5327 | device = peer_device->device; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5328 | |
| 5329 | sector = be64_to_cpu(p->sector); |
| 5330 | size = be32_to_cpu(p->blksize); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5331 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 5332 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5333 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5334 | dec_rs_pending(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5335 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5336 | if (get_ldev_if_state(device, D_FAILED)) { |
| 5337 | drbd_rs_complete_io(device, sector); |
Andreas Gruenbacher | e05e1e5 | 2011-03-25 15:16:26 +0100 | [diff] [blame] | 5338 | switch (pi->cmd) { |
Philipp Reisner | d612d30 | 2010-12-27 10:53:28 +0100 | [diff] [blame] | 5339 | case P_NEG_RS_DREPLY: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5340 | drbd_rs_failed_io(device, sector, size); |
Philipp Reisner | d612d30 | 2010-12-27 10:53:28 +0100 | [diff] [blame] | 5341 | case P_RS_CANCEL: |
| 5342 | break; |
| 5343 | default: |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5344 | BUG(); |
Philipp Reisner | d612d30 | 2010-12-27 10:53:28 +0100 | [diff] [blame] | 5345 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5346 | put_ldev(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5347 | } |
| 5348 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5349 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5350 | } |
| 5351 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5352 | static int got_BarrierAck(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5353 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5354 | struct p_barrier_ack *p = pi->data; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 5355 | struct drbd_peer_device *peer_device; |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 5356 | int vnr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5357 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5358 | tl_release(connection, p->barrier, be32_to_cpu(p->set_size)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5359 | |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 5360 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 5361 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 5362 | struct drbd_device *device = peer_device->device; |
| 5363 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5364 | if (device->state.conn == C_AHEAD && |
| 5365 | atomic_read(&device->ap_in_flight) == 0 && |
| 5366 | !test_and_set_bit(AHEAD_TO_SYNC_SOURCE, &device->flags)) { |
| 5367 | device->start_resync_timer.expires = jiffies + HZ; |
| 5368 | add_timer(&device->start_resync_timer); |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 5369 | } |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 5370 | } |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 5371 | rcu_read_unlock(); |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 5372 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5373 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5374 | } |
| 5375 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5376 | static int got_OVResult(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5377 | { |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5378 | struct drbd_peer_device *peer_device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5379 | struct drbd_device *device; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5380 | struct p_block_ack *p = pi->data; |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 5381 | struct drbd_device_work *dw; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5382 | sector_t sector; |
| 5383 | int size; |
| 5384 | |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5385 | peer_device = conn_peer_device(connection, pi->vnr); |
| 5386 | if (!peer_device) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5387 | return -EIO; |
Andreas Gruenbacher | 9f4fe9a | 2011-08-09 03:54:55 +0200 | [diff] [blame] | 5388 | device = peer_device->device; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5389 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5390 | sector = be64_to_cpu(p->sector); |
| 5391 | size = be32_to_cpu(p->blksize); |
| 5392 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 5393 | update_peer_seq(peer_device, be32_to_cpu(p->seq_num)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5394 | |
| 5395 | if (be64_to_cpu(p->block_id) == ID_OUT_OF_SYNC) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5396 | drbd_ov_out_of_sync_found(device, sector, size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5397 | else |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5398 | ov_out_of_sync_print(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5399 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5400 | if (!get_ldev(device)) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5401 | return 0; |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 5402 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5403 | drbd_rs_complete_io(device, sector); |
| 5404 | dec_rs_pending(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5405 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5406 | --device->ov_left; |
Lars Ellenberg | ea5442a | 2010-11-05 09:48:01 +0100 | [diff] [blame] | 5407 | |
| 5408 | /* let's advance progress step marks only for every other megabyte */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5409 | if ((device->ov_left & 0x200) == 0x200) |
| 5410 | drbd_advance_rs_marks(device, device->ov_left); |
Lars Ellenberg | ea5442a | 2010-11-05 09:48:01 +0100 | [diff] [blame] | 5411 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5412 | if (device->ov_left == 0) { |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 5413 | dw = kmalloc(sizeof(*dw), GFP_NOIO); |
| 5414 | if (dw) { |
| 5415 | dw->w.cb = w_ov_finished; |
| 5416 | dw->device = device; |
| 5417 | drbd_queue_work(&peer_device->connection->sender_work, &dw->w); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5418 | } else { |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 5419 | drbd_err(device, "kmalloc(dw) failed."); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5420 | ov_out_of_sync_print(device); |
| 5421 | drbd_resync_finished(device); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5422 | } |
| 5423 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5424 | put_ldev(device); |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5425 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5426 | } |
| 5427 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5428 | static int got_skip(struct drbd_connection *connection, struct packet_info *pi) |
Philipp Reisner | 0ced55a | 2010-04-30 15:26:20 +0200 | [diff] [blame] | 5429 | { |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5430 | return 0; |
Philipp Reisner | 0ced55a | 2010-04-30 15:26:20 +0200 | [diff] [blame] | 5431 | } |
| 5432 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5433 | static int connection_finish_peer_reqs(struct drbd_connection *connection) |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5434 | { |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 5435 | struct drbd_peer_device *peer_device; |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5436 | int vnr, not_empty = 0; |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5437 | |
| 5438 | do { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5439 | clear_bit(SIGNAL_ASENDER, &connection->flags); |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5440 | flush_signals(current); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5441 | |
| 5442 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 5443 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 5444 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5445 | kref_get(&device->kref); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5446 | rcu_read_unlock(); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5447 | if (drbd_finish_peer_reqs(device)) { |
Andreas Gruenbacher | 05a10ec | 2011-06-07 22:54:17 +0200 | [diff] [blame] | 5448 | kref_put(&device->kref, drbd_destroy_device); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5449 | return 1; |
Philipp Reisner | d3fcb49 | 2011-04-13 14:46:05 -0700 | [diff] [blame] | 5450 | } |
Andreas Gruenbacher | 05a10ec | 2011-06-07 22:54:17 +0200 | [diff] [blame] | 5451 | kref_put(&device->kref, drbd_destroy_device); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5452 | rcu_read_lock(); |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 5453 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5454 | set_bit(SIGNAL_ASENDER, &connection->flags); |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 5455 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 5456 | spin_lock_irq(&connection->resource->req_lock); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 5457 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 5458 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 5459 | not_empty = !list_empty(&device->done_ee); |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 5460 | if (not_empty) |
| 5461 | break; |
| 5462 | } |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 5463 | spin_unlock_irq(&connection->resource->req_lock); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5464 | rcu_read_unlock(); |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5465 | } while (not_empty); |
| 5466 | |
| 5467 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | struct asender_cmd { |
| 5471 | size_t pkt_size; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5472 | int (*fn)(struct drbd_connection *connection, struct packet_info *); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5473 | }; |
| 5474 | |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 5475 | static struct asender_cmd asender_tbl[] = { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5476 | [P_PING] = { 0, got_Ping }, |
| 5477 | [P_PING_ACK] = { 0, got_PingAck }, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5478 | [P_RECV_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 5479 | [P_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 5480 | [P_RS_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, |
Lars Ellenberg | d4dabbe | 2012-08-01 12:33:51 +0200 | [diff] [blame] | 5481 | [P_SUPERSEDED] = { sizeof(struct p_block_ack), got_BlockAck }, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5482 | [P_NEG_ACK] = { sizeof(struct p_block_ack), got_NegAck }, |
| 5483 | [P_NEG_DREPLY] = { sizeof(struct p_block_ack), got_NegDReply }, |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5484 | [P_NEG_RS_DREPLY] = { sizeof(struct p_block_ack), got_NegRSDReply }, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5485 | [P_OV_RESULT] = { sizeof(struct p_block_ack), got_OVResult }, |
| 5486 | [P_BARRIER_ACK] = { sizeof(struct p_barrier_ack), got_BarrierAck }, |
| 5487 | [P_STATE_CHG_REPLY] = { sizeof(struct p_req_state_reply), got_RqSReply }, |
| 5488 | [P_RS_IS_IN_SYNC] = { sizeof(struct p_block_ack), got_IsInSync }, |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 5489 | [P_DELAY_PROBE] = { sizeof(struct p_delay_probe93), got_skip }, |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5490 | [P_RS_CANCEL] = { sizeof(struct p_block_ack), got_NegRSDReply }, |
| 5491 | [P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), got_conn_RqSReply }, |
| 5492 | [P_RETRY_WRITE] = { sizeof(struct p_block_ack), got_BlockAck }, |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 5493 | }; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5494 | |
| 5495 | int drbd_asender(struct drbd_thread *thi) |
| 5496 | { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5497 | struct drbd_connection *connection = thi->connection; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5498 | struct asender_cmd *cmd = NULL; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 5499 | struct packet_info pi; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 5500 | int rv; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5501 | void *buf = connection->meta.rbuf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5502 | int received = 0; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5503 | unsigned int header_size = drbd_header_size(connection); |
Andreas Gruenbacher | 52b061a | 2011-03-30 11:38:49 +0200 | [diff] [blame] | 5504 | int expect = header_size; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5505 | bool ping_timeout_active = false; |
| 5506 | struct net_conf *nc; |
Andreas Gruenbacher | bb77d34 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 5507 | int ping_timeo, tcp_cork, ping_int; |
Philipp Reisner | 3990e04 | 2013-03-27 14:08:48 +0100 | [diff] [blame] | 5508 | struct sched_param param = { .sched_priority = 2 }; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5509 | |
Philipp Reisner | 3990e04 | 2013-03-27 14:08:48 +0100 | [diff] [blame] | 5510 | rv = sched_setscheduler(current, SCHED_RR, ¶m); |
| 5511 | if (rv < 0) |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5512 | drbd_err(connection, "drbd_asender: ERROR set priority, ret=%d\n", rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5513 | |
Andreas Gruenbacher | e77a0a5 | 2011-01-25 15:43:39 +0100 | [diff] [blame] | 5514 | while (get_t_state(thi) == RUNNING) { |
Philipp Reisner | 8082228 | 2011-02-08 12:46:30 +0100 | [diff] [blame] | 5515 | drbd_thread_current_set_cpu(thi); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5516 | |
| 5517 | rcu_read_lock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5518 | nc = rcu_dereference(connection->net_conf); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5519 | ping_timeo = nc->ping_timeo; |
Andreas Gruenbacher | bb77d34 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 5520 | tcp_cork = nc->tcp_cork; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5521 | ping_int = nc->ping_int; |
| 5522 | rcu_read_unlock(); |
| 5523 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5524 | if (test_and_clear_bit(SEND_PING, &connection->flags)) { |
| 5525 | if (drbd_send_ping(connection)) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5526 | drbd_err(connection, "drbd_send_ping has failed\n"); |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 5527 | goto reconnect; |
| 5528 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5529 | connection->meta.socket->sk->sk_rcvtimeo = ping_timeo * HZ / 10; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5530 | ping_timeout_active = true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5531 | } |
| 5532 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5533 | /* TODO: conditionally cork; it may hurt latency if we cork without |
| 5534 | much to send */ |
Andreas Gruenbacher | bb77d34 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 5535 | if (tcp_cork) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5536 | drbd_tcp_cork(connection->meta.socket); |
| 5537 | if (connection_finish_peer_reqs(connection)) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5538 | drbd_err(connection, "connection_finish_peer_reqs() failed\n"); |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5539 | goto reconnect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5540 | } |
| 5541 | /* but unconditionally uncork unless disabled */ |
Andreas Gruenbacher | bb77d34 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 5542 | if (tcp_cork) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5543 | drbd_tcp_uncork(connection->meta.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5544 | |
| 5545 | /* short circuit, recv_msg would return EINTR anyways. */ |
| 5546 | if (signal_pending(current)) |
| 5547 | continue; |
| 5548 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5549 | rv = drbd_recv_short(connection->meta.socket, buf, expect-received, 0); |
| 5550 | clear_bit(SIGNAL_ASENDER, &connection->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5551 | |
| 5552 | flush_signals(current); |
| 5553 | |
| 5554 | /* Note: |
| 5555 | * -EINTR (on meta) we got a signal |
| 5556 | * -EAGAIN (on meta) rcvtimeo expired |
| 5557 | * -ECONNRESET other side closed the connection |
| 5558 | * -ERESTARTSYS (on data) we got a signal |
| 5559 | * rv < 0 other than above: unexpected error! |
| 5560 | * rv == expected: full header or command |
| 5561 | * rv < expected: "woken" by signal during receive |
| 5562 | * rv == 0 : "connection shut down by peer" |
| 5563 | */ |
Lars Ellenberg | abde9cc | 2014-09-11 14:29:11 +0200 | [diff] [blame] | 5564 | received_more: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5565 | if (likely(rv > 0)) { |
| 5566 | received += rv; |
| 5567 | buf += rv; |
| 5568 | } else if (rv == 0) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5569 | if (test_bit(DISCONNECT_SENT, &connection->flags)) { |
Philipp Reisner | b66623e | 2012-08-08 21:19:09 +0200 | [diff] [blame] | 5570 | long t; |
| 5571 | rcu_read_lock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5572 | t = rcu_dereference(connection->net_conf)->ping_timeo * HZ/10; |
Philipp Reisner | b66623e | 2012-08-08 21:19:09 +0200 | [diff] [blame] | 5573 | rcu_read_unlock(); |
| 5574 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5575 | t = wait_event_timeout(connection->ping_wait, |
| 5576 | connection->cstate < C_WF_REPORT_PARAMS, |
Philipp Reisner | b66623e | 2012-08-08 21:19:09 +0200 | [diff] [blame] | 5577 | t); |
Philipp Reisner | 599377a | 2012-08-17 14:50:22 +0200 | [diff] [blame] | 5578 | if (t) |
| 5579 | break; |
| 5580 | } |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5581 | drbd_err(connection, "meta connection shut down by peer.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5582 | goto reconnect; |
| 5583 | } else if (rv == -EAGAIN) { |
Lars Ellenberg | cb6518c | 2011-06-20 14:44:45 +0200 | [diff] [blame] | 5584 | /* If the data socket received something meanwhile, |
| 5585 | * that is good enough: peer is still alive. */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5586 | if (time_after(connection->last_received, |
| 5587 | jiffies - connection->meta.socket->sk->sk_rcvtimeo)) |
Lars Ellenberg | cb6518c | 2011-06-20 14:44:45 +0200 | [diff] [blame] | 5588 | continue; |
Lars Ellenberg | f36af18 | 2011-03-09 22:44:55 +0100 | [diff] [blame] | 5589 | if (ping_timeout_active) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5590 | drbd_err(connection, "PingAck did not arrive in time.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5591 | goto reconnect; |
| 5592 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5593 | set_bit(SEND_PING, &connection->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5594 | continue; |
| 5595 | } else if (rv == -EINTR) { |
| 5596 | continue; |
| 5597 | } else { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5598 | drbd_err(connection, "sock_recvmsg returned %d\n", rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5599 | goto reconnect; |
| 5600 | } |
| 5601 | |
| 5602 | if (received == expect && cmd == NULL) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5603 | if (decode_header(connection, connection->meta.rbuf, &pi)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5604 | goto reconnect; |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 5605 | cmd = &asender_tbl[pi.cmd]; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5606 | if (pi.cmd >= ARRAY_SIZE(asender_tbl) || !cmd->fn) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5607 | drbd_err(connection, "Unexpected meta packet %s (0x%04x)\n", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 5608 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5609 | goto disconnect; |
| 5610 | } |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5611 | expect = header_size + cmd->pkt_size; |
Andreas Gruenbacher | 52b061a | 2011-03-30 11:38:49 +0200 | [diff] [blame] | 5612 | if (pi.size != expect - header_size) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5613 | drbd_err(connection, "Wrong packet size on meta (c: %d, l: %d)\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 5614 | pi.cmd, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5615 | goto reconnect; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 5616 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5617 | } |
| 5618 | if (received == expect) { |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5619 | bool err; |
Philipp Reisner | a4fbda8 | 2011-03-16 11:13:17 +0100 | [diff] [blame] | 5620 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5621 | err = cmd->fn(connection, &pi); |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5622 | if (err) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5623 | drbd_err(connection, "%pf failed\n", cmd->fn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5624 | goto reconnect; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5625 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5626 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5627 | connection->last_received = jiffies; |
Lars Ellenberg | f36af18 | 2011-03-09 22:44:55 +0100 | [diff] [blame] | 5628 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5629 | if (cmd == &asender_tbl[P_PING_ACK]) { |
| 5630 | /* restore idle timeout */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5631 | connection->meta.socket->sk->sk_rcvtimeo = ping_int * HZ; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5632 | ping_timeout_active = false; |
| 5633 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5634 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5635 | buf = connection->meta.rbuf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5636 | received = 0; |
Andreas Gruenbacher | 52b061a | 2011-03-30 11:38:49 +0200 | [diff] [blame] | 5637 | expect = header_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5638 | cmd = NULL; |
| 5639 | } |
Lars Ellenberg | abde9cc | 2014-09-11 14:29:11 +0200 | [diff] [blame] | 5640 | if (test_bit(SEND_PING, &connection->flags)) |
| 5641 | continue; |
| 5642 | rv = drbd_recv_short(connection->meta.socket, buf, expect-received, MSG_DONTWAIT); |
| 5643 | if (rv > 0) |
| 5644 | goto received_more; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | if (0) { |
| 5648 | reconnect: |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5649 | conn_request_state(connection, NS(conn, C_NETWORK_FAILURE), CS_HARD); |
| 5650 | conn_md_sync(connection); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5651 | } |
| 5652 | if (0) { |
| 5653 | disconnect: |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5654 | conn_request_state(connection, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5655 | } |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 5656 | clear_bit(SIGNAL_ASENDER, &connection->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5657 | |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 5658 | drbd_info(connection, "asender terminated\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5659 | |
| 5660 | return 0; |
| 5661 | } |