File: | xlators/protocol/client/src/client-helpers.c |
Location: | line 330, column 9 |
Description: | Value stored to 'conf' 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 | #ifndef _CONFIG_H |
12 | #define _CONFIG_H |
13 | #include "config.h" |
14 | #endif |
15 | |
16 | #include "client.h" |
17 | #include "fd.h" |
18 | |
19 | int |
20 | client_fd_lk_list_empty (fd_lk_ctx_t *lk_ctx, gf_boolean_t try_lock) |
21 | { |
22 | int ret = 1; |
23 | |
24 | if (!lk_ctx) { |
25 | ret = -1; |
26 | goto out; |
27 | } |
28 | |
29 | if (try_lock) { |
30 | ret = TRY_LOCK (&lk_ctx->lock)pthread_spin_trylock (&lk_ctx->lock); |
31 | if (ret != 0) { |
32 | ret = -1; |
33 | goto out; |
34 | } |
35 | } else { |
36 | LOCK (&lk_ctx->lock)pthread_spin_lock (&lk_ctx->lock); |
37 | } |
38 | |
39 | ret = list_empty (&lk_ctx->lk_list); |
40 | UNLOCK (&lk_ctx->lock)pthread_spin_unlock (&lk_ctx->lock); |
41 | out: |
42 | return ret; |
43 | } |
44 | |
45 | clnt_fd_ctx_t * |
46 | this_fd_del_ctx (fd_t *file, xlator_t *this) |
47 | { |
48 | int dict_ret = -1; |
49 | uint64_t ctxaddr = 0; |
50 | |
51 | GF_VALIDATE_OR_GOTO ("client", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("client", "client-helpers.c", __FUNCTION__, 51, GF_LOG_ERROR , "invalid argument: " "this"); } while (0); goto out; } } while (0); |
52 | GF_VALIDATE_OR_GOTO (this->name, file, out)do { if (!file) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "file"); } while (0); _gf_log_callingfn (this->name, "client-helpers.c", __FUNCTION__, 52, GF_LOG_ERROR , "invalid argument: " "file"); } while (0); goto out; } } while (0); |
53 | |
54 | dict_ret = fd_ctx_del (file, this, &ctxaddr); |
55 | |
56 | if (dict_ret < 0) { |
57 | ctxaddr = 0; |
58 | } |
59 | |
60 | out: |
61 | return (clnt_fd_ctx_t *)(unsigned long)ctxaddr; |
62 | } |
63 | |
64 | |
65 | clnt_fd_ctx_t * |
66 | this_fd_get_ctx (fd_t *file, xlator_t *this) |
67 | { |
68 | int dict_ret = -1; |
69 | uint64_t ctxaddr = 0; |
70 | |
71 | GF_VALIDATE_OR_GOTO ("client", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("client", "client-helpers.c", __FUNCTION__, 71, GF_LOG_ERROR , "invalid argument: " "this"); } while (0); goto out; } } while (0); |
72 | GF_VALIDATE_OR_GOTO (this->name, file, out)do { if (!file) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "file"); } while (0); _gf_log_callingfn (this->name, "client-helpers.c", __FUNCTION__, 72, GF_LOG_ERROR , "invalid argument: " "file"); } while (0); goto out; } } while (0); |
73 | |
74 | dict_ret = fd_ctx_get (file, this, &ctxaddr); |
75 | |
76 | if (dict_ret < 0) { |
77 | ctxaddr = 0; |
78 | } |
79 | |
80 | out: |
81 | return (clnt_fd_ctx_t *)(unsigned long)ctxaddr; |
82 | } |
83 | |
84 | |
85 | void |
86 | this_fd_set_ctx (fd_t *file, xlator_t *this, loc_t *loc, clnt_fd_ctx_t *ctx) |
87 | { |
88 | uint64_t oldaddr = 0; |
89 | int32_t ret = -1; |
90 | |
91 | GF_VALIDATE_OR_GOTO ("client", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("client", "client-helpers.c", __FUNCTION__, 91, GF_LOG_ERROR , "invalid argument: " "this"); } while (0); goto out; } } while (0); |
92 | GF_VALIDATE_OR_GOTO (this->name, file, out)do { if (!file) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "file"); } while (0); _gf_log_callingfn (this->name, "client-helpers.c", __FUNCTION__, 92, GF_LOG_ERROR , "invalid argument: " "file"); } while (0); goto out; } } while (0); |
93 | |
94 | ret = fd_ctx_get (file, this, &oldaddr); |
95 | if (ret >= 0) { |
96 | if (loc) |
97 | gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("%s (%s): trying duplicate remote fd set. " , loc->path, uuid_utoa (loc->inode->gfid)); } while ( 0); _gf_log (this->name, "client-helpers.c", __FUNCTION__, 99, GF_LOG_INFO, "%s (%s): trying duplicate remote fd set. " , loc->path, uuid_utoa (loc->inode->gfid)); } while ( 0) |
98 | "%s (%s): trying duplicate remote fd set. ",do { do { if (0) printf ("%s (%s): trying duplicate remote fd set. " , loc->path, uuid_utoa (loc->inode->gfid)); } while ( 0); _gf_log (this->name, "client-helpers.c", __FUNCTION__, 99, GF_LOG_INFO, "%s (%s): trying duplicate remote fd set. " , loc->path, uuid_utoa (loc->inode->gfid)); } while ( 0) |
99 | loc->path, uuid_utoa (loc->inode->gfid))do { do { if (0) printf ("%s (%s): trying duplicate remote fd set. " , loc->path, uuid_utoa (loc->inode->gfid)); } while ( 0); _gf_log (this->name, "client-helpers.c", __FUNCTION__, 99, GF_LOG_INFO, "%s (%s): trying duplicate remote fd set. " , loc->path, uuid_utoa (loc->inode->gfid)); } while ( 0); |
100 | else |
101 | gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("%p: trying duplicate remote fd set. " , file); } while (0); _gf_log (this->name, "client-helpers.c" , __FUNCTION__, 102, GF_LOG_INFO, "%p: trying duplicate remote fd set. " , file); } while (0) |
102 | "%p: trying duplicate remote fd set. ", file)do { do { if (0) printf ("%p: trying duplicate remote fd set. " , file); } while (0); _gf_log (this->name, "client-helpers.c" , __FUNCTION__, 102, GF_LOG_INFO, "%p: trying duplicate remote fd set. " , file); } while (0); |
103 | } |
104 | |
105 | ret = fd_ctx_set (file, this, (uint64_t)(unsigned long)ctx); |
106 | if (ret < 0) { |
107 | if (loc) |
108 | gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("%s (%s): failed to set remote fd", loc ->path, uuid_utoa (loc->inode->gfid)); } while (0); _gf_log (this->name, "client-helpers.c", __FUNCTION__, 110, GF_LOG_WARNING , "%s (%s): failed to set remote fd", loc->path, uuid_utoa (loc->inode->gfid)); } while (0) |
109 | "%s (%s): failed to set remote fd",do { do { if (0) printf ("%s (%s): failed to set remote fd", loc ->path, uuid_utoa (loc->inode->gfid)); } while (0); _gf_log (this->name, "client-helpers.c", __FUNCTION__, 110, GF_LOG_WARNING , "%s (%s): failed to set remote fd", loc->path, uuid_utoa (loc->inode->gfid)); } while (0) |
110 | loc->path, uuid_utoa (loc->inode->gfid))do { do { if (0) printf ("%s (%s): failed to set remote fd", loc ->path, uuid_utoa (loc->inode->gfid)); } while (0); _gf_log (this->name, "client-helpers.c", __FUNCTION__, 110, GF_LOG_WARNING , "%s (%s): failed to set remote fd", loc->path, uuid_utoa (loc->inode->gfid)); } while (0); |
111 | else |
112 | gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("%p: failed to set remote fd", file) ; } while (0); _gf_log (this->name, "client-helpers.c", __FUNCTION__ , 113, GF_LOG_WARNING, "%p: failed to set remote fd", file); } while (0) |
113 | "%p: failed to set remote fd", file)do { do { if (0) printf ("%p: failed to set remote fd", file) ; } while (0); _gf_log (this->name, "client-helpers.c", __FUNCTION__ , 113, GF_LOG_WARNING, "%p: failed to set remote fd", file); } while (0); |
114 | } |
115 | out: |
116 | return; |
117 | } |
118 | |
119 | |
120 | int |
121 | client_local_wipe (clnt_local_t *local) |
122 | { |
123 | if (local) { |
124 | loc_wipe (&local->loc); |
125 | loc_wipe (&local->loc2); |
126 | |
127 | if (local->fd) { |
128 | fd_unref (local->fd); |
129 | } |
130 | |
131 | if (local->iobref) { |
132 | iobref_unref (local->iobref); |
133 | } |
134 | |
135 | GF_FREE (local->name)__gf_free (local->name); |
136 | |
137 | mem_put (local); |
138 | } |
139 | |
140 | return 0; |
141 | } |
142 | |
143 | int |
144 | unserialize_rsp_dirent (struct gfs3_readdir_rsp *rsp, gf_dirent_t *entries) |
145 | { |
146 | struct gfs3_dirlist *trav = NULL((void*)0); |
147 | gf_dirent_t *entry = NULL((void*)0); |
148 | int entry_len = 0; |
149 | int ret = -1; |
150 | |
151 | trav = rsp->reply; |
152 | while (trav) { |
153 | entry_len = gf_dirent_size (trav->name)(sizeof (gf_dirent_t) + strlen (trav->name) + 1); |
154 | entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t)__gf_calloc (1, entry_len, gf_common_mt_gf_dirent_t); |
155 | if (!entry) |
156 | goto out; |
157 | |
158 | entry->d_ino = trav->d_ino; |
159 | entry->d_off = trav->d_off; |
160 | entry->d_len = trav->d_len; |
161 | entry->d_type = trav->d_type; |
162 | |
163 | strcpy (entry->d_name, trav->name); |
164 | |
165 | list_add_tail (&entry->list, &entries->list); |
166 | |
167 | trav = trav->nextentry; |
168 | } |
169 | |
170 | ret = 0; |
171 | out: |
172 | return ret; |
173 | } |
174 | |
175 | int |
176 | unserialize_rsp_direntp (xlator_t *this, fd_t *fd, |
177 | struct gfs3_readdirp_rsp *rsp, gf_dirent_t *entries) |
178 | { |
179 | struct gfs3_dirplist *trav = NULL((void*)0); |
180 | char *buf = NULL((void*)0); |
181 | gf_dirent_t *entry = NULL((void*)0); |
182 | inode_table_t *itable = NULL((void*)0); |
183 | int entry_len = 0; |
184 | int ret = -1; |
185 | |
186 | trav = rsp->reply; |
187 | |
188 | if (fd) |
189 | itable = fd->inode->table; |
190 | |
191 | while (trav) { |
192 | entry_len = gf_dirent_size (trav->name)(sizeof (gf_dirent_t) + strlen (trav->name) + 1); |
193 | entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t)__gf_calloc (1, entry_len, gf_common_mt_gf_dirent_t); |
194 | if (!entry) |
195 | goto out; |
196 | |
197 | entry->d_ino = trav->d_ino; |
198 | entry->d_off = trav->d_off; |
199 | entry->d_len = trav->d_len; |
200 | entry->d_type = trav->d_type; |
201 | |
202 | gf_stat_to_iatt (&trav->stat, &entry->d_stat); |
203 | |
204 | strcpy (entry->d_name, trav->name); |
205 | |
206 | if (trav->dict.dict_val) { |
207 | /* Dictionary is sent along with response */ |
208 | buf = memdup (trav->dict.dict_val, trav->dict.dict_len); |
209 | if (!buf) |
210 | goto out; |
211 | |
212 | entry->dict = dict_new (); |
213 | |
214 | ret = dict_unserialize (buf, trav->dict.dict_len, |
215 | &entry->dict); |
216 | if (ret < 0) { |
217 | gf_log (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to unserialize xattr dict"); } while (0); _gf_log ((*__glusterfs_this_location())->name , "client-helpers.c", __FUNCTION__, 218, GF_LOG_WARNING, "failed to unserialize xattr dict" ); } while (0) |
218 | "failed to unserialize xattr dict")do { do { if (0) printf ("failed to unserialize xattr dict"); } while (0); _gf_log ((*__glusterfs_this_location())->name , "client-helpers.c", __FUNCTION__, 218, GF_LOG_WARNING, "failed to unserialize xattr dict" ); } while (0); |
219 | errno(*__errno_location ()) = EINVAL22; |
220 | goto out; |
221 | } |
222 | entry->dict->extra_free = buf; |
223 | buf = NULL((void*)0); |
224 | } |
225 | |
226 | entry->inode = inode_find (itable, entry->d_stat.ia_gfid); |
227 | if (!entry->inode) |
228 | entry->inode = inode_new (itable); |
229 | |
230 | list_add_tail (&entry->list, &entries->list); |
231 | |
232 | trav = trav->nextentry; |
233 | } |
234 | |
235 | ret = 0; |
236 | out: |
237 | return ret; |
238 | } |
239 | |
240 | int |
241 | clnt_readdirp_rsp_cleanup (gfs3_readdirp_rsp *rsp) |
242 | { |
243 | gfs3_dirplist *prev = NULL((void*)0); |
244 | gfs3_dirplist *trav = NULL((void*)0); |
245 | |
246 | trav = rsp->reply; |
247 | prev = trav; |
248 | while (trav) { |
249 | trav = trav->nextentry; |
250 | /* on client, the rpc lib allocates this */ |
251 | free (prev->dict.dict_val); |
252 | free (prev->name); |
253 | free (prev); |
254 | prev = trav; |
255 | } |
256 | |
257 | return 0; |
258 | } |
259 | |
260 | int |
261 | clnt_readdir_rsp_cleanup (gfs3_readdir_rsp *rsp) |
262 | { |
263 | gfs3_dirlist *prev = NULL((void*)0); |
264 | gfs3_dirlist *trav = NULL((void*)0); |
265 | |
266 | trav = rsp->reply; |
267 | prev = trav; |
268 | while (trav) { |
269 | trav = trav->nextentry; |
270 | /* on client, the rpc lib allocates this */ |
271 | free (prev->name); |
272 | free (prev); |
273 | prev = trav; |
274 | } |
275 | |
276 | return 0; |
277 | } |
278 | |
279 | int |
280 | client_get_remote_fd (xlator_t *this, fd_t *fd, int flags, int64_t *remote_fd) |
281 | { |
282 | clnt_fd_ctx_t *fdctx = NULL((void*)0); |
283 | clnt_conf_t *conf = NULL((void*)0); |
284 | |
285 | GF_VALIDATE_OR_GOTO (this->name, fd, out)do { if (!fd) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "fd"); } while (0); _gf_log_callingfn (this->name, "client-helpers.c", __FUNCTION__, 285, GF_LOG_ERROR , "invalid argument: " "fd"); } while (0); goto out; } } while (0); |
286 | GF_VALIDATE_OR_GOTO (this->name, remote_fd, out)do { if (!remote_fd) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "remote_fd"); } while (0 ); _gf_log_callingfn (this->name, "client-helpers.c", __FUNCTION__ , 286, GF_LOG_ERROR, "invalid argument: " "remote_fd"); } while (0); goto out; } } while (0); |
287 | |
288 | conf = this->private; |
289 | pthread_mutex_lock (&conf->lock); |
290 | { |
291 | fdctx = this_fd_get_ctx (fd, this); |
292 | if (!fdctx) |
293 | *remote_fd = GF_ANON_FD_NO-2; |
294 | else if (__is_fd_reopen_in_progress (fdctx)) |
295 | *remote_fd = -1; |
296 | else |
297 | *remote_fd = fdctx->remote_fd; |
298 | } |
299 | pthread_mutex_unlock (&conf->lock); |
300 | |
301 | if ((flags & FALLBACK_TO_ANON_FD) && (*remote_fd == -1)) |
302 | *remote_fd = GF_ANON_FD_NO-2; |
303 | |
304 | return 0; |
305 | out: |
306 | return -1; |
307 | } |
308 | |
309 | gf_boolean_t |
310 | client_is_reopen_needed (fd_t *fd, xlator_t *this, int64_t remote_fd) |
311 | { |
312 | clnt_fd_ctx_t *fdctx = NULL((void*)0); |
313 | |
314 | fdctx = this_fd_get_ctx (fd, this); |
315 | if (fdctx && (fdctx->remote_fd == -1) && |
316 | (remote_fd == GF_ANON_FD_NO-2)) |
317 | return _gf_true; |
318 | return _gf_false; |
319 | } |
320 | |
321 | int |
322 | client_fd_fop_prepare_local (call_frame_t *frame, fd_t *fd, int64_t remote_fd) |
323 | { |
324 | xlator_t *this = NULL((void*)0); |
325 | clnt_conf_t *conf = NULL((void*)0); |
326 | clnt_local_t *local = NULL((void*)0); |
327 | int ret = 0; |
328 | |
329 | this = frame->this; |
330 | conf = this->private; |
Value stored to 'conf' is never read | |
331 | |
332 | if (!frame || !fd) { |
333 | ret = -EINVAL22; |
334 | goto out; |
335 | } |
336 | |
337 | frame->local = mem_get0 (this->local_pool); |
338 | if (frame->local == NULL((void*)0)) { |
339 | ret = -ENOMEM12; |
340 | goto out; |
341 | } |
342 | |
343 | local = frame->local; |
344 | local->fd = fd_ref (fd); |
345 | local->attempt_reopen = client_is_reopen_needed (fd, this, remote_fd); |
346 | return 0; |
347 | out: |
348 | return ret; |
349 | } |