1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
/*
Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
This file is part of GlusterFS.
GlusterFS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
GlusterFS is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef __RPC_TRANSPORT_H__
#define __RPC_TRANSPORT_H__
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
#include <inttypes.h>
#include <rpc/rpc.h>
#include <rpc/auth.h>
#include <rpc/rpc_msg.h>
#ifndef MAX_IOVEC
#define MAX_IOVEC 16
#endif
/* Given the 4-byte fragment header, returns non-zero if this fragment
* is the last fragment for the RPC record being assemebled.
* RPC Record marking standard defines a 32 bit value as the fragment
* header with the MSB signifying whether the fragment is the last
* fragment for the record being asembled.
*/
#define RPC_LASTFRAG(fraghdr) ((uint32_t)(fraghdr & 0x80000000U))
/* Given the 4-byte fragment header, extracts the bits that contain
* the fragment size.
*/
#define RPC_FRAGSIZE(fraghdr) ((uint32_t)(fraghdr & 0x7fffffffU))
#define RPC_FRAGHDR_SIZE 4
#define RPC_MSGTYPE_SIZE 8
/* size of the msg from the start of call-body till and including credlen */
#define RPC_CALL_BODY_SIZE 24
#define RPC_REPLY_STATUS_SIZE 4
#define RPC_AUTH_FLAVOUR_N_LENGTH_SIZE 8
#define RPC_ACCEPT_STATUS_LEN 4
struct rpc_transport_ops;
typedef struct rpc_transport rpc_transport_t;
#include "dict.h"
#include "compat.h"
#include "rpcsvc-common.h"
struct peer_info {
struct sockaddr_storage sockaddr;
socklen_t sockaddr_len;
char identifier[UNIX_PATH_MAX];
};
typedef struct peer_info peer_info_t;
typedef enum msg_type msg_type_t;
typedef enum {
RPC_TRANSPORT_ACCEPT, /* New client has been accepted */
RPC_TRANSPORT_DISCONNECT, /* Connection is disconnected */
RPC_TRANSPORT_CLEANUP, /* connection is about to be freed */
/*RPC_TRANSPORT_READ,*/ /* An event used to enable rpcsvc to instruct
* transport the number of bytes to read.
* This helps in reading large msgs, wherein
* the rpc actors might decide to place the
* actor's payload in new iobufs separate
* from the rpc header, proghdr and
* authentication information. glusterfs/nfs
* read and write actors are few examples
* that might beniefit from this. While
* reading a single msg, this event may be
* delivered more than once.
*/
RPC_TRANSPORT_MAP_XID_REQUEST, /* reciever of this event should send
* the prognum and procnum corresponding
* to xid.
*/
RPC_TRANSPORT_MSG_RECEIVED, /* Complete rpc msg has been read */
RPC_TRANSPORT_CONNECT, /* client is connected to server */
RPC_TRANSPORT_MSG_SENT,
} rpc_transport_event_t;
struct rpc_transport_msg {
struct iovec *rpchdr;
int rpchdrcount;
struct iovec *proghdr;
int proghdrcount;
struct iovec *progpayload;
int progpayloadcount;
struct iobref *iobref;
};
typedef struct rpc_transport_msg rpc_transport_msg_t;
struct rpc_transport_rsp {
struct iovec *rsphdr;
int rsphdr_count;
struct iovec *rsp_payload;
int rsp_payload_count;
struct iobref *rsp_iobref;
};
typedef struct rpc_transport_rsp rpc_transport_rsp_t;
struct rpc_transport_req {
rpc_transport_msg_t msg;
rpc_transport_rsp_t rsp;
};
typedef struct rpc_transport_req rpc_transport_req_t;
struct rpc_transport_reply {
rpc_transport_msg_t msg;
void *private;
};
typedef struct rpc_transport_reply rpc_transport_reply_t;
struct rpc_transport_data {
char is_request;
union {
rpc_transport_req_t req;
rpc_transport_reply_t reply;
} data;
};
typedef struct rpc_transport_data rpc_transport_data_t;
struct rpc_request_info {
uint32_t xid;
int prognum;
int progver;
int procnum;
rpc_transport_rsp_t rsp;
};
typedef struct rpc_request_info rpc_request_info_t;
struct rpc_transport_pollin {
struct iovec vector[2];
int count;
char vectored;
void *private;
struct iobref *iobref;
};
typedef struct rpc_transport_pollin rpc_transport_pollin_t;
typedef int (*rpc_transport_notify_t) (rpc_transport_t *, void *mydata,
rpc_transport_event_t, void *data, ...);
struct rpc_transport {
struct rpc_transport_ops *ops;
void *private;
void *xl_private;
void *mydata;
pthread_mutex_t lock;
int32_t refcount;
glusterfs_ctx_t *ctx;
dict_t *options;
char *name;
void *dnscache;
data_t *buf;
int32_t (*init) (rpc_transport_t *this);
void (*fini) (rpc_transport_t *this);
rpc_transport_notify_t notify;
void *notify_data;
peer_info_t peerinfo;
peer_info_t myinfo;
rpc_transport_t *peer_trans;
struct {
pthread_mutex_t mutex;
pthread_cond_t cond;
pthread_t thread;
struct list_head msgs;
/* any request/reply will be transformed as pollin data on the
* peer, hence we are building up a pollin data even before
* handing it over to peer rpc_transport. In order to decide whether
* the pollin data is vectored or simple, we follow a simple
* algo i.e., if there is a progpayload in request/reply, its
* considered vectored, otherwise its a simple pollin data.
*/
rpc_transport_pollin_t *msg;
} handover;
};
typedef struct {
rpc_transport_pollin_t *pollin;
struct list_head list;
} rpc_transport_handover_t;
struct rpc_transport_ops {
/* no need of receive op, msg will be delivered through an event
* notification
*/
int32_t (*submit_request) (rpc_transport_t *this,
rpc_transport_req_t *req);
int32_t (*submit_reply) (rpc_transport_t *this,
rpc_transport_reply_t *reply);
int32_t (*connect) (rpc_transport_t *this);
int32_t (*listen) (rpc_transport_t *this);
int32_t (*disconnect) (rpc_transport_t *this);
int32_t (*get_peername) (rpc_transport_t *this, char *hostname,
int hostlen);
int32_t (*get_peeraddr) (rpc_transport_t *this, char *peeraddr,
int addrlen, struct sockaddr *sa,
socklen_t sasize);
int32_t (*get_myname) (rpc_transport_t *this, char *hostname,
int hostlen);
int32_t (*get_myaddr) (rpc_transport_t *this, char *peeraddr,
int addrlen, struct sockaddr *sa,
socklen_t sasize);
};
int32_t
rpc_transport_listen (rpc_transport_t *this);
int32_t
rpc_transport_connect (rpc_transport_t *this);
int32_t
rpc_transport_disconnect (rpc_transport_t *this);
int32_t
rpc_transport_notify (rpc_transport_t *this, rpc_transport_event_t event,
void *data, ...);
int32_t
rpc_transport_submit_request (rpc_transport_t *this, rpc_transport_req_t *req);
int32_t
rpc_transport_submit_reply (rpc_transport_t *this,
rpc_transport_reply_t *reply);
int32_t
rpc_transport_destroy (rpc_transport_t *this);
rpc_transport_t *
rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *name);
rpc_transport_t *
rpc_transport_ref (rpc_transport_t *trans);
int32_t
rpc_transport_unref (rpc_transport_t *trans);
int
rpc_transport_setpeer (rpc_transport_t *trans, rpc_transport_t *trans_peer);
int
rpc_transport_register_notify (rpc_transport_t *trans, rpc_transport_notify_t,
void *mydata);
int32_t
rpc_transport_get_peername (rpc_transport_t *this, char *hostname, int hostlen);
int32_t
rpc_transport_get_peeraddr (rpc_transport_t *this, char *peeraddr, int addrlen,
struct sockaddr *sa, size_t salen);
int32_t
rpc_transport_get_myname (rpc_transport_t *this, char *hostname, int hostlen);
int32_t
rpc_transport_get_myaddr (rpc_transport_t *this, char *peeraddr, int addrlen,
struct sockaddr *sa, size_t salen);
rpc_transport_pollin_t *
rpc_transport_pollin_alloc (rpc_transport_t *this, struct iovec *vector,
int count, struct iobref *iobref, void *private);
void
rpc_transport_pollin_destroy (rpc_transport_pollin_t *pollin);
#endif /* __RPC_TRANSPORT_H__ */
|