File: | libglusterfs/src/stack.c |
Location: | line 304, column 17 |
Description: | Value stored to 'ret' is never read |
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 "statedump.h" |
12 | #include "stack.h" |
13 | |
14 | static inline |
15 | int call_frames_count (call_frame_t *call_frame) |
16 | { |
17 | call_frame_t *pos; |
18 | int32_t count = 0; |
19 | |
20 | if (!call_frame) |
21 | return count; |
22 | |
23 | for (pos = call_frame; pos != NULL((void*)0); pos = pos->next) |
24 | count++; |
25 | |
26 | return count; |
27 | } |
28 | |
29 | call_frame_t * |
30 | create_frame (xlator_t *xl, call_pool_t *pool) |
31 | { |
32 | call_stack_t *stack = NULL((void*)0); |
33 | |
34 | if (!xl || !pool) { |
35 | return NULL((void*)0); |
36 | } |
37 | |
38 | stack = mem_get0 (pool->stack_mem_pool); |
39 | if (!stack) |
40 | return NULL((void*)0); |
41 | |
42 | stack->pool = pool; |
43 | stack->frames.root = stack; |
44 | stack->frames.this = xl; |
45 | stack->ctx = xl->ctx; |
46 | |
47 | if (stack->ctx->measure_latency) { |
48 | if (gettimeofday (&stack->tv, NULL((void*)0)) == -1) |
49 | gf_log ("stack", GF_LOG_ERROR, "gettimeofday () failed."do { do { if (0) printf ("gettimeofday () failed." " (%s)", strerror ((*__errno_location ()))); } while (0); _gf_log ("stack", "stack.c" , __FUNCTION__, 50, GF_LOG_ERROR, "gettimeofday () failed." " (%s)" , strerror ((*__errno_location ()))); } while (0) |
50 | " (%s)", strerror (errno))do { do { if (0) printf ("gettimeofday () failed." " (%s)", strerror ((*__errno_location ()))); } while (0); _gf_log ("stack", "stack.c" , __FUNCTION__, 50, GF_LOG_ERROR, "gettimeofday () failed." " (%s)" , strerror ((*__errno_location ()))); } while (0); |
51 | memcpy (&stack->frames.begin, &stack->tv, sizeof (stack->tv)); |
52 | } |
53 | |
54 | LOCK (&pool->lock)pthread_spin_lock (&pool->lock); |
55 | { |
56 | list_add (&stack->all_frames, &pool->all_frames); |
57 | pool->cnt++; |
58 | } |
59 | UNLOCK (&pool->lock)pthread_spin_unlock (&pool->lock); |
60 | |
61 | LOCK_INIT (&stack->frames.lock)pthread_spin_init (&stack->frames.lock, 0); |
62 | LOCK_INIT (&stack->stack_lock)pthread_spin_init (&stack->stack_lock, 0); |
63 | |
64 | return &stack->frames; |
65 | } |
66 | |
67 | void |
68 | gf_proc_dump_call_frame (call_frame_t *call_frame, const char *key_buf,...) |
69 | { |
70 | |
71 | char prefix[GF_DUMP_MAX_BUF_LEN4096]; |
72 | va_list ap; |
73 | call_frame_t my_frame; |
74 | int ret = -1; |
75 | char timestr[256] = {0,}; |
76 | |
77 | if (!call_frame) |
78 | return; |
79 | |
80 | GF_ASSERT (key_buf)do { if (!(key_buf)) { do { do { if (0) printf ("Assertion failed: " "key_buf"); } while (0); _gf_log_callingfn ("", "stack.c", __FUNCTION__ , 80, GF_LOG_ERROR, "Assertion failed: " "key_buf"); } while ( 0); } } while (0); |
81 | |
82 | memset(prefix, 0, sizeof(prefix)); |
83 | memset(&my_frame, 0, sizeof(my_frame)); |
84 | va_start(ap, key_buf)__builtin_va_start(ap, key_buf); |
85 | vsnprintf(prefix, GF_DUMP_MAX_BUF_LEN4096, key_buf, ap); |
86 | va_end(ap)__builtin_va_end(ap); |
87 | |
88 | ret = TRY_LOCK(&call_frame->lock)pthread_spin_trylock (&call_frame->lock); |
89 | if (ret) |
90 | goto out; |
91 | |
92 | memcpy(&my_frame, call_frame, sizeof(my_frame)); |
93 | UNLOCK(&call_frame->lock)pthread_spin_unlock (&call_frame->lock); |
94 | |
95 | if (my_frame.this->ctx->measure_latency) { |
96 | gf_time_fmt (timestr, sizeof timestr, my_frame.begin.tv_sec, |
97 | gf_timefmt_FT); |
98 | snprintf (timestr + strlen (timestr), |
99 | sizeof timestr - strlen (timestr), |
100 | ".%"GF_PRI_SUSECONDS"06ld", my_frame.begin.tv_usec); |
101 | gf_proc_dump_write("frame-creation-time", "%s", timestr); |
102 | } |
103 | |
104 | gf_proc_dump_write("ref_count", "%d", my_frame.ref_count); |
105 | gf_proc_dump_write("translator", "%s", my_frame.this->name); |
106 | gf_proc_dump_write("complete", "%d", my_frame.complete); |
107 | if (my_frame.parent) |
108 | gf_proc_dump_write("parent", "%s", my_frame.parent->this->name); |
109 | |
110 | if (my_frame.wind_from) |
111 | gf_proc_dump_write("wind_from", "%s", my_frame.wind_from); |
112 | |
113 | if (my_frame.wind_to) |
114 | gf_proc_dump_write("wind_to", "%s", my_frame.wind_to); |
115 | |
116 | if (my_frame.unwind_from) |
117 | gf_proc_dump_write("unwind_from", "%s", my_frame.unwind_from); |
118 | |
119 | if (my_frame.unwind_to) |
120 | gf_proc_dump_write("unwind_to", "%s", my_frame.unwind_to); |
121 | |
122 | ret = 0; |
123 | out: |
124 | if (ret) { |
125 | gf_proc_dump_write("Unable to dump the frame information", |
126 | "(Lock acquisition failed) %p", my_frame); |
127 | return; |
128 | } |
129 | } |
130 | |
131 | |
132 | void |
133 | gf_proc_dump_call_stack (call_stack_t *call_stack, const char *key_buf,...) |
134 | { |
135 | char prefix[GF_DUMP_MAX_BUF_LEN4096]; |
136 | va_list ap; |
137 | call_frame_t *trav; |
138 | int32_t cnt, i; |
139 | char timestr[256] = {0,}; |
140 | |
141 | if (!call_stack) |
142 | return; |
143 | |
144 | GF_ASSERT (key_buf)do { if (!(key_buf)) { do { do { if (0) printf ("Assertion failed: " "key_buf"); } while (0); _gf_log_callingfn ("", "stack.c", __FUNCTION__ , 144, GF_LOG_ERROR, "Assertion failed: " "key_buf"); } while (0); } } while (0); |
145 | |
146 | cnt = call_frames_count(&call_stack->frames); |
147 | |
148 | memset(prefix, 0, sizeof(prefix)); |
149 | va_start(ap, key_buf)__builtin_va_start(ap, key_buf); |
150 | vsnprintf(prefix, GF_DUMP_MAX_BUF_LEN4096, key_buf, ap); |
151 | va_end(ap)__builtin_va_end(ap); |
152 | |
153 | if (call_stack->ctx->measure_latency) { |
154 | gf_time_fmt (timestr, sizeof timestr, call_stack->tv.tv_sec, |
155 | gf_timefmt_FT); |
156 | snprintf (timestr + strlen (timestr), |
157 | sizeof timestr - strlen (timestr), |
158 | ".%"GF_PRI_SUSECONDS"06ld", call_stack->tv.tv_usec); |
159 | gf_proc_dump_write("callstack-creation-time", "%s", timestr); |
160 | } |
161 | |
162 | gf_proc_dump_write("uid", "%d", call_stack->uid); |
163 | gf_proc_dump_write("gid", "%d", call_stack->gid); |
164 | gf_proc_dump_write("pid", "%d", call_stack->pid); |
165 | gf_proc_dump_write("unique", "%Ld", call_stack->unique); |
166 | gf_proc_dump_write("lk-owner", "%s", lkowner_utoa (&call_stack->lk_owner)); |
167 | |
168 | if (call_stack->type == GF_OP_TYPE_FOP) |
169 | gf_proc_dump_write("op", "%s", |
170 | (char *)gf_fop_list[call_stack->op]); |
171 | else |
172 | gf_proc_dump_write("op", "stack"); |
173 | |
174 | gf_proc_dump_write("type", "%d", call_stack->type); |
175 | gf_proc_dump_write("cnt", "%d", cnt); |
176 | |
177 | trav = &call_stack->frames; |
178 | |
179 | for (i = 1; i <= cnt; i++) { |
180 | if (trav) { |
181 | gf_proc_dump_add_section("%s.frame.%d", prefix, i); |
182 | gf_proc_dump_call_frame(trav, "%s.frame.%d", prefix, i); |
183 | trav = trav->next; |
184 | } |
185 | } |
186 | } |
187 | |
188 | void |
189 | gf_proc_dump_pending_frames (call_pool_t *call_pool) |
190 | { |
191 | |
192 | call_stack_t *trav = NULL((void*)0); |
193 | int i = 1; |
194 | int ret = -1; |
195 | gf_boolean_t section_added = _gf_true; |
196 | |
197 | if (!call_pool) |
198 | return; |
199 | |
200 | ret = TRY_LOCK (&(call_pool->lock))pthread_spin_trylock (&(call_pool->lock)); |
201 | if (ret) |
202 | goto out; |
203 | |
204 | |
205 | gf_proc_dump_add_section("global.callpool"); |
206 | section_added = _gf_true; |
207 | gf_proc_dump_write("callpool_address","%p", call_pool); |
208 | gf_proc_dump_write("callpool.cnt","%d", call_pool->cnt); |
209 | |
210 | |
211 | list_for_each_entry (trav, &call_pool->all_frames, all_frames)for (trav = ((typeof(*trav) *)((char *)((&call_pool->all_frames )->next)-(unsigned long)(&((typeof(*trav) *)0)->all_frames ))); &trav->all_frames != (&call_pool->all_frames ); trav = ((typeof(*trav) *)((char *)(trav->all_frames.next )-(unsigned long)(&((typeof(*trav) *)0)->all_frames))) ) { |
212 | gf_proc_dump_add_section("global.callpool.stack.%d",i); |
213 | gf_proc_dump_call_stack(trav, "global.callpool.stack.%d", i); |
214 | i++; |
215 | } |
216 | UNLOCK (&(call_pool->lock))pthread_spin_unlock (&(call_pool->lock)); |
217 | |
218 | ret = 0; |
219 | out: |
220 | if (ret) { |
221 | if (_gf_false == section_added) |
222 | gf_proc_dump_add_section("global.callpool"); |
223 | gf_proc_dump_write("Unable to dump the callpool", |
224 | "(Lock acquisition failed) %p", |
225 | call_pool); |
226 | } |
227 | return; |
228 | } |
229 | |
230 | void |
231 | gf_proc_dump_call_frame_to_dict (call_frame_t *call_frame, |
232 | char *prefix, dict_t *dict) |
233 | { |
234 | int ret = -1; |
235 | char key[GF_DUMP_MAX_BUF_LEN4096] = {0,}; |
236 | call_frame_t tmp_frame = {0,}; |
237 | |
238 | if (!call_frame || !dict) |
239 | return; |
240 | |
241 | ret = TRY_LOCK (&call_frame->lock)pthread_spin_trylock (&call_frame->lock); |
242 | if (ret) |
243 | return; |
244 | memcpy (&tmp_frame, call_frame, sizeof (tmp_frame)); |
245 | UNLOCK (&call_frame->lock)pthread_spin_unlock (&call_frame->lock); |
246 | |
247 | memset (key, 0, sizeof (key)); |
248 | snprintf (key, sizeof (key), "%s.refcount", prefix); |
249 | ret = dict_set_int32 (dict, key, tmp_frame.ref_count); |
250 | if (ret) |
251 | return; |
252 | |
253 | memset (key, 0, sizeof (key)); |
254 | snprintf (key, sizeof (key), "%s.translator", prefix); |
255 | ret = dict_set_dynstr (dict, key, gf_strdup (tmp_frame.this->name)); |
256 | if (ret) |
257 | return; |
258 | |
259 | memset (key, 0, sizeof (key)); |
260 | snprintf (key, sizeof (key), "%s.complete", prefix); |
261 | ret = dict_set_int32 (dict, key, tmp_frame.complete); |
262 | if (ret) |
263 | return; |
264 | |
265 | if (tmp_frame.parent) { |
266 | memset (key, 0, sizeof (key)); |
267 | snprintf (key, sizeof (key), "%s.parent", prefix); |
268 | ret = dict_set_dynstr (dict, key, |
269 | gf_strdup (tmp_frame.parent->this->name)); |
270 | if (ret) |
271 | return; |
272 | } |
273 | |
274 | if (tmp_frame.wind_from) { |
275 | memset (key, 0, sizeof (key)); |
276 | snprintf (key, sizeof (key), "%s.windfrom", prefix); |
277 | ret = dict_set_dynstr (dict, key, |
278 | gf_strdup (tmp_frame.wind_from)); |
279 | if (ret) |
280 | return; |
281 | } |
282 | |
283 | if (tmp_frame.wind_to) { |
284 | memset (key, 0, sizeof (key)); |
285 | snprintf (key, sizeof (key), "%s.windto", prefix); |
286 | ret = dict_set_dynstr (dict, key, |
287 | gf_strdup (tmp_frame.wind_to)); |
288 | if (ret) |
289 | return; |
290 | } |
291 | |
292 | if (tmp_frame.unwind_from) { |
293 | memset (key, 0, sizeof (key)); |
294 | snprintf (key, sizeof (key), "%s.unwindfrom", prefix); |
295 | ret = dict_set_dynstr (dict, key, |
296 | gf_strdup (tmp_frame.unwind_from)); |
297 | if (ret) |
298 | return; |
299 | } |
300 | |
301 | if (tmp_frame.unwind_to) { |
302 | memset (key, 0, sizeof (key)); |
303 | snprintf (key, sizeof (key), "%s.unwind_to", prefix); |
304 | ret = dict_set_dynstr (dict, key, |
Value stored to 'ret' is never read | |
305 | gf_strdup (tmp_frame.unwind_to)); |
306 | } |
307 | |
308 | return; |
309 | } |
310 | |
311 | void |
312 | gf_proc_dump_call_stack_to_dict (call_stack_t *call_stack, |
313 | char *prefix, dict_t *dict) |
314 | { |
315 | int ret = -1; |
316 | char key[GF_DUMP_MAX_BUF_LEN4096] = {0,}; |
317 | call_frame_t *trav = NULL((void*)0); |
318 | int count = 0; |
319 | int i = 0; |
320 | |
321 | if (!call_stack || !dict) |
322 | return; |
323 | |
324 | count = call_frames_count (&call_stack->frames); |
325 | |
326 | memset (key, 0, sizeof (key)); |
327 | snprintf (key, sizeof (key), "%s.uid", prefix); |
328 | ret = dict_set_int32 (dict, key, call_stack->uid); |
329 | if (ret) |
330 | return; |
331 | |
332 | memset (key, 0, sizeof (key)); |
333 | snprintf (key, sizeof (key), "%s.gid", prefix); |
334 | ret = dict_set_int32 (dict, key, call_stack->gid); |
335 | if (ret) |
336 | return; |
337 | |
338 | memset (key, 0, sizeof (key)); |
339 | snprintf (key, sizeof (key), "%s.pid", prefix); |
340 | ret = dict_set_int32 (dict, key, call_stack->pid); |
341 | if (ret) |
342 | return; |
343 | |
344 | memset (key, 0, sizeof (key)); |
345 | snprintf (key, sizeof (key), "%s.unique", prefix); |
346 | ret = dict_set_uint64 (dict, key, call_stack->unique); |
347 | if (ret) |
348 | return; |
349 | |
350 | memset (key, 0, sizeof (key)); |
351 | snprintf (key, sizeof (key), "%s.op", prefix); |
352 | if (call_stack->type == GF_OP_TYPE_FOP) |
353 | ret = dict_set_str (dict, key, |
354 | (char *)gf_fop_list[call_stack->op]); |
355 | else |
356 | ret = dict_set_str (dict, key, "other"); |
357 | |
358 | if (ret) |
359 | return; |
360 | |
361 | memset (key, 0, sizeof (key)); |
362 | snprintf (key, sizeof (key), "%s.type", prefix); |
363 | ret = dict_set_int32 (dict, key, call_stack->type); |
364 | if (ret) |
365 | return; |
366 | |
367 | memset (key, 0, sizeof (key)); |
368 | snprintf (key, sizeof (key), "%s.count", prefix); |
369 | ret = dict_set_int32 (dict, key, count); |
370 | if (ret) |
371 | return; |
372 | |
373 | trav = &call_stack->frames; |
374 | for (i = 0; i < count; i++) { |
375 | if (trav) { |
376 | memset (key, 0, sizeof (key)); |
377 | snprintf (key, sizeof (key), "%s.frame%d", |
378 | prefix, i); |
379 | gf_proc_dump_call_frame_to_dict (trav, key, dict); |
380 | trav = trav->next; |
381 | } |
382 | } |
383 | |
384 | return; |
385 | } |
386 | |
387 | void |
388 | gf_proc_dump_pending_frames_to_dict (call_pool_t *call_pool, dict_t *dict) |
389 | { |
390 | int ret = -1; |
391 | call_stack_t *trav = NULL((void*)0); |
392 | char key[GF_DUMP_MAX_BUF_LEN4096] = {0,}; |
393 | int i = 0; |
394 | |
395 | if (!call_pool || !dict) |
396 | return; |
397 | |
398 | ret = TRY_LOCK (&call_pool->lock)pthread_spin_trylock (&call_pool->lock); |
399 | if (ret) { |
400 | gf_log (THIS->name, GF_LOG_WARNING, "Unable to dump call pool"do { do { if (0) printf ("Unable to dump call pool" " to dict. errno: %d" , (*__errno_location ())); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "stack.c", __FUNCTION__, 401, GF_LOG_WARNING, "Unable to dump call pool" " to dict. errno: %d", (*__errno_location ())); } while (0) |
401 | " to dict. errno: %d", errno)do { do { if (0) printf ("Unable to dump call pool" " to dict. errno: %d" , (*__errno_location ())); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "stack.c", __FUNCTION__, 401, GF_LOG_WARNING, "Unable to dump call pool" " to dict. errno: %d", (*__errno_location ())); } while (0); |
402 | return; |
403 | } |
404 | |
405 | ret = dict_set_int32 (dict, "callpool.count", call_pool->cnt); |
406 | if (ret) |
407 | goto out; |
408 | |
409 | list_for_each_entry (trav, &call_pool->all_frames, all_frames)for (trav = ((typeof(*trav) *)((char *)((&call_pool->all_frames )->next)-(unsigned long)(&((typeof(*trav) *)0)->all_frames ))); &trav->all_frames != (&call_pool->all_frames ); trav = ((typeof(*trav) *)((char *)(trav->all_frames.next )-(unsigned long)(&((typeof(*trav) *)0)->all_frames))) ) { |
410 | memset (key, 0, sizeof (key)); |
411 | snprintf (key, sizeof (key), "callpool.stack%d", i); |
412 | gf_proc_dump_call_stack_to_dict (trav, key, dict); |
413 | i++; |
414 | } |
415 | |
416 | out: |
417 | UNLOCK (&call_pool->lock)pthread_spin_unlock (&call_pool->lock); |
418 | |
419 | return; |
420 | } |
421 | |
422 | gf_boolean_t |
423 | __is_fuse_call (call_frame_t *frame) |
424 | { |
425 | gf_boolean_t is_fuse_call = _gf_false; |
426 | GF_ASSERT (frame)do { if (!(frame)) { do { do { if (0) printf ("Assertion failed: " "frame"); } while (0); _gf_log_callingfn ("", "stack.c", __FUNCTION__ , 426, GF_LOG_ERROR, "Assertion failed: " "frame"); } while ( 0); } } while (0); |
427 | GF_ASSERT (frame->root)do { if (!(frame->root)) { do { do { if (0) printf ("Assertion failed: " "frame->root"); } while (0); _gf_log_callingfn ("", "stack.c" , __FUNCTION__, 427, GF_LOG_ERROR, "Assertion failed: " "frame->root" ); } while (0); } } while (0); |
428 | |
429 | if (NFS_PID1 != frame->root->pid) |
430 | is_fuse_call = _gf_true; |
431 | return is_fuse_call; |
432 | } |