File: | xlators/cluster/dht/src/dht-helper.c |
Location: | line 941, column 9 |
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 | #ifndef _CONFIG_H |
12 | #define _CONFIG_H |
13 | #include "config.h" |
14 | #endif |
15 | |
16 | |
17 | #include "glusterfs.h" |
18 | #include "xlator.h" |
19 | #include "dht-common.h" |
20 | |
21 | |
22 | int |
23 | dht_frame_return (call_frame_t *frame) |
24 | { |
25 | dht_local_t *local = NULL((void*)0); |
26 | int this_call_cnt = -1; |
27 | |
28 | if (!frame) |
29 | return -1; |
30 | |
31 | local = frame->local; |
32 | |
33 | LOCK (&frame->lock)pthread_spin_lock (&frame->lock); |
34 | { |
35 | this_call_cnt = --local->call_cnt; |
36 | } |
37 | UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock); |
38 | |
39 | return this_call_cnt; |
40 | } |
41 | |
42 | |
43 | static uint64_t |
44 | dht_bits_for (uint64_t num) |
45 | { |
46 | uint64_t bits = 0, ctrl = 1; |
47 | |
48 | while (ctrl < num) { |
49 | ctrl *= 2; |
50 | bits ++; |
51 | } |
52 | |
53 | return bits; |
54 | } |
55 | |
56 | /* |
57 | * A slightly "updated" version of the algorithm described in the commit log |
58 | * is used here. |
59 | * |
60 | * The only enhancement is that: |
61 | * |
62 | * - The number of bits used by the backend filesystem for HUGE d_off which |
63 | * is described as 63, and |
64 | * - The number of bits used by the d_off presented by the transformation |
65 | * upwards which is described as 64, are both made "configurable." |
66 | */ |
67 | |
68 | |
69 | #define BACKEND_D_OFF_BITS63 63 |
70 | #define PRESENT_D_OFF_BITS63 63 |
71 | |
72 | #define ONE1ULL 1ULL |
73 | #define MASK(~0ULL) (~0ULL) |
74 | #define PRESENT_MASK((~0ULL) >> (64 - 63)) (MASK(~0ULL) >> (64 - PRESENT_D_OFF_BITS63)) |
75 | #define BACKEND_MASK((~0ULL) >> (64 - 63)) (MASK(~0ULL) >> (64 - BACKEND_D_OFF_BITS63)) |
76 | |
77 | #define TOP_BIT(1ULL << (63 - 1)) (ONE1ULL << (PRESENT_D_OFF_BITS63 - 1)) |
78 | #define SHIFT_BITS(((0)>((63 - 63 + 1))?(0):((63 - 63 + 1)))) (max (0, (BACKEND_D_OFF_BITS - PRESENT_D_OFF_BITS + 1))((0)>((63 - 63 + 1))?(0):((63 - 63 + 1)))) |
79 | |
80 | int |
81 | dht_itransform (xlator_t *this, xlator_t *subvol, uint64_t x, uint64_t *y_p) |
82 | { |
83 | dht_conf_t *conf = NULL((void*)0); |
84 | int cnt = 0; |
85 | int max = 0; |
86 | uint64_t y = 0; |
87 | uint64_t hi_mask = 0; |
88 | uint64_t off_mask = 0; |
89 | int max_bits = 0; |
90 | |
91 | if (x == ((uint64_t) -1)) { |
92 | y = (uint64_t) -1; |
93 | goto out; |
94 | } |
95 | |
96 | conf = this->private; |
97 | if (!conf) |
98 | goto out; |
99 | |
100 | max = conf->subvolume_cnt; |
101 | cnt = dht_subvol_cnt (this, subvol); |
102 | |
103 | if (max == 1) { |
104 | y = x; |
105 | goto out; |
106 | } |
107 | |
108 | max_bits = dht_bits_for (max); |
109 | |
110 | hi_mask = ~(PRESENT_MASK((~0ULL) >> (64 - 63)) >> (max_bits + 1)); |
111 | |
112 | if (x & hi_mask) { |
113 | /* HUGE d_off */ |
114 | off_mask = MASK(~0ULL) << max_bits; |
115 | y = TOP_BIT(1ULL << (63 - 1)) | ((x >> SHIFT_BITS(((0)>((63 - 63 + 1))?(0):((63 - 63 + 1))))) & off_mask) | cnt; |
116 | } else { |
117 | /* small d_off */ |
118 | y = ((x * max) + cnt); |
119 | } |
120 | |
121 | out: |
122 | if (y_p) |
123 | *y_p = y; |
124 | |
125 | return 0; |
126 | } |
127 | |
128 | int |
129 | dht_filter_loc_subvol_key (xlator_t *this, loc_t *loc, loc_t *new_loc, |
130 | xlator_t **subvol) |
131 | { |
132 | char *new_name = NULL((void*)0); |
133 | char *new_path = NULL((void*)0); |
134 | xlator_list_t *trav = NULL((void*)0); |
135 | char key[1024] = {0,}; |
136 | int ret = 0; /* not found */ |
137 | |
138 | /* Why do other tasks if first required 'char' itself is not there */ |
139 | if (!new_loc || !loc || !loc->name || !strchr (loc->name, '@')) |
140 | goto out; |
141 | |
142 | trav = this->children; |
143 | while (trav) { |
144 | snprintf (key, 1024, "*@%s:%s", this->name, trav->xlator->name); |
145 | if (fnmatch (key, loc->name, FNM_NOESCAPE(1 << 1)) == 0) { |
146 | new_name = GF_CALLOC(strlen (loc->name),__gf_calloc (strlen (loc->name), sizeof (char), gf_common_mt_char ) |
147 | sizeof (char),__gf_calloc (strlen (loc->name), sizeof (char), gf_common_mt_char ) |
148 | gf_common_mt_char)__gf_calloc (strlen (loc->name), sizeof (char), gf_common_mt_char ); |
149 | if (!new_name) |
150 | goto out; |
151 | if (fnmatch (key, loc->path, FNM_NOESCAPE(1 << 1)) == 0) { |
152 | new_path = GF_CALLOC(strlen (loc->path),__gf_calloc (strlen (loc->path), sizeof (char), gf_common_mt_char ) |
153 | sizeof (char),__gf_calloc (strlen (loc->path), sizeof (char), gf_common_mt_char ) |
154 | gf_common_mt_char)__gf_calloc (strlen (loc->path), sizeof (char), gf_common_mt_char ); |
155 | if (!new_path) |
156 | goto out; |
157 | strncpy (new_path, loc->path, (strlen (loc->path) - |
158 | strlen (key) + 1)); |
159 | } |
160 | strncpy (new_name, loc->name, (strlen (loc->name) - |
161 | strlen (key) + 1)); |
162 | |
163 | if (new_loc) { |
164 | new_loc->path = ((new_path) ? new_path: |
165 | gf_strdup (loc->path)); |
166 | new_loc->name = new_name; |
167 | new_loc->inode = inode_ref (loc->inode); |
168 | new_loc->parent = inode_ref (loc->parent); |
169 | } |
170 | *subvol = trav->xlator; |
171 | ret = 1; /* success */ |
172 | goto out; |
173 | } |
174 | trav = trav->next; |
175 | } |
176 | out: |
177 | if (!ret) { |
178 | /* !success */ |
179 | GF_FREE (new_path)__gf_free (new_path); |
180 | GF_FREE (new_name)__gf_free (new_name); |
181 | } |
182 | return ret; |
183 | } |
184 | |
185 | int |
186 | dht_deitransform (xlator_t *this, uint64_t y, xlator_t **subvol_p, |
187 | uint64_t *x_p) |
188 | { |
189 | dht_conf_t *conf = NULL((void*)0); |
190 | int cnt = 0; |
191 | int max = 0; |
192 | uint64_t x = 0; |
193 | xlator_t *subvol = 0; |
194 | int max_bits = 0; |
195 | uint64_t off_mask = 0; |
196 | uint64_t host_mask = 0; |
197 | |
198 | if (!this->private) |
199 | return -1; |
200 | |
201 | conf = this->private; |
202 | max = conf->subvolume_cnt; |
203 | |
204 | if (max == 1) { |
205 | x = y; |
206 | cnt = 0; |
207 | goto out; |
208 | } |
209 | |
210 | if (y & TOP_BIT(1ULL << (63 - 1))) { |
211 | /* HUGE d_off */ |
212 | max_bits = dht_bits_for (max); |
213 | off_mask = (MASK(~0ULL) << max_bits); |
214 | host_mask = ~(off_mask); |
215 | |
216 | x = ((y & ~TOP_BIT(1ULL << (63 - 1))) & off_mask) << SHIFT_BITS(((0)>((63 - 63 + 1))?(0):((63 - 63 + 1)))); |
217 | |
218 | cnt = y & host_mask; |
219 | } else { |
220 | /* small d_off */ |
221 | cnt = y % max; |
222 | x = y / max; |
223 | } |
224 | |
225 | out: |
226 | subvol = conf->subvolumes[cnt]; |
227 | |
228 | if (subvol_p) |
229 | *subvol_p = subvol; |
230 | |
231 | if (x_p) |
232 | *x_p = x; |
233 | |
234 | return 0; |
235 | } |
236 | |
237 | |
238 | void |
239 | dht_local_wipe (xlator_t *this, dht_local_t *local) |
240 | { |
241 | if (!local) |
242 | return; |
243 | |
244 | loc_wipe (&local->loc); |
245 | loc_wipe (&local->loc2); |
246 | |
247 | if (local->xattr) |
248 | dict_unref (local->xattr); |
249 | |
250 | if (local->inode) |
251 | inode_unref (local->inode); |
252 | |
253 | if (local->layout) { |
254 | dht_layout_unref (this, local->layout); |
255 | local->layout = NULL((void*)0); |
256 | } |
257 | |
258 | loc_wipe (&local->linkfile.loc); |
259 | |
260 | if (local->linkfile.xattr) |
261 | dict_unref (local->linkfile.xattr); |
262 | |
263 | if (local->linkfile.inode) |
264 | inode_unref (local->linkfile.inode); |
265 | |
266 | if (local->fd) { |
267 | fd_unref (local->fd); |
268 | local->fd = NULL((void*)0); |
269 | } |
270 | |
271 | if (local->params) { |
272 | dict_unref (local->params); |
273 | local->params = NULL((void*)0); |
274 | } |
275 | |
276 | if (local->xattr_req) |
277 | dict_unref (local->xattr_req); |
278 | |
279 | if (local->selfheal.layout) { |
280 | dht_layout_unref (this, local->selfheal.layout); |
281 | local->selfheal.layout = NULL((void*)0); |
282 | } |
283 | |
284 | GF_FREE (local->newpath)__gf_free (local->newpath); |
285 | |
286 | GF_FREE (local->key)__gf_free (local->key); |
287 | |
288 | GF_FREE (local->rebalance.vector)__gf_free (local->rebalance.vector); |
289 | |
290 | if (local->rebalance.iobref) |
291 | iobref_unref (local->rebalance.iobref); |
292 | |
293 | mem_put (local); |
294 | } |
295 | |
296 | |
297 | dht_local_t * |
298 | dht_local_init (call_frame_t *frame, loc_t *loc, fd_t *fd, glusterfs_fop_t fop) |
299 | { |
300 | dht_local_t *local = NULL((void*)0); |
301 | inode_t *inode = NULL((void*)0); |
302 | int ret = 0; |
303 | |
304 | local = mem_get0 (THIS(*__glusterfs_this_location())->local_pool); |
305 | if (!local) |
306 | goto out; |
307 | |
308 | if (loc) { |
309 | ret = loc_copy (&local->loc, loc); |
310 | if (ret) |
311 | goto out; |
312 | |
313 | inode = loc->inode; |
314 | } |
315 | |
316 | if (fd) { |
317 | local->fd = fd_ref (fd); |
318 | if (!inode) |
319 | inode = fd->inode; |
320 | } |
321 | |
322 | local->op_ret = -1; |
323 | local->op_errno = EUCLEAN117; |
324 | local->fop = fop; |
325 | |
326 | if (inode) { |
327 | local->layout = dht_layout_get (frame->this, inode); |
328 | local->cached_subvol = dht_subvol_get_cached (frame->this, |
329 | inode); |
330 | } |
331 | |
332 | frame->local = local; |
333 | |
334 | out: |
335 | if (ret) { |
336 | if (local) |
337 | mem_put (local); |
338 | local = NULL((void*)0); |
339 | } |
340 | return local; |
341 | } |
342 | |
343 | |
344 | char * |
345 | basestr (const char *str) |
346 | { |
347 | char *basestr = NULL((void*)0); |
348 | |
349 | basestr = strrchr (str, '/'); |
350 | if (basestr) |
351 | basestr ++; |
352 | |
353 | return basestr; |
354 | } |
355 | |
356 | |
357 | xlator_t * |
358 | dht_first_up_subvol (xlator_t *this) |
359 | { |
360 | dht_conf_t *conf = NULL((void*)0); |
361 | xlator_t *child = NULL((void*)0); |
362 | int i = 0; |
363 | time_t time = 0; |
364 | |
365 | conf = this->private; |
366 | if (!conf) |
367 | goto out; |
368 | |
369 | LOCK (&conf->subvolume_lock)pthread_spin_lock (&conf->subvolume_lock); |
370 | { |
371 | for (i = 0; i < conf->subvolume_cnt; i++) { |
372 | if (conf->subvol_up_time[i]) { |
373 | if (!time) { |
374 | time = conf->subvol_up_time[i]; |
375 | child = conf->subvolumes[i]; |
376 | } else if (time > conf->subvol_up_time[i]) { |
377 | time = conf->subvol_up_time[i]; |
378 | child = conf->subvolumes[i]; |
379 | } |
380 | } |
381 | } |
382 | } |
383 | UNLOCK (&conf->subvolume_lock)pthread_spin_unlock (&conf->subvolume_lock); |
384 | |
385 | out: |
386 | return child; |
387 | } |
388 | |
389 | xlator_t * |
390 | dht_last_up_subvol (xlator_t *this) |
391 | { |
392 | dht_conf_t *conf = NULL((void*)0); |
393 | xlator_t *child = NULL((void*)0); |
394 | int i = 0; |
395 | |
396 | conf = this->private; |
397 | if (!conf) |
398 | goto out; |
399 | |
400 | LOCK (&conf->subvolume_lock)pthread_spin_lock (&conf->subvolume_lock); |
401 | { |
402 | for (i = conf->subvolume_cnt-1; i >= 0; i--) { |
403 | if (conf->subvolume_status[i]) { |
404 | child = conf->subvolumes[i]; |
405 | break; |
406 | } |
407 | } |
408 | } |
409 | UNLOCK (&conf->subvolume_lock)pthread_spin_unlock (&conf->subvolume_lock); |
410 | |
411 | out: |
412 | return child; |
413 | } |
414 | |
415 | xlator_t * |
416 | dht_subvol_get_hashed (xlator_t *this, loc_t *loc) |
417 | { |
418 | dht_layout_t *layout = NULL((void*)0); |
419 | xlator_t *subvol = NULL((void*)0); |
420 | |
421 | GF_VALIDATE_OR_GOTO ("dht", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("dht", "dht-helper.c", __FUNCTION__, 421, GF_LOG_ERROR, "invalid argument: " "this"); } while (0); goto out; } } while (0); |
422 | GF_VALIDATE_OR_GOTO (this->name, loc, out)do { if (!loc) { (*__errno_location ()) = 22; do { do { if (0 ) printf ("invalid argument: " "loc"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__, 422, GF_LOG_ERROR , "invalid argument: " "loc"); } while (0); goto out; } } while (0); |
423 | |
424 | if (__is_root_gfid (loc->gfid)) { |
425 | subvol = dht_first_up_subvol (this); |
426 | goto out; |
427 | } |
428 | |
429 | GF_VALIDATE_OR_GOTO (this->name, loc->parent, out)do { if (!loc->parent) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "loc->parent"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__, 429, GF_LOG_ERROR, "invalid argument: " "loc->parent" ); } while (0); goto out; } } while (0); |
430 | GF_VALIDATE_OR_GOTO (this->name, loc->name, out)do { if (!loc->name) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "loc->name"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__ , 430, GF_LOG_ERROR, "invalid argument: " "loc->name"); } while (0); goto out; } } while (0); |
431 | |
432 | layout = dht_layout_get (this, loc->parent); |
433 | |
434 | if (!layout) { |
435 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("layout missing path=%s parent=%s", loc ->path, uuid_utoa (loc->parent->gfid)); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 437, GF_LOG_DEBUG , "layout missing path=%s parent=%s", loc->path, uuid_utoa (loc->parent->gfid)); } while (0) |
436 | "layout missing path=%s parent=%s",do { do { if (0) printf ("layout missing path=%s parent=%s", loc ->path, uuid_utoa (loc->parent->gfid)); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 437, GF_LOG_DEBUG , "layout missing path=%s parent=%s", loc->path, uuid_utoa (loc->parent->gfid)); } while (0) |
437 | loc->path, uuid_utoa (loc->parent->gfid))do { do { if (0) printf ("layout missing path=%s parent=%s", loc ->path, uuid_utoa (loc->parent->gfid)); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 437, GF_LOG_DEBUG , "layout missing path=%s parent=%s", loc->path, uuid_utoa (loc->parent->gfid)); } while (0); |
438 | goto out; |
439 | } |
440 | |
441 | subvol = dht_layout_search (this, layout, loc->name); |
442 | |
443 | if (!subvol) { |
444 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("could not find subvolume for path=%s" , loc->path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 446, GF_LOG_DEBUG, "could not find subvolume for path=%s" , loc->path); } while (0) |
445 | "could not find subvolume for path=%s",do { do { if (0) printf ("could not find subvolume for path=%s" , loc->path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 446, GF_LOG_DEBUG, "could not find subvolume for path=%s" , loc->path); } while (0) |
446 | loc->path)do { do { if (0) printf ("could not find subvolume for path=%s" , loc->path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 446, GF_LOG_DEBUG, "could not find subvolume for path=%s" , loc->path); } while (0); |
447 | goto out; |
448 | } |
449 | |
450 | out: |
451 | if (layout) { |
452 | dht_layout_unref (this, layout); |
453 | } |
454 | |
455 | return subvol; |
456 | } |
457 | |
458 | |
459 | xlator_t * |
460 | dht_subvol_get_cached (xlator_t *this, inode_t *inode) |
461 | { |
462 | dht_layout_t *layout = NULL((void*)0); |
463 | xlator_t *subvol = NULL((void*)0); |
464 | |
465 | GF_VALIDATE_OR_GOTO (this->name, this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__, 465, GF_LOG_ERROR , "invalid argument: " "this"); } while (0); goto out; } } while (0); |
466 | GF_VALIDATE_OR_GOTO (this->name, inode, out)do { if (!inode) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "inode"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__, 466, GF_LOG_ERROR , "invalid argument: " "inode"); } while (0); goto out; } } while (0); |
467 | |
468 | layout = dht_layout_get (this, inode); |
469 | |
470 | if (!layout) { |
471 | goto out; |
472 | } |
473 | |
474 | subvol = layout->list[0].xlator; |
475 | |
476 | out: |
477 | if (layout) { |
478 | dht_layout_unref (this, layout); |
479 | } |
480 | |
481 | return subvol; |
482 | } |
483 | |
484 | |
485 | xlator_t * |
486 | dht_subvol_next (xlator_t *this, xlator_t *prev) |
487 | { |
488 | dht_conf_t *conf = NULL((void*)0); |
489 | int i = 0; |
490 | xlator_t *next = NULL((void*)0); |
491 | |
492 | conf = this->private; |
493 | if (!conf) |
494 | goto out; |
495 | |
496 | for (i = 0; i < conf->subvolume_cnt; i++) { |
497 | if (conf->subvolumes[i] == prev) { |
498 | if ((i + 1) < conf->subvolume_cnt) |
499 | next = conf->subvolumes[i + 1]; |
500 | break; |
501 | } |
502 | } |
503 | |
504 | out: |
505 | return next; |
506 | } |
507 | |
508 | |
509 | int |
510 | dht_subvol_cnt (xlator_t *this, xlator_t *subvol) |
511 | { |
512 | int i = 0; |
513 | int ret = -1; |
514 | dht_conf_t *conf = NULL((void*)0); |
515 | |
516 | conf = this->private; |
517 | if (!conf) |
518 | goto out; |
519 | |
520 | for (i = 0; i < conf->subvolume_cnt; i++) { |
521 | if (subvol == conf->subvolumes[i]) { |
522 | ret = i; |
523 | break; |
524 | } |
525 | } |
526 | |
527 | out: |
528 | return ret; |
529 | } |
530 | |
531 | |
532 | #define set_if_greater(a, b)do { if ((a) < (b)) (a) = (b); } while (0) do { \ |
533 | if ((a) < (b)) \ |
534 | (a) = (b); \ |
535 | } while (0) |
536 | |
537 | |
538 | #define set_if_greater_time(a, an, b, bn)do { if (((a) < (b)) || (((a) == (b)) && ((an) < (bn)))){ (a) = (b); (an) = (bn); } } while (0) do { \ |
539 | if (((a) < (b)) || (((a) == (b)) && ((an) < (bn)))){ \ |
540 | (a) = (b); \ |
541 | (an) = (bn); \ |
542 | } \ |
543 | } while (0) \ |
544 | |
545 | |
546 | int |
547 | dht_iatt_merge (xlator_t *this, struct iatt *to, |
548 | struct iatt *from, xlator_t *subvol) |
549 | { |
550 | if (!from || !to) |
551 | return 0; |
552 | |
553 | to->ia_dev = from->ia_dev; |
554 | |
555 | uuid_copy (to->ia_gfid, from->ia_gfid); |
556 | |
557 | to->ia_ino = from->ia_ino; |
558 | to->ia_prot = from->ia_prot; |
559 | to->ia_type = from->ia_type; |
560 | to->ia_nlink = from->ia_nlink; |
561 | to->ia_rdev = from->ia_rdev; |
562 | to->ia_size += from->ia_size; |
563 | to->ia_blksize = from->ia_blksize; |
564 | to->ia_blocks += from->ia_blocks; |
565 | |
566 | set_if_greater (to->ia_uid, from->ia_uid)do { if ((to->ia_uid) < (from->ia_uid)) (to->ia_uid ) = (from->ia_uid); } while (0); |
567 | set_if_greater (to->ia_gid, from->ia_gid)do { if ((to->ia_gid) < (from->ia_gid)) (to->ia_gid ) = (from->ia_gid); } while (0); |
568 | |
569 | set_if_greater_time(to->ia_atime, to->ia_atime_nsec,do { if (((to->ia_atime) < (from->ia_atime)) || (((to ->ia_atime) == (from->ia_atime)) && ((to->ia_atime_nsec ) < (from->ia_atime_nsec)))){ (to->ia_atime) = (from ->ia_atime); (to->ia_atime_nsec) = (from->ia_atime_nsec ); } } while (0) |
570 | from->ia_atime, from->ia_atime_nsec)do { if (((to->ia_atime) < (from->ia_atime)) || (((to ->ia_atime) == (from->ia_atime)) && ((to->ia_atime_nsec ) < (from->ia_atime_nsec)))){ (to->ia_atime) = (from ->ia_atime); (to->ia_atime_nsec) = (from->ia_atime_nsec ); } } while (0); |
571 | set_if_greater_time (to->ia_mtime, to->ia_mtime_nsec,do { if (((to->ia_mtime) < (from->ia_mtime)) || (((to ->ia_mtime) == (from->ia_mtime)) && ((to->ia_mtime_nsec ) < (from->ia_mtime_nsec)))){ (to->ia_mtime) = (from ->ia_mtime); (to->ia_mtime_nsec) = (from->ia_mtime_nsec ); } } while (0) |
572 | from->ia_mtime, from->ia_mtime_nsec)do { if (((to->ia_mtime) < (from->ia_mtime)) || (((to ->ia_mtime) == (from->ia_mtime)) && ((to->ia_mtime_nsec ) < (from->ia_mtime_nsec)))){ (to->ia_mtime) = (from ->ia_mtime); (to->ia_mtime_nsec) = (from->ia_mtime_nsec ); } } while (0); |
573 | set_if_greater_time (to->ia_ctime, to->ia_ctime_nsec,do { if (((to->ia_ctime) < (from->ia_ctime)) || (((to ->ia_ctime) == (from->ia_ctime)) && ((to->ia_ctime_nsec ) < (from->ia_ctime_nsec)))){ (to->ia_ctime) = (from ->ia_ctime); (to->ia_ctime_nsec) = (from->ia_ctime_nsec ); } } while (0) |
574 | from->ia_ctime, from->ia_ctime_nsec)do { if (((to->ia_ctime) < (from->ia_ctime)) || (((to ->ia_ctime) == (from->ia_ctime)) && ((to->ia_ctime_nsec ) < (from->ia_ctime_nsec)))){ (to->ia_ctime) = (from ->ia_ctime); (to->ia_ctime_nsec) = (from->ia_ctime_nsec ); } } while (0); |
575 | |
576 | return 0; |
577 | } |
578 | |
579 | int |
580 | dht_build_child_loc (xlator_t *this, loc_t *child, loc_t *parent, char *name) |
581 | { |
582 | if (!child) { |
583 | goto err; |
584 | } |
585 | |
586 | if (strcmp (parent->path, "/") == 0) |
587 | gf_asprintf ((char **)&child->path, "/%s", name); |
588 | else |
589 | gf_asprintf ((char **)&child->path, "%s/%s", parent->path, name); |
590 | |
591 | if (!child->path) { |
592 | goto err; |
593 | } |
594 | |
595 | child->name = strrchr (child->path, '/'); |
596 | if (child->name) |
597 | child->name++; |
598 | |
599 | child->parent = inode_ref (parent->inode); |
600 | child->inode = inode_new (parent->inode->table); |
601 | |
602 | if (!child->inode) { |
603 | goto err; |
604 | } |
605 | |
606 | return 0; |
607 | err: |
608 | loc_wipe (child); |
609 | return -1; |
610 | } |
611 | |
612 | |
613 | |
614 | int |
615 | dht_init_subvolumes (xlator_t *this, dht_conf_t *conf) |
616 | { |
617 | xlator_list_t *subvols = NULL((void*)0); |
618 | int cnt = 0; |
619 | |
620 | if (!conf) |
621 | return -1; |
622 | |
623 | for (subvols = this->children; subvols; subvols = subvols->next) |
624 | cnt++; |
625 | |
626 | conf->subvolumes = GF_CALLOC (cnt, sizeof (xlator_t *),__gf_calloc (cnt, sizeof (xlator_t *), gf_dht_mt_xlator_t) |
627 | gf_dht_mt_xlator_t)__gf_calloc (cnt, sizeof (xlator_t *), gf_dht_mt_xlator_t); |
628 | if (!conf->subvolumes) { |
629 | return -1; |
630 | } |
631 | conf->subvolume_cnt = cnt; |
632 | |
633 | cnt = 0; |
634 | for (subvols = this->children; subvols; subvols = subvols->next) |
635 | conf->subvolumes[cnt++] = subvols->xlator; |
636 | |
637 | conf->subvolume_status = GF_CALLOC (cnt, sizeof (char),__gf_calloc (cnt, sizeof (char), gf_dht_mt_char) |
638 | gf_dht_mt_char)__gf_calloc (cnt, sizeof (char), gf_dht_mt_char); |
639 | if (!conf->subvolume_status) { |
640 | return -1; |
641 | } |
642 | |
643 | conf->last_event = GF_CALLOC (cnt, sizeof (int),__gf_calloc (cnt, sizeof (int), gf_dht_mt_char) |
644 | gf_dht_mt_char)__gf_calloc (cnt, sizeof (int), gf_dht_mt_char); |
645 | if (!conf->last_event) { |
646 | return -1; |
647 | } |
648 | |
649 | conf->subvol_up_time = GF_CALLOC (cnt, sizeof (time_t),__gf_calloc (cnt, sizeof (time_t), gf_dht_mt_subvol_time) |
650 | gf_dht_mt_subvol_time)__gf_calloc (cnt, sizeof (time_t), gf_dht_mt_subvol_time); |
651 | if (!conf->subvol_up_time) { |
652 | return -1; |
653 | } |
654 | |
655 | conf->du_stats = GF_CALLOC (conf->subvolume_cnt, sizeof (dht_du_t),__gf_calloc (conf->subvolume_cnt, sizeof (dht_du_t), gf_dht_mt_dht_du_t ) |
656 | gf_dht_mt_dht_du_t)__gf_calloc (conf->subvolume_cnt, sizeof (dht_du_t), gf_dht_mt_dht_du_t ); |
657 | if (!conf->du_stats) { |
658 | return -1; |
659 | } |
660 | |
661 | conf->decommissioned_bricks = GF_CALLOC (cnt, sizeof (xlator_t *),__gf_calloc (cnt, sizeof (xlator_t *), gf_dht_mt_xlator_t) |
662 | gf_dht_mt_xlator_t)__gf_calloc (cnt, sizeof (xlator_t *), gf_dht_mt_xlator_t); |
663 | if (!conf->decommissioned_bricks) { |
664 | return -1; |
665 | } |
666 | |
667 | return 0; |
668 | } |
669 | |
670 | |
671 | |
672 | |
673 | static int |
674 | dht_migration_complete_check_done (int op_ret, call_frame_t *frame, void *data) |
675 | { |
676 | dht_local_t *local = NULL((void*)0); |
677 | |
678 | local = frame->local; |
679 | |
680 | local->rebalance.target_op_fn (THIS(*__glusterfs_this_location()), frame, op_ret); |
681 | |
682 | return 0; |
683 | } |
684 | |
685 | |
686 | int |
687 | dht_migration_complete_check_task (void *data) |
688 | { |
689 | int ret = -1; |
690 | xlator_t *src_node = NULL((void*)0); |
691 | xlator_t *dst_node = NULL((void*)0); |
692 | dht_local_t *local = NULL((void*)0); |
693 | dict_t *dict = NULL((void*)0); |
694 | dht_layout_t *layout = NULL((void*)0); |
695 | struct iatt stbuf = {0,}; |
696 | xlator_t *this = NULL((void*)0); |
697 | call_frame_t *frame = NULL((void*)0); |
698 | loc_t tmp_loc = {0,}; |
699 | char *path = NULL((void*)0); |
700 | dht_conf_t *conf = NULL((void*)0); |
701 | |
702 | this = THIS(*__glusterfs_this_location()); |
703 | frame = data; |
704 | local = frame->local; |
705 | conf = this->private; |
706 | |
707 | src_node = local->cached_subvol; |
708 | |
709 | if (!local->loc.inode && !local->fd) |
710 | goto out; |
711 | |
712 | /* getxattr on cached_subvol for 'linkto' value */ |
713 | if (!local->loc.inode) |
714 | ret = syncop_fgetxattr (src_node, local->fd, &dict, |
715 | conf->link_xattr_name); |
716 | else |
717 | ret = syncop_getxattr (src_node, &local->loc, &dict, |
718 | conf->link_xattr_name); |
719 | |
720 | if (!ret) |
721 | dst_node = dht_linkfile_subvol (this, NULL((void*)0), NULL((void*)0), dict); |
722 | |
723 | if (ret) { |
724 | if ((errno(*__errno_location ()) != ENOENT2) || (!local->loc.inode)) { |
725 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to get the 'linkto' xattr %s" , local->loc.path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 727 , GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr %s", local ->loc.path, strerror ((*__errno_location ()))); } while (0 ) |
726 | "%s: failed to get the 'linkto' xattr %s",do { do { if (0) printf ("%s: failed to get the 'linkto' xattr %s" , local->loc.path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 727 , GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr %s", local ->loc.path, strerror ((*__errno_location ()))); } while (0 ) |
727 | local->loc.path, strerror (errno))do { do { if (0) printf ("%s: failed to get the 'linkto' xattr %s" , local->loc.path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 727 , GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr %s", local ->loc.path, strerror ((*__errno_location ()))); } while (0 ); |
728 | goto out; |
729 | } |
730 | /* Need to do lookup on hashed subvol, then get the file */ |
731 | ret = syncop_lookup (this, &local->loc, NULL((void*)0), &stbuf, NULL((void*)0), |
732 | NULL((void*)0)); |
733 | if (ret) |
734 | goto out; |
735 | dst_node = dht_subvol_get_cached (this, local->loc.inode); |
736 | } |
737 | |
738 | if (!dst_node) { |
739 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to get the destination node" , local->loc.path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 741, GF_LOG_ERROR, "%s: failed to get the destination node" , local->loc.path); } while (0) |
740 | "%s: failed to get the destination node",do { do { if (0) printf ("%s: failed to get the destination node" , local->loc.path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 741, GF_LOG_ERROR, "%s: failed to get the destination node" , local->loc.path); } while (0) |
741 | local->loc.path)do { do { if (0) printf ("%s: failed to get the destination node" , local->loc.path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 741, GF_LOG_ERROR, "%s: failed to get the destination node" , local->loc.path); } while (0); |
742 | ret = -1; |
743 | goto out; |
744 | } |
745 | |
746 | /* lookup on dst */ |
747 | if (local->loc.inode) { |
748 | ret = syncop_lookup (dst_node, &local->loc, NULL((void*)0), &stbuf, NULL((void*)0), NULL((void*)0)); |
749 | |
750 | if (ret) { |
751 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to lookup the file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 753, GF_LOG_ERROR , "%s: failed to lookup the file on %s", local->loc.path, dst_node ->name); } while (0) |
752 | "%s: failed to lookup the file on %s",do { do { if (0) printf ("%s: failed to lookup the file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 753, GF_LOG_ERROR , "%s: failed to lookup the file on %s", local->loc.path, dst_node ->name); } while (0) |
753 | local->loc.path, dst_node->name)do { do { if (0) printf ("%s: failed to lookup the file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 753, GF_LOG_ERROR , "%s: failed to lookup the file on %s", local->loc.path, dst_node ->name); } while (0); |
754 | goto out; |
755 | } |
756 | |
757 | if (uuid_compare (stbuf.ia_gfid, local->loc.inode->gfid)) { |
758 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: gfid different on the target file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 760, GF_LOG_ERROR , "%s: gfid different on the target file on %s", local->loc .path, dst_node->name); } while (0) |
759 | "%s: gfid different on the target file on %s",do { do { if (0) printf ("%s: gfid different on the target file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 760, GF_LOG_ERROR , "%s: gfid different on the target file on %s", local->loc .path, dst_node->name); } while (0) |
760 | local->loc.path, dst_node->name)do { do { if (0) printf ("%s: gfid different on the target file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 760, GF_LOG_ERROR , "%s: gfid different on the target file on %s", local->loc .path, dst_node->name); } while (0); |
761 | ret = -1; |
762 | goto out; |
763 | } |
764 | } |
765 | |
766 | /* update inode ctx (the layout) */ |
767 | dht_layout_unref (this, local->layout); |
768 | |
769 | if (!local->loc.inode) |
770 | ret = dht_layout_preset (this, dst_node, local->fd->inode); |
771 | else |
772 | ret = dht_layout_preset (this, dst_node, local->loc.inode); |
773 | if (ret != 0) { |
774 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("%s: could not set preset layout for subvol %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 776, GF_LOG_DEBUG , "%s: could not set preset layout for subvol %s", local-> loc.path, dst_node->name); } while (0) |
775 | "%s: could not set preset layout for subvol %s",do { do { if (0) printf ("%s: could not set preset layout for subvol %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 776, GF_LOG_DEBUG , "%s: could not set preset layout for subvol %s", local-> loc.path, dst_node->name); } while (0) |
776 | local->loc.path, dst_node->name)do { do { if (0) printf ("%s: could not set preset layout for subvol %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 776, GF_LOG_DEBUG , "%s: could not set preset layout for subvol %s", local-> loc.path, dst_node->name); } while (0); |
777 | ret = -1; |
778 | goto out; |
779 | } |
780 | |
781 | layout = dht_layout_for_subvol (this, dst_node); |
782 | if (!layout) { |
783 | gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("%s: no pre-set layout for subvolume %s" , local->loc.path, dst_node ? dst_node->name : "<nil>" ); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__ , 785, GF_LOG_INFO, "%s: no pre-set layout for subvolume %s", local->loc.path, dst_node ? dst_node->name : "<nil>" ); } while (0) |
784 | "%s: no pre-set layout for subvolume %s",do { do { if (0) printf ("%s: no pre-set layout for subvolume %s" , local->loc.path, dst_node ? dst_node->name : "<nil>" ); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__ , 785, GF_LOG_INFO, "%s: no pre-set layout for subvolume %s", local->loc.path, dst_node ? dst_node->name : "<nil>" ); } while (0) |
785 | local->loc.path, dst_node ? dst_node->name : "<nil>")do { do { if (0) printf ("%s: no pre-set layout for subvolume %s" , local->loc.path, dst_node ? dst_node->name : "<nil>" ); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__ , 785, GF_LOG_INFO, "%s: no pre-set layout for subvolume %s", local->loc.path, dst_node ? dst_node->name : "<nil>" ); } while (0); |
786 | ret = -1; |
787 | goto out; |
788 | } |
789 | |
790 | if (!local->loc.inode) |
791 | ret = dht_layout_set (this, local->fd->inode, layout); |
792 | else |
793 | ret = dht_layout_set (this, local->loc.inode, layout); |
794 | if (ret) { |
795 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to set the new layout", local ->loc.path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 797, GF_LOG_ERROR, "%s: failed to set the new layout" , local->loc.path); } while (0) |
796 | "%s: failed to set the new layout",do { do { if (0) printf ("%s: failed to set the new layout", local ->loc.path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 797, GF_LOG_ERROR, "%s: failed to set the new layout" , local->loc.path); } while (0) |
797 | local->loc.path)do { do { if (0) printf ("%s: failed to set the new layout", local ->loc.path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 797, GF_LOG_ERROR, "%s: failed to set the new layout" , local->loc.path); } while (0); |
798 | goto out; |
799 | } |
800 | |
801 | local->cached_subvol = dst_node; |
802 | ret = 0; |
803 | |
804 | /* once we detect the migration complete, the fd-ctx is no more |
805 | required.. delete the ctx, and do one extra 'fd_unref' for open fd */ |
806 | ret = fd_ctx_del (local->fd, this, NULL((void*)0)); |
807 | if (!ret) { |
808 | fd_unref (local->fd); |
809 | ret = 0; |
810 | goto out; |
811 | } |
812 | |
813 | /* perform open as root:root. There is window between linkfile |
814 | * creation(root:root) and setattr with the correct uid/gid |
815 | */ |
816 | SYNCTASK_SETID(0, 0)synctask_setid (synctask_get(), 0, 0);; |
817 | /* if 'local->fd' (ie, fd based operation), send a 'open()' on |
818 | destination if not already done */ |
819 | if (local->loc.inode) { |
820 | ret = syncop_open (dst_node, &local->loc, |
821 | local->fd->flags, local->fd); |
822 | } else { |
823 | tmp_loc.inode = local->fd->inode; |
824 | inode_path (local->fd->inode, NULL((void*)0), &path); |
825 | if (path) |
826 | tmp_loc.path = path; |
827 | ret = syncop_open (dst_node, &tmp_loc, |
828 | local->fd->flags, local->fd); |
829 | GF_FREE (path)__gf_free (path); |
830 | |
831 | } |
832 | SYNCTASK_SETID (frame->root->uid, frame->root->gid)synctask_setid (synctask_get(), frame->root->uid, frame ->root->gid);; |
833 | if (ret == -1) { |
834 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to send open() on target file at %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 836, GF_LOG_ERROR , "%s: failed to send open() on target file at %s", local-> loc.path, dst_node->name); } while (0) |
835 | "%s: failed to send open() on target file at %s",do { do { if (0) printf ("%s: failed to send open() on target file at %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 836, GF_LOG_ERROR , "%s: failed to send open() on target file at %s", local-> loc.path, dst_node->name); } while (0) |
836 | local->loc.path, dst_node->name)do { do { if (0) printf ("%s: failed to send open() on target file at %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 836, GF_LOG_ERROR , "%s: failed to send open() on target file at %s", local-> loc.path, dst_node->name); } while (0); |
837 | goto out; |
838 | } |
839 | |
840 | ret = 0; |
841 | out: |
842 | |
843 | return ret; |
844 | } |
845 | |
846 | int |
847 | dht_rebalance_complete_check (xlator_t *this, call_frame_t *frame) |
848 | { |
849 | int ret = -1; |
850 | |
851 | ret = synctask_new (this->ctx->env, dht_migration_complete_check_task, |
852 | dht_migration_complete_check_done, |
853 | frame, frame); |
854 | return ret; |
855 | } |
856 | |
857 | /* During 'in-progress' state, both nodes should have the file */ |
858 | static int |
859 | dht_inprogress_check_done (int op_ret, call_frame_t *sync_frame, void *data) |
860 | { |
861 | dht_local_t *local = NULL((void*)0); |
862 | |
863 | local = sync_frame->local; |
864 | |
865 | local->rebalance.target_op_fn (THIS(*__glusterfs_this_location()), sync_frame, op_ret); |
866 | |
867 | return 0; |
868 | } |
869 | |
870 | static int |
871 | dht_rebalance_inprogress_task (void *data) |
872 | { |
873 | int ret = -1; |
874 | xlator_t *src_node = NULL((void*)0); |
875 | xlator_t *dst_node = NULL((void*)0); |
876 | dht_local_t *local = NULL((void*)0); |
877 | dict_t *dict = NULL((void*)0); |
878 | call_frame_t *frame = NULL((void*)0); |
879 | xlator_t *this = NULL((void*)0); |
880 | char *path = NULL((void*)0); |
881 | struct iatt stbuf = {0,}; |
882 | loc_t tmp_loc = {0,}; |
883 | dht_conf_t *conf = NULL((void*)0); |
884 | |
885 | this = THIS(*__glusterfs_this_location()); |
886 | frame = data; |
887 | local = frame->local; |
888 | conf = this->private; |
889 | |
890 | src_node = local->cached_subvol; |
891 | |
892 | if (!local->loc.inode && !local->fd) |
893 | goto out; |
894 | |
895 | /* getxattr on cached_subvol for 'linkto' value */ |
896 | if (local->loc.inode) |
897 | ret = syncop_getxattr (src_node, &local->loc, &dict, |
898 | conf->link_xattr_name); |
899 | else |
900 | ret = syncop_fgetxattr (src_node, local->fd, &dict, |
901 | conf->link_xattr_name); |
902 | |
903 | if (ret) { |
904 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to get the 'linkto' xattr %s" , local->loc.path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 906 , GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr %s", local ->loc.path, strerror ((*__errno_location ()))); } while (0 ) |
905 | "%s: failed to get the 'linkto' xattr %s",do { do { if (0) printf ("%s: failed to get the 'linkto' xattr %s" , local->loc.path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 906 , GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr %s", local ->loc.path, strerror ((*__errno_location ()))); } while (0 ) |
906 | local->loc.path, strerror (errno))do { do { if (0) printf ("%s: failed to get the 'linkto' xattr %s" , local->loc.path, strerror ((*__errno_location ()))); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 906 , GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr %s", local ->loc.path, strerror ((*__errno_location ()))); } while (0 ); |
907 | goto out; |
908 | } |
909 | |
910 | dst_node = dht_linkfile_subvol (this, NULL((void*)0), NULL((void*)0), dict); |
911 | if (!dst_node) { |
912 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to get the 'linkto' xattr from dict" , local->loc.path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 914, GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr from dict" , local->loc.path); } while (0) |
913 | "%s: failed to get the 'linkto' xattr from dict",do { do { if (0) printf ("%s: failed to get the 'linkto' xattr from dict" , local->loc.path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 914, GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr from dict" , local->loc.path); } while (0) |
914 | local->loc.path)do { do { if (0) printf ("%s: failed to get the 'linkto' xattr from dict" , local->loc.path); } while (0); _gf_log (this->name, "dht-helper.c" , __FUNCTION__, 914, GF_LOG_ERROR, "%s: failed to get the 'linkto' xattr from dict" , local->loc.path); } while (0); |
915 | ret = -1; |
916 | goto out; |
917 | } |
918 | |
919 | local->rebalance.target_node = dst_node; |
920 | |
921 | if (local->loc.inode) { |
922 | /* lookup on dst */ |
923 | ret = syncop_lookup (dst_node, &local->loc, NULL((void*)0), |
924 | &stbuf, NULL((void*)0), NULL((void*)0)); |
925 | if (ret) { |
926 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to lookup the file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 928, GF_LOG_ERROR , "%s: failed to lookup the file on %s", local->loc.path, dst_node ->name); } while (0) |
927 | "%s: failed to lookup the file on %s",do { do { if (0) printf ("%s: failed to lookup the file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 928, GF_LOG_ERROR , "%s: failed to lookup the file on %s", local->loc.path, dst_node ->name); } while (0) |
928 | local->loc.path, dst_node->name)do { do { if (0) printf ("%s: failed to lookup the file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 928, GF_LOG_ERROR , "%s: failed to lookup the file on %s", local->loc.path, dst_node ->name); } while (0); |
929 | goto out; |
930 | } |
931 | |
932 | if (uuid_compare (stbuf.ia_gfid, local->loc.inode->gfid)) { |
933 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: gfid different on the target file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 935, GF_LOG_ERROR , "%s: gfid different on the target file on %s", local->loc .path, dst_node->name); } while (0) |
934 | "%s: gfid different on the target file on %s",do { do { if (0) printf ("%s: gfid different on the target file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 935, GF_LOG_ERROR , "%s: gfid different on the target file on %s", local->loc .path, dst_node->name); } while (0) |
935 | local->loc.path, dst_node->name)do { do { if (0) printf ("%s: gfid different on the target file on %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 935, GF_LOG_ERROR , "%s: gfid different on the target file on %s", local->loc .path, dst_node->name); } while (0); |
936 | ret = -1; |
937 | goto out; |
938 | } |
939 | } |
940 | |
941 | ret = 0; |
Value stored to 'ret' is never read | |
942 | /* perform open as root:root. There is window between linkfile |
943 | * creation(root:root) and setattr with the correct uid/gid |
944 | */ |
945 | SYNCTASK_SETID (0, 0)synctask_setid (synctask_get(), 0, 0);; |
946 | if (local->loc.inode) { |
947 | ret = syncop_open (dst_node, &local->loc, |
948 | local->fd->flags, local->fd); |
949 | } else { |
950 | tmp_loc.inode = local->fd->inode; |
951 | inode_path (local->fd->inode, NULL((void*)0), &path); |
952 | if (path) |
953 | tmp_loc.path = path; |
954 | ret = syncop_open (dst_node, &tmp_loc, |
955 | local->fd->flags, local->fd); |
956 | GF_FREE (path)__gf_free (path); |
957 | } |
958 | |
959 | if (ret == -1) { |
960 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to send open() on target file at %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 962, GF_LOG_ERROR , "%s: failed to send open() on target file at %s", local-> loc.path, dst_node->name); } while (0) |
961 | "%s: failed to send open() on target file at %s",do { do { if (0) printf ("%s: failed to send open() on target file at %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 962, GF_LOG_ERROR , "%s: failed to send open() on target file at %s", local-> loc.path, dst_node->name); } while (0) |
962 | local->loc.path, dst_node->name)do { do { if (0) printf ("%s: failed to send open() on target file at %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 962, GF_LOG_ERROR , "%s: failed to send open() on target file at %s", local-> loc.path, dst_node->name); } while (0); |
963 | goto out; |
964 | } |
965 | |
966 | SYNCTASK_SETID (frame->root->uid, frame->root->gid)synctask_setid (synctask_get(), frame->root->uid, frame ->root->gid);; |
967 | ret = fd_ctx_set (local->fd, this, (uint64_t)(long)dst_node); |
968 | if (ret) { |
969 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: failed to set fd-ctx target file at %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 971, GF_LOG_ERROR , "%s: failed to set fd-ctx target file at %s", local->loc .path, dst_node->name); } while (0) |
970 | "%s: failed to set fd-ctx target file at %s",do { do { if (0) printf ("%s: failed to set fd-ctx target file at %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 971, GF_LOG_ERROR , "%s: failed to set fd-ctx target file at %s", local->loc .path, dst_node->name); } while (0) |
971 | local->loc.path, dst_node->name)do { do { if (0) printf ("%s: failed to set fd-ctx target file at %s" , local->loc.path, dst_node->name); } while (0); _gf_log (this->name, "dht-helper.c", __FUNCTION__, 971, GF_LOG_ERROR , "%s: failed to set fd-ctx target file at %s", local->loc .path, dst_node->name); } while (0); |
972 | goto out; |
973 | } |
974 | |
975 | ret = 0; |
976 | out: |
977 | return ret; |
978 | } |
979 | |
980 | int |
981 | dht_rebalance_in_progress_check (xlator_t *this, call_frame_t *frame) |
982 | { |
983 | |
984 | int ret = -1; |
985 | |
986 | ret = synctask_new (this->ctx->env, dht_rebalance_inprogress_task, |
987 | dht_inprogress_check_done, |
988 | frame, frame); |
989 | return ret; |
990 | } |
991 | |
992 | int |
993 | dht_inode_ctx_layout_set (inode_t *inode, xlator_t *this, |
994 | dht_layout_t *layout_int) |
995 | { |
996 | dht_inode_ctx_t *ctx = NULL((void*)0); |
997 | int ret = -1; |
998 | |
999 | ret = dht_inode_ctx_get (inode, this, &ctx); |
1000 | if (!ret && ctx) { |
1001 | ctx->layout = layout_int; |
1002 | } else { |
1003 | ctx = GF_CALLOC (1, sizeof (*ctx), gf_dht_mt_inode_ctx_t)__gf_calloc (1, sizeof (*ctx), gf_dht_mt_inode_ctx_t); |
1004 | if (!ctx) |
1005 | return ret; |
1006 | ctx->layout = layout_int; |
1007 | } |
1008 | |
1009 | ret = dht_inode_ctx_set (inode, this, ctx); |
1010 | |
1011 | return ret; |
1012 | } |
1013 | |
1014 | int |
1015 | dht_inode_ctx_time_update (inode_t *inode, xlator_t *this, struct iatt *stat, |
1016 | int32_t post) |
1017 | { |
1018 | dht_inode_ctx_t *ctx = NULL((void*)0); |
1019 | dht_stat_time_t *time = 0; |
1020 | int ret = -1; |
1021 | |
1022 | GF_VALIDATE_OR_GOTO (this->name, stat, out)do { if (!stat) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "stat"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__, 1022, GF_LOG_ERROR , "invalid argument: " "stat"); } while (0); goto out; } } while (0); |
1023 | GF_VALIDATE_OR_GOTO (this->name, inode, out)do { if (!inode) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "inode"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__, 1023, GF_LOG_ERROR , "invalid argument: " "inode"); } while (0); goto out; } } while (0); |
1024 | |
1025 | ret = dht_inode_ctx_get (inode, this, &ctx); |
1026 | |
1027 | if (ret) { |
1028 | ctx = GF_CALLOC (1, sizeof (*ctx), gf_dht_mt_inode_ctx_t)__gf_calloc (1, sizeof (*ctx), gf_dht_mt_inode_ctx_t); |
1029 | if (!ctx) |
1030 | return -1; |
1031 | } |
1032 | |
1033 | time = &ctx->time; |
1034 | |
1035 | DHT_UPDATE_TIME(time->mtime, time->mtime_nsec,do { int32_t sec = 0; sec = stat->ia_mtime; pthread_spin_lock (&inode->lock); { stat->ia_mtime = ((stat->ia_mtime )>(time->mtime)?(stat->ia_mtime):(time->mtime)); if (sec < stat->ia_mtime) stat->ia_mtime_nsec = time-> mtime_nsec; if (sec == stat->ia_mtime) stat->ia_mtime_nsec = ((stat->ia_mtime_nsec)>(time->mtime_nsec)?(stat-> ia_mtime_nsec):(time->mtime_nsec)); if (post) { time->mtime = stat->ia_mtime; time->mtime_nsec = stat->ia_mtime_nsec ; } } pthread_spin_unlock (&inode->lock); } while (0) |
1036 | stat->ia_mtime, stat->ia_mtime_nsec, inode, post)do { int32_t sec = 0; sec = stat->ia_mtime; pthread_spin_lock (&inode->lock); { stat->ia_mtime = ((stat->ia_mtime )>(time->mtime)?(stat->ia_mtime):(time->mtime)); if (sec < stat->ia_mtime) stat->ia_mtime_nsec = time-> mtime_nsec; if (sec == stat->ia_mtime) stat->ia_mtime_nsec = ((stat->ia_mtime_nsec)>(time->mtime_nsec)?(stat-> ia_mtime_nsec):(time->mtime_nsec)); if (post) { time->mtime = stat->ia_mtime; time->mtime_nsec = stat->ia_mtime_nsec ; } } pthread_spin_unlock (&inode->lock); } while (0); |
1037 | DHT_UPDATE_TIME(time->ctime, time->ctime_nsec,do { int32_t sec = 0; sec = stat->ia_ctime; pthread_spin_lock (&inode->lock); { stat->ia_ctime = ((stat->ia_ctime )>(time->ctime)?(stat->ia_ctime):(time->ctime)); if (sec < stat->ia_ctime) stat->ia_ctime_nsec = time-> ctime_nsec; if (sec == stat->ia_ctime) stat->ia_ctime_nsec = ((stat->ia_ctime_nsec)>(time->ctime_nsec)?(stat-> ia_ctime_nsec):(time->ctime_nsec)); if (post) { time->ctime = stat->ia_ctime; time->ctime_nsec = stat->ia_ctime_nsec ; } } pthread_spin_unlock (&inode->lock); } while (0) |
1038 | stat->ia_ctime, stat->ia_ctime_nsec, inode, post)do { int32_t sec = 0; sec = stat->ia_ctime; pthread_spin_lock (&inode->lock); { stat->ia_ctime = ((stat->ia_ctime )>(time->ctime)?(stat->ia_ctime):(time->ctime)); if (sec < stat->ia_ctime) stat->ia_ctime_nsec = time-> ctime_nsec; if (sec == stat->ia_ctime) stat->ia_ctime_nsec = ((stat->ia_ctime_nsec)>(time->ctime_nsec)?(stat-> ia_ctime_nsec):(time->ctime_nsec)); if (post) { time->ctime = stat->ia_ctime; time->ctime_nsec = stat->ia_ctime_nsec ; } } pthread_spin_unlock (&inode->lock); } while (0); |
1039 | DHT_UPDATE_TIME(time->atime, time->atime_nsec,do { int32_t sec = 0; sec = stat->ia_atime; pthread_spin_lock (&inode->lock); { stat->ia_atime = ((stat->ia_atime )>(time->atime)?(stat->ia_atime):(time->atime)); if (sec < stat->ia_atime) stat->ia_atime_nsec = time-> atime_nsec; if (sec == stat->ia_atime) stat->ia_atime_nsec = ((stat->ia_atime_nsec)>(time->atime_nsec)?(stat-> ia_atime_nsec):(time->atime_nsec)); if (post) { time->atime = stat->ia_atime; time->atime_nsec = stat->ia_atime_nsec ; } } pthread_spin_unlock (&inode->lock); } while (0) |
1040 | stat->ia_atime, stat->ia_atime_nsec, inode, post)do { int32_t sec = 0; sec = stat->ia_atime; pthread_spin_lock (&inode->lock); { stat->ia_atime = ((stat->ia_atime )>(time->atime)?(stat->ia_atime):(time->atime)); if (sec < stat->ia_atime) stat->ia_atime_nsec = time-> atime_nsec; if (sec == stat->ia_atime) stat->ia_atime_nsec = ((stat->ia_atime_nsec)>(time->atime_nsec)?(stat-> ia_atime_nsec):(time->atime_nsec)); if (post) { time->atime = stat->ia_atime; time->atime_nsec = stat->ia_atime_nsec ; } } pthread_spin_unlock (&inode->lock); } while (0); |
1041 | |
1042 | ret = dht_inode_ctx_set (inode, this, ctx); |
1043 | out: |
1044 | return 0; |
1045 | } |
1046 | |
1047 | int |
1048 | dht_inode_ctx_get (inode_t *inode, xlator_t *this, dht_inode_ctx_t **ctx) |
1049 | { |
1050 | int ret = -1; |
1051 | uint64_t ctx_int = 0; |
1052 | |
1053 | GF_VALIDATE_OR_GOTO ("dht", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("dht", "dht-helper.c", __FUNCTION__, 1053, GF_LOG_ERROR, "invalid argument: " "this"); } while (0); goto out; } } while (0); |
1054 | GF_VALIDATE_OR_GOTO (this->name, inode, out)do { if (!inode) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "inode"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__, 1054, GF_LOG_ERROR , "invalid argument: " "inode"); } while (0); goto out; } } while (0); |
1055 | |
1056 | ret = inode_ctx_get (inode, this, &ctx_int)inode_ctx_get2(inode,this,&ctx_int,0); |
1057 | |
1058 | if (ret) |
1059 | return ret; |
1060 | |
1061 | if (ctx) |
1062 | *ctx = (dht_inode_ctx_t *) ctx_int; |
1063 | out: |
1064 | return ret; |
1065 | } |
1066 | |
1067 | int dht_inode_ctx_set (inode_t *inode, xlator_t *this, dht_inode_ctx_t *ctx) |
1068 | { |
1069 | int ret = -1; |
1070 | uint64_t ctx_int = 0; |
1071 | |
1072 | GF_VALIDATE_OR_GOTO ("dht", this, out)do { if (!this) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "this"); } while (0); _gf_log_callingfn ("dht", "dht-helper.c", __FUNCTION__, 1072, GF_LOG_ERROR, "invalid argument: " "this"); } while (0); goto out; } } while (0); |
1073 | GF_VALIDATE_OR_GOTO (this->name, inode, out)do { if (!inode) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "inode"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__, 1073, GF_LOG_ERROR , "invalid argument: " "inode"); } while (0); goto out; } } while (0); |
1074 | GF_VALIDATE_OR_GOTO (this->name, ctx, out)do { if (!ctx) { (*__errno_location ()) = 22; do { do { if (0 ) printf ("invalid argument: " "ctx"); } while (0); _gf_log_callingfn (this->name, "dht-helper.c", __FUNCTION__, 1074, GF_LOG_ERROR , "invalid argument: " "ctx"); } while (0); goto out; } } while (0); |
1075 | |
1076 | ctx_int = (long)ctx; |
1077 | ret = inode_ctx_set (inode, this, &ctx_int)inode_ctx_set2(inode,this,&ctx_int,0); |
1078 | out: |
1079 | return ret; |
1080 | } |