blob: 3dbe9bd57a094b9b63175de44d6f9fd1022c322b [file] [log] [blame]
Philipp Reisnerb411b362009-09-25 16:07:19 -07001/*
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
Lucas De Marchi25985ed2011-03-30 22:57:33 -030039/* Although the Linux source code makes a difference between
Philipp Reisnerb411b362009-09-25 16:07:19 -070040 generic endianness and the bitfields' endianness, there is no
Bart Van Assche24c48302011-05-21 18:32:29 +020041 architecture as of Linux-2.6.24-rc4 where the bitfields' endianness
Philipp Reisnerb411b362009-09-25 16:07:19 -070042 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
Philipp Reisnerb411b362009-09-25 16:07:19 -070054extern const char *drbd_buildtag(void);
Philipp Reisner3990e042013-03-27 14:08:48 +010055#define REL_VERSION "8.4.3"
Philipp Reisner328e0f12012-10-19 14:37:47 +020056#define API_VERSION 1
Philipp Reisnerb411b362009-09-25 16:07:19 -070057#define PRO_VERSION_MIN 86
Lars Ellenberg58ffa582012-07-26 14:09:49 +020058#define PRO_VERSION_MAX 101
Philipp Reisnerb411b362009-09-25 16:07:19 -070059
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 {
Philipp Reisnercb703452011-03-24 11:03:07 +010068 FP_NOT_AVAIL = -1, /* Not a policy */
69 FP_DONT_CARE = 0,
Philipp Reisnerb411b362009-09-25 16:07:19 -070070 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
Philipp Reisner265be2d2010-05-31 10:14:17 +020094enum drbd_on_no_data {
95 OND_IO_ERROR,
96 OND_SUSPEND_IO
97};
98
Philipp Reisner422028b2010-10-27 11:12:07 +020099enum drbd_on_congestion {
100 OC_BLOCK,
101 OC_PULL_AHEAD,
102 OC_DISCONNECT,
103};
104
Philipp Reisner380207d2011-11-11 12:31:20 +0100105enum drbd_read_balancing {
106 RB_PREFER_LOCAL,
107 RB_PREFER_REMOTE,
108 RB_ROUND_ROBIN,
109 RB_LEAST_PENDING,
110 RB_CONGESTED_REMOTE,
Philipp Reisnerd60de032011-11-17 10:12:31 +0100111 RB_32K_STRIPING,
112 RB_64K_STRIPING,
113 RB_128K_STRIPING,
114 RB_256K_STRIPING,
115 RB_512K_STRIPING,
116 RB_1M_STRIPING,
Philipp Reisner380207d2011-11-11 12:31:20 +0100117};
118
Philipp Reisnerb411b362009-09-25 16:07:19 -0700119/* KEEP the order, do not delete or insert. Only append. */
Andreas Gruenbacher116676c2010-12-08 13:33:11 +0100120enum drbd_ret_code {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700121 ERR_CODE_BASE = 100,
122 NO_ERROR = 101,
123 ERR_LOCAL_ADDR = 102,
124 ERR_PEER_ADDR = 103,
125 ERR_OPEN_DISK = 104,
126 ERR_OPEN_MD_DISK = 105,
127 ERR_DISK_NOT_BDEV = 107,
128 ERR_MD_NOT_BDEV = 108,
Lars Ellenberg67b58bf2011-06-06 15:36:04 +0200129 ERR_DISK_TOO_SMALL = 111,
130 ERR_MD_DISK_TOO_SMALL = 112,
Philipp Reisnerb411b362009-09-25 16:07:19 -0700131 ERR_BDCLAIM_DISK = 114,
132 ERR_BDCLAIM_MD_DISK = 115,
133 ERR_MD_IDX_INVALID = 116,
134 ERR_IO_MD_DISK = 118,
135 ERR_MD_INVALID = 119,
136 ERR_AUTH_ALG = 120,
137 ERR_AUTH_ALG_ND = 121,
138 ERR_NOMEM = 122,
Lars Ellenbergeb120102012-08-01 12:46:20 +0200139 ERR_DISCARD_IMPOSSIBLE = 123,
Philipp Reisnerb411b362009-09-25 16:07:19 -0700140 ERR_DISK_CONFIGURED = 124,
141 ERR_NET_CONFIGURED = 125,
142 ERR_MANDATORY_TAG = 126,
143 ERR_MINOR_INVALID = 127,
144 ERR_INTR = 129, /* EINTR */
145 ERR_RESIZE_RESYNC = 130,
146 ERR_NO_PRIMARY = 131,
Andreas Gruenbacher95f8efd2011-05-12 11:15:34 +0200147 ERR_RESYNC_AFTER = 132,
148 ERR_RESYNC_AFTER_CYCLE = 133,
Philipp Reisnerb411b362009-09-25 16:07:19 -0700149 ERR_PAUSE_IS_SET = 134,
150 ERR_PAUSE_IS_CLEAR = 135,
151 ERR_PACKET_NR = 137,
152 ERR_NO_DISK = 138,
153 ERR_NOT_PROTO_C = 139,
154 ERR_NOMEM_BITMAP = 140,
155 ERR_INTEGRITY_ALG = 141, /* DRBD 8.2 only */
156 ERR_INTEGRITY_ALG_ND = 142, /* DRBD 8.2 only */
157 ERR_CPU_MASK_PARSE = 143, /* DRBD 8.2 only */
158 ERR_CSUMS_ALG = 144, /* DRBD 8.2 only */
159 ERR_CSUMS_ALG_ND = 145, /* DRBD 8.2 only */
160 ERR_VERIFY_ALG = 146, /* DRBD 8.2 only */
161 ERR_VERIFY_ALG_ND = 147, /* DRBD 8.2 only */
162 ERR_CSUMS_RESYNC_RUNNING= 148, /* DRBD 8.2 only */
163 ERR_VERIFY_RUNNING = 149, /* DRBD 8.2 only */
164 ERR_DATA_NOT_CURRENT = 150,
165 ERR_CONNECTED = 151, /* DRBD 8.3 only */
Philipp Reisner9f5180e2009-10-06 09:30:14 +0200166 ERR_PERM = 152,
Philipp Reisner6495d2c2010-03-24 16:07:04 +0100167 ERR_NEED_APV_93 = 153,
Philipp Reisner47ff2d02010-06-18 13:56:57 +0200168 ERR_STONITH_AND_PROT_A = 154,
Philipp Reisner422028b2010-10-27 11:12:07 +0200169 ERR_CONG_NOT_PROTO_A = 155,
Philipp Reisnercd88d032011-01-20 11:46:41 +0100170 ERR_PIC_AFTER_DEP = 156,
171 ERR_PIC_PEER_DEP = 157,
Andreas Gruenbacher789c1b62011-06-06 16:16:44 +0200172 ERR_RES_NOT_KNOWN = 158,
173 ERR_RES_IN_USE = 159,
Philipp Reisner774b3052011-02-22 02:07:03 -0500174 ERR_MINOR_CONFIGURED = 160,
175 ERR_MINOR_EXISTS = 161,
Lars Ellenberg3b98c0c2011-03-07 12:49:34 +0100176 ERR_INVALID_REQUEST = 162,
Philipp Reisnerb032b6f2011-04-13 18:16:10 -0700177 ERR_NEED_APV_100 = 163,
Philipp Reisnerdcb20d12011-05-16 14:30:24 +0200178 ERR_NEED_ALLOW_TWO_PRI = 164,
Lars Ellenbergd5d7ebd2011-07-05 20:59:26 +0200179 ERR_MD_UNCLEAN = 165,
Philipp Reisnerd752b262013-06-25 16:50:08 +0200180 ERR_MD_LAYOUT_CONNECTED = 166,
181 ERR_MD_LAYOUT_TOO_BIG = 167,
182 ERR_MD_LAYOUT_TOO_SMALL = 168,
183 ERR_MD_LAYOUT_NO_FIT = 169,
184 ERR_IMPLICIT_SHRINK = 170,
Philipp Reisnerb411b362009-09-25 16:07:19 -0700185 /* insert new ones above this line */
186 AFTER_LAST_ERR_CODE
187};
188
189#define DRBD_PROT_A 1
190#define DRBD_PROT_B 2
191#define DRBD_PROT_C 3
192
193enum drbd_role {
194 R_UNKNOWN = 0,
195 R_PRIMARY = 1, /* role */
196 R_SECONDARY = 2, /* role */
197 R_MASK = 3,
198};
199
200/* The order of these constants is important.
201 * The lower ones (<C_WF_REPORT_PARAMS) indicate
202 * that there is no socket!
203 * >=C_WF_REPORT_PARAMS ==> There is a socket
204 */
205enum drbd_conns {
206 C_STANDALONE,
207 C_DISCONNECTING, /* Temporal state on the way to StandAlone. */
208 C_UNCONNECTED, /* >= C_UNCONNECTED -> inc_net() succeeds */
209
210 /* These temporal states are all used on the way
211 * from >= C_CONNECTED to Unconnected.
212 * The 'disconnect reason' states
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300213 * I do not allow to change between them. */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700214 C_TIMEOUT,
215 C_BROKEN_PIPE,
216 C_NETWORK_FAILURE,
217 C_PROTOCOL_ERROR,
218 C_TEAR_DOWN,
219
220 C_WF_CONNECTION,
221 C_WF_REPORT_PARAMS, /* we have a socket */
222 C_CONNECTED, /* we have introduced each other */
223 C_STARTING_SYNC_S, /* starting full sync by admin request. */
Bart Van Assche24c48302011-05-21 18:32:29 +0200224 C_STARTING_SYNC_T, /* starting full sync by admin request. */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700225 C_WF_BITMAP_S,
226 C_WF_BITMAP_T,
227 C_WF_SYNC_UUID,
228
229 /* All SyncStates are tested with this comparison
230 * xx >= C_SYNC_SOURCE && xx <= C_PAUSED_SYNC_T */
231 C_SYNC_SOURCE,
232 C_SYNC_TARGET,
233 C_VERIFY_S,
234 C_VERIFY_T,
235 C_PAUSED_SYNC_S,
236 C_PAUSED_SYNC_T,
Philipp Reisner67531712010-10-27 12:21:30 +0200237
238 C_AHEAD,
239 C_BEHIND,
240
Philipp Reisnerb411b362009-09-25 16:07:19 -0700241 C_MASK = 31
242};
243
244enum drbd_disk_state {
245 D_DISKLESS,
246 D_ATTACHING, /* In the process of reading the meta-data */
247 D_FAILED, /* Becomes D_DISKLESS as soon as we told it the peer */
248 /* when >= D_FAILED it is legal to access mdev->bc */
249 D_NEGOTIATING, /* Late attaching state, we need to talk to the peer */
250 D_INCONSISTENT,
251 D_OUTDATED,
252 D_UNKNOWN, /* Only used for the peer, never for myself */
253 D_CONSISTENT, /* Might be D_OUTDATED, might be D_UP_TO_DATE ... */
254 D_UP_TO_DATE, /* Only this disk state allows applications' IO ! */
255 D_MASK = 15
256};
257
258union drbd_state {
259/* According to gcc's docs is the ...
260 * The order of allocation of bit-fields within a unit (C90 6.5.2.1, C99 6.7.2.1).
261 * Determined by ABI.
262 * pointed out by Maxim Uvarov q<muvarov@ru.mvista.com>
263 * even though we transmit as "cpu_to_be32(state)",
264 * the offsets of the bitfields still need to be swapped
Bart Van Assche24c48302011-05-21 18:32:29 +0200265 * on different endianness.
Philipp Reisnerb411b362009-09-25 16:07:19 -0700266 */
267 struct {
268#if defined(__LITTLE_ENDIAN_BITFIELD)
269 unsigned role:2 ; /* 3/4 primary/secondary/unknown */
270 unsigned peer:2 ; /* 3/4 primary/secondary/unknown */
271 unsigned conn:5 ; /* 17/32 cstates */
272 unsigned disk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
273 unsigned pdsk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
Philipp Reisnerfb22c402010-09-08 23:20:21 +0200274 unsigned susp:1 ; /* 2/2 IO suspended no/yes (by user) */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700275 unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
276 unsigned peer_isp:1 ;
277 unsigned user_isp:1 ;
Philipp Reisnerfb22c402010-09-08 23:20:21 +0200278 unsigned susp_nod:1 ; /* IO suspended because no data */
279 unsigned susp_fen:1 ; /* IO suspended because fence peer handler runs*/
280 unsigned _pad:9; /* 0 unused */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700281#elif defined(__BIG_ENDIAN_BITFIELD)
Philipp Reisnerfb22c402010-09-08 23:20:21 +0200282 unsigned _pad:9;
283 unsigned susp_fen:1 ;
284 unsigned susp_nod:1 ;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700285 unsigned user_isp:1 ;
286 unsigned peer_isp:1 ;
287 unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
288 unsigned susp:1 ; /* 2/2 IO suspended no/yes */
289 unsigned pdsk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
290 unsigned disk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
291 unsigned conn:5 ; /* 17/32 cstates */
292 unsigned peer:2 ; /* 3/4 primary/secondary/unknown */
293 unsigned role:2 ; /* 3/4 primary/secondary/unknown */
294#else
Bart Van Assche24c48302011-05-21 18:32:29 +0200295# error "this endianness is not supported"
Philipp Reisnerb411b362009-09-25 16:07:19 -0700296#endif
297 };
298 unsigned int i;
299};
300
Andreas Gruenbacherc8b32562010-12-08 01:06:16 +0100301enum drbd_state_rv {
Philipp Reisnerb411b362009-09-25 16:07:19 -0700302 SS_CW_NO_NEED = 4,
303 SS_CW_SUCCESS = 3,
304 SS_NOTHING_TO_DO = 2,
305 SS_SUCCESS = 1,
306 SS_UNKNOWN_ERROR = 0, /* Used to sleep longer in _drbd_request_state */
307 SS_TWO_PRIMARIES = -1,
308 SS_NO_UP_TO_DATE_DISK = -2,
309 SS_NO_LOCAL_DISK = -4,
310 SS_NO_REMOTE_DISK = -5,
311 SS_CONNECTED_OUTDATES = -6,
312 SS_PRIMARY_NOP = -7,
313 SS_RESYNC_RUNNING = -8,
314 SS_ALREADY_STANDALONE = -9,
315 SS_CW_FAILED_BY_PEER = -10,
316 SS_IS_DISKLESS = -11,
317 SS_DEVICE_IN_USE = -12,
318 SS_NO_NET_CONFIG = -13,
319 SS_NO_VERIFY_ALG = -14, /* drbd-8.2 only */
320 SS_NEED_CONNECTION = -15, /* drbd-8.2 only */
321 SS_LOWER_THAN_OUTDATED = -16,
322 SS_NOT_SUPPORTED = -17, /* drbd-8.2 only */
323 SS_IN_TRANSIENT_STATE = -18, /* Retry after the next state change */
324 SS_CONCURRENT_ST_CHG = -19, /* Concurrent cluster side state change! */
Philipp Reisner047e95e22011-03-16 14:43:36 +0100325 SS_O_VOL_PEER_PRI = -20,
Philipp Reisner2bd5ed52013-03-27 14:08:40 +0100326 SS_OUTDATE_WO_CONN = -21,
327 SS_AFTER_LAST_ERROR = -22, /* Keep this at bottom */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700328};
329
Philipp Reisnerb411b362009-09-25 16:07:19 -0700330#define SHARED_SECRET_MAX 64
331
332#define MDF_CONSISTENT (1 << 0)
333#define MDF_PRIMARY_IND (1 << 1)
334#define MDF_CONNECTED_IND (1 << 2)
335#define MDF_FULL_SYNC (1 << 3)
336#define MDF_WAS_UP_TO_DATE (1 << 4)
337#define MDF_PEER_OUT_DATED (1 << 5)
Lars Ellenbergd5d7ebd2011-07-05 20:59:26 +0200338#define MDF_CRASHED_PRIMARY (1 << 6)
339#define MDF_AL_CLEAN (1 << 7)
Philipp Reisner9a51ab12012-02-20 21:53:28 +0100340#define MDF_AL_DISABLED (1 << 8)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700341
342enum drbd_uuid_index {
343 UI_CURRENT,
344 UI_BITMAP,
345 UI_HISTORY_START,
346 UI_HISTORY_END,
347 UI_SIZE, /* nl-packet: number of dirty bits */
348 UI_FLAGS, /* nl-packet: flags */
349 UI_EXTENDED_SIZE /* Everything. */
350};
351
352enum drbd_timeout_flag {
353 UT_DEFAULT = 0,
354 UT_DEGRADED = 1,
355 UT_PEER_OUTDATED = 2,
356};
357
358#define UUID_JUST_CREATED ((__u64)4)
359
Lars Ellenbergd5d7ebd2011-07-05 20:59:26 +0200360/* magic numbers used in meta data and network packets */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700361#define DRBD_MAGIC 0x83740267
Philipp Reisner0b70a132010-08-20 13:36:10 +0200362#define DRBD_MAGIC_BIG 0x835a
Andreas Gruenbacher0c8e36d2011-03-30 16:00:17 +0200363#define DRBD_MAGIC_100 0x8620ec20
Philipp Reisnerb411b362009-09-25 16:07:19 -0700364
Lars Ellenbergd5d7ebd2011-07-05 20:59:26 +0200365#define DRBD_MD_MAGIC_07 (DRBD_MAGIC+3)
366#define DRBD_MD_MAGIC_08 (DRBD_MAGIC+4)
367#define DRBD_MD_MAGIC_84_UNCLEAN (DRBD_MAGIC+5)
368
369
Lars Ellenberg7ad651b2011-02-21 13:21:03 +0100370/* how I came up with this magic?
371 * base64 decode "actlog==" ;) */
372#define DRBD_AL_MAGIC 0x69cb65a2
373
Philipp Reisnerb411b362009-09-25 16:07:19 -0700374/* these are of type "int" */
375#define DRBD_MD_INDEX_INTERNAL -1
376#define DRBD_MD_INDEX_FLEX_EXT -2
377#define DRBD_MD_INDEX_FLEX_INT -3
378
Andreas Gruenbacherf44d0432011-07-22 13:53:19 +0200379#define DRBD_CPU_MASK_SIZE 32
380
Philipp Reisnerb411b362009-09-25 16:07:19 -0700381#endif