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