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 v027"
  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 0x01
  40. #define CEPH_ENTITY_TYPE_MDS 0x02
  41. #define CEPH_ENTITY_TYPE_OSD 0x04
  42. #define CEPH_ENTITY_TYPE_CLIENT 0x08
  43. #define CEPH_ENTITY_TYPE_ADMIN 0x10
  44. #define CEPH_ENTITY_TYPE_AUTH 0x20
  45. #define CEPH_ENTITY_TYPE_ANY 0xFF
  46. extern const char *ceph_entity_type_name(int type);
  47. /*
  48. * entity_addr -- network address
  49. */
  50. struct ceph_entity_addr {
  51. __le32 type;
  52. __le32 nonce; /* unique id for process (e.g. pid) */
  53. struct sockaddr_storage in_addr;
  54. } __attribute__ ((packed));
  55. struct ceph_entity_inst {
  56. struct ceph_entity_name name;
  57. struct ceph_entity_addr addr;
  58. } __attribute__ ((packed));
  59. /* used by message exchange protocol */
  60. #define CEPH_MSGR_TAG_READY 1 /* server->client: ready for messages */
  61. #define CEPH_MSGR_TAG_RESETSESSION 2 /* server->client: reset, try again */
  62. #define CEPH_MSGR_TAG_WAIT 3 /* server->client: wait for racing
  63. incoming connection */
  64. #define CEPH_MSGR_TAG_RETRY_SESSION 4 /* server->client + cseq: try again
  65. with higher cseq */
  66. #define CEPH_MSGR_TAG_RETRY_GLOBAL 5 /* server->client + gseq: try again
  67. with higher gseq */
  68. #define CEPH_MSGR_TAG_CLOSE 6 /* closing pipe */
  69. #define CEPH_MSGR_TAG_MSG 7 /* message */
  70. #define CEPH_MSGR_TAG_ACK 8 /* message ack */
  71. #define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */
  72. #define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */
  73. #define CEPH_MSGR_TAG_BADAUTHORIZER 11 /* bad authorizer */
  74. #define CEPH_MSGR_TAG_FEATURES 12 /* insufficient features */
  75. /*
  76. * connection negotiation
  77. */
  78. struct ceph_msg_connect {
  79. __le64 features; /* supported feature bits */
  80. __le32 host_type; /* CEPH_ENTITY_TYPE_* */
  81. __le32 global_seq; /* count connections initiated by this host */
  82. __le32 connect_seq; /* count connections initiated in this session */
  83. __le32 protocol_version;
  84. __le32 authorizer_protocol;
  85. __le32 authorizer_len;
  86. __u8 flags; /* CEPH_MSG_CONNECT_* */
  87. } __attribute__ ((packed));
  88. struct ceph_msg_connect_reply {
  89. __u8 tag;
  90. __le64 features; /* feature bits for this session */
  91. __le32 global_seq;
  92. __le32 connect_seq;
  93. __le32 protocol_version;
  94. __le32 authorizer_len;
  95. __u8 flags;
  96. } __attribute__ ((packed));
  97. #define CEPH_MSG_CONNECT_LOSSY 1 /* messages i send may be safely dropped */
  98. /*
  99. * message header
  100. */
  101. struct ceph_msg_header {
  102. __le64 seq; /* message seq# for this session */
  103. __le64 tid; /* transaction id */
  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 reserved;
  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