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