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