Bug Summary

File:xlators/mgmt/glusterd/src/glusterd-handshake.c
Location:line 886, column 9
Description:Value stored to 'op_errno' is never read

Annotated Source Code

1/*
2 Copyright (c) 2010-2012 Red Hat, Inc. <http://www.redhat.com>
3 This file is part of GlusterFS.
4
5 This file is licensed to you under your choice of the GNU Lesser
6 General Public License, version 3 or any later version (LGPLv3 or
7 later), or the GNU General Public License, version 2 (GPLv2), in all
8 cases as published by the Free Software Foundation.
9*/
10
11#ifndef _CONFIG_H
12#define _CONFIG_H
13#include "config.h"
14#endif
15
16#include "xlator.h"
17#include "defaults.h"
18#include "glusterfs.h"
19#include "compat-errno.h"
20
21#include "glusterd.h"
22#include "glusterd-utils.h"
23#include "glusterd-op-sm.h"
24#include "glusterd-store.h"
25
26#include "glusterfs3.h"
27#include "protocol-common.h"
28#include "rpcsvc.h"
29#include "rpc-common-xdr.h"
30
31extern struct rpc_clnt_program gd_peer_prog;
32extern struct rpc_clnt_program gd_mgmt_prog;
33
34#define TRUSTED_PREFIX"trusted-" "trusted-"
35
36typedef ssize_t (*gfs_serialize_t) (struct iovec outmsg, void *data);
37
38static size_t
39build_volfile_path (const char *volname, char *path,
40 size_t path_len, char *trusted_str)
41{
42 struct stat stbuf = {0,};
43 int32_t ret = -1;
44 glusterd_conf_t *priv = NULL((void*)0);
45 char *vol = NULL((void*)0);
46 char *dup_volname = NULL((void*)0);
47 char *free_ptr = NULL((void*)0);
48 char *tmp = NULL((void*)0);
49 glusterd_volinfo_t *volinfo = NULL((void*)0);
50 char *server = NULL((void*)0);
51
52 priv = THIS(*__glusterfs_this_location())->private;
53
54 if (strstr (volname, "gluster/")) {
55 server = strchr (volname, '/') + 1;
56 glusterd_get_nodesvc_volfile (server, priv->workdir,
57 path, path_len);
58 ret = 1;
59 goto out;
60 } else if (volname[0] != '/') {
61 /* Normal behavior */
62 dup_volname = gf_strdup (volname);
63 } else {
64 /* Bringing in NFS like behavior for mount command, */
65 /* With this, one can mount a volume with below cmd */
66 /* bash# mount -t glusterfs server:/volume /mnt/pnt */
67 dup_volname = gf_strdup (&volname[1]);
68 }
69
70 free_ptr = dup_volname;
71
72 ret = glusterd_volinfo_find (dup_volname, &volinfo);
73 if (ret) {
74 /* Split the volume name */
75 vol = strtok_r (dup_volname, ".", &tmp);
76 if (!vol)
77 goto out;
78 ret = glusterd_volinfo_find (vol, &volinfo);
79 if (ret)
80 goto out;
81 }
82
83 if (!glusterd_auth_get_username (volinfo))
84 trusted_str = NULL((void*)0);
85
86 ret = snprintf (path, path_len, "%s/vols/%s/%s.vol",
87 priv->workdir, volinfo->volname, volname);
88 if (ret == -1)
89 goto out;
90
91 ret = stat (path, &stbuf);
92
93 if ((ret == -1) && (errno(*__errno_location ()) == ENOENT2)) {
94 snprintf (path, path_len, "%s/vols/%s/%s%s-fuse.vol",
95 priv->workdir, volinfo->volname,
96 (trusted_str ? trusted_str : ""), dup_volname);
97 ret = stat (path, &stbuf);
98 }
99
100 if ((ret == -1) && (errno(*__errno_location ()) == ENOENT2)) {
101 snprintf (path, path_len, "%s/vols/%s/%s-tcp.vol",
102 priv->workdir, volinfo->volname, volname);
103 }
104
105 ret = 1;
106out:
107 GF_FREE (free_ptr)__gf_free (free_ptr);
108 return ret;
109}
110
111/* Get and store op-versions of the clients sending the getspec request
112 * Clients of versions <= 3.3, don't send op-versions, their op-versions are
113 * defaulted to 1
114 */
115static int
116_get_client_op_versions (gf_getspec_req *args, peer_info_t *peerinfo)
117{
118 int ret = 0;
119 int client_max_op_version = 1;
120 int client_min_op_version = 1;
121 dict_t *dict = NULL((void*)0);
122
123 GF_ASSERT (args)do { if (!(args)) { do { do { if (0) printf ("Assertion failed: "
"args"); } while (0); _gf_log_callingfn ("", "glusterd-handshake.c"
, __FUNCTION__, 123, GF_LOG_ERROR, "Assertion failed: " "args"
); } while (0); } } while (0)
;
124 GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: "
"peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-handshake.c"
, __FUNCTION__, 124, GF_LOG_ERROR, "Assertion failed: " "peerinfo"
); } while (0); } } while (0)
;
125
126 if (args->xdata.xdata_len) {
127 dict = dict_new ();
128 if (!dict) {
129 ret = -1;
130 goto out;
131 }
132
133 ret = dict_unserialize (args->xdata.xdata_val,
134 args->xdata.xdata_len, &dict);
135 if (ret) {
136 gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Failed to unserialize request dictionary"
); } while (0); _gf_log ("glusterd", "glusterd-handshake.c", __FUNCTION__
, 137, GF_LOG_ERROR, "Failed to unserialize request dictionary"
); } while (0)
137 "Failed to unserialize request dictionary")do { do { if (0) printf ("Failed to unserialize request dictionary"
); } while (0); _gf_log ("glusterd", "glusterd-handshake.c", __FUNCTION__
, 137, GF_LOG_ERROR, "Failed to unserialize request dictionary"
); } while (0)
;
138 goto out;
139 }
140
141 ret = dict_get_int32 (dict, "min-op-version",
142 &client_min_op_version);
143 if (ret) {
144 gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Failed to get client-min-op-version"
); } while (0); _gf_log ("glusterd", "glusterd-handshake.c", __FUNCTION__
, 145, GF_LOG_ERROR, "Failed to get client-min-op-version"); }
while (0)
145 "Failed to get client-min-op-version")do { do { if (0) printf ("Failed to get client-min-op-version"
); } while (0); _gf_log ("glusterd", "glusterd-handshake.c", __FUNCTION__
, 145, GF_LOG_ERROR, "Failed to get client-min-op-version"); }
while (0)
;
146 goto out;
147 }
148
149 ret = dict_get_int32 (dict, "max-op-version",
150 &client_max_op_version);
151 if (ret) {
152 gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Failed to get client-max-op-version"
); } while (0); _gf_log ("glusterd", "glusterd-handshake.c", __FUNCTION__
, 153, GF_LOG_ERROR, "Failed to get client-max-op-version"); }
while (0)
153 "Failed to get client-max-op-version")do { do { if (0) printf ("Failed to get client-max-op-version"
); } while (0); _gf_log ("glusterd", "glusterd-handshake.c", __FUNCTION__
, 153, GF_LOG_ERROR, "Failed to get client-max-op-version"); }
while (0)
;
154 goto out;
155 }
156 }
157
158 peerinfo->max_op_version = client_max_op_version;
159 peerinfo->min_op_version = client_min_op_version;
160
161out:
162 return ret;
163}
164
165/* Checks if the client supports the volume, ie. client can understand all the
166 * options in the volfile
167 */
168static gf_boolean_t
169_client_supports_volume (peer_info_t *peerinfo, int32_t *op_errno)
170{
171 gf_boolean_t ret = _gf_true;
172 glusterd_volinfo_t *volinfo = NULL((void*)0);
173
174 GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: "
"peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-handshake.c"
, __FUNCTION__, 174, GF_LOG_ERROR, "Assertion failed: " "peerinfo"
); } while (0); } } while (0)
;
175 GF_ASSERT (op_errno)do { if (!(op_errno)) { do { do { if (0) printf ("Assertion failed: "
"op_errno"); } while (0); _gf_log_callingfn ("", "glusterd-handshake.c"
, __FUNCTION__, 175, GF_LOG_ERROR, "Assertion failed: " "op_errno"
); } while (0); } } while (0)
;
176
177
178 /* Only check when the volfile being requested is a volume. Not finding
179 * a volinfo implies that the volfile requested for is not of a gluster
180 * volume. A non volume volfile is requested by the local gluster
181 * services like shd and nfs-server. These need not be checked as they
182 * will be running at the same op-version as glusterd and will be able
183 * to support all the features
184 */
185 if ((glusterd_volinfo_find (peerinfo->volname, &volinfo) == 0) &&
186 ((peerinfo->min_op_version > volinfo->client_op_version) ||
187 (peerinfo->max_op_version < volinfo->client_op_version))) {
188 ret = _gf_false;
189 *op_errno = ENOTSUP95;
190 gf_log ("glusterd", GF_LOG_INFO,do { do { if (0) printf ("Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0); _gf_log ("glusterd"
, "glusterd-handshake.c", __FUNCTION__, 194, GF_LOG_INFO, "Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0)
191 "Client %s (%d -> %d) doesn't support required "do { do { if (0) printf ("Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0); _gf_log ("glusterd"
, "glusterd-handshake.c", __FUNCTION__, 194, GF_LOG_INFO, "Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0)
192 "op-version (%d). Rejecting volfile request.",do { do { if (0) printf ("Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0); _gf_log ("glusterd"
, "glusterd-handshake.c", __FUNCTION__, 194, GF_LOG_INFO, "Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0)
193 peerinfo->identifier, peerinfo->min_op_version,do { do { if (0) printf ("Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0); _gf_log ("glusterd"
, "glusterd-handshake.c", __FUNCTION__, 194, GF_LOG_INFO, "Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0)
194 peerinfo->max_op_version, volinfo->client_op_version)do { do { if (0) printf ("Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0); _gf_log ("glusterd"
, "glusterd-handshake.c", __FUNCTION__, 194, GF_LOG_INFO, "Client %s (%d -> %d) doesn't support required "
"op-version (%d). Rejecting volfile request.", peerinfo->
identifier, peerinfo->min_op_version, peerinfo->max_op_version
, volinfo->client_op_version); } while (0)
;
195 }
196
197 return ret;
198}
199
200int
201__server_getspec (rpcsvc_request_t *req)
202{
203 int32_t ret = -1;
204 int32_t op_errno = 0;
205 int32_t spec_fd = -1;
206 size_t file_len = 0;
207 char filename[PATH_MAX4096] = {0,};
208 struct stat stbuf = {0,};
209 char *volume = NULL((void*)0);
210 char *tmp = NULL((void*)0);
211 int cookie = 0;
212 rpc_transport_t *trans = NULL((void*)0);
213 gf_getspec_req args = {0,};
214 gf_getspec_rsp rsp = {0,};
215 char addrstr[RPCSVC_PEER_STRLEN1024] = {0};
216 peer_info_t *peerinfo = NULL((void*)0);
217
218 ret = xdr_to_generic (req->msg[0], &args,
219 (xdrproc_t)xdr_gf_getspec_req);
220 if (ret < 0) {
221 //failed to decode msg;
222 req->rpc_err = GARBAGE_ARGS;
223 goto fail;
224 }
225
226 peerinfo = &req->trans->peerinfo;
227
228 volume = args.key;
229 /* Need to strip leading '/' from volnames. This was introduced to
230 * support nfs style mount parameters for native gluster mount
231 */
232 if (volume[0] == '/')
233 strncpy (peerinfo->volname, &volume[1], strlen(&volume[1]));
234 else
235 strncpy (peerinfo->volname, volume, strlen(volume));
236
237 ret = _get_client_op_versions (&args, peerinfo);
238 if (ret)
239 goto fail;
240
241 if (!_client_supports_volume (peerinfo, &op_errno)) {
242 ret = -1;
243 goto fail;
244 }
245
246 trans = req->trans;
247 ret = rpcsvc_transport_peername (trans, (char *)&addrstr,
248 sizeof (addrstr));
249 if (ret)
250 goto fail;
251
252 tmp = strrchr (addrstr, ':');
253 *tmp = '\0';
254
255 /* we trust the local admin */
256 if (glusterd_is_local_addr (addrstr)) {
257
258 ret = build_volfile_path (volume, filename,
259 sizeof (filename),
260 TRUSTED_PREFIX"trusted-");
261 } else {
262 ret = build_volfile_path (volume, filename,
263 sizeof (filename), NULL((void*)0));
264 }
265
266 if (ret > 0) {
267 /* to allocate the proper buffer to hold the file data */
268 ret = stat (filename, &stbuf);
269 if (ret < 0){
270 gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Unable to stat %s (%s)", filename, strerror
((*__errno_location ()))); } while (0); _gf_log ("glusterd",
"glusterd-handshake.c", __FUNCTION__, 272, GF_LOG_ERROR, "Unable to stat %s (%s)"
, filename, strerror ((*__errno_location ()))); } while (0)
271 "Unable to stat %s (%s)",do { do { if (0) printf ("Unable to stat %s (%s)", filename, strerror
((*__errno_location ()))); } while (0); _gf_log ("glusterd",
"glusterd-handshake.c", __FUNCTION__, 272, GF_LOG_ERROR, "Unable to stat %s (%s)"
, filename, strerror ((*__errno_location ()))); } while (0)
272 filename, strerror (errno))do { do { if (0) printf ("Unable to stat %s (%s)", filename, strerror
((*__errno_location ()))); } while (0); _gf_log ("glusterd",
"glusterd-handshake.c", __FUNCTION__, 272, GF_LOG_ERROR, "Unable to stat %s (%s)"
, filename, strerror ((*__errno_location ()))); } while (0)
;
273 goto fail;
274 }
275
276 spec_fd = open (filename, O_RDONLY00);
277 if (spec_fd < 0) {
278 gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Unable to open %s (%s)", filename, strerror
((*__errno_location ()))); } while (0); _gf_log ("glusterd",
"glusterd-handshake.c", __FUNCTION__, 280, GF_LOG_ERROR, "Unable to open %s (%s)"
, filename, strerror ((*__errno_location ()))); } while (0)
279 "Unable to open %s (%s)",do { do { if (0) printf ("Unable to open %s (%s)", filename, strerror
((*__errno_location ()))); } while (0); _gf_log ("glusterd",
"glusterd-handshake.c", __FUNCTION__, 280, GF_LOG_ERROR, "Unable to open %s (%s)"
, filename, strerror ((*__errno_location ()))); } while (0)
280 filename, strerror (errno))do { do { if (0) printf ("Unable to open %s (%s)", filename, strerror
((*__errno_location ()))); } while (0); _gf_log ("glusterd",
"glusterd-handshake.c", __FUNCTION__, 280, GF_LOG_ERROR, "Unable to open %s (%s)"
, filename, strerror ((*__errno_location ()))); } while (0)
;
281 goto fail;
282 }
283 ret = file_len = stbuf.st_size;
284 } else {
285 op_errno = ENOENT2;
286 }
287
288 if (file_len) {
289 rsp.spec = CALLOC (file_len+1, sizeof (char))__gf_default_calloc(file_len+1,sizeof (char));
290 if (!rsp.spec) {
291 ret = -1;
292 op_errno = ENOMEM12;
293 goto fail;
294 }
295 ret = read (spec_fd, rsp.spec, file_len);
296
297 close (spec_fd);
298 }
299
300 /* convert to XDR */
301fail:
302 rsp.op_ret = ret;
303
304 if (op_errno)
305 rsp.op_errno = gf_errno_to_error (op_errno);
306 if (cookie)
307 rsp.op_errno = cookie;
308
309 if (!rsp.spec)
310 rsp.spec = strdup ("");
311
312 glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0),
313 (xdrproc_t)xdr_gf_getspec_rsp);
314 free (args.key);//malloced by xdr
315 free (rsp.spec);
316
317 return 0;
318}
319
320int
321server_getspec (rpcsvc_request_t *req)
322{
323 return glusterd_big_locked_handler (req, __server_getspec);
324}
325
326int32_t
327__server_event_notify (rpcsvc_request_t *req)
328{
329 int32_t ret = -1;
330 int32_t op_errno = 0;
331 gf_event_notify_req args = {0,};
332 gf_event_notify_rsp rsp = {0,};
333 dict_t *dict = NULL((void*)0);
334 gf_boolean_t need_rsp = _gf_true;
335
336 ret = xdr_to_generic (req->msg[0], &args,
337 (xdrproc_t)xdr_gf_event_notify_req);
338 if (ret < 0) {
339 req->rpc_err = GARBAGE_ARGS;
340 goto fail;
341 }
342
343 if (args.dict.dict_len) {
344 dict = dict_new ();
345 if (!dict)
346 return ret;
347 ret = dict_unserialize (args.dict.dict_val,
348 args.dict.dict_len, &dict);
349 if (ret) {
350 gf_log ("", GF_LOG_ERROR, "Failed to unserialize req")do { do { if (0) printf ("Failed to unserialize req"); } while
(0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__, 350,
GF_LOG_ERROR, "Failed to unserialize req"); } while (0)
;
351 goto fail;
352 }
353 }
354
355 switch (args.op) {
356 case GF_EN_DEFRAG_STATUS:
357 gf_log ("", GF_LOG_INFO,do { do { if (0) printf ("received defrag status updated"); }
while (0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__
, 358, GF_LOG_INFO, "received defrag status updated"); } while
(0)
358 "received defrag status updated")do { do { if (0) printf ("received defrag status updated"); }
while (0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__
, 358, GF_LOG_INFO, "received defrag status updated"); } while
(0)
;
359 if (dict) {
360 glusterd_defrag_event_notify_handle (dict);
361 need_rsp = _gf_false;
362 }
363 break;
364 default:
365 gf_log ("", GF_LOG_ERROR, "Unknown op received in event "do { do { if (0) printf ("Unknown op received in event " "notify"
); } while (0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__
, 366, GF_LOG_ERROR, "Unknown op received in event " "notify"
); } while (0)
366 "notify")do { do { if (0) printf ("Unknown op received in event " "notify"
); } while (0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__
, 366, GF_LOG_ERROR, "Unknown op received in event " "notify"
); } while (0)
;
367 ret = -1;
368 break;
369 }
370
371fail:
372 rsp.op_ret = ret;
373
374 if (op_errno)
375 rsp.op_errno = gf_errno_to_error (op_errno);
376
377 if (need_rsp)
378 glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0),
379 (xdrproc_t)xdr_gf_event_notify_rsp);
380 if (dict)
381 dict_unref (dict);
382 free (args.dict.dict_val);//malloced by xdr
383
384 return 0;
385}
386
387int32_t
388server_event_notify (rpcsvc_request_t *req)
389{
390 return glusterd_big_locked_handler (req, __server_event_notify);
391}
392
393int
394gd_validate_cluster_op_version (xlator_t *this, int cluster_op_version,
395 char *peerid)
396{
397 int ret = -1;
398 glusterd_conf_t *conf = NULL((void*)0);
399
400 conf = this->private;
401
402 if (cluster_op_version > GD_OP_VERSION_MAX2) {
403 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("operating version %d is more than the maximum "
"supported (%d) on the machine (as per peer request " "from %s)"
, cluster_op_version, 2, peerid); } while (0); _gf_log (this->
name, "glusterd-handshake.c", __FUNCTION__, 407, GF_LOG_ERROR
, "operating version %d is more than the maximum " "supported (%d) on the machine (as per peer request "
"from %s)", cluster_op_version, 2, peerid); } while (0)
404 "operating version %d is more than the maximum "do { do { if (0) printf ("operating version %d is more than the maximum "
"supported (%d) on the machine (as per peer request " "from %s)"
, cluster_op_version, 2, peerid); } while (0); _gf_log (this->
name, "glusterd-handshake.c", __FUNCTION__, 407, GF_LOG_ERROR
, "operating version %d is more than the maximum " "supported (%d) on the machine (as per peer request "
"from %s)", cluster_op_version, 2, peerid); } while (0)
405 "supported (%d) on the machine (as per peer request "do { do { if (0) printf ("operating version %d is more than the maximum "
"supported (%d) on the machine (as per peer request " "from %s)"
, cluster_op_version, 2, peerid); } while (0); _gf_log (this->
name, "glusterd-handshake.c", __FUNCTION__, 407, GF_LOG_ERROR
, "operating version %d is more than the maximum " "supported (%d) on the machine (as per peer request "
"from %s)", cluster_op_version, 2, peerid); } while (0)
406 "from %s)", cluster_op_version, GD_OP_VERSION_MAX,do { do { if (0) printf ("operating version %d is more than the maximum "
"supported (%d) on the machine (as per peer request " "from %s)"
, cluster_op_version, 2, peerid); } while (0); _gf_log (this->
name, "glusterd-handshake.c", __FUNCTION__, 407, GF_LOG_ERROR
, "operating version %d is more than the maximum " "supported (%d) on the machine (as per peer request "
"from %s)", cluster_op_version, 2, peerid); } while (0)
407 peerid)do { do { if (0) printf ("operating version %d is more than the maximum "
"supported (%d) on the machine (as per peer request " "from %s)"
, cluster_op_version, 2, peerid); } while (0); _gf_log (this->
name, "glusterd-handshake.c", __FUNCTION__, 407, GF_LOG_ERROR
, "operating version %d is more than the maximum " "supported (%d) on the machine (as per peer request "
"from %s)", cluster_op_version, 2, peerid); } while (0)
;
408 goto out;
409 }
410
411 if (cluster_op_version < conf->op_version) {
412 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 416, GF_LOG_ERROR, "operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0)
413 "operating version %d is less than the currently "do { do { if (0) printf ("operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 416, GF_LOG_ERROR, "operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0)
414 "running version (%d) on the machine (as per peer "do { do { if (0) printf ("operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 416, GF_LOG_ERROR, "operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0)
415 "request from %s)", cluster_op_version,do { do { if (0) printf ("operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 416, GF_LOG_ERROR, "operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0)
416 conf->op_version, peerid)do { do { if (0) printf ("operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 416, GF_LOG_ERROR, "operating version %d is less than the currently "
"running version (%d) on the machine (as per peer " "request from %s)"
, cluster_op_version, conf->op_version, peerid); } while (
0)
;
417 goto out;
418 }
419
420 ret = 0;
421out:
422 return ret;
423}
424
425int
426__glusterd_mgmt_hndsk_versions (rpcsvc_request_t *req)
427{
428 dict_t *dict = NULL((void*)0);
429 xlator_t *this = NULL((void*)0);
430 glusterd_conf_t *conf = NULL((void*)0);
431 int ret = -1;
432 int op_errno = EINVAL22;
433 gf_mgmt_hndsk_req args = {{0,},};
434 gf_mgmt_hndsk_rsp rsp = {0,};
435
436 this = THIS(*__glusterfs_this_location());
437 conf = this->private;
438
439 ret = xdr_to_generic (req->msg[0], &args,
440 (xdrproc_t)xdr_gf_mgmt_hndsk_req);
441 if (ret < 0) {
442 //failed to decode msg;
443 req->rpc_err = GARBAGE_ARGS;
444 goto out;
445 }
446
447 dict = dict_new ();
448 if (!dict)
449 goto out;
450
451 ret = dict_set_int32 (dict, GD_OP_VERSION_KEY"operating-version", conf->op_version);
452 if (ret) {
453 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to set operating version"); }
while (0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 454, GF_LOG_WARNING, "failed to set operating version"); } while
(0)
454 "failed to set operating version")do { do { if (0) printf ("failed to set operating version"); }
while (0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 454, GF_LOG_WARNING, "failed to set operating version"); } while
(0)
;
455 rsp.op_ret = ret;
456 goto out;
457 }
458
459 ret = dict_set_int32 (dict, GD_MIN_OP_VERSION_KEY"minimum-operating-version", GD_OP_VERSION_MIN1);
460 if (ret) {
461 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to set %s", "minimum-operating-version"
); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 462, GF_LOG_WARNING, "failed to set %s", "minimum-operating-version"
); } while (0)
462 "failed to set %s", GD_MIN_OP_VERSION_KEY)do { do { if (0) printf ("failed to set %s", "minimum-operating-version"
); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 462, GF_LOG_WARNING, "failed to set %s", "minimum-operating-version"
); } while (0)
;
463 rsp.op_ret = ret;
464 goto out;
465 }
466
467 ret = dict_set_int32 (dict, GD_MAX_OP_VERSION_KEY"maximum-operating-version", GD_OP_VERSION_MAX2);
468 if (ret) {
469 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to set %s", "maximum-operating-version"
); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 470, GF_LOG_WARNING, "failed to set %s", "maximum-operating-version"
); } while (0)
470 "failed to set %s", GD_MAX_OP_VERSION_KEY)do { do { if (0) printf ("failed to set %s", "maximum-operating-version"
); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 470, GF_LOG_WARNING, "failed to set %s", "maximum-operating-version"
); } while (0)
;
471 rsp.op_ret = ret;
472 goto out;
473 }
474
475 ret = 0;
476
477 GF_PROTOCOL_DICT_SERIALIZE (this, dict, (&rsp.hndsk.hndsk_val),do { int ret = 0; if (!dict) break; ret = dict_allocate_and_serialize
(dict, (&rsp.hndsk.hndsk_val), &rsp.hndsk.hndsk_len)
; if (ret < 0) { do { do { if (0) printf ("failed to get serialized dict (%s)"
, ("dict")); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 478, GF_LOG_WARNING, "failed to get serialized dict (%s)"
, ("dict")); } while (0); op_errno = 22; goto out; } } while (
0)
478 rsp.hndsk.hndsk_len, op_errno, out)do { int ret = 0; if (!dict) break; ret = dict_allocate_and_serialize
(dict, (&rsp.hndsk.hndsk_val), &rsp.hndsk.hndsk_len)
; if (ret < 0) { do { do { if (0) printf ("failed to get serialized dict (%s)"
, ("dict")); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 478, GF_LOG_WARNING, "failed to get serialized dict (%s)"
, ("dict")); } while (0); op_errno = 22; goto out; } } while (
0)
;
479out:
480
481 rsp.op_ret = ret;
482 rsp.op_errno = op_errno;
483
484 glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0),
485 (xdrproc_t)xdr_gf_mgmt_hndsk_rsp);
486
487 ret = 0;
488
489 if (dict)
490 dict_unref (dict);
491
492 if (args.hndsk.hndsk_val)
493 free (args.hndsk.hndsk_val);
494
495 if (rsp.hndsk.hndsk_val)
496 GF_FREE (rsp.hndsk.hndsk_val)__gf_free (rsp.hndsk.hndsk_val);
497
498 return ret;
499}
500
501int
502glusterd_mgmt_hndsk_versions (rpcsvc_request_t *req)
503{
504 return glusterd_big_locked_handler (req,
505 __glusterd_mgmt_hndsk_versions);
506}
507
508int
509__glusterd_mgmt_hndsk_versions_ack (rpcsvc_request_t *req)
510{
511 dict_t *clnt_dict = NULL((void*)0);
512 xlator_t *this = NULL((void*)0);
513 glusterd_conf_t *conf = NULL((void*)0);
514 int ret = -1;
515 int op_errno = EINVAL22;
516 int peer_op_version = 0;
517 gf_mgmt_hndsk_req args = {{0,},};
518 gf_mgmt_hndsk_rsp rsp = {0,};
519
520 this = THIS(*__glusterfs_this_location());
521 conf = this->private;
522
523 ret = xdr_to_generic (req->msg[0], &args,
524 (xdrproc_t)xdr_gf_mgmt_hndsk_req);
525 if (ret < 0) {
526 //failed to decode msg;
527 req->rpc_err = GARBAGE_ARGS;
528 goto out;
529 }
530
531 GF_PROTOCOL_DICT_UNSERIALIZE (this, clnt_dict, args.hndsk.hndsk_val,do { if (!(args.hndsk.hndsk_len)) break; clnt_dict = dict_new
(); do { if (!clnt_dict) { (*__errno_location ()) = 22; do { do
{ if (0) printf ("invalid argument: " "clnt_dict"); } while (
0); _gf_log_callingfn (this->name, "glusterd-handshake.c",
__FUNCTION__, 533, GF_LOG_ERROR, "invalid argument: " "clnt_dict"
); } while (0); goto out; } } while (0); ret = dict_unserialize
(args.hndsk.hndsk_val, (args.hndsk.hndsk_len), &clnt_dict
); if (ret < 0) { do { do { if (0) printf ("failed to unserialize dictionary (%s)"
, ("clnt_dict")); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 533, GF_LOG_WARNING, "failed to unserialize dictionary (%s)"
, ("clnt_dict")); } while (0); op_errno = 22; goto out; } } while
(0)
532 (args.hndsk.hndsk_len), ret, op_errno,do { if (!(args.hndsk.hndsk_len)) break; clnt_dict = dict_new
(); do { if (!clnt_dict) { (*__errno_location ()) = 22; do { do
{ if (0) printf ("invalid argument: " "clnt_dict"); } while (
0); _gf_log_callingfn (this->name, "glusterd-handshake.c",
__FUNCTION__, 533, GF_LOG_ERROR, "invalid argument: " "clnt_dict"
); } while (0); goto out; } } while (0); ret = dict_unserialize
(args.hndsk.hndsk_val, (args.hndsk.hndsk_len), &clnt_dict
); if (ret < 0) { do { do { if (0) printf ("failed to unserialize dictionary (%s)"
, ("clnt_dict")); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 533, GF_LOG_WARNING, "failed to unserialize dictionary (%s)"
, ("clnt_dict")); } while (0); op_errno = 22; goto out; } } while
(0)
533 out)do { if (!(args.hndsk.hndsk_len)) break; clnt_dict = dict_new
(); do { if (!clnt_dict) { (*__errno_location ()) = 22; do { do
{ if (0) printf ("invalid argument: " "clnt_dict"); } while (
0); _gf_log_callingfn (this->name, "glusterd-handshake.c",
__FUNCTION__, 533, GF_LOG_ERROR, "invalid argument: " "clnt_dict"
); } while (0); goto out; } } while (0); ret = dict_unserialize
(args.hndsk.hndsk_val, (args.hndsk.hndsk_len), &clnt_dict
); if (ret < 0) { do { do { if (0) printf ("failed to unserialize dictionary (%s)"
, ("clnt_dict")); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 533, GF_LOG_WARNING, "failed to unserialize dictionary (%s)"
, ("clnt_dict")); } while (0); op_errno = 22; goto out; } } while
(0)
;
534
535 ret = dict_get_int32 (clnt_dict, GD_OP_VERSION_KEY"operating-version", &peer_op_version);
536 if (ret) {
537 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to get the op-version key peer=%s"
, req->trans->peerinfo.identifier); } while (0); _gf_log
(this->name, "glusterd-handshake.c", __FUNCTION__, 539, GF_LOG_WARNING
, "failed to get the op-version key peer=%s", req->trans->
peerinfo.identifier); } while (0)
538 "failed to get the op-version key peer=%s",do { do { if (0) printf ("failed to get the op-version key peer=%s"
, req->trans->peerinfo.identifier); } while (0); _gf_log
(this->name, "glusterd-handshake.c", __FUNCTION__, 539, GF_LOG_WARNING
, "failed to get the op-version key peer=%s", req->trans->
peerinfo.identifier); } while (0)
539 req->trans->peerinfo.identifier)do { do { if (0) printf ("failed to get the op-version key peer=%s"
, req->trans->peerinfo.identifier); } while (0); _gf_log
(this->name, "glusterd-handshake.c", __FUNCTION__, 539, GF_LOG_WARNING
, "failed to get the op-version key peer=%s", req->trans->
peerinfo.identifier); } while (0)
;
540 goto out;
541 }
542
543 ret = gd_validate_cluster_op_version (this, peer_op_version,
544 req->trans->peerinfo.identifier);
545 if (ret)
546 goto out;
547
548
549 /* As this is ACK from the Cluster for the versions supported,
550 can set the op-version of 'this' glusterd to the one
551 received. */
552 gf_log (this->name, GF_LOG_INFO, "using the op-version %d",do { do { if (0) printf ("using the op-version %d", peer_op_version
); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 553, GF_LOG_INFO, "using the op-version %d", peer_op_version
); } while (0)
553 peer_op_version)do { do { if (0) printf ("using the op-version %d", peer_op_version
); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 553, GF_LOG_INFO, "using the op-version %d", peer_op_version
); } while (0)
;
554 conf->op_version = peer_op_version;
555 ret = glusterd_store_global_info (this);
556 if (ret)
557 gf_log (this->name, GF_LOG_ERROR, "Failed to store op-version")do { do { if (0) printf ("Failed to store op-version"); } while
(0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 557, GF_LOG_ERROR, "Failed to store op-version"); } while (
0)
;
558
559out:
560 rsp.op_ret = ret;
561 rsp.op_errno = op_errno;
562
563 glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0),
564 (xdrproc_t)xdr_gf_mgmt_hndsk_rsp);
565
566 ret = 0;
567
568 if (clnt_dict)
569 dict_unref (clnt_dict);
570
571 if (args.hndsk.hndsk_val)
572 free (args.hndsk.hndsk_val);
573
574 return ret;
575}
576
577int
578glusterd_mgmt_hndsk_versions_ack (rpcsvc_request_t *req)
579{
580 return glusterd_big_locked_handler (req,
581 __glusterd_mgmt_hndsk_versions_ack);
582}
583
584rpcsvc_actor_t gluster_handshake_actors[] = {
585 [GF_HNDSK_NULL] = {"NULL", GF_HNDSK_NULL, NULL((void*)0), NULL((void*)0), 0},
586 [GF_HNDSK_GETSPEC] = {"GETSPEC", GF_HNDSK_GETSPEC,
587 server_getspec, NULL((void*)0), 0},
588 [GF_HNDSK_EVENT_NOTIFY] = {"EVENTNOTIFY", GF_HNDSK_EVENT_NOTIFY,
589 server_event_notify, NULL((void*)0), 0},
590};
591
592
593struct rpcsvc_program gluster_handshake_prog = {
594 .progname = "Gluster Handshake",
595 .prognum = GLUSTER_HNDSK_PROGRAM14398633,
596 .progver = GLUSTER_HNDSK_VERSION2,
597 .actors = gluster_handshake_actors,
598 .numactors = GF_HNDSK_MAXVALUE,
599};
600
601
602char *glusterd_dump_proc[GF_DUMP_MAXVALUE] = {
603 [GF_DUMP_NULL] = "NULL",
604 [GF_DUMP_DUMP] = "DUMP",
605};
606
607rpc_clnt_prog_t glusterd_dump_prog = {
608 .progname = "GLUSTERD-DUMP",
609 .prognum = GLUSTER_DUMP_PROGRAM123451501,
610 .progver = GLUSTER_DUMP_VERSION1,
611 .procnames = glusterd_dump_proc,
612};
613
614
615rpcsvc_actor_t glusterd_mgmt_hndsk_actors[] = {
616 [GD_MGMT_HNDSK_NULL] = {"NULL", GD_MGMT_HNDSK_NULL, NULL((void*)0),
617 NULL((void*)0), 0},
618 [GD_MGMT_HNDSK_VERSIONS] = {"MGMT-VERS", GD_MGMT_HNDSK_VERSIONS,
619 glusterd_mgmt_hndsk_versions, NULL((void*)0),
620 0},
621 [GD_MGMT_HNDSK_VERSIONS_ACK] = {"MGMT-VERS-ACK",
622 GD_MGMT_HNDSK_VERSIONS_ACK,
623 glusterd_mgmt_hndsk_versions_ack,
624 NULL((void*)0), 0},
625};
626
627struct rpcsvc_program glusterd_mgmt_hndsk_prog = {
628 .progname = "Gluster MGMT Handshake",
629 .prognum = GD_MGMT_HNDSK_PROGRAM1239873,
630 .progver = GD_MGMT_HNDSK_VERSION1,
631 .actors = glusterd_mgmt_hndsk_actors,
632 .numactors = GD_MGMT_HNDSK_MAXVALUE,
633};
634
635char *glusterd_mgmt_hndsk_proc[GD_MGMT_HNDSK_MAXVALUE] = {
636 [GD_MGMT_HNDSK_NULL] = "NULL",
637 [GD_MGMT_HNDSK_VERSIONS] = "MGMT-VERS",
638 [GD_MGMT_HNDSK_VERSIONS_ACK] = "MGMT-VERS-ACK",
639};
640
641rpc_clnt_prog_t gd_clnt_mgmt_hndsk_prog = {
642 .progname = "Gluster MGMT Handshake",
643 .prognum = GD_MGMT_HNDSK_PROGRAM1239873,
644 .progver = GD_MGMT_HNDSK_VERSION1,
645 .procnames = glusterd_mgmt_hndsk_proc,
646};
647
648
649static int
650glusterd_event_connected_inject (glusterd_peerctx_t *peerctx)
651{
652 GF_ASSERT (peerctx)do { if (!(peerctx)) { do { do { if (0) printf ("Assertion failed: "
"peerctx"); } while (0); _gf_log_callingfn ("", "glusterd-handshake.c"
, __FUNCTION__, 652, GF_LOG_ERROR, "Assertion failed: " "peerctx"
); } while (0); } } while (0)
;
653
654 glusterd_friend_sm_event_t *event = NULL((void*)0);
655 glusterd_probe_ctx_t *ctx = NULL((void*)0);
656 int ret = -1;
657 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
658
659
660 ret = glusterd_friend_sm_new_event
661 (GD_FRIEND_EVENT_CONNECTED, &event);
662
663 if (ret) {
664 gf_log ("", GF_LOG_ERROR, "Unable to get new event")do { do { if (0) printf ("Unable to get new event"); } while (
0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__, 664, GF_LOG_ERROR
, "Unable to get new event"); } while (0)
;
665 goto out;
666 }
667
668 ctx = GF_CALLOC (1, sizeof(*ctx), gf_gld_mt_probe_ctx_t)__gf_calloc (1, sizeof(*ctx), gf_gld_mt_probe_ctx_t);
669
670 if (!ctx) {
671 ret = -1;
672 gf_log ("", GF_LOG_ERROR, "Memory not available")do { do { if (0) printf ("Memory not available"); } while (0)
; _gf_log ("", "glusterd-handshake.c", __FUNCTION__, 672, GF_LOG_ERROR
, "Memory not available"); } while (0)
;
673 goto out;
674 }
675
676 peerinfo = peerctx->peerinfo;
677 ctx->hostname = gf_strdup (peerinfo->hostname);
678 ctx->port = peerinfo->port;
679 ctx->req = peerctx->args.req;
680
681 event->peerinfo = peerinfo;
682 event->ctx = ctx;
683
684 ret = glusterd_friend_sm_inject_event (event);
685
686 if (ret) {
687 gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject "do { do { if (0) printf ("Unable to inject " "EVENT_CONNECTED ret = %d"
, ret); } while (0); _gf_log ("glusterd", "glusterd-handshake.c"
, __FUNCTION__, 688, GF_LOG_ERROR, "Unable to inject " "EVENT_CONNECTED ret = %d"
, ret); } while (0)
688 "EVENT_CONNECTED ret = %d", ret)do { do { if (0) printf ("Unable to inject " "EVENT_CONNECTED ret = %d"
, ret); } while (0); _gf_log ("glusterd", "glusterd-handshake.c"
, __FUNCTION__, 688, GF_LOG_ERROR, "Unable to inject " "EVENT_CONNECTED ret = %d"
, ret); } while (0)
;
689 goto out;
690 }
691
692out:
693 gf_log ("", GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log
("", "glusterd-handshake.c", __FUNCTION__, 693, GF_LOG_DEBUG
, "returning %d", ret); } while (0)
;
694 return ret;
695}
696
697
698int
699gd_validate_peer_op_version (xlator_t *this, glusterd_peerinfo_t *peerinfo,
700 dict_t *dict, char **errstr)
701{
702 int ret = -1;
703 glusterd_conf_t *conf = NULL((void*)0);
704 int32_t peer_op_version = 0;
705 int32_t peer_min_op_version = 0;
706 int32_t peer_max_op_version = 0;
707
708 if (!dict && !this && !peerinfo)
709 goto out;
710
711 conf = this->private;
712
713 ret = dict_get_int32 (dict, GD_OP_VERSION_KEY"operating-version", &peer_op_version);
714 if (ret)
715 goto out;
716
717 ret = dict_get_int32 (dict, GD_MAX_OP_VERSION_KEY"maximum-operating-version",
718 &peer_max_op_version);
719 if (ret)
720 goto out;
721
722 ret = dict_get_int32 (dict, GD_MIN_OP_VERSION_KEY"minimum-operating-version",
723 &peer_min_op_version);
724 if (ret)
725 goto out;
726
727 ret = -1;
728 /* Check if peer can support our op_version */
729 if ((peer_max_op_version < conf->op_version) ||
730 (peer_min_op_version > conf->op_version)) {
731 ret = gf_asprintf (errstr, "Peer %s does not support required "
732 "op-version", peerinfo->hostname);
733 ret = -1;
734 goto out;
735 }
736
737 /* If peer is already operating at a higher op_version reject it.
738 * Cluster cannot be moved to higher op_version to accomodate a peer.
739 */
740 if (peer_op_version > conf->op_version) {
741 ret = gf_asprintf (errstr, "Peer %s is already at a higher "
742 "op-version", peerinfo->hostname);
743 ret = -1;
744 goto out;
745 }
746
747 ret = 0;
748out:
749 gf_log (this->name , GF_LOG_DEBUG, "Peer %s %s", peerinfo->hostname,do { do { if (0) printf ("Peer %s %s", peerinfo->hostname,
((ret < 0) ? "rejected" : "accepted")); } while (0); _gf_log
(this->name, "glusterd-handshake.c", __FUNCTION__, 750, GF_LOG_DEBUG
, "Peer %s %s", peerinfo->hostname, ((ret < 0) ? "rejected"
: "accepted")); } while (0)
750 ((ret < 0) ? "rejected" : "accepted"))do { do { if (0) printf ("Peer %s %s", peerinfo->hostname,
((ret < 0) ? "rejected" : "accepted")); } while (0); _gf_log
(this->name, "glusterd-handshake.c", __FUNCTION__, 750, GF_LOG_DEBUG
, "Peer %s %s", peerinfo->hostname, ((ret < 0) ? "rejected"
: "accepted")); } while (0)
;
751 return ret;
752}
753
754int
755__glusterd_mgmt_hndsk_version_ack_cbk (struct rpc_req *req, struct iovec *iov,
756 int count, void *myframe)
757{
758 int ret = -1;
759 int op_errno = EINVAL22;
760 gf_mgmt_hndsk_rsp rsp = {0,};
761 xlator_t *this = NULL((void*)0);
762 call_frame_t *frame = NULL((void*)0);
763 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
764 glusterd_peerctx_t *peerctx = NULL((void*)0);
765 char msg[1024] = {0,};
766
767 this = THIS(*__glusterfs_this_location());
768 frame = myframe;
769 peerctx = frame->local;
770 peerinfo = peerctx->peerinfo;
771
772 if (-1 == req->rpc_status) {
773 snprintf (msg, sizeof (msg),
774 "Error through RPC layer, retry again later");
775 gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (""
, "glusterd-handshake.c", __FUNCTION__, 775, GF_LOG_ERROR, "%s"
, msg); } while (0)
;
776 peerctx->errstr = gf_strdup (msg);
777 goto out;
778 }
779
780 ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_mgmt_hndsk_rsp);
781 if (ret < 0) {
782 snprintf (msg, sizeof (msg), "Failed to decode XDR");
783 gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (""
, "glusterd-handshake.c", __FUNCTION__, 783, GF_LOG_ERROR, "%s"
, msg); } while (0)
;
784 peerctx->errstr = gf_strdup (msg);
785 goto out;
786 }
787
788 op_errno = rsp.op_errno;
789 if (-1 == rsp.op_ret) {
790 ret = -1;
791 snprintf (msg, sizeof (msg),
792 "Failed to get handshake ack from remote server");
793 gf_log (frame->this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (frame
->this->name, "glusterd-handshake.c", __FUNCTION__, 793
, GF_LOG_ERROR, "%s", msg); } while (0)
;
794 peerctx->errstr = gf_strdup (msg);
795 goto out;
796 }
797
798 /* TODO: this is hardcoded as of now, but I don't forsee any problems
799 * with this as long as we are properly handshaking operating versions
800 */
801 peerinfo->mgmt = &gd_mgmt_prog;
802 peerinfo->peer = &gd_peer_prog;
803
804 ret = default_notify (this, GF_EVENT_CHILD_UP, NULL((void*)0));
805
806 if (GD_MODE_ON == peerctx->args.mode) {
807 ret = glusterd_event_connected_inject (peerctx);
808 peerctx->args.req = NULL((void*)0);
809 } else if (GD_MODE_SWITCH_ON == peerctx->args.mode) {
810 peerctx->args.mode = GD_MODE_ON;
811 } else {
812 gf_log (this->name, GF_LOG_WARNING, "unknown mode %d",do { do { if (0) printf ("unknown mode %d", peerctx->args.
mode); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 813, GF_LOG_WARNING, "unknown mode %d", peerctx
->args.mode); } while (0)
813 peerctx->args.mode)do { do { if (0) printf ("unknown mode %d", peerctx->args.
mode); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 813, GF_LOG_WARNING, "unknown mode %d", peerctx
->args.mode); } while (0)
;
814 }
815
816 glusterd_friend_sm ();
817
818 ret = 0;
819out:
820
821 frame->local = NULL((void*)0);
822 STACK_DESTROY (frame->root);
823
824 if (ret != 0)
825 rpc_transport_disconnect (peerinfo->rpc->conn.trans);
826
827 if (rsp.hndsk.hndsk_val)
828 free (rsp.hndsk.hndsk_val);
829
830 return 0;
831}
832
833int
834glusterd_mgmt_hndsk_version_ack_cbk (struct rpc_req *req, struct iovec *iov,
835 int count, void *myframe)
836{
837 return glusterd_big_locked_cbk (req, iov, count, myframe,
838 __glusterd_mgmt_hndsk_version_ack_cbk);
839}
840
841int
842__glusterd_mgmt_hndsk_version_cbk (struct rpc_req *req, struct iovec *iov,
843 int count, void *myframe)
844{
845 int ret = -1;
846 int op_errno = EINVAL22;
847 gf_mgmt_hndsk_rsp rsp = {0,};
848 gf_mgmt_hndsk_req arg = {{0,}};
849 xlator_t *this = NULL((void*)0);
850 call_frame_t *frame = NULL((void*)0);
851 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
852 glusterd_peerctx_t *peerctx = NULL((void*)0);
853 dict_t *dict = NULL((void*)0);
854 dict_t *rsp_dict = NULL((void*)0);
855 glusterd_conf_t *conf = NULL((void*)0);
856 char msg[1024] = {0,};
857
858 this = THIS(*__glusterfs_this_location());
859 conf = this->private;
860 frame = myframe;
861 peerctx = frame->local;
862 peerinfo = peerctx->peerinfo;
863
864 if (-1 == req->rpc_status) {
865 ret = -1;
866 snprintf (msg, sizeof (msg),
867 "Error through RPC layer, retry again later");
868 gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this
->name, "glusterd-handshake.c", __FUNCTION__, 868, GF_LOG_ERROR
, "%s", msg); } while (0)
;
869 peerctx->errstr = gf_strdup (msg);
870 goto out;
871 }
872
873 ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_mgmt_hndsk_rsp);
874 if (ret < 0) {
875 snprintf (msg, sizeof (msg), "Failed to decode management "
876 "handshake response");
877 gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this
->name, "glusterd-handshake.c", __FUNCTION__, 877, GF_LOG_ERROR
, "%s", msg); } while (0)
;
878 peerctx->errstr = gf_strdup (msg);
879 goto out;
880 }
881
882 GF_PROTOCOL_DICT_UNSERIALIZE (this, dict, rsp.hndsk.hndsk_val,do { if (!rsp.hndsk.hndsk_len) break; dict = dict_new(); do {
if (!dict) { (*__errno_location ()) = 22; do { do { if (0) printf
("invalid argument: " "dict"); } while (0); _gf_log_callingfn
(this->name, "glusterd-handshake.c", __FUNCTION__, 884, GF_LOG_ERROR
, "invalid argument: " "dict"); } while (0); goto out; } } while
(0); ret = dict_unserialize (rsp.hndsk.hndsk_val, rsp.hndsk.
hndsk_len, &dict); if (ret < 0) { do { do { if (0) printf
("failed to unserialize dictionary (%s)", ("dict")); } while
(0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 884, GF_LOG_WARNING, "failed to unserialize dictionary (%s)"
, ("dict")); } while (0); op_errno = 22; goto out; } } while (
0)
883 rsp.hndsk.hndsk_len, ret, op_errno,do { if (!rsp.hndsk.hndsk_len) break; dict = dict_new(); do {
if (!dict) { (*__errno_location ()) = 22; do { do { if (0) printf
("invalid argument: " "dict"); } while (0); _gf_log_callingfn
(this->name, "glusterd-handshake.c", __FUNCTION__, 884, GF_LOG_ERROR
, "invalid argument: " "dict"); } while (0); goto out; } } while
(0); ret = dict_unserialize (rsp.hndsk.hndsk_val, rsp.hndsk.
hndsk_len, &dict); if (ret < 0) { do { do { if (0) printf
("failed to unserialize dictionary (%s)", ("dict")); } while
(0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 884, GF_LOG_WARNING, "failed to unserialize dictionary (%s)"
, ("dict")); } while (0); op_errno = 22; goto out; } } while (
0)
884 out)do { if (!rsp.hndsk.hndsk_len) break; dict = dict_new(); do {
if (!dict) { (*__errno_location ()) = 22; do { do { if (0) printf
("invalid argument: " "dict"); } while (0); _gf_log_callingfn
(this->name, "glusterd-handshake.c", __FUNCTION__, 884, GF_LOG_ERROR
, "invalid argument: " "dict"); } while (0); goto out; } } while
(0); ret = dict_unserialize (rsp.hndsk.hndsk_val, rsp.hndsk.
hndsk_len, &dict); if (ret < 0) { do { do { if (0) printf
("failed to unserialize dictionary (%s)", ("dict")); } while
(0); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 884, GF_LOG_WARNING, "failed to unserialize dictionary (%s)"
, ("dict")); } while (0); op_errno = 22; goto out; } } while (
0)
;
885
886 op_errno = rsp.op_errno;
Value stored to 'op_errno' is never read
887 if (-1 == rsp.op_ret) {
888 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to get the 'versions' from peer (%s)"
, req->conn->trans->peerinfo.identifier); } while (0
); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 890, GF_LOG_ERROR, "failed to get the 'versions' from peer (%s)"
, req->conn->trans->peerinfo.identifier); } while (0
)
889 "failed to get the 'versions' from peer (%s)",do { do { if (0) printf ("failed to get the 'versions' from peer (%s)"
, req->conn->trans->peerinfo.identifier); } while (0
); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 890, GF_LOG_ERROR, "failed to get the 'versions' from peer (%s)"
, req->conn->trans->peerinfo.identifier); } while (0
)
890 req->conn->trans->peerinfo.identifier)do { do { if (0) printf ("failed to get the 'versions' from peer (%s)"
, req->conn->trans->peerinfo.identifier); } while (0
); _gf_log (this->name, "glusterd-handshake.c", __FUNCTION__
, 890, GF_LOG_ERROR, "failed to get the 'versions' from peer (%s)"
, req->conn->trans->peerinfo.identifier); } while (0
)
;
891 goto out;
892 }
893
894 /* Check if peer can be part of cluster */
895 ret = gd_validate_peer_op_version (this, peerinfo, dict,
896 &peerctx->errstr);
897 if (ret < 0) {
898 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to validate the operating version of peer (%s)"
, peerinfo->hostname); } while (0); _gf_log (this->name
, "glusterd-handshake.c", __FUNCTION__, 900, GF_LOG_ERROR, "failed to validate the operating version of peer (%s)"
, peerinfo->hostname); } while (0)
899 "failed to validate the operating version of peer (%s)",do { do { if (0) printf ("failed to validate the operating version of peer (%s)"
, peerinfo->hostname); } while (0); _gf_log (this->name
, "glusterd-handshake.c", __FUNCTION__, 900, GF_LOG_ERROR, "failed to validate the operating version of peer (%s)"
, peerinfo->hostname); } while (0)
900 peerinfo->hostname)do { do { if (0) printf ("failed to validate the operating version of peer (%s)"
, peerinfo->hostname); } while (0); _gf_log (this->name
, "glusterd-handshake.c", __FUNCTION__, 900, GF_LOG_ERROR, "failed to validate the operating version of peer (%s)"
, peerinfo->hostname); } while (0)
;
901 goto out;
902 }
903
904 rsp_dict = dict_new ();
905 if (!rsp_dict)
906 goto out;
907
908 ret = dict_set_int32 (rsp_dict, GD_OP_VERSION_KEY"operating-version", conf->op_version);
909 if (ret) {
910 gf_log(this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to set operating version in dict"
); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 911, GF_LOG_ERROR, "failed to set operating version in dict"
); } while (0)
911 "failed to set operating version in dict")do { do { if (0) printf ("failed to set operating version in dict"
); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 911, GF_LOG_ERROR, "failed to set operating version in dict"
); } while (0)
;
912 goto out;
913 }
914
915 GF_PROTOCOL_DICT_SERIALIZE (this, rsp_dict, (&arg.hndsk.hndsk_val),do { int ret = 0; if (!rsp_dict) break; ret = dict_allocate_and_serialize
(rsp_dict, (&arg.hndsk.hndsk_val), &arg.hndsk.hndsk_len
); if (ret < 0) { do { do { if (0) printf ("failed to get serialized dict (%s)"
, ("rsp_dict")); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 916, GF_LOG_WARNING, "failed to get serialized dict (%s)"
, ("rsp_dict")); } while (0); op_errno = 22; goto out; } } while
(0)
916 arg.hndsk.hndsk_len, op_errno, out)do { int ret = 0; if (!rsp_dict) break; ret = dict_allocate_and_serialize
(rsp_dict, (&arg.hndsk.hndsk_val), &arg.hndsk.hndsk_len
); if (ret < 0) { do { do { if (0) printf ("failed to get serialized dict (%s)"
, ("rsp_dict")); } while (0); _gf_log (this->name, "glusterd-handshake.c"
, __FUNCTION__, 916, GF_LOG_WARNING, "failed to get serialized dict (%s)"
, ("rsp_dict")); } while (0); op_errno = 22; goto out; } } while
(0)
;
917
918 ret = glusterd_submit_request (peerctx->peerinfo->rpc, &arg, frame,
919 &gd_clnt_mgmt_hndsk_prog,
920 GD_MGMT_HNDSK_VERSIONS_ACK, NULL((void*)0), this,
921 glusterd_mgmt_hndsk_version_ack_cbk,
922 (xdrproc_t)xdr_gf_mgmt_hndsk_req);
923
924out:
925 if (ret) {
926 frame->local = NULL((void*)0);
927 STACK_DESTROY (frame->root);
928 rpc_transport_disconnect (peerinfo->rpc->conn.trans);
929 }
930
931 if (rsp.hndsk.hndsk_val)
932 free (rsp.hndsk.hndsk_val);
933
934 if (arg.hndsk.hndsk_val)
935 GF_FREE (arg.hndsk.hndsk_val)__gf_free (arg.hndsk.hndsk_val);
936
937 if (dict)
938 dict_unref (dict);
939
940 if (rsp_dict)
941 dict_unref (rsp_dict);
942
943 return 0;
944}
945
946int
947glusterd_mgmt_hndsk_version_cbk (struct rpc_req *req, struct iovec *iov,
948 int count, void *myframe)
949{
950 return glusterd_big_locked_cbk (req, iov, count, myframe,
951 __glusterd_mgmt_hndsk_version_cbk);
952}
953
954int
955glusterd_mgmt_handshake (xlator_t *this, glusterd_peerctx_t *peerctx)
956{
957 call_frame_t *frame = NULL((void*)0);
958 gf_mgmt_hndsk_req req = {{0,},};
959 int ret = -1;
960
961 frame = create_frame (this, this->ctx->pool);
962 if (!frame)
963 goto out;
964
965 frame->local = peerctx;
966
967 ret = glusterd_submit_request (peerctx->peerinfo->rpc, &req, frame,
968 &gd_clnt_mgmt_hndsk_prog,
969 GD_MGMT_HNDSK_VERSIONS, NULL((void*)0), this,
970 glusterd_mgmt_hndsk_version_cbk,
971 (xdrproc_t)xdr_gf_mgmt_hndsk_req);
972 ret = 0;
973out:
974 if (ret && frame)
975 STACK_DESTROY (frame->root);
976
977 return ret;
978}
979
980int
981glusterd_set_clnt_mgmt_program (glusterd_peerinfo_t *peerinfo,
982 gf_prog_detail *prog)
983{
984 gf_prog_detail *trav = NULL((void*)0);
985 int ret = -1;
986
987 if (!peerinfo || !prog)
988 goto out;
989
990 trav = prog;
991
992 while (trav) {
993 ret = -1;
994 if ((gd_mgmt_prog.prognum == trav->prognum) &&
995 (gd_mgmt_prog.progver == trav->progver)) {
996 peerinfo->mgmt = &gd_mgmt_prog;
997 ret = 0;
998 }
999
1000 if ((gd_peer_prog.prognum == trav->prognum) &&
1001 (gd_peer_prog.progver == trav->progver)) {
1002 peerinfo->peer = &gd_peer_prog;
1003 ret = 0;
1004 }
1005
1006 if (ret) {
1007 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("%s (%""ll" "d"":%""ll" "d"") not supported"
, trav->progname, trav->prognum, trav->progver); } while
(0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__, 1010
, GF_LOG_DEBUG, "%s (%""ll" "d"":%""ll" "d"") not supported",
trav->progname, trav->prognum, trav->progver); } while
(0)
1008 "%s (%"PRId64":%"PRId64") not supported",do { do { if (0) printf ("%s (%""ll" "d"":%""ll" "d"") not supported"
, trav->progname, trav->prognum, trav->progver); } while
(0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__, 1010
, GF_LOG_DEBUG, "%s (%""ll" "d"":%""ll" "d"") not supported",
trav->progname, trav->prognum, trav->progver); } while
(0)
1009 trav->progname, trav->prognum,do { do { if (0) printf ("%s (%""ll" "d"":%""ll" "d"") not supported"
, trav->progname, trav->prognum, trav->progver); } while
(0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__, 1010
, GF_LOG_DEBUG, "%s (%""ll" "d"":%""ll" "d"") not supported",
trav->progname, trav->prognum, trav->progver); } while
(0)
1010 trav->progver)do { do { if (0) printf ("%s (%""ll" "d"":%""ll" "d"") not supported"
, trav->progname, trav->prognum, trav->progver); } while
(0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__, 1010
, GF_LOG_DEBUG, "%s (%""ll" "d"":%""ll" "d"") not supported",
trav->progname, trav->prognum, trav->progver); } while
(0)
;
1011 }
1012
1013 trav = trav->next;
1014 }
1015
1016 if (peerinfo->mgmt) {
1017 gf_log ("", GF_LOG_INFO,do { do { if (0) printf ("Using Program %s, Num (%d), Version (%d)"
, peerinfo->mgmt->progname, peerinfo->mgmt->prognum
, peerinfo->mgmt->progver); } while (0); _gf_log ("", "glusterd-handshake.c"
, __FUNCTION__, 1020, GF_LOG_INFO, "Using Program %s, Num (%d), Version (%d)"
, peerinfo->mgmt->progname, peerinfo->mgmt->prognum
, peerinfo->mgmt->progver); } while (0)
1018 "Using Program %s, Num (%d), Version (%d)",do { do { if (0) printf ("Using Program %s, Num (%d), Version (%d)"
, peerinfo->mgmt->progname, peerinfo->mgmt->prognum
, peerinfo->mgmt->progver); } while (0); _gf_log ("", "glusterd-handshake.c"
, __FUNCTION__, 1020, GF_LOG_INFO, "Using Program %s, Num (%d), Version (%d)"
, peerinfo->mgmt->progname, peerinfo->mgmt->prognum
, peerinfo->mgmt->progver); } while (0)
1019 peerinfo->mgmt->progname, peerinfo->mgmt->prognum,do { do { if (0) printf ("Using Program %s, Num (%d), Version (%d)"
, peerinfo->mgmt->progname, peerinfo->mgmt->prognum
, peerinfo->mgmt->progver); } while (0); _gf_log ("", "glusterd-handshake.c"
, __FUNCTION__, 1020, GF_LOG_INFO, "Using Program %s, Num (%d), Version (%d)"
, peerinfo->mgmt->progname, peerinfo->mgmt->prognum
, peerinfo->mgmt->progver); } while (0)
1020 peerinfo->mgmt->progver)do { do { if (0) printf ("Using Program %s, Num (%d), Version (%d)"
, peerinfo->mgmt->progname, peerinfo->mgmt->prognum
, peerinfo->mgmt->progver); } while (0); _gf_log ("", "glusterd-handshake.c"
, __FUNCTION__, 1020, GF_LOG_INFO, "Using Program %s, Num (%d), Version (%d)"
, peerinfo->mgmt->progname, peerinfo->mgmt->prognum
, peerinfo->mgmt->progver); } while (0)
;
1021 }
1022
1023 if (peerinfo->peer) {
1024 gf_log ("", GF_LOG_INFO,do { do { if (0) printf ("Using Program %s, Num (%d), Version (%d)"
, peerinfo->peer->progname, peerinfo->peer->prognum
, peerinfo->peer->progver); } while (0); _gf_log ("", "glusterd-handshake.c"
, __FUNCTION__, 1027, GF_LOG_INFO, "Using Program %s, Num (%d), Version (%d)"
, peerinfo->peer->progname, peerinfo->peer->prognum
, peerinfo->peer->progver); } while (0)
1025 "Using Program %s, Num (%d), Version (%d)",do { do { if (0) printf ("Using Program %s, Num (%d), Version (%d)"
, peerinfo->peer->progname, peerinfo->peer->prognum
, peerinfo->peer->progver); } while (0); _gf_log ("", "glusterd-handshake.c"
, __FUNCTION__, 1027, GF_LOG_INFO, "Using Program %s, Num (%d), Version (%d)"
, peerinfo->peer->progname, peerinfo->peer->prognum
, peerinfo->peer->progver); } while (0)
1026 peerinfo->peer->progname, peerinfo->peer->prognum,do { do { if (0) printf ("Using Program %s, Num (%d), Version (%d)"
, peerinfo->peer->progname, peerinfo->peer->prognum
, peerinfo->peer->progver); } while (0); _gf_log ("", "glusterd-handshake.c"
, __FUNCTION__, 1027, GF_LOG_INFO, "Using Program %s, Num (%d), Version (%d)"
, peerinfo->peer->progname, peerinfo->peer->prognum
, peerinfo->peer->progver); } while (0)
1027 peerinfo->peer->progver)do { do { if (0) printf ("Using Program %s, Num (%d), Version (%d)"
, peerinfo->peer->progname, peerinfo->peer->prognum
, peerinfo->peer->progver); } while (0); _gf_log ("", "glusterd-handshake.c"
, __FUNCTION__, 1027, GF_LOG_INFO, "Using Program %s, Num (%d), Version (%d)"
, peerinfo->peer->progname, peerinfo->peer->prognum
, peerinfo->peer->progver); } while (0)
;
1028 }
1029 ret = 0;
1030out:
1031 return ret;
1032
1033}
1034
1035static gf_boolean_t
1036_mgmt_hndsk_prog_present (gf_prog_detail *prog) {
1037 gf_boolean_t ret = _gf_false;
1038 gf_prog_detail *trav = NULL((void*)0);
1039
1040 GF_ASSERT (prog)do { if (!(prog)) { do { do { if (0) printf ("Assertion failed: "
"prog"); } while (0); _gf_log_callingfn ("", "glusterd-handshake.c"
, __FUNCTION__, 1040, GF_LOG_ERROR, "Assertion failed: " "prog"
); } while (0); } } while (0)
;
1041
1042 trav = prog;
1043
1044 while (trav) {
1045 if ((trav->prognum == GD_MGMT_HNDSK_PROGRAM1239873) &&
1046 (trav->progver == GD_MGMT_HNDSK_VERSION1)) {
1047 ret = _gf_true;
1048 goto out;
1049 }
1050 trav = trav->next;
1051 }
1052out:
1053 return ret;
1054}
1055
1056int
1057__glusterd_peer_dump_version_cbk (struct rpc_req *req, struct iovec *iov,
1058 int count, void *myframe)
1059{
1060 int ret = -1;
1061 gf_dump_rsp rsp = {0,};
1062 xlator_t *this = NULL((void*)0);
1063 gf_prog_detail *trav = NULL((void*)0);
1064 gf_prog_detail *next = NULL((void*)0);
1065 call_frame_t *frame = NULL((void*)0);
1066 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
1067 glusterd_peerctx_t *peerctx = NULL((void*)0);
1068 glusterd_conf_t *conf = NULL((void*)0);
1069 char msg[1024] = {0,};
1070
1071 this = THIS(*__glusterfs_this_location());
1072 conf = this->private;
1073 frame = myframe;
1074 peerctx = frame->local;
1075 peerinfo = peerctx->peerinfo;
1076
1077 if (-1 == req->rpc_status) {
1078 snprintf (msg, sizeof (msg),
1079 "Error through RPC layer, retry again later");
1080 gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (""
, "glusterd-handshake.c", __FUNCTION__, 1080, GF_LOG_ERROR, "%s"
, msg); } while (0)
;
1081 peerctx->errstr = gf_strdup (msg);
1082 goto out;
1083 }
1084
1085 ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_dump_rsp);
1086 if (ret < 0) {
1087 snprintf (msg, sizeof (msg), "Failed to decode XDR");
1088 gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (""
, "glusterd-handshake.c", __FUNCTION__, 1088, GF_LOG_ERROR, "%s"
, msg); } while (0)
;
1089 peerctx->errstr = gf_strdup (msg);
1090 goto out;
1091 }
1092 if (-1 == rsp.op_ret) {
1093 snprintf (msg, sizeof (msg),
1094 "Failed to get the 'versions' from remote server");
1095 gf_log (frame->this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (frame
->this->name, "glusterd-handshake.c", __FUNCTION__, 1095
, GF_LOG_ERROR, "%s", msg); } while (0)
;
1096 peerctx->errstr = gf_strdup (msg);
1097 goto out;
1098 }
1099
1100 if (_mgmt_hndsk_prog_present (rsp.prog)) {
1101 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Proceeding to op-version handshake with peer %s"
, peerinfo->hostname); } while (0); _gf_log (this->name
, "glusterd-handshake.c", __FUNCTION__, 1103, GF_LOG_DEBUG, "Proceeding to op-version handshake with peer %s"
, peerinfo->hostname); } while (0)
1102 "Proceeding to op-version handshake with peer %s",do { do { if (0) printf ("Proceeding to op-version handshake with peer %s"
, peerinfo->hostname); } while (0); _gf_log (this->name
, "glusterd-handshake.c", __FUNCTION__, 1103, GF_LOG_DEBUG, "Proceeding to op-version handshake with peer %s"
, peerinfo->hostname); } while (0)
1103 peerinfo->hostname)do { do { if (0) printf ("Proceeding to op-version handshake with peer %s"
, peerinfo->hostname); } while (0); _gf_log (this->name
, "glusterd-handshake.c", __FUNCTION__, 1103, GF_LOG_DEBUG, "Proceeding to op-version handshake with peer %s"
, peerinfo->hostname); } while (0)
;
1104 ret = glusterd_mgmt_handshake (this, peerctx);
1105 goto out;
1106 } else if (conf->op_version > 1) {
1107 ret = -1;
1108 snprintf (msg, sizeof (msg),
1109 "Peer %s does not support required op-version",
1110 peerinfo->hostname);
1111 peerctx->errstr = gf_strdup (msg);
1112 gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this
->name, "glusterd-handshake.c", __FUNCTION__, 1112, GF_LOG_ERROR
, "%s", msg); } while (0)
;
1113 goto out;
1114 }
1115
1116 /* Make sure we assign the proper program to peer */
1117 ret = glusterd_set_clnt_mgmt_program (peerinfo, rsp.prog);
1118 if (ret) {
1119 gf_log ("", GF_LOG_WARNING, "failed to set the mgmt program")do { do { if (0) printf ("failed to set the mgmt program"); }
while (0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__
, 1119, GF_LOG_WARNING, "failed to set the mgmt program"); } while
(0)
;
1120 goto out;
1121 }
1122
1123 ret = default_notify (this, GF_EVENT_CHILD_UP, NULL((void*)0));
1124
1125 if (GD_MODE_ON == peerctx->args.mode) {
1126 ret = glusterd_event_connected_inject (peerctx);
1127 peerctx->args.req = NULL((void*)0);
1128 } else if (GD_MODE_SWITCH_ON == peerctx->args.mode) {
1129 peerctx->args.mode = GD_MODE_ON;
1130 } else {
1131 gf_log ("", GF_LOG_WARNING, "unknown mode %d",do { do { if (0) printf ("unknown mode %d", peerctx->args.
mode); } while (0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__
, 1132, GF_LOG_WARNING, "unknown mode %d", peerctx->args.mode
); } while (0)
1132 peerctx->args.mode)do { do { if (0) printf ("unknown mode %d", peerctx->args.
mode); } while (0); _gf_log ("", "glusterd-handshake.c", __FUNCTION__
, 1132, GF_LOG_WARNING, "unknown mode %d", peerctx->args.mode
); } while (0)
;
1133 }
1134
1135 glusterd_friend_sm();
1136 glusterd_op_sm();
1137
1138 ret = 0;
1139
1140out:
1141
1142 /* don't use GF_FREE, buffer was allocated by libc */
1143 if (rsp.prog) {
1144 trav = rsp.prog;
1145 while (trav) {
1146 next = trav->next;
1147 free (trav->progname);
1148 free (trav);
1149 trav = next;
1150 }
1151 }
1152
1153 frame->local = NULL((void*)0);
1154 STACK_DESTROY (frame->root);
1155
1156 if (ret != 0)
1157 rpc_transport_disconnect (peerinfo->rpc->conn.trans);
1158
1159 return 0;
1160}
1161
1162
1163int
1164glusterd_peer_dump_version_cbk (struct rpc_req *req, struct iovec *iov,
1165 int count, void *myframe)
1166{
1167 return glusterd_big_locked_cbk (req, iov, count, myframe,
1168 __glusterd_peer_dump_version_cbk);
1169}
1170
1171int
1172glusterd_peer_dump_version (xlator_t *this, struct rpc_clnt *rpc,
1173 glusterd_peerctx_t *peerctx)
1174{
1175 call_frame_t *frame = NULL((void*)0);
1176 gf_dump_req req = {0,};
1177 int ret = -1;
1178
1179 frame = create_frame (this, this->ctx->pool);
1180 if (!frame)
1181 goto out;
1182
1183 frame->local = peerctx;
1184
1185 req.gfs_id = 0xcafe;
1186
1187 ret = glusterd_submit_request (peerctx->peerinfo->rpc, &req, frame,
1188 &glusterd_dump_prog, GF_DUMP_DUMP,
1189 NULL((void*)0), this,
1190 glusterd_peer_dump_version_cbk,
1191 (xdrproc_t)xdr_gf_dump_req);
1192out:
1193 return ret;
1194}