diff options
author | Sage Weil <sage@newdream.net> | 2009-10-06 14:31:06 -0400 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2009-10-06 14:31:06 -0400 |
commit | 0dee3c28af2fbe22ca62739a7f57da5435d35793 (patch) | |
tree | dd5992a4abc86c5931ce36258b972dbf48ab355d /fs/ceph/msgr.h | |
parent | 7ad920b504a980adcab4d3f6b85695526e6fd7bb (diff) |
ceph: on-wire types
These headers describe the types used to exchange messages between the
Ceph client and various servers. All types are little-endian and
packed. These headers are shared between the kernel and userspace, so
all types are in terms of e.g. __u32.
Additionally, we define a few magic values to identify the current
version of the protocol(s) in use, so that discrepancies to be
detected on mount.
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/msgr.h')
-rw-r--r-- | fs/ceph/msgr.h | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/fs/ceph/msgr.h b/fs/ceph/msgr.h new file mode 100644 index 000000000000..73921ae43faa --- /dev/null +++ b/fs/ceph/msgr.h | |||
@@ -0,0 +1,157 @@ | |||
1 | #ifndef __MSGR_H | ||
2 | #define __MSGR_H | ||
3 | |||
4 | /* | ||
5 | * Data types for message passing layer used by Ceph. | ||
6 | */ | ||
7 | |||
8 | #define CEPH_MON_PORT 6789 /* default monitor port */ | ||
9 | |||
10 | /* | ||
11 | * client-side processes will try to bind to ports in this | ||
12 | * range, simply for the benefit of tools like nmap or wireshark | ||
13 | * that would like to identify the protocol. | ||
14 | */ | ||
15 | #define CEPH_PORT_FIRST 6789 | ||
16 | #define CEPH_PORT_START 6800 /* non-monitors start here */ | ||
17 | #define CEPH_PORT_LAST 6900 | ||
18 | |||
19 | /* | ||
20 | * tcp connection banner. include a protocol version. and adjust | ||
21 | * whenever the wire protocol changes. try to keep this string length | ||
22 | * constant. | ||
23 | */ | ||
24 | #define CEPH_BANNER "ceph v021" | ||
25 | #define CEPH_BANNER_MAX_LEN 30 | ||
26 | |||
27 | |||
28 | /* | ||
29 | * Rollover-safe type and comparator for 32-bit sequence numbers. | ||
30 | * Comparator returns -1, 0, or 1. | ||
31 | */ | ||
32 | typedef __u32 ceph_seq_t; | ||
33 | |||
34 | static inline __s32 ceph_seq_cmp(__u32 a, __u32 b) | ||
35 | { | ||
36 | return (__s32)a - (__s32)b; | ||
37 | } | ||
38 | |||
39 | |||
40 | /* | ||
41 | * entity_name -- logical name for a process participating in the | ||
42 | * network, e.g. 'mds0' or 'osd3'. | ||
43 | */ | ||
44 | struct ceph_entity_name { | ||
45 | __u8 type; /* CEPH_ENTITY_TYPE_* */ | ||
46 | __le64 num; | ||
47 | } __attribute__ ((packed)); | ||
48 | |||
49 | #define CEPH_ENTITY_TYPE_MON 1 | ||
50 | #define CEPH_ENTITY_TYPE_MDS 2 | ||
51 | #define CEPH_ENTITY_TYPE_OSD 3 | ||
52 | #define CEPH_ENTITY_TYPE_CLIENT 4 | ||
53 | #define CEPH_ENTITY_TYPE_ADMIN 5 | ||
54 | |||
55 | /* | ||
56 | * entity_addr -- network address | ||
57 | */ | ||
58 | struct ceph_entity_addr { | ||
59 | __le32 erank; /* entity's rank in process */ | ||
60 | __le32 nonce; /* unique id for process (e.g. pid) */ | ||
61 | struct sockaddr_storage in_addr; | ||
62 | } __attribute__ ((packed)); | ||
63 | |||
64 | static inline bool ceph_entity_addr_is_local(const struct ceph_entity_addr *a, | ||
65 | const struct ceph_entity_addr *b) | ||
66 | { | ||
67 | return a->nonce == b->nonce && | ||
68 | memcmp(&a->in_addr, &b->in_addr, sizeof(a->in_addr)) == 0; | ||
69 | } | ||
70 | |||
71 | static inline bool ceph_entity_addr_equal(const struct ceph_entity_addr *a, | ||
72 | const struct ceph_entity_addr *b) | ||
73 | { | ||
74 | return memcmp(a, b, sizeof(*a)) == 0; | ||
75 | } | ||
76 | |||
77 | struct ceph_entity_inst { | ||
78 | struct ceph_entity_name name; | ||
79 | struct ceph_entity_addr addr; | ||
80 | } __attribute__ ((packed)); | ||
81 | |||
82 | |||
83 | /* used by message exchange protocol */ | ||
84 | #define CEPH_MSGR_TAG_READY 1 /* server->client: ready for messages */ | ||
85 | #define CEPH_MSGR_TAG_RESETSESSION 2 /* server->client: reset, try again */ | ||
86 | #define CEPH_MSGR_TAG_WAIT 3 /* server->client: wait for racing | ||
87 | incoming connection */ | ||
88 | #define CEPH_MSGR_TAG_RETRY_SESSION 4 /* server->client + cseq: try again | ||
89 | with higher cseq */ | ||
90 | #define CEPH_MSGR_TAG_RETRY_GLOBAL 5 /* server->client + gseq: try again | ||
91 | with higher gseq */ | ||
92 | #define CEPH_MSGR_TAG_CLOSE 6 /* closing pipe */ | ||
93 | #define CEPH_MSGR_TAG_MSG 7 /* message */ | ||
94 | #define CEPH_MSGR_TAG_ACK 8 /* message ack */ | ||
95 | #define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */ | ||
96 | #define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */ | ||
97 | |||
98 | |||
99 | /* | ||
100 | * connection negotiation | ||
101 | */ | ||
102 | struct ceph_msg_connect { | ||
103 | __le32 host_type; /* CEPH_ENTITY_TYPE_* */ | ||
104 | __le32 global_seq; /* count connections initiated by this host */ | ||
105 | __le32 connect_seq; /* count connections initiated in this session */ | ||
106 | __le32 protocol_version; | ||
107 | __u8 flags; /* CEPH_MSG_CONNECT_* */ | ||
108 | } __attribute__ ((packed)); | ||
109 | |||
110 | struct ceph_msg_connect_reply { | ||
111 | __u8 tag; | ||
112 | __le32 global_seq; | ||
113 | __le32 connect_seq; | ||
114 | __le32 protocol_version; | ||
115 | __u8 flags; | ||
116 | } __attribute__ ((packed)); | ||
117 | |||
118 | #define CEPH_MSG_CONNECT_LOSSY 1 /* messages i send may be safely dropped */ | ||
119 | |||
120 | |||
121 | /* | ||
122 | * message header | ||
123 | */ | ||
124 | struct ceph_msg_header { | ||
125 | __le64 seq; /* message seq# for this session */ | ||
126 | __le16 type; /* message type */ | ||
127 | __le16 priority; /* priority. higher value == higher priority */ | ||
128 | |||
129 | __le32 front_len; /* bytes in main payload */ | ||
130 | __le32 middle_len;/* bytes in middle payload */ | ||
131 | __le32 data_len; /* bytes of data payload */ | ||
132 | __le16 data_off; /* sender: include full offset; | ||
133 | receiver: mask against ~PAGE_MASK */ | ||
134 | |||
135 | struct ceph_entity_inst src, orig_src; | ||
136 | __le32 dst_erank; | ||
137 | __le32 crc; /* header crc32c */ | ||
138 | } __attribute__ ((packed)); | ||
139 | |||
140 | #define CEPH_MSG_PRIO_LOW 64 | ||
141 | #define CEPH_MSG_PRIO_DEFAULT 127 | ||
142 | #define CEPH_MSG_PRIO_HIGH 196 | ||
143 | #define CEPH_MSG_PRIO_HIGHEST 255 | ||
144 | |||
145 | /* | ||
146 | * follows data payload | ||
147 | */ | ||
148 | struct ceph_msg_footer { | ||
149 | __le32 front_crc, middle_crc, data_crc; | ||
150 | __u8 flags; | ||
151 | } __attribute__ ((packed)); | ||
152 | |||
153 | #define CEPH_MSG_FOOTER_COMPLETE (1<<0) /* msg wasn't aborted */ | ||
154 | #define CEPH_MSG_FOOTER_NOCRC (1<<1) /* no data crc */ | ||
155 | |||
156 | |||
157 | #endif | ||