Bug Summary

File:rpc/rpc-lib/src/rpc-transport.c
Location:line 610, column 18
Description:Dereference of null pointer (loaded from variable 'options')

Annotated Source Code

1/*
2 Copyright (c) 2008-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#include <dlfcn.h>
12#include <stdlib.h>
13#include <stdio.h>
14#include <sys/poll.h>
15#include <fnmatch.h>
16#include <stdint.h>
17
18#ifndef _CONFIG_H
19#define _CONFIG_H
20#include "config.h"
21#endif
22
23#include "logging.h"
24#include "rpc-transport.h"
25#include "glusterfs.h"
26/* FIXME: xlator.h is needed for volume_option_t, need to define the datatype
27 * in some other header
28 */
29#include "xlator.h"
30#include "list.h"
31
32#ifndef GF_OPTION_LIST_EMPTY
33#define GF_OPTION_LIST_EMPTY(_opt)(_opt->value[0] == ((void*)0)) (_opt->value[0] == NULL((void*)0))
34#endif
35
36
37int
38rpc_transport_get_myaddr (rpc_transport_t *this, char *peeraddr, int addrlen,
39 struct sockaddr_storage *sa, size_t salen)
40{
41 int32_t ret = -1;
42 GF_VALIDATE_OR_GOTO ("rpc", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc", "rpc-transport.c", __FUNCTION__, 42, GF_LOG_ERROR, "invalid argument: "
"this"); } while (0); goto out; } } while (0)
;
43
44 ret = this->ops->get_myaddr (this, peeraddr, addrlen, sa, salen);
45
46out:
47 return ret;
48}
49
50int32_t
51rpc_transport_get_myname (rpc_transport_t *this, char *hostname, int hostlen)
52{
53 int32_t ret = -1;
54 GF_VALIDATE_OR_GOTO ("rpc", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc", "rpc-transport.c", __FUNCTION__, 54, GF_LOG_ERROR, "invalid argument: "
"this"); } while (0); goto out; } } while (0)
;
55
56 ret = this->ops->get_myname (this, hostname, hostlen);
57out:
58 return ret;
59}
60
61int32_t
62rpc_transport_get_peername (rpc_transport_t *this, char *hostname, int hostlen)
63{
64 int32_t ret = -1;
65 GF_VALIDATE_OR_GOTO ("rpc", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc", "rpc-transport.c", __FUNCTION__, 65, GF_LOG_ERROR, "invalid argument: "
"this"); } while (0); goto out; } } while (0)
;
66
67 ret = this->ops->get_peername (this, hostname, hostlen);
68out:
69 return ret;
70}
71
72int32_t
73rpc_transport_get_peeraddr (rpc_transport_t *this, char *peeraddr, int addrlen,
74 struct sockaddr_storage *sa, size_t salen)
75{
76 int32_t ret = -1;
77 GF_VALIDATE_OR_GOTO ("rpc", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc", "rpc-transport.c", __FUNCTION__, 77, GF_LOG_ERROR, "invalid argument: "
"this"); } while (0); goto out; } } while (0)
;
78
79 ret = this->ops->get_peeraddr (this, peeraddr, addrlen, sa, salen);
80out:
81 return ret;
82}
83
84void
85rpc_transport_pollin_destroy (rpc_transport_pollin_t *pollin)
86{
87 GF_VALIDATE_OR_GOTO ("rpc", pollin, out)do { if (!pollin) { (*__errno_location ()) = 22; do { do { if
(0) printf ("invalid argument: " "pollin"); } while (0); _gf_log_callingfn
("rpc", "rpc-transport.c", __FUNCTION__, 87, GF_LOG_ERROR, "invalid argument: "
"pollin"); } while (0); goto out; } } while (0)
;
88
89 if (pollin->iobref) {
90 iobref_unref (pollin->iobref);
91 }
92
93 if (pollin->hdr_iobuf) {
94 iobuf_unref (pollin->hdr_iobuf);
95 }
96
97 if (pollin->private) {
98 /* */
99 GF_FREE (pollin->private)__gf_free (pollin->private);
100 }
101
102 GF_FREE (pollin)__gf_free (pollin);
103out:
104 return;
105}
106
107
108rpc_transport_pollin_t *
109rpc_transport_pollin_alloc (rpc_transport_t *this, struct iovec *vector,
110 int count, struct iobuf *hdr_iobuf,
111 struct iobref *iobref, void *private)
112{
113 rpc_transport_pollin_t *msg = NULL((void*)0);
114 msg = GF_CALLOC (1, sizeof (*msg), gf_common_mt_rpc_trans_pollin_t)__gf_calloc (1, sizeof (*msg), gf_common_mt_rpc_trans_pollin_t
)
;
115 if (!msg) {
116 goto out;
117 }
118
119 if (count > 1) {
120 msg->vectored = 1;
121 }
122
123 memcpy (msg->vector, vector, count * sizeof (*vector));
124 msg->count = count;
125 msg->iobref = iobref_ref (iobref);
126 msg->private = private;
127 if (hdr_iobuf)
128 msg->hdr_iobuf = iobuf_ref (hdr_iobuf);
129
130out:
131 return msg;
132}
133
134
135
136rpc_transport_t *
137rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
138{
139 struct rpc_transport *trans = NULL((void*)0), *return_trans = NULL((void*)0);
140 char *name = NULL((void*)0);
141 void *handle = NULL((void*)0);
142 char *type = NULL((void*)0);
143 char str[] = "ERROR";
144 int32_t ret = -1;
145 int8_t is_tcp = 0, is_unix = 0, is_ibsdp = 0;
146 volume_opt_list_t *vol_opt = NULL((void*)0);
147 gf_boolean_t bind_insecure = _gf_false;
148 xlator_t *this = NULL((void*)0);
149
150 GF_VALIDATE_OR_GOTO("rpc-transport", options, fail)do { if (!options) { (*__errno_location ()) = 22; do { do { if
(0) printf ("invalid argument: " "options"); } while (0); _gf_log_callingfn
("rpc-transport", "rpc-transport.c", __FUNCTION__, 150, GF_LOG_ERROR
, "invalid argument: " "options"); } while (0); goto fail; } }
while (0)
;
151 GF_VALIDATE_OR_GOTO("rpc-transport", ctx, fail)do { if (!ctx) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "ctx"); } while (0); _gf_log_callingfn
("rpc-transport", "rpc-transport.c", __FUNCTION__, 151, GF_LOG_ERROR
, "invalid argument: " "ctx"); } while (0); goto fail; } } while
(0)
;
152 GF_VALIDATE_OR_GOTO("rpc-transport", trans_name, fail)do { if (!trans_name) { (*__errno_location ()) = 22; do { do {
if (0) printf ("invalid argument: " "trans_name"); } while (
0); _gf_log_callingfn ("rpc-transport", "rpc-transport.c", __FUNCTION__
, 152, GF_LOG_ERROR, "invalid argument: " "trans_name"); } while
(0); goto fail; } } while (0)
;
153
154 trans = GF_CALLOC (1, sizeof (struct rpc_transport), gf_common_mt_rpc_trans_t)__gf_calloc (1, sizeof (struct rpc_transport), gf_common_mt_rpc_trans_t
)
;
155 if (!trans)
156 goto fail;
157
158 trans->name = gf_strdup (trans_name);
159 if (!trans->name)
160 goto fail;
161
162 trans->ctx = ctx;
163 type = str;
164
165 /* Backward compatibility */
166 ret = dict_get_str (options, "transport-type", &type);
167 if (ret < 0) {
168 ret = dict_set_str (options, "transport-type", "socket");
169 if (ret < 0)
170 gf_log ("dict", GF_LOG_DEBUG,do { do { if (0) printf ("setting transport-type failed"); } while
(0); _gf_log ("dict", "rpc-transport.c", __FUNCTION__, 171, GF_LOG_DEBUG
, "setting transport-type failed"); } while (0)
171 "setting transport-type failed")do { do { if (0) printf ("setting transport-type failed"); } while
(0); _gf_log ("dict", "rpc-transport.c", __FUNCTION__, 171, GF_LOG_DEBUG
, "setting transport-type failed"); } while (0)
;
172 else
173 gf_log ("rpc-transport", GF_LOG_DEBUG,do { do { if (0) printf ("missing 'option transport-type'. defaulting to "
"\"socket\""); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 175, GF_LOG_DEBUG, "missing 'option transport-type'. defaulting to "
"\"socket\""); } while (0)
174 "missing 'option transport-type'. defaulting to "do { do { if (0) printf ("missing 'option transport-type'. defaulting to "
"\"socket\""); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 175, GF_LOG_DEBUG, "missing 'option transport-type'. defaulting to "
"\"socket\""); } while (0)
175 "\"socket\"")do { do { if (0) printf ("missing 'option transport-type'. defaulting to "
"\"socket\""); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 175, GF_LOG_DEBUG, "missing 'option transport-type'. defaulting to "
"\"socket\""); } while (0)
;
176 } else {
177 {
178 /* Backword compatibility to handle * /client,
179 * * /server.
180 */
181 char *tmp = strchr (type, '/');
182 if (tmp)
183 *tmp = '\0';
184 }
185
186 is_tcp = strcmp (type, "tcp");
187 is_unix = strcmp (type, "unix");
188 is_ibsdp = strcmp (type, "ib-sdp");
189 if ((is_tcp == 0) ||
190 (is_unix == 0) ||
191 (is_ibsdp == 0)) {
192 if (is_unix == 0)
193 ret = dict_set_str (options,
194 "transport.address-family",
195 "unix");
196 if (is_ibsdp == 0)
197 ret = dict_set_str (options,
198 "transport.address-family",
199 "inet-sdp");
200
201 if (ret < 0)
202 gf_log ("dict", GF_LOG_DEBUG,do { do { if (0) printf ("setting address-family failed"); } while
(0); _gf_log ("dict", "rpc-transport.c", __FUNCTION__, 203, GF_LOG_DEBUG
, "setting address-family failed"); } while (0)
203 "setting address-family failed")do { do { if (0) printf ("setting address-family failed"); } while
(0); _gf_log ("dict", "rpc-transport.c", __FUNCTION__, 203, GF_LOG_DEBUG
, "setting address-family failed"); } while (0)
;
204
205 ret = dict_set_str (options,
206 "transport-type", "socket");
207 if (ret < 0)
208 gf_log ("dict", GF_LOG_DEBUG,do { do { if (0) printf ("setting transport-type failed"); } while
(0); _gf_log ("dict", "rpc-transport.c", __FUNCTION__, 209, GF_LOG_DEBUG
, "setting transport-type failed"); } while (0)
209 "setting transport-type failed")do { do { if (0) printf ("setting transport-type failed"); } while
(0); _gf_log ("dict", "rpc-transport.c", __FUNCTION__, 209, GF_LOG_DEBUG
, "setting transport-type failed"); } while (0)
;
210 }
211 }
212
213 /* client-bind-insecure is for clients protocol, and
214 * bind-insecure for glusterd. Both mutually exclusive
215 */
216 ret = dict_get_str (options, "client-bind-insecure", &type);
217 if (ret)
218 ret = dict_get_str (options, "bind-insecure", &type);
219 if (ret == 0) {
220 ret = gf_string2boolean (type, &bind_insecure);
221 if (ret < 0) {
222 gf_log ("rcp-transport", GF_LOG_WARNING,do { do { if (0) printf ("bind-insecure option %s is not a" " valid bool option"
, type); } while (0); _gf_log ("rcp-transport", "rpc-transport.c"
, __FUNCTION__, 224, GF_LOG_WARNING, "bind-insecure option %s is not a"
" valid bool option", type); } while (0)
223 "bind-insecure option %s is not a"do { do { if (0) printf ("bind-insecure option %s is not a" " valid bool option"
, type); } while (0); _gf_log ("rcp-transport", "rpc-transport.c"
, __FUNCTION__, 224, GF_LOG_WARNING, "bind-insecure option %s is not a"
" valid bool option", type); } while (0)
224 " valid bool option", type)do { do { if (0) printf ("bind-insecure option %s is not a" " valid bool option"
, type); } while (0); _gf_log ("rcp-transport", "rpc-transport.c"
, __FUNCTION__, 224, GF_LOG_WARNING, "bind-insecure option %s is not a"
" valid bool option", type); } while (0)
;
225 goto fail;
226 }
227 if (_gf_true == bind_insecure)
228 trans->bind_insecure = 1;
229 else
230 trans->bind_insecure = 0;
231 } else {
232 trans->bind_insecure = 0;
233 }
234
235 ret = dict_get_str (options, "transport-type", &type);
236 if (ret < 0) {
237 gf_log ("rpc-transport", GF_LOG_ERROR,do { do { if (0) printf ("'option transport-type <xx>' missing in volume '%s'"
, trans_name); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 239, GF_LOG_ERROR, "'option transport-type <xx>' missing in volume '%s'"
, trans_name); } while (0)
238 "'option transport-type <xx>' missing in volume '%s'",do { do { if (0) printf ("'option transport-type <xx>' missing in volume '%s'"
, trans_name); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 239, GF_LOG_ERROR, "'option transport-type <xx>' missing in volume '%s'"
, trans_name); } while (0)
239 trans_name)do { do { if (0) printf ("'option transport-type <xx>' missing in volume '%s'"
, trans_name); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 239, GF_LOG_ERROR, "'option transport-type <xx>' missing in volume '%s'"
, trans_name); } while (0)
;
240 goto fail;
241 }
242
243 ret = gf_asprintf (&name, "%s/%s.so", RPC_TRANSPORTDIR"/usr/local/lib/glusterfs/3git/rpc-transport", type);
244 if (-1 == ret) {
245 goto fail;
246 }
247
248 gf_log ("rpc-transport", GF_LOG_DEBUG,do { do { if (0) printf ("attempt to load file %s", name); } while
(0); _gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__
, 249, GF_LOG_DEBUG, "attempt to load file %s", name); } while
(0)
249 "attempt to load file %s", name)do { do { if (0) printf ("attempt to load file %s", name); } while
(0); _gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__
, 249, GF_LOG_DEBUG, "attempt to load file %s", name); } while
(0)
;
250
251 handle = dlopen (name, RTLD_NOW0x00002|RTLD_GLOBAL0x00100);
252 if (handle == NULL((void*)0)) {
253 gf_log ("rpc-transport", GF_LOG_ERROR, "%s", dlerror ())do { do { if (0) printf ("%s", dlerror ()); } while (0); _gf_log
("rpc-transport", "rpc-transport.c", __FUNCTION__, 253, GF_LOG_ERROR
, "%s", dlerror ()); } while (0)
;
254 gf_log ("rpc-transport", GF_LOG_WARNING,do { do { if (0) printf ("volume '%s': transport-type '%s' is not valid or "
"not found on this machine", trans_name, type); } while (0);
_gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__, 257
, GF_LOG_WARNING, "volume '%s': transport-type '%s' is not valid or "
"not found on this machine", trans_name, type); } while (0)
255 "volume '%s': transport-type '%s' is not valid or "do { do { if (0) printf ("volume '%s': transport-type '%s' is not valid or "
"not found on this machine", trans_name, type); } while (0);
_gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__, 257
, GF_LOG_WARNING, "volume '%s': transport-type '%s' is not valid or "
"not found on this machine", trans_name, type); } while (0)
256 "not found on this machine",do { do { if (0) printf ("volume '%s': transport-type '%s' is not valid or "
"not found on this machine", trans_name, type); } while (0);
_gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__, 257
, GF_LOG_WARNING, "volume '%s': transport-type '%s' is not valid or "
"not found on this machine", trans_name, type); } while (0)
257 trans_name, type)do { do { if (0) printf ("volume '%s': transport-type '%s' is not valid or "
"not found on this machine", trans_name, type); } while (0);
_gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__, 257
, GF_LOG_WARNING, "volume '%s': transport-type '%s' is not valid or "
"not found on this machine", trans_name, type); } while (0)
;
258 goto fail;
259 }
260
261 trans->dl_handle = handle;
262
263 trans->ops = dlsym (handle, "tops");
264 if (trans->ops == NULL((void*)0)) {
265 gf_log ("rpc-transport", GF_LOG_ERROR,do { do { if (0) printf ("dlsym (rpc_transport_ops) on %s", dlerror
()); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 266, GF_LOG_ERROR, "dlsym (rpc_transport_ops) on %s"
, dlerror ()); } while (0)
266 "dlsym (rpc_transport_ops) on %s", dlerror ())do { do { if (0) printf ("dlsym (rpc_transport_ops) on %s", dlerror
()); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 266, GF_LOG_ERROR, "dlsym (rpc_transport_ops) on %s"
, dlerror ()); } while (0)
;
267 goto fail;
268 }
269
270 *VOID(&(trans->init))((void **) ((void *) &(trans->init))) = dlsym (handle, "init");
271 if (trans->init == NULL((void*)0)) {
272 gf_log ("rpc-transport", GF_LOG_ERROR,do { do { if (0) printf ("dlsym (gf_rpc_transport_init) on %s"
, dlerror ()); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 273, GF_LOG_ERROR, "dlsym (gf_rpc_transport_init) on %s"
, dlerror ()); } while (0)
273 "dlsym (gf_rpc_transport_init) on %s", dlerror ())do { do { if (0) printf ("dlsym (gf_rpc_transport_init) on %s"
, dlerror ()); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 273, GF_LOG_ERROR, "dlsym (gf_rpc_transport_init) on %s"
, dlerror ()); } while (0)
;
274 goto fail;
275 }
276
277 *VOID(&(trans->fini))((void **) ((void *) &(trans->fini))) = dlsym (handle, "fini");
278 if (trans->fini == NULL((void*)0)) {
279 gf_log ("rpc-transport", GF_LOG_ERROR,do { do { if (0) printf ("dlsym (gf_rpc_transport_fini) on %s"
, dlerror ()); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 280, GF_LOG_ERROR, "dlsym (gf_rpc_transport_fini) on %s"
, dlerror ()); } while (0)
280 "dlsym (gf_rpc_transport_fini) on %s", dlerror ())do { do { if (0) printf ("dlsym (gf_rpc_transport_fini) on %s"
, dlerror ()); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 280, GF_LOG_ERROR, "dlsym (gf_rpc_transport_fini) on %s"
, dlerror ()); } while (0)
;
281 goto fail;
282 }
283
284 *VOID(&(trans->reconfigure))((void **) ((void *) &(trans->reconfigure))) = dlsym (handle, "reconfigure");
285 if (trans->fini == NULL((void*)0)) {
286 gf_log ("rpc-transport", GF_LOG_DEBUG,do { do { if (0) printf ("dlsym (gf_rpc_transport_reconfigure) on %s"
, dlerror()); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 287, GF_LOG_DEBUG, "dlsym (gf_rpc_transport_reconfigure) on %s"
, dlerror()); } while (0)
287 "dlsym (gf_rpc_transport_reconfigure) on %s", dlerror())do { do { if (0) printf ("dlsym (gf_rpc_transport_reconfigure) on %s"
, dlerror()); } while (0); _gf_log ("rpc-transport", "rpc-transport.c"
, __FUNCTION__, 287, GF_LOG_DEBUG, "dlsym (gf_rpc_transport_reconfigure) on %s"
, dlerror()); } while (0)
;
288 }
289
290 vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t),__gf_calloc (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t
)
291 gf_common_mt_volume_opt_list_t)__gf_calloc (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t
)
;
292 if (!vol_opt) {
293 goto fail;
294 }
295
296 this = THIS(*__glusterfs_this_location());
297 vol_opt->given_opt = dlsym (handle, "options");
298 if (vol_opt->given_opt == NULL((void*)0)) {
299 gf_log ("rpc-transport", GF_LOG_DEBUG,do { do { if (0) printf ("volume option validation not specified"
); } while (0); _gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__
, 300, GF_LOG_DEBUG, "volume option validation not specified"
); } while (0)
300 "volume option validation not specified")do { do { if (0) printf ("volume option validation not specified"
); } while (0); _gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__
, 300, GF_LOG_DEBUG, "volume option validation not specified"
); } while (0)
;
301 } else {
302 INIT_LIST_HEAD (&vol_opt->list)do { (&vol_opt->list)->next = (&vol_opt->list
)->prev = &vol_opt->list; } while (0)
;
303 list_add_tail (&vol_opt->list, &(this->volume_options));
304 if (xlator_options_validate_list (this, options, vol_opt,
305 NULL((void*)0))) {
306 gf_log ("rpc-transport", GF_LOG_ERROR,do { do { if (0) printf ("volume option validation failed"); }
while (0); _gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__
, 307, GF_LOG_ERROR, "volume option validation failed"); } while
(0)
307 "volume option validation failed")do { do { if (0) printf ("volume option validation failed"); }
while (0); _gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__
, 307, GF_LOG_ERROR, "volume option validation failed"); } while
(0)
;
308 goto fail;
309 }
310 }
311
312 trans->options = options;
313
314 pthread_mutex_init (&trans->lock, NULL((void*)0));
315 trans->xl = this;
316
317 ret = trans->init (trans);
318 if (ret != 0) {
319 gf_log ("rpc-transport", GF_LOG_ERROR,do { do { if (0) printf ("'%s' initialization failed", type);
} while (0); _gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__
, 320, GF_LOG_ERROR, "'%s' initialization failed", type); } while
(0)
320 "'%s' initialization failed", type)do { do { if (0) printf ("'%s' initialization failed", type);
} while (0); _gf_log ("rpc-transport", "rpc-transport.c", __FUNCTION__
, 320, GF_LOG_ERROR, "'%s' initialization failed", type); } while
(0)
;
321 goto fail;
322 }
323
324 return_trans = trans;
325
326 GF_FREE (name)__gf_free (name);
327
328 return return_trans;
329
330fail:
331 if (trans) {
332 GF_FREE (trans->name)__gf_free (trans->name);
333
334 if (trans->dl_handle)
335 dlclose (trans->dl_handle);
336
337 GF_FREE (trans)__gf_free (trans);
338 }
339
340 GF_FREE (name)__gf_free (name);
341
342 if (vol_opt && !list_empty (&vol_opt->list)) {
343 list_del_init (&vol_opt->list);
344 GF_FREE (vol_opt)__gf_free (vol_opt);
345 }
346
347 return NULL((void*)0);
348}
349
350
351int32_t
352rpc_transport_submit_request (rpc_transport_t *this, rpc_transport_req_t *req)
353{
354 int32_t ret = -1;
355
356 GF_VALIDATE_OR_GOTO("rpc_transport", this, fail)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc_transport", "rpc-transport.c", __FUNCTION__, 356, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto fail; } } while
(0)
;
357 GF_VALIDATE_OR_GOTO("rpc_transport", this->ops, fail)do { if (!this->ops) { (*__errno_location ()) = 22; do { do
{ if (0) printf ("invalid argument: " "this->ops"); } while
(0); _gf_log_callingfn ("rpc_transport", "rpc-transport.c", __FUNCTION__
, 357, GF_LOG_ERROR, "invalid argument: " "this->ops"); } while
(0); goto fail; } } while (0)
;
358
359 ret = this->ops->submit_request (this, req);
360fail:
361 return ret;
362}
363
364
365int32_t
366rpc_transport_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply)
367{
368 int32_t ret = -1;
369
370 GF_VALIDATE_OR_GOTO("rpc_transport", this, fail)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc_transport", "rpc-transport.c", __FUNCTION__, 370, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto fail; } } while
(0)
;
371 GF_VALIDATE_OR_GOTO("rpc_transport", this->ops, fail)do { if (!this->ops) { (*__errno_location ()) = 22; do { do
{ if (0) printf ("invalid argument: " "this->ops"); } while
(0); _gf_log_callingfn ("rpc_transport", "rpc-transport.c", __FUNCTION__
, 371, GF_LOG_ERROR, "invalid argument: " "this->ops"); } while
(0); goto fail; } } while (0)
;
372
373 ret = this->ops->submit_reply (this, reply);
374fail:
375 return ret;
376}
377
378
379int32_t
380rpc_transport_connect (rpc_transport_t *this, int port)
381{
382 int ret = -1;
383
384 GF_VALIDATE_OR_GOTO("rpc_transport", this, fail)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc_transport", "rpc-transport.c", __FUNCTION__, 384, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto fail; } } while
(0)
;
385
386 ret = this->ops->connect (this, port);
387fail:
388 return ret;
389}
390
391
392int32_t
393rpc_transport_listen (rpc_transport_t *this)
394{
395 int ret = -1;
396
397 GF_VALIDATE_OR_GOTO("rpc_transport", this, fail)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc_transport", "rpc-transport.c", __FUNCTION__, 397, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto fail; } } while
(0)
;
398
399 ret = this->ops->listen (this);
400fail:
401 return ret;
402}
403
404
405int32_t
406rpc_transport_disconnect (rpc_transport_t *this)
407{
408 int32_t ret = -1;
409
410 GF_VALIDATE_OR_GOTO("rpc_transport", this, fail)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc_transport", "rpc-transport.c", __FUNCTION__, 410, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto fail; } } while
(0)
;
411
412 ret = this->ops->disconnect (this);
413fail:
414 return ret;
415}
416
417
418int32_t
419rpc_transport_destroy (rpc_transport_t *this)
420{
421 int32_t ret = -1;
422
423 GF_VALIDATE_OR_GOTO("rpc_transport", this, fail)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc_transport", "rpc-transport.c", __FUNCTION__, 423, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto fail; } } while
(0)
;
424
425 if (this->options)
426 dict_unref (this->options);
427 if (this->fini)
428 this->fini (this);
429
430 pthread_mutex_destroy (&this->lock);
431
432 GF_FREE (this->name)__gf_free (this->name);
433
434 if (this->dl_handle)
435 dlclose (this->dl_handle);
436
437 GF_FREE (this)__gf_free (this);
438fail:
439 return ret;
440}
441
442
443rpc_transport_t *
444rpc_transport_ref (rpc_transport_t *this)
445{
446 rpc_transport_t *return_this = NULL((void*)0);
447
448 GF_VALIDATE_OR_GOTO("rpc_transport", this, fail)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc_transport", "rpc-transport.c", __FUNCTION__, 448, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto fail; } } while
(0)
;
449
450 pthread_mutex_lock (&this->lock);
451 {
452 this->refcount ++;
453 }
454 pthread_mutex_unlock (&this->lock);
455
456 return_this = this;
457fail:
458 return return_this;
459}
460
461
462int32_t
463rpc_transport_unref (rpc_transport_t *this)
464{
465 int32_t refcount = 0;
466 int32_t ret = -1;
467
468 GF_VALIDATE_OR_GOTO("rpc_transport", this, fail)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc_transport", "rpc-transport.c", __FUNCTION__, 468, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto fail; } } while
(0)
;
469
470 pthread_mutex_lock (&this->lock);
471 {
472 refcount = --this->refcount;
473 }
474 pthread_mutex_unlock (&this->lock);
475
476 if (refcount == 0) {
477 if (this->mydata)
478 this->notify (this, this->mydata, RPC_TRANSPORT_CLEANUP,
479 NULL((void*)0));
480 rpc_transport_destroy (this);
481 }
482
483 ret = 0;
484fail:
485 return ret;
486}
487
488
489int32_t
490rpc_transport_notify (rpc_transport_t *this, rpc_transport_event_t event,
491 void *data, ...)
492{
493 int32_t ret = -1;
494 GF_VALIDATE_OR_GOTO ("rpc", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("rpc", "rpc-transport.c", __FUNCTION__, 494, GF_LOG_ERROR, "invalid argument: "
"this"); } while (0); goto out; } } while (0)
;
495
496 if (this->notify != NULL((void*)0)) {
497 ret = this->notify (this, this->mydata, event, data);
498 } else {
499 ret = 0;
500 }
501out:
502 return ret;
503}
504
505
506
507inline int
508rpc_transport_register_notify (rpc_transport_t *trans,
509 rpc_transport_notify_t notify, void *mydata)
510{
511 int32_t ret = -1;
512 GF_VALIDATE_OR_GOTO ("rpc", trans, out)do { if (!trans) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "trans"); } while (0); _gf_log_callingfn
("rpc", "rpc-transport.c", __FUNCTION__, 512, GF_LOG_ERROR, "invalid argument: "
"trans"); } while (0); goto out; } } while (0)
;
513
514 trans->notify = notify;
515 trans->mydata = mydata;
516
517 ret = 0;
518out:
519 return ret;
520}
521
522
523inline int
524rpc_transport_unregister_notify (rpc_transport_t *trans)
525{
526 GF_VALIDATE_OR_GOTO ("rpc-transport", trans, out)do { if (!trans) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "trans"); } while (0); _gf_log_callingfn
("rpc-transport", "rpc-transport.c", __FUNCTION__, 526, GF_LOG_ERROR
, "invalid argument: " "trans"); } while (0); goto out; } } while
(0)
;
527
528 trans->notify = NULL((void*)0);
529 trans->mydata = NULL((void*)0);
530
531out:
532 return 0;
533}
534
535
536//give negative values to skip setting that value
537//this function asserts if both the values are negative.
538//why call it if you dont set it.
539int
540rpc_transport_keepalive_options_set (dict_t *options, int32_t interval,
541 int32_t time)
542{
543 int ret = -1;
544
545 GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: "
"options"); } while (0); _gf_log_callingfn ("", "rpc-transport.c"
, __FUNCTION__, 545, GF_LOG_ERROR, "Assertion failed: " "options"
); } while (0); } } while (0)
;
546 GF_ASSERT ((interval > 0) || (time > 0))do { if (!((interval > 0) || (time > 0))) { do { do { if
(0) printf ("Assertion failed: " "(interval > 0) || (time > 0)"
); } while (0); _gf_log_callingfn ("", "rpc-transport.c", __FUNCTION__
, 546, GF_LOG_ERROR, "Assertion failed: " "(interval > 0) || (time > 0)"
); } while (0); } } while (0)
;
547
548 ret = dict_set_int32 (options,
549 "transport.socket.keepalive-interval", interval);
550 if (ret)
551 goto out;
552
553 ret = dict_set_int32 (options,
554 "transport.socket.keepalive-time", time);
555 if (ret)
556 goto out;
557out:
558 return ret;
559}
560
561int
562rpc_transport_inet_options_build (dict_t **options, const char *hostname,
563 int port)
564{
565 dict_t *dict = NULL((void*)0);
566 char *host = NULL((void*)0);
567 int ret = -1;
568
569 GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: "
"options"); } while (0); _gf_log_callingfn ("", "rpc-transport.c"
, __FUNCTION__, 569, GF_LOG_ERROR, "Assertion failed: " "options"
); } while (0); } } while (0)
;
1
Within the expansion of the macro 'GF_ASSERT':
a
Assuming 'options' is null
570 GF_ASSERT (hostname)do { if (!(hostname)) { do { do { if (0) printf ("Assertion failed: "
"hostname"); } while (0); _gf_log_callingfn ("", "rpc-transport.c"
, __FUNCTION__, 570, GF_LOG_ERROR, "Assertion failed: " "hostname"
); } while (0); } } while (0)
;
571 GF_ASSERT (port >= 1024)do { if (!(port >= 1024)) { do { do { if (0) printf ("Assertion failed: "
"port >= 1024"); } while (0); _gf_log_callingfn ("", "rpc-transport.c"
, __FUNCTION__, 571, GF_LOG_ERROR, "Assertion failed: " "port >= 1024"
); } while (0); } } while (0)
;
572
573 dict = dict_new ();
574 if (!dict)
2
Assuming 'dict' is non-null
3
Taking false branch
575 goto out;
576
577 host = gf_strdup ((char*)hostname);
578 if (!hostname) {
4
Taking false branch
579 ret = -1;
580 goto out;
581 }
582
583 ret = dict_set_dynstr (dict, "remote-host", host);
584 if (ret) {
5
Assuming 'ret' is 0
6
Taking false branch
585 gf_log (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to set remote-host with %s",
host); } while (0); _gf_log ((*__glusterfs_this_location())->
name, "rpc-transport.c", __FUNCTION__, 586, GF_LOG_WARNING, "failed to set remote-host with %s"
, host); } while (0)
586 "failed to set remote-host with %s", host)do { do { if (0) printf ("failed to set remote-host with %s",
host); } while (0); _gf_log ((*__glusterfs_this_location())->
name, "rpc-transport.c", __FUNCTION__, 586, GF_LOG_WARNING, "failed to set remote-host with %s"
, host); } while (0)
;
587 goto out;
588 }
589
590 ret = dict_set_int32 (dict, "remote-port", port);
591 if (ret) {
7
Assuming 'ret' is 0
8
Taking false branch
592 gf_log (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to set remote-port with %d",
port); } while (0); _gf_log ((*__glusterfs_this_location())->
name, "rpc-transport.c", __FUNCTION__, 593, GF_LOG_WARNING, "failed to set remote-port with %d"
, port); } while (0)
593 "failed to set remote-port with %d", port)do { do { if (0) printf ("failed to set remote-port with %d",
port); } while (0); _gf_log ((*__glusterfs_this_location())->
name, "rpc-transport.c", __FUNCTION__, 593, GF_LOG_WARNING, "failed to set remote-port with %d"
, port); } while (0)
;
594 goto out;
595 }
596 ret = dict_set_str (dict, "transport.address-family", "inet");
597 if (ret) {
9
Assuming 'ret' is 0
10
Taking false branch
598 gf_log (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to set addr-family with inet"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "rpc-transport.c", __FUNCTION__, 599, GF_LOG_WARNING, "failed to set addr-family with inet"
); } while (0)
599 "failed to set addr-family with inet")do { do { if (0) printf ("failed to set addr-family with inet"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "rpc-transport.c", __FUNCTION__, 599, GF_LOG_WARNING, "failed to set addr-family with inet"
); } while (0)
;
600 goto out;
601 }
602
603 ret = dict_set_str (dict, "transport-type", "socket");
604 if (ret) {
11
Assuming 'ret' is 0
12
Taking false branch
605 gf_log (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to set trans-type with socket"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "rpc-transport.c", __FUNCTION__, 606, GF_LOG_WARNING, "failed to set trans-type with socket"
); } while (0)
606 "failed to set trans-type with socket")do { do { if (0) printf ("failed to set trans-type with socket"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "rpc-transport.c", __FUNCTION__, 606, GF_LOG_WARNING, "failed to set trans-type with socket"
); } while (0)
;
607 goto out;
608 }
609
610 *options = dict;
13
Dereference of null pointer (loaded from variable 'options')
611out:
612 if (ret) {
613 GF_FREE (host)__gf_free (host);
614 if (dict)
615 dict_unref (dict);
616 }
617
618 return ret;
619}