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; |
| 53 | int size; |
| 54 | int vnr; |
| 55 | }; |
| 56 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 57 | enum finish_epoch { |
| 58 | FE_STILL_LIVE, |
| 59 | FE_DESTROYED, |
| 60 | FE_RECYCLED, |
| 61 | }; |
| 62 | |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 63 | static int drbd_do_handshake(struct drbd_tconn *tconn); |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 64 | static int drbd_do_auth(struct drbd_tconn *tconn); |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 65 | static int drbd_disconnected(int vnr, void *p, void *data); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 66 | |
| 67 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *, struct drbd_epoch *, enum epoch_event); |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 68 | static int e_end_block(struct drbd_work *, int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 69 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 70 | |
| 71 | #define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN) |
| 72 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 73 | /* |
| 74 | * some helper functions to deal with single linked page lists, |
| 75 | * page->private being our "next" pointer. |
| 76 | */ |
| 77 | |
| 78 | /* If at least n pages are linked at head, get n pages off. |
| 79 | * Otherwise, don't modify head, and return NULL. |
| 80 | * Locking is the responsibility of the caller. |
| 81 | */ |
| 82 | static struct page *page_chain_del(struct page **head, int n) |
| 83 | { |
| 84 | struct page *page; |
| 85 | struct page *tmp; |
| 86 | |
| 87 | BUG_ON(!n); |
| 88 | BUG_ON(!head); |
| 89 | |
| 90 | page = *head; |
Philipp Reisner | 23ce422 | 2010-05-20 13:35:31 +0200 | [diff] [blame] | 91 | |
| 92 | if (!page) |
| 93 | return NULL; |
| 94 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 95 | while (page) { |
| 96 | tmp = page_chain_next(page); |
| 97 | if (--n == 0) |
| 98 | break; /* found sufficient pages */ |
| 99 | if (tmp == NULL) |
| 100 | /* insufficient pages, don't use any of them. */ |
| 101 | return NULL; |
| 102 | page = tmp; |
| 103 | } |
| 104 | |
| 105 | /* add end of list marker for the returned list */ |
| 106 | set_page_private(page, 0); |
| 107 | /* actual return value, and adjustment of head */ |
| 108 | page = *head; |
| 109 | *head = tmp; |
| 110 | return page; |
| 111 | } |
| 112 | |
| 113 | /* may be used outside of locks to find the tail of a (usually short) |
| 114 | * "private" page chain, before adding it back to a global chain head |
| 115 | * with page_chain_add() under a spinlock. */ |
| 116 | static struct page *page_chain_tail(struct page *page, int *len) |
| 117 | { |
| 118 | struct page *tmp; |
| 119 | int i = 1; |
| 120 | while ((tmp = page_chain_next(page))) |
| 121 | ++i, page = tmp; |
| 122 | if (len) |
| 123 | *len = i; |
| 124 | return page; |
| 125 | } |
| 126 | |
| 127 | static int page_chain_free(struct page *page) |
| 128 | { |
| 129 | struct page *tmp; |
| 130 | int i = 0; |
| 131 | page_chain_for_each_safe(page, tmp) { |
| 132 | put_page(page); |
| 133 | ++i; |
| 134 | } |
| 135 | return i; |
| 136 | } |
| 137 | |
| 138 | static void page_chain_add(struct page **head, |
| 139 | struct page *chain_first, struct page *chain_last) |
| 140 | { |
| 141 | #if 1 |
| 142 | struct page *tmp; |
| 143 | tmp = page_chain_tail(chain_first, NULL); |
| 144 | BUG_ON(tmp != chain_last); |
| 145 | #endif |
| 146 | |
| 147 | /* add chain to head */ |
| 148 | set_page_private(chain_last, (unsigned long)*head); |
| 149 | *head = chain_first; |
| 150 | } |
| 151 | |
| 152 | static struct page *drbd_pp_first_pages_or_try_alloc(struct drbd_conf *mdev, int number) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 153 | { |
| 154 | struct page *page = NULL; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 155 | struct page *tmp = NULL; |
| 156 | int i = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 157 | |
| 158 | /* Yes, testing drbd_pp_vacant outside the lock is racy. |
| 159 | * So what. It saves a spin_lock. */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 160 | if (drbd_pp_vacant >= number) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 161 | spin_lock(&drbd_pp_lock); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 162 | page = page_chain_del(&drbd_pp_pool, number); |
| 163 | if (page) |
| 164 | drbd_pp_vacant -= number; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 165 | spin_unlock(&drbd_pp_lock); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 166 | if (page) |
| 167 | return page; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 168 | } |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 169 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 170 | /* GFP_TRY, because we must not cause arbitrary write-out: in a DRBD |
| 171 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
| 172 | * 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] | 173 | for (i = 0; i < number; i++) { |
| 174 | tmp = alloc_page(GFP_TRY); |
| 175 | if (!tmp) |
| 176 | break; |
| 177 | set_page_private(tmp, (unsigned long)page); |
| 178 | page = tmp; |
| 179 | } |
| 180 | |
| 181 | if (i == number) |
| 182 | return page; |
| 183 | |
| 184 | /* Not enough pages immediately available this time. |
| 185 | * No need to jump around here, drbd_pp_alloc will retry this |
| 186 | * function "soon". */ |
| 187 | if (page) { |
| 188 | tmp = page_chain_tail(page, NULL); |
| 189 | spin_lock(&drbd_pp_lock); |
| 190 | page_chain_add(&drbd_pp_pool, page, tmp); |
| 191 | drbd_pp_vacant += i; |
| 192 | spin_unlock(&drbd_pp_lock); |
| 193 | } |
| 194 | return NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 197 | static void reclaim_net_ee(struct drbd_conf *mdev, struct list_head *to_be_freed) |
| 198 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 199 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 200 | struct list_head *le, *tle; |
| 201 | |
| 202 | /* The EEs are always appended to the end of the list. Since |
| 203 | they are sent in order over the wire, they have to finish |
| 204 | in order. As soon as we see the first not finished we can |
| 205 | stop to examine the list... */ |
| 206 | |
| 207 | list_for_each_safe(le, tle, &mdev->net_ee) { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 208 | peer_req = list_entry(le, struct drbd_peer_request, w.list); |
| 209 | if (drbd_ee_has_active_page(peer_req)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 210 | break; |
| 211 | list_move(le, to_be_freed); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | static void drbd_kick_lo_and_reclaim_net(struct drbd_conf *mdev) |
| 216 | { |
| 217 | LIST_HEAD(reclaimed); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 218 | struct drbd_peer_request *peer_req, *t; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 219 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 220 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 221 | reclaim_net_ee(mdev, &reclaimed); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 222 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 223 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 224 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) |
| 225 | drbd_free_net_ee(mdev, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /** |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 229 | * drbd_pp_alloc() - Returns @number pages, retries forever (or until signalled) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 230 | * @mdev: DRBD device. |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 231 | * @number: number of pages requested |
| 232 | * @retry: whether to retry, if not enough pages are available right now |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 233 | * |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 234 | * Tries to allocate number pages, first from our own page pool, then from |
| 235 | * the kernel, unless this allocation would exceed the max_buffers setting. |
| 236 | * Possibly retry until DRBD frees sufficient pages somewhere else. |
| 237 | * |
| 238 | * Returns a page chain linked via page->private. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 239 | */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 240 | static struct page *drbd_pp_alloc(struct drbd_conf *mdev, unsigned number, bool retry) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 241 | { |
| 242 | struct page *page = NULL; |
| 243 | DEFINE_WAIT(wait); |
| 244 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 245 | /* Yes, we may run up to @number over max_buffers. If we |
| 246 | * follow it strictly, the admin will get it wrong anyways. */ |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 247 | if (atomic_read(&mdev->pp_in_use) < mdev->tconn->net_conf->max_buffers) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 248 | page = drbd_pp_first_pages_or_try_alloc(mdev, number); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 249 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 250 | while (page == NULL) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 251 | prepare_to_wait(&drbd_pp_wait, &wait, TASK_INTERRUPTIBLE); |
| 252 | |
| 253 | drbd_kick_lo_and_reclaim_net(mdev); |
| 254 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 255 | if (atomic_read(&mdev->pp_in_use) < mdev->tconn->net_conf->max_buffers) { |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 256 | page = drbd_pp_first_pages_or_try_alloc(mdev, number); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 257 | if (page) |
| 258 | break; |
| 259 | } |
| 260 | |
| 261 | if (!retry) |
| 262 | break; |
| 263 | |
| 264 | if (signal_pending(current)) { |
| 265 | dev_warn(DEV, "drbd_pp_alloc interrupted!\n"); |
| 266 | break; |
| 267 | } |
| 268 | |
| 269 | schedule(); |
| 270 | } |
| 271 | finish_wait(&drbd_pp_wait, &wait); |
| 272 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 273 | if (page) |
| 274 | atomic_add(number, &mdev->pp_in_use); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 275 | return page; |
| 276 | } |
| 277 | |
| 278 | /* Must not be used from irq, as that may deadlock: see drbd_pp_alloc. |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 279 | * 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] | 280 | * Either links the page chain back to the global pool, |
| 281 | * or returns all pages to the system. */ |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 282 | static void drbd_pp_free(struct drbd_conf *mdev, struct page *page, int is_net) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 283 | { |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 284 | 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] | 285 | int i; |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 286 | |
Philipp Reisner | 81a5d60 | 2011-02-22 19:53:16 -0500 | [diff] [blame] | 287 | if (drbd_pp_vacant > (DRBD_MAX_BIO_SIZE/PAGE_SIZE) * minor_count) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 288 | i = page_chain_free(page); |
| 289 | else { |
| 290 | struct page *tmp; |
| 291 | tmp = page_chain_tail(page, &i); |
| 292 | spin_lock(&drbd_pp_lock); |
| 293 | page_chain_add(&drbd_pp_pool, page, tmp); |
| 294 | drbd_pp_vacant += i; |
| 295 | spin_unlock(&drbd_pp_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 296 | } |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 297 | i = atomic_sub_return(i, a); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 298 | if (i < 0) |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 299 | dev_warn(DEV, "ASSERTION FAILED: %s: %d < 0\n", |
| 300 | is_net ? "pp_in_use_by_net" : "pp_in_use", i); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 301 | wake_up(&drbd_pp_wait); |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | You need to hold the req_lock: |
| 306 | _drbd_wait_ee_list_empty() |
| 307 | |
| 308 | You must not have the req_lock: |
| 309 | drbd_free_ee() |
| 310 | drbd_alloc_ee() |
| 311 | drbd_init_ee() |
| 312 | drbd_release_ee() |
| 313 | drbd_ee_fix_bhs() |
| 314 | drbd_process_done_ee() |
| 315 | drbd_clear_done_ee() |
| 316 | drbd_wait_ee_list_empty() |
| 317 | */ |
| 318 | |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 319 | struct drbd_peer_request * |
| 320 | drbd_alloc_ee(struct drbd_conf *mdev, u64 id, sector_t sector, |
| 321 | unsigned int data_size, gfp_t gfp_mask) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 322 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 323 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 324 | struct page *page; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 325 | unsigned nr_pages = (data_size + PAGE_SIZE -1) >> PAGE_SHIFT; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 326 | |
Andreas Gruenbacher | 0cf9d27 | 2010-12-07 10:43:29 +0100 | [diff] [blame] | 327 | if (drbd_insert_fault(mdev, DRBD_FAULT_AL_EE)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 328 | return NULL; |
| 329 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 330 | peer_req = mempool_alloc(drbd_ee_mempool, gfp_mask & ~__GFP_HIGHMEM); |
| 331 | if (!peer_req) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 332 | if (!(gfp_mask & __GFP_NOWARN)) |
| 333 | dev_err(DEV, "alloc_ee: Allocation of an EE failed\n"); |
| 334 | return NULL; |
| 335 | } |
| 336 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 337 | page = drbd_pp_alloc(mdev, nr_pages, (gfp_mask & __GFP_WAIT)); |
| 338 | if (!page) |
| 339 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 340 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 341 | drbd_clear_interval(&peer_req->i); |
| 342 | peer_req->i.size = data_size; |
| 343 | peer_req->i.sector = sector; |
| 344 | peer_req->i.local = false; |
| 345 | peer_req->i.waiting = false; |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 346 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 347 | peer_req->epoch = NULL; |
Philipp Reisner | a21e929 | 2011-02-08 15:08:49 +0100 | [diff] [blame] | 348 | peer_req->w.mdev = mdev; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 349 | peer_req->pages = page; |
| 350 | atomic_set(&peer_req->pending_bios, 0); |
| 351 | peer_req->flags = 0; |
Andreas Gruenbacher | 9a8e775 | 2011-01-11 14:04:09 +0100 | [diff] [blame] | 352 | /* |
| 353 | * The block_id is opaque to the receiver. It is not endianness |
| 354 | * converted, and sent back to the sender unchanged. |
| 355 | */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 356 | peer_req->block_id = id; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 357 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 358 | return peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 359 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 360 | fail: |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 361 | mempool_free(peer_req, drbd_ee_mempool); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 362 | return NULL; |
| 363 | } |
| 364 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 365 | void drbd_free_some_ee(struct drbd_conf *mdev, struct drbd_peer_request *peer_req, |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 366 | int is_net) |
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 | if (peer_req->flags & EE_HAS_DIGEST) |
| 369 | kfree(peer_req->digest); |
| 370 | drbd_pp_free(mdev, peer_req->pages, is_net); |
| 371 | D_ASSERT(atomic_read(&peer_req->pending_bios) == 0); |
| 372 | D_ASSERT(drbd_interval_empty(&peer_req->i)); |
| 373 | mempool_free(peer_req, drbd_ee_mempool); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | int drbd_release_ee(struct drbd_conf *mdev, struct list_head *list) |
| 377 | { |
| 378 | LIST_HEAD(work_list); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 379 | struct drbd_peer_request *peer_req, *t; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 380 | int count = 0; |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 381 | int is_net = list == &mdev->net_ee; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 382 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 383 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 384 | list_splice_init(list, &work_list); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 385 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 386 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 387 | list_for_each_entry_safe(peer_req, t, &work_list, w.list) { |
| 388 | drbd_free_some_ee(mdev, peer_req, is_net); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 389 | count++; |
| 390 | } |
| 391 | return count; |
| 392 | } |
| 393 | |
| 394 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 395 | /* See also comments in _req_mod(,BARRIER_ACKED) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 396 | * and receive_Barrier. |
| 397 | * |
| 398 | * Move entries from net_ee to done_ee, if ready. |
| 399 | * Grab done_ee, call all callbacks, free the entries. |
| 400 | * The callbacks typically send out ACKs. |
| 401 | */ |
| 402 | static int drbd_process_done_ee(struct drbd_conf *mdev) |
| 403 | { |
| 404 | LIST_HEAD(work_list); |
| 405 | LIST_HEAD(reclaimed); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 406 | struct drbd_peer_request *peer_req, *t; |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 407 | int ok = 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 408 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 409 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 410 | reclaim_net_ee(mdev, &reclaimed); |
| 411 | list_splice_init(&mdev->done_ee, &work_list); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 412 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 413 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 414 | list_for_each_entry_safe(peer_req, t, &reclaimed, w.list) |
| 415 | drbd_free_net_ee(mdev, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 416 | |
| 417 | /* possible callbacks here: |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 418 | * e_end_block, and e_end_resync_block, e_send_discard_write. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 419 | * all ignore the last argument. |
| 420 | */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 421 | list_for_each_entry_safe(peer_req, t, &work_list, w.list) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 422 | /* list_del not necessary, next/prev members not touched */ |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 423 | ok = peer_req->w.cb(&peer_req->w, !ok) && ok; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 424 | drbd_free_ee(mdev, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 425 | } |
| 426 | wake_up(&mdev->ee_wait); |
| 427 | |
| 428 | return ok; |
| 429 | } |
| 430 | |
| 431 | void _drbd_wait_ee_list_empty(struct drbd_conf *mdev, struct list_head *head) |
| 432 | { |
| 433 | DEFINE_WAIT(wait); |
| 434 | |
| 435 | /* avoids spin_lock/unlock |
| 436 | * and calling prepare_to_wait in the fast path */ |
| 437 | while (!list_empty(head)) { |
| 438 | prepare_to_wait(&mdev->ee_wait, &wait, TASK_UNINTERRUPTIBLE); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 439 | spin_unlock_irq(&mdev->tconn->req_lock); |
Jens Axboe | 7eaceac | 2011-03-10 08:52:07 +0100 | [diff] [blame] | 440 | io_schedule(); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 441 | finish_wait(&mdev->ee_wait, &wait); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 442 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
| 446 | void drbd_wait_ee_list_empty(struct drbd_conf *mdev, struct list_head *head) |
| 447 | { |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 448 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 449 | _drbd_wait_ee_list_empty(mdev, head); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 450 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /* see also kernel_accept; which is only present since 2.6.18. |
| 454 | * also we want to log which part of it failed, exactly */ |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 455 | static int drbd_accept(const char **what, struct socket *sock, struct socket **newsock) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 456 | { |
| 457 | struct sock *sk = sock->sk; |
| 458 | int err = 0; |
| 459 | |
| 460 | *what = "listen"; |
| 461 | err = sock->ops->listen(sock, 5); |
| 462 | if (err < 0) |
| 463 | goto out; |
| 464 | |
| 465 | *what = "sock_create_lite"; |
| 466 | err = sock_create_lite(sk->sk_family, sk->sk_type, sk->sk_protocol, |
| 467 | newsock); |
| 468 | if (err < 0) |
| 469 | goto out; |
| 470 | |
| 471 | *what = "accept"; |
| 472 | err = sock->ops->accept(sock, *newsock, 0); |
| 473 | if (err < 0) { |
| 474 | sock_release(*newsock); |
| 475 | *newsock = NULL; |
| 476 | goto out; |
| 477 | } |
| 478 | (*newsock)->ops = sock->ops; |
| 479 | |
| 480 | out: |
| 481 | return err; |
| 482 | } |
| 483 | |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 484 | 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] | 485 | { |
| 486 | mm_segment_t oldfs; |
| 487 | struct kvec iov = { |
| 488 | .iov_base = buf, |
| 489 | .iov_len = size, |
| 490 | }; |
| 491 | struct msghdr msg = { |
| 492 | .msg_iovlen = 1, |
| 493 | .msg_iov = (struct iovec *)&iov, |
| 494 | .msg_flags = (flags ? flags : MSG_WAITALL | MSG_NOSIGNAL) |
| 495 | }; |
| 496 | int rv; |
| 497 | |
| 498 | oldfs = get_fs(); |
| 499 | set_fs(KERNEL_DS); |
| 500 | rv = sock_recvmsg(sock, &msg, size, msg.msg_flags); |
| 501 | set_fs(oldfs); |
| 502 | |
| 503 | return rv; |
| 504 | } |
| 505 | |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 506 | 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] | 507 | { |
| 508 | mm_segment_t oldfs; |
| 509 | struct kvec iov = { |
| 510 | .iov_base = buf, |
| 511 | .iov_len = size, |
| 512 | }; |
| 513 | struct msghdr msg = { |
| 514 | .msg_iovlen = 1, |
| 515 | .msg_iov = (struct iovec *)&iov, |
| 516 | .msg_flags = MSG_WAITALL | MSG_NOSIGNAL |
| 517 | }; |
| 518 | int rv; |
| 519 | |
| 520 | oldfs = get_fs(); |
| 521 | set_fs(KERNEL_DS); |
| 522 | |
| 523 | for (;;) { |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 524 | rv = sock_recvmsg(tconn->data.socket, &msg, size, msg.msg_flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 525 | if (rv == size) |
| 526 | break; |
| 527 | |
| 528 | /* Note: |
| 529 | * ECONNRESET other side closed the connection |
| 530 | * ERESTARTSYS (on sock) we got a signal |
| 531 | */ |
| 532 | |
| 533 | if (rv < 0) { |
| 534 | if (rv == -ECONNRESET) |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 535 | conn_info(tconn, "sock was reset by peer\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 536 | else if (rv != -ERESTARTSYS) |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 537 | conn_err(tconn, "sock_recvmsg returned %d\n", rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 538 | break; |
| 539 | } else if (rv == 0) { |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 540 | conn_info(tconn, "sock was shut down by peer\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 541 | break; |
| 542 | } else { |
| 543 | /* signal came in, or peer/link went down, |
| 544 | * after we read a partial message |
| 545 | */ |
| 546 | /* D_ASSERT(signal_pending(current)); */ |
| 547 | break; |
| 548 | } |
| 549 | }; |
| 550 | |
| 551 | set_fs(oldfs); |
| 552 | |
| 553 | if (rv != size) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 554 | conn_request_state(tconn, NS(conn, C_BROKEN_PIPE), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 555 | |
| 556 | return rv; |
| 557 | } |
| 558 | |
Lars Ellenberg | 5dbf167 | 2010-05-25 16:18:01 +0200 | [diff] [blame] | 559 | /* quoting tcp(7): |
| 560 | * On individual connections, the socket buffer size must be set prior to the |
| 561 | * listen(2) or connect(2) calls in order to have it take effect. |
| 562 | * This is our wrapper to do so. |
| 563 | */ |
| 564 | static void drbd_setbufsize(struct socket *sock, unsigned int snd, |
| 565 | unsigned int rcv) |
| 566 | { |
| 567 | /* open coded SO_SNDBUF, SO_RCVBUF */ |
| 568 | if (snd) { |
| 569 | sock->sk->sk_sndbuf = snd; |
| 570 | sock->sk->sk_userlocks |= SOCK_SNDBUF_LOCK; |
| 571 | } |
| 572 | if (rcv) { |
| 573 | sock->sk->sk_rcvbuf = rcv; |
| 574 | sock->sk->sk_userlocks |= SOCK_RCVBUF_LOCK; |
| 575 | } |
| 576 | } |
| 577 | |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 578 | static struct socket *drbd_try_connect(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 579 | { |
| 580 | const char *what; |
| 581 | struct socket *sock; |
| 582 | struct sockaddr_in6 src_in6; |
| 583 | int err; |
| 584 | int disconnect_on_error = 1; |
| 585 | |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 586 | if (!get_net_conf(tconn)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 587 | return NULL; |
| 588 | |
| 589 | what = "sock_create_kern"; |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 590 | err = sock_create_kern(((struct sockaddr *)tconn->net_conf->my_addr)->sa_family, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 591 | SOCK_STREAM, IPPROTO_TCP, &sock); |
| 592 | if (err < 0) { |
| 593 | sock = NULL; |
| 594 | goto out; |
| 595 | } |
| 596 | |
| 597 | sock->sk->sk_rcvtimeo = |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 598 | sock->sk->sk_sndtimeo = tconn->net_conf->try_connect_int*HZ; |
| 599 | drbd_setbufsize(sock, tconn->net_conf->sndbuf_size, |
| 600 | tconn->net_conf->rcvbuf_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 601 | |
| 602 | /* explicitly bind to the configured IP as source IP |
| 603 | * for the outgoing connections. |
| 604 | * This is needed for multihomed hosts and to be |
| 605 | * able to use lo: interfaces for drbd. |
| 606 | * Make sure to use 0 as port number, so linux selects |
| 607 | * a free one dynamically. |
| 608 | */ |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 609 | memcpy(&src_in6, tconn->net_conf->my_addr, |
| 610 | min_t(int, tconn->net_conf->my_addr_len, sizeof(src_in6))); |
| 611 | if (((struct sockaddr *)tconn->net_conf->my_addr)->sa_family == AF_INET6) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 612 | src_in6.sin6_port = 0; |
| 613 | else |
| 614 | ((struct sockaddr_in *)&src_in6)->sin_port = 0; /* AF_INET & AF_SCI */ |
| 615 | |
| 616 | what = "bind before connect"; |
| 617 | err = sock->ops->bind(sock, |
| 618 | (struct sockaddr *) &src_in6, |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 619 | tconn->net_conf->my_addr_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 620 | if (err < 0) |
| 621 | goto out; |
| 622 | |
| 623 | /* connect may fail, peer not yet available. |
| 624 | * stay C_WF_CONNECTION, don't go Disconnecting! */ |
| 625 | disconnect_on_error = 0; |
| 626 | what = "connect"; |
| 627 | err = sock->ops->connect(sock, |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 628 | (struct sockaddr *)tconn->net_conf->peer_addr, |
| 629 | tconn->net_conf->peer_addr_len, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 630 | |
| 631 | out: |
| 632 | if (err < 0) { |
| 633 | if (sock) { |
| 634 | sock_release(sock); |
| 635 | sock = NULL; |
| 636 | } |
| 637 | switch (-err) { |
| 638 | /* timeout, busy, signal pending */ |
| 639 | case ETIMEDOUT: case EAGAIN: case EINPROGRESS: |
| 640 | case EINTR: case ERESTARTSYS: |
| 641 | /* peer not (yet) available, network problem */ |
| 642 | case ECONNREFUSED: case ENETUNREACH: |
| 643 | case EHOSTDOWN: case EHOSTUNREACH: |
| 644 | disconnect_on_error = 0; |
| 645 | break; |
| 646 | default: |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 647 | conn_err(tconn, "%s failed, err = %d\n", what, err); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 648 | } |
| 649 | if (disconnect_on_error) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 650 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 651 | } |
Philipp Reisner | eac3e99 | 2011-02-07 14:05:07 +0100 | [diff] [blame] | 652 | put_net_conf(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 653 | return sock; |
| 654 | } |
| 655 | |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 656 | static struct socket *drbd_wait_for_connect(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 657 | { |
| 658 | int timeo, err; |
| 659 | struct socket *s_estab = NULL, *s_listen; |
| 660 | const char *what; |
| 661 | |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 662 | if (!get_net_conf(tconn)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 663 | return NULL; |
| 664 | |
| 665 | what = "sock_create_kern"; |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 666 | err = sock_create_kern(((struct sockaddr *)tconn->net_conf->my_addr)->sa_family, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 667 | SOCK_STREAM, IPPROTO_TCP, &s_listen); |
| 668 | if (err) { |
| 669 | s_listen = NULL; |
| 670 | goto out; |
| 671 | } |
| 672 | |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 673 | timeo = tconn->net_conf->try_connect_int * HZ; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 674 | timeo += (random32() & 1) ? timeo / 7 : -timeo / 7; /* 28.5% random jitter */ |
| 675 | |
| 676 | s_listen->sk->sk_reuse = 1; /* SO_REUSEADDR */ |
| 677 | s_listen->sk->sk_rcvtimeo = timeo; |
| 678 | s_listen->sk->sk_sndtimeo = timeo; |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 679 | drbd_setbufsize(s_listen, tconn->net_conf->sndbuf_size, |
| 680 | tconn->net_conf->rcvbuf_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 681 | |
| 682 | what = "bind before listen"; |
| 683 | err = s_listen->ops->bind(s_listen, |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 684 | (struct sockaddr *) tconn->net_conf->my_addr, |
| 685 | tconn->net_conf->my_addr_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 686 | if (err < 0) |
| 687 | goto out; |
| 688 | |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 689 | err = drbd_accept(&what, s_listen, &s_estab); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 690 | |
| 691 | out: |
| 692 | if (s_listen) |
| 693 | sock_release(s_listen); |
| 694 | if (err < 0) { |
| 695 | if (err != -EAGAIN && err != -EINTR && err != -ERESTARTSYS) { |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 696 | conn_err(tconn, "%s failed, err = %d\n", what, err); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 697 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 698 | } |
| 699 | } |
Philipp Reisner | 7653620 | 2011-02-07 14:09:54 +0100 | [diff] [blame] | 700 | put_net_conf(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 701 | |
| 702 | return s_estab; |
| 703 | } |
| 704 | |
Philipp Reisner | d38e787 | 2011-02-07 15:32:04 +0100 | [diff] [blame] | 705 | static int drbd_send_fp(struct drbd_tconn *tconn, struct socket *sock, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 706 | { |
Philipp Reisner | d38e787 | 2011-02-07 15:32:04 +0100 | [diff] [blame] | 707 | struct p_header *h = &tconn->data.sbuf.header; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 708 | |
Philipp Reisner | d38e787 | 2011-02-07 15:32:04 +0100 | [diff] [blame] | 709 | return _conn_send_cmd(tconn, 0, sock, cmd, h, sizeof(*h), 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Philipp Reisner | a25b63f | 2011-02-07 15:43:45 +0100 | [diff] [blame] | 712 | static enum drbd_packet drbd_recv_fp(struct drbd_tconn *tconn, struct socket *sock) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 713 | { |
Philipp Reisner | a25b63f | 2011-02-07 15:43:45 +0100 | [diff] [blame] | 714 | struct p_header80 *h = &tconn->data.rbuf.header.h80; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 715 | int rr; |
| 716 | |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 717 | rr = drbd_recv_short(sock, h, sizeof(*h), 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 718 | |
Andreas Gruenbacher | ca9bc12 | 2011-01-11 13:47:24 +0100 | [diff] [blame] | 719 | if (rr == sizeof(*h) && h->magic == cpu_to_be32(DRBD_MAGIC)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 720 | return be16_to_cpu(h->command); |
| 721 | |
| 722 | return 0xffff; |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * drbd_socket_okay() - Free the socket if its connection is not okay |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 727 | * @sock: pointer to the pointer to the socket. |
| 728 | */ |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 729 | static int drbd_socket_okay(struct socket **sock) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 730 | { |
| 731 | int rr; |
| 732 | char tb[4]; |
| 733 | |
| 734 | if (!*sock) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 735 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 736 | |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 737 | rr = drbd_recv_short(*sock, tb, 4, MSG_DONTWAIT | MSG_PEEK); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 738 | |
| 739 | if (rr > 0 || rr == -EAGAIN) { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 740 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 741 | } else { |
| 742 | sock_release(*sock); |
| 743 | *sock = NULL; |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 744 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 745 | } |
| 746 | } |
Philipp Reisner | 2325eb6 | 2011-03-15 16:56:18 +0100 | [diff] [blame] | 747 | /* Gets called if a connection is established, or if a new minor gets created |
| 748 | in a connection */ |
| 749 | int drbd_connected(int vnr, void *p, void *data) |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 750 | { |
| 751 | struct drbd_conf *mdev = (struct drbd_conf *)p; |
| 752 | int ok = 1; |
| 753 | |
| 754 | atomic_set(&mdev->packet_seq, 0); |
| 755 | mdev->peer_seq = 0; |
| 756 | |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 757 | mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ? |
| 758 | &mdev->tconn->cstate_mutex : |
| 759 | &mdev->own_state_mutex; |
| 760 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 761 | ok &= drbd_send_sync_param(mdev, &mdev->sync_conf); |
| 762 | ok &= drbd_send_sizes(mdev, 0, 0); |
| 763 | ok &= drbd_send_uuids(mdev); |
| 764 | ok &= drbd_send_state(mdev); |
| 765 | clear_bit(USE_DEGR_WFC_T, &mdev->flags); |
| 766 | clear_bit(RESIZE_PENDING, &mdev->flags); |
| 767 | |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 768 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 769 | return !ok; |
| 770 | } |
| 771 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 772 | /* |
| 773 | * return values: |
| 774 | * 1 yes, we have a valid connection |
| 775 | * 0 oops, did not work out, please try again |
| 776 | * -1 peer talks different language, |
| 777 | * no point in trying again, please go standalone. |
| 778 | * -2 We do not have a network config... |
| 779 | */ |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 780 | static int drbd_connect(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 781 | { |
| 782 | struct socket *s, *sock, *msock; |
| 783 | int try, h, ok; |
| 784 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 785 | 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] | 786 | return -2; |
| 787 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 788 | clear_bit(DISCARD_CONCURRENT, &tconn->flags); |
| 789 | tconn->agreed_pro_version = 99; |
Philipp Reisner | fd340c1 | 2011-01-19 16:57:39 +0100 | [diff] [blame] | 790 | /* agreed_pro_version must be smaller than 100 so we send the old |
| 791 | header (h80) in the first packet and in the handshake packet. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 792 | |
| 793 | sock = NULL; |
| 794 | msock = NULL; |
| 795 | |
| 796 | do { |
| 797 | for (try = 0;;) { |
| 798 | /* 3 tries, this should take less than a second! */ |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 799 | s = drbd_try_connect(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 800 | if (s || ++try >= 3) |
| 801 | break; |
| 802 | /* give the other side time to call bind() & listen() */ |
Philipp Reisner | 20ee639 | 2011-01-18 15:28:59 +0100 | [diff] [blame] | 803 | schedule_timeout_interruptible(HZ / 10); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | if (s) { |
| 807 | if (!sock) { |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 808 | drbd_send_fp(tconn, s, P_HAND_SHAKE_S); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 809 | sock = s; |
| 810 | s = NULL; |
| 811 | } else if (!msock) { |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 812 | drbd_send_fp(tconn, s, P_HAND_SHAKE_M); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 813 | msock = s; |
| 814 | s = NULL; |
| 815 | } else { |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 816 | conn_err(tconn, "Logic error in drbd_connect()\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 817 | goto out_release_sockets; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | if (sock && msock) { |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 822 | schedule_timeout_interruptible(tconn->net_conf->ping_timeo*HZ/10); |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 823 | ok = drbd_socket_okay(&sock); |
| 824 | ok = drbd_socket_okay(&msock) && ok; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 825 | if (ok) |
| 826 | break; |
| 827 | } |
| 828 | |
| 829 | retry: |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 830 | s = drbd_wait_for_connect(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 831 | if (s) { |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 832 | try = drbd_recv_fp(tconn, s); |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 833 | drbd_socket_okay(&sock); |
| 834 | drbd_socket_okay(&msock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 835 | switch (try) { |
| 836 | case P_HAND_SHAKE_S: |
| 837 | if (sock) { |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 838 | conn_warn(tconn, "initial packet S crossed\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 839 | sock_release(sock); |
| 840 | } |
| 841 | sock = s; |
| 842 | break; |
| 843 | case P_HAND_SHAKE_M: |
| 844 | if (msock) { |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 845 | conn_warn(tconn, "initial packet M crossed\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 846 | sock_release(msock); |
| 847 | } |
| 848 | msock = s; |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 849 | set_bit(DISCARD_CONCURRENT, &tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 850 | break; |
| 851 | default: |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 852 | conn_warn(tconn, "Error receiving initial packet\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 853 | sock_release(s); |
| 854 | if (random32() & 1) |
| 855 | goto retry; |
| 856 | } |
| 857 | } |
| 858 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 859 | if (tconn->cstate <= C_DISCONNECTING) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 860 | goto out_release_sockets; |
| 861 | if (signal_pending(current)) { |
| 862 | flush_signals(current); |
| 863 | smp_rmb(); |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 864 | if (get_t_state(&tconn->receiver) == EXITING) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 865 | goto out_release_sockets; |
| 866 | } |
| 867 | |
| 868 | if (sock && msock) { |
Philipp Reisner | dbd9eea | 2011-02-07 15:34:16 +0100 | [diff] [blame] | 869 | ok = drbd_socket_okay(&sock); |
| 870 | ok = drbd_socket_okay(&msock) && ok; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 871 | if (ok) |
| 872 | break; |
| 873 | } |
| 874 | } while (1); |
| 875 | |
| 876 | msock->sk->sk_reuse = 1; /* SO_REUSEADDR */ |
| 877 | sock->sk->sk_reuse = 1; /* SO_REUSEADDR */ |
| 878 | |
| 879 | sock->sk->sk_allocation = GFP_NOIO; |
| 880 | msock->sk->sk_allocation = GFP_NOIO; |
| 881 | |
| 882 | sock->sk->sk_priority = TC_PRIO_INTERACTIVE_BULK; |
| 883 | msock->sk->sk_priority = TC_PRIO_INTERACTIVE; |
| 884 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 885 | /* NOT YET ... |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 886 | * sock->sk->sk_sndtimeo = tconn->net_conf->timeout*HZ/10; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 887 | * sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; |
| 888 | * first set it to the P_HAND_SHAKE timeout, |
| 889 | * which we set to 4x the configured ping_timeout. */ |
| 890 | sock->sk->sk_sndtimeo = |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 891 | sock->sk->sk_rcvtimeo = tconn->net_conf->ping_timeo*4*HZ/10; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 892 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 893 | msock->sk->sk_sndtimeo = tconn->net_conf->timeout*HZ/10; |
| 894 | msock->sk->sk_rcvtimeo = tconn->net_conf->ping_int*HZ; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 895 | |
| 896 | /* we don't want delays. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 897 | * we use TCP_CORK where appropriate, though */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 898 | drbd_tcp_nodelay(sock); |
| 899 | drbd_tcp_nodelay(msock); |
| 900 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 901 | tconn->data.socket = sock; |
| 902 | tconn->meta.socket = msock; |
| 903 | tconn->last_received = jiffies; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 904 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 905 | h = drbd_do_handshake(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 906 | if (h <= 0) |
| 907 | return h; |
| 908 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 909 | if (tconn->cram_hmac_tfm) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 910 | /* drbd_request_state(mdev, NS(conn, WFAuth)); */ |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 911 | switch (drbd_do_auth(tconn)) { |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 912 | case -1: |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 913 | conn_err(tconn, "Authentication of peer failed\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 914 | return -1; |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 915 | case 0: |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 916 | conn_err(tconn, "Authentication of peer failed, trying again.\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 917 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 921 | if (conn_request_state(tconn, NS(conn, C_WF_REPORT_PARAMS), CS_VERBOSE) < SS_SUCCESS) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 922 | return 0; |
| 923 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 924 | sock->sk->sk_sndtimeo = tconn->net_conf->timeout*HZ/10; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 925 | sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; |
| 926 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 927 | drbd_thread_start(&tconn->asender); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 928 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 929 | if (drbd_send_protocol(tconn) == -1) |
Philipp Reisner | 7e2455c | 2010-04-22 14:50:23 +0200 | [diff] [blame] | 930 | return -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 931 | |
Philipp Reisner | 907599e | 2011-02-08 11:25:37 +0100 | [diff] [blame] | 932 | return !idr_for_each(&tconn->volumes, drbd_connected, tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 933 | |
| 934 | out_release_sockets: |
| 935 | if (sock) |
| 936 | sock_release(sock); |
| 937 | if (msock) |
| 938 | sock_release(msock); |
| 939 | return -1; |
| 940 | } |
| 941 | |
Philipp Reisner | ce24385 | 2011-02-07 17:27:47 +0100 | [diff] [blame] | 942 | static bool decode_header(struct drbd_tconn *tconn, struct p_header *h, struct packet_info *pi) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 943 | { |
Philipp Reisner | fd340c1 | 2011-01-19 16:57:39 +0100 | [diff] [blame] | 944 | if (h->h80.magic == cpu_to_be32(DRBD_MAGIC)) { |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 945 | pi->cmd = be16_to_cpu(h->h80.command); |
| 946 | pi->size = be16_to_cpu(h->h80.length); |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 947 | pi->vnr = 0; |
Andreas Gruenbacher | ca9bc12 | 2011-01-11 13:47:24 +0100 | [diff] [blame] | 948 | } else if (h->h95.magic == cpu_to_be16(DRBD_MAGIC_BIG)) { |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 949 | pi->cmd = be16_to_cpu(h->h95.command); |
| 950 | pi->size = be32_to_cpu(h->h95.length) & 0x00ffffff; |
| 951 | pi->vnr = 0; |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 952 | } else { |
Philipp Reisner | ce24385 | 2011-02-07 17:27:47 +0100 | [diff] [blame] | 953 | conn_err(tconn, "magic?? on data m: 0x%08x c: %d l: %d\n", |
Lars Ellenberg | 004352f | 2010-10-05 20:13:58 +0200 | [diff] [blame] | 954 | be32_to_cpu(h->h80.magic), |
| 955 | be16_to_cpu(h->h80.command), |
| 956 | be16_to_cpu(h->h80.length)); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 957 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 958 | } |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 959 | return true; |
| 960 | } |
| 961 | |
Philipp Reisner | 9ba7aa0 | 2011-02-07 17:32:41 +0100 | [diff] [blame] | 962 | 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] | 963 | { |
Philipp Reisner | 9ba7aa0 | 2011-02-07 17:32:41 +0100 | [diff] [blame] | 964 | struct p_header *h = &tconn->data.rbuf.header; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 965 | int r; |
| 966 | |
Philipp Reisner | 9ba7aa0 | 2011-02-07 17:32:41 +0100 | [diff] [blame] | 967 | r = drbd_recv(tconn, h, sizeof(*h)); |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 968 | if (unlikely(r != sizeof(*h))) { |
| 969 | if (!signal_pending(current)) |
Philipp Reisner | 9ba7aa0 | 2011-02-07 17:32:41 +0100 | [diff] [blame] | 970 | conn_warn(tconn, "short read expecting header on sock: r=%d\n", r); |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 971 | return false; |
| 972 | } |
| 973 | |
Philipp Reisner | 9ba7aa0 | 2011-02-07 17:32:41 +0100 | [diff] [blame] | 974 | r = decode_header(tconn, h, pi); |
| 975 | tconn->last_received = jiffies; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 976 | |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 977 | return r; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 980 | static void drbd_flush(struct drbd_conf *mdev) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 981 | { |
| 982 | int rv; |
| 983 | |
| 984 | if (mdev->write_ordering >= WO_bdev_flush && get_ldev(mdev)) { |
Dmitry Monakhov | fbd9b09 | 2010-04-28 17:55:06 +0400 | [diff] [blame] | 985 | rv = blkdev_issue_flush(mdev->ldev->backing_bdev, GFP_KERNEL, |
Christoph Hellwig | dd3932e | 2010-09-16 20:51:46 +0200 | [diff] [blame] | 986 | NULL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 987 | if (rv) { |
| 988 | dev_err(DEV, "local disk flush failed with status %d\n", rv); |
| 989 | /* would rather check on EOPNOTSUPP, but that is not reliable. |
| 990 | * don't try again for ANY return value != 0 |
| 991 | * if (rv == -EOPNOTSUPP) */ |
| 992 | drbd_bump_write_ordering(mdev, WO_drain_io); |
| 993 | } |
| 994 | put_ldev(mdev); |
| 995 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | /** |
| 999 | * drbd_may_finish_epoch() - Applies an epoch_event to the epoch's state, eventually finishes it. |
| 1000 | * @mdev: DRBD device. |
| 1001 | * @epoch: Epoch object. |
| 1002 | * @ev: Epoch event. |
| 1003 | */ |
| 1004 | static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev, |
| 1005 | struct drbd_epoch *epoch, |
| 1006 | enum epoch_event ev) |
| 1007 | { |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1008 | int epoch_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1009 | struct drbd_epoch *next_epoch; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1010 | enum finish_epoch rv = FE_STILL_LIVE; |
| 1011 | |
| 1012 | spin_lock(&mdev->epoch_lock); |
| 1013 | do { |
| 1014 | next_epoch = NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1015 | |
| 1016 | epoch_size = atomic_read(&epoch->epoch_size); |
| 1017 | |
| 1018 | switch (ev & ~EV_CLEANUP) { |
| 1019 | case EV_PUT: |
| 1020 | atomic_dec(&epoch->active); |
| 1021 | break; |
| 1022 | case EV_GOT_BARRIER_NR: |
| 1023 | set_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1024 | break; |
| 1025 | case EV_BECAME_LAST: |
| 1026 | /* nothing to do*/ |
| 1027 | break; |
| 1028 | } |
| 1029 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1030 | if (epoch_size != 0 && |
| 1031 | atomic_read(&epoch->active) == 0 && |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1032 | test_bit(DE_HAVE_BARRIER_NUMBER, &epoch->flags)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1033 | if (!(ev & EV_CLEANUP)) { |
| 1034 | spin_unlock(&mdev->epoch_lock); |
| 1035 | drbd_send_b_ack(mdev, epoch->barrier_nr, epoch_size); |
| 1036 | spin_lock(&mdev->epoch_lock); |
| 1037 | } |
| 1038 | dec_unacked(mdev); |
| 1039 | |
| 1040 | if (mdev->current_epoch != epoch) { |
| 1041 | next_epoch = list_entry(epoch->list.next, struct drbd_epoch, list); |
| 1042 | list_del(&epoch->list); |
| 1043 | ev = EV_BECAME_LAST | (ev & EV_CLEANUP); |
| 1044 | mdev->epochs--; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1045 | kfree(epoch); |
| 1046 | |
| 1047 | if (rv == FE_STILL_LIVE) |
| 1048 | rv = FE_DESTROYED; |
| 1049 | } else { |
| 1050 | epoch->flags = 0; |
| 1051 | atomic_set(&epoch->epoch_size, 0); |
Uwe Kleine-König | 698f931 | 2010-07-02 20:41:51 +0200 | [diff] [blame] | 1052 | /* atomic_set(&epoch->active, 0); is already zero */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1053 | if (rv == FE_STILL_LIVE) |
| 1054 | rv = FE_RECYCLED; |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1055 | wake_up(&mdev->ee_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | if (!next_epoch) |
| 1060 | break; |
| 1061 | |
| 1062 | epoch = next_epoch; |
| 1063 | } while (1); |
| 1064 | |
| 1065 | spin_unlock(&mdev->epoch_lock); |
| 1066 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1067 | return rv; |
| 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * drbd_bump_write_ordering() - Fall back to an other write ordering method |
| 1072 | * @mdev: DRBD device. |
| 1073 | * @wo: Write ordering method to try. |
| 1074 | */ |
| 1075 | void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo) __must_hold(local) |
| 1076 | { |
| 1077 | enum write_ordering_e pwo; |
| 1078 | static char *write_ordering_str[] = { |
| 1079 | [WO_none] = "none", |
| 1080 | [WO_drain_io] = "drain", |
| 1081 | [WO_bdev_flush] = "flush", |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1082 | }; |
| 1083 | |
| 1084 | pwo = mdev->write_ordering; |
| 1085 | wo = min(pwo, wo); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1086 | if (wo == WO_bdev_flush && mdev->ldev->dc.no_disk_flush) |
| 1087 | wo = WO_drain_io; |
| 1088 | if (wo == WO_drain_io && mdev->ldev->dc.no_disk_drain) |
| 1089 | wo = WO_none; |
| 1090 | mdev->write_ordering = wo; |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1091 | if (pwo != mdev->write_ordering || wo == WO_bdev_flush) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1092 | dev_info(DEV, "Method to ensure write ordering: %s\n", write_ordering_str[mdev->write_ordering]); |
| 1093 | } |
| 1094 | |
| 1095 | /** |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 1096 | * drbd_submit_peer_request() |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1097 | * @mdev: DRBD device. |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1098 | * @peer_req: peer request |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1099 | * @rw: flag field, see bio->bi_rw |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1100 | * |
| 1101 | * May spread the pages to multiple bios, |
| 1102 | * depending on bio_add_page restrictions. |
| 1103 | * |
| 1104 | * Returns 0 if all bios have been submitted, |
| 1105 | * -ENOMEM if we could not allocate enough bios, |
| 1106 | * -ENOSPC (any better suggestion?) if we have not been able to bio_add_page a |
| 1107 | * single page to an empty bio (which should never happen and likely indicates |
| 1108 | * that the lower level IO stack is in some way broken). This has been observed |
| 1109 | * on certain Xen deployments. |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1110 | */ |
| 1111 | /* TODO allocate from our own bio_set. */ |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 1112 | int drbd_submit_peer_request(struct drbd_conf *mdev, |
| 1113 | struct drbd_peer_request *peer_req, |
| 1114 | const unsigned rw, const int fault_type) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1115 | { |
| 1116 | struct bio *bios = NULL; |
| 1117 | struct bio *bio; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1118 | struct page *page = peer_req->pages; |
| 1119 | sector_t sector = peer_req->i.sector; |
| 1120 | unsigned ds = peer_req->i.size; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1121 | unsigned n_bios = 0; |
| 1122 | unsigned nr_pages = (ds + PAGE_SIZE -1) >> PAGE_SHIFT; |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1123 | int err = -ENOMEM; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1124 | |
| 1125 | /* In most cases, we will only need one bio. But in case the lower |
| 1126 | * level restrictions happen to be different at this offset on this |
| 1127 | * 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] | 1128 | * request in more than one bio. |
| 1129 | * |
| 1130 | * Plain bio_alloc is good enough here, this is no DRBD internally |
| 1131 | * generated bio, but a bio allocated on behalf of the peer. |
| 1132 | */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1133 | next_bio: |
| 1134 | bio = bio_alloc(GFP_NOIO, nr_pages); |
| 1135 | if (!bio) { |
| 1136 | dev_err(DEV, "submit_ee: Allocation of a bio failed\n"); |
| 1137 | goto fail; |
| 1138 | } |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1139 | /* > peer_req->i.sector, unless this is the first bio */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1140 | bio->bi_sector = sector; |
| 1141 | bio->bi_bdev = mdev->ldev->backing_bdev; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1142 | bio->bi_rw = rw; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1143 | bio->bi_private = peer_req; |
Andreas Gruenbacher | fcefa62 | 2011-02-17 16:46:59 +0100 | [diff] [blame] | 1144 | bio->bi_end_io = drbd_peer_request_endio; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1145 | |
| 1146 | bio->bi_next = bios; |
| 1147 | bios = bio; |
| 1148 | ++n_bios; |
| 1149 | |
| 1150 | page_chain_for_each(page) { |
| 1151 | unsigned len = min_t(unsigned, ds, PAGE_SIZE); |
| 1152 | if (!bio_add_page(bio, page, len, 0)) { |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1153 | /* A single page must always be possible! |
| 1154 | * But in case it fails anyways, |
| 1155 | * we deal with it, and complain (below). */ |
| 1156 | if (bio->bi_vcnt == 0) { |
| 1157 | dev_err(DEV, |
| 1158 | "bio_add_page failed for len=%u, " |
| 1159 | "bi_vcnt=0 (bi_sector=%llu)\n", |
| 1160 | len, (unsigned long long)bio->bi_sector); |
| 1161 | err = -ENOSPC; |
| 1162 | goto fail; |
| 1163 | } |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1164 | goto next_bio; |
| 1165 | } |
| 1166 | ds -= len; |
| 1167 | sector += len >> 9; |
| 1168 | --nr_pages; |
| 1169 | } |
| 1170 | D_ASSERT(page == NULL); |
| 1171 | D_ASSERT(ds == 0); |
| 1172 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1173 | atomic_set(&peer_req->pending_bios, n_bios); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1174 | do { |
| 1175 | bio = bios; |
| 1176 | bios = bios->bi_next; |
| 1177 | bio->bi_next = NULL; |
| 1178 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1179 | drbd_generic_make_request(mdev, fault_type, bio); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1180 | } while (bios); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1181 | return 0; |
| 1182 | |
| 1183 | fail: |
| 1184 | while (bios) { |
| 1185 | bio = bios; |
| 1186 | bios = bios->bi_next; |
| 1187 | bio_put(bio); |
| 1188 | } |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1189 | return err; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1190 | } |
| 1191 | |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1192 | static void drbd_remove_epoch_entry_interval(struct drbd_conf *mdev, |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1193 | struct drbd_peer_request *peer_req) |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1194 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1195 | struct drbd_interval *i = &peer_req->i; |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1196 | |
| 1197 | drbd_remove_interval(&mdev->write_requests, i); |
| 1198 | drbd_clear_interval(i); |
| 1199 | |
Andreas Gruenbacher | 6c852be | 2011-02-04 15:38:52 +0100 | [diff] [blame] | 1200 | /* Wake up any processes waiting for this peer request to complete. */ |
Andreas Gruenbacher | 5384064 | 2011-01-28 10:31:04 +0100 | [diff] [blame] | 1201 | if (i->waiting) |
| 1202 | wake_up(&mdev->misc_wait); |
| 1203 | } |
| 1204 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 1205 | static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 1206 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1207 | { |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1208 | int rv; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 1209 | struct p_barrier *p = &mdev->tconn->data.rbuf.barrier; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1210 | struct drbd_epoch *epoch; |
| 1211 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1212 | inc_unacked(mdev); |
| 1213 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1214 | mdev->current_epoch->barrier_nr = p->barrier; |
| 1215 | rv = drbd_may_finish_epoch(mdev, mdev->current_epoch, EV_GOT_BARRIER_NR); |
| 1216 | |
| 1217 | /* P_BARRIER_ACK may imply that the corresponding extent is dropped from |
| 1218 | * the activity log, which means it would not be resynced in case the |
| 1219 | * R_PRIMARY crashes now. |
| 1220 | * Therefore we must send the barrier_ack after the barrier request was |
| 1221 | * completed. */ |
| 1222 | switch (mdev->write_ordering) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1223 | case WO_none: |
| 1224 | if (rv == FE_RECYCLED) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1225 | return true; |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1226 | |
| 1227 | /* receiver context, in the writeout path of the other node. |
| 1228 | * avoid potential distributed deadlock */ |
| 1229 | epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO); |
| 1230 | if (epoch) |
| 1231 | break; |
| 1232 | else |
| 1233 | dev_warn(DEV, "Allocation of an epoch failed, slowing down\n"); |
| 1234 | /* Fall through */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1235 | |
| 1236 | case WO_bdev_flush: |
| 1237 | case WO_drain_io: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1238 | drbd_wait_ee_list_empty(mdev, &mdev->active_ee); |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1239 | drbd_flush(mdev); |
| 1240 | |
| 1241 | if (atomic_read(&mdev->current_epoch->epoch_size)) { |
| 1242 | epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO); |
| 1243 | if (epoch) |
| 1244 | break; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1247 | epoch = mdev->current_epoch; |
| 1248 | wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0); |
| 1249 | |
| 1250 | D_ASSERT(atomic_read(&epoch->active) == 0); |
| 1251 | D_ASSERT(epoch->flags == 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1252 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1253 | return true; |
Philipp Reisner | 2451fc3 | 2010-08-24 13:43:11 +0200 | [diff] [blame] | 1254 | default: |
| 1255 | dev_err(DEV, "Strangeness in mdev->write_ordering %d\n", mdev->write_ordering); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1256 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | epoch->flags = 0; |
| 1260 | atomic_set(&epoch->epoch_size, 0); |
| 1261 | atomic_set(&epoch->active, 0); |
| 1262 | |
| 1263 | spin_lock(&mdev->epoch_lock); |
| 1264 | if (atomic_read(&mdev->current_epoch->epoch_size)) { |
| 1265 | list_add(&epoch->list, &mdev->current_epoch->list); |
| 1266 | mdev->current_epoch = epoch; |
| 1267 | mdev->epochs++; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1268 | } else { |
| 1269 | /* The current_epoch got recycled while we allocated this one... */ |
| 1270 | kfree(epoch); |
| 1271 | } |
| 1272 | spin_unlock(&mdev->epoch_lock); |
| 1273 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1274 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | /* used from receive_RSDataReply (recv_resync_read) |
| 1278 | * and from receive_Data */ |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1279 | static struct drbd_peer_request * |
| 1280 | read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, |
| 1281 | int data_size) __must_hold(local) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1282 | { |
Lars Ellenberg | 6666032 | 2010-04-06 12:15:04 +0200 | [diff] [blame] | 1283 | const sector_t capacity = drbd_get_capacity(mdev->this_bdev); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1284 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1285 | struct page *page; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1286 | int dgs, ds, rr; |
Philipp Reisner | a063845 | 2011-01-19 14:31:32 +0100 | [diff] [blame] | 1287 | void *dig_in = mdev->tconn->int_dig_in; |
| 1288 | void *dig_vv = mdev->tconn->int_dig_vv; |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 1289 | unsigned long *data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1290 | |
Philipp Reisner | a063845 | 2011-01-19 14:31:32 +0100 | [diff] [blame] | 1291 | dgs = (mdev->tconn->agreed_pro_version >= 87 && mdev->tconn->integrity_r_tfm) ? |
| 1292 | crypto_hash_digestsize(mdev->tconn->integrity_r_tfm) : 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1293 | |
| 1294 | if (dgs) { |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 1295 | rr = drbd_recv(mdev->tconn, dig_in, dgs); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1296 | if (rr != dgs) { |
Lars Ellenberg | 0ddc554 | 2011-01-21 12:35:15 +0100 | [diff] [blame] | 1297 | if (!signal_pending(current)) |
| 1298 | dev_warn(DEV, |
| 1299 | "short read receiving data digest: read %d expected %d\n", |
| 1300 | rr, dgs); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1301 | return NULL; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | data_size -= dgs; |
| 1306 | |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 1307 | if (!expect(data_size != 0)) |
| 1308 | return NULL; |
| 1309 | if (!expect(IS_ALIGNED(data_size, 512))) |
| 1310 | return NULL; |
| 1311 | if (!expect(data_size <= DRBD_MAX_BIO_SIZE)) |
| 1312 | return NULL; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1313 | |
Lars Ellenberg | 6666032 | 2010-04-06 12:15:04 +0200 | [diff] [blame] | 1314 | /* even though we trust out peer, |
| 1315 | * we sometimes have to double check. */ |
| 1316 | if (sector + (data_size>>9) > capacity) { |
Lars Ellenberg | fdda654 | 2011-01-24 15:11:01 +0100 | [diff] [blame] | 1317 | dev_err(DEV, "request from peer beyond end of local disk: " |
| 1318 | "capacity: %llus < sector: %llus + size: %u\n", |
Lars Ellenberg | 6666032 | 2010-04-06 12:15:04 +0200 | [diff] [blame] | 1319 | (unsigned long long)capacity, |
| 1320 | (unsigned long long)sector, data_size); |
| 1321 | return NULL; |
| 1322 | } |
| 1323 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1324 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD |
| 1325 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
| 1326 | * which in turn might block on the other node at this very place. */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1327 | peer_req = drbd_alloc_ee(mdev, id, sector, data_size, GFP_NOIO); |
| 1328 | if (!peer_req) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1329 | return NULL; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1330 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1331 | ds = data_size; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1332 | page = peer_req->pages; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1333 | page_chain_for_each(page) { |
| 1334 | unsigned len = min_t(int, ds, PAGE_SIZE); |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 1335 | data = kmap(page); |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 1336 | rr = drbd_recv(mdev->tconn, data, len); |
Andreas Gruenbacher | 0cf9d27 | 2010-12-07 10:43:29 +0100 | [diff] [blame] | 1337 | if (drbd_insert_fault(mdev, DRBD_FAULT_RECEIVE)) { |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 1338 | dev_err(DEV, "Fault injection: Corrupting data on receive\n"); |
| 1339 | data[0] = data[0] ^ (unsigned long)-1; |
| 1340 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1341 | kunmap(page); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1342 | if (rr != len) { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1343 | drbd_free_ee(mdev, peer_req); |
Lars Ellenberg | 0ddc554 | 2011-01-21 12:35:15 +0100 | [diff] [blame] | 1344 | if (!signal_pending(current)) |
| 1345 | dev_warn(DEV, "short read receiving data: read %d expected %d\n", |
| 1346 | rr, len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1347 | return NULL; |
| 1348 | } |
| 1349 | ds -= rr; |
| 1350 | } |
| 1351 | |
| 1352 | if (dgs) { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1353 | drbd_csum_ee(mdev, mdev->tconn->integrity_r_tfm, peer_req, dig_vv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1354 | if (memcmp(dig_in, dig_vv, dgs)) { |
Lars Ellenberg | 470be44 | 2010-11-10 10:36:52 +0100 | [diff] [blame] | 1355 | dev_err(DEV, "Digest integrity check FAILED: %llus +%u\n", |
| 1356 | (unsigned long long)sector, data_size); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1357 | drbd_free_ee(mdev, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1358 | return NULL; |
| 1359 | } |
| 1360 | } |
| 1361 | mdev->recv_cnt += data_size>>9; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1362 | return peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | /* drbd_drain_block() just takes a data block |
| 1366 | * out of the socket input buffer, and discards it. |
| 1367 | */ |
| 1368 | static int drbd_drain_block(struct drbd_conf *mdev, int data_size) |
| 1369 | { |
| 1370 | struct page *page; |
| 1371 | int rr, rv = 1; |
| 1372 | void *data; |
| 1373 | |
Lars Ellenberg | c3470cd | 2010-04-01 16:57:19 +0200 | [diff] [blame] | 1374 | if (!data_size) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1375 | return true; |
Lars Ellenberg | c3470cd | 2010-04-01 16:57:19 +0200 | [diff] [blame] | 1376 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1377 | page = drbd_pp_alloc(mdev, 1, 1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1378 | |
| 1379 | data = kmap(page); |
| 1380 | while (data_size) { |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 1381 | rr = drbd_recv(mdev->tconn, data, min_t(int, data_size, PAGE_SIZE)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1382 | if (rr != min_t(int, data_size, PAGE_SIZE)) { |
| 1383 | rv = 0; |
Lars Ellenberg | 0ddc554 | 2011-01-21 12:35:15 +0100 | [diff] [blame] | 1384 | if (!signal_pending(current)) |
| 1385 | dev_warn(DEV, |
| 1386 | "short read receiving data: read %d expected %d\n", |
| 1387 | rr, min_t(int, data_size, PAGE_SIZE)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1388 | break; |
| 1389 | } |
| 1390 | data_size -= rr; |
| 1391 | } |
| 1392 | kunmap(page); |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 1393 | drbd_pp_free(mdev, page, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1394 | return rv; |
| 1395 | } |
| 1396 | |
| 1397 | static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req, |
| 1398 | sector_t sector, int data_size) |
| 1399 | { |
| 1400 | struct bio_vec *bvec; |
| 1401 | struct bio *bio; |
| 1402 | int dgs, rr, i, expect; |
Philipp Reisner | a063845 | 2011-01-19 14:31:32 +0100 | [diff] [blame] | 1403 | void *dig_in = mdev->tconn->int_dig_in; |
| 1404 | void *dig_vv = mdev->tconn->int_dig_vv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1405 | |
Philipp Reisner | a063845 | 2011-01-19 14:31:32 +0100 | [diff] [blame] | 1406 | dgs = (mdev->tconn->agreed_pro_version >= 87 && mdev->tconn->integrity_r_tfm) ? |
| 1407 | crypto_hash_digestsize(mdev->tconn->integrity_r_tfm) : 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1408 | |
| 1409 | if (dgs) { |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 1410 | rr = drbd_recv(mdev->tconn, dig_in, dgs); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1411 | if (rr != dgs) { |
Lars Ellenberg | 0ddc554 | 2011-01-21 12:35:15 +0100 | [diff] [blame] | 1412 | if (!signal_pending(current)) |
| 1413 | dev_warn(DEV, |
| 1414 | "short read receiving data reply digest: read %d expected %d\n", |
| 1415 | rr, dgs); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1416 | return 0; |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | data_size -= dgs; |
| 1421 | |
| 1422 | /* optimistically update recv_cnt. if receiving fails below, |
| 1423 | * we disconnect anyways, and counters will be reset. */ |
| 1424 | mdev->recv_cnt += data_size>>9; |
| 1425 | |
| 1426 | bio = req->master_bio; |
| 1427 | D_ASSERT(sector == bio->bi_sector); |
| 1428 | |
| 1429 | bio_for_each_segment(bvec, bio, i) { |
| 1430 | expect = min_t(int, data_size, bvec->bv_len); |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 1431 | rr = drbd_recv(mdev->tconn, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1432 | kmap(bvec->bv_page)+bvec->bv_offset, |
| 1433 | expect); |
| 1434 | kunmap(bvec->bv_page); |
| 1435 | if (rr != expect) { |
Lars Ellenberg | 0ddc554 | 2011-01-21 12:35:15 +0100 | [diff] [blame] | 1436 | if (!signal_pending(current)) |
| 1437 | dev_warn(DEV, "short read receiving data reply: " |
| 1438 | "read %d expected %d\n", |
| 1439 | rr, expect); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1440 | return 0; |
| 1441 | } |
| 1442 | data_size -= rr; |
| 1443 | } |
| 1444 | |
| 1445 | if (dgs) { |
Philipp Reisner | a063845 | 2011-01-19 14:31:32 +0100 | [diff] [blame] | 1446 | drbd_csum_bio(mdev, mdev->tconn->integrity_r_tfm, bio, dig_vv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1447 | if (memcmp(dig_in, dig_vv, dgs)) { |
| 1448 | dev_err(DEV, "Digest integrity check FAILED. Broken NICs?\n"); |
| 1449 | return 0; |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | D_ASSERT(data_size == 0); |
| 1454 | return 1; |
| 1455 | } |
| 1456 | |
| 1457 | /* e_end_resync_block() is called via |
| 1458 | * drbd_process_done_ee() by asender only */ |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 1459 | static int e_end_resync_block(struct drbd_work *w, int unused) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1460 | { |
Andreas Gruenbacher | 8050e6d | 2011-02-18 16:12:48 +0100 | [diff] [blame] | 1461 | struct drbd_peer_request *peer_req = |
| 1462 | container_of(w, struct drbd_peer_request, w); |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 1463 | struct drbd_conf *mdev = w->mdev; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1464 | sector_t sector = peer_req->i.sector; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1465 | int ok; |
| 1466 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1467 | D_ASSERT(drbd_interval_empty(&peer_req->i)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1468 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1469 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
| 1470 | drbd_set_in_sync(mdev, sector, peer_req->i.size); |
| 1471 | ok = drbd_send_ack(mdev, P_RS_WRITE_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1472 | } else { |
| 1473 | /* Record failure to sync */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1474 | drbd_rs_failed_io(mdev, sector, peer_req->i.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1475 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1476 | ok = drbd_send_ack(mdev, P_NEG_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1477 | } |
| 1478 | dec_unacked(mdev); |
| 1479 | |
| 1480 | return ok; |
| 1481 | } |
| 1482 | |
| 1483 | static int recv_resync_read(struct drbd_conf *mdev, sector_t sector, int data_size) __releases(local) |
| 1484 | { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1485 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1486 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1487 | peer_req = read_in_block(mdev, ID_SYNCER, sector, data_size); |
| 1488 | if (!peer_req) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1489 | goto fail; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1490 | |
| 1491 | dec_rs_pending(mdev); |
| 1492 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1493 | inc_unacked(mdev); |
| 1494 | /* corresponding dec_unacked() in e_end_resync_block() |
| 1495 | * respective _drbd_clear_done_ee */ |
| 1496 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1497 | peer_req->w.cb = e_end_resync_block; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1498 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1499 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1500 | list_add(&peer_req->w.list, &mdev->sync_ee); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1501 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1502 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 1503 | atomic_add(data_size >> 9, &mdev->rs_sect_ev); |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 1504 | if (drbd_submit_peer_request(mdev, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1505 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1506 | |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 1507 | /* don't care for the reason here */ |
| 1508 | dev_err(DEV, "submit failed, triggering re-connect\n"); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1509 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1510 | list_del(&peer_req->w.list); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1511 | spin_unlock_irq(&mdev->tconn->req_lock); |
Lars Ellenberg | 22cc37a | 2010-09-14 20:40:41 +0200 | [diff] [blame] | 1512 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1513 | drbd_free_ee(mdev, peer_req); |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1514 | fail: |
| 1515 | put_ldev(mdev); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1516 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1519 | static struct drbd_request * |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 1520 | find_request(struct drbd_conf *mdev, struct rb_root *root, u64 id, |
| 1521 | sector_t sector, bool missing_ok, const char *func) |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1522 | { |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1523 | struct drbd_request *req; |
| 1524 | |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 1525 | /* Request object according to our peer */ |
| 1526 | req = (struct drbd_request *)(unsigned long)id; |
Andreas Gruenbacher | 5e47226 | 2011-01-27 14:42:51 +0100 | [diff] [blame] | 1527 | if (drbd_contains_interval(root, sector, &req->i) && req->i.local) |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1528 | return req; |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 1529 | if (!missing_ok) { |
| 1530 | dev_err(DEV, "%s: failed to find request %lu, sector %llus\n", func, |
| 1531 | (unsigned long)id, (unsigned long long)sector); |
| 1532 | } |
Andreas Gruenbacher | 668eebc | 2011-01-20 17:14:26 +0100 | [diff] [blame] | 1533 | return NULL; |
| 1534 | } |
| 1535 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 1536 | static int receive_DataReply(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 1537 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1538 | { |
| 1539 | struct drbd_request *req; |
| 1540 | sector_t sector; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1541 | int ok; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 1542 | struct p_data *p = &mdev->tconn->data.rbuf.data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1543 | |
| 1544 | sector = be64_to_cpu(p->sector); |
| 1545 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1546 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 1547 | 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] | 1548 | spin_unlock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 1549 | if (unlikely(!req)) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1550 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1551 | |
Bart Van Assche | 24c4830 | 2011-05-21 18:32:29 +0200 | [diff] [blame] | 1552 | /* 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] | 1553 | * special casing it there for the various failure cases. |
| 1554 | * still no race with drbd_fail_pending_reads */ |
| 1555 | ok = recv_dless_read(mdev, req, sector, data_size); |
| 1556 | |
| 1557 | if (ok) |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 1558 | req_mod(req, DATA_RECEIVED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1559 | /* else: nothing. handled from drbd_disconnect... |
| 1560 | * I don't think we may complete this just yet |
| 1561 | * in case we are "on-disconnect: freeze" */ |
| 1562 | |
| 1563 | return ok; |
| 1564 | } |
| 1565 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 1566 | static int receive_RSDataReply(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 1567 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1568 | { |
| 1569 | sector_t sector; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1570 | int ok; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 1571 | struct p_data *p = &mdev->tconn->data.rbuf.data; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1572 | |
| 1573 | sector = be64_to_cpu(p->sector); |
| 1574 | D_ASSERT(p->block_id == ID_SYNCER); |
| 1575 | |
| 1576 | if (get_ldev(mdev)) { |
| 1577 | /* data is submitted to disk within recv_resync_read. |
| 1578 | * corresponding put_ldev done below on error, |
Andreas Gruenbacher | fcefa62 | 2011-02-17 16:46:59 +0100 | [diff] [blame] | 1579 | * or in drbd_peer_request_endio. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1580 | ok = recv_resync_read(mdev, sector, data_size); |
| 1581 | } else { |
| 1582 | if (__ratelimit(&drbd_ratelimit_state)) |
| 1583 | dev_err(DEV, "Can not write resync data to local disk.\n"); |
| 1584 | |
| 1585 | ok = drbd_drain_block(mdev, data_size); |
| 1586 | |
Lars Ellenberg | 2b2bf21 | 2010-10-06 11:46:55 +0200 | [diff] [blame] | 1587 | drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 1590 | atomic_add(data_size >> 9, &mdev->rs_sect_in); |
| 1591 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1592 | return ok; |
| 1593 | } |
| 1594 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1595 | static int w_restart_write(struct drbd_work *w, int cancel) |
| 1596 | { |
| 1597 | struct drbd_request *req = container_of(w, struct drbd_request, w); |
| 1598 | struct drbd_conf *mdev = w->mdev; |
| 1599 | struct bio *bio; |
| 1600 | unsigned long start_time; |
| 1601 | unsigned long flags; |
| 1602 | |
| 1603 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); |
| 1604 | if (!expect(req->rq_state & RQ_POSTPONED)) { |
| 1605 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); |
| 1606 | return 0; |
| 1607 | } |
| 1608 | bio = req->master_bio; |
| 1609 | start_time = req->start_time; |
| 1610 | /* Postponed requests will not have their master_bio completed! */ |
| 1611 | __req_mod(req, DISCARD_WRITE, NULL); |
| 1612 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); |
| 1613 | |
| 1614 | while (__drbd_make_request(mdev, bio, start_time)) |
| 1615 | /* retry */ ; |
| 1616 | return 1; |
| 1617 | } |
| 1618 | |
| 1619 | static void restart_conflicting_writes(struct drbd_conf *mdev, |
| 1620 | sector_t sector, int size) |
| 1621 | { |
| 1622 | struct drbd_interval *i; |
| 1623 | struct drbd_request *req; |
| 1624 | |
| 1625 | drbd_for_each_overlap(i, &mdev->write_requests, sector, size) { |
| 1626 | if (!i->local) |
| 1627 | continue; |
| 1628 | req = container_of(i, struct drbd_request, i); |
| 1629 | if (req->rq_state & RQ_LOCAL_PENDING || |
| 1630 | !(req->rq_state & RQ_POSTPONED)) |
| 1631 | continue; |
| 1632 | if (expect(list_empty(&req->w.list))) { |
| 1633 | req->w.mdev = mdev; |
| 1634 | req->w.cb = w_restart_write; |
| 1635 | drbd_queue_work(&mdev->tconn->data.work, &req->w); |
| 1636 | } |
| 1637 | } |
| 1638 | } |
| 1639 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1640 | /* e_end_block() is called via drbd_process_done_ee(). |
| 1641 | * this means this function only runs in the asender thread |
| 1642 | */ |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 1643 | static int e_end_block(struct drbd_work *w, int cancel) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1644 | { |
Andreas Gruenbacher | 8050e6d | 2011-02-18 16:12:48 +0100 | [diff] [blame] | 1645 | struct drbd_peer_request *peer_req = |
| 1646 | container_of(w, struct drbd_peer_request, w); |
Philipp Reisner | 00d5694 | 2011-02-09 18:09:48 +0100 | [diff] [blame] | 1647 | struct drbd_conf *mdev = w->mdev; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1648 | sector_t sector = peer_req->i.sector; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1649 | int ok = 1, pcmd; |
| 1650 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 1651 | if (mdev->tconn->net_conf->wire_protocol == DRBD_PROT_C) { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1652 | if (likely((peer_req->flags & EE_WAS_ERROR) == 0)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1653 | pcmd = (mdev->state.conn >= C_SYNC_SOURCE && |
| 1654 | mdev->state.conn <= C_PAUSED_SYNC_T && |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1655 | peer_req->flags & EE_MAY_SET_IN_SYNC) ? |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1656 | P_RS_WRITE_ACK : P_WRITE_ACK; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1657 | ok &= drbd_send_ack(mdev, pcmd, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1658 | if (pcmd == P_RS_WRITE_ACK) |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1659 | drbd_set_in_sync(mdev, sector, peer_req->i.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1660 | } else { |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1661 | ok = drbd_send_ack(mdev, P_NEG_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1662 | /* we expect it to be marked out of sync anyways... |
| 1663 | * maybe assert this? */ |
| 1664 | } |
| 1665 | dec_unacked(mdev); |
| 1666 | } |
| 1667 | /* we delete from the conflict detection hash _after_ we sent out the |
| 1668 | * P_WRITE_ACK / P_NEG_ACK, to get the sequence number right. */ |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 1669 | if (mdev->tconn->net_conf->two_primaries) { |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1670 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1671 | D_ASSERT(!drbd_interval_empty(&peer_req->i)); |
| 1672 | drbd_remove_epoch_entry_interval(mdev, peer_req); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1673 | if (peer_req->flags & EE_RESTART_REQUESTS) |
| 1674 | restart_conflicting_writes(mdev, sector, peer_req->i.size); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1675 | spin_unlock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | bb3bfe9 | 2011-01-21 15:59:23 +0100 | [diff] [blame] | 1676 | } else |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1677 | D_ASSERT(drbd_interval_empty(&peer_req->i)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1678 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1679 | drbd_may_finish_epoch(mdev, peer_req->epoch, EV_PUT + (cancel ? EV_CLEANUP : 0)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1680 | |
| 1681 | return ok; |
| 1682 | } |
| 1683 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1684 | 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] | 1685 | { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1686 | struct drbd_conf *mdev = w->mdev; |
Andreas Gruenbacher | 8050e6d | 2011-02-18 16:12:48 +0100 | [diff] [blame] | 1687 | struct drbd_peer_request *peer_req = |
| 1688 | container_of(w, struct drbd_peer_request, w); |
Andreas Gruenbacher | 206d358 | 2011-02-26 23:19:15 +0100 | [diff] [blame] | 1689 | int ok; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1690 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1691 | ok = drbd_send_ack(mdev, ack, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1692 | dec_unacked(mdev); |
| 1693 | |
| 1694 | return ok; |
| 1695 | } |
| 1696 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1697 | static int e_send_discard_write(struct drbd_work *w, int unused) |
| 1698 | { |
| 1699 | return e_send_ack(w, P_DISCARD_WRITE); |
| 1700 | } |
| 1701 | |
| 1702 | static int e_send_retry_write(struct drbd_work *w, int unused) |
| 1703 | { |
| 1704 | struct drbd_tconn *tconn = w->mdev->tconn; |
| 1705 | |
| 1706 | return e_send_ack(w, tconn->agreed_pro_version >= 100 ? |
| 1707 | P_RETRY_WRITE : P_DISCARD_WRITE); |
| 1708 | } |
| 1709 | |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 1710 | static bool seq_greater(u32 a, u32 b) |
| 1711 | { |
| 1712 | /* |
| 1713 | * We assume 32-bit wrap-around here. |
| 1714 | * For 24-bit wrap-around, we would have to shift: |
| 1715 | * a <<= 8; b <<= 8; |
| 1716 | */ |
| 1717 | return (s32)a - (s32)b > 0; |
| 1718 | } |
| 1719 | |
| 1720 | static u32 seq_max(u32 a, u32 b) |
| 1721 | { |
| 1722 | return seq_greater(a, b) ? a : b; |
| 1723 | } |
| 1724 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1725 | static bool need_peer_seq(struct drbd_conf *mdev) |
| 1726 | { |
| 1727 | struct drbd_tconn *tconn = mdev->tconn; |
| 1728 | |
| 1729 | /* |
| 1730 | * We only need to keep track of the last packet_seq number of our peer |
| 1731 | * if we are in dual-primary mode and we have the discard flag set; see |
| 1732 | * handle_write_conflicts(). |
| 1733 | */ |
| 1734 | return tconn->net_conf->two_primaries && |
| 1735 | test_bit(DISCARD_CONCURRENT, &tconn->flags); |
| 1736 | } |
| 1737 | |
Andreas Gruenbacher | 43ae077 | 2011-02-03 18:42:08 +0100 | [diff] [blame] | 1738 | 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] | 1739 | { |
Lars Ellenberg | 3c13b68 | 2011-02-23 16:10:01 +0100 | [diff] [blame] | 1740 | unsigned int newest_peer_seq; |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 1741 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1742 | if (need_peer_seq(mdev)) { |
| 1743 | spin_lock(&mdev->peer_seq_lock); |
Lars Ellenberg | 3c13b68 | 2011-02-23 16:10:01 +0100 | [diff] [blame] | 1744 | newest_peer_seq = seq_max(mdev->peer_seq, peer_seq); |
| 1745 | mdev->peer_seq = newest_peer_seq; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1746 | spin_unlock(&mdev->peer_seq_lock); |
Lars Ellenberg | 3c13b68 | 2011-02-23 16:10:01 +0100 | [diff] [blame] | 1747 | /* wake up only if we actually changed mdev->peer_seq */ |
| 1748 | if (peer_seq == newest_peer_seq) |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1749 | wake_up(&mdev->seq_wait); |
| 1750 | } |
Andreas Gruenbacher | 3e394da | 2011-01-26 18:36:55 +0100 | [diff] [blame] | 1751 | } |
| 1752 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1753 | /* Called from receive_Data. |
| 1754 | * Synchronize packets on sock with packets on msock. |
| 1755 | * |
| 1756 | * This is here so even when a P_DATA packet traveling via sock overtook an Ack |
| 1757 | * packet traveling on msock, they are still processed in the order they have |
| 1758 | * been sent. |
| 1759 | * |
| 1760 | * Note: we don't care for Ack packets overtaking P_DATA packets. |
| 1761 | * |
| 1762 | * In case packet_seq is larger than mdev->peer_seq number, there are |
| 1763 | * outstanding packets on the msock. We wait for them to arrive. |
| 1764 | * In case we are the logically next packet, we update mdev->peer_seq |
| 1765 | * ourselves. Correctly handles 32bit wrap around. |
| 1766 | * |
| 1767 | * Assume we have a 10 GBit connection, that is about 1<<30 byte per second, |
| 1768 | * about 1<<21 sectors per second. So "worst" case, we have 1<<3 == 8 seconds |
| 1769 | * for the 24bit wrap (historical atomic_t guarantee on some archs), and we have |
| 1770 | * 1<<9 == 512 seconds aka ages for the 32bit wrap around... |
| 1771 | * |
| 1772 | * returns 0 if we may process the packet, |
| 1773 | * -ERESTARTSYS if we were interrupted (by disconnect signal). */ |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1774 | 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] | 1775 | { |
| 1776 | DEFINE_WAIT(wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1777 | long timeout; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1778 | int ret; |
| 1779 | |
| 1780 | if (!need_peer_seq(mdev)) |
| 1781 | return 0; |
| 1782 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1783 | spin_lock(&mdev->peer_seq_lock); |
| 1784 | for (;;) { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1785 | if (!seq_greater(peer_seq - 1, mdev->peer_seq)) { |
| 1786 | mdev->peer_seq = seq_max(mdev->peer_seq, peer_seq); |
| 1787 | ret = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1788 | break; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1789 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1790 | if (signal_pending(current)) { |
| 1791 | ret = -ERESTARTSYS; |
| 1792 | break; |
| 1793 | } |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1794 | prepare_to_wait(&mdev->seq_wait, &wait, TASK_INTERRUPTIBLE); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1795 | spin_unlock(&mdev->peer_seq_lock); |
Andreas Gruenbacher | 71b1c1e | 2011-03-01 15:40:43 +0100 | [diff] [blame] | 1796 | timeout = mdev->tconn->net_conf->ping_timeo*HZ/10; |
| 1797 | timeout = schedule_timeout(timeout); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1798 | spin_lock(&mdev->peer_seq_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1799 | if (!timeout) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1800 | ret = -ETIMEDOUT; |
Andreas Gruenbacher | 71b1c1e | 2011-03-01 15:40:43 +0100 | [diff] [blame] | 1801 | dev_err(DEV, "Timed out waiting for missing ack packets; disconnecting\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1802 | break; |
| 1803 | } |
| 1804 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1805 | spin_unlock(&mdev->peer_seq_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1806 | finish_wait(&mdev->seq_wait, &wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1807 | return ret; |
| 1808 | } |
| 1809 | |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 1810 | /* see also bio_flags_to_wire() |
| 1811 | * DRBD_REQ_*, because we need to semantically map the flags to data packet |
| 1812 | * flags and back. We may replicate to other kernel versions. */ |
| 1813 | 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] | 1814 | { |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 1815 | return (dpf & DP_RW_SYNC ? REQ_SYNC : 0) | |
| 1816 | (dpf & DP_FUA ? REQ_FUA : 0) | |
| 1817 | (dpf & DP_FLUSH ? REQ_FLUSH : 0) | |
| 1818 | (dpf & DP_DISCARD ? REQ_DISCARD : 0); |
Philipp Reisner | 76d2e7e | 2010-08-25 11:58:05 +0200 | [diff] [blame] | 1819 | } |
| 1820 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1821 | static void fail_postponed_requests(struct drbd_conf *mdev, sector_t sector, |
| 1822 | unsigned int size) |
| 1823 | { |
| 1824 | struct drbd_interval *i; |
| 1825 | |
| 1826 | repeat: |
| 1827 | drbd_for_each_overlap(i, &mdev->write_requests, sector, size) { |
| 1828 | struct drbd_request *req; |
| 1829 | struct bio_and_error m; |
| 1830 | |
| 1831 | if (!i->local) |
| 1832 | continue; |
| 1833 | req = container_of(i, struct drbd_request, i); |
| 1834 | if (!(req->rq_state & RQ_POSTPONED)) |
| 1835 | continue; |
| 1836 | req->rq_state &= ~RQ_POSTPONED; |
| 1837 | __req_mod(req, NEG_ACKED, &m); |
| 1838 | spin_unlock_irq(&mdev->tconn->req_lock); |
| 1839 | if (m.bio) |
| 1840 | complete_master_bio(mdev, &m); |
| 1841 | spin_lock_irq(&mdev->tconn->req_lock); |
| 1842 | goto repeat; |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | static int handle_write_conflicts(struct drbd_conf *mdev, |
| 1847 | struct drbd_peer_request *peer_req) |
| 1848 | { |
| 1849 | struct drbd_tconn *tconn = mdev->tconn; |
| 1850 | bool resolve_conflicts = test_bit(DISCARD_CONCURRENT, &tconn->flags); |
| 1851 | sector_t sector = peer_req->i.sector; |
| 1852 | const unsigned int size = peer_req->i.size; |
| 1853 | struct drbd_interval *i; |
| 1854 | bool equal; |
| 1855 | int err; |
| 1856 | |
| 1857 | /* |
| 1858 | * Inserting the peer request into the write_requests tree will prevent |
| 1859 | * new conflicting local requests from being added. |
| 1860 | */ |
| 1861 | drbd_insert_interval(&mdev->write_requests, &peer_req->i); |
| 1862 | |
| 1863 | repeat: |
| 1864 | drbd_for_each_overlap(i, &mdev->write_requests, sector, size) { |
| 1865 | if (i == &peer_req->i) |
| 1866 | continue; |
| 1867 | |
| 1868 | if (!i->local) { |
| 1869 | /* |
| 1870 | * Our peer has sent a conflicting remote request; this |
| 1871 | * should not happen in a two-node setup. Wait for the |
| 1872 | * earlier peer request to complete. |
| 1873 | */ |
| 1874 | err = drbd_wait_misc(mdev, i); |
| 1875 | if (err) |
| 1876 | goto out; |
| 1877 | goto repeat; |
| 1878 | } |
| 1879 | |
| 1880 | equal = i->sector == sector && i->size == size; |
| 1881 | if (resolve_conflicts) { |
| 1882 | /* |
| 1883 | * If the peer request is fully contained within the |
| 1884 | * overlapping request, it can be discarded; otherwise, |
| 1885 | * it will be retried once all overlapping requests |
| 1886 | * have completed. |
| 1887 | */ |
| 1888 | bool discard = i->sector <= sector && i->sector + |
| 1889 | (i->size >> 9) >= sector + (size >> 9); |
| 1890 | |
| 1891 | if (!equal) |
| 1892 | dev_alert(DEV, "Concurrent writes detected: " |
| 1893 | "local=%llus +%u, remote=%llus +%u, " |
| 1894 | "assuming %s came first\n", |
| 1895 | (unsigned long long)i->sector, i->size, |
| 1896 | (unsigned long long)sector, size, |
| 1897 | discard ? "local" : "remote"); |
| 1898 | |
| 1899 | inc_unacked(mdev); |
| 1900 | peer_req->w.cb = discard ? e_send_discard_write : |
| 1901 | e_send_retry_write; |
| 1902 | list_add_tail(&peer_req->w.list, &mdev->done_ee); |
| 1903 | wake_asender(mdev->tconn); |
| 1904 | |
| 1905 | err = -ENOENT; |
| 1906 | goto out; |
| 1907 | } else { |
| 1908 | struct drbd_request *req = |
| 1909 | container_of(i, struct drbd_request, i); |
| 1910 | |
| 1911 | if (!equal) |
| 1912 | dev_alert(DEV, "Concurrent writes detected: " |
| 1913 | "local=%llus +%u, remote=%llus +%u\n", |
| 1914 | (unsigned long long)i->sector, i->size, |
| 1915 | (unsigned long long)sector, size); |
| 1916 | |
| 1917 | if (req->rq_state & RQ_LOCAL_PENDING || |
| 1918 | !(req->rq_state & RQ_POSTPONED)) { |
| 1919 | /* |
| 1920 | * Wait for the node with the discard flag to |
| 1921 | * decide if this request will be discarded or |
| 1922 | * retried. Requests that are discarded will |
| 1923 | * disappear from the write_requests tree. |
| 1924 | * |
| 1925 | * In addition, wait for the conflicting |
| 1926 | * request to finish locally before submitting |
| 1927 | * the conflicting peer request. |
| 1928 | */ |
| 1929 | err = drbd_wait_misc(mdev, &req->i); |
| 1930 | if (err) { |
| 1931 | _conn_request_state(mdev->tconn, |
| 1932 | NS(conn, C_TIMEOUT), |
| 1933 | CS_HARD); |
| 1934 | fail_postponed_requests(mdev, sector, size); |
| 1935 | goto out; |
| 1936 | } |
| 1937 | goto repeat; |
| 1938 | } |
| 1939 | /* |
| 1940 | * Remember to restart the conflicting requests after |
| 1941 | * the new peer request has completed. |
| 1942 | */ |
| 1943 | peer_req->flags |= EE_RESTART_REQUESTS; |
| 1944 | } |
| 1945 | } |
| 1946 | err = 0; |
| 1947 | |
| 1948 | out: |
| 1949 | if (err) |
| 1950 | drbd_remove_epoch_entry_interval(mdev, peer_req); |
| 1951 | return err; |
| 1952 | } |
| 1953 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1954 | /* mirrored write */ |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 1955 | static int receive_Data(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 1956 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1957 | { |
| 1958 | sector_t sector; |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1959 | struct drbd_peer_request *peer_req; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 1960 | struct p_data *p = &mdev->tconn->data.rbuf.data; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1961 | u32 peer_seq = be32_to_cpu(p->seq_num); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1962 | int rw = WRITE; |
| 1963 | u32 dp_flags; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1964 | int err; |
| 1965 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1966 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1967 | if (!get_ldev(mdev)) { |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1968 | err = wait_for_and_update_peer_seq(mdev, peer_seq); |
Lars Ellenberg | 2b2bf21 | 2010-10-06 11:46:55 +0200 | [diff] [blame] | 1969 | drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1970 | atomic_inc(&mdev->current_epoch->epoch_size); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 1971 | return drbd_drain_block(mdev, data_size) && err == 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Andreas Gruenbacher | fcefa62 | 2011-02-17 16:46:59 +0100 | [diff] [blame] | 1974 | /* |
| 1975 | * Corresponding put_ldev done either below (on various errors), or in |
| 1976 | * drbd_peer_request_endio, if we successfully submit the data at the |
| 1977 | * end of this function. |
| 1978 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1979 | |
| 1980 | sector = be64_to_cpu(p->sector); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1981 | peer_req = read_in_block(mdev, p->block_id, sector, data_size); |
| 1982 | if (!peer_req) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1983 | put_ldev(mdev); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1984 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1987 | peer_req->w.cb = e_end_block; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1988 | |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 1989 | dp_flags = be32_to_cpu(p->dp_flags); |
| 1990 | rw |= wire_flags_to_bio(mdev, dp_flags); |
| 1991 | |
| 1992 | if (dp_flags & DP_MAY_SET_IN_SYNC) |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1993 | peer_req->flags |= EE_MAY_SET_IN_SYNC; |
Lars Ellenberg | 688593c | 2010-11-17 22:25:03 +0100 | [diff] [blame] | 1994 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1995 | spin_lock(&mdev->epoch_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 1996 | peer_req->epoch = mdev->current_epoch; |
| 1997 | atomic_inc(&peer_req->epoch->epoch_size); |
| 1998 | atomic_inc(&peer_req->epoch->active); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1999 | spin_unlock(&mdev->epoch_lock); |
| 2000 | |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2001 | if (mdev->tconn->net_conf->two_primaries) { |
| 2002 | err = wait_for_and_update_peer_seq(mdev, peer_seq); |
| 2003 | if (err) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2004 | goto out_interrupted; |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2005 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2006 | err = handle_write_conflicts(mdev, peer_req); |
| 2007 | if (err) { |
| 2008 | spin_unlock_irq(&mdev->tconn->req_lock); |
| 2009 | if (err == -ENOENT) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2010 | put_ldev(mdev); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2011 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2012 | } |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2013 | goto out_interrupted; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2014 | } |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 2015 | } else |
| 2016 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2017 | list_add(&peer_req->w.list, &mdev->active_ee); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2018 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2019 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2020 | switch (mdev->tconn->net_conf->wire_protocol) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2021 | case DRBD_PROT_C: |
| 2022 | inc_unacked(mdev); |
| 2023 | /* corresponding dec_unacked() in e_end_block() |
| 2024 | * respective _drbd_clear_done_ee */ |
| 2025 | break; |
| 2026 | case DRBD_PROT_B: |
| 2027 | /* I really don't like it that the receiver thread |
| 2028 | * sends on the msock, but anyways */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2029 | drbd_send_ack(mdev, P_RECV_ACK, peer_req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2030 | break; |
| 2031 | case DRBD_PROT_A: |
| 2032 | /* nothing to do */ |
| 2033 | break; |
| 2034 | } |
| 2035 | |
Lars Ellenberg | 6719fb0 | 2010-10-18 23:04:07 +0200 | [diff] [blame] | 2036 | if (mdev->state.pdsk < D_INCONSISTENT) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2037 | /* In case we have the only disk of the cluster, */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2038 | drbd_set_out_of_sync(mdev, peer_req->i.sector, peer_req->i.size); |
| 2039 | peer_req->flags |= EE_CALL_AL_COMPLETE_IO; |
| 2040 | peer_req->flags &= ~EE_MAY_SET_IN_SYNC; |
| 2041 | drbd_al_begin_io(mdev, peer_req->i.sector); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 2044 | if (drbd_submit_peer_request(mdev, peer_req, rw, DRBD_FAULT_DT_WR) == 0) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2045 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2046 | |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 2047 | /* don't care for the reason here */ |
| 2048 | dev_err(DEV, "submit failed, triggering re-connect\n"); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2049 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2050 | list_del(&peer_req->w.list); |
| 2051 | drbd_remove_epoch_entry_interval(mdev, peer_req); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2052 | spin_unlock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2053 | if (peer_req->flags & EE_CALL_AL_COMPLETE_IO) |
| 2054 | drbd_al_complete_io(mdev, peer_req->i.sector); |
Lars Ellenberg | 22cc37a | 2010-09-14 20:40:41 +0200 | [diff] [blame] | 2055 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2056 | out_interrupted: |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2057 | drbd_may_finish_epoch(mdev, peer_req->epoch, EV_PUT + EV_CLEANUP); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2058 | put_ldev(mdev); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2059 | drbd_free_ee(mdev, peer_req); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2060 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2063 | /* We may throttle resync, if the lower device seems to be busy, |
| 2064 | * and current sync rate is above c_min_rate. |
| 2065 | * |
| 2066 | * To decide whether or not the lower device is busy, we use a scheme similar |
| 2067 | * to MD RAID is_mddev_idle(): if the partition stats reveal "significant" |
| 2068 | * (more than 64 sectors) of activity we cannot account for with our own resync |
| 2069 | * activity, it obviously is "busy". |
| 2070 | * |
| 2071 | * The current sync rate used here uses only the most recent two step marks, |
| 2072 | * to have a short time average so we can react faster. |
| 2073 | */ |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2074 | 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] | 2075 | { |
| 2076 | struct gendisk *disk = mdev->ldev->backing_bdev->bd_contains->bd_disk; |
| 2077 | unsigned long db, dt, dbdt; |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2078 | struct lc_element *tmp; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2079 | int curr_events; |
| 2080 | int throttle = 0; |
| 2081 | |
| 2082 | /* feature disabled? */ |
| 2083 | if (mdev->sync_conf.c_min_rate == 0) |
| 2084 | return 0; |
| 2085 | |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2086 | spin_lock_irq(&mdev->al_lock); |
| 2087 | tmp = lc_find(mdev->resync, BM_SECT_TO_EXT(sector)); |
| 2088 | if (tmp) { |
| 2089 | struct bm_extent *bm_ext = lc_entry(tmp, struct bm_extent, lce); |
| 2090 | if (test_bit(BME_PRIORITY, &bm_ext->flags)) { |
| 2091 | spin_unlock_irq(&mdev->al_lock); |
| 2092 | return 0; |
| 2093 | } |
| 2094 | /* Do not slow down if app IO is already waiting for this extent */ |
| 2095 | } |
| 2096 | spin_unlock_irq(&mdev->al_lock); |
| 2097 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2098 | curr_events = (int)part_stat_read(&disk->part0, sectors[0]) + |
| 2099 | (int)part_stat_read(&disk->part0, sectors[1]) - |
| 2100 | atomic_read(&mdev->rs_sect_ev); |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2101 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2102 | if (!mdev->rs_last_events || curr_events - mdev->rs_last_events > 64) { |
| 2103 | unsigned long rs_left; |
| 2104 | int i; |
| 2105 | |
| 2106 | mdev->rs_last_events = curr_events; |
| 2107 | |
| 2108 | /* sync speed average over the last 2*DRBD_SYNC_MARK_STEP, |
| 2109 | * approx. */ |
Lars Ellenberg | 2649f08 | 2010-11-05 10:05:47 +0100 | [diff] [blame] | 2110 | i = (mdev->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS; |
| 2111 | |
| 2112 | if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T) |
| 2113 | rs_left = mdev->ov_left; |
| 2114 | else |
| 2115 | rs_left = drbd_bm_total_weight(mdev) - mdev->rs_failed; |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2116 | |
| 2117 | dt = ((long)jiffies - (long)mdev->rs_mark_time[i]) / HZ; |
| 2118 | if (!dt) |
| 2119 | dt++; |
| 2120 | db = mdev->rs_mark_left[i] - rs_left; |
| 2121 | dbdt = Bit2KB(db/dt); |
| 2122 | |
| 2123 | if (dbdt > mdev->sync_conf.c_min_rate) |
| 2124 | throttle = 1; |
| 2125 | } |
| 2126 | return throttle; |
| 2127 | } |
| 2128 | |
| 2129 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 2130 | static int receive_DataRequest(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 2131 | unsigned int digest_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2132 | { |
| 2133 | sector_t sector; |
| 2134 | const sector_t capacity = drbd_get_capacity(mdev->this_bdev); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2135 | struct drbd_peer_request *peer_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2136 | struct digest_info *di = NULL; |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2137 | int size, verb; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2138 | unsigned int fault_type; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 2139 | struct p_block_req *p = &mdev->tconn->data.rbuf.block_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2140 | |
| 2141 | sector = be64_to_cpu(p->sector); |
| 2142 | size = be32_to_cpu(p->blksize); |
| 2143 | |
Andreas Gruenbacher | c670a39 | 2011-02-21 12:41:39 +0100 | [diff] [blame] | 2144 | if (size <= 0 || !IS_ALIGNED(size, 512) || size > DRBD_MAX_BIO_SIZE) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2145 | dev_err(DEV, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, |
| 2146 | (unsigned long long)sector, size); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2147 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2148 | } |
| 2149 | if (sector + (size>>9) > capacity) { |
| 2150 | dev_err(DEV, "%s:%d: sector: %llus, size: %u\n", __FILE__, __LINE__, |
| 2151 | (unsigned long long)sector, size); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2152 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | if (!get_ldev_if_state(mdev, D_UP_TO_DATE)) { |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2156 | verb = 1; |
| 2157 | switch (cmd) { |
| 2158 | case P_DATA_REQUEST: |
| 2159 | drbd_send_ack_rp(mdev, P_NEG_DREPLY, p); |
| 2160 | break; |
| 2161 | case P_RS_DATA_REQUEST: |
| 2162 | case P_CSUM_RS_REQUEST: |
| 2163 | case P_OV_REQUEST: |
| 2164 | drbd_send_ack_rp(mdev, P_NEG_RS_DREPLY , p); |
| 2165 | break; |
| 2166 | case P_OV_REPLY: |
| 2167 | verb = 0; |
| 2168 | dec_rs_pending(mdev); |
| 2169 | drbd_send_ack_ex(mdev, P_OV_RESULT, sector, size, ID_IN_SYNC); |
| 2170 | break; |
| 2171 | default: |
| 2172 | dev_err(DEV, "unexpected command (%s) in receive_DataRequest\n", |
| 2173 | cmdname(cmd)); |
| 2174 | } |
| 2175 | if (verb && __ratelimit(&drbd_ratelimit_state)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2176 | dev_err(DEV, "Can not satisfy peer's read request, " |
| 2177 | "no local data.\n"); |
Philipp Reisner | b18b37b | 2010-10-13 15:32:44 +0200 | [diff] [blame] | 2178 | |
Lars Ellenberg | a821cc4 | 2010-09-06 12:31:37 +0200 | [diff] [blame] | 2179 | /* drain possibly payload */ |
| 2180 | return drbd_drain_block(mdev, digest_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | /* GFP_NOIO, because we must not cause arbitrary write-out: in a DRBD |
| 2184 | * "criss-cross" setup, that might cause write-out on some other DRBD, |
| 2185 | * which in turn might block on the other node at this very place. */ |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2186 | peer_req = drbd_alloc_ee(mdev, p->block_id, sector, size, GFP_NOIO); |
| 2187 | if (!peer_req) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2188 | put_ldev(mdev); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2189 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 2192 | switch (cmd) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2193 | case P_DATA_REQUEST: |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2194 | peer_req->w.cb = w_e_end_data_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2195 | fault_type = DRBD_FAULT_DT_RD; |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2196 | /* application IO, don't drbd_rs_begin_io */ |
| 2197 | goto submit; |
| 2198 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2199 | case P_RS_DATA_REQUEST: |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2200 | peer_req->w.cb = w_e_end_rsdata_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2201 | fault_type = DRBD_FAULT_RS_RD; |
Lars Ellenberg | 5f9915b | 2010-11-09 14:15:24 +0100 | [diff] [blame] | 2202 | /* used in the sector offset progress display */ |
| 2203 | mdev->bm_resync_fo = BM_SECT_TO_BIT(sector); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2204 | break; |
| 2205 | |
| 2206 | case P_OV_REPLY: |
| 2207 | case P_CSUM_RS_REQUEST: |
| 2208 | fault_type = DRBD_FAULT_RS_RD; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2209 | di = kmalloc(sizeof(*di) + digest_size, GFP_NOIO); |
| 2210 | if (!di) |
| 2211 | goto out_free_e; |
| 2212 | |
| 2213 | di->digest_size = digest_size; |
| 2214 | di->digest = (((char *)di)+sizeof(struct digest_info)); |
| 2215 | |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2216 | peer_req->digest = di; |
| 2217 | peer_req->flags |= EE_HAS_DIGEST; |
Lars Ellenberg | c36c3ce | 2010-08-11 20:42:55 +0200 | [diff] [blame] | 2218 | |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 2219 | if (drbd_recv(mdev->tconn, di->digest, digest_size) != digest_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2220 | goto out_free_e; |
| 2221 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 2222 | if (cmd == P_CSUM_RS_REQUEST) { |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2223 | D_ASSERT(mdev->tconn->agreed_pro_version >= 89); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2224 | peer_req->w.cb = w_e_end_csum_rs_req; |
Lars Ellenberg | 5f9915b | 2010-11-09 14:15:24 +0100 | [diff] [blame] | 2225 | /* used in the sector offset progress display */ |
| 2226 | mdev->bm_resync_fo = BM_SECT_TO_BIT(sector); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 2227 | } else if (cmd == P_OV_REPLY) { |
Lars Ellenberg | 2649f08 | 2010-11-05 10:05:47 +0100 | [diff] [blame] | 2228 | /* track progress, we may need to throttle */ |
| 2229 | atomic_add(size >> 9, &mdev->rs_sect_in); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2230 | peer_req->w.cb = w_e_end_ov_reply; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2231 | dec_rs_pending(mdev); |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2232 | /* drbd_rs_begin_io done when we sent this request, |
| 2233 | * but accounting still needs to be done. */ |
| 2234 | goto submit_for_resync; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2235 | } |
| 2236 | break; |
| 2237 | |
| 2238 | case P_OV_REQUEST: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2239 | if (mdev->ov_start_sector == ~(sector_t)0 && |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2240 | mdev->tconn->agreed_pro_version >= 90) { |
Lars Ellenberg | de228bb | 2010-11-05 09:43:15 +0100 | [diff] [blame] | 2241 | unsigned long now = jiffies; |
| 2242 | int i; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2243 | mdev->ov_start_sector = sector; |
| 2244 | mdev->ov_position = sector; |
Lars Ellenberg | 30b743a | 2010-11-05 09:39:06 +0100 | [diff] [blame] | 2245 | mdev->ov_left = drbd_bm_bits(mdev) - BM_SECT_TO_BIT(sector); |
| 2246 | mdev->rs_total = mdev->ov_left; |
Lars Ellenberg | de228bb | 2010-11-05 09:43:15 +0100 | [diff] [blame] | 2247 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { |
| 2248 | mdev->rs_mark_left[i] = mdev->ov_left; |
| 2249 | mdev->rs_mark_time[i] = now; |
| 2250 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2251 | dev_info(DEV, "Online Verify start sector: %llu\n", |
| 2252 | (unsigned long long)sector); |
| 2253 | } |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2254 | peer_req->w.cb = w_e_end_ov_req; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2255 | fault_type = DRBD_FAULT_RS_RD; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2256 | break; |
| 2257 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2258 | default: |
| 2259 | dev_err(DEV, "unexpected command (%s) in receive_DataRequest\n", |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 2260 | cmdname(cmd)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2261 | fault_type = DRBD_FAULT_MAX; |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2262 | goto out_free_e; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2265 | /* Throttle, drbd_rs_begin_io and submit should become asynchronous |
| 2266 | * wrt the receiver, but it is not as straightforward as it may seem. |
| 2267 | * Various places in the resync start and stop logic assume resync |
| 2268 | * requests are processed in order, requeuing this on the worker thread |
| 2269 | * introduces a bunch of new code for synchronization between threads. |
| 2270 | * |
| 2271 | * Unlimited throttling before drbd_rs_begin_io may stall the resync |
| 2272 | * "forever", throttling after drbd_rs_begin_io will lock that extent |
| 2273 | * for application writes for the same time. For now, just throttle |
| 2274 | * here, where the rest of the code expects the receiver to sleep for |
| 2275 | * a while, anyways. |
| 2276 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2277 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2278 | /* Throttle before drbd_rs_begin_io, as that locks out application IO; |
| 2279 | * this defers syncer requests for some time, before letting at least |
| 2280 | * on request through. The resync controller on the receiving side |
| 2281 | * will adapt to the incoming rate accordingly. |
| 2282 | * |
| 2283 | * We cannot throttle here if remote is Primary/SyncTarget: |
| 2284 | * we would also throttle its application reads. |
| 2285 | * In that case, throttling is done on the SyncTarget only. |
| 2286 | */ |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 2287 | if (mdev->state.peer != R_PRIMARY && drbd_rs_should_slow_down(mdev, sector)) |
| 2288 | schedule_timeout_uninterruptible(HZ/10); |
| 2289 | if (drbd_rs_begin_io(mdev, sector)) |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2290 | goto out_free_e; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2291 | |
Lars Ellenberg | 0f0601f | 2010-08-11 23:40:24 +0200 | [diff] [blame] | 2292 | submit_for_resync: |
| 2293 | atomic_add(size >> 9, &mdev->rs_sect_ev); |
| 2294 | |
Lars Ellenberg | 80a40e4 | 2010-08-11 23:28:00 +0200 | [diff] [blame] | 2295 | submit: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2296 | inc_unacked(mdev); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2297 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2298 | list_add_tail(&peer_req->w.list, &mdev->read_ee); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2299 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2300 | |
Andreas Gruenbacher | fbe29de | 2011-02-17 16:38:35 +0100 | [diff] [blame] | 2301 | if (drbd_submit_peer_request(mdev, peer_req, READ, fault_type) == 0) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2302 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2303 | |
Lars Ellenberg | 10f6d992 | 2011-01-24 14:47:09 +0100 | [diff] [blame] | 2304 | /* don't care for the reason here */ |
| 2305 | dev_err(DEV, "submit failed, triggering re-connect\n"); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2306 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2307 | list_del(&peer_req->w.list); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2308 | spin_unlock_irq(&mdev->tconn->req_lock); |
Lars Ellenberg | 22cc37a | 2010-09-14 20:40:41 +0200 | [diff] [blame] | 2309 | /* no drbd_rs_complete_io(), we are dropping the connection anyways */ |
| 2310 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2311 | out_free_e: |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2312 | put_ldev(mdev); |
Andreas Gruenbacher | db830c4 | 2011-02-04 15:57:48 +0100 | [diff] [blame] | 2313 | drbd_free_ee(mdev, peer_req); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2314 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | static int drbd_asb_recover_0p(struct drbd_conf *mdev) __must_hold(local) |
| 2318 | { |
| 2319 | int self, peer, rv = -100; |
| 2320 | unsigned long ch_self, ch_peer; |
| 2321 | |
| 2322 | self = mdev->ldev->md.uuid[UI_BITMAP] & 1; |
| 2323 | peer = mdev->p_uuid[UI_BITMAP] & 1; |
| 2324 | |
| 2325 | ch_peer = mdev->p_uuid[UI_SIZE]; |
| 2326 | ch_self = mdev->comm_bm_set; |
| 2327 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2328 | switch (mdev->tconn->net_conf->after_sb_0p) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2329 | case ASB_CONSENSUS: |
| 2330 | case ASB_DISCARD_SECONDARY: |
| 2331 | case ASB_CALL_HELPER: |
| 2332 | dev_err(DEV, "Configuration error.\n"); |
| 2333 | break; |
| 2334 | case ASB_DISCONNECT: |
| 2335 | break; |
| 2336 | case ASB_DISCARD_YOUNGER_PRI: |
| 2337 | if (self == 0 && peer == 1) { |
| 2338 | rv = -1; |
| 2339 | break; |
| 2340 | } |
| 2341 | if (self == 1 && peer == 0) { |
| 2342 | rv = 1; |
| 2343 | break; |
| 2344 | } |
| 2345 | /* Else fall through to one of the other strategies... */ |
| 2346 | case ASB_DISCARD_OLDER_PRI: |
| 2347 | if (self == 0 && peer == 1) { |
| 2348 | rv = 1; |
| 2349 | break; |
| 2350 | } |
| 2351 | if (self == 1 && peer == 0) { |
| 2352 | rv = -1; |
| 2353 | break; |
| 2354 | } |
| 2355 | /* Else fall through to one of the other strategies... */ |
Lars Ellenberg | ad19bf6 | 2009-10-14 09:36:49 +0200 | [diff] [blame] | 2356 | 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] | 2357 | "Using discard-least-changes instead\n"); |
| 2358 | case ASB_DISCARD_ZERO_CHG: |
| 2359 | if (ch_peer == 0 && ch_self == 0) { |
Philipp Reisner | 25703f8 | 2011-02-07 14:35:25 +0100 | [diff] [blame] | 2360 | rv = test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2361 | ? -1 : 1; |
| 2362 | break; |
| 2363 | } else { |
| 2364 | if (ch_peer == 0) { rv = 1; break; } |
| 2365 | if (ch_self == 0) { rv = -1; break; } |
| 2366 | } |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2367 | if (mdev->tconn->net_conf->after_sb_0p == ASB_DISCARD_ZERO_CHG) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2368 | break; |
| 2369 | case ASB_DISCARD_LEAST_CHG: |
| 2370 | if (ch_self < ch_peer) |
| 2371 | rv = -1; |
| 2372 | else if (ch_self > ch_peer) |
| 2373 | rv = 1; |
| 2374 | else /* ( ch_self == ch_peer ) */ |
| 2375 | /* Well, then use something else. */ |
Philipp Reisner | 25703f8 | 2011-02-07 14:35:25 +0100 | [diff] [blame] | 2376 | rv = test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2377 | ? -1 : 1; |
| 2378 | break; |
| 2379 | case ASB_DISCARD_LOCAL: |
| 2380 | rv = -1; |
| 2381 | break; |
| 2382 | case ASB_DISCARD_REMOTE: |
| 2383 | rv = 1; |
| 2384 | } |
| 2385 | |
| 2386 | return rv; |
| 2387 | } |
| 2388 | |
| 2389 | static int drbd_asb_recover_1p(struct drbd_conf *mdev) __must_hold(local) |
| 2390 | { |
Andreas Gruenbacher | 6184ea2 | 2010-12-09 14:23:27 +0100 | [diff] [blame] | 2391 | int hg, rv = -100; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2392 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2393 | switch (mdev->tconn->net_conf->after_sb_1p) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2394 | case ASB_DISCARD_YOUNGER_PRI: |
| 2395 | case ASB_DISCARD_OLDER_PRI: |
| 2396 | case ASB_DISCARD_LEAST_CHG: |
| 2397 | case ASB_DISCARD_LOCAL: |
| 2398 | case ASB_DISCARD_REMOTE: |
| 2399 | dev_err(DEV, "Configuration error.\n"); |
| 2400 | break; |
| 2401 | case ASB_DISCONNECT: |
| 2402 | break; |
| 2403 | case ASB_CONSENSUS: |
| 2404 | hg = drbd_asb_recover_0p(mdev); |
| 2405 | if (hg == -1 && mdev->state.role == R_SECONDARY) |
| 2406 | rv = hg; |
| 2407 | if (hg == 1 && mdev->state.role == R_PRIMARY) |
| 2408 | rv = hg; |
| 2409 | break; |
| 2410 | case ASB_VIOLENTLY: |
| 2411 | rv = drbd_asb_recover_0p(mdev); |
| 2412 | break; |
| 2413 | case ASB_DISCARD_SECONDARY: |
| 2414 | return mdev->state.role == R_PRIMARY ? 1 : -1; |
| 2415 | case ASB_CALL_HELPER: |
| 2416 | hg = drbd_asb_recover_0p(mdev); |
| 2417 | if (hg == -1 && mdev->state.role == R_PRIMARY) { |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2418 | enum drbd_state_rv rv2; |
| 2419 | |
| 2420 | drbd_set_role(mdev, R_SECONDARY, 0); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2421 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, |
| 2422 | * we might be here in C_WF_REPORT_PARAMS which is transient. |
| 2423 | * 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] | 2424 | rv2 = drbd_change_state(mdev, CS_VERBOSE, NS(role, R_SECONDARY)); |
| 2425 | if (rv2 != SS_SUCCESS) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2426 | drbd_khelper(mdev, "pri-lost-after-sb"); |
| 2427 | } else { |
| 2428 | dev_warn(DEV, "Successfully gave up primary role.\n"); |
| 2429 | rv = hg; |
| 2430 | } |
| 2431 | } else |
| 2432 | rv = hg; |
| 2433 | } |
| 2434 | |
| 2435 | return rv; |
| 2436 | } |
| 2437 | |
| 2438 | static int drbd_asb_recover_2p(struct drbd_conf *mdev) __must_hold(local) |
| 2439 | { |
Andreas Gruenbacher | 6184ea2 | 2010-12-09 14:23:27 +0100 | [diff] [blame] | 2440 | int hg, rv = -100; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2441 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2442 | switch (mdev->tconn->net_conf->after_sb_2p) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2443 | case ASB_DISCARD_YOUNGER_PRI: |
| 2444 | case ASB_DISCARD_OLDER_PRI: |
| 2445 | case ASB_DISCARD_LEAST_CHG: |
| 2446 | case ASB_DISCARD_LOCAL: |
| 2447 | case ASB_DISCARD_REMOTE: |
| 2448 | case ASB_CONSENSUS: |
| 2449 | case ASB_DISCARD_SECONDARY: |
| 2450 | dev_err(DEV, "Configuration error.\n"); |
| 2451 | break; |
| 2452 | case ASB_VIOLENTLY: |
| 2453 | rv = drbd_asb_recover_0p(mdev); |
| 2454 | break; |
| 2455 | case ASB_DISCONNECT: |
| 2456 | break; |
| 2457 | case ASB_CALL_HELPER: |
| 2458 | hg = drbd_asb_recover_0p(mdev); |
| 2459 | if (hg == -1) { |
Andreas Gruenbacher | bb43794 | 2010-12-09 14:02:35 +0100 | [diff] [blame] | 2460 | enum drbd_state_rv rv2; |
| 2461 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2462 | /* drbd_change_state() does not sleep while in SS_IN_TRANSIENT_STATE, |
| 2463 | * we might be here in C_WF_REPORT_PARAMS which is transient. |
| 2464 | * 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] | 2465 | rv2 = drbd_change_state(mdev, CS_VERBOSE, NS(role, R_SECONDARY)); |
| 2466 | if (rv2 != SS_SUCCESS) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2467 | drbd_khelper(mdev, "pri-lost-after-sb"); |
| 2468 | } else { |
| 2469 | dev_warn(DEV, "Successfully gave up primary role.\n"); |
| 2470 | rv = hg; |
| 2471 | } |
| 2472 | } else |
| 2473 | rv = hg; |
| 2474 | } |
| 2475 | |
| 2476 | return rv; |
| 2477 | } |
| 2478 | |
| 2479 | static void drbd_uuid_dump(struct drbd_conf *mdev, char *text, u64 *uuid, |
| 2480 | u64 bits, u64 flags) |
| 2481 | { |
| 2482 | if (!uuid) { |
| 2483 | dev_info(DEV, "%s uuid info vanished while I was looking!\n", text); |
| 2484 | return; |
| 2485 | } |
| 2486 | dev_info(DEV, "%s %016llX:%016llX:%016llX:%016llX bits:%llu flags:%llX\n", |
| 2487 | text, |
| 2488 | (unsigned long long)uuid[UI_CURRENT], |
| 2489 | (unsigned long long)uuid[UI_BITMAP], |
| 2490 | (unsigned long long)uuid[UI_HISTORY_START], |
| 2491 | (unsigned long long)uuid[UI_HISTORY_END], |
| 2492 | (unsigned long long)bits, |
| 2493 | (unsigned long long)flags); |
| 2494 | } |
| 2495 | |
| 2496 | /* |
| 2497 | 100 after split brain try auto recover |
| 2498 | 2 C_SYNC_SOURCE set BitMap |
| 2499 | 1 C_SYNC_SOURCE use BitMap |
| 2500 | 0 no Sync |
| 2501 | -1 C_SYNC_TARGET use BitMap |
| 2502 | -2 C_SYNC_TARGET set BitMap |
| 2503 | -100 after split brain, disconnect |
| 2504 | -1000 unrelated data |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2505 | -1091 requires proto 91 |
| 2506 | -1096 requires proto 96 |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2507 | */ |
| 2508 | static int drbd_uuid_compare(struct drbd_conf *mdev, int *rule_nr) __must_hold(local) |
| 2509 | { |
| 2510 | u64 self, peer; |
| 2511 | int i, j; |
| 2512 | |
| 2513 | self = mdev->ldev->md.uuid[UI_CURRENT] & ~((u64)1); |
| 2514 | peer = mdev->p_uuid[UI_CURRENT] & ~((u64)1); |
| 2515 | |
| 2516 | *rule_nr = 10; |
| 2517 | if (self == UUID_JUST_CREATED && peer == UUID_JUST_CREATED) |
| 2518 | return 0; |
| 2519 | |
| 2520 | *rule_nr = 20; |
| 2521 | if ((self == UUID_JUST_CREATED || self == (u64)0) && |
| 2522 | peer != UUID_JUST_CREATED) |
| 2523 | return -2; |
| 2524 | |
| 2525 | *rule_nr = 30; |
| 2526 | if (self != UUID_JUST_CREATED && |
| 2527 | (peer == UUID_JUST_CREATED || peer == (u64)0)) |
| 2528 | return 2; |
| 2529 | |
| 2530 | if (self == peer) { |
| 2531 | int rct, dc; /* roles at crash time */ |
| 2532 | |
| 2533 | if (mdev->p_uuid[UI_BITMAP] == (u64)0 && mdev->ldev->md.uuid[UI_BITMAP] != (u64)0) { |
| 2534 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2535 | if (mdev->tconn->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2536 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2537 | |
| 2538 | if ((mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1)) == (mdev->p_uuid[UI_HISTORY_START] & ~((u64)1)) && |
| 2539 | (mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (mdev->p_uuid[UI_HISTORY_START + 1] & ~((u64)1))) { |
| 2540 | dev_info(DEV, "was SyncSource, missed the resync finished event, corrected myself:\n"); |
| 2541 | drbd_uuid_set_bm(mdev, 0UL); |
| 2542 | |
| 2543 | drbd_uuid_dump(mdev, "self", mdev->ldev->md.uuid, |
| 2544 | mdev->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(mdev) : 0, 0); |
| 2545 | *rule_nr = 34; |
| 2546 | } else { |
| 2547 | dev_info(DEV, "was SyncSource (peer failed to write sync_uuid)\n"); |
| 2548 | *rule_nr = 36; |
| 2549 | } |
| 2550 | |
| 2551 | return 1; |
| 2552 | } |
| 2553 | |
| 2554 | if (mdev->ldev->md.uuid[UI_BITMAP] == (u64)0 && mdev->p_uuid[UI_BITMAP] != (u64)0) { |
| 2555 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2556 | if (mdev->tconn->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2557 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2558 | |
| 2559 | if ((mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == (mdev->p_uuid[UI_BITMAP] & ~((u64)1)) && |
| 2560 | (mdev->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == (mdev->p_uuid[UI_HISTORY_START] & ~((u64)1))) { |
| 2561 | dev_info(DEV, "was SyncTarget, peer missed the resync finished event, corrected peer:\n"); |
| 2562 | |
| 2563 | mdev->p_uuid[UI_HISTORY_START + 1] = mdev->p_uuid[UI_HISTORY_START]; |
| 2564 | mdev->p_uuid[UI_HISTORY_START] = mdev->p_uuid[UI_BITMAP]; |
| 2565 | mdev->p_uuid[UI_BITMAP] = 0UL; |
| 2566 | |
| 2567 | drbd_uuid_dump(mdev, "peer", mdev->p_uuid, mdev->p_uuid[UI_SIZE], mdev->p_uuid[UI_FLAGS]); |
| 2568 | *rule_nr = 35; |
| 2569 | } else { |
| 2570 | dev_info(DEV, "was SyncTarget (failed to write sync_uuid)\n"); |
| 2571 | *rule_nr = 37; |
| 2572 | } |
| 2573 | |
| 2574 | return -1; |
| 2575 | } |
| 2576 | |
| 2577 | /* Common power [off|failure] */ |
| 2578 | rct = (test_bit(CRASHED_PRIMARY, &mdev->flags) ? 1 : 0) + |
| 2579 | (mdev->p_uuid[UI_FLAGS] & 2); |
| 2580 | /* lowest bit is set when we were primary, |
| 2581 | * next bit (weight 2) is set when peer was primary */ |
| 2582 | *rule_nr = 40; |
| 2583 | |
| 2584 | switch (rct) { |
| 2585 | case 0: /* !self_pri && !peer_pri */ return 0; |
| 2586 | case 1: /* self_pri && !peer_pri */ return 1; |
| 2587 | case 2: /* !self_pri && peer_pri */ return -1; |
| 2588 | case 3: /* self_pri && peer_pri */ |
Philipp Reisner | 25703f8 | 2011-02-07 14:35:25 +0100 | [diff] [blame] | 2589 | dc = test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2590 | return dc ? -1 : 1; |
| 2591 | } |
| 2592 | } |
| 2593 | |
| 2594 | *rule_nr = 50; |
| 2595 | peer = mdev->p_uuid[UI_BITMAP] & ~((u64)1); |
| 2596 | if (self == peer) |
| 2597 | return -1; |
| 2598 | |
| 2599 | *rule_nr = 51; |
| 2600 | peer = mdev->p_uuid[UI_HISTORY_START] & ~((u64)1); |
| 2601 | if (self == peer) { |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2602 | if (mdev->tconn->agreed_pro_version < 96 ? |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2603 | (mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1)) == |
| 2604 | (mdev->p_uuid[UI_HISTORY_START + 1] & ~((u64)1)) : |
| 2605 | peer + UUID_NEW_BM_OFFSET == (mdev->p_uuid[UI_BITMAP] & ~((u64)1))) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2606 | /* The last P_SYNC_UUID did not get though. Undo the last start of |
| 2607 | resync as sync source modifications of the peer's UUIDs. */ |
| 2608 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2609 | if (mdev->tconn->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2610 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2611 | |
| 2612 | mdev->p_uuid[UI_BITMAP] = mdev->p_uuid[UI_HISTORY_START]; |
| 2613 | 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] | 2614 | |
| 2615 | dev_info(DEV, "Did not got last syncUUID packet, corrected:\n"); |
| 2616 | drbd_uuid_dump(mdev, "peer", mdev->p_uuid, mdev->p_uuid[UI_SIZE], mdev->p_uuid[UI_FLAGS]); |
| 2617 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2618 | return -1; |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | *rule_nr = 60; |
| 2623 | self = mdev->ldev->md.uuid[UI_CURRENT] & ~((u64)1); |
| 2624 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
| 2625 | peer = mdev->p_uuid[i] & ~((u64)1); |
| 2626 | if (self == peer) |
| 2627 | return -2; |
| 2628 | } |
| 2629 | |
| 2630 | *rule_nr = 70; |
| 2631 | self = mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1); |
| 2632 | peer = mdev->p_uuid[UI_CURRENT] & ~((u64)1); |
| 2633 | if (self == peer) |
| 2634 | return 1; |
| 2635 | |
| 2636 | *rule_nr = 71; |
| 2637 | self = mdev->ldev->md.uuid[UI_HISTORY_START] & ~((u64)1); |
| 2638 | if (self == peer) { |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2639 | if (mdev->tconn->agreed_pro_version < 96 ? |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2640 | (mdev->ldev->md.uuid[UI_HISTORY_START + 1] & ~((u64)1)) == |
| 2641 | (mdev->p_uuid[UI_HISTORY_START] & ~((u64)1)) : |
| 2642 | 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] | 2643 | /* The last P_SYNC_UUID did not get though. Undo the last start of |
| 2644 | resync as sync source modifications of our UUIDs. */ |
| 2645 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2646 | if (mdev->tconn->agreed_pro_version < 91) |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2647 | return -1091; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2648 | |
| 2649 | _drbd_uuid_set(mdev, UI_BITMAP, mdev->ldev->md.uuid[UI_HISTORY_START]); |
| 2650 | _drbd_uuid_set(mdev, UI_HISTORY_START, mdev->ldev->md.uuid[UI_HISTORY_START + 1]); |
| 2651 | |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2652 | dev_info(DEV, "Last syncUUID did not get through, corrected:\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2653 | drbd_uuid_dump(mdev, "self", mdev->ldev->md.uuid, |
| 2654 | mdev->state.disk >= D_NEGOTIATING ? drbd_bm_total_weight(mdev) : 0, 0); |
| 2655 | |
| 2656 | return 1; |
| 2657 | } |
| 2658 | } |
| 2659 | |
| 2660 | |
| 2661 | *rule_nr = 80; |
Philipp Reisner | d8c2a36 | 2009-11-18 15:52:51 +0100 | [diff] [blame] | 2662 | peer = mdev->p_uuid[UI_CURRENT] & ~((u64)1); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2663 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
| 2664 | self = mdev->ldev->md.uuid[i] & ~((u64)1); |
| 2665 | if (self == peer) |
| 2666 | return 2; |
| 2667 | } |
| 2668 | |
| 2669 | *rule_nr = 90; |
| 2670 | self = mdev->ldev->md.uuid[UI_BITMAP] & ~((u64)1); |
| 2671 | peer = mdev->p_uuid[UI_BITMAP] & ~((u64)1); |
| 2672 | if (self == peer && self != ((u64)0)) |
| 2673 | return 100; |
| 2674 | |
| 2675 | *rule_nr = 100; |
| 2676 | for (i = UI_HISTORY_START; i <= UI_HISTORY_END; i++) { |
| 2677 | self = mdev->ldev->md.uuid[i] & ~((u64)1); |
| 2678 | for (j = UI_HISTORY_START; j <= UI_HISTORY_END; j++) { |
| 2679 | peer = mdev->p_uuid[j] & ~((u64)1); |
| 2680 | if (self == peer) |
| 2681 | return -100; |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | return -1000; |
| 2686 | } |
| 2687 | |
| 2688 | /* drbd_sync_handshake() returns the new conn state on success, or |
| 2689 | CONN_MASK (-1) on failure. |
| 2690 | */ |
| 2691 | static enum drbd_conns drbd_sync_handshake(struct drbd_conf *mdev, enum drbd_role peer_role, |
| 2692 | enum drbd_disk_state peer_disk) __must_hold(local) |
| 2693 | { |
| 2694 | int hg, rule_nr; |
| 2695 | enum drbd_conns rv = C_MASK; |
| 2696 | enum drbd_disk_state mydisk; |
| 2697 | |
| 2698 | mydisk = mdev->state.disk; |
| 2699 | if (mydisk == D_NEGOTIATING) |
| 2700 | mydisk = mdev->new_state_tmp.disk; |
| 2701 | |
| 2702 | dev_info(DEV, "drbd_sync_handshake:\n"); |
| 2703 | drbd_uuid_dump(mdev, "self", mdev->ldev->md.uuid, mdev->comm_bm_set, 0); |
| 2704 | drbd_uuid_dump(mdev, "peer", mdev->p_uuid, |
| 2705 | mdev->p_uuid[UI_SIZE], mdev->p_uuid[UI_FLAGS]); |
| 2706 | |
| 2707 | hg = drbd_uuid_compare(mdev, &rule_nr); |
| 2708 | |
| 2709 | dev_info(DEV, "uuid_compare()=%d by rule %d\n", hg, rule_nr); |
| 2710 | |
| 2711 | if (hg == -1000) { |
| 2712 | dev_alert(DEV, "Unrelated data, aborting!\n"); |
| 2713 | return C_MASK; |
| 2714 | } |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 2715 | if (hg < -1000) { |
| 2716 | 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] | 2717 | return C_MASK; |
| 2718 | } |
| 2719 | |
| 2720 | if ((mydisk == D_INCONSISTENT && peer_disk > D_INCONSISTENT) || |
| 2721 | (peer_disk == D_INCONSISTENT && mydisk > D_INCONSISTENT)) { |
| 2722 | int f = (hg == -100) || abs(hg) == 2; |
| 2723 | hg = mydisk > D_INCONSISTENT ? 1 : -1; |
| 2724 | if (f) |
| 2725 | hg = hg*2; |
| 2726 | dev_info(DEV, "Becoming sync %s due to disk states.\n", |
| 2727 | hg > 0 ? "source" : "target"); |
| 2728 | } |
| 2729 | |
Adam Gandelman | 3a11a48 | 2010-04-08 16:48:23 -0700 | [diff] [blame] | 2730 | if (abs(hg) == 100) |
| 2731 | drbd_khelper(mdev, "initial-split-brain"); |
| 2732 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2733 | if (hg == 100 || (hg == -100 && mdev->tconn->net_conf->always_asbp)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2734 | int pcount = (mdev->state.role == R_PRIMARY) |
| 2735 | + (peer_role == R_PRIMARY); |
| 2736 | int forced = (hg == -100); |
| 2737 | |
| 2738 | switch (pcount) { |
| 2739 | case 0: |
| 2740 | hg = drbd_asb_recover_0p(mdev); |
| 2741 | break; |
| 2742 | case 1: |
| 2743 | hg = drbd_asb_recover_1p(mdev); |
| 2744 | break; |
| 2745 | case 2: |
| 2746 | hg = drbd_asb_recover_2p(mdev); |
| 2747 | break; |
| 2748 | } |
| 2749 | if (abs(hg) < 100) { |
| 2750 | dev_warn(DEV, "Split-Brain detected, %d primaries, " |
| 2751 | "automatically solved. Sync from %s node\n", |
| 2752 | pcount, (hg < 0) ? "peer" : "this"); |
| 2753 | if (forced) { |
| 2754 | dev_warn(DEV, "Doing a full sync, since" |
| 2755 | " UUIDs where ambiguous.\n"); |
| 2756 | hg = hg*2; |
| 2757 | } |
| 2758 | } |
| 2759 | } |
| 2760 | |
| 2761 | if (hg == -100) { |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2762 | if (mdev->tconn->net_conf->want_lose && !(mdev->p_uuid[UI_FLAGS]&1)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2763 | hg = -1; |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2764 | if (!mdev->tconn->net_conf->want_lose && (mdev->p_uuid[UI_FLAGS]&1)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2765 | hg = 1; |
| 2766 | |
| 2767 | if (abs(hg) < 100) |
| 2768 | dev_warn(DEV, "Split-Brain detected, manually solved. " |
| 2769 | "Sync from %s node\n", |
| 2770 | (hg < 0) ? "peer" : "this"); |
| 2771 | } |
| 2772 | |
| 2773 | if (hg == -100) { |
Lars Ellenberg | 580b976 | 2010-02-26 23:15:23 +0100 | [diff] [blame] | 2774 | /* FIXME this log message is not correct if we end up here |
| 2775 | * after an attempted attach on a diskless node. |
| 2776 | * We just refuse to attach -- well, we drop the "connection" |
| 2777 | * to that disk, in a way... */ |
Adam Gandelman | 3a11a48 | 2010-04-08 16:48:23 -0700 | [diff] [blame] | 2778 | dev_alert(DEV, "Split-Brain detected but unresolved, dropping connection!\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2779 | drbd_khelper(mdev, "split-brain"); |
| 2780 | return C_MASK; |
| 2781 | } |
| 2782 | |
| 2783 | if (hg > 0 && mydisk <= D_INCONSISTENT) { |
| 2784 | dev_err(DEV, "I shall become SyncSource, but I am inconsistent!\n"); |
| 2785 | return C_MASK; |
| 2786 | } |
| 2787 | |
| 2788 | if (hg < 0 && /* by intention we do not use mydisk here. */ |
| 2789 | mdev->state.role == R_PRIMARY && mdev->state.disk >= D_CONSISTENT) { |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2790 | switch (mdev->tconn->net_conf->rr_conflict) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2791 | case ASB_CALL_HELPER: |
| 2792 | drbd_khelper(mdev, "pri-lost"); |
| 2793 | /* fall through */ |
| 2794 | case ASB_DISCONNECT: |
| 2795 | dev_err(DEV, "I shall become SyncTarget, but I am primary!\n"); |
| 2796 | return C_MASK; |
| 2797 | case ASB_VIOLENTLY: |
| 2798 | dev_warn(DEV, "Becoming SyncTarget, violating the stable-data" |
| 2799 | "assumption\n"); |
| 2800 | } |
| 2801 | } |
| 2802 | |
Philipp Reisner | 8169e41 | 2011-03-15 18:40:27 +0100 | [diff] [blame] | 2803 | if (mdev->tconn->net_conf->dry_run || test_bit(CONN_DRY_RUN, &mdev->tconn->flags)) { |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 2804 | if (hg == 0) |
| 2805 | dev_info(DEV, "dry-run connect: No resync, would become Connected immediately.\n"); |
| 2806 | else |
| 2807 | dev_info(DEV, "dry-run connect: Would become %s, doing a %s resync.", |
| 2808 | drbd_conn_str(hg > 0 ? C_SYNC_SOURCE : C_SYNC_TARGET), |
| 2809 | abs(hg) >= 2 ? "full" : "bit-map based"); |
| 2810 | return C_MASK; |
| 2811 | } |
| 2812 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2813 | if (abs(hg) >= 2) { |
| 2814 | 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] | 2815 | if (drbd_bitmap_io(mdev, &drbd_bmio_set_n_write, "set_n_write from sync_handshake", |
| 2816 | BM_LOCKED_SET_ALLOWED)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2817 | return C_MASK; |
| 2818 | } |
| 2819 | |
| 2820 | if (hg > 0) { /* become sync source. */ |
| 2821 | rv = C_WF_BITMAP_S; |
| 2822 | } else if (hg < 0) { /* become sync target */ |
| 2823 | rv = C_WF_BITMAP_T; |
| 2824 | } else { |
| 2825 | rv = C_CONNECTED; |
| 2826 | if (drbd_bm_total_weight(mdev)) { |
| 2827 | dev_info(DEV, "No resync, but %lu bits in bitmap!\n", |
| 2828 | drbd_bm_total_weight(mdev)); |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | return rv; |
| 2833 | } |
| 2834 | |
| 2835 | /* returns 1 if invalid */ |
| 2836 | static int cmp_after_sb(enum drbd_after_sb_p peer, enum drbd_after_sb_p self) |
| 2837 | { |
| 2838 | /* ASB_DISCARD_REMOTE - ASB_DISCARD_LOCAL is valid */ |
| 2839 | if ((peer == ASB_DISCARD_REMOTE && self == ASB_DISCARD_LOCAL) || |
| 2840 | (self == ASB_DISCARD_REMOTE && peer == ASB_DISCARD_LOCAL)) |
| 2841 | return 0; |
| 2842 | |
| 2843 | /* any other things with ASB_DISCARD_REMOTE or ASB_DISCARD_LOCAL are invalid */ |
| 2844 | if (peer == ASB_DISCARD_REMOTE || peer == ASB_DISCARD_LOCAL || |
| 2845 | self == ASB_DISCARD_REMOTE || self == ASB_DISCARD_LOCAL) |
| 2846 | return 1; |
| 2847 | |
| 2848 | /* everything else is valid if they are equal on both sides. */ |
| 2849 | if (peer == self) |
| 2850 | return 0; |
| 2851 | |
| 2852 | /* everything es is invalid. */ |
| 2853 | return 1; |
| 2854 | } |
| 2855 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 2856 | static int receive_protocol(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 2857 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2858 | { |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 2859 | struct p_protocol *p = &mdev->tconn->data.rbuf.protocol; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2860 | int p_proto, p_after_sb_0p, p_after_sb_1p, p_after_sb_2p; |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 2861 | int p_want_lose, p_two_primaries, cf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2862 | char p_integrity_alg[SHARED_SECRET_MAX] = ""; |
| 2863 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2864 | p_proto = be32_to_cpu(p->protocol); |
| 2865 | p_after_sb_0p = be32_to_cpu(p->after_sb_0p); |
| 2866 | p_after_sb_1p = be32_to_cpu(p->after_sb_1p); |
| 2867 | p_after_sb_2p = be32_to_cpu(p->after_sb_2p); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2868 | p_two_primaries = be32_to_cpu(p->two_primaries); |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 2869 | cf = be32_to_cpu(p->conn_flags); |
| 2870 | p_want_lose = cf & CF_WANT_LOSE; |
| 2871 | |
Philipp Reisner | 8169e41 | 2011-03-15 18:40:27 +0100 | [diff] [blame] | 2872 | clear_bit(CONN_DRY_RUN, &mdev->tconn->flags); |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 2873 | |
| 2874 | if (cf & CF_DRY_RUN) |
Philipp Reisner | 8169e41 | 2011-03-15 18:40:27 +0100 | [diff] [blame] | 2875 | set_bit(CONN_DRY_RUN, &mdev->tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2876 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2877 | if (p_proto != mdev->tconn->net_conf->wire_protocol) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2878 | dev_err(DEV, "incompatible communication protocols\n"); |
| 2879 | goto disconnect; |
| 2880 | } |
| 2881 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2882 | if (cmp_after_sb(p_after_sb_0p, mdev->tconn->net_conf->after_sb_0p)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2883 | dev_err(DEV, "incompatible after-sb-0pri settings\n"); |
| 2884 | goto disconnect; |
| 2885 | } |
| 2886 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2887 | if (cmp_after_sb(p_after_sb_1p, mdev->tconn->net_conf->after_sb_1p)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2888 | dev_err(DEV, "incompatible after-sb-1pri settings\n"); |
| 2889 | goto disconnect; |
| 2890 | } |
| 2891 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2892 | if (cmp_after_sb(p_after_sb_2p, mdev->tconn->net_conf->after_sb_2p)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2893 | dev_err(DEV, "incompatible after-sb-2pri settings\n"); |
| 2894 | goto disconnect; |
| 2895 | } |
| 2896 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2897 | if (p_want_lose && mdev->tconn->net_conf->want_lose) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2898 | dev_err(DEV, "both sides have the 'want_lose' flag set\n"); |
| 2899 | goto disconnect; |
| 2900 | } |
| 2901 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2902 | if (p_two_primaries != mdev->tconn->net_conf->two_primaries) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2903 | dev_err(DEV, "incompatible setting of the two-primaries options\n"); |
| 2904 | goto disconnect; |
| 2905 | } |
| 2906 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2907 | if (mdev->tconn->agreed_pro_version >= 87) { |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2908 | unsigned char *my_alg = mdev->tconn->net_conf->integrity_alg; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2909 | |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 2910 | if (drbd_recv(mdev->tconn, p_integrity_alg, data_size) != data_size) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2911 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2912 | |
| 2913 | p_integrity_alg[SHARED_SECRET_MAX-1] = 0; |
| 2914 | if (strcmp(p_integrity_alg, my_alg)) { |
| 2915 | dev_err(DEV, "incompatible setting of the data-integrity-alg\n"); |
| 2916 | goto disconnect; |
| 2917 | } |
| 2918 | dev_info(DEV, "data-integrity-alg: %s\n", |
| 2919 | my_alg[0] ? my_alg : (unsigned char *)"<not-used>"); |
| 2920 | } |
| 2921 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2922 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2923 | |
| 2924 | disconnect: |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 2925 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2926 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | /* helper function |
| 2930 | * input: alg name, feature name |
| 2931 | * return: NULL (alg name was "") |
| 2932 | * ERR_PTR(error) if something goes wrong |
| 2933 | * or the crypto hash ptr, if it worked out ok. */ |
| 2934 | struct crypto_hash *drbd_crypto_alloc_digest_safe(const struct drbd_conf *mdev, |
| 2935 | const char *alg, const char *name) |
| 2936 | { |
| 2937 | struct crypto_hash *tfm; |
| 2938 | |
| 2939 | if (!alg[0]) |
| 2940 | return NULL; |
| 2941 | |
| 2942 | tfm = crypto_alloc_hash(alg, 0, CRYPTO_ALG_ASYNC); |
| 2943 | if (IS_ERR(tfm)) { |
| 2944 | dev_err(DEV, "Can not allocate \"%s\" as %s (reason: %ld)\n", |
| 2945 | alg, name, PTR_ERR(tfm)); |
| 2946 | return tfm; |
| 2947 | } |
| 2948 | if (!drbd_crypto_is_hash(crypto_hash_tfm(tfm))) { |
| 2949 | crypto_free_hash(tfm); |
| 2950 | dev_err(DEV, "\"%s\" is not a digest (%s)\n", alg, name); |
| 2951 | return ERR_PTR(-EINVAL); |
| 2952 | } |
| 2953 | return tfm; |
| 2954 | } |
| 2955 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 2956 | static int receive_SyncParam(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 2957 | unsigned int packet_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2958 | { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2959 | int ok = true; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 2960 | struct p_rs_param_95 *p = &mdev->tconn->data.rbuf.rs_param_95; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2961 | unsigned int header_size, data_size, exp_max_sz; |
| 2962 | struct crypto_hash *verify_tfm = NULL; |
| 2963 | struct crypto_hash *csums_tfm = NULL; |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2964 | const int apv = mdev->tconn->agreed_pro_version; |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 2965 | int *rs_plan_s = NULL; |
| 2966 | int fifo_size = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2967 | |
| 2968 | exp_max_sz = apv <= 87 ? sizeof(struct p_rs_param) |
| 2969 | : apv == 88 ? sizeof(struct p_rs_param) |
| 2970 | + SHARED_SECRET_MAX |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 2971 | : apv <= 94 ? sizeof(struct p_rs_param_89) |
| 2972 | : /* apv >= 95 */ sizeof(struct p_rs_param_95); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2973 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 2974 | if (packet_size > exp_max_sz) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2975 | dev_err(DEV, "SyncParam packet too long: received %u, expected <= %u bytes\n", |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 2976 | packet_size, exp_max_sz); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2977 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | if (apv <= 88) { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 2981 | header_size = sizeof(struct p_rs_param) - sizeof(struct p_header); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 2982 | data_size = packet_size - header_size; |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 2983 | } else if (apv <= 94) { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 2984 | header_size = sizeof(struct p_rs_param_89) - sizeof(struct p_header); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 2985 | data_size = packet_size - header_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2986 | D_ASSERT(data_size == 0); |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 2987 | } else { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 2988 | header_size = sizeof(struct p_rs_param_95) - sizeof(struct p_header); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 2989 | data_size = packet_size - header_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2990 | D_ASSERT(data_size == 0); |
| 2991 | } |
| 2992 | |
| 2993 | /* initialize verify_alg and csums_alg */ |
| 2994 | memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); |
| 2995 | |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 2996 | if (drbd_recv(mdev->tconn, &p->head.payload, header_size) != header_size) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 2997 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2998 | |
| 2999 | mdev->sync_conf.rate = be32_to_cpu(p->rate); |
| 3000 | |
| 3001 | if (apv >= 88) { |
| 3002 | if (apv == 88) { |
| 3003 | if (data_size > SHARED_SECRET_MAX) { |
| 3004 | dev_err(DEV, "verify-alg too long, " |
| 3005 | "peer wants %u, accepting only %u byte\n", |
| 3006 | data_size, SHARED_SECRET_MAX); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3007 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 3010 | if (drbd_recv(mdev->tconn, p->verify_alg, data_size) != data_size) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3011 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3012 | |
| 3013 | /* we expect NUL terminated string */ |
| 3014 | /* but just in case someone tries to be evil */ |
| 3015 | D_ASSERT(p->verify_alg[data_size-1] == 0); |
| 3016 | p->verify_alg[data_size-1] = 0; |
| 3017 | |
| 3018 | } else /* apv >= 89 */ { |
| 3019 | /* we still expect NUL terminated strings */ |
| 3020 | /* but just in case someone tries to be evil */ |
| 3021 | D_ASSERT(p->verify_alg[SHARED_SECRET_MAX-1] == 0); |
| 3022 | D_ASSERT(p->csums_alg[SHARED_SECRET_MAX-1] == 0); |
| 3023 | p->verify_alg[SHARED_SECRET_MAX-1] = 0; |
| 3024 | p->csums_alg[SHARED_SECRET_MAX-1] = 0; |
| 3025 | } |
| 3026 | |
| 3027 | if (strcmp(mdev->sync_conf.verify_alg, p->verify_alg)) { |
| 3028 | if (mdev->state.conn == C_WF_REPORT_PARAMS) { |
| 3029 | dev_err(DEV, "Different verify-alg settings. me=\"%s\" peer=\"%s\"\n", |
| 3030 | mdev->sync_conf.verify_alg, p->verify_alg); |
| 3031 | goto disconnect; |
| 3032 | } |
| 3033 | verify_tfm = drbd_crypto_alloc_digest_safe(mdev, |
| 3034 | p->verify_alg, "verify-alg"); |
| 3035 | if (IS_ERR(verify_tfm)) { |
| 3036 | verify_tfm = NULL; |
| 3037 | goto disconnect; |
| 3038 | } |
| 3039 | } |
| 3040 | |
| 3041 | if (apv >= 89 && strcmp(mdev->sync_conf.csums_alg, p->csums_alg)) { |
| 3042 | if (mdev->state.conn == C_WF_REPORT_PARAMS) { |
| 3043 | dev_err(DEV, "Different csums-alg settings. me=\"%s\" peer=\"%s\"\n", |
| 3044 | mdev->sync_conf.csums_alg, p->csums_alg); |
| 3045 | goto disconnect; |
| 3046 | } |
| 3047 | csums_tfm = drbd_crypto_alloc_digest_safe(mdev, |
| 3048 | p->csums_alg, "csums-alg"); |
| 3049 | if (IS_ERR(csums_tfm)) { |
| 3050 | csums_tfm = NULL; |
| 3051 | goto disconnect; |
| 3052 | } |
| 3053 | } |
| 3054 | |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3055 | if (apv > 94) { |
| 3056 | mdev->sync_conf.rate = be32_to_cpu(p->rate); |
| 3057 | mdev->sync_conf.c_plan_ahead = be32_to_cpu(p->c_plan_ahead); |
| 3058 | mdev->sync_conf.c_delay_target = be32_to_cpu(p->c_delay_target); |
| 3059 | mdev->sync_conf.c_fill_target = be32_to_cpu(p->c_fill_target); |
| 3060 | mdev->sync_conf.c_max_rate = be32_to_cpu(p->c_max_rate); |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 3061 | |
| 3062 | fifo_size = (mdev->sync_conf.c_plan_ahead * 10 * SLEEP_TIME) / HZ; |
| 3063 | if (fifo_size != mdev->rs_plan_s.size && fifo_size > 0) { |
| 3064 | rs_plan_s = kzalloc(sizeof(int) * fifo_size, GFP_KERNEL); |
| 3065 | if (!rs_plan_s) { |
| 3066 | dev_err(DEV, "kmalloc of fifo_buffer failed"); |
| 3067 | goto disconnect; |
| 3068 | } |
| 3069 | } |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 3070 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3071 | |
| 3072 | spin_lock(&mdev->peer_seq_lock); |
| 3073 | /* lock against drbd_nl_syncer_conf() */ |
| 3074 | if (verify_tfm) { |
| 3075 | strcpy(mdev->sync_conf.verify_alg, p->verify_alg); |
| 3076 | mdev->sync_conf.verify_alg_len = strlen(p->verify_alg) + 1; |
| 3077 | crypto_free_hash(mdev->verify_tfm); |
| 3078 | mdev->verify_tfm = verify_tfm; |
| 3079 | dev_info(DEV, "using verify-alg: \"%s\"\n", p->verify_alg); |
| 3080 | } |
| 3081 | if (csums_tfm) { |
| 3082 | strcpy(mdev->sync_conf.csums_alg, p->csums_alg); |
| 3083 | mdev->sync_conf.csums_alg_len = strlen(p->csums_alg) + 1; |
| 3084 | crypto_free_hash(mdev->csums_tfm); |
| 3085 | mdev->csums_tfm = csums_tfm; |
| 3086 | dev_info(DEV, "using csums-alg: \"%s\"\n", p->csums_alg); |
| 3087 | } |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 3088 | if (fifo_size != mdev->rs_plan_s.size) { |
| 3089 | kfree(mdev->rs_plan_s.values); |
| 3090 | mdev->rs_plan_s.values = rs_plan_s; |
| 3091 | mdev->rs_plan_s.size = fifo_size; |
| 3092 | mdev->rs_planed = 0; |
| 3093 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3094 | spin_unlock(&mdev->peer_seq_lock); |
| 3095 | } |
| 3096 | |
| 3097 | return ok; |
| 3098 | disconnect: |
| 3099 | /* just for completeness: actually not needed, |
| 3100 | * as this is not reached if csums_tfm was ok. */ |
| 3101 | crypto_free_hash(csums_tfm); |
| 3102 | /* but free the verify_tfm again, if csums_tfm did not work out */ |
| 3103 | crypto_free_hash(verify_tfm); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3104 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3105 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3108 | /* warn if the arguments differ by more than 12.5% */ |
| 3109 | static void warn_if_differ_considerably(struct drbd_conf *mdev, |
| 3110 | const char *s, sector_t a, sector_t b) |
| 3111 | { |
| 3112 | sector_t d; |
| 3113 | if (a == 0 || b == 0) |
| 3114 | return; |
| 3115 | d = (a > b) ? (a - b) : (b - a); |
| 3116 | if (d > (a>>3) || d > (b>>3)) |
| 3117 | dev_warn(DEV, "Considerable difference in %s: %llus vs. %llus\n", s, |
| 3118 | (unsigned long long)a, (unsigned long long)b); |
| 3119 | } |
| 3120 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 3121 | static int receive_sizes(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 3122 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3123 | { |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 3124 | struct p_sizes *p = &mdev->tconn->data.rbuf.sizes; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3125 | enum determine_dev_size dd = unchanged; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3126 | sector_t p_size, p_usize, my_usize; |
| 3127 | int ldsc = 0; /* local disk size changed */ |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3128 | enum dds_flags ddsf; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3129 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3130 | p_size = be64_to_cpu(p->d_size); |
| 3131 | p_usize = be64_to_cpu(p->u_size); |
| 3132 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3133 | /* just store the peer's disk size for now. |
| 3134 | * we still need to figure out whether we accept that. */ |
| 3135 | mdev->p_size = p_size; |
| 3136 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3137 | if (get_ldev(mdev)) { |
| 3138 | warn_if_differ_considerably(mdev, "lower level device sizes", |
| 3139 | p_size, drbd_get_max_capacity(mdev->ldev)); |
| 3140 | warn_if_differ_considerably(mdev, "user requested size", |
| 3141 | p_usize, mdev->ldev->dc.disk_size); |
| 3142 | |
| 3143 | /* if this is the first connect, or an otherwise expected |
| 3144 | * param exchange, choose the minimum */ |
| 3145 | if (mdev->state.conn == C_WF_REPORT_PARAMS) |
| 3146 | p_usize = min_not_zero((sector_t)mdev->ldev->dc.disk_size, |
| 3147 | p_usize); |
| 3148 | |
| 3149 | my_usize = mdev->ldev->dc.disk_size; |
| 3150 | |
| 3151 | if (mdev->ldev->dc.disk_size != p_usize) { |
| 3152 | mdev->ldev->dc.disk_size = p_usize; |
| 3153 | dev_info(DEV, "Peer sets u_size to %lu sectors\n", |
| 3154 | (unsigned long)mdev->ldev->dc.disk_size); |
| 3155 | } |
| 3156 | |
| 3157 | /* Never shrink a device with usable data during connect. |
| 3158 | But allow online shrinking if we are connected. */ |
Philipp Reisner | a393db6 | 2009-12-22 13:35:52 +0100 | [diff] [blame] | 3159 | if (drbd_new_dev_size(mdev, mdev->ldev, 0) < |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3160 | drbd_get_capacity(mdev->this_bdev) && |
| 3161 | mdev->state.disk >= D_OUTDATED && |
| 3162 | mdev->state.conn < C_CONNECTED) { |
| 3163 | dev_err(DEV, "The peer's disk size is too small!\n"); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3164 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3165 | mdev->ldev->dc.disk_size = my_usize; |
| 3166 | put_ldev(mdev); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3167 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3168 | } |
| 3169 | put_ldev(mdev); |
| 3170 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3171 | |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3172 | ddsf = be16_to_cpu(p->dds_flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3173 | if (get_ldev(mdev)) { |
Bart Van Assche | 24c4830 | 2011-05-21 18:32:29 +0200 | [diff] [blame] | 3174 | dd = drbd_determine_dev_size(mdev, ddsf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3175 | put_ldev(mdev); |
| 3176 | if (dd == dev_size_error) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3177 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3178 | drbd_md_sync(mdev); |
| 3179 | } else { |
| 3180 | /* I am diskless, need to accept the peer's size. */ |
| 3181 | drbd_set_my_capacity(mdev, p_size); |
| 3182 | } |
| 3183 | |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 3184 | mdev->peer_max_bio_size = be32_to_cpu(p->max_bio_size); |
| 3185 | drbd_reconsider_max_bio_size(mdev); |
| 3186 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3187 | if (get_ldev(mdev)) { |
| 3188 | if (mdev->ldev->known_size != drbd_get_capacity(mdev->ldev->backing_bdev)) { |
| 3189 | mdev->ldev->known_size = drbd_get_capacity(mdev->ldev->backing_bdev); |
| 3190 | ldsc = 1; |
| 3191 | } |
| 3192 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3193 | put_ldev(mdev); |
| 3194 | } |
| 3195 | |
| 3196 | if (mdev->state.conn > C_WF_REPORT_PARAMS) { |
| 3197 | if (be64_to_cpu(p->c_size) != |
| 3198 | drbd_get_capacity(mdev->this_bdev) || ldsc) { |
| 3199 | /* we have different sizes, probably peer |
| 3200 | * needs to know my new size... */ |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3201 | drbd_send_sizes(mdev, 0, ddsf); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3202 | } |
| 3203 | if (test_and_clear_bit(RESIZE_PENDING, &mdev->flags) || |
| 3204 | (dd == grew && mdev->state.conn == C_CONNECTED)) { |
| 3205 | if (mdev->state.pdsk >= D_INCONSISTENT && |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 3206 | mdev->state.disk >= D_INCONSISTENT) { |
| 3207 | if (ddsf & DDSF_NO_RESYNC) |
| 3208 | dev_info(DEV, "Resync of new storage suppressed with --assume-clean\n"); |
| 3209 | else |
| 3210 | resync_after_online_grow(mdev); |
| 3211 | } else |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3212 | set_bit(RESYNC_AFTER_NEG, &mdev->flags); |
| 3213 | } |
| 3214 | } |
| 3215 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3216 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 3219 | static int receive_uuids(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 3220 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3221 | { |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 3222 | struct p_uuids *p = &mdev->tconn->data.rbuf.uuids; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3223 | u64 *p_uuid; |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3224 | int i, updated_uuids = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3225 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3226 | p_uuid = kmalloc(sizeof(u64)*UI_EXTENDED_SIZE, GFP_NOIO); |
| 3227 | |
| 3228 | for (i = UI_CURRENT; i < UI_EXTENDED_SIZE; i++) |
| 3229 | p_uuid[i] = be64_to_cpu(p->uuid[i]); |
| 3230 | |
| 3231 | kfree(mdev->p_uuid); |
| 3232 | mdev->p_uuid = p_uuid; |
| 3233 | |
| 3234 | if (mdev->state.conn < C_CONNECTED && |
| 3235 | mdev->state.disk < D_INCONSISTENT && |
| 3236 | mdev->state.role == R_PRIMARY && |
| 3237 | (mdev->ed_uuid & ~((u64)1)) != (p_uuid[UI_CURRENT] & ~((u64)1))) { |
| 3238 | dev_err(DEV, "Can only connect to data with current UUID=%016llX\n", |
| 3239 | (unsigned long long)mdev->ed_uuid); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3240 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3241 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | if (get_ldev(mdev)) { |
| 3245 | int skip_initial_sync = |
| 3246 | mdev->state.conn == C_CONNECTED && |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 3247 | mdev->tconn->agreed_pro_version >= 90 && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3248 | mdev->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && |
| 3249 | (p_uuid[UI_FLAGS] & 8); |
| 3250 | if (skip_initial_sync) { |
| 3251 | dev_info(DEV, "Accepted new current UUID, preparing to skip initial sync\n"); |
| 3252 | drbd_bitmap_io(mdev, &drbd_bmio_clear_n_write, |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 3253 | "clear_n_write from receive_uuids", |
| 3254 | BM_LOCKED_TEST_ALLOWED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3255 | _drbd_uuid_set(mdev, UI_CURRENT, p_uuid[UI_CURRENT]); |
| 3256 | _drbd_uuid_set(mdev, UI_BITMAP, 0); |
| 3257 | _drbd_set_state(_NS2(mdev, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE), |
| 3258 | CS_VERBOSE, NULL); |
| 3259 | drbd_md_sync(mdev); |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3260 | updated_uuids = 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3261 | } |
| 3262 | put_ldev(mdev); |
Philipp Reisner | 18a50fa | 2010-06-21 14:14:15 +0200 | [diff] [blame] | 3263 | } else if (mdev->state.disk < D_INCONSISTENT && |
| 3264 | mdev->state.role == R_PRIMARY) { |
| 3265 | /* I am a diskless primary, the peer just created a new current UUID |
| 3266 | for me. */ |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3267 | updated_uuids = drbd_set_ed_uuid(mdev, p_uuid[UI_CURRENT]); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | /* Before we test for the disk state, we should wait until an eventually |
| 3271 | ongoing cluster wide state change is finished. That is important if |
| 3272 | we are primary and are detaching from our disk. We need to see the |
| 3273 | new disk state... */ |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 3274 | mutex_lock(mdev->state_mutex); |
| 3275 | mutex_unlock(mdev->state_mutex); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3276 | if (mdev->state.conn >= C_CONNECTED && mdev->state.disk < D_INCONSISTENT) |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3277 | updated_uuids |= drbd_set_ed_uuid(mdev, p_uuid[UI_CURRENT]); |
| 3278 | |
| 3279 | if (updated_uuids) |
| 3280 | drbd_print_uuids(mdev, "receiver updated UUIDs to"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3281 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3282 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | /** |
| 3286 | * convert_state() - Converts the peer's view of the cluster state to our point of view |
| 3287 | * @ps: The state as seen by the peer. |
| 3288 | */ |
| 3289 | static union drbd_state convert_state(union drbd_state ps) |
| 3290 | { |
| 3291 | union drbd_state ms; |
| 3292 | |
| 3293 | static enum drbd_conns c_tab[] = { |
| 3294 | [C_CONNECTED] = C_CONNECTED, |
| 3295 | |
| 3296 | [C_STARTING_SYNC_S] = C_STARTING_SYNC_T, |
| 3297 | [C_STARTING_SYNC_T] = C_STARTING_SYNC_S, |
| 3298 | [C_DISCONNECTING] = C_TEAR_DOWN, /* C_NETWORK_FAILURE, */ |
| 3299 | [C_VERIFY_S] = C_VERIFY_T, |
| 3300 | [C_MASK] = C_MASK, |
| 3301 | }; |
| 3302 | |
| 3303 | ms.i = ps.i; |
| 3304 | |
| 3305 | ms.conn = c_tab[ps.conn]; |
| 3306 | ms.peer = ps.role; |
| 3307 | ms.role = ps.peer; |
| 3308 | ms.pdsk = ps.disk; |
| 3309 | ms.disk = ps.pdsk; |
| 3310 | ms.peer_isp = (ps.aftr_isp | ps.user_isp); |
| 3311 | |
| 3312 | return ms; |
| 3313 | } |
| 3314 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 3315 | static int receive_req_state(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 3316 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3317 | { |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 3318 | struct p_req_state *p = &mdev->tconn->data.rbuf.req_state; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3319 | union drbd_state mask, val; |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 3320 | enum drbd_state_rv rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3321 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3322 | mask.i = be32_to_cpu(p->mask); |
| 3323 | val.i = be32_to_cpu(p->val); |
| 3324 | |
Philipp Reisner | 25703f8 | 2011-02-07 14:35:25 +0100 | [diff] [blame] | 3325 | if (test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags) && |
Philipp Reisner | 8410da8 | 2011-02-11 20:11:10 +0100 | [diff] [blame] | 3326 | mutex_is_locked(mdev->state_mutex)) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3327 | drbd_send_sr_reply(mdev, SS_CONCURRENT_ST_CHG); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3328 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | mask = convert_state(mask); |
| 3332 | val = convert_state(val); |
| 3333 | |
Philipp Reisner | 047cd4a | 2011-02-15 11:09:33 +0100 | [diff] [blame] | 3334 | if (cmd == P_CONN_ST_CHG_REQ) { |
| 3335 | rv = conn_request_state(mdev->tconn, mask, val, CS_VERBOSE | CS_LOCAL_ONLY); |
| 3336 | conn_send_sr_reply(mdev->tconn, rv); |
| 3337 | } else { |
| 3338 | rv = drbd_change_state(mdev, CS_VERBOSE, mask, val); |
| 3339 | drbd_send_sr_reply(mdev, rv); |
| 3340 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3341 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3342 | drbd_md_sync(mdev); |
| 3343 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3344 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3345 | } |
| 3346 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 3347 | static int receive_state(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 3348 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3349 | { |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 3350 | struct p_state *p = &mdev->tconn->data.rbuf.state; |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3351 | union drbd_state os, ns, peer_state; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3352 | enum drbd_disk_state real_peer_disk; |
Philipp Reisner | 65d922c | 2010-06-16 16:18:09 +0200 | [diff] [blame] | 3353 | enum chg_state_flags cs_flags; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3354 | int rv; |
| 3355 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3356 | peer_state.i = be32_to_cpu(p->state); |
| 3357 | |
| 3358 | real_peer_disk = peer_state.disk; |
| 3359 | if (peer_state.disk == D_NEGOTIATING) { |
| 3360 | real_peer_disk = mdev->p_uuid[UI_FLAGS] & 4 ? D_INCONSISTENT : D_CONSISTENT; |
| 3361 | dev_info(DEV, "real peer disk state = %s\n", drbd_disk_str(real_peer_disk)); |
| 3362 | } |
| 3363 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3364 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3365 | retry: |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3366 | os = ns = mdev->state; |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3367 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3368 | |
Lars Ellenberg | e9ef7bb | 2010-10-07 15:55:39 +0200 | [diff] [blame] | 3369 | /* peer says his disk is uptodate, while we think it is inconsistent, |
| 3370 | * and this happens while we think we have a sync going on. */ |
| 3371 | if (os.pdsk == D_INCONSISTENT && real_peer_disk == D_UP_TO_DATE && |
| 3372 | os.conn > C_CONNECTED && os.disk == D_UP_TO_DATE) { |
| 3373 | /* If we are (becoming) SyncSource, but peer is still in sync |
| 3374 | * preparation, ignore its uptodate-ness to avoid flapping, it |
| 3375 | * will change to inconsistent once the peer reaches active |
| 3376 | * syncing states. |
| 3377 | * It may have changed syncer-paused flags, however, so we |
| 3378 | * cannot ignore this completely. */ |
| 3379 | if (peer_state.conn > C_CONNECTED && |
| 3380 | peer_state.conn < C_SYNC_SOURCE) |
| 3381 | real_peer_disk = D_INCONSISTENT; |
| 3382 | |
| 3383 | /* if peer_state changes to connected at the same time, |
| 3384 | * it explicitly notifies us that it finished resync. |
| 3385 | * Maybe we should finish it up, too? */ |
| 3386 | else if (os.conn >= C_SYNC_SOURCE && |
| 3387 | peer_state.conn == C_CONNECTED) { |
| 3388 | if (drbd_bm_total_weight(mdev) <= mdev->rs_failed) |
| 3389 | drbd_resync_finished(mdev); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3390 | return true; |
Lars Ellenberg | e9ef7bb | 2010-10-07 15:55:39 +0200 | [diff] [blame] | 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | /* peer says his disk is inconsistent, while we think it is uptodate, |
| 3395 | * and this happens while the peer still thinks we have a sync going on, |
| 3396 | * but we think we are already done with the sync. |
| 3397 | * We ignore this to avoid flapping pdsk. |
| 3398 | * This should not happen, if the peer is a recent version of drbd. */ |
| 3399 | if (os.pdsk == D_UP_TO_DATE && real_peer_disk == D_INCONSISTENT && |
| 3400 | os.conn == C_CONNECTED && peer_state.conn > C_SYNC_SOURCE) |
| 3401 | real_peer_disk = D_UP_TO_DATE; |
| 3402 | |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3403 | if (ns.conn == C_WF_REPORT_PARAMS) |
| 3404 | ns.conn = C_CONNECTED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3405 | |
Philipp Reisner | 6753171 | 2010-10-27 12:21:30 +0200 | [diff] [blame] | 3406 | if (peer_state.conn == C_AHEAD) |
| 3407 | ns.conn = C_BEHIND; |
| 3408 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3409 | if (mdev->p_uuid && peer_state.disk >= D_NEGOTIATING && |
| 3410 | get_ldev_if_state(mdev, D_NEGOTIATING)) { |
| 3411 | int cr; /* consider resync */ |
| 3412 | |
| 3413 | /* if we established a new connection */ |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3414 | cr = (os.conn < C_CONNECTED); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3415 | /* if we had an established connection |
| 3416 | * and one of the nodes newly attaches a disk */ |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3417 | cr |= (os.conn == C_CONNECTED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3418 | (peer_state.disk == D_NEGOTIATING || |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3419 | os.disk == D_NEGOTIATING)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3420 | /* if we have both been inconsistent, and the peer has been |
| 3421 | * forced to be UpToDate with --overwrite-data */ |
| 3422 | cr |= test_bit(CONSIDER_RESYNC, &mdev->flags); |
| 3423 | /* if we had been plain connected, and the admin requested to |
| 3424 | * start a sync by "invalidate" or "invalidate-remote" */ |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3425 | cr |= (os.conn == C_CONNECTED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3426 | (peer_state.conn >= C_STARTING_SYNC_S && |
| 3427 | peer_state.conn <= C_WF_BITMAP_T)); |
| 3428 | |
| 3429 | if (cr) |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3430 | ns.conn = drbd_sync_handshake(mdev, peer_state.role, real_peer_disk); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3431 | |
| 3432 | put_ldev(mdev); |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3433 | if (ns.conn == C_MASK) { |
| 3434 | ns.conn = C_CONNECTED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3435 | if (mdev->state.disk == D_NEGOTIATING) { |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 3436 | drbd_force_state(mdev, NS(disk, D_FAILED)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3437 | } else if (peer_state.disk == D_NEGOTIATING) { |
| 3438 | dev_err(DEV, "Disk attach process on the peer node was aborted.\n"); |
| 3439 | peer_state.disk = D_DISKLESS; |
Lars Ellenberg | 580b976 | 2010-02-26 23:15:23 +0100 | [diff] [blame] | 3440 | real_peer_disk = D_DISKLESS; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3441 | } else { |
Philipp Reisner | 8169e41 | 2011-03-15 18:40:27 +0100 | [diff] [blame] | 3442 | if (test_and_clear_bit(CONN_DRY_RUN, &mdev->tconn->flags)) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3443 | return false; |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3444 | D_ASSERT(os.conn == C_WF_REPORT_PARAMS); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3445 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3446 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3447 | } |
| 3448 | } |
| 3449 | } |
| 3450 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3451 | spin_lock_irq(&mdev->tconn->req_lock); |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3452 | if (mdev->state.i != os.i) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3453 | goto retry; |
| 3454 | clear_bit(CONSIDER_RESYNC, &mdev->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3455 | ns.peer = peer_state.role; |
| 3456 | ns.pdsk = real_peer_disk; |
| 3457 | ns.peer_isp = (peer_state.aftr_isp | peer_state.user_isp); |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3458 | 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] | 3459 | ns.disk = mdev->new_state_tmp.disk; |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3460 | cs_flags = CS_VERBOSE + (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED ? 0 : CS_HARD); |
| 3461 | if (ns.pdsk == D_CONSISTENT && is_susp(ns) && ns.conn == C_CONNECTED && os.conn < C_CONNECTED && |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 3462 | test_bit(NEW_CUR_UUID, &mdev->flags)) { |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 3463 | /* 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] | 3464 | for temporal network outages! */ |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3465 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 3466 | 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] | 3467 | tl_clear(mdev->tconn); |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 3468 | drbd_uuid_new_current(mdev); |
| 3469 | clear_bit(NEW_CUR_UUID, &mdev->flags); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3470 | conn_request_state(mdev->tconn, NS2(conn, C_PROTOCOL_ERROR, susp, 0), CS_HARD); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3471 | return false; |
Philipp Reisner | 481c6f5 | 2010-06-22 14:03:27 +0200 | [diff] [blame] | 3472 | } |
Philipp Reisner | 65d922c | 2010-06-16 16:18:09 +0200 | [diff] [blame] | 3473 | rv = _drbd_set_state(mdev, ns, cs_flags, NULL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3474 | ns = mdev->state; |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 3475 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3476 | |
| 3477 | if (rv < SS_SUCCESS) { |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3478 | conn_request_state(mdev->tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3479 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3480 | } |
| 3481 | |
Lars Ellenberg | 4ac4aad | 2010-07-22 17:39:26 +0200 | [diff] [blame] | 3482 | if (os.conn > C_WF_REPORT_PARAMS) { |
| 3483 | if (ns.conn > C_CONNECTED && peer_state.conn <= C_CONNECTED && |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3484 | peer_state.disk != D_NEGOTIATING ) { |
| 3485 | /* we want resync, peer has not yet decided to sync... */ |
| 3486 | /* Nowadays only used when forcing a node into primary role and |
| 3487 | setting its disk to UpToDate with that */ |
| 3488 | drbd_send_uuids(mdev); |
| 3489 | drbd_send_state(mdev); |
| 3490 | } |
| 3491 | } |
| 3492 | |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 3493 | mdev->tconn->net_conf->want_lose = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3494 | |
| 3495 | drbd_md_sync(mdev); /* update connected indicator, la_size, ... */ |
| 3496 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3497 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3498 | } |
| 3499 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 3500 | static int receive_sync_uuid(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 3501 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3502 | { |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 3503 | struct p_rs_uuid *p = &mdev->tconn->data.rbuf.rs_uuid; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3504 | |
| 3505 | wait_event(mdev->misc_wait, |
| 3506 | mdev->state.conn == C_WF_SYNC_UUID || |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 3507 | mdev->state.conn == C_BEHIND || |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3508 | mdev->state.conn < C_CONNECTED || |
| 3509 | mdev->state.disk < D_NEGOTIATING); |
| 3510 | |
| 3511 | /* D_ASSERT( mdev->state.conn == C_WF_SYNC_UUID ); */ |
| 3512 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3513 | /* Here the _drbd_uuid_ functions are right, current should |
| 3514 | _not_ be rotated into the history */ |
| 3515 | if (get_ldev_if_state(mdev, D_NEGOTIATING)) { |
| 3516 | _drbd_uuid_set(mdev, UI_CURRENT, be64_to_cpu(p->uuid)); |
| 3517 | _drbd_uuid_set(mdev, UI_BITMAP, 0UL); |
| 3518 | |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 3519 | drbd_print_uuids(mdev, "updated sync uuid"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3520 | drbd_start_resync(mdev, C_SYNC_TARGET); |
| 3521 | |
| 3522 | put_ldev(mdev); |
| 3523 | } else |
| 3524 | dev_err(DEV, "Ignoring SyncUUID packet!\n"); |
| 3525 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3526 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3529 | /** |
| 3530 | * receive_bitmap_plain |
| 3531 | * |
| 3532 | * Return 0 when done, 1 when another iteration is needed, and a negative error |
| 3533 | * code upon failure. |
| 3534 | */ |
| 3535 | static int |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3536 | receive_bitmap_plain(struct drbd_conf *mdev, unsigned int data_size, |
| 3537 | unsigned long *buffer, struct bm_xfer_ctx *c) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3538 | { |
| 3539 | unsigned num_words = min_t(size_t, BM_PACKET_WORDS, c->bm_words - c->word_offset); |
| 3540 | unsigned want = num_words * sizeof(long); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3541 | int err; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3542 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3543 | if (want != data_size) { |
| 3544 | dev_err(DEV, "%s:want (%u) != data_size (%u)\n", __func__, want, data_size); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3545 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3546 | } |
| 3547 | if (want == 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3548 | return 0; |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 3549 | err = drbd_recv(mdev->tconn, buffer, want); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3550 | if (err != want) { |
| 3551 | if (err >= 0) |
| 3552 | err = -EIO; |
| 3553 | return err; |
| 3554 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3555 | |
| 3556 | drbd_bm_merge_lel(mdev, c->word_offset, num_words, buffer); |
| 3557 | |
| 3558 | c->word_offset += num_words; |
| 3559 | c->bit_offset = c->word_offset * BITS_PER_LONG; |
| 3560 | if (c->bit_offset > c->bm_bits) |
| 3561 | c->bit_offset = c->bm_bits; |
| 3562 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3563 | return 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3566 | /** |
| 3567 | * recv_bm_rle_bits |
| 3568 | * |
| 3569 | * Return 0 when done, 1 when another iteration is needed, and a negative error |
| 3570 | * code upon failure. |
| 3571 | */ |
| 3572 | static int |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3573 | recv_bm_rle_bits(struct drbd_conf *mdev, |
| 3574 | struct p_compressed_bm *p, |
Philipp Reisner | c6d25cf | 2011-01-19 16:13:06 +0100 | [diff] [blame] | 3575 | struct bm_xfer_ctx *c, |
| 3576 | unsigned int len) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3577 | { |
| 3578 | struct bitstream bs; |
| 3579 | u64 look_ahead; |
| 3580 | u64 rl; |
| 3581 | u64 tmp; |
| 3582 | unsigned long s = c->bit_offset; |
| 3583 | unsigned long e; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3584 | int toggle = DCBP_get_start(p); |
| 3585 | int have; |
| 3586 | int bits; |
| 3587 | |
| 3588 | bitstream_init(&bs, p->code, len, DCBP_get_pad_bits(p)); |
| 3589 | |
| 3590 | bits = bitstream_get_bits(&bs, &look_ahead, 64); |
| 3591 | if (bits < 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3592 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3593 | |
| 3594 | for (have = bits; have > 0; s += rl, toggle = !toggle) { |
| 3595 | bits = vli_decode_bits(&rl, look_ahead); |
| 3596 | if (bits <= 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3597 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3598 | |
| 3599 | if (toggle) { |
| 3600 | e = s + rl -1; |
| 3601 | if (e >= c->bm_bits) { |
| 3602 | 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] | 3603 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3604 | } |
| 3605 | _drbd_bm_set_bits(mdev, s, e); |
| 3606 | } |
| 3607 | |
| 3608 | if (have < bits) { |
| 3609 | dev_err(DEV, "bitmap decoding error: h:%d b:%d la:0x%08llx l:%u/%u\n", |
| 3610 | have, bits, look_ahead, |
| 3611 | (unsigned int)(bs.cur.b - p->code), |
| 3612 | (unsigned int)bs.buf_len); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3613 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3614 | } |
| 3615 | look_ahead >>= bits; |
| 3616 | have -= bits; |
| 3617 | |
| 3618 | bits = bitstream_get_bits(&bs, &tmp, 64 - have); |
| 3619 | if (bits < 0) |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3620 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3621 | look_ahead |= tmp << have; |
| 3622 | have += bits; |
| 3623 | } |
| 3624 | |
| 3625 | c->bit_offset = s; |
| 3626 | bm_xfer_ctx_bit_to_word_offset(c); |
| 3627 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3628 | return (s != c->bm_bits); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3631 | /** |
| 3632 | * decode_bitmap_c |
| 3633 | * |
| 3634 | * Return 0 when done, 1 when another iteration is needed, and a negative error |
| 3635 | * code upon failure. |
| 3636 | */ |
| 3637 | static int |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3638 | decode_bitmap_c(struct drbd_conf *mdev, |
| 3639 | struct p_compressed_bm *p, |
Philipp Reisner | c6d25cf | 2011-01-19 16:13:06 +0100 | [diff] [blame] | 3640 | struct bm_xfer_ctx *c, |
| 3641 | unsigned int len) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3642 | { |
| 3643 | if (DCBP_get_code(p) == RLE_VLI_Bits) |
Philipp Reisner | c6d25cf | 2011-01-19 16:13:06 +0100 | [diff] [blame] | 3644 | return recv_bm_rle_bits(mdev, p, c, len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3645 | |
| 3646 | /* other variants had been implemented for evaluation, |
| 3647 | * but have been dropped as this one turned out to be "best" |
| 3648 | * during all our tests. */ |
| 3649 | |
| 3650 | dev_err(DEV, "receive_bitmap_c: unknown encoding %u\n", p->encoding); |
Philipp Reisner | 38fa998 | 2011-03-15 18:24:49 +0100 | [diff] [blame] | 3651 | conn_request_state(mdev->tconn, NS(conn, C_PROTOCOL_ERROR), CS_HARD); |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3652 | return -EIO; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | void INFO_bm_xfer_stats(struct drbd_conf *mdev, |
| 3656 | const char *direction, struct bm_xfer_ctx *c) |
| 3657 | { |
| 3658 | /* what would it take to transfer it "plaintext" */ |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 3659 | unsigned plain = sizeof(struct p_header) * |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3660 | ((c->bm_words+BM_PACKET_WORDS-1)/BM_PACKET_WORDS+1) |
| 3661 | + c->bm_words * sizeof(long); |
| 3662 | unsigned total = c->bytes[0] + c->bytes[1]; |
| 3663 | unsigned r; |
| 3664 | |
| 3665 | /* total can not be zero. but just in case: */ |
| 3666 | if (total == 0) |
| 3667 | return; |
| 3668 | |
| 3669 | /* don't report if not compressed */ |
| 3670 | if (total >= plain) |
| 3671 | return; |
| 3672 | |
| 3673 | /* total < plain. check for overflow, still */ |
| 3674 | r = (total > UINT_MAX/1000) ? (total / (plain/1000)) |
| 3675 | : (1000 * total / plain); |
| 3676 | |
| 3677 | if (r > 1000) |
| 3678 | r = 1000; |
| 3679 | |
| 3680 | r = 1000 - r; |
| 3681 | dev_info(DEV, "%s bitmap stats [Bytes(packets)]: plain %u(%u), RLE %u(%u), " |
| 3682 | "total %u; compression: %u.%u%%\n", |
| 3683 | direction, |
| 3684 | c->bytes[1], c->packets[1], |
| 3685 | c->bytes[0], c->packets[0], |
| 3686 | total, r/10, r % 10); |
| 3687 | } |
| 3688 | |
| 3689 | /* Since we are processing the bitfield from lower addresses to higher, |
| 3690 | it does not matter if the process it in 32 bit chunks or 64 bit |
| 3691 | chunks as long as it is little endian. (Understand it as byte stream, |
| 3692 | beginning with the lowest byte...) If we would use big endian |
| 3693 | we would need to process it from the highest address to the lowest, |
| 3694 | in order to be agnostic to the 32 vs 64 bits issue. |
| 3695 | |
| 3696 | returns 0 on failure, 1 if we successfully received it. */ |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 3697 | static int receive_bitmap(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 3698 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3699 | { |
| 3700 | struct bm_xfer_ctx c; |
| 3701 | void *buffer; |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3702 | int err; |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3703 | int ok = false; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 3704 | struct p_header *h = &mdev->tconn->data.rbuf.header; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 3705 | struct packet_info pi; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3706 | |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 3707 | drbd_bm_lock(mdev, "receive bitmap", BM_LOCKED_SET_ALLOWED); |
| 3708 | /* you are supposed to send additional out-of-sync information |
| 3709 | * if you actually set bits during this phase */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3710 | |
| 3711 | /* maybe we should use some per thread scratch page, |
| 3712 | * and allocate that during initial device creation? */ |
| 3713 | buffer = (unsigned long *) __get_free_page(GFP_NOIO); |
| 3714 | if (!buffer) { |
| 3715 | dev_err(DEV, "failed to allocate one page buffer in %s\n", __func__); |
| 3716 | goto out; |
| 3717 | } |
| 3718 | |
| 3719 | c = (struct bm_xfer_ctx) { |
| 3720 | .bm_bits = drbd_bm_bits(mdev), |
| 3721 | .bm_words = drbd_bm_words(mdev), |
| 3722 | }; |
| 3723 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3724 | for(;;) { |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3725 | if (cmd == P_BITMAP) { |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3726 | err = receive_bitmap_plain(mdev, data_size, buffer, &c); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3727 | } else if (cmd == P_COMPRESSED_BITMAP) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3728 | /* MAYBE: sanity check that we speak proto >= 90, |
| 3729 | * and the feature is enabled! */ |
| 3730 | struct p_compressed_bm *p; |
| 3731 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3732 | if (data_size > BM_PACKET_PAYLOAD_BYTES) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3733 | dev_err(DEV, "ReportCBitmap packet too large\n"); |
| 3734 | goto out; |
| 3735 | } |
| 3736 | /* use the page buff */ |
| 3737 | p = buffer; |
| 3738 | memcpy(p, h, sizeof(*h)); |
Philipp Reisner | de0ff33 | 2011-02-07 16:56:20 +0100 | [diff] [blame] | 3739 | if (drbd_recv(mdev->tconn, p->head.payload, data_size) != data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3740 | goto out; |
Lars Ellenberg | 004352f | 2010-10-05 20:13:58 +0200 | [diff] [blame] | 3741 | if (data_size <= (sizeof(*p) - sizeof(p->head))) { |
| 3742 | dev_err(DEV, "ReportCBitmap packet too small (l:%u)\n", data_size); |
Andreas Gruenbacher | 78fcbda | 2010-12-10 22:18:27 +0100 | [diff] [blame] | 3743 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3744 | } |
Philipp Reisner | c6d25cf | 2011-01-19 16:13:06 +0100 | [diff] [blame] | 3745 | err = decode_bitmap_c(mdev, p, &c, data_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3746 | } else { |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3747 | dev_warn(DEV, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3748 | goto out; |
| 3749 | } |
| 3750 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3751 | c.packets[cmd == P_BITMAP]++; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 3752 | c.bytes[cmd == P_BITMAP] += sizeof(struct p_header) + data_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3753 | |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3754 | if (err <= 0) { |
| 3755 | if (err < 0) |
| 3756 | goto out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3757 | break; |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3758 | } |
Philipp Reisner | 9ba7aa0 | 2011-02-07 17:32:41 +0100 | [diff] [blame] | 3759 | if (!drbd_recv_header(mdev->tconn, &pi)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3760 | goto out; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 3761 | cmd = pi.cmd; |
| 3762 | data_size = pi.size; |
Andreas Gruenbacher | 2c46407 | 2010-12-11 21:53:12 +0100 | [diff] [blame] | 3763 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3764 | |
| 3765 | INFO_bm_xfer_stats(mdev, "receive", &c); |
| 3766 | |
| 3767 | if (mdev->state.conn == C_WF_BITMAP_T) { |
Andreas Gruenbacher | de1f8e4 | 2010-12-10 21:04:00 +0100 | [diff] [blame] | 3768 | enum drbd_state_rv rv; |
| 3769 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3770 | ok = !drbd_send_bitmap(mdev); |
| 3771 | if (!ok) |
| 3772 | goto out; |
| 3773 | /* Omit CS_ORDERED with this state transition to avoid deadlocks. */ |
Andreas Gruenbacher | de1f8e4 | 2010-12-10 21:04:00 +0100 | [diff] [blame] | 3774 | rv = _drbd_request_state(mdev, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE); |
| 3775 | D_ASSERT(rv == SS_SUCCESS); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3776 | } else if (mdev->state.conn != C_WF_BITMAP_S) { |
| 3777 | /* admin may have requested C_DISCONNECTING, |
| 3778 | * other threads may have noticed network errors */ |
| 3779 | dev_info(DEV, "unexpected cstate (%s) in receive_bitmap\n", |
| 3780 | drbd_conn_str(mdev->state.conn)); |
| 3781 | } |
| 3782 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3783 | ok = true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3784 | out: |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 3785 | drbd_bm_unlock(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3786 | if (ok && mdev->state.conn == C_WF_BITMAP_S) |
| 3787 | drbd_start_resync(mdev, C_SYNC_SOURCE); |
| 3788 | free_page((unsigned long) buffer); |
| 3789 | return ok; |
| 3790 | } |
| 3791 | |
Philipp Reisner | 2de876e | 2011-03-15 14:38:01 +0100 | [diff] [blame] | 3792 | static int _tconn_receive_skip(struct drbd_tconn *tconn, unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3793 | { |
| 3794 | /* TODO zero copy sink :) */ |
| 3795 | static char sink[128]; |
| 3796 | int size, want, r; |
| 3797 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3798 | size = data_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3799 | while (size > 0) { |
| 3800 | want = min_t(int, size, sizeof(sink)); |
Philipp Reisner | 2de876e | 2011-03-15 14:38:01 +0100 | [diff] [blame] | 3801 | r = drbd_recv(tconn, sink, want); |
| 3802 | if (r <= 0) |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 3803 | break; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3804 | size -= r; |
| 3805 | } |
| 3806 | return size == 0; |
| 3807 | } |
| 3808 | |
Philipp Reisner | 2de876e | 2011-03-15 14:38:01 +0100 | [diff] [blame] | 3809 | static int receive_skip(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 3810 | unsigned int data_size) |
| 3811 | { |
| 3812 | dev_warn(DEV, "skipping unknown optional packet type %d, l: %d!\n", |
| 3813 | cmd, data_size); |
| 3814 | |
| 3815 | return _tconn_receive_skip(mdev->tconn, data_size); |
| 3816 | } |
| 3817 | |
| 3818 | static int tconn_receive_skip(struct drbd_tconn *tconn, enum drbd_packet cmd, unsigned int data_size) |
| 3819 | { |
| 3820 | conn_warn(tconn, "skipping packet for non existing volume type %d, l: %d!\n", |
| 3821 | cmd, data_size); |
| 3822 | |
| 3823 | return _tconn_receive_skip(tconn, data_size); |
| 3824 | } |
| 3825 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 3826 | static int receive_UnplugRemote(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 3827 | unsigned int data_size) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3828 | { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3829 | /* Make sure we've acked all the TCP data associated |
| 3830 | * with the data requests being unplugged */ |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 3831 | drbd_tcp_quickack(mdev->tconn->data.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3832 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3833 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3834 | } |
| 3835 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 3836 | static int receive_out_of_sync(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 3837 | unsigned int data_size) |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 3838 | { |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 3839 | struct p_block_desc *p = &mdev->tconn->data.rbuf.block_desc; |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 3840 | |
Lars Ellenberg | f735e363 | 2010-12-17 21:06:18 +0100 | [diff] [blame] | 3841 | switch (mdev->state.conn) { |
| 3842 | case C_WF_SYNC_UUID: |
| 3843 | case C_WF_BITMAP_T: |
| 3844 | case C_BEHIND: |
| 3845 | break; |
| 3846 | default: |
| 3847 | dev_err(DEV, "ASSERT FAILED cstate = %s, expected: WFSyncUUID|WFBitMapT|Behind\n", |
| 3848 | drbd_conn_str(mdev->state.conn)); |
| 3849 | } |
| 3850 | |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 3851 | drbd_set_out_of_sync(mdev, be64_to_cpu(p->sector), be32_to_cpu(p->blksize)); |
| 3852 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 3853 | return true; |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 3854 | } |
| 3855 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3856 | struct data_cmd { |
| 3857 | int expect_payload; |
| 3858 | size_t pkt_size; |
Philipp Reisner | d9ae84e | 2011-03-15 18:50:22 +0100 | [diff] [blame^] | 3859 | enum { |
| 3860 | MDEV, |
| 3861 | CONN, |
| 3862 | } type; |
| 3863 | union { |
| 3864 | int (*mdev_fn)(struct drbd_conf *, enum drbd_packet cmd, |
| 3865 | unsigned int to_receive); |
| 3866 | int (*conn_fn)(struct drbd_tconn *, enum drbd_packet cmd, |
| 3867 | unsigned int to_receive); |
| 3868 | }; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3869 | }; |
| 3870 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3871 | static struct data_cmd drbd_cmd_handler[] = { |
Philipp Reisner | d9ae84e | 2011-03-15 18:50:22 +0100 | [diff] [blame^] | 3872 | [P_DATA] = { 1, sizeof(struct p_data), MDEV, { receive_Data } }, |
| 3873 | [P_DATA_REPLY] = { 1, sizeof(struct p_data), MDEV, { receive_DataReply } }, |
| 3874 | [P_RS_DATA_REPLY] = { 1, sizeof(struct p_data), MDEV, { receive_RSDataReply } } , |
| 3875 | [P_BARRIER] = { 0, sizeof(struct p_barrier), MDEV, { receive_Barrier } } , |
| 3876 | [P_BITMAP] = { 1, sizeof(struct p_header), MDEV, { receive_bitmap } } , |
| 3877 | [P_COMPRESSED_BITMAP] = { 1, sizeof(struct p_header), MDEV, { receive_bitmap } } , |
| 3878 | [P_UNPLUG_REMOTE] = { 0, sizeof(struct p_header), MDEV, { receive_UnplugRemote } }, |
| 3879 | [P_DATA_REQUEST] = { 0, sizeof(struct p_block_req), MDEV, { receive_DataRequest } }, |
| 3880 | [P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), MDEV, { receive_DataRequest } }, |
| 3881 | [P_SYNC_PARAM] = { 1, sizeof(struct p_header), MDEV, { receive_SyncParam } }, |
| 3882 | [P_SYNC_PARAM89] = { 1, sizeof(struct p_header), MDEV, { receive_SyncParam } }, |
| 3883 | [P_PROTOCOL] = { 1, sizeof(struct p_protocol), MDEV, { receive_protocol } }, |
| 3884 | [P_UUIDS] = { 0, sizeof(struct p_uuids), MDEV, { receive_uuids } }, |
| 3885 | [P_SIZES] = { 0, sizeof(struct p_sizes), MDEV, { receive_sizes } }, |
| 3886 | [P_STATE] = { 0, sizeof(struct p_state), MDEV, { receive_state } }, |
| 3887 | [P_STATE_CHG_REQ] = { 0, sizeof(struct p_req_state), MDEV, { receive_req_state } }, |
| 3888 | [P_SYNC_UUID] = { 0, sizeof(struct p_rs_uuid), MDEV, { receive_sync_uuid } }, |
| 3889 | [P_OV_REQUEST] = { 0, sizeof(struct p_block_req), MDEV, { receive_DataRequest } }, |
| 3890 | [P_OV_REPLY] = { 1, sizeof(struct p_block_req), MDEV, { receive_DataRequest } }, |
| 3891 | [P_CSUM_RS_REQUEST] = { 1, sizeof(struct p_block_req), MDEV, { receive_DataRequest } }, |
| 3892 | [P_DELAY_PROBE] = { 0, sizeof(struct p_delay_probe93), MDEV, { receive_skip } }, |
| 3893 | [P_OUT_OF_SYNC] = { 0, sizeof(struct p_block_desc), MDEV, { receive_out_of_sync } }, |
| 3894 | [P_CONN_ST_CHG_REQ] = { 0, sizeof(struct p_req_state), MDEV, { receive_req_state } }, |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3895 | }; |
| 3896 | |
| 3897 | /* All handler functions that expect a sub-header get that sub-heder in |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 3898 | mdev->tconn->data.rbuf.header.head.payload. |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3899 | |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 3900 | Usually in mdev->tconn->data.rbuf.header.head the callback can find the usual |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3901 | p_header, but they may not rely on that. Since there is also p_header95 ! |
| 3902 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3903 | |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 3904 | static void drbdd(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3905 | { |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 3906 | struct p_header *header = &tconn->data.rbuf.header; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 3907 | struct packet_info pi; |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3908 | size_t shs; /* sub header size */ |
| 3909 | int rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3910 | |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 3911 | while (get_t_state(&tconn->receiver) == RUNNING) { |
| 3912 | drbd_thread_current_set_cpu(&tconn->receiver); |
| 3913 | if (!drbd_recv_header(tconn, &pi)) |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3914 | goto err_out; |
| 3915 | |
Andreas Gruenbacher | 6e849ce | 2011-03-14 17:27:45 +0100 | [diff] [blame] | 3916 | if (unlikely(pi.cmd >= ARRAY_SIZE(drbd_cmd_handler) || |
Philipp Reisner | d9ae84e | 2011-03-15 18:50:22 +0100 | [diff] [blame^] | 3917 | !drbd_cmd_handler[pi.cmd].mdev_fn)) { |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 3918 | conn_err(tconn, "unknown packet type %d, l: %d!\n", pi.cmd, pi.size); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3919 | goto err_out; |
Lars Ellenberg | 0b33a91 | 2009-11-16 15:58:04 +0100 | [diff] [blame] | 3920 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3921 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 3922 | shs = drbd_cmd_handler[pi.cmd].pkt_size - sizeof(struct p_header); |
| 3923 | if (pi.size - shs > 0 && !drbd_cmd_handler[pi.cmd].expect_payload) { |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 3924 | conn_err(tconn, "No payload expected %s l:%d\n", cmdname(pi.cmd), pi.size); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3925 | goto err_out; |
| 3926 | } |
| 3927 | |
Lars Ellenberg | c13f7e1 | 2010-10-29 23:32:01 +0200 | [diff] [blame] | 3928 | if (shs) { |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 3929 | rv = drbd_recv(tconn, &header->payload, shs); |
Lars Ellenberg | c13f7e1 | 2010-10-29 23:32:01 +0200 | [diff] [blame] | 3930 | if (unlikely(rv != shs)) { |
Lars Ellenberg | 0ddc554 | 2011-01-21 12:35:15 +0100 | [diff] [blame] | 3931 | if (!signal_pending(current)) |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 3932 | conn_warn(tconn, "short read while reading sub header: rv=%d\n", rv); |
Lars Ellenberg | c13f7e1 | 2010-10-29 23:32:01 +0200 | [diff] [blame] | 3933 | goto err_out; |
| 3934 | } |
| 3935 | } |
| 3936 | |
Philipp Reisner | d9ae84e | 2011-03-15 18:50:22 +0100 | [diff] [blame^] | 3937 | if (drbd_cmd_handler[pi.cmd].type == CONN) { |
| 3938 | rv = drbd_cmd_handler[pi.cmd].conn_fn(tconn, pi.cmd, pi.size - shs); |
| 3939 | } else { |
| 3940 | struct drbd_conf *mdev = vnr_to_mdev(tconn, pi.vnr); |
| 3941 | rv = mdev ? |
| 3942 | drbd_cmd_handler[pi.cmd].mdev_fn(mdev, pi.cmd, pi.size - shs) : |
| 3943 | tconn_receive_skip(tconn, pi.cmd, pi.size - shs); |
| 3944 | } |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3945 | |
| 3946 | if (unlikely(!rv)) { |
Philipp Reisner | eefc2f7 | 2011-02-08 12:55:24 +0100 | [diff] [blame] | 3947 | conn_err(tconn, "error receiving %s, l: %d!\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 3948 | cmdname(pi.cmd), pi.size); |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3949 | goto err_out; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3950 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3951 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3952 | |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 3953 | if (0) { |
| 3954 | err_out: |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 3955 | conn_request_state(tconn, NS(conn, C_PROTOCOL_ERROR), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3956 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 3959 | void conn_flush_workqueue(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3960 | { |
| 3961 | struct drbd_wq_barrier barr; |
| 3962 | |
| 3963 | barr.w.cb = w_prev_work_done; |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 3964 | barr.w.tconn = tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3965 | init_completion(&barr.done); |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 3966 | drbd_queue_work(&tconn->data.work, &barr.w); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3967 | wait_for_completion(&barr.done); |
| 3968 | } |
| 3969 | |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 3970 | static void drbd_disconnect(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3971 | { |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 3972 | enum drbd_conns oc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3973 | int rv = SS_UNKNOWN_ERROR; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3974 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 3975 | if (tconn->cstate == C_STANDALONE) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3976 | return; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 3977 | |
| 3978 | /* asender does not clean up anything. it must not interfere, either */ |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 3979 | drbd_thread_stop(&tconn->asender); |
| 3980 | drbd_free_sock(tconn); |
| 3981 | |
| 3982 | idr_for_each(&tconn->volumes, drbd_disconnected, tconn); |
| 3983 | |
| 3984 | conn_info(tconn, "Connection closed\n"); |
| 3985 | |
| 3986 | spin_lock_irq(&tconn->req_lock); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 3987 | oc = tconn->cstate; |
| 3988 | if (oc >= C_UNCONNECTED) |
| 3989 | rv = _conn_request_state(tconn, NS(conn, C_UNCONNECTED), CS_VERBOSE); |
| 3990 | |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 3991 | spin_unlock_irq(&tconn->req_lock); |
| 3992 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 3993 | if (oc == C_DISCONNECTING) { |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 3994 | wait_event(tconn->net_cnt_wait, atomic_read(&tconn->net_cnt) == 0); |
| 3995 | |
| 3996 | crypto_free_hash(tconn->cram_hmac_tfm); |
| 3997 | tconn->cram_hmac_tfm = NULL; |
| 3998 | |
| 3999 | kfree(tconn->net_conf); |
| 4000 | tconn->net_conf = NULL; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4001 | conn_request_state(tconn, NS(conn, C_STANDALONE), CS_VERBOSE); |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4002 | } |
| 4003 | } |
| 4004 | |
| 4005 | static int drbd_disconnected(int vnr, void *p, void *data) |
| 4006 | { |
| 4007 | struct drbd_conf *mdev = (struct drbd_conf *)p; |
| 4008 | enum drbd_fencing_p fp; |
| 4009 | unsigned int i; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4010 | |
Philipp Reisner | 8571957 | 2010-07-21 10:20:17 +0200 | [diff] [blame] | 4011 | /* wait for current activity to cease. */ |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4012 | spin_lock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4013 | _drbd_wait_ee_list_empty(mdev, &mdev->active_ee); |
| 4014 | _drbd_wait_ee_list_empty(mdev, &mdev->sync_ee); |
| 4015 | _drbd_wait_ee_list_empty(mdev, &mdev->read_ee); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4016 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4017 | |
| 4018 | /* We do not have data structures that would allow us to |
| 4019 | * get the rs_pending_cnt down to 0 again. |
| 4020 | * * On C_SYNC_TARGET we do not have any data structures describing |
| 4021 | * the pending RSDataRequest's we have sent. |
| 4022 | * * On C_SYNC_SOURCE there is no data structure that tracks |
| 4023 | * the P_RS_DATA_REPLY blocks that we sent to the SyncTarget. |
| 4024 | * And no, it is not the sum of the reference counts in the |
| 4025 | * resync_LRU. The resync_LRU tracks the whole operation including |
| 4026 | * the disk-IO, while the rs_pending_cnt only tracks the blocks |
| 4027 | * on the fly. */ |
| 4028 | drbd_rs_cancel_all(mdev); |
| 4029 | mdev->rs_total = 0; |
| 4030 | mdev->rs_failed = 0; |
| 4031 | atomic_set(&mdev->rs_pending_cnt, 0); |
| 4032 | wake_up(&mdev->misc_wait); |
| 4033 | |
Philipp Reisner | 7fde2be | 2011-03-01 11:08:28 +0100 | [diff] [blame] | 4034 | del_timer(&mdev->request_timer); |
| 4035 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4036 | del_timer_sync(&mdev->resync_timer); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4037 | resync_timer_fn((unsigned long)mdev); |
| 4038 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4039 | /* wait for all w_e_end_data_req, w_e_end_rsdata_req, w_send_barrier, |
| 4040 | * w_make_resync_request etc. which may still be on the worker queue |
| 4041 | * to be "canceled" */ |
Philipp Reisner | a21e929 | 2011-02-08 15:08:49 +0100 | [diff] [blame] | 4042 | drbd_flush_workqueue(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4043 | |
| 4044 | /* This also does reclaim_net_ee(). If we do this too early, we might |
| 4045 | * miss some resync ee and pages.*/ |
| 4046 | drbd_process_done_ee(mdev); |
| 4047 | |
| 4048 | kfree(mdev->p_uuid); |
| 4049 | mdev->p_uuid = NULL; |
| 4050 | |
Philipp Reisner | fb22c40 | 2010-09-08 23:20:21 +0200 | [diff] [blame] | 4051 | if (!is_susp(mdev->state)) |
Philipp Reisner | 2f5cdd0 | 2011-02-21 14:29:27 +0100 | [diff] [blame] | 4052 | tl_clear(mdev->tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4053 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4054 | drbd_md_sync(mdev); |
| 4055 | |
| 4056 | fp = FP_DONT_CARE; |
| 4057 | if (get_ldev(mdev)) { |
| 4058 | fp = mdev->ldev->dc.fencing; |
| 4059 | put_ldev(mdev); |
| 4060 | } |
| 4061 | |
Philipp Reisner | 87f7be4 | 2010-06-11 13:56:33 +0200 | [diff] [blame] | 4062 | if (mdev->state.role == R_PRIMARY && fp >= FP_RESOURCE && mdev->state.pdsk >= D_UNKNOWN) |
| 4063 | drbd_try_outdate_peer_async(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4064 | |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 4065 | /* serialize with bitmap writeout triggered by the state change, |
| 4066 | * if any. */ |
| 4067 | wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags)); |
| 4068 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4069 | /* tcp_close and release of sendpage pages can be deferred. I don't |
| 4070 | * want to use SO_LINGER, because apparently it can be deferred for |
| 4071 | * more than 20 seconds (longest time I checked). |
| 4072 | * |
| 4073 | * Actually we don't care for exactly when the network stack does its |
| 4074 | * put_page(), but release our reference on these pages right here. |
| 4075 | */ |
| 4076 | i = drbd_release_ee(mdev, &mdev->net_ee); |
| 4077 | if (i) |
| 4078 | dev_info(DEV, "net_ee not empty, killed %u entries\n", i); |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 4079 | i = atomic_read(&mdev->pp_in_use_by_net); |
| 4080 | if (i) |
| 4081 | 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] | 4082 | i = atomic_read(&mdev->pp_in_use); |
| 4083 | if (i) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 4084 | dev_info(DEV, "pp_in_use = %d, expected 0\n", i); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4085 | |
| 4086 | D_ASSERT(list_empty(&mdev->read_ee)); |
| 4087 | D_ASSERT(list_empty(&mdev->active_ee)); |
| 4088 | D_ASSERT(list_empty(&mdev->sync_ee)); |
| 4089 | D_ASSERT(list_empty(&mdev->done_ee)); |
| 4090 | |
| 4091 | /* ok, no more ee's on the fly, it is safe to reset the epoch_size */ |
| 4092 | atomic_set(&mdev->current_epoch->epoch_size, 0); |
| 4093 | D_ASSERT(list_empty(&mdev->current_epoch->list)); |
Philipp Reisner | 360cc74 | 2011-02-08 14:29:53 +0100 | [diff] [blame] | 4094 | |
| 4095 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | /* |
| 4099 | * We support PRO_VERSION_MIN to PRO_VERSION_MAX. The protocol version |
| 4100 | * we can agree on is stored in agreed_pro_version. |
| 4101 | * |
| 4102 | * feature flags and the reserved array should be enough room for future |
| 4103 | * enhancements of the handshake protocol, and possible plugins... |
| 4104 | * |
| 4105 | * for now, they are expected to be zero, but ignored. |
| 4106 | */ |
Philipp Reisner | 8a22ccc | 2011-02-07 16:47:12 +0100 | [diff] [blame] | 4107 | static int drbd_send_handshake(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4108 | { |
Philipp Reisner | e6b3ea8 | 2011-01-19 14:02:01 +0100 | [diff] [blame] | 4109 | /* ASSERT current == mdev->tconn->receiver ... */ |
Philipp Reisner | 8a22ccc | 2011-02-07 16:47:12 +0100 | [diff] [blame] | 4110 | struct p_handshake *p = &tconn->data.sbuf.handshake; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4111 | int ok; |
| 4112 | |
Philipp Reisner | 8a22ccc | 2011-02-07 16:47:12 +0100 | [diff] [blame] | 4113 | if (mutex_lock_interruptible(&tconn->data.mutex)) { |
| 4114 | conn_err(tconn, "interrupted during initial handshake\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4115 | return 0; /* interrupted. not ok. */ |
| 4116 | } |
| 4117 | |
Philipp Reisner | 8a22ccc | 2011-02-07 16:47:12 +0100 | [diff] [blame] | 4118 | if (tconn->data.socket == NULL) { |
| 4119 | mutex_unlock(&tconn->data.mutex); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4120 | return 0; |
| 4121 | } |
| 4122 | |
| 4123 | memset(p, 0, sizeof(*p)); |
| 4124 | p->protocol_min = cpu_to_be32(PRO_VERSION_MIN); |
| 4125 | p->protocol_max = cpu_to_be32(PRO_VERSION_MAX); |
Philipp Reisner | 8a22ccc | 2011-02-07 16:47:12 +0100 | [diff] [blame] | 4126 | ok = _conn_send_cmd(tconn, 0, tconn->data.socket, P_HAND_SHAKE, |
| 4127 | &p->head, sizeof(*p), 0); |
| 4128 | mutex_unlock(&tconn->data.mutex); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4129 | return ok; |
| 4130 | } |
| 4131 | |
| 4132 | /* |
| 4133 | * return values: |
| 4134 | * 1 yes, we have a valid connection |
| 4135 | * 0 oops, did not work out, please try again |
| 4136 | * -1 peer talks different language, |
| 4137 | * no point in trying again, please go standalone. |
| 4138 | */ |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4139 | static int drbd_do_handshake(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4140 | { |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4141 | /* ASSERT current == tconn->receiver ... */ |
| 4142 | struct p_handshake *p = &tconn->data.rbuf.handshake; |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 4143 | const int expect = sizeof(struct p_handshake) - sizeof(struct p_header80); |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4144 | struct packet_info pi; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4145 | int rv; |
| 4146 | |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4147 | rv = drbd_send_handshake(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4148 | if (!rv) |
| 4149 | return 0; |
| 4150 | |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4151 | rv = drbd_recv_header(tconn, &pi); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4152 | if (!rv) |
| 4153 | return 0; |
| 4154 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4155 | if (pi.cmd != P_HAND_SHAKE) { |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4156 | conn_err(tconn, "expected HandShake packet, received: %s (0x%04x)\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4157 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4158 | return -1; |
| 4159 | } |
| 4160 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4161 | if (pi.size != expect) { |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4162 | conn_err(tconn, "expected HandShake length: %u, received: %u\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4163 | expect, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4164 | return -1; |
| 4165 | } |
| 4166 | |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4167 | rv = drbd_recv(tconn, &p->head.payload, expect); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4168 | |
| 4169 | if (rv != expect) { |
Lars Ellenberg | 0ddc554 | 2011-01-21 12:35:15 +0100 | [diff] [blame] | 4170 | if (!signal_pending(current)) |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4171 | conn_warn(tconn, "short read receiving handshake packet: l=%u\n", rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4172 | return 0; |
| 4173 | } |
| 4174 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4175 | p->protocol_min = be32_to_cpu(p->protocol_min); |
| 4176 | p->protocol_max = be32_to_cpu(p->protocol_max); |
| 4177 | if (p->protocol_max == 0) |
| 4178 | p->protocol_max = p->protocol_min; |
| 4179 | |
| 4180 | if (PRO_VERSION_MAX < p->protocol_min || |
| 4181 | PRO_VERSION_MIN > p->protocol_max) |
| 4182 | goto incompat; |
| 4183 | |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4184 | 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] | 4185 | |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4186 | conn_info(tconn, "Handshake successful: " |
| 4187 | "Agreed network protocol version %d\n", tconn->agreed_pro_version); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4188 | |
| 4189 | return 1; |
| 4190 | |
| 4191 | incompat: |
Philipp Reisner | 65d11ed | 2011-02-07 17:35:59 +0100 | [diff] [blame] | 4192 | conn_err(tconn, "incompatible DRBD dialects: " |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4193 | "I support %d-%d, peer supports %d-%d\n", |
| 4194 | PRO_VERSION_MIN, PRO_VERSION_MAX, |
| 4195 | p->protocol_min, p->protocol_max); |
| 4196 | return -1; |
| 4197 | } |
| 4198 | |
| 4199 | #if !defined(CONFIG_CRYPTO_HMAC) && !defined(CONFIG_CRYPTO_HMAC_MODULE) |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4200 | static int drbd_do_auth(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4201 | { |
| 4202 | dev_err(DEV, "This kernel was build without CONFIG_CRYPTO_HMAC.\n"); |
| 4203 | 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] | 4204 | return -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4205 | } |
| 4206 | #else |
| 4207 | #define CHALLENGE_LEN 64 |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4208 | |
| 4209 | /* Return value: |
| 4210 | 1 - auth succeeded, |
| 4211 | 0 - failed, try again (network error), |
| 4212 | -1 - auth failed, don't try again. |
| 4213 | */ |
| 4214 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4215 | static int drbd_do_auth(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4216 | { |
| 4217 | char my_challenge[CHALLENGE_LEN]; /* 64 Bytes... */ |
| 4218 | struct scatterlist sg; |
| 4219 | char *response = NULL; |
| 4220 | char *right_response = NULL; |
| 4221 | char *peers_ch = NULL; |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4222 | unsigned int key_len = strlen(tconn->net_conf->shared_secret); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4223 | unsigned int resp_size; |
| 4224 | struct hash_desc desc; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4225 | struct packet_info pi; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4226 | int rv; |
| 4227 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4228 | desc.tfm = tconn->cram_hmac_tfm; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4229 | desc.flags = 0; |
| 4230 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4231 | rv = crypto_hash_setkey(tconn->cram_hmac_tfm, |
| 4232 | (u8 *)tconn->net_conf->shared_secret, key_len); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4233 | if (rv) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4234 | conn_err(tconn, "crypto_hash_setkey() failed with %d\n", rv); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4235 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4236 | goto fail; |
| 4237 | } |
| 4238 | |
| 4239 | get_random_bytes(my_challenge, CHALLENGE_LEN); |
| 4240 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4241 | rv = conn_send_cmd2(tconn, P_AUTH_CHALLENGE, my_challenge, CHALLENGE_LEN); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4242 | if (!rv) |
| 4243 | goto fail; |
| 4244 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4245 | rv = drbd_recv_header(tconn, &pi); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4246 | if (!rv) |
| 4247 | goto fail; |
| 4248 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4249 | if (pi.cmd != P_AUTH_CHALLENGE) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4250 | conn_err(tconn, "expected AuthChallenge packet, received: %s (0x%04x)\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4251 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4252 | rv = 0; |
| 4253 | goto fail; |
| 4254 | } |
| 4255 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4256 | if (pi.size > CHALLENGE_LEN * 2) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4257 | conn_err(tconn, "expected AuthChallenge payload too big.\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4258 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4259 | goto fail; |
| 4260 | } |
| 4261 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4262 | peers_ch = kmalloc(pi.size, GFP_NOIO); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4263 | if (peers_ch == NULL) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4264 | conn_err(tconn, "kmalloc of peers_ch failed\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4265 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4266 | goto fail; |
| 4267 | } |
| 4268 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4269 | rv = drbd_recv(tconn, peers_ch, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4270 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4271 | if (rv != pi.size) { |
Lars Ellenberg | 0ddc554 | 2011-01-21 12:35:15 +0100 | [diff] [blame] | 4272 | if (!signal_pending(current)) |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4273 | conn_warn(tconn, "short read AuthChallenge: l=%u\n", rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4274 | rv = 0; |
| 4275 | goto fail; |
| 4276 | } |
| 4277 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4278 | resp_size = crypto_hash_digestsize(tconn->cram_hmac_tfm); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4279 | response = kmalloc(resp_size, GFP_NOIO); |
| 4280 | if (response == NULL) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4281 | conn_err(tconn, "kmalloc of response failed\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4282 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4283 | goto fail; |
| 4284 | } |
| 4285 | |
| 4286 | sg_init_table(&sg, 1); |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4287 | sg_set_buf(&sg, peers_ch, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4288 | |
| 4289 | rv = crypto_hash_digest(&desc, &sg, sg.length, response); |
| 4290 | if (rv) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4291 | conn_err(tconn, "crypto_hash_digest() failed with %d\n", rv); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4292 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4293 | goto fail; |
| 4294 | } |
| 4295 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4296 | rv = conn_send_cmd2(tconn, P_AUTH_RESPONSE, response, resp_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4297 | if (!rv) |
| 4298 | goto fail; |
| 4299 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4300 | rv = drbd_recv_header(tconn, &pi); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4301 | if (!rv) |
| 4302 | goto fail; |
| 4303 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4304 | if (pi.cmd != P_AUTH_RESPONSE) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4305 | conn_err(tconn, "expected AuthResponse packet, received: %s (0x%04x)\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4306 | cmdname(pi.cmd), pi.cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4307 | rv = 0; |
| 4308 | goto fail; |
| 4309 | } |
| 4310 | |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4311 | if (pi.size != resp_size) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4312 | conn_err(tconn, "expected AuthResponse payload of wrong size\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4313 | rv = 0; |
| 4314 | goto fail; |
| 4315 | } |
| 4316 | |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4317 | rv = drbd_recv(tconn, response , resp_size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4318 | |
| 4319 | if (rv != resp_size) { |
Lars Ellenberg | 0ddc554 | 2011-01-21 12:35:15 +0100 | [diff] [blame] | 4320 | if (!signal_pending(current)) |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4321 | conn_warn(tconn, "short read receiving AuthResponse: l=%u\n", rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4322 | rv = 0; |
| 4323 | goto fail; |
| 4324 | } |
| 4325 | |
| 4326 | right_response = kmalloc(resp_size, GFP_NOIO); |
Julia Lawall | 2d1ee87 | 2009-12-27 22:27:11 +0100 | [diff] [blame] | 4327 | if (right_response == NULL) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4328 | conn_err(tconn, "kmalloc of right_response failed\n"); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4329 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4330 | goto fail; |
| 4331 | } |
| 4332 | |
| 4333 | sg_set_buf(&sg, my_challenge, CHALLENGE_LEN); |
| 4334 | |
| 4335 | rv = crypto_hash_digest(&desc, &sg, sg.length, right_response); |
| 4336 | if (rv) { |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4337 | conn_err(tconn, "crypto_hash_digest() failed with %d\n", rv); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4338 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4339 | goto fail; |
| 4340 | } |
| 4341 | |
| 4342 | rv = !memcmp(response, right_response, resp_size); |
| 4343 | |
| 4344 | if (rv) |
Philipp Reisner | 13e6037 | 2011-02-08 09:54:40 +0100 | [diff] [blame] | 4345 | conn_info(tconn, "Peer authenticated using %d bytes of '%s' HMAC\n", |
| 4346 | resp_size, tconn->net_conf->cram_hmac_alg); |
Johannes Thoma | b10d96c | 2010-01-07 16:02:50 +0100 | [diff] [blame] | 4347 | else |
| 4348 | rv = -1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4349 | |
| 4350 | fail: |
| 4351 | kfree(peers_ch); |
| 4352 | kfree(response); |
| 4353 | kfree(right_response); |
| 4354 | |
| 4355 | return rv; |
| 4356 | } |
| 4357 | #endif |
| 4358 | |
| 4359 | int drbdd_init(struct drbd_thread *thi) |
| 4360 | { |
Philipp Reisner | 392c880 | 2011-02-09 10:33:31 +0100 | [diff] [blame] | 4361 | struct drbd_tconn *tconn = thi->tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4362 | int h; |
| 4363 | |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4364 | conn_info(tconn, "receiver (re)started\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4365 | |
| 4366 | do { |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4367 | h = drbd_connect(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4368 | if (h == 0) { |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4369 | drbd_disconnect(tconn); |
Philipp Reisner | 20ee639 | 2011-01-18 15:28:59 +0100 | [diff] [blame] | 4370 | schedule_timeout_interruptible(HZ); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4371 | } |
| 4372 | if (h == -1) { |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4373 | conn_warn(tconn, "Discarding network configuration.\n"); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4374 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4375 | } |
| 4376 | } while (h == 0); |
| 4377 | |
| 4378 | if (h > 0) { |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4379 | if (get_net_conf(tconn)) { |
| 4380 | drbdd(tconn); |
| 4381 | put_net_conf(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4382 | } |
| 4383 | } |
| 4384 | |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4385 | drbd_disconnect(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4386 | |
Philipp Reisner | 4d641dd | 2011-02-08 15:40:24 +0100 | [diff] [blame] | 4387 | conn_info(tconn, "receiver terminated\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4388 | return 0; |
| 4389 | } |
| 4390 | |
| 4391 | /* ********* acknowledge sender ******** */ |
| 4392 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4393 | static int got_RqSReply(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4394 | { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4395 | struct p_req_state_reply *p = &mdev->tconn->meta.rbuf.req_state_reply; |
Philipp Reisner | fc3b10a | 2011-02-15 11:07:59 +0100 | [diff] [blame] | 4396 | struct drbd_tconn *tconn = mdev->tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4397 | |
| 4398 | int retcode = be32_to_cpu(p->retcode); |
| 4399 | |
Philipp Reisner | fc3b10a | 2011-02-15 11:07:59 +0100 | [diff] [blame] | 4400 | if (cmd == P_STATE_CHG_REPLY) { |
| 4401 | if (retcode >= SS_SUCCESS) { |
| 4402 | set_bit(CL_ST_CHG_SUCCESS, &mdev->flags); |
| 4403 | } else { |
| 4404 | set_bit(CL_ST_CHG_FAIL, &mdev->flags); |
| 4405 | dev_err(DEV, "Requested state change failed by peer: %s (%d)\n", |
| 4406 | drbd_set_st_err_str(retcode), retcode); |
| 4407 | } |
| 4408 | wake_up(&mdev->state_wait); |
| 4409 | } else /* conn == P_CONN_ST_CHG_REPLY */ { |
| 4410 | if (retcode >= SS_SUCCESS) { |
| 4411 | set_bit(CONN_WD_ST_CHG_OKAY, &tconn->flags); |
| 4412 | } else { |
| 4413 | set_bit(CONN_WD_ST_CHG_FAIL, &tconn->flags); |
| 4414 | conn_err(tconn, "Requested state change failed by peer: %s (%d)\n", |
| 4415 | drbd_set_st_err_str(retcode), retcode); |
| 4416 | } |
| 4417 | wake_up(&tconn->ping_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4418 | } |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4419 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4422 | static int got_Ping(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4423 | { |
Philipp Reisner | 2a67d8b | 2011-02-09 14:10:32 +0100 | [diff] [blame] | 4424 | return drbd_send_ping_ack(mdev->tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4425 | |
| 4426 | } |
| 4427 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4428 | static int got_PingAck(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4429 | { |
Philipp Reisner | 2a67d8b | 2011-02-09 14:10:32 +0100 | [diff] [blame] | 4430 | struct drbd_tconn *tconn = mdev->tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4431 | /* restore idle timeout */ |
Philipp Reisner | 2a67d8b | 2011-02-09 14:10:32 +0100 | [diff] [blame] | 4432 | tconn->meta.socket->sk->sk_rcvtimeo = tconn->net_conf->ping_int*HZ; |
| 4433 | if (!test_and_set_bit(GOT_PING_ACK, &tconn->flags)) |
| 4434 | wake_up(&tconn->ping_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4435 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4436 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4437 | } |
| 4438 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4439 | static int got_IsInSync(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4440 | { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4441 | struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4442 | sector_t sector = be64_to_cpu(p->sector); |
| 4443 | int blksize = be32_to_cpu(p->blksize); |
| 4444 | |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 4445 | D_ASSERT(mdev->tconn->agreed_pro_version >= 89); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4446 | |
| 4447 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 4448 | |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 4449 | if (get_ldev(mdev)) { |
| 4450 | drbd_rs_complete_io(mdev, sector); |
| 4451 | drbd_set_in_sync(mdev, sector, blksize); |
| 4452 | /* rs_same_csums is supposed to count in units of BM_BLOCK_SIZE */ |
| 4453 | mdev->rs_same_csum += (blksize >> BM_BLOCK_SHIFT); |
| 4454 | put_ldev(mdev); |
| 4455 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4456 | dec_rs_pending(mdev); |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 4457 | atomic_add(blksize >> 9, &mdev->rs_sect_in); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4458 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4459 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4460 | } |
| 4461 | |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 4462 | static int |
| 4463 | validate_req_change_req_state(struct drbd_conf *mdev, u64 id, sector_t sector, |
| 4464 | struct rb_root *root, const char *func, |
| 4465 | enum drbd_req_event what, bool missing_ok) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4466 | { |
| 4467 | struct drbd_request *req; |
| 4468 | struct bio_and_error m; |
| 4469 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4470 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 4471 | req = find_request(mdev, root, id, sector, missing_ok, func); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4472 | if (unlikely(!req)) { |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4473 | spin_unlock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4474 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4475 | } |
| 4476 | __req_mod(req, what, &m); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 4477 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4478 | |
| 4479 | if (m.bio) |
| 4480 | complete_master_bio(mdev, &m); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4481 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4482 | } |
| 4483 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4484 | static int got_BlockAck(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4485 | { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4486 | struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4487 | sector_t sector = be64_to_cpu(p->sector); |
| 4488 | int blksize = be32_to_cpu(p->blksize); |
| 4489 | enum drbd_req_event what; |
| 4490 | |
| 4491 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 4492 | |
Andreas Gruenbacher | 579b57e | 2011-01-13 18:40:57 +0100 | [diff] [blame] | 4493 | if (p->block_id == ID_SYNCER) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4494 | drbd_set_in_sync(mdev, sector, blksize); |
| 4495 | dec_rs_pending(mdev); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4496 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4497 | } |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4498 | switch (cmd) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4499 | case P_RS_WRITE_ACK: |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 4500 | D_ASSERT(mdev->tconn->net_conf->wire_protocol == DRBD_PROT_C); |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 4501 | what = WRITE_ACKED_BY_PEER_AND_SIS; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4502 | break; |
| 4503 | case P_WRITE_ACK: |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 4504 | D_ASSERT(mdev->tconn->net_conf->wire_protocol == DRBD_PROT_C); |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 4505 | what = WRITE_ACKED_BY_PEER; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4506 | break; |
| 4507 | case P_RECV_ACK: |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 4508 | D_ASSERT(mdev->tconn->net_conf->wire_protocol == DRBD_PROT_B); |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 4509 | what = RECV_ACKED_BY_PEER; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4510 | break; |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 4511 | case P_DISCARD_WRITE: |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 4512 | D_ASSERT(mdev->tconn->net_conf->wire_protocol == DRBD_PROT_C); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 4513 | what = DISCARD_WRITE; |
| 4514 | break; |
| 4515 | case P_RETRY_WRITE: |
| 4516 | D_ASSERT(mdev->tconn->net_conf->wire_protocol == DRBD_PROT_C); |
| 4517 | what = POSTPONE_WRITE; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4518 | break; |
| 4519 | default: |
| 4520 | D_ASSERT(0); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4521 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | return validate_req_change_req_state(mdev, p->block_id, sector, |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 4525 | &mdev->write_requests, __func__, |
| 4526 | what, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4529 | static int got_NegAck(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4530 | { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4531 | struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4532 | sector_t sector = be64_to_cpu(p->sector); |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 4533 | int size = be32_to_cpu(p->blksize); |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 4534 | bool missing_ok = mdev->tconn->net_conf->wire_protocol == DRBD_PROT_A || |
| 4535 | mdev->tconn->net_conf->wire_protocol == DRBD_PROT_B; |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 4536 | bool found; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4537 | |
| 4538 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 4539 | |
Andreas Gruenbacher | 579b57e | 2011-01-13 18:40:57 +0100 | [diff] [blame] | 4540 | if (p->block_id == ID_SYNCER) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4541 | dec_rs_pending(mdev); |
| 4542 | drbd_rs_failed_io(mdev, sector, size); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4543 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4544 | } |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 4545 | |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 4546 | found = validate_req_change_req_state(mdev, p->block_id, sector, |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 4547 | &mdev->write_requests, __func__, |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 4548 | NEG_ACKED, missing_ok); |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 4549 | if (!found) { |
| 4550 | /* Protocol A has no P_WRITE_ACKs, but has P_NEG_ACKs. |
| 4551 | The master bio might already be completed, therefore the |
| 4552 | request is no longer in the collision hash. */ |
| 4553 | /* In Protocol B we might already have got a P_RECV_ACK |
| 4554 | but then get a P_NEG_ACK afterwards. */ |
| 4555 | if (!missing_ok) |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 4556 | return false; |
Andreas Gruenbacher | c3afd8f | 2011-01-20 22:25:40 +0100 | [diff] [blame] | 4557 | drbd_set_out_of_sync(mdev, sector, size); |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 4558 | } |
Philipp Reisner | 2deb833 | 2011-01-17 18:39:18 +0100 | [diff] [blame] | 4559 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4560 | } |
| 4561 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4562 | static int got_NegDReply(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4563 | { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4564 | struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4565 | sector_t sector = be64_to_cpu(p->sector); |
| 4566 | |
| 4567 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
Andreas Gruenbacher | 7be8da0 | 2011-02-22 02:15:32 +0100 | [diff] [blame] | 4568 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4569 | dev_err(DEV, "Got NegDReply; Sector %llus, len %u; Fail original request.\n", |
| 4570 | (unsigned long long)sector, be32_to_cpu(p->blksize)); |
| 4571 | |
| 4572 | return validate_req_change_req_state(mdev, p->block_id, sector, |
Andreas Gruenbacher | bc9c5c4 | 2011-01-21 18:00:55 +0100 | [diff] [blame] | 4573 | &mdev->read_requests, __func__, |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 4574 | NEG_ACKED, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4575 | } |
| 4576 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4577 | static int got_NegRSDReply(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4578 | { |
| 4579 | sector_t sector; |
| 4580 | int size; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4581 | struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4582 | |
| 4583 | sector = be64_to_cpu(p->sector); |
| 4584 | size = be32_to_cpu(p->blksize); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4585 | |
| 4586 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 4587 | |
| 4588 | dec_rs_pending(mdev); |
| 4589 | |
| 4590 | if (get_ldev_if_state(mdev, D_FAILED)) { |
| 4591 | drbd_rs_complete_io(mdev, sector); |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4592 | switch (cmd) { |
Philipp Reisner | d612d30 | 2010-12-27 10:53:28 +0100 | [diff] [blame] | 4593 | case P_NEG_RS_DREPLY: |
| 4594 | drbd_rs_failed_io(mdev, sector, size); |
| 4595 | case P_RS_CANCEL: |
| 4596 | break; |
| 4597 | default: |
| 4598 | D_ASSERT(0); |
| 4599 | put_ldev(mdev); |
| 4600 | return false; |
| 4601 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4602 | put_ldev(mdev); |
| 4603 | } |
| 4604 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4605 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4606 | } |
| 4607 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4608 | static int got_BarrierAck(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4609 | { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4610 | struct p_barrier_ack *p = &mdev->tconn->meta.rbuf.barrier_ack; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4611 | |
Philipp Reisner | 2f5cdd0 | 2011-02-21 14:29:27 +0100 | [diff] [blame] | 4612 | tl_release(mdev->tconn, p->barrier, be32_to_cpu(p->set_size)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4613 | |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 4614 | if (mdev->state.conn == C_AHEAD && |
| 4615 | atomic_read(&mdev->ap_in_flight) == 0 && |
Philipp Reisner | 370a43e | 2011-01-14 16:03:11 +0100 | [diff] [blame] | 4616 | !test_and_set_bit(AHEAD_TO_SYNC_SOURCE, &mdev->current_epoch->flags)) { |
| 4617 | mdev->start_resync_timer.expires = jiffies + HZ; |
| 4618 | add_timer(&mdev->start_resync_timer); |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 4619 | } |
| 4620 | |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4621 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4622 | } |
| 4623 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4624 | static int got_OVResult(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4625 | { |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4626 | struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4627 | struct drbd_work *w; |
| 4628 | sector_t sector; |
| 4629 | int size; |
| 4630 | |
| 4631 | sector = be64_to_cpu(p->sector); |
| 4632 | size = be32_to_cpu(p->blksize); |
| 4633 | |
| 4634 | update_peer_seq(mdev, be32_to_cpu(p->seq_num)); |
| 4635 | |
| 4636 | if (be64_to_cpu(p->block_id) == ID_OUT_OF_SYNC) |
| 4637 | drbd_ov_oos_found(mdev, sector, size); |
| 4638 | else |
| 4639 | ov_oos_print(mdev); |
| 4640 | |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 4641 | if (!get_ldev(mdev)) |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4642 | return true; |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 4643 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4644 | drbd_rs_complete_io(mdev, sector); |
| 4645 | dec_rs_pending(mdev); |
| 4646 | |
Lars Ellenberg | ea5442a | 2010-11-05 09:48:01 +0100 | [diff] [blame] | 4647 | --mdev->ov_left; |
| 4648 | |
| 4649 | /* let's advance progress step marks only for every other megabyte */ |
| 4650 | if ((mdev->ov_left & 0x200) == 0x200) |
| 4651 | drbd_advance_rs_marks(mdev, mdev->ov_left); |
| 4652 | |
| 4653 | if (mdev->ov_left == 0) { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4654 | w = kmalloc(sizeof(*w), GFP_NOIO); |
| 4655 | if (w) { |
| 4656 | w->cb = w_ov_finished; |
Philipp Reisner | a21e929 | 2011-02-08 15:08:49 +0100 | [diff] [blame] | 4657 | w->mdev = mdev; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 4658 | drbd_queue_work_front(&mdev->tconn->data.work, w); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4659 | } else { |
| 4660 | dev_err(DEV, "kmalloc(w) failed."); |
| 4661 | ov_oos_print(mdev); |
| 4662 | drbd_resync_finished(mdev); |
| 4663 | } |
| 4664 | } |
Lars Ellenberg | 1d53f09 | 2010-09-05 01:13:24 +0200 | [diff] [blame] | 4665 | put_ldev(mdev); |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4666 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4667 | } |
| 4668 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 4669 | static int got_skip(struct drbd_conf *mdev, enum drbd_packet cmd) |
Philipp Reisner | 0ced55a | 2010-04-30 15:26:20 +0200 | [diff] [blame] | 4670 | { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 4671 | return true; |
Philipp Reisner | 0ced55a | 2010-04-30 15:26:20 +0200 | [diff] [blame] | 4672 | } |
| 4673 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4674 | static int tconn_process_done_ee(struct drbd_tconn *tconn) |
| 4675 | { |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 4676 | struct drbd_conf *mdev; |
| 4677 | int i, not_empty = 0; |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4678 | |
| 4679 | do { |
| 4680 | clear_bit(SIGNAL_ASENDER, &tconn->flags); |
| 4681 | flush_signals(current); |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 4682 | idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 4683 | if (!drbd_process_done_ee(mdev)) |
| 4684 | return 1; /* error */ |
| 4685 | } |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4686 | set_bit(SIGNAL_ASENDER, &tconn->flags); |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 4687 | |
| 4688 | spin_lock_irq(&tconn->req_lock); |
| 4689 | idr_for_each_entry(&tconn->volumes, mdev, i) { |
| 4690 | not_empty = !list_empty(&mdev->done_ee); |
| 4691 | if (not_empty) |
| 4692 | break; |
| 4693 | } |
| 4694 | spin_unlock_irq(&tconn->req_lock); |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4695 | } while (not_empty); |
| 4696 | |
| 4697 | return 0; |
| 4698 | } |
| 4699 | |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 4700 | struct asender_cmd { |
| 4701 | size_t pkt_size; |
| 4702 | int (*process)(struct drbd_conf *, enum drbd_packet); |
| 4703 | }; |
| 4704 | |
| 4705 | static struct asender_cmd asender_tbl[] = { |
| 4706 | [P_PING] = { sizeof(struct p_header), got_Ping }, |
| 4707 | [P_PING_ACK] = { sizeof(struct p_header), got_PingAck }, |
| 4708 | [P_RECV_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 4709 | [P_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 4710 | [P_RS_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 4711 | [P_DISCARD_WRITE] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 4712 | [P_NEG_ACK] = { sizeof(struct p_block_ack), got_NegAck }, |
| 4713 | [P_NEG_DREPLY] = { sizeof(struct p_block_ack), got_NegDReply }, |
| 4714 | [P_NEG_RS_DREPLY] = { sizeof(struct p_block_ack), got_NegRSDReply}, |
| 4715 | [P_OV_RESULT] = { sizeof(struct p_block_ack), got_OVResult }, |
| 4716 | [P_BARRIER_ACK] = { sizeof(struct p_barrier_ack), got_BarrierAck }, |
| 4717 | [P_STATE_CHG_REPLY] = { sizeof(struct p_req_state_reply), got_RqSReply }, |
| 4718 | [P_RS_IS_IN_SYNC] = { sizeof(struct p_block_ack), got_IsInSync }, |
| 4719 | [P_DELAY_PROBE] = { sizeof(struct p_delay_probe93), got_skip }, |
| 4720 | [P_RS_CANCEL] = { sizeof(struct p_block_ack), got_NegRSDReply}, |
| 4721 | [P_CONN_ST_CHG_REPLY]={ sizeof(struct p_req_state_reply), got_RqSReply }, |
| 4722 | [P_RETRY_WRITE] = { sizeof(struct p_block_ack), got_BlockAck }, |
| 4723 | }; |
| 4724 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4725 | int drbd_asender(struct drbd_thread *thi) |
| 4726 | { |
Philipp Reisner | 392c880 | 2011-02-09 10:33:31 +0100 | [diff] [blame] | 4727 | struct drbd_tconn *tconn = thi->tconn; |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4728 | struct p_header *h = &tconn->meta.rbuf.header; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4729 | struct asender_cmd *cmd = NULL; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4730 | struct packet_info pi; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4731 | int rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4732 | void *buf = h; |
| 4733 | int received = 0; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4734 | int expect = sizeof(struct p_header); |
Lars Ellenberg | f36af18 | 2011-03-09 22:44:55 +0100 | [diff] [blame] | 4735 | int ping_timeout_active = 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4736 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4737 | current->policy = SCHED_RR; /* Make this a realtime task! */ |
| 4738 | current->rt_priority = 2; /* more important than all other tasks */ |
| 4739 | |
Andreas Gruenbacher | e77a0a5 | 2011-01-25 15:43:39 +0100 | [diff] [blame] | 4740 | while (get_t_state(thi) == RUNNING) { |
Philipp Reisner | 8082228 | 2011-02-08 12:46:30 +0100 | [diff] [blame] | 4741 | drbd_thread_current_set_cpu(thi); |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4742 | if (test_and_clear_bit(SEND_PING, &tconn->flags)) { |
Philipp Reisner | 2a67d8b | 2011-02-09 14:10:32 +0100 | [diff] [blame] | 4743 | if (!drbd_send_ping(tconn)) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4744 | conn_err(tconn, "drbd_send_ping has failed\n"); |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 4745 | goto reconnect; |
| 4746 | } |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4747 | tconn->meta.socket->sk->sk_rcvtimeo = |
| 4748 | tconn->net_conf->ping_timeo*HZ/10; |
Lars Ellenberg | f36af18 | 2011-03-09 22:44:55 +0100 | [diff] [blame] | 4749 | ping_timeout_active = 1; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4750 | } |
| 4751 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4752 | /* TODO: conditionally cork; it may hurt latency if we cork without |
| 4753 | much to send */ |
| 4754 | if (!tconn->net_conf->no_cork) |
| 4755 | drbd_tcp_cork(tconn->meta.socket); |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 4756 | if (tconn_process_done_ee(tconn)) { |
| 4757 | conn_err(tconn, "tconn_process_done_ee() failed\n"); |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4758 | goto reconnect; |
Philipp Reisner | 082a343 | 2011-03-15 16:05:42 +0100 | [diff] [blame] | 4759 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4760 | /* but unconditionally uncork unless disabled */ |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4761 | if (!tconn->net_conf->no_cork) |
| 4762 | drbd_tcp_uncork(tconn->meta.socket); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4763 | |
| 4764 | /* short circuit, recv_msg would return EINTR anyways. */ |
| 4765 | if (signal_pending(current)) |
| 4766 | continue; |
| 4767 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4768 | rv = drbd_recv_short(tconn->meta.socket, buf, expect-received, 0); |
| 4769 | clear_bit(SIGNAL_ASENDER, &tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4770 | |
| 4771 | flush_signals(current); |
| 4772 | |
| 4773 | /* Note: |
| 4774 | * -EINTR (on meta) we got a signal |
| 4775 | * -EAGAIN (on meta) rcvtimeo expired |
| 4776 | * -ECONNRESET other side closed the connection |
| 4777 | * -ERESTARTSYS (on data) we got a signal |
| 4778 | * rv < 0 other than above: unexpected error! |
| 4779 | * rv == expected: full header or command |
| 4780 | * rv < expected: "woken" by signal during receive |
| 4781 | * rv == 0 : "connection shut down by peer" |
| 4782 | */ |
| 4783 | if (likely(rv > 0)) { |
| 4784 | received += rv; |
| 4785 | buf += rv; |
| 4786 | } else if (rv == 0) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4787 | conn_err(tconn, "meta connection shut down by peer.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4788 | goto reconnect; |
| 4789 | } else if (rv == -EAGAIN) { |
Lars Ellenberg | cb6518c | 2011-06-20 14:44:45 +0200 | [diff] [blame] | 4790 | /* If the data socket received something meanwhile, |
| 4791 | * that is good enough: peer is still alive. */ |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4792 | if (time_after(tconn->last_received, |
| 4793 | jiffies - tconn->meta.socket->sk->sk_rcvtimeo)) |
Lars Ellenberg | cb6518c | 2011-06-20 14:44:45 +0200 | [diff] [blame] | 4794 | continue; |
Lars Ellenberg | f36af18 | 2011-03-09 22:44:55 +0100 | [diff] [blame] | 4795 | if (ping_timeout_active) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4796 | conn_err(tconn, "PingAck did not arrive in time.\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4797 | goto reconnect; |
| 4798 | } |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4799 | set_bit(SEND_PING, &tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4800 | continue; |
| 4801 | } else if (rv == -EINTR) { |
| 4802 | continue; |
| 4803 | } else { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4804 | conn_err(tconn, "sock_recvmsg returned %d\n", rv); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4805 | goto reconnect; |
| 4806 | } |
| 4807 | |
| 4808 | if (received == expect && cmd == NULL) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4809 | if (!decode_header(tconn, h, &pi)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4810 | goto reconnect; |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 4811 | cmd = &asender_tbl[pi.cmd]; |
| 4812 | if (pi.cmd >= ARRAY_SIZE(asender_tbl) || !cmd) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4813 | conn_err(tconn, "unknown command %d on meta (l: %d)\n", |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4814 | pi.cmd, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4815 | goto disconnect; |
| 4816 | } |
| 4817 | expect = cmd->pkt_size; |
Philipp Reisner | 77351055b | 2011-02-07 17:24:26 +0100 | [diff] [blame] | 4818 | if (pi.size != expect - sizeof(struct p_header)) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4819 | 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] | 4820 | pi.cmd, pi.size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4821 | goto reconnect; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4822 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4823 | } |
| 4824 | if (received == expect) { |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4825 | tconn->last_received = jiffies; |
| 4826 | if (!cmd->process(vnr_to_mdev(tconn, pi.vnr), pi.cmd)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4827 | goto reconnect; |
| 4828 | |
Lars Ellenberg | f36af18 | 2011-03-09 22:44:55 +0100 | [diff] [blame] | 4829 | /* the idle_timeout (ping-int) |
| 4830 | * has been restored in got_PingAck() */ |
Andreas Gruenbacher | 7201b97 | 2011-03-14 18:23:00 +0100 | [diff] [blame] | 4831 | if (cmd == &asender_tbl[P_PING_ACK]) |
Lars Ellenberg | f36af18 | 2011-03-09 22:44:55 +0100 | [diff] [blame] | 4832 | ping_timeout_active = 0; |
| 4833 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4834 | buf = h; |
| 4835 | received = 0; |
Philipp Reisner | 257d0af | 2011-01-26 12:15:29 +0100 | [diff] [blame] | 4836 | expect = sizeof(struct p_header); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4837 | cmd = NULL; |
| 4838 | } |
| 4839 | } |
| 4840 | |
| 4841 | if (0) { |
| 4842 | reconnect: |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4843 | conn_request_state(tconn, NS(conn, C_NETWORK_FAILURE), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4844 | } |
| 4845 | if (0) { |
| 4846 | disconnect: |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 4847 | conn_request_state(tconn, NS(conn, C_DISCONNECTING), CS_HARD); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4848 | } |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4849 | clear_bit(SIGNAL_ASENDER, &tconn->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4850 | |
Philipp Reisner | 32862ec | 2011-02-08 16:41:01 +0100 | [diff] [blame] | 4851 | conn_info(tconn, "asender terminated\n"); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 4852 | |
| 4853 | return 0; |
| 4854 | } |