| 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 |
#include "afr-common.c" |
| 19 |
#include "afr-messages.h" |
| 20 |
|
| 21 |
struct volume_options options[]; |
| 22 |
|
| 23 |
static char *afr_favorite_child_policies[AFR_FAV_CHILD_POLICY_MAX + 1] = { |
| 24 |
[AFR_FAV_CHILD_NONE] = "none", |
| 25 |
[AFR_FAV_CHILD_BY_SIZE] = "size", |
| 26 |
[AFR_FAV_CHILD_BY_CTIME] = "ctime", |
| 27 |
[AFR_FAV_CHILD_BY_MTIME] = "mtime", |
| 28 |
[AFR_FAV_CHILD_BY_MAJORITY] = "majority", |
| 29 |
[AFR_FAV_CHILD_POLICY_MAX] = NULL, |
| 30 |
}; |
| 31 |
|
| 32 |
int32_t |
| 33 |
notify(xlator_t *this, int32_t event, void *data, ...) |
| 34 |
{ |
| 35 |
int ret = -1; |
| 36 |
va_list ap; |
| 37 |
void *data2 = NULL; |
| 38 |
|
| 39 |
va_start(ap, data); |
| 40 |
data2 = va_arg(ap, dict_t *); |
| 41 |
va_end(ap); |
| 42 |
ret = afr_notify(this, event, data, data2); |
| 43 |
|
| 44 |
return ret; |
| 45 |
} |
| 46 |
|
| 47 |
int32_t |
| 48 |
mem_acct_init(xlator_t *this) |
| 49 |
{ |
| 50 |
int ret = -1; |
| 51 |
|
| 52 |
if (!this) |
| 53 |
return ret; |
| 54 |
|
| 55 |
ret = xlator_mem_acct_init(this, gf_afr_mt_end); |
| 56 |
|
| 57 |
if (ret != 0) { |
| 58 |
return ret; |
| 59 |
} |
| 60 |
|
| 61 |
return ret; |
| 62 |
} |
| 63 |
|
| 64 |
static int |
| 65 |
xlator_subvolume_index(xlator_t *this, xlator_t *subvol) |
| 66 |
{ |
| 67 |
int index = -1; |
| 68 |
int i = 0; |
| 69 |
xlator_list_t *list = NULL; |
| 70 |
|
| 71 |
list = this->children; |
| 72 |
|
| 73 |
while (list) { |
| 74 |
if (subvol == list->xlator || |
| 75 |
strcmp(subvol->name, list->xlator->name) == 0) { |
| 76 |
index = i; |
| 77 |
break; |
| 78 |
} |
| 79 |
list = list->next; |
| 80 |
i++; |
| 81 |
} |
| 82 |
|
| 83 |
return index; |
| 84 |
} |
| 85 |
|
| 86 |
static void |
| 87 |
fix_quorum_options(xlator_t *this, afr_private_t *priv, char *qtype, |
| 88 |
dict_t *options) |
| 89 |
{ |
| 90 |
if (dict_get_sizen(options, "quorum-type") == NULL) { |
| 91 |
/* If user doesn't configure anything enable auto-quorum if the |
| 92 |
* replica has more than two subvolumes */ |
| 93 |
if (priv->child_count > 2) |
| 94 |
qtype = "auto"; |
| 95 |
} |
| 96 |
|
| 97 |
if (priv->quorum_count && strcmp(qtype, "fixed")) { |
| 98 |
gf_msg(this->name, GF_LOG_WARNING, 0, AFR_MSG_QUORUM_OVERRIDE, |
| 99 |
"quorum-type %s overriding quorum-count %u", qtype, |
| 100 |
priv->quorum_count); |
| 101 |
} |
| 102 |
|
| 103 |
if (!strcmp(qtype, "none")) { |
| 104 |
priv->quorum_count = 0; |
| 105 |
} else if (!strcmp(qtype, "auto")) { |
| 106 |
priv->quorum_count = AFR_QUORUM_AUTO; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
static int |
| 111 |
afr_set_favorite_child_policy(afr_private_t *priv, char *policy) |
| 112 |
{ |
| 113 |
int index = -1; |
| 114 |
|
| 115 |
index = gf_get_index_by_elem(afr_favorite_child_policies, policy); |
| 116 |
if (index < 0 || index >= AFR_FAV_CHILD_POLICY_MAX) |
| 117 |
return -1; |
| 118 |
|
| 119 |
priv->fav_child_policy = index; |
| 120 |
|
| 121 |
return 0; |
| 122 |
} |
| 123 |
|
| 124 |
static void |
| 125 |
set_data_self_heal_algorithm(afr_private_t *priv, char *algo) |
| 126 |
{ |
| 127 |
if (!algo) { |
| 128 |
priv->data_self_heal_algorithm = AFR_SELFHEAL_DATA_DYNAMIC; |
| 129 |
} else if (strcmp(algo, "full") == 0) { |
| 130 |
priv->data_self_heal_algorithm = AFR_SELFHEAL_DATA_FULL; |
| 131 |
} else if (strcmp(algo, "diff") == 0) { |
| 132 |
priv->data_self_heal_algorithm = AFR_SELFHEAL_DATA_DIFF; |
| 133 |
} else { |
| 134 |
priv->data_self_heal_algorithm = AFR_SELFHEAL_DATA_DYNAMIC; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
static void |
| 139 |
afr_handle_anon_inode_options(afr_private_t *priv, dict_t *options) |
| 140 |
{ |
| 141 |
char *volfile_id_str = NULL; |
| 142 |
uuid_t anon_inode_gfid = {0}; |
| 143 |
|
| 144 |
/* If volume id is not present don't enable anything. */ |
| 145 |
if (dict_get_str(options, "volume-id", &volfile_id_str)) |
| 146 |
return; |
| 147 |
|
| 148 |
/* Note anon_inode_name is not supposed to change once assigned. */ |
| 149 |
if (!priv->anon_inode_name[0]) { |
| 150 |
int nr = snprintf(priv->anon_inode_name, NAME_MAX, "%s-%s", |
| 151 |
AFR_ANON_DIR_PREFIX, volfile_id_str); |
| 152 |
/* Check whether an output was not truncated. */ |
| 153 |
GF_ASSERT(nr < NAME_MAX); |
| 154 |
gf_uuid_parse(volfile_id_str, anon_inode_gfid); |
| 155 |
/* Flip a bit to make sure volfile-id and anon-gfid are not same. */ |
| 156 |
anon_inode_gfid[0] ^= 1; |
| 157 |
uuid_utoa_r(anon_inode_gfid, priv->anon_gfid_str); |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
int |
| 162 |
reconfigure(xlator_t *this, dict_t *options) |
| 163 |
{ |
| 164 |
afr_private_t *priv = NULL; |
| 165 |
xlator_t *read_subvol = NULL; |
| 166 |
int read_subvol_index = -1; |
| 167 |
time_t timeout_old = 0; |
| 168 |
int ret = -1; |
| 169 |
int index = -1; |
| 170 |
char *qtype = NULL; |
| 171 |
char *fav_child_policy = NULL; |
| 172 |
char *data_self_heal = NULL; |
| 173 |
char *data_self_heal_algorithm = NULL; |
| 174 |
char *locking_scheme = NULL; |
| 175 |
gf_boolean_t consistent_io = _gf_false; |
| 176 |
gf_boolean_t choose_local_old = _gf_false; |
| 177 |
gf_boolean_t enabled_old = _gf_false; |
| 178 |
|
| 179 |
priv = this->private; |
| 180 |
|
| 181 |
GF_OPTION_RECONF("metadata-splitbrain-forced-heal", |
| 182 |
priv->metadata_splitbrain_forced_heal, options, bool, out); |
| 183 |
|
| 184 |
GF_OPTION_RECONF("background-self-heal-count", |
| 185 |
priv->background_self_heal_count, options, uint32, out); |
| 186 |
|
| 187 |
GF_OPTION_RECONF("heal-wait-queue-length", priv->heal_wait_qlen, options, |
| 188 |
uint32, out); |
| 189 |
|
| 190 |
GF_OPTION_RECONF("metadata-self-heal", priv->metadata_self_heal, options, |
| 191 |
bool, out); |
| 192 |
|
| 193 |
GF_OPTION_RECONF("data-self-heal", data_self_heal, options, str, out); |
| 194 |
if (gf_string2boolean(data_self_heal, &priv->data_self_heal) == -1) |
| 195 |
goto out; |
| 196 |
|
| 197 |
GF_OPTION_RECONF("entry-self-heal", priv->entry_self_heal, options, bool, |
| 198 |
out); |
| 199 |
|
| 200 |
GF_OPTION_RECONF("data-self-heal-window-size", |
| 201 |
priv->data_self_heal_window_size, options, uint32, out); |
| 202 |
|
| 203 |
GF_OPTION_RECONF("data-self-heal-algorithm", data_self_heal_algorithm, |
| 204 |
options, str, out); |
| 205 |
set_data_self_heal_algorithm(priv, data_self_heal_algorithm); |
| 206 |
|
| 207 |
GF_OPTION_RECONF("halo-enabled", priv->halo_enabled, options, bool, out); |
| 208 |
|
| 209 |
GF_OPTION_RECONF("halo-shd-max-latency", priv->shd.halo_max_latency_msec, |
| 210 |
options, uint32, out); |
| 211 |
|
| 212 |
GF_OPTION_RECONF("halo-nfsd-max-latency", priv->nfsd.halo_max_latency_msec, |
| 213 |
options, uint32, out); |
| 214 |
|
| 215 |
GF_OPTION_RECONF("halo-max-latency", priv->halo_max_latency_msec, options, |
| 216 |
uint32, out); |
| 217 |
|
| 218 |
GF_OPTION_RECONF("halo-max-replicas", priv->halo_max_replicas, options, |
| 219 |
uint32, out); |
| 220 |
|
| 221 |
GF_OPTION_RECONF("halo-min-replicas", priv->halo_min_replicas, options, |
| 222 |
uint32, out); |
| 223 |
|
| 224 |
GF_OPTION_RECONF("read-subvolume", read_subvol, options, xlator, out); |
| 225 |
|
| 226 |
choose_local_old = priv->choose_local; |
| 227 |
GF_OPTION_RECONF("choose-local", priv->choose_local, options, bool, out); |
| 228 |
|
| 229 |
if (choose_local_old != priv->choose_local) { |
| 230 |
priv->read_child = -1; |
| 231 |
if (choose_local_old == _gf_false) |
| 232 |
priv->did_discovery = _gf_false; |
| 233 |
} |
| 234 |
|
| 235 |
GF_OPTION_RECONF("read-hash-mode", priv->hash_mode, options, uint32, out); |
| 236 |
|
| 237 |
if (read_subvol) { |
| 238 |
index = xlator_subvolume_index(this, read_subvol); |
| 239 |
if (index == -1) { |
| 240 |
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_INVALID_SUBVOL, |
| 241 |
"%s not a subvolume", read_subvol->name); |
| 242 |
goto out; |
| 243 |
} |
| 244 |
priv->read_child = index; |
| 245 |
} |
| 246 |
|
| 247 |
GF_OPTION_RECONF("read-subvolume-index", read_subvol_index, options, int32, |
| 248 |
out); |
| 249 |
|
| 250 |
if (read_subvol_index > -1) { |
| 251 |
index = read_subvol_index; |
| 252 |
if (index >= priv->child_count) { |
| 253 |
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_INVALID_SUBVOL, |
| 254 |
"%d not a subvolume-index", index); |
| 255 |
goto out; |
| 256 |
} |
| 257 |
priv->read_child = index; |
| 258 |
} |
| 259 |
|
| 260 |
GF_OPTION_RECONF("pre-op-compat", priv->pre_op_compat, options, bool, out); |
| 261 |
GF_OPTION_RECONF("locking-scheme", locking_scheme, options, str, out); |
| 262 |
priv->granular_locks = (strcmp(locking_scheme, "granular") == 0); |
| 263 |
GF_OPTION_RECONF("full-lock", priv->full_lock, options, bool, out); |
| 264 |
GF_OPTION_RECONF("granular-entry-heal", priv->esh_granular, options, bool, |
| 265 |
out); |
| 266 |
|
| 267 |
GF_OPTION_RECONF("eager-lock", priv->eager_lock, options, bool, out); |
| 268 |
GF_OPTION_RECONF("optimistic-change-log", priv->optimistic_change_log, |
| 269 |
options, bool, out); |
| 270 |
GF_OPTION_RECONF("quorum-type", qtype, options, str, out); |
| 271 |
GF_OPTION_RECONF("quorum-count", priv->quorum_count, options, uint32, out); |
| 272 |
fix_quorum_options(this, priv, qtype, options); |
| 273 |
if (priv->quorum_count && !afr_has_quorum(priv->child_up, priv, NULL)) |
| 274 |
gf_msg(this->name, GF_LOG_WARNING, 0, AFR_MSG_QUORUM_FAIL, |
| 275 |
"Client-quorum is not met"); |
| 276 |
|
| 277 |
GF_OPTION_RECONF("post-op-delay-secs", priv->post_op_delay_secs, options, |
| 278 |
uint32, out); |
| 279 |
|
| 280 |
/* Reset this so we re-discover in case the topology changed. */ |
| 281 |
GF_OPTION_RECONF("ensure-durability", priv->ensure_durability, options, |
| 282 |
bool, out); |
| 283 |
|
| 284 |
enabled_old = priv->shd.enabled; |
| 285 |
GF_OPTION_RECONF("self-heal-daemon", priv->shd.enabled, options, bool, out); |
| 286 |
|
| 287 |
GF_OPTION_RECONF("iam-self-heal-daemon", priv->shd.iamshd, options, bool, |
| 288 |
out); |
| 289 |
|
| 290 |
timeout_old = priv->shd.timeout; |
| 291 |
GF_OPTION_RECONF("heal-timeout", priv->shd.timeout, options, time, out); |
| 292 |
|
| 293 |
GF_OPTION_RECONF("consistent-metadata", priv->consistent_metadata, options, |
| 294 |
bool, out); |
| 295 |
|
| 296 |
GF_OPTION_RECONF("shd-max-threads", priv->shd.max_threads, options, uint32, |
| 297 |
out); |
| 298 |
|
| 299 |
GF_OPTION_RECONF("shd-wait-qlength", priv->shd.wait_qlength, options, |
| 300 |
uint32, out); |
| 301 |
|
| 302 |
GF_OPTION_RECONF("favorite-child-policy", fav_child_policy, options, str, |
| 303 |
out); |
| 304 |
if (afr_set_favorite_child_policy(priv, fav_child_policy) == -1) |
| 305 |
goto out; |
| 306 |
|
| 307 |
priv->did_discovery = _gf_false; |
| 308 |
|
| 309 |
GF_OPTION_RECONF("consistent-io", consistent_io, options, bool, out); |
| 310 |
if (priv->quorum_count != 0) |
| 311 |
consistent_io = _gf_false; |
| 312 |
priv->consistent_io = consistent_io; |
| 313 |
|
| 314 |
afr_handle_anon_inode_options(priv, options); |
| 315 |
|
| 316 |
GF_OPTION_RECONF("use-anonymous-inode", priv->use_anon_inode, options, bool, |
| 317 |
out); |
| 318 |
if (priv->shd.enabled) { |
| 319 |
if ((priv->shd.enabled != enabled_old) || |
| 320 |
(timeout_old != priv->shd.timeout)) |
| 321 |
afr_selfheal_childup(this, priv); |
| 322 |
} |
| 323 |
|
| 324 |
ret = 0; |
| 325 |
out: |
| 326 |
return ret; |
| 327 |
} |
| 328 |
|
| 329 |
static int |
| 330 |
afr_pending_xattrs_init(afr_private_t *priv, xlator_t *this) |
| 331 |
{ |
| 332 |
int ret = -1; |
| 333 |
int i = 0; |
| 334 |
char *ptr = NULL; |
| 335 |
char *ptr1 = NULL; |
| 336 |
char *xattrs_list = NULL; |
| 337 |
xlator_list_t *trav = NULL; |
| 338 |
int child_count = -1; |
| 339 |
|
| 340 |
trav = this->children; |
| 341 |
child_count = priv->child_count; |
| 342 |
if (priv->thin_arbiter_count) { |
| 343 |
/* priv->pending_key[THIN_ARBITER_BRICK_INDEX] is used as the |
| 344 |
* name of the thin arbiter file for persistence across add/ |
| 345 |
* removal of DHT subvols.*/ |
| 346 |
child_count++; |
| 347 |
} |
| 348 |
|
| 349 |
GF_OPTION_INIT("afr-pending-xattr", xattrs_list, str, out); |
| 350 |
priv->pending_key = GF_CALLOC(sizeof(*priv->pending_key), child_count, |
| 351 |
gf_afr_mt_char); |
| 352 |
if (!priv->pending_key) { |
| 353 |
ret = -ENOMEM; |
| 354 |
goto out; |
| 355 |
} |
| 356 |
if (!xattrs_list) { |
| 357 |
gf_msg(this->name, GF_LOG_WARNING, 0, AFR_MSG_NO_CHANGELOG, |
| 358 |
"Unable to fetch afr-pending-xattr option from volfile." |
| 359 |
" Falling back to using client translator names. "); |
| 360 |
|
| 361 |
while (i < child_count) { |
| 362 |
ret = gf_asprintf(&priv->pending_key[i], "%s.%s", AFR_XATTR_PREFIX, |
| 363 |
trav->xlator->name); |
| 364 |
if (ret == -1) { |
| 365 |
ret = -ENOMEM; |
| 366 |
goto out; |
| 367 |
} |
| 368 |
trav = trav->next; |
| 369 |
i++; |
| 370 |
} |
| 371 |
ret = 0; |
| 372 |
goto out; |
| 373 |
} |
| 374 |
|
| 375 |
ptr = ptr1 = gf_strdup(xattrs_list); |
| 376 |
if (!ptr) { |
| 377 |
ret = -ENOMEM; |
| 378 |
goto out; |
| 379 |
} |
| 380 |
for (i = 0, ptr = strtok(ptr, ","); ptr; ptr = strtok(NULL, ",")) { |
| 381 |
ret = gf_asprintf(&priv->pending_key[i], "%s.%s", AFR_XATTR_PREFIX, |
| 382 |
ptr); |
| 383 |
if (ret == -1) { |
| 384 |
ret = -ENOMEM; |
| 385 |
goto out; |
| 386 |
} |
| 387 |
i++; |
| 388 |
} |
| 389 |
ret = 0; |
| 390 |
|
| 391 |
out: |
| 392 |
GF_FREE(ptr1); |
| 393 |
return ret; |
| 394 |
} |
| 395 |
|
| 396 |
void |
| 397 |
afr_ta_init(afr_private_t *priv) |
| 398 |
{ |
| 399 |
priv->thin_arbiter_count = 1; |
| 400 |
priv->child_count--; |
| 401 |
priv->ta_child_up = 0; |
| 402 |
priv->ta_bad_child_index = AFR_CHILD_UNKNOWN; |
| 403 |
priv->ta_notify_dom_lock_offset = 0; |
| 404 |
priv->ta_in_mem_txn_count = 0; |
| 405 |
priv->ta_on_wire_txn_count = 0; |
| 406 |
priv->release_ta_notify_dom_lock = _gf_false; |
| 407 |
INIT_LIST_HEAD(&priv->ta_waitq); |
| 408 |
INIT_LIST_HEAD(&priv->ta_onwireq); |
| 409 |
gf_uuid_clear(priv->ta_gfid); |
| 410 |
} |
| 411 |
|
| 412 |
int32_t |
| 413 |
init(xlator_t *this) |
| 414 |
{ |
| 415 |
afr_private_t *priv = NULL; |
| 416 |
int child_count = 0; |
| 417 |
xlator_list_t *trav = NULL; |
| 418 |
int i = 0; |
| 419 |
int ret = -1; |
| 420 |
GF_UNUSED int op_errno = 0; |
| 421 |
xlator_t *read_subvol = NULL; |
| 422 |
int read_subvol_index = -1; |
| 423 |
char *qtype = NULL; |
| 424 |
char *fav_child_policy = NULL; |
| 425 |
char *thin_arbiter = NULL; |
| 426 |
char *data_self_heal = NULL; |
| 427 |
char *locking_scheme = NULL; |
| 428 |
char *data_self_heal_algorithm = NULL; |
| 429 |
|
| 430 |
if (!this->children) { |
| 431 |
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_CHILD_MISCONFIGURED, |
| 432 |
"replicate translator needs more than one " |
| 433 |
"subvolume defined."); |
| 434 |
return -1; |
| 435 |
} |
| 436 |
|
| 437 |
if (!this->parents) { |
| 438 |
gf_msg(this->name, GF_LOG_WARNING, 0, AFR_MSG_VOL_MISCONFIGURED, |
| 439 |
"Volume is dangling."); |
| 440 |
} |
| 441 |
|
| 442 |
this->private = GF_CALLOC(1, sizeof(afr_private_t), |
| 443 |
gf_afr_mt_afr_private_t); |
| 444 |
if (!this->private) |
| 445 |
goto out; |
| 446 |
|
| 447 |
priv = this->private; |
| 448 |
INIT_LIST_HEAD(&priv->saved_locks); |
| 449 |
INIT_LIST_HEAD(&priv->lk_healq); |
| 450 |
LOCK_INIT(&priv->lock); |
| 451 |
|
| 452 |
child_count = xlator_subvolume_count(this); |
| 453 |
|
| 454 |
priv->child_count = child_count; |
| 455 |
|
| 456 |
priv->read_child = -1; |
| 457 |
|
| 458 |
GF_OPTION_INIT("arbiter-count", priv->arbiter_count, uint32, out); |
| 459 |
GF_OPTION_INIT("thin-arbiter", thin_arbiter, str, out); |
| 460 |
if (thin_arbiter && strlen(thin_arbiter) > 0) { |
| 461 |
afr_ta_init(priv); |
| 462 |
} |
| 463 |
INIT_LIST_HEAD(&priv->healing); |
| 464 |
INIT_LIST_HEAD(&priv->heal_waiting); |
| 465 |
|
| 466 |
priv->spb_choice_timeout = AFR_DEFAULT_SPB_CHOICE_TIMEOUT; |
| 467 |
|
| 468 |
GF_OPTION_INIT("afr-dirty-xattr", priv->afr_dirty, str, out); |
| 469 |
|
| 470 |
GF_OPTION_INIT("metadata-splitbrain-forced-heal", |
| 471 |
priv->metadata_splitbrain_forced_heal, bool, out); |
| 472 |
|
| 473 |
GF_OPTION_INIT("read-subvolume", read_subvol, xlator, out); |
| 474 |
if (read_subvol) { |
| 475 |
priv->read_child = xlator_subvolume_index(this, read_subvol); |
| 476 |
if (priv->read_child == -1) { |
| 477 |
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_INVALID_SUBVOL, |
| 478 |
"%s not a subvolume", read_subvol->name); |
| 479 |
goto out; |
| 480 |
} |
| 481 |
} |
| 482 |
GF_OPTION_INIT("read-subvolume-index", read_subvol_index, int32, out); |
| 483 |
if (read_subvol_index > -1) { |
| 484 |
if (read_subvol_index >= priv->child_count) { |
| 485 |
gf_msg(this->name, GF_LOG_ERROR, 0, AFR_MSG_INVALID_SUBVOL, |
| 486 |
"%d not a subvolume-index", read_subvol_index); |
| 487 |
goto out; |
| 488 |
} |
| 489 |
priv->read_child = read_subvol_index; |
| 490 |
} |
| 491 |
GF_OPTION_INIT("choose-local", priv->choose_local, bool, out); |
| 492 |
|
| 493 |
priv->pending_reads = GF_CALLOC(sizeof(*priv->pending_reads), |
| 494 |
priv->child_count, gf_afr_mt_atomic_t); |
| 495 |
|
| 496 |
GF_OPTION_INIT("read-hash-mode", priv->hash_mode, uint32, out); |
| 497 |
|
| 498 |
priv->favorite_child = -1; |
| 499 |
|
| 500 |
GF_OPTION_INIT("favorite-child-policy", fav_child_policy, str, out); |
| 501 |
if (afr_set_favorite_child_policy(priv, fav_child_policy) == -1) |
| 502 |
goto out; |
| 503 |
|
| 504 |
GF_OPTION_INIT("shd-max-threads", priv->shd.max_threads, uint32, out); |
| 505 |
|
| 506 |
GF_OPTION_INIT("shd-wait-qlength", priv->shd.wait_qlength, uint32, out); |
| 507 |
|
| 508 |
GF_OPTION_INIT("background-self-heal-count", |
| 509 |
priv->background_self_heal_count, uint32, out); |
| 510 |
|
| 511 |
GF_OPTION_INIT("heal-wait-queue-length", priv->heal_wait_qlen, uint32, out); |
| 512 |
|
| 513 |
GF_OPTION_INIT("data-self-heal", data_self_heal, str, out); |
| 514 |
if (gf_string2boolean(data_self_heal, &priv->data_self_heal) == -1) |
| 515 |
goto out; |
| 516 |
|
| 517 |
GF_OPTION_INIT("data-self-heal-algorithm", data_self_heal_algorithm, str, |
| 518 |
out); |
| 519 |
set_data_self_heal_algorithm(priv, data_self_heal_algorithm); |
| 520 |
|
| 521 |
GF_OPTION_INIT("data-self-heal-window-size", |
| 522 |
priv->data_self_heal_window_size, uint32, out); |
| 523 |
|
| 524 |
GF_OPTION_INIT("metadata-self-heal", priv->metadata_self_heal, bool, out); |
| 525 |
|
| 526 |
GF_OPTION_INIT("entry-self-heal", priv->entry_self_heal, bool, out); |
| 527 |
|
| 528 |
GF_OPTION_INIT("halo-shd-max-latency", priv->shd.halo_max_latency_msec, |
| 529 |
uint32, out); |
| 530 |
|
| 531 |
GF_OPTION_INIT("halo-max-latency", priv->halo_max_latency_msec, uint32, |
| 532 |
out); |
| 533 |
GF_OPTION_INIT("halo-max-replicas", priv->halo_max_replicas, uint32, out); |
| 534 |
GF_OPTION_INIT("halo-min-replicas", priv->halo_min_replicas, uint32, out); |
| 535 |
|
| 536 |
GF_OPTION_INIT("halo-enabled", priv->halo_enabled, bool, out); |
| 537 |
|
| 538 |
GF_OPTION_INIT("halo-nfsd-max-latency", priv->nfsd.halo_max_latency_msec, |
| 539 |
uint32, out); |
| 540 |
|
| 541 |
GF_OPTION_INIT("iam-nfs-daemon", priv->nfsd.iamnfsd, bool, out); |
| 542 |
|
| 543 |
GF_OPTION_INIT("optimistic-change-log", priv->optimistic_change_log, bool, |
| 544 |
out); |
| 545 |
|
| 546 |
GF_OPTION_INIT("pre-op-compat", priv->pre_op_compat, bool, out); |
| 547 |
GF_OPTION_INIT("locking-scheme", locking_scheme, str, out); |
| 548 |
priv->granular_locks = (strcmp(locking_scheme, "granular") == 0); |
| 549 |
GF_OPTION_INIT("full-lock", priv->full_lock, bool, out); |
| 550 |
GF_OPTION_INIT("granular-entry-heal", priv->esh_granular, bool, out); |
| 551 |
|
| 552 |
GF_OPTION_INIT("eager-lock", priv->eager_lock, bool, out); |
| 553 |
GF_OPTION_INIT("quorum-type", qtype, str, out); |
| 554 |
GF_OPTION_INIT("quorum-count", priv->quorum_count, uint32, out); |
| 555 |
fix_quorum_options(this, priv, qtype, this->options); |
| 556 |
|
| 557 |
GF_OPTION_INIT("post-op-delay-secs", priv->post_op_delay_secs, uint32, out); |
| 558 |
GF_OPTION_INIT("ensure-durability", priv->ensure_durability, bool, out); |
| 559 |
|
| 560 |
GF_OPTION_INIT("self-heal-daemon", priv->shd.enabled, bool, out); |
| 561 |
|
| 562 |
GF_OPTION_INIT("iam-self-heal-daemon", priv->shd.iamshd, bool, out); |
| 563 |
GF_OPTION_INIT("heal-timeout", priv->shd.timeout, time, out); |
| 564 |
|
| 565 |
GF_OPTION_INIT("consistent-metadata", priv->consistent_metadata, bool, out); |
| 566 |
GF_OPTION_INIT("consistent-io", priv->consistent_io, bool, out); |
| 567 |
afr_handle_anon_inode_options(priv, this->options); |
| 568 |
|
| 569 |
GF_OPTION_INIT("use-anonymous-inode", priv->use_anon_inode, bool, out); |
| 570 |
if (priv->quorum_count != 0) |
| 571 |
priv->consistent_io = _gf_false; |
| 572 |
|
| 573 |
priv->wait_count = 1; |
| 574 |
|
| 575 |
priv->local = GF_CALLOC(sizeof(unsigned char), child_count, gf_afr_mt_char); |
| 576 |
if (!priv->local) { |
| 577 |
ret = -ENOMEM; |
| 578 |
goto out; |
| 579 |
} |
| 580 |
|
| 581 |
priv->anon_inode = GF_CALLOC(sizeof(unsigned char), child_count, |
| 582 |
gf_afr_mt_char); |
| 583 |
|
| 584 |
priv->child_up = GF_CALLOC(sizeof(unsigned char), child_count, |
| 585 |
gf_afr_mt_char); |
| 586 |
|
| 587 |
priv->child_latency = GF_MALLOC(sizeof(*priv->child_latency) * child_count, |
| 588 |
gf_afr_mt_child_latency_t); |
| 589 |
priv->halo_child_up = GF_CALLOC(sizeof(unsigned char), child_count, |
| 590 |
gf_afr_mt_char); |
| 591 |
|
| 592 |
if (!priv->child_up || !priv->child_latency || !priv->halo_child_up || |
| 593 |
!priv->anon_inode) { |
| 594 |
ret = -ENOMEM; |
| 595 |
goto out; |
| 596 |
} |
| 597 |
/*Initialize to -ve ping timeout so that they are not considered |
| 598 |
* in child-up events until ping-event comes*/ |
| 599 |
for (i = 0; i < child_count; i++) |
| 600 |
priv->child_latency[i] = -1; |
| 601 |
|
| 602 |
priv->children = GF_CALLOC(sizeof(xlator_t *), child_count, |
| 603 |
gf_afr_mt_xlator_t); |
| 604 |
if (!priv->children) { |
| 605 |
ret = -ENOMEM; |
| 606 |
goto out; |
| 607 |
} |
| 608 |
|
| 609 |
ret = afr_pending_xattrs_init(priv, this); |
| 610 |
if (ret) |
| 611 |
goto out; |
| 612 |
|
| 613 |
trav = this->children; |
| 614 |
i = 0; |
| 615 |
while (i < child_count) { |
| 616 |
priv->children[i] = trav->xlator; |
| 617 |
trav = trav->next; |
| 618 |
i++; |
| 619 |
} |
| 620 |
|
| 621 |
ret = gf_asprintf(&priv->sh_domain, AFR_SH_DATA_DOMAIN_FMT, this->name); |
| 622 |
if (-1 == ret) { |
| 623 |
ret = -ENOMEM; |
| 624 |
goto out; |
| 625 |
} |
| 626 |
|
| 627 |
priv->last_event = GF_CALLOC(child_count, sizeof(*priv->last_event), |
| 628 |
gf_afr_mt_int32_t); |
| 629 |
if (!priv->last_event) { |
| 630 |
ret = -ENOMEM; |
| 631 |
goto out; |
| 632 |
} |
| 633 |
|
| 634 |
if (priv->shd.iamshd) { |
| 635 |
/* Number of hash bucket should be prime number so declare 131 |
| 636 |
total dentry hash buckets |
| 637 |
*/ |
| 638 |
this->itable = inode_table_new(SHD_INODE_LRU_LIMIT, this, 131, 128); |
| 639 |
} else { |
| 640 |
this->itable = inode_table_new(SHD_INODE_LRU_LIMIT, this, 0, 0); |
| 641 |
} |
| 642 |
|
| 643 |
if (!this->itable) { |
| 644 |
ret = -ENOMEM; |
| 645 |
goto out; |
| 646 |
} |
| 647 |
|
| 648 |
if (priv->shd.iamshd) { |
| 649 |
ret = afr_selfheal_daemon_init(this); |
| 650 |
if (ret) { |
| 651 |
ret = -ENOMEM; |
| 652 |
goto out; |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
/* keep more local here as we may need them for self-heal etc */ |
| 657 |
this->local_pool = mem_pool_new(afr_local_t, 512); |
| 658 |
if (!this->local_pool) { |
| 659 |
ret = -1; |
| 660 |
goto out; |
| 661 |
} |
| 662 |
|
| 663 |
ret = 0; |
| 664 |
out: |
| 665 |
return ret; |
| 666 |
} |
| 667 |
static void |
| 668 |
afr_destroy_healer_object(xlator_t *this, struct subvol_healer *healer) |
| 669 |
{ |
| 670 |
int ret = -1; |
| 671 |
|
| 672 |
if (!healer) |
| 673 |
return; |
| 674 |
|
| 675 |
if (healer->running) { |
| 676 |
/* |
| 677 |
* If there are any resources to cleanup, We need |
| 678 |
* to do that gracefully using pthread_cleanup_push |
| 679 |
*/ |
| 680 |
ret = gf_thread_cleanup_xint(healer->thread); |
| 681 |
if (ret) |
| 682 |
gf_msg(this->name, GF_LOG_WARNING, 0, AFR_MSG_SELF_HEAL_FAILED, |
| 683 |
"Failed to clean up healer threads."); |
| 684 |
healer->thread = 0; |
| 685 |
} |
| 686 |
pthread_cond_destroy(&healer->cond); |
| 687 |
pthread_mutex_destroy(&healer->mutex); |
| 688 |
} |
| 689 |
|
| 690 |
static void |
| 691 |
afr_selfheal_daemon_fini(xlator_t *this) |
| 692 |
{ |
| 693 |
struct subvol_healer *healer = NULL; |
| 694 |
afr_self_heald_t *shd = NULL; |
| 695 |
afr_private_t *priv = NULL; |
| 696 |
int i = 0; |
| 697 |
|
| 698 |
priv = this->private; |
| 699 |
if (!priv) |
| 700 |
return; |
| 701 |
|
| 702 |
shd = &priv->shd; |
| 703 |
if (!shd->iamshd) |
| 704 |
return; |
| 705 |
|
| 706 |
for (i = 0; i < priv->child_count; i++) { |
| 707 |
healer = &shd->index_healers[i]; |
| 708 |
afr_destroy_healer_object(this, healer); |
| 709 |
|
| 710 |
healer = &shd->full_healers[i]; |
| 711 |
afr_destroy_healer_object(this, healer); |
| 712 |
|
| 713 |
if (shd->statistics[i]) |
| 714 |
eh_destroy(shd->statistics[i]); |
| 715 |
} |
| 716 |
GF_FREE(shd->index_healers); |
| 717 |
GF_FREE(shd->full_healers); |
| 718 |
GF_FREE(shd->statistics); |
| 719 |
if (shd->split_brain) |
| 720 |
eh_destroy(shd->split_brain); |
| 721 |
} |
| 722 |
void |
| 723 |
fini(xlator_t *this) |
| 724 |
{ |
| 725 |
afr_private_t *priv = NULL; |
| 726 |
|
| 727 |
priv = this->private; |
| 728 |
|
| 729 |
afr_selfheal_daemon_fini(this); |
| 730 |
GF_ASSERT(list_empty(&priv->saved_locks)); |
| 731 |
|
| 732 |
LOCK(&priv->lock); |
| 733 |
if (priv->timer != NULL) { |
| 734 |
gf_timer_call_cancel(this->ctx, priv->timer); |
| 735 |
priv->timer = NULL; |
| 736 |
} |
| 737 |
UNLOCK(&priv->lock); |
| 738 |
|
| 739 |
if (this->local_pool != NULL) { |
| 740 |
mem_pool_destroy(this->local_pool); |
| 741 |
this->local_pool = NULL; |
| 742 |
} |
| 743 |
|
| 744 |
this->private = NULL; |
| 745 |
afr_priv_destroy(priv); |
| 746 |
if (this->itable) { |
| 747 |
inode_table_destroy(this->itable); |
| 748 |
this->itable = NULL; |
| 749 |
} |
| 750 |
|
| 751 |
return; |
| 752 |
} |
| 753 |
|
| 754 |
struct xlator_fops fops = { |
| 755 |
.lookup = afr_lookup, |
| 756 |
.lk = afr_lk, |
| 757 |
.flush = afr_flush, |
| 758 |
.statfs = afr_statfs, |
| 759 |
.fsyncdir = afr_fsyncdir, |
| 760 |
.inodelk = afr_inodelk, |
| 761 |
.finodelk = afr_finodelk, |
| 762 |
.entrylk = afr_entrylk, |
| 763 |
.fentrylk = afr_fentrylk, |
| 764 |
.ipc = afr_ipc, |
| 765 |
.lease = afr_lease, |
| 766 |
|
| 767 |
/* inode read */ |
| 768 |
.access = afr_access, |
| 769 |
.stat = afr_stat, |
| 770 |
.fstat = afr_fstat, |
| 771 |
.readlink = afr_readlink, |
| 772 |
.getxattr = afr_getxattr, |
| 773 |
.fgetxattr = afr_fgetxattr, |
| 774 |
.readv = afr_readv, |
| 775 |
.seek = afr_seek, |
| 776 |
|
| 777 |
/* inode write */ |
| 778 |
.writev = afr_writev, |
| 779 |
.truncate = afr_truncate, |
| 780 |
.ftruncate = afr_ftruncate, |
| 781 |
.setxattr = afr_setxattr, |
| 782 |
.fsetxattr = afr_fsetxattr, |
| 783 |
.setattr = afr_setattr, |
| 784 |
.fsetattr = afr_fsetattr, |
| 785 |
.removexattr = afr_removexattr, |
| 786 |
.fremovexattr = afr_fremovexattr, |
| 787 |
.fallocate = afr_fallocate, |
| 788 |
.discard = afr_discard, |
| 789 |
.zerofill = afr_zerofill, |
| 790 |
.xattrop = afr_xattrop, |
| 791 |
.fxattrop = afr_fxattrop, |
| 792 |
.fsync = afr_fsync, |
| 793 |
|
| 794 |
/*inode open*/ |
| 795 |
.opendir = afr_opendir, |
| 796 |
.open = afr_open, |
| 797 |
|
| 798 |
/* dir read */ |
| 799 |
.readdir = afr_readdir, |
| 800 |
.readdirp = afr_readdirp, |
| 801 |
|
| 802 |
/* dir write */ |
| 803 |
.create = afr_create, |
| 804 |
.mknod = afr_mknod, |
| 805 |
.mkdir = afr_mkdir, |
| 806 |
.unlink = afr_unlink, |
| 807 |
.rmdir = afr_rmdir, |
| 808 |
.link = afr_link, |
| 809 |
.symlink = afr_symlink, |
| 810 |
.rename = afr_rename, |
| 811 |
}; |
| 812 |
|
| 813 |
struct xlator_dumpops dumpops = { |
| 814 |
.priv = afr_priv_dump, |
| 815 |
}; |
| 816 |
|
| 817 |
struct xlator_cbks cbks = { |
| 818 |
.release = afr_release, |
| 819 |
.releasedir = afr_releasedir, |
| 820 |
.forget = afr_forget, |
| 821 |
}; |
| 822 |
|
| 823 |
struct volume_options options[] = { |
| 824 |
{.key = {"read-subvolume"}, |
| 825 |
.type = GF_OPTION_TYPE_XLATOR, |
| 826 |
.op_version = {1}, |
| 827 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 828 |
.tags = {"replicate"}, |
| 829 |
.description = "inode-read fops happen only on one of the bricks in " |
| 830 |
"replicate. Afr will prefer the one specified using " |
| 831 |
"this option if it is not stale. Option value must be " |
| 832 |
"one of the xlator names of the children. " |
| 833 |
"Ex: <volname>-client-0 till " |
| 834 |
"<volname>-client-<number-of-bricks - 1>"}, |
| 835 |
{.key = {"read-subvolume-index"}, |
| 836 |
.type = GF_OPTION_TYPE_INT, |
| 837 |
.default_value = "-1", |
| 838 |
.op_version = {2}, |
| 839 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 840 |
.tags = {"replicate"}, |
| 841 |
.description = "inode-read fops happen only on one of the bricks in " |
| 842 |
"replicate. AFR will prefer the one specified using " |
| 843 |
"this option if it is not stale. allowed options" |
| 844 |
" include -1 till replica-count - 1"}, |
| 845 |
{.key = {"read-hash-mode"}, |
| 846 |
.type = GF_OPTION_TYPE_INT, |
| 847 |
.min = 0, |
| 848 |
.max = 5, |
| 849 |
.default_value = "1", |
| 850 |
.op_version = {2}, |
| 851 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 852 |
.tags = {"replicate"}, |
| 853 |
.description = |
| 854 |
"inode-read fops happen only on one of the bricks in " |
| 855 |
"replicate. AFR will prefer the one computed using " |
| 856 |
"the method specified using this option.\n" |
| 857 |
"0 = first readable child of AFR, starting from 1st child.\n" |
| 858 |
"1 = hash by GFID of file (all clients use " |
| 859 |
"same subvolume).\n" |
| 860 |
"2 = hash by GFID of file and client PID.\n" |
| 861 |
"3 = brick having the least outstanding read requests.\n" |
| 862 |
"4 = brick having the least network ping latency.\n" |
| 863 |
"5 = Hybrid mode between 3 and 4, ie least value among " |
| 864 |
"network-latency multiplied by outstanding-read-requests."}, |
| 865 |
{ |
| 866 |
.key = {"choose-local"}, |
| 867 |
.type = GF_OPTION_TYPE_BOOL, |
| 868 |
.default_value = "true", |
| 869 |
.op_version = {2}, |
| 870 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 871 |
.tags = {"replicate"}, |
| 872 |
.description = "Choose a local subvolume (i.e. Brick) to read from" |
| 873 |
" if read-subvolume is not explicitly set.", |
| 874 |
}, |
| 875 |
{.key = {"background-self-heal-count"}, |
| 876 |
.type = GF_OPTION_TYPE_INT, |
| 877 |
.min = 0, |
| 878 |
.max = 256, |
| 879 |
.default_value = "8", |
| 880 |
.validate = GF_OPT_VALIDATE_MIN, |
| 881 |
.op_version = {1}, |
| 882 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 883 |
OPT_FLAG_RANGE, |
| 884 |
.tags = {"replicate"}, |
| 885 |
.description = "This specifies the number of per client self-heal " |
| 886 |
"jobs that can perform parallel heals in the " |
| 887 |
"background."}, |
| 888 |
{.key = {"halo-shd-max-latency"}, |
| 889 |
.type = GF_OPTION_TYPE_INT, |
| 890 |
.min = 1, |
| 891 |
.max = 99999, |
| 892 |
.default_value = "99999", |
| 893 |
.op_version = {GD_OP_VERSION_3_11_0}, |
| 894 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 895 |
OPT_FLAG_RANGE, |
| 896 |
.tags = {"replicate", "halo"}, |
| 897 |
.description = "Maximum latency for shd halo replication in msec."}, |
| 898 |
{.key = {"halo-enabled"}, |
| 899 |
.type = GF_OPTION_TYPE_BOOL, |
| 900 |
.default_value = "False", |
| 901 |
.op_version = {GD_OP_VERSION_3_11_0}, |
| 902 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 903 |
.tags = {"replicate", "halo"}, |
| 904 |
.description = "Enable Halo (geo) replication mode."}, |
| 905 |
{.key = {"halo-nfsd-max-latency"}, |
| 906 |
.type = GF_OPTION_TYPE_INT, |
| 907 |
.min = 1, |
| 908 |
.max = 99999, |
| 909 |
.default_value = "5", |
| 910 |
.op_version = {GD_OP_VERSION_3_11_0}, |
| 911 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 912 |
OPT_FLAG_RANGE, |
| 913 |
.tags = {"replicate", "halo"}, |
| 914 |
.description = "Maximum latency for nfsd halo replication in msec."}, |
| 915 |
{.key = {"halo-max-latency"}, |
| 916 |
.type = GF_OPTION_TYPE_INT, |
| 917 |
.min = 1, |
| 918 |
.max = AFR_HALO_MAX_LATENCY, |
| 919 |
.default_value = "5", |
| 920 |
.op_version = {GD_OP_VERSION_3_11_0}, |
| 921 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 922 |
OPT_FLAG_RANGE, |
| 923 |
.tags = {"replicate", "halo"}, |
| 924 |
.description = "Maximum latency for halo replication in msec."}, |
| 925 |
{.key = {"halo-max-replicas"}, |
| 926 |
.type = GF_OPTION_TYPE_INT, |
| 927 |
.min = 1, |
| 928 |
.max = 99999, |
| 929 |
.default_value = "99999", |
| 930 |
.op_version = {GD_OP_VERSION_3_11_0}, |
| 931 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 932 |
OPT_FLAG_RANGE, |
| 933 |
.tags = {"replicate", "halo"}, |
| 934 |
.description = "The maximum number of halo replicas; replicas" |
| 935 |
" beyond this value will be written asynchronously" |
| 936 |
"via the SHD."}, |
| 937 |
{.key = {"halo-min-replicas"}, |
| 938 |
.type = GF_OPTION_TYPE_INT, |
| 939 |
.min = 1, |
| 940 |
.max = 99999, |
| 941 |
.default_value = "2", |
| 942 |
.op_version = {GD_OP_VERSION_3_11_0}, |
| 943 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 944 |
OPT_FLAG_RANGE, |
| 945 |
.tags = {"replicate", "halo"}, |
| 946 |
.description = "The minimmum number of halo replicas, before adding " |
| 947 |
"out of region replicas."}, |
| 948 |
{.key = {"heal-wait-queue-length"}, |
| 949 |
.type = GF_OPTION_TYPE_INT, |
| 950 |
.min = 0, |
| 951 |
.max = 10000, /*Around 100MB with sizeof(afr_local_t)= 10496 bytes*/ |
| 952 |
.default_value = "128", |
| 953 |
.validate = GF_OPT_VALIDATE_MIN, |
| 954 |
.op_version = {GD_OP_VERSION_3_7_10}, |
| 955 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 956 |
OPT_FLAG_RANGE, |
| 957 |
.tags = {"replicate"}, |
| 958 |
.description = "This specifies the number of heals that can be queued" |
| 959 |
" for the parallel background self heal jobs."}, |
| 960 |
{.key = {"data-self-heal"}, |
| 961 |
.type = GF_OPTION_TYPE_STR, |
| 962 |
.value = {"1", "on", "yes", "true", "enable", "0", "off", "no", "false", |
| 963 |
"disable", "open"}, |
| 964 |
.default_value = "off", |
| 965 |
.op_version = {1}, |
| 966 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 967 |
.tags = {"replicate"}, |
| 968 |
.description = "Using this option we can enable/disable data " |
| 969 |
"self-heal on the file. \"open\" means data " |
| 970 |
"self-heal action will only be triggered by file " |
| 971 |
"open operations."}, |
| 972 |
{.key = {"data-self-heal-algorithm"}, |
| 973 |
.type = GF_OPTION_TYPE_STR, |
| 974 |
.op_version = {1}, |
| 975 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 976 |
.tags = {"replicate"}, |
| 977 |
.description = "Select between \"full\", \"diff\". The " |
| 978 |
"\"full\" algorithm copies the entire file from " |
| 979 |
"source to sink. The \"diff\" algorithm copies to " |
| 980 |
"sink only those blocks whose checksums don't match " |
| 981 |
"with those of source. If no option is configured " |
| 982 |
"the option is chosen dynamically as follows: " |
| 983 |
"If the file does not exist on one of the sinks " |
| 984 |
"or empty file exists or if the source file size is " |
| 985 |
"about the same as page size the entire file will " |
| 986 |
"be read and written i.e \"full\" algo, " |
| 987 |
"otherwise \"diff\" algo is chosen.", |
| 988 |
.value = {"diff", "full"}}, |
| 989 |
{.key = {"data-self-heal-window-size"}, |
| 990 |
.type = GF_OPTION_TYPE_INT, |
| 991 |
.min = 1, |
| 992 |
.max = 1024, |
| 993 |
.default_value = "8", |
| 994 |
.op_version = {1}, |
| 995 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 996 |
OPT_FLAG_RANGE, |
| 997 |
.tags = {"replicate"}, |
| 998 |
.description = "Maximum number of 128KB blocks per file for which " |
| 999 |
"self-heal process would be applied simultaneously."}, |
| 1000 |
{.key = {"metadata-self-heal"}, |
| 1001 |
.type = GF_OPTION_TYPE_BOOL, |
| 1002 |
.default_value = "off", |
| 1003 |
.op_version = {1}, |
| 1004 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1005 |
.tags = {"replicate"}, |
| 1006 |
/*.validate_fn = validate_replica*/ |
| 1007 |
.description = "Using this option we can enable/disable metadata " |
| 1008 |
"i.e. Permissions, ownerships, xattrs self-heal on " |
| 1009 |
"the file/directory."}, |
| 1010 |
{.key = {"entry-self-heal"}, |
| 1011 |
.type = GF_OPTION_TYPE_BOOL, |
| 1012 |
.default_value = "off", |
| 1013 |
.op_version = {1}, |
| 1014 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1015 |
.tags = {"replicate"}, |
| 1016 |
/*.validate_fn = validate_replica*/ |
| 1017 |
.description = "Using this option we can enable/disable entry " |
| 1018 |
"self-heal on the directory."}, |
| 1019 |
{.key = {"data-change-log"}, |
| 1020 |
.type = GF_OPTION_TYPE_BOOL, |
| 1021 |
.default_value = "on", |
| 1022 |
.op_version = {1}, |
| 1023 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1024 |
.tags = {"replicate"}, |
| 1025 |
.description = "This option exists only for backward compatibility " |
| 1026 |
"and configuring it doesn't have any effect"}, |
| 1027 |
{.key = {"metadata-change-log"}, |
| 1028 |
.type = GF_OPTION_TYPE_BOOL, |
| 1029 |
.default_value = "on", |
| 1030 |
.op_version = {1}, |
| 1031 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1032 |
.tags = {"replicate"}, |
| 1033 |
.description = "This option exists only for backward compatibility " |
| 1034 |
"and configuring it doesn't have any effect"}, |
| 1035 |
{.key = {"entry-change-log"}, |
| 1036 |
.type = GF_OPTION_TYPE_BOOL, |
| 1037 |
.default_value = "on", |
| 1038 |
.op_version = {1}, |
| 1039 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1040 |
.tags = {"replicate"}, |
| 1041 |
.description = "This option exists only for backward compatibility " |
| 1042 |
"and configuring it doesn't have any effect"}, |
| 1043 |
{.key = {"optimistic-change-log"}, |
| 1044 |
.type = GF_OPTION_TYPE_BOOL, |
| 1045 |
.default_value = "on", |
| 1046 |
.description = "Entry/Metadata fops will not perform " |
| 1047 |
"pre fop changelog operations in afr transaction " |
| 1048 |
"if this option is enabled."}, |
| 1049 |
{.key = {"inodelk-trace"}, |
| 1050 |
.type = GF_OPTION_TYPE_BOOL, |
| 1051 |
.default_value = "off", |
| 1052 |
.description = "Enabling this option logs inode lock/unlocks"}, |
| 1053 |
{.key = {"entrylk-trace"}, |
| 1054 |
.type = GF_OPTION_TYPE_BOOL, |
| 1055 |
.default_value = "off", |
| 1056 |
.description = "Enabling this option logs entry lock/unlocks"}, |
| 1057 |
{.key = {"pre-op-compat"}, |
| 1058 |
.type = GF_OPTION_TYPE_BOOL, |
| 1059 |
.default_value = "on", |
| 1060 |
.description = "Use separate pre-op xattrop() FOP rather than " |
| 1061 |
"overloading xdata of the OP"}, |
| 1062 |
{.key = {"eager-lock"}, |
| 1063 |
.type = GF_OPTION_TYPE_BOOL, |
| 1064 |
.default_value = "on", |
| 1065 |
.op_version = {1}, |
| 1066 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1067 |
.tags = {"replicate"}, |
| 1068 |
.description = |
| 1069 |
"Enable/Disable eager lock for replica volume. " |
| 1070 |
"Lock phase of a transaction has two sub-phases. " |
| 1071 |
"First is an attempt to acquire locks in parallel by " |
| 1072 |
"broadcasting non-blocking lock requests. If lock " |
| 1073 |
"acquisition fails on any server, then the held locks " |
| 1074 |
"are unlocked and we revert to a blocking locks mode " |
| 1075 |
"sequentially on one server after another. If this " |
| 1076 |
"option is enabled the initial broadcasting lock " |
| 1077 |
"request attempts to acquire a full lock on the entire file. " |
| 1078 |
"If this fails, we revert back to the sequential " |
| 1079 |
"\"regional\" blocking locks as before. In the case " |
| 1080 |
"where such an \"eager\" lock is granted in the " |
| 1081 |
"non-blocking phase, it gives rise to an opportunity " |
| 1082 |
"for optimization. i.e, if the next write transaction " |
| 1083 |
"on the same FD arrives before the unlock phase of " |
| 1084 |
"the first transaction, it \"takes over\" the full " |
| 1085 |
"file lock. Similarly if yet another data transaction " |
| 1086 |
"arrives before the unlock phase of the \"optimized\" " |
| 1087 |
"transaction, that in turn \"takes over\" the lock as " |
| 1088 |
"well. The actual unlock now happens at the end of " |
| 1089 |
"the last \"optimized\" transaction." |
| 1090 |
|
| 1091 |
}, |
| 1092 |
{.key = {"self-heal-daemon"}, |
| 1093 |
.type = GF_OPTION_TYPE_BOOL, |
| 1094 |
.default_value = "on", |
| 1095 |
.op_version = {1}, |
| 1096 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE, |
| 1097 |
.tags = {"replicate"}, |
| 1098 |
/*.validate_fn = validate_replica_heal_enable_disable*/ |
| 1099 |
.description = "This option applies to only self-heal-daemon. " |
| 1100 |
"Index directory crawl and automatic healing of files " |
| 1101 |
"will not be performed if this option is turned off."}, |
| 1102 |
{.key = {"iam-self-heal-daemon"}, |
| 1103 |
.type = GF_OPTION_TYPE_BOOL, |
| 1104 |
.default_value = "off", |
| 1105 |
.description = "This option differentiates if the replicate " |
| 1106 |
"translator is running as part of self-heal-daemon " |
| 1107 |
"or not."}, |
| 1108 |
{.key = {"iam-nfs-daemon"}, |
| 1109 |
.type = GF_OPTION_TYPE_BOOL, |
| 1110 |
.default_value = "off", |
| 1111 |
.description = "This option differentiates if the replicate " |
| 1112 |
"translator is running as part of an NFS daemon " |
| 1113 |
"or not."}, |
| 1114 |
{ |
| 1115 |
.key = {"quorum-type"}, |
| 1116 |
.type = GF_OPTION_TYPE_STR, |
| 1117 |
.value = {"none", "auto", "fixed"}, |
| 1118 |
.default_value = "none", |
| 1119 |
.op_version = {1}, |
| 1120 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1121 |
.tags = {"replicate"}, |
| 1122 |
/*.option = quorum-type*/ |
| 1123 |
.description = "If value is \"fixed\" only allow writes if " |
| 1124 |
"quorum-count bricks are present. If value is " |
| 1125 |
"\"auto\" only allow writes if more than half of " |
| 1126 |
"bricks, or exactly half including the first, are " |
| 1127 |
"present.", |
| 1128 |
}, |
| 1129 |
{ |
| 1130 |
.key = {"quorum-count"}, |
| 1131 |
.type = GF_OPTION_TYPE_INT, |
| 1132 |
.min = 1, |
| 1133 |
.max = INT_MAX, |
| 1134 |
.default_value = 0, |
| 1135 |
.op_version = {1}, |
| 1136 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 1137 |
OPT_FLAG_RANGE, |
| 1138 |
.tags = {"replicate"}, |
| 1139 |
/*.option = quorum-count*/ |
| 1140 |
/*.validate_fn = validate_quorum_count*/ |
| 1141 |
.description = "If quorum-type is \"fixed\" only allow writes if " |
| 1142 |
"this many bricks are present. Other quorum types " |
| 1143 |
"will OVERWRITE this value.", |
| 1144 |
}, |
| 1145 |
{ |
| 1146 |
.key = {"quorum-reads"}, |
| 1147 |
.type = GF_OPTION_TYPE_BOOL, |
| 1148 |
.default_value = "no", |
| 1149 |
.op_version = {GD_OP_VERSION_3_7_0}, |
| 1150 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1151 |
.tags = {"replicate"}, |
| 1152 |
.description = "This option has been removed. Reads are not allowed " |
| 1153 |
"if quorum is not met.", |
| 1154 |
}, |
| 1155 |
{ |
| 1156 |
.key = {"node-uuid"}, |
| 1157 |
.type = GF_OPTION_TYPE_STR, |
| 1158 |
.description = "Local glusterd uuid string, used in starting " |
| 1159 |
"self-heal-daemon so that it can crawl only on " |
| 1160 |
"local index directories.", |
| 1161 |
}, |
| 1162 |
{ |
| 1163 |
.key = {"post-op-delay-secs"}, |
| 1164 |
.type = GF_OPTION_TYPE_INT, |
| 1165 |
.min = 0, |
| 1166 |
.max = INT_MAX, |
| 1167 |
.default_value = "1", |
| 1168 |
.op_version = {2}, |
| 1169 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 1170 |
OPT_FLAG_RANGE, |
| 1171 |
.tags = {"replicate"}, |
| 1172 |
.description = "Time interval induced artificially before " |
| 1173 |
"post-operation phase of the transaction to " |
| 1174 |
"enhance overlap of adjacent write operations.", |
| 1175 |
}, |
| 1176 |
{ |
| 1177 |
.key = {"self-heal-readdir-size"}, |
| 1178 |
.type = GF_OPTION_TYPE_SIZET, |
| 1179 |
.description = "This option exists only for backward compatibility " |
| 1180 |
"and configuring it doesn't have any effect", |
| 1181 |
.min = 1024, |
| 1182 |
.max = 131072, |
| 1183 |
.op_version = {2}, |
| 1184 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE, |
| 1185 |
.tags = {"replicate"}, |
| 1186 |
.default_value = "1KB", |
| 1187 |
}, |
| 1188 |
{ |
| 1189 |
.key = {"ensure-durability"}, |
| 1190 |
.type = GF_OPTION_TYPE_BOOL, |
| 1191 |
.op_version = {3}, |
| 1192 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1193 |
.tags = {"replicate"}, |
| 1194 |
.description = "Afr performs fsyncs for transactions if this " |
| 1195 |
"option is on to make sure the changelogs/data is " |
| 1196 |
"written to the disk. Please note that disabling this " |
| 1197 |
"option can lead to bad data if the data couldn't be " |
| 1198 |
"synced by the brick machine's kernel, because of " |
| 1199 |
"hardware failure etc.", |
| 1200 |
.default_value = "on", |
| 1201 |
}, |
| 1202 |
{ |
| 1203 |
.key = {"afr-dirty-xattr"}, |
| 1204 |
.type = GF_OPTION_TYPE_STR, |
| 1205 |
.default_value = AFR_DIRTY_DEFAULT, |
| 1206 |
}, |
| 1207 |
{.key = {"afr-pending-xattr"}, |
| 1208 |
.type = GF_OPTION_TYPE_STR, |
| 1209 |
.description = "Comma separated list of xattrs that are used to " |
| 1210 |
"capture information on pending heals."}, |
| 1211 |
{ |
| 1212 |
.key = {"metadata-splitbrain-forced-heal"}, |
| 1213 |
.type = GF_OPTION_TYPE_BOOL, |
| 1214 |
.default_value = "off", |
| 1215 |
}, |
| 1216 |
{.key = {"heal-timeout"}, |
| 1217 |
.type = GF_OPTION_TYPE_INT, |
| 1218 |
.min = 5, |
| 1219 |
.max = INT_MAX, |
| 1220 |
.default_value = "600", |
| 1221 |
.op_version = {2}, |
| 1222 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 1223 |
OPT_FLAG_RANGE, |
| 1224 |
.tags = {"replicate"}, |
| 1225 |
.description = "Time interval for checking the need to self-heal " |
| 1226 |
"in self-heal-daemon."}, |
| 1227 |
{ |
| 1228 |
.key = {"consistent-metadata"}, |
| 1229 |
.type = GF_OPTION_TYPE_BOOL, |
| 1230 |
.default_value = "no", |
| 1231 |
.op_version = {GD_OP_VERSION_3_7_0}, |
| 1232 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1233 |
.tags = {"replicate"}, |
| 1234 |
.description = "If this option is enabled, readdirp will force " |
| 1235 |
"lookups on those entries read whose read child is " |
| 1236 |
"not the same as that of the parent. This will " |
| 1237 |
"guarantee that all read operations on a file serve " |
| 1238 |
"attributes from the same subvol as long as it holds " |
| 1239 |
" a good copy of the file/dir.", |
| 1240 |
}, |
| 1241 |
{.key = {"arbiter-count"}, |
| 1242 |
.type = GF_OPTION_TYPE_INT, |
| 1243 |
.description = "subset of child_count. Has to be 0 or 1."}, |
| 1244 |
{ |
| 1245 |
.key = {"thin-arbiter"}, |
| 1246 |
.type = GF_OPTION_TYPE_STR, |
| 1247 |
.op_version = {GD_OP_VERSION_4_1_0}, |
| 1248 |
.flags = OPT_FLAG_SETTABLE, |
| 1249 |
.tags = {"replicate"}, |
| 1250 |
.description = "contains host:path of thin abriter brick", |
| 1251 |
}, |
| 1252 |
{.key = {"shd-max-threads"}, |
| 1253 |
.type = GF_OPTION_TYPE_INT, |
| 1254 |
.min = SHD_MIN_THREADS, |
| 1255 |
.max = SHD_MAX_THREADS, |
| 1256 |
.default_value = TOSTRING(SHD_DEFAULT_THREADS), |
| 1257 |
.op_version = {GD_OP_VERSION_3_7_12}, |
| 1258 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 1259 |
OPT_FLAG_RANGE, |
| 1260 |
.tags = {"replicate"}, |
| 1261 |
.description = "Maximum number of parallel heals SHD can do per local " |
| 1262 |
"brick. This can substantially lower heal times, but can " |
| 1263 |
"also crush your bricks if you don't have the storage " |
| 1264 |
"hardware to support this."}, |
| 1265 |
{ |
| 1266 |
.key = {"shd-wait-qlength"}, |
| 1267 |
.type = GF_OPTION_TYPE_INT, |
| 1268 |
.min = 1, |
| 1269 |
.max = 655536, |
| 1270 |
.default_value = "1024", |
| 1271 |
.op_version = {GD_OP_VERSION_3_7_12}, |
| 1272 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC | |
| 1273 |
OPT_FLAG_RANGE, |
| 1274 |
.tags = {"replicate"}, |
| 1275 |
.description = "This option can be used to control number of heals" |
| 1276 |
" that can wait in SHD per subvolume.", |
| 1277 |
}, |
| 1278 |
{ |
| 1279 |
.key = {"locking-scheme"}, |
| 1280 |
.type = GF_OPTION_TYPE_STR, |
| 1281 |
.value = {"full", "granular"}, |
| 1282 |
.default_value = "full", |
| 1283 |
.op_version = {GD_OP_VERSION_3_7_12}, |
| 1284 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1285 |
.tags = {"replicate"}, |
| 1286 |
.description = "If this option is set to granular, self-heal will " |
| 1287 |
"stop being compatible with afr-v1, which helps afr " |
| 1288 |
"be more granular while self-healing", |
| 1289 |
}, |
| 1290 |
{.key = {"full-lock"}, |
| 1291 |
.type = GF_OPTION_TYPE_BOOL, |
| 1292 |
.default_value = "yes", |
| 1293 |
.op_version = {GD_OP_VERSION_3_13_2}, |
| 1294 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE, |
| 1295 |
.tags = {"replicate"}, |
| 1296 |
.description = "If this option is disabled, then the IOs will take " |
| 1297 |
"range locks same as versions till 3.13.1."}, |
| 1298 |
{ |
| 1299 |
.key = {"granular-entry-heal"}, |
| 1300 |
.type = GF_OPTION_TYPE_BOOL, |
| 1301 |
.default_value = "no", |
| 1302 |
.op_version = {GD_OP_VERSION_3_8_0}, |
| 1303 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1304 |
.tags = {"replicate"}, |
| 1305 |
.description = "If this option is enabled, self-heal will resort to " |
| 1306 |
"granular way of recording changelogs and doing entry " |
| 1307 |
"self-heal.", |
| 1308 |
}, |
| 1309 |
{ |
| 1310 |
.key = {"favorite-child-policy"}, |
| 1311 |
.type = GF_OPTION_TYPE_STR, |
| 1312 |
.value = {"none", "size", "ctime", "mtime", "majority"}, |
| 1313 |
.default_value = "none", |
| 1314 |
.op_version = {GD_OP_VERSION_3_7_12}, |
| 1315 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1316 |
.tags = {"replicate"}, |
| 1317 |
.description = "This option can be used to automatically resolve " |
| 1318 |
"split-brains using various policies without user " |
| 1319 |
"intervention. \"size\" picks the file with the " |
| 1320 |
"biggest size as the source. \"ctime\" and \"mtime\" " |
| 1321 |
"pick the file with the latest ctime and mtime " |
| 1322 |
"respectively as the source. \"majority\" picks a file" |
| 1323 |
" with identical mtime and size in more than half the " |
| 1324 |
"number of bricks in the replica.", |
| 1325 |
}, |
| 1326 |
{ |
| 1327 |
.key = {"consistent-io"}, |
| 1328 |
.type = GF_OPTION_TYPE_BOOL, |
| 1329 |
.default_value = "no", |
| 1330 |
.description = "If this option is enabled, i/o will fail even if " |
| 1331 |
"one of the bricks is down in the replicas", |
| 1332 |
}, |
| 1333 |
{.key = {"use-compound-fops"}, |
| 1334 |
.type = GF_OPTION_TYPE_BOOL, |
| 1335 |
.default_value = "no", |
| 1336 |
.op_version = {GD_OP_VERSION_3_8_4}, |
| 1337 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC, |
| 1338 |
.tags = {"replicate"}, |
| 1339 |
.description = "This option exists only for backward compatibility " |
| 1340 |
"and configuring it doesn't have any effect"}, |
| 1341 |
{.key = {"use-anonymous-inode"}, |
| 1342 |
.type = GF_OPTION_TYPE_BOOL, |
| 1343 |
.default_value = "no", |
| 1344 |
.op_version = {GD_OP_VERSION_8_0}, |
| 1345 |
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE, |
| 1346 |
.tags = {"replicate"}, |
| 1347 |
.description = "Setting this option heals directory renames efficiently"}, |
| 1348 |
|
| 1349 |
{.key = {NULL}}, |
| 1350 |
}; |
| 1351 |
|
| 1352 |
xlator_api_t xlator_api = { |
| 1353 |
.init = init, |
| 1354 |
.fini = fini, |
| 1355 |
.notify = notify, |
| 1356 |
.reconfigure = reconfigure, |
| 1357 |
.mem_acct_init = mem_acct_init, |
| 1358 |
.op_version = {1}, /* Present from the initial version */ |
| 1359 |
.dumpops = &dumpops, |
| 1360 |
.fops = &fops, |
| 1361 |
.cbks = &cbks, |
| 1362 |
.options = options, |
| 1363 |
.identifier = "replicate", |
| 1364 |
.category = GF_MAINTAINED, |
| 1365 |
}; |