drbd: Load balancing of read requests
[linux-block.git] / include / linux / drbd.h
CommitLineData
b411b363
PR
1/*
2 drbd.h
3 Kernel module for 2.6.x Kernels
4
5 This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
6
7 Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
8 Copyright (C) 2001-2008, Philipp Reisner <philipp.reisner@linbit.com>.
9 Copyright (C) 2001-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
10
11 drbd is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
14 any later version.
15
16 drbd is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with drbd; see the file COPYING. If not, write to
23 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25*/
26#ifndef DRBD_H
27#define DRBD_H
28#include <linux/connector.h>
29#include <asm/types.h>
30
31#ifdef __KERNEL__
32#include <linux/types.h>
33#include <asm/byteorder.h>
34#else
35#include <sys/types.h>
36#include <sys/wait.h>
37#include <limits.h>
38
25985edc 39/* Although the Linux source code makes a difference between
b411b363 40 generic endianness and the bitfields' endianness, there is no
24c4830c 41 architecture as of Linux-2.6.24-rc4 where the bitfields' endianness
b411b363
PR
42 does not match the generic endianness. */
43
44#if __BYTE_ORDER == __LITTLE_ENDIAN
45#define __LITTLE_ENDIAN_BITFIELD
46#elif __BYTE_ORDER == __BIG_ENDIAN
47#define __BIG_ENDIAN_BITFIELD
48#else
49# error "sorry, weird endianness on this box"
50#endif
51
52#endif
53
b411b363 54extern const char *drbd_buildtag(void);
9a0d9d03 55#define REL_VERSION "8.3.11"
b411b363
PR
56#define API_VERSION 88
57#define PRO_VERSION_MIN 86
fd340c12 58#define PRO_VERSION_MAX 100
b411b363
PR
59
60
61enum drbd_io_error_p {
62 EP_PASS_ON, /* FIXME should the better be named "Ignore"? */
63 EP_CALL_HELPER,
64 EP_DETACH
65};
66
67enum drbd_fencing_p {
cb703454
PR
68 FP_NOT_AVAIL = -1, /* Not a policy */
69 FP_DONT_CARE = 0,
b411b363
PR
70 FP_RESOURCE,
71 FP_STONITH
72};
73
74enum drbd_disconnect_p {
75 DP_RECONNECT,
76 DP_DROP_NET_CONF,
77 DP_FREEZE_IO
78};
79
80enum drbd_after_sb_p {
81 ASB_DISCONNECT,
82 ASB_DISCARD_YOUNGER_PRI,
83 ASB_DISCARD_OLDER_PRI,
84 ASB_DISCARD_ZERO_CHG,
85 ASB_DISCARD_LEAST_CHG,
86 ASB_DISCARD_LOCAL,
87 ASB_DISCARD_REMOTE,
88 ASB_CONSENSUS,
89 ASB_DISCARD_SECONDARY,
90 ASB_CALL_HELPER,
91 ASB_VIOLENTLY
92};
93
265be2d0
PR
94enum drbd_on_no_data {
95 OND_IO_ERROR,
96 OND_SUSPEND_IO
97};
98
422028b1
PR
99enum drbd_on_congestion {
100 OC_BLOCK,
101 OC_PULL_AHEAD,
102 OC_DISCONNECT,
103};
104
380207d0
PR
105enum drbd_read_balancing {
106 RB_PREFER_LOCAL,
107 RB_PREFER_REMOTE,
108 RB_ROUND_ROBIN,
109 RB_LEAST_PENDING,
110 RB_CONGESTED_REMOTE,
111};
112
b411b363 113/* KEEP the order, do not delete or insert. Only append. */
116676ca 114enum drbd_ret_code {
b411b363
PR
115 ERR_CODE_BASE = 100,
116 NO_ERROR = 101,
117 ERR_LOCAL_ADDR = 102,
118 ERR_PEER_ADDR = 103,
119 ERR_OPEN_DISK = 104,
120 ERR_OPEN_MD_DISK = 105,
121 ERR_DISK_NOT_BDEV = 107,
122 ERR_MD_NOT_BDEV = 108,
67b58bf7
LE
123 ERR_DISK_TOO_SMALL = 111,
124 ERR_MD_DISK_TOO_SMALL = 112,
b411b363
PR
125 ERR_BDCLAIM_DISK = 114,
126 ERR_BDCLAIM_MD_DISK = 115,
127 ERR_MD_IDX_INVALID = 116,
128 ERR_IO_MD_DISK = 118,
129 ERR_MD_INVALID = 119,
130 ERR_AUTH_ALG = 120,
131 ERR_AUTH_ALG_ND = 121,
132 ERR_NOMEM = 122,
133 ERR_DISCARD = 123,
134 ERR_DISK_CONFIGURED = 124,
135 ERR_NET_CONFIGURED = 125,
136 ERR_MANDATORY_TAG = 126,
137 ERR_MINOR_INVALID = 127,
138 ERR_INTR = 129, /* EINTR */
139 ERR_RESIZE_RESYNC = 130,
140 ERR_NO_PRIMARY = 131,
95f8efd0
AG
141 ERR_RESYNC_AFTER = 132,
142 ERR_RESYNC_AFTER_CYCLE = 133,
b411b363
PR
143 ERR_PAUSE_IS_SET = 134,
144 ERR_PAUSE_IS_CLEAR = 135,
145 ERR_PACKET_NR = 137,
146 ERR_NO_DISK = 138,
147 ERR_NOT_PROTO_C = 139,
148 ERR_NOMEM_BITMAP = 140,
149 ERR_INTEGRITY_ALG = 141, /* DRBD 8.2 only */
150 ERR_INTEGRITY_ALG_ND = 142, /* DRBD 8.2 only */
151 ERR_CPU_MASK_PARSE = 143, /* DRBD 8.2 only */
152 ERR_CSUMS_ALG = 144, /* DRBD 8.2 only */
153 ERR_CSUMS_ALG_ND = 145, /* DRBD 8.2 only */
154 ERR_VERIFY_ALG = 146, /* DRBD 8.2 only */
155 ERR_VERIFY_ALG_ND = 147, /* DRBD 8.2 only */
156 ERR_CSUMS_RESYNC_RUNNING= 148, /* DRBD 8.2 only */
157 ERR_VERIFY_RUNNING = 149, /* DRBD 8.2 only */
158 ERR_DATA_NOT_CURRENT = 150,
159 ERR_CONNECTED = 151, /* DRBD 8.3 only */
9f5180e5 160 ERR_PERM = 152,
6495d2c6 161 ERR_NEED_APV_93 = 153,
47ff2d0a 162 ERR_STONITH_AND_PROT_A = 154,
422028b1 163 ERR_CONG_NOT_PROTO_A = 155,
cd88d030
PR
164 ERR_PIC_AFTER_DEP = 156,
165 ERR_PIC_PEER_DEP = 157,
789c1b62
AG
166 ERR_RES_NOT_KNOWN = 158,
167 ERR_RES_IN_USE = 159,
774b3055
PR
168 ERR_MINOR_CONFIGURED = 160,
169 ERR_MINOR_EXISTS = 161,
3b98c0c2 170 ERR_INVALID_REQUEST = 162,
b032b6fa 171 ERR_NEED_APV_100 = 163,
dcb20d1a 172 ERR_NEED_ALLOW_TWO_PRI = 164,
d5d7ebd4 173 ERR_MD_UNCLEAN = 165,
b411b363
PR
174
175 /* insert new ones above this line */
176 AFTER_LAST_ERR_CODE
177};
178
179#define DRBD_PROT_A 1
180#define DRBD_PROT_B 2
181#define DRBD_PROT_C 3
182
183enum drbd_role {
184 R_UNKNOWN = 0,
185 R_PRIMARY = 1, /* role */
186 R_SECONDARY = 2, /* role */
187 R_MASK = 3,
188};
189
190/* The order of these constants is important.
191 * The lower ones (<C_WF_REPORT_PARAMS) indicate
192 * that there is no socket!
193 * >=C_WF_REPORT_PARAMS ==> There is a socket
194 */
195enum drbd_conns {
196 C_STANDALONE,
197 C_DISCONNECTING, /* Temporal state on the way to StandAlone. */
198 C_UNCONNECTED, /* >= C_UNCONNECTED -> inc_net() succeeds */
199
200 /* These temporal states are all used on the way
201 * from >= C_CONNECTED to Unconnected.
202 * The 'disconnect reason' states
25985edc 203 * I do not allow to change between them. */
b411b363
PR
204 C_TIMEOUT,
205 C_BROKEN_PIPE,
206 C_NETWORK_FAILURE,
207 C_PROTOCOL_ERROR,
208 C_TEAR_DOWN,
209
210 C_WF_CONNECTION,
211 C_WF_REPORT_PARAMS, /* we have a socket */
212 C_CONNECTED, /* we have introduced each other */
213 C_STARTING_SYNC_S, /* starting full sync by admin request. */
24c4830c 214 C_STARTING_SYNC_T, /* starting full sync by admin request. */
b411b363
PR
215 C_WF_BITMAP_S,
216 C_WF_BITMAP_T,
217 C_WF_SYNC_UUID,
218
219 /* All SyncStates are tested with this comparison
220 * xx >= C_SYNC_SOURCE && xx <= C_PAUSED_SYNC_T */
221 C_SYNC_SOURCE,
222 C_SYNC_TARGET,
223 C_VERIFY_S,
224 C_VERIFY_T,
225 C_PAUSED_SYNC_S,
226 C_PAUSED_SYNC_T,
67531718
PR
227
228 C_AHEAD,
229 C_BEHIND,
230
b411b363
PR
231 C_MASK = 31
232};
233
234enum drbd_disk_state {
235 D_DISKLESS,
236 D_ATTACHING, /* In the process of reading the meta-data */
237 D_FAILED, /* Becomes D_DISKLESS as soon as we told it the peer */
238 /* when >= D_FAILED it is legal to access mdev->bc */
239 D_NEGOTIATING, /* Late attaching state, we need to talk to the peer */
240 D_INCONSISTENT,
241 D_OUTDATED,
242 D_UNKNOWN, /* Only used for the peer, never for myself */
243 D_CONSISTENT, /* Might be D_OUTDATED, might be D_UP_TO_DATE ... */
244 D_UP_TO_DATE, /* Only this disk state allows applications' IO ! */
245 D_MASK = 15
246};
247
248union drbd_state {
249/* According to gcc's docs is the ...
250 * The order of allocation of bit-fields within a unit (C90 6.5.2.1, C99 6.7.2.1).
251 * Determined by ABI.
252 * pointed out by Maxim Uvarov q<muvarov@ru.mvista.com>
253 * even though we transmit as "cpu_to_be32(state)",
254 * the offsets of the bitfields still need to be swapped
24c4830c 255 * on different endianness.
b411b363
PR
256 */
257 struct {
258#if defined(__LITTLE_ENDIAN_BITFIELD)
259 unsigned role:2 ; /* 3/4 primary/secondary/unknown */
260 unsigned peer:2 ; /* 3/4 primary/secondary/unknown */
261 unsigned conn:5 ; /* 17/32 cstates */
262 unsigned disk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
263 unsigned pdsk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
fb22c402 264 unsigned susp:1 ; /* 2/2 IO suspended no/yes (by user) */
b411b363
PR
265 unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
266 unsigned peer_isp:1 ;
267 unsigned user_isp:1 ;
fb22c402
PR
268 unsigned susp_nod:1 ; /* IO suspended because no data */
269 unsigned susp_fen:1 ; /* IO suspended because fence peer handler runs*/
270 unsigned _pad:9; /* 0 unused */
b411b363 271#elif defined(__BIG_ENDIAN_BITFIELD)
fb22c402
PR
272 unsigned _pad:9;
273 unsigned susp_fen:1 ;
274 unsigned susp_nod:1 ;
b411b363
PR
275 unsigned user_isp:1 ;
276 unsigned peer_isp:1 ;
277 unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
278 unsigned susp:1 ; /* 2/2 IO suspended no/yes */
279 unsigned pdsk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
280 unsigned disk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
281 unsigned conn:5 ; /* 17/32 cstates */
282 unsigned peer:2 ; /* 3/4 primary/secondary/unknown */
283 unsigned role:2 ; /* 3/4 primary/secondary/unknown */
284#else
24c4830c 285# error "this endianness is not supported"
b411b363
PR
286#endif
287 };
288 unsigned int i;
289};
290
c8b32563 291enum drbd_state_rv {
b411b363
PR
292 SS_CW_NO_NEED = 4,
293 SS_CW_SUCCESS = 3,
294 SS_NOTHING_TO_DO = 2,
295 SS_SUCCESS = 1,
296 SS_UNKNOWN_ERROR = 0, /* Used to sleep longer in _drbd_request_state */
297 SS_TWO_PRIMARIES = -1,
298 SS_NO_UP_TO_DATE_DISK = -2,
299 SS_NO_LOCAL_DISK = -4,
300 SS_NO_REMOTE_DISK = -5,
301 SS_CONNECTED_OUTDATES = -6,
302 SS_PRIMARY_NOP = -7,
303 SS_RESYNC_RUNNING = -8,
304 SS_ALREADY_STANDALONE = -9,
305 SS_CW_FAILED_BY_PEER = -10,
306 SS_IS_DISKLESS = -11,
307 SS_DEVICE_IN_USE = -12,
308 SS_NO_NET_CONFIG = -13,
309 SS_NO_VERIFY_ALG = -14, /* drbd-8.2 only */
310 SS_NEED_CONNECTION = -15, /* drbd-8.2 only */
311 SS_LOWER_THAN_OUTDATED = -16,
312 SS_NOT_SUPPORTED = -17, /* drbd-8.2 only */
313 SS_IN_TRANSIENT_STATE = -18, /* Retry after the next state change */
314 SS_CONCURRENT_ST_CHG = -19, /* Concurrent cluster side state change! */
047e95e2
PR
315 SS_O_VOL_PEER_PRI = -20,
316 SS_AFTER_LAST_ERROR = -21, /* Keep this at bottom */
b411b363
PR
317};
318
319/* from drbd_strings.c */
320extern const char *drbd_conn_str(enum drbd_conns);
321extern const char *drbd_role_str(enum drbd_role);
322extern const char *drbd_disk_str(enum drbd_disk_state);
c8b32563 323extern const char *drbd_set_st_err_str(enum drbd_state_rv);
b411b363
PR
324
325#define SHARED_SECRET_MAX 64
326
327#define MDF_CONSISTENT (1 << 0)
328#define MDF_PRIMARY_IND (1 << 1)
329#define MDF_CONNECTED_IND (1 << 2)
330#define MDF_FULL_SYNC (1 << 3)
331#define MDF_WAS_UP_TO_DATE (1 << 4)
332#define MDF_PEER_OUT_DATED (1 << 5)
d5d7ebd4
LE
333#define MDF_CRASHED_PRIMARY (1 << 6)
334#define MDF_AL_CLEAN (1 << 7)
b411b363
PR
335
336enum drbd_uuid_index {
337 UI_CURRENT,
338 UI_BITMAP,
339 UI_HISTORY_START,
340 UI_HISTORY_END,
341 UI_SIZE, /* nl-packet: number of dirty bits */
342 UI_FLAGS, /* nl-packet: flags */
343 UI_EXTENDED_SIZE /* Everything. */
344};
345
346enum drbd_timeout_flag {
347 UT_DEFAULT = 0,
348 UT_DEGRADED = 1,
349 UT_PEER_OUTDATED = 2,
350};
351
352#define UUID_JUST_CREATED ((__u64)4)
353
d5d7ebd4 354/* magic numbers used in meta data and network packets */
b411b363 355#define DRBD_MAGIC 0x83740267
0b70a13d 356#define DRBD_MAGIC_BIG 0x835a
0c8e36d9 357#define DRBD_MAGIC_100 0x8620ec20
b411b363 358
d5d7ebd4
LE
359#define DRBD_MD_MAGIC_07 (DRBD_MAGIC+3)
360#define DRBD_MD_MAGIC_08 (DRBD_MAGIC+4)
361#define DRBD_MD_MAGIC_84_UNCLEAN (DRBD_MAGIC+5)
362
363
7ad651b5
LE
364/* how I came up with this magic?
365 * base64 decode "actlog==" ;) */
366#define DRBD_AL_MAGIC 0x69cb65a2
367
b411b363
PR
368/* these are of type "int" */
369#define DRBD_MD_INDEX_INTERNAL -1
370#define DRBD_MD_INDEX_FLEX_EXT -2
371#define DRBD_MD_INDEX_FLEX_INT -3
372
b411b363 373#endif