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" |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 47 | #include "drbd_req.h" |
| 48 | |
| 49 | #include "drbd_vli.h" |
| 50 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 51 | struct packet_info { |
| 52 | enum drbd_packet cmd; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 53 | unsigned int size; |
| 54 | unsigned int vnr; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 55 | void *data; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 58 | enum finish_epoch { |
| 59 | FE_STILL_LIVE, |
| 60 | FE_DESTROYED, |
| 61 | FE_RECYCLED, |
| 62 | }; |
| 63 | |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 64 | static int drbd_do_features(struct drbd_tconn *tconn); |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 65 | static int drbd_do_auth(struct drbd_tconn *tconn); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 66 | static int drbd_disconnected(struct drbd_conf *mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 67 | |
Philipp Reisner | 1e9dd29 | 2011-11-10 15:14:53 +0100 | [diff] [blame] | 68 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *, struct drbd_epoch *, enum epoch_event); |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 69 | static int e_end_block(struct drbd_work *, int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 70 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 71 | |
| 72 | #define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN) |
| 73 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 74 | /* |
| 75 | * some helper functions to deal with single linked page lists, |
| 76 | * page->private being our "next" pointer. |
| 77 | */ |
| 78 | |
| 79 | /* If at least n pages are linked at head, get n pages off. |
| 80 | * Otherwise, don't modify head, and return NULL. |
| 81 | * Locking is the responsibility of the caller. |
| 82 | */ |
| 83 | static struct page *page_chain_del(struct page **head, int n) |
| 84 | { |
| 85 | struct page *page; |
| 86 | struct page *tmp; |
| 87 | |
| 88 | BUG_ON(!n); |
| 89 | BUG_ON(!head); |
| 90 | |
| 91 | page = *head; |
Philipp Reisner | 23ce422 | 2010-05-20 13:35:31 +0200 | [diff] [blame] | 92 | |
| 93 | if (!page) |
| 94 | return NULL; |
| 95 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 96 | while (page) { |
| 97 | tmp = page_chain_next(page); |
| 98 | if (--n == 0) |
| 99 | break; /* found sufficient pages */ |
| 100 | if (tmp == NULL) |
| 101 | /* insufficient pages, don't use any of them. */ |
| 102 | return NULL; |
| 103 | page = tmp; |
| 104 | } |
| 105 | |
| 106 | /* add end of list marker for the returned list */ |
| 107 | set_page_private(page, 0); |
| 108 | /* actual return value, and adjustment of head */ |
| 109 | page = *head; |
| 110 | *head = tmp; |
| 111 | return page; |
| 112 | } |
| 113 | |
| 114 | /* may be used outside of locks to find the tail of a (usually short) |
| 115 | * "private" page chain, before adding it back to a global chain head |
| 116 | * with page_chain_add() under a spinlock. */ |
| 117 | static struct page *page_chain_tail(struct page *page, int *len) |
| 118 | { |
| 119 | struct page *tmp; |
| 120 | int i = 1; |
| 121 | while ((tmp = page_chain_next(page))) |
| 122 | ++i, page = tmp; |
| 123 | if (len) |
| 124 | *len = i; |
| 125 | return page; |
| 126 | } |
| 127 | |
| 128 | static int page_chain_free(struct page *page) |
| 129 | { |
| 130 | struct page *tmp; |
| 131 | int i = 0; |
| 132 | page_chain_for_each_safe(page, tmp) { |
| 133 | put_page(page); |
| 134 | ++i; |
| 135 | } |
| 136 | return i; |
| 137 | } |
| 138 | |
| 139 | static void page_chain_add(struct page **head, |
| 140 | struct page *chain_first, struct page *chain_last) |
| 141 | { |
| 142 | #if 1 |
| 143 | struct page *tmp; |
| 144 | tmp = page_chain_tail(chain_first, NULL); |
| 145 | BUG_ON(tmp != chain_last); |
| 146 | #endif |
| 147 | |
| 148 | /* add chain to head */ |
| 149 | set_page_private(chain_last, (unsigned long)*head); |
| 150 | *head = chain_first; |
| 151 | } |
| 152 | |
Andreas Gruenbacher | 18c2d52 | 2011-04-07 21:08:50 +0200 | [diff] [blame] | 153 | static struct page *__drbd_alloc_pages(struct drbd_conf *mdev, |
| 154 | unsigned int number) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 155 | { |
| 156 | struct page *page = NULL; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 157 | struct page *tmp = NULL; |
Andreas Gruenbacher | 18c2d52 | 2011-04-07 21:08:50 +0200 | [diff] [blame] | 158 | unsigned int i = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 159 | |
| 160 | /* Yes, testing drbd_pp_vacant outside the lock is racy. |
| 161 | * So what. It saves a spin_lock. */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 162 | if (drbd_pp_vacant >= number) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 163 | spin_lock(&drbd_pp_lock); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 164 | page = page_chain_del(&drbd_pp_pool, number); |
| 165 | if (page) |
| 166 | drbd_pp_vacant -= number; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 167 | spin_unlock(&drbd_pp_lock); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 168 | if (page) |
| 169 | return page; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 170 | } |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 171 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 172 | /* GFP_TRY, because we must not cause arbitrary write-out: in a DRBD |
| 173 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
| 174 | * 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] | 175 | for (i = 0; i < number; i++) { |
| 176 | tmp = alloc_page(GFP_TRY); |
| 177 | if (!tmp) |
| 178 | break; |
| 179 | set_page_private(tmp, (unsigned long)page); |
| 180 | page = tmp; |
| 181 | } |
| 182 | |
| 183 | if (i == number) |
| 184 | return page; |
| 185 | |
| 186 | /* Not enough pages immediately available this time. |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 187 | * No need to jump around here, drbd_alloc_pages will retry this |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 188 | * function "soon". */ |
| 189 | if (page) { |
| 190 | tmp = page_chain_tail(page, NULL); |
| 191 | spin_lock(&drbd_pp_lock); |
| 192 | page_chain_add(&drbd_pp_pool, page, tmp); |
| 193 | drbd_pp_vacant += i; |
| 194 | spin_unlock(&drbd_pp_lock); |
| 195 | } |
| 196 | return NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 199 | static void reclaim_finished_net_peer_reqs(struct drbd_conf *mdev, |
| 200 | struct list_head *to_be_freed) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 201 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 202 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 203 | struct list_head *le, *tle; |
| 204 | |
| 205 | /* The EEs are always appended to the end of the list. Since |
| 206 | they are sent in order over the wire, they have to finish |
| 207 | in order. As soon as we see the first not finished we can |
| 208 | stop to examine the list... */ |
| 209 | |
| 210 | list_for_each_safe(le, tle, &mdev->net_ee) { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 211 | peer_req = list_entry(le, struct drbd_peer_request, 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; |
| 214 | list_move(le, to_be_freed); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static void drbd_kick_lo_and_reclaim_net(struct drbd_conf *mdev) |
| 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 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 223 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 224 | reclaim_finished_net_peer_reqs(mdev, &reclaimed); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 225 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 226 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 227 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 228 | drbd_free_net_peer_req(mdev, 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) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 233 | * @mdev: 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 |
| 238 | * the kernel, unless this allocation would exceed the max_buffers setting. |
| 239 | * Possibly retry until DRBD frees sufficient pages somewhere else. |
| 240 | * |
| 241 | * Returns a page chain linked via page->private. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 242 | */ |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 243 | struct page *drbd_alloc_pages(struct drbd_conf *mdev, unsigned int number, |
| 244 | bool retry) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 245 | { |
| 246 | struct page *page = NULL; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 247 | struct net_conf *nc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 248 | DEFINE_WAIT(wait); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 249 | int mxb; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 250 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 251 | /* Yes, we may run up to @number over max_buffers. If we |
| 252 | * follow it strictly, the admin will get it wrong anyways. */ |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 253 | rcu_read_lock(); |
| 254 | nc = rcu_dereference(mdev->tconn->net_conf); |
| 255 | mxb = nc ? nc->max_buffers : 1000000; |
| 256 | rcu_read_unlock(); |
| 257 | |
| 258 | if (atomic_read(&mdev->pp_in_use) < mxb) |
Andreas Gruenbacher | 18c2d52 | 2011-04-07 21:08:50 +0200 | [diff] [blame] | 259 | page = __drbd_alloc_pages(mdev, number); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 260 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 261 | while (page == NULL) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 262 | prepare_to_wait(&drbd_pp_wait, &wait, TASK_INTERRUPTIBLE); |
| 263 | |
| 264 | drbd_kick_lo_and_reclaim_net(mdev); |
| 265 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 266 | if (atomic_read(&mdev->pp_in_use) < mxb) { |
Andreas Gruenbacher | 18c2d52 | 2011-04-07 21:08:50 +0200 | [diff] [blame] | 267 | page = __drbd_alloc_pages(mdev, number); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 268 | if (page) |
| 269 | break; |
| 270 | } |
| 271 | |
| 272 | if (!retry) |
| 273 | break; |
| 274 | |
| 275 | if (signal_pending(current)) { |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 276 | dev_warn(DEV, "drbd_alloc_pages interrupted!\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 277 | break; |
| 278 | } |
| 279 | |
| 280 | schedule(); |
| 281 | } |
| 282 | finish_wait(&drbd_pp_wait, &wait); |
| 283 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 284 | if (page) |
| 285 | atomic_add(number, &mdev->pp_in_use); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 286 | return page; |
| 287 | } |
| 288 | |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 289 | /* Must not be used from irq, as that may deadlock: see drbd_alloc_pages. |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 290 | * Is also used from inside an other spin_lock_irq(&mdev->tconn->req_lock); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 291 | * Either links the page chain back to the global pool, |
| 292 | * or returns all pages to the system. */ |
Andreas Gruenbacher | 5cc287e | 2011-04-07 21:02:59 +0200 | [diff] [blame] | 293 | static void drbd_free_pages(struct drbd_conf *mdev, struct page *page, int is_net) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 294 | { |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 295 | atomic_t *a = is_net ? &mdev->pp_in_use_by_net : &mdev->pp_in_use; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 296 | int i; |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 297 | |
Philipp Reisner | 81a5d60 | 2011-02-22 19:53:16 -0500 | [diff] [blame] | 298 | if (drbd_pp_vacant > (DRBD_MAX_BIO_SIZE/PAGE_SIZE) * minor_count) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 299 | i = page_chain_free(page); |
| 300 | else { |
| 301 | struct page *tmp; |
| 302 | tmp = page_chain_tail(page, &i); |
| 303 | spin_lock(&drbd_pp_lock); |
| 304 | page_chain_add(&drbd_pp_pool, page, tmp); |
| 305 | drbd_pp_vacant += i; |
| 306 | spin_unlock(&drbd_pp_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 307 | } |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 308 | i = atomic_sub_return(i, a); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 309 | if (i < 0) |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 310 | dev_warn(DEV, "ASSERTION FAILED: %s: %d < 0\n", |
| 311 | is_net ? "pp_in_use_by_net" : "pp_in_use", i); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 312 | wake_up(&drbd_pp_wait); |
| 313 | } |
| 314 | |
| 315 | /* |
| 316 | You need to hold the req_lock: |
| 317 | _drbd_wait_ee_list_empty() |
| 318 | |
| 319 | You must not have the req_lock: |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 320 | drbd_free_peer_req() |
Andreas Gruenbacher | 0db5536 | 2011-04-06 16:09:15 +0200 | [diff] [blame] | 321 | drbd_alloc_peer_req() |
Andreas Gruenbacher | 7721f56 | 2011-04-06 17:14:02 +0200 | [diff] [blame] | 322 | drbd_free_peer_reqs() |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 323 | drbd_ee_fix_bhs() |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 324 | drbd_finish_peer_reqs() |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 325 | drbd_clear_done_ee() |
| 326 | drbd_wait_ee_list_empty() |
| 327 | */ |
| 328 | |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 329 | struct drbd_peer_request * |
Andreas Gruenbacher | 0db5536 | 2011-04-06 16:09:15 +0200 | [diff] [blame] | 330 | drbd_alloc_peer_req(struct drbd_conf *mdev, u64 id, sector_t sector, |
| 331 | unsigned int data_size, gfp_t gfp_mask) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 332 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 333 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 334 | struct page *page; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 335 | unsigned nr_pages = (data_size + PAGE_SIZE -1) >> PAGE_SHIFT; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 336 | |
Andreas Gruenbacher | 0cf9d27 | 2010-12-07 10:43:29 +0100 | [diff] [blame] | 337 | if (drbd_insert_fault(mdev, DRBD_FAULT_AL_EE)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 338 | return NULL; |
| 339 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 340 | peer_req = mempool_alloc(drbd_ee_mempool, gfp_mask & ~__GFP_HIGHMEM); |
| 341 | if (!peer_req) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 342 | if (!(gfp_mask & __GFP_NOWARN)) |
Andreas Gruenbacher | 0db5536 | 2011-04-06 16:09:15 +0200 | [diff] [blame] | 343 | dev_err(DEV, "%s: allocation failed\n", __func__); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 344 | return NULL; |
| 345 | } |
| 346 | |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 347 | page = drbd_alloc_pages(mdev, nr_pages, (gfp_mask & __GFP_WAIT)); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 348 | if (!page) |
| 349 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 350 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 351 | drbd_clear_interval(&peer_req->i); |
| 352 | peer_req->i.size = data_size; |
| 353 | peer_req->i.sector = sector; |
| 354 | peer_req->i.local = false; |
| 355 | peer_req->i.waiting = false; |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 356 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 357 | peer_req->epoch = NULL; |
Philipp Reisner | a21e929 | 2011-02-08 15:08:49 +0100 | [diff] [blame] | 358 | peer_req->w.mdev = mdev; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 359 | peer_req->pages = page; |
| 360 | atomic_set(&peer_req->pending_bios, 0); |
| 361 | peer_req->flags = 0; |
Andreas Gruenbacher | 9a8e775 | 2011-01-11 14:04:09 +0100 | [diff] [blame] | 362 | /* |
| 363 | * The block_id is opaque to the receiver. It is not endianness |
| 364 | * converted, and sent back to the sender unchanged. |
| 365 | */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 366 | peer_req->block_id = id; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 367 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 368 | return peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 369 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 370 | fail: |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 371 | mempool_free(peer_req, drbd_ee_mempool); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 372 | return NULL; |
| 373 | } |
| 374 | |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 375 | void __drbd_free_peer_req(struct drbd_conf *mdev, struct drbd_peer_request *peer_req, |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 376 | int is_net) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 377 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 378 | if (peer_req->flags & EE_HAS_DIGEST) |
| 379 | kfree(peer_req->digest); |
Andreas Gruenbacher | 5cc287e | 2011-04-07 21:02:59 +0200 | [diff] [blame] | 380 | drbd_free_pages(mdev, peer_req->pages, is_net); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 381 | D_ASSERT(atomic_read(&peer_req->pending_bios) == 0); |
| 382 | D_ASSERT(drbd_interval_empty(&peer_req->i)); |
| 383 | mempool_free(peer_req, drbd_ee_mempool); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Andreas Gruenbacher | 7721f56 | 2011-04-06 17:14:02 +0200 | [diff] [blame] | 386 | int drbd_free_peer_reqs(struct drbd_conf *mdev, struct list_head *list) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 387 | { |
| 388 | LIST_HEAD(work_list); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 389 | struct drbd_peer_request *peer_req, *t; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 390 | int count = 0; |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 391 | int is_net = list == &mdev->net_ee; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 392 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 393 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 394 | list_splice_init(list, &work_list); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 395 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 396 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 397 | list_for_each_entry_safe(peer_req, t, &work_list, w.list) { |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 398 | __drbd_free_peer_req(mdev, peer_req, is_net); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 399 | count++; |
| 400 | } |
| 401 | return count; |
| 402 | } |
| 403 | |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 404 | /* |
| 405 | * See also comments in _req_mod(,BARRIER_ACKED) and receive_Barrier. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 406 | */ |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 407 | static int drbd_finish_peer_reqs(struct drbd_conf *mdev) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 408 | { |
| 409 | LIST_HEAD(work_list); |
| 410 | LIST_HEAD(reclaimed); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 411 | struct drbd_peer_request *peer_req, *t; |
Andreas Gruenbacher | e2b3032 | 2011-03-16 17:16:12 +0100 | [diff] [blame] | 412 | int err = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 413 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 414 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 415 | reclaim_finished_net_peer_reqs(mdev, &reclaimed); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 416 | list_splice_init(&mdev->done_ee, &work_list); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 417 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 418 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 419 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 420 | drbd_free_net_peer_req(mdev, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 421 | |
| 422 | /* possible callbacks here: |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 423 | * e_end_block, and e_end_resync_block, e_send_discard_write. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 424 | * all ignore the last argument. |
| 425 | */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 426 | list_for_each_entry_safe(peer_req, t, &work_list, w.list) { |
Andreas Gruenbacher | e2b3032 | 2011-03-16 17:16:12 +0100 | [diff] [blame] | 427 | int err2; |
| 428 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 429 | /* list_del not necessary, next/prev members not touched */ |
Andreas Gruenbacher | e2b3032 | 2011-03-16 17:16:12 +0100 | [diff] [blame] | 430 | err2 = peer_req->w.cb(&peer_req->w, !!err); |
| 431 | if (!err) |
| 432 | err = err2; |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 433 | drbd_free_peer_req(mdev, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 434 | } |
| 435 | wake_up(&mdev->ee_wait); |
| 436 | |
Andreas Gruenbacher | e2b3032 | 2011-03-16 17:16:12 +0100 | [diff] [blame] | 437 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Andreas Gruenbacher | d4da153 | 2011-04-07 00:06:56 +0200 | [diff] [blame] | 440 | static void _drbd_wait_ee_list_empty(struct drbd_conf *mdev, |
| 441 | struct list_head *head) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 442 | { |
| 443 | DEFINE_WAIT(wait); |
| 444 | |
| 445 | /* avoids spin_lock/unlock |
| 446 | * and calling prepare_to_wait in the fast path */ |
| 447 | while (!list_empty(head)) { |
| 448 | prepare_to_wait(&mdev->ee_wait, &wait, TASK_UNINTERRUPTIBLE); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 449 | spin_unlock_irq(&mdev->tconn->req_lock); |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 450 | io_schedule(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 451 | finish_wait(&mdev->ee_wait, &wait); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 452 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Andreas Gruenbacher | d4da153 | 2011-04-07 00:06:56 +0200 | [diff] [blame] | 456 | static void drbd_wait_ee_list_empty(struct drbd_conf *mdev, |
| 457 | struct list_head *head) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 458 | { |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 459 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 460 | _drbd_wait_ee_list_empty(mdev, head); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 461 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 464 | 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] | 465 | { |
| 466 | mm_segment_t oldfs; |
| 467 | struct kvec iov = { |
| 468 | .iov_base = buf, |
| 469 | .iov_len = size, |
| 470 | }; |
| 471 | struct msghdr msg = { |
| 472 | .msg_iovlen = 1, |
| 473 | .msg_iov = (struct iovec *)&iov, |
| 474 | .msg_flags = (flags ? flags : MSG_WAITALL | MSG_NOSIGNAL) |
| 475 | }; |
| 476 | int rv; |
| 477 | |
| 478 | oldfs = get_fs(); |
| 479 | set_fs(KERNEL_DS); |
| 480 | rv = sock_recvmsg(sock, &msg, size, msg.msg_flags); |
| 481 | set_fs(oldfs); |
| 482 | |
| 483 | return rv; |
| 484 | } |
| 485 | |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 486 | static int drbd_recv(struct drbd_tconn *tconn, void *buf, size_t size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 487 | { |
| 488 | mm_segment_t oldfs; |
| 489 | struct kvec iov = { |
| 490 | .iov_base = buf, |
| 491 | .iov_len = size, |
| 492 | }; |
| 493 | struct msghdr msg = { |
| 494 | .msg_iovlen = 1, |
| 495 | .msg_iov = (struct iovec *)&iov, |
| 496 | .msg_flags = MSG_WAITALL | MSG_NOSIGNAL |
| 497 | }; |
| 498 | int rv; |
| 499 | |
| 500 | oldfs = get_fs(); |
| 501 | set_fs(KERNEL_DS); |
| 502 | |
| 503 | for (;;) { |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 504 | rv = sock_recvmsg(tconn->data.socket, &msg, size, msg.msg_flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 505 | if (rv == size) |
| 506 | break; |
| 507 | |
| 508 | /* Note: |
| 509 | * ECONNRESET other side closed the connection |
| 510 | * ERESTARTSYS (on sock) we got a signal |
| 511 | */ |
| 512 | |
| 513 | if (rv < 0) { |
| 514 | if (rv == -ECONNRESET) |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 515 | conn_info(tconn, "sock was reset by peer\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 516 | else if (rv != -ERESTARTSYS) |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 517 | conn_err(tconn, "sock_recvmsg returned %d\n", rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 518 | break; |
| 519 | } else if (rv == 0) { |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 520 | conn_info(tconn, "sock was shut down by peer\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 521 | break; |
| 522 | } else { |
| 523 | /* signal came in, or peer/link went down, |
| 524 | * after we read a partial message |
| 525 | */ |
| 526 | /* D_ASSERT(signal_pending(current)); */ |
| 527 | break; |
| 528 | } |
| 529 | }; |
| 530 | |
| 531 | set_fs(oldfs); |
| 532 | |
| 533 | if (rv != size) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 534 | conn_request_state(tconn, NS(conn, C_BROKEN_PIPE), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 535 | |
| 536 | return rv; |
| 537 | } |
| 538 | |
Andreas Gruenbacher | c696774 | 2011-03-17 17:15:20 +0100 | [diff] [blame] | 539 | static int drbd_recv_all(struct drbd_tconn *tconn, void *buf, size_t size) |
| 540 | { |
| 541 | int err; |
| 542 | |
| 543 | err = drbd_recv(tconn, buf, size); |
| 544 | if (err != size) { |
| 545 | if (err >= 0) |
| 546 | err = -EIO; |
| 547 | } else |
| 548 | err = 0; |
| 549 | return err; |
| 550 | } |
| 551 | |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 552 | static int drbd_recv_all_warn(struct drbd_tconn *tconn, void *buf, size_t size) |
| 553 | { |
| 554 | int err; |
| 555 | |
| 556 | err = drbd_recv_all(tconn, buf, size); |
| 557 | if (err && !signal_pending(current)) |
| 558 | conn_warn(tconn, "short read (expected size %d)\n", (int)size); |
| 559 | return err; |
| 560 | } |
| 561 | |
Lars Ellenberg | 5dbf167 | 2010-05-25 16:18:01 +0200 | [diff] [blame] | 562 | /* quoting tcp(7): |
| 563 | * On individual connections, the socket buffer size must be set prior to the |
| 564 | * listen(2) or connect(2) calls in order to have it take effect. |
| 565 | * This is our wrapper to do so. |
| 566 | */ |
| 567 | static void drbd_setbufsize(struct socket *sock, unsigned int snd, |
| 568 | unsigned int rcv) |
| 569 | { |
| 570 | /* open coded SO_SNDBUF, SO_RCVBUF */ |
| 571 | if (snd) { |
| 572 | sock->sk->sk_sndbuf = snd; |
| 573 | sock->sk->sk_userlocks |= SOCK_SNDBUF_LOCK; |
| 574 | } |
| 575 | if (rcv) { |
| 576 | sock->sk->sk_rcvbuf = rcv; |
| 577 | sock->sk->sk_userlocks |= SOCK_RCVBUF_LOCK; |
| 578 | } |
| 579 | } |
| 580 | |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 581 | static struct socket *drbd_try_connect(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 582 | { |
| 583 | const char *what; |
| 584 | struct socket *sock; |
| 585 | struct sockaddr_in6 src_in6; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 586 | struct sockaddr_in6 peer_in6; |
| 587 | struct net_conf *nc; |
| 588 | int err, peer_addr_len, my_addr_len; |
Andreas Gruenbacher | 69ef82d | 2011-05-11 14:34:35 +0200 | [diff] [blame] | 589 | int sndbuf_size, rcvbuf_size, connect_int; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 590 | int disconnect_on_error = 1; |
| 591 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 592 | rcu_read_lock(); |
| 593 | nc = rcu_dereference(tconn->net_conf); |
| 594 | if (!nc) { |
| 595 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 596 | return NULL; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 597 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 598 | sndbuf_size = nc->sndbuf_size; |
| 599 | rcvbuf_size = nc->rcvbuf_size; |
Andreas Gruenbacher | 69ef82d | 2011-05-11 14:34:35 +0200 | [diff] [blame] | 600 | connect_int = nc->connect_int; |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 601 | rcu_read_unlock(); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 602 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 603 | my_addr_len = min_t(int, tconn->my_addr_len, sizeof(src_in6)); |
| 604 | memcpy(&src_in6, &tconn->my_addr, my_addr_len); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 605 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 606 | if (((struct sockaddr *)&tconn->my_addr)->sa_family == AF_INET6) |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 607 | src_in6.sin6_port = 0; |
| 608 | else |
| 609 | ((struct sockaddr_in *)&src_in6)->sin_port = 0; /* AF_INET & AF_SCI */ |
| 610 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 611 | peer_addr_len = min_t(int, tconn->peer_addr_len, sizeof(src_in6)); |
| 612 | memcpy(&peer_in6, &tconn->peer_addr, peer_addr_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 613 | |
| 614 | what = "sock_create_kern"; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 615 | err = sock_create_kern(((struct sockaddr *)&src_in6)->sa_family, |
| 616 | SOCK_STREAM, IPPROTO_TCP, &sock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 617 | if (err < 0) { |
| 618 | sock = NULL; |
| 619 | goto out; |
| 620 | } |
| 621 | |
| 622 | sock->sk->sk_rcvtimeo = |
Andreas Gruenbacher | 69ef82d | 2011-05-11 14:34:35 +0200 | [diff] [blame] | 623 | sock->sk->sk_sndtimeo = connect_int * HZ; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 624 | drbd_setbufsize(sock, sndbuf_size, rcvbuf_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 625 | |
| 626 | /* explicitly bind to the configured IP as source IP |
| 627 | * for the outgoing connections. |
| 628 | * This is needed for multihomed hosts and to be |
| 629 | * able to use lo: interfaces for drbd. |
| 630 | * Make sure to use 0 as port number, so linux selects |
| 631 | * a free one dynamically. |
| 632 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 633 | what = "bind before connect"; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 634 | err = sock->ops->bind(sock, (struct sockaddr *) &src_in6, my_addr_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 635 | if (err < 0) |
| 636 | goto out; |
| 637 | |
| 638 | /* connect may fail, peer not yet available. |
| 639 | * stay C_WF_CONNECTION, don't go Disconnecting! */ |
| 640 | disconnect_on_error = 0; |
| 641 | what = "connect"; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 642 | 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] | 643 | |
| 644 | out: |
| 645 | if (err < 0) { |
| 646 | if (sock) { |
| 647 | sock_release(sock); |
| 648 | sock = NULL; |
| 649 | } |
| 650 | switch (-err) { |
| 651 | /* timeout, busy, signal pending */ |
| 652 | case ETIMEDOUT: case EAGAIN: case EINPROGRESS: |
| 653 | case EINTR: case ERESTARTSYS: |
| 654 | /* peer not (yet) available, network problem */ |
| 655 | case ECONNREFUSED: case ENETUNREACH: |
| 656 | case EHOSTDOWN: case EHOSTUNREACH: |
| 657 | disconnect_on_error = 0; |
| 658 | break; |
| 659 | default: |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 660 | conn_err(tconn, "%s failed, err = %d\n", what, err); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 661 | } |
| 662 | if (disconnect_on_error) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 663 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 664 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 665 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 666 | return sock; |
| 667 | } |
| 668 | |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 669 | static struct socket *drbd_wait_for_connect(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 670 | { |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 671 | int timeo, err, my_addr_len; |
Andreas Gruenbacher | 69ef82d | 2011-05-11 14:34:35 +0200 | [diff] [blame] | 672 | int sndbuf_size, rcvbuf_size, connect_int; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 673 | struct socket *s_estab = NULL, *s_listen; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 674 | struct sockaddr_in6 my_addr; |
| 675 | struct net_conf *nc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 676 | const char *what; |
| 677 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 678 | rcu_read_lock(); |
| 679 | nc = rcu_dereference(tconn->net_conf); |
| 680 | if (!nc) { |
| 681 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 682 | return NULL; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 683 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 684 | sndbuf_size = nc->sndbuf_size; |
| 685 | rcvbuf_size = nc->rcvbuf_size; |
Andreas Gruenbacher | 69ef82d | 2011-05-11 14:34:35 +0200 | [diff] [blame] | 686 | connect_int = nc->connect_int; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 687 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 688 | |
Andreas Gruenbacher | 089c075 | 2011-06-14 18:28:09 +0200 | [diff] [blame] | 689 | my_addr_len = min_t(int, tconn->my_addr_len, sizeof(struct sockaddr_in6)); |
| 690 | memcpy(&my_addr, &tconn->my_addr, my_addr_len); |
| 691 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 692 | what = "sock_create_kern"; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 693 | err = sock_create_kern(((struct sockaddr *)&my_addr)->sa_family, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 694 | SOCK_STREAM, IPPROTO_TCP, &s_listen); |
| 695 | if (err) { |
| 696 | s_listen = NULL; |
| 697 | goto out; |
| 698 | } |
| 699 | |
Andreas Gruenbacher | 69ef82d | 2011-05-11 14:34:35 +0200 | [diff] [blame] | 700 | timeo = connect_int * HZ; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 701 | timeo += (random32() & 1) ? timeo / 7 : -timeo / 7; /* 28.5% random jitter */ |
| 702 | |
| 703 | s_listen->sk->sk_reuse = 1; /* SO_REUSEADDR */ |
| 704 | s_listen->sk->sk_rcvtimeo = timeo; |
| 705 | s_listen->sk->sk_sndtimeo = timeo; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 706 | drbd_setbufsize(s_listen, sndbuf_size, rcvbuf_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 707 | |
| 708 | what = "bind before listen"; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 709 | 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] | 710 | if (err < 0) |
| 711 | goto out; |
| 712 | |
Philipp Reisner | 2820fd3 | 2012-07-12 10:22:48 +0200 | [diff] [blame] | 713 | what = "listen"; |
| 714 | err = s_listen->ops->listen(s_listen, 5); |
| 715 | if (err < 0) |
| 716 | goto out; |
| 717 | |
Philipp Reisner | 7e0f096 | 2012-07-12 10:25:35 +0200 | [diff] [blame] | 718 | what = "accept"; |
| 719 | err = kernel_accept(s_listen, &s_estab, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 720 | |
| 721 | out: |
| 722 | if (s_listen) |
| 723 | sock_release(s_listen); |
| 724 | if (err < 0) { |
| 725 | if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 726 | conn_err(tconn, "%s failed, err = %d\n", what, err); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 727 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 728 | } |
| 729 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 730 | |
| 731 | return s_estab; |
| 732 | } |
| 733 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 734 | static int decode_header(struct drbd_tconn *, void *, struct packet_info *); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 735 | |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 736 | static int send_first_packet(struct drbd_tconn *tconn, struct drbd_socket *sock, |
| 737 | enum drbd_packet cmd) |
| 738 | { |
| 739 | if (!conn_prepare_command(tconn, sock)) |
| 740 | return -EIO; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 741 | return conn_send_command(tconn, sock, cmd, 0, NULL, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 744 | static int receive_first_packet(struct drbd_tconn *tconn, struct socket *sock) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 745 | { |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 746 | unsigned int header_size = drbd_header_size(tconn); |
| 747 | struct packet_info pi; |
| 748 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 749 | |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 750 | err = drbd_recv_short(sock, tconn->data.rbuf, header_size, 0); |
| 751 | if (err != header_size) { |
| 752 | if (err >= 0) |
| 753 | err = -EIO; |
| 754 | return err; |
| 755 | } |
| 756 | err = decode_header(tconn, tconn->data.rbuf, &pi); |
| 757 | if (err) |
| 758 | return err; |
| 759 | return pi.cmd; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /** |
| 763 | * drbd_socket_okay() - Free the socket if its connection is not okay |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 764 | * @sock: pointer to the pointer to the socket. |
| 765 | */ |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 766 | static int drbd_socket_okay(struct socket **sock) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 767 | { |
| 768 | int rr; |
| 769 | char tb[4]; |
| 770 | |
| 771 | if (!*sock) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 772 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 773 | |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 774 | rr = drbd_recv_short(*sock, tb, 4, MSG_DONTWAIT | MSG_PEEK); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 775 | |
| 776 | if (rr > 0 || rr == -EAGAIN) { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 777 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 778 | } else { |
| 779 | sock_release(*sock); |
| 780 | *sock = NULL; |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 781 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 782 | } |
| 783 | } |
Philipp Reisner | 2325eb6 | 2011-03-15 16:56:18 +0100 | [diff] [blame] | 784 | /* Gets called if a connection is established, or if a new minor gets created |
| 785 | in a connection */ |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 786 | int drbd_connected(struct drbd_conf *mdev) |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 787 | { |
Andreas Gruenbacher | 0829f5e | 2011-03-24 14:31:22 +0100 | [diff] [blame] | 788 | int err; |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 789 | |
| 790 | atomic_set(&mdev->packet_seq, 0); |
| 791 | mdev->peer_seq = 0; |
| 792 | |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 793 | mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ? |
| 794 | &mdev->tconn->cstate_mutex : |
| 795 | &mdev->own_state_mutex; |
| 796 | |
Andreas Gruenbacher | 0829f5e | 2011-03-24 14:31:22 +0100 | [diff] [blame] | 797 | err = drbd_send_sync_param(mdev); |
| 798 | if (!err) |
| 799 | err = drbd_send_sizes(mdev, 0, 0); |
| 800 | if (!err) |
| 801 | err = drbd_send_uuids(mdev); |
| 802 | if (!err) |
Philipp Reisner | 43de7c8 | 2011-11-10 13:16:13 +0100 | [diff] [blame] | 803 | err = drbd_send_current_state(mdev); |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 804 | clear_bit(USE_DEGR_WFC_T, &mdev->flags); |
| 805 | clear_bit(RESIZE_PENDING, &mdev->flags); |
Philipp Reisner | 8b924f1 | 2011-03-01 11:08:28 +0100 | [diff] [blame] | 806 | mod_timer(&mdev->request_timer, jiffies + HZ); /* just start it here. */ |
Andreas Gruenbacher | 0829f5e | 2011-03-24 14:31:22 +0100 | [diff] [blame] | 807 | return err; |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 810 | /* |
| 811 | * return values: |
| 812 | * 1 yes, we have a valid connection |
| 813 | * 0 oops, did not work out, please try again |
| 814 | * -1 peer talks different language, |
| 815 | * no point in trying again, please go standalone. |
| 816 | * -2 We do not have a network config... |
| 817 | */ |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 818 | static int conn_connect(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 819 | { |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 820 | struct drbd_socket sock, msock; |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 821 | struct drbd_conf *mdev; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 822 | struct net_conf *nc; |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 823 | int vnr, timeout, try, h, ok; |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 824 | bool discard_my_data; |
Philipp Reisner | a1096a6 | 2012-04-06 12:07:34 +0200 | [diff] [blame] | 825 | enum drbd_state_rv rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 826 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 827 | if (conn_request_state(tconn, NS(conn, C_WF_CONNECTION), CS_VERBOSE) < SS_SUCCESS) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 828 | return -2; |
| 829 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 830 | mutex_init(&sock.mutex); |
| 831 | sock.sbuf = tconn->data.sbuf; |
| 832 | sock.rbuf = tconn->data.rbuf; |
| 833 | sock.socket = NULL; |
| 834 | mutex_init(&msock.mutex); |
| 835 | msock.sbuf = tconn->meta.sbuf; |
| 836 | msock.rbuf = tconn->meta.rbuf; |
| 837 | msock.socket = NULL; |
| 838 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 839 | clear_bit(DISCARD_CONCURRENT, &tconn->flags); |
Andreas Gruenbacher | 0916e0e | 2011-03-21 14:10:15 +0100 | [diff] [blame] | 840 | |
| 841 | /* Assume that the peer only understands protocol 80 until we know better. */ |
| 842 | tconn->agreed_pro_version = 80; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 843 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 844 | do { |
Andreas Gruenbacher | 2bf8962 | 2011-03-28 16:33:12 +0200 | [diff] [blame] | 845 | struct socket *s; |
| 846 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 847 | for (try = 0;;) { |
| 848 | /* 3 tries, this should take less than a second! */ |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 849 | s = drbd_try_connect(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 850 | if (s || ++try >= 3) |
| 851 | break; |
| 852 | /* give the other side time to call bind() & listen() */ |
Philipp Reisner | 20ee639 | 2011-01-18 15:28:59 +0100 | [diff] [blame] | 853 | schedule_timeout_interruptible(HZ / 10); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | if (s) { |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 857 | if (!sock.socket) { |
| 858 | sock.socket = s; |
| 859 | send_first_packet(tconn, &sock, P_INITIAL_DATA); |
| 860 | } else if (!msock.socket) { |
| 861 | msock.socket = s; |
| 862 | send_first_packet(tconn, &msock, P_INITIAL_META); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 863 | } else { |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 864 | conn_err(tconn, "Logic error in conn_connect()\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 865 | goto out_release_sockets; |
| 866 | } |
| 867 | } |
| 868 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 869 | if (sock.socket && msock.socket) { |
| 870 | rcu_read_lock(); |
| 871 | nc = rcu_dereference(tconn->net_conf); |
| 872 | timeout = nc->ping_timeo * HZ / 10; |
| 873 | rcu_read_unlock(); |
| 874 | schedule_timeout_interruptible(timeout); |
| 875 | ok = drbd_socket_okay(&sock.socket); |
| 876 | ok = drbd_socket_okay(&msock.socket) && ok; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 877 | if (ok) |
| 878 | break; |
| 879 | } |
| 880 | |
| 881 | retry: |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 882 | s = drbd_wait_for_connect(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 883 | if (s) { |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 884 | try = receive_first_packet(tconn, s); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 885 | drbd_socket_okay(&sock.socket); |
| 886 | drbd_socket_okay(&msock.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 887 | switch (try) { |
Andreas Gruenbacher | e5d6f33 | 2011-03-28 16:44:40 +0200 | [diff] [blame] | 888 | case P_INITIAL_DATA: |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 889 | if (sock.socket) { |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 890 | conn_warn(tconn, "initial packet S crossed\n"); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 891 | sock_release(sock.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 892 | } |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 893 | sock.socket = s; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 894 | break; |
Andreas Gruenbacher | e5d6f33 | 2011-03-28 16:44:40 +0200 | [diff] [blame] | 895 | case P_INITIAL_META: |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 896 | if (msock.socket) { |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 897 | conn_warn(tconn, "initial packet M crossed\n"); |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 898 | sock_release(msock.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 899 | } |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 900 | msock.socket = s; |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 901 | set_bit(DISCARD_CONCURRENT, &tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 902 | break; |
| 903 | default: |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 904 | conn_warn(tconn, "Error receiving initial packet\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 905 | sock_release(s); |
| 906 | if (random32() & 1) |
| 907 | goto retry; |
| 908 | } |
| 909 | } |
| 910 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 911 | if (tconn->cstate <= C_DISCONNECTING) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 912 | goto out_release_sockets; |
| 913 | if (signal_pending(current)) { |
| 914 | flush_signals(current); |
| 915 | smp_rmb(); |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 916 | if (get_t_state(&tconn->receiver) == EXITING) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 917 | goto out_release_sockets; |
| 918 | } |
| 919 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 920 | if (sock.socket && &msock.socket) { |
| 921 | ok = drbd_socket_okay(&sock.socket); |
| 922 | ok = drbd_socket_okay(&msock.socket) && ok; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 923 | if (ok) |
| 924 | break; |
| 925 | } |
| 926 | } while (1); |
| 927 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 928 | sock.socket->sk->sk_reuse = 1; /* SO_REUSEADDR */ |
| 929 | msock.socket->sk->sk_reuse = 1; /* SO_REUSEADDR */ |
Andreas Gruenbacher | 2bf8962 | 2011-03-28 16:33:12 +0200 | [diff] [blame] | 930 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 931 | sock.socket->sk->sk_allocation = GFP_NOIO; |
| 932 | msock.socket->sk->sk_allocation = GFP_NOIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 933 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 934 | sock.socket->sk->sk_priority = TC_PRIO_INTERACTIVE_BULK; |
| 935 | msock.socket->sk->sk_priority = TC_PRIO_INTERACTIVE; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 936 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 937 | /* NOT YET ... |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 938 | * sock.socket->sk->sk_sndtimeo = tconn->net_conf->timeout*HZ/10; |
| 939 | * sock.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 940 | * first set it to the P_CONNECTION_FEATURES timeout, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 941 | * which we set to 4x the configured ping_timeout. */ |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 942 | rcu_read_lock(); |
| 943 | nc = rcu_dereference(tconn->net_conf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 944 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 945 | sock.socket->sk->sk_sndtimeo = |
| 946 | sock.socket->sk->sk_rcvtimeo = nc->ping_timeo*4*HZ/10; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 947 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 948 | msock.socket->sk->sk_rcvtimeo = nc->ping_int*HZ; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 949 | timeout = nc->timeout * HZ / 10; |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 950 | discard_my_data = nc->discard_my_data; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 951 | rcu_read_unlock(); |
| 952 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 953 | msock.socket->sk->sk_sndtimeo = timeout; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 954 | |
| 955 | /* we don't want delays. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 956 | * we use TCP_CORK where appropriate, though */ |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 957 | drbd_tcp_nodelay(sock.socket); |
| 958 | drbd_tcp_nodelay(msock.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 959 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 960 | tconn->data.socket = sock.socket; |
| 961 | tconn->meta.socket = msock.socket; |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 962 | tconn->last_received = jiffies; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 963 | |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 964 | h = drbd_do_features(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 965 | if (h <= 0) |
| 966 | return h; |
| 967 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 968 | if (tconn->cram_hmac_tfm) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 969 | /* drbd_request_state(mdev, NS(conn, WFAuth)); */ |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 970 | switch (drbd_do_auth(tconn)) { |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 971 | case -1: |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 972 | conn_err(tconn, "Authentication of peer failed\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 973 | return -1; |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 974 | case 0: |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 975 | conn_err(tconn, "Authentication of peer failed, trying again.\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 976 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 977 | } |
| 978 | } |
| 979 | |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 980 | tconn->data.socket->sk->sk_sndtimeo = timeout; |
| 981 | tconn->data.socket->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 982 | |
Andreas Gruenbacher | 387eb30 | 2011-03-16 01:05:37 +0100 | [diff] [blame] | 983 | if (drbd_send_protocol(tconn) == -EOPNOTSUPP) |
Philipp Reisner | 7e2455c | 2010-04-22 14:50:23 +0200 | [diff] [blame] | 984 | return -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 985 | |
Philipp Reisner | a1096a6 | 2012-04-06 12:07:34 +0200 | [diff] [blame] | 986 | set_bit(STATE_SENT, &tconn->flags); |
| 987 | |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 988 | rcu_read_lock(); |
| 989 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
| 990 | kref_get(&mdev->kref); |
| 991 | rcu_read_unlock(); |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 992 | |
| 993 | if (discard_my_data) |
| 994 | set_bit(DISCARD_MY_DATA, &mdev->flags); |
| 995 | else |
| 996 | clear_bit(DISCARD_MY_DATA, &mdev->flags); |
| 997 | |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 998 | drbd_connected(mdev); |
| 999 | kref_put(&mdev->kref, &drbd_minor_destroy); |
| 1000 | rcu_read_lock(); |
| 1001 | } |
| 1002 | rcu_read_unlock(); |
| 1003 | |
Philipp Reisner | a1096a6 | 2012-04-06 12:07:34 +0200 | [diff] [blame] | 1004 | rv = conn_request_state(tconn, NS(conn, C_WF_REPORT_PARAMS), CS_VERBOSE); |
| 1005 | if (rv < SS_SUCCESS) { |
| 1006 | clear_bit(STATE_SENT, &tconn->flags); |
Philipp Reisner | 823bd83 | 2012-11-08 15:04:36 +0100 | [diff] [blame] | 1007 | return 0; |
Philipp Reisner | a1096a6 | 2012-04-06 12:07:34 +0200 | [diff] [blame] | 1008 | } |
Philipp Reisner | 823bd83 | 2012-11-08 15:04:36 +0100 | [diff] [blame] | 1009 | |
| 1010 | drbd_thread_start(&tconn->asender); |
| 1011 | |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 1012 | mutex_lock(&tconn->conf_update); |
| 1013 | /* The discard_my_data flag is a single-shot modifier to the next |
| 1014 | * connection attempt, the handshake of which is now well underway. |
| 1015 | * No need for rcu style copying of the whole struct |
| 1016 | * just to clear a single value. */ |
| 1017 | tconn->net_conf->discard_my_data = 0; |
| 1018 | mutex_unlock(&tconn->conf_update); |
| 1019 | |
Philipp Reisner | d3fcb49 | 2011-04-13 14:46:05 -0700 | [diff] [blame] | 1020 | return h; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1021 | |
| 1022 | out_release_sockets: |
Philipp Reisner | 7da3586 | 2011-12-19 22:42:56 +0100 | [diff] [blame] | 1023 | if (sock.socket) |
| 1024 | sock_release(sock.socket); |
| 1025 | if (msock.socket) |
| 1026 | sock_release(msock.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1027 | return -1; |
| 1028 | } |
| 1029 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1030 | static int decode_header(struct drbd_tconn *tconn, void *header, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1031 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1032 | unsigned int header_size = drbd_header_size(tconn); |
| 1033 | |
Andreas Gruenbacher | 0c8e36d | 2011-03-30 16:00:17 +0200 | [diff] [blame] | 1034 | if (header_size == sizeof(struct p_header100) && |
| 1035 | *(__be32 *)header == cpu_to_be32(DRBD_MAGIC_100)) { |
| 1036 | struct p_header100 *h = header; |
| 1037 | if (h->pad != 0) { |
| 1038 | conn_err(tconn, "Header padding is not zero\n"); |
| 1039 | return -EINVAL; |
| 1040 | } |
| 1041 | pi->vnr = be16_to_cpu(h->volume); |
| 1042 | pi->cmd = be16_to_cpu(h->command); |
| 1043 | pi->size = be32_to_cpu(h->length); |
| 1044 | } else if (header_size == sizeof(struct p_header95) && |
| 1045 | *(__be16 *)header == cpu_to_be16(DRBD_MAGIC_BIG)) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1046 | struct p_header95 *h = header; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1047 | pi->cmd = be16_to_cpu(h->command); |
Andreas Gruenbacher | b55d84b | 2011-03-22 13:17:47 +0100 | [diff] [blame] | 1048 | pi->size = be32_to_cpu(h->length); |
| 1049 | pi->vnr = 0; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1050 | } else if (header_size == sizeof(struct p_header80) && |
| 1051 | *(__be32 *)header == cpu_to_be32(DRBD_MAGIC)) { |
| 1052 | struct p_header80 *h = header; |
| 1053 | pi->cmd = be16_to_cpu(h->command); |
| 1054 | pi->size = be16_to_cpu(h->length); |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 1055 | pi->vnr = 0; |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 1056 | } else { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1057 | conn_err(tconn, "Wrong magic value 0x%08x in protocol version %d\n", |
| 1058 | be32_to_cpu(*(__be32 *)header), |
| 1059 | tconn->agreed_pro_version); |
Andreas Gruenbacher | 8172f3e | 2011-03-16 17:22:39 +0100 | [diff] [blame] | 1060 | return -EINVAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1061 | } |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1062 | pi->data = header + header_size; |
Andreas Gruenbacher | 8172f3e | 2011-03-16 17:22:39 +0100 | [diff] [blame] | 1063 | return 0; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
Philipp Reisner | 9ba7aa0 | 2011-02-07 17:32:41 +0100 | [diff] [blame] | 1066 | static int drbd_recv_header(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 1067 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1068 | void *buffer = tconn->data.rbuf; |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 1069 | int err; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 1070 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1071 | err = drbd_recv_all_warn(tconn, buffer, drbd_header_size(tconn)); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1072 | if (err) |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 1073 | return err; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 1074 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1075 | err = decode_header(tconn, buffer, pi); |
Philipp Reisner | 9ba7aa0 | 2011-02-07 17:32:41 +0100 | [diff] [blame] | 1076 | tconn->last_received = jiffies; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1077 | |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 1078 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1081 | static void drbd_flush(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1082 | { |
| 1083 | int rv; |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1084 | struct drbd_conf *mdev; |
| 1085 | int vnr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1086 | |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1087 | if (tconn->write_ordering >= WO_bdev_flush) { |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1088 | rcu_read_lock(); |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1089 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1090 | if (!get_ldev(mdev)) |
| 1091 | continue; |
| 1092 | kref_get(&mdev->kref); |
| 1093 | rcu_read_unlock(); |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1094 | |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1095 | rv = blkdev_issue_flush(mdev->ldev->backing_bdev, |
| 1096 | GFP_NOIO, NULL); |
| 1097 | if (rv) { |
| 1098 | dev_info(DEV, "local disk flush failed with status %d\n", rv); |
| 1099 | /* would rather check on EOPNOTSUPP, but that is not reliable. |
| 1100 | * don't try again for ANY return value != 0 |
| 1101 | * if (rv == -EOPNOTSUPP) */ |
| 1102 | drbd_bump_write_ordering(tconn, WO_drain_io); |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1103 | } |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1104 | put_ldev(mdev); |
| 1105 | kref_put(&mdev->kref, &drbd_minor_destroy); |
| 1106 | |
| 1107 | rcu_read_lock(); |
| 1108 | if (rv) |
| 1109 | break; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1110 | } |
Lars Ellenberg | 615e087 | 2011-11-17 14:32:12 +0100 | [diff] [blame] | 1111 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1112 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | /** |
| 1116 | * drbd_may_finish_epoch() - Applies an epoch_event to the epoch's state, eventually finishes it. |
| 1117 | * @mdev: DRBD device. |
| 1118 | * @epoch: Epoch object. |
| 1119 | * @ev: Epoch event. |
| 1120 | */ |
Philipp Reisner | 1e9dd29 | 2011-11-10 15:14:53 +0100 | [diff] [blame] | 1121 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1122 | struct drbd_epoch *epoch, |
| 1123 | enum epoch_event ev) |
| 1124 | { |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1125 | int epoch_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1126 | struct drbd_epoch *next_epoch; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1127 | enum finish_epoch rv = FE_STILL_LIVE; |
| 1128 | |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1129 | spin_lock(&tconn->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1130 | do { |
| 1131 | next_epoch = NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1132 | |
| 1133 | epoch_size = atomic_read(&epoch->epoch_size); |
| 1134 | |
| 1135 | switch (ev & ~EV_CLEANUP) { |
| 1136 | case EV_PUT: |
| 1137 | atomic_dec(&epoch->active); |
| 1138 | break; |
| 1139 | case EV_GOT_BARRIER_NR: |
| 1140 | set_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1141 | break; |
| 1142 | case EV_BECAME_LAST: |
| 1143 | /* nothing to do*/ |
| 1144 | break; |
| 1145 | } |
| 1146 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1147 | if (epoch_size != 0 && |
| 1148 | atomic_read(&epoch->active) == 0 && |
Philipp Reisner | 85d73513 | 2011-07-18 15:45:15 +0200 | [diff] [blame] | 1149 | (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags) || ev & EV_CLEANUP)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1150 | if (!(ev & EV_CLEANUP)) { |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1151 | spin_unlock(&tconn->epoch_lock); |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1152 | drbd_send_b_ack(epoch->tconn, epoch->barrier_nr, epoch_size); |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1153 | spin_lock(&tconn->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1154 | } |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1155 | #if 0 |
| 1156 | /* FIXME: dec unacked on connection, once we have |
| 1157 | * something to count pending connection packets in. */ |
Philipp Reisner | 85d73513 | 2011-07-18 15:45:15 +0200 | [diff] [blame] | 1158 | if (test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags)) |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1159 | dec_unacked(epoch->tconn); |
| 1160 | #endif |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1161 | |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1162 | if (tconn->current_epoch != epoch) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1163 | next_epoch = list_entry(epoch->list.next, struct drbd_epoch, list); |
| 1164 | list_del(&epoch->list); |
| 1165 | ev = EV_BECAME_LAST | (ev & EV_CLEANUP); |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1166 | tconn->epochs--; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1167 | kfree(epoch); |
| 1168 | |
| 1169 | if (rv == FE_STILL_LIVE) |
| 1170 | rv = FE_DESTROYED; |
| 1171 | } else { |
| 1172 | epoch->flags = 0; |
| 1173 | atomic_set(&epoch->epoch_size, 0); |
Uwe Kleine-König | 698f931 | 2010-07-02 20:41:51 +0200 | [diff] [blame] | 1174 | /* atomic_set(&epoch->active, 0); is already zero */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1175 | if (rv == FE_STILL_LIVE) |
| 1176 | rv = FE_RECYCLED; |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | if (!next_epoch) |
| 1181 | break; |
| 1182 | |
| 1183 | epoch = next_epoch; |
| 1184 | } while (1); |
| 1185 | |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1186 | spin_unlock(&tconn->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1187 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1188 | return rv; |
| 1189 | } |
| 1190 | |
| 1191 | /** |
| 1192 | * drbd_bump_write_ordering() - Fall back to an other write ordering method |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1193 | * @tconn: DRBD connection. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1194 | * @wo: Write ordering method to try. |
| 1195 | */ |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1196 | void drbd_bump_write_ordering(struct drbd_tconn *tconn, enum write_ordering_e wo) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1197 | { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1198 | struct disk_conf *dc; |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1199 | struct drbd_conf *mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1200 | enum write_ordering_e pwo; |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1201 | int vnr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1202 | static char *write_ordering_str[] = { |
| 1203 | [WO_none] = "none", |
| 1204 | [WO_drain_io] = "drain", |
| 1205 | [WO_bdev_flush] = "flush", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1206 | }; |
| 1207 | |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1208 | pwo = tconn->write_ordering; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1209 | wo = min(pwo, wo); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1210 | rcu_read_lock(); |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1211 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
Philipp Reisner | 27eb13e | 2012-03-30 14:12:15 +0200 | [diff] [blame] | 1212 | if (!get_ldev_if_state(mdev, D_ATTACHING)) |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1213 | continue; |
| 1214 | dc = rcu_dereference(mdev->ldev->disk_conf); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1215 | |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1216 | if (wo == WO_bdev_flush && !dc->disk_flushes) |
| 1217 | wo = WO_drain_io; |
| 1218 | if (wo == WO_drain_io && !dc->disk_drain) |
| 1219 | wo = WO_none; |
| 1220 | put_ldev(mdev); |
| 1221 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 1222 | rcu_read_unlock(); |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1223 | tconn->write_ordering = wo; |
| 1224 | if (pwo != tconn->write_ordering || wo == WO_bdev_flush) |
| 1225 | conn_info(tconn, "Method to ensure write ordering: %s\n", write_ordering_str[tconn->write_ordering]); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | /** |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 1229 | * drbd_submit_peer_request() |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1230 | * @mdev: DRBD device. |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1231 | * @peer_req: peer request |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1232 | * @rw: flag field, see bio->bi_rw |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1233 | * |
| 1234 | * May spread the pages to multiple bios, |
| 1235 | * depending on bio_add_page restrictions. |
| 1236 | * |
| 1237 | * Returns 0 if all bios have been submitted, |
| 1238 | * -ENOMEM if we could not allocate enough bios, |
| 1239 | * -ENOSPC (any better suggestion?) if we have not been able to bio_add_page a |
| 1240 | * single page to an empty bio (which should never happen and likely indicates |
| 1241 | * that the lower level IO stack is in some way broken). This has been observed |
| 1242 | * on certain Xen deployments. |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1243 | */ |
| 1244 | /* TODO allocate from our own bio_set. */ |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 1245 | int drbd_submit_peer_request(struct drbd_conf *mdev, |
| 1246 | struct drbd_peer_request *peer_req, |
| 1247 | const unsigned rw, const int fault_type) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1248 | { |
| 1249 | struct bio *bios = NULL; |
| 1250 | struct bio *bio; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1251 | struct page *page = peer_req->pages; |
| 1252 | sector_t sector = peer_req->i.sector; |
| 1253 | unsigned ds = peer_req->i.size; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1254 | unsigned n_bios = 0; |
| 1255 | unsigned nr_pages = (ds + PAGE_SIZE -1) >> PAGE_SHIFT; |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1256 | int err = -ENOMEM; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1257 | |
| 1258 | /* In most cases, we will only need one bio. But in case the lower |
| 1259 | * level restrictions happen to be different at this offset on this |
| 1260 | * side than those of the sending peer, we may need to submit the |
Lars Ellenberg | da4a75d | 2011-02-23 17:02:01 +0100 | [diff] [blame] | 1261 | * request in more than one bio. |
| 1262 | * |
| 1263 | * Plain bio_alloc is good enough here, this is no DRBD internally |
| 1264 | * generated bio, but a bio allocated on behalf of the peer. |
| 1265 | */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1266 | next_bio: |
| 1267 | bio = bio_alloc(GFP_NOIO, nr_pages); |
| 1268 | if (!bio) { |
| 1269 | dev_err(DEV, "submit_ee: Allocation of a bio failed\n"); |
| 1270 | goto fail; |
| 1271 | } |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1272 | /* > peer_req->i.sector, unless this is the first bio */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1273 | bio->bi_sector = sector; |
| 1274 | bio->bi_bdev = mdev->ldev->backing_bdev; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1275 | bio->bi_rw = rw; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1276 | bio->bi_private = peer_req; |
Andreas Gruenbacher | fcefa62 | 2011-02-17 16:46:59 +0100 | [diff] [blame] | 1277 | bio->bi_end_io = drbd_peer_request_endio; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1278 | |
| 1279 | bio->bi_next = bios; |
| 1280 | bios = bio; |
| 1281 | ++n_bios; |
| 1282 | |
| 1283 | page_chain_for_each(page) { |
| 1284 | unsigned len = min_t(unsigned, ds, PAGE_SIZE); |
| 1285 | if (!bio_add_page(bio, page, len, 0)) { |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1286 | /* A single page must always be possible! |
| 1287 | * But in case it fails anyways, |
| 1288 | * we deal with it, and complain (below). */ |
| 1289 | if (bio->bi_vcnt == 0) { |
| 1290 | dev_err(DEV, |
| 1291 | "bio_add_page failed for len=%u, " |
| 1292 | "bi_vcnt=0 (bi_sector=%llu)\n", |
| 1293 | len, (unsigned long long)bio->bi_sector); |
| 1294 | err = -ENOSPC; |
| 1295 | goto fail; |
| 1296 | } |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1297 | goto next_bio; |
| 1298 | } |
| 1299 | ds -= len; |
| 1300 | sector += len >> 9; |
| 1301 | --nr_pages; |
| 1302 | } |
| 1303 | D_ASSERT(page == NULL); |
| 1304 | D_ASSERT(ds == 0); |
| 1305 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1306 | atomic_set(&peer_req->pending_bios, n_bios); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1307 | do { |
| 1308 | bio = bios; |
| 1309 | bios = bios->bi_next; |
| 1310 | bio->bi_next = NULL; |
| 1311 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1312 | drbd_generic_make_request(mdev, fault_type, bio); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1313 | } while (bios); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1314 | return 0; |
| 1315 | |
| 1316 | fail: |
| 1317 | while (bios) { |
| 1318 | bio = bios; |
| 1319 | bios = bios->bi_next; |
| 1320 | bio_put(bio); |
| 1321 | } |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1322 | return err; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1323 | } |
| 1324 | |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1325 | static void drbd_remove_epoch_entry_interval(struct drbd_conf *mdev, |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1326 | struct drbd_peer_request *peer_req) |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1327 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1328 | struct drbd_interval *i = &peer_req->i; |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1329 | |
| 1330 | drbd_remove_interval(&mdev->write_requests, i); |
| 1331 | drbd_clear_interval(i); |
| 1332 | |
Andreas Gruenbacher | 6c852be | 2011-02-04 15:38:52 +0100 | [diff] [blame] | 1333 | /* Wake up any processes waiting for this peer request to complete. */ |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1334 | if (i->waiting) |
| 1335 | wake_up(&mdev->misc_wait); |
| 1336 | } |
| 1337 | |
Philipp Reisner | 77fede5 | 2011-11-10 21:19:11 +0100 | [diff] [blame] | 1338 | void conn_wait_active_ee_empty(struct drbd_tconn *tconn) |
| 1339 | { |
| 1340 | struct drbd_conf *mdev; |
| 1341 | int vnr; |
| 1342 | |
| 1343 | rcu_read_lock(); |
| 1344 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
| 1345 | kref_get(&mdev->kref); |
| 1346 | rcu_read_unlock(); |
| 1347 | drbd_wait_ee_list_empty(mdev, &mdev->active_ee); |
| 1348 | kref_put(&mdev->kref, &drbd_minor_destroy); |
| 1349 | rcu_read_lock(); |
| 1350 | } |
| 1351 | rcu_read_unlock(); |
| 1352 | } |
| 1353 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1354 | static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1355 | { |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1356 | int rv; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1357 | struct p_barrier *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1358 | struct drbd_epoch *epoch; |
| 1359 | |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1360 | /* FIXME these are unacked on connection, |
| 1361 | * not a specific (peer)device. |
| 1362 | */ |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1363 | tconn->current_epoch->barrier_nr = p->barrier; |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1364 | tconn->current_epoch->tconn = tconn; |
Philipp Reisner | 1e9dd29 | 2011-11-10 15:14:53 +0100 | [diff] [blame] | 1365 | rv = drbd_may_finish_epoch(tconn, tconn->current_epoch, EV_GOT_BARRIER_NR); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1366 | |
| 1367 | /* P_BARRIER_ACK may imply that the corresponding extent is dropped from |
| 1368 | * the activity log, which means it would not be resynced in case the |
| 1369 | * R_PRIMARY crashes now. |
| 1370 | * Therefore we must send the barrier_ack after the barrier request was |
| 1371 | * completed. */ |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1372 | switch (tconn->write_ordering) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1373 | case WO_none: |
| 1374 | if (rv == FE_RECYCLED) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1375 | return 0; |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1376 | |
| 1377 | /* receiver context, in the writeout path of the other node. |
| 1378 | * avoid potential distributed deadlock */ |
| 1379 | epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO); |
| 1380 | if (epoch) |
| 1381 | break; |
| 1382 | else |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1383 | conn_warn(tconn, "Allocation of an epoch failed, slowing down\n"); |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1384 | /* Fall through */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1385 | |
| 1386 | case WO_bdev_flush: |
| 1387 | case WO_drain_io: |
Philipp Reisner | 77fede5 | 2011-11-10 21:19:11 +0100 | [diff] [blame] | 1388 | conn_wait_active_ee_empty(tconn); |
Philipp Reisner | 4b0007c | 2011-11-09 20:12:34 +0100 | [diff] [blame] | 1389 | drbd_flush(tconn); |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1390 | |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1391 | if (atomic_read(&tconn->current_epoch->epoch_size)) { |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1392 | epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO); |
| 1393 | if (epoch) |
| 1394 | break; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1397 | return 0; |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1398 | default: |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 1399 | conn_err(tconn, "Strangeness in tconn->write_ordering %d\n", tconn->write_ordering); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1400 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | epoch->flags = 0; |
| 1404 | atomic_set(&epoch->epoch_size, 0); |
| 1405 | atomic_set(&epoch->active, 0); |
| 1406 | |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1407 | spin_lock(&tconn->epoch_lock); |
| 1408 | if (atomic_read(&tconn->current_epoch->epoch_size)) { |
| 1409 | list_add(&epoch->list, &tconn->current_epoch->list); |
| 1410 | tconn->current_epoch = epoch; |
| 1411 | tconn->epochs++; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1412 | } else { |
| 1413 | /* The current_epoch got recycled while we allocated this one... */ |
| 1414 | kfree(epoch); |
| 1415 | } |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 1416 | spin_unlock(&tconn->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1417 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1418 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | /* used from receive_RSDataReply (recv_resync_read) |
| 1422 | * and from receive_Data */ |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1423 | static struct drbd_peer_request * |
| 1424 | read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, |
| 1425 | int data_size) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1426 | { |
Lars Ellenberg | 6666032 | 2010-04-06 12:15:04 +0200 | [diff] [blame] | 1427 | const sector_t capacity = drbd_get_capacity(mdev->this_bdev); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1428 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1429 | struct page *page; |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1430 | int dgs, ds, err; |
Philipp Reisner | a063845 | 2011-01-19 14:31:32 +0100 | [diff] [blame] | 1431 | void *dig_in = mdev->tconn->int_dig_in; |
| 1432 | void *dig_vv = mdev->tconn->int_dig_vv; |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 1433 | unsigned long *data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1434 | |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 1435 | dgs = 0; |
| 1436 | if (mdev->tconn->peer_integrity_tfm) { |
| 1437 | dgs = crypto_hash_digestsize(mdev->tconn->peer_integrity_tfm); |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 1438 | /* |
| 1439 | * FIXME: Receive the incoming digest into the receive buffer |
| 1440 | * here, together with its struct p_data? |
| 1441 | */ |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1442 | err = drbd_recv_all_warn(mdev->tconn, dig_in, dgs); |
| 1443 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1444 | return NULL; |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 1445 | data_size -= dgs; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 1448 | if (!expect(data_size != 0)) |
| 1449 | return NULL; |
| 1450 | if (!expect(IS_ALIGNED(data_size, 512))) |
| 1451 | return NULL; |
| 1452 | if (!expect(data_size <= DRBD_MAX_BIO_SIZE)) |
| 1453 | return NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1454 | |
Lars Ellenberg | 6666032 | 2010-04-06 12:15:04 +0200 | [diff] [blame] | 1455 | /* even though we trust out peer, |
| 1456 | * we sometimes have to double check. */ |
| 1457 | if (sector + (data_size>>9) > capacity) { |
Lars Ellenberg | fdda654 | 2011-01-24 15:11:01 +0100 | [diff] [blame] | 1458 | dev_err(DEV, "request from peer beyond end of local disk: " |
| 1459 | "capacity: %llus < sector: %llus + size: %u\n", |
Lars Ellenberg | 6666032 | 2010-04-06 12:15:04 +0200 | [diff] [blame] | 1460 | (unsigned long long)capacity, |
| 1461 | (unsigned long long)sector, data_size); |
| 1462 | return NULL; |
| 1463 | } |
| 1464 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1465 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD |
| 1466 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
| 1467 | * which in turn might block on the other node at this very place. */ |
Andreas Gruenbacher | 0db5536 | 2011-04-06 16:09:15 +0200 | [diff] [blame] | 1468 | peer_req = drbd_alloc_peer_req(mdev, id, sector, data_size, GFP_NOIO); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1469 | if (!peer_req) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1470 | return NULL; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1471 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1472 | ds = data_size; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1473 | page = peer_req->pages; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1474 | page_chain_for_each(page) { |
| 1475 | unsigned len = min_t(int, ds, PAGE_SIZE); |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 1476 | data = kmap(page); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1477 | err = drbd_recv_all_warn(mdev->tconn, data, len); |
Andreas Gruenbacher | 0cf9d27 | 2010-12-07 10:43:29 +0100 | [diff] [blame] | 1478 | if (drbd_insert_fault(mdev, DRBD_FAULT_RECEIVE)) { |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 1479 | dev_err(DEV, "Fault injection: Corrupting data on receive\n"); |
| 1480 | data[0] = data[0] ^ (unsigned long)-1; |
| 1481 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1482 | kunmap(page); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1483 | if (err) { |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 1484 | drbd_free_peer_req(mdev, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1485 | return NULL; |
| 1486 | } |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1487 | ds -= len; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | if (dgs) { |
Andreas Gruenbacher | 5b614ab | 2011-04-27 21:00:12 +0200 | [diff] [blame] | 1491 | drbd_csum_ee(mdev, mdev->tconn->peer_integrity_tfm, peer_req, dig_vv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1492 | if (memcmp(dig_in, dig_vv, dgs)) { |
Lars Ellenberg | 470be44 | 2010-11-10 10:36:52 +0100 | [diff] [blame] | 1493 | dev_err(DEV, "Digest integrity check FAILED: %llus +%u\n", |
| 1494 | (unsigned long long)sector, data_size); |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 1495 | drbd_free_peer_req(mdev, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1496 | return NULL; |
| 1497 | } |
| 1498 | } |
| 1499 | mdev->recv_cnt += data_size>>9; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1500 | return peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /* drbd_drain_block() just takes a data block |
| 1504 | * out of the socket input buffer, and discards it. |
| 1505 | */ |
| 1506 | static int drbd_drain_block(struct drbd_conf *mdev, int data_size) |
| 1507 | { |
| 1508 | struct page *page; |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1509 | int err = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1510 | void *data; |
| 1511 | |
Lars Ellenberg | c3470cd | 2010-04-01 16:57:19 +0200 | [diff] [blame] | 1512 | if (!data_size) |
Andreas Gruenbacher | fc5be83 | 2011-03-16 17:50:50 +0100 | [diff] [blame] | 1513 | return 0; |
Lars Ellenberg | c3470cd | 2010-04-01 16:57:19 +0200 | [diff] [blame] | 1514 | |
Andreas Gruenbacher | c37c8ec | 2011-04-07 21:02:09 +0200 | [diff] [blame] | 1515 | page = drbd_alloc_pages(mdev, 1, 1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1516 | |
| 1517 | data = kmap(page); |
| 1518 | while (data_size) { |
Andreas Gruenbacher | fc5be83 | 2011-03-16 17:50:50 +0100 | [diff] [blame] | 1519 | unsigned int len = min_t(int, data_size, PAGE_SIZE); |
| 1520 | |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1521 | err = drbd_recv_all_warn(mdev->tconn, data, len); |
| 1522 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1523 | break; |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1524 | data_size -= len; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1525 | } |
| 1526 | kunmap(page); |
Andreas Gruenbacher | 5cc287e | 2011-04-07 21:02:59 +0200 | [diff] [blame] | 1527 | drbd_free_pages(mdev, page, 0); |
Andreas Gruenbacher | fc5be83 | 2011-03-16 17:50:50 +0100 | [diff] [blame] | 1528 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req, |
| 1532 | sector_t sector, int data_size) |
| 1533 | { |
| 1534 | struct bio_vec *bvec; |
| 1535 | struct bio *bio; |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1536 | int dgs, err, i, expect; |
Philipp Reisner | a063845 | 2011-01-19 14:31:32 +0100 | [diff] [blame] | 1537 | void *dig_in = mdev->tconn->int_dig_in; |
| 1538 | void *dig_vv = mdev->tconn->int_dig_vv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1539 | |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 1540 | dgs = 0; |
| 1541 | if (mdev->tconn->peer_integrity_tfm) { |
| 1542 | dgs = crypto_hash_digestsize(mdev->tconn->peer_integrity_tfm); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1543 | err = drbd_recv_all_warn(mdev->tconn, dig_in, dgs); |
| 1544 | if (err) |
| 1545 | return err; |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 1546 | data_size -= dgs; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1547 | } |
| 1548 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1549 | /* optimistically update recv_cnt. if receiving fails below, |
| 1550 | * we disconnect anyways, and counters will be reset. */ |
| 1551 | mdev->recv_cnt += data_size>>9; |
| 1552 | |
| 1553 | bio = req->master_bio; |
| 1554 | D_ASSERT(sector == bio->bi_sector); |
| 1555 | |
| 1556 | bio_for_each_segment(bvec, bio, i) { |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1557 | void *mapped = kmap(bvec->bv_page) + bvec->bv_offset; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1558 | expect = min_t(int, data_size, bvec->bv_len); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1559 | err = drbd_recv_all_warn(mdev->tconn, mapped, expect); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1560 | kunmap(bvec->bv_page); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 1561 | if (err) |
| 1562 | return err; |
| 1563 | data_size -= expect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | if (dgs) { |
Andreas Gruenbacher | 5b614ab | 2011-04-27 21:00:12 +0200 | [diff] [blame] | 1567 | drbd_csum_bio(mdev, mdev->tconn->peer_integrity_tfm, bio, dig_vv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1568 | if (memcmp(dig_in, dig_vv, dgs)) { |
| 1569 | dev_err(DEV, "Digest integrity check FAILED. Broken NICs?\n"); |
Andreas Gruenbacher | 28284ce | 2011-03-16 17:54:02 +0100 | [diff] [blame] | 1570 | return -EINVAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | D_ASSERT(data_size == 0); |
Andreas Gruenbacher | 28284ce | 2011-03-16 17:54:02 +0100 | [diff] [blame] | 1575 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 1578 | /* |
| 1579 | * e_end_resync_block() is called in asender context via |
| 1580 | * drbd_finish_peer_reqs(). |
| 1581 | */ |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1582 | static int e_end_resync_block(struct drbd_work *w, int unused) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1583 | { |
Andreas Gruenbacher | 8050e6d | 2011-02-18 16:12:48 +0100 | [diff] [blame] | 1584 | struct drbd_peer_request *peer_req = |
| 1585 | container_of(w, struct drbd_peer_request, w); |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 1586 | struct drbd_conf *mdev = w->mdev; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1587 | sector_t sector = peer_req->i.sector; |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1588 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1589 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1590 | D_ASSERT(drbd_interval_empty(&peer_req->i)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1591 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1592 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
| 1593 | drbd_set_in_sync(mdev, sector, peer_req->i.size); |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1594 | err = drbd_send_ack(mdev, P_RS_WRITE_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1595 | } else { |
| 1596 | /* Record failure to sync */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1597 | drbd_rs_failed_io(mdev, sector, peer_req->i.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1598 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1599 | err = drbd_send_ack(mdev, P_NEG_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1600 | } |
| 1601 | dec_unacked(mdev); |
| 1602 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1603 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | static int recv_resync_read(struct drbd_conf *mdev, sector_t sector, int data_size) __releases(local) |
| 1607 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1608 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1609 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1610 | peer_req = read_in_block(mdev, ID_SYNCER, sector, data_size); |
| 1611 | if (!peer_req) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1612 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1613 | |
| 1614 | dec_rs_pending(mdev); |
| 1615 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1616 | inc_unacked(mdev); |
| 1617 | /* corresponding dec_unacked() in e_end_resync_block() |
| 1618 | * respective _drbd_clear_done_ee */ |
| 1619 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1620 | peer_req->w.cb = e_end_resync_block; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1621 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1622 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1623 | list_add(&peer_req->w.list, &mdev->sync_ee); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1624 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1625 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 1626 | atomic_add(data_size >> 9, &mdev->rs_sect_ev); |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 1627 | if (drbd_submit_peer_request(mdev, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0) |
Andreas Gruenbacher | e1c1b0f | 2011-03-16 17:58:27 +0100 | [diff] [blame] | 1628 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1629 | |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1630 | /* don't care for the reason here */ |
| 1631 | dev_err(DEV, "submit failed, triggering re-connect\n"); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1632 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1633 | list_del(&peer_req->w.list); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1634 | spin_unlock_irq(&mdev->tconn->req_lock); |
Lars Ellenberg | 22cc37a | 2010-09-14 20:40:41 +0200 | [diff] [blame] | 1635 | |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 1636 | drbd_free_peer_req(mdev, peer_req); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1637 | fail: |
| 1638 | put_ldev(mdev); |
Andreas Gruenbacher | e1c1b0f | 2011-03-16 17:58:27 +0100 | [diff] [blame] | 1639 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1642 | static struct drbd_request * |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 1643 | find_request(struct drbd_conf *mdev, struct rb_root *root, u64 id, |
| 1644 | sector_t sector, bool missing_ok, const char *func) |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1645 | { |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1646 | struct drbd_request *req; |
| 1647 | |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 1648 | /* Request object according to our peer */ |
| 1649 | req = (struct drbd_request *)(unsigned long)id; |
Andreas Gruenbacher | 5e47226 | 2011-01-27 14:42:51 +0100 | [diff] [blame] | 1650 | if (drbd_contains_interval(root, sector, &req->i) && req->i.local) |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1651 | return req; |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 1652 | if (!missing_ok) { |
Andreas Gruenbacher | 5af172e | 2011-07-15 09:43:23 +0200 | [diff] [blame] | 1653 | dev_err(DEV, "%s: failed to find request 0x%lx, sector %llus\n", func, |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 1654 | (unsigned long)id, (unsigned long long)sector); |
| 1655 | } |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1656 | return NULL; |
| 1657 | } |
| 1658 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1659 | static int receive_DataReply(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1660 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1661 | struct drbd_conf *mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1662 | struct drbd_request *req; |
| 1663 | sector_t sector; |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1664 | int err; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1665 | struct p_data *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1666 | |
| 1667 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 1668 | if (!mdev) |
| 1669 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1670 | |
| 1671 | sector = be64_to_cpu(p->sector); |
| 1672 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1673 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 1674 | req = find_request(mdev, &mdev->read_requests, p->block_id, sector, false, __func__); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1675 | spin_unlock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 1676 | if (unlikely(!req)) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1677 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1678 | |
Bart Van Assche | 24c4830 | 2011-05-21 18:32:29 +0200 | [diff] [blame] | 1679 | /* 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] | 1680 | * special casing it there for the various failure cases. |
| 1681 | * still no race with drbd_fail_pending_reads */ |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 1682 | err = recv_dless_read(mdev, req, sector, pi->size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1683 | if (!err) |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 1684 | req_mod(req, DATA_RECEIVED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1685 | /* else: nothing. handled from drbd_disconnect... |
| 1686 | * I don't think we may complete this just yet |
| 1687 | * in case we are "on-disconnect: freeze" */ |
| 1688 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1689 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1692 | static int receive_RSDataReply(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1693 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1694 | struct drbd_conf *mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1695 | sector_t sector; |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1696 | int err; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 1697 | struct p_data *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 1698 | |
| 1699 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 1700 | if (!mdev) |
| 1701 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1702 | |
| 1703 | sector = be64_to_cpu(p->sector); |
| 1704 | D_ASSERT(p->block_id == ID_SYNCER); |
| 1705 | |
| 1706 | if (get_ldev(mdev)) { |
| 1707 | /* data is submitted to disk within recv_resync_read. |
| 1708 | * corresponding put_ldev done below on error, |
Andreas Gruenbacher | fcefa62 | 2011-02-17 16:46:59 +0100 | [diff] [blame] | 1709 | * or in drbd_peer_request_endio. */ |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 1710 | err = recv_resync_read(mdev, sector, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1711 | } else { |
| 1712 | if (__ratelimit(&drbd_ratelimit_state)) |
| 1713 | dev_err(DEV, "Can not write resync data to local disk.\n"); |
| 1714 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 1715 | err = drbd_drain_block(mdev, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1716 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 1717 | drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 1720 | atomic_add(pi->size >> 9, &mdev->rs_sect_in); |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 1721 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 1722 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1725 | static void restart_conflicting_writes(struct drbd_conf *mdev, |
| 1726 | sector_t sector, int size) |
| 1727 | { |
| 1728 | struct drbd_interval *i; |
| 1729 | struct drbd_request *req; |
| 1730 | |
| 1731 | drbd_for_each_overlap(i, &mdev->write_requests, sector, size) { |
| 1732 | if (!i->local) |
| 1733 | continue; |
| 1734 | req = container_of(i, struct drbd_request, i); |
| 1735 | if (req->rq_state & RQ_LOCAL_PENDING || |
| 1736 | !(req->rq_state & RQ_POSTPONED)) |
| 1737 | continue; |
Lars Ellenberg | 2312f0b3 | 2011-11-24 10:36:25 +0100 | [diff] [blame] | 1738 | /* as it is RQ_POSTPONED, this will cause it to |
| 1739 | * be queued on the retry workqueue. */ |
| 1740 | __req_mod(req, DISCARD_WRITE, NULL); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1741 | } |
| 1742 | } |
| 1743 | |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 1744 | /* |
| 1745 | * 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] | 1746 | */ |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1747 | static int e_end_block(struct drbd_work *w, int cancel) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1748 | { |
Andreas Gruenbacher | 8050e6d | 2011-02-18 16:12:48 +0100 | [diff] [blame] | 1749 | struct drbd_peer_request *peer_req = |
| 1750 | container_of(w, struct drbd_peer_request, w); |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 1751 | struct drbd_conf *mdev = w->mdev; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1752 | sector_t sector = peer_req->i.sector; |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1753 | int err = 0, pcmd; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1754 | |
Philipp Reisner | 303d144 | 2011-04-13 16:24:47 -0700 | [diff] [blame] | 1755 | if (peer_req->flags & EE_SEND_WRITE_ACK) { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1756 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1757 | pcmd = (mdev->state.conn >= C_SYNC_SOURCE && |
| 1758 | mdev->state.conn <= C_PAUSED_SYNC_T && |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1759 | peer_req->flags & EE_MAY_SET_IN_SYNC) ? |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1760 | P_RS_WRITE_ACK : P_WRITE_ACK; |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1761 | err = drbd_send_ack(mdev, pcmd, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1762 | if (pcmd == P_RS_WRITE_ACK) |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1763 | drbd_set_in_sync(mdev, sector, peer_req->i.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1764 | } else { |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1765 | err = drbd_send_ack(mdev, P_NEG_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1766 | /* we expect it to be marked out of sync anyways... |
| 1767 | * maybe assert this? */ |
| 1768 | } |
| 1769 | dec_unacked(mdev); |
| 1770 | } |
| 1771 | /* we delete from the conflict detection hash _after_ we sent out the |
| 1772 | * P_WRITE_ACK / P_NEG_ACK, to get the sequence number right. */ |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 1773 | if (peer_req->flags & EE_IN_INTERVAL_TREE) { |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1774 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1775 | D_ASSERT(!drbd_interval_empty(&peer_req->i)); |
| 1776 | drbd_remove_epoch_entry_interval(mdev, peer_req); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1777 | if (peer_req->flags & EE_RESTART_REQUESTS) |
| 1778 | restart_conflicting_writes(mdev, sector, peer_req->i.size); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1779 | spin_unlock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | bb3bfe9 | 2011-01-21 15:59:23 +0100 | [diff] [blame] | 1780 | } else |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1781 | D_ASSERT(drbd_interval_empty(&peer_req->i)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1782 | |
Philipp Reisner | 1e9dd29 | 2011-11-10 15:14:53 +0100 | [diff] [blame] | 1783 | drbd_may_finish_epoch(mdev->tconn, peer_req->epoch, EV_PUT + (cancel ? EV_CLEANUP : 0)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1784 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1785 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1788 | 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] | 1789 | { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1790 | struct drbd_conf *mdev = w->mdev; |
Andreas Gruenbacher | 8050e6d | 2011-02-18 16:12:48 +0100 | [diff] [blame] | 1791 | struct drbd_peer_request *peer_req = |
| 1792 | container_of(w, struct drbd_peer_request, w); |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1793 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1794 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1795 | err = drbd_send_ack(mdev, ack, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1796 | dec_unacked(mdev); |
| 1797 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1798 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1801 | static int e_send_discard_write(struct drbd_work *w, int unused) |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1802 | { |
| 1803 | return e_send_ack(w, P_DISCARD_WRITE); |
| 1804 | } |
| 1805 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1806 | static int e_send_retry_write(struct drbd_work *w, int unused) |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1807 | { |
| 1808 | struct drbd_tconn *tconn = w->mdev->tconn; |
| 1809 | |
| 1810 | return e_send_ack(w, tconn->agreed_pro_version >= 100 ? |
| 1811 | P_RETRY_WRITE : P_DISCARD_WRITE); |
| 1812 | } |
| 1813 | |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 1814 | static bool seq_greater(u32 a, u32 b) |
| 1815 | { |
| 1816 | /* |
| 1817 | * We assume 32-bit wrap-around here. |
| 1818 | * For 24-bit wrap-around, we would have to shift: |
| 1819 | * a <<= 8; b <<= 8; |
| 1820 | */ |
| 1821 | return (s32)a - (s32)b > 0; |
| 1822 | } |
| 1823 | |
| 1824 | static u32 seq_max(u32 a, u32 b) |
| 1825 | { |
| 1826 | return seq_greater(a, b) ? a : b; |
| 1827 | } |
| 1828 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1829 | static bool need_peer_seq(struct drbd_conf *mdev) |
| 1830 | { |
| 1831 | struct drbd_tconn *tconn = mdev->tconn; |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 1832 | int tp; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1833 | |
| 1834 | /* |
| 1835 | * We only need to keep track of the last packet_seq number of our peer |
| 1836 | * if we are in dual-primary mode and we have the discard flag set; see |
| 1837 | * handle_write_conflicts(). |
| 1838 | */ |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 1839 | |
| 1840 | rcu_read_lock(); |
| 1841 | tp = rcu_dereference(mdev->tconn->net_conf)->two_primaries; |
| 1842 | rcu_read_unlock(); |
| 1843 | |
| 1844 | return tp && test_bit(DISCARD_CONCURRENT, &tconn->flags); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1845 | } |
| 1846 | |
Andreas Gruenbacher | 43ae077 | 2011-02-03 18:42:08 +0100 | [diff] [blame] | 1847 | static void update_peer_seq(struct drbd_conf *mdev, unsigned int peer_seq) |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 1848 | { |
Lars Ellenberg | 3c13b68 | 2011-02-23 16:10:01 +0100 | [diff] [blame] | 1849 | unsigned int newest_peer_seq; |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 1850 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1851 | if (need_peer_seq(mdev)) { |
| 1852 | spin_lock(&mdev->peer_seq_lock); |
Lars Ellenberg | 3c13b68 | 2011-02-23 16:10:01 +0100 | [diff] [blame] | 1853 | newest_peer_seq = seq_max(mdev->peer_seq, peer_seq); |
| 1854 | mdev->peer_seq = newest_peer_seq; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1855 | spin_unlock(&mdev->peer_seq_lock); |
Lars Ellenberg | 3c13b68 | 2011-02-23 16:10:01 +0100 | [diff] [blame] | 1856 | /* wake up only if we actually changed mdev->peer_seq */ |
| 1857 | if (peer_seq == newest_peer_seq) |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1858 | wake_up(&mdev->seq_wait); |
| 1859 | } |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 1860 | } |
| 1861 | |
Lars Ellenberg | d93f630 | 2012-03-26 15:49:13 +0200 | [diff] [blame] | 1862 | static inline int overlaps(sector_t s1, int l1, sector_t s2, int l2) |
| 1863 | { |
| 1864 | return !((s1 + (l1>>9) <= s2) || (s1 >= s2 + (l2>>9))); |
| 1865 | } |
| 1866 | |
| 1867 | /* maybe change sync_ee into interval trees as well? */ |
Philipp Reisner | 3ea35df | 2012-04-06 12:13:18 +0200 | [diff] [blame] | 1868 | static bool overlapping_resync_write(struct drbd_conf *mdev, struct drbd_peer_request *peer_req) |
Lars Ellenberg | d93f630 | 2012-03-26 15:49:13 +0200 | [diff] [blame] | 1869 | { |
| 1870 | struct drbd_peer_request *rs_req; |
| 1871 | bool rv = 0; |
| 1872 | |
| 1873 | spin_lock_irq(&mdev->tconn->req_lock); |
| 1874 | list_for_each_entry(rs_req, &mdev->sync_ee, w.list) { |
| 1875 | if (overlaps(peer_req->i.sector, peer_req->i.size, |
| 1876 | rs_req->i.sector, rs_req->i.size)) { |
| 1877 | rv = 1; |
| 1878 | break; |
| 1879 | } |
| 1880 | } |
| 1881 | spin_unlock_irq(&mdev->tconn->req_lock); |
| 1882 | |
Lars Ellenberg | d93f630 | 2012-03-26 15:49:13 +0200 | [diff] [blame] | 1883 | return rv; |
| 1884 | } |
| 1885 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1886 | /* Called from receive_Data. |
| 1887 | * Synchronize packets on sock with packets on msock. |
| 1888 | * |
| 1889 | * This is here so even when a P_DATA packet traveling via sock overtook an Ack |
| 1890 | * packet traveling on msock, they are still processed in the order they have |
| 1891 | * been sent. |
| 1892 | * |
| 1893 | * Note: we don't care for Ack packets overtaking P_DATA packets. |
| 1894 | * |
| 1895 | * In case packet_seq is larger than mdev->peer_seq number, there are |
| 1896 | * outstanding packets on the msock. We wait for them to arrive. |
| 1897 | * In case we are the logically next packet, we update mdev->peer_seq |
| 1898 | * ourselves. Correctly handles 32bit wrap around. |
| 1899 | * |
| 1900 | * Assume we have a 10 GBit connection, that is about 1<<30 byte per second, |
| 1901 | * about 1<<21 sectors per second. So "worst" case, we have 1<<3 == 8 seconds |
| 1902 | * for the 24bit wrap (historical atomic_t guarantee on some archs), and we have |
| 1903 | * 1<<9 == 512 seconds aka ages for the 32bit wrap around... |
| 1904 | * |
| 1905 | * returns 0 if we may process the packet, |
| 1906 | * -ERESTARTSYS if we were interrupted (by disconnect signal). */ |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1907 | static int wait_for_and_update_peer_seq(struct drbd_conf *mdev, const u32 peer_seq) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1908 | { |
| 1909 | DEFINE_WAIT(wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1910 | long timeout; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1911 | int ret; |
| 1912 | |
| 1913 | if (!need_peer_seq(mdev)) |
| 1914 | return 0; |
| 1915 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1916 | spin_lock(&mdev->peer_seq_lock); |
| 1917 | for (;;) { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1918 | if (!seq_greater(peer_seq - 1, mdev->peer_seq)) { |
| 1919 | mdev->peer_seq = seq_max(mdev->peer_seq, peer_seq); |
| 1920 | ret = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1921 | break; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1922 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1923 | if (signal_pending(current)) { |
| 1924 | ret = -ERESTARTSYS; |
| 1925 | break; |
| 1926 | } |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1927 | prepare_to_wait(&mdev->seq_wait, &wait, TASK_INTERRUPTIBLE); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1928 | spin_unlock(&mdev->peer_seq_lock); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 1929 | rcu_read_lock(); |
| 1930 | timeout = rcu_dereference(mdev->tconn->net_conf)->ping_timeo*HZ/10; |
| 1931 | rcu_read_unlock(); |
Andreas Gruenbacher | 71b1c1e | 2011-03-01 15:40:43 +0100 | [diff] [blame] | 1932 | timeout = schedule_timeout(timeout); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1933 | spin_lock(&mdev->peer_seq_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1934 | if (!timeout) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1935 | ret = -ETIMEDOUT; |
Andreas Gruenbacher | 71b1c1e | 2011-03-01 15:40:43 +0100 | [diff] [blame] | 1936 | dev_err(DEV, "Timed out waiting for missing ack packets; disconnecting\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1937 | break; |
| 1938 | } |
| 1939 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1940 | spin_unlock(&mdev->peer_seq_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1941 | finish_wait(&mdev->seq_wait, &wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1942 | return ret; |
| 1943 | } |
| 1944 | |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 1945 | /* see also bio_flags_to_wire() |
| 1946 | * DRBD_REQ_*, because we need to semantically map the flags to data packet |
| 1947 | * flags and back. We may replicate to other kernel versions. */ |
| 1948 | static unsigned long wire_flags_to_bio(struct drbd_conf *mdev, u32 dpf) |
Philipp Reisner | 76d2e7e | 2010-08-25 11:58:05 +0200 | [diff] [blame] | 1949 | { |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 1950 | return (dpf & DP_RW_SYNC ? REQ_SYNC : 0) | |
| 1951 | (dpf & DP_FUA ? REQ_FUA : 0) | |
| 1952 | (dpf & DP_FLUSH ? REQ_FLUSH : 0) | |
| 1953 | (dpf & DP_DISCARD ? REQ_DISCARD : 0); |
Philipp Reisner | 76d2e7e | 2010-08-25 11:58:05 +0200 | [diff] [blame] | 1954 | } |
| 1955 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1956 | static void fail_postponed_requests(struct drbd_conf *mdev, sector_t sector, |
| 1957 | unsigned int size) |
| 1958 | { |
| 1959 | struct drbd_interval *i; |
| 1960 | |
| 1961 | repeat: |
| 1962 | drbd_for_each_overlap(i, &mdev->write_requests, sector, size) { |
| 1963 | struct drbd_request *req; |
| 1964 | struct bio_and_error m; |
| 1965 | |
| 1966 | if (!i->local) |
| 1967 | continue; |
| 1968 | req = container_of(i, struct drbd_request, i); |
| 1969 | if (!(req->rq_state & RQ_POSTPONED)) |
| 1970 | continue; |
| 1971 | req->rq_state &= ~RQ_POSTPONED; |
| 1972 | __req_mod(req, NEG_ACKED, &m); |
| 1973 | spin_unlock_irq(&mdev->tconn->req_lock); |
| 1974 | if (m.bio) |
| 1975 | complete_master_bio(mdev, &m); |
| 1976 | spin_lock_irq(&mdev->tconn->req_lock); |
| 1977 | goto repeat; |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | static int handle_write_conflicts(struct drbd_conf *mdev, |
| 1982 | struct drbd_peer_request *peer_req) |
| 1983 | { |
| 1984 | struct drbd_tconn *tconn = mdev->tconn; |
| 1985 | bool resolve_conflicts = test_bit(DISCARD_CONCURRENT, &tconn->flags); |
| 1986 | sector_t sector = peer_req->i.sector; |
| 1987 | const unsigned int size = peer_req->i.size; |
| 1988 | struct drbd_interval *i; |
| 1989 | bool equal; |
| 1990 | int err; |
| 1991 | |
| 1992 | /* |
| 1993 | * Inserting the peer request into the write_requests tree will prevent |
| 1994 | * new conflicting local requests from being added. |
| 1995 | */ |
| 1996 | drbd_insert_interval(&mdev->write_requests, &peer_req->i); |
| 1997 | |
| 1998 | repeat: |
| 1999 | drbd_for_each_overlap(i, &mdev->write_requests, sector, size) { |
| 2000 | if (i == &peer_req->i) |
| 2001 | continue; |
| 2002 | |
| 2003 | if (!i->local) { |
| 2004 | /* |
| 2005 | * Our peer has sent a conflicting remote request; this |
| 2006 | * should not happen in a two-node setup. Wait for the |
| 2007 | * earlier peer request to complete. |
| 2008 | */ |
| 2009 | err = drbd_wait_misc(mdev, i); |
| 2010 | if (err) |
| 2011 | goto out; |
| 2012 | goto repeat; |
| 2013 | } |
| 2014 | |
| 2015 | equal = i->sector == sector && i->size == size; |
| 2016 | if (resolve_conflicts) { |
| 2017 | /* |
| 2018 | * If the peer request is fully contained within the |
| 2019 | * overlapping request, it can be discarded; otherwise, |
| 2020 | * it will be retried once all overlapping requests |
| 2021 | * have completed. |
| 2022 | */ |
| 2023 | bool discard = i->sector <= sector && i->sector + |
| 2024 | (i->size >> 9) >= sector + (size >> 9); |
| 2025 | |
| 2026 | if (!equal) |
| 2027 | dev_alert(DEV, "Concurrent writes detected: " |
| 2028 | "local=%llus +%u, remote=%llus +%u, " |
| 2029 | "assuming %s came first\n", |
| 2030 | (unsigned long long)i->sector, i->size, |
| 2031 | (unsigned long long)sector, size, |
| 2032 | discard ? "local" : "remote"); |
| 2033 | |
| 2034 | inc_unacked(mdev); |
| 2035 | peer_req->w.cb = discard ? e_send_discard_write : |
| 2036 | e_send_retry_write; |
| 2037 | list_add_tail(&peer_req->w.list, &mdev->done_ee); |
| 2038 | wake_asender(mdev->tconn); |
| 2039 | |
| 2040 | err = -ENOENT; |
| 2041 | goto out; |
| 2042 | } else { |
| 2043 | struct drbd_request *req = |
| 2044 | container_of(i, struct drbd_request, i); |
| 2045 | |
| 2046 | if (!equal) |
| 2047 | dev_alert(DEV, "Concurrent writes detected: " |
| 2048 | "local=%llus +%u, remote=%llus +%u\n", |
| 2049 | (unsigned long long)i->sector, i->size, |
| 2050 | (unsigned long long)sector, size); |
| 2051 | |
| 2052 | if (req->rq_state & RQ_LOCAL_PENDING || |
| 2053 | !(req->rq_state & RQ_POSTPONED)) { |
| 2054 | /* |
| 2055 | * Wait for the node with the discard flag to |
| 2056 | * decide if this request will be discarded or |
| 2057 | * retried. Requests that are discarded will |
| 2058 | * disappear from the write_requests tree. |
| 2059 | * |
| 2060 | * In addition, wait for the conflicting |
| 2061 | * request to finish locally before submitting |
| 2062 | * the conflicting peer request. |
| 2063 | */ |
| 2064 | err = drbd_wait_misc(mdev, &req->i); |
| 2065 | if (err) { |
| 2066 | _conn_request_state(mdev->tconn, |
| 2067 | NS(conn, C_TIMEOUT), |
| 2068 | CS_HARD); |
| 2069 | fail_postponed_requests(mdev, sector, size); |
| 2070 | goto out; |
| 2071 | } |
| 2072 | goto repeat; |
| 2073 | } |
| 2074 | /* |
| 2075 | * Remember to restart the conflicting requests after |
| 2076 | * the new peer request has completed. |
| 2077 | */ |
| 2078 | peer_req->flags |= EE_RESTART_REQUESTS; |
| 2079 | } |
| 2080 | } |
| 2081 | err = 0; |
| 2082 | |
| 2083 | out: |
| 2084 | if (err) |
| 2085 | drbd_remove_epoch_entry_interval(mdev, peer_req); |
| 2086 | return err; |
| 2087 | } |
| 2088 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2089 | /* mirrored write */ |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2090 | static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2091 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2092 | struct drbd_conf *mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2093 | sector_t sector; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2094 | struct drbd_peer_request *peer_req; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 2095 | struct p_data *p = pi->data; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2096 | u32 peer_seq = be32_to_cpu(p->seq_num); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2097 | int rw = WRITE; |
| 2098 | u32 dp_flags; |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 2099 | int err, tp; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2100 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2101 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 2102 | if (!mdev) |
| 2103 | return -EIO; |
| 2104 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2105 | if (!get_ldev(mdev)) { |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2106 | int err2; |
| 2107 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2108 | err = wait_for_and_update_peer_seq(mdev, peer_seq); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2109 | drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size); |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 2110 | atomic_inc(&tconn->current_epoch->epoch_size); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2111 | err2 = drbd_drain_block(mdev, pi->size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2112 | if (!err) |
| 2113 | err = err2; |
| 2114 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
Andreas Gruenbacher | fcefa62 | 2011-02-17 16:46:59 +0100 | [diff] [blame] | 2117 | /* |
| 2118 | * Corresponding put_ldev done either below (on various errors), or in |
| 2119 | * drbd_peer_request_endio, if we successfully submit the data at the |
| 2120 | * end of this function. |
| 2121 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2122 | |
| 2123 | sector = be64_to_cpu(p->sector); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2124 | peer_req = read_in_block(mdev, p->block_id, sector, pi->size); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2125 | if (!peer_req) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2126 | put_ldev(mdev); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2127 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2130 | peer_req->w.cb = e_end_block; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2131 | |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 2132 | dp_flags = be32_to_cpu(p->dp_flags); |
| 2133 | rw |= wire_flags_to_bio(mdev, dp_flags); |
| 2134 | |
| 2135 | if (dp_flags & DP_MAY_SET_IN_SYNC) |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2136 | peer_req->flags |= EE_MAY_SET_IN_SYNC; |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 2137 | |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 2138 | spin_lock(&tconn->epoch_lock); |
| 2139 | peer_req->epoch = tconn->current_epoch; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2140 | atomic_inc(&peer_req->epoch->epoch_size); |
| 2141 | atomic_inc(&peer_req->epoch->active); |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 2142 | spin_unlock(&tconn->epoch_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2143 | |
Philipp Reisner | 302bdea | 2011-04-21 11:36:49 +0200 | [diff] [blame] | 2144 | rcu_read_lock(); |
| 2145 | tp = rcu_dereference(mdev->tconn->net_conf)->two_primaries; |
| 2146 | rcu_read_unlock(); |
| 2147 | if (tp) { |
| 2148 | peer_req->flags |= EE_IN_INTERVAL_TREE; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2149 | err = wait_for_and_update_peer_seq(mdev, peer_seq); |
| 2150 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2151 | goto out_interrupted; |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2152 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2153 | err = handle_write_conflicts(mdev, peer_req); |
| 2154 | if (err) { |
| 2155 | spin_unlock_irq(&mdev->tconn->req_lock); |
| 2156 | if (err == -ENOENT) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2157 | put_ldev(mdev); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2158 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2159 | } |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2160 | goto out_interrupted; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2161 | } |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2162 | } else |
| 2163 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2164 | list_add(&peer_req->w.list, &mdev->active_ee); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2165 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2166 | |
Lars Ellenberg | d93f630 | 2012-03-26 15:49:13 +0200 | [diff] [blame] | 2167 | if (mdev->state.conn == C_SYNC_TARGET) |
Philipp Reisner | 3ea35df | 2012-04-06 12:13:18 +0200 | [diff] [blame] | 2168 | wait_event(mdev->ee_wait, !overlapping_resync_write(mdev, peer_req)); |
Lars Ellenberg | d93f630 | 2012-03-26 15:49:13 +0200 | [diff] [blame] | 2169 | |
Philipp Reisner | 303d144 | 2011-04-13 16:24:47 -0700 | [diff] [blame] | 2170 | if (mdev->tconn->agreed_pro_version < 100) { |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2171 | rcu_read_lock(); |
| 2172 | switch (rcu_dereference(mdev->tconn->net_conf)->wire_protocol) { |
Philipp Reisner | 303d144 | 2011-04-13 16:24:47 -0700 | [diff] [blame] | 2173 | case DRBD_PROT_C: |
| 2174 | dp_flags |= DP_SEND_WRITE_ACK; |
| 2175 | break; |
| 2176 | case DRBD_PROT_B: |
| 2177 | dp_flags |= DP_SEND_RECEIVE_ACK; |
| 2178 | break; |
| 2179 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2180 | rcu_read_unlock(); |
Philipp Reisner | 303d144 | 2011-04-13 16:24:47 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | if (dp_flags & DP_SEND_WRITE_ACK) { |
| 2184 | peer_req->flags |= EE_SEND_WRITE_ACK; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2185 | inc_unacked(mdev); |
| 2186 | /* corresponding dec_unacked() in e_end_block() |
| 2187 | * respective _drbd_clear_done_ee */ |
Philipp Reisner | 303d144 | 2011-04-13 16:24:47 -0700 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | if (dp_flags & DP_SEND_RECEIVE_ACK) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2191 | /* I really don't like it that the receiver thread |
| 2192 | * sends on the msock, but anyways */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2193 | drbd_send_ack(mdev, P_RECV_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Lars Ellenberg | 6719fb0 | 2010-10-18 23:04:07 +0200 | [diff] [blame] | 2196 | if (mdev->state.pdsk < D_INCONSISTENT) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2197 | /* In case we have the only disk of the cluster, */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2198 | drbd_set_out_of_sync(mdev, peer_req->i.sector, peer_req->i.size); |
| 2199 | peer_req->flags |= EE_CALL_AL_COMPLETE_IO; |
| 2200 | peer_req->flags &= ~EE_MAY_SET_IN_SYNC; |
Lars Ellenberg | 181286a | 2011-03-31 15:18:56 +0200 | [diff] [blame] | 2201 | drbd_al_begin_io(mdev, &peer_req->i); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2204 | err = drbd_submit_peer_request(mdev, peer_req, rw, DRBD_FAULT_DT_WR); |
| 2205 | if (!err) |
| 2206 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2207 | |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 2208 | /* don't care for the reason here */ |
| 2209 | dev_err(DEV, "submit failed, triggering re-connect\n"); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2210 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2211 | list_del(&peer_req->w.list); |
| 2212 | drbd_remove_epoch_entry_interval(mdev, peer_req); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2213 | spin_unlock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2214 | if (peer_req->flags & EE_CALL_AL_COMPLETE_IO) |
Lars Ellenberg | 181286a | 2011-03-31 15:18:56 +0200 | [diff] [blame] | 2215 | drbd_al_complete_io(mdev, &peer_req->i); |
Lars Ellenberg | 22cc37a | 2010-09-14 20:40:41 +0200 | [diff] [blame] | 2216 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2217 | out_interrupted: |
Philipp Reisner | 1e9dd29 | 2011-11-10 15:14:53 +0100 | [diff] [blame] | 2218 | drbd_may_finish_epoch(tconn, peer_req->epoch, EV_PUT + EV_CLEANUP); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2219 | put_ldev(mdev); |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 2220 | drbd_free_peer_req(mdev, peer_req); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2221 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2224 | /* We may throttle resync, if the lower device seems to be busy, |
| 2225 | * and current sync rate is above c_min_rate. |
| 2226 | * |
| 2227 | * To decide whether or not the lower device is busy, we use a scheme similar |
| 2228 | * to MD RAID is_mddev_idle(): if the partition stats reveal "significant" |
| 2229 | * (more than 64 sectors) of activity we cannot account for with our own resync |
| 2230 | * activity, it obviously is "busy". |
| 2231 | * |
| 2232 | * The current sync rate used here uses only the most recent two step marks, |
| 2233 | * to have a short time average so we can react faster. |
| 2234 | */ |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2235 | int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector) |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2236 | { |
| 2237 | struct gendisk *disk = mdev->ldev->backing_bdev->bd_contains->bd_disk; |
| 2238 | unsigned long db, dt, dbdt; |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2239 | struct lc_element *tmp; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2240 | int curr_events; |
| 2241 | int throttle = 0; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2242 | unsigned int c_min_rate; |
| 2243 | |
| 2244 | rcu_read_lock(); |
| 2245 | c_min_rate = rcu_dereference(mdev->ldev->disk_conf)->c_min_rate; |
| 2246 | rcu_read_unlock(); |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2247 | |
| 2248 | /* feature disabled? */ |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2249 | if (c_min_rate == 0) |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2250 | return 0; |
| 2251 | |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2252 | spin_lock_irq(&mdev->al_lock); |
| 2253 | tmp = lc_find(mdev->resync, BM_SECT_TO_EXT(sector)); |
| 2254 | if (tmp) { |
| 2255 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); |
| 2256 | if (test_bit(BME_PRIORITY, &bm_ext->flags)) { |
| 2257 | spin_unlock_irq(&mdev->al_lock); |
| 2258 | return 0; |
| 2259 | } |
| 2260 | /* Do not slow down if app IO is already waiting for this extent */ |
| 2261 | } |
| 2262 | spin_unlock_irq(&mdev->al_lock); |
| 2263 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2264 | curr_events = (int)part_stat_read(&disk->part0, sectors[0]) + |
| 2265 | (int)part_stat_read(&disk->part0, sectors[1]) - |
| 2266 | atomic_read(&mdev->rs_sect_ev); |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2267 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2268 | if (!mdev->rs_last_events || curr_events - mdev->rs_last_events > 64) { |
| 2269 | unsigned long rs_left; |
| 2270 | int i; |
| 2271 | |
| 2272 | mdev->rs_last_events = curr_events; |
| 2273 | |
| 2274 | /* sync speed average over the last 2*DRBD_SYNC_MARK_STEP, |
| 2275 | * approx. */ |
Lars Ellenberg | 2649f08 | 2010-11-05 10:05:47 +0100 | [diff] [blame] | 2276 | i = (mdev->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS; |
| 2277 | |
| 2278 | if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T) |
| 2279 | rs_left = mdev->ov_left; |
| 2280 | else |
| 2281 | rs_left = drbd_bm_total_weight(mdev) - mdev->rs_failed; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2282 | |
| 2283 | dt = ((long)jiffies - (long)mdev->rs_mark_time[i]) / HZ; |
| 2284 | if (!dt) |
| 2285 | dt++; |
| 2286 | db = mdev->rs_mark_left[i] - rs_left; |
| 2287 | dbdt = Bit2KB(db/dt); |
| 2288 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 2289 | if (dbdt > c_min_rate) |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2290 | throttle = 1; |
| 2291 | } |
| 2292 | return throttle; |
| 2293 | } |
| 2294 | |
| 2295 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2296 | static int receive_DataRequest(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2297 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2298 | struct drbd_conf *mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2299 | sector_t sector; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2300 | sector_t capacity; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2301 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2302 | struct digest_info *di = NULL; |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2303 | int size, verb; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2304 | unsigned int fault_type; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 2305 | struct p_block_req *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 2306 | |
| 2307 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 2308 | if (!mdev) |
| 2309 | return -EIO; |
| 2310 | capacity = drbd_get_capacity(mdev->this_bdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2311 | |
| 2312 | sector = be64_to_cpu(p->sector); |
| 2313 | size = be32_to_cpu(p->blksize); |
| 2314 | |
Andreas Gruenbacher | c670a39 | 2011-02-21 12:41:39 +0100 | [diff] [blame] | 2315 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2316 | dev_err(DEV, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, |
| 2317 | (unsigned long long)sector, size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2318 | return -EINVAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2319 | } |
| 2320 | if (sector + (size>>9) > capacity) { |
| 2321 | dev_err(DEV, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, |
| 2322 | (unsigned long long)sector, size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2323 | return -EINVAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | if (!get_ldev_if_state(mdev, D_UP_TO_DATE)) { |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2327 | verb = 1; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2328 | switch (pi->cmd) { |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2329 | case P_DATA_REQUEST: |
| 2330 | drbd_send_ack_rp(mdev, P_NEG_DREPLY, p); |
| 2331 | break; |
| 2332 | case P_RS_DATA_REQUEST: |
| 2333 | case P_CSUM_RS_REQUEST: |
| 2334 | case P_OV_REQUEST: |
| 2335 | drbd_send_ack_rp(mdev, P_NEG_RS_DREPLY , p); |
| 2336 | break; |
| 2337 | case P_OV_REPLY: |
| 2338 | verb = 0; |
| 2339 | dec_rs_pending(mdev); |
| 2340 | drbd_send_ack_ex(mdev, P_OV_RESULT, sector, size, ID_IN_SYNC); |
| 2341 | break; |
| 2342 | default: |
Andreas Gruenbacher | 49ba9b1 | 2011-03-25 00:35:45 +0100 | [diff] [blame] | 2343 | BUG(); |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2344 | } |
| 2345 | if (verb && __ratelimit(&drbd_ratelimit_state)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2346 | dev_err(DEV, "Can not satisfy peer's read request, " |
| 2347 | "no local data.\n"); |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2348 | |
Lars Ellenberg | a821cc4 | 2010-09-06 12:31:37 +0200 | [diff] [blame] | 2349 | /* drain possibly payload */ |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2350 | return drbd_drain_block(mdev, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD |
| 2354 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
| 2355 | * which in turn might block on the other node at this very place. */ |
Andreas Gruenbacher | 0db5536 | 2011-04-06 16:09:15 +0200 | [diff] [blame] | 2356 | peer_req = drbd_alloc_peer_req(mdev, p->block_id, sector, size, GFP_NOIO); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2357 | if (!peer_req) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2358 | put_ldev(mdev); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2359 | return -ENOMEM; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2362 | switch (pi->cmd) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2363 | case P_DATA_REQUEST: |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2364 | peer_req->w.cb = w_e_end_data_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2365 | fault_type = DRBD_FAULT_DT_RD; |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2366 | /* application IO, don't drbd_rs_begin_io */ |
| 2367 | goto submit; |
| 2368 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2369 | case P_RS_DATA_REQUEST: |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2370 | peer_req->w.cb = w_e_end_rsdata_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2371 | fault_type = DRBD_FAULT_RS_RD; |
Lars Ellenberg | 5f9915b | 2010-11-09 14:15:24 +0100 | [diff] [blame] | 2372 | /* used in the sector offset progress display */ |
| 2373 | mdev->bm_resync_fo = BM_SECT_TO_BIT(sector); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2374 | break; |
| 2375 | |
| 2376 | case P_OV_REPLY: |
| 2377 | case P_CSUM_RS_REQUEST: |
| 2378 | fault_type = DRBD_FAULT_RS_RD; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2379 | di = kmalloc(sizeof(*di) + pi->size, GFP_NOIO); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2380 | if (!di) |
| 2381 | goto out_free_e; |
| 2382 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2383 | di->digest_size = pi->size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2384 | di->digest = (((char *)di)+sizeof(struct digest_info)); |
| 2385 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2386 | peer_req->digest = di; |
| 2387 | peer_req->flags |= EE_HAS_DIGEST; |
Lars Ellenberg | c36c3ce | 2010-08-11 20:42:55 +0200 | [diff] [blame] | 2388 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2389 | if (drbd_recv_all(mdev->tconn, di->digest, pi->size)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2390 | goto out_free_e; |
| 2391 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2392 | if (pi->cmd == P_CSUM_RS_REQUEST) { |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2393 | D_ASSERT(mdev->tconn->agreed_pro_version >= 89); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2394 | peer_req->w.cb = w_e_end_csum_rs_req; |
Lars Ellenberg | 5f9915b | 2010-11-09 14:15:24 +0100 | [diff] [blame] | 2395 | /* used in the sector offset progress display */ |
| 2396 | mdev->bm_resync_fo = BM_SECT_TO_BIT(sector); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 2397 | } else if (pi->cmd == P_OV_REPLY) { |
Lars Ellenberg | 2649f08 | 2010-11-05 10:05:47 +0100 | [diff] [blame] | 2398 | /* track progress, we may need to throttle */ |
| 2399 | atomic_add(size >> 9, &mdev->rs_sect_in); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2400 | peer_req->w.cb = w_e_end_ov_reply; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2401 | dec_rs_pending(mdev); |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2402 | /* drbd_rs_begin_io done when we sent this request, |
| 2403 | * but accounting still needs to be done. */ |
| 2404 | goto submit_for_resync; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2405 | } |
| 2406 | break; |
| 2407 | |
| 2408 | case P_OV_REQUEST: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2409 | if (mdev->ov_start_sector == ~(sector_t)0 && |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2410 | mdev->tconn->agreed_pro_version >= 90) { |
Lars Ellenberg | de228bb | 2010-11-05 09:43:15 +0100 | [diff] [blame] | 2411 | unsigned long now = jiffies; |
| 2412 | int i; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2413 | mdev->ov_start_sector = sector; |
| 2414 | mdev->ov_position = sector; |
Lars Ellenberg | 30b743a | 2010-11-05 09:39:06 +0100 | [diff] [blame] | 2415 | mdev->ov_left = drbd_bm_bits(mdev) - BM_SECT_TO_BIT(sector); |
| 2416 | mdev->rs_total = mdev->ov_left; |
Lars Ellenberg | de228bb | 2010-11-05 09:43:15 +0100 | [diff] [blame] | 2417 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { |
| 2418 | mdev->rs_mark_left[i] = mdev->ov_left; |
| 2419 | mdev->rs_mark_time[i] = now; |
| 2420 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2421 | dev_info(DEV, "Online Verify start sector: %llu\n", |
| 2422 | (unsigned long long)sector); |
| 2423 | } |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2424 | peer_req->w.cb = w_e_end_ov_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2425 | fault_type = DRBD_FAULT_RS_RD; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2426 | break; |
| 2427 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2428 | default: |
Andreas Gruenbacher | 49ba9b1 | 2011-03-25 00:35:45 +0100 | [diff] [blame] | 2429 | BUG(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2432 | /* Throttle, drbd_rs_begin_io and submit should become asynchronous |
| 2433 | * wrt the receiver, but it is not as straightforward as it may seem. |
| 2434 | * Various places in the resync start and stop logic assume resync |
| 2435 | * requests are processed in order, requeuing this on the worker thread |
| 2436 | * introduces a bunch of new code for synchronization between threads. |
| 2437 | * |
| 2438 | * Unlimited throttling before drbd_rs_begin_io may stall the resync |
| 2439 | * "forever", throttling after drbd_rs_begin_io will lock that extent |
| 2440 | * for application writes for the same time. For now, just throttle |
| 2441 | * here, where the rest of the code expects the receiver to sleep for |
| 2442 | * a while, anyways. |
| 2443 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2444 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2445 | /* Throttle before drbd_rs_begin_io, as that locks out application IO; |
| 2446 | * this defers syncer requests for some time, before letting at least |
| 2447 | * on request through. The resync controller on the receiving side |
| 2448 | * will adapt to the incoming rate accordingly. |
| 2449 | * |
| 2450 | * We cannot throttle here if remote is Primary/SyncTarget: |
| 2451 | * we would also throttle its application reads. |
| 2452 | * In that case, throttling is done on the SyncTarget only. |
| 2453 | */ |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2454 | if (mdev->state.peer != R_PRIMARY && drbd_rs_should_slow_down(mdev, sector)) |
| 2455 | schedule_timeout_uninterruptible(HZ/10); |
| 2456 | if (drbd_rs_begin_io(mdev, sector)) |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2457 | goto out_free_e; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2458 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2459 | submit_for_resync: |
| 2460 | atomic_add(size >> 9, &mdev->rs_sect_ev); |
| 2461 | |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2462 | submit: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2463 | inc_unacked(mdev); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2464 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2465 | list_add_tail(&peer_req->w.list, &mdev->read_ee); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2466 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2467 | |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 2468 | if (drbd_submit_peer_request(mdev, peer_req, READ, fault_type) == 0) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2469 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2470 | |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 2471 | /* don't care for the reason here */ |
| 2472 | dev_err(DEV, "submit failed, triggering re-connect\n"); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2473 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2474 | list_del(&peer_req->w.list); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2475 | spin_unlock_irq(&mdev->tconn->req_lock); |
Lars Ellenberg | 22cc37a | 2010-09-14 20:40:41 +0200 | [diff] [blame] | 2476 | /* no drbd_rs_complete_io(), we are dropping the connection anyways */ |
| 2477 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2478 | out_free_e: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2479 | put_ldev(mdev); |
Andreas Gruenbacher | 3967deb | 2011-04-06 16:16:56 +0200 | [diff] [blame] | 2480 | drbd_free_peer_req(mdev, peer_req); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 2481 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | static int drbd_asb_recover_0p(struct drbd_conf *mdev) __must_hold(local) |
| 2485 | { |
| 2486 | int self, peer, rv = -100; |
| 2487 | unsigned long ch_self, ch_peer; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2488 | enum drbd_after_sb_p after_sb_0p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2489 | |
| 2490 | self = mdev->ldev->md.uuid[UI_BITMAP] & 1; |
| 2491 | peer = mdev->p_uuid[UI_BITMAP] & 1; |
| 2492 | |
| 2493 | ch_peer = mdev->p_uuid[UI_SIZE]; |
| 2494 | ch_self = mdev->comm_bm_set; |
| 2495 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2496 | rcu_read_lock(); |
| 2497 | after_sb_0p = rcu_dereference(mdev->tconn->net_conf)->after_sb_0p; |
| 2498 | rcu_read_unlock(); |
| 2499 | switch (after_sb_0p) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2500 | case ASB_CONSENSUS: |
| 2501 | case ASB_DISCARD_SECONDARY: |
| 2502 | case ASB_CALL_HELPER: |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2503 | case ASB_VIOLENTLY: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2504 | dev_err(DEV, "Configuration error.\n"); |
| 2505 | break; |
| 2506 | case ASB_DISCONNECT: |
| 2507 | break; |
| 2508 | case ASB_DISCARD_YOUNGER_PRI: |
| 2509 | if (self == 0 && peer == 1) { |
| 2510 | rv = -1; |
| 2511 | break; |
| 2512 | } |
| 2513 | if (self == 1 && peer == 0) { |
| 2514 | rv = 1; |
| 2515 | break; |
| 2516 | } |
| 2517 | /* Else fall through to one of the other strategies... */ |
| 2518 | case ASB_DISCARD_OLDER_PRI: |
| 2519 | if (self == 0 && peer == 1) { |
| 2520 | rv = 1; |
| 2521 | break; |
| 2522 | } |
| 2523 | if (self == 1 && peer == 0) { |
| 2524 | rv = -1; |
| 2525 | break; |
| 2526 | } |
| 2527 | /* Else fall through to one of the other strategies... */ |
Lars Ellenberg | ad19bf6 | 2009-10-14 09:36:49 +0200 | [diff] [blame] | 2528 | dev_warn(DEV, "Discard younger/older primary did not find a decision\n" |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2529 | "Using discard-least-changes instead\n"); |
| 2530 | case ASB_DISCARD_ZERO_CHG: |
| 2531 | if (ch_peer == 0 && ch_self == 0) { |
Philipp Reisner | 25703f8 | 2011-02-07 14:35:25 +0100 | [diff] [blame] | 2532 | rv = test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2533 | ? -1 : 1; |
| 2534 | break; |
| 2535 | } else { |
| 2536 | if (ch_peer == 0) { rv = 1; break; } |
| 2537 | if (ch_self == 0) { rv = -1; break; } |
| 2538 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2539 | if (after_sb_0p == ASB_DISCARD_ZERO_CHG) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2540 | break; |
| 2541 | case ASB_DISCARD_LEAST_CHG: |
| 2542 | if (ch_self < ch_peer) |
| 2543 | rv = -1; |
| 2544 | else if (ch_self > ch_peer) |
| 2545 | rv = 1; |
| 2546 | else /* ( ch_self == ch_peer ) */ |
| 2547 | /* Well, then use something else. */ |
Philipp Reisner | 25703f8 | 2011-02-07 14:35:25 +0100 | [diff] [blame] | 2548 | rv = test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2549 | ? -1 : 1; |
| 2550 | break; |
| 2551 | case ASB_DISCARD_LOCAL: |
| 2552 | rv = -1; |
| 2553 | break; |
| 2554 | case ASB_DISCARD_REMOTE: |
| 2555 | rv = 1; |
| 2556 | } |
| 2557 | |
| 2558 | return rv; |
| 2559 | } |
| 2560 | |
| 2561 | static int drbd_asb_recover_1p(struct drbd_conf *mdev) __must_hold(local) |
| 2562 | { |
Andreas Gruenbacher | 6184ea2 | 2010-12-09 14:23:27 +0100 | [diff] [blame] | 2563 | int hg, rv = -100; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2564 | enum drbd_after_sb_p after_sb_1p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2565 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2566 | rcu_read_lock(); |
| 2567 | after_sb_1p = rcu_dereference(mdev->tconn->net_conf)->after_sb_1p; |
| 2568 | rcu_read_unlock(); |
| 2569 | switch (after_sb_1p) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2570 | case ASB_DISCARD_YOUNGER_PRI: |
| 2571 | case ASB_DISCARD_OLDER_PRI: |
| 2572 | case ASB_DISCARD_LEAST_CHG: |
| 2573 | case ASB_DISCARD_LOCAL: |
| 2574 | case ASB_DISCARD_REMOTE: |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2575 | case ASB_DISCARD_ZERO_CHG: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2576 | dev_err(DEV, "Configuration error.\n"); |
| 2577 | break; |
| 2578 | case ASB_DISCONNECT: |
| 2579 | break; |
| 2580 | case ASB_CONSENSUS: |
| 2581 | hg = drbd_asb_recover_0p(mdev); |
| 2582 | if (hg == -1 && mdev->state.role == R_SECONDARY) |
| 2583 | rv = hg; |
| 2584 | if (hg == 1 && mdev->state.role == R_PRIMARY) |
| 2585 | rv = hg; |
| 2586 | break; |
| 2587 | case ASB_VIOLENTLY: |
| 2588 | rv = drbd_asb_recover_0p(mdev); |
| 2589 | break; |
| 2590 | case ASB_DISCARD_SECONDARY: |
| 2591 | return mdev->state.role == R_PRIMARY ? 1 : -1; |
| 2592 | case ASB_CALL_HELPER: |
| 2593 | hg = drbd_asb_recover_0p(mdev); |
| 2594 | if (hg == -1 && mdev->state.role == R_PRIMARY) { |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2595 | enum drbd_state_rv rv2; |
| 2596 | |
| 2597 | drbd_set_role(mdev, R_SECONDARY, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2598 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, |
| 2599 | * we might be here in C_WF_REPORT_PARAMS which is transient. |
| 2600 | * we do not need to wait for the after state change work either. */ |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2601 | rv2 = drbd_change_state(mdev, CS_VERBOSE, NS(role, R_SECONDARY)); |
| 2602 | if (rv2 != SS_SUCCESS) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2603 | drbd_khelper(mdev, "pri-lost-after-sb"); |
| 2604 | } else { |
| 2605 | dev_warn(DEV, "Successfully gave up primary role.\n"); |
| 2606 | rv = hg; |
| 2607 | } |
| 2608 | } else |
| 2609 | rv = hg; |
| 2610 | } |
| 2611 | |
| 2612 | return rv; |
| 2613 | } |
| 2614 | |
| 2615 | static int drbd_asb_recover_2p(struct drbd_conf *mdev) __must_hold(local) |
| 2616 | { |
Andreas Gruenbacher | 6184ea2 | 2010-12-09 14:23:27 +0100 | [diff] [blame] | 2617 | int hg, rv = -100; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2618 | enum drbd_after_sb_p after_sb_2p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2619 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2620 | rcu_read_lock(); |
| 2621 | after_sb_2p = rcu_dereference(mdev->tconn->net_conf)->after_sb_2p; |
| 2622 | rcu_read_unlock(); |
| 2623 | switch (after_sb_2p) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2624 | case ASB_DISCARD_YOUNGER_PRI: |
| 2625 | case ASB_DISCARD_OLDER_PRI: |
| 2626 | case ASB_DISCARD_LEAST_CHG: |
| 2627 | case ASB_DISCARD_LOCAL: |
| 2628 | case ASB_DISCARD_REMOTE: |
| 2629 | case ASB_CONSENSUS: |
| 2630 | case ASB_DISCARD_SECONDARY: |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2631 | case ASB_DISCARD_ZERO_CHG: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2632 | dev_err(DEV, "Configuration error.\n"); |
| 2633 | break; |
| 2634 | case ASB_VIOLENTLY: |
| 2635 | rv = drbd_asb_recover_0p(mdev); |
| 2636 | break; |
| 2637 | case ASB_DISCONNECT: |
| 2638 | break; |
| 2639 | case ASB_CALL_HELPER: |
| 2640 | hg = drbd_asb_recover_0p(mdev); |
| 2641 | if (hg == -1) { |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2642 | enum drbd_state_rv rv2; |
| 2643 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2644 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, |
| 2645 | * we might be here in C_WF_REPORT_PARAMS which is transient. |
| 2646 | * we do not need to wait for the after state change work either. */ |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2647 | rv2 = drbd_change_state(mdev, CS_VERBOSE, NS(role, R_SECONDARY)); |
| 2648 | if (rv2 != SS_SUCCESS) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2649 | drbd_khelper(mdev, "pri-lost-after-sb"); |
| 2650 | } else { |
| 2651 | dev_warn(DEV, "Successfully gave up primary role.\n"); |
| 2652 | rv = hg; |
| 2653 | } |
| 2654 | } else |
| 2655 | rv = hg; |
| 2656 | } |
| 2657 | |
| 2658 | return rv; |
| 2659 | } |
| 2660 | |
| 2661 | static void drbd_uuid_dump(struct drbd_conf *mdev, char *text, u64 *uuid, |
| 2662 | u64 bits, u64 flags) |
| 2663 | { |
| 2664 | if (!uuid) { |
| 2665 | dev_info(DEV, "%s uuid info vanished while I was looking!\n", text); |
| 2666 | return; |
| 2667 | } |
| 2668 | dev_info(DEV, "%s %016llX:%016llX:%016llX:%016llX bits:%llu flags:%llX\n", |
| 2669 | text, |
| 2670 | (unsigned long long)uuid[UI_CURRENT], |
| 2671 | (unsigned long long)uuid[UI_BITMAP], |
| 2672 | (unsigned long long)uuid[UI_HISTORY_START], |
| 2673 | (unsigned long long)uuid[UI_HISTORY_END], |
| 2674 | (unsigned long long)bits, |
| 2675 | (unsigned long long)flags); |
| 2676 | } |
| 2677 | |
| 2678 | /* |
| 2679 | 100 after split brain try auto recover |
| 2680 | 2 C_SYNC_SOURCE set BitMap |
| 2681 | 1 C_SYNC_SOURCE use BitMap |
| 2682 | 0 no Sync |
| 2683 | -1 C_SYNC_TARGET use BitMap |
| 2684 | -2 C_SYNC_TARGET set BitMap |
| 2685 | -100 after split brain, disconnect |
| 2686 | -1000 unrelated data |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2687 | -1091 requires proto 91 |
| 2688 | -1096 requires proto 96 |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2689 | */ |
| 2690 | static int drbd_uuid_compare(struct drbd_conf *mdev, int *rule_nr) __must_hold(local) |
| 2691 | { |
| 2692 | u64 self, peer; |
| 2693 | int i, j; |
| 2694 | |
| 2695 | self = mdev->ldev->md.uuid[UI_CURRENT] & ~((u64)1); |
| 2696 | peer = mdev->p_uuid[UI_CURRENT] & ~((u64)1); |
| 2697 | |
| 2698 | *rule_nr = 10; |
| 2699 | if (self == UUID_JUST_CREATED && peer == UUID_JUST_CREATED) |
| 2700 | return 0; |
| 2701 | |
| 2702 | *rule_nr = 20; |
| 2703 | if ((self == UUID_JUST_CREATED || self == (u64)0) && |
| 2704 | peer != UUID_JUST_CREATED) |
| 2705 | return -2; |
| 2706 | |
| 2707 | *rule_nr = 30; |
| 2708 | if (self != UUID_JUST_CREATED && |
| 2709 | (peer == UUID_JUST_CREATED || peer == (u64)0)) |
| 2710 | return 2; |
| 2711 | |
| 2712 | if (self == peer) { |
| 2713 | int rct, dc; /* roles at crash time */ |
| 2714 | |
| 2715 | if (mdev->p_uuid[UI_BITMAP] == (u64)0 && mdev->ldev->md.uuid[UI_BITMAP] != (u64)0) { |
| 2716 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2717 | if (mdev->tconn->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2718 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2719 | |
| 2720 | if ((mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1)) == (mdev->p_uuid[UI_HISTORY_START] & ~((u64)1)) && |
| 2721 | (mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (mdev->p_uuid[UI_HISTORY_START + 1] & ~((u64)1))) { |
| 2722 | dev_info(DEV, "was SyncSource, missed the resync finished event, corrected myself:\n"); |
| 2723 | drbd_uuid_set_bm(mdev, 0UL); |
| 2724 | |
| 2725 | drbd_uuid_dump(mdev, "self", mdev->ldev->md.uuid, |
| 2726 | mdev->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(mdev) : 0, 0); |
| 2727 | *rule_nr = 34; |
| 2728 | } else { |
| 2729 | dev_info(DEV, "was SyncSource (peer failed to write sync_uuid)\n"); |
| 2730 | *rule_nr = 36; |
| 2731 | } |
| 2732 | |
| 2733 | return 1; |
| 2734 | } |
| 2735 | |
| 2736 | if (mdev->ldev->md.uuid[UI_BITMAP] == (u64)0 && mdev->p_uuid[UI_BITMAP] != (u64)0) { |
| 2737 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2738 | if (mdev->tconn->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2739 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2740 | |
| 2741 | if ((mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (mdev->p_uuid[UI_BITMAP] & ~((u64)1)) && |
| 2742 | (mdev->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == (mdev->p_uuid[UI_HISTORY_START] & ~((u64)1))) { |
| 2743 | dev_info(DEV, "was SyncTarget, peer missed the resync finished event, corrected peer:\n"); |
| 2744 | |
| 2745 | mdev->p_uuid[UI_HISTORY_START + 1] = mdev->p_uuid[UI_HISTORY_START]; |
| 2746 | mdev->p_uuid[UI_HISTORY_START] = mdev->p_uuid[UI_BITMAP]; |
| 2747 | mdev->p_uuid[UI_BITMAP] = 0UL; |
| 2748 | |
| 2749 | drbd_uuid_dump(mdev, "peer", mdev->p_uuid, mdev->p_uuid[UI_SIZE], mdev->p_uuid[UI_FLAGS]); |
| 2750 | *rule_nr = 35; |
| 2751 | } else { |
| 2752 | dev_info(DEV, "was SyncTarget (failed to write sync_uuid)\n"); |
| 2753 | *rule_nr = 37; |
| 2754 | } |
| 2755 | |
| 2756 | return -1; |
| 2757 | } |
| 2758 | |
| 2759 | /* Common power [off|failure] */ |
| 2760 | rct = (test_bit(CRASHED_PRIMARY, &mdev->flags) ? 1 : 0) + |
| 2761 | (mdev->p_uuid[UI_FLAGS] & 2); |
| 2762 | /* lowest bit is set when we were primary, |
| 2763 | * next bit (weight 2) is set when peer was primary */ |
| 2764 | *rule_nr = 40; |
| 2765 | |
| 2766 | switch (rct) { |
| 2767 | case 0: /* !self_pri && !peer_pri */ return 0; |
| 2768 | case 1: /* self_pri && !peer_pri */ return 1; |
| 2769 | case 2: /* !self_pri && peer_pri */ return -1; |
| 2770 | case 3: /* self_pri && peer_pri */ |
Philipp Reisner | 25703f8 | 2011-02-07 14:35:25 +0100 | [diff] [blame] | 2771 | dc = test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2772 | return dc ? -1 : 1; |
| 2773 | } |
| 2774 | } |
| 2775 | |
| 2776 | *rule_nr = 50; |
| 2777 | peer = mdev->p_uuid[UI_BITMAP] & ~((u64)1); |
| 2778 | if (self == peer) |
| 2779 | return -1; |
| 2780 | |
| 2781 | *rule_nr = 51; |
| 2782 | peer = mdev->p_uuid[UI_HISTORY_START] & ~((u64)1); |
| 2783 | if (self == peer) { |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2784 | if (mdev->tconn->agreed_pro_version < 96 ? |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2785 | (mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == |
| 2786 | (mdev->p_uuid[UI_HISTORY_START + 1] & ~((u64)1)) : |
| 2787 | peer + UUID_NEW_BM_OFFSET == (mdev->p_uuid[UI_BITMAP] & ~((u64)1))) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2788 | /* The last P_SYNC_UUID did not get though. Undo the last start of |
| 2789 | resync as sync source modifications of the peer's UUIDs. */ |
| 2790 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2791 | if (mdev->tconn->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2792 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2793 | |
| 2794 | mdev->p_uuid[UI_BITMAP] = mdev->p_uuid[UI_HISTORY_START]; |
| 2795 | mdev->p_uuid[UI_HISTORY_START] = mdev->p_uuid[UI_HISTORY_START + 1]; |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2796 | |
Lars Ellenberg | 1882e22 | 2012-05-07 13:09:00 +0200 | [diff] [blame] | 2797 | dev_info(DEV, "Lost last syncUUID packet, corrected:\n"); |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2798 | drbd_uuid_dump(mdev, "peer", mdev->p_uuid, mdev->p_uuid[UI_SIZE], mdev->p_uuid[UI_FLAGS]); |
| 2799 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2800 | return -1; |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | *rule_nr = 60; |
| 2805 | self = mdev->ldev->md.uuid[UI_CURRENT] & ~((u64)1); |
| 2806 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
| 2807 | peer = mdev->p_uuid[i] & ~((u64)1); |
| 2808 | if (self == peer) |
| 2809 | return -2; |
| 2810 | } |
| 2811 | |
| 2812 | *rule_nr = 70; |
| 2813 | self = mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1); |
| 2814 | peer = mdev->p_uuid[UI_CURRENT] & ~((u64)1); |
| 2815 | if (self == peer) |
| 2816 | return 1; |
| 2817 | |
| 2818 | *rule_nr = 71; |
| 2819 | self = mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1); |
| 2820 | if (self == peer) { |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2821 | if (mdev->tconn->agreed_pro_version < 96 ? |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2822 | (mdev->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == |
| 2823 | (mdev->p_uuid[UI_HISTORY_START] & ~((u64)1)) : |
| 2824 | self + UUID_NEW_BM_OFFSET == (mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1))) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2825 | /* The last P_SYNC_UUID did not get though. Undo the last start of |
| 2826 | resync as sync source modifications of our UUIDs. */ |
| 2827 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2828 | if (mdev->tconn->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2829 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2830 | |
| 2831 | _drbd_uuid_set(mdev, UI_BITMAP, mdev->ldev->md.uuid[UI_HISTORY_START]); |
| 2832 | _drbd_uuid_set(mdev, UI_HISTORY_START, mdev->ldev->md.uuid[UI_HISTORY_START + 1]); |
| 2833 | |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2834 | dev_info(DEV, "Last syncUUID did not get through, corrected:\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2835 | drbd_uuid_dump(mdev, "self", mdev->ldev->md.uuid, |
| 2836 | mdev->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(mdev) : 0, 0); |
| 2837 | |
| 2838 | return 1; |
| 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | |
| 2843 | *rule_nr = 80; |
Philipp Reisner | d8c2a36 | 2009-11-18 15:52:51 +0100 | [diff] [blame] | 2844 | peer = mdev->p_uuid[UI_CURRENT] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2845 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
| 2846 | self = mdev->ldev->md.uuid[i] & ~((u64)1); |
| 2847 | if (self == peer) |
| 2848 | return 2; |
| 2849 | } |
| 2850 | |
| 2851 | *rule_nr = 90; |
| 2852 | self = mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1); |
| 2853 | peer = mdev->p_uuid[UI_BITMAP] & ~((u64)1); |
| 2854 | if (self == peer && self != ((u64)0)) |
| 2855 | return 100; |
| 2856 | |
| 2857 | *rule_nr = 100; |
| 2858 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
| 2859 | self = mdev->ldev->md.uuid[i] & ~((u64)1); |
| 2860 | for (j = UI_HISTORY_START; j <= UI_HISTORY_END; j++) { |
| 2861 | peer = mdev->p_uuid[j] & ~((u64)1); |
| 2862 | if (self == peer) |
| 2863 | return -100; |
| 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | return -1000; |
| 2868 | } |
| 2869 | |
| 2870 | /* drbd_sync_handshake() returns the new conn state on success, or |
| 2871 | CONN_MASK (-1) on failure. |
| 2872 | */ |
| 2873 | static enum drbd_conns drbd_sync_handshake(struct drbd_conf *mdev, enum drbd_role peer_role, |
| 2874 | enum drbd_disk_state peer_disk) __must_hold(local) |
| 2875 | { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2876 | enum drbd_conns rv = C_MASK; |
| 2877 | enum drbd_disk_state mydisk; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2878 | struct net_conf *nc; |
Andreas Gruenbacher | 6dff290 | 2011-06-28 14:18:12 +0200 | [diff] [blame] | 2879 | int hg, rule_nr, rr_conflict, tentative; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2880 | |
| 2881 | mydisk = mdev->state.disk; |
| 2882 | if (mydisk == D_NEGOTIATING) |
| 2883 | mydisk = mdev->new_state_tmp.disk; |
| 2884 | |
| 2885 | dev_info(DEV, "drbd_sync_handshake:\n"); |
| 2886 | drbd_uuid_dump(mdev, "self", mdev->ldev->md.uuid, mdev->comm_bm_set, 0); |
| 2887 | drbd_uuid_dump(mdev, "peer", mdev->p_uuid, |
| 2888 | mdev->p_uuid[UI_SIZE], mdev->p_uuid[UI_FLAGS]); |
| 2889 | |
| 2890 | hg = drbd_uuid_compare(mdev, &rule_nr); |
| 2891 | |
| 2892 | dev_info(DEV, "uuid_compare()=%d by rule %d\n", hg, rule_nr); |
| 2893 | |
| 2894 | if (hg == -1000) { |
| 2895 | dev_alert(DEV, "Unrelated data, aborting!\n"); |
| 2896 | return C_MASK; |
| 2897 | } |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2898 | if (hg < -1000) { |
| 2899 | dev_alert(DEV, "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] | 2900 | return C_MASK; |
| 2901 | } |
| 2902 | |
| 2903 | if ((mydisk == D_INCONSISTENT && peer_disk > D_INCONSISTENT) || |
| 2904 | (peer_disk == D_INCONSISTENT && mydisk > D_INCONSISTENT)) { |
| 2905 | int f = (hg == -100) || abs(hg) == 2; |
| 2906 | hg = mydisk > D_INCONSISTENT ? 1 : -1; |
| 2907 | if (f) |
| 2908 | hg = hg*2; |
| 2909 | dev_info(DEV, "Becoming sync %s due to disk states.\n", |
| 2910 | hg > 0 ? "source" : "target"); |
| 2911 | } |
| 2912 | |
Adam Gandelman | 3a11a48 | 2010-04-08 16:48:23 -0700 | [diff] [blame] | 2913 | if (abs(hg) == 100) |
| 2914 | drbd_khelper(mdev, "initial-split-brain"); |
| 2915 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2916 | rcu_read_lock(); |
| 2917 | nc = rcu_dereference(mdev->tconn->net_conf); |
| 2918 | |
| 2919 | if (hg == 100 || (hg == -100 && nc->always_asbp)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2920 | int pcount = (mdev->state.role == R_PRIMARY) |
| 2921 | + (peer_role == R_PRIMARY); |
| 2922 | int forced = (hg == -100); |
| 2923 | |
| 2924 | switch (pcount) { |
| 2925 | case 0: |
| 2926 | hg = drbd_asb_recover_0p(mdev); |
| 2927 | break; |
| 2928 | case 1: |
| 2929 | hg = drbd_asb_recover_1p(mdev); |
| 2930 | break; |
| 2931 | case 2: |
| 2932 | hg = drbd_asb_recover_2p(mdev); |
| 2933 | break; |
| 2934 | } |
| 2935 | if (abs(hg) < 100) { |
| 2936 | dev_warn(DEV, "Split-Brain detected, %d primaries, " |
| 2937 | "automatically solved. Sync from %s node\n", |
| 2938 | pcount, (hg < 0) ? "peer" : "this"); |
| 2939 | if (forced) { |
| 2940 | dev_warn(DEV, "Doing a full sync, since" |
| 2941 | " UUIDs where ambiguous.\n"); |
| 2942 | hg = hg*2; |
| 2943 | } |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | if (hg == -100) { |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 2948 | if (test_bit(DISCARD_MY_DATA, &mdev->flags) && !(mdev->p_uuid[UI_FLAGS]&1)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2949 | hg = -1; |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 2950 | if (!test_bit(DISCARD_MY_DATA, &mdev->flags) && (mdev->p_uuid[UI_FLAGS]&1)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2951 | hg = 1; |
| 2952 | |
| 2953 | if (abs(hg) < 100) |
| 2954 | dev_warn(DEV, "Split-Brain detected, manually solved. " |
| 2955 | "Sync from %s node\n", |
| 2956 | (hg < 0) ? "peer" : "this"); |
| 2957 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2958 | rr_conflict = nc->rr_conflict; |
Andreas Gruenbacher | 6dff290 | 2011-06-28 14:18:12 +0200 | [diff] [blame] | 2959 | tentative = nc->tentative; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2960 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2961 | |
| 2962 | if (hg == -100) { |
Lars Ellenberg | 580b976 | 2010-02-26 23:15:23 +0100 | [diff] [blame] | 2963 | /* FIXME this log message is not correct if we end up here |
| 2964 | * after an attempted attach on a diskless node. |
| 2965 | * We just refuse to attach -- well, we drop the "connection" |
| 2966 | * to that disk, in a way... */ |
Adam Gandelman | 3a11a48 | 2010-04-08 16:48:23 -0700 | [diff] [blame] | 2967 | dev_alert(DEV, "Split-Brain detected but unresolved, dropping connection!\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2968 | drbd_khelper(mdev, "split-brain"); |
| 2969 | return C_MASK; |
| 2970 | } |
| 2971 | |
| 2972 | if (hg > 0 && mydisk <= D_INCONSISTENT) { |
| 2973 | dev_err(DEV, "I shall become SyncSource, but I am inconsistent!\n"); |
| 2974 | return C_MASK; |
| 2975 | } |
| 2976 | |
| 2977 | if (hg < 0 && /* by intention we do not use mydisk here. */ |
| 2978 | mdev->state.role == R_PRIMARY && mdev->state.disk >= D_CONSISTENT) { |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 2979 | switch (rr_conflict) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2980 | case ASB_CALL_HELPER: |
| 2981 | drbd_khelper(mdev, "pri-lost"); |
| 2982 | /* fall through */ |
| 2983 | case ASB_DISCONNECT: |
| 2984 | dev_err(DEV, "I shall become SyncTarget, but I am primary!\n"); |
| 2985 | return C_MASK; |
| 2986 | case ASB_VIOLENTLY: |
| 2987 | dev_warn(DEV, "Becoming SyncTarget, violating the stable-data" |
| 2988 | "assumption\n"); |
| 2989 | } |
| 2990 | } |
| 2991 | |
Andreas Gruenbacher | 6dff290 | 2011-06-28 14:18:12 +0200 | [diff] [blame] | 2992 | if (tentative || test_bit(CONN_DRY_RUN, &mdev->tconn->flags)) { |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 2993 | if (hg == 0) |
| 2994 | dev_info(DEV, "dry-run connect: No resync, would become Connected immediately.\n"); |
| 2995 | else |
| 2996 | dev_info(DEV, "dry-run connect: Would become %s, doing a %s resync.", |
| 2997 | drbd_conn_str(hg > 0 ? C_SYNC_SOURCE : C_SYNC_TARGET), |
| 2998 | abs(hg) >= 2 ? "full" : "bit-map based"); |
| 2999 | return C_MASK; |
| 3000 | } |
| 3001 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3002 | if (abs(hg) >= 2) { |
| 3003 | dev_info(DEV, "Writing the whole bitmap, full sync required after drbd_sync_handshake.\n"); |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 3004 | if (drbd_bitmap_io(mdev, &drbd_bmio_set_n_write, "set_n_write from sync_handshake", |
| 3005 | BM_LOCKED_SET_ALLOWED)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3006 | return C_MASK; |
| 3007 | } |
| 3008 | |
| 3009 | if (hg > 0) { /* become sync source. */ |
| 3010 | rv = C_WF_BITMAP_S; |
| 3011 | } else if (hg < 0) { /* become sync target */ |
| 3012 | rv = C_WF_BITMAP_T; |
| 3013 | } else { |
| 3014 | rv = C_CONNECTED; |
| 3015 | if (drbd_bm_total_weight(mdev)) { |
| 3016 | dev_info(DEV, "No resync, but %lu bits in bitmap!\n", |
| 3017 | drbd_bm_total_weight(mdev)); |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | return rv; |
| 3022 | } |
| 3023 | |
Philipp Reisner | f179d76 | 2011-05-16 17:31:47 +0200 | [diff] [blame] | 3024 | 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] | 3025 | { |
| 3026 | /* ASB_DISCARD_REMOTE - ASB_DISCARD_LOCAL is valid */ |
Philipp Reisner | f179d76 | 2011-05-16 17:31:47 +0200 | [diff] [blame] | 3027 | if (peer == ASB_DISCARD_REMOTE) |
| 3028 | return ASB_DISCARD_LOCAL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3029 | |
| 3030 | /* 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] | 3031 | if (peer == ASB_DISCARD_LOCAL) |
| 3032 | return ASB_DISCARD_REMOTE; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3033 | |
| 3034 | /* everything else is valid if they are equal on both sides. */ |
Philipp Reisner | f179d76 | 2011-05-16 17:31:47 +0200 | [diff] [blame] | 3035 | return peer; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3038 | static int receive_protocol(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3039 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3040 | struct p_protocol *p = pi->data; |
Philipp Reisner | 036b17e | 2011-05-16 17:38:11 +0200 | [diff] [blame] | 3041 | enum drbd_after_sb_p p_after_sb_0p, p_after_sb_1p, p_after_sb_2p; |
| 3042 | int p_proto, p_discard_my_data, p_two_primaries, cf; |
| 3043 | struct net_conf *nc, *old_net_conf, *new_net_conf = NULL; |
| 3044 | char integrity_alg[SHARED_SECRET_MAX] = ""; |
Andreas Gruenbacher | accdbcc | 2011-07-15 17:41:09 +0200 | [diff] [blame] | 3045 | struct crypto_hash *peer_integrity_tfm = NULL; |
Philipp Reisner | 7aca6c7 | 2011-05-17 10:12:56 +0200 | [diff] [blame] | 3046 | void *int_dig_in = NULL, *int_dig_vv = NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3047 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3048 | p_proto = be32_to_cpu(p->protocol); |
| 3049 | p_after_sb_0p = be32_to_cpu(p->after_sb_0p); |
| 3050 | p_after_sb_1p = be32_to_cpu(p->after_sb_1p); |
| 3051 | p_after_sb_2p = be32_to_cpu(p->after_sb_2p); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3052 | p_two_primaries = be32_to_cpu(p->two_primaries); |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 3053 | cf = be32_to_cpu(p->conn_flags); |
Andreas Gruenbacher | 6139f60 | 2011-05-06 20:00:02 +0200 | [diff] [blame] | 3054 | p_discard_my_data = cf & CF_DISCARD_MY_DATA; |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 3055 | |
Andreas Gruenbacher | 86db061 | 2011-04-28 15:24:18 +0200 | [diff] [blame] | 3056 | if (tconn->agreed_pro_version >= 87) { |
| 3057 | int err; |
| 3058 | |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 3059 | if (pi->size > sizeof(integrity_alg)) |
Andreas Gruenbacher | 86db061 | 2011-04-28 15:24:18 +0200 | [diff] [blame] | 3060 | return -EIO; |
Andreas Gruenbacher | 88104ca | 2011-04-28 21:47:21 +0200 | [diff] [blame] | 3061 | err = drbd_recv_all(tconn, integrity_alg, pi->size); |
Andreas Gruenbacher | 86db061 | 2011-04-28 15:24:18 +0200 | [diff] [blame] | 3062 | if (err) |
| 3063 | return err; |
Philipp Reisner | 036b17e | 2011-05-16 17:38:11 +0200 | [diff] [blame] | 3064 | integrity_alg[SHARED_SECRET_MAX - 1] = 0; |
| 3065 | } |
Andreas Gruenbacher | 86db061 | 2011-04-28 15:24:18 +0200 | [diff] [blame] | 3066 | |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3067 | if (pi->cmd != P_PROTOCOL_UPDATE) { |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3068 | clear_bit(CONN_DRY_RUN, &tconn->flags); |
Philipp Reisner | 036b17e | 2011-05-16 17:38:11 +0200 | [diff] [blame] | 3069 | |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3070 | if (cf & CF_DRY_RUN) |
| 3071 | set_bit(CONN_DRY_RUN, &tconn->flags); |
| 3072 | |
| 3073 | rcu_read_lock(); |
| 3074 | nc = rcu_dereference(tconn->net_conf); |
| 3075 | |
| 3076 | if (p_proto != nc->wire_protocol) { |
Andreas Gruenbacher | d505d9b | 2011-07-15 17:19:18 +0200 | [diff] [blame] | 3077 | conn_err(tconn, "incompatible %s settings\n", "protocol"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3078 | goto disconnect_rcu_unlock; |
| 3079 | } |
| 3080 | |
| 3081 | if (convert_after_sb(p_after_sb_0p) != nc->after_sb_0p) { |
Andreas Gruenbacher | d505d9b | 2011-07-15 17:19:18 +0200 | [diff] [blame] | 3082 | conn_err(tconn, "incompatible %s settings\n", "after-sb-0pri"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3083 | goto disconnect_rcu_unlock; |
| 3084 | } |
| 3085 | |
| 3086 | if (convert_after_sb(p_after_sb_1p) != nc->after_sb_1p) { |
Andreas Gruenbacher | d505d9b | 2011-07-15 17:19:18 +0200 | [diff] [blame] | 3087 | conn_err(tconn, "incompatible %s settings\n", "after-sb-1pri"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3088 | goto disconnect_rcu_unlock; |
| 3089 | } |
| 3090 | |
| 3091 | if (convert_after_sb(p_after_sb_2p) != nc->after_sb_2p) { |
Andreas Gruenbacher | d505d9b | 2011-07-15 17:19:18 +0200 | [diff] [blame] | 3092 | conn_err(tconn, "incompatible %s settings\n", "after-sb-2pri"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3093 | goto disconnect_rcu_unlock; |
| 3094 | } |
| 3095 | |
| 3096 | if (p_discard_my_data && nc->discard_my_data) { |
Andreas Gruenbacher | d505d9b | 2011-07-15 17:19:18 +0200 | [diff] [blame] | 3097 | conn_err(tconn, "incompatible %s settings\n", "discard-my-data"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3098 | goto disconnect_rcu_unlock; |
| 3099 | } |
| 3100 | |
| 3101 | if (p_two_primaries != nc->two_primaries) { |
Andreas Gruenbacher | d505d9b | 2011-07-15 17:19:18 +0200 | [diff] [blame] | 3102 | conn_err(tconn, "incompatible %s settings\n", "allow-two-primaries"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3103 | goto disconnect_rcu_unlock; |
| 3104 | } |
| 3105 | |
| 3106 | if (strcmp(integrity_alg, nc->integrity_alg)) { |
Andreas Gruenbacher | d505d9b | 2011-07-15 17:19:18 +0200 | [diff] [blame] | 3107 | conn_err(tconn, "incompatible %s settings\n", "data-integrity-alg"); |
Andreas Gruenbacher | fbc12f4 | 2011-07-15 17:04:26 +0200 | [diff] [blame] | 3108 | goto disconnect_rcu_unlock; |
| 3109 | } |
| 3110 | |
| 3111 | rcu_read_unlock(); |
Andreas Gruenbacher | 86db061 | 2011-04-28 15:24:18 +0200 | [diff] [blame] | 3112 | } |
Andreas Gruenbacher | 7d4c782 | 2011-07-17 23:06:12 +0200 | [diff] [blame] | 3113 | |
| 3114 | if (integrity_alg[0]) { |
| 3115 | int hash_size; |
| 3116 | |
| 3117 | /* |
| 3118 | * We can only change the peer data integrity algorithm |
| 3119 | * here. Changing our own data integrity algorithm |
| 3120 | * requires that we send a P_PROTOCOL_UPDATE packet at |
| 3121 | * the same time; otherwise, the peer has no way to |
| 3122 | * tell between which packets the algorithm should |
| 3123 | * change. |
| 3124 | */ |
| 3125 | |
| 3126 | peer_integrity_tfm = crypto_alloc_hash(integrity_alg, 0, CRYPTO_ALG_ASYNC); |
| 3127 | if (!peer_integrity_tfm) { |
| 3128 | conn_err(tconn, "peer data-integrity-alg %s not supported\n", |
| 3129 | integrity_alg); |
| 3130 | goto disconnect; |
| 3131 | } |
| 3132 | |
| 3133 | hash_size = crypto_hash_digestsize(peer_integrity_tfm); |
| 3134 | int_dig_in = kmalloc(hash_size, GFP_KERNEL); |
| 3135 | int_dig_vv = kmalloc(hash_size, GFP_KERNEL); |
| 3136 | if (!(int_dig_in && int_dig_vv)) { |
| 3137 | conn_err(tconn, "Allocation of buffers for data integrity checking failed\n"); |
| 3138 | goto disconnect; |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | new_net_conf = kmalloc(sizeof(struct net_conf), GFP_KERNEL); |
| 3143 | if (!new_net_conf) { |
| 3144 | conn_err(tconn, "Allocation of new net_conf failed\n"); |
| 3145 | goto disconnect; |
| 3146 | } |
| 3147 | |
| 3148 | mutex_lock(&tconn->data.mutex); |
| 3149 | mutex_lock(&tconn->conf_update); |
| 3150 | old_net_conf = tconn->net_conf; |
| 3151 | *new_net_conf = *old_net_conf; |
| 3152 | |
| 3153 | new_net_conf->wire_protocol = p_proto; |
| 3154 | new_net_conf->after_sb_0p = convert_after_sb(p_after_sb_0p); |
| 3155 | new_net_conf->after_sb_1p = convert_after_sb(p_after_sb_1p); |
| 3156 | new_net_conf->after_sb_2p = convert_after_sb(p_after_sb_2p); |
| 3157 | new_net_conf->two_primaries = p_two_primaries; |
| 3158 | |
| 3159 | rcu_assign_pointer(tconn->net_conf, new_net_conf); |
| 3160 | mutex_unlock(&tconn->conf_update); |
| 3161 | mutex_unlock(&tconn->data.mutex); |
| 3162 | |
| 3163 | crypto_free_hash(tconn->peer_integrity_tfm); |
| 3164 | kfree(tconn->int_dig_in); |
| 3165 | kfree(tconn->int_dig_vv); |
| 3166 | tconn->peer_integrity_tfm = peer_integrity_tfm; |
| 3167 | tconn->int_dig_in = int_dig_in; |
| 3168 | tconn->int_dig_vv = int_dig_vv; |
| 3169 | |
| 3170 | if (strcmp(old_net_conf->integrity_alg, integrity_alg)) |
| 3171 | conn_info(tconn, "peer data-integrity-alg: %s\n", |
| 3172 | integrity_alg[0] ? integrity_alg : "(none)"); |
| 3173 | |
| 3174 | synchronize_rcu(); |
| 3175 | kfree(old_net_conf); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3176 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3177 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 3178 | disconnect_rcu_unlock: |
| 3179 | rcu_read_unlock(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3180 | disconnect: |
Andreas Gruenbacher | b792c35 | 2011-07-15 16:48:49 +0200 | [diff] [blame] | 3181 | crypto_free_hash(peer_integrity_tfm); |
Philipp Reisner | 036b17e | 2011-05-16 17:38:11 +0200 | [diff] [blame] | 3182 | kfree(int_dig_in); |
| 3183 | kfree(int_dig_vv); |
Philipp Reisner | 7204624 | 2011-03-15 18:51:47 +0100 | [diff] [blame] | 3184 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3185 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | /* helper function |
| 3189 | * input: alg name, feature name |
| 3190 | * return: NULL (alg name was "") |
| 3191 | * ERR_PTR(error) if something goes wrong |
| 3192 | * or the crypto hash ptr, if it worked out ok. */ |
| 3193 | struct crypto_hash *drbd_crypto_alloc_digest_safe(const struct drbd_conf *mdev, |
| 3194 | const char *alg, const char *name) |
| 3195 | { |
| 3196 | struct crypto_hash *tfm; |
| 3197 | |
| 3198 | if (!alg[0]) |
| 3199 | return NULL; |
| 3200 | |
| 3201 | tfm = crypto_alloc_hash(alg, 0, CRYPTO_ALG_ASYNC); |
| 3202 | if (IS_ERR(tfm)) { |
| 3203 | dev_err(DEV, "Can not allocate \"%s\" as %s (reason: %ld)\n", |
| 3204 | alg, name, PTR_ERR(tfm)); |
| 3205 | return tfm; |
| 3206 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3207 | return tfm; |
| 3208 | } |
| 3209 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3210 | static int ignore_remaining_packet(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3211 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3212 | void *buffer = tconn->data.rbuf; |
| 3213 | int size = pi->size; |
| 3214 | |
| 3215 | while (size) { |
| 3216 | int s = min_t(int, size, DRBD_SOCKET_BUFFER_SIZE); |
| 3217 | s = drbd_recv(tconn, buffer, s); |
| 3218 | if (s <= 0) { |
| 3219 | if (s < 0) |
| 3220 | return s; |
| 3221 | break; |
| 3222 | } |
| 3223 | size -= s; |
| 3224 | } |
| 3225 | if (size) |
| 3226 | return -EIO; |
| 3227 | return 0; |
| 3228 | } |
| 3229 | |
| 3230 | /* |
| 3231 | * config_unknown_volume - device configuration command for unknown volume |
| 3232 | * |
| 3233 | * When a device is added to an existing connection, the node on which the |
| 3234 | * device is added first will send configuration commands to its peer but the |
| 3235 | * peer will not know about the device yet. It will warn and ignore these |
| 3236 | * commands. Once the device is added on the second node, the second node will |
| 3237 | * send the same device configuration commands, but in the other direction. |
| 3238 | * |
| 3239 | * (We can also end up here if drbd is misconfigured.) |
| 3240 | */ |
| 3241 | static int config_unknown_volume(struct drbd_tconn *tconn, struct packet_info *pi) |
| 3242 | { |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 3243 | conn_warn(tconn, "%s packet received for volume %u, which is not configured locally\n", |
| 3244 | cmdname(pi->cmd), pi->vnr); |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3245 | return ignore_remaining_packet(tconn, pi); |
| 3246 | } |
| 3247 | |
| 3248 | static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) |
| 3249 | { |
| 3250 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3251 | struct p_rs_param_95 *p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3252 | unsigned int header_size, data_size, exp_max_sz; |
| 3253 | struct crypto_hash *verify_tfm = NULL; |
| 3254 | struct crypto_hash *csums_tfm = NULL; |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3255 | struct net_conf *old_net_conf, *new_net_conf = NULL; |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3256 | struct disk_conf *old_disk_conf = NULL, *new_disk_conf = NULL; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3257 | const int apv = tconn->agreed_pro_version; |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3258 | struct fifo_buffer *old_plan = NULL, *new_plan = NULL; |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 3259 | int fifo_size = 0; |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3260 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3261 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3262 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 3263 | if (!mdev) |
| 3264 | return config_unknown_volume(tconn, pi); |
| 3265 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3266 | exp_max_sz = apv <= 87 ? sizeof(struct p_rs_param) |
| 3267 | : apv == 88 ? sizeof(struct p_rs_param) |
| 3268 | + SHARED_SECRET_MAX |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3269 | : apv <= 94 ? sizeof(struct p_rs_param_89) |
| 3270 | : /* apv >= 95 */ sizeof(struct p_rs_param_95); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3271 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3272 | if (pi->size > exp_max_sz) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3273 | dev_err(DEV, "SyncParam packet too long: received %u, expected <= %u bytes\n", |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3274 | pi->size, exp_max_sz); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3275 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | if (apv <= 88) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3279 | header_size = sizeof(struct p_rs_param); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3280 | data_size = pi->size - header_size; |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3281 | } else if (apv <= 94) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3282 | header_size = sizeof(struct p_rs_param_89); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3283 | data_size = pi->size - header_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3284 | D_ASSERT(data_size == 0); |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3285 | } else { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3286 | header_size = sizeof(struct p_rs_param_95); |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3287 | data_size = pi->size - header_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3288 | D_ASSERT(data_size == 0); |
| 3289 | } |
| 3290 | |
| 3291 | /* initialize verify_alg and csums_alg */ |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3292 | p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3293 | memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); |
| 3294 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3295 | err = drbd_recv_all(mdev->tconn, p, header_size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3296 | if (err) |
| 3297 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3298 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3299 | mutex_lock(&mdev->tconn->conf_update); |
| 3300 | old_net_conf = mdev->tconn->net_conf; |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3301 | if (get_ldev(mdev)) { |
| 3302 | new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL); |
| 3303 | if (!new_disk_conf) { |
| 3304 | put_ldev(mdev); |
| 3305 | mutex_unlock(&mdev->tconn->conf_update); |
| 3306 | dev_err(DEV, "Allocation of new disk_conf failed\n"); |
| 3307 | return -ENOMEM; |
| 3308 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3309 | |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3310 | old_disk_conf = mdev->ldev->disk_conf; |
| 3311 | *new_disk_conf = *old_disk_conf; |
| 3312 | |
Andreas Gruenbacher | 6394b93 | 2011-05-11 14:29:52 +0200 | [diff] [blame] | 3313 | new_disk_conf->resync_rate = be32_to_cpu(p->resync_rate); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3314 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3315 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3316 | if (apv >= 88) { |
| 3317 | if (apv == 88) { |
Philipp Reisner | e4bad1b | 2012-04-06 12:08:51 +0200 | [diff] [blame] | 3318 | if (data_size > SHARED_SECRET_MAX || data_size == 0) { |
| 3319 | dev_err(DEV, "verify-alg of wrong size, " |
| 3320 | "peer wants %u, accepting only up to %u byte\n", |
| 3321 | data_size, SHARED_SECRET_MAX); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3322 | err = -EIO; |
| 3323 | goto reconnect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3324 | } |
| 3325 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3326 | err = drbd_recv_all(mdev->tconn, p->verify_alg, data_size); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3327 | if (err) |
| 3328 | goto reconnect; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3329 | /* we expect NUL terminated string */ |
| 3330 | /* but just in case someone tries to be evil */ |
| 3331 | D_ASSERT(p->verify_alg[data_size-1] == 0); |
| 3332 | p->verify_alg[data_size-1] = 0; |
| 3333 | |
| 3334 | } else /* apv >= 89 */ { |
| 3335 | /* we still expect NUL terminated strings */ |
| 3336 | /* but just in case someone tries to be evil */ |
| 3337 | D_ASSERT(p->verify_alg[SHARED_SECRET_MAX-1] == 0); |
| 3338 | D_ASSERT(p->csums_alg[SHARED_SECRET_MAX-1] == 0); |
| 3339 | p->verify_alg[SHARED_SECRET_MAX-1] = 0; |
| 3340 | p->csums_alg[SHARED_SECRET_MAX-1] = 0; |
| 3341 | } |
| 3342 | |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3343 | if (strcmp(old_net_conf->verify_alg, p->verify_alg)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3344 | if (mdev->state.conn == C_WF_REPORT_PARAMS) { |
| 3345 | dev_err(DEV, "Different verify-alg settings. me=\"%s\" peer=\"%s\"\n", |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3346 | old_net_conf->verify_alg, p->verify_alg); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3347 | goto disconnect; |
| 3348 | } |
| 3349 | verify_tfm = drbd_crypto_alloc_digest_safe(mdev, |
| 3350 | p->verify_alg, "verify-alg"); |
| 3351 | if (IS_ERR(verify_tfm)) { |
| 3352 | verify_tfm = NULL; |
| 3353 | goto disconnect; |
| 3354 | } |
| 3355 | } |
| 3356 | |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3357 | if (apv >= 89 && strcmp(old_net_conf->csums_alg, p->csums_alg)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3358 | if (mdev->state.conn == C_WF_REPORT_PARAMS) { |
| 3359 | dev_err(DEV, "Different csums-alg settings. me=\"%s\" peer=\"%s\"\n", |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3360 | old_net_conf->csums_alg, p->csums_alg); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3361 | goto disconnect; |
| 3362 | } |
| 3363 | csums_tfm = drbd_crypto_alloc_digest_safe(mdev, |
| 3364 | p->csums_alg, "csums-alg"); |
| 3365 | if (IS_ERR(csums_tfm)) { |
| 3366 | csums_tfm = NULL; |
| 3367 | goto disconnect; |
| 3368 | } |
| 3369 | } |
| 3370 | |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3371 | if (apv > 94 && new_disk_conf) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3372 | new_disk_conf->c_plan_ahead = be32_to_cpu(p->c_plan_ahead); |
| 3373 | new_disk_conf->c_delay_target = be32_to_cpu(p->c_delay_target); |
| 3374 | new_disk_conf->c_fill_target = be32_to_cpu(p->c_fill_target); |
| 3375 | 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] | 3376 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3377 | fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ; |
Philipp Reisner | 9958c85 | 2011-05-03 16:19:31 +0200 | [diff] [blame] | 3378 | if (fifo_size != mdev->rs_plan_s->size) { |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3379 | new_plan = fifo_alloc(fifo_size); |
| 3380 | if (!new_plan) { |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 3381 | dev_err(DEV, "kmalloc of fifo_buffer failed"); |
Lars Ellenberg | f399002 | 2011-03-23 14:31:09 +0100 | [diff] [blame] | 3382 | put_ldev(mdev); |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 3383 | goto disconnect; |
| 3384 | } |
| 3385 | } |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3386 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3387 | |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3388 | if (verify_tfm || csums_tfm) { |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3389 | new_net_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL); |
| 3390 | if (!new_net_conf) { |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3391 | dev_err(DEV, "Allocation of new net_conf failed\n"); |
| 3392 | goto disconnect; |
| 3393 | } |
| 3394 | |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3395 | *new_net_conf = *old_net_conf; |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3396 | |
| 3397 | if (verify_tfm) { |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3398 | strcpy(new_net_conf->verify_alg, p->verify_alg); |
| 3399 | new_net_conf->verify_alg_len = strlen(p->verify_alg) + 1; |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3400 | crypto_free_hash(mdev->tconn->verify_tfm); |
| 3401 | mdev->tconn->verify_tfm = verify_tfm; |
| 3402 | dev_info(DEV, "using verify-alg: \"%s\"\n", p->verify_alg); |
| 3403 | } |
| 3404 | if (csums_tfm) { |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3405 | strcpy(new_net_conf->csums_alg, p->csums_alg); |
| 3406 | new_net_conf->csums_alg_len = strlen(p->csums_alg) + 1; |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3407 | crypto_free_hash(mdev->tconn->csums_tfm); |
| 3408 | mdev->tconn->csums_tfm = csums_tfm; |
| 3409 | dev_info(DEV, "using csums-alg: \"%s\"\n", p->csums_alg); |
| 3410 | } |
Philipp Reisner | 2ec91e0 | 2011-05-03 14:58:00 +0200 | [diff] [blame] | 3411 | rcu_assign_pointer(tconn->net_conf, new_net_conf); |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 3412 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3413 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3414 | |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3415 | if (new_disk_conf) { |
| 3416 | rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf); |
| 3417 | put_ldev(mdev); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3418 | } |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3419 | |
| 3420 | if (new_plan) { |
| 3421 | old_plan = mdev->rs_plan_s; |
| 3422 | rcu_assign_pointer(mdev->rs_plan_s, new_plan); |
| 3423 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3424 | |
| 3425 | mutex_unlock(&mdev->tconn->conf_update); |
| 3426 | synchronize_rcu(); |
| 3427 | if (new_net_conf) |
| 3428 | kfree(old_net_conf); |
| 3429 | kfree(old_disk_conf); |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3430 | kfree(old_plan); |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3431 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3432 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3433 | |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3434 | reconnect: |
| 3435 | if (new_disk_conf) { |
| 3436 | put_ldev(mdev); |
| 3437 | kfree(new_disk_conf); |
| 3438 | } |
| 3439 | mutex_unlock(&mdev->tconn->conf_update); |
| 3440 | return -EIO; |
| 3441 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3442 | disconnect: |
Philipp Reisner | 813472c | 2011-05-03 16:47:02 +0200 | [diff] [blame] | 3443 | kfree(new_plan); |
| 3444 | if (new_disk_conf) { |
| 3445 | put_ldev(mdev); |
| 3446 | kfree(new_disk_conf); |
| 3447 | } |
Philipp Reisner | a009550 | 2011-05-03 13:14:15 +0200 | [diff] [blame] | 3448 | mutex_unlock(&mdev->tconn->conf_update); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3449 | /* just for completeness: actually not needed, |
| 3450 | * as this is not reached if csums_tfm was ok. */ |
| 3451 | crypto_free_hash(csums_tfm); |
| 3452 | /* but free the verify_tfm again, if csums_tfm did not work out */ |
| 3453 | crypto_free_hash(verify_tfm); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3454 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3455 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3458 | /* warn if the arguments differ by more than 12.5% */ |
| 3459 | static void warn_if_differ_considerably(struct drbd_conf *mdev, |
| 3460 | const char *s, sector_t a, sector_t b) |
| 3461 | { |
| 3462 | sector_t d; |
| 3463 | if (a == 0 || b == 0) |
| 3464 | return; |
| 3465 | d = (a > b) ? (a - b) : (b - a); |
| 3466 | if (d > (a>>3) || d > (b>>3)) |
| 3467 | dev_warn(DEV, "Considerable difference in %s: %llus vs. %llus\n", s, |
| 3468 | (unsigned long long)a, (unsigned long long)b); |
| 3469 | } |
| 3470 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3471 | static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3472 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3473 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3474 | struct p_sizes *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3475 | enum determine_dev_size dd = unchanged; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3476 | sector_t p_size, p_usize, my_usize; |
| 3477 | int ldsc = 0; /* local disk size changed */ |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3478 | enum dds_flags ddsf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3479 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3480 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 3481 | if (!mdev) |
| 3482 | return config_unknown_volume(tconn, pi); |
| 3483 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3484 | p_size = be64_to_cpu(p->d_size); |
| 3485 | p_usize = be64_to_cpu(p->u_size); |
| 3486 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3487 | /* just store the peer's disk size for now. |
| 3488 | * we still need to figure out whether we accept that. */ |
| 3489 | mdev->p_size = p_size; |
| 3490 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3491 | if (get_ldev(mdev)) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3492 | rcu_read_lock(); |
| 3493 | my_usize = rcu_dereference(mdev->ldev->disk_conf)->disk_size; |
| 3494 | rcu_read_unlock(); |
| 3495 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3496 | warn_if_differ_considerably(mdev, "lower level device sizes", |
| 3497 | p_size, drbd_get_max_capacity(mdev->ldev)); |
| 3498 | warn_if_differ_considerably(mdev, "user requested size", |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3499 | p_usize, my_usize); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3500 | |
| 3501 | /* if this is the first connect, or an otherwise expected |
| 3502 | * param exchange, choose the minimum */ |
| 3503 | if (mdev->state.conn == C_WF_REPORT_PARAMS) |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3504 | p_usize = min_not_zero(my_usize, p_usize); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3505 | |
| 3506 | /* Never shrink a device with usable data during connect. |
| 3507 | But allow online shrinking if we are connected. */ |
Philipp Reisner | ef5e44a | 2011-05-03 13:27:43 +0200 | [diff] [blame] | 3508 | if (drbd_new_dev_size(mdev, mdev->ldev, p_usize, 0) < |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3509 | drbd_get_capacity(mdev->this_bdev) && |
| 3510 | mdev->state.disk >= D_OUTDATED && |
| 3511 | mdev->state.conn < C_CONNECTED) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3512 | dev_err(DEV, "The peer's disk size is too small!\n"); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3513 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3514 | put_ldev(mdev); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3515 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3516 | } |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 3517 | |
| 3518 | if (my_usize != p_usize) { |
| 3519 | struct disk_conf *old_disk_conf, *new_disk_conf = NULL; |
| 3520 | |
| 3521 | new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL); |
| 3522 | if (!new_disk_conf) { |
| 3523 | dev_err(DEV, "Allocation of new disk_conf failed\n"); |
| 3524 | put_ldev(mdev); |
| 3525 | return -ENOMEM; |
| 3526 | } |
| 3527 | |
| 3528 | mutex_lock(&mdev->tconn->conf_update); |
| 3529 | old_disk_conf = mdev->ldev->disk_conf; |
| 3530 | *new_disk_conf = *old_disk_conf; |
| 3531 | new_disk_conf->disk_size = p_usize; |
| 3532 | |
| 3533 | rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf); |
| 3534 | mutex_unlock(&mdev->tconn->conf_update); |
| 3535 | synchronize_rcu(); |
| 3536 | kfree(old_disk_conf); |
| 3537 | |
| 3538 | dev_info(DEV, "Peer sets u_size to %lu sectors\n", |
| 3539 | (unsigned long)my_usize); |
| 3540 | } |
| 3541 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3542 | put_ldev(mdev); |
| 3543 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3544 | |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3545 | ddsf = be16_to_cpu(p->dds_flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3546 | if (get_ldev(mdev)) { |
Bart Van Assche | 24c4830 | 2011-05-21 18:32:29 +0200 | [diff] [blame] | 3547 | dd = drbd_determine_dev_size(mdev, ddsf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3548 | put_ldev(mdev); |
| 3549 | if (dd == dev_size_error) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3550 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3551 | drbd_md_sync(mdev); |
| 3552 | } else { |
| 3553 | /* I am diskless, need to accept the peer's size. */ |
| 3554 | drbd_set_my_capacity(mdev, p_size); |
| 3555 | } |
| 3556 | |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 3557 | mdev->peer_max_bio_size = be32_to_cpu(p->max_bio_size); |
| 3558 | drbd_reconsider_max_bio_size(mdev); |
| 3559 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3560 | if (get_ldev(mdev)) { |
| 3561 | if (mdev->ldev->known_size != drbd_get_capacity(mdev->ldev->backing_bdev)) { |
| 3562 | mdev->ldev->known_size = drbd_get_capacity(mdev->ldev->backing_bdev); |
| 3563 | ldsc = 1; |
| 3564 | } |
| 3565 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3566 | put_ldev(mdev); |
| 3567 | } |
| 3568 | |
| 3569 | if (mdev->state.conn > C_WF_REPORT_PARAMS) { |
| 3570 | if (be64_to_cpu(p->c_size) != |
| 3571 | drbd_get_capacity(mdev->this_bdev) || ldsc) { |
| 3572 | /* we have different sizes, probably peer |
| 3573 | * needs to know my new size... */ |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3574 | drbd_send_sizes(mdev, 0, ddsf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3575 | } |
| 3576 | if (test_and_clear_bit(RESIZE_PENDING, &mdev->flags) || |
| 3577 | (dd == grew && mdev->state.conn == C_CONNECTED)) { |
| 3578 | if (mdev->state.pdsk >= D_INCONSISTENT && |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3579 | mdev->state.disk >= D_INCONSISTENT) { |
| 3580 | if (ddsf & DDSF_NO_RESYNC) |
| 3581 | dev_info(DEV, "Resync of new storage suppressed with --assume-clean\n"); |
| 3582 | else |
| 3583 | resync_after_online_grow(mdev); |
| 3584 | } else |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3585 | set_bit(RESYNC_AFTER_NEG, &mdev->flags); |
| 3586 | } |
| 3587 | } |
| 3588 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3589 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3592 | static int receive_uuids(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3593 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3594 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3595 | struct p_uuids *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3596 | u64 *p_uuid; |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3597 | int i, updated_uuids = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3598 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3599 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 3600 | if (!mdev) |
| 3601 | return config_unknown_volume(tconn, pi); |
| 3602 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3603 | p_uuid = kmalloc(sizeof(u64)*UI_EXTENDED_SIZE, GFP_NOIO); |
| 3604 | |
| 3605 | for (i = UI_CURRENT; i < UI_EXTENDED_SIZE; i++) |
| 3606 | p_uuid[i] = be64_to_cpu(p->uuid[i]); |
| 3607 | |
| 3608 | kfree(mdev->p_uuid); |
| 3609 | mdev->p_uuid = p_uuid; |
| 3610 | |
| 3611 | if (mdev->state.conn < C_CONNECTED && |
| 3612 | mdev->state.disk < D_INCONSISTENT && |
| 3613 | mdev->state.role == R_PRIMARY && |
| 3614 | (mdev->ed_uuid & ~((u64)1)) != (p_uuid[UI_CURRENT] & ~((u64)1))) { |
| 3615 | dev_err(DEV, "Can only connect to data with current UUID=%016llX\n", |
| 3616 | (unsigned long long)mdev->ed_uuid); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3617 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3618 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | if (get_ldev(mdev)) { |
| 3622 | int skip_initial_sync = |
| 3623 | mdev->state.conn == C_CONNECTED && |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 3624 | mdev->tconn->agreed_pro_version >= 90 && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3625 | mdev->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && |
| 3626 | (p_uuid[UI_FLAGS] & 8); |
| 3627 | if (skip_initial_sync) { |
| 3628 | dev_info(DEV, "Accepted new current UUID, preparing to skip initial sync\n"); |
| 3629 | drbd_bitmap_io(mdev, &drbd_bmio_clear_n_write, |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 3630 | "clear_n_write from receive_uuids", |
| 3631 | BM_LOCKED_TEST_ALLOWED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3632 | _drbd_uuid_set(mdev, UI_CURRENT, p_uuid[UI_CURRENT]); |
| 3633 | _drbd_uuid_set(mdev, UI_BITMAP, 0); |
| 3634 | _drbd_set_state(_NS2(mdev, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE), |
| 3635 | CS_VERBOSE, NULL); |
| 3636 | drbd_md_sync(mdev); |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3637 | updated_uuids = 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3638 | } |
| 3639 | put_ldev(mdev); |
Philipp Reisner | 18a50fa | 2010-06-21 14:14:15 +0200 | [diff] [blame] | 3640 | } else if (mdev->state.disk < D_INCONSISTENT && |
| 3641 | mdev->state.role == R_PRIMARY) { |
| 3642 | /* I am a diskless primary, the peer just created a new current UUID |
| 3643 | for me. */ |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3644 | updated_uuids = drbd_set_ed_uuid(mdev, p_uuid[UI_CURRENT]); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | /* Before we test for the disk state, we should wait until an eventually |
| 3648 | ongoing cluster wide state change is finished. That is important if |
| 3649 | we are primary and are detaching from our disk. We need to see the |
| 3650 | new disk state... */ |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 3651 | mutex_lock(mdev->state_mutex); |
| 3652 | mutex_unlock(mdev->state_mutex); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3653 | if (mdev->state.conn >= C_CONNECTED && mdev->state.disk < D_INCONSISTENT) |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3654 | updated_uuids |= drbd_set_ed_uuid(mdev, p_uuid[UI_CURRENT]); |
| 3655 | |
| 3656 | if (updated_uuids) |
| 3657 | drbd_print_uuids(mdev, "receiver updated UUIDs to"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3658 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3659 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | /** |
| 3663 | * convert_state() - Converts the peer's view of the cluster state to our point of view |
| 3664 | * @ps: The state as seen by the peer. |
| 3665 | */ |
| 3666 | static union drbd_state convert_state(union drbd_state ps) |
| 3667 | { |
| 3668 | union drbd_state ms; |
| 3669 | |
| 3670 | static enum drbd_conns c_tab[] = { |
Philipp Reisner | 369bea6 | 2011-07-06 23:04:44 +0200 | [diff] [blame] | 3671 | [C_WF_REPORT_PARAMS] = C_WF_REPORT_PARAMS, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3672 | [C_CONNECTED] = C_CONNECTED, |
| 3673 | |
| 3674 | [C_STARTING_SYNC_S] = C_STARTING_SYNC_T, |
| 3675 | [C_STARTING_SYNC_T] = C_STARTING_SYNC_S, |
| 3676 | [C_DISCONNECTING] = C_TEAR_DOWN, /* C_NETWORK_FAILURE, */ |
| 3677 | [C_VERIFY_S] = C_VERIFY_T, |
| 3678 | [C_MASK] = C_MASK, |
| 3679 | }; |
| 3680 | |
| 3681 | ms.i = ps.i; |
| 3682 | |
| 3683 | ms.conn = c_tab[ps.conn]; |
| 3684 | ms.peer = ps.role; |
| 3685 | ms.role = ps.peer; |
| 3686 | ms.pdsk = ps.disk; |
| 3687 | ms.disk = ps.pdsk; |
| 3688 | ms.peer_isp = (ps.aftr_isp | ps.user_isp); |
| 3689 | |
| 3690 | return ms; |
| 3691 | } |
| 3692 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3693 | static int receive_req_state(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3694 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3695 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3696 | struct p_req_state *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3697 | union drbd_state mask, val; |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 3698 | enum drbd_state_rv rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3699 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3700 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 3701 | if (!mdev) |
| 3702 | return -EIO; |
| 3703 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3704 | mask.i = be32_to_cpu(p->mask); |
| 3705 | val.i = be32_to_cpu(p->val); |
| 3706 | |
Philipp Reisner | 25703f8 | 2011-02-07 14:35:25 +0100 | [diff] [blame] | 3707 | if (test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags) && |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 3708 | mutex_is_locked(mdev->state_mutex)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3709 | drbd_send_sr_reply(mdev, SS_CONCURRENT_ST_CHG); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3710 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | mask = convert_state(mask); |
| 3714 | val = convert_state(val); |
| 3715 | |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 3716 | rv = drbd_change_state(mdev, CS_VERBOSE, mask, val); |
| 3717 | drbd_send_sr_reply(mdev, rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3718 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3719 | drbd_md_sync(mdev); |
| 3720 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3721 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 3724 | static int receive_req_conn_state(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 3725 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3726 | struct p_req_state *p = pi->data; |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 3727 | union drbd_state mask, val; |
| 3728 | enum drbd_state_rv rv; |
| 3729 | |
| 3730 | mask.i = be32_to_cpu(p->mask); |
| 3731 | val.i = be32_to_cpu(p->val); |
| 3732 | |
| 3733 | if (test_bit(DISCARD_CONCURRENT, &tconn->flags) && |
| 3734 | mutex_is_locked(&tconn->cstate_mutex)) { |
| 3735 | conn_send_sr_reply(tconn, SS_CONCURRENT_ST_CHG); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3736 | return 0; |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | mask = convert_state(mask); |
| 3740 | val = convert_state(val); |
| 3741 | |
Philipp Reisner | 778bcf2 | 2011-03-28 12:55:03 +0200 | [diff] [blame] | 3742 | rv = conn_request_state(tconn, mask, val, CS_VERBOSE | CS_LOCAL_ONLY | CS_IGN_OUTD_FAIL); |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 3743 | conn_send_sr_reply(tconn, rv); |
| 3744 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3745 | return 0; |
Philipp Reisner | dfafcc8 | 2011-03-16 10:55:07 +0100 | [diff] [blame] | 3746 | } |
| 3747 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3748 | static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3749 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3750 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3751 | struct p_state *p = pi->data; |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3752 | union drbd_state os, ns, peer_state; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3753 | enum drbd_disk_state real_peer_disk; |
Philipp Reisner | 65d922c | 2010-06-16 16:18:09 +0200 | [diff] [blame] | 3754 | enum chg_state_flags cs_flags; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3755 | int rv; |
| 3756 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3757 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 3758 | if (!mdev) |
| 3759 | return config_unknown_volume(tconn, pi); |
| 3760 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3761 | peer_state.i = be32_to_cpu(p->state); |
| 3762 | |
| 3763 | real_peer_disk = peer_state.disk; |
| 3764 | if (peer_state.disk == D_NEGOTIATING) { |
| 3765 | real_peer_disk = mdev->p_uuid[UI_FLAGS] & 4 ? D_INCONSISTENT : D_CONSISTENT; |
| 3766 | dev_info(DEV, "real peer disk state = %s\n", drbd_disk_str(real_peer_disk)); |
| 3767 | } |
| 3768 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3769 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3770 | retry: |
Philipp Reisner | 78bae59 | 2011-03-28 15:40:12 +0200 | [diff] [blame] | 3771 | os = ns = drbd_read_state(mdev); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3772 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3773 | |
Philipp Reisner | b8853db | 2011-12-13 11:09:16 +0100 | [diff] [blame] | 3774 | /* If some other part of the code (asender thread, timeout) |
| 3775 | * already decided to close the connection again, |
| 3776 | * we must not "re-establish" it here. */ |
| 3777 | if (os.conn <= C_TEAR_DOWN) |
| 3778 | return false; |
| 3779 | |
Philipp Reisner | 9bcd252 | 2011-09-29 13:00:14 +0200 | [diff] [blame] | 3780 | /* If this is the "end of sync" confirmation, usually the peer disk |
| 3781 | * transitions from D_INCONSISTENT to D_UP_TO_DATE. For empty (0 bits |
| 3782 | * set) resync started in PausedSyncT, or if the timing of pause-/ |
| 3783 | * unpause-sync events has been "just right", the peer disk may |
| 3784 | * transition from D_CONSISTENT to D_UP_TO_DATE as well. |
| 3785 | */ |
| 3786 | if ((os.pdsk == D_INCONSISTENT || os.pdsk == D_CONSISTENT) && |
| 3787 | real_peer_disk == D_UP_TO_DATE && |
Lars Ellenberg | e9ef7bb | 2010-10-07 15:55:39 +0200 | [diff] [blame] | 3788 | os.conn > C_CONNECTED && os.disk == D_UP_TO_DATE) { |
| 3789 | /* If we are (becoming) SyncSource, but peer is still in sync |
| 3790 | * preparation, ignore its uptodate-ness to avoid flapping, it |
| 3791 | * will change to inconsistent once the peer reaches active |
| 3792 | * syncing states. |
| 3793 | * It may have changed syncer-paused flags, however, so we |
| 3794 | * cannot ignore this completely. */ |
| 3795 | if (peer_state.conn > C_CONNECTED && |
| 3796 | peer_state.conn < C_SYNC_SOURCE) |
| 3797 | real_peer_disk = D_INCONSISTENT; |
| 3798 | |
| 3799 | /* if peer_state changes to connected at the same time, |
| 3800 | * it explicitly notifies us that it finished resync. |
| 3801 | * Maybe we should finish it up, too? */ |
| 3802 | else if (os.conn >= C_SYNC_SOURCE && |
| 3803 | peer_state.conn == C_CONNECTED) { |
| 3804 | if (drbd_bm_total_weight(mdev) <= mdev->rs_failed) |
| 3805 | drbd_resync_finished(mdev); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3806 | return 0; |
Lars Ellenberg | e9ef7bb | 2010-10-07 15:55:39 +0200 | [diff] [blame] | 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | /* peer says his disk is inconsistent, while we think it is uptodate, |
| 3811 | * and this happens while the peer still thinks we have a sync going on, |
| 3812 | * but we think we are already done with the sync. |
| 3813 | * We ignore this to avoid flapping pdsk. |
| 3814 | * This should not happen, if the peer is a recent version of drbd. */ |
| 3815 | if (os.pdsk == D_UP_TO_DATE && real_peer_disk == D_INCONSISTENT && |
| 3816 | os.conn == C_CONNECTED && peer_state.conn > C_SYNC_SOURCE) |
| 3817 | real_peer_disk = D_UP_TO_DATE; |
| 3818 | |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3819 | if (ns.conn == C_WF_REPORT_PARAMS) |
| 3820 | ns.conn = C_CONNECTED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3821 | |
Philipp Reisner | 6753171 | 2010-10-27 12:21:30 +0200 | [diff] [blame] | 3822 | if (peer_state.conn == C_AHEAD) |
| 3823 | ns.conn = C_BEHIND; |
| 3824 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3825 | if (mdev->p_uuid && peer_state.disk >= D_NEGOTIATING && |
| 3826 | get_ldev_if_state(mdev, D_NEGOTIATING)) { |
| 3827 | int cr; /* consider resync */ |
| 3828 | |
| 3829 | /* if we established a new connection */ |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3830 | cr = (os.conn < C_CONNECTED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3831 | /* if we had an established connection |
| 3832 | * and one of the nodes newly attaches a disk */ |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3833 | cr |= (os.conn == C_CONNECTED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3834 | (peer_state.disk == D_NEGOTIATING || |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3835 | os.disk == D_NEGOTIATING)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3836 | /* if we have both been inconsistent, and the peer has been |
| 3837 | * forced to be UpToDate with --overwrite-data */ |
| 3838 | cr |= test_bit(CONSIDER_RESYNC, &mdev->flags); |
| 3839 | /* if we had been plain connected, and the admin requested to |
| 3840 | * start a sync by "invalidate" or "invalidate-remote" */ |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3841 | cr |= (os.conn == C_CONNECTED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3842 | (peer_state.conn >= C_STARTING_SYNC_S && |
| 3843 | peer_state.conn <= C_WF_BITMAP_T)); |
| 3844 | |
| 3845 | if (cr) |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3846 | ns.conn = drbd_sync_handshake(mdev, peer_state.role, real_peer_disk); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3847 | |
| 3848 | put_ldev(mdev); |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3849 | if (ns.conn == C_MASK) { |
| 3850 | ns.conn = C_CONNECTED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3851 | if (mdev->state.disk == D_NEGOTIATING) { |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 3852 | drbd_force_state(mdev, NS(disk, D_FAILED)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3853 | } else if (peer_state.disk == D_NEGOTIATING) { |
| 3854 | dev_err(DEV, "Disk attach process on the peer node was aborted.\n"); |
| 3855 | peer_state.disk = D_DISKLESS; |
Lars Ellenberg | 580b976 | 2010-02-26 23:15:23 +0100 | [diff] [blame] | 3856 | real_peer_disk = D_DISKLESS; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3857 | } else { |
Philipp Reisner | 8169e41 | 2011-03-15 18:40:27 +0100 | [diff] [blame] | 3858 | if (test_and_clear_bit(CONN_DRY_RUN, &mdev->tconn->flags)) |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3859 | return -EIO; |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3860 | D_ASSERT(os.conn == C_WF_REPORT_PARAMS); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3861 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3862 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3863 | } |
| 3864 | } |
| 3865 | } |
| 3866 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3867 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | 78bae59 | 2011-03-28 15:40:12 +0200 | [diff] [blame] | 3868 | if (os.i != drbd_read_state(mdev).i) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3869 | goto retry; |
| 3870 | clear_bit(CONSIDER_RESYNC, &mdev->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3871 | ns.peer = peer_state.role; |
| 3872 | ns.pdsk = real_peer_disk; |
| 3873 | ns.peer_isp = (peer_state.aftr_isp | peer_state.user_isp); |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3874 | if ((ns.conn == C_CONNECTED || ns.conn == C_WF_BITMAP_S) && ns.disk == D_NEGOTIATING) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3875 | ns.disk = mdev->new_state_tmp.disk; |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3876 | cs_flags = CS_VERBOSE + (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED ? 0 : CS_HARD); |
Philipp Reisner | 2aebfab | 2011-03-28 16:48:11 +0200 | [diff] [blame] | 3877 | if (ns.pdsk == D_CONSISTENT && drbd_suspended(mdev) && ns.conn == C_CONNECTED && os.conn < C_CONNECTED && |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 3878 | test_bit(NEW_CUR_UUID, &mdev->flags)) { |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 3879 | /* 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] | 3880 | for temporal network outages! */ |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3881 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 3882 | dev_err(DEV, "Aborting Connect, can not thaw IO with an only Consistent peer\n"); |
Philipp Reisner | 2f5cdd0 | 2011-02-21 14:29:27 +0100 | [diff] [blame] | 3883 | tl_clear(mdev->tconn); |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 3884 | drbd_uuid_new_current(mdev); |
| 3885 | clear_bit(NEW_CUR_UUID, &mdev->flags); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3886 | conn_request_state(mdev->tconn, NS2(conn, C_PROTOCOL_ERROR, susp, 0), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3887 | return -EIO; |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 3888 | } |
Philipp Reisner | 65d922c | 2010-06-16 16:18:09 +0200 | [diff] [blame] | 3889 | rv = _drbd_set_state(mdev, ns, cs_flags, NULL); |
Philipp Reisner | 78bae59 | 2011-03-28 15:40:12 +0200 | [diff] [blame] | 3890 | ns = drbd_read_state(mdev); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3891 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3892 | |
| 3893 | if (rv < SS_SUCCESS) { |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3894 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3895 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3896 | } |
| 3897 | |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3898 | if (os.conn > C_WF_REPORT_PARAMS) { |
| 3899 | if (ns.conn > C_CONNECTED && peer_state.conn <= C_CONNECTED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3900 | peer_state.disk != D_NEGOTIATING ) { |
| 3901 | /* we want resync, peer has not yet decided to sync... */ |
| 3902 | /* Nowadays only used when forcing a node into primary role and |
| 3903 | setting its disk to UpToDate with that */ |
| 3904 | drbd_send_uuids(mdev); |
Philipp Reisner | 43de7c8 | 2011-11-10 13:16:13 +0100 | [diff] [blame] | 3905 | drbd_send_current_state(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | |
Philipp Reisner | 08b165b | 2011-09-05 16:22:33 +0200 | [diff] [blame] | 3909 | clear_bit(DISCARD_MY_DATA, &mdev->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3910 | |
| 3911 | drbd_md_sync(mdev); /* update connected indicator, la_size, ... */ |
| 3912 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3913 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3914 | } |
| 3915 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3916 | static int receive_sync_uuid(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3917 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3918 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3919 | struct p_rs_uuid *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 3920 | |
| 3921 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 3922 | if (!mdev) |
| 3923 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3924 | |
| 3925 | wait_event(mdev->misc_wait, |
| 3926 | mdev->state.conn == C_WF_SYNC_UUID || |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 3927 | mdev->state.conn == C_BEHIND || |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3928 | mdev->state.conn < C_CONNECTED || |
| 3929 | mdev->state.disk < D_NEGOTIATING); |
| 3930 | |
| 3931 | /* D_ASSERT( mdev->state.conn == C_WF_SYNC_UUID ); */ |
| 3932 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3933 | /* Here the _drbd_uuid_ functions are right, current should |
| 3934 | _not_ be rotated into the history */ |
| 3935 | if (get_ldev_if_state(mdev, D_NEGOTIATING)) { |
| 3936 | _drbd_uuid_set(mdev, UI_CURRENT, be64_to_cpu(p->uuid)); |
| 3937 | _drbd_uuid_set(mdev, UI_BITMAP, 0UL); |
| 3938 | |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3939 | drbd_print_uuids(mdev, "updated sync uuid"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3940 | drbd_start_resync(mdev, C_SYNC_TARGET); |
| 3941 | |
| 3942 | put_ldev(mdev); |
| 3943 | } else |
| 3944 | dev_err(DEV, "Ignoring SyncUUID packet!\n"); |
| 3945 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3946 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3949 | /** |
| 3950 | * receive_bitmap_plain |
| 3951 | * |
| 3952 | * Return 0 when done, 1 when another iteration is needed, and a negative error |
| 3953 | * code upon failure. |
| 3954 | */ |
| 3955 | static int |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 3956 | receive_bitmap_plain(struct drbd_conf *mdev, unsigned int size, |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3957 | unsigned long *p, struct bm_xfer_ctx *c) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3958 | { |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 3959 | unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - |
| 3960 | drbd_header_size(mdev->tconn); |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3961 | unsigned int num_words = min_t(size_t, data_size / sizeof(*p), |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 3962 | c->bm_words - c->word_offset); |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3963 | unsigned int want = num_words * sizeof(*p); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3964 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3965 | |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 3966 | if (want != size) { |
| 3967 | dev_err(DEV, "%s:want (%u) != size (%u)\n", __func__, want, size); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3968 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3969 | } |
| 3970 | if (want == 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3971 | return 0; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3972 | err = drbd_recv_all(mdev->tconn, p, want); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 3973 | if (err) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3974 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3975 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 3976 | drbd_bm_merge_lel(mdev, c->word_offset, num_words, p); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3977 | |
| 3978 | c->word_offset += num_words; |
| 3979 | c->bit_offset = c->word_offset * BITS_PER_LONG; |
| 3980 | if (c->bit_offset > c->bm_bits) |
| 3981 | c->bit_offset = c->bm_bits; |
| 3982 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3983 | return 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
Andreas Gruenbacher | a02d124 | 2011-03-22 17:20:45 +0100 | [diff] [blame] | 3986 | static enum drbd_bitmap_code dcbp_get_code(struct p_compressed_bm *p) |
| 3987 | { |
| 3988 | return (enum drbd_bitmap_code)(p->encoding & 0x0f); |
| 3989 | } |
| 3990 | |
| 3991 | static int dcbp_get_start(struct p_compressed_bm *p) |
| 3992 | { |
| 3993 | return (p->encoding & 0x80) != 0; |
| 3994 | } |
| 3995 | |
| 3996 | static int dcbp_get_pad_bits(struct p_compressed_bm *p) |
| 3997 | { |
| 3998 | return (p->encoding >> 4) & 0x7; |
| 3999 | } |
| 4000 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4001 | /** |
| 4002 | * recv_bm_rle_bits |
| 4003 | * |
| 4004 | * Return 0 when done, 1 when another iteration is needed, and a negative error |
| 4005 | * code upon failure. |
| 4006 | */ |
| 4007 | static int |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4008 | recv_bm_rle_bits(struct drbd_conf *mdev, |
| 4009 | struct p_compressed_bm *p, |
Philipp Reisner | c6d25cf | 2011-01-19 16:13:06 +0100 | [diff] [blame] | 4010 | struct bm_xfer_ctx *c, |
| 4011 | unsigned int len) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4012 | { |
| 4013 | struct bitstream bs; |
| 4014 | u64 look_ahead; |
| 4015 | u64 rl; |
| 4016 | u64 tmp; |
| 4017 | unsigned long s = c->bit_offset; |
| 4018 | unsigned long e; |
Andreas Gruenbacher | a02d124 | 2011-03-22 17:20:45 +0100 | [diff] [blame] | 4019 | int toggle = dcbp_get_start(p); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4020 | int have; |
| 4021 | int bits; |
| 4022 | |
Andreas Gruenbacher | a02d124 | 2011-03-22 17:20:45 +0100 | [diff] [blame] | 4023 | bitstream_init(&bs, p->code, len, dcbp_get_pad_bits(p)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4024 | |
| 4025 | bits = bitstream_get_bits(&bs, &look_ahead, 64); |
| 4026 | if (bits < 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4027 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4028 | |
| 4029 | for (have = bits; have > 0; s += rl, toggle = !toggle) { |
| 4030 | bits = vli_decode_bits(&rl, look_ahead); |
| 4031 | if (bits <= 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4032 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4033 | |
| 4034 | if (toggle) { |
| 4035 | e = s + rl -1; |
| 4036 | if (e >= c->bm_bits) { |
| 4037 | dev_err(DEV, "bitmap overflow (e:%lu) while decoding bm RLE packet\n", e); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4038 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4039 | } |
| 4040 | _drbd_bm_set_bits(mdev, s, e); |
| 4041 | } |
| 4042 | |
| 4043 | if (have < bits) { |
| 4044 | dev_err(DEV, "bitmap decoding error: h:%d b:%d la:0x%08llx l:%u/%u\n", |
| 4045 | have, bits, look_ahead, |
| 4046 | (unsigned int)(bs.cur.b - p->code), |
| 4047 | (unsigned int)bs.buf_len); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4048 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4049 | } |
| 4050 | look_ahead >>= bits; |
| 4051 | have -= bits; |
| 4052 | |
| 4053 | bits = bitstream_get_bits(&bs, &tmp, 64 - have); |
| 4054 | if (bits < 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4055 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4056 | look_ahead |= tmp << have; |
| 4057 | have += bits; |
| 4058 | } |
| 4059 | |
| 4060 | c->bit_offset = s; |
| 4061 | bm_xfer_ctx_bit_to_word_offset(c); |
| 4062 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4063 | return (s != c->bm_bits); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4066 | /** |
| 4067 | * decode_bitmap_c |
| 4068 | * |
| 4069 | * Return 0 when done, 1 when another iteration is needed, and a negative error |
| 4070 | * code upon failure. |
| 4071 | */ |
| 4072 | static int |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4073 | decode_bitmap_c(struct drbd_conf *mdev, |
| 4074 | struct p_compressed_bm *p, |
Philipp Reisner | c6d25cf | 2011-01-19 16:13:06 +0100 | [diff] [blame] | 4075 | struct bm_xfer_ctx *c, |
| 4076 | unsigned int len) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4077 | { |
Andreas Gruenbacher | a02d124 | 2011-03-22 17:20:45 +0100 | [diff] [blame] | 4078 | if (dcbp_get_code(p) == RLE_VLI_Bits) |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4079 | return recv_bm_rle_bits(mdev, p, c, len - sizeof(*p)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4080 | |
| 4081 | /* other variants had been implemented for evaluation, |
| 4082 | * but have been dropped as this one turned out to be "best" |
| 4083 | * during all our tests. */ |
| 4084 | |
| 4085 | dev_err(DEV, "receive_bitmap_c: unknown encoding %u\n", p->encoding); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 4086 | conn_request_state(mdev->tconn, NS(conn, C_PROTOCOL_ERROR), CS_HARD); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4087 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | void INFO_bm_xfer_stats(struct drbd_conf *mdev, |
| 4091 | const char *direction, struct bm_xfer_ctx *c) |
| 4092 | { |
| 4093 | /* what would it take to transfer it "plaintext" */ |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 4094 | unsigned int header_size = drbd_header_size(mdev->tconn); |
| 4095 | unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - header_size; |
| 4096 | unsigned int plain = |
| 4097 | header_size * (DIV_ROUND_UP(c->bm_words, data_size) + 1) + |
| 4098 | c->bm_words * sizeof(unsigned long); |
| 4099 | unsigned int total = c->bytes[0] + c->bytes[1]; |
| 4100 | unsigned int r; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4101 | |
| 4102 | /* total can not be zero. but just in case: */ |
| 4103 | if (total == 0) |
| 4104 | return; |
| 4105 | |
| 4106 | /* don't report if not compressed */ |
| 4107 | if (total >= plain) |
| 4108 | return; |
| 4109 | |
| 4110 | /* total < plain. check for overflow, still */ |
| 4111 | r = (total > UINT_MAX/1000) ? (total / (plain/1000)) |
| 4112 | : (1000 * total / plain); |
| 4113 | |
| 4114 | if (r > 1000) |
| 4115 | r = 1000; |
| 4116 | |
| 4117 | r = 1000 - r; |
| 4118 | dev_info(DEV, "%s bitmap stats [Bytes(packets)]: plain %u(%u), RLE %u(%u), " |
| 4119 | "total %u; compression: %u.%u%%\n", |
| 4120 | direction, |
| 4121 | c->bytes[1], c->packets[1], |
| 4122 | c->bytes[0], c->packets[0], |
| 4123 | total, r/10, r % 10); |
| 4124 | } |
| 4125 | |
| 4126 | /* Since we are processing the bitfield from lower addresses to higher, |
| 4127 | it does not matter if the process it in 32 bit chunks or 64 bit |
| 4128 | chunks as long as it is little endian. (Understand it as byte stream, |
| 4129 | beginning with the lowest byte...) If we would use big endian |
| 4130 | we would need to process it from the highest address to the lowest, |
| 4131 | in order to be agnostic to the 32 vs 64 bits issue. |
| 4132 | |
| 4133 | returns 0 on failure, 1 if we successfully received it. */ |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4134 | static int receive_bitmap(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4135 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4136 | struct drbd_conf *mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4137 | struct bm_xfer_ctx c; |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4138 | int err; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4139 | |
| 4140 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 4141 | if (!mdev) |
| 4142 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4143 | |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 4144 | drbd_bm_lock(mdev, "receive bitmap", BM_LOCKED_SET_ALLOWED); |
| 4145 | /* you are supposed to send additional out-of-sync information |
| 4146 | * if you actually set bits during this phase */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4147 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4148 | c = (struct bm_xfer_ctx) { |
| 4149 | .bm_bits = drbd_bm_bits(mdev), |
| 4150 | .bm_words = drbd_bm_words(mdev), |
| 4151 | }; |
| 4152 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4153 | for(;;) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4154 | if (pi->cmd == P_BITMAP) |
| 4155 | err = receive_bitmap_plain(mdev, pi->size, pi->data, &c); |
| 4156 | else if (pi->cmd == P_COMPRESSED_BITMAP) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4157 | /* MAYBE: sanity check that we speak proto >= 90, |
| 4158 | * and the feature is enabled! */ |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4159 | struct p_compressed_bm *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4160 | |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 4161 | if (pi->size > DRBD_SOCKET_BUFFER_SIZE - drbd_header_size(tconn)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4162 | dev_err(DEV, "ReportCBitmap packet too large\n"); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4163 | err = -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4164 | goto out; |
| 4165 | } |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4166 | if (pi->size <= sizeof(*p)) { |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4167 | dev_err(DEV, "ReportCBitmap packet too small (l:%u)\n", pi->size); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4168 | err = -EIO; |
Andreas Gruenbacher | 78fcbda | 2010-12-10 22:18:27 +0100 | [diff] [blame] | 4169 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4170 | } |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4171 | err = drbd_recv_all(mdev->tconn, p, pi->size); |
| 4172 | if (err) |
| 4173 | goto out; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4174 | err = decode_bitmap_c(mdev, p, &c, pi->size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4175 | } else { |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4176 | dev_warn(DEV, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", pi->cmd); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4177 | err = -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4178 | goto out; |
| 4179 | } |
| 4180 | |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4181 | c.packets[pi->cmd == P_BITMAP]++; |
Andreas Gruenbacher | 50d0b1a | 2011-03-30 11:53:51 +0200 | [diff] [blame] | 4182 | c.bytes[pi->cmd == P_BITMAP] += drbd_header_size(tconn) + pi->size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4183 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4184 | if (err <= 0) { |
| 4185 | if (err < 0) |
| 4186 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4187 | break; |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4188 | } |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4189 | err = drbd_recv_header(mdev->tconn, pi); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4190 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4191 | goto out; |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 4192 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4193 | |
| 4194 | INFO_bm_xfer_stats(mdev, "receive", &c); |
| 4195 | |
| 4196 | if (mdev->state.conn == C_WF_BITMAP_T) { |
Andreas Gruenbacher | de1f8e4 | 2010-12-10 21:04:00 +0100 | [diff] [blame] | 4197 | enum drbd_state_rv rv; |
| 4198 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4199 | err = drbd_send_bitmap(mdev); |
| 4200 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4201 | goto out; |
| 4202 | /* Omit CS_ORDERED with this state transition to avoid deadlocks. */ |
Andreas Gruenbacher | de1f8e4 | 2010-12-10 21:04:00 +0100 | [diff] [blame] | 4203 | rv = _drbd_request_state(mdev, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE); |
| 4204 | D_ASSERT(rv == SS_SUCCESS); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4205 | } else if (mdev->state.conn != C_WF_BITMAP_S) { |
| 4206 | /* admin may have requested C_DISCONNECTING, |
| 4207 | * other threads may have noticed network errors */ |
| 4208 | dev_info(DEV, "unexpected cstate (%s) in receive_bitmap\n", |
| 4209 | drbd_conn_str(mdev->state.conn)); |
| 4210 | } |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4211 | err = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4212 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4213 | out: |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 4214 | drbd_bm_unlock(mdev); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4215 | if (!err && mdev->state.conn == C_WF_BITMAP_S) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4216 | drbd_start_resync(mdev, C_SYNC_SOURCE); |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4217 | return err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4220 | static int receive_skip(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4221 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4222 | conn_warn(tconn, "skipping unknown optional packet type %d, l: %d!\n", |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4223 | pi->cmd, pi->size); |
Philipp Reisner | 2de876e | 2011-03-15 14:38:01 +0100 | [diff] [blame] | 4224 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4225 | return ignore_remaining_packet(tconn, pi); |
Philipp Reisner | 2de876e | 2011-03-15 14:38:01 +0100 | [diff] [blame] | 4226 | } |
| 4227 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4228 | static int receive_UnplugRemote(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4229 | { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4230 | /* Make sure we've acked all the TCP data associated |
| 4231 | * with the data requests being unplugged */ |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4232 | drbd_tcp_quickack(tconn->data.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4233 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4234 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4235 | } |
| 4236 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4237 | static int receive_out_of_sync(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 4238 | { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4239 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4240 | struct p_block_desc *p = pi->data; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4241 | |
| 4242 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 4243 | if (!mdev) |
| 4244 | return -EIO; |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 4245 | |
Lars Ellenberg | f735e363 | 2010-12-17 21:06:18 +0100 | [diff] [blame] | 4246 | switch (mdev->state.conn) { |
| 4247 | case C_WF_SYNC_UUID: |
| 4248 | case C_WF_BITMAP_T: |
| 4249 | case C_BEHIND: |
| 4250 | break; |
| 4251 | default: |
| 4252 | dev_err(DEV, "ASSERT FAILED cstate = %s, expected: WFSyncUUID|WFBitMapT|Behind\n", |
| 4253 | drbd_conn_str(mdev->state.conn)); |
| 4254 | } |
| 4255 | |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 4256 | drbd_set_out_of_sync(mdev, be64_to_cpu(p->sector), be32_to_cpu(p->blksize)); |
| 4257 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4258 | return 0; |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 4259 | } |
| 4260 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4261 | struct data_cmd { |
| 4262 | int expect_payload; |
| 4263 | size_t pkt_size; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4264 | int (*fn)(struct drbd_tconn *, struct packet_info *); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4265 | }; |
| 4266 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4267 | static struct data_cmd drbd_cmd_handler[] = { |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4268 | [P_DATA] = { 1, sizeof(struct p_data), receive_Data }, |
| 4269 | [P_DATA_REPLY] = { 1, sizeof(struct p_data), receive_DataReply }, |
| 4270 | [P_RS_DATA_REPLY] = { 1, sizeof(struct p_data), receive_RSDataReply } , |
| 4271 | [P_BARRIER] = { 0, sizeof(struct p_barrier), receive_Barrier } , |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4272 | [P_BITMAP] = { 1, 0, receive_bitmap } , |
| 4273 | [P_COMPRESSED_BITMAP] = { 1, 0, receive_bitmap } , |
| 4274 | [P_UNPLUG_REMOTE] = { 0, 0, receive_UnplugRemote }, |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4275 | [P_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, |
| 4276 | [P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4277 | [P_SYNC_PARAM] = { 1, 0, receive_SyncParam }, |
| 4278 | [P_SYNC_PARAM89] = { 1, 0, receive_SyncParam }, |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4279 | [P_PROTOCOL] = { 1, sizeof(struct p_protocol), receive_protocol }, |
| 4280 | [P_UUIDS] = { 0, sizeof(struct p_uuids), receive_uuids }, |
| 4281 | [P_SIZES] = { 0, sizeof(struct p_sizes), receive_sizes }, |
| 4282 | [P_STATE] = { 0, sizeof(struct p_state), receive_state }, |
| 4283 | [P_STATE_CHG_REQ] = { 0, sizeof(struct p_req_state), receive_req_state }, |
| 4284 | [P_SYNC_UUID] = { 0, sizeof(struct p_rs_uuid), receive_sync_uuid }, |
| 4285 | [P_OV_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, |
| 4286 | [P_OV_REPLY] = { 1, sizeof(struct p_block_req), receive_DataRequest }, |
| 4287 | [P_CSUM_RS_REQUEST] = { 1, sizeof(struct p_block_req), receive_DataRequest }, |
| 4288 | [P_DELAY_PROBE] = { 0, sizeof(struct p_delay_probe93), receive_skip }, |
| 4289 | [P_OUT_OF_SYNC] = { 0, sizeof(struct p_block_desc), receive_out_of_sync }, |
| 4290 | [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] | 4291 | [P_PROTOCOL_UPDATE] = { 1, sizeof(struct p_protocol), receive_protocol }, |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4292 | }; |
| 4293 | |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 4294 | static void drbdd(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4295 | { |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4296 | struct packet_info pi; |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4297 | size_t shs; /* sub header size */ |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4298 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4299 | |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 4300 | while (get_t_state(&tconn->receiver) == RUNNING) { |
Andreas Gruenbacher | deebe19 | 2011-03-25 00:01:04 +0100 | [diff] [blame] | 4301 | struct data_cmd *cmd; |
| 4302 | |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 4303 | drbd_thread_current_set_cpu(&tconn->receiver); |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4304 | if (drbd_recv_header(tconn, &pi)) |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4305 | goto err_out; |
| 4306 | |
Andreas Gruenbacher | deebe19 | 2011-03-25 00:01:04 +0100 | [diff] [blame] | 4307 | cmd = &drbd_cmd_handler[pi.cmd]; |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4308 | if (unlikely(pi.cmd >= ARRAY_SIZE(drbd_cmd_handler) || !cmd->fn)) { |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 4309 | conn_err(tconn, "Unexpected data packet %s (0x%04x)", |
| 4310 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4311 | goto err_out; |
Lars Ellenberg | 0b33a91 | 2009-11-16 15:58:04 +0100 | [diff] [blame] | 4312 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4313 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4314 | shs = cmd->pkt_size; |
| 4315 | if (pi.size > shs && !cmd->expect_payload) { |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 4316 | conn_err(tconn, "No payload expected %s l:%d\n", |
| 4317 | cmdname(pi.cmd), pi.size); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4318 | goto err_out; |
| 4319 | } |
| 4320 | |
Lars Ellenberg | c13f7e1 | 2010-10-29 23:32:01 +0200 | [diff] [blame] | 4321 | if (shs) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4322 | err = drbd_recv_all_warn(tconn, pi.data, shs); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 4323 | if (err) |
Lars Ellenberg | c13f7e1 | 2010-10-29 23:32:01 +0200 | [diff] [blame] | 4324 | goto err_out; |
Andreas Gruenbacher | e285721 | 2011-03-25 00:57:38 +0100 | [diff] [blame] | 4325 | pi.size -= shs; |
Lars Ellenberg | c13f7e1 | 2010-10-29 23:32:01 +0200 | [diff] [blame] | 4326 | } |
| 4327 | |
Andreas Gruenbacher | 4a76b16 | 2011-03-25 02:43:51 +0100 | [diff] [blame] | 4328 | err = cmd->fn(tconn, &pi); |
| 4329 | if (err) { |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4330 | conn_err(tconn, "error receiving %s, e: %d l: %d!\n", |
| 4331 | cmdname(pi.cmd), err, pi.size); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4332 | goto err_out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4333 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4334 | } |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4335 | return; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4336 | |
Andreas Gruenbacher | 82bc019 | 2011-03-17 12:10:19 +0100 | [diff] [blame] | 4337 | err_out: |
| 4338 | conn_request_state(tconn, NS(conn, C_PROTOCOL_ERROR), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 4341 | void conn_flush_workqueue(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4342 | { |
| 4343 | struct drbd_wq_barrier barr; |
| 4344 | |
| 4345 | barr.w.cb = w_prev_work_done; |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 4346 | barr.w.tconn = tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4347 | init_completion(&barr.done); |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 4348 | drbd_queue_work(&tconn->data.work, &barr.w); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4349 | wait_for_completion(&barr.done); |
| 4350 | } |
| 4351 | |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 4352 | static void conn_disconnect(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4353 | { |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 4354 | struct drbd_conf *mdev; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4355 | enum drbd_conns oc; |
Philipp Reisner | 376694a | 2011-11-07 10:54:28 +0100 | [diff] [blame] | 4356 | int vnr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4357 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4358 | if (tconn->cstate == C_STANDALONE) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4359 | return; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4360 | |
Philipp Reisner | b8853db | 2011-12-13 11:09:16 +0100 | [diff] [blame] | 4361 | /* We are about to start the cleanup after connection loss. |
| 4362 | * Make sure drbd_make_request knows about that. |
| 4363 | * Usually we should be in some network failure state already, |
| 4364 | * but just in case we are not, we fix it up here. |
| 4365 | */ |
| 4366 | conn_request_state(tconn, NS(conn, C_NETWORK_FAILURE), CS_HARD); |
| 4367 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4368 | /* asender does not clean up anything. it must not interfere, either */ |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4369 | drbd_thread_stop(&tconn->asender); |
| 4370 | drbd_free_sock(tconn); |
| 4371 | |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 4372 | rcu_read_lock(); |
| 4373 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
| 4374 | kref_get(&mdev->kref); |
| 4375 | rcu_read_unlock(); |
| 4376 | drbd_disconnected(mdev); |
| 4377 | kref_put(&mdev->kref, &drbd_minor_destroy); |
| 4378 | rcu_read_lock(); |
| 4379 | } |
| 4380 | rcu_read_unlock(); |
| 4381 | |
Philipp Reisner | 12038a3 | 2011-11-09 19:18:00 +0100 | [diff] [blame] | 4382 | if (!list_empty(&tconn->current_epoch->list)) |
| 4383 | conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n"); |
| 4384 | /* ok, no more ee's on the fly, it is safe to reset the epoch_size */ |
| 4385 | atomic_set(&tconn->current_epoch->epoch_size, 0); |
| 4386 | |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4387 | conn_info(tconn, "Connection closed\n"); |
| 4388 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 4389 | if (conn_highest_role(tconn) == R_PRIMARY && conn_highest_pdsk(tconn) >= D_UNKNOWN) |
| 4390 | conn_try_outdate_peer_async(tconn); |
| 4391 | |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4392 | spin_lock_irq(&tconn->req_lock); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4393 | oc = tconn->cstate; |
| 4394 | if (oc >= C_UNCONNECTED) |
Philipp Reisner | 376694a | 2011-11-07 10:54:28 +0100 | [diff] [blame] | 4395 | _conn_request_state(tconn, NS(conn, C_UNCONNECTED), CS_VERBOSE); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4396 | |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4397 | spin_unlock_irq(&tconn->req_lock); |
| 4398 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 4399 | if (oc == C_DISCONNECTING) |
Lars Ellenberg | d9cc6e2 | 2011-04-27 10:25:28 +0200 | [diff] [blame] | 4400 | conn_request_state(tconn, NS(conn, C_STANDALONE), CS_VERBOSE | CS_HARD); |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4401 | } |
| 4402 | |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 4403 | static int drbd_disconnected(struct drbd_conf *mdev) |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4404 | { |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4405 | unsigned int i; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4406 | |
Philipp Reisner | 8571957 | 2010-07-21 10:20:17 +0200 | [diff] [blame] | 4407 | /* wait for current activity to cease. */ |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4408 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4409 | _drbd_wait_ee_list_empty(mdev, &mdev->active_ee); |
| 4410 | _drbd_wait_ee_list_empty(mdev, &mdev->sync_ee); |
| 4411 | _drbd_wait_ee_list_empty(mdev, &mdev->read_ee); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4412 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4413 | |
| 4414 | /* We do not have data structures that would allow us to |
| 4415 | * get the rs_pending_cnt down to 0 again. |
| 4416 | * * On C_SYNC_TARGET we do not have any data structures describing |
| 4417 | * the pending RSDataRequest's we have sent. |
| 4418 | * * On C_SYNC_SOURCE there is no data structure that tracks |
| 4419 | * the P_RS_DATA_REPLY blocks that we sent to the SyncTarget. |
| 4420 | * And no, it is not the sum of the reference counts in the |
| 4421 | * resync_LRU. The resync_LRU tracks the whole operation including |
| 4422 | * the disk-IO, while the rs_pending_cnt only tracks the blocks |
| 4423 | * on the fly. */ |
| 4424 | drbd_rs_cancel_all(mdev); |
| 4425 | mdev->rs_total = 0; |
| 4426 | mdev->rs_failed = 0; |
| 4427 | atomic_set(&mdev->rs_pending_cnt, 0); |
| 4428 | wake_up(&mdev->misc_wait); |
| 4429 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4430 | del_timer_sync(&mdev->resync_timer); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4431 | resync_timer_fn((unsigned long)mdev); |
| 4432 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4433 | /* wait for all w_e_end_data_req, w_e_end_rsdata_req, w_send_barrier, |
| 4434 | * w_make_resync_request etc. which may still be on the worker queue |
| 4435 | * to be "canceled" */ |
Philipp Reisner | a21e929 | 2011-02-08 15:08:49 +0100 | [diff] [blame] | 4436 | drbd_flush_workqueue(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4437 | |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 4438 | drbd_finish_peer_reqs(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4439 | |
Philipp Reisner | d10b4ea | 2011-11-30 23:25:36 +0100 | [diff] [blame] | 4440 | /* This second workqueue flush is necessary, since drbd_finish_peer_reqs() |
| 4441 | might have issued a work again. The one before drbd_finish_peer_reqs() is |
| 4442 | necessary to reclain net_ee in drbd_finish_peer_reqs(). */ |
| 4443 | drbd_flush_workqueue(mdev); |
| 4444 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4445 | kfree(mdev->p_uuid); |
| 4446 | mdev->p_uuid = NULL; |
| 4447 | |
Philipp Reisner | 2aebfab | 2011-03-28 16:48:11 +0200 | [diff] [blame] | 4448 | if (!drbd_suspended(mdev)) |
Philipp Reisner | 2f5cdd0 | 2011-02-21 14:29:27 +0100 | [diff] [blame] | 4449 | tl_clear(mdev->tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4450 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4451 | drbd_md_sync(mdev); |
| 4452 | |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 4453 | /* serialize with bitmap writeout triggered by the state change, |
| 4454 | * if any. */ |
| 4455 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); |
| 4456 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4457 | /* tcp_close and release of sendpage pages can be deferred. I don't |
| 4458 | * want to use SO_LINGER, because apparently it can be deferred for |
| 4459 | * more than 20 seconds (longest time I checked). |
| 4460 | * |
| 4461 | * Actually we don't care for exactly when the network stack does its |
| 4462 | * put_page(), but release our reference on these pages right here. |
| 4463 | */ |
Andreas Gruenbacher | 7721f56 | 2011-04-06 17:14:02 +0200 | [diff] [blame] | 4464 | i = drbd_free_peer_reqs(mdev, &mdev->net_ee); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4465 | if (i) |
| 4466 | dev_info(DEV, "net_ee not empty, killed %u entries\n", i); |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 4467 | i = atomic_read(&mdev->pp_in_use_by_net); |
| 4468 | if (i) |
| 4469 | dev_info(DEV, "pp_in_use_by_net = %d, expected 0\n", i); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4470 | i = atomic_read(&mdev->pp_in_use); |
| 4471 | if (i) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 4472 | dev_info(DEV, "pp_in_use = %d, expected 0\n", i); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4473 | |
| 4474 | D_ASSERT(list_empty(&mdev->read_ee)); |
| 4475 | D_ASSERT(list_empty(&mdev->active_ee)); |
| 4476 | D_ASSERT(list_empty(&mdev->sync_ee)); |
| 4477 | D_ASSERT(list_empty(&mdev->done_ee)); |
| 4478 | |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4479 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | /* |
| 4483 | * We support PRO_VERSION_MIN to PRO_VERSION_MAX. The protocol version |
| 4484 | * we can agree on is stored in agreed_pro_version. |
| 4485 | * |
| 4486 | * feature flags and the reserved array should be enough room for future |
| 4487 | * enhancements of the handshake protocol, and possible plugins... |
| 4488 | * |
| 4489 | * for now, they are expected to be zero, but ignored. |
| 4490 | */ |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 4491 | static int drbd_send_features(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4492 | { |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4493 | struct drbd_socket *sock; |
| 4494 | struct p_connection_features *p; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4495 | |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4496 | sock = &tconn->data; |
| 4497 | p = conn_prepare_command(tconn, sock); |
| 4498 | if (!p) |
Andreas Gruenbacher | e8d17b0 | 2011-03-16 00:54:19 +0100 | [diff] [blame] | 4499 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4500 | memset(p, 0, sizeof(*p)); |
| 4501 | p->protocol_min = cpu_to_be32(PRO_VERSION_MIN); |
| 4502 | p->protocol_max = cpu_to_be32(PRO_VERSION_MAX); |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4503 | return conn_send_command(tconn, sock, P_CONNECTION_FEATURES, sizeof(*p), NULL, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4504 | } |
| 4505 | |
| 4506 | /* |
| 4507 | * return values: |
| 4508 | * 1 yes, we have a valid connection |
| 4509 | * 0 oops, did not work out, please try again |
| 4510 | * -1 peer talks different language, |
| 4511 | * no point in trying again, please go standalone. |
| 4512 | */ |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 4513 | static int drbd_do_features(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4514 | { |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4515 | /* ASSERT current == tconn->receiver ... */ |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4516 | struct p_connection_features *p; |
| 4517 | const int expect = sizeof(struct p_connection_features); |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4518 | struct packet_info pi; |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 4519 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4520 | |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 4521 | err = drbd_send_features(tconn); |
Andreas Gruenbacher | e8d17b0 | 2011-03-16 00:54:19 +0100 | [diff] [blame] | 4522 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4523 | return 0; |
| 4524 | |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4525 | err = drbd_recv_header(tconn, &pi); |
| 4526 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4527 | return 0; |
| 4528 | |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 4529 | if (pi.cmd != P_CONNECTION_FEATURES) { |
| 4530 | conn_err(tconn, "expected ConnectionFeatures packet, received: %s (0x%04x)\n", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 4531 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4532 | return -1; |
| 4533 | } |
| 4534 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4535 | if (pi.size != expect) { |
Andreas Gruenbacher | 6038178 | 2011-03-28 17:05:50 +0200 | [diff] [blame] | 4536 | conn_err(tconn, "expected ConnectionFeatures length: %u, received: %u\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4537 | expect, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4538 | return -1; |
| 4539 | } |
| 4540 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4541 | p = pi.data; |
| 4542 | err = drbd_recv_all_warn(tconn, p, expect); |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 4543 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4544 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4545 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4546 | p->protocol_min = be32_to_cpu(p->protocol_min); |
| 4547 | p->protocol_max = be32_to_cpu(p->protocol_max); |
| 4548 | if (p->protocol_max == 0) |
| 4549 | p->protocol_max = p->protocol_min; |
| 4550 | |
| 4551 | if (PRO_VERSION_MAX < p->protocol_min || |
| 4552 | PRO_VERSION_MIN > p->protocol_max) |
| 4553 | goto incompat; |
| 4554 | |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4555 | tconn->agreed_pro_version = min_t(int, PRO_VERSION_MAX, p->protocol_max); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4556 | |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4557 | conn_info(tconn, "Handshake successful: " |
| 4558 | "Agreed network protocol version %d\n", tconn->agreed_pro_version); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4559 | |
| 4560 | return 1; |
| 4561 | |
| 4562 | incompat: |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4563 | conn_err(tconn, "incompatible DRBD dialects: " |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4564 | "I support %d-%d, peer supports %d-%d\n", |
| 4565 | PRO_VERSION_MIN, PRO_VERSION_MAX, |
| 4566 | p->protocol_min, p->protocol_max); |
| 4567 | return -1; |
| 4568 | } |
| 4569 | |
| 4570 | #if !defined(CONFIG_CRYPTO_HMAC) && !defined(CONFIG_CRYPTO_HMAC_MODULE) |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4571 | static int drbd_do_auth(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4572 | { |
| 4573 | dev_err(DEV, "This kernel was build without CONFIG_CRYPTO_HMAC.\n"); |
| 4574 | dev_err(DEV, "You need to disable 'cram-hmac-alg' in drbd.conf.\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4575 | return -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4576 | } |
| 4577 | #else |
| 4578 | #define CHALLENGE_LEN 64 |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4579 | |
| 4580 | /* Return value: |
| 4581 | 1 - auth succeeded, |
| 4582 | 0 - failed, try again (network error), |
| 4583 | -1 - auth failed, don't try again. |
| 4584 | */ |
| 4585 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4586 | static int drbd_do_auth(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4587 | { |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4588 | struct drbd_socket *sock; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4589 | char my_challenge[CHALLENGE_LEN]; /* 64 Bytes... */ |
| 4590 | struct scatterlist sg; |
| 4591 | char *response = NULL; |
| 4592 | char *right_response = NULL; |
| 4593 | char *peers_ch = NULL; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 4594 | unsigned int key_len; |
| 4595 | char secret[SHARED_SECRET_MAX]; /* 64 byte */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4596 | unsigned int resp_size; |
| 4597 | struct hash_desc desc; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4598 | struct packet_info pi; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 4599 | struct net_conf *nc; |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4600 | int err, rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4601 | |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4602 | /* FIXME: Put the challenge/response into the preallocated socket buffer. */ |
| 4603 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 4604 | rcu_read_lock(); |
| 4605 | nc = rcu_dereference(tconn->net_conf); |
| 4606 | key_len = strlen(nc->shared_secret); |
| 4607 | memcpy(secret, nc->shared_secret, key_len); |
| 4608 | rcu_read_unlock(); |
| 4609 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4610 | desc.tfm = tconn->cram_hmac_tfm; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4611 | desc.flags = 0; |
| 4612 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 4613 | rv = crypto_hash_setkey(tconn->cram_hmac_tfm, (u8 *)secret, key_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4614 | if (rv) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4615 | conn_err(tconn, "crypto_hash_setkey() failed with %d\n", rv); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4616 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4617 | goto fail; |
| 4618 | } |
| 4619 | |
| 4620 | get_random_bytes(my_challenge, CHALLENGE_LEN); |
| 4621 | |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4622 | sock = &tconn->data; |
| 4623 | if (!conn_prepare_command(tconn, sock)) { |
| 4624 | rv = 0; |
| 4625 | goto fail; |
| 4626 | } |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4627 | rv = !conn_send_command(tconn, sock, P_AUTH_CHALLENGE, 0, |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4628 | my_challenge, CHALLENGE_LEN); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4629 | if (!rv) |
| 4630 | goto fail; |
| 4631 | |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4632 | err = drbd_recv_header(tconn, &pi); |
| 4633 | if (err) { |
| 4634 | rv = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4635 | goto fail; |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4636 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4637 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4638 | if (pi.cmd != P_AUTH_CHALLENGE) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4639 | conn_err(tconn, "expected AuthChallenge packet, received: %s (0x%04x)\n", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 4640 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4641 | rv = 0; |
| 4642 | goto fail; |
| 4643 | } |
| 4644 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4645 | if (pi.size > CHALLENGE_LEN * 2) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4646 | conn_err(tconn, "expected AuthChallenge payload too big.\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4647 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4648 | goto fail; |
| 4649 | } |
| 4650 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4651 | peers_ch = kmalloc(pi.size, GFP_NOIO); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4652 | if (peers_ch == NULL) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4653 | conn_err(tconn, "kmalloc of peers_ch failed\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4654 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4655 | goto fail; |
| 4656 | } |
| 4657 | |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 4658 | err = drbd_recv_all_warn(tconn, peers_ch, pi.size); |
| 4659 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4660 | rv = 0; |
| 4661 | goto fail; |
| 4662 | } |
| 4663 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4664 | resp_size = crypto_hash_digestsize(tconn->cram_hmac_tfm); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4665 | response = kmalloc(resp_size, GFP_NOIO); |
| 4666 | if (response == NULL) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4667 | conn_err(tconn, "kmalloc of response failed\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4668 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4669 | goto fail; |
| 4670 | } |
| 4671 | |
| 4672 | sg_init_table(&sg, 1); |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4673 | sg_set_buf(&sg, peers_ch, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4674 | |
| 4675 | rv = crypto_hash_digest(&desc, &sg, sg.length, response); |
| 4676 | if (rv) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4677 | conn_err(tconn, "crypto_hash_digest() failed with %d\n", rv); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4678 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4679 | goto fail; |
| 4680 | } |
| 4681 | |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4682 | if (!conn_prepare_command(tconn, sock)) { |
| 4683 | rv = 0; |
| 4684 | goto fail; |
| 4685 | } |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4686 | rv = !conn_send_command(tconn, sock, P_AUTH_RESPONSE, 0, |
Andreas Gruenbacher | 9f5bdc3 | 2011-03-28 14:23:08 +0200 | [diff] [blame] | 4687 | response, resp_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4688 | if (!rv) |
| 4689 | goto fail; |
| 4690 | |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4691 | err = drbd_recv_header(tconn, &pi); |
| 4692 | if (err) { |
| 4693 | rv = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4694 | goto fail; |
Andreas Gruenbacher | 69bc7bc | 2011-03-16 17:31:52 +0100 | [diff] [blame] | 4695 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4696 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4697 | if (pi.cmd != P_AUTH_RESPONSE) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4698 | conn_err(tconn, "expected AuthResponse packet, received: %s (0x%04x)\n", |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 4699 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4700 | rv = 0; |
| 4701 | goto fail; |
| 4702 | } |
| 4703 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4704 | if (pi.size != resp_size) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4705 | conn_err(tconn, "expected AuthResponse payload of wrong size\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4706 | rv = 0; |
| 4707 | goto fail; |
| 4708 | } |
| 4709 | |
Andreas Gruenbacher | a5c3190 | 2011-03-24 03:28:04 +0100 | [diff] [blame] | 4710 | err = drbd_recv_all_warn(tconn, response , resp_size); |
| 4711 | if (err) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4712 | rv = 0; |
| 4713 | goto fail; |
| 4714 | } |
| 4715 | |
| 4716 | right_response = kmalloc(resp_size, GFP_NOIO); |
Julia Lawall | 2d1ee87 | 2009-12-27 22:27:11 +0100 | [diff] [blame] | 4717 | if (right_response == NULL) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4718 | conn_err(tconn, "kmalloc of right_response failed\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4719 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4720 | goto fail; |
| 4721 | } |
| 4722 | |
| 4723 | sg_set_buf(&sg, my_challenge, CHALLENGE_LEN); |
| 4724 | |
| 4725 | rv = crypto_hash_digest(&desc, &sg, sg.length, right_response); |
| 4726 | if (rv) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4727 | conn_err(tconn, "crypto_hash_digest() failed with %d\n", rv); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4728 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4729 | goto fail; |
| 4730 | } |
| 4731 | |
| 4732 | rv = !memcmp(response, right_response, resp_size); |
| 4733 | |
| 4734 | if (rv) |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 4735 | conn_info(tconn, "Peer authenticated using %d bytes HMAC\n", |
| 4736 | resp_size); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4737 | else |
| 4738 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4739 | |
| 4740 | fail: |
| 4741 | kfree(peers_ch); |
| 4742 | kfree(response); |
| 4743 | kfree(right_response); |
| 4744 | |
| 4745 | return rv; |
| 4746 | } |
| 4747 | #endif |
| 4748 | |
| 4749 | int drbdd_init(struct drbd_thread *thi) |
| 4750 | { |
Philipp Reisner | 392c880 | 2011-02-09 10:33:31 +0100 | [diff] [blame] | 4751 | struct drbd_tconn *tconn = thi->tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4752 | int h; |
| 4753 | |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4754 | conn_info(tconn, "receiver (re)started\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4755 | |
| 4756 | do { |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 4757 | h = conn_connect(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4758 | if (h == 0) { |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 4759 | conn_disconnect(tconn); |
Philipp Reisner | 20ee639 | 2011-01-18 15:28:59 +0100 | [diff] [blame] | 4760 | schedule_timeout_interruptible(HZ); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4761 | } |
| 4762 | if (h == -1) { |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4763 | conn_warn(tconn, "Discarding network configuration.\n"); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4764 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4765 | } |
| 4766 | } while (h == 0); |
| 4767 | |
Philipp Reisner | 91fd4da | 2011-04-20 17:47:29 +0200 | [diff] [blame] | 4768 | if (h > 0) |
| 4769 | drbdd(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4770 | |
Philipp Reisner | 81fa2e6 | 2011-05-04 15:10:30 +0200 | [diff] [blame] | 4771 | conn_disconnect(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4772 | |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4773 | conn_info(tconn, "receiver terminated\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4774 | return 0; |
| 4775 | } |
| 4776 | |
| 4777 | /* ********* acknowledge sender ******** */ |
| 4778 | |
Andreas Gruenbacher | e05e1e5 | 2011-03-25 15:16:26 +0100 | [diff] [blame] | 4779 | static int got_conn_RqSReply(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 4780 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4781 | struct p_req_state_reply *p = pi->data; |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 4782 | int retcode = be32_to_cpu(p->retcode); |
| 4783 | |
| 4784 | if (retcode >= SS_SUCCESS) { |
| 4785 | set_bit(CONN_WD_ST_CHG_OKAY, &tconn->flags); |
| 4786 | } else { |
| 4787 | set_bit(CONN_WD_ST_CHG_FAIL, &tconn->flags); |
| 4788 | conn_err(tconn, "Requested state change failed by peer: %s (%d)\n", |
| 4789 | drbd_set_st_err_str(retcode), retcode); |
| 4790 | } |
| 4791 | wake_up(&tconn->ping_wait); |
| 4792 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4793 | return 0; |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 4794 | } |
| 4795 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4796 | static int got_RqSReply(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4797 | { |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4798 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4799 | struct p_req_state_reply *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4800 | int retcode = be32_to_cpu(p->retcode); |
| 4801 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4802 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 4803 | if (!mdev) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4804 | return -EIO; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4805 | |
Philipp Reisner | 4d0fc3f | 2012-01-20 13:52:27 +0100 | [diff] [blame] | 4806 | if (test_bit(CONN_WD_ST_CHG_REQ, &tconn->flags)) { |
| 4807 | D_ASSERT(tconn->agreed_pro_version < 100); |
| 4808 | return got_conn_RqSReply(tconn, pi); |
| 4809 | } |
| 4810 | |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 4811 | if (retcode >= SS_SUCCESS) { |
| 4812 | set_bit(CL_ST_CHG_SUCCESS, &mdev->flags); |
| 4813 | } else { |
| 4814 | set_bit(CL_ST_CHG_FAIL, &mdev->flags); |
| 4815 | dev_err(DEV, "Requested state change failed by peer: %s (%d)\n", |
| 4816 | drbd_set_st_err_str(retcode), retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4817 | } |
Philipp Reisner | e4f78ed | 2011-03-16 11:27:48 +0100 | [diff] [blame] | 4818 | wake_up(&mdev->state_wait); |
| 4819 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4820 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4821 | } |
| 4822 | |
Andreas Gruenbacher | e05e1e5 | 2011-03-25 15:16:26 +0100 | [diff] [blame] | 4823 | static int got_Ping(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4824 | { |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4825 | return drbd_send_ping_ack(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4826 | |
| 4827 | } |
| 4828 | |
Andreas Gruenbacher | e05e1e5 | 2011-03-25 15:16:26 +0100 | [diff] [blame] | 4829 | static int got_PingAck(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4830 | { |
| 4831 | /* restore idle timeout */ |
Philipp Reisner | 2a67d8b | 2011-02-09 14:10:32 +0100 | [diff] [blame] | 4832 | tconn->meta.socket->sk->sk_rcvtimeo = tconn->net_conf->ping_int*HZ; |
| 4833 | if (!test_and_set_bit(GOT_PING_ACK, &tconn->flags)) |
| 4834 | wake_up(&tconn->ping_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4835 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4836 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4837 | } |
| 4838 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4839 | static int got_IsInSync(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4840 | { |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4841 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4842 | struct p_block_ack *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4843 | sector_t sector = be64_to_cpu(p->sector); |
| 4844 | int blksize = be32_to_cpu(p->blksize); |
| 4845 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4846 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 4847 | if (!mdev) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4848 | return -EIO; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4849 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 4850 | D_ASSERT(mdev->tconn->agreed_pro_version >= 89); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4851 | |
| 4852 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 4853 | |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 4854 | if (get_ldev(mdev)) { |
| 4855 | drbd_rs_complete_io(mdev, sector); |
| 4856 | drbd_set_in_sync(mdev, sector, blksize); |
| 4857 | /* rs_same_csums is supposed to count in units of BM_BLOCK_SIZE */ |
| 4858 | mdev->rs_same_csum += (blksize >> BM_BLOCK_SHIFT); |
| 4859 | put_ldev(mdev); |
| 4860 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4861 | dec_rs_pending(mdev); |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 4862 | atomic_add(blksize >> 9, &mdev->rs_sect_in); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4863 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4864 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4865 | } |
| 4866 | |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 4867 | static int |
| 4868 | validate_req_change_req_state(struct drbd_conf *mdev, u64 id, sector_t sector, |
| 4869 | struct rb_root *root, const char *func, |
| 4870 | enum drbd_req_event what, bool missing_ok) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4871 | { |
| 4872 | struct drbd_request *req; |
| 4873 | struct bio_and_error m; |
| 4874 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4875 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 4876 | req = find_request(mdev, root, id, sector, missing_ok, func); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4877 | if (unlikely(!req)) { |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4878 | spin_unlock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | 8599767 | 2011-04-04 13:09:15 +0200 | [diff] [blame] | 4879 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4880 | } |
| 4881 | __req_mod(req, what, &m); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4882 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4883 | |
| 4884 | if (m.bio) |
| 4885 | complete_master_bio(mdev, &m); |
Andreas Gruenbacher | 8599767 | 2011-04-04 13:09:15 +0200 | [diff] [blame] | 4886 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4889 | static int got_BlockAck(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4890 | { |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4891 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4892 | struct p_block_ack *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4893 | sector_t sector = be64_to_cpu(p->sector); |
| 4894 | int blksize = be32_to_cpu(p->blksize); |
| 4895 | enum drbd_req_event what; |
| 4896 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4897 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 4898 | if (!mdev) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4899 | return -EIO; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4900 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4901 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 4902 | |
Andreas Gruenbacher | 579b57e | 2011-01-13 18:40:57 +0100 | [diff] [blame] | 4903 | if (p->block_id == ID_SYNCER) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4904 | drbd_set_in_sync(mdev, sector, blksize); |
| 4905 | dec_rs_pending(mdev); |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4906 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4907 | } |
Andreas Gruenbacher | e05e1e5 | 2011-03-25 15:16:26 +0100 | [diff] [blame] | 4908 | switch (pi->cmd) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4909 | case P_RS_WRITE_ACK: |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 4910 | what = WRITE_ACKED_BY_PEER_AND_SIS; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4911 | break; |
| 4912 | case P_WRITE_ACK: |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 4913 | what = WRITE_ACKED_BY_PEER; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4914 | break; |
| 4915 | case P_RECV_ACK: |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 4916 | what = RECV_ACKED_BY_PEER; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4917 | break; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 4918 | case P_DISCARD_WRITE: |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 4919 | what = DISCARD_WRITE; |
| 4920 | break; |
| 4921 | case P_RETRY_WRITE: |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 4922 | what = POSTPONE_WRITE; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4923 | break; |
| 4924 | default: |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4925 | BUG(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4928 | return validate_req_change_req_state(mdev, p->block_id, sector, |
| 4929 | &mdev->write_requests, __func__, |
| 4930 | what, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4931 | } |
| 4932 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4933 | static int got_NegAck(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4934 | { |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4935 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4936 | struct p_block_ack *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4937 | sector_t sector = be64_to_cpu(p->sector); |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 4938 | int size = be32_to_cpu(p->blksize); |
Andreas Gruenbacher | 8599767 | 2011-04-04 13:09:15 +0200 | [diff] [blame] | 4939 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4940 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4941 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 4942 | if (!mdev) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4943 | return -EIO; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4944 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4945 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 4946 | |
Andreas Gruenbacher | 579b57e | 2011-01-13 18:40:57 +0100 | [diff] [blame] | 4947 | if (p->block_id == ID_SYNCER) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4948 | dec_rs_pending(mdev); |
| 4949 | drbd_rs_failed_io(mdev, sector, size); |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4950 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4951 | } |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 4952 | |
Andreas Gruenbacher | 8599767 | 2011-04-04 13:09:15 +0200 | [diff] [blame] | 4953 | err = validate_req_change_req_state(mdev, p->block_id, sector, |
| 4954 | &mdev->write_requests, __func__, |
Philipp Reisner | 303d144 | 2011-04-13 16:24:47 -0700 | [diff] [blame] | 4955 | NEG_ACKED, true); |
Andreas Gruenbacher | 8599767 | 2011-04-04 13:09:15 +0200 | [diff] [blame] | 4956 | if (err) { |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 4957 | /* Protocol A has no P_WRITE_ACKs, but has P_NEG_ACKs. |
| 4958 | The master bio might already be completed, therefore the |
| 4959 | request is no longer in the collision hash. */ |
| 4960 | /* In Protocol B we might already have got a P_RECV_ACK |
| 4961 | but then get a P_NEG_ACK afterwards. */ |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 4962 | drbd_set_out_of_sync(mdev, sector, size); |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 4963 | } |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4964 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4965 | } |
| 4966 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4967 | static int got_NegDReply(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4968 | { |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4969 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4970 | struct p_block_ack *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4971 | sector_t sector = be64_to_cpu(p->sector); |
| 4972 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4973 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 4974 | if (!mdev) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4975 | return -EIO; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4976 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4977 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 4978 | |
Philipp Reisner | 380207d | 2011-11-11 12:31:20 +0100 | [diff] [blame] | 4979 | dev_err(DEV, "Got NegDReply; Sector %llus, len %u.\n", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4980 | (unsigned long long)sector, be32_to_cpu(p->blksize)); |
| 4981 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4982 | return validate_req_change_req_state(mdev, p->block_id, sector, |
| 4983 | &mdev->read_requests, __func__, |
| 4984 | NEG_ACKED, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4985 | } |
| 4986 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4987 | static int got_NegRSDReply(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4988 | { |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4989 | struct drbd_conf *mdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4990 | sector_t sector; |
| 4991 | int size; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 4992 | struct p_block_ack *p = pi->data; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 4993 | |
| 4994 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 4995 | if (!mdev) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 4996 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4997 | |
| 4998 | sector = be64_to_cpu(p->sector); |
| 4999 | size = be32_to_cpu(p->blksize); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5000 | |
| 5001 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 5002 | |
| 5003 | dec_rs_pending(mdev); |
| 5004 | |
| 5005 | if (get_ldev_if_state(mdev, D_FAILED)) { |
| 5006 | drbd_rs_complete_io(mdev, sector); |
Andreas Gruenbacher | e05e1e5 | 2011-03-25 15:16:26 +0100 | [diff] [blame] | 5007 | switch (pi->cmd) { |
Philipp Reisner | d612d30 | 2010-12-27 10:53:28 +0100 | [diff] [blame] | 5008 | case P_NEG_RS_DREPLY: |
| 5009 | drbd_rs_failed_io(mdev, sector, size); |
| 5010 | case P_RS_CANCEL: |
| 5011 | break; |
| 5012 | default: |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5013 | BUG(); |
Philipp Reisner | d612d30 | 2010-12-27 10:53:28 +0100 | [diff] [blame] | 5014 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5015 | put_ldev(mdev); |
| 5016 | } |
| 5017 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5018 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5021 | static int got_BarrierAck(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5022 | { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5023 | struct p_barrier_ack *p = pi->data; |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 5024 | struct drbd_conf *mdev; |
| 5025 | int vnr; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5026 | |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 5027 | tl_release(tconn, p->barrier, be32_to_cpu(p->set_size)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5028 | |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 5029 | rcu_read_lock(); |
| 5030 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
| 5031 | if (mdev->state.conn == C_AHEAD && |
| 5032 | atomic_read(&mdev->ap_in_flight) == 0 && |
| 5033 | !test_and_set_bit(AHEAD_TO_SYNC_SOURCE, &mdev->flags)) { |
| 5034 | mdev->start_resync_timer.expires = jiffies + HZ; |
| 5035 | add_timer(&mdev->start_resync_timer); |
| 5036 | } |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 5037 | } |
Lars Ellenberg | 9ed57dc | 2012-03-26 20:55:17 +0200 | [diff] [blame] | 5038 | rcu_read_unlock(); |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 5039 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5040 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5041 | } |
| 5042 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5043 | static int got_OVResult(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5044 | { |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5045 | struct drbd_conf *mdev; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5046 | struct p_block_ack *p = pi->data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5047 | struct drbd_work *w; |
| 5048 | sector_t sector; |
| 5049 | int size; |
| 5050 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5051 | mdev = vnr_to_mdev(tconn, pi->vnr); |
| 5052 | if (!mdev) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5053 | return -EIO; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5054 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5055 | sector = be64_to_cpu(p->sector); |
| 5056 | size = be32_to_cpu(p->blksize); |
| 5057 | |
| 5058 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 5059 | |
| 5060 | if (be64_to_cpu(p->block_id) == ID_OUT_OF_SYNC) |
Andreas Gruenbacher | 8f7bed7 | 2010-12-19 23:53:14 +0100 | [diff] [blame] | 5061 | drbd_ov_out_of_sync_found(mdev, sector, size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5062 | else |
Andreas Gruenbacher | 8f7bed7 | 2010-12-19 23:53:14 +0100 | [diff] [blame] | 5063 | ov_out_of_sync_print(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5064 | |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 5065 | if (!get_ldev(mdev)) |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5066 | return 0; |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 5067 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5068 | drbd_rs_complete_io(mdev, sector); |
| 5069 | dec_rs_pending(mdev); |
| 5070 | |
Lars Ellenberg | ea5442a | 2010-11-05 09:48:01 +0100 | [diff] [blame] | 5071 | --mdev->ov_left; |
| 5072 | |
| 5073 | /* let's advance progress step marks only for every other megabyte */ |
| 5074 | if ((mdev->ov_left & 0x200) == 0x200) |
| 5075 | drbd_advance_rs_marks(mdev, mdev->ov_left); |
| 5076 | |
| 5077 | if (mdev->ov_left == 0) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5078 | w = kmalloc(sizeof(*w), GFP_NOIO); |
| 5079 | if (w) { |
| 5080 | w->cb = w_ov_finished; |
Philipp Reisner | a21e929 | 2011-02-08 15:08:49 +0100 | [diff] [blame] | 5081 | w->mdev = mdev; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 5082 | drbd_queue_work_front(&mdev->tconn->data.work, w); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5083 | } else { |
| 5084 | dev_err(DEV, "kmalloc(w) failed."); |
Andreas Gruenbacher | 8f7bed7 | 2010-12-19 23:53:14 +0100 | [diff] [blame] | 5085 | ov_out_of_sync_print(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5086 | drbd_resync_finished(mdev); |
| 5087 | } |
| 5088 | } |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 5089 | put_ldev(mdev); |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5090 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5091 | } |
| 5092 | |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5093 | static int got_skip(struct drbd_tconn *tconn, struct packet_info *pi) |
Philipp Reisner | 0ced55a | 2010-04-30 15:26:20 +0200 | [diff] [blame] | 5094 | { |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5095 | return 0; |
Philipp Reisner | 0ced55a | 2010-04-30 15:26:20 +0200 | [diff] [blame] | 5096 | } |
| 5097 | |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 5098 | static int tconn_finish_peer_reqs(struct drbd_tconn *tconn) |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5099 | { |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 5100 | struct drbd_conf *mdev; |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5101 | int vnr, not_empty = 0; |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5102 | |
| 5103 | do { |
| 5104 | clear_bit(SIGNAL_ASENDER, &tconn->flags); |
| 5105 | flush_signals(current); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5106 | |
| 5107 | rcu_read_lock(); |
| 5108 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
| 5109 | kref_get(&mdev->kref); |
| 5110 | rcu_read_unlock(); |
Philipp Reisner | d3fcb49 | 2011-04-13 14:46:05 -0700 | [diff] [blame] | 5111 | if (drbd_finish_peer_reqs(mdev)) { |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5112 | kref_put(&mdev->kref, &drbd_minor_destroy); |
| 5113 | return 1; |
Philipp Reisner | d3fcb49 | 2011-04-13 14:46:05 -0700 | [diff] [blame] | 5114 | } |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5115 | kref_put(&mdev->kref, &drbd_minor_destroy); |
| 5116 | rcu_read_lock(); |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 5117 | } |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5118 | set_bit(SIGNAL_ASENDER, &tconn->flags); |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 5119 | |
| 5120 | spin_lock_irq(&tconn->req_lock); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5121 | idr_for_each_entry(&tconn->volumes, mdev, vnr) { |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 5122 | not_empty = !list_empty(&mdev->done_ee); |
| 5123 | if (not_empty) |
| 5124 | break; |
| 5125 | } |
| 5126 | spin_unlock_irq(&tconn->req_lock); |
Philipp Reisner | c141ebd | 2011-05-05 16:13:10 +0200 | [diff] [blame] | 5127 | rcu_read_unlock(); |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5128 | } while (not_empty); |
| 5129 | |
| 5130 | return 0; |
| 5131 | } |
| 5132 | |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 5133 | struct asender_cmd { |
| 5134 | size_t pkt_size; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5135 | int (*fn)(struct drbd_tconn *tconn, struct packet_info *); |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 5136 | }; |
| 5137 | |
| 5138 | static struct asender_cmd asender_tbl[] = { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5139 | [P_PING] = { 0, got_Ping }, |
| 5140 | [P_PING_ACK] = { 0, got_PingAck }, |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5141 | [P_RECV_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 5142 | [P_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 5143 | [P_RS_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 5144 | [P_DISCARD_WRITE] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 5145 | [P_NEG_ACK] = { sizeof(struct p_block_ack), got_NegAck }, |
| 5146 | [P_NEG_DREPLY] = { sizeof(struct p_block_ack), got_NegDReply }, |
| 5147 | [P_NEG_RS_DREPLY] = { sizeof(struct p_block_ack), got_NegRSDReply }, |
| 5148 | [P_OV_RESULT] = { sizeof(struct p_block_ack), got_OVResult }, |
| 5149 | [P_BARRIER_ACK] = { sizeof(struct p_barrier_ack), got_BarrierAck }, |
| 5150 | [P_STATE_CHG_REPLY] = { sizeof(struct p_req_state_reply), got_RqSReply }, |
| 5151 | [P_RS_IS_IN_SYNC] = { sizeof(struct p_block_ack), got_IsInSync }, |
| 5152 | [P_DELAY_PROBE] = { sizeof(struct p_delay_probe93), got_skip }, |
| 5153 | [P_RS_CANCEL] = { sizeof(struct p_block_ack), got_NegRSDReply }, |
| 5154 | [P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), got_conn_RqSReply }, |
| 5155 | [P_RETRY_WRITE] = { sizeof(struct p_block_ack), got_BlockAck }, |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 5156 | }; |
| 5157 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5158 | int drbd_asender(struct drbd_thread *thi) |
| 5159 | { |
Philipp Reisner | 392c880 | 2011-02-09 10:33:31 +0100 | [diff] [blame] | 5160 | struct drbd_tconn *tconn = thi->tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5161 | struct asender_cmd *cmd = NULL; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 5162 | struct packet_info pi; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 5163 | int rv; |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5164 | void *buf = tconn->meta.rbuf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5165 | int received = 0; |
Andreas Gruenbacher | 52b061a | 2011-03-30 11:38:49 +0200 | [diff] [blame] | 5166 | unsigned int header_size = drbd_header_size(tconn); |
| 5167 | int expect = header_size; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5168 | bool ping_timeout_active = false; |
| 5169 | struct net_conf *nc; |
Andreas Gruenbacher | bb77d34 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 5170 | int ping_timeo, tcp_cork, ping_int; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5171 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5172 | current->policy = SCHED_RR; /* Make this a realtime task! */ |
| 5173 | current->rt_priority = 2; /* more important than all other tasks */ |
| 5174 | |
Andreas Gruenbacher | e77a0a5 | 2011-01-25 15:43:39 +0100 | [diff] [blame] | 5175 | while (get_t_state(thi) == RUNNING) { |
Philipp Reisner | 8082228 | 2011-02-08 12:46:30 +0100 | [diff] [blame] | 5176 | drbd_thread_current_set_cpu(thi); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5177 | |
| 5178 | rcu_read_lock(); |
| 5179 | nc = rcu_dereference(tconn->net_conf); |
| 5180 | ping_timeo = nc->ping_timeo; |
Andreas Gruenbacher | bb77d34 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 5181 | tcp_cork = nc->tcp_cork; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5182 | ping_int = nc->ping_int; |
| 5183 | rcu_read_unlock(); |
| 5184 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5185 | if (test_and_clear_bit(SEND_PING, &tconn->flags)) { |
Andreas Gruenbacher | a17647a | 2011-04-01 12:49:42 +0200 | [diff] [blame] | 5186 | if (drbd_send_ping(tconn)) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5187 | conn_err(tconn, "drbd_send_ping has failed\n"); |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 5188 | goto reconnect; |
| 5189 | } |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5190 | tconn->meta.socket->sk->sk_rcvtimeo = ping_timeo * HZ / 10; |
| 5191 | ping_timeout_active = true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5192 | } |
| 5193 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5194 | /* TODO: conditionally cork; it may hurt latency if we cork without |
| 5195 | much to send */ |
Andreas Gruenbacher | bb77d34 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 5196 | if (tcp_cork) |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5197 | drbd_tcp_cork(tconn->meta.socket); |
Andreas Gruenbacher | a990be4 | 2011-04-06 17:56:48 +0200 | [diff] [blame] | 5198 | if (tconn_finish_peer_reqs(tconn)) { |
| 5199 | conn_err(tconn, "tconn_finish_peer_reqs() failed\n"); |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5200 | goto reconnect; |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 5201 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5202 | /* but unconditionally uncork unless disabled */ |
Andreas Gruenbacher | bb77d34 | 2011-05-04 15:25:35 +0200 | [diff] [blame] | 5203 | if (tcp_cork) |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5204 | drbd_tcp_uncork(tconn->meta.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5205 | |
| 5206 | /* short circuit, recv_msg would return EINTR anyways. */ |
| 5207 | if (signal_pending(current)) |
| 5208 | continue; |
| 5209 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5210 | rv = drbd_recv_short(tconn->meta.socket, buf, expect-received, 0); |
| 5211 | clear_bit(SIGNAL_ASENDER, &tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5212 | |
| 5213 | flush_signals(current); |
| 5214 | |
| 5215 | /* Note: |
| 5216 | * -EINTR (on meta) we got a signal |
| 5217 | * -EAGAIN (on meta) rcvtimeo expired |
| 5218 | * -ECONNRESET other side closed the connection |
| 5219 | * -ERESTARTSYS (on data) we got a signal |
| 5220 | * rv < 0 other than above: unexpected error! |
| 5221 | * rv == expected: full header or command |
| 5222 | * rv < expected: "woken" by signal during receive |
| 5223 | * rv == 0 : "connection shut down by peer" |
| 5224 | */ |
| 5225 | if (likely(rv > 0)) { |
| 5226 | received += rv; |
| 5227 | buf += rv; |
| 5228 | } else if (rv == 0) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5229 | conn_err(tconn, "meta connection shut down by peer.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5230 | goto reconnect; |
| 5231 | } else if (rv == -EAGAIN) { |
Lars Ellenberg | cb6518c | 2011-06-20 14:44:45 +0200 | [diff] [blame] | 5232 | /* If the data socket received something meanwhile, |
| 5233 | * that is good enough: peer is still alive. */ |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5234 | if (time_after(tconn->last_received, |
| 5235 | jiffies - tconn->meta.socket->sk->sk_rcvtimeo)) |
Lars Ellenberg | cb6518c | 2011-06-20 14:44:45 +0200 | [diff] [blame] | 5236 | continue; |
Lars Ellenberg | f36af18 | 2011-03-09 22:44:55 +0100 | [diff] [blame] | 5237 | if (ping_timeout_active) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5238 | conn_err(tconn, "PingAck did not arrive in time.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5239 | goto reconnect; |
| 5240 | } |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5241 | set_bit(SEND_PING, &tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5242 | continue; |
| 5243 | } else if (rv == -EINTR) { |
| 5244 | continue; |
| 5245 | } else { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5246 | conn_err(tconn, "sock_recvmsg returned %d\n", rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5247 | goto reconnect; |
| 5248 | } |
| 5249 | |
| 5250 | if (received == expect && cmd == NULL) { |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5251 | if (decode_header(tconn, tconn->meta.rbuf, &pi)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5252 | goto reconnect; |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 5253 | cmd = &asender_tbl[pi.cmd]; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5254 | if (pi.cmd >= ARRAY_SIZE(asender_tbl) || !cmd->fn) { |
Andreas Gruenbacher | 2fcb8f3 | 2011-07-03 11:41:08 +0200 | [diff] [blame] | 5255 | conn_err(tconn, "Unexpected meta packet %s (0x%04x)\n", |
| 5256 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5257 | goto disconnect; |
| 5258 | } |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5259 | expect = header_size + cmd->pkt_size; |
Andreas Gruenbacher | 52b061a | 2011-03-30 11:38:49 +0200 | [diff] [blame] | 5260 | if (pi.size != expect - header_size) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5261 | conn_err(tconn, "Wrong packet size on meta (c: %d, l: %d)\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 5262 | pi.cmd, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5263 | goto reconnect; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 5264 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5265 | } |
| 5266 | if (received == expect) { |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5267 | bool err; |
Philipp Reisner | a4fbda8 | 2011-03-16 11:13:17 +0100 | [diff] [blame] | 5268 | |
Andreas Gruenbacher | 2735a59 | 2011-04-04 15:30:24 +0200 | [diff] [blame] | 5269 | err = cmd->fn(tconn, &pi); |
| 5270 | if (err) { |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5271 | conn_err(tconn, "%pf failed\n", cmd->fn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5272 | goto reconnect; |
Andreas Gruenbacher | 1952e91 | 2011-03-25 15:37:43 +0100 | [diff] [blame] | 5273 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5274 | |
Philipp Reisner | a4fbda8 | 2011-03-16 11:13:17 +0100 | [diff] [blame] | 5275 | tconn->last_received = jiffies; |
| 5276 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 5277 | if (cmd == &asender_tbl[P_PING_ACK]) { |
| 5278 | /* restore idle timeout */ |
| 5279 | tconn->meta.socket->sk->sk_rcvtimeo = ping_int * HZ; |
| 5280 | ping_timeout_active = false; |
| 5281 | } |
Lars Ellenberg | f36af18 | 2011-03-09 22:44:55 +0100 | [diff] [blame] | 5282 | |
Andreas Gruenbacher | e658983 | 2011-03-30 12:54:42 +0200 | [diff] [blame] | 5283 | buf = tconn->meta.rbuf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5284 | received = 0; |
Andreas Gruenbacher | 52b061a | 2011-03-30 11:38:49 +0200 | [diff] [blame] | 5285 | expect = header_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5286 | cmd = NULL; |
| 5287 | } |
| 5288 | } |
| 5289 | |
| 5290 | if (0) { |
| 5291 | reconnect: |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 5292 | conn_request_state(tconn, NS(conn, C_NETWORK_FAILURE), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5293 | } |
| 5294 | if (0) { |
| 5295 | disconnect: |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 5296 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5297 | } |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5298 | clear_bit(SIGNAL_ASENDER, &tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5299 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 5300 | conn_info(tconn, "asender terminated\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 5301 | |
| 5302 | return 0; |
| 5303 | } |