Debian Codegraph @

xlators/cluster/afr/src/afr.h

raw
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 #ifndef __AFR_H__
12 #define __AFR_H__
13
14 #include <glusterfs/call-stub.h>
15 #include <glusterfs/compat-errno.h>
16 #include "afr-mem-types.h"
17
18 #include <glusterfs/syncop.h>
19
20 #include "afr-self-heald.h"
21 #include "afr-messages.h"
22
23 #define SHD_INODE_LRU_LIMIT 1
24 #define AFR_PATHINFO_HEADER "REPLICATE:"
25 #define AFR_SH_DATA_DOMAIN_FMT "%s:self-heal"
26 #define AFR_DIRTY_DEFAULT AFR_XATTR_PREFIX ".dirty"
27 #define AFR_DIRTY (((afr_private_t *)(THIS->private))->afr_dirty)
28
29 #define AFR_LOCKEE_COUNT_MAX 3
30 #define AFR_NUM_CHANGE_LOGS 3 /*data + metadata + entry*/
31 #define AFR_DEFAULT_SPB_CHOICE_TIMEOUT 300 /*in seconds*/
32
33 #define ARBITER_BRICK_INDEX 2
34 #define THIN_ARBITER_BRICK_INDEX 2
35 #define AFR_TA_DOM_NOTIFY "afr.ta.dom-notify"
36 #define AFR_TA_DOM_MODIFY "afr.ta.dom-modify"
37
38 #define AFR_LK_HEAL_DOM "afr.lock-heal.domain"
39
40 #define AFR_HALO_MAX_LATENCY 99999
41 #define AFR_ANON_DIR_PREFIX ".glusterfs-anonymous-inode"
42
43 #define PFLAG_PENDING (1 << 0)
44 #define PFLAG_SBRAIN (1 << 1)
45
46 typedef int (*afr_lock_cbk_t)(call_frame_t *frame, xlator_t *this);
47
48 typedef int (*afr_read_txn_wind_t)(call_frame_t *frame, xlator_t *this,
49 int subvol);
50
51 typedef int (*afr_inode_refresh_cbk_t)(call_frame_t *frame, xlator_t *this,
52 int err);
53
54 typedef int (*afr_changelog_resume_t)(call_frame_t *frame, xlator_t *this);
55
56 #define AFR_COUNT(array, max) \
57 ({ \
58 int __i; \
59 int __res = 0; \
60 for (__i = 0; __i < max; __i++) \
61 if (array[__i]) \
62 __res++; \
63 __res; \
64 })
65 #define AFR_INTERSECT(dst, src1, src2, max) \
66 ({ \
67 int __i; \
68 for (__i = 0; __i < max; __i++) \
69 dst[__i] = src1[__i] && src2[__i]; \
70 })
71 #define AFR_CMP(a1, a2, len) \
72 ({ \
73 int __cmp = 0; \
74 int __i; \
75 for (__i = 0; __i < len; __i++) \
76 if (a1[__i] != a2[__i]) { \
77 __cmp = 1; \
78 break; \
79 } \
80 __cmp; \
81 })
82 #define AFR_IS_ARBITER_BRICK(priv, index) \
83 ((priv->arbiter_count == 1) && (index == ARBITER_BRICK_INDEX))
84
85 #define AFR_SET_ERROR_AND_CHECK_SPLIT_BRAIN(ret, errnum) \
86 do { \
87 local->op_ret = ret; \
88 local->op_errno = errnum; \
89 if (local->op_errno == EIO) \
90 gf_msg(this->name, GF_LOG_ERROR, local->op_errno, \
91 AFR_MSG_SPLIT_BRAIN, \
92 "Failing %s on gfid %s: " \
93 "split-brain observed.", \
94 gf_fop_list[local->op], uuid_utoa(local->inode->gfid)); \
95 } while (0)
96
97 #define AFR_ERROR_OUT_IF_FDCTX_INVALID(__fd, __this, __error, __label) \
98 do { \
99 afr_fd_ctx_t *__fd_ctx = NULL; \
100 __fd_ctx = afr_fd_ctx_get(__fd, __this); \
101 if (__fd_ctx && __fd_ctx->is_fd_bad) { \
102 __error = EBADF; \
103 goto __label; \
104 } \
105 } while (0)
106
107 typedef enum {
108 AFR_READ_POLICY_FIRST_UP,
109 AFR_READ_POLICY_GFID_HASH,
110 AFR_READ_POLICY_GFID_PID_HASH,
111 AFR_READ_POLICY_LESS_LOAD,
112 AFR_READ_POLICY_LEAST_LATENCY,
113 AFR_READ_POLICY_LOAD_LATENCY_HYBRID,
114 } afr_read_hash_mode_t;
115
116 typedef enum {
117 AFR_FAV_CHILD_NONE,
118 AFR_FAV_CHILD_BY_SIZE,
119 AFR_FAV_CHILD_BY_CTIME,
120 AFR_FAV_CHILD_BY_MTIME,
121 AFR_FAV_CHILD_BY_MAJORITY,
122 AFR_FAV_CHILD_POLICY_MAX,
123 } afr_favorite_child_policy;
124
125 typedef enum {
126 AFR_SELFHEAL_DATA_FULL = 0,
127 AFR_SELFHEAL_DATA_DIFF,
128 AFR_SELFHEAL_DATA_DYNAMIC,
129 } afr_data_self_heal_type_t;
130
131 typedef enum {
132 AFR_CHILD_UNKNOWN = -1,
133 AFR_CHILD_ZERO,
134 AFR_CHILD_ONE,
135 AFR_CHILD_THIN_ARBITER,
136 } afr_child_index;
137
138 typedef enum {
139 TA_WAIT_FOR_NOTIFY_LOCK_REL, /*FOP came after notify domain lock upcall
140 notification and waiting for its release.*/
141 TA_GET_INFO_FROM_TA_FILE, /*FOP needs post-op on ta file to get
142 *info about which brick is bad.*/
143 TA_INFO_IN_MEMORY_SUCCESS, /*Bad brick info is in memory and fop failed
144 *on BAD brick - Success*/
145 TA_INFO_IN_MEMORY_FAILED, /*Bad brick info is in memory and fop failed
146 *on GOOD brick - Failed*/
147 TA_SUCCESS, /*FOP succeeded on both data bricks.*/
148 } afr_ta_fop_state_t;
149
150 struct afr_nfsd {
151 uint32_t halo_max_latency_msec;
152 gf_boolean_t iamnfsd;
153 };
154
155 typedef struct _afr_lk_heal_info {
156 fd_t *fd;
157 struct gf_flock flock;
158 int32_t cmd;
159 dict_t *xdata_req;
160 unsigned char *locked_nodes;
161 struct list_head pos;
162 gf_lkowner_t lk_owner;
163 pid_t pid;
164 int32_t *child_up_event_gen;
165 int32_t *child_down_event_gen;
166 } afr_lk_heal_info_t;
167
168 typedef struct _afr_private {
169 gf_lock_t lock; /* to guard access to child_count, etc */
170 unsigned int child_count; /* total number of children */
171 unsigned int arbiter_count; /*subset of child_count.
172 Has to be 0 or 1.*/
173
174 xlator_t **children;
175
176 int favorite_child; /* subvolume to be preferred in resolving
177 split-brain cases */
178 /* For thin-arbiter. */
179 uuid_t ta_gfid;
180 unsigned int thin_arbiter_count; /* 0 or 1 at the moment.*/
181 int ta_bad_child_index;
182 int ta_event_gen;
183 unsigned int ta_in_mem_txn_count;
184 unsigned int ta_on_wire_txn_count;
185 struct list_head ta_waitq;
186 struct list_head ta_onwireq;
187
188 unsigned char *anon_inode;
189 unsigned char *child_up;
190 unsigned char *halo_child_up;
191 int64_t *child_latency;
192 unsigned char *local;
193
194 char **pending_key;
195
196 afr_data_self_heal_type_t data_self_heal_algorithm;
197 unsigned int data_self_heal_window_size; /* max number of pipelined
198 read/writes */
199
200 struct list_head heal_waiting; /*queue for files that need heal*/
201 uint32_t heal_wait_qlen; /*configurable queue length for heal_waiting*/
202 int32_t heal_waiters; /* No. of elements currently in wait queue.*/
203
204 struct list_head healing; /* queue for files that are undergoing
205 background heal*/
206 uint32_t background_self_heal_count; /*configurable queue length for
207 healing queue*/
208 int32_t healers; /* No. of elements currently undergoing background
209 heal*/
210
211 gf_boolean_t release_ta_notify_dom_lock;
212
213 gf_boolean_t metadata_self_heal; /* on/off */
214 gf_boolean_t entry_self_heal; /* on/off */
215
216 gf_boolean_t metadata_splitbrain_forced_heal; /* on/off */
217 int read_child; /* read-subvolume */
218 gf_atomic_t *pending_reads; /*No. of pending read cbks per child.*/
219
220 gf_timer_t *timer; /* launched when parent up is received */
221
222 unsigned int wait_count; /* # of servers to wait for success */
223
224 unsigned char ta_child_up;
225 gf_boolean_t optimistic_change_log;
226 gf_boolean_t eager_lock;
227 gf_boolean_t pre_op_compat; /* on/off */
228 uint32_t post_op_delay_secs;
229 unsigned int quorum_count;
230
231 off_t ta_notify_dom_lock_offset;
232 afr_favorite_child_policy fav_child_policy; /*Policy to use for automatic
233 resolution of split-brains.*/
234 afr_read_hash_mode_t hash_mode; /* for when read_child is not set */
235
236 int32_t *last_event;
237
238 /* @event_generation: Keeps count of number of events received which can
239 potentially impact consistency decisions. The events are CHILD_UP
240 and CHILD_DOWN, when we have to recalculate the freshness/staleness
241 of copies to detect if changes had happened while the other server
242 was down. CHILD_DOWN and CHILD_UP can also be received on network
243 disconnect/reconnects and not necessarily server going down/up.
244 Recalculating freshness/staleness on network events is equally
245 important as we might have had a network split brain.
246 */
247 uint32_t event_generation;
248 char vol_uuid[GF_UUID_BUF_SIZE];
249
250 gf_boolean_t choose_local;
251 gf_boolean_t did_discovery;
252 gf_boolean_t ensure_durability;
253 gf_boolean_t halo_enabled;
254 gf_boolean_t consistent_metadata;
255 gf_boolean_t need_heal;
256 gf_boolean_t granular_locks;
257 char *sh_domain;
258 char *afr_dirty;
259
260 uint64_t spb_choice_timeout;
261
262 afr_self_heald_t shd;
263 struct afr_nfsd nfsd;
264
265 gf_boolean_t use_anon_inode;
266
267 uint32_t halo_max_latency_msec;
268 uint32_t halo_max_replicas;
269 uint32_t halo_min_replicas;
270
271 gf_boolean_t full_lock;
272 gf_boolean_t esh_granular;
273 gf_boolean_t consistent_io;
274 gf_boolean_t data_self_heal; /* on/off */
275
276 /*For lock healing.*/
277 struct list_head saved_locks;
278 struct list_head lk_healq;
279
280 /*For anon-inode handling */
281 char anon_inode_name[NAME_MAX + 1];
282 char anon_gfid_str[GF_UUID_BUF_SIZE];
283 } afr_private_t;
284
285 typedef enum {
286 AFR_DATA_TRANSACTION, /* truncate, write, ... */
287 AFR_METADATA_TRANSACTION, /* chmod, chown, ... */
288 AFR_ENTRY_TRANSACTION, /* create, rmdir, ... */
289 AFR_ENTRY_RENAME_TRANSACTION, /* rename */
290 } afr_transaction_type;
291
292 /*
293 xattr format: trusted.afr.volume = [x y z]
294 x - data pending
295 y - metadata pending
296 z - entry pending
297 */
298
299 static inline int
300 afr_index_for_transaction_type(afr_transaction_type type)
301 {
302 switch (type) {
303 case AFR_DATA_TRANSACTION:
304 return 0;
305
306 case AFR_METADATA_TRANSACTION:
307 return 1;
308
309 case AFR_ENTRY_TRANSACTION:
310 case AFR_ENTRY_RENAME_TRANSACTION:
311 return 2;
312 }
313
314 return -1; /* make gcc happy */
315 }
316
317 static inline int
318 afr_index_from_ia_type(ia_type_t type)
319 {
320 switch (type) {
321 case IA_IFDIR:
322 return afr_index_for_transaction_type(AFR_ENTRY_TRANSACTION);
323 case IA_IFREG:
324 return afr_index_for_transaction_type(AFR_DATA_TRANSACTION);
325 default:
326 return -1;
327 }
328 }
329
330 typedef struct {
331 loc_t loc;
332 fd_t *fd;
333 char *basename;
334 unsigned char *locked_nodes;
335 int locked_count;
336 struct gf_flock flock;
337 } afr_lockee_t;
338
339 int
340 afr_entry_lockee_cmp(const void *l1, const void *l2);
341
342 typedef struct {
343 loc_t *lk_loc;
344 afr_lockee_t lockee[AFR_LOCKEE_COUNT_MAX];
345 afr_lock_cbk_t lock_cbk;
346
347 int32_t lock_count;
348 int32_t lockee_count;
349
350 int32_t lk_call_count;
351 int32_t lk_expected_count;
352 int32_t lk_attempted_count;
353
354 int32_t lock_op_ret;
355 int32_t lock_op_errno;
356 char *domain; /* Domain on which inode/entry lock/unlock in progress. */
357 } afr_internal_lock_t;
358
359 struct afr_reply {
360 int valid;
361 int32_t op_ret;
362 dict_t *xattr; /*For xattrop*/
363 dict_t *xdata;
364 struct iatt poststat;
365 struct iatt postparent;
366 struct iatt prestat;
367 struct iatt preparent;
368 struct iatt preparent2;
369 struct iatt postparent2;
370 int32_t op_errno;
371 /* For rchecksum */
372 uint8_t checksum[SHA256_DIGEST_LENGTH];
373 gf_boolean_t buf_has_zeroes;
374 gf_boolean_t fips_mode_rchecksum;
375 /* For lookup */
376 int8_t need_heal;
377 };
378
379 typedef enum {
380 AFR_FD_NOT_OPENED,
381 AFR_FD_OPENED,
382 AFR_FD_OPENING
383 } afr_fd_open_status_t;
384
385 typedef struct {
386 afr_fd_open_status_t *opened_on; /* which subvolumes the fd is open on */
387 int flags;
388
389 /* the subvolume on which the latest sequence of readdirs (starting
390 at offset 0) has begun. Till the next readdir request with 0 offset
391 arrives, we continue to read off this subvol.
392 */
393 int readdir_subvol;
394 /* lock-healing related members. */
395 gf_boolean_t is_fd_bad;
396 afr_lk_heal_info_t *lk_heal_info;
397
398 } afr_fd_ctx_t;
399
400 typedef enum {
401 AFR_FOP_LOCK_PARALLEL,
402 AFR_FOP_LOCK_SERIAL,
403 AFR_FOP_LOCK_QUORUM_FAILED,
404 } afr_fop_lock_state_t;
405
406 typedef struct _afr_inode_lock_t {
407 /* @num_inodelks:
408 Number of inodelks queried from the server, as queried through
409 xdata in FOPs. Currently, used to decide if eager-locking must be
410 temporarily disabled.
411 */
412 int32_t num_inodelks;
413 unsigned int event_generation;
414 gf_timer_t *delay_timer;
415 struct list_head owners; /*Transactions that are performing fop*/
416 struct list_head post_op; /*Transactions that are done with the fop
417 *So can not conflict with the fops*/
418 struct list_head waiting; /*Transaction that are waiting for
419 *conflicting transactions to complete*/
420 struct list_head frozen; /*Transactions that need to go as part of
421 * next batch of eager-lock*/
422 gf_boolean_t release;
423 gf_boolean_t acquired;
424 } afr_lock_t;
425
426 typedef struct _afr_inode_ctx {
427 uint64_t read_subvol;
428 uint64_t write_subvol;
429 int lock_count;
430 int spb_choice;
431 gf_timer_t *timer;
432 unsigned int *pre_op_done[AFR_NUM_CHANGE_LOGS];
433 int inherited[AFR_NUM_CHANGE_LOGS];
434 int on_disk[AFR_NUM_CHANGE_LOGS];
435 /*Only 2 types of transactions support eager-locks now. DATA/METADATA*/
436 afr_lock_t lock[2];
437
438 /* @open_fd_count:
439 Number of open FDs queried from the server, as queried through
440 xdata in FOPs. Currently, used to decide if eager-locking must be
441 temporarily disabled.
442 */
443 uint32_t open_fd_count;
444 gf_boolean_t need_refresh;
445
446 /* set if any write on this fd was a non stable write
447 (i.e, without O_SYNC or O_DSYNC)
448 */
449 gf_boolean_t witnessed_unstable_write;
450 } afr_inode_ctx_t;
451
452 typedef struct _afr_local {
453 glusterfs_fop_t op;
454 unsigned int call_count;
455
456 /* @event_generation: copy of priv->event_generation taken at the
457 time of starting the transaction. The copy is made so that we
458 have a stable value through the various phases of the transaction.
459 */
460 unsigned int event_generation;
461
462 uint32_t open_fd_count;
463 int32_t num_inodelks;
464
465 int32_t op_ret;
466 int32_t op_errno;
467
468 int dirty[AFR_NUM_CHANGE_LOGS];
469
470 int32_t **pending;
471
472 loc_t loc;
473 loc_t newloc;
474
475 fd_t *fd;
476 afr_fd_ctx_t *fd_ctx;
477
478 /* @child_up: copy of priv->child_up taken at the time of transaction
479 start. The copy is taken so that we have a stable child_up array
480 through the phases of the transaction as priv->child_up[i] can keep
481 changing through time.
482 */
483 unsigned char *child_up;
484
485 /* @read_attempted:
486 array of flags representing subvolumes where read operations of
487 the read transaction have already been attempted. The array is
488 first pre-filled with down subvolumes, and as reads are performed
489 on other subvolumes, those are set as well. This way if the read
490 operation fails we do not retry on that subvolume again.
491 */
492 unsigned char *read_attempted;
493
494 /* @readfn:
495
496 pointer to function which will perform the read operation on a given
497 subvolume. Used in read transactions.
498 */
499
500 afr_read_txn_wind_t readfn;
501
502 /* @inode:
503
504 the inode on which the read txn is performed on. ref'ed and copied
505 from either fd->inode or loc.inode
506 */
507
508 inode_t *inode;
509
510 /* @parent[2]:
511
512 parent inode[s] on which directory transactions are performed.
513 */
514
515 inode_t *parent;
516 inode_t *parent2;
517
518 /* @readable:
519
520 array of flags representing servers from which a read can be
521 performed. This is the output of afr_inode_refresh()
522 */
523 unsigned char *readable;
524 unsigned char *readable2; /*For rename transaction*/
525
526 afr_inode_refresh_cbk_t refreshfn;
527
528 /* @refreshinode:
529
530 Inode currently getting refreshed.
531 */
532 inode_t *refreshinode;
533
534 dict_t *xattr_req;
535
536 dict_t *dict;
537
538 int read_subvol; /* Current read subvolume */
539
540 int optimistic_change_log;
541
542 afr_internal_lock_t internal_lock;
543
544 /*To handle setattr/setxattr on yet to be linked inode from dht*/
545 uuid_t refreshgfid;
546
547 /* @refreshed:
548
549 the inode was "refreshed" (i.e, pending xattrs from all subvols
550 freshly inspected and inode ctx updated accordingly) as part of
551 this transaction already.
552 */
553 gf_boolean_t refreshed;
554
555 gf_boolean_t update_num_inodelks;
556 gf_boolean_t update_open_fd_count;
557
558 /*
559 @pre_op_compat:
560
561 compatibility mode of pre-op. send a separate pre-op and
562 op operations as part of transaction, rather than combining
563 */
564
565 gf_boolean_t pre_op_compat;
566
567 /* Is the current writev() going to perform a stable write?
568 i.e, is fd->flags or @flags writev param have O_SYNC or
569 O_DSYNC?
570 */
571 gf_boolean_t stable_write;
572
573 /* This write appended to the file. Nnot necessarily O_APPEND,
574 just means the offset of write was at the end of file.
575 */
576 gf_boolean_t append_write;
577
578 /*
579 This struct contains the arguments for the "continuation"
580 (scheme-like) of fops
581 */
582
583 struct {
584 struct {
585 struct statvfs buf;
586 unsigned char buf_set;
587 } statfs;
588
589 struct {
590 fd_t *fd;
591 int32_t flags;
592 } open;
593
594 struct {
595 struct gf_flock user_flock;
596 struct gf_flock ret_flock;
597 unsigned char *locked_nodes;
598 int32_t cmd;
599 /* For lock healing only. */
600 unsigned char *dom_locked_nodes;
601 int32_t *dom_lock_op_ret;
602 int32_t *dom_lock_op_errno;
603 struct gf_flock *getlk_rsp;
604 } lk;
605
606 /* inode read */
607
608 struct {
609 int32_t mask;
610 } access;
611
612 struct {
613 size_t size;
614 } readlink;
615
616 struct {
617 char *name;
618 long xattr_len;
619 } getxattr;
620
621 struct {
622 size_t size;
623 off_t offset;
624 uint32_t flags;
625 } readv;
626
627 /* dir read */
628
629 struct {
630 uint32_t *checksum;
631 int success_count;
632 } opendir;
633
634 struct {
635 size_t size;
636 off_t offset;
637 dict_t *dict;
638 } readdir;
639 /* inode write */
640
641 struct {
642 struct iatt prebuf;
643 struct iatt postbuf;
644 } inode_wfop; // common structure for all inode-write-fops
645
646 struct {
647 struct iovec *vector;
648 struct iobref *iobref;
649 off_t offset;
650 int32_t count;
651 uint32_t flags;
652 } writev;
653
654 struct {
655 off_t offset;
656 } truncate;
657
658 struct {
659 off_t offset;
660 } ftruncate;
661
662 struct {
663 struct iatt in_buf;
664 int32_t valid;
665 } setattr;
666
667 struct {
668 struct iatt in_buf;
669 int32_t valid;
670 } fsetattr;
671
672 struct {
673 dict_t *dict;
674 int32_t flags;
675 } setxattr;
676
677 struct {
678 dict_t *dict;
679 int32_t flags;
680 } fsetxattr;
681
682 struct {
683 char *name;
684 } removexattr;
685
686 struct {
687 dict_t *xattr;
688 gf_xattrop_flags_t optype;
689 } xattrop;
690
691 /* dir write */
692
693 struct {
694 inode_t *inode;
695 struct iatt buf;
696 struct iatt preparent;
697 struct iatt postparent;
698 struct iatt prenewparent;
699 struct iatt postnewparent;
700 } dir_fop; // common structure for all dir fops
701
702 struct {
703 fd_t *fd;
704 dict_t *params;
705 int32_t flags;
706 mode_t mode;
707 } create;
708
709 struct {
710 dict_t *params;
711 dev_t dev;
712 mode_t mode;
713 } mknod;
714
715 struct {
716 dict_t *params;
717 int32_t mode;
718 } mkdir;
719
720 struct {
721 dict_t *params;
722 char *linkpath;
723 } symlink;
724
725 struct {
726 off_t offset;
727 size_t len;
728 int32_t mode;
729 } fallocate;
730
731 struct {
732 off_t offset;
733 size_t len;
734 } discard;
735
736 struct {
737 off_t offset;
738 off_t len;
739 } zerofill;
740
741 struct {
742 char *volume;
743 int32_t cmd;
744 int32_t in_cmd;
745 void *xdata;
746 struct gf_flock in_flock;
747 struct gf_flock flock;
748 } inodelk;
749
750 struct {
751 char *volume;
752 char *basename;
753 void *xdata;
754 entrylk_cmd in_cmd;
755 entrylk_cmd cmd;
756 entrylk_type type;
757 } entrylk;
758
759 struct {
760 off_t offset;
761 gf_seek_what_t what;
762 } seek;
763
764 struct {
765 struct gf_lease user_lease;
766 struct gf_lease ret_lease;
767 unsigned char *locked_nodes;
768 } lease;
769
770 struct {
771 int flags;
772 } rmdir;
773
774 struct {
775 int32_t datasync;
776 } fsync;
777
778 struct {
779 uuid_t gfid_req;
780 gf_boolean_t needs_fresh_lookup;
781 } lookup;
782
783 } cont;
784
785 struct {
786 char *basename;
787 char *new_basename;
788
789 loc_t parent_loc;
790 loc_t new_parent_loc;
791
792 /* stub to resume on destruction
793 of the transaction frame */
794 call_stub_t *resume_stub;
795
796 struct list_head owner_list;
797 struct list_head wait_list;
798
799 unsigned char *pre_op;
800
801 /* Changelog xattr dict for [f]xattrop*/
802 dict_t **changelog_xdata;
803 unsigned char *pre_op_sources;
804
805 /* @failed_subvols: subvolumes on which a pre-op or a
806 FOP failed. */
807 unsigned char *failed_subvols;
808
809 call_frame_t *main_frame; /*Fop frame*/
810 call_frame_t *frame; /*Transaction frame*/
811
812 int (*wind)(call_frame_t *frame, xlator_t *this, int subvol);
813
814 int (*unwind)(call_frame_t *frame, xlator_t *this);
815
816 off_t start, len;
817
818 afr_transaction_type type;
819
820 int32_t in_flight_sb_errno; /* This is where the cause of the
821 failure on the last good copy of
822 the file is stored.
823 */
824
825 /* @changelog_resume: function to be called after changlogging
826 (either pre-op or post-op) is done
827 */
828 afr_changelog_resume_t changelog_resume;
829
830 gf_boolean_t eager_lock_on;
831 gf_boolean_t do_eager_unlock;
832
833 /* @dirtied: flag which indicates whether we set dirty flag
834 in the OP. Typically true when we are performing operation
835 on more than one subvol and optimistic changelog is disabled
836
837 A 'true' value set in @dirtied flag means an 'undirtying'
838 has to be done in POST-OP phase.
839 */
840 gf_boolean_t dirtied;
841
842 /* @inherited: flag which indicates that the dirty flags
843 of the previous transaction were inherited
844 */
845 gf_boolean_t inherited;
846
847 /*
848 @no_uninherit: flag which indicates that a pre_op_uninherit()
849 must _not_ be attempted (and returned as failure) always. This
850 flag is set when a hard pre-op is performed, but not accounted
851 for it in fd_ctx->on_disk[]. Such transactions are "isolated"
852 from the pre-op piggybacking entirely and therefore uninherit
853 must not be attempted.
854 */
855 gf_boolean_t no_uninherit;
856
857 gf_boolean_t in_flight_sb; /* Indicator for occurrence of
858 split-brain while in the middle of
859 a txn. */
860
861 /* @uninherit_done:
862 @uninherit_value:
863
864 The above pair variables make pre_op_uninherit() idempotent.
865 Both are FALSE initially. The first call to pre_op_uninherit
866 sets @uninherit_done to TRUE and the return value to
867 @uninherit_value. Further calls will check for @uninherit_done
868 to be TRUE and if so will simply return @uninherit_value.
869 */
870 gf_boolean_t uninherit_done;
871 gf_boolean_t uninherit_value;
872
873 gf_boolean_t disable_delayed_post_op;
874 } transaction;
875
876 syncbarrier_t barrier;
877
878 /* extra data for fops */
879 dict_t *xdata_req;
880 dict_t *xdata_rsp;
881
882 dict_t *xattr_rsp; /*for [f]xattrop*/
883
884 mode_t umask;
885 int xflag;
886 struct afr_reply *replies;
887
888 /* For client side background heals. */
889 struct list_head healer;
890 call_frame_t *heal_frame;
891
892 afr_inode_ctx_t *inode_ctx;
893
894 /*For thin-arbiter transactions.*/
895 int ta_failed_subvol;
896 int ta_event_gen;
897 struct list_head ta_waitq;
898 struct list_head ta_onwireq;
899 afr_ta_fop_state_t fop_state;
900 afr_fop_lock_state_t fop_lock_state;
901 gf_lkowner_t saved_lk_owner;
902 unsigned char read_txn_query_child;
903 unsigned char ta_child_up;
904 gf_boolean_t do_discovery;
905 gf_boolean_t need_full_crawl;
906 gf_boolean_t is_read_txn;
907 gf_boolean_t is_new_entry;
908
909 /* For fix_open */
910 unsigned char *need_open;
911 } afr_local_t;
912
913 typedef struct afr_spbc_timeout {
914 call_frame_t *frame;
915 loc_t *loc;
916 int spb_child_index;
917 gf_boolean_t d_spb;
918 gf_boolean_t m_spb;
919 } afr_spbc_timeout_t;
920
921 typedef struct afr_spb_status {
922 call_frame_t *frame;
923 loc_t *loc;
924 } afr_spb_status_t;
925
926 typedef struct afr_empty_brick_args {
927 call_frame_t *frame;
928 char *op_type;
929 loc_t loc;
930 int empty_index;
931 } afr_empty_brick_args_t;
932
933 typedef struct afr_read_subvol_args {
934 ia_type_t ia_type;
935 uuid_t gfid;
936 } afr_read_subvol_args_t;
937
938 int
939 afr_inode_get_readable(call_frame_t *frame, inode_t *inode, xlator_t *this,
940 unsigned char *readable, int *event_p, int type);
941 int
942 afr_inode_read_subvol_get(inode_t *inode, xlator_t *this,
943 unsigned char *data_subvols,
944 unsigned char *metadata_subvols,
945 int *event_generation);
946
947 int
948 afr_inode_need_refresh_set(inode_t *inode, xlator_t *this);
949
950 int
951 afr_read_subvol_select_by_policy(inode_t *inode, xlator_t *this,
952 unsigned char *readable,
953 afr_read_subvol_args_t *args);
954
955 int
956 afr_read_subvol_get(inode_t *inode, xlator_t *this, int *subvol_p,
957 unsigned char *readables, int *event_p,
958 afr_transaction_type type, afr_read_subvol_args_t *args);
959
960 #define afr_data_subvol_get(i, t, s, r, e, a) \
961 afr_read_subvol_get(i, t, s, r, e, AFR_DATA_TRANSACTION, a)
962
963 #define afr_metadata_subvol_get(i, t, s, r, e, a) \
964 afr_read_subvol_get(i, t, s, r, e, AFR_METADATA_TRANSACTION, a)
965
966 int
967 afr_inode_refresh(call_frame_t *frame, xlator_t *this, inode_t *inode,
968 uuid_t gfid, afr_inode_refresh_cbk_t cbk);
969
970 int32_t
971 afr_notify(xlator_t *this, int32_t event, void *data, void *data2);
972
973 int
974 afr_add_entry_lockee(afr_local_t *local, loc_t *loc, char *basename,
975 int child_count);
976
977 int
978 afr_add_inode_lockee(afr_local_t *local, int child_count);
979
980 void
981 afr_lockees_cleanup(afr_internal_lock_t *int_lock);
982
983 void
984 afr_set_lk_owner(call_frame_t *frame, xlator_t *this, void *lk_owner);
985
986 int32_t
987 afr_unlock(call_frame_t *frame, xlator_t *this);
988
989 int
990 afr_lock_nonblocking(call_frame_t *frame, xlator_t *this);
991
992 int
993 afr_blocking_lock(call_frame_t *frame, xlator_t *this);
994
995 afr_fd_ctx_t *
996 afr_fd_ctx_get(fd_t *fd, xlator_t *this);
997
998 int
999 afr_locked_nodes_count(unsigned char *locked_nodes, int child_count);
1000
1001 int
1002 afr_replies_interpret(afr_local_t *local, xlator_t *this, inode_t *inode,
1003 gf_boolean_t *start_heal);
1004
1005 void
1006 afr_local_replies_wipe(afr_local_t *local, afr_private_t *priv);
1007
1008 void
1009 afr_local_cleanup(afr_local_t *local, xlator_t *this);
1010
1011 int
1012 afr_frame_return(call_frame_t *frame);
1013
1014 int
1015 afr_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
1016 fd_t *fd, dict_t *xdata);
1017
1018 void
1019 afr_cleanup_fd_ctx(xlator_t *this, fd_t *fd);
1020
1021 #define AFR_STACK_UNWIND(fop, frame, op_ret, op_errno, params...) \
1022 do { \
1023 afr_local_t *__local = NULL; \
1024 xlator_t *__this = NULL; \
1025 int32_t __op_ret = 0; \
1026 int32_t __op_errno = 0; \
1027 \
1028 __op_ret = op_ret; \
1029 __op_errno = op_errno; \
1030 if (frame) { \
1031 __local = frame->local; \
1032 __this = frame->this; \
1033 afr_handle_inconsistent_fop(frame, &__op_ret, &__op_errno); \
1034 if (__local && __local->is_read_txn) \
1035 afr_pending_read_decrement(__this->private, \
1036 __local->read_subvol); \
1037 if (__local && __local->xdata_req && \
1038 afr_is_lock_mode_mandatory(__local->xdata_req)) \
1039 afr_dom_lock_release(frame); \
1040 frame->local = NULL; \
1041 } \
1042 \
1043 STACK_UNWIND_STRICT(fop, frame, __op_ret, __op_errno, params); \
1044 if (__local) { \
1045 afr_local_cleanup(__local, __this); \
1046 mem_put(__local); \
1047 } \
1048 } while (0)
1049
1050 #define AFR_STACK_DESTROY(frame) \
1051 do { \
1052 afr_local_t *__local = NULL; \
1053 xlator_t *__this = NULL; \
1054 __local = frame->local; \
1055 __this = frame->this; \
1056 frame->local = NULL; \
1057 STACK_DESTROY(frame->root); \
1058 if (__local) { \
1059 afr_local_cleanup(__local, __this); \
1060 mem_put(__local); \
1061 } \
1062 } while (0);
1063
1064 #define AFR_FRAME_INIT(frame, op_errno) \
1065 ({ \
1066 xlator_t *__this = frame->this; \
1067 frame->local = mem_get0(__this->local_pool); \
1068 if (caa_likely(frame->local)) { \
1069 if (afr_local_init(frame->local, __this->private, &op_errno)) { \
1070 afr_local_cleanup(frame->local, __this); \
1071 mem_put(frame->local); \
1072 frame->local = NULL; \
1073 } \
1074 } else { \
1075 op_errno = ENOMEM; \
1076 } \
1077 frame->local; \
1078 })
1079
1080 #define AFR_STACK_RESET(frame) \
1081 do { \
1082 afr_local_t *__local = NULL; \
1083 xlator_t *__this = NULL; \
1084 __local = frame->local; \
1085 __this = frame->this; \
1086 frame->local = NULL; \
1087 int __opr; \
1088 STACK_RESET(frame->root); \
1089 if (__local) { \
1090 afr_local_cleanup(__local, __this); \
1091 mem_put(__local); \
1092 } \
1093 AFR_FRAME_INIT(frame, __opr); \
1094 } while (0)
1095
1096 /* allocate and return a string that is the basename of argument */
1097 static inline char *
1098 AFR_BASENAME(const char *str)
1099 {
1100 char *__tmp_str = NULL;
1101 char *__basename_str = NULL;
1102 __tmp_str = gf_strdup(str);
1103 __basename_str = gf_strdup(basename(__tmp_str));
1104 GF_FREE(__tmp_str);
1105 return __basename_str;
1106 }
1107
1108 call_frame_t *
1109 afr_copy_frame(call_frame_t *base);
1110
1111 int
1112 afr_transaction_local_init(afr_local_t *local, xlator_t *this);
1113
1114 int
1115 afr_local_init(afr_local_t *local, afr_private_t *priv, int32_t *op_errno);
1116
1117 int
1118 afr_higher_errno(int32_t old_errno, int32_t new_errno);
1119
1120 int
1121 afr_final_errno(afr_local_t *local, afr_private_t *priv);
1122
1123 int
1124 afr_xattr_req_prepare(xlator_t *this, dict_t *xattr_req);
1125
1126 void
1127 afr_fix_open(fd_t *fd, xlator_t *this);
1128
1129 void
1130 afr_matrix_cleanup(int32_t **pending, unsigned int m);
1131
1132 int32_t **
1133 afr_matrix_create(unsigned int m, unsigned int n);
1134
1135 int **
1136 afr_mark_pending_changelog(afr_private_t *priv, unsigned char *pending,
1137 dict_t *xattr, ia_type_t iat);
1138
1139 /*
1140 * Special value indicating we should use the "auto" quorum method instead of
1141 * a fixed value (including zero to turn off quorum enforcement).
1142 */
1143 #define AFR_QUORUM_AUTO INT_MAX
1144
1145 int
1146 afr_fd_report_unstable_write(xlator_t *this, afr_local_t *local);
1147
1148 gf_boolean_t
1149 afr_fd_has_witnessed_unstable_write(xlator_t *this, inode_t *inode);
1150
1151 void
1152 afr_reply_wipe(struct afr_reply *reply);
1153
1154 void
1155 afr_replies_wipe(struct afr_reply *replies, int count);
1156
1157 gf_boolean_t
1158 afr_xattrs_are_equal(dict_t *dict1, dict_t *dict2, gf_boolean_t is_arbiter);
1159
1160 gf_boolean_t
1161 afr_is_xattr_ignorable(char *key);
1162
1163 int
1164 afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc);
1165
1166 int
1167 afr_heal_splitbrain_file(call_frame_t *frame, xlator_t *this, loc_t *loc);
1168
1169 int
1170 afr_get_split_brain_status(void *opaque);
1171
1172 int
1173 afr_get_split_brain_status_cbk(int ret, call_frame_t *frame, void *opaque);
1174
1175 int
1176 afr_inode_split_brain_choice_set(inode_t *inode, xlator_t *this,
1177 int spb_choice);
1178 int
1179 afr_split_brain_read_subvol_get(inode_t *inode, xlator_t *this,
1180 call_frame_t *frame, int *spb_subvol);
1181 int
1182 afr_get_child_index_from_name(xlator_t *this, char *name);
1183
1184 int
1185 afr_is_split_brain(call_frame_t *frame, xlator_t *this, inode_t *inode,
1186 uuid_t gfid, gf_boolean_t *d_spb, gf_boolean_t *m_spb);
1187
1188 int
1189 afr_set_split_brain_choice(int ret, call_frame_t *frame, void *opaque);
1190
1191 gf_boolean_t
1192 afr_get_need_heal(afr_private_t *priv);
1193
1194 int
1195 afr_selfheal_data_open(xlator_t *this, inode_t *inode, fd_t **fd);
1196
1197 int
1198 afr_set_in_flight_sb_status(xlator_t *this, call_frame_t *frame,
1199 inode_t *inode);
1200
1201 int32_t
1202 afr_quorum_errno(afr_private_t *priv);
1203
1204 gf_boolean_t
1205 afr_is_consistent_io_possible(afr_local_t *local, afr_private_t *priv,
1206 int32_t *op_errno);
1207 void
1208 afr_handle_inconsistent_fop(call_frame_t *frame, int32_t *op_ret,
1209 int32_t *op_errno);
1210
1211 gf_boolean_t
1212 afr_is_inode_refresh_reqd(inode_t *inode, xlator_t *this, int event_gen1,
1213 int event_gen2);
1214
1215 int
1216 afr_serialize_xattrs_with_delimiter(call_frame_t *frame, xlator_t *this,
1217 char *buf, size_t size,
1218 const char *default_str, int32_t *serz_len,
1219 char delimiter);
1220 gf_boolean_t
1221 afr_is_symmetric_error(call_frame_t *frame, xlator_t *this);
1222
1223 afr_inode_ctx_t *
1224 __afr_inode_ctx_get(xlator_t *this, inode_t *inode);
1225
1226 uint64_t
1227 afr_write_subvol_get(call_frame_t *frame, xlator_t *this);
1228
1229 int
1230 afr_write_subvol_set(call_frame_t *frame, xlator_t *this);
1231
1232 int
1233 afr_write_subvol_reset(call_frame_t *frame, xlator_t *this);
1234
1235 int
1236 afr_set_inode_local(xlator_t *this, afr_local_t *local, inode_t *inode);
1237
1238 int
1239 afr_fill_ta_loc(xlator_t *this, loc_t *loc, gf_boolean_t is_gfid_based_fop);
1240
1241 int
1242 afr_ta_post_op_lock(xlator_t *this, loc_t *loc);
1243
1244 int
1245 afr_ta_post_op_unlock(xlator_t *this, loc_t *loc);
1246
1247 gf_boolean_t
1248 afr_is_pending_set(xlator_t *this, dict_t *xdata, int type);
1249
1250 int
1251 __afr_get_up_children_count(afr_private_t *priv);
1252
1253 call_frame_t *
1254 afr_ta_frame_create(xlator_t *this);
1255
1256 gf_boolean_t
1257 afr_ta_has_quorum(afr_private_t *priv, afr_local_t *local);
1258
1259 void
1260 afr_ta_lock_release_synctask(xlator_t *this);
1261
1262 void
1263 afr_ta_locked_priv_invalidate(afr_private_t *priv);
1264
1265 gf_boolean_t
1266 afr_lookup_has_quorum(call_frame_t *frame,
1267 const unsigned int up_children_count);
1268
1269 void
1270 afr_mark_new_entry_changelog(call_frame_t *frame, xlator_t *this);
1271
1272 void
1273 afr_handle_replies_quorum(call_frame_t *frame, xlator_t *this);
1274
1275 gf_boolean_t
1276 afr_ta_dict_contains_pending_xattr(dict_t *dict, afr_private_t *priv,
1277 int child);
1278
1279 void
1280 afr_selfheal_childup(xlator_t *this, afr_private_t *priv);
1281
1282 gf_boolean_t
1283 afr_is_lock_mode_mandatory(dict_t *xdata);
1284
1285 void
1286 afr_dom_lock_release(call_frame_t *frame);
1287
1288 void
1289 afr_fill_success_replies(afr_local_t *local, afr_private_t *priv,
1290 unsigned char *replies);
1291
1292 gf_boolean_t
1293 afr_is_private_directory(afr_private_t *priv, const char *name, pid_t pid);
1294 #endif /* __AFR_H__ */