"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/libglusterfs/src/glusterfs/glusterfs.h" (16 Sep 2020, 27630 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "glusterfs.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 8.0_vs_8.1.

    1 /*
    2   Copyright (c) 2008-2016 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 _GLUSTERFS_H
   12 #define _GLUSTERFS_H
   13 
   14 #include <stdio.h>
   15 #include <string.h>
   16 #include <stdlib.h>
   17 #include <stdbool.h>
   18 #include <netinet/in.h>
   19 #include <sys/socket.h>
   20 #include <sys/types.h>
   21 #include <sys/stat.h>
   22 #include <sys/statvfs.h>
   23 #include <netdb.h>
   24 #include <errno.h>
   25 #include <dirent.h>
   26 #include <unistd.h>
   27 #include <fcntl.h>
   28 #include <arpa/inet.h>
   29 #include <sys/poll.h>
   30 #include <pthread.h>
   31 #include <limits.h> /* For PATH_MAX */
   32 #include <openssl/sha.h>
   33 
   34 #include "glusterfs/glusterfs-fops.h"
   35 #include "glusterfs/list.h"
   36 #include "glusterfs/locking.h"
   37 #include "glusterfs/logging.h"
   38 #include "glusterfs/lkowner.h"
   39 #include "glusterfs/compat-uuid.h"
   40 #include "glusterfs/refcount.h"
   41 #include "glusterfs/atomic.h"
   42 
   43 #define GF_YES 1
   44 #define GF_NO 0
   45 
   46 #ifndef O_LARGEFILE
   47 /* savannah bug #20053, patch for compiling on darwin */
   48 #define O_LARGEFILE 0100000 /* from bits/fcntl.h */
   49 #endif
   50 
   51 #ifndef O_FMODE_EXEC
   52 /* redhat bug 843080, added from linux/fs.h */
   53 #define O_FMODE_EXEC 040  // 0x20
   54 #endif
   55 
   56 #ifndef O_DIRECT
   57 /* savannah bug #20050, #20052 */
   58 #define O_DIRECT 0 /* From asm/fcntl.h */
   59 #endif
   60 
   61 #ifndef O_DIRECTORY
   62 /* FreeBSD does not need O_DIRECTORY */
   63 #define O_DIRECTORY 0
   64 #endif
   65 
   66 #ifndef EBADFD
   67 /* Mac OS X does not have EBADFD */
   68 #define EBADFD EBADF
   69 #endif
   70 
   71 #ifndef FNM_EXTMATCH
   72 #define FNM_EXTMATCH 0
   73 #endif
   74 
   75 /*gets max-offset on all architectures correctly*/
   76 #define GF_OFF_MAX ((1ULL << (sizeof(off_t) * 8 - 1)) - 1ULL)
   77 
   78 #define GLUSTERD_MAX_SNAP_NAME 255
   79 #define GLUSTERFS_SOCKET_LISTEN_BACKLOG 1024
   80 #define GLUSTERD_BRICK_SERVERS "cluster.brick-vol-servers"
   81 #define SLEN(str) (sizeof(str) - 1)
   82 
   83 #define ZR_MOUNTPOINT_OPT "mountpoint"
   84 #define ZR_ATTR_TIMEOUT_OPT "attribute-timeout"
   85 #define ZR_ENTRY_TIMEOUT_OPT "entry-timeout"
   86 #define ZR_NEGATIVE_TIMEOUT_OPT "negative-timeout"
   87 #define ZR_DIRECT_IO_OPT "direct-io-mode"
   88 #define ZR_STRICT_VOLFILE_CHECK "strict-volfile-check"
   89 #define ZR_DUMP_FUSE "dump-fuse"
   90 #define ZR_FUSE_MOUNTOPTS "fuse-mountopts"
   91 #define IO_THREADS_QUEUE_SIZE_KEY "io-thread-queue-size"
   92 
   93 #define GF_XATTR_CLRLK_CMD "glusterfs.clrlk"
   94 #define GF_XATTR_PATHINFO_KEY "trusted.glusterfs.pathinfo"
   95 #define GF_XATTR_NODE_UUID_KEY "trusted.glusterfs.node-uuid"
   96 #define GF_XATTR_LIST_NODE_UUIDS_KEY "trusted.glusterfs.list-node-uuids"
   97 #define GF_REBAL_FIND_LOCAL_SUBVOL "glusterfs.find-local-subvol"
   98 #define GF_REBAL_OLD_FIND_LOCAL_SUBVOL "glusterfs.old-find-local-subvol"
   99 #define GF_XATTR_VOL_ID_KEY "trusted.glusterfs.volume-id"
  100 #define GF_XATTR_LOCKINFO_KEY "trusted.glusterfs.lockinfo"
  101 #define GF_META_LOCK_KEY "glusterfs.lock-migration-meta-lock"
  102 #define GF_META_UNLOCK_KEY "glusterfs.lock-migration-meta-unlock"
  103 #define GF_XATTR_GET_REAL_FILENAME_KEY "glusterfs.get_real_filename:"
  104 #define GF_XATTR_USER_PATHINFO_KEY "glusterfs.pathinfo"
  105 #define GF_INTERNAL_IGNORE_DEEM_STATFS "ignore-deem-statfs"
  106 #define GF_XATTR_IOSTATS_DUMP_KEY "trusted.io-stats-dump"
  107 
  108 #define GF_READDIR_SKIP_DIRS "readdir-filter-directories"
  109 #define GF_MDC_LOADED_KEY_NAMES "glusterfs.mdc.loaded.key.names"
  110 
  111 #define BD_XATTR_KEY "user.glusterfs"
  112 #define GF_PREOP_PARENT_KEY "glusterfs.preop.parent.key"
  113 #define GF_PREOP_CHECK_FAILED "glusterfs.preop.check.failed"
  114 
  115 #define XATTR_IS_PATHINFO(x)                                                   \
  116     ((strncmp(x, GF_XATTR_PATHINFO_KEY, strlen(x)) == 0) ||                    \
  117      (strncmp(x, GF_XATTR_USER_PATHINFO_KEY, strlen(x)) == 0))
  118 #define XATTR_IS_NODE_UUID(x)                                                  \
  119     (strncmp(x, GF_XATTR_NODE_UUID_KEY, SLEN(GF_XATTR_NODE_UUID_KEY)) == 0)
  120 #define XATTR_IS_NODE_UUID_LIST(x)                                             \
  121     (strncmp(x, GF_XATTR_LIST_NODE_UUIDS_KEY,                                  \
  122              SLEN(GF_XATTR_LIST_NODE_UUIDS_KEY)) == 0)
  123 #define XATTR_IS_LOCKINFO(x)                                                   \
  124     (strncmp(x, GF_XATTR_LOCKINFO_KEY, SLEN(GF_XATTR_LOCKINFO_KEY)) == 0)
  125 
  126 #define XATTR_IS_BD(x) (strncmp(x, BD_XATTR_KEY, SLEN(BD_XATTR_KEY)) == 0)
  127 
  128 #define GF_XATTR_LINKINFO_KEY "trusted.distribute.linkinfo"
  129 #define GFID_XATTR_KEY "trusted.gfid"
  130 #define PGFID_XATTR_KEY_PREFIX "trusted.pgfid."
  131 #define GFID2PATH_VIRT_XATTR_KEY "glusterfs.gfidtopath"
  132 #define GFID2PATH_XATTR_KEY_PREFIX "trusted.gfid2path."
  133 #define GFID2PATH_XATTR_KEY_PREFIX_LENGTH 18
  134 #define VIRTUAL_GFID_XATTR_KEY_STR "glusterfs.gfid.string"
  135 #define VIRTUAL_GFID_XATTR_KEY "glusterfs.gfid"
  136 #define GF_XATTR_MDATA_KEY "trusted.glusterfs.mdata"
  137 #define UUID_CANONICAL_FORM_LEN 36
  138 
  139 #define GET_ANCESTRY_PATH_KEY "glusterfs.ancestry.path"
  140 #define GET_ANCESTRY_DENTRY_KEY "glusterfs.ancestry.dentry"
  141 
  142 #define BITROT_DEFAULT_CURRENT_VERSION (unsigned long)1
  143 #define BITROT_DEFAULT_SIGNING_VERSION (unsigned long)0
  144 
  145 /* on-disk object signature keys */
  146 #define BITROT_OBJECT_BAD_KEY "trusted.bit-rot.bad-file"
  147 #define BITROT_CURRENT_VERSION_KEY "trusted.bit-rot.version"
  148 #define BITROT_SIGNING_VERSION_KEY "trusted.bit-rot.signature"
  149 
  150 /* globally usable bad file marker */
  151 #define GLUSTERFS_BAD_INODE "glusterfs.bad-inode"
  152 
  153 /* on-disk size of signing xattr (not the signature itself) */
  154 #define BITROT_SIGNING_XATTR_SIZE_KEY "trusted.glusterfs.bit-rot.size"
  155 
  156 /* GET/SET object signature */
  157 #define GLUSTERFS_GET_OBJECT_SIGNATURE "trusted.glusterfs.get-signature"
  158 #define GLUSTERFS_SET_OBJECT_SIGNATURE "trusted.glusterfs.set-signature"
  159 
  160 /* operation needs to be durable on-disk */
  161 #define GLUSTERFS_DURABLE_OP "trusted.glusterfs.durable-op"
  162 
  163 /* key for version exchange b/w bitrot stub and changelog */
  164 #define GLUSTERFS_VERSION_XCHG_KEY "glusterfs.version.xchg"
  165 
  166 #define GLUSTERFS_INTERNAL_FOP_KEY "glusterfs-internal-fop"
  167 
  168 #define GF_ENFORCE_MANDATORY_LOCK "trusted.glusterfs.enforce-mandatory-lock"
  169 
  170 /* GlusterFS Internal FOP Indicator flags
  171  * (To pass information on the context in which a paritcular
  172  *  fop is performed between translators)
  173  * The presence of a particular flag must be treated as an
  174  * indicator of the context, however the flag is added only in
  175  * a scenario where there is a need for such context across translators.
  176  * So it cannot be an absolute information on context.
  177  */
  178 #define GF_INTERNAL_CTX_KEY "glusterfs.internal-ctx"
  179 
  180 /*
  181  * Always append entries to end of the enum, do not delete entries.
  182  * Currently dict_set_flag allows to set up to 256 flag, if the enum
  183  * needs to grow beyond this dict_set_flag has to be changed accordingly
  184  */
  185 enum gf_internal_fop_indicator {
  186     GF_DHT_HEAL_DIR /* Index 0 in bit array*/
  187 };
  188 
  189 /* Todo:
  190  * Add GF_FOP_LINK_FILE         0x2ULL
  191  * address GLUSTERFS_MARKER_DONT_ACCOUNT_KEY and
  192  * GLUSTERFS_INTERNAL_FOP_KEY with this flag
  193  */
  194 
  195 #define DHT_CHANGELOG_RENAME_OP_KEY "changelog.rename-op"
  196 
  197 #define GLUSTERFS_WRITE_IS_APPEND "glusterfs.write-is-append"
  198 #define GLUSTERFS_WRITE_UPDATE_ATOMIC "glusterfs.write-update-atomic"
  199 #define GLUSTERFS_OPEN_FD_COUNT "glusterfs.open-fd-count"
  200 #define GLUSTERFS_ACTIVE_FD_COUNT "glusterfs.open-active-fd-count"
  201 #define GLUSTERFS_INODELK_COUNT "glusterfs.inodelk-count"
  202 #define GLUSTERFS_ENTRYLK_COUNT "glusterfs.entrylk-count"
  203 #define GLUSTERFS_POSIXLK_COUNT "glusterfs.posixlk-count"
  204 #define GLUSTERFS_PARENT_ENTRYLK "glusterfs.parent-entrylk"
  205 #define GLUSTERFS_INODELK_DOM_COUNT "glusterfs.inodelk-dom-count"
  206 #define GLUSTERFS_INODELK_DOM_PREFIX "glusterfs.inodelk-dom-prefix"
  207 #define GLUSTERFS_MULTIPLE_DOM_LK_CNT_REQUESTS "glusterfs.multi-dom-lk-cnt-req"
  208 #define GFID_TO_PATH_KEY "glusterfs.gfid2path"
  209 #define GF_XATTR_STIME_PATTERN "trusted.glusterfs.*.stime"
  210 #define GF_XATTR_XTIME_PATTERN "trusted.glusterfs.*.xtime"
  211 #define GF_XATTR_TRIGGER_SYNC "glusterfs.geo-rep.trigger-sync"
  212 
  213 /* quota xattrs */
  214 #define QUOTA_SIZE_KEY "trusted.glusterfs.quota.size"
  215 #define QUOTA_LIMIT_KEY "trusted.glusterfs.quota.limit-set"
  216 #define QUOTA_LIMIT_OBJECTS_KEY "trusted.glusterfs.quota.limit-objects"
  217 #define VIRTUAL_QUOTA_XATTR_CLEANUP_KEY "glusterfs.quota-xattr-cleanup"
  218 #define QUOTA_READ_ONLY_KEY "trusted.glusterfs.quota.read-only"
  219 
  220 /* ctime related */
  221 #define CTIME_MDATA_XDATA_KEY "set-ctime-mdata"
  222 
  223 /* afr related */
  224 #define AFR_XATTR_PREFIX "trusted.afr"
  225 
  226 /* Index xlator related */
  227 #define GF_XATTROP_INDEX_GFID "glusterfs.xattrop_index_gfid"
  228 #define GF_XATTROP_ENTRY_CHANGES_GFID "glusterfs.xattrop_entry_changes_gfid"
  229 #define GF_XATTROP_INDEX_COUNT "glusterfs.xattrop_index_count"
  230 #define GF_XATTROP_DIRTY_GFID "glusterfs.xattrop_dirty_gfid"
  231 #define GF_XATTROP_DIRTY_COUNT "glusterfs.xattrop_dirty_count"
  232 #define GF_XATTROP_ENTRY_IN_KEY "glusterfs.xattrop-entry-create"
  233 #define GF_XATTROP_ENTRY_OUT_KEY "glusterfs.xattrop-entry-delete"
  234 #define GF_INDEX_IA_TYPE_GET_REQ "glusterfs.index-ia-type-get-req"
  235 #define GF_INDEX_IA_TYPE_GET_RSP "glusterfs.index-ia-type-get-rsp"
  236 
  237 #define GF_HEAL_INFO "glusterfs.heal-info"
  238 #define GF_AFR_HEAL_SBRAIN "glusterfs.heal-sbrain"
  239 #define GF_AFR_SBRAIN_STATUS "replica.split-brain-status"
  240 #define GF_AFR_SBRAIN_CHOICE "replica.split-brain-choice"
  241 #define GF_AFR_SPB_CHOICE_TIMEOUT "replica.split-brain-choice-timeout"
  242 #define GF_AFR_SBRAIN_RESOLVE "replica.split-brain-heal-finalize"
  243 #define GF_AFR_ADD_BRICK "trusted.add-brick"
  244 #define GF_AFR_REPLACE_BRICK "trusted.replace-brick"
  245 #define GF_AFR_DIRTY "trusted.afr.dirty"
  246 #define GF_XATTROP_ENTRY_OUT "glusterfs.xattrop-entry-delete"
  247 #define GF_XATTROP_PURGE_INDEX "glusterfs.xattrop-purge-index"
  248 
  249 #define GF_GFIDLESS_LOOKUP "gfidless-lookup"
  250 /* replace-brick and pump related internal xattrs */
  251 #define RB_PUMP_CMD_START "glusterfs.pump.start"
  252 #define RB_PUMP_CMD_PAUSE "glusterfs.pump.pause"
  253 #define RB_PUMP_CMD_COMMIT "glusterfs.pump.commit"
  254 #define RB_PUMP_CMD_ABORT "glusterfs.pump.abort"
  255 #define RB_PUMP_CMD_STATUS "glusterfs.pump.status"
  256 
  257 #define GLUSTERFS_MARKER_DONT_ACCOUNT_KEY "glusters.marker.dont-account"
  258 #define GLUSTERFS_RDMA_INLINE_THRESHOLD (2048)
  259 #define GLUSTERFS_RDMA_MAX_HEADER_SIZE                                         \
  260     (228) /* (sizeof (rdma_header_t)                                           \
  261              + RDMA_MAX_SEGMENTS                                               \
  262              * sizeof (rdma_read_chunk_t))                                     \
  263              */
  264 
  265 #define GLUSTERFS_RPC_REPLY_SIZE 24
  266 
  267 #define STARTING_EVENT_THREADS 2
  268 
  269 #define DEFAULT_VAR_RUN_DIRECTORY DATADIR "/run/gluster"
  270 #define DEFAULT_GLUSTERFSD_MISC_DIRETORY DATADIR "/lib/misc/glusterfsd"
  271 #ifdef GF_LINUX_HOST_OS
  272 #define GLUSTERD_DEFAULT_WORKDIR DATADIR "/lib/glusterd"
  273 #else
  274 #define GLUSTERD_DEFAULT_WORKDIR DATADIR "/db/glusterd"
  275 #endif
  276 #define GF_REPLICATE_TRASH_DIR ".landfill"
  277 
  278 /* GlusterFS's maximum supported Auxiliary GIDs */
  279 #define GF_MAX_AUX_GROUPS 65535
  280 
  281 #define GF_UUID_BUF_SIZE 37          /* UUID_CANONICAL_FORM_LEN + NULL */
  282 #define GF_UUID_BNAME_BUF_SIZE (320) /* (64 + 256) */
  283 
  284 #define GF_REBALANCE_TID_KEY "rebalance-id"
  285 #define GF_REMOVE_BRICK_TID_KEY "remove-brick-id"
  286 #define GF_TIER_TID_KEY "tier-id"
  287 #define GF_TIER_ENABLED "tier-enabled"
  288 
  289 #define UUID_CANONICAL_FORM_LEN 36
  290 
  291 /* Adding this here instead of any glusterd*.h files as it is also required by
  292  * cli
  293  */
  294 #define DEFAULT_GLUSTERD_SOCKFILE DATADIR "/run/glusterd.socket"
  295 
  296 /* features/marker-quota also needs to have knowledge of link-files so as to
  297  * exclude them from accounting.
  298  */
  299 #define DHT_LINKFILE_MODE (S_ISVTX)
  300 
  301 #define IS_DHT_LINKFILE_MODE(iabuf)                                            \
  302     ((st_mode_from_ia((iabuf)->ia_prot, (iabuf)->ia_type) & ~S_IFMT) ==        \
  303      DHT_LINKFILE_MODE)
  304 #define DHT_LINKFILE_STR "linkto"
  305 #define DHT_COMMITHASH_STR "commithash"
  306 
  307 #define DHT_SKIP_NON_LINKTO_UNLINK "unlink-only-if-dht-linkto-file"
  308 #define TIER_SKIP_NON_LINKTO_UNLINK "unlink-only-if-tier-linkto-file"
  309 #define DHT_SKIP_OPEN_FD_UNLINK "dont-unlink-for-open-fd"
  310 #define DHT_IATT_IN_XDATA_KEY "dht-get-iatt-in-xattr"
  311 #define DHT_MODE_IN_XDATA_KEY "dht-get-mode-in-xattr"
  312 #define GET_LINK_COUNT "get-link-count"
  313 #define GF_GET_SIZE "get-size"
  314 #define GF_PRESTAT "virt-gf-prestat"
  315 #define GF_POSTSTAT "virt-gf-poststat"
  316 
  317 /*CTR and Marker requires inode dentry link count from posix*/
  318 #define GF_RESPONSE_LINK_COUNT_XDATA "gf_response_link_count"
  319 #define GF_REQUEST_LINK_COUNT_XDATA "gf_request_link_count"
  320 
  321 #define GF_GET_FILE_BLOCK_COUNT "gf_get_file_block_count"
  322 
  323 #define CTR_ATTACH_TIER_LOOKUP "ctr_attach_tier_lookup"
  324 
  325 #define CLIENT_CMD_CONNECT "trusted.glusterfs.client-connect"
  326 #define CLIENT_CMD_DISCONNECT "trusted.glusterfs.client-disconnect"
  327 
  328 #define GF_LOG_LRU_BUFSIZE_DEFAULT 5
  329 #define GF_LOG_LRU_BUFSIZE_MIN 0
  330 #define GF_LOG_LRU_BUFSIZE_MAX 20
  331 #define GF_LOG_LRU_BUFSIZE_MIN_STR "0"
  332 #define GF_LOG_LRU_BUFSIZE_MAX_STR "20"
  333 
  334 #define GF_LOG_FLUSH_TIMEOUT_DEFAULT 120
  335 #define GF_LOG_FLUSH_TIMEOUT_MIN 30
  336 #define GF_LOG_FLUSH_TIMEOUT_MAX 300
  337 #define GF_LOG_FLUSH_TIMEOUT_MIN_STR "30"
  338 #define GF_LOG_FLUSH_TIMEOUT_MAX_STR "300"
  339 #define GF_LOG_LOCALTIME_DEFAULT 0
  340 
  341 #define GF_NETWORK_TIMEOUT 42
  342 
  343 #define GF_BACKTRACE_LEN 4096
  344 #define GF_BACKTRACE_FRAME_COUNT 7
  345 
  346 #define GF_LK_ADVISORY 0  /* maps to GLFS_LK_ADVISORY from libgfapi*/
  347 #define GF_LK_MANDATORY 1 /* maps to GLFS_LK_MANDATORY from libgfapi*/
  348 #define GF_LOCK_MODE "glusterfs.lk.lkmode"
  349 
  350 #define GF_CHECK_XATTR_KEY_AND_GOTO(key, cmpkey, errval, lbl)                  \
  351     do {                                                                       \
  352         if (key && strcmp(key, cmpkey) == 0) {                                 \
  353             errval = -EINVAL;                                                  \
  354             goto lbl;                                                          \
  355         }                                                                      \
  356     } while (0)
  357 
  358 #define GF_CS_OBJECT_SIZE "trusted.glusterfs.cs.object_size"
  359 #define GF_CS_BLOCK_SIZE "trusted.glusterfs.cs.block_size"
  360 #define GF_CS_NUM_BLOCKS "trusted.glusterfs.cs.num_blocks"
  361 
  362 #define GF_CS_XATTR_ARCHIVE_UUID "trusted.cloudsync.uuid"
  363 
  364 #define GF_CS_OBJECT_UPLOAD_COMPLETE "trusted.glusterfs.csou.complete"
  365 #define GF_CS_OBJECT_REMOTE "trusted.glusterfs.cs.remote"
  366 #define GF_CS_OBJECT_DOWNLOADING "trusted.glusterfs.cs.downloading"
  367 #define GF_CS_OBJECT_DOWNLOADED "trusted.glusterfs.cs.downloaded"
  368 #define GF_CS_OBJECT_STATUS "trusted.glusterfs.cs.status"
  369 #define GF_CS_OBJECT_REPAIR "trusted.glusterfs.cs.repair"
  370 
  371 #define gf_boolean_t bool
  372 #define _gf_false false
  373 #define _gf_true true
  374 
  375 typedef enum {
  376     GF_CS_LOCAL = 1,
  377     GF_CS_REMOTE = 2,
  378     GF_CS_REPAIR = 4,
  379     GF_CS_DOWNLOADING = 8,
  380     GF_CS_ERROR = 16,
  381 } gf_cs_obj_state;
  382 
  383 typedef enum {
  384     GF_FOP_PRI_UNSPEC = -1, /* Priority not specified */
  385     GF_FOP_PRI_HI = 0,      /* low latency */
  386     GF_FOP_PRI_NORMAL,      /* normal */
  387     GF_FOP_PRI_LO,          /* bulk */
  388     GF_FOP_PRI_LEAST,       /* least */
  389     GF_FOP_PRI_MAX,         /* Highest */
  390 } gf_fop_pri_t;
  391 
  392 typedef enum {
  393     /* The 'component' (xlator / option) is not yet setting the flag */
  394     GF_UNCLASSIFIED = 0,
  395     /* The 'component' is experimental, should not be recommened
  396        in production mode */
  397     GF_EXPERIMENTAL,
  398     /* The 'component' is tech preview, ie, it is 'mostly' working as
  399        expected, but can have some of the corner cases, which is not
  400        handled. */
  401     GF_TECH_PREVIEW,
  402     /* The 'component' is good to run. Has good enough test and
  403        documentation coverage. */
  404     GF_MAINTAINED,
  405     /* The component is:
  406        - no more a focus
  407        - no more solving a valid use case
  408        - no more maintained, no volunteers to maintain
  409        - there is 'maintained' or 'tech-preview' feature,
  410        which does the same thing, better.
  411     */
  412     GF_DEPRECATED,
  413     /* The 'component' is no more 'built'. */
  414     GF_OBSOLETE,
  415     /* The 'component' exist for Documentation purposes.
  416        No real usecase */
  417     GF_DOCUMENT_PURPOSE,
  418 } gf_category_t;
  419 
  420 static const char *const FOP_PRI_STRINGS[] = {"HIGH", "NORMAL", "LOW", "LEAST"};
  421 
  422 static inline const char *
  423 fop_pri_to_string(gf_fop_pri_t pri)
  424 {
  425     if (pri < 0)
  426         return "UNSPEC";
  427 
  428     if (pri >= GF_FOP_PRI_MAX)
  429         return "INVALID";
  430 
  431     return FOP_PRI_STRINGS[pri];
  432 }
  433 
  434 const char *
  435 fop_enum_to_pri_string(glusterfs_fop_t fop);
  436 
  437 #define GF_SET_IF_NOT_PRESENT 0x1 /* default behaviour */
  438 #define GF_SET_OVERWRITE 0x2      /* Overwrite with the buf given */
  439 #define GF_SET_DIR_ONLY 0x4
  440 #define GF_SET_EPOCH_TIME 0x8    /* used by afr dir lookup selfheal */
  441 #define GF_AUXILLARY_PARGFID 0xd /* RIO dummy parent gfid */
  442 
  443 /* key value which quick read uses to get small files in lookup cbk */
  444 #define GF_CONTENT_KEY "glusterfs.content"
  445 
  446 struct _xlator_cmdline_option {
  447     struct list_head cmd_args;
  448     char *volume;
  449     char *key;
  450     char *value;
  451 };
  452 typedef struct _xlator_cmdline_option xlator_cmdline_option_t;
  453 
  454 struct _server_cmdline {
  455     struct list_head list;
  456     char *volfile_server;
  457     char *transport;
  458     int port;
  459 };
  460 typedef struct _server_cmdline server_cmdline_t;
  461 
  462 #define GF_OPTION_ENABLE _gf_true
  463 #define GF_OPTION_DISABLE _gf_false
  464 #define GF_OPTION_DEFERRED 2
  465 
  466 struct _cmd_args {
  467     /* basic options */
  468     char *volfile_server;
  469     server_cmdline_t *curr_server;
  470     /* List of backup  volfile servers, including original */
  471     struct list_head volfile_servers;
  472     char *volfile;
  473     char *log_server;
  474     gf_loglevel_t log_level;
  475     char *log_file;
  476     char *log_ident;
  477     gf_log_logger_t logger;
  478     gf_log_format_t log_format;
  479     uint32_t log_buf_size;
  480     uint32_t log_flush_timeout;
  481     int32_t max_connect_attempts;
  482     char *print_exports;
  483     char *print_netgroups;
  484     int print_xlatordir;
  485     int print_statedumpdir;
  486     int print_logdir;
  487     int print_libexecdir;
  488     /* advanced options */
  489     uint32_t volfile_server_port;
  490     char *volfile_server_transport;
  491     uint32_t log_server_port;
  492     char *pid_file;
  493     char *sock_file;
  494     int no_daemon_mode;
  495     char *run_id;
  496     int debug_mode;
  497     int read_only;
  498     int acl;
  499     int selinux;
  500     int capability;
  501     int enable_ino32;
  502     int worm;
  503     int mac_compat;
  504     int fopen_keep_cache;
  505     int gid_timeout;
  506     char gid_timeout_set;
  507     int aux_gfid_mount;
  508 
  509     /* need a process wide timer-wheel? */
  510     int global_timer_wheel;
  511 
  512     /* list of xlator_option_t */
  513     struct list_head xlator_options;
  514 
  515     /* fuse options */
  516     int fuse_direct_io_mode;
  517     char *use_readdirp;
  518     int no_root_squash;
  519     int volfile_check;
  520     double fuse_entry_timeout;
  521     double fuse_negative_timeout;
  522     double fuse_attribute_timeout;
  523     char *volume_name;
  524     int fuse_nodev;
  525     int fuse_nosuid;
  526     char *dump_fuse;
  527     pid_t client_pid;
  528     int client_pid_set;
  529     unsigned uid_map_root;
  530     int32_t lru_limit;
  531     int32_t invalidate_limit;
  532     int background_qlen;
  533     int congestion_threshold;
  534     char *fuse_mountopts;
  535     int mem_acct;
  536     int resolve_gids;
  537 
  538     /* key args */
  539     char *mount_point;
  540     char *volfile_id;
  541 
  542     /* required for portmap */
  543     int brick_port;
  544     char *brick_name;
  545     int brick_port2;
  546 
  547     /* Should management connections use SSL? */
  548     int secure_mgmt;
  549 
  550     /* Linux-only OOM killer adjustment */
  551 #ifdef GF_LINUX_HOST_OS
  552     char *oom_score_adj;
  553 #endif
  554 
  555     /* Run this process with valgrind? Might want to prevent calling
  556      * functions that prevent valgrind from working correctly, like
  557      * dlclose(). */
  558     int valgrind;
  559     int localtime_logging;
  560 
  561     /* For the subdir mount */
  562     char *subdir_mount;
  563 
  564     char *process_name;
  565     char *event_history;
  566     int thin_client;
  567     uint32_t reader_thread_count;
  568 
  569     /* FUSE writeback cache support */
  570     int kernel_writeback_cache;
  571     uint32_t attr_times_granularity;
  572 
  573     int fuse_flush_handle_interrupt;
  574     int fuse_auto_inval;
  575 
  576     bool global_threading;
  577     bool brick_mux;
  578 
  579     uint32_t fuse_dev_eperm_ratelimit_ns;
  580 };
  581 typedef struct _cmd_args cmd_args_t;
  582 
  583 struct _glusterfs_graph {
  584     struct list_head list;
  585     struct timeval dob;
  586     void *first;
  587     void *top; /* selected by -n */
  588     int xl_count;
  589     int id;   /* Used in logging */
  590     int used; /* Should be set when fuse gets
  591                         first CHILD_UP */
  592     uint32_t volfile_checksum;
  593     uint32_t leaf_count;
  594     void *last_xl; /* Stores the last xl of the graph, as of now only populated
  595                       in client multiplexed code path */
  596     pthread_mutex_t mutex;
  597     pthread_cond_t child_down_cond; /* for broadcasting CHILD_DOWN */
  598     int parent_down;
  599     char graph_uuid[128];
  600     char volume_id[GF_UUID_BUF_SIZE];
  601 };
  602 typedef struct _glusterfs_graph glusterfs_graph_t;
  603 
  604 typedef int32_t (*glusterfsd_mgmt_event_notify_fn_t)(int32_t event, void *data,
  605                                                      ...);
  606 
  607 typedef enum {
  608     MGMT_SSL_NEVER = 0,
  609     MGMT_SSL_COPY_IO,
  610     MGMT_SSL_ALWAYS
  611 } mgmt_ssl_t;
  612 
  613 struct tvec_base;
  614 
  615 /* reference counting for the global (per ctx) timer-wheel */
  616 struct gf_ctx_tw {
  617     GF_REF_DECL;
  618     struct tvec_base *timer_wheel; /* global timer-wheel instance */
  619 };
  620 
  621 struct _glusterfs_ctx {
  622     cmd_args_t cmd_args;
  623     char *process_uuid;
  624     FILE *pidfp;
  625     char fin;
  626     void *timer;
  627     void *ib;
  628     struct call_pool *pool;
  629     void *event_pool;
  630     void *iobuf_pool;
  631     void *logbuf_pool;
  632     gf_lock_t lock;
  633     size_t page_size;
  634 
  635     /* one per volfile parse */
  636     struct list_head graphs;
  637 
  638     /* the latest graph in use */
  639     glusterfs_graph_t *active;
  640 
  641     /* fuse or nfs (but not protocol/server) */
  642     void *master;
  643 
  644     /* xlator implementing MOPs for centralized logging, volfile server */
  645     void *mgmt;
  646 
  647     /* listener of the commands from glusterd */
  648     void *listener;
  649 
  650     /* toggle switch for latency measurement */
  651     unsigned char measure_latency;
  652     pthread_t sigwaiter;
  653     char *cmdlinestr;
  654     struct mem_pool *stub_mem_pool;
  655     unsigned char cleanup_started;
  656     int graph_id;        /* Incremented per graph, value should
  657                             indicate how many times the graph has
  658                             got changed */
  659     pid_t mnt_pid;       /* pid of the mount agent */
  660     int process_mode;    /*mode in which process is runninng*/
  661     struct syncenv *env; /* The env pointer to the synctasks */
  662 
  663     struct list_head mempool_list; /* used to keep a global list of
  664                                       mempools, used to log details of
  665                                       mempool in statedump */
  666     char *statedump_path;
  667 
  668     struct mem_pool *dict_pool;
  669     struct mem_pool *dict_pair_pool;
  670     struct mem_pool *dict_data_pool;
  671 
  672     glusterfsd_mgmt_event_notify_fn_t notify; /* Used for xlators to make
  673                                                  call to fsd-mgmt */
  674     gf_log_handle_t log; /* all logging related variables */
  675 
  676     int mem_acct_enable;
  677 
  678     int daemon_pipe[2];
  679 
  680     struct clienttable *clienttable;
  681 
  682     /*
  683      * Should management connections use SSL?  This is the only place we
  684      * can put it where both daemon-startup and socket code will see it.
  685      *
  686      * Why is it an int?  Because we're included before common-utils.h,
  687      * which defines gf_boolean_t (what we really want).  It doesn't make
  688      * any sense, but it's not worth turning the codebase upside-down to
  689      * fix it.  Thus, an int.
  690      */
  691     int secure_mgmt;
  692 
  693     /* The option is use to set cert_depth while management connection
  694        use SSL
  695      */
  696     int ssl_cert_depth;
  697 
  698     /*
  699      * Should *our* server/inbound connections use SSL?  This is only true
  700      * if we're glusterd and secure_mgmt is set, or if we're glusterfsd
  701      * and SSL is set on the I/O path.  It should never be set e.g. for
  702      * NFS.
  703      */
  704     mgmt_ssl_t secure_srvr;
  705     /* Buffer to 'save' backtrace even under OOM-kill like situations*/
  706     char btbuf[GF_BACKTRACE_LEN];
  707 
  708     pthread_mutex_t notify_lock;
  709     pthread_mutex_t cleanup_lock;
  710     pthread_cond_t notify_cond;
  711     int notifying;
  712 
  713     struct gf_ctx_tw *tw; /* refcounted timer_wheel */
  714 
  715     gf_lock_t volfile_lock;
  716 
  717     /* configuration related elements, which gets changed
  718        from global xlator */
  719     struct {
  720         char *metrics_dumppath;
  721     } config;
  722 
  723     struct {
  724         gf_atomic_t max_dict_pairs;
  725         gf_atomic_t total_pairs_used;
  726         gf_atomic_t total_dicts_used;
  727     } stats;
  728 
  729     struct list_head volfile_list;
  730     /* Add members to manage janitor threads for cleanup fd */
  731     struct list_head janitor_fds;
  732     pthread_cond_t fd_cond;
  733     pthread_mutex_t fd_lock;
  734     pthread_t janitor;
  735     /* The variable is use to save total posix xlator count */
  736     uint32_t pxl_count;
  737 
  738     char volume_id[GF_UUID_BUF_SIZE]; /* Used only in protocol/client */
  739 };
  740 typedef struct _glusterfs_ctx glusterfs_ctx_t;
  741 
  742 typedef struct {
  743     char volfile_checksum[SHA256_DIGEST_LENGTH];
  744     char vol_id[NAME_MAX + 1];
  745     struct list_head volfile_list;
  746     glusterfs_graph_t *graph;
  747     FILE *pidfp;
  748 } gf_volfile_t;
  749 
  750 glusterfs_ctx_t *
  751 glusterfs_ctx_new(void);
  752 
  753 struct gf_flock {
  754     short l_type;
  755     short l_whence;
  756     off_t l_start;
  757     off_t l_len;
  758     pid_t l_pid;
  759     gf_lkowner_t l_owner;
  760 };
  761 
  762 typedef struct lock_migration_info {
  763     struct list_head list;
  764     struct gf_flock flock;
  765     char *client_uid;
  766     uint32_t lk_flags;
  767 } lock_migration_info_t;
  768 
  769 #define GF_MUST_CHECK __attribute__((warn_unused_result))
  770 /*
  771  * Some macros (e.g. ALLOC_OR_GOTO) set variables in function scope, but the
  772  * calling function might not only declare the variable to keep the macro happy
  773  * and not use it otherwise.  In such cases, the following can be used to
  774  * suppress the "set but not used" warning that would otherwise occur.
  775  */
  776 #define GF_UNUSED __attribute__((unused))
  777 
  778 /*
  779  * If present, this has the following effects:
  780  *
  781  *      glusterd enables privileged commands over TCP
  782  *
  783  *      all code enables SSL for outbound connections to management port
  784  *
  785  *      glusterd enables SSL for inbound connections
  786  *
  787  * Servers and clients enable/disable SSL among themselves by other means.
  788  * Making secure management connections conditional on a file is a bit of a
  789  * hack, but we don't have any other place for such global settings across
  790  * all of the affected components.  Making it a compile-time option would
  791  * reduce functionality, both for users and for testing (which can now be
  792  * done using secure connections for all tests without change elsewhere).
  793  *
  794  */
  795 #define SECURE_ACCESS_FILE GLUSTERD_DEFAULT_WORKDIR "/secure-access"
  796 
  797 int
  798 glusterfs_graph_prepare(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx,
  799                         char *volume_name);
  800 int
  801 glusterfs_graph_destroy_residual(glusterfs_graph_t *graph);
  802 int
  803 glusterfs_graph_deactivate(glusterfs_graph_t *graph);
  804 int
  805 glusterfs_graph_destroy(glusterfs_graph_t *graph);
  806 int
  807 glusterfs_get_leaf_count(glusterfs_graph_t *graph);
  808 int
  809 glusterfs_graph_activate(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx);
  810 glusterfs_graph_t *
  811 glusterfs_graph_construct(FILE *fp);
  812 int
  813 glusterfs_graph_init(glusterfs_graph_t *graph);
  814 glusterfs_graph_t *
  815 glusterfs_graph_new(void);
  816 int
  817 glusterfs_graph_reconfigure(glusterfs_graph_t *oldgraph,
  818                             glusterfs_graph_t *newgraph);
  819 int
  820 glusterfs_graph_attach(glusterfs_graph_t *orig_graph, char *path,
  821                        glusterfs_graph_t **newgraph);
  822 int
  823 glusterfs_graph_parent_up(glusterfs_graph_t *graph);
  824 
  825 void
  826 gf_free_mig_locks(lock_migration_info_t *locks);
  827 
  828 int
  829 glusterfs_read_secure_access_file(void);
  830 int
  831 glusterfs_graph_fini(glusterfs_graph_t *graph);
  832 #endif /* _GLUSTERFS_H */