| 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 |
#ifndef _AFR_SELFHEAL_H |
| 12 |
#define _AFR_SELFHEAL_H |
| 13 |
|
| 14 |
typedef struct afr_granular_esh_args { |
| 15 |
fd_t *heal_fd; |
| 16 |
xlator_t *xl; |
| 17 |
call_frame_t *frame; |
| 18 |
gf_boolean_t mismatch; /* flag to represent occurrence of type/gfid |
| 19 |
mismatch */ |
| 20 |
} afr_granular_esh_args_t; |
| 21 |
|
| 22 |
/* Perform fop on all UP subvolumes and wait for all callbacks to return */ |
| 23 |
|
| 24 |
#define AFR_ONALL(frame, rfn, fop, args...) \ |
| 25 |
do { \ |
| 26 |
afr_local_t *__local = frame->local; \ |
| 27 |
afr_private_t *__priv = frame->this->private; \ |
| 28 |
int __i = 0, __count = 0; \ |
| 29 |
unsigned char *__child_up = alloca(__priv->child_count); \ |
| 30 |
\ |
| 31 |
memcpy(__child_up, __priv->child_up, \ |
| 32 |
sizeof(*__child_up) * __priv->child_count); \ |
| 33 |
__count = AFR_COUNT(__child_up, __priv->child_count); \ |
| 34 |
\ |
| 35 |
__local->barrier.waitfor = __count; \ |
| 36 |
afr_local_replies_wipe(__local, __priv); \ |
| 37 |
\ |
| 38 |
for (__i = 0; __i < __priv->child_count; __i++) { \ |
| 39 |
if (!__child_up[__i]) \ |
| 40 |
continue; \ |
| 41 |
STACK_WIND_COOKIE(frame, rfn, (void *)(long)__i, \ |
| 42 |
__priv->children[__i], \ |
| 43 |
__priv->children[__i]->fops->fop, args); \ |
| 44 |
} \ |
| 45 |
syncbarrier_wait(&__local->barrier, __count); \ |
| 46 |
} while (0) |
| 47 |
|
| 48 |
/* Perform fop on all subvolumes represented by list[] array and wait |
| 49 |
for all callbacks to return */ |
| 50 |
|
| 51 |
#define AFR_ONLIST(list, frame, rfn, fop, args...) \ |
| 52 |
do { \ |
| 53 |
afr_local_t *__local = frame->local; \ |
| 54 |
afr_private_t *__priv = frame->this->private; \ |
| 55 |
int __i = 0; \ |
| 56 |
int __count = 0; \ |
| 57 |
unsigned char *__list = alloca(__priv->child_count); \ |
| 58 |
\ |
| 59 |
memcpy(__list, list, sizeof(*__list) * __priv->child_count); \ |
| 60 |
__count = AFR_COUNT(__list, __priv->child_count); \ |
| 61 |
__local->barrier.waitfor = __count; \ |
| 62 |
afr_local_replies_wipe(__local, __priv); \ |
| 63 |
\ |
| 64 |
for (__i = 0; __i < __priv->child_count; __i++) { \ |
| 65 |
if (!__list[__i]) \ |
| 66 |
continue; \ |
| 67 |
STACK_WIND_COOKIE(frame, rfn, (void *)(long)__i, \ |
| 68 |
__priv->children[__i], \ |
| 69 |
__priv->children[__i]->fops->fop, args); \ |
| 70 |
} \ |
| 71 |
syncbarrier_wait(&__local->barrier, __count); \ |
| 72 |
} while (0) |
| 73 |
|
| 74 |
#define AFR_SEQ(frame, rfn, fop, args...) \ |
| 75 |
do { \ |
| 76 |
afr_local_t *__local = frame->local; \ |
| 77 |
afr_private_t *__priv = frame->this->private; \ |
| 78 |
int __i = 0; \ |
| 79 |
\ |
| 80 |
afr_local_replies_wipe(__local, __priv); \ |
| 81 |
\ |
| 82 |
for (__i = 0; __i < __priv->child_count; __i++) { \ |
| 83 |
if (!__priv->child_up[__i]) \ |
| 84 |
continue; \ |
| 85 |
STACK_WIND_COOKIE(frame, rfn, (void *)(long)__i, \ |
| 86 |
__priv->children[__i], \ |
| 87 |
__priv->children[__i]->fops->fop, args); \ |
| 88 |
syncbarrier_wait(&__local->barrier, 1); \ |
| 89 |
} \ |
| 90 |
} while (0) |
| 91 |
|
| 92 |
#define ALLOC_MATRIX(n, type) \ |
| 93 |
({ \ |
| 94 |
int __i; \ |
| 95 |
type **__ptr = alloca(n * sizeof(type *)); \ |
| 96 |
\ |
| 97 |
for (__i = 0; __i < n; __i++) \ |
| 98 |
__ptr[__i] = alloca0(n * sizeof(type)); \ |
| 99 |
__ptr; \ |
| 100 |
}) |
| 101 |
|
| 102 |
#define IA_EQUAL(f, s, field) \ |
| 103 |
(memcmp(&(f.ia_##field), &(s.ia_##field), sizeof(s.ia_##field)) == 0) |
| 104 |
|
| 105 |
#define SBRAIN_HEAL_NO_GO_MSG \ |
| 106 |
"Failed to obtain replies from all bricks of " \ |
| 107 |
"the replica (are they up?). Cannot resolve split-brain." |
| 108 |
#define SFILE_NOT_IN_SPLIT_BRAIN "File not in split-brain" |
| 109 |
#define SNO_BIGGER_FILE "No bigger file" |
| 110 |
#define SNO_DIFF_IN_MTIME "No difference in mtime" |
| 111 |
#define SUSE_SOURCE_BRICK_TO_HEAL \ |
| 112 |
"Use source-brick option to heal metadata" \ |
| 113 |
" split-brain" |
| 114 |
#define SINVALID_BRICK_NAME "Invalid brick name" |
| 115 |
#define SBRICK_IS_NOT_UP "Brick is not up" |
| 116 |
#define SBRICK_NOT_CONNECTED "Brick is not connected" |
| 117 |
#define SLESS_THAN2_BRICKS_in_REP "< 2 bricks in replica are up" |
| 118 |
#define SBRICK_IS_REMOTE "Brick is remote" |
| 119 |
#define SSTARTED_SELF_HEAL "Started self-heal" |
| 120 |
#define SOP_NOT_SUPPORTED "Operation Not Supported" |
| 121 |
#define SFILE_NOT_UNDER_DATA \ |
| 122 |
"The file is not under data or metadata " \ |
| 123 |
"split-brain" |
| 124 |
#define SFILE_NOT_IN_SPLIT_BRAIN "File not in split-brain" |
| 125 |
#define SALL_BRICKS_UP_TO_RESOLVE \ |
| 126 |
"All the bricks should be up to resolve the" \ |
| 127 |
" gfid split brain" |
| 128 |
#define SERROR_GETTING_SRC_BRICK "Error getting the source brick" |
| 129 |
int |
| 130 |
afr_selfheal(xlator_t *this, uuid_t gfid); |
| 131 |
|
| 132 |
gf_boolean_t |
| 133 |
afr_throttled_selfheal(call_frame_t *frame, xlator_t *this); |
| 134 |
|
| 135 |
int |
| 136 |
afr_selfheal_name(xlator_t *this, uuid_t gfid, const char *name, void *gfid_req, |
| 137 |
dict_t *req, dict_t *rsp); |
| 138 |
|
| 139 |
int |
| 140 |
afr_selfheal_data(call_frame_t *frame, xlator_t *this, fd_t *fd); |
| 141 |
|
| 142 |
int |
| 143 |
afr_selfheal_metadata(call_frame_t *frame, xlator_t *this, inode_t *inode); |
| 144 |
|
| 145 |
int |
| 146 |
afr_selfheal_entry(call_frame_t *frame, xlator_t *this, inode_t *inode); |
| 147 |
|
| 148 |
int |
| 149 |
afr_lookup_and_heal_gfid(xlator_t *this, inode_t *parent, const char *name, |
| 150 |
inode_t *inode, struct afr_reply *replies, int source, |
| 151 |
unsigned char *sources, void *gfid, int *gfid_idx); |
| 152 |
|
| 153 |
int |
| 154 |
afr_selfheal_inodelk(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 155 |
char *dom, off_t off, size_t size, |
| 156 |
unsigned char *locked_on); |
| 157 |
|
| 158 |
int |
| 159 |
afr_selfheal_tie_breaker_inodelk(call_frame_t *frame, xlator_t *this, |
| 160 |
inode_t *inode, char *dom, off_t off, |
| 161 |
size_t size, unsigned char *locked_on); |
| 162 |
|
| 163 |
int |
| 164 |
afr_selfheal_uninodelk(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 165 |
char *dom, off_t off, size_t size, |
| 166 |
const unsigned char *locked_on); |
| 167 |
|
| 168 |
int |
| 169 |
afr_selfheal_entrylk(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 170 |
char *dom, const char *name, unsigned char *locked_on); |
| 171 |
|
| 172 |
int |
| 173 |
afr_selfheal_tryentrylk(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 174 |
char *dom, const char *name, unsigned char *locked_on); |
| 175 |
|
| 176 |
int |
| 177 |
afr_selfheal_tie_breaker_entrylk(call_frame_t *frame, xlator_t *this, |
| 178 |
inode_t *inode, char *dom, const char *name, |
| 179 |
unsigned char *locked_on); |
| 180 |
|
| 181 |
int |
| 182 |
afr_selfheal_unentrylk(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 183 |
char *dom, const char *name, unsigned char *locked_on, |
| 184 |
dict_t *xdata); |
| 185 |
|
| 186 |
int |
| 187 |
afr_selfheal_unlocked_discover(call_frame_t *frame, inode_t *inode, uuid_t gfid, |
| 188 |
struct afr_reply *replies); |
| 189 |
|
| 190 |
int |
| 191 |
afr_selfheal_unlocked_discover_on(call_frame_t *frame, inode_t *inode, |
| 192 |
uuid_t gfid, struct afr_reply *replies, |
| 193 |
unsigned char *discover_on, dict_t *dict); |
| 194 |
inode_t * |
| 195 |
afr_selfheal_unlocked_lookup_on(call_frame_t *frame, inode_t *parent, |
| 196 |
const char *name, struct afr_reply *replies, |
| 197 |
unsigned char *lookup_on, dict_t *xattr); |
| 198 |
|
| 199 |
int |
| 200 |
afr_selfheal_find_direction(call_frame_t *frame, xlator_t *this, |
| 201 |
struct afr_reply *replies, |
| 202 |
afr_transaction_type type, unsigned char *locked_on, |
| 203 |
unsigned char *sources, unsigned char *sinks, |
| 204 |
uint64_t *witness, unsigned char *flag); |
| 205 |
int |
| 206 |
afr_selfheal_fill_matrix(xlator_t *this, int **matrix, int subvol, int idx, |
| 207 |
dict_t *xdata); |
| 208 |
|
| 209 |
int |
| 210 |
afr_selfheal_extract_xattr(xlator_t *this, struct afr_reply *replies, |
| 211 |
afr_transaction_type type, int *dirty, int **matrix); |
| 212 |
|
| 213 |
int |
| 214 |
afr_sh_generic_fop_cbk(call_frame_t *frame, void *cookie, xlator_t *this, |
| 215 |
int op_ret, int op_errno, struct iatt *pre, |
| 216 |
struct iatt *post, dict_t *xdata); |
| 217 |
|
| 218 |
int |
| 219 |
afr_selfheal_restore_time(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 220 |
int source, unsigned char *healed_sinks, |
| 221 |
struct afr_reply *replies); |
| 222 |
int |
| 223 |
afr_selfheal_undo_pending(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 224 |
unsigned char *sources, unsigned char *sinks, |
| 225 |
unsigned char *healed_sinks, |
| 226 |
unsigned char *undid_pending, |
| 227 |
afr_transaction_type type, struct afr_reply *replies, |
| 228 |
unsigned char *locked_on); |
| 229 |
|
| 230 |
int |
| 231 |
afr_selfheal_recreate_entry(call_frame_t *frame, int dst, int source, |
| 232 |
unsigned char *sources, inode_t *dir, |
| 233 |
const char *name, inode_t *inode, |
| 234 |
struct afr_reply *replies); |
| 235 |
|
| 236 |
int |
| 237 |
afr_selfheal_post_op(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 238 |
int subvol, dict_t *xattr, dict_t *xdata); |
| 239 |
|
| 240 |
call_frame_t * |
| 241 |
afr_frame_create(xlator_t *this, int32_t *op_errno); |
| 242 |
|
| 243 |
inode_t * |
| 244 |
afr_inode_find(xlator_t *this, uuid_t gfid); |
| 245 |
|
| 246 |
int |
| 247 |
afr_selfheal_discover_cbk(call_frame_t *frame, void *cookie, xlator_t *this, |
| 248 |
int op_ret, int op_errno, inode_t *inode, |
| 249 |
struct iatt *buf, dict_t *xdata, struct iatt *parbuf); |
| 250 |
void |
| 251 |
afr_reply_copy(struct afr_reply *dst, struct afr_reply *src); |
| 252 |
|
| 253 |
void |
| 254 |
afr_replies_copy(struct afr_reply *dst, struct afr_reply *src, int count); |
| 255 |
|
| 256 |
int |
| 257 |
afr_selfheal_newentry_mark(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 258 |
int source, struct afr_reply *replies, |
| 259 |
unsigned char *sources, unsigned char *newentry); |
| 260 |
|
| 261 |
unsigned int |
| 262 |
afr_success_count(struct afr_reply *replies, unsigned int count); |
| 263 |
|
| 264 |
void |
| 265 |
afr_log_selfheal(uuid_t gfid, xlator_t *this, int ret, char *type, int source, |
| 266 |
unsigned char *sources, unsigned char *healed_sinks); |
| 267 |
|
| 268 |
void |
| 269 |
afr_mark_largest_file_as_source(xlator_t *this, unsigned char *sources, |
| 270 |
struct afr_reply *replies); |
| 271 |
void |
| 272 |
afr_mark_active_sinks(xlator_t *this, unsigned char *sources, |
| 273 |
unsigned char *locked_on, unsigned char *sinks); |
| 274 |
|
| 275 |
gf_boolean_t |
| 276 |
afr_dict_contains_heal_op(call_frame_t *frame); |
| 277 |
|
| 278 |
gf_boolean_t |
| 279 |
afr_can_decide_split_brain_source_sinks(struct afr_reply *replies, |
| 280 |
int child_count); |
| 281 |
int |
| 282 |
afr_mark_split_brain_source_sinks( |
| 283 |
call_frame_t *frame, xlator_t *this, inode_t *inode, unsigned char *sources, |
| 284 |
unsigned char *sinks, unsigned char *healed_sinks, unsigned char *locked_on, |
| 285 |
struct afr_reply *replies, afr_transaction_type type); |
| 286 |
|
| 287 |
int |
| 288 |
afr_sh_get_fav_by_policy(xlator_t *this, struct afr_reply *replies, |
| 289 |
inode_t *inode, char **policy_str); |
| 290 |
|
| 291 |
int |
| 292 |
_afr_fav_child_reset_sink_xattrs(call_frame_t *frame, xlator_t *this, |
| 293 |
inode_t *inode, int source, |
| 294 |
unsigned char *healed_sinks, |
| 295 |
unsigned char *undid_pending, |
| 296 |
afr_transaction_type type, |
| 297 |
unsigned char *locked_on, |
| 298 |
struct afr_reply *replies); |
| 299 |
|
| 300 |
int |
| 301 |
afr_get_child_index_from_name(xlator_t *this, char *name); |
| 302 |
|
| 303 |
gf_boolean_t |
| 304 |
afr_does_witness_exist(xlator_t *this, uint64_t *witness); |
| 305 |
|
| 306 |
int |
| 307 |
__afr_selfheal_data_prepare(call_frame_t *frame, xlator_t *this, inode_t *inode, |
| 308 |
unsigned char *locked_on, unsigned char *sources, |
| 309 |
unsigned char *sinks, unsigned char *healed_sinks, |
| 310 |
unsigned char *undid_pending, |
| 311 |
struct afr_reply *replies, unsigned char *flag); |
| 312 |
|
| 313 |
int |
| 314 |
__afr_selfheal_metadata_prepare(call_frame_t *frame, xlator_t *this, |
| 315 |
inode_t *inode, unsigned char *locked_on, |
| 316 |
unsigned char *sources, unsigned char *sinks, |
| 317 |
unsigned char *healed_sinks, |
| 318 |
unsigned char *undid_pending, |
| 319 |
struct afr_reply *replies, unsigned char *flag); |
| 320 |
int |
| 321 |
__afr_selfheal_entry_prepare(call_frame_t *frame, xlator_t *this, |
| 322 |
inode_t *inode, unsigned char *locked_on, |
| 323 |
unsigned char *sources, unsigned char *sinks, |
| 324 |
unsigned char *healed_sinks, |
| 325 |
struct afr_reply *replies, int *source_p, |
| 326 |
unsigned char *flag); |
| 327 |
|
| 328 |
int |
| 329 |
afr_selfheal_unlocked_inspect(call_frame_t *frame, xlator_t *this, uuid_t gfid, |
| 330 |
inode_t **link_inode, gf_boolean_t *data_selfheal, |
| 331 |
gf_boolean_t *metadata_selfheal, |
| 332 |
gf_boolean_t *entry_selfheal, |
| 333 |
struct afr_reply *replies); |
| 334 |
|
| 335 |
int |
| 336 |
afr_selfheal_do(call_frame_t *frame, xlator_t *this, uuid_t gfid); |
| 337 |
|
| 338 |
int |
| 339 |
afr_selfheal_lock_cbk(call_frame_t *frame, void *cookie, xlator_t *this, |
| 340 |
int op_ret, int op_errno, dict_t *xdata); |
| 341 |
|
| 342 |
int |
| 343 |
afr_locked_fill(call_frame_t *frame, xlator_t *this, unsigned char *locked_on); |
| 344 |
int |
| 345 |
afr_choose_source_by_policy(afr_private_t *priv, unsigned char *sources, |
| 346 |
afr_transaction_type type); |
| 347 |
|
| 348 |
int |
| 349 |
afr_selfheal_metadata_by_stbuf(xlator_t *this, struct iatt *stbuf); |
| 350 |
|
| 351 |
int |
| 352 |
afr_sh_fav_by_size(xlator_t *this, struct afr_reply *replies, inode_t *inode); |
| 353 |
int |
| 354 |
afr_sh_fav_by_mtime(xlator_t *this, struct afr_reply *replies, inode_t *inode); |
| 355 |
int |
| 356 |
afr_sh_fav_by_ctime(xlator_t *this, struct afr_reply *replies, inode_t *inode); |
| 357 |
|
| 358 |
int |
| 359 |
afr_gfid_split_brain_source(xlator_t *this, struct afr_reply *replies, |
| 360 |
inode_t *inode, uuid_t pargfid, const char *bname, |
| 361 |
int src_idx, int child_idx, |
| 362 |
unsigned char *locked_on, int *src, dict_t *req, |
| 363 |
dict_t *rsp); |
| 364 |
int |
| 365 |
afr_mark_source_sinks_if_file_empty(xlator_t *this, unsigned char *sources, |
| 366 |
unsigned char *sinks, |
| 367 |
unsigned char *healed_sinks, |
| 368 |
unsigned char *locked_on, |
| 369 |
struct afr_reply *replies, |
| 370 |
afr_transaction_type type); |
| 371 |
|
| 372 |
gf_boolean_t |
| 373 |
afr_is_file_empty_on_all_children(afr_private_t *priv, |
| 374 |
struct afr_reply *replies); |
| 375 |
|
| 376 |
int |
| 377 |
afr_selfheal_entry_delete(xlator_t *this, inode_t *dir, const char *name, |
| 378 |
inode_t *inode, int child, struct afr_reply *replies); |
| 379 |
int |
| 380 |
afr_anon_inode_create(xlator_t *this, int child, inode_t **linked_inode); |
| 381 |
void |
| 382 |
afr_selfheal_fill_cell(afr_private_t *priv, dict_t *src_xdata, int *cell, |
| 383 |
int sink, int idx); |
| 384 |
#endif /* !_AFR_SELFHEAL_H */ |