| 1 |
/* |
| 2 |
Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com> |
| 3 |
This file is part of GlusterFS. |
| 4 |
|
| 5 |
This file is licensed to you under your choice of the GNU Lesser |
| 6 |
General Public License, version 3 or any later version (LGPLv3 or |
| 7 |
later), or the GNU General Public License, version 2 (GPLv2), in all |
| 8 |
cases as published by the Free Software Foundation. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <glusterfs/events.h> |
| 12 |
#include "afr.h" |
| 13 |
#include "afr-self-heal.h" |
| 14 |
#include "afr-messages.h" |
| 15 |
|
| 16 |
static int |
| 17 |
__afr_selfheal_assign_gfid(xlator_t *this, inode_t *parent, uuid_t pargfid, |
| 18 |
const char *bname, inode_t *inode, |
| 19 |
struct afr_reply *replies, void *gfid, |
| 20 |
unsigned char *locked_on, int source, |
| 21 |
unsigned char *sources, gf_boolean_t is_gfid_absent, |
| 22 |
int *gfid_idx) |
| 23 |
{ |
| 24 |
int ret = 0; |
| 25 |
int up_count = 0; |
| 26 |
int locked_count = 0; |
| 27 |
afr_private_t *priv = NULL; |
| 28 |
|
| 29 |
priv = this->private; |
| 30 |
|
| 31 |
gf_uuid_copy(parent->gfid, pargfid); |
| 32 |
|
| 33 |
if (is_gfid_absent) { |
| 34 |
/* Ensure all children of AFR are up before performing gfid heal, to |
| 35 |
* guard against the possibility of gfid split brain. */ |
| 36 |
|
| 37 |
up_count = AFR_COUNT(priv->child_up, priv->child_count); |
| 38 |
if (up_count != priv->child_count) { |
| 39 |
ret = -EIO; |
| 40 |
goto out; |
| 41 |
} |
| 42 |
|
| 43 |
locked_count = AFR_COUNT(locked_on, priv->child_count); |
| 44 |
if (locked_count != priv->child_count) { |
| 45 |
ret = -EIO; |
| 46 |
goto out; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
ret = afr_lookup_and_heal_gfid(this, parent, bname, inode, replies, source, |
| 51 |
sources, gfid, gfid_idx); |
| 52 |
|
| 53 |
out: |
| 54 |
return ret; |
| 55 |
} |
| 56 |
|
| 57 |
static int |
| 58 |
__afr_selfheal_name_impunge(call_frame_t *frame, xlator_t *this, |
| 59 |
inode_t *parent, uuid_t pargfid, const char *bname, |
| 60 |
inode_t *inode, struct afr_reply *replies, |
| 61 |
int gfid_idx) |
| 62 |
{ |
| 63 |
int i = 0; |
| 64 |
afr_private_t *priv = NULL; |
| 65 |
int ret = 0; |
| 66 |
unsigned char *sources = NULL; |
| 67 |
|
| 68 |
priv = this->private; |
| 69 |
|
| 70 |
sources = alloca0(priv->child_count); |
| 71 |
|
| 72 |
gf_uuid_copy(parent->gfid, pargfid); |
| 73 |
|
| 74 |
for (i = 0; i < priv->child_count; i++) { |
| 75 |
if (!replies[i].valid || replies[i].op_ret != 0) |
| 76 |
continue; |
| 77 |
|
| 78 |
if (gf_uuid_compare(replies[i].poststat.ia_gfid, |
| 79 |
replies[gfid_idx].poststat.ia_gfid) == 0) { |
| 80 |
sources[i] = 1; |
| 81 |
continue; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
for (i = 0; i < priv->child_count; i++) { |
| 86 |
if (sources[i]) |
| 87 |
continue; |
| 88 |
|
| 89 |
ret |= afr_selfheal_recreate_entry(frame, i, gfid_idx, sources, parent, |
| 90 |
bname, inode, replies); |
| 91 |
} |
| 92 |
|
| 93 |
return ret; |
| 94 |
} |
| 95 |
|
| 96 |
static int |
| 97 |
__afr_selfheal_name_expunge(xlator_t *this, inode_t *parent, uuid_t pargfid, |
| 98 |
const char *bname, inode_t *inode, |
| 99 |
struct afr_reply *replies) |
| 100 |
{ |
| 101 |
int i = 0; |
| 102 |
afr_private_t *priv = NULL; |
| 103 |
int ret = 0; |
| 104 |
|
| 105 |
priv = this->private; |
| 106 |
|
| 107 |
for (i = 0; i < priv->child_count; i++) { |
| 108 |
if (!replies[i].valid) |
| 109 |
continue; |
| 110 |
|
| 111 |
if (replies[i].op_ret) |
| 112 |
continue; |
| 113 |
|
| 114 |
ret |= afr_selfheal_entry_delete(this, parent, bname, inode, i, |
| 115 |
replies); |
| 116 |
} |
| 117 |
|
| 118 |
return ret; |
| 119 |
} |
| 120 |
|
| 121 |
static gf_boolean_t |
| 122 |
afr_selfheal_name_need_heal_check(xlator_t *this, struct afr_reply *replies) |
| 123 |
{ |
| 124 |
int i = 0; |
| 125 |
int first_idx = -1; |
| 126 |
gf_boolean_t need_heal = _gf_false; |
| 127 |
afr_private_t *priv = NULL; |
| 128 |
|
| 129 |
priv = this->private; |
| 130 |
|
| 131 |
for (i = 0; i < priv->child_count; i++) { |
| 132 |
if (!replies[i].valid) |
| 133 |
continue; |
| 134 |
|
| 135 |
if ((replies[i].op_ret == -1) && (replies[i].op_errno == ENODATA)) |
| 136 |
need_heal = _gf_true; |
| 137 |
|
| 138 |
if (first_idx == -1) { |
| 139 |
first_idx = i; |
| 140 |
continue; |
| 141 |
} |
| 142 |
|
| 143 |
if (replies[i].op_ret != replies[first_idx].op_ret) |
| 144 |
need_heal = _gf_true; |
| 145 |
|
| 146 |
if (gf_uuid_compare(replies[i].poststat.ia_gfid, |
| 147 |
replies[first_idx].poststat.ia_gfid)) |
| 148 |
need_heal = _gf_true; |
| 149 |
|
| 150 |
if ((replies[i].op_ret == 0) && |
| 151 |
(gf_uuid_is_null(replies[i].poststat.ia_gfid))) |
| 152 |
need_heal = _gf_true; |
| 153 |
} |
| 154 |
|
| 155 |
return need_heal; |
| 156 |
} |
| 157 |
|
| 158 |
static int |
| 159 |
afr_selfheal_name_type_mismatch_check(xlator_t *this, struct afr_reply *replies, |
| 160 |
int source, unsigned char *sources, |
| 161 |
uuid_t pargfid, const char *bname) |
| 162 |
{ |
| 163 |
int i = 0; |
| 164 |
int type_idx = -1; |
| 165 |
ia_type_t inode_type = IA_INVAL; |
| 166 |
ia_type_t inode_type1 = IA_INVAL; |
| 167 |
afr_private_t *priv = NULL; |
| 168 |
|
| 169 |
priv = this->private; |
| 170 |
|
| 171 |
for (i = 0; i < priv->child_count; i++) { |
| 172 |
if (!replies[i].valid || replies[i].op_ret != 0) |
| 173 |
continue; |
| 174 |
|
| 175 |
if (replies[i].poststat.ia_type == IA_INVAL) |
| 176 |
continue; |
| 177 |
|
| 178 |
if (inode_type == IA_INVAL) { |
| 179 |
inode_type = replies[i].poststat.ia_type; |
| 180 |
type_idx = i; |
| 181 |
continue; |
| 182 |
} |
| 183 |
inode_type1 = replies[i].poststat.ia_type; |
| 184 |
if (sources[i] || source == -1) { |
| 185 |
if ((sources[type_idx] || source == -1) && |
| 186 |
(inode_type != inode_type1)) { |
| 187 |
gf_msg(this->name, GF_LOG_WARNING, 0, AFR_MSG_SPLIT_BRAIN, |
| 188 |
"Type mismatch for <gfid:%s>/%s: " |
| 189 |
"%s on %s and %s on %s", |
| 190 |
uuid_utoa(pargfid), bname, |
| 191 |
gf_inode_type_to_str(inode_type1), |
| 192 |
priv->children[i]->name, |
| 193 |
gf_inode_type_to_str(inode_type), |
| 194 |
priv->children[type_idx]->name); |
| 195 |
gf_event(EVENT_AFR_SPLIT_BRAIN, |
| 196 |
"client-pid=%d;" |
| 197 |
"subvol=%s;type=file;" |
| 198 |
"file=<gfid:%s>/%s;count=2;" |
| 199 |
"child-%d=%s;type-%d=%s;child-%d=%s;" |
| 200 |
"type-%d=%s", |
| 201 |
this->ctx->cmd_args.client_pid, this->name, |
| 202 |
uuid_utoa(pargfid), bname, i, priv->children[i]->name, |
| 203 |
i, gf_inode_type_to_str(inode_type1), type_idx, |
| 204 |
priv->children[type_idx]->name, type_idx, |
| 205 |
gf_inode_type_to_str(inode_type)); |
| 206 |
return -EIO; |
| 207 |
} |
| 208 |
inode_type = replies[i].poststat.ia_type; |
| 209 |
type_idx = i; |
| 210 |
} |
| 211 |
} |
| 212 |
return 0; |
| 213 |
} |
| 214 |
|
| 215 |
static int |
| 216 |
afr_selfheal_name_gfid_mismatch_check(xlator_t *this, struct afr_reply *replies, |
| 217 |
int source, unsigned char *sources, |
| 218 |
int *gfid_idx, uuid_t pargfid, |
| 219 |
const char *bname, inode_t *inode, |
| 220 |
unsigned char *locked_on, dict_t *req, |
| 221 |
dict_t *rsp) |
| 222 |
{ |
| 223 |
int i = 0; |
| 224 |
int gfid_idx_iter = -1; |
| 225 |
int ret = -1; |
| 226 |
void *gfid = NULL; |
| 227 |
void *gfid1 = NULL; |
| 228 |
afr_private_t *priv = NULL; |
| 229 |
|
| 230 |
priv = this->private; |
| 231 |
|
| 232 |
for (i = 0; i < priv->child_count; i++) { |
| 233 |
if (!replies[i].valid || replies[i].op_ret != 0) |
| 234 |
continue; |
| 235 |
|
| 236 |
if (gf_uuid_is_null(replies[i].poststat.ia_gfid)) |
| 237 |
continue; |
| 238 |
|
| 239 |
if (!gfid) { |
| 240 |
gfid = &replies[i].poststat.ia_gfid; |
| 241 |
gfid_idx_iter = i; |
| 242 |
continue; |
| 243 |
} |
| 244 |
|
| 245 |
gfid1 = &replies[i].poststat.ia_gfid; |
| 246 |
if (sources[i] || source == -1) { |
| 247 |
if ((sources[gfid_idx_iter] || source == -1) && |
| 248 |
gf_uuid_compare(gfid, gfid1)) { |
| 249 |
ret = afr_gfid_split_brain_source( |
| 250 |
this, replies, inode, pargfid, bname, gfid_idx_iter, i, |
| 251 |
locked_on, gfid_idx, req, rsp); |
| 252 |
if (!ret && *gfid_idx >= 0) { |
| 253 |
ret = dict_set_sizen_str_sizen(rsp, "gfid-heal-msg", |
| 254 |
"GFID split-brain resolved"); |
| 255 |
if (ret) |
| 256 |
gf_msg(this->name, GF_LOG_ERROR, 0, |
| 257 |
AFR_MSG_DICT_SET_FAILED, |
| 258 |
"Error setting gfid-" |
| 259 |
"heal-msg dict"); |
| 260 |
} |
| 261 |
return ret; |
| 262 |
} |
| 263 |
gfid = &replies[i].poststat.ia_gfid; |
| 264 |
gfid_idx_iter = i; |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
*gfid_idx = gfid_idx_iter; |
| 269 |
return 0; |
| 270 |
} |
| 271 |
|
| 272 |
static gf_boolean_t |
| 273 |
afr_selfheal_name_source_empty_check(xlator_t *this, struct afr_reply *replies, |
| 274 |
unsigned char *sources, int source) |
| 275 |
{ |
| 276 |
int i = 0; |
| 277 |
afr_private_t *priv = NULL; |
| 278 |
gf_boolean_t source_is_empty = _gf_true; |
| 279 |
|
| 280 |
priv = this->private; |
| 281 |
|
| 282 |
if (source == -1) { |
| 283 |
source_is_empty = _gf_false; |
| 284 |
goto out; |
| 285 |
} |
| 286 |
|
| 287 |
for (i = 0; i < priv->child_count; i++) { |
| 288 |
if (!sources[i]) |
| 289 |
continue; |
| 290 |
|
| 291 |
if (replies[i].op_ret == -1 && replies[i].op_errno == ENOENT) |
| 292 |
continue; |
| 293 |
|
| 294 |
source_is_empty = _gf_false; |
| 295 |
break; |
| 296 |
} |
| 297 |
out: |
| 298 |
return source_is_empty; |
| 299 |
} |
| 300 |
|
| 301 |
static int |
| 302 |
__afr_selfheal_name_do(call_frame_t *frame, xlator_t *this, inode_t *parent, |
| 303 |
uuid_t pargfid, const char *bname, inode_t *inode, |
| 304 |
unsigned char *sources, unsigned char *sinks, |
| 305 |
unsigned char *healed_sinks, int source, |
| 306 |
unsigned char *locked_on, struct afr_reply *replies, |
| 307 |
void *gfid_req, dict_t *req, dict_t *rsp) |
| 308 |
{ |
| 309 |
int gfid_idx = -1; |
| 310 |
int ret = -1; |
| 311 |
void *gfid = NULL; |
| 312 |
gf_boolean_t source_is_empty = _gf_true; |
| 313 |
gf_boolean_t need_heal = _gf_false; |
| 314 |
gf_boolean_t is_gfid_absent = _gf_false; |
| 315 |
|
| 316 |
need_heal = afr_selfheal_name_need_heal_check(this, replies); |
| 317 |
if (!need_heal) |
| 318 |
return 0; |
| 319 |
|
| 320 |
source_is_empty = afr_selfheal_name_source_empty_check(this, replies, |
| 321 |
sources, source); |
| 322 |
if (source_is_empty) { |
| 323 |
ret = __afr_selfheal_name_expunge(this, parent, pargfid, bname, inode, |
| 324 |
replies); |
| 325 |
if (ret == -EIO) |
| 326 |
ret = -1; |
| 327 |
return ret; |
| 328 |
} |
| 329 |
|
| 330 |
ret = afr_selfheal_name_type_mismatch_check(this, replies, source, sources, |
| 331 |
pargfid, bname); |
| 332 |
if (ret) |
| 333 |
return ret; |
| 334 |
|
| 335 |
ret = afr_selfheal_name_gfid_mismatch_check(this, replies, source, sources, |
| 336 |
&gfid_idx, pargfid, bname, |
| 337 |
inode, locked_on, req, rsp); |
| 338 |
if (ret) |
| 339 |
return ret; |
| 340 |
|
| 341 |
if (gfid_idx == -1) { |
| 342 |
if (!gfid_req || gf_uuid_is_null(gfid_req)) |
| 343 |
return -1; |
| 344 |
gfid = gfid_req; |
| 345 |
} else { |
| 346 |
gfid = &replies[gfid_idx].poststat.ia_gfid; |
| 347 |
if (source == -1) |
| 348 |
/* Either entry split-brain or dirty xattrs are present on parent.*/ |
| 349 |
source = gfid_idx; |
| 350 |
} |
| 351 |
|
| 352 |
is_gfid_absent = (gfid_idx == -1) ? _gf_true : _gf_false; |
| 353 |
ret = __afr_selfheal_assign_gfid(this, parent, pargfid, bname, inode, |
| 354 |
replies, gfid, locked_on, source, sources, |
| 355 |
is_gfid_absent, &gfid_idx); |
| 356 |
if (ret || (gfid_idx < 0)) |
| 357 |
return ret; |
| 358 |
|
| 359 |
ret = __afr_selfheal_name_impunge(frame, this, parent, pargfid, bname, |
| 360 |
inode, replies, gfid_idx); |
| 361 |
if (ret == -EIO) |
| 362 |
ret = -1; |
| 363 |
|
| 364 |
return ret; |
| 365 |
} |
| 366 |
|
| 367 |
static int |
| 368 |
__afr_selfheal_name_finalize_source(xlator_t *this, unsigned char *sources, |
| 369 |
unsigned char *healed_sinks, |
| 370 |
unsigned char *locked_on, uint64_t *witness) |
| 371 |
{ |
| 372 |
int i = 0; |
| 373 |
afr_private_t *priv = NULL; |
| 374 |
int source = -1; |
| 375 |
int sources_count = 0; |
| 376 |
|
| 377 |
priv = this->private; |
| 378 |
|
| 379 |
sources_count = AFR_COUNT(sources, priv->child_count); |
| 380 |
|
| 381 |
if ((AFR_CMP(locked_on, healed_sinks, priv->child_count) == 0) || |
| 382 |
!sources_count || afr_does_witness_exist(this, witness)) { |
| 383 |
memset(sources, 0, sizeof(*sources) * priv->child_count); |
| 384 |
afr_mark_active_sinks(this, sources, locked_on, healed_sinks); |
| 385 |
return -1; |
| 386 |
} |
| 387 |
|
| 388 |
for (i = 0; i < priv->child_count; i++) { |
| 389 |
if (sources[i]) { |
| 390 |
source = i; |
| 391 |
break; |
| 392 |
} |
| 393 |
} |
| 394 |
|
| 395 |
return source; |
| 396 |
} |
| 397 |
|
| 398 |
static int |
| 399 |
__afr_selfheal_name_prepare(call_frame_t *frame, xlator_t *this, |
| 400 |
inode_t *parent, uuid_t pargfid, |
| 401 |
unsigned char *locked_on, unsigned char *sources, |
| 402 |
unsigned char *sinks, unsigned char *healed_sinks, |
| 403 |
int *source_p) |
| 404 |
{ |
| 405 |
int ret = -1; |
| 406 |
int source = -1; |
| 407 |
afr_private_t *priv = NULL; |
| 408 |
struct afr_reply *replies = NULL; |
| 409 |
uint64_t *witness = NULL; |
| 410 |
|
| 411 |
priv = this->private; |
| 412 |
|
| 413 |
replies = alloca0(priv->child_count * sizeof(*replies)); |
| 414 |
|
| 415 |
ret = afr_selfheal_unlocked_discover(frame, parent, pargfid, replies); |
| 416 |
if (ret) |
| 417 |
goto out; |
| 418 |
|
| 419 |
witness = alloca0(sizeof(*witness) * priv->child_count); |
| 420 |
ret = afr_selfheal_find_direction(frame, this, replies, |
| 421 |
AFR_ENTRY_TRANSACTION, locked_on, sources, |
| 422 |
sinks, witness, NULL); |
| 423 |
if (ret) |
| 424 |
goto out; |
| 425 |
|
| 426 |
/* Initialize the healed_sinks[] array optimistically to |
| 427 |
the intersection of to-be-healed (i.e sinks[]) and |
| 428 |
the list of servers which are up (i.e locked_on[]). |
| 429 |
|
| 430 |
As we encounter failures in the healing process, we |
| 431 |
will unmark the respective servers in the healed_sinks[] |
| 432 |
array. |
| 433 |
*/ |
| 434 |
AFR_INTERSECT(healed_sinks, sinks, locked_on, priv->child_count); |
| 435 |
|
| 436 |
source = __afr_selfheal_name_finalize_source(this, sources, healed_sinks, |
| 437 |
locked_on, witness); |
| 438 |
if (source < 0) { |
| 439 |
/* If source is < 0 (typically split-brain), we perform a |
| 440 |
conservative merge of entries rather than erroring out */ |
| 441 |
} |
| 442 |
*source_p = source; |
| 443 |
|
| 444 |
out: |
| 445 |
if (replies) |
| 446 |
afr_replies_wipe(replies, priv->child_count); |
| 447 |
|
| 448 |
return ret; |
| 449 |
} |
| 450 |
|
| 451 |
static int |
| 452 |
afr_selfheal_name_do(call_frame_t *frame, xlator_t *this, inode_t *parent, |
| 453 |
uuid_t pargfid, const char *bname, void *gfid_req, |
| 454 |
dict_t *req, dict_t *rsp) |
| 455 |
{ |
| 456 |
afr_private_t *priv = NULL; |
| 457 |
unsigned char *sources = NULL; |
| 458 |
unsigned char *sinks = NULL; |
| 459 |
unsigned char *healed_sinks = NULL; |
| 460 |
unsigned char *locked_on = NULL; |
| 461 |
int source = -1; |
| 462 |
struct afr_reply *replies = NULL; |
| 463 |
int ret = -1; |
| 464 |
inode_t *inode = NULL; |
| 465 |
dict_t *xattr = NULL; |
| 466 |
|
| 467 |
xattr = dict_new(); |
| 468 |
if (!xattr) |
| 469 |
return -ENOMEM; |
| 470 |
|
| 471 |
ret = dict_set_int32_sizen(xattr, GF_GFIDLESS_LOOKUP, 1); |
| 472 |
if (ret) { |
| 473 |
dict_unref(xattr); |
| 474 |
return -1; |
| 475 |
} |
| 476 |
|
| 477 |
priv = this->private; |
| 478 |
|
| 479 |
locked_on = alloca0(priv->child_count); |
| 480 |
sources = alloca0(priv->child_count); |
| 481 |
sinks = alloca0(priv->child_count); |
| 482 |
healed_sinks = alloca0(priv->child_count); |
| 483 |
|
| 484 |
replies = alloca0(priv->child_count * sizeof(*replies)); |
| 485 |
|
| 486 |
ret = afr_selfheal_entrylk(frame, this, parent, this->name, bname, |
| 487 |
locked_on); |
| 488 |
{ |
| 489 |
if (ret < priv->child_count) { |
| 490 |
ret = -ENOTCONN; |
| 491 |
goto unlock; |
| 492 |
} |
| 493 |
|
| 494 |
ret = __afr_selfheal_name_prepare(frame, this, parent, pargfid, |
| 495 |
locked_on, sources, sinks, |
| 496 |
healed_sinks, &source); |
| 497 |
if (ret) |
| 498 |
goto unlock; |
| 499 |
|
| 500 |
inode = afr_selfheal_unlocked_lookup_on(frame, parent, bname, replies, |
| 501 |
locked_on, xattr); |
| 502 |
if (!inode) { |
| 503 |
ret = -ENOMEM; |
| 504 |
goto unlock; |
| 505 |
} |
| 506 |
|
| 507 |
ret = __afr_selfheal_name_do(frame, this, parent, pargfid, bname, inode, |
| 508 |
sources, sinks, healed_sinks, source, |
| 509 |
locked_on, replies, gfid_req, req, rsp); |
| 510 |
} |
| 511 |
unlock: |
| 512 |
afr_selfheal_unentrylk(frame, this, parent, this->name, bname, locked_on, |
| 513 |
NULL); |
| 514 |
if (inode) |
| 515 |
inode_unref(inode); |
| 516 |
|
| 517 |
if (replies) |
| 518 |
afr_replies_wipe(replies, priv->child_count); |
| 519 |
if (xattr) |
| 520 |
dict_unref(xattr); |
| 521 |
|
| 522 |
return ret; |
| 523 |
} |
| 524 |
|
| 525 |
static int |
| 526 |
afr_selfheal_name_unlocked_inspect(call_frame_t *frame, xlator_t *this, |
| 527 |
inode_t *parent, uuid_t pargfid, |
| 528 |
const char *bname, gf_boolean_t *need_heal) |
| 529 |
{ |
| 530 |
afr_private_t *priv = NULL; |
| 531 |
int i = 0; |
| 532 |
struct afr_reply *replies = NULL; |
| 533 |
inode_t *inode = NULL; |
| 534 |
int first_idx = -1; |
| 535 |
afr_local_t *local = NULL; |
| 536 |
|
| 537 |
priv = this->private; |
| 538 |
local = frame->local; |
| 539 |
|
| 540 |
replies = alloca0(sizeof(*replies) * priv->child_count); |
| 541 |
|
| 542 |
inode = afr_selfheal_unlocked_lookup_on(frame, parent, bname, replies, |
| 543 |
local->child_up, NULL); |
| 544 |
if (!inode) |
| 545 |
return -ENOMEM; |
| 546 |
|
| 547 |
for (i = 0; i < priv->child_count; i++) { |
| 548 |
if (!replies[i].valid) |
| 549 |
continue; |
| 550 |
|
| 551 |
if ((replies[i].op_ret == -1) && (replies[i].op_errno == ENODATA)) { |
| 552 |
*need_heal = _gf_true; |
| 553 |
break; |
| 554 |
} |
| 555 |
|
| 556 |
if (first_idx == -1) { |
| 557 |
first_idx = i; |
| 558 |
continue; |
| 559 |
} |
| 560 |
|
| 561 |
if (replies[i].op_ret != replies[first_idx].op_ret) { |
| 562 |
*need_heal = _gf_true; |
| 563 |
break; |
| 564 |
} |
| 565 |
|
| 566 |
if (gf_uuid_compare(replies[i].poststat.ia_gfid, |
| 567 |
replies[first_idx].poststat.ia_gfid)) { |
| 568 |
*need_heal = _gf_true; |
| 569 |
break; |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
if (inode) |
| 574 |
inode_unref(inode); |
| 575 |
if (replies) |
| 576 |
afr_replies_wipe(replies, priv->child_count); |
| 577 |
return 0; |
| 578 |
} |
| 579 |
|
| 580 |
int |
| 581 |
afr_selfheal_name(xlator_t *this, uuid_t pargfid, const char *bname, |
| 582 |
void *gfid_req, dict_t *req, dict_t *rsp) |
| 583 |
{ |
| 584 |
inode_t *parent = NULL; |
| 585 |
call_frame_t *frame = NULL; |
| 586 |
int ret = -1; |
| 587 |
gf_boolean_t need_heal = _gf_false; |
| 588 |
|
| 589 |
parent = afr_inode_find(this, pargfid); |
| 590 |
if (!parent) |
| 591 |
goto out; |
| 592 |
|
| 593 |
frame = afr_frame_create(this, NULL); |
| 594 |
if (!frame) |
| 595 |
goto out; |
| 596 |
|
| 597 |
ret = afr_selfheal_name_unlocked_inspect(frame, this, parent, pargfid, |
| 598 |
bname, &need_heal); |
| 599 |
if (ret) |
| 600 |
goto out; |
| 601 |
|
| 602 |
if (need_heal) { |
| 603 |
ret = afr_selfheal_name_do(frame, this, parent, pargfid, bname, |
| 604 |
gfid_req, req, rsp); |
| 605 |
if (ret) |
| 606 |
goto out; |
| 607 |
} |
| 608 |
|
| 609 |
ret = 0; |
| 610 |
out: |
| 611 |
if (parent) |
| 612 |
inode_unref(parent); |
| 613 |
if (frame) |
| 614 |
AFR_STACK_DESTROY(frame); |
| 615 |
|
| 616 |
return ret; |
| 617 |
} |