File: | xlators/cluster/afr/src/afr-self-heal-common.c |
Location: | line 1479, column 17 |
Description: | Called function pointer is null (null dereference) |
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 "glusterfs.h" | |||
12 | #include "xlator.h" | |||
13 | #include "byte-order.h" | |||
14 | ||||
15 | #include "afr.h" | |||
16 | #include "afr-transaction.h" | |||
17 | #include "afr-self-heal-common.h" | |||
18 | #include "afr-self-heal.h" | |||
19 | #include "pump.h" | |||
20 | ||||
21 | void | |||
22 | afr_sh_reset (call_frame_t *frame, xlator_t *this) | |||
23 | { | |||
24 | afr_local_t *local = NULL((void*)0); | |||
25 | afr_self_heal_t *sh = NULL((void*)0); | |||
26 | afr_private_t *priv = NULL((void*)0); | |||
27 | ||||
28 | local = frame->local; | |||
29 | sh = &local->self_heal; | |||
30 | priv = this->private; | |||
31 | ||||
32 | memset (sh->child_errno, 0, | |||
33 | sizeof (*sh->child_errno) * priv->child_count); | |||
34 | memset (sh->buf, 0, sizeof (*sh->buf) * priv->child_count); | |||
35 | memset (sh->parentbufs, 0, | |||
36 | sizeof (*sh->parentbufs) * priv->child_count); | |||
37 | memset (sh->success, 0, sizeof (*sh->success) * priv->child_count); | |||
38 | memset (sh->locked_nodes, 0, | |||
39 | sizeof (*sh->locked_nodes) * priv->child_count); | |||
40 | sh->active_sinks = 0; | |||
41 | ||||
42 | afr_reset_xattr (sh->xattr, priv->child_count); | |||
43 | } | |||
44 | ||||
45 | //Intersection[child]=1 if child is part of intersection | |||
46 | void | |||
47 | afr_children_intersection_get (int32_t *set1, int32_t *set2, | |||
48 | int *intersection, unsigned int child_count) | |||
49 | { | |||
50 | int i = 0; | |||
51 | ||||
52 | memset (intersection, 0, sizeof (*intersection) * child_count); | |||
53 | for (i = 0; i < child_count; i++) { | |||
54 | intersection[i] = afr_is_child_present (set1, child_count, i) | |||
55 | && afr_is_child_present (set2, child_count, | |||
56 | i); | |||
57 | } | |||
58 | } | |||
59 | ||||
60 | /** | |||
61 | * select_source - select a source and return it | |||
62 | */ | |||
63 | ||||
64 | int | |||
65 | afr_sh_select_source (int sources[], int child_count) | |||
66 | { | |||
67 | int i = 0; | |||
68 | for (i = 0; i < child_count; i++) | |||
69 | if (sources[i]) | |||
70 | return i; | |||
71 | ||||
72 | return -1; | |||
73 | } | |||
74 | ||||
75 | void | |||
76 | afr_sh_mark_source_sinks (call_frame_t *frame, xlator_t *this) | |||
77 | { | |||
78 | int i = 0; | |||
79 | afr_local_t *local = NULL((void*)0); | |||
80 | afr_self_heal_t *sh = NULL((void*)0); | |||
81 | afr_private_t *priv = NULL((void*)0); | |||
82 | int active_sinks = 0; | |||
83 | ||||
84 | local = frame->local; | |||
85 | sh = &local->self_heal; | |||
86 | priv = this->private; | |||
87 | ||||
88 | for (i = 0; i < priv->child_count; i++) { | |||
89 | if (sh->sources[i] == 0 && local->child_up[i] == 1) { | |||
90 | active_sinks++; | |||
91 | sh->success[i] = 1; | |||
92 | } else if (sh->sources[i] == 1 && local->child_up[i] == 1) { | |||
93 | sh->success[i] = 1; | |||
94 | } | |||
95 | } | |||
96 | sh->active_sinks = active_sinks; | |||
97 | } | |||
98 | ||||
99 | int | |||
100 | afr_sh_source_count (int sources[], int child_count) | |||
101 | { | |||
102 | int i = 0; | |||
103 | int nsource = 0; | |||
104 | ||||
105 | for (i = 0; i < child_count; i++) | |||
106 | if (sources[i]) | |||
107 | nsource++; | |||
108 | return nsource; | |||
109 | } | |||
110 | ||||
111 | void | |||
112 | afr_sh_set_error (afr_self_heal_t *sh, int32_t op_errno) | |||
113 | { | |||
114 | sh->op_ret = -1; | |||
115 | sh->op_errno = afr_most_important_error(sh->op_errno, op_errno, | |||
116 | _gf_false); | |||
117 | } | |||
118 | ||||
119 | void | |||
120 | afr_sh_print_pending_matrix (int32_t *pending_matrix[], xlator_t *this) | |||
121 | { | |||
122 | afr_private_t * priv = this->private; | |||
123 | char *buf = NULL((void*)0); | |||
124 | char *ptr = NULL((void*)0); | |||
125 | int i = 0; | |||
126 | int j = 0; | |||
127 | ||||
128 | /* 10 digits per entry + 1 space + '[' and ']' */ | |||
129 | buf = GF_MALLOC (priv->child_count * 11 + 8, gf_afr_mt_char)__gf_malloc (priv->child_count * 11 + 8, gf_afr_mt_char); | |||
130 | ||||
131 | for (i = 0; i < priv->child_count; i++) { | |||
132 | ptr = buf; | |||
133 | ptr += sprintf (ptr, "[ "); | |||
134 | for (j = 0; j < priv->child_count; j++) { | |||
135 | ptr += sprintf (ptr, "%d ", pending_matrix[i][j]); | |||
136 | } | |||
137 | sprintf (ptr, "]"); | |||
138 | gf_log (this->name, GF_LOG_DEBUG, "pending_matrix: %s", buf)do { do { if (0) printf ("pending_matrix: %s", buf); } while ( 0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 138, GF_LOG_DEBUG, "pending_matrix: %s", buf); } while (0); | |||
139 | } | |||
140 | ||||
141 | GF_FREE (buf)__gf_free (buf); | |||
142 | } | |||
143 | ||||
144 | void | |||
145 | afr_sh_print_split_brain_log (int32_t *pending_matrix[], xlator_t *this, | |||
146 | const char *loc) | |||
147 | { | |||
148 | afr_private_t * priv = this->private; | |||
149 | char *buf = NULL((void*)0); | |||
150 | char *ptr = NULL((void*)0); | |||
151 | int i = 0; | |||
152 | int j = 0; | |||
153 | int child_count = priv->child_count; | |||
154 | char *matrix_begin = "[ [ "; | |||
155 | char *matrix_end = "] ]"; | |||
156 | char *seperator = "] [ "; | |||
157 | int pending_entry_strlen = 12; //Including space after entry | |||
158 | int matrix_begin_strlen = 0; | |||
159 | int matrix_end_strlen = 0; | |||
160 | int seperator_strlen = 0; | |||
161 | int string_length = 0; | |||
162 | char *msg = "- Pending matrix: "; | |||
163 | ||||
164 | /* | |||
165 | * for a list of lists of [ [ a b ] [ c d ] ] | |||
166 | * */ | |||
167 | ||||
168 | matrix_begin_strlen = strlen (matrix_begin); | |||
169 | matrix_end_strlen = strlen (matrix_end); | |||
170 | seperator_strlen = strlen (seperator); | |||
171 | string_length = matrix_begin_strlen + matrix_end_strlen | |||
172 | + (child_count -1) * seperator_strlen | |||
173 | + (child_count * child_count * pending_entry_strlen); | |||
174 | ||||
175 | buf = GF_CALLOC (1, 1 + strlen (msg) + string_length , gf_afr_mt_char)__gf_calloc (1, 1 + strlen (msg) + string_length, gf_afr_mt_char ); | |||
176 | if (!buf) { | |||
177 | buf = ""; | |||
178 | goto out; | |||
179 | } | |||
180 | ||||
181 | ptr = buf; | |||
182 | ptr += sprintf (ptr, "%s", msg); | |||
183 | ptr += sprintf (ptr, "%s", matrix_begin); | |||
184 | for (i = 0; i < priv->child_count; i++) { | |||
185 | for (j = 0; j < priv->child_count; j++) { | |||
186 | ptr += sprintf (ptr, "%d ", pending_matrix[i][j]); | |||
187 | } | |||
188 | if (i < priv->child_count -1) | |||
189 | ptr += sprintf (ptr, "%s", seperator); | |||
190 | } | |||
191 | ||||
192 | ptr += sprintf (ptr, "%s", matrix_end); | |||
193 | ||||
194 | out: | |||
195 | gf_log (this->name, GF_LOG_ERROR, "Unable to self-heal contents of '%s'"do { do { if (0) printf ("Unable to self-heal contents of '%s'" " (possible split-brain). Please delete the file from all but " "the preferred subvolume.%s", loc, buf); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 197, GF_LOG_ERROR, "Unable to self-heal contents of '%s'" " (possible split-brain). Please delete the file from all but " "the preferred subvolume.%s", loc, buf); } while (0) | |||
196 | " (possible split-brain). Please delete the file from all but "do { do { if (0) printf ("Unable to self-heal contents of '%s'" " (possible split-brain). Please delete the file from all but " "the preferred subvolume.%s", loc, buf); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 197, GF_LOG_ERROR, "Unable to self-heal contents of '%s'" " (possible split-brain). Please delete the file from all but " "the preferred subvolume.%s", loc, buf); } while (0) | |||
197 | "the preferred subvolume.%s", loc, buf)do { do { if (0) printf ("Unable to self-heal contents of '%s'" " (possible split-brain). Please delete the file from all but " "the preferred subvolume.%s", loc, buf); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 197, GF_LOG_ERROR, "Unable to self-heal contents of '%s'" " (possible split-brain). Please delete the file from all but " "the preferred subvolume.%s", loc, buf); } while (0); | |||
198 | if (buf) | |||
199 | GF_FREE (buf)__gf_free (buf); | |||
200 | return; | |||
201 | } | |||
202 | ||||
203 | ||||
204 | void | |||
205 | afr_init_pending_matrix (int32_t **pending_matrix, size_t child_count) | |||
206 | { | |||
207 | int i = 0; | |||
208 | int j = 0; | |||
209 | ||||
210 | GF_ASSERT (pending_matrix)do { if (!(pending_matrix)) { do { do { if (0) printf ("Assertion failed: " "pending_matrix"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 210, GF_LOG_ERROR, "Assertion failed: " "pending_matrix" ); } while (0); } } while (0); | |||
211 | ||||
212 | for (i = 0; i < child_count; i++) { | |||
213 | for (j = 0; j < child_count; j++) { | |||
214 | pending_matrix[i][j] = 0; | |||
215 | } | |||
216 | } | |||
217 | } | |||
218 | ||||
219 | void | |||
220 | afr_mark_ignorant_subvols_as_pending (int32_t **pending_matrix, | |||
221 | unsigned char *ignorant_subvols, | |||
222 | size_t child_count) | |||
223 | { | |||
224 | int i = 0; | |||
225 | int j = 0; | |||
226 | ||||
227 | GF_ASSERT (pending_matrix)do { if (!(pending_matrix)) { do { do { if (0) printf ("Assertion failed: " "pending_matrix"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 227, GF_LOG_ERROR, "Assertion failed: " "pending_matrix" ); } while (0); } } while (0); | |||
228 | GF_ASSERT (ignorant_subvols)do { if (!(ignorant_subvols)) { do { do { if (0) printf ("Assertion failed: " "ignorant_subvols"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 228, GF_LOG_ERROR, "Assertion failed: " "ignorant_subvols" ); } while (0); } } while (0); | |||
229 | ||||
230 | for (i = 0; i < child_count; i++) { | |||
231 | if (ignorant_subvols[i]) { | |||
232 | for (j = 0; j < child_count; j++) { | |||
233 | if (!ignorant_subvols[j]) | |||
234 | pending_matrix[j][i] += 1; | |||
235 | } | |||
236 | } | |||
237 | } | |||
238 | } | |||
239 | ||||
240 | int | |||
241 | afr_build_pending_matrix (char **pending_key, int32_t **pending_matrix, | |||
242 | unsigned char *ignorant_subvols, | |||
243 | dict_t *xattr[], afr_transaction_type type, | |||
244 | size_t child_count) | |||
245 | { | |||
246 | /* Indexable by result of afr_index_for_transaction_type(): 0 -- 2. */ | |||
247 | int32_t pending[3] = {0,}; | |||
248 | void *pending_raw = NULL((void*)0); | |||
249 | int ret = -1; | |||
250 | int i = 0; | |||
251 | int j = 0; | |||
252 | int k = 0; | |||
253 | ||||
254 | afr_init_pending_matrix (pending_matrix, child_count); | |||
255 | ||||
256 | for (i = 0; i < child_count; i++) { | |||
257 | pending_raw = NULL((void*)0); | |||
258 | ||||
259 | for (j = 0; j < child_count; j++) { | |||
260 | ret = dict_get_ptr (xattr[i], pending_key[j], | |||
261 | &pending_raw); | |||
262 | ||||
263 | if (ret != 0) { | |||
264 | /* | |||
265 | * There is no xattr present. This means this | |||
266 | * subvolume should be considered an 'ignorant' | |||
267 | * subvolume. | |||
268 | */ | |||
269 | ||||
270 | if (ignorant_subvols) | |||
271 | ignorant_subvols[i] = 1; | |||
272 | continue; | |||
273 | } | |||
274 | ||||
275 | memcpy (pending, pending_raw, sizeof(pending)); | |||
276 | k = afr_index_for_transaction_type (type); | |||
277 | ||||
278 | pending_matrix[i][j] = ntoh32hton32 (pending[k]); | |||
279 | } | |||
280 | } | |||
281 | ||||
282 | return ret; | |||
283 | } | |||
284 | ||||
285 | typedef enum { | |||
286 | AFR_NODE_INVALID, | |||
287 | AFR_NODE_INNOCENT, | |||
288 | AFR_NODE_FOOL, | |||
289 | AFR_NODE_WISE, | |||
290 | } afr_node_type; | |||
291 | ||||
292 | typedef struct { | |||
293 | afr_node_type type; | |||
294 | int wisdom; | |||
295 | } afr_node_character; | |||
296 | ||||
297 | ||||
298 | static int | |||
299 | afr_sh_is_innocent (int32_t *array, int child_count) | |||
300 | { | |||
301 | int i = 0; | |||
302 | int ret = 1; /* innocent until proven guilty */ | |||
303 | ||||
304 | for (i = 0; i < child_count; i++) { | |||
305 | if (array[i]) { | |||
306 | ret = 0; | |||
307 | break; | |||
308 | } | |||
309 | } | |||
310 | ||||
311 | return ret; | |||
312 | } | |||
313 | ||||
314 | ||||
315 | static int | |||
316 | afr_sh_is_fool (int32_t *array, int i, int child_count) | |||
317 | { | |||
318 | return array[i]; /* fool if accuses itself */ | |||
319 | } | |||
320 | ||||
321 | ||||
322 | static int | |||
323 | afr_sh_is_wise (int32_t *array, int i, int child_count) | |||
324 | { | |||
325 | return !array[i]; /* wise if does not accuse itself */ | |||
326 | } | |||
327 | ||||
328 | ||||
329 | static int | |||
330 | afr_sh_all_nodes_innocent (afr_node_character *characters, | |||
331 | int child_count) | |||
332 | { | |||
333 | int i = 0; | |||
334 | int ret = 1; | |||
335 | ||||
336 | for (i = 0; i < child_count; i++) { | |||
337 | if (characters[i].type != AFR_NODE_INNOCENT) { | |||
338 | ret = 0; | |||
339 | break; | |||
340 | } | |||
341 | } | |||
342 | ||||
343 | return ret; | |||
344 | } | |||
345 | ||||
346 | ||||
347 | static int | |||
348 | afr_sh_wise_nodes_exist (afr_node_character *characters, int child_count) | |||
349 | { | |||
350 | int i = 0; | |||
351 | int ret = 0; | |||
352 | ||||
353 | for (i = 0; i < child_count; i++) { | |||
354 | if (characters[i].type == AFR_NODE_WISE) { | |||
355 | ret = 1; | |||
356 | break; | |||
357 | } | |||
358 | } | |||
359 | ||||
360 | return ret; | |||
361 | } | |||
362 | ||||
363 | ||||
364 | /* | |||
365 | * The 'wisdom' of a wise node is 0 if any other wise node accuses it. | |||
366 | * It is 1 if no other wise node accuses it. | |||
367 | * Only wise nodes with wisdom 1 are sources. | |||
368 | * | |||
369 | * If no nodes with wisdom 1 exist, a split-brain has occurred. | |||
370 | */ | |||
371 | ||||
372 | static void | |||
373 | afr_sh_compute_wisdom (int32_t *pending_matrix[], | |||
374 | afr_node_character characters[], int child_count) | |||
375 | { | |||
376 | int i = 0; | |||
377 | int j = 0; | |||
378 | ||||
379 | for (i = 0; i < child_count; i++) { | |||
380 | if (characters[i].type == AFR_NODE_WISE) { | |||
381 | characters[i].wisdom = 1; | |||
382 | ||||
383 | for (j = 0; j < child_count; j++) { | |||
384 | if ((characters[j].type == AFR_NODE_WISE) | |||
385 | && pending_matrix[j][i]) { | |||
386 | ||||
387 | characters[i].wisdom = 0; | |||
388 | } | |||
389 | } | |||
390 | } | |||
391 | } | |||
392 | } | |||
393 | ||||
394 | ||||
395 | static int | |||
396 | afr_sh_wise_nodes_conflict (afr_node_character *characters, | |||
397 | int child_count) | |||
398 | { | |||
399 | int i = 0; | |||
400 | int ret = 1; | |||
401 | ||||
402 | for (i = 0; i < child_count; i++) { | |||
403 | if ((characters[i].type == AFR_NODE_WISE) | |||
404 | && characters[i].wisdom == 1) { | |||
405 | ||||
406 | /* There is atleast one bona-fide wise node */ | |||
407 | ret = 0; | |||
408 | break; | |||
409 | } | |||
410 | } | |||
411 | ||||
412 | return ret; | |||
413 | } | |||
414 | ||||
415 | ||||
416 | static int | |||
417 | afr_sh_mark_wisest_as_sources (int sources[], | |||
418 | afr_node_character *characters, | |||
419 | int child_count) | |||
420 | { | |||
421 | int nsources = 0; | |||
422 | int i = 0; | |||
423 | ||||
424 | for (i = 0; i < child_count; i++) { | |||
425 | if (characters[i].wisdom == 1) { | |||
426 | sources[i] = 1; | |||
427 | nsources++; | |||
428 | } | |||
429 | } | |||
430 | ||||
431 | return nsources; | |||
432 | } | |||
433 | ||||
434 | static void | |||
435 | afr_compute_witness_of_fools (int32_t *witnesses, int32_t **pending_matrix, | |||
436 | afr_node_character *characters, | |||
437 | int32_t child_count) | |||
438 | { | |||
439 | int i = 0; | |||
440 | int j = 0; | |||
441 | int witness = 0; | |||
442 | ||||
443 | GF_ASSERT (witnesses)do { if (!(witnesses)) { do { do { if (0) printf ("Assertion failed: " "witnesses"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 443, GF_LOG_ERROR, "Assertion failed: " "witnesses" ); } while (0); } } while (0); | |||
444 | GF_ASSERT (pending_matrix)do { if (!(pending_matrix)) { do { do { if (0) printf ("Assertion failed: " "pending_matrix"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 444, GF_LOG_ERROR, "Assertion failed: " "pending_matrix" ); } while (0); } } while (0); | |||
445 | GF_ASSERT (characters)do { if (!(characters)) { do { do { if (0) printf ("Assertion failed: " "characters"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 445, GF_LOG_ERROR, "Assertion failed: " "characters" ); } while (0); } } while (0); | |||
446 | GF_ASSERT (child_count > 0)do { if (!(child_count > 0)) { do { do { if (0) printf ("Assertion failed: " "child_count > 0"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 446, GF_LOG_ERROR, "Assertion failed: " "child_count > 0" ); } while (0); } } while (0); | |||
447 | ||||
448 | for (i = 0; i < child_count; i++) { | |||
449 | if (characters[i].type != AFR_NODE_FOOL) | |||
450 | continue; | |||
451 | ||||
452 | witness = 0; | |||
453 | for (j = 0; j < child_count; j++) { | |||
454 | if (i == j) | |||
455 | continue; | |||
456 | witness += pending_matrix[i][j]; | |||
457 | } | |||
458 | witnesses[i] = witness; | |||
459 | } | |||
460 | } | |||
461 | ||||
462 | static int32_t | |||
463 | afr_find_biggest_witness_among_fools (int32_t *witnesses, | |||
464 | afr_node_character *characters, | |||
465 | int32_t child_count) | |||
466 | { | |||
467 | int i = 0; | |||
468 | int biggest_witness = -1; | |||
469 | ||||
470 | GF_ASSERT (witnesses)do { if (!(witnesses)) { do { do { if (0) printf ("Assertion failed: " "witnesses"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 470, GF_LOG_ERROR, "Assertion failed: " "witnesses" ); } while (0); } } while (0); | |||
471 | GF_ASSERT (characters)do { if (!(characters)) { do { do { if (0) printf ("Assertion failed: " "characters"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 471, GF_LOG_ERROR, "Assertion failed: " "characters" ); } while (0); } } while (0); | |||
472 | GF_ASSERT (child_count > 0)do { if (!(child_count > 0)) { do { do { if (0) printf ("Assertion failed: " "child_count > 0"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 472, GF_LOG_ERROR, "Assertion failed: " "child_count > 0" ); } while (0); } } while (0); | |||
473 | ||||
474 | for (i = 0; i < child_count; i++) { | |||
475 | if (characters[i].type != AFR_NODE_FOOL) | |||
476 | continue; | |||
477 | ||||
478 | if (biggest_witness < witnesses[i]) | |||
479 | biggest_witness = witnesses[i]; | |||
480 | } | |||
481 | return biggest_witness; | |||
482 | } | |||
483 | ||||
484 | int | |||
485 | afr_mark_fool_as_source_by_witness (int32_t *sources, int32_t *witnesses, | |||
486 | afr_node_character *characters, | |||
487 | int32_t child_count, int32_t witness) | |||
488 | { | |||
489 | int i = 0; | |||
490 | int nsources = 0; | |||
491 | ||||
492 | GF_ASSERT (sources)do { if (!(sources)) { do { do { if (0) printf ("Assertion failed: " "sources"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 492, GF_LOG_ERROR, "Assertion failed: " "sources" ); } while (0); } } while (0); | |||
493 | GF_ASSERT (witnesses)do { if (!(witnesses)) { do { do { if (0) printf ("Assertion failed: " "witnesses"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 493, GF_LOG_ERROR, "Assertion failed: " "witnesses" ); } while (0); } } while (0); | |||
494 | GF_ASSERT (characters)do { if (!(characters)) { do { do { if (0) printf ("Assertion failed: " "characters"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 494, GF_LOG_ERROR, "Assertion failed: " "characters" ); } while (0); } } while (0); | |||
495 | GF_ASSERT (child_count > 0)do { if (!(child_count > 0)) { do { do { if (0) printf ("Assertion failed: " "child_count > 0"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 495, GF_LOG_ERROR, "Assertion failed: " "child_count > 0" ); } while (0); } } while (0); | |||
496 | ||||
497 | for (i = 0; i < child_count; i++) { | |||
498 | if (characters[i].type != AFR_NODE_FOOL) | |||
499 | continue; | |||
500 | ||||
501 | if (witness == witnesses[i]) { | |||
502 | sources[i] = 1; | |||
503 | nsources++; | |||
504 | } | |||
505 | } | |||
506 | return nsources; | |||
507 | } | |||
508 | ||||
509 | static int | |||
510 | afr_mark_biggest_of_fools_as_source (int32_t *sources, int32_t **pending_matrix, | |||
511 | afr_node_character *characters, | |||
512 | int child_count) | |||
513 | { | |||
514 | int32_t biggest_witness = 0; | |||
515 | int nsources = 0; | |||
516 | int32_t *witnesses = NULL((void*)0); | |||
517 | ||||
518 | GF_ASSERT (child_count > 0)do { if (!(child_count > 0)) { do { do { if (0) printf ("Assertion failed: " "child_count > 0"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 518, GF_LOG_ERROR, "Assertion failed: " "child_count > 0" ); } while (0); } } while (0); | |||
519 | ||||
520 | witnesses = GF_CALLOC (child_count, sizeof (*witnesses),__gf_calloc (child_count, sizeof (*witnesses), gf_afr_mt_int32_t ) | |||
521 | gf_afr_mt_int32_t)__gf_calloc (child_count, sizeof (*witnesses), gf_afr_mt_int32_t ); | |||
522 | if (NULL((void*)0) == witnesses) { | |||
523 | nsources = -1; | |||
524 | goto out; | |||
525 | } | |||
526 | ||||
527 | afr_compute_witness_of_fools (witnesses, pending_matrix, characters, | |||
528 | child_count); | |||
529 | biggest_witness = afr_find_biggest_witness_among_fools (witnesses, | |||
530 | characters, | |||
531 | child_count); | |||
532 | nsources = afr_mark_fool_as_source_by_witness (sources, witnesses, | |||
533 | characters, child_count, | |||
534 | biggest_witness); | |||
535 | out: | |||
536 | GF_FREE (witnesses)__gf_free (witnesses); | |||
537 | return nsources; | |||
538 | } | |||
539 | ||||
540 | int | |||
541 | afr_mark_child_as_source_by_uid (int32_t *sources, struct iatt *bufs, | |||
542 | int32_t *success_children, | |||
543 | unsigned int child_count, uint32_t uid) | |||
544 | { | |||
545 | int i = 0; | |||
546 | int nsources = 0; | |||
547 | int child = 0; | |||
548 | ||||
549 | for (i = 0; i < child_count; i++) { | |||
550 | if (-1 == success_children[i]) | |||
551 | break; | |||
552 | ||||
553 | child = success_children[i]; | |||
554 | if (uid == bufs[child].ia_uid) { | |||
555 | sources[child] = 1; | |||
556 | nsources++; | |||
557 | } | |||
558 | } | |||
559 | return nsources; | |||
560 | } | |||
561 | ||||
562 | int | |||
563 | afr_get_child_with_lowest_uid (struct iatt *bufs, int32_t *success_children, | |||
564 | unsigned int child_count) | |||
565 | { | |||
566 | int i = 0; | |||
567 | int smallest = -1; | |||
568 | int child = 0; | |||
569 | ||||
570 | for (i = 0; i < child_count; i++) { | |||
571 | if (-1 == success_children[i]) | |||
572 | break; | |||
573 | child = success_children[i]; | |||
574 | if ((smallest == -1) || | |||
575 | (bufs[child].ia_uid < bufs[smallest].ia_uid)) { | |||
576 | smallest = child; | |||
577 | } | |||
578 | } | |||
579 | return smallest; | |||
580 | } | |||
581 | ||||
582 | static int | |||
583 | afr_sh_mark_lowest_uid_as_source (struct iatt *bufs, int32_t *success_children, | |||
584 | int child_count, int32_t *sources) | |||
585 | { | |||
586 | int nsources = 0; | |||
587 | int smallest = 0; | |||
588 | ||||
589 | smallest = afr_get_child_with_lowest_uid (bufs, success_children, | |||
590 | child_count); | |||
591 | if (smallest < 0) { | |||
592 | nsources = -1; | |||
593 | goto out; | |||
594 | } | |||
595 | nsources = afr_mark_child_as_source_by_uid (sources, bufs, | |||
596 | success_children, child_count, | |||
597 | bufs[smallest].ia_uid); | |||
598 | out: | |||
599 | return nsources; | |||
600 | } | |||
601 | ||||
602 | int | |||
603 | afr_get_no_xattr_dir_read_child (xlator_t *this, int32_t *success_children, | |||
604 | struct iatt *bufs) | |||
605 | { | |||
606 | afr_private_t *priv = NULL((void*)0); | |||
607 | int i = 0; | |||
608 | int child = -1; | |||
609 | int read_child = -1; | |||
610 | ||||
611 | priv = this->private; | |||
612 | for (i = 0; i < priv->child_count; i++) { | |||
613 | child = success_children[i]; | |||
614 | if (child < 0) | |||
615 | break; | |||
616 | if (read_child < 0) | |||
617 | read_child = child; | |||
618 | else if (bufs[read_child].ia_size < bufs[child].ia_size) | |||
619 | read_child = child; | |||
620 | } | |||
621 | return read_child; | |||
622 | } | |||
623 | ||||
624 | int | |||
625 | afr_sh_mark_zero_size_file_as_sink (struct iatt *bufs, int32_t *success_children, | |||
626 | int child_count, int32_t *sources) | |||
627 | { | |||
628 | int nsources = 0; | |||
629 | int i = 0; | |||
630 | int child = 0; | |||
631 | gf_boolean_t sink_exists = _gf_false; | |||
632 | gf_boolean_t source_exists = _gf_false; | |||
633 | int source = -1; | |||
634 | ||||
635 | for (i = 0; i < child_count; i++) { | |||
636 | child = success_children[i]; | |||
637 | if (child < 0) | |||
638 | break; | |||
639 | if (!bufs[child].ia_size) { | |||
640 | sink_exists = _gf_true; | |||
641 | continue; | |||
642 | } | |||
643 | if (!source_exists) { | |||
644 | source_exists = _gf_true; | |||
645 | source = child; | |||
646 | continue; | |||
647 | } | |||
648 | if (bufs[source].ia_size != bufs[child].ia_size) { | |||
649 | nsources = -1; | |||
650 | goto out; | |||
651 | } | |||
652 | } | |||
653 | if (!source_exists && !sink_exists) { | |||
654 | nsources = -1; | |||
655 | goto out; | |||
656 | } | |||
657 | ||||
658 | if (!source_exists || !sink_exists) | |||
659 | goto out; | |||
660 | ||||
661 | for (i = 0; i < child_count; i++) { | |||
662 | child = success_children[i]; | |||
663 | if (child < 0) | |||
664 | break; | |||
665 | if (bufs[child].ia_size) { | |||
666 | sources[child] = 1; | |||
667 | nsources++; | |||
668 | } | |||
669 | } | |||
670 | out: | |||
671 | return nsources; | |||
672 | } | |||
673 | ||||
674 | char * | |||
675 | afr_get_character_str (afr_node_type type) | |||
676 | { | |||
677 | char *character = NULL((void*)0); | |||
678 | ||||
679 | switch (type) { | |||
680 | case AFR_NODE_INNOCENT: | |||
681 | character = "innocent"; | |||
682 | break; | |||
683 | case AFR_NODE_FOOL: | |||
684 | character = "fool"; | |||
685 | break; | |||
686 | case AFR_NODE_WISE: | |||
687 | character = "wise"; | |||
688 | break; | |||
689 | default: | |||
690 | character = "invalid"; | |||
691 | break; | |||
692 | } | |||
693 | return character; | |||
694 | } | |||
695 | ||||
696 | afr_node_type | |||
697 | afr_find_child_character_type (int32_t *pending_row, int32_t child, | |||
698 | unsigned int child_count) | |||
699 | { | |||
700 | afr_node_type type = AFR_NODE_INVALID; | |||
701 | ||||
702 | GF_ASSERT ((child >= 0) && (child < child_count))do { if (!((child >= 0) && (child < child_count ))) { do { do { if (0) printf ("Assertion failed: " "(child >= 0) && (child < child_count)" ); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 702, GF_LOG_ERROR, "Assertion failed: " "(child >= 0) && (child < child_count)" ); } while (0); } } while (0); | |||
703 | ||||
704 | if (afr_sh_is_innocent (pending_row, child_count)) | |||
705 | type = AFR_NODE_INNOCENT; | |||
706 | else if (afr_sh_is_fool (pending_row, child, child_count)) | |||
707 | type = AFR_NODE_FOOL; | |||
708 | else if (afr_sh_is_wise (pending_row, child, child_count)) | |||
709 | type = AFR_NODE_WISE; | |||
710 | return type; | |||
711 | } | |||
712 | ||||
713 | int | |||
714 | afr_build_sources (xlator_t *this, dict_t **xattr, struct iatt *bufs, | |||
715 | int32_t **pending_matrix, int32_t *sources, | |||
716 | int32_t *success_children, afr_transaction_type type, | |||
717 | int32_t *subvol_status, gf_boolean_t ignore_ignorant) | |||
718 | { | |||
719 | afr_private_t *priv = NULL((void*)0); | |||
720 | afr_self_heal_type sh_type = AFR_SELF_HEAL_INVALID; | |||
721 | int nsources = -1; | |||
722 | unsigned char *ignorant_subvols = NULL((void*)0); | |||
723 | unsigned int child_count = 0; | |||
724 | ||||
725 | priv = this->private; | |||
726 | child_count = priv->child_count; | |||
727 | ||||
728 | if (afr_get_children_count (success_children, priv->child_count) == 0) | |||
729 | goto out; | |||
730 | ||||
731 | if (!ignore_ignorant) { | |||
732 | ignorant_subvols = GF_CALLOC (sizeof (*ignorant_subvols),__gf_calloc (sizeof (*ignorant_subvols), child_count, gf_afr_mt_char ) | |||
733 | child_count, gf_afr_mt_char)__gf_calloc (sizeof (*ignorant_subvols), child_count, gf_afr_mt_char ); | |||
734 | if (NULL((void*)0) == ignorant_subvols) | |||
735 | goto out; | |||
736 | } | |||
737 | ||||
738 | afr_build_pending_matrix (priv->pending_key, pending_matrix, | |||
739 | ignorant_subvols, xattr, type, | |||
740 | priv->child_count); | |||
741 | ||||
742 | if (!ignore_ignorant) | |||
743 | afr_mark_ignorant_subvols_as_pending (pending_matrix, | |||
744 | ignorant_subvols, | |||
745 | priv->child_count); | |||
746 | sh_type = afr_self_heal_type_for_transaction (type); | |||
747 | if (AFR_SELF_HEAL_INVALID == sh_type) | |||
748 | goto out; | |||
749 | ||||
750 | afr_sh_print_pending_matrix (pending_matrix, this); | |||
751 | ||||
752 | nsources = afr_mark_sources (this, sources, pending_matrix, bufs, | |||
753 | sh_type, success_children, subvol_status); | |||
754 | out: | |||
755 | GF_FREE (ignorant_subvols)__gf_free (ignorant_subvols); | |||
756 | return nsources; | |||
757 | } | |||
758 | ||||
759 | void | |||
760 | afr_find_character_types (afr_node_character *characters, | |||
761 | int32_t **pending_matrix, int32_t *success_children, | |||
762 | unsigned int child_count) | |||
763 | { | |||
764 | afr_node_type type = AFR_NODE_INVALID; | |||
765 | int child = 0; | |||
766 | int i = 0; | |||
767 | ||||
768 | for (i = 0; i < child_count; i++) { | |||
769 | child = success_children[i]; | |||
770 | if (child == -1) | |||
771 | break; | |||
772 | type = afr_find_child_character_type (pending_matrix[child], | |||
773 | child, child_count); | |||
774 | characters[child].type = type; | |||
775 | } | |||
776 | } | |||
777 | ||||
778 | void | |||
779 | afr_mark_success_children_sources (int32_t *sources, int32_t *success_children, | |||
780 | unsigned int child_count) | |||
781 | { | |||
782 | int i = 0; | |||
783 | for (i = 0; i < child_count; i++) { | |||
784 | if (success_children[i] == -1) | |||
785 | break; | |||
786 | sources[success_children[i]] = 1; | |||
787 | } | |||
788 | } | |||
789 | /** | |||
790 | * mark_sources: Mark all 'source' nodes and return number of source | |||
791 | * nodes found | |||
792 | * | |||
793 | * A node (a row in the pending matrix) belongs to one of | |||
794 | * three categories: | |||
795 | * | |||
796 | * M is the pending matrix. | |||
797 | * | |||
798 | * 'innocent' - M[i] is all zeroes | |||
799 | * 'fool' - M[i] has i'th element = 1 (self-reference) | |||
800 | * 'wise' - M[i] has i'th element = 0, others are 1 or 0. | |||
801 | * | |||
802 | * All 'innocent' nodes are sinks. If all nodes are innocent, no self-heal is | |||
803 | * needed. | |||
804 | * | |||
805 | * A 'wise' node can be a source. If two 'wise' nodes conflict, it is | |||
806 | * a split-brain. If one wise node refers to the other but the other doesn't | |||
807 | * refer back, the referrer is a source. | |||
808 | * | |||
809 | * All fools are sinks, unless there are no 'wise' nodes. In that case, | |||
810 | * one of the fools is made a source. | |||
811 | */ | |||
812 | ||||
813 | int | |||
814 | afr_mark_sources (xlator_t *this, int32_t *sources, int32_t **pending_matrix, | |||
815 | struct iatt *bufs, afr_self_heal_type type, | |||
816 | int32_t *success_children, int32_t *subvol_status) | |||
817 | { | |||
818 | /* stores the 'characters' (innocent, fool, wise) of the nodes */ | |||
819 | afr_node_character *characters = NULL((void*)0); | |||
820 | int nsources = -1; | |||
821 | unsigned int child_count = 0; | |||
822 | afr_private_t *priv = NULL((void*)0); | |||
823 | ||||
824 | priv = this->private; | |||
825 | child_count = priv->child_count; | |||
826 | characters = GF_CALLOC (sizeof (afr_node_character),__gf_calloc (sizeof (afr_node_character), child_count, gf_afr_mt_afr_node_character ) | |||
827 | child_count, gf_afr_mt_afr_node_character)__gf_calloc (sizeof (afr_node_character), child_count, gf_afr_mt_afr_node_character ); | |||
828 | if (!characters) | |||
829 | goto out; | |||
830 | ||||
831 | this = THIS(*__glusterfs_this_location()); | |||
832 | ||||
833 | /* start clean */ | |||
834 | memset (sources, 0, sizeof (*sources) * child_count); | |||
835 | nsources = 0; | |||
836 | afr_find_character_types (characters, pending_matrix, success_children, | |||
837 | child_count); | |||
838 | if (afr_sh_all_nodes_innocent (characters, child_count)) { | |||
839 | switch (type) { | |||
840 | case AFR_SELF_HEAL_METADATA: | |||
841 | nsources = afr_sh_mark_lowest_uid_as_source (bufs, | |||
842 | success_children, | |||
843 | child_count, | |||
844 | sources); | |||
845 | break; | |||
846 | case AFR_SELF_HEAL_DATA: | |||
847 | nsources = afr_sh_mark_zero_size_file_as_sink (bufs, | |||
848 | success_children, | |||
849 | child_count, | |||
850 | sources); | |||
851 | if ((nsources < 0) && subvol_status) | |||
852 | *subvol_status |= SPLIT_BRAIN; | |||
853 | break; | |||
854 | default: | |||
855 | break; | |||
856 | } | |||
857 | goto out; | |||
858 | } | |||
859 | ||||
860 | if (afr_sh_wise_nodes_exist (characters, child_count)) { | |||
861 | afr_sh_compute_wisdom (pending_matrix, characters, child_count); | |||
862 | ||||
863 | if (afr_sh_wise_nodes_conflict (characters, child_count)) { | |||
864 | if (subvol_status) | |||
865 | *subvol_status |= SPLIT_BRAIN; | |||
866 | nsources = -1; | |||
867 | } else { | |||
868 | nsources = afr_sh_mark_wisest_as_sources (sources, | |||
869 | characters, | |||
870 | child_count); | |||
871 | } | |||
872 | } else { | |||
873 | if (subvol_status) | |||
874 | *subvol_status |= ALL_FOOLS; | |||
875 | nsources = afr_mark_biggest_of_fools_as_source (sources, | |||
876 | pending_matrix, | |||
877 | characters, | |||
878 | child_count); | |||
879 | } | |||
880 | ||||
881 | out: | |||
882 | if (nsources == 0) | |||
883 | afr_mark_success_children_sources (sources, success_children, | |||
884 | child_count); | |||
885 | GF_FREE (characters)__gf_free (characters); | |||
886 | ||||
887 | gf_log (this->name, GF_LOG_DEBUG, "Number of sources: %d", nsources)do { do { if (0) printf ("Number of sources: %d", nsources); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 887, GF_LOG_DEBUG, "Number of sources: %d", nsources ); } while (0); | |||
888 | return nsources; | |||
889 | } | |||
890 | ||||
891 | void | |||
892 | afr_sh_pending_to_delta (afr_private_t *priv, dict_t **xattr, | |||
893 | int32_t *delta_matrix[], unsigned char success[], | |||
894 | int child_count, afr_transaction_type type) | |||
895 | { | |||
896 | int tgt = 0; | |||
897 | int src = 0; | |||
898 | int value = 0; | |||
899 | ||||
900 | afr_build_pending_matrix (priv->pending_key, delta_matrix, NULL((void*)0), | |||
901 | xattr, type, priv->child_count); | |||
902 | ||||
903 | /* | |||
904 | * The algorithm here has two parts. First, for each subvol indexed | |||
905 | * as tgt, we try to figure out what count everyone should have for it. | |||
906 | * If the self-heal succeeded, that's easy; the value is zero. | |||
907 | * Otherwise, the value is the maximum of the succeeding nodes' counts. | |||
908 | * Once we know the value, we loop through (possibly for a second time) | |||
909 | * setting each count to the difference so that when we're done all | |||
910 | * succeeding nodes will have the same count for tgt. | |||
911 | */ | |||
912 | for (tgt = 0; tgt < priv->child_count; ++tgt) { | |||
913 | value = 0; | |||
914 | if (!success[tgt]) { | |||
915 | /* Find the maximum. */ | |||
916 | for (src = 0; src < priv->child_count; ++src) { | |||
917 | if (!success[src]) { | |||
918 | continue; | |||
919 | } | |||
920 | if (delta_matrix[src][tgt] > value) { | |||
921 | value = delta_matrix[src][tgt]; | |||
922 | } | |||
923 | } | |||
924 | } | |||
925 | /* Force everyone who succeeded to the chosen value. */ | |||
926 | for (src = 0; src < priv->child_count; ++src) { | |||
927 | if (success[src]) { | |||
928 | delta_matrix[src][tgt] = value | |||
929 | - delta_matrix[src][tgt]; | |||
930 | } | |||
931 | else { | |||
932 | delta_matrix[src][tgt] = 0; | |||
933 | } | |||
934 | } | |||
935 | } | |||
936 | } | |||
937 | ||||
938 | ||||
939 | int | |||
940 | afr_sh_delta_to_xattr (xlator_t *this, | |||
941 | int32_t *delta_matrix[], dict_t *xattr[], | |||
942 | int child_count, afr_transaction_type type) | |||
943 | { | |||
944 | int i = 0; | |||
945 | int j = 0; | |||
946 | int k = 0; | |||
947 | int ret = 0; | |||
948 | int32_t *pending = NULL((void*)0); | |||
949 | int32_t *local_pending = NULL((void*)0); | |||
950 | afr_private_t *priv = NULL((void*)0); | |||
951 | ||||
952 | priv = this->private; | |||
953 | for (i = 0; i < child_count; i++) { | |||
954 | if (!xattr[i]) | |||
955 | continue; | |||
956 | ||||
957 | local_pending = NULL((void*)0); | |||
958 | for (j = 0; j < child_count; j++) { | |||
959 | pending = GF_CALLOC (sizeof (int32_t), 3,__gf_calloc (sizeof (int32_t), 3, gf_afr_mt_int32_t) | |||
960 | gf_afr_mt_int32_t)__gf_calloc (sizeof (int32_t), 3, gf_afr_mt_int32_t); | |||
961 | ||||
962 | if (!pending) { | |||
963 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to allocate pending entry " "for %s[%d] on %s" , priv->pending_key[j], type, priv->children[i]->name ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 967, GF_LOG_ERROR, "failed to allocate pending entry " "for %s[%d] on %s", priv->pending_key[j], type, priv-> children[i]->name); } while (0) | |||
964 | "failed to allocate pending entry "do { do { if (0) printf ("failed to allocate pending entry " "for %s[%d] on %s" , priv->pending_key[j], type, priv->children[i]->name ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 967, GF_LOG_ERROR, "failed to allocate pending entry " "for %s[%d] on %s", priv->pending_key[j], type, priv-> children[i]->name); } while (0) | |||
965 | "for %s[%d] on %s",do { do { if (0) printf ("failed to allocate pending entry " "for %s[%d] on %s" , priv->pending_key[j], type, priv->children[i]->name ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 967, GF_LOG_ERROR, "failed to allocate pending entry " "for %s[%d] on %s", priv->pending_key[j], type, priv-> children[i]->name); } while (0) | |||
966 | priv->pending_key[j], type,do { do { if (0) printf ("failed to allocate pending entry " "for %s[%d] on %s" , priv->pending_key[j], type, priv->children[i]->name ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 967, GF_LOG_ERROR, "failed to allocate pending entry " "for %s[%d] on %s", priv->pending_key[j], type, priv-> children[i]->name); } while (0) | |||
967 | priv->children[i]->name)do { do { if (0) printf ("failed to allocate pending entry " "for %s[%d] on %s" , priv->pending_key[j], type, priv->children[i]->name ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 967, GF_LOG_ERROR, "failed to allocate pending entry " "for %s[%d] on %s", priv->pending_key[j], type, priv-> children[i]->name); } while (0); | |||
968 | continue; | |||
969 | } | |||
970 | /* 3 = data+metadata+entry */ | |||
971 | ||||
972 | k = afr_index_for_transaction_type (type); | |||
973 | ||||
974 | pending[k] = hton32 (delta_matrix[i][j]); | |||
975 | ||||
976 | if (j == i) { | |||
977 | local_pending = pending; | |||
978 | continue; | |||
979 | } | |||
980 | ret = dict_set_bin (xattr[i], priv->pending_key[j], | |||
981 | pending, | |||
982 | AFR_NUM_CHANGE_LOGS3 * sizeof (int32_t)); | |||
983 | if (ret < 0) { | |||
984 | gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("Unable to set dict value."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 985, GF_LOG_WARNING, "Unable to set dict value."); } while ( 0) | |||
985 | "Unable to set dict value.")do { do { if (0) printf ("Unable to set dict value."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 985, GF_LOG_WARNING, "Unable to set dict value."); } while ( 0); | |||
986 | GF_FREE (pending)__gf_free (pending); | |||
987 | } | |||
988 | } | |||
989 | if (local_pending) { | |||
990 | ret = dict_set_bin (xattr[i], priv->pending_key[i], | |||
991 | local_pending, | |||
992 | AFR_NUM_CHANGE_LOGS3 * sizeof (int32_t)); | |||
993 | if (ret < 0) { | |||
994 | gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("Unable to set dict value."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 995, GF_LOG_WARNING, "Unable to set dict value."); } while ( 0) | |||
995 | "Unable to set dict value.")do { do { if (0) printf ("Unable to set dict value."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 995, GF_LOG_WARNING, "Unable to set dict value."); } while ( 0); | |||
996 | GF_FREE (local_pending)__gf_free (local_pending); | |||
997 | } | |||
998 | } | |||
999 | } | |||
1000 | return 0; | |||
1001 | } | |||
1002 | ||||
1003 | ||||
1004 | int | |||
1005 | afr_sh_missing_entries_done (call_frame_t *frame, xlator_t *this) | |||
1006 | { | |||
1007 | afr_local_t *local = NULL((void*)0); | |||
1008 | afr_self_heal_t *sh = NULL((void*)0); | |||
1009 | ||||
1010 | local = frame->local; | |||
1011 | sh = &local->self_heal; | |||
1012 | ||||
1013 | afr_sh_reset (frame, this); | |||
1014 | ||||
1015 | if (local->govinda_gOvinda) { | |||
1016 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("split brain found, aborting selfheal of %s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1018, GF_LOG_DEBUG, "split brain found, aborting selfheal of %s" , local->loc.path); } while (0) | |||
1017 | "split brain found, aborting selfheal of %s",do { do { if (0) printf ("split brain found, aborting selfheal of %s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1018, GF_LOG_DEBUG, "split brain found, aborting selfheal of %s" , local->loc.path); } while (0) | |||
1018 | local->loc.path)do { do { if (0) printf ("split brain found, aborting selfheal of %s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1018, GF_LOG_DEBUG, "split brain found, aborting selfheal of %s" , local->loc.path); } while (0); | |||
1019 | sh->op_failed = 1; | |||
1020 | } | |||
1021 | ||||
1022 | if (sh->op_failed) { | |||
1023 | sh->completion_cbk (frame, this); | |||
1024 | } else { | |||
1025 | gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("proceeding to metadata check on %s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1027, GF_LOG_TRACE, "proceeding to metadata check on %s" , local->loc.path); } while (0) | |||
1026 | "proceeding to metadata check on %s",do { do { if (0) printf ("proceeding to metadata check on %s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1027, GF_LOG_TRACE, "proceeding to metadata check on %s" , local->loc.path); } while (0) | |||
1027 | local->loc.path)do { do { if (0) printf ("proceeding to metadata check on %s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1027, GF_LOG_TRACE, "proceeding to metadata check on %s" , local->loc.path); } while (0); | |||
1028 | afr_self_heal_metadata (frame, this); | |||
1029 | } | |||
1030 | ||||
1031 | return 0; | |||
1032 | } | |||
1033 | ||||
1034 | ||||
1035 | static int | |||
1036 | afr_sh_missing_entries_finish (call_frame_t *frame, xlator_t *this) | |||
1037 | { | |||
1038 | afr_internal_lock_t *int_lock = NULL((void*)0); | |||
1039 | afr_local_t *local = NULL((void*)0); | |||
1040 | ||||
1041 | local = frame->local; | |||
1042 | int_lock = &local->internal_lock; | |||
1043 | ||||
1044 | int_lock->lock_cbk = afr_sh_missing_entries_done; | |||
1045 | afr_unlock (frame, this); | |||
1046 | ||||
1047 | return 0; | |||
1048 | } | |||
1049 | ||||
1050 | int | |||
1051 | afr_sh_common_create (afr_self_heal_t *sh, unsigned int child_count) | |||
1052 | { | |||
1053 | int ret = -ENOMEM12; | |||
1054 | sh->buf = GF_CALLOC (child_count, sizeof (*sh->buf),__gf_calloc (child_count, sizeof (*sh->buf), gf_afr_mt_iatt ) | |||
1055 | gf_afr_mt_iatt)__gf_calloc (child_count, sizeof (*sh->buf), gf_afr_mt_iatt ); | |||
1056 | if (!sh->buf) | |||
1057 | goto out; | |||
1058 | sh->parentbufs = GF_CALLOC (child_count, sizeof (*sh->parentbufs),__gf_calloc (child_count, sizeof (*sh->parentbufs), gf_afr_mt_iatt ) | |||
1059 | gf_afr_mt_iatt)__gf_calloc (child_count, sizeof (*sh->parentbufs), gf_afr_mt_iatt ); | |||
1060 | if (!sh->parentbufs) | |||
1061 | goto out; | |||
1062 | sh->child_errno = GF_CALLOC (child_count, sizeof (*sh->child_errno),__gf_calloc (child_count, sizeof (*sh->child_errno), gf_afr_mt_int ) | |||
1063 | gf_afr_mt_int)__gf_calloc (child_count, sizeof (*sh->child_errno), gf_afr_mt_int ); | |||
1064 | if (!sh->child_errno) | |||
1065 | goto out; | |||
1066 | sh->success_children = afr_children_create (child_count); | |||
1067 | if (!sh->success_children) | |||
1068 | goto out; | |||
1069 | sh->fresh_children = afr_children_create (child_count); | |||
1070 | if (!sh->fresh_children) | |||
1071 | goto out; | |||
1072 | sh->xattr = GF_CALLOC (child_count, sizeof (*sh->xattr),__gf_calloc (child_count, sizeof (*sh->xattr), gf_afr_mt_dict_t ) | |||
1073 | gf_afr_mt_dict_t)__gf_calloc (child_count, sizeof (*sh->xattr), gf_afr_mt_dict_t ); | |||
1074 | if (!sh->xattr) | |||
1075 | goto out; | |||
1076 | ret = 0; | |||
1077 | out: | |||
1078 | return ret; | |||
1079 | } | |||
1080 | ||||
1081 | void | |||
1082 | afr_sh_common_lookup_resp_handler (call_frame_t *frame, void *cookie, | |||
1083 | xlator_t *this, | |||
1084 | int32_t op_ret, int32_t op_errno, | |||
1085 | inode_t *inode, struct iatt *buf, | |||
1086 | dict_t *xattr, struct iatt *postparent, | |||
1087 | loc_t *loc) | |||
1088 | { | |||
1089 | int child_index = 0; | |||
1090 | afr_local_t *local = NULL((void*)0); | |||
1091 | afr_private_t *priv = NULL((void*)0); | |||
1092 | afr_self_heal_t *sh = NULL((void*)0); | |||
1093 | ||||
1094 | local = frame->local; | |||
1095 | priv = this->private; | |||
1096 | sh = &local->self_heal; | |||
1097 | child_index = (long) cookie; | |||
1098 | ||||
1099 | LOCK (&frame->lock)pthread_spin_lock (&frame->lock); | |||
1100 | { | |||
1101 | if (op_ret == 0) { | |||
1102 | sh->buf[child_index] = *buf; | |||
1103 | sh->parentbufs[child_index] = *postparent; | |||
1104 | sh->success_children[sh->success_count] = child_index; | |||
1105 | sh->success_count++; | |||
1106 | sh->xattr[child_index] = dict_ref (xattr); | |||
1107 | } else { | |||
1108 | gf_log (this->name, GF_LOG_DEBUG, "path %s on subvolume"do { do { if (0) printf ("path %s on subvolume" " %s => -1 (%s)" , loc->path, priv->children[child_index]->name, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1111, GF_LOG_DEBUG, "path %s on subvolume" " %s => -1 (%s)" , loc->path, priv->children[child_index]->name, strerror (op_errno)); } while (0) | |||
1109 | " %s => -1 (%s)", loc->path,do { do { if (0) printf ("path %s on subvolume" " %s => -1 (%s)" , loc->path, priv->children[child_index]->name, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1111, GF_LOG_DEBUG, "path %s on subvolume" " %s => -1 (%s)" , loc->path, priv->children[child_index]->name, strerror (op_errno)); } while (0) | |||
1110 | priv->children[child_index]->name,do { do { if (0) printf ("path %s on subvolume" " %s => -1 (%s)" , loc->path, priv->children[child_index]->name, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1111, GF_LOG_DEBUG, "path %s on subvolume" " %s => -1 (%s)" , loc->path, priv->children[child_index]->name, strerror (op_errno)); } while (0) | |||
1111 | strerror (op_errno))do { do { if (0) printf ("path %s on subvolume" " %s => -1 (%s)" , loc->path, priv->children[child_index]->name, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1111, GF_LOG_DEBUG, "path %s on subvolume" " %s => -1 (%s)" , loc->path, priv->children[child_index]->name, strerror (op_errno)); } while (0); | |||
1112 | local->self_heal.child_errno[child_index] = op_errno; | |||
1113 | } | |||
1114 | } | |||
1115 | UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock); | |||
1116 | return; | |||
1117 | } | |||
1118 | ||||
1119 | gf_boolean_t | |||
1120 | afr_valid_ia_type (ia_type_t ia_type) | |||
1121 | { | |||
1122 | switch (ia_type) { | |||
1123 | case IA_IFSOCK: | |||
1124 | case IA_IFREG: | |||
1125 | case IA_IFBLK: | |||
1126 | case IA_IFCHR: | |||
1127 | case IA_IFIFO: | |||
1128 | case IA_IFLNK: | |||
1129 | case IA_IFDIR: | |||
1130 | return _gf_true; | |||
1131 | default: | |||
1132 | return _gf_false; | |||
1133 | } | |||
1134 | return _gf_false; | |||
1135 | } | |||
1136 | ||||
1137 | int | |||
1138 | afr_impunge_frame_create (call_frame_t *frame, xlator_t *this, | |||
1139 | int active_source, call_frame_t **impunge_frame) | |||
1140 | { | |||
1141 | afr_local_t *local = NULL((void*)0); | |||
1142 | afr_local_t *impunge_local = NULL((void*)0); | |||
1143 | afr_self_heal_t *impunge_sh = NULL((void*)0); | |||
1144 | int32_t op_errno = 0; | |||
1145 | afr_private_t *priv = NULL((void*)0); | |||
1146 | int ret = 0; | |||
1147 | call_frame_t *new_frame = NULL((void*)0); | |||
1148 | ||||
1149 | op_errno = ENOMEM12; | |||
1150 | priv = this->private; | |||
1151 | new_frame = copy_frame (frame); | |||
1152 | if (!new_frame) { | |||
1153 | goto out; | |||
1154 | } | |||
1155 | ||||
1156 | AFR_LOCAL_ALLOC_OR_GOTO (impunge_local, out)do { impunge_local = mem_get0 ((*__glusterfs_this_location()) ->local_pool); if (!impunge_local) { do { do { if (0) printf ("out of memory :("); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1156, GF_LOG_ERROR, "out of memory :("); } while (0); op_errno = 12; goto out; } } while (0);; | |||
1157 | ||||
1158 | local = frame->local; | |||
1159 | new_frame->local = impunge_local; | |||
1160 | impunge_sh = &impunge_local->self_heal; | |||
1161 | impunge_sh->sh_frame = frame; | |||
1162 | impunge_sh->active_source = active_source; | |||
1163 | impunge_local->child_up = memdup (local->child_up, | |||
1164 | sizeof (*local->child_up) * | |||
1165 | priv->child_count); | |||
1166 | if (!impunge_local->child_up) | |||
1167 | goto out; | |||
1168 | ||||
1169 | impunge_local->pending = afr_matrix_create (priv->child_count, | |||
1170 | AFR_NUM_CHANGE_LOGS3); | |||
1171 | if (!impunge_local->pending) | |||
1172 | goto out; | |||
1173 | ||||
1174 | ret = afr_sh_common_create (impunge_sh, priv->child_count); | |||
1175 | if (ret) { | |||
1176 | op_errno = -ret; | |||
1177 | goto out; | |||
1178 | } | |||
1179 | op_errno = 0; | |||
1180 | *impunge_frame = new_frame; | |||
1181 | out: | |||
1182 | if (op_errno && new_frame) | |||
1183 | AFR_STACK_DESTROY (new_frame)do { afr_local_t *__local = ((void*)0); xlator_t *__this = (( void*)0); __local = new_frame->local; __this = new_frame-> this; new_frame->local = ((void*)0); STACK_DESTROY (new_frame ->root); if (__local) { afr_local_cleanup (__local, __this ); mem_put (__local); } } while (0);; | |||
1184 | return -op_errno; | |||
1185 | } | |||
1186 | ||||
1187 | void | |||
1188 | afr_sh_missing_entry_call_impunge_recreate (call_frame_t *frame, xlator_t *this, | |||
1189 | struct iatt *buf, | |||
1190 | struct iatt *postparent, | |||
1191 | afr_impunge_done_cbk_t impunge_done) | |||
1192 | { | |||
1193 | call_frame_t *impunge_frame = NULL((void*)0); | |||
1194 | afr_local_t *local = NULL((void*)0); | |||
1195 | afr_local_t *impunge_local = NULL((void*)0); | |||
1196 | afr_self_heal_t *sh = NULL((void*)0); | |||
1197 | afr_self_heal_t *impunge_sh = NULL((void*)0); | |||
1198 | int ret = 0; | |||
1199 | unsigned int enoent_count = 0; | |||
1200 | afr_private_t *priv = NULL((void*)0); | |||
1201 | int i = 0; | |||
1202 | int32_t op_errno = 0; | |||
1203 | ||||
1204 | local = frame->local; | |||
1205 | sh = &local->self_heal; | |||
1206 | priv = this->private; | |||
1207 | ||||
1208 | enoent_count = afr_errno_count (NULL((void*)0), sh->child_errno, | |||
1209 | priv->child_count, ENOENT2); | |||
1210 | if (!enoent_count) { | |||
1211 | gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("no missing files - %s. proceeding to metadata check" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1213, GF_LOG_INFO, "no missing files - %s. proceeding to metadata check" , local->loc.path); } while (0) | |||
1212 | "no missing files - %s. proceeding to metadata check",do { do { if (0) printf ("no missing files - %s. proceeding to metadata check" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1213, GF_LOG_INFO, "no missing files - %s. proceeding to metadata check" , local->loc.path); } while (0) | |||
1213 | local->loc.path)do { do { if (0) printf ("no missing files - %s. proceeding to metadata check" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1213, GF_LOG_INFO, "no missing files - %s. proceeding to metadata check" , local->loc.path); } while (0); | |||
1214 | goto out; | |||
1215 | } | |||
1216 | sh->impunge_done = impunge_done; | |||
1217 | ret = afr_impunge_frame_create (frame, this, sh->source, &impunge_frame); | |||
1218 | if (ret) | |||
1219 | goto out; | |||
1220 | impunge_local = impunge_frame->local; | |||
1221 | impunge_sh = &impunge_local->self_heal; | |||
1222 | loc_copy (&impunge_local->loc, &local->loc); | |||
1223 | ret = afr_build_parent_loc (&impunge_sh->parent_loc, | |||
1224 | &impunge_local->loc, &op_errno); | |||
1225 | if (ret) { | |||
1226 | ret = -op_errno; | |||
1227 | goto out; | |||
1228 | } | |||
1229 | impunge_local->call_count = enoent_count; | |||
1230 | impunge_sh->entrybuf = sh->buf[sh->source]; | |||
1231 | impunge_sh->parentbuf = sh->parentbufs[sh->source]; | |||
1232 | for (i = 0; i < priv->child_count; i++) { | |||
1233 | if (!impunge_local->child_up[i]) { | |||
1234 | impunge_sh->child_errno[i] = ENOTCONN107; | |||
1235 | continue; | |||
1236 | } | |||
1237 | if (sh->child_errno[i] != ENOENT2) { | |||
1238 | impunge_sh->child_errno[i] = EEXIST17; | |||
1239 | continue; | |||
1240 | } | |||
1241 | } | |||
1242 | for (i = 0; i < priv->child_count; i++) { | |||
1243 | if (sh->child_errno[i] != ENOENT2) | |||
1244 | continue; | |||
1245 | afr_sh_entry_impunge_create (impunge_frame, this, i); | |||
1246 | enoent_count--; | |||
1247 | } | |||
1248 | GF_ASSERT (!enoent_count)do { if (!(!enoent_count)) { do { do { if (0) printf ("Assertion failed: " "!enoent_count"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 1248, GF_LOG_ERROR, "Assertion failed: " "!enoent_count" ); } while (0); } } while (0); | |||
1249 | return; | |||
1250 | out: | |||
1251 | if (ret) { | |||
1252 | gf_log (this->name, GF_LOG_ERROR, "impunge of %s failed, "do { do { if (0) printf ("impunge of %s failed, " "reason: %s" , local->loc.path, strerror (-ret)); } while (0); _gf_log ( this->name, "afr-self-heal-common.c", __FUNCTION__, 1253, GF_LOG_ERROR , "impunge of %s failed, " "reason: %s", local->loc.path, strerror (-ret)); } while (0) | |||
1253 | "reason: %s", local->loc.path, strerror (-ret))do { do { if (0) printf ("impunge of %s failed, " "reason: %s" , local->loc.path, strerror (-ret)); } while (0); _gf_log ( this->name, "afr-self-heal-common.c", __FUNCTION__, 1253, GF_LOG_ERROR , "impunge of %s failed, " "reason: %s", local->loc.path, strerror (-ret)); } while (0); | |||
1254 | sh->op_failed = 1; | |||
1255 | } | |||
1256 | afr_sh_missing_entries_finish (frame, this); | |||
1257 | } | |||
1258 | ||||
1259 | int | |||
1260 | afr_sh_create_entry_cbk (call_frame_t *frame, xlator_t *this, | |||
1261 | int32_t op_ret, int32_t op_errno) | |||
1262 | { | |||
1263 | afr_local_t *local = NULL((void*)0); | |||
1264 | afr_self_heal_t *sh = NULL((void*)0); | |||
1265 | ||||
1266 | local = frame->local; | |||
1267 | sh = &local->self_heal; | |||
1268 | if (op_ret < 0) | |||
1269 | sh->op_failed = 1; | |||
1270 | afr_sh_missing_entries_finish (frame, this); | |||
1271 | return 0; | |||
1272 | } | |||
1273 | ||||
1274 | static int | |||
1275 | sh_missing_entries_create (call_frame_t *frame, xlator_t *this) | |||
1276 | { | |||
1277 | afr_local_t *local = NULL((void*)0); | |||
1278 | afr_self_heal_t *sh = NULL((void*)0); | |||
1279 | int type = 0; | |||
1280 | struct iatt *buf = NULL((void*)0); | |||
1281 | struct iatt *postparent = NULL((void*)0); | |||
1282 | ||||
1283 | local = frame->local; | |||
1284 | sh = &local->self_heal; | |||
1285 | ||||
1286 | buf = &sh->buf[sh->source]; | |||
1287 | postparent = &sh->parentbufs[sh->source]; | |||
1288 | ||||
1289 | type = buf->ia_type; | |||
1290 | if (!afr_valid_ia_type (type)) { | |||
1291 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: unknown file type: 0%o", local-> loc.path, type); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1292, GF_LOG_ERROR, "%s: unknown file type: 0%o" , local->loc.path, type); } while (0) | |||
1292 | "%s: unknown file type: 0%o", local->loc.path, type)do { do { if (0) printf ("%s: unknown file type: 0%o", local-> loc.path, type); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1292, GF_LOG_ERROR, "%s: unknown file type: 0%o" , local->loc.path, type); } while (0); | |||
1293 | local->govinda_gOvinda = 1; | |||
1294 | afr_sh_missing_entries_finish (frame, this); | |||
1295 | goto out; | |||
1296 | } | |||
1297 | ||||
1298 | afr_sh_missing_entry_call_impunge_recreate (frame, this, | |||
1299 | buf, postparent, | |||
1300 | afr_sh_create_entry_cbk); | |||
1301 | out: | |||
1302 | return 0; | |||
1303 | } | |||
1304 | ||||
1305 | void | |||
1306 | afr_sh_missing_entries_lookup_done (call_frame_t *frame, xlator_t *this, | |||
1307 | int32_t op_ret, int32_t op_errno) | |||
1308 | { | |||
1309 | afr_local_t *local = NULL((void*)0); | |||
1310 | afr_self_heal_t *sh = NULL((void*)0); | |||
1311 | afr_private_t *priv = NULL((void*)0); | |||
1312 | ia_type_t ia_type = IA_INVAL; | |||
1313 | int32_t nsources = 0; | |||
1314 | loc_t *loc = NULL((void*)0); | |||
1315 | int32_t subvol_status = 0; | |||
1316 | afr_transaction_type txn_type = AFR_DATA_TRANSACTION; | |||
1317 | gf_boolean_t split_brain = _gf_false; | |||
1318 | int read_child = -1; | |||
1319 | ||||
1320 | local = frame->local; | |||
1321 | sh = &local->self_heal; | |||
1322 | priv = this->private; | |||
1323 | loc = &local->loc; | |||
1324 | ||||
1325 | if (op_ret < 0) { | |||
1326 | if (op_errno == EIO5) | |||
1327 | local->govinda_gOvinda = 1; | |||
1328 | // EIO can happen if finding the fresh parent dir failed | |||
1329 | goto out; | |||
1330 | } | |||
1331 | ||||
1332 | //now No chance for the ia_type to conflict | |||
1333 | ia_type = sh->buf[sh->success_children[0]].ia_type; | |||
1334 | txn_type = afr_transaction_type_get (ia_type); | |||
1335 | nsources = afr_build_sources (this, sh->xattr, sh->buf, | |||
1336 | sh->pending_matrix, sh->sources, | |||
1337 | sh->success_children, txn_type, | |||
1338 | &subvol_status, _gf_false); | |||
1339 | if (nsources < 0) { | |||
1340 | gf_log (this->name, GF_LOG_INFO, "No sources for dir of %s,"do { do { if (0) printf ("No sources for dir of %s," " in missing entry self-heal, continuing with the rest" " of the self-heals", local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1342 , GF_LOG_INFO, "No sources for dir of %s," " in missing entry self-heal, continuing with the rest" " of the self-heals", local->loc.path); } while (0) | |||
1341 | " in missing entry self-heal, continuing with the rest"do { do { if (0) printf ("No sources for dir of %s," " in missing entry self-heal, continuing with the rest" " of the self-heals", local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1342 , GF_LOG_INFO, "No sources for dir of %s," " in missing entry self-heal, continuing with the rest" " of the self-heals", local->loc.path); } while (0) | |||
1342 | " of the self-heals", local->loc.path)do { do { if (0) printf ("No sources for dir of %s," " in missing entry self-heal, continuing with the rest" " of the self-heals", local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1342 , GF_LOG_INFO, "No sources for dir of %s," " in missing entry self-heal, continuing with the rest" " of the self-heals", local->loc.path); } while (0); | |||
1343 | if (subvol_status & SPLIT_BRAIN) { | |||
1344 | split_brain = _gf_true; | |||
1345 | switch (txn_type) { | |||
1346 | case AFR_DATA_TRANSACTION: | |||
1347 | nsources = 1; | |||
1348 | sh->sources[sh->success_children[0]] = 1; | |||
1349 | break; | |||
1350 | case AFR_ENTRY_TRANSACTION: | |||
1351 | read_child = afr_get_no_xattr_dir_read_child | |||
1352 | (this, | |||
1353 | sh->success_children, | |||
1354 | sh->buf); | |||
1355 | sh->sources[read_child] = 1; | |||
1356 | nsources = 1; | |||
1357 | break; | |||
1358 | default: | |||
1359 | op_errno = EIO5; | |||
1360 | goto out; | |||
1361 | } | |||
1362 | } else { | |||
1363 | op_errno = EIO5; | |||
1364 | goto out; | |||
1365 | } | |||
1366 | } | |||
1367 | ||||
1368 | afr_get_fresh_children (sh->success_children, sh->sources, | |||
1369 | sh->fresh_children, priv->child_count); | |||
1370 | sh->source = sh->fresh_children[0]; | |||
1371 | if (sh->source == -1) { | |||
1372 | gf_log (this->name, GF_LOG_DEBUG, "No active sources found.")do { do { if (0) printf ("No active sources found."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1372, GF_LOG_DEBUG, "No active sources found."); } while (0 ); | |||
1373 | op_errno = EIO5; | |||
1374 | goto out; | |||
1375 | } | |||
1376 | ||||
1377 | if (sh->gfid_sh_success_cbk) | |||
1378 | sh->gfid_sh_success_cbk (frame, this); | |||
1379 | sh->type = sh->buf[sh->source].ia_type; | |||
1380 | if (uuid_is_null (loc->inode->gfid)) | |||
1381 | uuid_copy (loc->gfid, sh->buf[sh->source].ia_gfid); | |||
1382 | if (split_brain) { | |||
1383 | afr_sh_missing_entries_finish (frame, this); | |||
1384 | } else { | |||
1385 | sh_missing_entries_create (frame, this); | |||
1386 | } | |||
1387 | return; | |||
1388 | out: | |||
1389 | sh->op_failed = 1; | |||
1390 | afr_sh_set_error (sh, op_errno); | |||
1391 | afr_sh_missing_entries_finish (frame, this); | |||
1392 | return; | |||
1393 | } | |||
1394 | ||||
1395 | static int | |||
1396 | afr_sh_common_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, | |||
1397 | int32_t op_ret, int32_t op_errno, inode_t *inode, | |||
1398 | struct iatt *buf, dict_t *xattr, | |||
1399 | struct iatt *postparent) | |||
1400 | { | |||
1401 | int call_count = 0; | |||
1402 | afr_local_t *local = NULL((void*)0); | |||
1403 | afr_self_heal_t *sh = NULL((void*)0); | |||
1404 | afr_private_t *priv = NULL((void*)0); | |||
1405 | ||||
1406 | local = frame->local; | |||
1407 | sh = &local->self_heal; | |||
1408 | priv = this->private; | |||
1409 | ||||
1410 | afr_sh_common_lookup_resp_handler (frame, cookie, this, op_ret, | |||
1411 | op_errno, inode, buf, xattr, | |||
1412 | postparent, &sh->lookup_loc); | |||
1413 | call_count = afr_frame_return (frame); | |||
1414 | ||||
1415 | if (call_count) | |||
1416 | goto out; | |||
1417 | op_ret = -1; | |||
1418 | if (!sh->success_count) { | |||
1419 | op_errno = afr_resultant_errno_get (NULL((void*)0), sh->child_errno, | |||
1420 | priv->child_count); | |||
1421 | gf_log (this->name, GF_LOG_ERROR, "Failed to lookup %s, "do { do { if (0) printf ("Failed to lookup %s, " "reason %s", sh->lookup_loc.path, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1423 , GF_LOG_ERROR, "Failed to lookup %s, " "reason %s", sh->lookup_loc .path, strerror (op_errno)); } while (0) | |||
1422 | "reason %s", sh->lookup_loc.path,do { do { if (0) printf ("Failed to lookup %s, " "reason %s", sh->lookup_loc.path, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1423 , GF_LOG_ERROR, "Failed to lookup %s, " "reason %s", sh->lookup_loc .path, strerror (op_errno)); } while (0) | |||
1423 | strerror (op_errno))do { do { if (0) printf ("Failed to lookup %s, " "reason %s", sh->lookup_loc.path, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1423 , GF_LOG_ERROR, "Failed to lookup %s, " "reason %s", sh->lookup_loc .path, strerror (op_errno)); } while (0); | |||
1424 | goto done; | |||
1425 | } | |||
1426 | ||||
1427 | if ((sh->lookup_flags & AFR_LOOKUP_FAIL_CONFLICTS) && | |||
1428 | (afr_conflicting_iattrs (sh->buf, sh->success_children, | |||
1429 | priv->child_count, | |||
1430 | sh->lookup_loc.path, this->name))) { | |||
1431 | op_errno = EIO5; | |||
1432 | gf_log (this->name, GF_LOG_ERROR, "Conflicting entries "do { do { if (0) printf ("Conflicting entries " "for %s", sh-> lookup_loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1433, GF_LOG_ERROR, "Conflicting entries " "for %s" , sh->lookup_loc.path); } while (0) | |||
1433 | "for %s", sh->lookup_loc.path)do { do { if (0) printf ("Conflicting entries " "for %s", sh-> lookup_loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1433, GF_LOG_ERROR, "Conflicting entries " "for %s" , sh->lookup_loc.path); } while (0); | |||
1434 | goto done; | |||
1435 | } | |||
1436 | ||||
1437 | if ((sh->lookup_flags & AFR_LOOKUP_FAIL_MISSING_GFIDS) && | |||
1438 | (afr_gfid_missing_count (this->name, sh->success_children, | |||
1439 | sh->buf, priv->child_count, | |||
1440 | sh->lookup_loc.path))) { | |||
1441 | op_errno = ENODATA61; | |||
1442 | gf_log (this->name, GF_LOG_ERROR, "Missing Gfids "do { do { if (0) printf ("Missing Gfids " "for %s", sh->lookup_loc .path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1443, GF_LOG_ERROR, "Missing Gfids " "for %s" , sh->lookup_loc.path); } while (0) | |||
1443 | "for %s", sh->lookup_loc.path)do { do { if (0) printf ("Missing Gfids " "for %s", sh->lookup_loc .path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1443, GF_LOG_ERROR, "Missing Gfids " "for %s" , sh->lookup_loc.path); } while (0); | |||
1444 | goto done; | |||
1445 | } | |||
1446 | op_ret = 0; | |||
1447 | ||||
1448 | done: | |||
1449 | sh->lookup_done (frame, this, op_ret, op_errno); | |||
1450 | out: | |||
1451 | return 0; | |||
1452 | } | |||
1453 | ||||
1454 | int | |||
1455 | afr_sh_remove_entry_cbk (call_frame_t *frame, xlator_t *this, int child, | |||
1456 | int32_t op_ret, int32_t op_errno) | |||
1457 | { | |||
1458 | int call_count = 0; | |||
1459 | afr_local_t *local = NULL((void*)0); | |||
1460 | afr_self_heal_t *sh = NULL((void*)0); | |||
1461 | ||||
1462 | local = frame->local; | |||
1463 | sh = &local->self_heal; | |||
1464 | ||||
1465 | GF_ASSERT (sh->post_remove_call)do { if (!(sh->post_remove_call)) { do { do { if (0) printf ("Assertion failed: " "sh->post_remove_call"); } while (0 ); _gf_log_callingfn ("", "afr-self-heal-common.c", __FUNCTION__ , 1465, GF_LOG_ERROR, "Assertion failed: " "sh->post_remove_call" ); } while (0); } } while (0); | |||
1466 | if ((op_ret == -1) && (op_errno != ENOENT2)) { | |||
1467 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("purge entry %s failed, on child %d reason, %s" , local->loc.path, child, strerror (op_errno)); } while (0 ); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1469, GF_LOG_ERROR, "purge entry %s failed, on child %d reason, %s" , local->loc.path, child, strerror (op_errno)); } while (0 ) | |||
1468 | "purge entry %s failed, on child %d reason, %s",do { do { if (0) printf ("purge entry %s failed, on child %d reason, %s" , local->loc.path, child, strerror (op_errno)); } while (0 ); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1469, GF_LOG_ERROR, "purge entry %s failed, on child %d reason, %s" , local->loc.path, child, strerror (op_errno)); } while (0 ) | |||
1469 | local->loc.path, child, strerror (op_errno))do { do { if (0) printf ("purge entry %s failed, on child %d reason, %s" , local->loc.path, child, strerror (op_errno)); } while (0 ); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1469, GF_LOG_ERROR, "purge entry %s failed, on child %d reason, %s" , local->loc.path, child, strerror (op_errno)); } while (0 ); | |||
1470 | LOCK (&frame->lock)pthread_spin_lock (&frame->lock); | |||
1471 | { | |||
1472 | afr_sh_set_error (sh, EIO5); | |||
1473 | sh->op_failed = 1; | |||
1474 | } | |||
1475 | UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock); | |||
1476 | } | |||
1477 | call_count = afr_frame_return (frame); | |||
1478 | if (call_count == 0) | |||
1479 | sh->post_remove_call (frame, this); | |||
| ||||
1480 | return 0; | |||
1481 | } | |||
1482 | ||||
1483 | void | |||
1484 | afr_sh_call_entry_expunge_remove (call_frame_t *frame, xlator_t *this, | |||
1485 | int child_index, struct iatt *buf, | |||
1486 | struct iatt *parentbuf, | |||
1487 | afr_expunge_done_cbk_t expunge_done) | |||
1488 | { | |||
1489 | call_frame_t *expunge_frame = NULL((void*)0); | |||
1490 | afr_local_t *local = NULL((void*)0); | |||
1491 | afr_local_t *expunge_local = NULL((void*)0); | |||
1492 | afr_self_heal_t *sh = NULL((void*)0); | |||
1493 | afr_self_heal_t *expunge_sh = NULL((void*)0); | |||
1494 | int32_t op_errno = 0; | |||
1495 | int ret = 0; | |||
1496 | ||||
1497 | expunge_frame = copy_frame (frame); | |||
1498 | if (!expunge_frame) { | |||
1499 | goto out; | |||
1500 | } | |||
1501 | ||||
1502 | AFR_LOCAL_ALLOC_OR_GOTO (expunge_local, out)do { expunge_local = mem_get0 ((*__glusterfs_this_location()) ->local_pool); if (!expunge_local) { do { do { if (0) printf ("out of memory :("); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1502, GF_LOG_ERROR, "out of memory :("); } while (0); op_errno = 12; goto out; } } while (0);; | |||
1503 | ||||
1504 | local = frame->local; | |||
1505 | sh = &local->self_heal; | |||
1506 | expunge_frame->local = expunge_local; | |||
1507 | expunge_sh = &expunge_local->self_heal; | |||
1508 | expunge_sh->sh_frame = frame; | |||
1509 | loc_copy (&expunge_local->loc, &local->loc); | |||
1510 | ret = afr_build_parent_loc (&expunge_sh->parent_loc, | |||
1511 | &expunge_local->loc, &op_errno); | |||
1512 | if (ret) { | |||
1513 | ret = -op_errno; | |||
1514 | goto out; | |||
1515 | } | |||
1516 | sh->expunge_done = expunge_done; | |||
1517 | afr_sh_entry_expunge_remove (expunge_frame, this, child_index, buf, | |||
1518 | parentbuf); | |||
1519 | return; | |||
1520 | out: | |||
1521 | gf_log (this->name, GF_LOG_ERROR, "Expunge of %s failed, reason: %s",do { do { if (0) printf ("Expunge of %s failed, reason: %s", local ->loc.path, strerror (op_errno)); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 1522, GF_LOG_ERROR , "Expunge of %s failed, reason: %s", local->loc.path, strerror (op_errno)); } while (0) | |||
1522 | local->loc.path, strerror (op_errno))do { do { if (0) printf ("Expunge of %s failed, reason: %s", local ->loc.path, strerror (op_errno)); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 1522, GF_LOG_ERROR , "Expunge of %s failed, reason: %s", local->loc.path, strerror (op_errno)); } while (0); | |||
1523 | expunge_done (frame, this, child_index, -1, op_errno); | |||
1524 | } | |||
1525 | ||||
1526 | void | |||
1527 | afr_sh_remove_stale_lookup_info (afr_self_heal_t *sh, int32_t *success_children, | |||
1528 | int32_t *fresh_children, | |||
1529 | unsigned int child_count) | |||
1530 | { | |||
1531 | int i = 0; | |||
1532 | ||||
1533 | for (i = 0; i < child_count; i++) { | |||
1534 | if (afr_is_child_present (success_children, child_count, i) && | |||
1535 | !afr_is_child_present (fresh_children, child_count, i)) { | |||
1536 | sh->child_errno[i] = ENOENT2; | |||
1537 | GF_ASSERT (sh->xattr[i])do { if (!(sh->xattr[i])) { do { do { if (0) printf ("Assertion failed: " "sh->xattr[i]"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 1537, GF_LOG_ERROR, "Assertion failed: " "sh->xattr[i]" ); } while (0); } } while (0); | |||
1538 | dict_unref (sh->xattr[i]); | |||
1539 | sh->xattr[i] = NULL((void*)0); | |||
1540 | } | |||
1541 | } | |||
1542 | } | |||
1543 | ||||
1544 | int | |||
1545 | afr_sh_purge_stale_entries_done (call_frame_t *frame, xlator_t *this) | |||
1546 | { | |||
1547 | afr_local_t *local = NULL((void*)0); | |||
1548 | afr_self_heal_t *sh = NULL((void*)0); | |||
1549 | afr_private_t *priv = NULL((void*)0); | |||
1550 | ||||
1551 | local = frame->local; | |||
1552 | sh = &local->self_heal; | |||
1553 | priv = this->private; | |||
1554 | ||||
1555 | if (sh->op_failed) { | |||
1556 | afr_sh_missing_entries_finish (frame, this); | |||
1557 | } else { | |||
1558 | if (afr_gfid_missing_count (this->name, sh->fresh_children, | |||
1559 | sh->buf, priv->child_count, | |||
1560 | local->loc.path)) { | |||
1561 | afr_sh_common_lookup (frame, this, &local->loc, | |||
1562 | afr_sh_missing_entries_lookup_done, | |||
1563 | sh->sh_gfid_req, | |||
1564 | AFR_LOOKUP_FAIL_CONFLICTS| | |||
1565 | AFR_LOOKUP_FAIL_MISSING_GFIDS, | |||
1566 | NULL((void*)0)); | |||
1567 | } else { | |||
1568 | //No need to set gfid so goto missing entries lookup done | |||
1569 | //Behave as if you have done the lookup | |||
1570 | afr_sh_remove_stale_lookup_info (sh, | |||
1571 | sh->success_children, | |||
1572 | sh->fresh_children, | |||
1573 | priv->child_count); | |||
1574 | afr_children_copy (sh->success_children, | |||
1575 | sh->fresh_children, | |||
1576 | priv->child_count); | |||
1577 | afr_sh_missing_entries_lookup_done (frame, this, 0, 0); | |||
1578 | } | |||
1579 | } | |||
1580 | return 0; | |||
1581 | } | |||
1582 | ||||
1583 | gf_boolean_t | |||
1584 | afr_sh_purge_entry_condition (afr_local_t *local, afr_private_t *priv, | |||
1585 | int child) | |||
1586 | { | |||
1587 | afr_self_heal_t *sh = NULL((void*)0); | |||
1588 | ||||
1589 | sh = &local->self_heal; | |||
1590 | ||||
1591 | if (local->child_up[child] && | |||
1592 | (!afr_is_child_present (sh->fresh_parent_dirs, priv->child_count, | |||
1593 | child)) | |||
1594 | && (sh->child_errno[child] != ENOENT2)) | |||
1595 | return _gf_true; | |||
1596 | ||||
1597 | return _gf_false; | |||
1598 | } | |||
1599 | ||||
1600 | gf_boolean_t | |||
1601 | afr_sh_purge_stale_entry_condition (afr_local_t *local, afr_private_t *priv, | |||
1602 | int child) | |||
1603 | { | |||
1604 | afr_self_heal_t *sh = NULL((void*)0); | |||
1605 | ||||
1606 | sh = &local->self_heal; | |||
1607 | ||||
1608 | if (local->child_up[child] && | |||
1609 | (!afr_is_child_present (sh->fresh_children, priv->child_count, | |||
1610 | child)) | |||
1611 | && (sh->child_errno[child] != ENOENT2)) | |||
1612 | return _gf_true; | |||
1613 | ||||
1614 | return _gf_false; | |||
1615 | } | |||
1616 | ||||
1617 | void | |||
1618 | afr_sh_purge_entry_common (call_frame_t *frame, xlator_t *this, | |||
1619 | gf_boolean_t purge_condition (afr_local_t *local, | |||
1620 | afr_private_t *priv, | |||
1621 | int child)) | |||
1622 | { | |||
1623 | afr_local_t *local = NULL((void*)0); | |||
1624 | afr_private_t *priv = NULL((void*)0); | |||
1625 | afr_self_heal_t *sh = NULL((void*)0); | |||
1626 | int i = 0; | |||
1627 | int call_count = 0; | |||
1628 | ||||
1629 | local = frame->local; | |||
1630 | sh = &local->self_heal; | |||
1631 | priv = this->private; | |||
1632 | ||||
1633 | for (i = 0; i < priv->child_count; i++) { | |||
1634 | if (purge_condition (local, priv, i)) | |||
1635 | call_count++; | |||
1636 | } | |||
1637 | ||||
1638 | if (call_count == 0) { | |||
1639 | sh->post_remove_call (frame, this); | |||
1640 | goto out; | |||
1641 | } | |||
1642 | ||||
1643 | local->call_count = call_count; | |||
1644 | for (i = 0; i < priv->child_count; i++) { | |||
1645 | if (!purge_condition (local, priv, i)) | |||
1646 | continue; | |||
1647 | gf_log (this->name, GF_LOG_INFO, "purging the stale entry %s "do { do { if (0) printf ("purging the stale entry %s " "on %s" , local->loc.path, priv->children[i]->name); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1648, GF_LOG_INFO, "purging the stale entry %s " "on %s", local ->loc.path, priv->children[i]->name); } while (0) | |||
1648 | "on %s", local->loc.path, priv->children[i]->name)do { do { if (0) printf ("purging the stale entry %s " "on %s" , local->loc.path, priv->children[i]->name); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1648, GF_LOG_INFO, "purging the stale entry %s " "on %s", local ->loc.path, priv->children[i]->name); } while (0); | |||
1649 | afr_sh_call_entry_expunge_remove (frame, this, | |||
1650 | (long) i, &sh->buf[i], | |||
1651 | &sh->parentbufs[i], | |||
1652 | afr_sh_remove_entry_cbk); | |||
1653 | } | |||
1654 | out: | |||
1655 | return; | |||
1656 | } | |||
1657 | ||||
1658 | void | |||
1659 | afr_sh_purge_entry (call_frame_t *frame, xlator_t *this) | |||
1660 | { | |||
1661 | afr_local_t *local = NULL((void*)0); | |||
1662 | afr_self_heal_t *sh = NULL((void*)0); | |||
1663 | ||||
1664 | local = frame->local; | |||
1665 | sh = &local->self_heal; | |||
1666 | sh->post_remove_call = afr_sh_missing_entries_finish; | |||
1667 | ||||
1668 | afr_sh_purge_entry_common (frame, this, afr_sh_purge_entry_condition); | |||
1669 | } | |||
1670 | ||||
1671 | void | |||
1672 | afr_sh_purge_stale_entry (call_frame_t *frame, xlator_t *this) | |||
1673 | { | |||
1674 | afr_local_t *local = NULL((void*)0); | |||
1675 | afr_self_heal_t *sh = NULL((void*)0); | |||
1676 | afr_private_t *priv = NULL((void*)0); | |||
1677 | int i = 0; | |||
1678 | ||||
1679 | local = frame->local; | |||
1680 | sh = &local->self_heal; | |||
1681 | priv = this->private; | |||
1682 | ||||
1683 | sh->post_remove_call = afr_sh_purge_stale_entries_done; | |||
1684 | ||||
1685 | for (i = 0; i < priv->child_count; i++) { | |||
1686 | if (afr_is_child_present (sh->fresh_children, | |||
1687 | priv->child_count, i)) | |||
1688 | continue; | |||
1689 | ||||
1690 | if ((!local->child_up[i]) || sh->child_errno[i] != 0) | |||
1691 | continue; | |||
1692 | ||||
1693 | GF_ASSERT (!uuid_is_null (sh->entrybuf.ia_gfid) ||do { if (!(!uuid_is_null (sh->entrybuf.ia_gfid) || uuid_is_null (sh->buf[i].ia_gfid))) { do { do { if (0) printf ("Assertion failed: " "!uuid_is_null (sh->entrybuf.ia_gfid) || uuid_is_null (sh->buf[i].ia_gfid)" ); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 1694, GF_LOG_ERROR, "Assertion failed: " "!uuid_is_null (sh->entrybuf.ia_gfid) || uuid_is_null (sh->buf[i].ia_gfid)" ); } while (0); } } while (0) | |||
1694 | uuid_is_null (sh->buf[i].ia_gfid))do { if (!(!uuid_is_null (sh->entrybuf.ia_gfid) || uuid_is_null (sh->buf[i].ia_gfid))) { do { do { if (0) printf ("Assertion failed: " "!uuid_is_null (sh->entrybuf.ia_gfid) || uuid_is_null (sh->buf[i].ia_gfid)" ); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 1694, GF_LOG_ERROR, "Assertion failed: " "!uuid_is_null (sh->entrybuf.ia_gfid) || uuid_is_null (sh->buf[i].ia_gfid)" ); } while (0); } } while (0); | |||
1695 | ||||
1696 | if ((sh->entrybuf.ia_type != sh->buf[i].ia_type) || | |||
1697 | (uuid_compare (sh->buf[i].ia_gfid, | |||
1698 | sh->entrybuf.ia_gfid))) | |||
1699 | continue; | |||
1700 | ||||
1701 | afr_children_add_child (sh->fresh_children, i, | |||
1702 | priv->child_count); | |||
1703 | ||||
1704 | } | |||
1705 | afr_sh_purge_entry_common (frame, this, | |||
1706 | afr_sh_purge_stale_entry_condition); | |||
1707 | } | |||
1708 | ||||
1709 | void | |||
1710 | afr_sh_save_child_iatts_from_policy (int32_t *children, struct iatt *bufs, | |||
1711 | struct iatt *save, | |||
1712 | unsigned int child_count) | |||
1713 | { | |||
1714 | int i = 0; | |||
1715 | int child = 0; | |||
1716 | gf_boolean_t saved = _gf_false; | |||
1717 | ||||
1718 | GF_ASSERT (save)do { if (!(save)) { do { do { if (0) printf ("Assertion failed: " "save"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 1718, GF_LOG_ERROR, "Assertion failed: " "save" ); } while (0); } } while (0); | |||
1719 | //if iatt buf with gfid exists sets it | |||
1720 | for (i = 0; i < child_count; i++) { | |||
1721 | child = children[i]; | |||
1722 | if (child == -1) | |||
1723 | break; | |||
1724 | *save = bufs[child]; | |||
1725 | saved = _gf_true; | |||
1726 | if (!uuid_is_null (save->ia_gfid)) | |||
1727 | break; | |||
1728 | } | |||
1729 | GF_ASSERT (saved)do { if (!(saved)) { do { do { if (0) printf ("Assertion failed: " "saved"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 1729, GF_LOG_ERROR, "Assertion failed: " "saved" ); } while (0); } } while (0); | |||
1730 | } | |||
1731 | ||||
1732 | void | |||
1733 | afr_get_children_of_fresh_parent_dirs (afr_self_heal_t *sh, | |||
1734 | unsigned int child_count) | |||
1735 | { | |||
1736 | afr_children_intersection_get (sh->success_children, | |||
1737 | sh->fresh_parent_dirs, | |||
1738 | sh->sources, child_count); | |||
1739 | afr_get_fresh_children (sh->success_children, sh->sources, | |||
1740 | sh->fresh_children, child_count); | |||
1741 | memset (sh->sources, 0, sizeof (*sh->sources) * child_count); | |||
1742 | } | |||
1743 | ||||
1744 | void | |||
1745 | afr_sh_children_lookup_done (call_frame_t *frame, xlator_t *this, | |||
1746 | int32_t op_ret, int32_t op_errno) | |||
1747 | { | |||
1748 | afr_local_t *local = NULL((void*)0); | |||
1749 | afr_self_heal_t *sh = NULL((void*)0); | |||
1750 | afr_private_t *priv = NULL((void*)0); | |||
1751 | int32_t fresh_child_enoents = 0; | |||
1752 | int32_t fresh_parent_count = 0; | |||
1753 | ||||
1754 | local = frame->local; | |||
1755 | sh = &local->self_heal; | |||
1756 | priv = this->private; | |||
1757 | ||||
1758 | if (op_ret < 0) | |||
| ||||
1759 | goto fail; | |||
1760 | afr_get_children_of_fresh_parent_dirs (sh, priv->child_count); | |||
1761 | fresh_parent_count = afr_get_children_count (sh->fresh_parent_dirs, | |||
1762 | priv->child_count); | |||
1763 | //we need the enoent count of the subvols present in fresh_parent_dirs | |||
1764 | fresh_child_enoents = afr_errno_count (sh->fresh_parent_dirs, | |||
1765 | sh->child_errno, | |||
1766 | priv->child_count, ENOENT2); | |||
1767 | if (fresh_child_enoents == fresh_parent_count) { | |||
1768 | afr_sh_set_error (sh, ENOENT2); | |||
1769 | sh->op_failed = 1; | |||
1770 | afr_sh_purge_entry (frame, this); | |||
1771 | } else if (!afr_conflicting_iattrs (sh->buf, sh->fresh_children, | |||
1772 | priv->child_count, local->loc.path, | |||
1773 | this->name)) { | |||
1774 | afr_sh_save_child_iatts_from_policy (sh->fresh_children, | |||
1775 | sh->buf, &sh->entrybuf, | |||
1776 | priv->child_count); | |||
1777 | afr_update_gfid_from_iatts (sh->sh_gfid_req, sh->buf, | |||
1778 | sh->fresh_children, | |||
1779 | priv->child_count); | |||
1780 | afr_sh_purge_stale_entry (frame, this); | |||
1781 | } else { | |||
1782 | op_errno = EIO5; | |||
1783 | local->govinda_gOvinda = 1; | |||
1784 | goto fail; | |||
1785 | } | |||
1786 | ||||
1787 | return; | |||
1788 | ||||
1789 | fail: | |||
1790 | sh->op_failed = 1; | |||
1791 | afr_sh_set_error (sh, op_errno); | |||
1792 | afr_sh_missing_entries_finish (frame, this); | |||
1793 | return; | |||
1794 | } | |||
1795 | ||||
1796 | static void | |||
1797 | afr_sh_find_fresh_parents (call_frame_t *frame, xlator_t *this, | |||
1798 | int32_t op_ret, int32_t op_errno) | |||
1799 | { | |||
1800 | afr_self_heal_t *sh = NULL((void*)0); | |||
1801 | afr_private_t *priv = NULL((void*)0); | |||
1802 | afr_local_t *local = NULL((void*)0); | |||
1803 | int enoent_count = 0; | |||
1804 | int nsources = 0; | |||
1805 | int source = -1; | |||
1806 | int32_t subvol_status = 0; | |||
1807 | ||||
1808 | local = frame->local; | |||
1809 | sh = &local->self_heal; | |||
1810 | priv = this->private; | |||
1811 | ||||
1812 | if (op_ret < 0) | |||
1813 | goto out; | |||
1814 | enoent_count = afr_errno_count (NULL((void*)0), sh->child_errno, | |||
1815 | priv->child_count, ENOENT2); | |||
1816 | if (enoent_count > 0) { | |||
1817 | gf_log (this->name, GF_LOG_INFO, "Parent dir missing for %s,"do { do { if (0) printf ("Parent dir missing for %s," " in missing entry self-heal, aborting missing-entry " "self-heal", local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 1820, GF_LOG_INFO , "Parent dir missing for %s," " in missing entry self-heal, aborting missing-entry " "self-heal", local->loc.path); } while (0) | |||
1818 | " in missing entry self-heal, aborting missing-entry "do { do { if (0) printf ("Parent dir missing for %s," " in missing entry self-heal, aborting missing-entry " "self-heal", local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 1820, GF_LOG_INFO , "Parent dir missing for %s," " in missing entry self-heal, aborting missing-entry " "self-heal", local->loc.path); } while (0) | |||
1819 | "self-heal",do { do { if (0) printf ("Parent dir missing for %s," " in missing entry self-heal, aborting missing-entry " "self-heal", local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 1820, GF_LOG_INFO , "Parent dir missing for %s," " in missing entry self-heal, aborting missing-entry " "self-heal", local->loc.path); } while (0) | |||
1820 | local->loc.path)do { do { if (0) printf ("Parent dir missing for %s," " in missing entry self-heal, aborting missing-entry " "self-heal", local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 1820, GF_LOG_INFO , "Parent dir missing for %s," " in missing entry self-heal, aborting missing-entry " "self-heal", local->loc.path); } while (0); | |||
1821 | afr_sh_missing_entries_finish (frame, this); | |||
1822 | return; | |||
1823 | } | |||
1824 | ||||
1825 | nsources = afr_build_sources (this, sh->xattr, sh->buf, | |||
1826 | sh->pending_matrix, sh->sources, | |||
1827 | sh->success_children, | |||
1828 | AFR_ENTRY_TRANSACTION, &subvol_status, | |||
1829 | _gf_true); | |||
1830 | if ((subvol_status & ALL_FOOLS) || | |||
1831 | (subvol_status & SPLIT_BRAIN)) { | |||
1832 | gf_log (this->name, GF_LOG_INFO, "%s: Performing conservative "do { do { if (0) printf ("%s: Performing conservative " "merge" , sh->parent_loc.path); } while (0); _gf_log (this->name , "afr-self-heal-common.c", __FUNCTION__, 1833, GF_LOG_INFO, "%s: Performing conservative " "merge", sh->parent_loc.path); } while (0) | |||
1833 | "merge", sh->parent_loc.path)do { do { if (0) printf ("%s: Performing conservative " "merge" , sh->parent_loc.path); } while (0); _gf_log (this->name , "afr-self-heal-common.c", __FUNCTION__, 1833, GF_LOG_INFO, "%s: Performing conservative " "merge", sh->parent_loc.path); } while (0); | |||
1834 | afr_mark_success_children_sources (sh->sources, | |||
1835 | sh->success_children, | |||
1836 | priv->child_count); | |||
1837 | } else if (nsources < 0) { | |||
1838 | gf_log (this->name, GF_LOG_ERROR, "No sources for dir "do { do { if (0) printf ("No sources for dir " "of %s, in missing entry self-heal, aborting " "self-heal", local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 1840, GF_LOG_ERROR , "No sources for dir " "of %s, in missing entry self-heal, aborting " "self-heal", local->loc.path); } while (0) | |||
1839 | "of %s, in missing entry self-heal, aborting "do { do { if (0) printf ("No sources for dir " "of %s, in missing entry self-heal, aborting " "self-heal", local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 1840, GF_LOG_ERROR , "No sources for dir " "of %s, in missing entry self-heal, aborting " "self-heal", local->loc.path); } while (0) | |||
1840 | "self-heal", local->loc.path)do { do { if (0) printf ("No sources for dir " "of %s, in missing entry self-heal, aborting " "self-heal", local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 1840, GF_LOG_ERROR , "No sources for dir " "of %s, in missing entry self-heal, aborting " "self-heal", local->loc.path); } while (0); | |||
1841 | op_errno = EIO5; | |||
1842 | goto out; | |||
1843 | } | |||
1844 | ||||
1845 | source = afr_sh_select_source (sh->sources, priv->child_count); | |||
1846 | if (source == -1) { | |||
1847 | GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: " "0"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 1847, GF_LOG_ERROR, "Assertion failed: " "0") ; } while (0); } } while (0); | |||
1848 | gf_log (this->name, GF_LOG_DEBUG, "No active sources found.")do { do { if (0) printf ("No active sources found."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1848, GF_LOG_DEBUG, "No active sources found."); } while (0 ); | |||
1849 | op_errno = EIO5; | |||
1850 | goto out; | |||
1851 | } | |||
1852 | afr_get_fresh_children (sh->success_children, sh->sources, | |||
1853 | sh->fresh_parent_dirs, priv->child_count); | |||
1854 | afr_sh_common_lookup (frame, this, &local->loc, | |||
1855 | afr_sh_children_lookup_done, NULL((void*)0), 0, | |||
1856 | NULL((void*)0)); | |||
1857 | return; | |||
1858 | ||||
1859 | out: | |||
1860 | afr_sh_set_error (sh, op_errno); | |||
1861 | sh->op_failed = 1; | |||
1862 | afr_sh_missing_entries_finish (frame, this); | |||
1863 | return; | |||
1864 | } | |||
1865 | ||||
1866 | void | |||
1867 | afr_sh_common_reset (afr_self_heal_t *sh, unsigned int child_count) | |||
1868 | { | |||
1869 | int i = 0; | |||
1870 | ||||
1871 | for (i = 0; i < child_count; i++) { | |||
1872 | memset (&sh->buf[i], 0, sizeof (sh->buf[i])); | |||
1873 | memset (&sh->parentbufs[i], 0, sizeof (sh->parentbufs[i])); | |||
1874 | sh->child_errno[i] = 0; | |||
1875 | } | |||
1876 | memset (&sh->parentbuf, 0, sizeof (sh->parentbuf)); | |||
1877 | sh->success_count = 0; | |||
1878 | afr_reset_children (sh->success_children, child_count); | |||
1879 | afr_reset_children (sh->fresh_children, child_count); | |||
1880 | afr_reset_xattr (sh->xattr, child_count); | |||
1881 | loc_wipe (&sh->lookup_loc); | |||
1882 | } | |||
1883 | ||||
1884 | /* afr self-heal state will be lost if this call is made | |||
1885 | * please check the afr_sh_common_reset that is called in this function | |||
1886 | */ | |||
1887 | int | |||
1888 | afr_sh_common_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, | |||
1889 | afr_lookup_done_cbk_t lookup_done , uuid_t gfid, | |||
1890 | int32_t flags, dict_t *xdata) | |||
1891 | { | |||
1892 | afr_local_t *local = NULL((void*)0); | |||
1893 | int i = 0; | |||
1894 | int call_count = 0; | |||
1895 | afr_private_t *priv = NULL((void*)0); | |||
1896 | dict_t *xattr_req = NULL((void*)0); | |||
1897 | afr_self_heal_t *sh = NULL((void*)0); | |||
1898 | ||||
1899 | local = frame->local; | |||
1900 | priv = this->private; | |||
1901 | sh = &local->self_heal; | |||
1902 | ||||
1903 | call_count = afr_up_children_count (local->child_up, priv->child_count); | |||
1904 | ||||
1905 | local->call_count = call_count; | |||
1906 | ||||
1907 | xattr_req = dict_new(); | |||
1908 | ||||
1909 | if (xattr_req) { | |||
1910 | afr_xattr_req_prepare (this, xattr_req, loc->path); | |||
1911 | if (gfid) { | |||
1912 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("looking up %s with gfid: %s", loc-> path, uuid_utoa (gfid)); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1914, GF_LOG_DEBUG, "looking up %s with gfid: %s" , loc->path, uuid_utoa (gfid)); } while (0) | |||
1913 | "looking up %s with gfid: %s",do { do { if (0) printf ("looking up %s with gfid: %s", loc-> path, uuid_utoa (gfid)); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1914, GF_LOG_DEBUG, "looking up %s with gfid: %s" , loc->path, uuid_utoa (gfid)); } while (0) | |||
1914 | loc->path, uuid_utoa (gfid))do { do { if (0) printf ("looking up %s with gfid: %s", loc-> path, uuid_utoa (gfid)); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1914, GF_LOG_DEBUG, "looking up %s with gfid: %s" , loc->path, uuid_utoa (gfid)); } while (0); | |||
1915 | GF_ASSERT (!uuid_is_null (gfid))do { if (!(!uuid_is_null (gfid))) { do { do { if (0) printf ( "Assertion failed: " "!uuid_is_null (gfid)"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c", __FUNCTION__, 1915, GF_LOG_ERROR , "Assertion failed: " "!uuid_is_null (gfid)"); } while (0); } } while (0); | |||
1916 | afr_set_dict_gfid (xattr_req, gfid); | |||
1917 | } | |||
1918 | } | |||
1919 | ||||
1920 | afr_sh_common_reset (sh, priv->child_count); | |||
1921 | sh->lookup_done = lookup_done; | |||
1922 | loc_copy (&sh->lookup_loc, loc); | |||
1923 | sh->lookup_flags = flags; | |||
1924 | for (i = 0; i < priv->child_count; i++) { | |||
1925 | if (local->child_up[i]) { | |||
1926 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("looking up %s on subvolume %s", loc ->path, priv->children[i]->name); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1928 , GF_LOG_DEBUG, "looking up %s on subvolume %s", loc->path , priv->children[i]->name); } while (0) | |||
1927 | "looking up %s on subvolume %s",do { do { if (0) printf ("looking up %s on subvolume %s", loc ->path, priv->children[i]->name); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1928 , GF_LOG_DEBUG, "looking up %s on subvolume %s", loc->path , priv->children[i]->name); } while (0) | |||
1928 | loc->path, priv->children[i]->name)do { do { if (0) printf ("looking up %s on subvolume %s", loc ->path, priv->children[i]->name); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__, 1928 , GF_LOG_DEBUG, "looking up %s on subvolume %s", loc->path , priv->children[i]->name); } while (0); | |||
1929 | ||||
1930 | STACK_WIND_COOKIE (frame,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 1935, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->lookup_cbk) tmp_cbk = afr_sh_common_lookup_cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->lookup" ; _new->unwind_to = "afr_sh_common_lookup_cbk"; pthread_spin_init (&_new->lock, 0); pthread_spin_lock (&frame->root ->stack_lock); { frame->ref_count++; _new->next = frame ->root->frames.next; _new->prev = &frame->root ->frames; if (frame->root->frames.next) frame->root ->frames.next->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock ); priv->children[i]->fops->lookup_cbk = afr_sh_common_lookup_cbk ; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location ()) = priv->children[i]; if (priv->children[i]->ctx-> measure_latency) gf_latency_begin (_new, priv->children[i] ->fops->lookup); priv->children[i]->fops->lookup (_new, priv->children[i], loc, xattr_req); (*__glusterfs_this_location ()) = old_THIS; } while (0) | |||
1931 | afr_sh_common_lookup_cbk,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 1935, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->lookup_cbk) tmp_cbk = afr_sh_common_lookup_cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->lookup" ; _new->unwind_to = "afr_sh_common_lookup_cbk"; pthread_spin_init (&_new->lock, 0); pthread_spin_lock (&frame->root ->stack_lock); { frame->ref_count++; _new->next = frame ->root->frames.next; _new->prev = &frame->root ->frames; if (frame->root->frames.next) frame->root ->frames.next->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock ); priv->children[i]->fops->lookup_cbk = afr_sh_common_lookup_cbk ; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location ()) = priv->children[i]; if (priv->children[i]->ctx-> measure_latency) gf_latency_begin (_new, priv->children[i] ->fops->lookup); priv->children[i]->fops->lookup (_new, priv->children[i], loc, xattr_req); (*__glusterfs_this_location ()) = old_THIS; } while (0) | |||
1932 | (void *) (long) i,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 1935, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->lookup_cbk) tmp_cbk = afr_sh_common_lookup_cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->lookup" ; _new->unwind_to = "afr_sh_common_lookup_cbk"; pthread_spin_init (&_new->lock, 0); pthread_spin_lock (&frame->root ->stack_lock); { frame->ref_count++; _new->next = frame ->root->frames.next; _new->prev = &frame->root ->frames; if (frame->root->frames.next) frame->root ->frames.next->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock ); priv->children[i]->fops->lookup_cbk = afr_sh_common_lookup_cbk ; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location ()) = priv->children[i]; if (priv->children[i]->ctx-> measure_latency) gf_latency_begin (_new, priv->children[i] ->fops->lookup); priv->children[i]->fops->lookup (_new, priv->children[i], loc, xattr_req); (*__glusterfs_this_location ()) = old_THIS; } while (0) | |||
1933 | priv->children[i],do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 1935, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->lookup_cbk) tmp_cbk = afr_sh_common_lookup_cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->lookup" ; _new->unwind_to = "afr_sh_common_lookup_cbk"; pthread_spin_init (&_new->lock, 0); pthread_spin_lock (&frame->root ->stack_lock); { frame->ref_count++; _new->next = frame ->root->frames.next; _new->prev = &frame->root ->frames; if (frame->root->frames.next) frame->root ->frames.next->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock ); priv->children[i]->fops->lookup_cbk = afr_sh_common_lookup_cbk ; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location ()) = priv->children[i]; if (priv->children[i]->ctx-> measure_latency) gf_latency_begin (_new, priv->children[i] ->fops->lookup); priv->children[i]->fops->lookup (_new, priv->children[i], loc, xattr_req); (*__glusterfs_this_location ()) = old_THIS; } while (0) | |||
1934 | priv->children[i]->fops->lookup,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 1935, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->lookup_cbk) tmp_cbk = afr_sh_common_lookup_cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->lookup" ; _new->unwind_to = "afr_sh_common_lookup_cbk"; pthread_spin_init (&_new->lock, 0); pthread_spin_lock (&frame->root ->stack_lock); { frame->ref_count++; _new->next = frame ->root->frames.next; _new->prev = &frame->root ->frames; if (frame->root->frames.next) frame->root ->frames.next->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock ); priv->children[i]->fops->lookup_cbk = afr_sh_common_lookup_cbk ; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location ()) = priv->children[i]; if (priv->children[i]->ctx-> measure_latency) gf_latency_begin (_new, priv->children[i] ->fops->lookup); priv->children[i]->fops->lookup (_new, priv->children[i], loc, xattr_req); (*__glusterfs_this_location ()) = old_THIS; } while (0) | |||
1935 | loc, xattr_req)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 1935, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->lookup_cbk) tmp_cbk = afr_sh_common_lookup_cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->lookup" ; _new->unwind_to = "afr_sh_common_lookup_cbk"; pthread_spin_init (&_new->lock, 0); pthread_spin_lock (&frame->root ->stack_lock); { frame->ref_count++; _new->next = frame ->root->frames.next; _new->prev = &frame->root ->frames; if (frame->root->frames.next) frame->root ->frames.next->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock ); priv->children[i]->fops->lookup_cbk = afr_sh_common_lookup_cbk ; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location ()) = priv->children[i]; if (priv->children[i]->ctx-> measure_latency) gf_latency_begin (_new, priv->children[i] ->fops->lookup); priv->children[i]->fops->lookup (_new, priv->children[i], loc, xattr_req); (*__glusterfs_this_location ()) = old_THIS; } while (0); | |||
1936 | ||||
1937 | if (!--call_count) | |||
1938 | break; | |||
1939 | } | |||
1940 | } | |||
1941 | ||||
1942 | if (xattr_req) | |||
1943 | dict_unref (xattr_req); | |||
1944 | ||||
1945 | return 0; | |||
1946 | } | |||
1947 | ||||
1948 | ||||
1949 | ||||
1950 | int | |||
1951 | afr_sh_post_nb_entrylk_conflicting_sh_cbk (call_frame_t *frame, xlator_t *this) | |||
1952 | { | |||
1953 | afr_internal_lock_t *int_lock = NULL((void*)0); | |||
1954 | afr_local_t *local = NULL((void*)0); | |||
1955 | afr_self_heal_t *sh = NULL((void*)0); | |||
1956 | ||||
1957 | local = frame->local; | |||
1958 | int_lock = &local->internal_lock; | |||
1959 | sh = &local->self_heal; | |||
1960 | ||||
1961 | if (int_lock->lock_op_ret < 0) { | |||
1962 | gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("Non blocking entrylks failed."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1963, GF_LOG_INFO, "Non blocking entrylks failed."); } while (0) | |||
1963 | "Non blocking entrylks failed.")do { do { if (0) printf ("Non blocking entrylks failed."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1963, GF_LOG_INFO, "Non blocking entrylks failed."); } while (0); | |||
1964 | sh->op_failed = -1; | |||
1965 | afr_sh_missing_entries_done (frame, this); | |||
1966 | } else { | |||
1967 | ||||
1968 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Non blocking entrylks done. Proceeding to FOP" ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1969, GF_LOG_DEBUG, "Non blocking entrylks done. Proceeding to FOP" ); } while (0) | |||
1969 | "Non blocking entrylks done. Proceeding to FOP")do { do { if (0) printf ("Non blocking entrylks done. Proceeding to FOP" ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1969, GF_LOG_DEBUG, "Non blocking entrylks done. Proceeding to FOP" ); } while (0); | |||
1970 | afr_sh_common_lookup (frame, this, &sh->parent_loc, | |||
1971 | afr_sh_find_fresh_parents, | |||
1972 | NULL((void*)0), AFR_LOOKUP_FAIL_CONFLICTS, | |||
1973 | NULL((void*)0)); | |||
1974 | } | |||
1975 | ||||
1976 | return 0; | |||
1977 | } | |||
1978 | ||||
1979 | int | |||
1980 | afr_sh_post_nb_entrylk_gfid_sh_cbk (call_frame_t *frame, xlator_t *this) | |||
1981 | { | |||
1982 | afr_internal_lock_t *int_lock = NULL((void*)0); | |||
1983 | afr_local_t *local = NULL((void*)0); | |||
1984 | afr_self_heal_t *sh = NULL((void*)0); | |||
1985 | ||||
1986 | local = frame->local; | |||
1987 | sh = &local->self_heal; | |||
1988 | int_lock = &local->internal_lock; | |||
1989 | ||||
1990 | if (int_lock->lock_op_ret < 0) { | |||
1991 | gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("Non blocking entrylks failed."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1992, GF_LOG_INFO, "Non blocking entrylks failed."); } while (0) | |||
1992 | "Non blocking entrylks failed.")do { do { if (0) printf ("Non blocking entrylks failed."); } while (0); _gf_log (this->name, "afr-self-heal-common.c", __FUNCTION__ , 1992, GF_LOG_INFO, "Non blocking entrylks failed."); } while (0); | |||
1993 | afr_sh_missing_entries_done (frame, this); | |||
1994 | } else { | |||
1995 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Non blocking entrylks done. Proceeding to FOP" ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1996, GF_LOG_DEBUG, "Non blocking entrylks done. Proceeding to FOP" ); } while (0) | |||
1996 | "Non blocking entrylks done. Proceeding to FOP")do { do { if (0) printf ("Non blocking entrylks done. Proceeding to FOP" ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 1996, GF_LOG_DEBUG, "Non blocking entrylks done. Proceeding to FOP" ); } while (0); | |||
1997 | afr_sh_common_lookup (frame, this, &local->loc, | |||
1998 | afr_sh_missing_entries_lookup_done, | |||
1999 | sh->sh_gfid_req, AFR_LOOKUP_FAIL_CONFLICTS| | |||
2000 | AFR_LOOKUP_FAIL_MISSING_GFIDS, | |||
2001 | NULL((void*)0)); | |||
2002 | } | |||
2003 | ||||
2004 | return 0; | |||
2005 | } | |||
2006 | ||||
2007 | int | |||
2008 | afr_sh_entrylk (call_frame_t *frame, xlator_t *this, loc_t *loc, | |||
2009 | char *base_name, afr_lock_cbk_t lock_cbk) | |||
2010 | { | |||
2011 | afr_internal_lock_t *int_lock = NULL((void*)0); | |||
2012 | afr_local_t *local = NULL((void*)0); | |||
2013 | afr_private_t *priv = NULL((void*)0); | |||
2014 | ||||
2015 | priv = this->private; | |||
2016 | local = frame->local; | |||
2017 | int_lock = &local->internal_lock; | |||
2018 | ||||
2019 | int_lock->transaction_lk_type = AFR_SELFHEAL_LK; | |||
2020 | int_lock->selfheal_lk_type = AFR_ENTRY_SELF_HEAL_LK; | |||
2021 | ||||
2022 | afr_set_lock_number (frame, this); | |||
2023 | ||||
2024 | int_lock->lk_basename = base_name; | |||
2025 | int_lock->lk_loc = loc; | |||
2026 | int_lock->lock_cbk = lock_cbk; | |||
2027 | ||||
2028 | int_lock->lockee_count = 0; | |||
2029 | afr_init_entry_lockee (&int_lock->lockee[0], local, loc, | |||
2030 | base_name, priv->child_count); | |||
2031 | int_lock->lockee_count++; | |||
2032 | afr_nonblocking_entrylk (frame, this); | |||
2033 | ||||
2034 | return 0; | |||
2035 | } | |||
2036 | ||||
2037 | static int | |||
2038 | afr_self_heal_parent_entrylk (call_frame_t *frame, xlator_t *this, | |||
2039 | afr_lock_cbk_t lock_cbk) | |||
2040 | { | |||
2041 | afr_local_t *local = NULL((void*)0); | |||
2042 | afr_self_heal_t *sh = NULL((void*)0); | |||
2043 | afr_internal_lock_t *int_lock = NULL((void*)0); | |||
2044 | int ret = -1; | |||
2045 | int32_t op_errno = 0; | |||
2046 | ||||
2047 | local = frame->local; | |||
2048 | sh = &local->self_heal; | |||
2049 | ||||
2050 | gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("attempting to recreate missing entries for path=%s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2052, GF_LOG_TRACE, "attempting to recreate missing entries for path=%s" , local->loc.path); } while (0) | |||
2051 | "attempting to recreate missing entries for path=%s",do { do { if (0) printf ("attempting to recreate missing entries for path=%s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2052, GF_LOG_TRACE, "attempting to recreate missing entries for path=%s" , local->loc.path); } while (0) | |||
2052 | local->loc.path)do { do { if (0) printf ("attempting to recreate missing entries for path=%s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2052, GF_LOG_TRACE, "attempting to recreate missing entries for path=%s" , local->loc.path); } while (0); | |||
2053 | ||||
2054 | ret = afr_build_parent_loc (&sh->parent_loc, &local->loc, &op_errno); | |||
2055 | if (ret) | |||
2056 | goto out; | |||
2057 | ||||
2058 | afr_sh_entrylk (frame, this, &sh->parent_loc, NULL((void*)0), | |||
2059 | lock_cbk); | |||
2060 | return 0; | |||
2061 | out: | |||
2062 | int_lock = &local->internal_lock; | |||
2063 | int_lock->lock_op_ret = -1; | |||
2064 | lock_cbk (frame, this); | |||
2065 | return 0; | |||
2066 | } | |||
2067 | ||||
2068 | static int | |||
2069 | afr_self_heal_conflicting_entries (call_frame_t *frame, xlator_t *this) | |||
2070 | { | |||
2071 | afr_self_heal_parent_entrylk (frame, this, | |||
2072 | afr_sh_post_nb_entrylk_conflicting_sh_cbk); | |||
2073 | return 0; | |||
2074 | } | |||
2075 | ||||
2076 | static int | |||
2077 | afr_self_heal_gfids (call_frame_t *frame, xlator_t *this) | |||
2078 | { | |||
2079 | afr_self_heal_parent_entrylk (frame, this, | |||
2080 | afr_sh_post_nb_entrylk_gfid_sh_cbk); | |||
2081 | return 0; | |||
2082 | } | |||
2083 | ||||
2084 | afr_local_t *afr_local_copy (afr_local_t *l, xlator_t *this) | |||
2085 | { | |||
2086 | afr_private_t *priv = NULL((void*)0); | |||
2087 | afr_local_t *lc = NULL((void*)0); | |||
2088 | afr_self_heal_t *sh = NULL((void*)0); | |||
2089 | afr_self_heal_t *shc = NULL((void*)0); | |||
2090 | int i = 0; | |||
2091 | ||||
2092 | priv = this->private; | |||
2093 | ||||
2094 | sh = &l->self_heal; | |||
2095 | ||||
2096 | lc = mem_get0 (this->local_pool); | |||
2097 | if (!lc) | |||
2098 | goto out; | |||
2099 | ||||
2100 | shc = &lc->self_heal; | |||
2101 | ||||
2102 | shc->unwind = sh->unwind; | |||
2103 | shc->gfid_sh_success_cbk = sh->gfid_sh_success_cbk; | |||
2104 | shc->do_missing_entry_self_heal = sh->do_missing_entry_self_heal; | |||
2105 | shc->do_gfid_self_heal = sh->do_gfid_self_heal; | |||
2106 | shc->do_data_self_heal = sh->do_data_self_heal; | |||
2107 | shc->do_metadata_self_heal = sh->do_metadata_self_heal; | |||
2108 | shc->do_entry_self_heal = sh->do_entry_self_heal; | |||
2109 | shc->force_confirm_spb = sh->force_confirm_spb; | |||
2110 | shc->forced_merge = sh->forced_merge; | |||
2111 | shc->background = sh->background; | |||
2112 | shc->type = sh->type; | |||
2113 | ||||
2114 | uuid_copy (shc->sh_gfid_req, sh->sh_gfid_req); | |||
2115 | if (l->loc.path) | |||
2116 | loc_copy (&lc->loc, &l->loc); | |||
2117 | ||||
2118 | lc->child_up = memdup (l->child_up, | |||
2119 | sizeof (*lc->child_up) * priv->child_count); | |||
2120 | if (l->xattr_req) | |||
2121 | lc->xattr_req = dict_ref (l->xattr_req); | |||
2122 | ||||
2123 | if (l->cont.lookup.inode) | |||
2124 | lc->cont.lookup.inode = inode_ref (l->cont.lookup.inode); | |||
2125 | if (l->cont.lookup.xattr) | |||
2126 | lc->cont.lookup.xattr = dict_ref (l->cont.lookup.xattr); | |||
2127 | if (l->internal_lock.inode_locked_nodes) | |||
2128 | lc->internal_lock.inode_locked_nodes = | |||
2129 | memdup (l->internal_lock.inode_locked_nodes, | |||
2130 | sizeof (*lc->internal_lock.inode_locked_nodes) * priv->child_count); | |||
2131 | else | |||
2132 | lc->internal_lock.inode_locked_nodes = | |||
2133 | GF_CALLOC (sizeof (*l->internal_lock.inode_locked_nodes),__gf_calloc (sizeof (*l->internal_lock.inode_locked_nodes) , priv->child_count, gf_afr_mt_char) | |||
2134 | priv->child_count,__gf_calloc (sizeof (*l->internal_lock.inode_locked_nodes) , priv->child_count, gf_afr_mt_char) | |||
2135 | gf_afr_mt_char)__gf_calloc (sizeof (*l->internal_lock.inode_locked_nodes) , priv->child_count, gf_afr_mt_char); | |||
2136 | ||||
2137 | if (l->internal_lock.locked_nodes) | |||
2138 | lc->internal_lock.locked_nodes = | |||
2139 | memdup (l->internal_lock.locked_nodes, | |||
2140 | sizeof (*lc->internal_lock.locked_nodes) * priv->child_count); | |||
2141 | else | |||
2142 | lc->internal_lock.locked_nodes = | |||
2143 | GF_CALLOC (sizeof (*l->internal_lock.locked_nodes),__gf_calloc (sizeof (*l->internal_lock.locked_nodes), priv ->child_count, gf_afr_mt_char) | |||
2144 | priv->child_count,__gf_calloc (sizeof (*l->internal_lock.locked_nodes), priv ->child_count, gf_afr_mt_char) | |||
2145 | gf_afr_mt_char)__gf_calloc (sizeof (*l->internal_lock.locked_nodes), priv ->child_count, gf_afr_mt_char); | |||
2146 | ||||
2147 | for (i = 0; i < l->internal_lock.lockee_count; i++) { | |||
2148 | loc_copy (&lc->internal_lock.lockee[i].loc, | |||
2149 | &l->internal_lock.lockee[i].loc); | |||
2150 | ||||
2151 | lc->internal_lock.lockee[i].locked_count = | |||
2152 | l->internal_lock.lockee[i].locked_count; | |||
2153 | ||||
2154 | if (l->internal_lock.lockee[i].basename) | |||
2155 | lc->internal_lock.lockee[i].basename = | |||
2156 | gf_strdup (l->internal_lock.lockee[i].basename); | |||
2157 | ||||
2158 | if (l->internal_lock.lockee[i].locked_nodes) { | |||
2159 | lc->internal_lock.lockee[i].locked_nodes = | |||
2160 | memdup (l->internal_lock.lockee[i].locked_nodes, | |||
2161 | sizeof (*lc->internal_lock.lockee[i].locked_nodes) * | |||
2162 | priv->child_count); | |||
2163 | } else { | |||
2164 | lc->internal_lock.lockee[i].locked_nodes = | |||
2165 | GF_CALLOC (priv->child_count,__gf_calloc (priv->child_count, sizeof (*lc->internal_lock .lockee[i].locked_nodes), gf_afr_mt_char) | |||
2166 | sizeof (*lc->internal_lock.lockee[i].locked_nodes),__gf_calloc (priv->child_count, sizeof (*lc->internal_lock .lockee[i].locked_nodes), gf_afr_mt_char) | |||
2167 | gf_afr_mt_char)__gf_calloc (priv->child_count, sizeof (*lc->internal_lock .lockee[i].locked_nodes), gf_afr_mt_char); | |||
2168 | } | |||
2169 | ||||
2170 | } | |||
2171 | lc->internal_lock.lockee_count = l->internal_lock.lockee_count; | |||
2172 | ||||
2173 | lc->internal_lock.inodelk_lock_count = | |||
2174 | l->internal_lock.inodelk_lock_count; | |||
2175 | lc->internal_lock.entrylk_lock_count = | |||
2176 | l->internal_lock.entrylk_lock_count; | |||
2177 | ||||
2178 | ||||
2179 | out: | |||
2180 | return lc; | |||
2181 | } | |||
2182 | ||||
2183 | int | |||
2184 | afr_self_heal_completion_cbk (call_frame_t *bgsh_frame, xlator_t *this) | |||
2185 | { | |||
2186 | afr_private_t * priv = NULL((void*)0); | |||
2187 | afr_local_t * local = NULL((void*)0); | |||
2188 | afr_self_heal_t * sh = NULL((void*)0); | |||
2189 | afr_local_t * orig_frame_local = NULL((void*)0); | |||
2190 | afr_self_heal_t * orig_frame_sh = NULL((void*)0); | |||
2191 | char sh_type_str[256] = {0,}; | |||
2192 | ||||
2193 | priv = this->private; | |||
2194 | local = bgsh_frame->local; | |||
2195 | sh = &local->self_heal; | |||
2196 | ||||
2197 | if (local->govinda_gOvinda) { | |||
2198 | afr_set_split_brain (this, sh->inode, SPB, SPB); | |||
2199 | sh->op_failed = 1; | |||
2200 | } | |||
2201 | ||||
2202 | afr_self_heal_type_str_get (sh, sh_type_str, | |||
2203 | sizeof(sh_type_str)); | |||
2204 | if (sh->op_failed) { | |||
2205 | gf_loglevel_t loglevel = GF_LOG_ERROR; | |||
2206 | if (priv->shd.iamshd) | |||
2207 | loglevel = GF_LOG_DEBUG; | |||
2208 | ||||
2209 | gf_log (this->name, loglevel, "background %s self-heal "do { do { if (0) printf ("background %s self-heal " "failed on %s" , sh_type_str, local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 2210, loglevel , "background %s self-heal " "failed on %s", sh_type_str, local ->loc.path); } while (0) | |||
2210 | "failed on %s", sh_type_str, local->loc.path)do { do { if (0) printf ("background %s self-heal " "failed on %s" , sh_type_str, local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 2210, loglevel , "background %s self-heal " "failed on %s", sh_type_str, local ->loc.path); } while (0); | |||
2211 | ||||
2212 | } else { | |||
2213 | gf_log (this->name, GF_LOG_DEBUG, "background %s self-heal "do { do { if (0) printf ("background %s self-heal " "completed on %s" , sh_type_str, local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 2214, GF_LOG_DEBUG , "background %s self-heal " "completed on %s", sh_type_str, local ->loc.path); } while (0) | |||
2214 | "completed on %s", sh_type_str, local->loc.path)do { do { if (0) printf ("background %s self-heal " "completed on %s" , sh_type_str, local->loc.path); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 2214, GF_LOG_DEBUG , "background %s self-heal " "completed on %s", sh_type_str, local ->loc.path); } while (0); | |||
2215 | ||||
2216 | } | |||
2217 | ||||
2218 | FRAME_SU_UNDO (bgsh_frame, afr_local_t)do { afr_local_t *__local = (bgsh_frame)->local; bgsh_frame ->root->uid = __local->uid; bgsh_frame->root-> gid = __local->gid; } while (0);; | |||
2219 | ||||
2220 | if (!sh->unwound && sh->unwind) { | |||
2221 | orig_frame_local = sh->orig_frame->local; | |||
2222 | orig_frame_sh = &orig_frame_local->self_heal; | |||
2223 | orig_frame_sh->actual_sh_started = _gf_true; | |||
2224 | sh->unwind (sh->orig_frame, this, sh->op_ret, sh->op_errno, | |||
2225 | sh->op_failed); | |||
2226 | } | |||
2227 | ||||
2228 | if (sh->background) { | |||
2229 | LOCK (&priv->lock)pthread_spin_lock (&priv->lock); | |||
2230 | { | |||
2231 | priv->background_self_heals_started--; | |||
2232 | } | |||
2233 | UNLOCK (&priv->lock)pthread_spin_unlock (&priv->lock); | |||
2234 | } | |||
2235 | ||||
2236 | AFR_STACK_DESTROY (bgsh_frame)do { afr_local_t *__local = ((void*)0); xlator_t *__this = (( void*)0); __local = bgsh_frame->local; __this = bgsh_frame ->this; bgsh_frame->local = ((void*)0); STACK_DESTROY ( bgsh_frame->root); if (__local) { afr_local_cleanup (__local , __this); mem_put (__local); } } while (0);; | |||
2237 | ||||
2238 | return 0; | |||
2239 | } | |||
2240 | ||||
2241 | int | |||
2242 | afr_self_heal (call_frame_t *frame, xlator_t *this, inode_t *inode) | |||
2243 | { | |||
2244 | afr_local_t *local = NULL((void*)0); | |||
2245 | afr_self_heal_t *sh = NULL((void*)0); | |||
2246 | afr_private_t *priv = NULL((void*)0); | |||
2247 | int32_t op_errno = 0; | |||
2248 | int ret = 0; | |||
2249 | afr_self_heal_t *orig_sh = NULL((void*)0); | |||
2250 | call_frame_t *sh_frame = NULL((void*)0); | |||
2251 | afr_local_t *sh_local = NULL((void*)0); | |||
2252 | loc_t *loc = NULL((void*)0); | |||
2253 | ||||
2254 | local = frame->local; | |||
2255 | orig_sh = &local->self_heal; | |||
2256 | priv = this->private; | |||
2257 | ||||
2258 | GF_ASSERT (local->loc.path)do { if (!(local->loc.path)) { do { do { if (0) printf ("Assertion failed: " "local->loc.path"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 2258, GF_LOG_ERROR, "Assertion failed: " "local->loc.path" ); } while (0); } } while (0); | |||
2259 | ||||
2260 | gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2265, GF_LOG_TRACE, "performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0) | |||
2261 | "performing self heal on %s (metadata=%d data=%d entry=%d)",do { do { if (0) printf ("performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2265, GF_LOG_TRACE, "performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0) | |||
2262 | local->loc.path,do { do { if (0) printf ("performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2265, GF_LOG_TRACE, "performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0) | |||
2263 | local->self_heal.do_metadata_self_heal,do { do { if (0) printf ("performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2265, GF_LOG_TRACE, "performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0) | |||
2264 | local->self_heal.do_data_self_heal,do { do { if (0) printf ("performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2265, GF_LOG_TRACE, "performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0) | |||
2265 | local->self_heal.do_entry_self_heal)do { do { if (0) printf ("performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2265, GF_LOG_TRACE, "performing self heal on %s (metadata=%d data=%d entry=%d)" , local->loc.path, local->self_heal.do_metadata_self_heal , local->self_heal.do_data_self_heal, local->self_heal. do_entry_self_heal); } while (0); | |||
2266 | ||||
2267 | op_errno = ENOMEM12; | |||
2268 | sh_frame = copy_frame (frame); | |||
2269 | if (!sh_frame) | |||
2270 | goto out; | |||
2271 | afr_set_lk_owner (sh_frame, this, sh_frame->root); | |||
2272 | afr_set_low_priority (sh_frame); | |||
2273 | ||||
2274 | sh_local = afr_local_copy (local, this); | |||
2275 | if (!sh_local) | |||
2276 | goto out; | |||
2277 | sh_frame->local = sh_local; | |||
2278 | sh = &sh_local->self_heal; | |||
2279 | ||||
2280 | sh->inode = inode_ref (inode); | |||
2281 | sh->orig_frame = frame; | |||
2282 | ||||
2283 | sh->completion_cbk = afr_self_heal_completion_cbk; | |||
2284 | ||||
2285 | sh->success = GF_CALLOC (priv->child_count, sizeof (*sh->success),__gf_calloc (priv->child_count, sizeof (*sh->success), gf_afr_mt_char ) | |||
2286 | gf_afr_mt_char)__gf_calloc (priv->child_count, sizeof (*sh->success), gf_afr_mt_char ); | |||
2287 | if (!sh->success) | |||
2288 | goto out; | |||
2289 | sh->sources = GF_CALLOC (sizeof (*sh->sources), priv->child_count,__gf_calloc (sizeof (*sh->sources), priv->child_count, gf_afr_mt_int ) | |||
2290 | gf_afr_mt_int)__gf_calloc (sizeof (*sh->sources), priv->child_count, gf_afr_mt_int ); | |||
2291 | if (!sh->sources) | |||
2292 | goto out; | |||
2293 | sh->locked_nodes = GF_CALLOC (sizeof (*sh->locked_nodes),__gf_calloc (sizeof (*sh->locked_nodes), priv->child_count , gf_afr_mt_int) | |||
2294 | priv->child_count,__gf_calloc (sizeof (*sh->locked_nodes), priv->child_count , gf_afr_mt_int) | |||
2295 | gf_afr_mt_int)__gf_calloc (sizeof (*sh->locked_nodes), priv->child_count , gf_afr_mt_int); | |||
2296 | if (!sh->locked_nodes) | |||
2297 | goto out; | |||
2298 | ||||
2299 | sh->pending_matrix = afr_matrix_create (priv->child_count, | |||
2300 | priv->child_count); | |||
2301 | if (!sh->pending_matrix) | |||
2302 | goto out; | |||
2303 | ||||
2304 | sh->delta_matrix = afr_matrix_create (priv->child_count, | |||
2305 | priv->child_count); | |||
2306 | if (!sh->delta_matrix) | |||
2307 | goto out; | |||
2308 | ||||
2309 | sh->fresh_parent_dirs = afr_children_create (priv->child_count); | |||
2310 | if (!sh->fresh_parent_dirs) | |||
2311 | goto out; | |||
2312 | ret = afr_sh_common_create (sh, priv->child_count); | |||
2313 | if (ret) { | |||
2314 | op_errno = -ret; | |||
2315 | goto out; | |||
2316 | } | |||
2317 | ||||
2318 | if (local->self_heal.background) { | |||
2319 | LOCK (&priv->lock)pthread_spin_lock (&priv->lock); | |||
2320 | { | |||
2321 | if (priv->background_self_heals_started | |||
2322 | < priv->background_self_heal_count) { | |||
2323 | priv->background_self_heals_started++; | |||
2324 | ||||
2325 | ||||
2326 | } else { | |||
2327 | local->self_heal.background = _gf_false; | |||
2328 | sh->background = _gf_false; | |||
2329 | } | |||
2330 | } | |||
2331 | UNLOCK (&priv->lock)pthread_spin_unlock (&priv->lock); | |||
2332 | } | |||
2333 | ||||
2334 | if (!local->loc.parent) { | |||
2335 | sh->do_missing_entry_self_heal = _gf_false; | |||
2336 | sh->do_gfid_self_heal = _gf_false; | |||
2337 | } | |||
2338 | ||||
2339 | FRAME_SU_DO (sh_frame, afr_local_t)do { afr_local_t *__local = (sh_frame)->local; __local-> uid = sh_frame->root->uid; __local->gid = sh_frame-> root->gid; sh_frame->root->uid = 0; sh_frame->root ->gid = 0; } while (0);; | |||
2340 | if (sh->do_missing_entry_self_heal) { | |||
2341 | afr_self_heal_conflicting_entries (sh_frame, this); | |||
2342 | } else if (sh->do_gfid_self_heal) { | |||
2343 | GF_ASSERT (!uuid_is_null (sh->sh_gfid_req))do { if (!(!uuid_is_null (sh->sh_gfid_req))) { do { do { if (0) printf ("Assertion failed: " "!uuid_is_null (sh->sh_gfid_req)" ); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 2343, GF_LOG_ERROR, "Assertion failed: " "!uuid_is_null (sh->sh_gfid_req)" ); } while (0); } } while (0); | |||
2344 | afr_self_heal_gfids (sh_frame, this); | |||
2345 | } else { | |||
2346 | loc = &sh_local->loc; | |||
2347 | if (uuid_is_null (loc->inode->gfid) && uuid_is_null (loc->gfid)) { | |||
2348 | if (!uuid_is_null (inode->gfid)) | |||
2349 | GF_ASSERT (!uuid_compare (inode->gfid,do { if (!(!uuid_compare (inode->gfid, sh->sh_gfid_req) )) { do { do { if (0) printf ("Assertion failed: " "!uuid_compare (inode->gfid, sh->sh_gfid_req)" ); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 2350, GF_LOG_ERROR, "Assertion failed: " "!uuid_compare (inode->gfid, sh->sh_gfid_req)" ); } while (0); } } while (0) | |||
2350 | sh->sh_gfid_req))do { if (!(!uuid_compare (inode->gfid, sh->sh_gfid_req) )) { do { do { if (0) printf ("Assertion failed: " "!uuid_compare (inode->gfid, sh->sh_gfid_req)" ); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 2350, GF_LOG_ERROR, "Assertion failed: " "!uuid_compare (inode->gfid, sh->sh_gfid_req)" ); } while (0); } } while (0); | |||
2351 | uuid_copy (loc->gfid, sh->sh_gfid_req); | |||
2352 | } | |||
2353 | gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("proceeding to metadata check on %s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2355, GF_LOG_TRACE, "proceeding to metadata check on %s" , local->loc.path); } while (0) | |||
2354 | "proceeding to metadata check on %s",do { do { if (0) printf ("proceeding to metadata check on %s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2355, GF_LOG_TRACE, "proceeding to metadata check on %s" , local->loc.path); } while (0) | |||
2355 | local->loc.path)do { do { if (0) printf ("proceeding to metadata check on %s" , local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2355, GF_LOG_TRACE, "proceeding to metadata check on %s" , local->loc.path); } while (0); | |||
2356 | ||||
2357 | afr_sh_missing_entries_done (sh_frame, this); | |||
2358 | } | |||
2359 | op_errno = 0; | |||
2360 | ||||
2361 | out: | |||
2362 | if (op_errno) { | |||
2363 | orig_sh->unwind (frame, this, -1, op_errno, 1); | |||
2364 | if (sh_frame) | |||
2365 | AFR_STACK_DESTROY (sh_frame)do { afr_local_t *__local = ((void*)0); xlator_t *__this = (( void*)0); __local = sh_frame->local; __this = sh_frame-> this; sh_frame->local = ((void*)0); STACK_DESTROY (sh_frame ->root); if (__local) { afr_local_cleanup (__local, __this ); mem_put (__local); } } while (0);; | |||
2366 | } | |||
2367 | return 0; | |||
2368 | } | |||
2369 | ||||
2370 | void | |||
2371 | afr_self_heal_type_str_get (afr_self_heal_t *self_heal_p, char *str, | |||
2372 | size_t size) | |||
2373 | { | |||
2374 | GF_ASSERT (str && (size > strlen (" missing-entry gfid "do { if (!(str && (size > strlen (" missing-entry gfid " "meta-data data entry")))) { do { do { if (0) printf ("Assertion failed: " "str && (size > strlen (\" missing-entry gfid \" \"meta-data data entry\"))" ); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 2375, GF_LOG_ERROR, "Assertion failed: " "str && (size > strlen (\" missing-entry gfid \" \"meta-data data entry\"))" ); } while (0); } } while (0) | |||
2375 | "meta-data data entry")))do { if (!(str && (size > strlen (" missing-entry gfid " "meta-data data entry")))) { do { do { if (0) printf ("Assertion failed: " "str && (size > strlen (\" missing-entry gfid \" \"meta-data data entry\"))" ); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 2375, GF_LOG_ERROR, "Assertion failed: " "str && (size > strlen (\" missing-entry gfid \" \"meta-data data entry\"))" ); } while (0); } } while (0); | |||
2376 | ||||
2377 | if (self_heal_p->do_metadata_self_heal) { | |||
2378 | snprintf (str, size, " meta-data"); | |||
2379 | } | |||
2380 | ||||
2381 | if (self_heal_p->do_data_self_heal) { | |||
2382 | snprintf (str + strlen(str), size - strlen(str), " data"); | |||
2383 | } | |||
2384 | ||||
2385 | if (self_heal_p->do_entry_self_heal) { | |||
2386 | snprintf (str + strlen(str), size - strlen(str), " entry"); | |||
2387 | } | |||
2388 | ||||
2389 | if (self_heal_p->do_missing_entry_self_heal) { | |||
2390 | snprintf (str + strlen(str), size - strlen(str), | |||
2391 | " missing-entry"); | |||
2392 | } | |||
2393 | ||||
2394 | if (self_heal_p->do_gfid_self_heal) { | |||
2395 | snprintf (str + strlen(str), size - strlen(str), " gfid"); | |||
2396 | } | |||
2397 | } | |||
2398 | ||||
2399 | afr_self_heal_type | |||
2400 | afr_self_heal_type_for_transaction (afr_transaction_type type) | |||
2401 | { | |||
2402 | afr_self_heal_type sh_type = AFR_SELF_HEAL_INVALID; | |||
2403 | ||||
2404 | switch (type) { | |||
2405 | case AFR_DATA_TRANSACTION: | |||
2406 | sh_type = AFR_SELF_HEAL_DATA; | |||
2407 | break; | |||
2408 | case AFR_METADATA_TRANSACTION: | |||
2409 | sh_type = AFR_SELF_HEAL_METADATA; | |||
2410 | break; | |||
2411 | case AFR_ENTRY_TRANSACTION: | |||
2412 | sh_type = AFR_SELF_HEAL_ENTRY; | |||
2413 | break; | |||
2414 | case AFR_ENTRY_RENAME_TRANSACTION: | |||
2415 | GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: " "0"); } while (0); _gf_log_callingfn ("", "afr-self-heal-common.c" , __FUNCTION__, 2415, GF_LOG_ERROR, "Assertion failed: " "0") ; } while (0); } } while (0); | |||
2416 | break; | |||
2417 | } | |||
2418 | return sh_type; | |||
2419 | } | |||
2420 | ||||
2421 | int | |||
2422 | afr_build_child_loc (xlator_t *this, loc_t *child, loc_t *parent, char *name) | |||
2423 | { | |||
2424 | int ret = -1; | |||
2425 | uuid_t pargfid = {0}; | |||
2426 | ||||
2427 | if (!child) | |||
2428 | goto out; | |||
2429 | ||||
2430 | if (!uuid_is_null (parent->inode->gfid)) | |||
2431 | uuid_copy (pargfid, parent->inode->gfid); | |||
2432 | else if (!uuid_is_null (parent->gfid)) | |||
2433 | uuid_copy (pargfid, parent->gfid); | |||
2434 | ||||
2435 | if (uuid_is_null (pargfid)) | |||
2436 | goto out; | |||
2437 | ||||
2438 | if (strcmp (parent->path, "/") == 0) | |||
2439 | ret = gf_asprintf ((char **)&child->path, "/%s", name); | |||
2440 | else | |||
2441 | ret = gf_asprintf ((char **)&child->path, "%s/%s", parent->path, | |||
2442 | name); | |||
2443 | ||||
2444 | if (-1 == ret) { | |||
2445 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("asprintf failed while setting child path" ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2446, GF_LOG_ERROR, "asprintf failed while setting child path" ); } while (0) | |||
2446 | "asprintf failed while setting child path")do { do { if (0) printf ("asprintf failed while setting child path" ); } while (0); _gf_log (this->name, "afr-self-heal-common.c" , __FUNCTION__, 2446, GF_LOG_ERROR, "asprintf failed while setting child path" ); } while (0); | |||
2447 | } | |||
2448 | ||||
2449 | child->name = strrchr (child->path, '/'); | |||
2450 | if (child->name) | |||
2451 | child->name++; | |||
2452 | ||||
2453 | child->parent = inode_ref (parent->inode); | |||
2454 | child->inode = inode_new (parent->inode->table); | |||
2455 | uuid_copy (child->pargfid, pargfid); | |||
2456 | ||||
2457 | if (!child->inode) { | |||
2458 | ret = -1; | |||
2459 | goto out; | |||
2460 | } | |||
2461 | ||||
2462 | ret = 0; | |||
2463 | out: | |||
2464 | if ((ret == -1) && child) | |||
2465 | loc_wipe (child); | |||
2466 | ||||
2467 | return ret; | |||
2468 | } | |||
2469 | ||||
2470 | int | |||
2471 | afr_sh_erase_pending (call_frame_t *frame, xlator_t *this, | |||
2472 | afr_transaction_type type, afr_fxattrop_cbk_t cbk, | |||
2473 | int (*finish)(call_frame_t *frame, xlator_t *this)) | |||
2474 | { | |||
2475 | afr_local_t *local = NULL((void*)0); | |||
2476 | afr_self_heal_t *sh = NULL((void*)0); | |||
2477 | afr_private_t *priv = NULL((void*)0); | |||
2478 | int call_count = 0; | |||
2479 | int i = 0; | |||
2480 | dict_t **erase_xattr = NULL((void*)0); | |||
2481 | int ret = -1; | |||
2482 | ||||
2483 | local = frame->local; | |||
2484 | sh = &local->self_heal; | |||
2485 | priv = this->private; | |||
2486 | ||||
2487 | afr_sh_pending_to_delta (priv, sh->xattr, sh->delta_matrix, | |||
2488 | sh->success, priv->child_count, type); | |||
2489 | ||||
2490 | erase_xattr = GF_CALLOC (sizeof (*erase_xattr), priv->child_count,__gf_calloc (sizeof (*erase_xattr), priv->child_count, gf_afr_mt_dict_t ) | |||
2491 | gf_afr_mt_dict_t)__gf_calloc (sizeof (*erase_xattr), priv->child_count, gf_afr_mt_dict_t ); | |||
2492 | if (!erase_xattr) | |||
2493 | goto out; | |||
2494 | ||||
2495 | for (i = 0; i < priv->child_count; i++) { | |||
2496 | if (sh->xattr[i]) { | |||
2497 | call_count++; | |||
2498 | erase_xattr[i] = dict_new (); | |||
2499 | if (!erase_xattr[i]) | |||
2500 | goto out; | |||
2501 | } | |||
2502 | } | |||
2503 | ||||
2504 | afr_sh_delta_to_xattr (this, sh->delta_matrix, erase_xattr, | |||
2505 | priv->child_count, type); | |||
2506 | ||||
2507 | gf_log (this->name, GF_LOG_DEBUG, "Delta matrix for: %s",do { do { if (0) printf ("Delta matrix for: %s", lkowner_utoa (&frame->root->lk_owner)); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 2508, GF_LOG_DEBUG , "Delta matrix for: %s", lkowner_utoa (&frame->root-> lk_owner)); } while (0) | |||
2508 | lkowner_utoa (&frame->root->lk_owner))do { do { if (0) printf ("Delta matrix for: %s", lkowner_utoa (&frame->root->lk_owner)); } while (0); _gf_log (this ->name, "afr-self-heal-common.c", __FUNCTION__, 2508, GF_LOG_DEBUG , "Delta matrix for: %s", lkowner_utoa (&frame->root-> lk_owner)); } while (0); | |||
2509 | afr_sh_print_pending_matrix (sh->delta_matrix, this); | |||
2510 | local->call_count = call_count; | |||
2511 | if (call_count == 0) { | |||
2512 | ret = 0; | |||
2513 | finish (frame, this); | |||
2514 | goto out; | |||
2515 | } | |||
2516 | ||||
2517 | for (i = 0; i < priv->child_count; i++) { | |||
2518 | if (!erase_xattr[i]) | |||
2519 | continue; | |||
2520 | ||||
2521 | if (sh->healing_fd) {//true for ENTRY, reg file DATA transaction | |||
2522 | STACK_WIND_COOKIE (frame, cbk, (void *) (long) i,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2527, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->fxattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->fxattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->fxattrop); priv-> children[i]->fops->fxattrop (_new, priv->children[i] , sh->healing_fd, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2523 | priv->children[i],do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2527, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->fxattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->fxattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->fxattrop); priv-> children[i]->fops->fxattrop (_new, priv->children[i] , sh->healing_fd, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2524 | priv->children[i]->fops->fxattrop,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2527, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->fxattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->fxattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->fxattrop); priv-> children[i]->fops->fxattrop (_new, priv->children[i] , sh->healing_fd, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2525 | sh->healing_fd,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2527, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->fxattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->fxattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->fxattrop); priv-> children[i]->fops->fxattrop (_new, priv->children[i] , sh->healing_fd, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2526 | GF_XATTROP_ADD_ARRAY, erase_xattr[i],do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2527, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->fxattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->fxattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->fxattrop); priv-> children[i]->fops->fxattrop (_new, priv->children[i] , sh->healing_fd, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2527 | NULL)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2527, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->fxattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->fxattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->fxattrop); priv-> children[i]->fops->fxattrop (_new, priv->children[i] , sh->healing_fd, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0); | |||
2528 | } else { | |||
2529 | STACK_WIND_COOKIE (frame, cbk, (void *) (long) i,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2534, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->xattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->xattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->xattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->xattrop); priv-> children[i]->fops->xattrop (_new, priv->children[i], &local->loc, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2530 | priv->children[i],do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2534, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->xattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->xattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->xattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->xattrop); priv-> children[i]->fops->xattrop (_new, priv->children[i], &local->loc, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2531 | priv->children[i]->fops->xattrop,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2534, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->xattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->xattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->xattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->xattrop); priv-> children[i]->fops->xattrop (_new, priv->children[i], &local->loc, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2532 | &local->loc,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2534, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->xattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->xattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->xattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->xattrop); priv-> children[i]->fops->xattrop (_new, priv->children[i], &local->loc, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2533 | GF_XATTROP_ADD_ARRAY, erase_xattr[i],do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2534, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->xattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->xattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->xattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->xattrop); priv-> children[i]->fops->xattrop (_new, priv->children[i], &local->loc, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||
2534 | NULL)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = (( void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool ); if (!_new) { do { do { if (0) printf ("alloc failed"); } while (0); _gf_log ("stack", "afr-self-heal-common.c", __FUNCTION__ , 2534, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof ( priv->children[i]->fops->xattrop_cbk) tmp_cbk = cbk ; _new->root = frame->root; _new->this = priv->children [i]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent = frame ; _new->cookie = (void *) (long) i; _new->wind_from = __FUNCTION__ ; _new->wind_to = "priv->children[i]->fops->xattrop" ; _new->unwind_to = "cbk"; pthread_spin_init (&_new-> lock, 0); pthread_spin_lock (&frame->root->stack_lock ); { frame->ref_count++; _new->next = frame->root-> frames.next; _new->prev = &frame->root->frames; if (frame->root->frames.next) frame->root->frames.next ->prev = _new; frame->root->frames.next = _new; } pthread_spin_unlock (&frame->root->stack_lock); priv->children[i]-> fops->xattrop_cbk = cbk; old_THIS = (*__glusterfs_this_location ()); (*__glusterfs_this_location()) = priv->children[i]; if (priv->children[i]->ctx->measure_latency) gf_latency_begin (_new, priv->children[i]->fops->xattrop); priv-> children[i]->fops->xattrop (_new, priv->children[i], &local->loc, GF_XATTROP_ADD_ARRAY, erase_xattr[i], (( void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0); | |||
2535 | } | |||
2536 | } | |||
2537 | ||||
2538 | ret = 0; | |||
2539 | out: | |||
2540 | if (erase_xattr) { | |||
2541 | for (i = 0; i < priv->child_count; i++) { | |||
2542 | if (erase_xattr[i]) { | |||
2543 | dict_unref (erase_xattr[i]); | |||
2544 | } | |||
2545 | } | |||
2546 | } | |||
2547 | ||||
2548 | GF_FREE (erase_xattr)__gf_free (erase_xattr); | |||
2549 | ||||
2550 | if (ret < 0) { | |||
2551 | sh->op_failed = _gf_true; | |||
2552 | finish (frame, this); | |||
2553 | } | |||
2554 | ||||
2555 | return 0; | |||
2556 | } |