Bug Summary

File:xlators/features/marker/src/marker-quota-helper.c
Location:line 304, column 33
Description:Value stored to 'ret' is never read

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#ifndef _CONFIG_H
11#define _CONFIG_H
12#include "config.h"
13#endif
14
15#include "locking.h"
16#include "marker-quota.h"
17#include "marker-common.h"
18#include "marker-quota-helper.h"
19#include "marker-mem-types.h"
20
21int
22mq_loc_fill (loc_t *loc, inode_t *inode, inode_t *parent, char *path)
23{
24 int ret = -1;
25
26 GF_VALIDATE_OR_GOTO ("marker", loc, out)do { if (!loc) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "loc"); } while (0); _gf_log_callingfn
("marker", "marker-quota-helper.c", __FUNCTION__, 26, GF_LOG_ERROR
, "invalid argument: " "loc"); } while (0); goto out; } } while
(0)
;
27 GF_VALIDATE_OR_GOTO ("marker", inode, out)do { if (!inode) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "inode"); } while (0); _gf_log_callingfn
("marker", "marker-quota-helper.c", __FUNCTION__, 27, GF_LOG_ERROR
, "invalid argument: " "inode"); } while (0); goto out; } } while
(0)
;
28 GF_VALIDATE_OR_GOTO ("marker", path, out)do { if (!path) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "path"); } while (0); _gf_log_callingfn
("marker", "marker-quota-helper.c", __FUNCTION__, 28, GF_LOG_ERROR
, "invalid argument: " "path"); } while (0); goto out; } } while
(0)
;
29 /* Not checking for parent because while filling
30 * loc of root, parent will be NULL
31 */
32
33 if (inode) {
34 loc->inode = inode_ref (inode);
35 }
36
37 if (parent)
38 loc->parent = inode_ref (parent);
39
40 loc->path = gf_strdup (path);
41 if (!loc->path) {
42 gf_log ("loc fill", GF_LOG_ERROR, "strdup failed")do { do { if (0) printf ("strdup failed"); } while (0); _gf_log
("loc fill", "marker-quota-helper.c", __FUNCTION__, 42, GF_LOG_ERROR
, "strdup failed"); } while (0)
;
43 goto loc_wipe;
44 }
45
46 loc->name = strrchr (loc->path, '/');
47 if (loc->name)
48 loc->name++;
49 else
50 goto loc_wipe;
51
52 ret = 0;
53loc_wipe:
54 if (ret < 0)
55 loc_wipe (loc);
56out:
57 return ret;
58}
59
60
61int32_t
62mq_inode_loc_fill (const char *parent_gfid, inode_t *inode, loc_t *loc)
63{
64 char *resolvedpath = NULL((void*)0);
65 inode_t *parent = NULL((void*)0);
66 int ret = -1;
67
68 if ((!inode) || (!loc))
69 return ret;
70
71 if ((inode) && __is_root_gfid (inode->gfid)) {
72 loc->parent = NULL((void*)0);
73 goto ignore_parent;
74 }
75
76 if (parent_gfid == NULL((void*)0))
77 parent = inode_parent (inode, 0, NULL((void*)0));
78 else
79 parent = inode_find (inode->table,
80 (unsigned char *) parent_gfid);
81
82 if (parent == NULL((void*)0))
83 goto err;
84
85ignore_parent:
86 ret = inode_path (inode, NULL((void*)0), &resolvedpath);
87 if (ret < 0)
88 goto err;
89
90 ret = mq_loc_fill (loc, inode, parent, resolvedpath);
91 if (ret < 0)
92 goto err;
93
94err:
95 if (parent)
96 inode_unref (parent);
97
98 GF_FREE (resolvedpath)__gf_free (resolvedpath);
99
100 return ret;
101}
102
103
104quota_inode_ctx_t *
105mq_alloc_inode_ctx ()
106{
107 int32_t ret = -1;
108 quota_inode_ctx_t *ctx = NULL((void*)0);
109
110 QUOTA_ALLOC (ctx, quota_inode_ctx_t, ret)do { ret = 0; ctx = __gf_calloc (sizeof (quota_inode_ctx_t), 1
, gf_marker_mt_quota_inode_ctx_t); if (!ctx) { do { do { if (
0) printf ("out of memory"); } while (0); _gf_log ("", "marker-quota-helper.c"
, __FUNCTION__, 110, GF_LOG_ERROR, "out of memory"); } while (
0); ret = -1; } } while (0);
;
111 if (ret == -1)
112 goto out;
113
114 ctx->size = 0;
115 ctx->dirty = 0;
116 ctx->updation_status = _gf_false;
117 LOCK_INIT (&ctx->lock)pthread_spin_init (&ctx->lock, 0);
118 INIT_LIST_HEAD (&ctx->contribution_head)do { (&ctx->contribution_head)->next = (&ctx->
contribution_head)->prev = &ctx->contribution_head;
} while (0)
;
119out:
120 return ctx;
121}
122
123inode_contribution_t *
124mq_get_contribution_node (inode_t *inode, quota_inode_ctx_t *ctx)
125{
126 inode_contribution_t *contri = NULL((void*)0);
127 inode_contribution_t *temp = NULL((void*)0);
128
129 if (!inode || !ctx)
130 goto out;
131
132 list_for_each_entry (temp, &ctx->contribution_head, contri_list)for (temp = ((typeof(*temp) *)((char *)((&ctx->contribution_head
)->next)-(unsigned long)(&((typeof(*temp) *)0)->contri_list
))); &temp->contri_list != (&ctx->contribution_head
); temp = ((typeof(*temp) *)((char *)(temp->contri_list.next
)-(unsigned long)(&((typeof(*temp) *)0)->contri_list))
))
{
133 if (uuid_compare (temp->gfid, inode->gfid) == 0) {
134 contri = temp;
135 goto out;
136 }
137 }
138out:
139 return contri;
140}
141
142
143int32_t
144mq_delete_contribution_node (dict_t *dict, char *key,
145 inode_contribution_t *contribution)
146{
147 if (dict_get (dict, key) != NULL((void*)0))
148 goto out;
149
150 QUOTA_FREE_CONTRIBUTION_NODE (contribution)do { list_del (&contribution->contri_list); __gf_free (
contribution); } while (0)
;
151out:
152 return 0;
153}
154
155
156inode_contribution_t *
157__mq_add_new_contribution_node (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc)
158{
159 int32_t ret = 0;
160 inode_contribution_t *contribution = NULL((void*)0);
161
162 if (!loc->parent) {
163 if (!uuid_is_null (loc->pargfid))
164 loc->parent = inode_find (loc->inode->table,
165 loc->pargfid);
166 if (!loc->parent)
167 loc->parent = inode_parent (loc->inode, loc->pargfid,
168 loc->name);
169 if (!loc->parent)
170 goto out;
171 }
172
173 list_for_each_entry (contribution, &ctx->contribution_head, contri_list)for (contribution = ((typeof(*contribution) *)((char *)((&
ctx->contribution_head)->next)-(unsigned long)(&((typeof
(*contribution) *)0)->contri_list))); &contribution->
contri_list != (&ctx->contribution_head); contribution
= ((typeof(*contribution) *)((char *)(contribution->contri_list
.next)-(unsigned long)(&((typeof(*contribution) *)0)->
contri_list))))
{
174 if (loc->parent &&
175 uuid_compare (contribution->gfid, loc->parent->gfid) == 0) {
176 goto out;
177 }
178 }
179
180 QUOTA_ALLOC (contribution, inode_contribution_t, ret)do { ret = 0; contribution = __gf_calloc (sizeof (inode_contribution_t
), 1, gf_marker_mt_inode_contribution_t); if (!contribution) {
do { do { if (0) printf ("out of memory"); } while (0); _gf_log
("", "marker-quota-helper.c", __FUNCTION__, 180, GF_LOG_ERROR
, "out of memory"); } while (0); ret = -1; } } while (0);
;
181 if (ret == -1)
182 goto out;
183
184 contribution->contribution = 0;
185
186 uuid_copy (contribution->gfid, loc->parent->gfid);
187
188 LOCK_INIT (&contribution->lock)pthread_spin_init (&contribution->lock, 0);
189 INIT_LIST_HEAD (&contribution->contri_list)do { (&contribution->contri_list)->next = (&contribution
->contri_list)->prev = &contribution->contri_list
; } while (0)
;
190
191 list_add_tail (&contribution->contri_list, &ctx->contribution_head);
192
193out:
194 return contribution;
195}
196
197
198inode_contribution_t *
199mq_add_new_contribution_node (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc)
200{
201 inode_contribution_t *contribution = NULL((void*)0);
202
203 if ((ctx == NULL((void*)0)) || (loc == NULL((void*)0)))
204 return NULL((void*)0);
205
206 if (strcmp (loc->path, "/") == 0)
207 return NULL((void*)0);
208
209 LOCK (&ctx->lock)pthread_spin_lock (&ctx->lock);
210 {
211 contribution = __mq_add_new_contribution_node (this, ctx, loc);
212 }
213 UNLOCK (&ctx->lock)pthread_spin_unlock (&ctx->lock);
214
215 return contribution;
216}
217
218
219int32_t
220mq_dict_set_contribution (xlator_t *this, dict_t *dict,
221 loc_t *loc)
222{
223 int32_t ret = -1;
224 char contri_key [512] = {0, };
225
226 GF_VALIDATE_OR_GOTO ("marker", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("marker", "marker-quota-helper.c", __FUNCTION__, 226, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto out; } } while
(0)
;
227 GF_VALIDATE_OR_GOTO ("marker", dict, out)do { if (!dict) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "dict"); } while (0); _gf_log_callingfn
("marker", "marker-quota-helper.c", __FUNCTION__, 227, GF_LOG_ERROR
, "invalid argument: " "dict"); } while (0); goto out; } } while
(0)
;
228 GF_VALIDATE_OR_GOTO ("marker", loc, out)do { if (!loc) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "loc"); } while (0); _gf_log_callingfn
("marker", "marker-quota-helper.c", __FUNCTION__, 228, GF_LOG_ERROR
, "invalid argument: " "loc"); } while (0); goto out; } } while
(0)
;
229 GF_VALIDATE_OR_GOTO ("marker", loc->parent, out)do { if (!loc->parent) { (*__errno_location ()) = 22; do {
do { if (0) printf ("invalid argument: " "loc->parent"); }
while (0); _gf_log_callingfn ("marker", "marker-quota-helper.c"
, __FUNCTION__, 229, GF_LOG_ERROR, "invalid argument: " "loc->parent"
); } while (0); goto out; } } while (0)
;
230
231 GET_CONTRI_KEY (contri_key, loc->parent->gfid, ret)do { char _gfid_unparsed[40]; uuid_unparse (loc->parent->
gfid, _gfid_unparsed); ret = snprintf (contri_key, 512, "trusted.glusterfs"
".%s.%s." "contri", "quota", _gfid_unparsed); } while (0);
;
232 if (ret < 0) {
233 ret = -1;
234 goto out;
235 }
236
237 ret = dict_set_int64 (dict, contri_key, 0);
238 if (ret < 0) {
239 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("unable to set dict value on %s.", loc
->path); } while (0); _gf_log (this->name, "marker-quota-helper.c"
, __FUNCTION__, 241, GF_LOG_WARNING, "unable to set dict value on %s."
, loc->path); } while (0)
240 "unable to set dict value on %s.",do { do { if (0) printf ("unable to set dict value on %s.", loc
->path); } while (0); _gf_log (this->name, "marker-quota-helper.c"
, __FUNCTION__, 241, GF_LOG_WARNING, "unable to set dict value on %s."
, loc->path); } while (0)
241 loc->path)do { do { if (0) printf ("unable to set dict value on %s.", loc
->path); } while (0); _gf_log (this->name, "marker-quota-helper.c"
, __FUNCTION__, 241, GF_LOG_WARNING, "unable to set dict value on %s."
, loc->path); } while (0)
;
242 goto out;
243 }
244
245 ret = 0;
246out:
247 return ret;
248}
249
250
251int32_t
252mq_inode_ctx_get (inode_t *inode, xlator_t *this,
253 quota_inode_ctx_t **ctx)
254{
255 int32_t ret = -1;
256 uint64_t ctx_int = 0;
257 marker_inode_ctx_t *mark_ctx = NULL((void*)0);
258
259 GF_VALIDATE_OR_GOTO ("marker", inode, out)do { if (!inode) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "inode"); } while (0); _gf_log_callingfn
("marker", "marker-quota-helper.c", __FUNCTION__, 259, GF_LOG_ERROR
, "invalid argument: " "inode"); } while (0); goto out; } } while
(0)
;
260 GF_VALIDATE_OR_GOTO ("marker", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn
("marker", "marker-quota-helper.c", __FUNCTION__, 260, GF_LOG_ERROR
, "invalid argument: " "this"); } while (0); goto out; } } while
(0)
;
261 GF_VALIDATE_OR_GOTO ("marker", ctx, out)do { if (!ctx) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "ctx"); } while (0); _gf_log_callingfn
("marker", "marker-quota-helper.c", __FUNCTION__, 261, GF_LOG_ERROR
, "invalid argument: " "ctx"); } while (0); goto out; } } while
(0)
;
262
263 ret = inode_ctx_get (inode, this, &ctx_int)inode_ctx_get2(inode,this,&ctx_int,0);
264 if (ret < 0) {
265 ret = -1;
266 *ctx = NULL((void*)0);
267 goto out;
268 }
269
270 mark_ctx = (marker_inode_ctx_t *) (unsigned long)ctx_int;
271 if (mark_ctx->quota_ctx == NULL((void*)0)) {
272 ret = -1;
273 goto out;
274 }
275
276 *ctx = mark_ctx->quota_ctx;
277
278 ret = 0;
279
280out:
281 return ret;
282}
283
284
285quota_inode_ctx_t *
286__mq_inode_ctx_new (inode_t *inode, xlator_t *this)
287{
288 int32_t ret = -1;
289 quota_inode_ctx_t *quota_ctx = NULL((void*)0);
290 marker_inode_ctx_t *mark_ctx = NULL((void*)0);
291
292 ret = marker_force_inode_ctx_get (inode, this, &mark_ctx);
293 if (ret < 0) {
294 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("marker_force_inode_ctx_get() failed"
); } while (0); _gf_log (this->name, "marker-quota-helper.c"
, __FUNCTION__, 295, GF_LOG_ERROR, "marker_force_inode_ctx_get() failed"
); } while (0)
295 "marker_force_inode_ctx_get() failed")do { do { if (0) printf ("marker_force_inode_ctx_get() failed"
); } while (0); _gf_log (this->name, "marker-quota-helper.c"
, __FUNCTION__, 295, GF_LOG_ERROR, "marker_force_inode_ctx_get() failed"
); } while (0)
;
296 goto out;
297 }
298
299 LOCK (&inode->lock)pthread_spin_lock (&inode->lock);
300 {
301 if (mark_ctx->quota_ctx == NULL((void*)0)) {
302 quota_ctx = mq_alloc_inode_ctx ();
303 if (quota_ctx == NULL((void*)0)) {
304 ret = -1;
Value stored to 'ret' is never read
305 goto unlock;
306 }
307 mark_ctx->quota_ctx = quota_ctx;
308 } else {
309 quota_ctx = mark_ctx->quota_ctx;
310 }
311
312 ret = 0;
313 }
314unlock:
315 UNLOCK (&inode->lock)pthread_spin_unlock (&inode->lock);
316out:
317 return quota_ctx;
318}
319
320
321quota_inode_ctx_t *
322mq_inode_ctx_new (inode_t * inode, xlator_t *this)
323{
324 return __mq_inode_ctx_new (inode, this);
325}
326
327quota_local_tmarker_local_t *
328mq_local_new ()
329{
330 quota_local_tmarker_local_t *local = NULL((void*)0);
331
332 local = mem_get0 (THIS(*__glusterfs_this_location())->local_pool);
333 if (!local)
334 goto out;
335
336 local->ref = 1;
337 LOCK_INIT (&local->lock)pthread_spin_init (&local->lock, 0);
338
339 local->ctx = NULL((void*)0);
340 local->contri = NULL((void*)0);
341
342out:
343 return local;
344}
345
346quota_local_tmarker_local_t *
347mq_local_ref (quota_local_tmarker_local_t *local)
348{
349 LOCK (&local->lock)pthread_spin_lock (&local->lock);
350 {
351 local->ref ++;
352 }
353 UNLOCK (&local->lock)pthread_spin_unlock (&local->lock);
354
355 return local;
356}
357
358
359int32_t
360mq_local_unref (xlator_t *this, quota_local_tmarker_local_t *local)
361{
362 int32_t ref = 0;
363 if (local == NULL((void*)0))
364 goto out;
365
366 QUOTA_SAFE_DECREMENT (&local->lock, local->ref, ref)do { pthread_spin_lock (&local->lock); { ref = --local
->ref; } pthread_spin_unlock (&local->lock); } while
(0)
;
367
368 if (ref != 0)
369 goto out;
370
371 if (local->fd != NULL((void*)0))
372 fd_unref (local->fd);
373
374 loc_wipe (&local->loc);
375
376 loc_wipe (&local->parent_loc);
377
378 LOCK_DESTROY (&local->lock)pthread_spin_destroy (&local->lock);
379
380 mem_put (local);
381out:
382 return 0;
383}
384
385
386inode_contribution_t *
387mq_get_contribution_from_loc (xlator_t *this, loc_t *loc)
388{
389 int32_t ret = 0;
390 quota_inode_ctx_t *ctx = NULL((void*)0);
391 inode_contribution_t *contribution = NULL((void*)0);
392
393 ret = mq_inode_ctx_get (loc->inode, this, &ctx);
394 if (ret < 0) {
395 gf_log_callingfn (this->name, GF_LOG_WARNING,do { do { if (0) printf ("cannot get marker-quota context from inode "
"(gfid:%s, path:%s)", uuid_utoa (loc->inode->gfid), loc
->path); } while (0); _gf_log_callingfn (this->name, "marker-quota-helper.c"
, __FUNCTION__, 398, GF_LOG_WARNING, "cannot get marker-quota context from inode "
"(gfid:%s, path:%s)", uuid_utoa (loc->inode->gfid), loc
->path); } while (0)
396 "cannot get marker-quota context from inode "do { do { if (0) printf ("cannot get marker-quota context from inode "
"(gfid:%s, path:%s)", uuid_utoa (loc->inode->gfid), loc
->path); } while (0); _gf_log_callingfn (this->name, "marker-quota-helper.c"
, __FUNCTION__, 398, GF_LOG_WARNING, "cannot get marker-quota context from inode "
"(gfid:%s, path:%s)", uuid_utoa (loc->inode->gfid), loc
->path); } while (0)
397 "(gfid:%s, path:%s)",do { do { if (0) printf ("cannot get marker-quota context from inode "
"(gfid:%s, path:%s)", uuid_utoa (loc->inode->gfid), loc
->path); } while (0); _gf_log_callingfn (this->name, "marker-quota-helper.c"
, __FUNCTION__, 398, GF_LOG_WARNING, "cannot get marker-quota context from inode "
"(gfid:%s, path:%s)", uuid_utoa (loc->inode->gfid), loc
->path); } while (0)
398 uuid_utoa (loc->inode->gfid), loc->path)do { do { if (0) printf ("cannot get marker-quota context from inode "
"(gfid:%s, path:%s)", uuid_utoa (loc->inode->gfid), loc
->path); } while (0); _gf_log_callingfn (this->name, "marker-quota-helper.c"
, __FUNCTION__, 398, GF_LOG_WARNING, "cannot get marker-quota context from inode "
"(gfid:%s, path:%s)", uuid_utoa (loc->inode->gfid), loc
->path); } while (0)
;
399 goto err;
400 }
401
402 contribution = mq_get_contribution_node (loc->parent, ctx);
403 if (contribution == NULL((void*)0)) {
404 gf_log_callingfn (this->name, GF_LOG_WARNING,do { do { if (0) printf ("inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0); _gf_log_callingfn (
this->name, "marker-quota-helper.c", __FUNCTION__, 408, GF_LOG_WARNING
, "inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0)
405 "inode (gfid:%s, path:%s) has "do { do { if (0) printf ("inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0); _gf_log_callingfn (
this->name, "marker-quota-helper.c", __FUNCTION__, 408, GF_LOG_WARNING
, "inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0)
406 "no contribution towards parent (gfid:%s)",do { do { if (0) printf ("inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0); _gf_log_callingfn (
this->name, "marker-quota-helper.c", __FUNCTION__, 408, GF_LOG_WARNING
, "inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0)
407 uuid_utoa (loc->inode->gfid),do { do { if (0) printf ("inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0); _gf_log_callingfn (
this->name, "marker-quota-helper.c", __FUNCTION__, 408, GF_LOG_WARNING
, "inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0)
408 loc->path, uuid_utoa (loc->parent->gfid))do { do { if (0) printf ("inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0); _gf_log_callingfn (
this->name, "marker-quota-helper.c", __FUNCTION__, 408, GF_LOG_WARNING
, "inode (gfid:%s, path:%s) has " "no contribution towards parent (gfid:%s)"
, uuid_utoa (loc->inode->gfid), loc->path, uuid_utoa
(loc->parent->gfid)); } while (0)
;
409 goto err;
410 }
411
412err:
413 return contribution;
414}