18
18
#include "afr-self-heal.h"
21
#define ADD_FMT_STRING(msg, off, sh_str, status, print_log) \
23
if (AFR_SELF_HEAL_NOT_ATTEMPTED != status) { \
24
off += snprintf (msg + off, sizeof (msg) - off, \
25
" "sh_str" self heal %s,", \
26
get_sh_completion_status (status));\
31
#define ADD_FMT_STRING_SYNC(msg, off, sh_str, status, print_log) \
33
if (AFR_SELF_HEAL_SYNC_BEGIN == status || \
34
AFR_SELF_HEAL_FAILED == status) { \
35
off += snprintf (msg + off, sizeof (msg) - off, \
36
" "sh_str" self heal %s,", \
37
get_sh_completion_status (status));\
22
44
afr_sh_reset (call_frame_t *frame, xlator_t *this)
573
afr_mark_fool_as_source_by_idx (int32_t *sources, int child_count, int idx)
575
if (idx >= 0 && idx < child_count) {
584
afr_find_largest_file_size (struct iatt *bufs, int32_t *success_children,
590
uint64_t max_size = 0;
591
uint64_t min_size = 0;
592
int num_children = 0;
594
for (i = 0; i < child_count; i++) {
595
if (success_children[i] == -1)
598
child = success_children[i];
599
if (bufs[child].ia_size > max_size) {
600
max_size = bufs[child].ia_size;
604
if ((num_children == 0) || (bufs[child].ia_size < min_size)) {
605
min_size = bufs[child].ia_size;
611
/* If sizes are same for all of them, finding sources will have to
612
* happen with pending changelog. So return -1
614
if ((num_children > 1) && (min_size == max_size))
621
afr_find_newest_file (struct iatt *bufs, int32_t *success_children,
627
uint64_t max_ctime = 0;
629
for (i = 0; i < child_count; i++) {
630
if (success_children[i] == -1)
633
child = success_children[i];
634
if (bufs[child].ia_ctime > max_ctime) {
635
max_ctime = bufs[child].ia_ctime;
524
645
afr_mark_biggest_of_fools_as_source (int32_t *sources, int32_t **pending_matrix,
525
646
afr_node_character *characters,
647
int32_t *success_children,
648
int child_count, struct iatt *bufs)
528
650
int32_t biggest_witness = 0;
529
651
int nsources = 0;
2030
afr_sh_post_nb_entrylk_gfid_sh_cbk (call_frame_t *frame, xlator_t *this)
2032
afr_internal_lock_t *int_lock = NULL;
2033
afr_local_t *local = NULL;
2034
afr_self_heal_t *sh = NULL;
2036
local = frame->local;
2037
sh = &local->self_heal;
2038
int_lock = &local->internal_lock;
2040
if (int_lock->lock_op_ret < 0) {
2041
gf_log (this->name, GF_LOG_INFO,
2042
"Non blocking entrylks failed.");
2043
afr_sh_missing_entries_done (frame, this);
2045
gf_log (this->name, GF_LOG_DEBUG,
2046
"Non blocking entrylks done. Proceeding to FOP");
2047
afr_sh_common_lookup (frame, this, &local->loc,
2048
afr_sh_missing_entries_lookup_done,
2049
sh->sh_gfid_req, AFR_LOOKUP_FAIL_CONFLICTS|
2050
AFR_LOOKUP_FAIL_MISSING_GFIDS,
2058
2163
afr_sh_entrylk (call_frame_t *frame, xlator_t *this, loc_t *loc,
2059
2164
char *base_name, afr_lock_cbk_t lock_cbk)
2119
afr_self_heal_conflicting_entries (call_frame_t *frame, xlator_t *this)
2121
afr_self_heal_parent_entrylk (frame, this,
2122
afr_sh_post_nb_entrylk_conflicting_sh_cbk);
2127
afr_self_heal_gfids (call_frame_t *frame, xlator_t *this)
2129
afr_self_heal_parent_entrylk (frame, this,
2130
afr_sh_post_nb_entrylk_gfid_sh_cbk);
2134
afr_local_t *afr_local_copy (afr_local_t *l, xlator_t *this)
2136
afr_private_t *priv = NULL;
2137
afr_local_t *lc = NULL;
2225
afr_self_heal_missing_entries (call_frame_t *frame, xlator_t *this)
2227
afr_local_t *local = NULL;
2138
2228
afr_self_heal_t *sh = NULL;
2139
afr_self_heal_t *shc = NULL;
2230
local = frame->local;
2231
sh = &local->self_heal;
2233
sh->sh_type_in_action = AFR_SELF_HEAL_GFID_OR_MISSING_ENTRY;
2235
afr_set_self_heal_status (sh, AFR_SELF_HEAL_STARTED);
2237
afr_self_heal_parent_entrylk (frame, this,
2238
afr_sh_post_nb_entrylk_missing_entry_sh_cbk);
2243
afr_self_heal_local_init (afr_local_t *l, xlator_t *this)
2245
afr_private_t *priv = NULL;
2246
afr_local_t *lc = NULL;
2247
afr_self_heal_t *sh = NULL;
2248
afr_self_heal_t *shc = NULL;
2142
2251
priv = this->private;
2174
2293
lc->cont.lookup.inode = inode_ref (l->cont.lookup.inode);
2175
2294
if (l->cont.lookup.xattr)
2176
2295
lc->cont.lookup.xattr = dict_ref (l->cont.lookup.xattr);
2177
if (l->internal_lock.inode_locked_nodes)
2178
lc->internal_lock.inode_locked_nodes =
2179
memdup (l->internal_lock.inode_locked_nodes,
2180
sizeof (*lc->internal_lock.inode_locked_nodes) * priv->child_count);
2182
lc->internal_lock.inode_locked_nodes =
2183
GF_CALLOC (sizeof (*l->internal_lock.inode_locked_nodes),
2187
if (l->internal_lock.locked_nodes)
2188
lc->internal_lock.locked_nodes =
2189
memdup (l->internal_lock.locked_nodes,
2190
sizeof (*lc->internal_lock.locked_nodes) * priv->child_count);
2192
lc->internal_lock.locked_nodes =
2193
GF_CALLOC (sizeof (*l->internal_lock.locked_nodes),
2197
for (i = 0; i < l->internal_lock.lockee_count; i++) {
2198
loc_copy (&lc->internal_lock.lockee[i].loc,
2199
&l->internal_lock.lockee[i].loc);
2201
lc->internal_lock.lockee[i].locked_count =
2202
l->internal_lock.lockee[i].locked_count;
2204
if (l->internal_lock.lockee[i].basename)
2205
lc->internal_lock.lockee[i].basename =
2206
gf_strdup (l->internal_lock.lockee[i].basename);
2208
if (l->internal_lock.lockee[i].locked_nodes) {
2209
lc->internal_lock.lockee[i].locked_nodes =
2210
memdup (l->internal_lock.lockee[i].locked_nodes,
2211
sizeof (*lc->internal_lock.lockee[i].locked_nodes) *
2214
lc->internal_lock.lockee[i].locked_nodes =
2215
GF_CALLOC (priv->child_count,
2216
sizeof (*lc->internal_lock.lockee[i].locked_nodes),
2297
lc->internal_lock.locked_nodes =
2298
GF_CALLOC (sizeof (*l->internal_lock.locked_nodes),
2299
priv->child_count, gf_afr_mt_char);
2300
if (!lc->internal_lock.locked_nodes) {
2221
lc->internal_lock.lockee_count = l->internal_lock.lockee_count;
2223
lc->internal_lock.inodelk_lock_count =
2224
l->internal_lock.inodelk_lock_count;
2225
lc->internal_lock.entrylk_lock_count =
2226
l->internal_lock.entrylk_lock_count;
2305
ret = afr_inodelk_init (&lc->internal_lock.inodelk[0],
2306
this->name, priv->child_count);
2312
afr_local_cleanup (lc, this);
2239
2324
afr_local_t * orig_frame_local = NULL;
2240
2325
afr_self_heal_t * orig_frame_sh = NULL;
2241
2326
char sh_type_str[256] = {0,};
2327
gf_loglevel_t loglevel = 0;
2243
2329
priv = this->private;
2244
2330
local = bgsh_frame->local;
2245
2331
sh = &local->self_heal;
2247
if (local->govinda_gOvinda) {
2333
if (local->unhealable) {
2248
2334
afr_set_split_brain (this, sh->inode, SPB, SPB);
2252
2337
afr_self_heal_type_str_get (sh, sh_type_str,
2253
2338
sizeof(sh_type_str));
2254
if (sh->op_failed) {
2255
gf_loglevel_t loglevel = GF_LOG_ERROR;
2256
if (priv->shd.iamshd)
2257
loglevel = GF_LOG_DEBUG;
2259
gf_log (this->name, loglevel, "background %s self-heal "
2260
"failed on %s", sh_type_str, local->loc.path);
2339
if (is_self_heal_failed (sh, AFR_CHECK_ALL) && !priv->shd.iamshd) {
2340
loglevel = GF_LOG_ERROR;
2341
} else if (!is_self_heal_failed (sh, AFR_CHECK_ALL)) {
2342
loglevel = GF_LOG_INFO;
2263
gf_log (this->name, GF_LOG_DEBUG, "background %s self-heal "
2264
"completed on %s", sh_type_str, local->loc.path);
2344
loglevel = GF_LOG_DEBUG;
2347
afr_log_self_heal_completion_status (local, loglevel);
2268
2349
FRAME_SU_UNDO (bgsh_frame, afr_local_t);
2270
2351
if (!sh->unwound && sh->unwind) {
2598
2678
GF_FREE (erase_xattr);
2601
sh->op_failed = _gf_true;
2681
afr_set_self_heal_status (sh, AFR_SELF_HEAL_FAILED);
2602
2682
finish (frame, this);
2689
afr_set_self_heal_status(afr_self_heal_t *sh, afr_self_heal_status status)
2691
xlator_t *this = NULL;
2692
afr_sh_status_for_all_type *sh_status = &(sh->afr_all_sh_status);
2693
afr_self_heal_type sh_type_in_action = sh->sh_type_in_action;
2697
gf_log_callingfn (this->name, GF_LOG_ERROR, "Null self heal"
2702
switch (sh_type_in_action) {
2703
case AFR_SELF_HEAL_GFID_OR_MISSING_ENTRY:
2704
sh_status->gfid_or_missing_entry_self_heal = status;
2706
case AFR_SELF_HEAL_METADATA:
2707
sh_status->metadata_self_heal = status;
2709
case AFR_SELF_HEAL_DATA:
2710
sh_status->data_self_heal = status;
2712
case AFR_SELF_HEAL_ENTRY:
2713
sh_status->entry_self_heal = status;
2715
case AFR_SELF_HEAL_INVALID:
2716
gf_log_callingfn (this->name, GF_LOG_ERROR, "Invalid"
2717
"self heal type in action");
2725
afr_set_local_for_unhealable (afr_local_t *local)
2727
afr_self_heal_t *sh = NULL;
2729
sh = &local->self_heal;
2731
local->unhealable = 1;
2732
afr_set_self_heal_status (sh, AFR_SELF_HEAL_FAILED);
2736
is_self_heal_failed (afr_self_heal_t *sh, afr_sh_fail_check_type type)
2738
afr_sh_status_for_all_type sh_status = sh->afr_all_sh_status;
2739
afr_self_heal_type sh_type_in_action = AFR_SELF_HEAL_INVALID;
2740
afr_self_heal_status status = AFR_SELF_HEAL_FAILED;
2741
xlator_t *this = NULL;
2747
gf_log_callingfn (this->name, GF_LOG_ERROR, "Null self heal "
2753
if (type == AFR_CHECK_ALL) {
2754
if ((sh_status.gfid_or_missing_entry_self_heal == AFR_SELF_HEAL_FAILED)
2755
|| (sh_status.metadata_self_heal == AFR_SELF_HEAL_FAILED)
2756
|| (sh_status.data_self_heal == AFR_SELF_HEAL_FAILED)
2757
|| (sh_status.entry_self_heal == AFR_SELF_HEAL_FAILED))
2759
} else if (type == AFR_CHECK_SPECIFIC) {
2760
sh_type_in_action = sh->sh_type_in_action;
2761
switch (sh_type_in_action) {
2762
case AFR_SELF_HEAL_GFID_OR_MISSING_ENTRY:
2763
status = sh_status.gfid_or_missing_entry_self_heal;
2765
case AFR_SELF_HEAL_METADATA:
2766
status = sh_status.metadata_self_heal;
2768
case AFR_SELF_HEAL_ENTRY:
2769
status = sh_status.entry_self_heal;
2771
case AFR_SELF_HEAL_DATA:
2772
status = sh_status.data_self_heal;
2774
case AFR_SELF_HEAL_INVALID:
2775
status = AFR_SELF_HEAL_NOT_ATTEMPTED;
2778
if (status == AFR_SELF_HEAL_FAILED)
2788
get_sh_completion_status (afr_self_heal_status status)
2791
char *not_attempted = " is not attempted";
2792
char *failed = " failed";
2793
char *started = " is started";
2794
char *sync_begin = " is successfully completed";
2795
char *result = " has unknown status";
2799
case AFR_SELF_HEAL_NOT_ATTEMPTED:
2800
result = not_attempted;
2802
case AFR_SELF_HEAL_FAILED:
2805
case AFR_SELF_HEAL_STARTED:
2808
case AFR_SELF_HEAL_SYNC_BEGIN:
2809
result = sync_begin;
2818
afr_log_self_heal_completion_status (afr_local_t *local, gf_loglevel_t loglvl)
2821
char sh_log[4096] = {0};
2822
afr_self_heal_t *sh = &local->self_heal;
2823
afr_sh_status_for_all_type all_status = sh->afr_all_sh_status;
2824
xlator_t *this = NULL;
2827
int metadata_sh = 0;
2832
ADD_FMT_STRING (sh_log, off, "gfid or missing entry",
2833
all_status.gfid_or_missing_entry_self_heal, print_log);
2834
ADD_FMT_STRING_SYNC (sh_log, off, "metadata",
2835
all_status.metadata_self_heal, print_log);
2836
if (sh->background) {
2837
ADD_FMT_STRING_SYNC (sh_log, off, "backgroung data",
2838
all_status.data_self_heal, print_log);
2840
ADD_FMT_STRING_SYNC (sh_log, off, "foreground data",
2841
all_status.data_self_heal, print_log);
2843
ADD_FMT_STRING_SYNC (sh_log, off, "entry", all_status.entry_self_heal,
2846
if (AFR_SELF_HEAL_SYNC_BEGIN == all_status.data_self_heal &&
2847
strcmp (sh->data_sh_info, "") && sh->data_sh_info )
2849
if (AFR_SELF_HEAL_SYNC_BEGIN == all_status.metadata_self_heal &&
2850
strcmp (sh->metadata_sh_info, "") && sh->metadata_sh_info)
2856
gf_log (this->name, loglvl, "%s %s %s on %s", sh_log,
2857
((data_sh == 1) ? sh->data_sh_info : ""),
2858
((metadata_sh == 1) ? sh->metadata_sh_info : ""),