msgr.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef __MSGR_H
  2. #define __MSGR_H
  3. /*
  4. * Data types for message passing layer used by Ceph.
  5. */
  6. #define CEPH_MON_PORT 6789 /* default monitor port */
  7. /*
  8. * client-side processes will try to bind to ports in this
  9. * range, simply for the benefit of tools like nmap or wireshark
  10. * that would like to identify the protocol.
  11. */
  12. #define CEPH_PORT_FIRST 6789
  13. #define CEPH_PORT_START 6800 /* non-monitors start here */
  14. #define CEPH_PORT_LAST 6900
  15. /*
  16. * tcp connection banner. include a protocol version. and adjust
  17. * whenever the wire protocol changes. try to keep this string length
  18. * constant.
  19. */
  20. #define CEPH_BANNER "ceph v023"
  21. #define CEPH_BANNER_MAX_LEN 30
  22. /*
  23. * Rollover-safe type and comparator for 32-bit sequence numbers.
  24. * Comparator returns -1, 0, or 1.
  25. */
  26. typedef __u32 ceph_seq_t;
  27. static inline __s32 ceph_seq_cmp(__u32 a, __u32 b)
  28. {
  29. return (__s32)a - (__s32)b;
  30. }
  31. /*
  32. * entity_name -- logical name for a process participating in the
  33. * network, e.g. 'mds0' or 'osd3'.
  34. */
  35. struct ceph_entity_name {
  36. __u8 type; /* CEPH_ENTITY_TYPE_* */
  37. __le64 num;
  38. } __attribute__ ((packed));
  39. #define CEPH_ENTITY_TYPE_MON 1
  40. #define CEPH_ENTITY_TYPE_MDS 2
  41. #define CEPH_ENTITY_TYPE_OSD 3
  42. #define CEPH_ENTITY_TYPE_CLIENT 4
  43. #define CEPH_ENTITY_TYPE_ADMIN 5
  44. /*
  45. * entity_addr -- network address
  46. */
  47. struct ceph_entity_addr {
  48. __le32 erank; /* entity's rank in process */
  49. __le32 nonce; /* unique id for process (e.g. pid) */
  50. struct sockaddr_storage in_addr;
  51. } __attribute__ ((packed));
  52. static inline bool ceph_entity_addr_is_local(const struct ceph_entity_addr *a,
  53. const struct ceph_entity_addr *b)
  54. {
  55. return a->nonce == b->nonce &&
  56. memcmp(&a->in_addr, &b->in_addr, sizeof(a->in_addr)) == 0;
  57. }
  58. static inline bool ceph_entity_addr_equal(const struct ceph_entity_addr *a,
  59. const struct ceph_entity_addr *b)
  60. {
  61. return memcmp(a, b, sizeof(*a)) == 0;
  62. }
  63. struct ceph_entity_inst {
  64. struct ceph_entity_name name;
  65. struct ceph_entity_addr addr;
  66. } __attribute__ ((packed));
  67. /* used by message exchange protocol */
  68. #define CEPH_MSGR_TAG_READY 1 /* server->client: ready for messages */
  69. #define CEPH_MSGR_TAG_RESETSESSION 2 /* server->client: reset, try again */
  70. #define CEPH_MSGR_TAG_WAIT 3 /* server->client: wait for racing
  71. incoming connection */
  72. #define CEPH_MSGR_TAG_RETRY_SESSION 4 /* server->client + cseq: try again
  73. with higher cseq */
  74. #define CEPH_MSGR_TAG_RETRY_GLOBAL 5 /* server->client + gseq: try again
  75. with higher gseq */
  76. #define CEPH_MSGR_TAG_CLOSE 6 /* closing pipe */
  77. #define CEPH_MSGR_TAG_MSG 7 /* message */
  78. #define CEPH_MSGR_TAG_ACK 8 /* message ack */
  79. #define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */
  80. #define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */
  81. /*
  82. * connection negotiation
  83. */
  84. struct ceph_msg_connect {
  85. __le32 host_type; /* CEPH_ENTITY_TYPE_* */
  86. __le32 global_seq; /* count connections initiated by this host */
  87. __le32 connect_seq; /* count connections initiated in this session */
  88. __le32 protocol_version;
  89. __u8 flags; /* CEPH_MSG_CONNECT_* */
  90. } __attribute__ ((packed));
  91. struct ceph_msg_connect_reply {
  92. __u8 tag;
  93. __le32 global_seq;
  94. __le32 connect_seq;
  95. __le32 protocol_version;
  96. __u8 flags;
  97. } __attribute__ ((packed));
  98. #define CEPH_MSG_CONNECT_LOSSY 1 /* messages i send may be safely dropped */
  99. /*
  100. * message header
  101. */
  102. struct ceph_msg_header {
  103. __le64 seq; /* message seq# for this session */
  104. __le16 type; /* message type */
  105. __le16 priority; /* priority. higher value == higher priority */
  106. __le16 version; /* version of message encoding */
  107. __le32 front_len; /* bytes in main payload */
  108. __le32 middle_len;/* bytes in middle payload */
  109. __le32 data_len; /* bytes of data payload */
  110. __le16 data_off; /* sender: include full offset;
  111. receiver: mask against ~PAGE_MASK */
  112. struct ceph_entity_inst src, orig_src;
  113. __le32 dst_erank;
  114. __le32 crc; /* header crc32c */
  115. } __attribute__ ((packed));
  116. #define CEPH_MSG_PRIO_LOW 64
  117. #define CEPH_MSG_PRIO_DEFAULT 127
  118. #define CEPH_MSG_PRIO_HIGH 196
  119. #define CEPH_MSG_PRIO_HIGHEST 255
  120. /*
  121. * follows data payload
  122. */
  123. struct ceph_msg_footer {
  124. __le32 front_crc, middle_crc, data_crc;
  125. __u8 flags;
  126. } __attribute__ ((packed));
  127. #define CEPH_MSG_FOOTER_COMPLETE (1<<0) /* msg wasn't aborted */
  128. #define CEPH_MSG_FOOTER_NOCRC (1<<1) /* no data crc */
  129. #endif