drbd.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. drbd.h
  3. Kernel module for 2.6.x Kernels
  4. This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
  5. Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
  6. Copyright (C) 2001-2008, Philipp Reisner <philipp.reisner@linbit.com>.
  7. Copyright (C) 2001-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
  8. drbd is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12. drbd is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with drbd; see the file COPYING. If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #ifndef DRBD_H
  21. #define DRBD_H
  22. #include <linux/connector.h>
  23. #include <asm/types.h>
  24. #ifdef __KERNEL__
  25. #include <linux/types.h>
  26. #include <asm/byteorder.h>
  27. #else
  28. #include <sys/types.h>
  29. #include <sys/wait.h>
  30. #include <limits.h>
  31. /* Altough the Linux source code makes a difference between
  32. generic endianness and the bitfields' endianness, there is no
  33. architecture as of Linux-2.6.24-rc4 where the bitfileds' endianness
  34. does not match the generic endianness. */
  35. #if __BYTE_ORDER == __LITTLE_ENDIAN
  36. #define __LITTLE_ENDIAN_BITFIELD
  37. #elif __BYTE_ORDER == __BIG_ENDIAN
  38. #define __BIG_ENDIAN_BITFIELD
  39. #else
  40. # error "sorry, weird endianness on this box"
  41. #endif
  42. #endif
  43. extern const char *drbd_buildtag(void);
  44. #define REL_VERSION "8.3.8.1"
  45. #define API_VERSION 88
  46. #define PRO_VERSION_MIN 86
  47. #define PRO_VERSION_MAX 94
  48. enum drbd_io_error_p {
  49. EP_PASS_ON, /* FIXME should the better be named "Ignore"? */
  50. EP_CALL_HELPER,
  51. EP_DETACH
  52. };
  53. enum drbd_fencing_p {
  54. FP_DONT_CARE,
  55. FP_RESOURCE,
  56. FP_STONITH
  57. };
  58. enum drbd_disconnect_p {
  59. DP_RECONNECT,
  60. DP_DROP_NET_CONF,
  61. DP_FREEZE_IO
  62. };
  63. enum drbd_after_sb_p {
  64. ASB_DISCONNECT,
  65. ASB_DISCARD_YOUNGER_PRI,
  66. ASB_DISCARD_OLDER_PRI,
  67. ASB_DISCARD_ZERO_CHG,
  68. ASB_DISCARD_LEAST_CHG,
  69. ASB_DISCARD_LOCAL,
  70. ASB_DISCARD_REMOTE,
  71. ASB_CONSENSUS,
  72. ASB_DISCARD_SECONDARY,
  73. ASB_CALL_HELPER,
  74. ASB_VIOLENTLY
  75. };
  76. /* KEEP the order, do not delete or insert. Only append. */
  77. enum drbd_ret_codes {
  78. ERR_CODE_BASE = 100,
  79. NO_ERROR = 101,
  80. ERR_LOCAL_ADDR = 102,
  81. ERR_PEER_ADDR = 103,
  82. ERR_OPEN_DISK = 104,
  83. ERR_OPEN_MD_DISK = 105,
  84. ERR_DISK_NOT_BDEV = 107,
  85. ERR_MD_NOT_BDEV = 108,
  86. ERR_DISK_TO_SMALL = 111,
  87. ERR_MD_DISK_TO_SMALL = 112,
  88. ERR_BDCLAIM_DISK = 114,
  89. ERR_BDCLAIM_MD_DISK = 115,
  90. ERR_MD_IDX_INVALID = 116,
  91. ERR_IO_MD_DISK = 118,
  92. ERR_MD_INVALID = 119,
  93. ERR_AUTH_ALG = 120,
  94. ERR_AUTH_ALG_ND = 121,
  95. ERR_NOMEM = 122,
  96. ERR_DISCARD = 123,
  97. ERR_DISK_CONFIGURED = 124,
  98. ERR_NET_CONFIGURED = 125,
  99. ERR_MANDATORY_TAG = 126,
  100. ERR_MINOR_INVALID = 127,
  101. ERR_INTR = 129, /* EINTR */
  102. ERR_RESIZE_RESYNC = 130,
  103. ERR_NO_PRIMARY = 131,
  104. ERR_SYNC_AFTER = 132,
  105. ERR_SYNC_AFTER_CYCLE = 133,
  106. ERR_PAUSE_IS_SET = 134,
  107. ERR_PAUSE_IS_CLEAR = 135,
  108. ERR_PACKET_NR = 137,
  109. ERR_NO_DISK = 138,
  110. ERR_NOT_PROTO_C = 139,
  111. ERR_NOMEM_BITMAP = 140,
  112. ERR_INTEGRITY_ALG = 141, /* DRBD 8.2 only */
  113. ERR_INTEGRITY_ALG_ND = 142, /* DRBD 8.2 only */
  114. ERR_CPU_MASK_PARSE = 143, /* DRBD 8.2 only */
  115. ERR_CSUMS_ALG = 144, /* DRBD 8.2 only */
  116. ERR_CSUMS_ALG_ND = 145, /* DRBD 8.2 only */
  117. ERR_VERIFY_ALG = 146, /* DRBD 8.2 only */
  118. ERR_VERIFY_ALG_ND = 147, /* DRBD 8.2 only */
  119. ERR_CSUMS_RESYNC_RUNNING= 148, /* DRBD 8.2 only */
  120. ERR_VERIFY_RUNNING = 149, /* DRBD 8.2 only */
  121. ERR_DATA_NOT_CURRENT = 150,
  122. ERR_CONNECTED = 151, /* DRBD 8.3 only */
  123. ERR_PERM = 152,
  124. ERR_NEED_APV_93 = 153,
  125. /* insert new ones above this line */
  126. AFTER_LAST_ERR_CODE
  127. };
  128. #define DRBD_PROT_A 1
  129. #define DRBD_PROT_B 2
  130. #define DRBD_PROT_C 3
  131. enum drbd_role {
  132. R_UNKNOWN = 0,
  133. R_PRIMARY = 1, /* role */
  134. R_SECONDARY = 2, /* role */
  135. R_MASK = 3,
  136. };
  137. /* The order of these constants is important.
  138. * The lower ones (<C_WF_REPORT_PARAMS) indicate
  139. * that there is no socket!
  140. * >=C_WF_REPORT_PARAMS ==> There is a socket
  141. */
  142. enum drbd_conns {
  143. C_STANDALONE,
  144. C_DISCONNECTING, /* Temporal state on the way to StandAlone. */
  145. C_UNCONNECTED, /* >= C_UNCONNECTED -> inc_net() succeeds */
  146. /* These temporal states are all used on the way
  147. * from >= C_CONNECTED to Unconnected.
  148. * The 'disconnect reason' states
  149. * I do not allow to change beween them. */
  150. C_TIMEOUT,
  151. C_BROKEN_PIPE,
  152. C_NETWORK_FAILURE,
  153. C_PROTOCOL_ERROR,
  154. C_TEAR_DOWN,
  155. C_WF_CONNECTION,
  156. C_WF_REPORT_PARAMS, /* we have a socket */
  157. C_CONNECTED, /* we have introduced each other */
  158. C_STARTING_SYNC_S, /* starting full sync by admin request. */
  159. C_STARTING_SYNC_T, /* stariing full sync by admin request. */
  160. C_WF_BITMAP_S,
  161. C_WF_BITMAP_T,
  162. C_WF_SYNC_UUID,
  163. /* All SyncStates are tested with this comparison
  164. * xx >= C_SYNC_SOURCE && xx <= C_PAUSED_SYNC_T */
  165. C_SYNC_SOURCE,
  166. C_SYNC_TARGET,
  167. C_VERIFY_S,
  168. C_VERIFY_T,
  169. C_PAUSED_SYNC_S,
  170. C_PAUSED_SYNC_T,
  171. C_MASK = 31
  172. };
  173. enum drbd_disk_state {
  174. D_DISKLESS,
  175. D_ATTACHING, /* In the process of reading the meta-data */
  176. D_FAILED, /* Becomes D_DISKLESS as soon as we told it the peer */
  177. /* when >= D_FAILED it is legal to access mdev->bc */
  178. D_NEGOTIATING, /* Late attaching state, we need to talk to the peer */
  179. D_INCONSISTENT,
  180. D_OUTDATED,
  181. D_UNKNOWN, /* Only used for the peer, never for myself */
  182. D_CONSISTENT, /* Might be D_OUTDATED, might be D_UP_TO_DATE ... */
  183. D_UP_TO_DATE, /* Only this disk state allows applications' IO ! */
  184. D_MASK = 15
  185. };
  186. union drbd_state {
  187. /* According to gcc's docs is the ...
  188. * The order of allocation of bit-fields within a unit (C90 6.5.2.1, C99 6.7.2.1).
  189. * Determined by ABI.
  190. * pointed out by Maxim Uvarov q<muvarov@ru.mvista.com>
  191. * even though we transmit as "cpu_to_be32(state)",
  192. * the offsets of the bitfields still need to be swapped
  193. * on different endianess.
  194. */
  195. struct {
  196. #if defined(__LITTLE_ENDIAN_BITFIELD)
  197. unsigned role:2 ; /* 3/4 primary/secondary/unknown */
  198. unsigned peer:2 ; /* 3/4 primary/secondary/unknown */
  199. unsigned conn:5 ; /* 17/32 cstates */
  200. unsigned disk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
  201. unsigned pdsk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
  202. unsigned susp:1 ; /* 2/2 IO suspended no/yes */
  203. unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
  204. unsigned peer_isp:1 ;
  205. unsigned user_isp:1 ;
  206. unsigned _pad:11; /* 0 unused */
  207. #elif defined(__BIG_ENDIAN_BITFIELD)
  208. unsigned _pad:11; /* 0 unused */
  209. unsigned user_isp:1 ;
  210. unsigned peer_isp:1 ;
  211. unsigned aftr_isp:1 ; /* isp .. imposed sync pause */
  212. unsigned susp:1 ; /* 2/2 IO suspended no/yes */
  213. unsigned pdsk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
  214. unsigned disk:4 ; /* 8/16 from D_DISKLESS to D_UP_TO_DATE */
  215. unsigned conn:5 ; /* 17/32 cstates */
  216. unsigned peer:2 ; /* 3/4 primary/secondary/unknown */
  217. unsigned role:2 ; /* 3/4 primary/secondary/unknown */
  218. #else
  219. # error "this endianess is not supported"
  220. #endif
  221. };
  222. unsigned int i;
  223. };
  224. enum drbd_state_ret_codes {
  225. SS_CW_NO_NEED = 4,
  226. SS_CW_SUCCESS = 3,
  227. SS_NOTHING_TO_DO = 2,
  228. SS_SUCCESS = 1,
  229. SS_UNKNOWN_ERROR = 0, /* Used to sleep longer in _drbd_request_state */
  230. SS_TWO_PRIMARIES = -1,
  231. SS_NO_UP_TO_DATE_DISK = -2,
  232. SS_NO_LOCAL_DISK = -4,
  233. SS_NO_REMOTE_DISK = -5,
  234. SS_CONNECTED_OUTDATES = -6,
  235. SS_PRIMARY_NOP = -7,
  236. SS_RESYNC_RUNNING = -8,
  237. SS_ALREADY_STANDALONE = -9,
  238. SS_CW_FAILED_BY_PEER = -10,
  239. SS_IS_DISKLESS = -11,
  240. SS_DEVICE_IN_USE = -12,
  241. SS_NO_NET_CONFIG = -13,
  242. SS_NO_VERIFY_ALG = -14, /* drbd-8.2 only */
  243. SS_NEED_CONNECTION = -15, /* drbd-8.2 only */
  244. SS_LOWER_THAN_OUTDATED = -16,
  245. SS_NOT_SUPPORTED = -17, /* drbd-8.2 only */
  246. SS_IN_TRANSIENT_STATE = -18, /* Retry after the next state change */
  247. SS_CONCURRENT_ST_CHG = -19, /* Concurrent cluster side state change! */
  248. SS_AFTER_LAST_ERROR = -20, /* Keep this at bottom */
  249. };
  250. /* from drbd_strings.c */
  251. extern const char *drbd_conn_str(enum drbd_conns);
  252. extern const char *drbd_role_str(enum drbd_role);
  253. extern const char *drbd_disk_str(enum drbd_disk_state);
  254. extern const char *drbd_set_st_err_str(enum drbd_state_ret_codes);
  255. #define SHARED_SECRET_MAX 64
  256. #define MDF_CONSISTENT (1 << 0)
  257. #define MDF_PRIMARY_IND (1 << 1)
  258. #define MDF_CONNECTED_IND (1 << 2)
  259. #define MDF_FULL_SYNC (1 << 3)
  260. #define MDF_WAS_UP_TO_DATE (1 << 4)
  261. #define MDF_PEER_OUT_DATED (1 << 5)
  262. #define MDF_CRASHED_PRIMARY (1 << 6)
  263. enum drbd_uuid_index {
  264. UI_CURRENT,
  265. UI_BITMAP,
  266. UI_HISTORY_START,
  267. UI_HISTORY_END,
  268. UI_SIZE, /* nl-packet: number of dirty bits */
  269. UI_FLAGS, /* nl-packet: flags */
  270. UI_EXTENDED_SIZE /* Everything. */
  271. };
  272. enum drbd_timeout_flag {
  273. UT_DEFAULT = 0,
  274. UT_DEGRADED = 1,
  275. UT_PEER_OUTDATED = 2,
  276. };
  277. #define UUID_JUST_CREATED ((__u64)4)
  278. #define DRBD_MAGIC 0x83740267
  279. #define BE_DRBD_MAGIC __constant_cpu_to_be32(DRBD_MAGIC)
  280. /* these are of type "int" */
  281. #define DRBD_MD_INDEX_INTERNAL -1
  282. #define DRBD_MD_INDEX_FLEX_EXT -2
  283. #define DRBD_MD_INDEX_FLEX_INT -3
  284. /* Start of the new netlink/connector stuff */
  285. #define DRBD_NL_CREATE_DEVICE 0x01
  286. #define DRBD_NL_SET_DEFAULTS 0x02
  287. /* For searching a vacant cn_idx value */
  288. #define CN_IDX_STEP 6977
  289. struct drbd_nl_cfg_req {
  290. int packet_type;
  291. unsigned int drbd_minor;
  292. int flags;
  293. unsigned short tag_list[];
  294. };
  295. struct drbd_nl_cfg_reply {
  296. int packet_type;
  297. unsigned int minor;
  298. int ret_code; /* enum ret_code or set_st_err_t */
  299. unsigned short tag_list[]; /* only used with get_* calls */
  300. };
  301. #endif