Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | drbd_int.h |
| 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 | |
| 26 | #ifndef _DRBD_INT_H |
| 27 | #define _DRBD_INT_H |
| 28 | |
| 29 | #include <linux/compiler.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/version.h> |
| 32 | #include <linux/list.h> |
| 33 | #include <linux/sched.h> |
| 34 | #include <linux/bitops.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/crypto.h> |
Randy Dunlap | 132cc53 | 2009-10-07 19:26:00 +0200 | [diff] [blame] | 37 | #include <linux/ratelimit.h> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 38 | #include <linux/tcp.h> |
| 39 | #include <linux/mutex.h> |
| 40 | #include <linux/major.h> |
| 41 | #include <linux/blkdev.h> |
| 42 | #include <linux/genhd.h> |
| 43 | #include <net/tcp.h> |
| 44 | #include <linux/lru_cache.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 45 | #include <linux/prefetch.h> |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 46 | |
| 47 | #ifdef __CHECKER__ |
| 48 | # define __protected_by(x) __attribute__((require_context(x,1,999,"rdwr"))) |
| 49 | # define __protected_read_by(x) __attribute__((require_context(x,1,999,"read"))) |
| 50 | # define __protected_write_by(x) __attribute__((require_context(x,1,999,"write"))) |
| 51 | # define __must_hold(x) __attribute__((context(x,1,1), require_context(x,1,999,"call"))) |
| 52 | #else |
| 53 | # define __protected_by(x) |
| 54 | # define __protected_read_by(x) |
| 55 | # define __protected_write_by(x) |
| 56 | # define __must_hold(x) |
| 57 | #endif |
| 58 | |
| 59 | #define __no_warn(lock, stmt) do { __acquire(lock); stmt; __release(lock); } while (0) |
| 60 | |
| 61 | /* module parameter, defined in drbd_main.c */ |
| 62 | extern unsigned int minor_count; |
| 63 | extern int disable_sendpage; |
| 64 | extern int allow_oos; |
| 65 | extern unsigned int cn_idx; |
| 66 | |
| 67 | #ifdef CONFIG_DRBD_FAULT_INJECTION |
| 68 | extern int enable_faults; |
| 69 | extern int fault_rate; |
| 70 | extern int fault_devs; |
| 71 | #endif |
| 72 | |
| 73 | extern char usermode_helper[]; |
| 74 | |
| 75 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 76 | /* I don't remember why XCPU ... |
| 77 | * This is used to wake the asender, |
| 78 | * and to interrupt sending the sending task |
| 79 | * on disconnect. |
| 80 | */ |
| 81 | #define DRBD_SIG SIGXCPU |
| 82 | |
| 83 | /* This is used to stop/restart our threads. |
| 84 | * Cannot use SIGTERM nor SIGKILL, since these |
| 85 | * are sent out by init on runlevel changes |
| 86 | * I choose SIGHUP for now. |
| 87 | */ |
| 88 | #define DRBD_SIGKILL SIGHUP |
| 89 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 90 | #define ID_IN_SYNC (4711ULL) |
| 91 | #define ID_OUT_OF_SYNC (4712ULL) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 92 | #define ID_SYNCER (-1ULL) |
Andreas Gruenbacher | 579b57e | 2011-01-13 18:40:57 +0100 | [diff] [blame] | 93 | |
Philipp Reisner | 4a23f26 | 2011-01-11 17:42:17 +0100 | [diff] [blame] | 94 | #define UUID_NEW_BM_OFFSET ((u64)0x0001000000000000ULL) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 95 | |
| 96 | struct drbd_conf; |
Philipp Reisner | 2111438 | 2011-01-19 12:26:59 +0100 | [diff] [blame] | 97 | struct drbd_tconn; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 98 | |
| 99 | |
| 100 | /* to shorten dev_warn(DEV, "msg"); and relatives statements */ |
| 101 | #define DEV (disk_to_dev(mdev->vdisk)) |
| 102 | |
| 103 | #define D_ASSERT(exp) if (!(exp)) \ |
| 104 | dev_err(DEV, "ASSERT( " #exp " ) in %s:%d\n", __FILE__, __LINE__) |
| 105 | |
Andreas Gruenbacher | 841ce24 | 2010-12-15 19:31:20 +0100 | [diff] [blame] | 106 | /** |
| 107 | * expect - Make an assertion |
| 108 | * |
| 109 | * Unlike the assert macro, this macro returns a boolean result. |
| 110 | */ |
| 111 | #define expect(exp) ({ \ |
| 112 | bool _bool = (exp); \ |
| 113 | if (!_bool) \ |
| 114 | dev_err(DEV, "ASSERTION %s FAILED in %s\n", \ |
| 115 | #exp, __func__); \ |
| 116 | _bool; \ |
| 117 | }) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 118 | |
| 119 | /* Defines to control fault insertion */ |
| 120 | enum { |
| 121 | DRBD_FAULT_MD_WR = 0, /* meta data write */ |
| 122 | DRBD_FAULT_MD_RD = 1, /* read */ |
| 123 | DRBD_FAULT_RS_WR = 2, /* resync */ |
| 124 | DRBD_FAULT_RS_RD = 3, |
| 125 | DRBD_FAULT_DT_WR = 4, /* data */ |
| 126 | DRBD_FAULT_DT_RD = 5, |
| 127 | DRBD_FAULT_DT_RA = 6, /* data read ahead */ |
| 128 | DRBD_FAULT_BM_ALLOC = 7, /* bitmap allocation */ |
| 129 | DRBD_FAULT_AL_EE = 8, /* alloc ee */ |
Philipp Reisner | 6b4388a | 2010-04-26 14:11:45 +0200 | [diff] [blame] | 130 | DRBD_FAULT_RECEIVE = 9, /* Changes some bytes upon receiving a [rs]data block */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 131 | |
| 132 | DRBD_FAULT_MAX, |
| 133 | }; |
| 134 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 135 | extern unsigned int |
| 136 | _drbd_insert_fault(struct drbd_conf *mdev, unsigned int type); |
Andreas Gruenbacher | 0cf9d27 | 2010-12-07 10:43:29 +0100 | [diff] [blame] | 137 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 138 | static inline int |
| 139 | drbd_insert_fault(struct drbd_conf *mdev, unsigned int type) { |
Andreas Gruenbacher | 0cf9d27 | 2010-12-07 10:43:29 +0100 | [diff] [blame] | 140 | #ifdef CONFIG_DRBD_FAULT_INJECTION |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 141 | return fault_rate && |
| 142 | (enable_faults & (1<<type)) && |
| 143 | _drbd_insert_fault(mdev, type); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 144 | #else |
Andreas Gruenbacher | 0cf9d27 | 2010-12-07 10:43:29 +0100 | [diff] [blame] | 145 | return 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 146 | #endif |
Andreas Gruenbacher | 0cf9d27 | 2010-12-07 10:43:29 +0100 | [diff] [blame] | 147 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 148 | |
| 149 | /* integer division, round _UP_ to the next integer */ |
| 150 | #define div_ceil(A, B) ((A)/(B) + ((A)%(B) ? 1 : 0)) |
| 151 | /* usual integer division */ |
| 152 | #define div_floor(A, B) ((A)/(B)) |
| 153 | |
| 154 | /* drbd_meta-data.c (still in drbd_main.c) */ |
| 155 | /* 4th incarnation of the disk layout. */ |
| 156 | #define DRBD_MD_MAGIC (DRBD_MAGIC+4) |
| 157 | |
| 158 | extern struct drbd_conf **minor_table; |
| 159 | extern struct ratelimit_state drbd_ratelimit_state; |
| 160 | |
| 161 | /* on the wire */ |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 162 | enum drbd_packet { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 163 | /* receiver (data socket) */ |
| 164 | P_DATA = 0x00, |
| 165 | P_DATA_REPLY = 0x01, /* Response to P_DATA_REQUEST */ |
| 166 | P_RS_DATA_REPLY = 0x02, /* Response to P_RS_DATA_REQUEST */ |
| 167 | P_BARRIER = 0x03, |
| 168 | P_BITMAP = 0x04, |
| 169 | P_BECOME_SYNC_TARGET = 0x05, |
| 170 | P_BECOME_SYNC_SOURCE = 0x06, |
| 171 | P_UNPLUG_REMOTE = 0x07, /* Used at various times to hint the peer */ |
| 172 | P_DATA_REQUEST = 0x08, /* Used to ask for a data block */ |
| 173 | P_RS_DATA_REQUEST = 0x09, /* Used to ask for a data block for resync */ |
| 174 | P_SYNC_PARAM = 0x0a, |
| 175 | P_PROTOCOL = 0x0b, |
| 176 | P_UUIDS = 0x0c, |
| 177 | P_SIZES = 0x0d, |
| 178 | P_STATE = 0x0e, |
| 179 | P_SYNC_UUID = 0x0f, |
| 180 | P_AUTH_CHALLENGE = 0x10, |
| 181 | P_AUTH_RESPONSE = 0x11, |
| 182 | P_STATE_CHG_REQ = 0x12, |
| 183 | |
| 184 | /* asender (meta socket */ |
| 185 | P_PING = 0x13, |
| 186 | P_PING_ACK = 0x14, |
| 187 | P_RECV_ACK = 0x15, /* Used in protocol B */ |
| 188 | P_WRITE_ACK = 0x16, /* Used in protocol C */ |
| 189 | P_RS_WRITE_ACK = 0x17, /* Is a P_WRITE_ACK, additionally call set_in_sync(). */ |
| 190 | P_DISCARD_ACK = 0x18, /* Used in proto C, two-primaries conflict detection */ |
| 191 | P_NEG_ACK = 0x19, /* Sent if local disk is unusable */ |
| 192 | P_NEG_DREPLY = 0x1a, /* Local disk is broken... */ |
| 193 | P_NEG_RS_DREPLY = 0x1b, /* Local disk is broken... */ |
| 194 | P_BARRIER_ACK = 0x1c, |
| 195 | P_STATE_CHG_REPLY = 0x1d, |
| 196 | |
| 197 | /* "new" commands, no longer fitting into the ordering scheme above */ |
| 198 | |
| 199 | P_OV_REQUEST = 0x1e, /* data socket */ |
| 200 | P_OV_REPLY = 0x1f, |
| 201 | P_OV_RESULT = 0x20, /* meta socket */ |
| 202 | P_CSUM_RS_REQUEST = 0x21, /* data socket */ |
| 203 | P_RS_IS_IN_SYNC = 0x22, /* meta socket */ |
| 204 | P_SYNC_PARAM89 = 0x23, /* data socket, protocol version 89 replacement for P_SYNC_PARAM */ |
| 205 | P_COMPRESSED_BITMAP = 0x24, /* compressed or otherwise encoded bitmap transfer */ |
Philipp Reisner | 0ced55a | 2010-04-30 15:26:20 +0200 | [diff] [blame] | 206 | /* P_CKPT_FENCE_REQ = 0x25, * currently reserved for protocol D */ |
| 207 | /* P_CKPT_DISABLE_REQ = 0x26, * currently reserved for protocol D */ |
| 208 | P_DELAY_PROBE = 0x27, /* is used on BOTH sockets */ |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 209 | P_OUT_OF_SYNC = 0x28, /* Mark as out of sync (Outrunning), data socket */ |
Philipp Reisner | d612d30 | 2010-12-27 10:53:28 +0100 | [diff] [blame] | 210 | P_RS_CANCEL = 0x29, /* meta: Used to cancel RS_DATA_REQUEST packet by SyncSource */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 211 | |
Philipp Reisner | d612d30 | 2010-12-27 10:53:28 +0100 | [diff] [blame] | 212 | P_MAX_CMD = 0x2A, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 213 | P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */ |
| 214 | P_MAX_OPT_CMD = 0x101, |
| 215 | |
| 216 | /* special command ids for handshake */ |
| 217 | |
| 218 | P_HAND_SHAKE_M = 0xfff1, /* First Packet on the MetaSock */ |
| 219 | P_HAND_SHAKE_S = 0xfff2, /* First Packet on the Socket */ |
| 220 | |
| 221 | P_HAND_SHAKE = 0xfffe /* FIXED for the next century! */ |
| 222 | }; |
| 223 | |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 224 | extern const char *cmdname(enum drbd_packet cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 225 | |
| 226 | /* for sending/receiving the bitmap, |
| 227 | * possibly in some encoding scheme */ |
| 228 | struct bm_xfer_ctx { |
| 229 | /* "const" |
| 230 | * stores total bits and long words |
| 231 | * of the bitmap, so we don't need to |
| 232 | * call the accessor functions over and again. */ |
| 233 | unsigned long bm_bits; |
| 234 | unsigned long bm_words; |
| 235 | /* during xfer, current position within the bitmap */ |
| 236 | unsigned long bit_offset; |
| 237 | unsigned long word_offset; |
| 238 | |
| 239 | /* statistics; index: (h->command == P_BITMAP) */ |
| 240 | unsigned packets[2]; |
| 241 | unsigned bytes[2]; |
| 242 | }; |
| 243 | |
| 244 | extern void INFO_bm_xfer_stats(struct drbd_conf *mdev, |
| 245 | const char *direction, struct bm_xfer_ctx *c); |
| 246 | |
| 247 | static inline void bm_xfer_ctx_bit_to_word_offset(struct bm_xfer_ctx *c) |
| 248 | { |
| 249 | /* word_offset counts "native long words" (32 or 64 bit), |
| 250 | * aligned at 64 bit. |
| 251 | * Encoded packet may end at an unaligned bit offset. |
| 252 | * In case a fallback clear text packet is transmitted in |
| 253 | * between, we adjust this offset back to the last 64bit |
| 254 | * aligned "native long word", which makes coding and decoding |
| 255 | * the plain text bitmap much more convenient. */ |
| 256 | #if BITS_PER_LONG == 64 |
| 257 | c->word_offset = c->bit_offset >> 6; |
| 258 | #elif BITS_PER_LONG == 32 |
| 259 | c->word_offset = c->bit_offset >> 5; |
| 260 | c->word_offset &= ~(1UL); |
| 261 | #else |
| 262 | # error "unsupported BITS_PER_LONG" |
| 263 | #endif |
| 264 | } |
| 265 | |
| 266 | #ifndef __packed |
| 267 | #define __packed __attribute__((packed)) |
| 268 | #endif |
| 269 | |
| 270 | /* This is the layout for a packet on the wire. |
| 271 | * The byteorder is the network byte order. |
| 272 | * (except block_id and barrier fields. |
| 273 | * these are pointers to local structs |
| 274 | * and have no relevance for the partner, |
| 275 | * which just echoes them as received.) |
| 276 | * |
| 277 | * NOTE that the payload starts at a long aligned offset, |
| 278 | * regardless of 32 or 64 bit arch! |
| 279 | */ |
Philipp Reisner | 0b70a13 | 2010-08-20 13:36:10 +0200 | [diff] [blame] | 280 | struct p_header80 { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 281 | u32 magic; |
| 282 | u16 command; |
| 283 | u16 length; /* bytes of data after this header */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 284 | } __packed; |
Philipp Reisner | 0b70a13 | 2010-08-20 13:36:10 +0200 | [diff] [blame] | 285 | |
| 286 | /* Header for big packets, Used for data packets exceeding 64kB */ |
| 287 | struct p_header95 { |
| 288 | u16 magic; /* use DRBD_MAGIC_BIG here */ |
| 289 | u16 command; |
Philipp Reisner | 00b4253 | 2010-10-05 11:19:39 +0200 | [diff] [blame] | 290 | u32 length; /* Use only 24 bits of that. Ignore the highest 8 bit. */ |
Philipp Reisner | 0b70a13 | 2010-08-20 13:36:10 +0200 | [diff] [blame] | 291 | } __packed; |
| 292 | |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 293 | struct p_header { |
| 294 | union { |
| 295 | struct p_header80 h80; |
| 296 | struct p_header95 h95; |
| 297 | }; |
| 298 | u8 payload[0]; |
Philipp Reisner | 0b70a13 | 2010-08-20 13:36:10 +0200 | [diff] [blame] | 299 | }; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 300 | |
| 301 | /* |
| 302 | * short commands, packets without payload, plain p_header: |
| 303 | * P_PING |
| 304 | * P_PING_ACK |
| 305 | * P_BECOME_SYNC_TARGET |
| 306 | * P_BECOME_SYNC_SOURCE |
| 307 | * P_UNPLUG_REMOTE |
| 308 | */ |
| 309 | |
| 310 | /* |
| 311 | * commands with out-of-struct payload: |
| 312 | * P_BITMAP (no additional fields) |
| 313 | * P_DATA, P_DATA_REPLY (see p_data) |
| 314 | * P_COMPRESSED_BITMAP (see receive_compressed_bitmap) |
| 315 | */ |
| 316 | |
| 317 | /* these defines must not be changed without changing the protocol version */ |
Philipp Reisner | 76d2e7e | 2010-08-25 11:58:05 +0200 | [diff] [blame] | 318 | #define DP_HARDBARRIER 1 /* depricated */ |
| 319 | #define DP_RW_SYNC 2 /* equals REQ_SYNC */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 320 | #define DP_MAY_SET_IN_SYNC 4 |
Jens Axboe | 721a960 | 2011-03-09 11:56:30 +0100 | [diff] [blame] | 321 | #define DP_UNPLUG 8 /* not used anymore */ |
Philipp Reisner | 76d2e7e | 2010-08-25 11:58:05 +0200 | [diff] [blame] | 322 | #define DP_FUA 16 /* equals REQ_FUA */ |
| 323 | #define DP_FLUSH 32 /* equals REQ_FLUSH */ |
| 324 | #define DP_DISCARD 64 /* equals REQ_DISCARD */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 325 | |
| 326 | struct p_data { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 327 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 328 | u64 sector; /* 64 bits sector number */ |
| 329 | u64 block_id; /* to identify the request in protocol B&C */ |
| 330 | u32 seq_num; |
| 331 | u32 dp_flags; |
| 332 | } __packed; |
| 333 | |
| 334 | /* |
| 335 | * commands which share a struct: |
| 336 | * p_block_ack: |
| 337 | * P_RECV_ACK (proto B), P_WRITE_ACK (proto C), |
| 338 | * P_DISCARD_ACK (proto C, two-primaries conflict detection) |
| 339 | * p_block_req: |
| 340 | * P_DATA_REQUEST, P_RS_DATA_REQUEST |
| 341 | */ |
| 342 | struct p_block_ack { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 343 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 344 | u64 sector; |
| 345 | u64 block_id; |
| 346 | u32 blksize; |
| 347 | u32 seq_num; |
| 348 | } __packed; |
| 349 | |
| 350 | |
| 351 | struct p_block_req { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 352 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 353 | u64 sector; |
| 354 | u64 block_id; |
| 355 | u32 blksize; |
| 356 | u32 pad; /* to multiple of 8 Byte */ |
| 357 | } __packed; |
| 358 | |
| 359 | /* |
| 360 | * commands with their own struct for additional fields: |
| 361 | * P_HAND_SHAKE |
| 362 | * P_BARRIER |
| 363 | * P_BARRIER_ACK |
| 364 | * P_SYNC_PARAM |
| 365 | * ReportParams |
| 366 | */ |
| 367 | |
| 368 | struct p_handshake { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 369 | struct p_header head; /* Note: You must always use a h80 here */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 370 | u32 protocol_min; |
| 371 | u32 feature_flags; |
| 372 | u32 protocol_max; |
| 373 | |
| 374 | /* should be more than enough for future enhancements |
| 375 | * for now, feature_flags and the reserverd array shall be zero. |
| 376 | */ |
| 377 | |
| 378 | u32 _pad; |
| 379 | u64 reserverd[7]; |
| 380 | } __packed; |
| 381 | /* 80 bytes, FIXED for the next century */ |
| 382 | |
| 383 | struct p_barrier { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 384 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 385 | u32 barrier; /* barrier number _handle_ only */ |
| 386 | u32 pad; /* to multiple of 8 Byte */ |
| 387 | } __packed; |
| 388 | |
| 389 | struct p_barrier_ack { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 390 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 391 | u32 barrier; |
| 392 | u32 set_size; |
| 393 | } __packed; |
| 394 | |
| 395 | struct p_rs_param { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 396 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 397 | u32 rate; |
| 398 | |
| 399 | /* Since protocol version 88 and higher. */ |
| 400 | char verify_alg[0]; |
| 401 | } __packed; |
| 402 | |
| 403 | struct p_rs_param_89 { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 404 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 405 | u32 rate; |
| 406 | /* protocol version 89: */ |
| 407 | char verify_alg[SHARED_SECRET_MAX]; |
| 408 | char csums_alg[SHARED_SECRET_MAX]; |
| 409 | } __packed; |
| 410 | |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 411 | struct p_rs_param_95 { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 412 | struct p_header head; |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 413 | u32 rate; |
| 414 | char verify_alg[SHARED_SECRET_MAX]; |
| 415 | char csums_alg[SHARED_SECRET_MAX]; |
| 416 | u32 c_plan_ahead; |
| 417 | u32 c_delay_target; |
| 418 | u32 c_fill_target; |
| 419 | u32 c_max_rate; |
| 420 | } __packed; |
| 421 | |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 422 | enum drbd_conn_flags { |
| 423 | CF_WANT_LOSE = 1, |
| 424 | CF_DRY_RUN = 2, |
| 425 | }; |
| 426 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 427 | struct p_protocol { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 428 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 429 | u32 protocol; |
| 430 | u32 after_sb_0p; |
| 431 | u32 after_sb_1p; |
| 432 | u32 after_sb_2p; |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 433 | u32 conn_flags; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 434 | u32 two_primaries; |
| 435 | |
| 436 | /* Since protocol version 87 and higher. */ |
| 437 | char integrity_alg[0]; |
| 438 | |
| 439 | } __packed; |
| 440 | |
| 441 | struct p_uuids { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 442 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 443 | u64 uuid[UI_EXTENDED_SIZE]; |
| 444 | } __packed; |
| 445 | |
| 446 | struct p_rs_uuid { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 447 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 448 | u64 uuid; |
| 449 | } __packed; |
| 450 | |
| 451 | struct p_sizes { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 452 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 453 | u64 d_size; /* size of disk */ |
| 454 | u64 u_size; /* user requested size */ |
| 455 | u64 c_size; /* current exported size */ |
Lars Ellenberg | 1816a2b | 2010-11-11 15:19:07 +0100 | [diff] [blame] | 456 | u32 max_bio_size; /* Maximal size of a BIO */ |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 457 | u16 queue_order_type; /* not yet implemented in DRBD*/ |
| 458 | u16 dds_flags; /* use enum dds_flags here. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 459 | } __packed; |
| 460 | |
| 461 | struct p_state { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 462 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 463 | u32 state; |
| 464 | } __packed; |
| 465 | |
| 466 | struct p_req_state { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 467 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 468 | u32 mask; |
| 469 | u32 val; |
| 470 | } __packed; |
| 471 | |
| 472 | struct p_req_state_reply { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 473 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 474 | u32 retcode; |
| 475 | } __packed; |
| 476 | |
| 477 | struct p_drbd06_param { |
| 478 | u64 size; |
| 479 | u32 state; |
| 480 | u32 blksize; |
| 481 | u32 protocol; |
| 482 | u32 version; |
| 483 | u32 gen_cnt[5]; |
| 484 | u32 bit_map_gen[5]; |
| 485 | } __packed; |
| 486 | |
| 487 | struct p_discard { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 488 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 489 | u64 block_id; |
| 490 | u32 seq_num; |
| 491 | u32 pad; |
| 492 | } __packed; |
| 493 | |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 494 | struct p_block_desc { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 495 | struct p_header head; |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 496 | u64 sector; |
| 497 | u32 blksize; |
| 498 | u32 pad; /* to multiple of 8 Byte */ |
| 499 | } __packed; |
| 500 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 501 | /* Valid values for the encoding field. |
| 502 | * Bump proto version when changing this. */ |
| 503 | enum drbd_bitmap_code { |
| 504 | /* RLE_VLI_Bytes = 0, |
| 505 | * and other bit variants had been defined during |
| 506 | * algorithm evaluation. */ |
| 507 | RLE_VLI_Bits = 2, |
| 508 | }; |
| 509 | |
| 510 | struct p_compressed_bm { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 511 | struct p_header head; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 512 | /* (encoding & 0x0f): actual encoding, see enum drbd_bitmap_code |
| 513 | * (encoding & 0x80): polarity (set/unset) of first runlength |
| 514 | * ((encoding >> 4) & 0x07): pad_bits, number of trailing zero bits |
| 515 | * used to pad up to head.length bytes |
| 516 | */ |
| 517 | u8 encoding; |
| 518 | |
| 519 | u8 code[0]; |
| 520 | } __packed; |
| 521 | |
Philipp Reisner | 0b70a13 | 2010-08-20 13:36:10 +0200 | [diff] [blame] | 522 | struct p_delay_probe93 { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 523 | struct p_header head; |
Philipp Reisner | 0b70a13 | 2010-08-20 13:36:10 +0200 | [diff] [blame] | 524 | u32 seq_num; /* sequence number to match the two probe packets */ |
| 525 | u32 offset; /* usecs the probe got sent after the reference time point */ |
Philipp Reisner | 0ced55a | 2010-04-30 15:26:20 +0200 | [diff] [blame] | 526 | } __packed; |
| 527 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 528 | /* DCBP: Drbd Compressed Bitmap Packet ... */ |
| 529 | static inline enum drbd_bitmap_code |
| 530 | DCBP_get_code(struct p_compressed_bm *p) |
| 531 | { |
| 532 | return (enum drbd_bitmap_code)(p->encoding & 0x0f); |
| 533 | } |
| 534 | |
| 535 | static inline void |
| 536 | DCBP_set_code(struct p_compressed_bm *p, enum drbd_bitmap_code code) |
| 537 | { |
| 538 | BUG_ON(code & ~0xf); |
| 539 | p->encoding = (p->encoding & ~0xf) | code; |
| 540 | } |
| 541 | |
| 542 | static inline int |
| 543 | DCBP_get_start(struct p_compressed_bm *p) |
| 544 | { |
| 545 | return (p->encoding & 0x80) != 0; |
| 546 | } |
| 547 | |
| 548 | static inline void |
| 549 | DCBP_set_start(struct p_compressed_bm *p, int set) |
| 550 | { |
| 551 | p->encoding = (p->encoding & ~0x80) | (set ? 0x80 : 0); |
| 552 | } |
| 553 | |
| 554 | static inline int |
| 555 | DCBP_get_pad_bits(struct p_compressed_bm *p) |
| 556 | { |
| 557 | return (p->encoding >> 4) & 0x7; |
| 558 | } |
| 559 | |
| 560 | static inline void |
| 561 | DCBP_set_pad_bits(struct p_compressed_bm *p, int n) |
| 562 | { |
| 563 | BUG_ON(n & ~0x7); |
| 564 | p->encoding = (p->encoding & (~0x7 << 4)) | (n << 4); |
| 565 | } |
| 566 | |
| 567 | /* one bitmap packet, including the p_header, |
| 568 | * should fit within one _architecture independend_ page. |
| 569 | * so we need to use the fixed size 4KiB page size |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 570 | * most architectures have used for a long time. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 571 | */ |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 572 | #define BM_PACKET_PAYLOAD_BYTES (4096 - sizeof(struct p_header)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 573 | #define BM_PACKET_WORDS (BM_PACKET_PAYLOAD_BYTES/sizeof(long)) |
| 574 | #define BM_PACKET_VLI_BYTES_MAX (4096 - sizeof(struct p_compressed_bm)) |
| 575 | #if (PAGE_SIZE < 4096) |
| 576 | /* drbd_send_bitmap / receive_bitmap would break horribly */ |
| 577 | #error "PAGE_SIZE too small" |
| 578 | #endif |
| 579 | |
| 580 | union p_polymorph { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 581 | struct p_header header; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 582 | struct p_handshake handshake; |
| 583 | struct p_data data; |
| 584 | struct p_block_ack block_ack; |
| 585 | struct p_barrier barrier; |
| 586 | struct p_barrier_ack barrier_ack; |
| 587 | struct p_rs_param_89 rs_param_89; |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 588 | struct p_rs_param_95 rs_param_95; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 589 | struct p_protocol protocol; |
| 590 | struct p_sizes sizes; |
| 591 | struct p_uuids uuids; |
| 592 | struct p_state state; |
| 593 | struct p_req_state req_state; |
| 594 | struct p_req_state_reply req_state_reply; |
| 595 | struct p_block_req block_req; |
Philipp Reisner | 02918be | 2010-08-20 14:35:10 +0200 | [diff] [blame] | 596 | struct p_delay_probe93 delay_probe93; |
| 597 | struct p_rs_uuid rs_uuid; |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 598 | struct p_block_desc block_desc; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 599 | } __packed; |
| 600 | |
| 601 | /**********************************************************************/ |
| 602 | enum drbd_thread_state { |
Andreas Gruenbacher | e77a0a5 | 2011-01-25 15:43:39 +0100 | [diff] [blame] | 603 | NONE, |
| 604 | RUNNING, |
| 605 | EXITING, |
| 606 | RESTARTING |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 607 | }; |
| 608 | |
| 609 | struct drbd_thread { |
| 610 | spinlock_t t_lock; |
| 611 | struct task_struct *task; |
| 612 | struct completion stop; |
| 613 | enum drbd_thread_state t_state; |
| 614 | int (*function) (struct drbd_thread *); |
| 615 | struct drbd_conf *mdev; |
| 616 | int reset_cpu_mask; |
| 617 | }; |
| 618 | |
| 619 | static inline enum drbd_thread_state get_t_state(struct drbd_thread *thi) |
| 620 | { |
| 621 | /* THINK testing the t_state seems to be uncritical in all cases |
| 622 | * (but thread_{start,stop}), so we can read it *without* the lock. |
| 623 | * --lge */ |
| 624 | |
| 625 | smp_rmb(); |
| 626 | return thi->t_state; |
| 627 | } |
| 628 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 629 | struct drbd_work; |
| 630 | typedef int (*drbd_work_cb)(struct drbd_conf *, struct drbd_work *, int cancel); |
| 631 | struct drbd_work { |
| 632 | struct list_head list; |
| 633 | drbd_work_cb cb; |
| 634 | }; |
| 635 | |
Andreas Gruenbacher | ace652a | 2011-01-03 17:09:58 +0100 | [diff] [blame] | 636 | #include "drbd_interval.h" |
| 637 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 638 | struct drbd_request { |
| 639 | struct drbd_work w; |
| 640 | struct drbd_conf *mdev; |
| 641 | |
| 642 | /* if local IO is not allowed, will be NULL. |
| 643 | * if local IO _is_ allowed, holds the locally submitted bio clone, |
| 644 | * or, after local IO completion, the ERR_PTR(error). |
| 645 | * see drbd_endio_pri(). */ |
| 646 | struct bio *private_bio; |
| 647 | |
Andreas Gruenbacher | ace652a | 2011-01-03 17:09:58 +0100 | [diff] [blame] | 648 | struct drbd_interval i; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 649 | unsigned int epoch; /* barrier_nr */ |
| 650 | |
| 651 | /* barrier_nr: used to check on "completion" whether this req was in |
| 652 | * the current epoch, and we therefore have to close it, |
| 653 | * starting a new epoch... |
| 654 | */ |
| 655 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 656 | struct list_head tl_requests; /* ring list in the transfer log */ |
| 657 | struct bio *master_bio; /* master bio pointer */ |
| 658 | unsigned long rq_state; /* see comments above _req_mod() */ |
| 659 | int seq_num; |
| 660 | unsigned long start_time; |
| 661 | }; |
| 662 | |
| 663 | struct drbd_tl_epoch { |
| 664 | struct drbd_work w; |
| 665 | struct list_head requests; /* requests before */ |
| 666 | struct drbd_tl_epoch *next; /* pointer to the next barrier */ |
| 667 | unsigned int br_number; /* the barriers identifier. */ |
Philipp Reisner | 7e602c0 | 2010-05-27 14:49:27 +0200 | [diff] [blame] | 668 | int n_writes; /* number of requests attached before this barrier */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 669 | }; |
| 670 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 671 | struct drbd_epoch { |
| 672 | struct list_head list; |
| 673 | unsigned int barrier_nr; |
| 674 | atomic_t epoch_size; /* increased on every request added. */ |
| 675 | atomic_t active; /* increased on every req. added, and dec on every finished. */ |
| 676 | unsigned long flags; |
| 677 | }; |
| 678 | |
| 679 | /* drbd_epoch flag bits */ |
| 680 | enum { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 681 | DE_HAVE_BARRIER_NUMBER, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 682 | }; |
| 683 | |
| 684 | enum epoch_event { |
| 685 | EV_PUT, |
| 686 | EV_GOT_BARRIER_NR, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 687 | EV_BECAME_LAST, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 688 | EV_CLEANUP = 32, /* used as flag */ |
| 689 | }; |
| 690 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 691 | struct drbd_wq_barrier { |
| 692 | struct drbd_work w; |
| 693 | struct completion done; |
| 694 | }; |
| 695 | |
| 696 | struct digest_info { |
| 697 | int digest_size; |
| 698 | void *digest; |
| 699 | }; |
| 700 | |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 701 | struct drbd_peer_request { |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 702 | struct drbd_work w; |
Philipp Reisner | 8571957 | 2010-07-21 10:20:17 +0200 | [diff] [blame] | 703 | struct drbd_epoch *epoch; /* for writes */ |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 704 | struct drbd_conf *mdev; |
| 705 | struct page *pages; |
| 706 | atomic_t pending_bios; |
Andreas Gruenbacher | 010f6e6 | 2011-01-14 20:59:35 +0100 | [diff] [blame] | 707 | struct drbd_interval i; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 708 | /* see comments on ee flag bits below */ |
| 709 | unsigned long flags; |
Philipp Reisner | 8571957 | 2010-07-21 10:20:17 +0200 | [diff] [blame] | 710 | union { |
| 711 | u64 block_id; |
| 712 | struct digest_info *digest; |
| 713 | }; |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 714 | }; |
| 715 | |
| 716 | /* ee flag bits. |
| 717 | * While corresponding bios are in flight, the only modification will be |
| 718 | * set_bit WAS_ERROR, which has to be atomic. |
| 719 | * If no bios are in flight yet, or all have been completed, |
| 720 | * non-atomic modification to ee->flags is ok. |
| 721 | */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 722 | enum { |
| 723 | __EE_CALL_AL_COMPLETE_IO, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 724 | __EE_MAY_SET_IN_SYNC, |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 725 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 726 | /* In case a barrier failed, |
| 727 | * we need to resubmit without the barrier flag. */ |
| 728 | __EE_RESUBMITTED, |
| 729 | |
Andreas Gruenbacher | 6c852be | 2011-02-04 15:38:52 +0100 | [diff] [blame^] | 730 | /* we may have several bios per peer request. |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 731 | * if any of those fail, we set this flag atomically |
| 732 | * from the endio callback */ |
| 733 | __EE_WAS_ERROR, |
Lars Ellenberg | c36c3ce | 2010-08-11 20:42:55 +0200 | [diff] [blame] | 734 | |
| 735 | /* This ee has a pointer to a digest instead of a block id */ |
| 736 | __EE_HAS_DIGEST, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 737 | }; |
| 738 | #define EE_CALL_AL_COMPLETE_IO (1<<__EE_CALL_AL_COMPLETE_IO) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 739 | #define EE_MAY_SET_IN_SYNC (1<<__EE_MAY_SET_IN_SYNC) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 740 | #define EE_RESUBMITTED (1<<__EE_RESUBMITTED) |
| 741 | #define EE_WAS_ERROR (1<<__EE_WAS_ERROR) |
Lars Ellenberg | c36c3ce | 2010-08-11 20:42:55 +0200 | [diff] [blame] | 742 | #define EE_HAS_DIGEST (1<<__EE_HAS_DIGEST) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 743 | |
| 744 | /* global flag bits */ |
| 745 | enum { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 746 | CREATE_BARRIER, /* next P_DATA is preceded by a P_BARRIER */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 747 | SIGNAL_ASENDER, /* whether asender wants to be interrupted */ |
| 748 | SEND_PING, /* whether asender should send a ping asap */ |
| 749 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 750 | UNPLUG_QUEUED, /* only relevant with kernel 2.4 */ |
| 751 | UNPLUG_REMOTE, /* sending a "UnplugRemote" could help */ |
| 752 | MD_DIRTY, /* current uuids and flags not yet on disk */ |
| 753 | DISCARD_CONCURRENT, /* Set on one node, cleared on the peer! */ |
| 754 | USE_DEGR_WFC_T, /* degr-wfc-timeout instead of wfc-timeout. */ |
| 755 | CLUSTER_ST_CHANGE, /* Cluster wide state change going on... */ |
| 756 | CL_ST_CHG_SUCCESS, |
| 757 | CL_ST_CHG_FAIL, |
| 758 | CRASHED_PRIMARY, /* This node was a crashed primary. |
| 759 | * Gets cleared when the state.conn |
| 760 | * goes into C_CONNECTED state. */ |
Lars Ellenberg | 19f843a | 2010-12-15 08:59:11 +0100 | [diff] [blame] | 761 | NO_BARRIER_SUPP, /* underlying block device doesn't implement barriers */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 762 | CONSIDER_RESYNC, |
| 763 | |
Philipp Reisner | a8a4e51 | 2010-08-25 10:21:04 +0200 | [diff] [blame] | 764 | MD_NO_FUA, /* Users wants us to not use FUA/FLUSH on meta data dev */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 765 | SUSPEND_IO, /* suspend application io */ |
| 766 | BITMAP_IO, /* suspend application io; |
| 767 | once no more io in flight, start bitmap io */ |
| 768 | BITMAP_IO_QUEUED, /* Started bitmap IO */ |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 769 | GO_DISKLESS, /* Disk is being detached, on io-error or admin request. */ |
| 770 | WAS_IO_ERROR, /* Local disk failed returned IO error */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 771 | RESYNC_AFTER_NEG, /* Resync after online grow after the attach&negotiate finished. */ |
| 772 | NET_CONGESTED, /* The data socket is congested */ |
| 773 | |
| 774 | CONFIG_PENDING, /* serialization of (re)configuration requests. |
| 775 | * if set, also prevents the device from dying */ |
| 776 | DEVICE_DYING, /* device became unconfigured, |
| 777 | * but worker thread is still handling the cleanup. |
| 778 | * reconfiguring (nl_disk_conf, nl_net_conf) is dissalowed, |
| 779 | * while this is set. */ |
| 780 | RESIZE_PENDING, /* Size change detected locally, waiting for the response from |
| 781 | * the peer, if it changed there as well. */ |
Philipp Reisner | cf14c2e | 2010-02-02 21:03:50 +0100 | [diff] [blame] | 782 | CONN_DRY_RUN, /* Expect disconnect after resync handshake. */ |
Philipp Reisner | 309d160 | 2010-03-02 15:03:44 +0100 | [diff] [blame] | 783 | GOT_PING_ACK, /* set when we receive a ping_ack packet, misc wait gets woken */ |
Philipp Reisner | 43a5182 | 2010-06-11 11:26:34 +0200 | [diff] [blame] | 784 | NEW_CUR_UUID, /* Create new current UUID when thawing IO */ |
Philipp Reisner | 0778286 | 2010-08-31 12:00:50 +0200 | [diff] [blame] | 785 | AL_SUSPENDED, /* Activity logging is currently suspended. */ |
Philipp Reisner | 370a43e | 2011-01-14 16:03:11 +0100 | [diff] [blame] | 786 | AHEAD_TO_SYNC_SOURCE, /* Ahead -> SyncSource queued */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 787 | }; |
| 788 | |
| 789 | struct drbd_bitmap; /* opaque for drbd_conf */ |
| 790 | |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 791 | /* definition of bits in bm_flags to be used in drbd_bm_lock |
| 792 | * and drbd_bitmap_io and friends. */ |
| 793 | enum bm_flag { |
| 794 | /* do we need to kfree, or vfree bm_pages? */ |
| 795 | BM_P_VMALLOCED = 0x10000, /* internal use only, will be masked out */ |
| 796 | |
| 797 | /* currently locked for bulk operation */ |
| 798 | BM_LOCKED_MASK = 0x7, |
| 799 | |
| 800 | /* in detail, that is: */ |
| 801 | BM_DONT_CLEAR = 0x1, |
| 802 | BM_DONT_SET = 0x2, |
| 803 | BM_DONT_TEST = 0x4, |
| 804 | |
| 805 | /* (test bit, count bit) allowed (common case) */ |
| 806 | BM_LOCKED_TEST_ALLOWED = 0x3, |
| 807 | |
| 808 | /* testing bits, as well as setting new bits allowed, but clearing bits |
| 809 | * would be unexpected. Used during bitmap receive. Setting new bits |
| 810 | * requires sending of "out-of-sync" information, though. */ |
| 811 | BM_LOCKED_SET_ALLOWED = 0x1, |
| 812 | |
| 813 | /* clear is not expected while bitmap is locked for bulk operation */ |
| 814 | }; |
| 815 | |
| 816 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 817 | /* TODO sort members for performance |
| 818 | * MAYBE group them further */ |
| 819 | |
| 820 | /* THINK maybe we actually want to use the default "event/%s" worker threads |
| 821 | * or similar in linux 2.6, which uses per cpu data and threads. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 822 | */ |
| 823 | struct drbd_work_queue { |
| 824 | struct list_head q; |
| 825 | struct semaphore s; /* producers up it, worker down()s it */ |
| 826 | spinlock_t q_lock; /* to protect the list. */ |
| 827 | }; |
| 828 | |
| 829 | struct drbd_socket { |
| 830 | struct drbd_work_queue work; |
| 831 | struct mutex mutex; |
| 832 | struct socket *socket; |
| 833 | /* this way we get our |
| 834 | * send/receive buffers off the stack */ |
| 835 | union p_polymorph sbuf; |
| 836 | union p_polymorph rbuf; |
| 837 | }; |
| 838 | |
| 839 | struct drbd_md { |
| 840 | u64 md_offset; /* sector offset to 'super' block */ |
| 841 | |
| 842 | u64 la_size_sect; /* last agreed size, unit sectors */ |
| 843 | u64 uuid[UI_SIZE]; |
| 844 | u64 device_uuid; |
| 845 | u32 flags; |
| 846 | u32 md_size_sect; |
| 847 | |
| 848 | s32 al_offset; /* signed relative sector offset to al area */ |
| 849 | s32 bm_offset; /* signed relative sector offset to bitmap */ |
| 850 | |
| 851 | /* u32 al_nr_extents; important for restoring the AL |
| 852 | * is stored into sync_conf.al_extents, which in turn |
| 853 | * gets applied to act_log->nr_elements |
| 854 | */ |
| 855 | }; |
| 856 | |
| 857 | /* for sync_conf and other types... */ |
| 858 | #define NL_PACKET(name, number, fields) struct name { fields }; |
| 859 | #define NL_INTEGER(pn,pr,member) int member; |
| 860 | #define NL_INT64(pn,pr,member) __u64 member; |
| 861 | #define NL_BIT(pn,pr,member) unsigned member:1; |
| 862 | #define NL_STRING(pn,pr,member,len) unsigned char member[len]; int member ## _len; |
| 863 | #include "linux/drbd_nl.h" |
| 864 | |
| 865 | struct drbd_backing_dev { |
| 866 | struct block_device *backing_bdev; |
| 867 | struct block_device *md_bdev; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 868 | struct drbd_md md; |
| 869 | struct disk_conf dc; /* The user provided config... */ |
| 870 | sector_t known_size; /* last known size of that backing device */ |
| 871 | }; |
| 872 | |
| 873 | struct drbd_md_io { |
| 874 | struct drbd_conf *mdev; |
| 875 | struct completion event; |
| 876 | int error; |
| 877 | }; |
| 878 | |
| 879 | struct bm_io_work { |
| 880 | struct drbd_work w; |
| 881 | char *why; |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 882 | enum bm_flag flags; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 883 | int (*io_fn)(struct drbd_conf *mdev); |
| 884 | void (*done)(struct drbd_conf *mdev, int rv); |
| 885 | }; |
| 886 | |
| 887 | enum write_ordering_e { |
| 888 | WO_none, |
| 889 | WO_drain_io, |
| 890 | WO_bdev_flush, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 891 | }; |
| 892 | |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 893 | struct fifo_buffer { |
| 894 | int *values; |
| 895 | unsigned int head_index; |
| 896 | unsigned int size; |
| 897 | }; |
| 898 | |
Philipp Reisner | 2111438 | 2011-01-19 12:26:59 +0100 | [diff] [blame] | 899 | struct drbd_tconn { /* is a resource from the config file */ |
| 900 | char *name; /* Resource name */ |
| 901 | struct list_head all_tconn; /* List of all drbd_tconn, prot by global_state_lock */ |
| 902 | struct drbd_conf *volume0; /* TODO: Remove me again */ |
| 903 | |
| 904 | struct net_conf *net_conf; /* protected by get_net_conf() and put_net_conf() */ |
Philipp Reisner | b2fb6dbe | 2011-01-19 13:48:44 +0100 | [diff] [blame] | 905 | atomic_t net_cnt; /* Users of net_conf */ |
| 906 | wait_queue_head_t net_cnt_wait; |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 907 | |
| 908 | struct drbd_socket data; /* data/barrier/cstate/parameter packets */ |
| 909 | struct drbd_socket meta; /* ping/ack (metadata) packets */ |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 910 | int agreed_pro_version; /* actually used protocol version */ |
| 911 | unsigned long last_received; /* in jiffies, either socket */ |
| 912 | unsigned int ko_count; |
Philipp Reisner | e6b3ea8 | 2011-01-19 14:02:01 +0100 | [diff] [blame] | 913 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 914 | spinlock_t req_lock; |
| 915 | struct drbd_tl_epoch *unused_spare_tle; /* for pre-allocation */ |
| 916 | struct drbd_tl_epoch *newest_tle; |
| 917 | struct drbd_tl_epoch *oldest_tle; |
| 918 | struct list_head out_of_sequence_requests; |
| 919 | |
Philipp Reisner | a063845 | 2011-01-19 14:31:32 +0100 | [diff] [blame] | 920 | struct crypto_hash *cram_hmac_tfm; |
| 921 | struct crypto_hash *integrity_w_tfm; /* to be used by the worker thread */ |
| 922 | struct crypto_hash *integrity_r_tfm; /* to be used by the receiver thread */ |
| 923 | void *int_dig_out; |
| 924 | void *int_dig_in; |
| 925 | void *int_dig_vv; |
| 926 | |
Philipp Reisner | e6b3ea8 | 2011-01-19 14:02:01 +0100 | [diff] [blame] | 927 | struct drbd_thread receiver; |
| 928 | struct drbd_thread worker; |
| 929 | struct drbd_thread asender; |
Philipp Reisner | 2111438 | 2011-01-19 12:26:59 +0100 | [diff] [blame] | 930 | }; |
| 931 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 932 | struct drbd_conf { |
Philipp Reisner | 2111438 | 2011-01-19 12:26:59 +0100 | [diff] [blame] | 933 | struct drbd_tconn *tconn; |
| 934 | int vnr; /* volume number within the connection */ |
| 935 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 936 | /* things that are stored as / read from meta data on disk */ |
| 937 | unsigned long flags; |
| 938 | |
| 939 | /* configured by drbdsetup */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 940 | struct syncer_conf sync_conf; |
| 941 | struct drbd_backing_dev *ldev __protected_by(local); |
| 942 | |
| 943 | sector_t p_size; /* partner's disk size */ |
| 944 | struct request_queue *rq_queue; |
| 945 | struct block_device *this_bdev; |
| 946 | struct gendisk *vdisk; |
| 947 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 948 | struct drbd_work resync_work, |
| 949 | unplug_work, |
Lars Ellenberg | e9e6f3e | 2010-09-14 20:26:27 +0200 | [diff] [blame] | 950 | go_diskless, |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 951 | md_sync_work, |
| 952 | start_resync_work; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 953 | struct timer_list resync_timer; |
| 954 | struct timer_list md_sync_timer; |
Philipp Reisner | 370a43e | 2011-01-14 16:03:11 +0100 | [diff] [blame] | 955 | struct timer_list start_resync_timer; |
Philipp Reisner | 7fde2be | 2011-03-01 11:08:28 +0100 | [diff] [blame] | 956 | struct timer_list request_timer; |
Lars Ellenberg | ee15b03 | 2010-09-03 10:00:09 +0200 | [diff] [blame] | 957 | #ifdef DRBD_DEBUG_MD_SYNC |
| 958 | struct { |
| 959 | unsigned int line; |
| 960 | const char* func; |
| 961 | } last_md_mark_dirty; |
| 962 | #endif |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 963 | |
| 964 | /* Used after attach while negotiating new disk state. */ |
| 965 | union drbd_state new_state_tmp; |
| 966 | |
| 967 | union drbd_state state; |
| 968 | wait_queue_head_t misc_wait; |
| 969 | wait_queue_head_t state_wait; /* upon each state change. */ |
| 970 | unsigned int send_cnt; |
| 971 | unsigned int recv_cnt; |
| 972 | unsigned int read_cnt; |
| 973 | unsigned int writ_cnt; |
| 974 | unsigned int al_writ_cnt; |
| 975 | unsigned int bm_writ_cnt; |
| 976 | atomic_t ap_bio_cnt; /* Requests we need to complete */ |
| 977 | atomic_t ap_pending_cnt; /* AP data packets on the wire, ack expected */ |
| 978 | atomic_t rs_pending_cnt; /* RS request/data packets on the wire */ |
| 979 | atomic_t unacked_cnt; /* Need to send replys for */ |
| 980 | atomic_t local_cnt; /* Waiting for local completion */ |
Philipp Reisner | b2fb6dbe | 2011-01-19 13:48:44 +0100 | [diff] [blame] | 981 | |
Andreas Gruenbacher | dac1389 | 2011-01-21 17:18:39 +0100 | [diff] [blame] | 982 | /* Interval tree of pending local requests */ |
| 983 | struct rb_root read_requests; |
Andreas Gruenbacher | de69671 | 2011-01-20 15:00:24 +0100 | [diff] [blame] | 984 | struct rb_root write_requests; |
| 985 | |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 986 | /* blocks to resync in this run [unit BM_BLOCK_SIZE] */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 987 | unsigned long rs_total; |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 988 | /* number of resync blocks that failed in this run */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 989 | unsigned long rs_failed; |
| 990 | /* Syncer's start time [unit jiffies] */ |
| 991 | unsigned long rs_start; |
| 992 | /* cumulated time in PausedSyncX state [unit jiffies] */ |
| 993 | unsigned long rs_paused; |
Lars Ellenberg | 1d7734a | 2010-08-11 21:21:50 +0200 | [diff] [blame] | 994 | /* skipped because csum was equal [unit BM_BLOCK_SIZE] */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 995 | unsigned long rs_same_csum; |
Lars Ellenberg | 1d7734a | 2010-08-11 21:21:50 +0200 | [diff] [blame] | 996 | #define DRBD_SYNC_MARKS 8 |
| 997 | #define DRBD_SYNC_MARK_STEP (3*HZ) |
| 998 | /* block not up-to-date at mark [unit BM_BLOCK_SIZE] */ |
| 999 | unsigned long rs_mark_left[DRBD_SYNC_MARKS]; |
| 1000 | /* marks's time [unit jiffies] */ |
| 1001 | unsigned long rs_mark_time[DRBD_SYNC_MARKS]; |
| 1002 | /* current index into rs_mark_{left,time} */ |
| 1003 | int rs_last_mark; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1004 | |
| 1005 | /* where does the admin want us to start? (sector) */ |
| 1006 | sector_t ov_start_sector; |
| 1007 | /* where are we now? (sector) */ |
| 1008 | sector_t ov_position; |
| 1009 | /* Start sector of out of sync range (to merge printk reporting). */ |
| 1010 | sector_t ov_last_oos_start; |
| 1011 | /* size of out-of-sync range in sectors. */ |
| 1012 | sector_t ov_last_oos_size; |
| 1013 | unsigned long ov_left; /* in bits */ |
| 1014 | struct crypto_hash *csums_tfm; |
| 1015 | struct crypto_hash *verify_tfm; |
| 1016 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1017 | struct drbd_bitmap *bitmap; |
| 1018 | unsigned long bm_resync_fo; /* bit offset for drbd_bm_find_next */ |
| 1019 | |
| 1020 | /* Used to track operations of resync... */ |
| 1021 | struct lru_cache *resync; |
| 1022 | /* Number of locked elements in resync LRU */ |
| 1023 | unsigned int resync_locked; |
| 1024 | /* resync extent number waiting for application requests */ |
| 1025 | unsigned int resync_wenr; |
| 1026 | |
| 1027 | int open_cnt; |
| 1028 | u64 *p_uuid; |
| 1029 | struct drbd_epoch *current_epoch; |
| 1030 | spinlock_t epoch_lock; |
| 1031 | unsigned int epochs; |
| 1032 | enum write_ordering_e write_ordering; |
Philipp Reisner | 8571957 | 2010-07-21 10:20:17 +0200 | [diff] [blame] | 1033 | struct list_head active_ee; /* IO in progress (P_DATA gets written to disk) */ |
| 1034 | struct list_head sync_ee; /* IO in progress (P_RS_DATA_REPLY gets written to disk) */ |
Andreas Gruenbacher | 18b75d7 | 2011-02-04 15:36:22 +0100 | [diff] [blame] | 1035 | struct list_head done_ee; /* need to send P_WRITE_ACK */ |
| 1036 | struct list_head read_ee; /* [RS]P_DATA_REQUEST being read */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1037 | struct list_head net_ee; /* zero-copy network send in progress */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1038 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1039 | int next_barrier_nr; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1040 | struct list_head resync_reads; |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 1041 | atomic_t pp_in_use; /* allocated from page pool */ |
| 1042 | atomic_t pp_in_use_by_net; /* sendpage()d, still referenced by tcp */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1043 | wait_queue_head_t ee_wait; |
| 1044 | struct page *md_io_page; /* one page buffer for md_io */ |
| 1045 | struct page *md_io_tmpp; /* for logical_block_size != 512 */ |
| 1046 | struct mutex md_io_mutex; /* protects the md_io_buffer */ |
| 1047 | spinlock_t al_lock; |
| 1048 | wait_queue_head_t al_wait; |
| 1049 | struct lru_cache *act_log; /* activity log */ |
| 1050 | unsigned int al_tr_number; |
| 1051 | int al_tr_cycle; |
| 1052 | int al_tr_pos; /* position of the next transaction in the journal */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1053 | wait_queue_head_t seq_wait; |
| 1054 | atomic_t packet_seq; |
| 1055 | unsigned int peer_seq; |
| 1056 | spinlock_t peer_seq_lock; |
| 1057 | unsigned int minor; |
| 1058 | unsigned long comm_bm_set; /* communicated number of set bits. */ |
| 1059 | cpumask_var_t cpu_mask; |
| 1060 | struct bm_io_work bm_io_work; |
| 1061 | u64 ed_uuid; /* UUID of the exposed data */ |
| 1062 | struct mutex state_mutex; |
| 1063 | char congestion_reason; /* Why we where congested... */ |
Lars Ellenberg | 1d7734a | 2010-08-11 21:21:50 +0200 | [diff] [blame] | 1064 | atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */ |
| 1065 | atomic_t rs_sect_ev; /* for submitted resync data rate, both */ |
| 1066 | int rs_last_sect_ev; /* counter to compare with */ |
| 1067 | int rs_last_events; /* counter of read or write "events" (unit sectors) |
| 1068 | * on the lower level device when we last looked. */ |
| 1069 | int c_sync_rate; /* current resync rate after syncer throttle magic */ |
Philipp Reisner | 778f271 | 2010-07-06 11:14:00 +0200 | [diff] [blame] | 1070 | struct fifo_buffer rs_plan_s; /* correction values of resync planer */ |
| 1071 | int rs_in_flight; /* resync sectors in flight (to proxy, in proxy and from proxy) */ |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1072 | int rs_planed; /* resync sectors already planned */ |
Philipp Reisner | 759fbdf | 2010-10-26 16:02:27 +0200 | [diff] [blame] | 1073 | atomic_t ap_in_flight; /* App sectors in flight (waiting for ack) */ |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1074 | int peer_max_bio_size; |
| 1075 | int local_max_bio_size; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1076 | }; |
| 1077 | |
| 1078 | static inline struct drbd_conf *minor_to_mdev(unsigned int minor) |
| 1079 | { |
| 1080 | struct drbd_conf *mdev; |
| 1081 | |
| 1082 | mdev = minor < minor_count ? minor_table[minor] : NULL; |
| 1083 | |
| 1084 | return mdev; |
| 1085 | } |
| 1086 | |
| 1087 | static inline unsigned int mdev_to_minor(struct drbd_conf *mdev) |
| 1088 | { |
| 1089 | return mdev->minor; |
| 1090 | } |
| 1091 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1092 | /* returns 1 if it was successful, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1093 | * returns 0 if there was no data socket. |
| 1094 | * so wherever you are going to use the data.socket, e.g. do |
| 1095 | * if (!drbd_get_data_sock(mdev)) |
| 1096 | * return 0; |
| 1097 | * CODE(); |
| 1098 | * drbd_put_data_sock(mdev); |
| 1099 | */ |
| 1100 | static inline int drbd_get_data_sock(struct drbd_conf *mdev) |
| 1101 | { |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 1102 | mutex_lock(&mdev->tconn->data.mutex); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1103 | /* drbd_disconnect() could have called drbd_free_sock() |
| 1104 | * while we were waiting in down()... */ |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 1105 | if (unlikely(mdev->tconn->data.socket == NULL)) { |
| 1106 | mutex_unlock(&mdev->tconn->data.mutex); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1107 | return 0; |
| 1108 | } |
| 1109 | return 1; |
| 1110 | } |
| 1111 | |
| 1112 | static inline void drbd_put_data_sock(struct drbd_conf *mdev) |
| 1113 | { |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 1114 | mutex_unlock(&mdev->tconn->data.mutex); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | /* |
| 1118 | * function declarations |
| 1119 | *************************/ |
| 1120 | |
| 1121 | /* drbd_main.c */ |
| 1122 | |
| 1123 | enum chg_state_flags { |
| 1124 | CS_HARD = 1, |
| 1125 | CS_VERBOSE = 2, |
| 1126 | CS_WAIT_COMPLETE = 4, |
| 1127 | CS_SERIALIZE = 8, |
| 1128 | CS_ORDERED = CS_WAIT_COMPLETE + CS_SERIALIZE, |
| 1129 | }; |
| 1130 | |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 1131 | enum dds_flags { |
| 1132 | DDSF_FORCED = 1, |
| 1133 | DDSF_NO_RESYNC = 2, /* Do not run a resync for the new space */ |
| 1134 | }; |
| 1135 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1136 | extern void drbd_init_set_defaults(struct drbd_conf *mdev); |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 1137 | extern enum drbd_state_rv drbd_change_state(struct drbd_conf *mdev, |
| 1138 | enum chg_state_flags f, |
| 1139 | union drbd_state mask, |
| 1140 | union drbd_state val); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1141 | extern void drbd_force_state(struct drbd_conf *, union drbd_state, |
| 1142 | union drbd_state); |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 1143 | extern enum drbd_state_rv _drbd_request_state(struct drbd_conf *, |
| 1144 | union drbd_state, |
| 1145 | union drbd_state, |
| 1146 | enum chg_state_flags); |
| 1147 | extern enum drbd_state_rv __drbd_set_state(struct drbd_conf *, union drbd_state, |
| 1148 | enum chg_state_flags, |
| 1149 | struct completion *done); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1150 | extern void print_st_err(struct drbd_conf *, union drbd_state, |
| 1151 | union drbd_state, int); |
| 1152 | extern int drbd_thread_start(struct drbd_thread *thi); |
| 1153 | extern void _drbd_thread_stop(struct drbd_thread *thi, int restart, int wait); |
| 1154 | #ifdef CONFIG_SMP |
| 1155 | extern void drbd_thread_current_set_cpu(struct drbd_conf *mdev); |
| 1156 | extern void drbd_calc_cpu_mask(struct drbd_conf *mdev); |
| 1157 | #else |
| 1158 | #define drbd_thread_current_set_cpu(A) ({}) |
| 1159 | #define drbd_calc_cpu_mask(A) ({}) |
| 1160 | #endif |
| 1161 | extern void drbd_free_resources(struct drbd_conf *mdev); |
| 1162 | extern void tl_release(struct drbd_conf *mdev, unsigned int barrier_nr, |
| 1163 | unsigned int set_size); |
| 1164 | extern void tl_clear(struct drbd_conf *mdev); |
| 1165 | extern void _tl_add_barrier(struct drbd_conf *, struct drbd_tl_epoch *); |
| 1166 | extern void drbd_free_sock(struct drbd_conf *mdev); |
| 1167 | extern int drbd_send(struct drbd_conf *mdev, struct socket *sock, |
| 1168 | void *buf, size_t size, unsigned msg_flags); |
| 1169 | extern int drbd_send_protocol(struct drbd_conf *mdev); |
| 1170 | extern int drbd_send_uuids(struct drbd_conf *mdev); |
| 1171 | extern int drbd_send_uuids_skip_initial_sync(struct drbd_conf *mdev); |
Lars Ellenberg | 5a22db8 | 2010-12-17 21:14:23 +0100 | [diff] [blame] | 1172 | extern int drbd_gen_and_send_sync_uuid(struct drbd_conf *mdev); |
Philipp Reisner | e89b591 | 2010-03-24 17:11:33 +0100 | [diff] [blame] | 1173 | extern int drbd_send_sizes(struct drbd_conf *mdev, int trigger_reply, enum dds_flags flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1174 | extern int _drbd_send_state(struct drbd_conf *mdev); |
| 1175 | extern int drbd_send_state(struct drbd_conf *mdev); |
| 1176 | extern int _drbd_send_cmd(struct drbd_conf *mdev, struct socket *sock, |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 1177 | enum drbd_packet cmd, struct p_header *h, |
| 1178 | size_t size, unsigned msg_flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1179 | #define USE_DATA_SOCKET 1 |
| 1180 | #define USE_META_SOCKET 0 |
| 1181 | extern int drbd_send_cmd(struct drbd_conf *mdev, int use_data_socket, |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 1182 | enum drbd_packet cmd, struct p_header *h, size_t size); |
| 1183 | extern int drbd_send_cmd2(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 1184 | char *data, size_t size); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1185 | extern int drbd_send_sync_param(struct drbd_conf *mdev, struct syncer_conf *sc); |
| 1186 | extern int drbd_send_b_ack(struct drbd_conf *mdev, u32 barrier_nr, |
| 1187 | u32 set_size); |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1188 | extern int drbd_send_ack(struct drbd_conf *, enum drbd_packet, |
| 1189 | struct drbd_peer_request *); |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 1190 | extern int drbd_send_ack_rp(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 1191 | struct p_block_req *rp); |
| 1192 | extern int drbd_send_ack_dp(struct drbd_conf *mdev, enum drbd_packet cmd, |
| 1193 | struct p_data *dp, int data_size); |
| 1194 | extern int drbd_send_ack_ex(struct drbd_conf *mdev, enum drbd_packet cmd, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1195 | sector_t sector, int blksize, u64 block_id); |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 1196 | extern int drbd_send_oos(struct drbd_conf *mdev, struct drbd_request *req); |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1197 | extern int drbd_send_block(struct drbd_conf *, enum drbd_packet, |
| 1198 | struct drbd_peer_request *); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1199 | extern int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1200 | extern int drbd_send_drequest(struct drbd_conf *mdev, int cmd, |
| 1201 | sector_t sector, int size, u64 block_id); |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 1202 | extern int drbd_send_drequest_csum(struct drbd_conf *mdev, sector_t sector, |
| 1203 | int size, void *digest, int digest_size, |
| 1204 | enum drbd_packet cmd); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1205 | extern int drbd_send_ov_request(struct drbd_conf *mdev,sector_t sector,int size); |
| 1206 | |
| 1207 | extern int drbd_send_bitmap(struct drbd_conf *mdev); |
| 1208 | extern int _drbd_send_bitmap(struct drbd_conf *mdev); |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 1209 | extern int drbd_send_sr_reply(struct drbd_conf *mdev, enum drbd_state_rv retcode); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1210 | extern void drbd_free_bc(struct drbd_backing_dev *ldev); |
| 1211 | extern void drbd_mdev_cleanup(struct drbd_conf *mdev); |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 1212 | void drbd_print_uuids(struct drbd_conf *mdev, const char *text); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1213 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1214 | extern void drbd_md_sync(struct drbd_conf *mdev); |
| 1215 | extern int drbd_md_read(struct drbd_conf *mdev, struct drbd_backing_dev *bdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1216 | extern void drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local); |
| 1217 | extern void _drbd_uuid_set(struct drbd_conf *mdev, int idx, u64 val) __must_hold(local); |
| 1218 | extern void drbd_uuid_new_current(struct drbd_conf *mdev) __must_hold(local); |
| 1219 | extern void _drbd_uuid_new_current(struct drbd_conf *mdev) __must_hold(local); |
| 1220 | extern void drbd_uuid_set_bm(struct drbd_conf *mdev, u64 val) __must_hold(local); |
| 1221 | extern void drbd_md_set_flag(struct drbd_conf *mdev, int flags) __must_hold(local); |
| 1222 | extern void drbd_md_clear_flag(struct drbd_conf *mdev, int flags)__must_hold(local); |
| 1223 | extern int drbd_md_test_flag(struct drbd_backing_dev *, int); |
Lars Ellenberg | ee15b03 | 2010-09-03 10:00:09 +0200 | [diff] [blame] | 1224 | #ifndef DRBD_DEBUG_MD_SYNC |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1225 | extern void drbd_md_mark_dirty(struct drbd_conf *mdev); |
Lars Ellenberg | ee15b03 | 2010-09-03 10:00:09 +0200 | [diff] [blame] | 1226 | #else |
| 1227 | #define drbd_md_mark_dirty(m) drbd_md_mark_dirty_(m, __LINE__ , __func__ ) |
| 1228 | extern void drbd_md_mark_dirty_(struct drbd_conf *mdev, |
| 1229 | unsigned int line, const char *func); |
| 1230 | #endif |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1231 | extern void drbd_queue_bitmap_io(struct drbd_conf *mdev, |
| 1232 | int (*io_fn)(struct drbd_conf *), |
| 1233 | void (*done)(struct drbd_conf *, int), |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 1234 | char *why, enum bm_flag flags); |
| 1235 | extern int drbd_bitmap_io(struct drbd_conf *mdev, |
| 1236 | int (*io_fn)(struct drbd_conf *), |
| 1237 | char *why, enum bm_flag flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1238 | extern int drbd_bmio_set_n_write(struct drbd_conf *mdev); |
| 1239 | extern int drbd_bmio_clear_n_write(struct drbd_conf *mdev); |
Lars Ellenberg | e9e6f3e | 2010-09-14 20:26:27 +0200 | [diff] [blame] | 1240 | extern void drbd_go_diskless(struct drbd_conf *mdev); |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 1241 | extern void drbd_ldev_destroy(struct drbd_conf *mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1242 | |
| 1243 | |
| 1244 | /* Meta data layout |
| 1245 | We reserve a 128MB Block (4k aligned) |
| 1246 | * either at the end of the backing device |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1247 | * or on a separate meta data device. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1248 | |
| 1249 | #define MD_RESERVED_SECT (128LU << 11) /* 128 MB, unit sectors */ |
| 1250 | /* The following numbers are sectors */ |
| 1251 | #define MD_AL_OFFSET 8 /* 8 Sectors after start of meta area */ |
| 1252 | #define MD_AL_MAX_SIZE 64 /* = 32 kb LOG ~ 3776 extents ~ 14 GB Storage */ |
| 1253 | /* Allows up to about 3.8TB */ |
| 1254 | #define MD_BM_OFFSET (MD_AL_OFFSET + MD_AL_MAX_SIZE) |
| 1255 | |
| 1256 | /* Since the smalles IO unit is usually 512 byte */ |
| 1257 | #define MD_SECTOR_SHIFT 9 |
| 1258 | #define MD_SECTOR_SIZE (1<<MD_SECTOR_SHIFT) |
| 1259 | |
| 1260 | /* activity log */ |
| 1261 | #define AL_EXTENTS_PT ((MD_SECTOR_SIZE-12)/8-1) /* 61 ; Extents per 512B sector */ |
| 1262 | #define AL_EXTENT_SHIFT 22 /* One extent represents 4M Storage */ |
| 1263 | #define AL_EXTENT_SIZE (1<<AL_EXTENT_SHIFT) |
| 1264 | |
| 1265 | #if BITS_PER_LONG == 32 |
| 1266 | #define LN2_BPL 5 |
| 1267 | #define cpu_to_lel(A) cpu_to_le32(A) |
| 1268 | #define lel_to_cpu(A) le32_to_cpu(A) |
| 1269 | #elif BITS_PER_LONG == 64 |
| 1270 | #define LN2_BPL 6 |
| 1271 | #define cpu_to_lel(A) cpu_to_le64(A) |
| 1272 | #define lel_to_cpu(A) le64_to_cpu(A) |
| 1273 | #else |
| 1274 | #error "LN2 of BITS_PER_LONG unknown!" |
| 1275 | #endif |
| 1276 | |
| 1277 | /* resync bitmap */ |
| 1278 | /* 16MB sized 'bitmap extent' to track syncer usage */ |
| 1279 | struct bm_extent { |
| 1280 | int rs_left; /* number of bits set (out of sync) in this extent. */ |
| 1281 | int rs_failed; /* number of failed resync requests in this extent. */ |
| 1282 | unsigned long flags; |
| 1283 | struct lc_element lce; |
| 1284 | }; |
| 1285 | |
| 1286 | #define BME_NO_WRITES 0 /* bm_extent.flags: no more requests on this one! */ |
| 1287 | #define BME_LOCKED 1 /* bm_extent.flags: syncer active on this one. */ |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 1288 | #define BME_PRIORITY 2 /* finish resync IO on this extent ASAP! App IO waiting! */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1289 | |
| 1290 | /* drbd_bitmap.c */ |
| 1291 | /* |
| 1292 | * We need to store one bit for a block. |
| 1293 | * Example: 1GB disk @ 4096 byte blocks ==> we need 32 KB bitmap. |
| 1294 | * Bit 0 ==> local node thinks this block is binary identical on both nodes |
| 1295 | * Bit 1 ==> local node thinks this block needs to be synced. |
| 1296 | */ |
| 1297 | |
Philipp Reisner | 8e26f9c | 2010-07-06 17:25:54 +0200 | [diff] [blame] | 1298 | #define SLEEP_TIME (HZ/10) |
| 1299 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1300 | #define BM_BLOCK_SHIFT 12 /* 4k per bit */ |
| 1301 | #define BM_BLOCK_SIZE (1<<BM_BLOCK_SHIFT) |
| 1302 | /* (9+3) : 512 bytes @ 8 bits; representing 16M storage |
| 1303 | * per sector of on disk bitmap */ |
| 1304 | #define BM_EXT_SHIFT (BM_BLOCK_SHIFT + MD_SECTOR_SHIFT + 3) /* = 24 */ |
| 1305 | #define BM_EXT_SIZE (1<<BM_EXT_SHIFT) |
| 1306 | |
| 1307 | #if (BM_EXT_SHIFT != 24) || (BM_BLOCK_SHIFT != 12) |
| 1308 | #error "HAVE YOU FIXED drbdmeta AS WELL??" |
| 1309 | #endif |
| 1310 | |
| 1311 | /* thus many _storage_ sectors are described by one bit */ |
| 1312 | #define BM_SECT_TO_BIT(x) ((x)>>(BM_BLOCK_SHIFT-9)) |
| 1313 | #define BM_BIT_TO_SECT(x) ((sector_t)(x)<<(BM_BLOCK_SHIFT-9)) |
| 1314 | #define BM_SECT_PER_BIT BM_BIT_TO_SECT(1) |
| 1315 | |
| 1316 | /* bit to represented kilo byte conversion */ |
| 1317 | #define Bit2KB(bits) ((bits)<<(BM_BLOCK_SHIFT-10)) |
| 1318 | |
| 1319 | /* in which _bitmap_ extent (resp. sector) the bit for a certain |
| 1320 | * _storage_ sector is located in */ |
| 1321 | #define BM_SECT_TO_EXT(x) ((x)>>(BM_EXT_SHIFT-9)) |
| 1322 | |
| 1323 | /* how much _storage_ sectors we have per bitmap sector */ |
| 1324 | #define BM_EXT_TO_SECT(x) ((sector_t)(x) << (BM_EXT_SHIFT-9)) |
| 1325 | #define BM_SECT_PER_EXT BM_EXT_TO_SECT(1) |
| 1326 | |
| 1327 | /* in one sector of the bitmap, we have this many activity_log extents. */ |
| 1328 | #define AL_EXT_PER_BM_SECT (1 << (BM_EXT_SHIFT - AL_EXTENT_SHIFT)) |
| 1329 | #define BM_WORDS_PER_AL_EXT (1 << (AL_EXTENT_SHIFT-BM_BLOCK_SHIFT-LN2_BPL)) |
| 1330 | |
| 1331 | #define BM_BLOCKS_PER_BM_EXT_B (BM_EXT_SHIFT - BM_BLOCK_SHIFT) |
| 1332 | #define BM_BLOCKS_PER_BM_EXT_MASK ((1<<BM_BLOCKS_PER_BM_EXT_B) - 1) |
| 1333 | |
| 1334 | /* the extent in "PER_EXTENT" below is an activity log extent |
| 1335 | * we need that many (long words/bytes) to store the bitmap |
| 1336 | * of one AL_EXTENT_SIZE chunk of storage. |
| 1337 | * we can store the bitmap for that many AL_EXTENTS within |
| 1338 | * one sector of the _on_disk_ bitmap: |
| 1339 | * bit 0 bit 37 bit 38 bit (512*8)-1 |
| 1340 | * ...|........|........|.. // ..|........| |
| 1341 | * sect. 0 `296 `304 ^(512*8*8)-1 |
| 1342 | * |
| 1343 | #define BM_WORDS_PER_EXT ( (AL_EXT_SIZE/BM_BLOCK_SIZE) / BITS_PER_LONG ) |
| 1344 | #define BM_BYTES_PER_EXT ( (AL_EXT_SIZE/BM_BLOCK_SIZE) / 8 ) // 128 |
| 1345 | #define BM_EXT_PER_SECT ( 512 / BM_BYTES_PER_EXTENT ) // 4 |
| 1346 | */ |
| 1347 | |
| 1348 | #define DRBD_MAX_SECTORS_32 (0xffffffffLU) |
| 1349 | #define DRBD_MAX_SECTORS_BM \ |
| 1350 | ((MD_RESERVED_SECT - MD_BM_OFFSET) * (1LL<<(BM_EXT_SHIFT-9))) |
| 1351 | #if DRBD_MAX_SECTORS_BM < DRBD_MAX_SECTORS_32 |
| 1352 | #define DRBD_MAX_SECTORS DRBD_MAX_SECTORS_BM |
| 1353 | #define DRBD_MAX_SECTORS_FLEX DRBD_MAX_SECTORS_BM |
Lars Ellenberg | 36bfc7e | 2010-01-05 19:33:54 +0100 | [diff] [blame] | 1354 | #elif !defined(CONFIG_LBDAF) && BITS_PER_LONG == 32 |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1355 | #define DRBD_MAX_SECTORS DRBD_MAX_SECTORS_32 |
| 1356 | #define DRBD_MAX_SECTORS_FLEX DRBD_MAX_SECTORS_32 |
| 1357 | #else |
| 1358 | #define DRBD_MAX_SECTORS DRBD_MAX_SECTORS_BM |
| 1359 | /* 16 TB in units of sectors */ |
| 1360 | #if BITS_PER_LONG == 32 |
| 1361 | /* adjust by one page worth of bitmap, |
| 1362 | * so we won't wrap around in drbd_bm_find_next_bit. |
| 1363 | * you should use 64bit OS for that much storage, anyways. */ |
| 1364 | #define DRBD_MAX_SECTORS_FLEX BM_BIT_TO_SECT(0xffff7fff) |
| 1365 | #else |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 1366 | /* we allow up to 1 PiB now on 64bit architecture with "flexible" meta data */ |
| 1367 | #define DRBD_MAX_SECTORS_FLEX (1UL << 51) |
| 1368 | /* corresponds to (1UL << 38) bits right now. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1369 | #endif |
| 1370 | #endif |
| 1371 | |
Philipp Reisner | d537338 | 2010-08-23 15:18:33 +0200 | [diff] [blame] | 1372 | #define HT_SHIFT 8 |
Lars Ellenberg | 1816a2b | 2010-11-11 15:19:07 +0100 | [diff] [blame] | 1373 | #define DRBD_MAX_BIO_SIZE (1U<<(9+HT_SHIFT)) |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1374 | #define DRBD_MAX_BIO_SIZE_SAFE (1 << 12) /* Works always = 4k */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1375 | |
Philipp Reisner | d537338 | 2010-08-23 15:18:33 +0200 | [diff] [blame] | 1376 | #define DRBD_MAX_SIZE_H80_PACKET (1 << 15) /* The old header only allows packets up to 32Kib data */ |
| 1377 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1378 | extern int drbd_bm_init(struct drbd_conf *mdev); |
Philipp Reisner | 02d9a94 | 2010-03-24 16:23:03 +0100 | [diff] [blame] | 1379 | extern int drbd_bm_resize(struct drbd_conf *mdev, sector_t sectors, int set_new_bits); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1380 | extern void drbd_bm_cleanup(struct drbd_conf *mdev); |
| 1381 | extern void drbd_bm_set_all(struct drbd_conf *mdev); |
| 1382 | extern void drbd_bm_clear_all(struct drbd_conf *mdev); |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 1383 | /* set/clear/test only a few bits at a time */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1384 | extern int drbd_bm_set_bits( |
| 1385 | struct drbd_conf *mdev, unsigned long s, unsigned long e); |
| 1386 | extern int drbd_bm_clear_bits( |
| 1387 | struct drbd_conf *mdev, unsigned long s, unsigned long e); |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 1388 | extern int drbd_bm_count_bits( |
| 1389 | struct drbd_conf *mdev, const unsigned long s, const unsigned long e); |
| 1390 | /* bm_set_bits variant for use while holding drbd_bm_lock, |
| 1391 | * may process the whole bitmap in one go */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1392 | extern void _drbd_bm_set_bits(struct drbd_conf *mdev, |
| 1393 | const unsigned long s, const unsigned long e); |
| 1394 | extern int drbd_bm_test_bit(struct drbd_conf *mdev, unsigned long bitnr); |
| 1395 | extern int drbd_bm_e_weight(struct drbd_conf *mdev, unsigned long enr); |
Lars Ellenberg | 19f843a | 2010-12-15 08:59:11 +0100 | [diff] [blame] | 1396 | extern int drbd_bm_write_page(struct drbd_conf *mdev, unsigned int idx) __must_hold(local); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1397 | extern int drbd_bm_read(struct drbd_conf *mdev) __must_hold(local); |
| 1398 | extern int drbd_bm_write(struct drbd_conf *mdev) __must_hold(local); |
| 1399 | extern unsigned long drbd_bm_ALe_set_all(struct drbd_conf *mdev, |
| 1400 | unsigned long al_enr); |
| 1401 | extern size_t drbd_bm_words(struct drbd_conf *mdev); |
| 1402 | extern unsigned long drbd_bm_bits(struct drbd_conf *mdev); |
| 1403 | extern sector_t drbd_bm_capacity(struct drbd_conf *mdev); |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 1404 | |
| 1405 | #define DRBD_END_OF_BITMAP (~(unsigned long)0) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1406 | extern unsigned long drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo); |
| 1407 | /* bm_find_next variants for use while you hold drbd_bm_lock() */ |
| 1408 | extern unsigned long _drbd_bm_find_next(struct drbd_conf *mdev, unsigned long bm_fo); |
| 1409 | extern unsigned long _drbd_bm_find_next_zero(struct drbd_conf *mdev, unsigned long bm_fo); |
Philipp Reisner | 0778286 | 2010-08-31 12:00:50 +0200 | [diff] [blame] | 1410 | extern unsigned long _drbd_bm_total_weight(struct drbd_conf *mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1411 | extern unsigned long drbd_bm_total_weight(struct drbd_conf *mdev); |
| 1412 | extern int drbd_bm_rs_done(struct drbd_conf *mdev); |
| 1413 | /* for receive_bitmap */ |
| 1414 | extern void drbd_bm_merge_lel(struct drbd_conf *mdev, size_t offset, |
| 1415 | size_t number, unsigned long *buffer); |
Lars Ellenberg | 19f843a | 2010-12-15 08:59:11 +0100 | [diff] [blame] | 1416 | /* for _drbd_send_bitmap */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1417 | extern void drbd_bm_get_lel(struct drbd_conf *mdev, size_t offset, |
| 1418 | size_t number, unsigned long *buffer); |
| 1419 | |
Lars Ellenberg | 20ceb2b | 2011-01-21 10:56:44 +0100 | [diff] [blame] | 1420 | extern void drbd_bm_lock(struct drbd_conf *mdev, char *why, enum bm_flag flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1421 | extern void drbd_bm_unlock(struct drbd_conf *mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1422 | /* drbd_main.c */ |
| 1423 | |
| 1424 | extern struct kmem_cache *drbd_request_cache; |
Andreas Gruenbacher | 6c852be | 2011-02-04 15:38:52 +0100 | [diff] [blame^] | 1425 | extern struct kmem_cache *drbd_ee_cache; /* peer requests */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1426 | extern struct kmem_cache *drbd_bm_ext_cache; /* bitmap extents */ |
| 1427 | extern struct kmem_cache *drbd_al_ext_cache; /* activity log extents */ |
| 1428 | extern mempool_t *drbd_request_mempool; |
| 1429 | extern mempool_t *drbd_ee_mempool; |
| 1430 | |
| 1431 | extern struct page *drbd_pp_pool; /* drbd's page pool */ |
| 1432 | extern spinlock_t drbd_pp_lock; |
| 1433 | extern int drbd_pp_vacant; |
| 1434 | extern wait_queue_head_t drbd_pp_wait; |
| 1435 | |
| 1436 | extern rwlock_t global_state_lock; |
| 1437 | |
| 1438 | extern struct drbd_conf *drbd_new_device(unsigned int minor); |
| 1439 | extern void drbd_free_mdev(struct drbd_conf *mdev); |
| 1440 | |
Philipp Reisner | 2111438 | 2011-01-19 12:26:59 +0100 | [diff] [blame] | 1441 | struct drbd_tconn *drbd_new_tconn(char *name); |
| 1442 | extern void drbd_free_tconn(struct drbd_tconn *tconn); |
| 1443 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1444 | extern int proc_details; |
| 1445 | |
| 1446 | /* drbd_req */ |
Andreas Gruenbacher | 2f58dcf | 2010-12-13 17:48:19 +0100 | [diff] [blame] | 1447 | extern int drbd_make_request(struct request_queue *q, struct bio *bio); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1448 | extern int drbd_read_remote(struct drbd_conf *mdev, struct drbd_request *req); |
| 1449 | extern int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec); |
| 1450 | extern int is_valid_ar_handle(struct drbd_request *, sector_t); |
| 1451 | |
| 1452 | |
| 1453 | /* drbd_nl.c */ |
| 1454 | extern void drbd_suspend_io(struct drbd_conf *mdev); |
| 1455 | extern void drbd_resume_io(struct drbd_conf *mdev); |
| 1456 | extern char *ppsize(char *buf, unsigned long long size); |
Philipp Reisner | a393db6 | 2009-12-22 13:35:52 +0100 | [diff] [blame] | 1457 | extern sector_t drbd_new_dev_size(struct drbd_conf *, struct drbd_backing_dev *, int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1458 | enum determine_dev_size { dev_size_error = -1, unchanged = 0, shrunk = 1, grew = 2 }; |
Bart Van Assche | 24c4830 | 2011-05-21 18:32:29 +0200 | [diff] [blame] | 1459 | extern enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *, enum dds_flags) __must_hold(local); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1460 | extern void resync_after_online_grow(struct drbd_conf *); |
Philipp Reisner | 99432fc | 2011-05-20 16:39:13 +0200 | [diff] [blame] | 1461 | extern void drbd_reconsider_max_bio_size(struct drbd_conf *mdev); |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 1462 | extern enum drbd_state_rv drbd_set_role(struct drbd_conf *mdev, |
| 1463 | enum drbd_role new_role, |
| 1464 | int force); |
Philipp Reisner | 87f7be4 | 2010-06-11 13:56:33 +0200 | [diff] [blame] | 1465 | extern enum drbd_disk_state drbd_try_outdate_peer(struct drbd_conf *mdev); |
| 1466 | extern void drbd_try_outdate_peer_async(struct drbd_conf *mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1467 | extern int drbd_khelper(struct drbd_conf *mdev, char *cmd); |
| 1468 | |
| 1469 | /* drbd_worker.c */ |
| 1470 | extern int drbd_worker(struct drbd_thread *thi); |
| 1471 | extern int drbd_alter_sa(struct drbd_conf *mdev, int na); |
| 1472 | extern void drbd_start_resync(struct drbd_conf *mdev, enum drbd_conns side); |
| 1473 | extern void resume_next_sg(struct drbd_conf *mdev); |
| 1474 | extern void suspend_other_sg(struct drbd_conf *mdev); |
| 1475 | extern int drbd_resync_finished(struct drbd_conf *mdev); |
| 1476 | /* maybe rather drbd_main.c ? */ |
| 1477 | extern int drbd_md_sync_page_io(struct drbd_conf *mdev, |
| 1478 | struct drbd_backing_dev *bdev, sector_t sector, int rw); |
| 1479 | extern void drbd_ov_oos_found(struct drbd_conf*, sector_t, int); |
Lars Ellenberg | 9bd28d3 | 2010-11-05 09:55:18 +0100 | [diff] [blame] | 1480 | extern void drbd_rs_controller_reset(struct drbd_conf *mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1481 | |
| 1482 | static inline void ov_oos_print(struct drbd_conf *mdev) |
| 1483 | { |
| 1484 | if (mdev->ov_last_oos_size) { |
| 1485 | dev_err(DEV, "Out of sync: start=%llu, size=%lu (sectors)\n", |
| 1486 | (unsigned long long)mdev->ov_last_oos_start, |
| 1487 | (unsigned long)mdev->ov_last_oos_size); |
| 1488 | } |
| 1489 | mdev->ov_last_oos_size=0; |
| 1490 | } |
| 1491 | |
| 1492 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1493 | extern void drbd_csum_bio(struct drbd_conf *, struct crypto_hash *, struct bio *, void *); |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1494 | extern void drbd_csum_ee(struct drbd_conf *, struct crypto_hash *, |
| 1495 | struct drbd_peer_request *, void *); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1496 | /* worker callbacks */ |
| 1497 | extern int w_req_cancel_conflict(struct drbd_conf *, struct drbd_work *, int); |
| 1498 | extern int w_read_retry_remote(struct drbd_conf *, struct drbd_work *, int); |
| 1499 | extern int w_e_end_data_req(struct drbd_conf *, struct drbd_work *, int); |
| 1500 | extern int w_e_end_rsdata_req(struct drbd_conf *, struct drbd_work *, int); |
| 1501 | extern int w_e_end_csum_rs_req(struct drbd_conf *, struct drbd_work *, int); |
| 1502 | extern int w_e_end_ov_reply(struct drbd_conf *, struct drbd_work *, int); |
| 1503 | extern int w_e_end_ov_req(struct drbd_conf *, struct drbd_work *, int); |
| 1504 | extern int w_ov_finished(struct drbd_conf *, struct drbd_work *, int); |
Philipp Reisner | 794abb7 | 2010-12-27 11:51:23 +0100 | [diff] [blame] | 1505 | extern int w_resync_timer(struct drbd_conf *, struct drbd_work *, int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1506 | extern int w_resume_next_sg(struct drbd_conf *, struct drbd_work *, int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1507 | extern int w_send_write_hint(struct drbd_conf *, struct drbd_work *, int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1508 | extern int w_send_dblock(struct drbd_conf *, struct drbd_work *, int); |
| 1509 | extern int w_send_barrier(struct drbd_conf *, struct drbd_work *, int); |
| 1510 | extern int w_send_read_req(struct drbd_conf *, struct drbd_work *, int); |
| 1511 | extern int w_prev_work_done(struct drbd_conf *, struct drbd_work *, int); |
| 1512 | extern int w_e_reissue(struct drbd_conf *, struct drbd_work *, int); |
Philipp Reisner | 265be2d | 2010-05-31 10:14:17 +0200 | [diff] [blame] | 1513 | extern int w_restart_disk_io(struct drbd_conf *, struct drbd_work *, int); |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 1514 | extern int w_send_oos(struct drbd_conf *, struct drbd_work *, int); |
Philipp Reisner | c4752ef | 2010-10-27 17:32:36 +0200 | [diff] [blame] | 1515 | extern int w_start_resync(struct drbd_conf *, struct drbd_work *, int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1516 | |
| 1517 | extern void resync_timer_fn(unsigned long data); |
Philipp Reisner | 370a43e | 2011-01-14 16:03:11 +0100 | [diff] [blame] | 1518 | extern void start_resync_timer_fn(unsigned long data); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1519 | |
| 1520 | /* drbd_receiver.c */ |
Philipp Reisner | e3555d8 | 2010-11-07 15:56:29 +0100 | [diff] [blame] | 1521 | extern int drbd_rs_should_slow_down(struct drbd_conf *mdev, sector_t sector); |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1522 | extern int drbd_submit_ee(struct drbd_conf *, struct drbd_peer_request *, |
| 1523 | const unsigned, const int); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1524 | extern int drbd_release_ee(struct drbd_conf *mdev, struct list_head *list); |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1525 | extern struct drbd_peer_request *drbd_alloc_ee(struct drbd_conf *, |
| 1526 | u64, sector_t, unsigned int, |
| 1527 | gfp_t) __must_hold(local); |
| 1528 | extern void drbd_free_some_ee(struct drbd_conf *, struct drbd_peer_request *, |
| 1529 | int); |
Lars Ellenberg | 435f074 | 2010-09-06 12:30:25 +0200 | [diff] [blame] | 1530 | #define drbd_free_ee(m,e) drbd_free_some_ee(m, e, 0) |
| 1531 | #define drbd_free_net_ee(m,e) drbd_free_some_ee(m, e, 1) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1532 | extern void drbd_wait_ee_list_empty(struct drbd_conf *mdev, |
| 1533 | struct list_head *head); |
| 1534 | extern void _drbd_wait_ee_list_empty(struct drbd_conf *mdev, |
| 1535 | struct list_head *head); |
| 1536 | extern void drbd_set_recv_tcq(struct drbd_conf *mdev, int tcq_enabled); |
| 1537 | extern void _drbd_clear_done_ee(struct drbd_conf *mdev, struct list_head *to_be_freed); |
Philipp Reisner | 191d3cc | 2011-01-19 14:53:22 +0100 | [diff] [blame] | 1538 | extern void drbd_flush_workqueue(struct drbd_tconn *tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1539 | |
| 1540 | /* yes, there is kernel_setsockopt, but only since 2.6.18. we don't need to |
| 1541 | * mess with get_fs/set_fs, we know we are KERNEL_DS always. */ |
| 1542 | static inline int drbd_setsockopt(struct socket *sock, int level, int optname, |
| 1543 | char __user *optval, int optlen) |
| 1544 | { |
| 1545 | int err; |
| 1546 | if (level == SOL_SOCKET) |
| 1547 | err = sock_setsockopt(sock, level, optname, optval, optlen); |
| 1548 | else |
| 1549 | err = sock->ops->setsockopt(sock, level, optname, optval, |
| 1550 | optlen); |
| 1551 | return err; |
| 1552 | } |
| 1553 | |
| 1554 | static inline void drbd_tcp_cork(struct socket *sock) |
| 1555 | { |
| 1556 | int __user val = 1; |
| 1557 | (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK, |
| 1558 | (char __user *)&val, sizeof(val)); |
| 1559 | } |
| 1560 | |
| 1561 | static inline void drbd_tcp_uncork(struct socket *sock) |
| 1562 | { |
| 1563 | int __user val = 0; |
| 1564 | (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK, |
| 1565 | (char __user *)&val, sizeof(val)); |
| 1566 | } |
| 1567 | |
| 1568 | static inline void drbd_tcp_nodelay(struct socket *sock) |
| 1569 | { |
| 1570 | int __user val = 1; |
| 1571 | (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY, |
| 1572 | (char __user *)&val, sizeof(val)); |
| 1573 | } |
| 1574 | |
| 1575 | static inline void drbd_tcp_quickack(struct socket *sock) |
| 1576 | { |
Lars Ellenberg | 344fa46 | 2010-05-25 14:23:57 +0200 | [diff] [blame] | 1577 | int __user val = 2; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1578 | (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK, |
| 1579 | (char __user *)&val, sizeof(val)); |
| 1580 | } |
| 1581 | |
| 1582 | void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo); |
| 1583 | |
| 1584 | /* drbd_proc.c */ |
| 1585 | extern struct proc_dir_entry *drbd_proc; |
Emese Revfy | 7d4e9d0 | 2009-12-14 00:59:30 +0100 | [diff] [blame] | 1586 | extern const struct file_operations drbd_proc_fops; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1587 | extern const char *drbd_conn_str(enum drbd_conns s); |
| 1588 | extern const char *drbd_role_str(enum drbd_role s); |
| 1589 | |
| 1590 | /* drbd_actlog.c */ |
| 1591 | extern void drbd_al_begin_io(struct drbd_conf *mdev, sector_t sector); |
| 1592 | extern void drbd_al_complete_io(struct drbd_conf *mdev, sector_t sector); |
| 1593 | extern void drbd_rs_complete_io(struct drbd_conf *mdev, sector_t sector); |
| 1594 | extern int drbd_rs_begin_io(struct drbd_conf *mdev, sector_t sector); |
| 1595 | extern int drbd_try_rs_begin_io(struct drbd_conf *mdev, sector_t sector); |
| 1596 | extern void drbd_rs_cancel_all(struct drbd_conf *mdev); |
| 1597 | extern int drbd_rs_del_all(struct drbd_conf *mdev); |
| 1598 | extern void drbd_rs_failed_io(struct drbd_conf *mdev, |
| 1599 | sector_t sector, int size); |
| 1600 | extern int drbd_al_read_log(struct drbd_conf *mdev, struct drbd_backing_dev *); |
Lars Ellenberg | ea5442a | 2010-11-05 09:48:01 +0100 | [diff] [blame] | 1601 | extern void drbd_advance_rs_marks(struct drbd_conf *mdev, unsigned long still_to_go); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1602 | extern void __drbd_set_in_sync(struct drbd_conf *mdev, sector_t sector, |
| 1603 | int size, const char *file, const unsigned int line); |
| 1604 | #define drbd_set_in_sync(mdev, sector, size) \ |
| 1605 | __drbd_set_in_sync(mdev, sector, size, __FILE__, __LINE__) |
Philipp Reisner | 73a01a1 | 2010-10-27 14:33:00 +0200 | [diff] [blame] | 1606 | extern int __drbd_set_out_of_sync(struct drbd_conf *mdev, sector_t sector, |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1607 | int size, const char *file, const unsigned int line); |
| 1608 | #define drbd_set_out_of_sync(mdev, sector, size) \ |
| 1609 | __drbd_set_out_of_sync(mdev, sector, size, __FILE__, __LINE__) |
| 1610 | extern void drbd_al_apply_to_bm(struct drbd_conf *mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1611 | extern void drbd_al_shrink(struct drbd_conf *mdev); |
| 1612 | |
| 1613 | |
| 1614 | /* drbd_nl.c */ |
| 1615 | |
| 1616 | void drbd_nl_cleanup(void); |
| 1617 | int __init drbd_nl_init(void); |
| 1618 | void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state); |
| 1619 | void drbd_bcast_sync_progress(struct drbd_conf *mdev); |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1620 | void drbd_bcast_ee(struct drbd_conf *, const char *, const int, const char *, |
| 1621 | const char *, const struct drbd_peer_request *); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1622 | |
| 1623 | |
| 1624 | /** |
| 1625 | * DOC: DRBD State macros |
| 1626 | * |
| 1627 | * These macros are used to express state changes in easily readable form. |
| 1628 | * |
| 1629 | * The NS macros expand to a mask and a value, that can be bit ored onto the |
| 1630 | * current state as soon as the spinlock (req_lock) was taken. |
| 1631 | * |
| 1632 | * The _NS macros are used for state functions that get called with the |
| 1633 | * spinlock. These macros expand directly to the new state value. |
| 1634 | * |
| 1635 | * Besides the basic forms NS() and _NS() additional _?NS[23] are defined |
| 1636 | * to express state changes that affect more than one aspect of the state. |
| 1637 | * |
| 1638 | * E.g. NS2(conn, C_CONNECTED, peer, R_SECONDARY) |
| 1639 | * Means that the network connection was established and that the peer |
| 1640 | * is in secondary role. |
| 1641 | */ |
| 1642 | #define role_MASK R_MASK |
| 1643 | #define peer_MASK R_MASK |
| 1644 | #define disk_MASK D_MASK |
| 1645 | #define pdsk_MASK D_MASK |
| 1646 | #define conn_MASK C_MASK |
| 1647 | #define susp_MASK 1 |
| 1648 | #define user_isp_MASK 1 |
| 1649 | #define aftr_isp_MASK 1 |
Philipp Reisner | fb22c40 | 2010-09-08 23:20:21 +0200 | [diff] [blame] | 1650 | #define susp_nod_MASK 1 |
| 1651 | #define susp_fen_MASK 1 |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1652 | |
| 1653 | #define NS(T, S) \ |
| 1654 | ({ union drbd_state mask; mask.i = 0; mask.T = T##_MASK; mask; }), \ |
| 1655 | ({ union drbd_state val; val.i = 0; val.T = (S); val; }) |
| 1656 | #define NS2(T1, S1, T2, S2) \ |
| 1657 | ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \ |
| 1658 | mask.T2 = T2##_MASK; mask; }), \ |
| 1659 | ({ union drbd_state val; val.i = 0; val.T1 = (S1); \ |
| 1660 | val.T2 = (S2); val; }) |
| 1661 | #define NS3(T1, S1, T2, S2, T3, S3) \ |
| 1662 | ({ union drbd_state mask; mask.i = 0; mask.T1 = T1##_MASK; \ |
| 1663 | mask.T2 = T2##_MASK; mask.T3 = T3##_MASK; mask; }), \ |
| 1664 | ({ union drbd_state val; val.i = 0; val.T1 = (S1); \ |
| 1665 | val.T2 = (S2); val.T3 = (S3); val; }) |
| 1666 | |
| 1667 | #define _NS(D, T, S) \ |
| 1668 | D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T = (S); __ns; }) |
| 1669 | #define _NS2(D, T1, S1, T2, S2) \ |
| 1670 | D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T1 = (S1); \ |
| 1671 | __ns.T2 = (S2); __ns; }) |
| 1672 | #define _NS3(D, T1, S1, T2, S2, T3, S3) \ |
| 1673 | D, ({ union drbd_state __ns; __ns.i = D->state.i; __ns.T1 = (S1); \ |
| 1674 | __ns.T2 = (S2); __ns.T3 = (S3); __ns; }) |
| 1675 | |
| 1676 | /* |
| 1677 | * inline helper functions |
| 1678 | *************************/ |
| 1679 | |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1680 | /* see also page_chain_add and friends in drbd_receiver.c */ |
| 1681 | static inline struct page *page_chain_next(struct page *page) |
| 1682 | { |
| 1683 | return (struct page *)page_private(page); |
| 1684 | } |
| 1685 | #define page_chain_for_each(page) \ |
| 1686 | for (; page && ({ prefetch(page_chain_next(page)); 1; }); \ |
| 1687 | page = page_chain_next(page)) |
| 1688 | #define page_chain_for_each_safe(page, n) \ |
| 1689 | for (; page && ({ n = page_chain_next(page); 1; }); page = n) |
| 1690 | |
| 1691 | static inline int drbd_bio_has_active_page(struct bio *bio) |
| 1692 | { |
| 1693 | struct bio_vec *bvec; |
| 1694 | int i; |
| 1695 | |
| 1696 | __bio_for_each_segment(bvec, bio, i, 0) { |
| 1697 | if (page_count(bvec->bv_page) > 1) |
| 1698 | return 1; |
| 1699 | } |
| 1700 | |
| 1701 | return 0; |
| 1702 | } |
| 1703 | |
Andreas Gruenbacher | f6ffca9 | 2011-02-04 15:30:34 +0100 | [diff] [blame] | 1704 | static inline int drbd_ee_has_active_page(struct drbd_peer_request *e) |
Lars Ellenberg | 45bb912 | 2010-05-14 17:10:48 +0200 | [diff] [blame] | 1705 | { |
| 1706 | struct page *page = e->pages; |
| 1707 | page_chain_for_each(page) { |
| 1708 | if (page_count(page) > 1) |
| 1709 | return 1; |
| 1710 | } |
| 1711 | return 0; |
| 1712 | } |
| 1713 | |
| 1714 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1715 | static inline void drbd_state_lock(struct drbd_conf *mdev) |
| 1716 | { |
| 1717 | wait_event(mdev->misc_wait, |
| 1718 | !test_and_set_bit(CLUSTER_ST_CHANGE, &mdev->flags)); |
| 1719 | } |
| 1720 | |
| 1721 | static inline void drbd_state_unlock(struct drbd_conf *mdev) |
| 1722 | { |
| 1723 | clear_bit(CLUSTER_ST_CHANGE, &mdev->flags); |
| 1724 | wake_up(&mdev->misc_wait); |
| 1725 | } |
| 1726 | |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 1727 | static inline enum drbd_state_rv |
| 1728 | _drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, |
| 1729 | enum chg_state_flags flags, struct completion *done) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1730 | { |
Andreas Gruenbacher | bf885f8 | 2010-12-08 00:39:32 +0100 | [diff] [blame] | 1731 | enum drbd_state_rv rv; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1732 | |
| 1733 | read_lock(&global_state_lock); |
| 1734 | rv = __drbd_set_state(mdev, ns, flags, done); |
| 1735 | read_unlock(&global_state_lock); |
| 1736 | |
| 1737 | return rv; |
| 1738 | } |
| 1739 | |
| 1740 | /** |
| 1741 | * drbd_request_state() - Reqest a state change |
| 1742 | * @mdev: DRBD device. |
| 1743 | * @mask: mask of state bits to change. |
| 1744 | * @val: value of new state bits. |
| 1745 | * |
| 1746 | * This is the most graceful way of requesting a state change. It is verbose |
| 1747 | * quite verbose in case the state change is not possible, and all those |
| 1748 | * state changes are globally serialized. |
| 1749 | */ |
| 1750 | static inline int drbd_request_state(struct drbd_conf *mdev, |
| 1751 | union drbd_state mask, |
| 1752 | union drbd_state val) |
| 1753 | { |
| 1754 | return _drbd_request_state(mdev, mask, val, CS_VERBOSE + CS_ORDERED); |
| 1755 | } |
| 1756 | |
| 1757 | #define __drbd_chk_io_error(m,f) __drbd_chk_io_error_(m,f, __func__) |
| 1758 | static inline void __drbd_chk_io_error_(struct drbd_conf *mdev, int forcedetach, const char *where) |
| 1759 | { |
| 1760 | switch (mdev->ldev->dc.on_io_error) { |
| 1761 | case EP_PASS_ON: |
| 1762 | if (!forcedetach) { |
Lars Ellenberg | 7383506 | 2010-05-27 11:51:56 +0200 | [diff] [blame] | 1763 | if (__ratelimit(&drbd_ratelimit_state)) |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 1764 | dev_err(DEV, "Local IO failed in %s.\n", where); |
Philipp Reisner | d2e1780 | 2011-03-14 11:54:47 +0100 | [diff] [blame] | 1765 | if (mdev->state.disk > D_INCONSISTENT) |
| 1766 | _drbd_set_state(_NS(mdev, disk, D_INCONSISTENT), CS_HARD, NULL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1767 | break; |
| 1768 | } |
| 1769 | /* NOTE fall through to detach case if forcedetach set */ |
| 1770 | case EP_DETACH: |
| 1771 | case EP_CALL_HELPER: |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 1772 | set_bit(WAS_IO_ERROR, &mdev->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1773 | if (mdev->state.disk > D_FAILED) { |
| 1774 | _drbd_set_state(_NS(mdev, disk, D_FAILED), CS_HARD, NULL); |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 1775 | dev_err(DEV, |
| 1776 | "Local IO failed in %s. Detaching...\n", where); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1777 | } |
| 1778 | break; |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | /** |
| 1783 | * drbd_chk_io_error: Handle the on_io_error setting, should be called from all io completion handlers |
| 1784 | * @mdev: DRBD device. |
| 1785 | * @error: Error code passed to the IO completion callback |
| 1786 | * @forcedetach: Force detach. I.e. the error happened while accessing the meta data |
| 1787 | * |
| 1788 | * See also drbd_main.c:after_state_ch() if (os.disk > D_FAILED && ns.disk == D_FAILED) |
| 1789 | */ |
| 1790 | #define drbd_chk_io_error(m,e,f) drbd_chk_io_error_(m,e,f, __func__) |
| 1791 | static inline void drbd_chk_io_error_(struct drbd_conf *mdev, |
| 1792 | int error, int forcedetach, const char *where) |
| 1793 | { |
| 1794 | if (error) { |
| 1795 | unsigned long flags; |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1796 | spin_lock_irqsave(&mdev->tconn->req_lock, flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1797 | __drbd_chk_io_error_(mdev, forcedetach, where); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 1798 | spin_unlock_irqrestore(&mdev->tconn->req_lock, flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | |
| 1803 | /** |
| 1804 | * drbd_md_first_sector() - Returns the first sector number of the meta data area |
| 1805 | * @bdev: Meta data block device. |
| 1806 | * |
| 1807 | * BTW, for internal meta data, this happens to be the maximum capacity |
| 1808 | * we could agree upon with our peer node. |
| 1809 | */ |
| 1810 | static inline sector_t drbd_md_first_sector(struct drbd_backing_dev *bdev) |
| 1811 | { |
| 1812 | switch (bdev->dc.meta_dev_idx) { |
| 1813 | case DRBD_MD_INDEX_INTERNAL: |
| 1814 | case DRBD_MD_INDEX_FLEX_INT: |
| 1815 | return bdev->md.md_offset + bdev->md.bm_offset; |
| 1816 | case DRBD_MD_INDEX_FLEX_EXT: |
| 1817 | default: |
| 1818 | return bdev->md.md_offset; |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | /** |
| 1823 | * drbd_md_last_sector() - Return the last sector number of the meta data area |
| 1824 | * @bdev: Meta data block device. |
| 1825 | */ |
| 1826 | static inline sector_t drbd_md_last_sector(struct drbd_backing_dev *bdev) |
| 1827 | { |
| 1828 | switch (bdev->dc.meta_dev_idx) { |
| 1829 | case DRBD_MD_INDEX_INTERNAL: |
| 1830 | case DRBD_MD_INDEX_FLEX_INT: |
| 1831 | return bdev->md.md_offset + MD_AL_OFFSET - 1; |
| 1832 | case DRBD_MD_INDEX_FLEX_EXT: |
| 1833 | default: |
| 1834 | return bdev->md.md_offset + bdev->md.md_size_sect; |
| 1835 | } |
| 1836 | } |
| 1837 | |
| 1838 | /* Returns the number of 512 byte sectors of the device */ |
| 1839 | static inline sector_t drbd_get_capacity(struct block_device *bdev) |
| 1840 | { |
| 1841 | /* return bdev ? get_capacity(bdev->bd_disk) : 0; */ |
Mike Snitzer | 77304d2 | 2010-11-08 14:39:12 +0100 | [diff] [blame] | 1842 | return bdev ? i_size_read(bdev->bd_inode) >> 9 : 0; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | /** |
| 1846 | * drbd_get_max_capacity() - Returns the capacity we announce to out peer |
| 1847 | * @bdev: Meta data block device. |
| 1848 | * |
| 1849 | * returns the capacity we announce to out peer. we clip ourselves at the |
| 1850 | * various MAX_SECTORS, because if we don't, current implementation will |
| 1851 | * oops sooner or later |
| 1852 | */ |
| 1853 | static inline sector_t drbd_get_max_capacity(struct drbd_backing_dev *bdev) |
| 1854 | { |
| 1855 | sector_t s; |
| 1856 | switch (bdev->dc.meta_dev_idx) { |
| 1857 | case DRBD_MD_INDEX_INTERNAL: |
| 1858 | case DRBD_MD_INDEX_FLEX_INT: |
| 1859 | s = drbd_get_capacity(bdev->backing_bdev) |
| 1860 | ? min_t(sector_t, DRBD_MAX_SECTORS_FLEX, |
| 1861 | drbd_md_first_sector(bdev)) |
| 1862 | : 0; |
| 1863 | break; |
| 1864 | case DRBD_MD_INDEX_FLEX_EXT: |
| 1865 | s = min_t(sector_t, DRBD_MAX_SECTORS_FLEX, |
| 1866 | drbd_get_capacity(bdev->backing_bdev)); |
| 1867 | /* clip at maximum size the meta device can support */ |
| 1868 | s = min_t(sector_t, s, |
| 1869 | BM_EXT_TO_SECT(bdev->md.md_size_sect |
| 1870 | - bdev->md.bm_offset)); |
| 1871 | break; |
| 1872 | default: |
| 1873 | s = min_t(sector_t, DRBD_MAX_SECTORS, |
| 1874 | drbd_get_capacity(bdev->backing_bdev)); |
| 1875 | } |
| 1876 | return s; |
| 1877 | } |
| 1878 | |
| 1879 | /** |
| 1880 | * drbd_md_ss__() - Return the sector number of our meta data super block |
| 1881 | * @mdev: DRBD device. |
| 1882 | * @bdev: Meta data block device. |
| 1883 | */ |
| 1884 | static inline sector_t drbd_md_ss__(struct drbd_conf *mdev, |
| 1885 | struct drbd_backing_dev *bdev) |
| 1886 | { |
| 1887 | switch (bdev->dc.meta_dev_idx) { |
| 1888 | default: /* external, some index */ |
| 1889 | return MD_RESERVED_SECT * bdev->dc.meta_dev_idx; |
| 1890 | case DRBD_MD_INDEX_INTERNAL: |
| 1891 | /* with drbd08, internal meta data is always "flexible" */ |
| 1892 | case DRBD_MD_INDEX_FLEX_INT: |
| 1893 | /* sizeof(struct md_on_disk_07) == 4k |
| 1894 | * position: last 4k aligned block of 4k size */ |
| 1895 | if (!bdev->backing_bdev) { |
| 1896 | if (__ratelimit(&drbd_ratelimit_state)) { |
| 1897 | dev_err(DEV, "bdev->backing_bdev==NULL\n"); |
| 1898 | dump_stack(); |
| 1899 | } |
| 1900 | return 0; |
| 1901 | } |
| 1902 | return (drbd_get_capacity(bdev->backing_bdev) & ~7ULL) |
| 1903 | - MD_AL_OFFSET; |
| 1904 | case DRBD_MD_INDEX_FLEX_EXT: |
| 1905 | return 0; |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | static inline void |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1910 | drbd_queue_work_front(struct drbd_work_queue *q, struct drbd_work *w) |
| 1911 | { |
| 1912 | unsigned long flags; |
| 1913 | spin_lock_irqsave(&q->q_lock, flags); |
| 1914 | list_add(&w->list, &q->q); |
| 1915 | up(&q->s); /* within the spinlock, |
| 1916 | see comment near end of drbd_worker() */ |
| 1917 | spin_unlock_irqrestore(&q->q_lock, flags); |
| 1918 | } |
| 1919 | |
| 1920 | static inline void |
| 1921 | drbd_queue_work(struct drbd_work_queue *q, struct drbd_work *w) |
| 1922 | { |
| 1923 | unsigned long flags; |
| 1924 | spin_lock_irqsave(&q->q_lock, flags); |
| 1925 | list_add_tail(&w->list, &q->q); |
| 1926 | up(&q->s); /* within the spinlock, |
| 1927 | see comment near end of drbd_worker() */ |
| 1928 | spin_unlock_irqrestore(&q->q_lock, flags); |
| 1929 | } |
| 1930 | |
| 1931 | static inline void wake_asender(struct drbd_conf *mdev) |
| 1932 | { |
| 1933 | if (test_bit(SIGNAL_ASENDER, &mdev->flags)) |
Philipp Reisner | e6b3ea8 | 2011-01-19 14:02:01 +0100 | [diff] [blame] | 1934 | force_sig(DRBD_SIG, mdev->tconn->asender.task); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | static inline void request_ping(struct drbd_conf *mdev) |
| 1938 | { |
| 1939 | set_bit(SEND_PING, &mdev->flags); |
| 1940 | wake_asender(mdev); |
| 1941 | } |
| 1942 | |
| 1943 | static inline int drbd_send_short_cmd(struct drbd_conf *mdev, |
Andreas Gruenbacher | d876302 | 2011-01-26 17:39:41 +0100 | [diff] [blame] | 1944 | enum drbd_packet cmd) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1945 | { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 1946 | struct p_header h; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1947 | return drbd_send_cmd(mdev, USE_DATA_SOCKET, cmd, &h, sizeof(h)); |
| 1948 | } |
| 1949 | |
| 1950 | static inline int drbd_send_ping(struct drbd_conf *mdev) |
| 1951 | { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 1952 | struct p_header h; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1953 | return drbd_send_cmd(mdev, USE_META_SOCKET, P_PING, &h, sizeof(h)); |
| 1954 | } |
| 1955 | |
| 1956 | static inline int drbd_send_ping_ack(struct drbd_conf *mdev) |
| 1957 | { |
Philipp Reisner | c012949 | 2011-01-19 16:58:16 +0100 | [diff] [blame] | 1958 | struct p_header h; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1959 | return drbd_send_cmd(mdev, USE_META_SOCKET, P_PING_ACK, &h, sizeof(h)); |
| 1960 | } |
| 1961 | |
| 1962 | static inline void drbd_thread_stop(struct drbd_thread *thi) |
| 1963 | { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1964 | _drbd_thread_stop(thi, false, true); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | static inline void drbd_thread_stop_nowait(struct drbd_thread *thi) |
| 1968 | { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1969 | _drbd_thread_stop(thi, false, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | static inline void drbd_thread_restart_nowait(struct drbd_thread *thi) |
| 1973 | { |
Andreas Gruenbacher | 81e8465 | 2010-12-09 15:03:57 +0100 | [diff] [blame] | 1974 | _drbd_thread_stop(thi, true, false); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | /* counts how many answer packets packets we expect from our peer, |
| 1978 | * for either explicit application requests, |
| 1979 | * or implicit barrier packets as necessary. |
| 1980 | * increased: |
| 1981 | * w_send_barrier |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 1982 | * _req_mod(req, QUEUE_FOR_NET_WRITE or QUEUE_FOR_NET_READ); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1983 | * it is much easier and equally valid to count what we queue for the |
| 1984 | * worker, even before it actually was queued or send. |
| 1985 | * (drbd_make_request_common; recovery path on read io-error) |
| 1986 | * decreased: |
| 1987 | * got_BarrierAck (respective tl_clear, tl_clear_barrier) |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 1988 | * _req_mod(req, DATA_RECEIVED) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1989 | * [from receive_DataReply] |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 1990 | * _req_mod(req, WRITE_ACKED_BY_PEER or RECV_ACKED_BY_PEER or NEG_ACKED) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1991 | * [from got_BlockAck (P_WRITE_ACK, P_RECV_ACK)] |
| 1992 | * for some reason it is NOT decreased in got_NegAck, |
| 1993 | * but in the resulting cleanup code from report_params. |
| 1994 | * we should try to remember the reason for that... |
Andreas Gruenbacher | 8554df1 | 2011-01-25 15:37:43 +0100 | [diff] [blame] | 1995 | * _req_mod(req, SEND_FAILED or SEND_CANCELED) |
| 1996 | * _req_mod(req, CONNECTION_LOST_WHILE_PENDING) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 1997 | * [from tl_clear_barrier] |
| 1998 | */ |
| 1999 | static inline void inc_ap_pending(struct drbd_conf *mdev) |
| 2000 | { |
| 2001 | atomic_inc(&mdev->ap_pending_cnt); |
| 2002 | } |
| 2003 | |
| 2004 | #define ERR_IF_CNT_IS_NEGATIVE(which) \ |
| 2005 | if (atomic_read(&mdev->which) < 0) \ |
| 2006 | dev_err(DEV, "in %s:%d: " #which " = %d < 0 !\n", \ |
| 2007 | __func__ , __LINE__ , \ |
| 2008 | atomic_read(&mdev->which)) |
| 2009 | |
| 2010 | #define dec_ap_pending(mdev) do { \ |
| 2011 | typecheck(struct drbd_conf *, mdev); \ |
| 2012 | if (atomic_dec_and_test(&mdev->ap_pending_cnt)) \ |
| 2013 | wake_up(&mdev->misc_wait); \ |
| 2014 | ERR_IF_CNT_IS_NEGATIVE(ap_pending_cnt); } while (0) |
| 2015 | |
| 2016 | /* counts how many resync-related answers we still expect from the peer |
| 2017 | * increase decrease |
| 2018 | * C_SYNC_TARGET sends P_RS_DATA_REQUEST (and expects P_RS_DATA_REPLY) |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2019 | * C_SYNC_SOURCE sends P_RS_DATA_REPLY (and expects P_WRITE_ACK with ID_SYNCER) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2020 | * (or P_NEG_ACK with ID_SYNCER) |
| 2021 | */ |
| 2022 | static inline void inc_rs_pending(struct drbd_conf *mdev) |
| 2023 | { |
| 2024 | atomic_inc(&mdev->rs_pending_cnt); |
| 2025 | } |
| 2026 | |
| 2027 | #define dec_rs_pending(mdev) do { \ |
| 2028 | typecheck(struct drbd_conf *, mdev); \ |
| 2029 | atomic_dec(&mdev->rs_pending_cnt); \ |
| 2030 | ERR_IF_CNT_IS_NEGATIVE(rs_pending_cnt); } while (0) |
| 2031 | |
| 2032 | /* counts how many answers we still need to send to the peer. |
| 2033 | * increased on |
| 2034 | * receive_Data unless protocol A; |
| 2035 | * we need to send a P_RECV_ACK (proto B) |
| 2036 | * or P_WRITE_ACK (proto C) |
| 2037 | * receive_RSDataReply (recv_resync_read) we need to send a P_WRITE_ACK |
| 2038 | * receive_DataRequest (receive_RSDataRequest) we need to send back P_DATA |
| 2039 | * receive_Barrier_* we need to send a P_BARRIER_ACK |
| 2040 | */ |
| 2041 | static inline void inc_unacked(struct drbd_conf *mdev) |
| 2042 | { |
| 2043 | atomic_inc(&mdev->unacked_cnt); |
| 2044 | } |
| 2045 | |
| 2046 | #define dec_unacked(mdev) do { \ |
| 2047 | typecheck(struct drbd_conf *, mdev); \ |
| 2048 | atomic_dec(&mdev->unacked_cnt); \ |
| 2049 | ERR_IF_CNT_IS_NEGATIVE(unacked_cnt); } while (0) |
| 2050 | |
| 2051 | #define sub_unacked(mdev, n) do { \ |
| 2052 | typecheck(struct drbd_conf *, mdev); \ |
| 2053 | atomic_sub(n, &mdev->unacked_cnt); \ |
| 2054 | ERR_IF_CNT_IS_NEGATIVE(unacked_cnt); } while (0) |
| 2055 | |
| 2056 | |
Philipp Reisner | b2fb6dbe | 2011-01-19 13:48:44 +0100 | [diff] [blame] | 2057 | static inline void put_net_conf(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2058 | { |
Philipp Reisner | b2fb6dbe | 2011-01-19 13:48:44 +0100 | [diff] [blame] | 2059 | if (atomic_dec_and_test(&tconn->net_cnt)) |
| 2060 | wake_up(&tconn->net_cnt_wait); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | /** |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2064 | * get_net_conf() - Increase ref count on mdev->tconn->net_conf; Returns 0 if nothing there |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2065 | * @mdev: DRBD device. |
| 2066 | * |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2067 | * You have to call put_net_conf() when finished working with mdev->tconn->net_conf. |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2068 | */ |
Philipp Reisner | b2fb6dbe | 2011-01-19 13:48:44 +0100 | [diff] [blame] | 2069 | static inline int get_net_conf(struct drbd_tconn *tconn) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2070 | { |
| 2071 | int have_net_conf; |
| 2072 | |
Philipp Reisner | b2fb6dbe | 2011-01-19 13:48:44 +0100 | [diff] [blame] | 2073 | atomic_inc(&tconn->net_cnt); |
| 2074 | have_net_conf = tconn->volume0->state.conn >= C_UNCONNECTED; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2075 | if (!have_net_conf) |
Philipp Reisner | b2fb6dbe | 2011-01-19 13:48:44 +0100 | [diff] [blame] | 2076 | put_net_conf(tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2077 | return have_net_conf; |
| 2078 | } |
| 2079 | |
| 2080 | /** |
| 2081 | * get_ldev() - Increase the ref count on mdev->ldev. Returns 0 if there is no ldev |
| 2082 | * @M: DRBD device. |
| 2083 | * |
| 2084 | * You have to call put_ldev() when finished working with mdev->ldev. |
| 2085 | */ |
| 2086 | #define get_ldev(M) __cond_lock(local, _get_ldev_if_state(M,D_INCONSISTENT)) |
| 2087 | #define get_ldev_if_state(M,MINS) __cond_lock(local, _get_ldev_if_state(M,MINS)) |
| 2088 | |
| 2089 | static inline void put_ldev(struct drbd_conf *mdev) |
| 2090 | { |
Lars Ellenberg | 1d7734a | 2010-08-11 21:21:50 +0200 | [diff] [blame] | 2091 | int i = atomic_dec_return(&mdev->local_cnt); |
Lars Ellenberg | 9a0d9d0 | 2011-05-02 11:51:31 +0200 | [diff] [blame] | 2092 | |
| 2093 | /* This may be called from some endio handler, |
| 2094 | * so we must not sleep here. */ |
| 2095 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2096 | __release(local); |
Lars Ellenberg | 1d7734a | 2010-08-11 21:21:50 +0200 | [diff] [blame] | 2097 | D_ASSERT(i >= 0); |
Lars Ellenberg | e9e6f3e | 2010-09-14 20:26:27 +0200 | [diff] [blame] | 2098 | if (i == 0) { |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 2099 | if (mdev->state.disk == D_DISKLESS) |
| 2100 | /* even internal references gone, safe to destroy */ |
| 2101 | drbd_ldev_destroy(mdev); |
Lars Ellenberg | e9e6f3e | 2010-09-14 20:26:27 +0200 | [diff] [blame] | 2102 | if (mdev->state.disk == D_FAILED) |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 2103 | /* all application IO references gone. */ |
Lars Ellenberg | e9e6f3e | 2010-09-14 20:26:27 +0200 | [diff] [blame] | 2104 | drbd_go_diskless(mdev); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2105 | wake_up(&mdev->misc_wait); |
Lars Ellenberg | e9e6f3e | 2010-09-14 20:26:27 +0200 | [diff] [blame] | 2106 | } |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | #ifndef __CHECKER__ |
| 2110 | static inline int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_state mins) |
| 2111 | { |
| 2112 | int io_allowed; |
| 2113 | |
Lars Ellenberg | 82f59cc | 2010-10-16 12:13:47 +0200 | [diff] [blame] | 2114 | /* never get a reference while D_DISKLESS */ |
| 2115 | if (mdev->state.disk == D_DISKLESS) |
| 2116 | return 0; |
| 2117 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2118 | atomic_inc(&mdev->local_cnt); |
| 2119 | io_allowed = (mdev->state.disk >= mins); |
| 2120 | if (!io_allowed) |
| 2121 | put_ldev(mdev); |
| 2122 | return io_allowed; |
| 2123 | } |
| 2124 | #else |
| 2125 | extern int _get_ldev_if_state(struct drbd_conf *mdev, enum drbd_disk_state mins); |
| 2126 | #endif |
| 2127 | |
| 2128 | /* you must have an "get_ldev" reference */ |
| 2129 | static inline void drbd_get_syncer_progress(struct drbd_conf *mdev, |
| 2130 | unsigned long *bits_left, unsigned int *per_mil_done) |
| 2131 | { |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 2132 | /* this is to break it at compile time when we change that, in case we |
| 2133 | * want to support more than (1<<32) bits on a 32bit arch. */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2134 | typecheck(unsigned long, mdev->rs_total); |
| 2135 | |
| 2136 | /* note: both rs_total and rs_left are in bits, i.e. in |
| 2137 | * units of BM_BLOCK_SIZE. |
| 2138 | * for the percentage, we don't care. */ |
| 2139 | |
Lars Ellenberg | 439d595 | 2010-11-05 09:52:46 +0100 | [diff] [blame] | 2140 | if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T) |
| 2141 | *bits_left = mdev->ov_left; |
| 2142 | else |
| 2143 | *bits_left = drbd_bm_total_weight(mdev) - mdev->rs_failed; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2144 | /* >> 10 to prevent overflow, |
| 2145 | * +1 to prevent division by zero */ |
| 2146 | if (*bits_left > mdev->rs_total) { |
| 2147 | /* doh. maybe a logic bug somewhere. |
| 2148 | * may also be just a race condition |
| 2149 | * between this and a disconnect during sync. |
| 2150 | * for now, just prevent in-kernel buffer overflow. |
| 2151 | */ |
| 2152 | smp_rmb(); |
| 2153 | dev_warn(DEV, "cs:%s rs_left=%lu > rs_total=%lu (rs_failed %lu)\n", |
| 2154 | drbd_conn_str(mdev->state.conn), |
| 2155 | *bits_left, mdev->rs_total, mdev->rs_failed); |
| 2156 | *per_mil_done = 0; |
| 2157 | } else { |
Lars Ellenberg | 4b0715f | 2010-12-14 15:13:04 +0100 | [diff] [blame] | 2158 | /* Make sure the division happens in long context. |
| 2159 | * We allow up to one petabyte storage right now, |
| 2160 | * at a granularity of 4k per bit that is 2**38 bits. |
| 2161 | * After shift right and multiplication by 1000, |
| 2162 | * this should still fit easily into a 32bit long, |
| 2163 | * so we don't need a 64bit division on 32bit arch. |
| 2164 | * Note: currently we don't support such large bitmaps on 32bit |
| 2165 | * arch anyways, but no harm done to be prepared for it here. |
| 2166 | */ |
| 2167 | unsigned int shift = mdev->rs_total >= (1ULL << 32) ? 16 : 10; |
| 2168 | unsigned long left = *bits_left >> shift; |
| 2169 | unsigned long total = 1UL + (mdev->rs_total >> shift); |
| 2170 | unsigned long tmp = 1000UL - left * 1000UL/total; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2171 | *per_mil_done = tmp; |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | |
| 2176 | /* this throttles on-the-fly application requests |
| 2177 | * according to max_buffers settings; |
| 2178 | * maybe re-implement using semaphores? */ |
| 2179 | static inline int drbd_get_max_buffers(struct drbd_conf *mdev) |
| 2180 | { |
| 2181 | int mxb = 1000000; /* arbitrary limit on open requests */ |
Philipp Reisner | b2fb6dbe | 2011-01-19 13:48:44 +0100 | [diff] [blame] | 2182 | if (get_net_conf(mdev->tconn)) { |
Philipp Reisner | 89e58e7 | 2011-01-19 13:12:45 +0100 | [diff] [blame] | 2183 | mxb = mdev->tconn->net_conf->max_buffers; |
Philipp Reisner | b2fb6dbe | 2011-01-19 13:48:44 +0100 | [diff] [blame] | 2184 | put_net_conf(mdev->tconn); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2185 | } |
| 2186 | return mxb; |
| 2187 | } |
| 2188 | |
Philipp Reisner | 3719094 | 2010-11-10 12:08:37 +0100 | [diff] [blame] | 2189 | static inline int drbd_state_is_stable(struct drbd_conf *mdev) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2190 | { |
Philipp Reisner | 3719094 | 2010-11-10 12:08:37 +0100 | [diff] [blame] | 2191 | union drbd_state s = mdev->state; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2192 | |
| 2193 | /* DO NOT add a default clause, we want the compiler to warn us |
| 2194 | * for any newly introduced state we may have forgotten to add here */ |
| 2195 | |
| 2196 | switch ((enum drbd_conns)s.conn) { |
| 2197 | /* new io only accepted when there is no connection, ... */ |
| 2198 | case C_STANDALONE: |
| 2199 | case C_WF_CONNECTION: |
| 2200 | /* ... or there is a well established connection. */ |
| 2201 | case C_CONNECTED: |
| 2202 | case C_SYNC_SOURCE: |
| 2203 | case C_SYNC_TARGET: |
| 2204 | case C_VERIFY_S: |
| 2205 | case C_VERIFY_T: |
| 2206 | case C_PAUSED_SYNC_S: |
| 2207 | case C_PAUSED_SYNC_T: |
Philipp Reisner | 6753171 | 2010-10-27 12:21:30 +0200 | [diff] [blame] | 2208 | case C_AHEAD: |
| 2209 | case C_BEHIND: |
Philipp Reisner | 3719094 | 2010-11-10 12:08:37 +0100 | [diff] [blame] | 2210 | /* transitional states, IO allowed */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2211 | case C_DISCONNECTING: |
| 2212 | case C_UNCONNECTED: |
| 2213 | case C_TIMEOUT: |
| 2214 | case C_BROKEN_PIPE: |
| 2215 | case C_NETWORK_FAILURE: |
| 2216 | case C_PROTOCOL_ERROR: |
| 2217 | case C_TEAR_DOWN: |
| 2218 | case C_WF_REPORT_PARAMS: |
| 2219 | case C_STARTING_SYNC_S: |
| 2220 | case C_STARTING_SYNC_T: |
Philipp Reisner | 3719094 | 2010-11-10 12:08:37 +0100 | [diff] [blame] | 2221 | break; |
| 2222 | |
| 2223 | /* Allow IO in BM exchange states with new protocols */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2224 | case C_WF_BITMAP_S: |
Philipp Reisner | 31890f4 | 2011-01-19 14:12:51 +0100 | [diff] [blame] | 2225 | if (mdev->tconn->agreed_pro_version < 96) |
Philipp Reisner | 3719094 | 2010-11-10 12:08:37 +0100 | [diff] [blame] | 2226 | return 0; |
| 2227 | break; |
| 2228 | |
| 2229 | /* no new io accepted in these states */ |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2230 | case C_WF_BITMAP_T: |
| 2231 | case C_WF_SYNC_UUID: |
| 2232 | case C_MASK: |
| 2233 | /* not "stable" */ |
| 2234 | return 0; |
| 2235 | } |
| 2236 | |
| 2237 | switch ((enum drbd_disk_state)s.disk) { |
| 2238 | case D_DISKLESS: |
| 2239 | case D_INCONSISTENT: |
| 2240 | case D_OUTDATED: |
| 2241 | case D_CONSISTENT: |
| 2242 | case D_UP_TO_DATE: |
| 2243 | /* disk state is stable as well. */ |
| 2244 | break; |
| 2245 | |
| 2246 | /* no new io accepted during tansitional states */ |
| 2247 | case D_ATTACHING: |
| 2248 | case D_FAILED: |
| 2249 | case D_NEGOTIATING: |
| 2250 | case D_UNKNOWN: |
| 2251 | case D_MASK: |
| 2252 | /* not "stable" */ |
| 2253 | return 0; |
| 2254 | } |
| 2255 | |
| 2256 | return 1; |
| 2257 | } |
| 2258 | |
Philipp Reisner | fb22c40 | 2010-09-08 23:20:21 +0200 | [diff] [blame] | 2259 | static inline int is_susp(union drbd_state s) |
| 2260 | { |
| 2261 | return s.susp || s.susp_nod || s.susp_fen; |
| 2262 | } |
| 2263 | |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2264 | static inline bool may_inc_ap_bio(struct drbd_conf *mdev) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2265 | { |
| 2266 | int mxb = drbd_get_max_buffers(mdev); |
| 2267 | |
Philipp Reisner | fb22c40 | 2010-09-08 23:20:21 +0200 | [diff] [blame] | 2268 | if (is_susp(mdev->state)) |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2269 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2270 | if (test_bit(SUSPEND_IO, &mdev->flags)) |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2271 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2272 | |
| 2273 | /* to avoid potential deadlock or bitmap corruption, |
| 2274 | * in various places, we only allow new application io |
| 2275 | * to start during "stable" states. */ |
| 2276 | |
| 2277 | /* no new io accepted when attaching or detaching the disk */ |
Philipp Reisner | 3719094 | 2010-11-10 12:08:37 +0100 | [diff] [blame] | 2278 | if (!drbd_state_is_stable(mdev)) |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2279 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2280 | |
| 2281 | /* since some older kernels don't have atomic_add_unless, |
| 2282 | * and we are within the spinlock anyways, we have this workaround. */ |
| 2283 | if (atomic_read(&mdev->ap_bio_cnt) > mxb) |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2284 | return false; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2285 | if (test_bit(BITMAP_IO, &mdev->flags)) |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2286 | return false; |
| 2287 | return true; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2290 | static inline bool inc_ap_bio_cond(struct drbd_conf *mdev, int count) |
Philipp Reisner | 8869d68 | 2010-11-17 18:24:19 +0100 | [diff] [blame] | 2291 | { |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2292 | bool rv = false; |
Philipp Reisner | 8869d68 | 2010-11-17 18:24:19 +0100 | [diff] [blame] | 2293 | |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2294 | spin_lock_irq(&mdev->tconn->req_lock); |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2295 | rv = may_inc_ap_bio(mdev); |
Philipp Reisner | 8869d68 | 2010-11-17 18:24:19 +0100 | [diff] [blame] | 2296 | if (rv) |
| 2297 | atomic_add(count, &mdev->ap_bio_cnt); |
Philipp Reisner | 87eeee4 | 2011-01-19 14:16:30 +0100 | [diff] [blame] | 2298 | spin_unlock_irq(&mdev->tconn->req_lock); |
Philipp Reisner | 8869d68 | 2010-11-17 18:24:19 +0100 | [diff] [blame] | 2299 | |
| 2300 | return rv; |
| 2301 | } |
| 2302 | |
Philipp Reisner | 9a25a04 | 2010-05-10 16:42:23 +0200 | [diff] [blame] | 2303 | static inline void inc_ap_bio(struct drbd_conf *mdev, int count) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2304 | { |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2305 | /* we wait here |
| 2306 | * as long as the device is suspended |
| 2307 | * until the bitmap is no longer on the fly during connection |
| 2308 | * handshake as long as we would exeed the max_buffer limit. |
| 2309 | * |
| 2310 | * to avoid races with the reconnect code, |
| 2311 | * we need to atomic_inc within the spinlock. */ |
| 2312 | |
Andreas Gruenbacher | 1b881ef | 2010-12-13 18:03:38 +0100 | [diff] [blame] | 2313 | wait_event(mdev->misc_wait, inc_ap_bio_cond(mdev, count)); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | static inline void dec_ap_bio(struct drbd_conf *mdev) |
| 2317 | { |
| 2318 | int mxb = drbd_get_max_buffers(mdev); |
| 2319 | int ap_bio = atomic_dec_return(&mdev->ap_bio_cnt); |
| 2320 | |
| 2321 | D_ASSERT(ap_bio >= 0); |
| 2322 | /* this currently does wake_up for every dec_ap_bio! |
| 2323 | * maybe rather introduce some type of hysteresis? |
| 2324 | * e.g. (ap_bio == mxb/2 || ap_bio == 0) ? */ |
| 2325 | if (ap_bio < mxb) |
| 2326 | wake_up(&mdev->misc_wait); |
| 2327 | if (ap_bio == 0 && test_bit(BITMAP_IO, &mdev->flags)) { |
| 2328 | if (!test_and_set_bit(BITMAP_IO_QUEUED, &mdev->flags)) |
Philipp Reisner | e42325a | 2011-01-19 13:55:45 +0100 | [diff] [blame] | 2329 | drbd_queue_work(&mdev->tconn->data.work, &mdev->bm_io_work.w); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2330 | } |
| 2331 | } |
| 2332 | |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 2333 | static inline int drbd_set_ed_uuid(struct drbd_conf *mdev, u64 val) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2334 | { |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 2335 | int changed = mdev->ed_uuid != val; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2336 | mdev->ed_uuid = val; |
Lars Ellenberg | 62b0da3 | 2011-01-20 13:25:21 +0100 | [diff] [blame] | 2337 | return changed; |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2340 | static inline int drbd_queue_order_type(struct drbd_conf *mdev) |
| 2341 | { |
| 2342 | /* sorry, we currently have no working implementation |
| 2343 | * of distributed TCQ stuff */ |
| 2344 | #ifndef QUEUE_ORDERED_NONE |
| 2345 | #define QUEUE_ORDERED_NONE 0 |
| 2346 | #endif |
| 2347 | return QUEUE_ORDERED_NONE; |
| 2348 | } |
| 2349 | |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2350 | static inline void drbd_md_flush(struct drbd_conf *mdev) |
| 2351 | { |
| 2352 | int r; |
| 2353 | |
Philipp Reisner | a8a4e51 | 2010-08-25 10:21:04 +0200 | [diff] [blame] | 2354 | if (test_bit(MD_NO_FUA, &mdev->flags)) |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2355 | return; |
| 2356 | |
Christoph Hellwig | dd3932e | 2010-09-16 20:51:46 +0200 | [diff] [blame] | 2357 | r = blkdev_issue_flush(mdev->ldev->md_bdev, GFP_KERNEL, NULL); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2358 | if (r) { |
Philipp Reisner | a8a4e51 | 2010-08-25 10:21:04 +0200 | [diff] [blame] | 2359 | set_bit(MD_NO_FUA, &mdev->flags); |
Philipp Reisner | b411b36 | 2009-09-25 16:07:19 -0700 | [diff] [blame] | 2360 | dev_err(DEV, "meta data flush failed with status %d, disabling md-flushes\n", r); |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | #endif |