summaryrefslogtreecommitdiffstats
path: root/base/common/python/pki/cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'base/common/python/pki/cli.py')
0 files changed, 0 insertions, 0 deletions
> 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
/*
  Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/


#ifndef __AFR_H__
#define __AFR_H__

#include "call-stub.h"
#include "compat-errno.h"
#include "afr-mem-types.h"

#include "libxlator.h"
#include "timer.h"
#include "syncop.h"

#include "afr-self-heald.h"
#include "afr-messages.h"

#define AFR_XATTR_PREFIX "trusted.afr"
#define AFR_PATHINFO_HEADER "REPLICATE:"
#define AFR_SH_READDIR_SIZE_KEY "self-heal-readdir-size"
#define AFR_SH_DATA_DOMAIN_FMT "%s:self-heal"
#define AFR_DIRTY_DEFAULT AFR_XATTR_PREFIX ".dirty"
#define AFR_DIRTY (((afr_private_t *) (THIS->private))->afr_dirty)

#define AFR_LOCKEE_COUNT_MAX    3
#define AFR_DOM_COUNT_MAX    3
#define AFR_NUM_CHANGE_LOGS            3 /*data + metadata + entry*/
#define AFR_DEFAULT_SPB_CHOICE_TIMEOUT 300 /*in seconds*/

#define ARBITER_BRICK_INDEX 2

typedef int (*afr_lock_cbk_t) (call_frame_t *frame, xlator_t *this);

typedef int (*afr_read_txn_wind_t) (call_frame_t *frame, xlator_t *this, int subvol);

typedef int (*afr_inode_refresh_cbk_t) (call_frame_t *frame, xlator_t *this, int err);

typedef int (*afr_changelog_resume_t) (call_frame_t *frame, xlator_t *this);

#define alloca0(size) ({void *__ptr; __ptr = alloca(size); memset(__ptr, 0, size); __ptr;})
#define AFR_COUNT(array,max) ({int __i; int __res = 0; for (__i = 0; __i < max; __i++) if (array[__i]) __res++; __res;})
#define AFR_INTERSECT(dst,src1,src2,max) ({int __i; for (__i = 0; __i < max; __i++) dst[__i] = src1[__i] && src2[__i];})
#define AFR_CMP(a1,a2,len) ({int __cmp = 0; int __i; for (__i = 0; __i < len; __i++) if (a1[__i] != a2[__i]) { __cmp = 1; break;} __cmp;})
#define AFR_IS_ARBITER_BRICK(priv, index) ((priv->arbiter_count == 1) && (index == ARBITER_BRICK_INDEX))
typedef struct _afr_private {
        gf_lock_t lock;               /* to guard access to child_count, etc */
        unsigned int child_count;     /* total number of children   */
        unsigned int arbiter_count;   /*subset of child_count.
                                        Has to be 0 or 1.*/

        xlator_t **children;

        inode_t *root_inode;

        unsigned char *child_up;

        char **pending_key;

        char         *data_self_heal;              /* on/off/open */
        char *       data_self_heal_algorithm;    /* name of algorithm */
        unsigned int data_self_heal_window_size;  /* max number of pipelined
                                                     read/writes */

        struct list_head heal_waiting; /*queue for files that need heal*/
        uint32_t  heal_wait_qlen; /*configurable queue length for heal_waiting*/
        int32_t  heal_waiters; /* No. of elements currently in wait queue.*/

        struct list_head healing;/* queue for files that are undergoing
                                    background heal*/
        uint32_t  background_self_heal_count;/*configurable queue length for
                                               healing queue*/
        int32_t  healers;/* No. of elements currently undergoing background
                          heal*/

        gf_boolean_t metadata_self_heal;   /* on/off */
        gf_boolean_t entry_self_heal;      /* on/off */

        gf_boolean_t data_change_log;       /* on/off */
        gf_boolean_t metadata_change_log;   /* on/off */
        gf_boolean_t entry_change_log;      /* on/off */

	gf_boolean_t metadata_splitbrain_forced_heal; /* on/off */
        int read_child;               /* read-subvolume */
        unsigned int hash_mode;       /* for when read_child is not set */
        int favorite_child;  /* subvolume to be preferred in resolving
                                         split-brain cases */

        gf_boolean_t inodelk_trace;
        gf_boolean_t entrylk_trace;

        unsigned int wait_count;      /* # of servers to wait for success */

        uint64_t up_count;      /* number of CHILD_UPs we have seen */
        uint64_t down_count;    /* number of CHILD_DOWNs we have seen */

        gf_boolean_t      optimistic_change_log;
        gf_boolean_t      eager_lock;
        gf_boolean_t      pre_op_compat;      /* on/off */
	uint32_t          post_op_delay_secs;
        unsigned int      quorum_count;
        gf_boolean_t      quorum_reads;

        char                   vol_uuid[UUID_SIZE + 1];
        int32_t                *last_event;

	/* @event_generation: Keeps count of number of events received which can
	   potentially impact consistency decisions. The events are CHILD_UP
	   and CHILD_DOWN, when we have to recalculate the freshness/staleness
	   of copies to detect if changes had happened while the other server
	   was down. CHILD_DOWN and CHILD_UP can also be received on network
	   disconnect/reconnects and not necessarily server going down/up.
	   Recalculating freshness/staleness on network events is equally
	   important as we might have had a network split brain.
	*/
	uint32_t               event_generation;

        gf_boolean_t           choose_local;
        gf_boolean_t           did_discovery;
        uint64_t               sh_readdir_size;
        gf_boolean_t           ensure_durability;
        char                   *sh_domain;
	char                   *afr_dirty;

	afr_self_heald_t       shd;

        gf_boolean_t           consistent_metadata;
        uint64_t               spb_choice_timeout;
        gf_boolean_t           need_heal;

	/* pump dependencies */
	void                   *pump_private;
	gf_boolean_t           use_afr_in_pump;

} afr_private_t;


typedef enum {
        AFR_DATA_TRANSACTION,          /* truncate, write, ... */
        AFR_METADATA_TRANSACTION,      /* chmod, chown, ... */
        AFR_ENTRY_TRANSACTION,         /* create, rmdir, ... */
        AFR_ENTRY_RENAME_TRANSACTION,  /* rename */
} afr_transaction_type;

typedef enum {
        AFR_TRANSACTION_LK,
        AFR_SELFHEAL_LK,
} transaction_lk_type_t;

typedef enum {
        AFR_LOCK_OP,
        AFR_UNLOCK_OP,
} afr_lock_op_type_t;

typedef enum {
        AFR_DATA_SELF_HEAL_LK,
        AFR_METADATA_SELF_HEAL_LK,
        AFR_ENTRY_SELF_HEAL_LK,
}selfheal_lk_type_t;

typedef enum {
        AFR_INODELK_TRANSACTION,
        AFR_INODELK_NB_TRANSACTION,
        AFR_ENTRYLK_TRANSACTION,
        AFR_ENTRYLK_NB_TRANSACTION,
        AFR_INODELK_SELFHEAL,
        AFR_INODELK_NB_SELFHEAL,
        AFR_ENTRYLK_SELFHEAL,
        AFR_ENTRYLK_NB_SELFHEAL,
} afr_lock_call_type_t;

/*
  xattr format: trusted.afr.volume = [x y z]
  x - data pending
  y - metadata pending
  z - entry pending
*/

static inline int
afr_index_for_transaction_type (afr_transaction_type type)
{
        switch (type) {

        case AFR_DATA_TRANSACTION:
                return 0;

        case AFR_METADATA_TRANSACTION:
                return 1;

        case AFR_ENTRY_TRANSACTION:
        case AFR_ENTRY_RENAME_TRANSACTION:
                return 2;
        }

        return -1;  /* make gcc happy */
}

static inline int
afr_index_from_ia_type (ia_type_t type)
{
        switch (type) {
        case IA_IFDIR:
                return afr_index_for_transaction_type (AFR_ENTRY_TRANSACTION);
        case IA_IFREG:
                return afr_index_for_transaction_type (AFR_DATA_TRANSACTION);
        default: return -1;
        }
}

typedef struct {
        loc_t                   loc;
        char                    *basename;
        unsigned char           *locked_nodes;
        int                     locked_count;

} afr_entry_lockee_t;

int
afr_entry_lockee_cmp (const void *l1, const void *l2);

typedef struct {
        char    *domain; /* Domain on which inodelk is taken */
        struct gf_flock flock;
        unsigned char *locked_nodes;
        int32_t lock_count;
} afr_inodelk_t;

typedef struct {
        loc_t *lk_loc;

        int                     lockee_count;
        afr_entry_lockee_t      lockee[AFR_LOCKEE_COUNT_MAX];

        afr_inodelk_t       inodelk[AFR_DOM_COUNT_MAX];
        const char *lk_basename;
        const char *lower_basename;
        const char *higher_basename;
        char lower_locked;
        char higher_locked;

        unsigned char *locked_nodes;
        unsigned char *lower_locked_nodes;

        selfheal_lk_type_t selfheal_lk_type;
        transaction_lk_type_t transaction_lk_type;

        int32_t lock_count;
        int32_t entrylk_lock_count;

        uint64_t lock_number;
        int32_t lk_call_count;
        int32_t lk_expected_count;
        int32_t lk_attempted_count;

        int32_t lock_op_ret;
        int32_t lock_op_errno;
        afr_lock_cbk_t lock_cbk;
        char *domain; /* Domain on which inode/entry lock/unlock in progress.*/
} afr_internal_lock_t;

struct afr_reply {
	int	valid;
	int32_t	op_ret;
	int32_t	op_errno;
	dict_t *xattr;/*For xattrop*/
	dict_t *xdata;
	struct iatt poststat;
	struct iatt postparent;
	struct iatt prestat;
	struct iatt preparent;
	struct iatt preparent2;
	struct iatt postparent2;
        /* For rchecksum */
	uint8_t checksum[MD5_DIGEST_LENGTH];
        gf_boolean_t buf_has_zeroes;
        /* For lookup */
        int8_t need_heal;
};

typedef enum {
        AFR_FD_NOT_OPENED,
        AFR_FD_OPENED,
        AFR_FD_OPENING
} afr_fd_open_status_t;

typedef struct {
        unsigned int *pre_op_done[AFR_NUM_CHANGE_LOGS];
	int inherited[AFR_NUM_CHANGE_LOGS];
	int on_disk[AFR_NUM_CHANGE_LOGS];
        afr_fd_open_status_t *opened_on; /* which subvolumes the fd is open on */

        unsigned int *lock_piggyback;
        unsigned int *lock_acquired;

        int flags;

	/* used for delayed-post-op optimization */
	pthread_mutex_t    delay_lock;
	gf_timer_t        *delay_timer;
	call_frame_t      *delay_frame;

	/* set if any write on this fd was a non stable write
	   (i.e, without O_SYNC or O_DSYNC)
	*/
	gf_boolean_t      witnessed_unstable_write;

	/* @open_fd_count:
	   Number of open FDs queried from the server, as queried through
	   xdata in FOPs. Currently, used to decide if eager-locking must be
	   temporarily disabled.
	*/
        uint32_t        open_fd_count;


	/* list of frames currently in progress */
	struct list_head  eager_locked;

	/* the subvolume on which the latest sequence of readdirs (starting
	   at offset 0) has begun. Till the next readdir request with 0 offset
	   arrives, we continue to read off this subvol.
	*/
	int readdir_subvol;
} afr_fd_ctx_t;


typedef struct _afr_local {
	glusterfs_fop_t  op;
        unsigned int call_count;

	/* @event_generation: copy of priv->event_generation taken at the
	   time of starting the transaction. The copy is made so that we
	   have a stable value through the various phases of the transaction.
	*/
	unsigned int event_generation;

        uint32_t     open_fd_count;
        gf_boolean_t update_open_fd_count;

	gf_lkowner_t  saved_lk_owner;

        int32_t op_ret;
        int32_t op_errno;

        int32_t **pending;

	int dirty[AFR_NUM_CHANGE_LOGS];

        loc_t loc;
        loc_t newloc;

        fd_t *fd;
	afr_fd_ctx_t *fd_ctx;

	/* @child_up: copy of priv->child_up taken at the time of transaction
	   start. The copy is taken so that we have a stable child_up array
	   through the phases of the transaction as priv->child_up[i] can keep
	   changing through time.
	*/
        unsigned char *child_up;

	/* @read_attempted:
	   array of flags representing subvolumes where read operations of
	   the read transaction have already been attempted. The array is
	   first pre-filled with down subvolumes, and as reads are performed
	   on other subvolumes, those are set as well. This way if the read
	   operation fails we do not retry on that subvolume again.
	*/
	unsigned char *read_attempted;

	/* @readfn:

	   pointer to function which will perform the read operation on a given
	   subvolume. Used in read transactions.
	*/

	afr_read_txn_wind_t readfn;

	/* @refreshed:

	   the inode was "refreshed" (i.e, pending xattrs from all subvols
	   freshly inspected and inode ctx updated accordingly) as part of
	   this transaction already.
	*/
	gf_boolean_t refreshed;

	/* @inode:

	   the inode on which the read txn is performed on. ref'ed and copied
	   from either fd->inode or loc.inode
	*/

	inode_t *inode;

	/* @parent[2]:

	   parent inode[s] on which directory transactions are performed.
	*/

	inode_t *parent;
	inode_t *parent2;

	/* @readable:

	   array of flags representing servers from which a read can be
	   performed. This is the output of afr_inode_refresh()
	*/
	unsigned char *readable;

	afr_inode_refresh_cbk_t refreshfn;

	/* @refreshinode:

	   Inode currently getting refreshed.
	*/
	inode_t *refreshinode;

	/*
	  @pre_op_compat:

	  compatibility mode of pre-op. send a separate pre-op and
	  op operations as part of transaction, rather than combining
	*/

	gf_boolean_t pre_op_compat;

        dict_t  *xattr_req;

        afr_internal_lock_t internal_lock;

        dict_t  *dict;

        int      optimistic_change_log;
	gf_boolean_t      delayed_post_op;

	/* Is the current writev() going to perform a stable write?
	   i.e, is fd->flags or @flags writev param have O_SYNC or
	   O_DSYNC?
	*/
	gf_boolean_t      stable_write;

	/* This write appended to the file. Nnot necessarily O_APPEND,
	   just means the offset of write was at the end of file.
	*/
	gf_boolean_t      append_write;

        /*
          This struct contains the arguments for the "continuation"
          (scheme-like) of fops
        */

        struct {
                struct {
                        gf_boolean_t needs_fresh_lookup;
                        uuid_t gfid_req;
                } lookup;

                struct {
                        unsigned char buf_set;
                        struct statvfs buf;
                } statfs;

                struct {
                        int32_t flags;
                } open;

                struct {
                        int32_t cmd;
                        struct gf_flock user_flock;
                        struct gf_flock ret_flock;
                        unsigned char *locked_nodes;
                } lk;

                /* inode read */

                struct {
                        int32_t mask;
                        int last_index;  /* index of the child we tried previously */
                } access;

                struct {
                        int last_index;
                } stat;

                struct {
                        int last_index;
                } fstat;

                struct {
                        size_t size;
                        int last_index;
                } readlink;

                struct {
                        char *name;
                        int last_index;
                        long xattr_len;
                } getxattr;

                struct {
                        size_t size;
                        off_t offset;
                        int last_index;
                        uint32_t flags;
                } readv;

                /* dir read */

                struct {
                        int success_count;
                        int32_t op_ret;
                        int32_t op_errno;

                        uint32_t *checksum;
                } opendir;

                struct {
                        int32_t op_ret;
                        int32_t op_errno;
                        size_t size;
                        off_t offset;
                        dict_t *dict;
                        gf_boolean_t failed;
                        int last_index;
                } readdir;
                /* inode write */

                struct {
                        struct iatt prebuf;
                        struct iatt postbuf;
                } inode_wfop; //common structure for all inode-write-fops

                struct {
                        int32_t op_ret;

                        struct iovec *vector;
                        struct iobref *iobref;
                        int32_t count;
                        off_t offset;
                        uint32_t flags;
                } writev;

                struct {