Bug Summary

File:xlators/cluster/afr/src/afr-self-heal-data.c
Location:line 815, column 29
Description:Array access (from variable 'old_sources') results in a null pointer dereference

Annotated Source Code

1/*
2 Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
3 This file is part of GlusterFS.
4
5 This file is licensed to you under your choice of the GNU Lesser
6 General Public License, version 3 or any later version (LGPLv3 or
7 later), or the GNU General Public License, version 2 (GPLv2), in all
8 cases as published by the Free Software Foundation.
9*/
10
11#include <libgen.h>
12#include <unistd.h>
13#include <fnmatch.h>
14#include <sys/time.h>
15#include <stdlib.h>
16#include <signal.h>
17
18#ifndef _CONFIG_H
19#define _CONFIG_H
20#include "config.h"
21#endif
22
23#include "glusterfs.h"
24#include "afr.h"
25#include "dict.h"
26#include "xlator.h"
27#include "hashfn.h"
28#include "logging.h"
29#include "stack.h"
30#include "list.h"
31#include "call-stub.h"
32#include "defaults.h"
33#include "common-utils.h"
34#include "compat-errno.h"
35#include "compat.h"
36#include "byte-order.h"
37
38#include "afr-transaction.h"
39#include "afr-self-heal.h"
40#include "afr-self-heal-common.h"
41#include "afr-self-heal-algorithm.h"
42
43int
44afr_sh_data_fail (call_frame_t *frame, xlator_t *this);
45
46static inline gf_boolean_t
47afr_sh_data_proceed (unsigned int success_count)
48{
49 return (success_count >= AFR_SH_MIN_PARTICIPANTS2);
50}
51
52extern int
53sh_loop_finish (call_frame_t *loop_frame, xlator_t *this);
54
55int
56afr_post_sh_big_lock_success (call_frame_t *frame, xlator_t *this);
57
58int
59afr_post_sh_big_lock_failure (call_frame_t *frame, xlator_t *this);
60
61int
62afr_sh_data_finish (call_frame_t *frame, xlator_t *this);
63
64int
65afr_sh_data_done (call_frame_t *frame, xlator_t *this)
66{
67 afr_local_t *local = NULL((void*)0);
68 afr_self_heal_t *sh = NULL((void*)0);
69
70 local = frame->local;
71 sh = &local->self_heal;
72
73 sh->completion_cbk (frame, this);
74
75 return 0;
76}
77
78
79int
80afr_sh_data_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
81 int32_t op_ret, int32_t op_errno, dict_t *xdata)
82{
83 afr_local_t *local = NULL((void*)0);
84 afr_private_t *priv = NULL((void*)0);
85 int call_count = 0;
86 int child_index = (long) cookie;
87
88 local = frame->local;
89 priv = this->private;
90
91 LOCK (&frame->lock)pthread_spin_lock (&frame->lock);
92 {
93 if (op_ret == -1) {
94 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("flush failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 97, GF_LOG_ERROR, "flush failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
95 "flush failed on %s on subvolume %s: %s",do { do { if (0) printf ("flush failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 97, GF_LOG_ERROR, "flush failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
96 local->loc.path, priv->children[child_index]->name,do { do { if (0) printf ("flush failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 97, GF_LOG_ERROR, "flush failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
97 strerror (op_errno))do { do { if (0) printf ("flush failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 97, GF_LOG_ERROR, "flush failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
;
98 }
99 }
100 UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock);
101
102 call_count = afr_frame_return (frame);
103
104 if (call_count == 0) {
105 afr_sh_data_done (frame, this);
106 }
107
108 return 0;
109}
110
111int
112afr_sh_data_close (call_frame_t *frame, xlator_t *this)
113{
114 afr_local_t *local = NULL((void*)0);
115 afr_private_t *priv = NULL((void*)0);
116 afr_self_heal_t *sh = NULL((void*)0);
117 int i = 0;
118 int call_count = 0;
119
120 local = frame->local;
121 sh = &local->self_heal;
122 priv = this->private;
123
124 if (!sh->healing_fd) {
125 //This happens when file is non-reg
126 afr_sh_data_done (frame, this);
127 return 0;
128 }
129 call_count = afr_set_elem_count_get (sh->success,
130 priv->child_count);
131 local->call_count = call_count;
132
133 if (call_count == 0) {
134 afr_sh_data_done (frame, this);
135 return 0;
136 }
137
138 for (i = 0; i < priv->child_count; i++) {
139 if (!sh->success[i])
140 continue;
141 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("closing fd of %s on %s", local->
loc.path, priv->children[i]->name); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 143, GF_LOG_DEBUG
, "closing fd of %s on %s", local->loc.path, priv->children
[i]->name); } while (0)
142 "closing fd of %s on %s",do { do { if (0) printf ("closing fd of %s on %s", local->
loc.path, priv->children[i]->name); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 143, GF_LOG_DEBUG
, "closing fd of %s on %s", local->loc.path, priv->children
[i]->name); } while (0)
143 local->loc.path, priv->children[i]->name)do { do { if (0) printf ("closing fd of %s on %s", local->
loc.path, priv->children[i]->name); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 143, GF_LOG_DEBUG
, "closing fd of %s on %s", local->loc.path, priv->children
[i]->name); } while (0)
;
144
145 STACK_WIND_COOKIE (frame, afr_sh_data_flush_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-data.c", __FUNCTION__,
149, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->flush_cbk) tmp_cbk = afr_sh_data_flush_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->flush"
; _new->unwind_to = "afr_sh_data_flush_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->flush_cbk = afr_sh_data_flush_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->flush); priv->children[i]->fops->flush
(_new, priv->children[i], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
146 (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-data.c", __FUNCTION__,
149, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->flush_cbk) tmp_cbk = afr_sh_data_flush_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->flush"
; _new->unwind_to = "afr_sh_data_flush_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->flush_cbk = afr_sh_data_flush_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->flush); priv->children[i]->fops->flush
(_new, priv->children[i], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
147 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-data.c", __FUNCTION__,
149, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->flush_cbk) tmp_cbk = afr_sh_data_flush_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->flush"
; _new->unwind_to = "afr_sh_data_flush_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->flush_cbk = afr_sh_data_flush_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->flush); priv->children[i]->fops->flush
(_new, priv->children[i], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
148 priv->children[i]->fops->flush,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-data.c", __FUNCTION__,
149, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->flush_cbk) tmp_cbk = afr_sh_data_flush_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->flush"
; _new->unwind_to = "afr_sh_data_flush_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->flush_cbk = afr_sh_data_flush_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->flush); priv->children[i]->fops->flush
(_new, priv->children[i], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
149 sh->healing_fd, 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-data.c", __FUNCTION__,
149, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->flush_cbk) tmp_cbk = afr_sh_data_flush_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->flush"
; _new->unwind_to = "afr_sh_data_flush_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->flush_cbk = afr_sh_data_flush_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->flush); priv->children[i]->fops->flush
(_new, priv->children[i], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
;
150
151 if (!--call_count)
152 break;
153 }
154
155 return 0;
156}
157
158int
159afr_sh_data_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
160 int32_t op_ret, int32_t op_errno, struct iatt *statpre,
161 struct iatt *statpost, dict_t *xdata)
162{
163
164 afr_local_t *local = NULL((void*)0);
165 afr_private_t *priv = NULL((void*)0);
166 int call_count = 0;
167 int child_index = (long) cookie;
168
169 local = frame->local;
170 priv = this->private;
171
172 LOCK (&frame->lock)pthread_spin_lock (&frame->lock);
173 {
174 if (op_ret == -1) {
175 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("setattr failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 178, GF_LOG_INFO, "setattr failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
176 "setattr failed on %s on subvolume %s: %s",do { do { if (0) printf ("setattr failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 178, GF_LOG_INFO, "setattr failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
177 local->loc.path, priv->children[child_index]->name,do { do { if (0) printf ("setattr failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 178, GF_LOG_INFO, "setattr failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
178 strerror (op_errno))do { do { if (0) printf ("setattr failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 178, GF_LOG_INFO, "setattr failed on %s on subvolume %s: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
;
179 }
180 }
181 UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock);
182
183 call_count = afr_frame_return (frame);
184
185 if (call_count == 0) {
186 afr_sh_data_finish (frame, this);
187 }
188
189 return 0;
190}
191
192int
193afr_sh_data_setattr (call_frame_t *frame, xlator_t *this, struct iatt* stbuf)
194{
195 afr_local_t *local = NULL((void*)0);
196 afr_private_t *priv = NULL((void*)0);
197 afr_self_heal_t *sh = NULL((void*)0);
198 int i = 0;
199 int call_count = 0;
200 int32_t valid = 0;
201
202 local = frame->local;
203 sh = &local->self_heal;
204 priv = this->private;
205
206 valid = (GF_SET_ATTR_ATIME0x10 | GF_SET_ATTR_MTIME0x20);
207
208 call_count = afr_set_elem_count_get (sh->success,
209 priv->child_count);
210 local->call_count = call_count;
211
212 if (call_count == 0) {
213 GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: "
"0"); } while (0); _gf_log_callingfn ("", "afr-self-heal-data.c"
, __FUNCTION__, 213, GF_LOG_ERROR, "Assertion failed: " "0");
} while (0); } } while (0)
;
214 afr_sh_data_finish (frame, this);
215 return 0;
216 }
217
218 for (i = 0; i < priv->child_count; i++) {
219 if (!sh->success[i])
220 continue;
221
222 STACK_WIND_COOKIE (frame, afr_sh_data_setattr_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-data.c", __FUNCTION__,
226, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->setattr_cbk) tmp_cbk = afr_sh_data_setattr_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->setattr"
; _new->unwind_to = "afr_sh_data_setattr_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->setattr_cbk = afr_sh_data_setattr_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->setattr); priv->children[i]->fops->setattr
(_new, priv->children[i], &local->loc, stbuf, valid
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
223 (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-data.c", __FUNCTION__,
226, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->setattr_cbk) tmp_cbk = afr_sh_data_setattr_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->setattr"
; _new->unwind_to = "afr_sh_data_setattr_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->setattr_cbk = afr_sh_data_setattr_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->setattr); priv->children[i]->fops->setattr
(_new, priv->children[i], &local->loc, stbuf, valid
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
224 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-data.c", __FUNCTION__,
226, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->setattr_cbk) tmp_cbk = afr_sh_data_setattr_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->setattr"
; _new->unwind_to = "afr_sh_data_setattr_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->setattr_cbk = afr_sh_data_setattr_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->setattr); priv->children[i]->fops->setattr
(_new, priv->children[i], &local->loc, stbuf, valid
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
225 priv->children[i]->fops->setattr,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-data.c", __FUNCTION__,
226, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->setattr_cbk) tmp_cbk = afr_sh_data_setattr_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->setattr"
; _new->unwind_to = "afr_sh_data_setattr_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->setattr_cbk = afr_sh_data_setattr_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->setattr); priv->children[i]->fops->setattr
(_new, priv->children[i], &local->loc, stbuf, valid
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
226 &local->loc, stbuf, valid, 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-data.c", __FUNCTION__,
226, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->setattr_cbk) tmp_cbk = afr_sh_data_setattr_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->setattr"
; _new->unwind_to = "afr_sh_data_setattr_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->setattr_cbk = afr_sh_data_setattr_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->setattr); priv->children[i]->fops->setattr
(_new, priv->children[i], &local->loc, stbuf, valid
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
;
227
228 if (!--call_count)
229 break;
230 }
231
232 return 0;
233}
234
235int
236afr_sh_data_setattr_fstat_cbk (call_frame_t *frame, void *cookie,
237 xlator_t *this, int32_t op_ret, int32_t op_errno,
238 struct iatt *buf, dict_t *xdata)
239{
240 afr_local_t *local = NULL((void*)0);
241 afr_self_heal_t *sh = NULL((void*)0);
242 int child_index = (long) cookie;
243
244 local = frame->local;
245 sh = &local->self_heal;
246
247 GF_ASSERT (sh->source == child_index)do { if (!(sh->source == child_index)) { do { do { if (0) printf
("Assertion failed: " "sh->source == child_index"); } while
(0); _gf_log_callingfn ("", "afr-self-heal-data.c", __FUNCTION__
, 247, GF_LOG_ERROR, "Assertion failed: " "sh->source == child_index"
); } while (0); } } while (0)
;
248 if (op_ret != -1) {
249 sh->buf[child_index] = *buf;
250 afr_sh_data_setattr (frame, this, buf);
251 } else {
252 gf_log (this->name, GF_LOG_ERROR, "%s: Failed to set "do { do { if (0) printf ("%s: Failed to set " "time-stamps after self-heal"
, local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 253, GF_LOG_ERROR, "%s: Failed to set " "time-stamps after self-heal"
, local->loc.path); } while (0)
253 "time-stamps after self-heal", local->loc.path)do { do { if (0) printf ("%s: Failed to set " "time-stamps after self-heal"
, local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 253, GF_LOG_ERROR, "%s: Failed to set " "time-stamps after self-heal"
, local->loc.path); } while (0)
;
254 afr_sh_data_fail (frame, this);
255 }
256
257 return 0;
258}
259
260/*
261 * If there are any writes after the self-heal is triggered then the
262 * stbuf stored in local->self_heal.buf[] will be invalid so we do one more
263 * stat on the source and then set the [am]times
264 */
265int
266afr_sh_set_timestamps (call_frame_t *frame, xlator_t *this)
267{
268 afr_local_t *local = NULL((void*)0);
269 afr_private_t *priv = NULL((void*)0);
270 afr_self_heal_t *sh = NULL((void*)0);
271
272 local = frame->local;
273 sh = &local->self_heal;
274 priv = this->private;
275
276 STACK_WIND_COOKIE (frame, afr_sh_data_setattr_fstat_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-data.c", __FUNCTION__,
280, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[sh->source]->fops->fstat_cbk) tmp_cbk
= afr_sh_data_setattr_fstat_cbk; _new->root = frame->root
; _new->this = priv->children[sh->source]; _new->
ret = (ret_fn_t) tmp_cbk; _new->parent = frame; _new->cookie
= (void *) (long) sh->source; _new->wind_from = __FUNCTION__
; _new->wind_to = "priv->children[sh->source]->fops->fstat"
; _new->unwind_to = "afr_sh_data_setattr_fstat_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[sh->source]->fops->fstat_cbk = afr_sh_data_setattr_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[sh->source]; if (priv->children
[sh->source]->ctx->measure_latency) gf_latency_begin
(_new, priv->children[sh->source]->fops->fstat);
priv->children[sh->source]->fops->fstat (_new, priv
->children[sh->source], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
277 (void *) (long) sh->source,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-data.c", __FUNCTION__,
280, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[sh->source]->fops->fstat_cbk) tmp_cbk
= afr_sh_data_setattr_fstat_cbk; _new->root = frame->root
; _new->this = priv->children[sh->source]; _new->
ret = (ret_fn_t) tmp_cbk; _new->parent = frame; _new->cookie
= (void *) (long) sh->source; _new->wind_from = __FUNCTION__
; _new->wind_to = "priv->children[sh->source]->fops->fstat"
; _new->unwind_to = "afr_sh_data_setattr_fstat_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[sh->source]->fops->fstat_cbk = afr_sh_data_setattr_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[sh->source]; if (priv->children
[sh->source]->ctx->measure_latency) gf_latency_begin
(_new, priv->children[sh->source]->fops->fstat);
priv->children[sh->source]->fops->fstat (_new, priv
->children[sh->source], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
278 priv->children[sh->source],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-data.c", __FUNCTION__,
280, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[sh->source]->fops->fstat_cbk) tmp_cbk
= afr_sh_data_setattr_fstat_cbk; _new->root = frame->root
; _new->this = priv->children[sh->source]; _new->
ret = (ret_fn_t) tmp_cbk; _new->parent = frame; _new->cookie
= (void *) (long) sh->source; _new->wind_from = __FUNCTION__
; _new->wind_to = "priv->children[sh->source]->fops->fstat"
; _new->unwind_to = "afr_sh_data_setattr_fstat_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[sh->source]->fops->fstat_cbk = afr_sh_data_setattr_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[sh->source]; if (priv->children
[sh->source]->ctx->measure_latency) gf_latency_begin
(_new, priv->children[sh->source]->fops->fstat);
priv->children[sh->source]->fops->fstat (_new, priv
->children[sh->source], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
279 priv->children[sh->source]->fops->fstat,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-data.c", __FUNCTION__,
280, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[sh->source]->fops->fstat_cbk) tmp_cbk
= afr_sh_data_setattr_fstat_cbk; _new->root = frame->root
; _new->this = priv->children[sh->source]; _new->
ret = (ret_fn_t) tmp_cbk; _new->parent = frame; _new->cookie
= (void *) (long) sh->source; _new->wind_from = __FUNCTION__
; _new->wind_to = "priv->children[sh->source]->fops->fstat"
; _new->unwind_to = "afr_sh_data_setattr_fstat_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[sh->source]->fops->fstat_cbk = afr_sh_data_setattr_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[sh->source]; if (priv->children
[sh->source]->ctx->measure_latency) gf_latency_begin
(_new, priv->children[sh->source]->fops->fstat);
priv->children[sh->source]->fops->fstat (_new, priv
->children[sh->source], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
280 sh->healing_fd, 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-data.c", __FUNCTION__,
280, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[sh->source]->fops->fstat_cbk) tmp_cbk
= afr_sh_data_setattr_fstat_cbk; _new->root = frame->root
; _new->this = priv->children[sh->source]; _new->
ret = (ret_fn_t) tmp_cbk; _new->parent = frame; _new->cookie
= (void *) (long) sh->source; _new->wind_from = __FUNCTION__
; _new->wind_to = "priv->children[sh->source]->fops->fstat"
; _new->unwind_to = "afr_sh_data_setattr_fstat_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[sh->source]->fops->fstat_cbk = afr_sh_data_setattr_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[sh->source]; if (priv->children
[sh->source]->ctx->measure_latency) gf_latency_begin
(_new, priv->children[sh->source]->fops->fstat);
priv->children[sh->source]->fops->fstat (_new, priv
->children[sh->source], sh->healing_fd, ((void*)0));
(*__glusterfs_this_location()) = old_THIS; } while (0)
;
281 return 0;
282}
283
284//Fun fact, lock_cbk is being used for both lock & unlock
285int
286afr_sh_data_unlock (call_frame_t *frame, xlator_t *this,
287 afr_lock_cbk_t lock_cbk)
288{
289 afr_local_t *local = NULL((void*)0);
290 afr_internal_lock_t *int_lock = NULL((void*)0);
291 afr_self_heal_t *sh = NULL((void*)0);
292
293 local = frame->local;
294 int_lock = &local->internal_lock;
295 sh = &local->self_heal;
296
297 GF_ASSERT (sh->data_lock_held)do { if (!(sh->data_lock_held)) { do { do { if (0) printf (
"Assertion failed: " "sh->data_lock_held"); } while (0); _gf_log_callingfn
("", "afr-self-heal-data.c", __FUNCTION__, 297, GF_LOG_ERROR
, "Assertion failed: " "sh->data_lock_held"); } while (0);
} } while (0)
;
298
299 sh->data_lock_held = _gf_false;
300 int_lock->lock_cbk = lock_cbk;
301 afr_unlock (frame, this);
302
303 return 0;
304}
305
306int
307afr_sh_data_finish (call_frame_t *frame, xlator_t *this)
308{
309 afr_local_t *local = NULL((void*)0);
310 afr_self_heal_t *sh = NULL((void*)0);
311
312 local = frame->local;
313 sh = &local->self_heal;
314
315 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("finishing data selfheal of %s", local
->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 316, GF_LOG_DEBUG, "finishing data selfheal of %s"
, local->loc.path); } while (0)
316 "finishing data selfheal of %s", local->loc.path)do { do { if (0) printf ("finishing data selfheal of %s", local
->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 316, GF_LOG_DEBUG, "finishing data selfheal of %s"
, local->loc.path); } while (0)
;
317
318 if (sh->data_lock_held)
319 afr_sh_data_unlock (frame, this, afr_sh_data_close);
320 else
321 afr_sh_data_close (frame, this);
322
323 return 0;
324}
325
326int
327afr_sh_data_fail (call_frame_t *frame, xlator_t *this)
328{
329 afr_local_t *local = NULL((void*)0);
330 afr_self_heal_t *sh = NULL((void*)0);
331
332 local = frame->local;
333 sh = &local->self_heal;
334
335 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("finishing failed data selfheal of %s"
, local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 336, GF_LOG_DEBUG, "finishing failed data selfheal of %s"
, local->loc.path); } while (0)
336 "finishing failed data selfheal of %s", local->loc.path)do { do { if (0) printf ("finishing failed data selfheal of %s"
, local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 336, GF_LOG_DEBUG, "finishing failed data selfheal of %s"
, local->loc.path); } while (0)
;
337
338 sh->op_failed = 1;
339 if (sh->data_lock_held)
340 afr_sh_data_unlock (frame, this, afr_sh_data_close);
341 else
342 afr_sh_data_close (frame, this);
343 return 0;
344}
345
346int
347afr_sh_data_erase_pending_cbk (call_frame_t *frame, void *cookie,
348 xlator_t *this, int32_t op_ret,
349 int32_t op_errno, dict_t *xattr, dict_t *xdata)
350{
351 int call_count = 0;
352 afr_local_t *local = NULL((void*)0);
353 afr_self_heal_t *sh = NULL((void*)0);
354 afr_private_t *priv = NULL((void*)0);
355 int32_t child_index = (long) cookie;
356
357 priv = this->private;
358 local = frame->local;
359 sh = &local->self_heal;
360 if (op_ret < 0) {
361 gf_log (this->name, GF_LOG_ERROR, "Erasing of pending change "do { do { if (0) printf ("Erasing of pending change " "log failed on %s for subvol %s, reason: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 364, GF_LOG_ERROR, "Erasing of pending change "
"log failed on %s for subvol %s, reason: %s", local->loc.
path, priv->children[child_index]->name, strerror (op_errno
)); } while (0)
362 "log failed on %s for subvol %s, reason: %s",do { do { if (0) printf ("Erasing of pending change " "log failed on %s for subvol %s, reason: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 364, GF_LOG_ERROR, "Erasing of pending change "
"log failed on %s for subvol %s, reason: %s", local->loc.
path, priv->children[child_index]->name, strerror (op_errno
)); } while (0)
363 local->loc.path, priv->children[child_index]->name,do { do { if (0) printf ("Erasing of pending change " "log failed on %s for subvol %s, reason: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 364, GF_LOG_ERROR, "Erasing of pending change "
"log failed on %s for subvol %s, reason: %s", local->loc.
path, priv->children[child_index]->name, strerror (op_errno
)); } while (0)
364 strerror (op_errno))do { do { if (0) printf ("Erasing of pending change " "log failed on %s for subvol %s, reason: %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 364, GF_LOG_ERROR, "Erasing of pending change "
"log failed on %s for subvol %s, reason: %s", local->loc.
path, priv->children[child_index]->name, strerror (op_errno
)); } while (0)
;
365 sh->op_failed = 1;
366 }
367
368 call_count = afr_frame_return (frame);
369
370 if (call_count == 0) {
371 if (sh->op_failed) {
372 if (sh->old_loop_frame)
373 sh_loop_finish (sh->old_loop_frame, this);
374 sh->old_loop_frame = NULL((void*)0);
375 afr_sh_data_fail (frame, this);
376 goto out;
377 }
378 if (!IA_ISREG (sh->type)(sh->type == IA_IFREG)) {
379 afr_sh_data_finish (frame, this);
380 goto out;
381 }
382 GF_ASSERT (sh->old_loop_frame)do { if (!(sh->old_loop_frame)) { do { do { if (0) printf (
"Assertion failed: " "sh->old_loop_frame"); } while (0); _gf_log_callingfn
("", "afr-self-heal-data.c", __FUNCTION__, 382, GF_LOG_ERROR
, "Assertion failed: " "sh->old_loop_frame"); } while (0);
} } while (0)
;
383 afr_sh_data_lock (frame, this, 0, 0, _gf_true,
384 afr_post_sh_big_lock_success,
385 afr_post_sh_big_lock_failure);
386 }
387out:
388 return 0;
389}
390
391int
392afr_sh_data_erase_pending (call_frame_t *frame, xlator_t *this)
393{
394 afr_sh_erase_pending (frame, this, AFR_DATA_TRANSACTION,
395 afr_sh_data_erase_pending_cbk,
396 afr_sh_data_finish);
397 return 0;
398}
399
400int
401afr_sh_data_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
402 int op_ret, int op_errno, struct iatt *pre,
403 struct iatt *post, dict_t *xdata)
404{
405 afr_local_t *local = NULL((void*)0);
406 afr_private_t *priv = NULL((void*)0);
407 afr_self_heal_t *sh = NULL((void*)0);
408 int call_count = 0;
409 int child_index = (long) cookie;
410
411 local = frame->local;
412 priv = this->private;
413 sh = &local->self_heal;
414
415 if (op_ret < 0) {
416 gf_log (this->name, GF_LOG_ERROR, "%s: Failed to fsync on "do { do { if (0) printf ("%s: Failed to fsync on " "%s - %s",
local->loc.path, priv->children[child_index]->name,
strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 418, GF_LOG_ERROR, "%s: Failed to fsync on " "%s - %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
417 "%s - %s", local->loc.path,do { do { if (0) printf ("%s: Failed to fsync on " "%s - %s",
local->loc.path, priv->children[child_index]->name,
strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 418, GF_LOG_ERROR, "%s: Failed to fsync on " "%s - %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
418 priv->children[child_index]->name, strerror (op_errno))do { do { if (0) printf ("%s: Failed to fsync on " "%s - %s",
local->loc.path, priv->children[child_index]->name,
strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 418, GF_LOG_ERROR, "%s: Failed to fsync on " "%s - %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
;
419 LOCK (&frame->lock)pthread_spin_lock (&frame->lock);
420 {
421 sh->op_failed = 1;
422 }
423 UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock);
424 if (sh->old_loop_frame)
425 sh_loop_finish (sh->old_loop_frame, this);
426 sh->old_loop_frame = NULL((void*)0);
427 }
428
429 call_count = afr_frame_return (frame);
430 if (call_count == 0) {
431 if (sh->op_failed)
432 afr_sh_data_fail (frame, this);
433 else
434 afr_sh_data_erase_pending (frame, this);
435 }
436 return 0;
437}
438
439/*
440 * Before erasing xattrs, make sure the data is written to disk
441 */
442int
443afr_sh_data_fsync (call_frame_t *frame, xlator_t *this)
444{
445 afr_local_t *local = NULL((void*)0);
446 afr_private_t *priv = NULL((void*)0);
447 afr_self_heal_t *sh = NULL((void*)0);
448 int i = 0;
449 int call_count = 0;
450
451 local = frame->local;
452 priv = this->private;
453 sh = &local->self_heal;
454
455 call_count = sh->active_sinks;
456 if (call_count == 0) {
457 afr_sh_data_erase_pending (frame, this);
458 return 0;
459 }
460
461 local->call_count = call_count;
462 for (i = 0; i < priv->child_count; i++) {
463 if (!sh->success[i] || sh->sources[i])
464 continue;
465
466 STACK_WIND_COOKIE (frame, afr_sh_data_fsync_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-data.c", __FUNCTION__,
469, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fsync_cbk) tmp_cbk = afr_sh_data_fsync_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->fsync"
; _new->unwind_to = "afr_sh_data_fsync_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->fsync_cbk = afr_sh_data_fsync_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->fsync); priv->children[i]->fops->fsync
(_new, priv->children[i], sh->healing_fd, 1, ((void*)0
)); (*__glusterfs_this_location()) = old_THIS; } while (0)
467 (void *) (long) i, 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-data.c", __FUNCTION__,
469, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fsync_cbk) tmp_cbk = afr_sh_data_fsync_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->fsync"
; _new->unwind_to = "afr_sh_data_fsync_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->fsync_cbk = afr_sh_data_fsync_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->fsync); priv->children[i]->fops->fsync
(_new, priv->children[i], sh->healing_fd, 1, ((void*)0
)); (*__glusterfs_this_location()) = old_THIS; } while (0)
468 priv->children[i]->fops->fsync,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-data.c", __FUNCTION__,
469, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fsync_cbk) tmp_cbk = afr_sh_data_fsync_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->fsync"
; _new->unwind_to = "afr_sh_data_fsync_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->fsync_cbk = afr_sh_data_fsync_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->fsync); priv->children[i]->fops->fsync
(_new, priv->children[i], sh->healing_fd, 1, ((void*)0
)); (*__glusterfs_this_location()) = old_THIS; } while (0)
469 sh->healing_fd, 1, 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-data.c", __FUNCTION__,
469, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fsync_cbk) tmp_cbk = afr_sh_data_fsync_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->fsync"
; _new->unwind_to = "afr_sh_data_fsync_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->fsync_cbk = afr_sh_data_fsync_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->fsync); priv->children[i]->fops->fsync
(_new, priv->children[i], sh->healing_fd, 1, ((void*)0
)); (*__glusterfs_this_location()) = old_THIS; } while (0)
;
470 }
471
472 return 0;
473}
474
475static struct afr_sh_algorithm *
476sh_algo_from_name (xlator_t *this, char *name)
477{
478 int i = 0;
479
480 if (name == NULL((void*)0))
481 goto out;
482
483 while (afr_self_heal_algorithms[i].name) {
484 if (!strcmp (name, afr_self_heal_algorithms[i].name)) {
485 return &afr_self_heal_algorithms[i];
486 }
487
488 i++;
489 }
490
491out:
492 return NULL((void*)0);
493}
494
495
496static int
497sh_zero_byte_files_exist (afr_local_t *local, int child_count)
498{
499 int i = 0;
500 int ret = 0;
501 afr_self_heal_t *sh = NULL((void*)0);
502
503 sh = &local->self_heal;
504 for (i = 0; i < child_count; i++) {
505 if (!local->child_up[i] || sh->child_errno[i])
506 continue;
507 if (sh->buf[i].ia_size == 0) {
508 ret = 1;
509 break;
510 }
511 }
512
513 return ret;
514}
515
516
517struct afr_sh_algorithm *
518afr_sh_data_pick_algo (call_frame_t *frame, xlator_t *this)
519{
520 afr_private_t * priv = NULL((void*)0);
521 struct afr_sh_algorithm * algo = NULL((void*)0);
522 afr_local_t * local = NULL((void*)0);
523 afr_self_heal_t * sh = NULL((void*)0);
524
525 priv = this->private;
526 local = frame->local;
527 sh = &local->self_heal;
528 algo = sh_algo_from_name (this, priv->data_self_heal_algorithm);
529
530 if (algo == NULL((void*)0)) {
531 /* option not set, so fall back on heuristics */
532
533 if (sh_zero_byte_files_exist (local, priv->child_count)
534 || (sh->file_size <= (priv->data_self_heal_window_size *
535 this->ctx->page_size))) {
536
537 /*
538 * If the file does not exist on one of the subvolumes,
539 * or a zero-byte file exists (created by entry self-heal)
540 * the entire content has to be copied anyway, so there
541 * is no benefit from using the "diff" algorithm.
542 *
543 * If the file size is about the same as page size,
544 * the entire file can be read and written with a few
545 * (pipelined) STACK_WINDs, which will be faster
546 * than "diff" which has to read checksums and then
547 * read and write.
548 */
549
550 algo = sh_algo_from_name (this, "full");
551
552 } else {
553 algo = sh_algo_from_name (this, "diff");
554 }
555 }
556
557 return algo;
558}
559
560
561int
562afr_sh_data_sync_prepare (call_frame_t *frame, xlator_t *this)
563{
564 afr_local_t *local = NULL((void*)0);
565 afr_self_heal_t *sh = NULL((void*)0);
566 struct afr_sh_algorithm *sh_algo = NULL((void*)0);
567
568 local = frame->local;
569 sh = &local->self_heal;
570
571 sh->algo_completion_cbk = afr_sh_data_fsync;
572 sh->algo_abort_cbk = afr_sh_data_fail;
573
574 sh_algo = afr_sh_data_pick_algo (frame, this);
575
576 sh->algo = sh_algo;
577 sh_algo->fn (frame, this);
578
579 return 0;
580}
581
582int
583afr_sh_data_trim_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
584 int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
585 struct iatt *postbuf, dict_t *xdata)
586{
587 int call_count = 0;
588 int child_index = 0;
589 afr_private_t *priv = NULL((void*)0);
590 afr_local_t *local = NULL((void*)0);
591 afr_self_heal_t *sh = NULL((void*)0);
592
593 priv = this->private;
594 local = frame->local;
595 sh = &local->self_heal;
596
597 child_index = (long) cookie;
598
599 LOCK (&frame->lock)pthread_spin_lock (&frame->lock);
600 {
601 if (op_ret == -1) {
602 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 606, GF_LOG_ERROR, "ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
603 "ftruncate of %s on subvolume %s failed (%s)",do { do { if (0) printf ("ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 606, GF_LOG_ERROR, "ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
604 local->loc.path,do { do { if (0) printf ("ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 606, GF_LOG_ERROR, "ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
605 priv->children[child_index]->name,do { do { if (0) printf ("ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 606, GF_LOG_ERROR, "ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
606 strerror (op_errno))do { do { if (0) printf ("ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 606, GF_LOG_ERROR, "ftruncate of %s on subvolume %s failed (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
;
607 sh->op_failed = 1;
608 } else {
609 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("ftruncate of %s on subvolume %s completed"
, local->loc.path, priv->children[child_index]->name
); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 612, GF_LOG_DEBUG, "ftruncate of %s on subvolume %s completed"
, local->loc.path, priv->children[child_index]->name
); } while (0)
610 "ftruncate of %s on subvolume %s completed",do { do { if (0) printf ("ftruncate of %s on subvolume %s completed"
, local->loc.path, priv->children[child_index]->name
); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 612, GF_LOG_DEBUG, "ftruncate of %s on subvolume %s completed"
, local->loc.path, priv->children[child_index]->name
); } while (0)
611 local->loc.path,do { do { if (0) printf ("ftruncate of %s on subvolume %s completed"
, local->loc.path, priv->children[child_index]->name
); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 612, GF_LOG_DEBUG, "ftruncate of %s on subvolume %s completed"
, local->loc.path, priv->children[child_index]->name
); } while (0)
612 priv->children[child_index]->name)do { do { if (0) printf ("ftruncate of %s on subvolume %s completed"
, local->loc.path, priv->children[child_index]->name
); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 612, GF_LOG_DEBUG, "ftruncate of %s on subvolume %s completed"
, local->loc.path, priv->children[child_index]->name
); } while (0)
;
613 }
614 }
615 UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock);
616
617 call_count = afr_frame_return (frame);
618
619 if (call_count == 0) {
620 if (sh->op_failed)
621 afr_sh_data_fail (frame, this);
622 else
623 afr_sh_data_sync_prepare (frame, this);
624 }
625
626 return 0;
627}
628
629
630int
631afr_sh_data_trim_sinks (call_frame_t *frame, xlator_t *this)
632{
633 afr_private_t * priv = NULL((void*)0);
634 afr_local_t * local = NULL((void*)0);
635 afr_self_heal_t *sh = NULL((void*)0);
636 int *sources = NULL((void*)0);
637 int call_count = 0;
638 int i = 0;
639
640
641 priv = this->private;
642 local = frame->local;
643 sh = &local->self_heal;
644
645 sources = sh->sources;
646 call_count = sh->active_sinks;
647
648 local->call_count = call_count;
649
650 for (i = 0; i < priv->child_count; i++) {
651 if (sources[i] || !local->child_up[i])
652 continue;
653
654 STACK_WIND_COOKIE (frame, afr_sh_data_trim_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-data.c", __FUNCTION__,
659, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->ftruncate_cbk) tmp_cbk = afr_sh_data_trim_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->ftruncate"
; _new->unwind_to = "afr_sh_data_trim_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->ftruncate_cbk = afr_sh_data_trim_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->ftruncate); priv->children[i]->fops->ftruncate
(_new, priv->children[i], sh->healing_fd, sh->file_size
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
655 (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-data.c", __FUNCTION__,
659, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->ftruncate_cbk) tmp_cbk = afr_sh_data_trim_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->ftruncate"
; _new->unwind_to = "afr_sh_data_trim_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->ftruncate_cbk = afr_sh_data_trim_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->ftruncate); priv->children[i]->fops->ftruncate
(_new, priv->children[i], sh->healing_fd, sh->file_size
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
656 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-data.c", __FUNCTION__,
659, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->ftruncate_cbk) tmp_cbk = afr_sh_data_trim_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->ftruncate"
; _new->unwind_to = "afr_sh_data_trim_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->ftruncate_cbk = afr_sh_data_trim_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->ftruncate); priv->children[i]->fops->ftruncate
(_new, priv->children[i], sh->healing_fd, sh->file_size
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
657 priv->children[i]->fops->ftruncate,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-data.c", __FUNCTION__,
659, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->ftruncate_cbk) tmp_cbk = afr_sh_data_trim_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->ftruncate"
; _new->unwind_to = "afr_sh_data_trim_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->ftruncate_cbk = afr_sh_data_trim_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->ftruncate); priv->children[i]->fops->ftruncate
(_new, priv->children[i], sh->healing_fd, sh->file_size
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
658 sh->healing_fd, sh->file_size,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-data.c", __FUNCTION__,
659, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->ftruncate_cbk) tmp_cbk = afr_sh_data_trim_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->ftruncate"
; _new->unwind_to = "afr_sh_data_trim_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->ftruncate_cbk = afr_sh_data_trim_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->ftruncate); priv->children[i]->fops->ftruncate
(_new, priv->children[i], sh->healing_fd, sh->file_size
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
659 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-data.c", __FUNCTION__,
659, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->ftruncate_cbk) tmp_cbk = afr_sh_data_trim_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->ftruncate"
; _new->unwind_to = "afr_sh_data_trim_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->ftruncate_cbk = afr_sh_data_trim_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->ftruncate); priv->children[i]->fops->ftruncate
(_new, priv->children[i], sh->healing_fd, sh->file_size
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
;
660
661 if (!--call_count)
662 break;
663 }
664
665 return 0;
666}
667
668int
669afr_sh_inode_set_read_ctx (afr_self_heal_t *sh, xlator_t *this)
670{
671 afr_private_t *priv = NULL((void*)0);
672 int ret = 0;
673 int i = 0;
674
675 priv = this->private;
676 sh->source = afr_sh_select_source (sh->sources, priv->child_count);
677 if (sh->source < 0) {
678 ret = -1;
679 goto out;
680 }
681
682 /* detect changes not visible through pending flags -- JIC */
683 for (i = 0; i < priv->child_count; i++) {
684 if (i == sh->source || sh->child_errno[i])
685 continue;
686
687 if (SIZE_DIFFERS (&sh->buf[i], &sh->buf[sh->source])((&sh->buf[i])->ia_size != (&sh->buf[sh->
source])->ia_size)
)
688 sh->sources[i] = 0;
689 }
690
691 afr_reset_children (sh->fresh_children, priv->child_count);
692 afr_get_fresh_children (sh->success_children, sh->sources,
693 sh->fresh_children, priv->child_count);
694 afr_inode_set_read_ctx (this, sh->inode, sh->source,
695 sh->fresh_children);
696out:
697 return ret;
698}
699
700void
701afr_sh_data_fix (call_frame_t *frame, xlator_t *this)
702{
703 int source = 0;
704 afr_local_t *local = NULL((void*)0);
705 afr_self_heal_t *sh = NULL((void*)0);
706 afr_private_t *priv = NULL((void*)0);
707
708 local = frame->local;
709 sh = &local->self_heal;
710 priv = this->private;
711
712 source = sh->source;
713 sh->block_size = this->ctx->page_size;
714 sh->file_size = sh->buf[source].ia_size;
715
716 if (FILE_HAS_HOLES (&sh->buf[source])(((&sh->buf[source])->ia_size) > ((&sh->buf
[source])->ia_blocks * 512))
)
717 sh->file_has_holes = 1;
718
719 if (sh->background && sh->unwind && !sh->unwound) {
720 sh->unwind (sh->orig_frame, this, sh->op_ret, sh->op_errno,
721 sh->op_failed);
722 sh->unwound = _gf_true;
723 }
724
725 afr_sh_mark_source_sinks (frame, this);
726 if (sh->active_sinks == 0) {
727 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("no active sinks for performing self-heal on file %s"
, local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 729, GF_LOG_INFO, "no active sinks for performing self-heal on file %s"
, local->loc.path); } while (0)
728 "no active sinks for performing self-heal on file %s",do { do { if (0) printf ("no active sinks for performing self-heal on file %s"
, local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 729, GF_LOG_INFO, "no active sinks for performing self-heal on file %s"
, local->loc.path); } while (0)
729 local->loc.path)do { do { if (0) printf ("no active sinks for performing self-heal on file %s"
, local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 729, GF_LOG_INFO, "no active sinks for performing self-heal on file %s"
, local->loc.path); } while (0)
;
730 afr_sh_data_finish (frame, this);
731 return;
732 }
733
734 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("self-healing file %s from subvolume %s to %d other"
, local->loc.path, priv->children[sh->source]->name
, sh->active_sinks); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 737, GF_LOG_DEBUG, "self-healing file %s from subvolume %s to %d other"
, local->loc.path, priv->children[sh->source]->name
, sh->active_sinks); } while (0)
735 "self-healing file %s from subvolume %s to %d other",do { do { if (0) printf ("self-healing file %s from subvolume %s to %d other"
, local->loc.path, priv->children[sh->source]->name
, sh->active_sinks); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 737, GF_LOG_DEBUG, "self-healing file %s from subvolume %s to %d other"
, local->loc.path, priv->children[sh->source]->name
, sh->active_sinks); } while (0)
736 local->loc.path, priv->children[sh->source]->name,do { do { if (0) printf ("self-healing file %s from subvolume %s to %d other"
, local->loc.path, priv->children[sh->source]->name
, sh->active_sinks); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 737, GF_LOG_DEBUG, "self-healing file %s from subvolume %s to %d other"
, local->loc.path, priv->children[sh->source]->name
, sh->active_sinks); } while (0)
737 sh->active_sinks)do { do { if (0) printf ("self-healing file %s from subvolume %s to %d other"
, local->loc.path, priv->children[sh->source]->name
, sh->active_sinks); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 737, GF_LOG_DEBUG, "self-healing file %s from subvolume %s to %d other"
, local->loc.path, priv->children[sh->source]->name
, sh->active_sinks); } while (0)
;
738
739 sh->actual_sh_started = _gf_true;
740 afr_sh_data_trim_sinks (frame, this);
741}
742
743int
744afr_sh_data_fxattrop_fstat_done (call_frame_t *frame, xlator_t *this)
745{
746 afr_local_t *local = NULL((void*)0);
747 afr_self_heal_t *sh = NULL((void*)0);
748 afr_private_t *priv = NULL((void*)0);
749 int nsources = 0;
750 int ret = 0;
751 int *old_sources = NULL((void*)0);
6
'old_sources' initialized to a null pointer value
752 int tstamp_source = 0;
753 int i = 0;
754
755 local = frame->local;
756 sh = &local->self_heal;
757 priv = this->private;
758
759 gf_log (this->name, GF_LOG_DEBUG, "Pending matrix for: %s",do { do { if (0) printf ("Pending matrix for: %s", lkowner_utoa
(&frame->root->lk_owner)); } while (0); _gf_log (this
->name, "afr-self-heal-data.c", __FUNCTION__, 760, GF_LOG_DEBUG
, "Pending matrix for: %s", lkowner_utoa (&frame->root
->lk_owner)); } while (0)
760 lkowner_utoa (&frame->root->lk_owner))do { do { if (0) printf ("Pending matrix for: %s", lkowner_utoa
(&frame->root->lk_owner)); } while (0); _gf_log (this
->name, "afr-self-heal-data.c", __FUNCTION__, 760, GF_LOG_DEBUG
, "Pending matrix for: %s", lkowner_utoa (&frame->root
->lk_owner)); } while (0)
;
761 if (sh->sync_done) {
7
Taking false branch
762 //store sources before sync so that mtime can be set using the
763 //iatt buf from one of them.
764 old_sources = alloca (priv->child_count*sizeof (*old_sources))__builtin_alloca (priv->child_count*sizeof (*old_sources));
765 memcpy (old_sources, sh->sources,
766 priv->child_count * sizeof (*old_sources));
767 }
768
769 nsources = afr_build_sources (this, sh->xattr, sh->buf, sh->pending_matrix,
770 sh->sources, sh->success_children,
771 AFR_DATA_TRANSACTION, NULL((void*)0), _gf_true);
772 if ((nsources == -1)
773 && (priv->favorite_child != -1)
774 && (sh->child_errno[priv->favorite_child] == 0)) {
775
776 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Picking favorite child %s as authentic source to "
"resolve conflicting data of %s", priv->children[priv->
favorite_child]->name, local->loc.path); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 780, GF_LOG_DEBUG
, "Picking favorite child %s as authentic source to " "resolve conflicting data of %s"
, priv->children[priv->favorite_child]->name, local->
loc.path); } while (0)
777 "Picking favorite child %s as authentic source to "do { do { if (0) printf ("Picking favorite child %s as authentic source to "
"resolve conflicting data of %s", priv->children[priv->
favorite_child]->name, local->loc.path); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 780, GF_LOG_DEBUG
, "Picking favorite child %s as authentic source to " "resolve conflicting data of %s"
, priv->children[priv->favorite_child]->name, local->
loc.path); } while (0)
778 "resolve conflicting data of %s",do { do { if (0) printf ("Picking favorite child %s as authentic source to "
"resolve conflicting data of %s", priv->children[priv->
favorite_child]->name, local->loc.path); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 780, GF_LOG_DEBUG
, "Picking favorite child %s as authentic source to " "resolve conflicting data of %s"
, priv->children[priv->favorite_child]->name, local->
loc.path); } while (0)
779 priv->children[priv->favorite_child]->name,do { do { if (0) printf ("Picking favorite child %s as authentic source to "
"resolve conflicting data of %s", priv->children[priv->
favorite_child]->name, local->loc.path); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 780, GF_LOG_DEBUG
, "Picking favorite child %s as authentic source to " "resolve conflicting data of %s"
, priv->children[priv->favorite_child]->name, local->
loc.path); } while (0)
780 local->loc.path)do { do { if (0) printf ("Picking favorite child %s as authentic source to "
"resolve conflicting data of %s", priv->children[priv->
favorite_child]->name, local->loc.path); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 780, GF_LOG_DEBUG
, "Picking favorite child %s as authentic source to " "resolve conflicting data of %s"
, priv->children[priv->favorite_child]->name, local->
loc.path); } while (0)
;
781
782 sh->sources[priv->favorite_child] = 1;
783
784 nsources = afr_sh_source_count (sh->sources,
785 priv->child_count);
786 }
787
788 if (nsources == -1) {
8
Taking false branch
789 afr_sh_print_split_brain_log (sh->pending_matrix, this,
790 local->loc.path);
791 afr_set_split_brain (this, sh->inode, DONT_KNOW, SPB);
792
793 afr_sh_data_fail (frame, this);
794 return 0;
795 }
796
797 afr_set_split_brain (this, sh->inode, DONT_KNOW, NO_SPB);
798
799 ret = afr_sh_inode_set_read_ctx (sh, this);
800 if (ret) {
9
Assuming 'ret' is 0
10
Taking false branch
801 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("No active sources found."); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 802, GF_LOG_DEBUG, "No active sources found."); } while (0)
802 "No active sources found.")do { do { if (0) printf ("No active sources found."); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 802, GF_LOG_DEBUG, "No active sources found."); } while (0)
;
803
804 afr_sh_data_fail (frame, this);
805 return 0;
806 }
807
808 if (sh->sync_done) {
11
Taking true branch
809 /* Perform setattr from one of the old_sources if possible
810 * Because only they have the correct mtime, the new sources
811 * (i.e. old sinks) have mtime from last writev in sync.
812 */
813 tstamp_source = sh->source;
814 for (i = 0; i < priv->child_count; i++) {
12
Loop condition is true. Entering loop body
815 if (old_sources[i] && sh->sources[i])
13
Array access (from variable 'old_sources') results in a null pointer dereference
816 tstamp_source = i;
817 }
818 afr_sh_data_setattr (frame, this, &sh->buf[tstamp_source]);
819 } else {
820 if (nsources == 0) {
821 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("No self-heal needed for %s", local->
loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 823, GF_LOG_DEBUG, "No self-heal needed for %s"
, local->loc.path); } while (0)
822 "No self-heal needed for %s",do { do { if (0) printf ("No self-heal needed for %s", local->
loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 823, GF_LOG_DEBUG, "No self-heal needed for %s"
, local->loc.path); } while (0)
823 local->loc.path)do { do { if (0) printf ("No self-heal needed for %s", local->
loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 823, GF_LOG_DEBUG, "No self-heal needed for %s"
, local->loc.path); } while (0)
;
824
825 afr_sh_data_finish (frame, this);
826 return 0;
827 }
828
829 if (sh->do_data_self_heal &&
830 afr_data_self_heal_enabled (priv->data_self_heal))
831 afr_sh_data_fix (frame, this);
832 else
833 afr_sh_data_finish (frame, this);
834 }
835 return 0;
836}
837
838int
839afr_lookup_select_read_child_by_txn_type (xlator_t *this, afr_local_t *local,
840 dict_t **xattr,
841 afr_transaction_type txn_type,
842 uuid_t gfid)
843{
844 afr_private_t *priv = NULL((void*)0);
845 int read_child = -1;
846 int32_t **pending_matrix = NULL((void*)0);
847 int32_t *sources = NULL((void*)0);
848 int32_t *success_children = NULL((void*)0);
849 struct iatt *bufs = NULL((void*)0);
850 int32_t nsources = 0;
851 int32_t prev_read_child = -1;
852 int32_t config_read_child = -1;
853 int32_t subvol_status = 0;
854
855 priv = this->private;
856 bufs = local->cont.lookup.bufs;
857 success_children = local->cont.lookup.success_children;
858
859 pending_matrix = local->cont.lookup.pending_matrix;
860 sources = local->cont.lookup.sources;
861 memset (sources, 0, sizeof (*sources) * priv->child_count);
862
863 nsources = afr_build_sources (this, xattr, bufs, pending_matrix,
864 sources, success_children, txn_type,
865 &subvol_status, _gf_false);
866 if (subvol_status & SPLIT_BRAIN) {
867 gf_log (this->name, GF_LOG_DEBUG, "%s: Possible split-brain",do { do { if (0) printf ("%s: Possible split-brain", local->
loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 868, GF_LOG_DEBUG, "%s: Possible split-brain"
, local->loc.path); } while (0)
868 local->loc.path)do { do { if (0) printf ("%s: Possible split-brain", local->
loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 868, GF_LOG_DEBUG, "%s: Possible split-brain"
, local->loc.path); } while (0)
;
869 switch (txn_type) {
870 case AFR_DATA_TRANSACTION:
871 local->cont.lookup.possible_spb = _gf_true;
872 nsources = 1;
873 sources[success_children[0]] = 1;
874 break;
875 case AFR_ENTRY_TRANSACTION:
876 read_child = afr_get_no_xattr_dir_read_child (this,
877 success_children,
878 bufs);
879 sources[read_child] = 1;
880 nsources = 1;
881 break;
882 default:
883 break;
884 }
885 }
886 if (nsources < 0)
887 goto out;
888
889 prev_read_child = local->read_child_index;
890 config_read_child = priv->read_child;
891 read_child = afr_select_read_child_from_policy (success_children,
892 priv->child_count,
893 prev_read_child,
894 config_read_child,
895 sources,
896 priv->hash_mode, gfid);
897out:
898 gf_log (this->name, GF_LOG_DEBUG, "returning read_child: %d",do { do { if (0) printf ("returning read_child: %d", read_child
); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 899, GF_LOG_DEBUG, "returning read_child: %d"
, read_child); } while (0)
899 read_child)do { do { if (0) printf ("returning read_child: %d", read_child
); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 899, GF_LOG_DEBUG, "returning read_child: %d"
, read_child); } while (0)
;
900 return read_child;
901}
902
903int
904afr_sh_data_fstat_cbk (call_frame_t *frame, void *cookie,
905 xlator_t *this, int32_t op_ret, int32_t op_errno,
906 struct iatt *buf, dict_t *xdata)
907{
908 afr_private_t *priv = NULL((void*)0);
909 afr_local_t *local = NULL((void*)0);
910 afr_self_heal_t *sh = NULL((void*)0);
911 int call_count = -1;
912 int child_index = (long) cookie;
913
914 local = frame->local;
915 sh = &local->self_heal;
916 priv = this->private;
917
918 LOCK (&frame->lock)pthread_spin_lock (&frame->lock);
919 {
920 if (op_ret != -1) {
1
Taking false branch
921 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("fstat of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 924, GF_LOG_TRACE, "fstat of %s on %s succeeded", local->
loc.path, priv->children[child_index]->name); } while (
0)
922 "fstat of %s on %s succeeded",do { do { if (0) printf ("fstat of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 924, GF_LOG_TRACE, "fstat of %s on %s succeeded", local->
loc.path, priv->children[child_index]->name); } while (
0)
923 local->loc.path,do { do { if (0) printf ("fstat of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 924, GF_LOG_TRACE, "fstat of %s on %s succeeded", local->
loc.path, priv->children[child_index]->name); } while (
0)
924 priv->children[child_index]->name)do { do { if (0) printf ("fstat of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 924, GF_LOG_TRACE, "fstat of %s on %s succeeded", local->
loc.path, priv->children[child_index]->name); } while (
0)
;
925
926 sh->buf[child_index] = *buf;
927 sh->success_children[sh->success_count] = child_index;
928 sh->success_count++;
929 } else {
930 gf_log (this->name, GF_LOG_ERROR, "%s: fstat failed "do { do { if (0) printf ("%s: fstat failed " "on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 933, GF_LOG_ERROR, "%s: fstat failed " "on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
931 "on %s, reason %s", local->loc.path,do { do { if (0) printf ("%s: fstat failed " "on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 933, GF_LOG_ERROR, "%s: fstat failed " "on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
932 priv->children[child_index]->name,do { do { if (0) printf ("%s: fstat failed " "on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 933, GF_LOG_ERROR, "%s: fstat failed " "on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
933 strerror (op_errno))do { do { if (0) printf ("%s: fstat failed " "on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 933, GF_LOG_ERROR, "%s: fstat failed " "on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
;
934 sh->child_errno[child_index] = op_errno;
935 }
936 }
937 UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock);
938
939 call_count = afr_frame_return (frame);
940
941 if (call_count == 0) {
2
Assuming 'call_count' is equal to 0
3
Taking true branch
942 /* Previous versions of glusterfs might have set
943 * the pending data xattrs which need to be erased
944 */
945 if (!afr_sh_data_proceed (sh->success_count)) {
4
Taking false branch
946 gf_log (this->name, GF_LOG_ERROR, "inspecting metadata "do { do { if (0) printf ("inspecting metadata " "succeeded on < %d children, aborting "
"self-heal for %s", 2, local->loc.path); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 949, GF_LOG_ERROR
, "inspecting metadata " "succeeded on < %d children, aborting "
"self-heal for %s", 2, local->loc.path); } while (0)
947 "succeeded on < %d children, aborting "do { do { if (0) printf ("inspecting metadata " "succeeded on < %d children, aborting "
"self-heal for %s", 2, local->loc.path); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 949, GF_LOG_ERROR
, "inspecting metadata " "succeeded on < %d children, aborting "
"self-heal for %s", 2, local->loc.path); } while (0)
948 "self-heal for %s", AFR_SH_MIN_PARTICIPANTS,do { do { if (0) printf ("inspecting metadata " "succeeded on < %d children, aborting "
"self-heal for %s", 2, local->loc.path); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 949, GF_LOG_ERROR
, "inspecting metadata " "succeeded on < %d children, aborting "
"self-heal for %s", 2, local->loc.path); } while (0)
949 local->loc.path)do { do { if (0) printf ("inspecting metadata " "succeeded on < %d children, aborting "
"self-heal for %s", 2, local->loc.path); } while (0); _gf_log
(this->name, "afr-self-heal-data.c", __FUNCTION__, 949, GF_LOG_ERROR
, "inspecting metadata " "succeeded on < %d children, aborting "
"self-heal for %s", 2, local->loc.path); } while (0)
;
950 afr_sh_data_fail (frame, this);
951 goto out;
952 }
953 afr_sh_data_fxattrop_fstat_done (frame, this);
5
Calling 'afr_sh_data_fxattrop_fstat_done'
954 }
955out:
956 return 0;
957}
958
959
960int
961afr_sh_data_fstat (call_frame_t *frame, xlator_t *this)
962{
963 afr_self_heal_t *sh = NULL((void*)0);
964 afr_local_t *local = NULL((void*)0);
965 afr_private_t *priv = NULL((void*)0);
966 int call_count = 0;
967 int i = 0;
968 int child = 0;
969 int32_t *fstat_children = NULL((void*)0);
970
971 priv = this->private;
972 local = frame->local;
973 sh = &local->self_heal;
974
975 fstat_children = memdup (sh->success_children,
976 sizeof (*fstat_children) * priv->child_count);
977 if (!fstat_children) {
978 afr_sh_data_fail (frame, this);
979 goto out;
980 }
981 call_count = sh->success_count;
982 local->call_count = call_count;
983
984 memset (sh->buf, 0, sizeof (*sh->buf) * priv->child_count);
985 afr_reset_children (sh->success_children, priv->child_count);
986 sh->success_count = 0;
987 for (i = 0; i < priv->child_count; i++) {
988 child = fstat_children[i];
989 if (child == -1)
990 break;
991 STACK_WIND_COOKIE (frame, afr_sh_data_fstat_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-data.c", __FUNCTION__,
995, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[child]->fops->fstat_cbk) tmp_cbk = afr_sh_data_fstat_cbk
; _new->root = frame->root; _new->this = priv->children
[child]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent =
frame; _new->cookie = (void *) (long) child; _new->wind_from
= __FUNCTION__; _new->wind_to = "priv->children[child]->fops->fstat"
; _new->unwind_to = "afr_sh_data_fstat_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[child]->fops->fstat_cbk = afr_sh_data_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[child]; if (priv->children[child]->
ctx->measure_latency) gf_latency_begin (_new, priv->children
[child]->fops->fstat); priv->children[child]->fops
->fstat (_new, priv->children[child], sh->healing_fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
992 (void *) (long) child,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-data.c", __FUNCTION__,
995, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[child]->fops->fstat_cbk) tmp_cbk = afr_sh_data_fstat_cbk
; _new->root = frame->root; _new->this = priv->children
[child]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent =
frame; _new->cookie = (void *) (long) child; _new->wind_from
= __FUNCTION__; _new->wind_to = "priv->children[child]->fops->fstat"
; _new->unwind_to = "afr_sh_data_fstat_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[child]->fops->fstat_cbk = afr_sh_data_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[child]; if (priv->children[child]->
ctx->measure_latency) gf_latency_begin (_new, priv->children
[child]->fops->fstat); priv->children[child]->fops
->fstat (_new, priv->children[child], sh->healing_fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
993 priv->children[child],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-data.c", __FUNCTION__,
995, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[child]->fops->fstat_cbk) tmp_cbk = afr_sh_data_fstat_cbk
; _new->root = frame->root; _new->this = priv->children
[child]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent =
frame; _new->cookie = (void *) (long) child; _new->wind_from
= __FUNCTION__; _new->wind_to = "priv->children[child]->fops->fstat"
; _new->unwind_to = "afr_sh_data_fstat_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[child]->fops->fstat_cbk = afr_sh_data_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[child]; if (priv->children[child]->
ctx->measure_latency) gf_latency_begin (_new, priv->children
[child]->fops->fstat); priv->children[child]->fops
->fstat (_new, priv->children[child], sh->healing_fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
994 priv->children[child]->fops->fstat,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-data.c", __FUNCTION__,
995, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[child]->fops->fstat_cbk) tmp_cbk = afr_sh_data_fstat_cbk
; _new->root = frame->root; _new->this = priv->children
[child]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent =
frame; _new->cookie = (void *) (long) child; _new->wind_from
= __FUNCTION__; _new->wind_to = "priv->children[child]->fops->fstat"
; _new->unwind_to = "afr_sh_data_fstat_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[child]->fops->fstat_cbk = afr_sh_data_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[child]; if (priv->children[child]->
ctx->measure_latency) gf_latency_begin (_new, priv->children
[child]->fops->fstat); priv->children[child]->fops
->fstat (_new, priv->children[child], sh->healing_fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
995 sh->healing_fd, 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-data.c", __FUNCTION__,
995, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[child]->fops->fstat_cbk) tmp_cbk = afr_sh_data_fstat_cbk
; _new->root = frame->root; _new->this = priv->children
[child]; _new->ret = (ret_fn_t) tmp_cbk; _new->parent =
frame; _new->cookie = (void *) (long) child; _new->wind_from
= __FUNCTION__; _new->wind_to = "priv->children[child]->fops->fstat"
; _new->unwind_to = "afr_sh_data_fstat_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[child]->fops->fstat_cbk = afr_sh_data_fstat_cbk
; old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = priv->children[child]; if (priv->children[child]->
ctx->measure_latency) gf_latency_begin (_new, priv->children
[child]->fops->fstat); priv->children[child]->fops
->fstat (_new, priv->children[child], sh->healing_fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
;
996 --call_count;
997 }
998 GF_ASSERT (!call_count)do { if (!(!call_count)) { do { do { if (0) printf ("Assertion failed: "
"!call_count"); } while (0); _gf_log_callingfn ("", "afr-self-heal-data.c"
, __FUNCTION__, 998, GF_LOG_ERROR, "Assertion failed: " "!call_count"
); } while (0); } } while (0)
;
999out:
1000 GF_FREE (fstat_children)__gf_free (fstat_children);
1001 return 0;
1002}
1003
1004void
1005afr_sh_common_fxattrop_resp_handler (call_frame_t *frame, void *cookie,
1006 xlator_t *this, int32_t op_ret,
1007 int32_t op_errno, dict_t *xattr)
1008{
1009 afr_private_t *priv = NULL((void*)0);
1010 afr_local_t *local = NULL((void*)0);
1011 afr_self_heal_t *sh = NULL((void*)0);
1012 int child_index = (long) cookie;
1013
1014 local = frame->local;
1015 sh = &local->self_heal;
1016 priv = this->private;
1017
1018 LOCK (&frame->lock)pthread_spin_lock (&frame->lock);
1019 {
1020 if (op_ret != -1) {
1021 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("fxattrop of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 1024, GF_LOG_TRACE, "fxattrop of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0)
1022 "fxattrop of %s on %s succeeded",do { do { if (0) printf ("fxattrop of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 1024, GF_LOG_TRACE, "fxattrop of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0)
1023 local->loc.path,do { do { if (0) printf ("fxattrop of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 1024, GF_LOG_TRACE, "fxattrop of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0)
1024 priv->children[child_index]->name)do { do { if (0) printf ("fxattrop of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 1024, GF_LOG_TRACE, "fxattrop of %s on %s succeeded", local
->loc.path, priv->children[child_index]->name); } while
(0)
;
1025
1026 sh->xattr[child_index] = dict_ref (xattr);
1027 sh->success_children[sh->success_count] = child_index;
1028 sh->success_count++;
1029 } else {
1030 gf_log (this->name, GF_LOG_ERROR, "fxattrop of %s "do { do { if (0) printf ("fxattrop of %s " "failed on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1033, GF_LOG_ERROR, "fxattrop of %s " "failed on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
1031 "failed on %s, reason %s", local->loc.path,do { do { if (0) printf ("fxattrop of %s " "failed on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1033, GF_LOG_ERROR, "fxattrop of %s " "failed on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
1032 priv->children[child_index]->name,do { do { if (0) printf ("fxattrop of %s " "failed on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1033, GF_LOG_ERROR, "fxattrop of %s " "failed on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
1033 strerror (op_errno))do { do { if (0) printf ("fxattrop of %s " "failed on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1033, GF_LOG_ERROR, "fxattrop of %s " "failed on %s, reason %s"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
;
1034 sh->child_errno[child_index] = op_errno;
1035 }
1036 }
1037 UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock);
1038}
1039
1040int
1041afr_sh_data_fxattrop_cbk (call_frame_t *frame, void *cookie,
1042 xlator_t *this, int32_t op_ret, int32_t op_errno,
1043 dict_t *xattr, dict_t *xdata)
1044{
1045 int call_count = -1;
1046 afr_local_t *local = NULL((void*)0);
1047 afr_self_heal_t *sh = NULL((void*)0);
1048
1049 local = frame->local;
1050 sh = &local->self_heal;
1051
1052 afr_sh_common_fxattrop_resp_handler (frame, cookie, this, op_ret,
1053 op_errno, xattr);
1054
1055 call_count = afr_frame_return (frame);
1056 if (call_count == 0) {
1057 if (!afr_sh_data_proceed (sh->success_count)) {
1058 gf_log (this->name, GF_LOG_ERROR, "%s, inspecting "do { do { if (0) printf ("%s, inspecting " "change log succeeded on < %d children"
, local->loc.path, 2); } while (0); _gf_log (this->name
, "afr-self-heal-data.c", __FUNCTION__, 1060, GF_LOG_ERROR, "%s, inspecting "
"change log succeeded on < %d children", local->loc.path
, 2); } while (0)
1059 "change log succeeded on < %d children",do { do { if (0) printf ("%s, inspecting " "change log succeeded on < %d children"
, local->loc.path, 2); } while (0); _gf_log (this->name
, "afr-self-heal-data.c", __FUNCTION__, 1060, GF_LOG_ERROR, "%s, inspecting "
"change log succeeded on < %d children", local->loc.path
, 2); } while (0)
1060 local->loc.path, AFR_SH_MIN_PARTICIPANTS)do { do { if (0) printf ("%s, inspecting " "change log succeeded on < %d children"
, local->loc.path, 2); } while (0); _gf_log (this->name
, "afr-self-heal-data.c", __FUNCTION__, 1060, GF_LOG_ERROR, "%s, inspecting "
"change log succeeded on < %d children", local->loc.path
, 2); } while (0)
;
1061 afr_sh_data_fail (frame, this);
1062 goto out;
1063 }
1064 afr_sh_data_fstat (frame, this);
1065 }
1066out:
1067 return 0;
1068}
1069
1070
1071int
1072afr_sh_data_fxattrop (call_frame_t *frame, xlator_t *this)
1073{
1074 afr_self_heal_t *sh = NULL((void*)0);
1075 afr_local_t *local = NULL((void*)0);
1076 afr_private_t *priv = NULL((void*)0);
1077 dict_t **xattr_req;
1078 int32_t *zero_pending = NULL((void*)0);
1079 int call_count = 0;
1080 int i = 0;
1081 int ret = 0;
1082 int j;
1083
1084 priv = this->private;
1085 local = frame->local;
1086 sh = &local->self_heal;
1087
1088 call_count = afr_up_children_count (local->child_up,
1089 priv->child_count);
1090
1091 local->call_count = call_count;
1092
1093 xattr_req = GF_CALLOC(priv->child_count, sizeof(struct dict_t *),__gf_calloc (priv->child_count, sizeof(struct dict_t *), gf_afr_mt_dict_t
)
1094 gf_afr_mt_dict_t)__gf_calloc (priv->child_count, sizeof(struct dict_t *), gf_afr_mt_dict_t
)
;
1095 if (!xattr_req)
1096 goto out;
1097
1098 for (i = 0; i < priv->child_count; i++) {
1099 xattr_req[i] = dict_new();
1100 if (!xattr_req[i]) {
1101 ret = -1;
1102 goto out;
1103 }
1104 }
1105
1106 for (i = 0; i < priv->child_count; i++) {
1107 for (j = 0; j < priv->child_count; j++) {
1108 zero_pending = GF_CALLOC (3, sizeof (*zero_pending),__gf_calloc (3, sizeof (*zero_pending), gf_afr_mt_int32_t)
1109 gf_afr_mt_int32_t)__gf_calloc (3, sizeof (*zero_pending), gf_afr_mt_int32_t);
1110 if (!zero_pending) {
1111 ret = -1;
1112 goto out;
1113 }
1114 ret = dict_set_dynptr (xattr_req[i], priv->pending_key[j],
1115 zero_pending,
1116 3 * sizeof (*zero_pending));
1117 if (ret < 0) {
1118 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-data.c", __FUNCTION__
, 1119, GF_LOG_WARNING, "Unable to set dict value"); } while (
0)
1119 "Unable to set dict value")do { do { if (0) printf ("Unable to set dict value"); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 1119, GF_LOG_WARNING, "Unable to set dict value"); } while (
0)
;
1120 goto out;
1121 } else {
1122 zero_pending = NULL((void*)0);
1123 }
1124 }
1125 }
1126
1127 afr_reset_xattr (sh->xattr, priv->child_count);
1128 afr_reset_children (sh->success_children, priv->child_count);
1129 memset (sh->child_errno, 0,
1130 sizeof (*sh->child_errno) * priv->child_count);
1131 sh->success_count = 0;
1132 for (i = 0; i < priv->child_count; i++) {
1133 if (local->child_up[i]) {
1134 STACK_WIND_COOKIE (frame, afr_sh_data_fxattrop_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-data.c", __FUNCTION__,
1139, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = afr_sh_data_fxattrop_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 = "afr_sh_data_fxattrop_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 = afr_sh_data_fxattrop_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
, xattr_req[i], ((void*)0)); (*__glusterfs_this_location()) =
old_THIS; } while (0)
1135 (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-data.c", __FUNCTION__,
1139, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = afr_sh_data_fxattrop_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 = "afr_sh_data_fxattrop_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 = afr_sh_data_fxattrop_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
, xattr_req[i], ((void*)0)); (*__glusterfs_this_location()) =
old_THIS; } while (0)
1136 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-data.c", __FUNCTION__,
1139, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = afr_sh_data_fxattrop_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 = "afr_sh_data_fxattrop_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 = afr_sh_data_fxattrop_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
, xattr_req[i], ((void*)0)); (*__glusterfs_this_location()) =
old_THIS; } while (0)
1137 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-data.c", __FUNCTION__,
1139, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = afr_sh_data_fxattrop_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 = "afr_sh_data_fxattrop_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 = afr_sh_data_fxattrop_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
, xattr_req[i], ((void*)0)); (*__glusterfs_this_location()) =
old_THIS; } while (0)
1138 sh->healing_fd, GF_XATTROP_ADD_ARRAY,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-data.c", __FUNCTION__,
1139, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = afr_sh_data_fxattrop_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 = "afr_sh_data_fxattrop_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 = afr_sh_data_fxattrop_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
, xattr_req[i], ((void*)0)); (*__glusterfs_this_location()) =
old_THIS; } while (0)
1139 xattr_req[i], 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-data.c", __FUNCTION__,
1139, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->fxattrop_cbk) tmp_cbk = afr_sh_data_fxattrop_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 = "afr_sh_data_fxattrop_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 = afr_sh_data_fxattrop_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
, xattr_req[i], ((void*)0)); (*__glusterfs_this_location()) =
old_THIS; } while (0)
;
1140
1141 if (!--call_count)
1142 break;
1143 }
1144 }
1145
1146out:
1147 if (xattr_req) {
1148 for (i = 0; i < priv->child_count; i++)
1149 if (xattr_req[i])
1150 dict_unref(xattr_req[i]);
1151 GF_FREE(xattr_req)__gf_free (xattr_req);
1152 }
1153
1154 if (ret) {
1155 GF_FREE (zero_pending)__gf_free (zero_pending);
1156 afr_sh_data_fail (frame, this);
1157 }
1158
1159 return 0;
1160}
1161
1162int
1163afr_sh_data_big_lock_success (call_frame_t *frame, xlator_t *this)
1164{
1165 afr_local_t *local = NULL((void*)0);
1166 afr_self_heal_t *sh = NULL((void*)0);
1167
1168 local = frame->local;
1169 sh = &local->self_heal;
1170
1171 sh->data_lock_held = _gf_true;
1172 afr_sh_data_fxattrop (frame, this);
1173 return 0;
1174}
1175
1176int
1177afr_sh_data_post_blocking_inodelk_cbk (call_frame_t *frame, xlator_t *this)
1178{
1179 afr_internal_lock_t *int_lock = NULL((void*)0);
1180 afr_local_t *local = NULL((void*)0);
1181 afr_self_heal_t *sh = NULL((void*)0);
1182
1183 local = frame->local;
1184 int_lock = &local->internal_lock;
1185 sh = &local->self_heal;
1186
1187 if (int_lock->lock_op_ret < 0) {
1188 gf_log (this->name, GF_LOG_ERROR, "Blocking data inodelks "do { do { if (0) printf ("Blocking data inodelks " "failed for %s. by %s"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1190, GF_LOG_ERROR, "Blocking data inodelks "
"failed for %s. by %s", local->loc.path, lkowner_utoa (&
frame->root->lk_owner)); } while (0)
1189 "failed for %s. by %s",do { do { if (0) printf ("Blocking data inodelks " "failed for %s. by %s"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1190, GF_LOG_ERROR, "Blocking data inodelks "
"failed for %s. by %s", local->loc.path, lkowner_utoa (&
frame->root->lk_owner)); } while (0)
1190 local->loc.path, lkowner_utoa (&frame->root->lk_owner))do { do { if (0) printf ("Blocking data inodelks " "failed for %s. by %s"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1190, GF_LOG_ERROR, "Blocking data inodelks "
"failed for %s. by %s", local->loc.path, lkowner_utoa (&
frame->root->lk_owner)); } while (0)
;
1191
1192 sh->data_lock_failure_handler (frame, this);
1193 } else {
1194
1195 gf_log (this->name, GF_LOG_DEBUG, "Blocking data inodelks "do { do { if (0) printf ("Blocking data inodelks " "done for %s by %s. Proceding to self-heal"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1197, GF_LOG_DEBUG, "Blocking data inodelks "
"done for %s by %s. Proceding to self-heal", local->loc.path
, lkowner_utoa (&frame->root->lk_owner)); } while (
0)
1196 "done for %s by %s. Proceding to self-heal",do { do { if (0) printf ("Blocking data inodelks " "done for %s by %s. Proceding to self-heal"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1197, GF_LOG_DEBUG, "Blocking data inodelks "
"done for %s by %s. Proceding to self-heal", local->loc.path
, lkowner_utoa (&frame->root->lk_owner)); } while (
0)
1197 local->loc.path, lkowner_utoa (&frame->root->lk_owner))do { do { if (0) printf ("Blocking data inodelks " "done for %s by %s. Proceding to self-heal"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1197, GF_LOG_DEBUG, "Blocking data inodelks "
"done for %s by %s. Proceding to self-heal", local->loc.path
, lkowner_utoa (&frame->root->lk_owner)); } while (
0)
;
1198
1199 sh->data_lock_success_handler (frame, this);
1200 }
1201
1202 return 0;
1203}
1204
1205int
1206afr_sh_data_post_nonblocking_inodelk_cbk (call_frame_t *frame, xlator_t *this)
1207{
1208 afr_internal_lock_t *int_lock = NULL((void*)0);
1209 afr_local_t *local = NULL((void*)0);
1210 afr_self_heal_t *sh = NULL((void*)0);
1211
1212 local = frame->local;
1213 int_lock = &local->internal_lock;
1214 sh = &local->self_heal;
1215
1216 if (int_lock->lock_op_ret < 0) {
1217 gf_log (this->name, GF_LOG_DEBUG, "Non Blocking data inodelks "do { do { if (0) printf ("Non Blocking data inodelks " "failed for %s. by %s"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1219, GF_LOG_DEBUG, "Non Blocking data inodelks "
"failed for %s. by %s", local->loc.path, lkowner_utoa (&
frame->root->lk_owner)); } while (0)
1218 "failed for %s. by %s",do { do { if (0) printf ("Non Blocking data inodelks " "failed for %s. by %s"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1219, GF_LOG_DEBUG, "Non Blocking data inodelks "
"failed for %s. by %s", local->loc.path, lkowner_utoa (&
frame->root->lk_owner)); } while (0)
1219 local->loc.path, lkowner_utoa (&frame->root->lk_owner))do { do { if (0) printf ("Non Blocking data inodelks " "failed for %s. by %s"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1219, GF_LOG_DEBUG, "Non Blocking data inodelks "
"failed for %s. by %s", local->loc.path, lkowner_utoa (&
frame->root->lk_owner)); } while (0)
;
1220
1221 if (!sh->data_lock_block) {
1222 sh->data_lock_failure_handler(frame, this);
1223 } else {
1224 int_lock->lock_cbk =
1225 afr_sh_data_post_blocking_inodelk_cbk;
1226 afr_blocking_lock (frame, this);
1227 }
1228 } else {
1229
1230 gf_log (this->name, GF_LOG_DEBUG, "Non Blocking data inodelks "do { do { if (0) printf ("Non Blocking data inodelks " "done for %s by %s. Proceeding to self-heal"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1232, GF_LOG_DEBUG, "Non Blocking data inodelks "
"done for %s by %s. Proceeding to self-heal", local->loc.
path, lkowner_utoa (&frame->root->lk_owner)); } while
(0)
1231 "done for %s by %s. Proceeding to self-heal",do { do { if (0) printf ("Non Blocking data inodelks " "done for %s by %s. Proceeding to self-heal"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1232, GF_LOG_DEBUG, "Non Blocking data inodelks "
"done for %s by %s. Proceeding to self-heal", local->loc.
path, lkowner_utoa (&frame->root->lk_owner)); } while
(0)
1232 local->loc.path, lkowner_utoa (&frame->root->lk_owner))do { do { if (0) printf ("Non Blocking data inodelks " "done for %s by %s. Proceeding to self-heal"
, local->loc.path, lkowner_utoa (&frame->root->lk_owner
)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1232, GF_LOG_DEBUG, "Non Blocking data inodelks "
"done for %s by %s. Proceeding to self-heal", local->loc.
path, lkowner_utoa (&frame->root->lk_owner)); } while
(0)
;
1233 sh->data_lock_success_handler (frame, this);
1234 }
1235
1236 return 0;
1237}
1238
1239int
1240afr_sh_data_lock_rec (call_frame_t *frame, xlator_t *this, off_t start, off_t len)
1241{
1242 afr_internal_lock_t *int_lock = NULL((void*)0);
1243 afr_local_t *local = NULL((void*)0);
1244
1245 local = frame->local;
1246 int_lock = &local->internal_lock;
1247
1248 int_lock->transaction_lk_type = AFR_SELFHEAL_LK;
1249 int_lock->selfheal_lk_type = AFR_DATA_SELF_HEAL_LK;
1250
1251 afr_set_lock_number (frame, this);
1252
1253 int_lock->lk_flock.l_start = start;
1254 int_lock->lk_flock.l_len = len;
1255 int_lock->lk_flock.l_type = F_WRLCK1;
1256 int_lock->lock_cbk = afr_sh_data_post_nonblocking_inodelk_cbk;
1257
1258 afr_nonblocking_inodelk (frame, this);
1259
1260 return 0;
1261}
1262
1263int
1264afr_post_sh_big_lock_success (call_frame_t *frame, xlator_t *this)
1265{
1266 afr_local_t *local = NULL((void*)0);
1267 afr_self_heal_t *sh = NULL((void*)0);
1268
1269 local = frame->local;
1270 sh = &local->self_heal;
1271
1272 GF_ASSERT (sh->old_loop_frame)do { if (!(sh->old_loop_frame)) { do { do { if (0) printf (
"Assertion failed: " "sh->old_loop_frame"); } while (0); _gf_log_callingfn
("", "afr-self-heal-data.c", __FUNCTION__, 1272, GF_LOG_ERROR
, "Assertion failed: " "sh->old_loop_frame"); } while (0);
} } while (0)
;
1273 sh_loop_finish (sh->old_loop_frame, this);
1274 sh->old_loop_frame = NULL((void*)0);
1275 sh->data_lock_held = _gf_true;
1276 sh->sync_done = _gf_true;
1277 afr_sh_data_fxattrop (frame, this);
1278 return 0;
1279}
1280
1281int
1282afr_post_sh_big_lock_failure (call_frame_t *frame, xlator_t *this)
1283{
1284 afr_local_t *local = NULL((void*)0);
1285 afr_self_heal_t *sh = NULL((void*)0);
1286
1287 local = frame->local;
1288 sh = &local->self_heal;
1289
1290 GF_ASSERT (sh->old_loop_frame)do { if (!(sh->old_loop_frame)) { do { do { if (0) printf (
"Assertion failed: " "sh->old_loop_frame"); } while (0); _gf_log_callingfn
("", "afr-self-heal-data.c", __FUNCTION__, 1290, GF_LOG_ERROR
, "Assertion failed: " "sh->old_loop_frame"); } while (0);
} } while (0)
;
1291 sh_loop_finish (sh->old_loop_frame, this);
1292 sh->old_loop_frame = NULL((void*)0);
1293 afr_sh_set_timestamps (frame, this);
1294 return 0;
1295}
1296
1297
1298int
1299afr_sh_data_lock (call_frame_t *frame, xlator_t *this,
1300 off_t start, off_t len, gf_boolean_t block,
1301 afr_lock_cbk_t success_handler,
1302 afr_lock_cbk_t failure_handler)
1303{
1304 afr_local_t * local = NULL((void*)0);
1305 afr_self_heal_t * sh = NULL((void*)0);
1306
1307 local = frame->local;
1308 sh = &local->self_heal;
1309
1310 sh->data_lock_success_handler = success_handler;
1311 sh->data_lock_failure_handler = failure_handler;
1312 sh->data_lock_block = block;
1313 return afr_sh_data_lock_rec (frame, this, start, len);
1314}
1315
1316int
1317afr_sh_data_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1318 int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)
1319{
1320 afr_local_t *local = NULL((void*)0);
1321 afr_self_heal_t *sh = NULL((void*)0);
1322 afr_private_t *priv = NULL((void*)0);
1323 int call_count = 0;
1324 int child_index = 0;
1325 gf_boolean_t block = _gf_true;
1326
1327 local = frame->local;
1328 sh = &local->self_heal;
1329 priv = this->private;
1330
1331 child_index = (long) cookie;
1332
1333 /* TODO: some of the open's might fail.
1334 In that case, modify cleanup fn to send flush on those
1335 fd's which are already open */
1336
1337 LOCK (&frame->lock)pthread_spin_lock (&frame->lock);
1338 {
1339 if (op_ret == -1) {
1340 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1344, GF_LOG_ERROR, "open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
1341 "open of %s failed on child %s (%s)",do { do { if (0) printf ("open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1344, GF_LOG_ERROR, "open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
1342 local->loc.path,do { do { if (0) printf ("open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1344, GF_LOG_ERROR, "open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
1343 priv->children[child_index]->name,do { do { if (0) printf ("open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1344, GF_LOG_ERROR, "open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
1344 strerror (op_errno))do { do { if (0) printf ("open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1344, GF_LOG_ERROR, "open of %s failed on child %s (%s)"
, local->loc.path, priv->children[child_index]->name
, strerror (op_errno)); } while (0)
;
1345 sh->op_failed = 1;
1346 } else {
1347 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("open of %s succeeded on child %s", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 1350, GF_LOG_TRACE, "open of %s succeeded on child %s", local
->loc.path, priv->children[child_index]->name); } while
(0)
1348 "open of %s succeeded on child %s",do { do { if (0) printf ("open of %s succeeded on child %s", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 1350, GF_LOG_TRACE, "open of %s succeeded on child %s", local
->loc.path, priv->children[child_index]->name); } while
(0)
1349 local->loc.path,do { do { if (0) printf ("open of %s succeeded on child %s", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 1350, GF_LOG_TRACE, "open of %s succeeded on child %s", local
->loc.path, priv->children[child_index]->name); } while
(0)
1350 priv->children[child_index]->name)do { do { if (0) printf ("open of %s succeeded on child %s", local
->loc.path, priv->children[child_index]->name); } while
(0); _gf_log (this->name, "afr-self-heal-data.c", __FUNCTION__
, 1350, GF_LOG_TRACE, "open of %s succeeded on child %s", local
->loc.path, priv->children[child_index]->name); } while
(0)
;
1351 }
1352 }
1353 UNLOCK (&frame->lock)pthread_spin_unlock (&frame->lock);
1354
1355 call_count = afr_frame_return (frame);
1356
1357 if (call_count == 0) {
1358 if (sh->op_failed) {
1359 afr_sh_data_fail (frame, this);
1360 return 0;
1361 }
1362
1363 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("fd for %s opened, commencing sync",
local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1365, GF_LOG_TRACE, "fd for %s opened, commencing sync"
, local->loc.path); } while (0)
1364 "fd for %s opened, commencing sync",do { do { if (0) printf ("fd for %s opened, commencing sync",
local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1365, GF_LOG_TRACE, "fd for %s opened, commencing sync"
, local->loc.path); } while (0)
1365 local->loc.path)do { do { if (0) printf ("fd for %s opened, commencing sync",
local->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1365, GF_LOG_TRACE, "fd for %s opened, commencing sync"
, local->loc.path); } while (0)
;
1366
1367 /*
1368 * The read and write self-heal trigger codepaths do not provide
1369 * an unwind callback. We run a trylock in these codepaths
1370 * because we are sensitive to locking latency.
1371 */
1372 block = sh->unwind ? _gf_true : _gf_false;
1373 afr_sh_data_lock (frame, this, 0, 0, block,
1374 afr_sh_data_big_lock_success,
1375 afr_sh_data_fail);
1376 }
1377
1378 return 0;
1379}
1380
1381
1382int
1383afr_sh_data_open (call_frame_t *frame, xlator_t *this)
1384{
1385 int i = 0;
1386 int call_count = 0;
1387 fd_t *fd = NULL((void*)0);
1388 afr_local_t * local = NULL((void*)0);
1389 afr_private_t * priv = NULL((void*)0);
1390 afr_self_heal_t *sh = NULL((void*)0);
1391
1392 local = frame->local;
1393 sh = &local->self_heal;
1394 priv = this->private;
1395
1396 call_count = afr_up_children_count (local->child_up, priv->child_count);
1397 local->call_count = call_count;
1398
1399 fd = fd_create (local->loc.inode, frame->root->pid);
1400 sh->healing_fd = fd;
1401
1402 /* open sinks */
1403 for (i = 0; i < priv->child_count; i++) {
1404 if(!local->child_up[i])
1405 continue;
1406
1407 STACK_WIND_COOKIE (frame, afr_sh_data_open_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-data.c", __FUNCTION__,
1412, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->open_cbk) tmp_cbk = afr_sh_data_open_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->open"
; _new->unwind_to = "afr_sh_data_open_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->open_cbk = afr_sh_data_open_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->open); priv->children[i]->fops->open (
_new, priv->children[i], &local->loc, 02|0100000, fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
1408 (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-data.c", __FUNCTION__,
1412, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->open_cbk) tmp_cbk = afr_sh_data_open_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->open"
; _new->unwind_to = "afr_sh_data_open_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->open_cbk = afr_sh_data_open_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->open); priv->children[i]->fops->open (
_new, priv->children[i], &local->loc, 02|0100000, fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
1409 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-data.c", __FUNCTION__,
1412, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->open_cbk) tmp_cbk = afr_sh_data_open_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->open"
; _new->unwind_to = "afr_sh_data_open_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->open_cbk = afr_sh_data_open_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->open); priv->children[i]->fops->open (
_new, priv->children[i], &local->loc, 02|0100000, fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
1410 priv->children[i]->fops->open,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-data.c", __FUNCTION__,
1412, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->open_cbk) tmp_cbk = afr_sh_data_open_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->open"
; _new->unwind_to = "afr_sh_data_open_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->open_cbk = afr_sh_data_open_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->open); priv->children[i]->fops->open (
_new, priv->children[i], &local->loc, 02|0100000, fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
1411 &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-data.c", __FUNCTION__,
1412, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->open_cbk) tmp_cbk = afr_sh_data_open_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->open"
; _new->unwind_to = "afr_sh_data_open_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->open_cbk = afr_sh_data_open_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->open); priv->children[i]->fops->open (
_new, priv->children[i], &local->loc, 02|0100000, fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
1412 O_RDWR|O_LARGEFILE, fd, 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-data.c", __FUNCTION__,
1412, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( priv->children[i]->fops->open_cbk) tmp_cbk = afr_sh_data_open_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->open"
; _new->unwind_to = "afr_sh_data_open_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->open_cbk = afr_sh_data_open_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->open); priv->children[i]->fops->open (
_new, priv->children[i], &local->loc, 02|0100000, fd
, ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
;
1413
1414 if (!--call_count)
1415 break;
1416 }
1417
1418 return 0;
1419}
1420
1421void
1422afr_sh_non_reg_fix (call_frame_t *frame, xlator_t *this,
1423 int32_t op_ret, int32_t op_errno)
1424{
1425 afr_private_t *priv = NULL((void*)0);
1426 afr_self_heal_t *sh = NULL((void*)0);
1427 afr_local_t *local = NULL((void*)0);
1428 int i = 0;
1429
1430 if (op_ret < 0) {
1431 afr_sh_data_fail (frame, this);
1432 return;
1433 }
1434
1435 local = frame->local;
1436 sh = &local->self_heal;
1437 priv = this->private;
1438
1439 for (i = 0; i < priv->child_count ; i++) {
1440 if (1 == local->child_up[i])
1441 sh->success[i] = 1;
1442 }
1443
1444 afr_sh_erase_pending (frame, this, AFR_DATA_TRANSACTION,
1445 afr_sh_data_erase_pending_cbk,
1446 afr_sh_data_finish);
1447}
1448
1449int
1450afr_sh_non_reg_lock_success (call_frame_t *frame, xlator_t *this)
1451{
1452 afr_local_t *local = NULL((void*)0);
1453 afr_self_heal_t *sh = NULL((void*)0);
1454
1455 local = frame->local;
1456 sh = &local->self_heal;
1457 sh->data_lock_held = _gf_true;
1458 afr_sh_common_lookup (frame, this, &local->loc,
1459 afr_sh_non_reg_fix, NULL((void*)0),
1460 AFR_LOOKUP_FAIL_CONFLICTS |
1461 AFR_LOOKUP_FAIL_MISSING_GFIDS,
1462 NULL((void*)0));
1463 return 0;
1464}
1465
1466gf_boolean_t
1467afr_can_start_data_self_heal (afr_self_heal_t *sh, afr_private_t *priv)
1468{
1469 if (sh->force_confirm_spb)
1470 return _gf_true;
1471 if (sh->do_data_self_heal &&
1472 afr_data_self_heal_enabled (priv->data_self_heal))
1473 return _gf_true;
1474 return _gf_false;
1475}
1476
1477int
1478afr_self_heal_data (call_frame_t *frame, xlator_t *this)
1479{
1480 afr_local_t *local = NULL((void*)0);
1481 afr_self_heal_t *sh = NULL((void*)0);
1482 afr_private_t *priv = this->private;
1483
1484 local = frame->local;
1485 sh = &local->self_heal;
1486
1487 if (afr_can_start_data_self_heal (sh, priv)) {
1488 if (IA_ISREG (sh->type)(sh->type == IA_IFREG)) {
1489 afr_sh_data_open (frame, this);
1490 } else {
1491 afr_sh_data_lock (frame, this, 0, 0, _gf_true,
1492 afr_sh_non_reg_lock_success,
1493 afr_sh_data_fail);
1494 }
1495 } else {
1496 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("not doing data self heal on %s", local
->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1498, GF_LOG_TRACE, "not doing data self heal on %s"
, local->loc.path); } while (0)
1497 "not doing data self heal on %s",do { do { if (0) printf ("not doing data self heal on %s", local
->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1498, GF_LOG_TRACE, "not doing data self heal on %s"
, local->loc.path); } while (0)
1498 local->loc.path)do { do { if (0) printf ("not doing data self heal on %s", local
->loc.path); } while (0); _gf_log (this->name, "afr-self-heal-data.c"
, __FUNCTION__, 1498, GF_LOG_TRACE, "not doing data self heal on %s"
, local->loc.path); } while (0)
;
1499 afr_sh_data_done (frame, this);
1500 }
1501
1502 return 0;
1503}