"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/cluster/dht/src/dht-common.h" (16 Sep 2020, 46712 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 "dht-common.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2   Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
    3   This file is part of GlusterFS.
    4 
    5   This file is licensed to you under your choice of the GNU Lesser
    6   General Public License, version 3 or any later version (LGPLv3 or
    7   later), or the GNU General Public License, version 2 (GPLv2), in all
    8   cases as published by the Free Software Foundation.
    9 */
   10 
   11 #include <regex.h>
   12 
   13 #include "dht-mem-types.h"
   14 #include "dht-messages.h"
   15 #include <glusterfs/call-stub.h>
   16 #include "libxlator.h"
   17 #include <glusterfs/syncop.h>
   18 #include <glusterfs/refcount.h>
   19 #include <glusterfs/timer.h>
   20 #include "protocol-common.h"
   21 #include <glusterfs/glusterfs-acl.h>
   22 
   23 #ifndef _DHT_H
   24 #define _DHT_H
   25 
   26 #define GF_XATTR_FIX_LAYOUT_KEY "distribute.fix.layout"
   27 #define GF_XATTR_TIER_LAYOUT_FIXED_KEY "trusted.tier.fix.layout.complete"
   28 #define GF_XATTR_FILE_MIGRATE_KEY "trusted.distribute.migrate-data"
   29 #define DHT_MDS_STR "mds"
   30 #define GF_DHT_LOOKUP_UNHASHED_OFF 0
   31 #define GF_DHT_LOOKUP_UNHASHED_ON 1
   32 #define GF_DHT_LOOKUP_UNHASHED_AUTO 2
   33 #define DHT_PATHINFO_HEADER "DISTRIBUTE:"
   34 #define DHT_FILE_MIGRATE_DOMAIN "dht.file.migrate"
   35 /* Layout synchronization */
   36 #define DHT_LAYOUT_HEAL_DOMAIN "dht.layout.heal"
   37 /* Namespace synchronization */
   38 #define DHT_ENTRY_SYNC_DOMAIN "dht.entry.sync"
   39 #define TIERING_MIGRATION_KEY "tiering.migration"
   40 #define DHT_LAYOUT_HASH_INVALID 1
   41 #define MAX_REBAL_THREADS sysconf(_SC_NPROCESSORS_ONLN)
   42 
   43 #define DHT_DIR_STAT_BLOCKS 8
   44 #define DHT_DIR_STAT_SIZE 4096
   45 
   46 /* Virtual xattr for subvols status */
   47 
   48 #define DHT_SUBVOL_STATUS_KEY "dht.subvol.status"
   49 
   50 /* Virtual xattrs for debugging */
   51 
   52 #define DHT_DBG_HASHED_SUBVOL_PATTERN "dht.file.hashed-subvol.*"
   53 #define DHT_DBG_HASHED_SUBVOL_KEY "dht.file.hashed-subvol."
   54 
   55 /* Array to hold custom xattr keys
   56  */
   57 extern char *xattrs_to_heal[];
   58 
   59 /* Rebalance nodeuuid flags */
   60 #define REBAL_NODEUUID_MINE 0x01
   61 
   62 typedef int (*dht_selfheal_dir_cbk_t)(call_frame_t *frame, void *cookie,
   63                                       xlator_t *this, int32_t op_ret,
   64                                       int32_t op_errno, dict_t *xdata);
   65 typedef int (*dht_defrag_cbk_fn_t)(xlator_t *this, xlator_t *dst_node,
   66                                    call_frame_t *frame, int ret);
   67 
   68 typedef int (*dht_refresh_layout_unlock)(call_frame_t *frame, xlator_t *this,
   69                                          int op_ret, int invoke_cbk);
   70 
   71 typedef int (*dht_refresh_layout_done_handle)(call_frame_t *frame);
   72 
   73 struct dht_layout {
   74     int spread_cnt; /* layout spread count per directory,
   75                        is controlled by 'setxattr()' with
   76                        special key */
   77     int cnt;
   78     int preset;
   79     /*
   80      * The last *configuration* state for which this directory was known
   81      * to be in balance.  The corresponding vol_commit_hash changes
   82      * whenever bricks are added or removed.  This value changes when a
   83      * (full) rebalance is complete.  If they match, it's safe to assume
   84      * that every file is where it should be and there's no need to do
   85      * lookups for files elsewhere.  If they don't, then we have to do a
   86      * global lookup to be sure.
   87      */
   88     uint32_t commit_hash;
   89     /*
   90      * The *runtime* state of the volume, changes when connections to
   91      * bricks are made or lost.
   92      */
   93     int gen;
   94     int type;
   95     gf_atomic_t ref; /* use with dht_conf_t->layout_lock */
   96     uint32_t search_unhashed;
   97     struct {
   98         int err; /* 0 = normal
   99                     -1 = dir exists and no xattr
  100                     >0 = dir lookup failed with errno
  101                  */
  102         uint32_t start;
  103         uint32_t stop;
  104         uint32_t commit_hash;
  105         xlator_t *xlator;
  106     } list[];
  107 };
  108 typedef struct dht_layout dht_layout_t;
  109 
  110 struct dht_stat_time {
  111     uint32_t atime;
  112     uint32_t atime_nsec;
  113     uint32_t ctime;
  114     uint32_t ctime_nsec;
  115     uint32_t mtime;
  116     uint32_t mtime_nsec;
  117 };
  118 
  119 typedef struct dht_stat_time dht_stat_time_t;
  120 
  121 struct dht_inode_ctx {
  122     dht_layout_t *layout;
  123     dht_stat_time_t time;
  124     xlator_t *lock_subvol;
  125     xlator_t *mds_subvol; /* This is only used for directories */
  126 };
  127 
  128 typedef struct dht_inode_ctx dht_inode_ctx_t;
  129 
  130 typedef enum {
  131     DHT_HASH_TYPE_DM,
  132     DHT_HASH_TYPE_DM_USER,
  133 } dht_hashfn_type_t;
  134 
  135 typedef enum {
  136     DHT_INODELK,
  137     DHT_ENTRYLK,
  138 } dht_lock_type_t;
  139 
  140 /* rebalance related */
  141 struct dht_rebalance_ {
  142     xlator_t *from_subvol;
  143     xlator_t *target_node;
  144     off_t offset;
  145     size_t size;
  146     int32_t flags;
  147     int count;
  148     struct iobref *iobref;
  149     struct iovec *vector;
  150     struct iatt stbuf;
  151     struct iatt prebuf;
  152     struct iatt postbuf;
  153     dht_defrag_cbk_fn_t target_op_fn;
  154     dict_t *xdata;
  155     dict_t *xattr;
  156     dict_t *dict;
  157     struct gf_flock flock;
  158     int32_t set;
  159     int lock_cmd;
  160 };
  161 
  162 /**
  163  * Enum to store decided action based on the qdstatfs (quota-deem-statfs)
  164  * events
  165  **/
  166 typedef enum {
  167     qdstatfs_action_OFF = 0,
  168     qdstatfs_action_REPLACE,
  169     qdstatfs_action_NEGLECT,
  170     qdstatfs_action_COMPARE,
  171 } qdstatfs_action_t;
  172 
  173 typedef enum {
  174     REACTION_INVALID,
  175     FAIL_ON_ANY_ERROR,
  176     IGNORE_ENOENT_ESTALE,
  177     IGNORE_ENOENT_ESTALE_EIO,
  178 } dht_reaction_type_t;
  179 
  180 struct dht_skip_linkto_unlink {
  181     xlator_t *hash_links_to;
  182     uuid_t cached_gfid;
  183     uuid_t hashed_gfid;
  184     int opend_fd_count;
  185     gf_boolean_t handle_valid_link;
  186 };
  187 
  188 typedef struct {
  189     xlator_t *xl;
  190     loc_t loc;      /* contains/points to inode to lock on. */
  191     char *domain;   /* Only locks within a single domain
  192                      * contend with each other
  193                      */
  194     char *basename; /* Required for entrylk */
  195     gf_boolean_t locked;
  196     dht_reaction_type_t do_on_failure;
  197     short type; /* read/write lock.                     */
  198     gf_lkowner_t lk_owner;
  199 } dht_lock_t;
  200 
  201 /* The lock structure represents inodelk. */
  202 typedef struct {
  203     fop_inodelk_cbk_t inodelk_cbk;
  204     dht_lock_t **locks;
  205     int lk_count;
  206     dht_reaction_type_t reaction;
  207 
  208     /* whether locking failed on _any_ of the "locks" above */
  209     int op_ret;
  210     int op_errno;
  211 } dht_ilock_wrap_t;
  212 
  213 /* The lock structure represents entrylk. */
  214 typedef struct {
  215     fop_entrylk_cbk_t entrylk_cbk;
  216     dht_lock_t **locks;
  217     int lk_count;
  218     dht_reaction_type_t reaction;
  219 
  220     /* whether locking failed on _any_ of the "locks" above */
  221     int op_ret;
  222     int op_errno;
  223 } dht_elock_wrap_t;
  224 
  225 /* The first member of dht_dir_transaction_t should be of type dht_ilock_wrap_t.
  226  * Otherwise it can result in subtle memory corruption issues as in most of the
  227  * places we use lock[0].layout.my_layout or lock[0].layout.parent_layout and
  228  * lock[0].ns.parent_layout (like in dht_local_wipe).
  229  */
  230 typedef union {
  231     union {
  232         dht_ilock_wrap_t my_layout;
  233         dht_ilock_wrap_t parent_layout;
  234     } layout;
  235     struct dht_namespace {
  236         dht_ilock_wrap_t parent_layout;
  237         dht_elock_wrap_t directory_ns;
  238         fop_entrylk_cbk_t ns_cbk;
  239     } ns;
  240 } dht_dir_transaction_t;
  241 
  242 typedef int (*dht_selfheal_layout_t)(call_frame_t *frame, loc_t *loc,
  243                                      dht_layout_t *layout);
  244 
  245 typedef gf_boolean_t (*dht_need_heal_t)(call_frame_t *frame,
  246                                         dht_layout_t **inmem,
  247                                         dht_layout_t **ondisk);
  248 
  249 typedef struct {
  250     uint64_t blocks_used;
  251     uint64_t pblocks_used;
  252     uint64_t files_used;
  253     uint64_t pfiles_used;
  254     uint64_t unhashed_blocks_used;
  255     uint64_t unhashed_pblocks_used;
  256     uint64_t unhashed_files_used;
  257     uint64_t unhashed_pfiles_used;
  258     uint64_t unhashed_fsid;
  259     uint64_t hashed_fsid;
  260 } tier_statvfs_t;
  261 
  262 struct dht_local {
  263     loc_t loc;
  264     loc_t loc2;
  265     int call_cnt;
  266     int op_ret;
  267     int op_errno;
  268     int layout_mismatch;
  269     /* Use stbuf as the postbuf, when we require both
  270      * pre and post attrs */
  271     struct iatt stbuf;
  272     struct iatt mds_stbuf;
  273     struct iatt prebuf;
  274     struct iatt preoldparent;
  275     struct iatt postoldparent;
  276     struct iatt preparent;
  277     struct iatt postparent;
  278     struct statvfs statvfs;
  279     tier_statvfs_t tier_statvfs;
  280     fd_t *fd;
  281     inode_t *inode;
  282     dict_t *params;
  283     dict_t *xattr;
  284     dict_t *mds_xattr;
  285     dict_t *xdata; /* dict used to save xdata response by xattr fop */
  286     dict_t *xattr_req;
  287     dht_layout_t *layout;
  288     size_t size;
  289     ino_t ia_ino;
  290     xlator_t *src_hashed, *src_cached;
  291     xlator_t *dst_hashed, *dst_cached;
  292     xlator_t *cached_subvol;
  293     xlator_t *hashed_subvol;
  294     xlator_t *mds_subvol; /* This is use for dir only */
  295     int file_count;
  296     int dir_count;
  297     call_frame_t *main_frame;
  298     int fop_succeeded;
  299     struct {
  300         fop_mknod_cbk_t linkfile_cbk;
  301         struct iatt stbuf;
  302         loc_t loc;
  303         inode_t *inode;
  304         dict_t *xattr;
  305         xlator_t *srcvol;
  306     } linkfile;
  307     struct {
  308         uint32_t hole_cnt;
  309         uint32_t overlaps_cnt;
  310         uint32_t down;
  311         uint32_t misc;
  312         dht_selfheal_dir_cbk_t dir_cbk;
  313         dht_selfheal_layout_t healer;
  314         dht_need_heal_t should_heal;
  315         dht_layout_t *layout, *refreshed_layout;
  316         uint32_t missing_cnt;
  317         gf_boolean_t force_mkdir;
  318     } selfheal;
  319 
  320     dht_refresh_layout_unlock refresh_layout_unlock;
  321     dht_refresh_layout_done_handle refresh_layout_done;
  322 
  323     uint32_t uid;
  324     uint32_t gid;
  325     pid_t pid;
  326 
  327     glusterfs_fop_t fop;
  328 
  329     /* need for file-info */
  330     char *xattr_val;
  331     char *key;
  332 
  333     /* needed by nufa */
  334     int32_t flags;
  335     mode_t mode;
  336     dev_t rdev;
  337     mode_t umask;
  338 
  339     /* which xattr request? */
  340     char xsel[256];
  341     int32_t alloc_len;
  342 
  343     /* gfid related */
  344     uuid_t gfid;
  345     uuid_t gfid_req;
  346 
  347     xlator_t *link_subvol;
  348 
  349     struct dht_rebalance_ rebalance;
  350     xlator_t *first_up_subvol;
  351 
  352     struct dht_skip_linkto_unlink skip_unlink;
  353 
  354     dht_dir_transaction_t lock[2], *current;
  355 
  356     /* inodelks during filerename for backward compatibility */
  357     dht_lock_t **rename_inodelk_backward_compatible;
  358 
  359     call_stub_t *stub;
  360     int32_t parent_disk_layout[4];
  361 
  362     /* rename rollback */
  363     int *ret_cache;
  364 
  365     loc_t loc2_copy;
  366 
  367     int rename_inodelk_bc_count;
  368     /* This is use only for directory operation */
  369     int32_t valid;
  370     int32_t mds_heal_fresh_lookup;
  371     short lock_type;
  372     char need_selfheal;
  373     char need_xattr_heal;
  374     char need_attrheal;
  375     /* flag used to make sure we need to return estale in
  376        {lookup,revalidate}_cbk */
  377     char return_estale;
  378     char need_lookup_everywhere;
  379     /* fd open check */
  380     gf_boolean_t fd_checked;
  381     gf_boolean_t linked;
  382     gf_boolean_t added_link;
  383     gf_boolean_t is_linkfile;
  384     gf_boolean_t quota_deem_statfs;
  385     gf_boolean_t heal_layout;
  386     gf_boolean_t locked;
  387     gf_boolean_t dont_create_linkto;
  388     gf_boolean_t gfid_missing;
  389 };
  390 typedef struct dht_local dht_local_t;
  391 
  392 /* du - disk-usage */
  393 struct dht_du {
  394     double avail_percent;
  395     double avail_inodes;
  396     uint64_t avail_space;
  397     uint32_t log;
  398     uint32_t chunks;
  399     uint32_t total_blocks;
  400     uint32_t avail_blocks;
  401     uint32_t frsize; /*fragment size*/
  402 };
  403 typedef struct dht_du dht_du_t;
  404 
  405 enum gf_defrag_type {
  406     GF_DEFRAG_CMD_NONE = 0,
  407     GF_DEFRAG_CMD_START = 1,
  408     GF_DEFRAG_CMD_STOP = 1 + 1,
  409     GF_DEFRAG_CMD_STATUS = 1 + 2,
  410     GF_DEFRAG_CMD_START_LAYOUT_FIX = 1 + 3,
  411     GF_DEFRAG_CMD_START_FORCE = 1 + 4,
  412     GF_DEFRAG_CMD_START_TIER = 1 + 5,
  413     GF_DEFRAG_CMD_STATUS_TIER = 1 + 6,
  414     GF_DEFRAG_CMD_START_DETACH_TIER = 1 + 7,
  415     GF_DEFRAG_CMD_STOP_DETACH_TIER = 1 + 8,
  416     GF_DEFRAG_CMD_PAUSE_TIER = 1 + 9,
  417     GF_DEFRAG_CMD_RESUME_TIER = 1 + 10,
  418     GF_DEFRAG_CMD_DETACH_STATUS = 1 + 11,
  419     GF_DEFRAG_CMD_STOP_TIER = 1 + 12,
  420     GF_DEFRAG_CMD_DETACH_START = 1 + 13,
  421     GF_DEFRAG_CMD_DETACH_COMMIT = 1 + 14,
  422     GF_DEFRAG_CMD_DETACH_COMMIT_FORCE = 1 + 15,
  423     GF_DEFRAG_CMD_DETACH_STOP = 1 + 16,
  424     /* new labels are used so it will help
  425      * while removing old labels by easily differentiating.
  426      * A few labels are added so that the count remains same
  427      * between this enum and the ones on the xdr file.
  428      * different values for the same enum cause errors and
  429      * confusion.
  430      */
  431 };
  432 typedef enum gf_defrag_type gf_defrag_type;
  433 
  434 enum gf_defrag_status_t {
  435     GF_DEFRAG_STATUS_NOT_STARTED,
  436     GF_DEFRAG_STATUS_STARTED,
  437     GF_DEFRAG_STATUS_STOPPED,
  438     GF_DEFRAG_STATUS_COMPLETE,
  439     GF_DEFRAG_STATUS_FAILED,
  440     GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED,
  441     GF_DEFRAG_STATUS_LAYOUT_FIX_STOPPED,
  442     GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE,
  443     GF_DEFRAG_STATUS_LAYOUT_FIX_FAILED,
  444 };
  445 typedef enum gf_defrag_status_t gf_defrag_status_t;
  446 
  447 typedef struct gf_defrag_pattern_list gf_defrag_pattern_list_t;
  448 
  449 struct gf_defrag_pattern_list {
  450     char path_pattern[256];
  451     uint64_t size;
  452     gf_defrag_pattern_list_t *next;
  453 };
  454 
  455 struct dht_container {
  456     union {
  457         struct list_head list;
  458         struct {
  459             struct _gf_dirent_t *next;
  460             struct _gf_dirent_t *prev;
  461         };
  462     };
  463     gf_dirent_t *df_entry;
  464     xlator_t *this;
  465     loc_t *parent_loc;
  466     dict_t *migrate_data;
  467     int local_subvol_index;
  468 };
  469 
  470 typedef enum tier_mode_ {
  471     TIER_MODE_NONE = 0,
  472     TIER_MODE_TEST,
  473     TIER_MODE_WM
  474 } tier_mode_t;
  475 
  476 typedef enum tier_pause_state_ {
  477     TIER_RUNNING = 0,
  478     TIER_REQUEST_PAUSE,
  479     TIER_PAUSED
  480 } tier_pause_state_t;
  481 
  482 /* This Structure is only used in tiering fixlayout */
  483 typedef struct gf_tier_fix_layout_arg {
  484     xlator_t *this;
  485     dict_t *fix_layout;
  486     pthread_t thread_id;
  487 } gf_tier_fix_layout_arg_t;
  488 
  489 typedef struct gf_tier_conf {
  490     int is_tier;
  491     int watermark_hi;
  492     int watermark_low;
  493     int watermark_last;
  494     unsigned long block_size;
  495     fsblkcnt_t blocks_total;
  496     fsblkcnt_t blocks_used;
  497     uint64_t max_migrate_bytes;
  498     int max_migrate_files;
  499     int query_limit;
  500     tier_mode_t mode;
  501     int percent_full;
  502     /* These flags are only used for tier-compact */
  503     gf_boolean_t compact_active;
  504     /* These 3 flags are set to true when the client changes the */
  505     /* compaction mode on the command line. */
  506     /* When they are set, the daemon will trigger compaction as */
  507     /* soon as possible to activate or deactivate compaction. */
  508     /* If in the middle of a compaction, then the switches take */
  509     /* effect on the next compaction, not the current one. */
  510     /* If the user switches it off, we want to avoid needless */
  511     /* compactions. */
  512     /* If the user switches it on, they want to compact as soon */
  513     /* as possible. */
  514     gf_boolean_t compact_mode_switched;
  515     gf_boolean_t compact_mode_switched_hot;
  516     gf_boolean_t compact_mode_switched_cold;
  517     int tier_max_promote_size;
  518     int tier_promote_frequency;
  519     int tier_demote_frequency;
  520     int tier_compact_hot_frequency;
  521     int tier_compact_cold_frequency;
  522     uint64_t st_last_promoted_size;
  523     uint64_t st_last_demoted_size;
  524     struct synctask *pause_synctask;
  525     gf_timer_t *pause_timer;
  526     pthread_mutex_t pause_mutex;
  527     int promote_in_progress;
  528     int demote_in_progress;
  529     /* This Structure is only used in tiering fixlayout */
  530     gf_tier_fix_layout_arg_t tier_fix_layout_arg;
  531     /* Indicates the index of the first queryfile picked
  532      * in the last cycle of promote or demote */
  533     int32_t last_promote_qfile_index;
  534     int32_t last_demote_qfile_index;
  535     tier_pause_state_t pause_state;
  536     char volname[GD_VOLUME_NAME_MAX + 1];
  537 } gf_tier_conf_t;
  538 
  539 typedef struct nodeuuid_info {
  540     char info;   /* Set to 1 is this is my node's uuid*/
  541     uuid_t uuid; /* Store the nodeuuid as well for debugging*/
  542 } nodeuuid_info_t;
  543 
  544 typedef struct subvol_nodeuuids_info {
  545     nodeuuid_info_t *elements;
  546     int count;
  547 } subvol_nodeuuids_info_t;
  548 
  549 struct gf_defrag_info_ {
  550     uint64_t total_files;
  551     uint64_t total_data;
  552     uint64_t num_files_lookedup;
  553     uint64_t total_failures;
  554     uint64_t skipped;
  555     uint64_t num_dirs_processed;
  556     uint64_t size_processed;
  557     gf_lock_t lock;
  558     pthread_t th;
  559     struct rpc_clnt *rpc;
  560     uint32_t connected;
  561     uint32_t is_exiting;
  562     pid_t pid;
  563     int cmd;
  564     inode_t *root_inode;
  565     uuid_t node_uuid;
  566     struct timeval start_time;
  567     uint32_t new_commit_hash;
  568     gf_defrag_status_t defrag_status;
  569     gf_defrag_pattern_list_t *defrag_pattern;
  570     gf_tier_conf_t tier_conf;
  571 
  572     /*Data Tiering params for scanner*/
  573     uint64_t total_files_promoted;
  574     uint64_t total_files_demoted;
  575     int write_freq_threshold;
  576     int read_freq_threshold;
  577 
  578     pthread_cond_t parallel_migration_cond;
  579     pthread_mutex_t dfq_mutex;
  580     pthread_cond_t rebalance_crawler_alarm;
  581     int32_t q_entry_count;
  582     int32_t global_error;
  583     struct dht_container *queue;
  584     int32_t crawl_done;
  585     int32_t abort;
  586     int32_t wakeup_crawler;
  587 
  588     /*Throttle params*/
  589     /*stands for reconfigured thread count*/
  590     int32_t recon_thread_count;
  591     pthread_cond_t df_wakeup_thread;
  592 
  593     /* backpointer to make it easier to write functions for rebalance */
  594     xlator_t *this;
  595 
  596     pthread_cond_t fc_wakeup_cond;
  597     pthread_mutex_t fc_mutex;
  598 
  599     /*stands for current running thread count*/
  600     int32_t current_thread_count;
  601 
  602     gf_boolean_t stats;
  603     /* lock migration flag */
  604     gf_boolean_t lock_migration_enabled;
  605 };
  606 
  607 typedef struct gf_defrag_info_ gf_defrag_info_t;
  608 
  609 struct dht_methods_s {
  610     int32_t (*migration_get_dst_subvol)(xlator_t *this, dht_local_t *local);
  611     int32_t (*migration_other)(xlator_t *this, gf_defrag_info_t *defrag);
  612     int32_t (*migration_needed)(xlator_t *this);
  613     xlator_t *(*layout_search)(xlator_t *this, dht_layout_t *layout,
  614                                const char *name);
  615 };
  616 
  617 typedef struct dht_methods_s dht_methods_t;
  618 
  619 struct dht_conf {
  620     xlator_t **subvolumes;
  621     char *subvolume_status;
  622     int *last_event;
  623     dht_layout_t **file_layouts;
  624     dht_layout_t **dir_layouts;
  625     unsigned int search_unhashed;
  626     int gen;
  627     dht_du_t *du_stats;
  628     double min_free_disk;
  629     double min_free_inodes;
  630     int subvolume_cnt;
  631     int32_t refresh_interval;
  632     gf_lock_t subvolume_lock;
  633     struct timeval last_stat_fetch;
  634     gf_lock_t layout_lock;
  635     dict_t *leaf_to_subvol;
  636     void *private; /* Can be used by wrapper xlators over
  637                       dht */
  638     time_t *subvol_up_time;
  639 
  640     /* to keep track of nodes which are decommissioned */
  641     xlator_t **decommissioned_bricks;
  642     int decommission_in_progress;
  643     int decommission_subvols_cnt;
  644 
  645     /* defrag related */
  646     gf_defrag_info_t *defrag;
  647 
  648     /* Support regex-based name reinterpretation. */
  649     regex_t rsync_regex;
  650     regex_t extra_regex;
  651 
  652     /* Support variable xattr names. */
  653     char *xattr_name;
  654     char *mds_xattr_key;
  655     char *link_xattr_name;
  656     char *commithash_xattr_name;
  657     char *wild_xattr_name;
  658 
  659     dht_methods_t methods;
  660 
  661     struct mem_pool *lock_pool;
  662 
  663     /*local subvol storage for rebalance*/
  664     xlator_t **local_subvols;
  665     subvol_nodeuuids_info_t *local_nodeuuids;
  666     int32_t local_subvols_cnt;
  667 
  668     int dthrottle;
  669 
  670     /* Hard link handle requirement for migration triggered from client*/
  671     synclock_t link_lock;
  672 
  673     /* lock migration */
  674     gf_lock_t lock;
  675 
  676     /* This is the count used as the distribute layout for a directory */
  677     /* Will be a global flag to control the layout spread count */
  678     uint32_t dir_spread_cnt;
  679 
  680     /*
  681      * "Commit hash" for this volume topology.  Changed whenever bricks
  682      * are added or removed.
  683      */
  684     uint32_t vol_commit_hash;
  685 
  686     char vol_uuid[UUID_SIZE + 1];
  687 
  688     char disk_unit;
  689 
  690     gf_boolean_t lock_migration_enabled;
  691 
  692     gf_boolean_t vch_forced;
  693 
  694     gf_boolean_t use_fallocate;
  695 
  696     gf_boolean_t force_migration;
  697 
  698     gf_boolean_t lookup_optimize;
  699 
  700     gf_boolean_t unhashed_sticky_bit;
  701 
  702     gf_boolean_t assert_no_child_down;
  703 
  704     gf_boolean_t use_readdirp;
  705 
  706     /* Request to filter directory entries in readdir request */
  707     gf_boolean_t readdir_optimize;
  708 
  709     gf_boolean_t rsync_regex_valid;
  710 
  711     gf_boolean_t extra_regex_valid;
  712 
  713     /* Support size-weighted rebalancing (heterogeneous bricks). */
  714     gf_boolean_t do_weighting;
  715 
  716     gf_boolean_t randomize_by_gfid;
  717 };
  718 typedef struct dht_conf dht_conf_t;
  719 
  720 struct dht_dfoffset_ctx {
  721     xlator_t *this;
  722     off_t offset;
  723     int32_t readdir_done;
  724 };
  725 typedef struct dht_dfoffset_ctx dht_dfoffset_ctx_t;
  726 
  727 struct dht_disk_layout {
  728     uint32_t cnt;
  729     uint32_t type;
  730     struct {
  731         uint32_t start;
  732         uint32_t stop;
  733     } list[1];
  734 };
  735 typedef struct dht_disk_layout dht_disk_layout_t;
  736 
  737 typedef enum {
  738     GF_DHT_MIGRATE_DATA,
  739     GF_DHT_MIGRATE_DATA_EVEN_IF_LINK_EXISTS,
  740     GF_DHT_MIGRATE_HARDLINK,
  741     GF_DHT_MIGRATE_HARDLINK_IN_PROGRESS
  742 } gf_dht_migrate_data_type_t;
  743 
  744 typedef enum {
  745     GF_DHT_EQUAL_DISTRIBUTION,
  746     GF_DHT_WEIGHTED_DISTRIBUTION
  747 } dht_distribution_type_t;
  748 
  749 struct dir_dfmeta {
  750     gf_dirent_t *equeue;
  751     dht_dfoffset_ctx_t *offset_var;
  752     struct list_head **head;
  753     struct list_head **iterator;
  754     int *fetch_entries;
  755 };
  756 
  757 typedef struct dht_migrate_info {
  758     xlator_t *src_subvol;
  759     xlator_t *dst_subvol;
  760     GF_REF_DECL;
  761 } dht_migrate_info_t;
  762 
  763 typedef struct dht_fd_ctx {
  764     uint64_t opened_on_dst;
  765     GF_REF_DECL;
  766 } dht_fd_ctx_t;
  767 
  768 #define ENTRY_MISSING(op_ret, op_errno) (op_ret == -1 && op_errno == ENOENT)
  769 
  770 #define is_revalidate(loc)                                                     \
  771     (dht_inode_ctx_layout_get((loc)->inode, this, NULL) == 0)
  772 
  773 #define is_last_call(cnt) (cnt == 0)
  774 
  775 #define DHT_MIGRATION_IN_PROGRESS 1
  776 #define DHT_MIGRATION_COMPLETED 2
  777 
  778 #define check_is_linkfile(i, s, x, n)                                          \
  779     (IS_DHT_LINKFILE_MODE(s) && dict_get(x, n))
  780 
  781 #define IS_DHT_MIGRATION_PHASE2(buf)                                           \
  782     (IA_ISREG((buf)->ia_type) &&                                               \
  783      ((st_mode_from_ia((buf)->ia_prot, (buf)->ia_type) & ~S_IFMT) ==           \
  784       DHT_LINKFILE_MODE))
  785 
  786 #define IS_DHT_MIGRATION_PHASE1(buf)                                           \
  787     (IA_ISREG((buf)->ia_type) && ((buf)->ia_prot.sticky == 1) &&               \
  788      ((buf)->ia_prot.sgid == 1))
  789 
  790 #define DHT_STRIP_PHASE1_FLAGS(buf)                                            \
  791     do {                                                                       \
  792         if ((buf) && IS_DHT_MIGRATION_PHASE1(buf)) {                           \
  793             (buf)->ia_prot.sticky = 0;                                         \
  794             (buf)->ia_prot.sgid = 0;                                           \
  795         }                                                                      \
  796     } while (0)
  797 
  798 #define dht_inode_missing(op_errno) (op_errno == ENOENT || op_errno == ESTALE)
  799 
  800 #define check_is_dir(i, s, x) (IA_ISDIR(s->ia_type))
  801 
  802 #define layout_is_sane(layout) ((layout) && (layout->cnt > 0))
  803 
  804 #define we_are_not_migrating(x) ((x) == 1)
  805 
  806 #define DHT_STACK_UNWIND(fop, frame, params...)                                \
  807     do {                                                                       \
  808         dht_local_t *__local = NULL;                                           \
  809         xlator_t *__xl = NULL;                                                 \
  810         if (frame) {                                                           \
  811             __xl = frame->this;                                                \
  812             __local = frame->local;                                            \
  813             frame->local = NULL;                                               \
  814         }                                                                      \
  815         STACK_UNWIND_STRICT(fop, frame, params);                               \
  816         dht_local_wipe(__xl, __local);                                         \
  817     } while (0)
  818 
  819 #define DHT_STACK_DESTROY(frame)                                               \
  820     do {                                                                       \
  821         dht_local_t *__local = NULL;                                           \
  822         xlator_t *__xl = NULL;                                                 \
  823         __xl = frame->this;                                                    \
  824         __local = frame->local;                                                \
  825         frame->local = NULL;                                                   \
  826         STACK_DESTROY(frame->root);                                            \
  827         dht_local_wipe(__xl, __local);                                         \
  828     } while (0)
  829 
  830 #define DHT_UPDATE_TIME(ctx_sec, ctx_nsec, new_sec, new_nsec, post)            \
  831     do {                                                                       \
  832         if (ctx_sec == new_sec)                                                \
  833             new_nsec = max(new_nsec, ctx_nsec);                                \
  834         else if (ctx_sec > new_sec) {                                          \
  835             new_sec = ctx_sec;                                                 \
  836             new_nsec = ctx_nsec;                                               \
  837         }                                                                      \
  838         if (post) {                                                            \
  839             ctx_sec = new_sec;                                                 \
  840             ctx_nsec = new_nsec;                                               \
  841         }                                                                      \
  842     } while (0)
  843 
  844 #define is_greater_time(a, an, b, bn)                                          \
  845     (((a) < (b)) || (((a) == (b)) && ((an) < (bn))))
  846 
  847 #define DHT_MARK_FOP_INTERNAL(xattr)                                           \
  848     do {                                                                       \
  849         int tmp = -1;                                                          \
  850         if (!xattr) {                                                          \
  851             xattr = dict_new();                                                \
  852             if (!xattr)                                                        \
  853                 break;                                                         \
  854         }                                                                      \
  855         tmp = dict_set_str(xattr, GLUSTERFS_INTERNAL_FOP_KEY, "yes");          \
  856         if (tmp) {                                                             \
  857             gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_DICT_SET_FAILED,       \
  858                    "Failed to set dictionary value: key = %s,"                 \
  859                    " path = %s",                                               \
  860                    GLUSTERFS_INTERNAL_FOP_KEY, local->loc.path);               \
  861         }                                                                      \
  862     } while (0)
  863 
  864 dht_layout_t *
  865 dht_layout_new(xlator_t *this, int cnt);
  866 dht_layout_t *
  867 dht_layout_get(xlator_t *this, inode_t *inode);
  868 dht_layout_t *
  869 dht_layout_for_subvol(xlator_t *this, xlator_t *subvol);
  870 xlator_t *
  871 dht_layout_search(xlator_t *this, dht_layout_t *layout, const char *name);
  872 int32_t
  873 dht_migration_get_dst_subvol(xlator_t *this, dht_local_t *local);
  874 int32_t
  875 dht_migration_needed(xlator_t *this);
  876 int
  877 dht_layout_normalize(xlator_t *this, loc_t *loc, dht_layout_t *layout);
  878 void
  879 dht_layout_anomalies(xlator_t *this, loc_t *loc, dht_layout_t *layout,
  880                      uint32_t *holes_p, uint32_t *overlaps_p,
  881                      uint32_t *missing_p, uint32_t *down_p, uint32_t *misc_p,
  882                      uint32_t *no_space_p);
  883 int
  884 dht_layout_dir_mismatch(xlator_t *this, dht_layout_t *layout, xlator_t *subvol,
  885                         loc_t *loc, dict_t *xattr);
  886 xlator_t *
  887 dht_linkfile_subvol(xlator_t *this, inode_t *inode, struct iatt *buf,
  888                     dict_t *xattr);
  889 int
  890 dht_linkfile_unlink(call_frame_t *frame, xlator_t *this, xlator_t *subvol,
  891                     loc_t *loc);
  892 
  893 int
  894 dht_layouts_init(xlator_t *this, dht_conf_t *conf);
  895 int
  896 dht_layout_merge(xlator_t *this, dht_layout_t *layout, xlator_t *subvol,
  897                  int op_ret, int op_errno, dict_t *xattr);
  898 
  899 int
  900 dht_disk_layout_extract(xlator_t *this, dht_layout_t *layout, int pos,
  901                         int32_t **disk_layout_p);
  902 int
  903 dht_disk_layout_extract_for_subvol(xlator_t *this, dht_layout_t *layout,
  904                                    xlator_t *subvol, int32_t **disk_layout_p);
  905 
  906 int
  907 dht_frame_return(call_frame_t *frame);
  908 
  909 int
  910 dht_deitransform(xlator_t *this, uint64_t y, xlator_t **subvol);
  911 
  912 void
  913 dht_local_wipe(xlator_t *this, dht_local_t *local);
  914 dht_local_t *
  915 dht_local_init(call_frame_t *frame, loc_t *loc, fd_t *fd, glusterfs_fop_t fop);
  916 int
  917 dht_iatt_merge(xlator_t *this, struct iatt *to, struct iatt *from);
  918 
  919 xlator_t *
  920 dht_subvol_get_hashed(xlator_t *this, loc_t *loc);
  921 xlator_t *
  922 dht_subvol_get_cached(xlator_t *this, inode_t *inode);
  923 xlator_t *
  924 dht_subvol_next(xlator_t *this, xlator_t *prev);
  925 xlator_t *
  926 dht_subvol_next_available(xlator_t *this, xlator_t *prev);
  927 int
  928 dht_subvol_cnt(xlator_t *this, xlator_t *subvol);
  929 
  930 int
  931 dht_hash_compute(xlator_t *this, int type, const char *name, uint32_t *hash_p);
  932 
  933 int
  934 dht_linkfile_create(call_frame_t *frame, fop_mknod_cbk_t linkfile_cbk,
  935                     xlator_t *this, xlator_t *tovol, xlator_t *fromvol,
  936                     loc_t *loc);
  937 int
  938 dht_lookup_everywhere(call_frame_t *frame, xlator_t *this, loc_t *loc);
  939 int
  940 dht_selfheal_directory(call_frame_t *frame, dht_selfheal_dir_cbk_t cbk,
  941                        loc_t *loc, dht_layout_t *layout);
  942 int
  943 dht_selfheal_new_directory(call_frame_t *frame, dht_selfheal_dir_cbk_t cbk,
  944                            dht_layout_t *layout);
  945 int
  946 dht_selfheal_restore(call_frame_t *frame, dht_selfheal_dir_cbk_t cbk,
  947                      loc_t *loc, dht_layout_t *layout);
  948 void
  949 dht_layout_sort_volname(dht_layout_t *layout);
  950 
  951 int
  952 dht_get_du_info(call_frame_t *frame, xlator_t *this, loc_t *loc);
  953 
  954 gf_boolean_t
  955 dht_is_subvol_filled(xlator_t *this, xlator_t *subvol);
  956 xlator_t *
  957 dht_free_disk_available_subvol(xlator_t *this, xlator_t *subvol,
  958                                dht_local_t *layout);
  959 int
  960 dht_get_du_info_for_subvol(xlator_t *this, int subvol_idx);
  961 
  962 int
  963 dht_layout_preset(xlator_t *this, xlator_t *subvol, inode_t *inode);
  964 int
  965 dht_layout_set(xlator_t *this, inode_t *inode, dht_layout_t *layout);
  966 ;
  967 void
  968 dht_layout_unref(xlator_t *this, dht_layout_t *layout);
  969 dht_layout_t *
  970 dht_layout_ref(xlator_t *this, dht_layout_t *layout);
  971 int
  972 dht_layout_index_for_subvol(dht_layout_t *layout, xlator_t *subvol);
  973 xlator_t *
  974 dht_first_up_subvol(xlator_t *this);
  975 xlator_t *
  976 dht_last_up_subvol(xlator_t *this);
  977 
  978 int
  979 dht_build_child_loc(xlator_t *this, loc_t *child, loc_t *parent, char *name);
  980 
  981 int
  982 dht_filter_loc_subvol_key(xlator_t *this, loc_t *loc, loc_t *new_loc,
  983                           xlator_t **subvol);
  984 
  985 int
  986 dht_rename_cleanup(call_frame_t *frame);
  987 int
  988 dht_rename_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
  989                     int32_t op_ret, int32_t op_errno, inode_t *inode,
  990                     struct iatt *stbuf, struct iatt *preparent,
  991                     struct iatt *postparent, dict_t *xdata);
  992 
  993 int
  994 dht_update_commit_hash_for_layout(call_frame_t *frame);
  995 int
  996 dht_fix_directory_layout(call_frame_t *frame, dht_selfheal_dir_cbk_t dir_cbk,
  997                          dht_layout_t *layout);
  998 
  999 int
 1000 dht_init_subvolumes(xlator_t *this, dht_conf_t *conf);
 1001 
 1002 /* migration/rebalance */
 1003 int
 1004 dht_start_rebalance_task(xlator_t *this, call_frame_t *frame);
 1005 
 1006 int
 1007 dht_rebalance_in_progress_check(xlator_t *this, call_frame_t *frame);
 1008 int
 1009 dht_rebalance_complete_check(xlator_t *this, call_frame_t *frame);
 1010 
 1011 int
 1012 dht_init_local_subvolumes(xlator_t *this, dht_conf_t *conf);
 1013 
 1014 /* FOPS */
 1015 int32_t
 1016 dht_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req);
 1017 
 1018 int32_t
 1019 dht_stat(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata);
 1020 
 1021 int32_t
 1022 dht_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata);
 1023 
 1024 int32_t
 1025 dht_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
 1026              dict_t *xdata);
 1027 
 1028 int32_t
 1029 dht_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
 1030               dict_t *xdata);
 1031 
 1032 int32_t
 1033 dht_access(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask,
 1034            dict_t *xdata);
 1035 
 1036 int32_t
 1037 dht_readlink(call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size,
 1038              dict_t *xdata);
 1039 
 1040 int32_t
 1041 dht_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
 1042           dev_t rdev, mode_t umask, dict_t *xdata);
 1043 
 1044 int32_t
 1045 dht_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
 1046           mode_t umask, dict_t *xdata);
 1047 
 1048 int32_t
 1049 dht_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
 1050            dict_t *xdata);
 1051 
 1052 int32_t
 1053 dht_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
 1054           dict_t *xdata);
 1055 
 1056 int32_t
 1057 dht_symlink(call_frame_t *frame, xlator_t *this, const char *linkpath,
 1058             loc_t *loc, mode_t umask, dict_t *xdata);
 1059 
 1060 int32_t
 1061 dht_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
 1062            dict_t *xdata);
 1063 
 1064 int32_t
 1065 dht_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
 1066          dict_t *xdata);
 1067 
 1068 int32_t
 1069 dht_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
 1070            mode_t mode, mode_t umask, fd_t *fd, dict_t *params);
 1071 
 1072 int32_t
 1073 dht_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
 1074          fd_t *fd, dict_t *xdata);
 1075 
 1076 int32_t
 1077 dht_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
 1078           off_t offset, uint32_t flags, dict_t *xdata);
 1079 
 1080 int32_t
 1081 dht_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector,
 1082            int32_t count, off_t offset, uint32_t flags, struct iobref *iobref,
 1083            dict_t *xdata);
 1084 
 1085 int32_t
 1086 dht_flush(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata);
 1087 
 1088 int32_t
 1089 dht_fsync(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t datasync,
 1090           dict_t *xdata);
 1091 
 1092 int32_t
 1093 dht_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
 1094             dict_t *xdata);
 1095 
 1096 int32_t
 1097 dht_fsyncdir(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t datasync,
 1098              dict_t *xdata);
 1099 
 1100 int32_t
 1101 dht_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata);
 1102 
 1103 int32_t
 1104 dht_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
 1105              int32_t flags, dict_t *xdata);
 1106 
 1107 int32_t
 1108 dht_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name,
 1109              dict_t *xdata);
 1110 
 1111 int32_t
 1112 dht_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
 1113               int32_t flags, dict_t *xdata);
 1114 
 1115 int32_t
 1116 dht_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
 1117               dict_t *xdata);
 1118 
 1119 int32_t
 1120 dht_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
 1121                 const char *name, dict_t *xdata);
 1122 int32_t
 1123 dht_fremovexattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
 1124                  const char *name, dict_t *xdata);
 1125 
 1126 int32_t
 1127 dht_lk(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd,
 1128        struct gf_flock *flock, dict_t *xdata);
 1129 
 1130 int32_t
 1131 dht_lease(call_frame_t *frame, xlator_t *this, loc_t *loc,
 1132           struct gf_lease *lease, dict_t *xdata);
 1133 
 1134 int32_t
 1135 dht_inodelk(call_frame_t *frame, xlator_t *this, const char *volume, loc_t *loc,
 1136             int32_t cmd, struct gf_flock *flock, dict_t *xdata);
 1137 
 1138 int32_t
 1139 dht_finodelk(call_frame_t *frame, xlator_t *this, const char *volume, fd_t *fd,
 1140              int32_t cmd, struct gf_flock *flock, dict_t *xdata);
 1141 
 1142 int32_t
 1143 dht_entrylk(call_frame_t *frame, xlator_t *this, const char *volume, loc_t *loc,
 1144             const char *basename, entrylk_cmd cmd, entrylk_type type,
 1145             dict_t *xdata);
 1146 
 1147 int32_t
 1148 dht_fentrylk(call_frame_t *frame, xlator_t *this, const char *volume, fd_t *fd,
 1149              const char *basename, entrylk_cmd cmd, entrylk_type type,
 1150              dict_t *xdata);
 1151 
 1152 int32_t
 1153 dht_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
 1154             off_t off, dict_t *xdata);
 1155 
 1156 int32_t
 1157 dht_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
 1158              off_t off, dict_t *dict);
 1159 
 1160 int32_t
 1161 dht_xattrop(call_frame_t *frame, xlator_t *this, loc_t *loc,
 1162             gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata);
 1163 
 1164 int32_t
 1165 dht_fxattrop(call_frame_t *frame, xlator_t *this, fd_t *fd,
 1166              gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata);
 1167 
 1168 int32_t
 1169 dht_forget(xlator_t *this, inode_t *inode);
 1170 int32_t
 1171 dht_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc, struct iatt *stbuf,
 1172             int32_t valid, dict_t *xdata);
 1173 int32_t
 1174 dht_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd, struct iatt *stbuf,
 1175              int32_t valid, dict_t *xdata);
 1176 int32_t
 1177 dht_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t mode,
 1178               off_t offset, size_t len, dict_t *xdata);
 1179 int32_t
 1180 dht_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
 1181             size_t len, dict_t *xdata);
 1182 int32_t
 1183 dht_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
 1184              off_t len, dict_t *xdata);
 1185 int32_t
 1186 dht_ipc(call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata);
 1187 
 1188 int
 1189 dht_set_subvol_range(xlator_t *this);
 1190 int32_t
 1191 dht_init(xlator_t *this);
 1192 void
 1193 dht_fini(xlator_t *this);
 1194 int
 1195 dht_reconfigure(xlator_t *this, dict_t *options);
 1196 int32_t
 1197 dht_notify(xlator_t *this, int32_t event, void *data, ...);
 1198 
 1199 /* definitions for nufa/switch */
 1200 int
 1201 dht_revalidate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
 1202                    int op_ret, int op_errno, inode_t *inode, struct iatt *stbuf,
 1203                    dict_t *xattr, struct iatt *postparent);
 1204 int
 1205 dht_lookup_dir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
 1206                    int op_ret, int op_errno, inode_t *inode, struct iatt *stbuf,
 1207                    dict_t *xattr, struct iatt *postparent);
 1208 int
 1209 dht_lookup_linkfile_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
 1210                         int op_ret, int op_errno, inode_t *inode,
 1211                         struct iatt *stbuf, dict_t *xattr,
 1212                         struct iatt *postparent);
 1213 int
 1214 dht_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1215                int op_errno, inode_t *inode, struct iatt *stbuf, dict_t *xattr,
 1216                struct iatt *postparent);
 1217 int
 1218 dht_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1219                int op_errno, fd_t *fd, inode_t *inode, struct iatt *stbuf,
 1220                struct iatt *preparent, struct iatt *postparent, dict_t *xdata);
 1221 int
 1222 dht_newfile_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1223                 int op_errno, inode_t *inode, struct iatt *stbuf,
 1224                 struct iatt *preparent, struct iatt *postparent, dict_t *xdata);
 1225 
 1226 int
 1227 dht_finodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
 1228                  int32_t op_ret, int32_t op_errno, dict_t *xdata);
 1229 
 1230 int
 1231 dht_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1232                  int op_errno, dict_t *xattr, dict_t *xdata);
 1233 
 1234 int
 1235 dht_common_xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
 1236                        int32_t op_ret, int32_t op_errno, dict_t *dict,
 1237                        dict_t *xdata);
 1238 int
 1239 gf_defrag_status_get(dht_conf_t *conf, dict_t *dict);
 1240 
 1241 int
 1242 gf_defrag_stop(dht_conf_t *conf, gf_defrag_status_t status, dict_t *output);
 1243 
 1244 void *
 1245 gf_defrag_start(void *this);
 1246 
 1247 int32_t
 1248 gf_defrag_handle_hardlink(xlator_t *this, loc_t *loc, int *fop_errno);
 1249 int
 1250 dht_migrate_file(xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to,
 1251                  int flag, int *fop_errno);
 1252 int
 1253 dht_inode_ctx_layout_get(inode_t *inode, xlator_t *this,
 1254                          dht_layout_t **layout_int);
 1255 int
 1256 dht_inode_ctx_layout_set(inode_t *inode, xlator_t *this,
 1257                          dht_layout_t *layout_int);
 1258 int
 1259 dht_inode_ctx_time_update(inode_t *inode, xlator_t *this, struct iatt *stat,
 1260                           int32_t update_ctx);
 1261 void
 1262 dht_inode_ctx_time_set(inode_t *inode, xlator_t *this, struct iatt *stat);
 1263 
 1264 int
 1265 dht_inode_ctx_get(inode_t *inode, xlator_t *this, dht_inode_ctx_t **ctx);
 1266 int
 1267 dht_inode_ctx_set(inode_t *inode, xlator_t *this, dht_inode_ctx_t *ctx);
 1268 int
 1269 dht_dir_attr_heal(void *data);
 1270 int
 1271 dht_dir_attr_heal_done(int ret, call_frame_t *sync_frame, void *data);
 1272 xlator_t *
 1273 dht_subvol_with_free_space_inodes(xlator_t *this, xlator_t *subvol,
 1274                                   xlator_t *ignore, dht_layout_t *layout,
 1275                                   uint64_t filesize);
 1276 xlator_t *
 1277 dht_subvol_maxspace_nonzeroinode(xlator_t *this, xlator_t *subvol,
 1278                                  dht_layout_t *layout);
 1279 int
 1280 dht_dir_has_layout(dict_t *xattr, char *name);
 1281 int
 1282 dht_linkfile_attr_heal(call_frame_t *frame, xlator_t *this);
 1283 
 1284 int32_t
 1285 dht_priv_dump(xlator_t *this);
 1286 int32_t
 1287 dht_inodectx_dump(xlator_t *this, inode_t *inode);
 1288 
 1289 gf_boolean_t
 1290 dht_is_subvol_in_layout(dht_layout_t *layout, xlator_t *xlator);
 1291 
 1292 int
 1293 dht_inode_ctx_get_mig_info(xlator_t *this, inode_t *inode,
 1294                            xlator_t **src_subvol, xlator_t **dst_subvol);
 1295 gf_boolean_t
 1296 dht_mig_info_is_invalid(xlator_t *current, xlator_t *src_subvol,
 1297                         xlator_t *dst_subvol);
 1298 
 1299 int
 1300 dht_subvol_status(dht_conf_t *conf, xlator_t *subvol);
 1301 
 1302 void
 1303 dht_log_new_layout_for_dir_selfheal(xlator_t *this, loc_t *loc,
 1304                                     dht_layout_t *layout);
 1305 
 1306 int
 1307 dht_layout_sort(dht_layout_t *layout);
 1308 
 1309 int
 1310 dht_heal_full_path(void *data);
 1311 
 1312 int
 1313 dht_heal_full_path_done(int op_ret, call_frame_t *frame, void *data);
 1314 
 1315 int
 1316 dht_layout_missing_dirs(dht_layout_t *layout);
 1317 
 1318 int
 1319 dht_refresh_layout(call_frame_t *frame);
 1320 
 1321 gf_boolean_t
 1322 dht_is_tier_xlator(xlator_t *this);
 1323 
 1324 int
 1325 dht_build_parent_loc(xlator_t *this, loc_t *parent, loc_t *child,
 1326                      int32_t *op_errno);
 1327 
 1328 int32_t
 1329 dht_set_local_rebalance(xlator_t *this, dht_local_t *local, struct iatt *stbuf,
 1330                         struct iatt *prebuf, struct iatt *postbuf,
 1331                         dict_t *xdata);
 1332 void
 1333 dht_build_root_loc(inode_t *inode, loc_t *loc);
 1334 
 1335 gf_boolean_t
 1336 dht_fd_open_on_dst(xlator_t *this, fd_t *fd, xlator_t *dst);
 1337 
 1338 int32_t
 1339 dht_fd_ctx_destroy(xlator_t *this, fd_t *fd);
 1340 
 1341 int32_t
 1342 dht_release(xlator_t *this, fd_t *fd);
 1343 
 1344 int32_t
 1345 dht_set_fixed_dir_stat(struct iatt *stat);
 1346 
 1347 xlator_t *
 1348 dht_get_lock_subvolume(xlator_t *this, struct gf_flock *lock,
 1349                        dht_local_t *local);
 1350 
 1351 int
 1352 dht_lk_inode_unref(call_frame_t *frame, int32_t op_ret);
 1353 
 1354 int
 1355 dht_fd_ctx_set(xlator_t *this, fd_t *fd, xlator_t *subvol);
 1356 
 1357 int
 1358 dht_check_and_open_fd_on_subvol(xlator_t *this, call_frame_t *frame);
 1359 
 1360 /* FD fop callbacks */
 1361 
 1362 int
 1363 dht_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1364                int op_errno, struct iatt *prebuf, struct iatt *postbuf,
 1365                dict_t *xdata);
 1366 
 1367 int
 1368 dht_flush_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1369               int op_errno, dict_t *xdata);
 1370 
 1371 int
 1372 dht_file_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
 1373                      int op_ret, int op_errno, struct iatt *prebuf,
 1374                      struct iatt *postbuf, dict_t *xdata);
 1375 
 1376 int
 1377 dht_zerofill_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1378                  int op_errno, struct iatt *prebuf, struct iatt *postbuf,
 1379                  dict_t *xdata);
 1380 
 1381 int
 1382 dht_discard_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1383                 int op_errno, struct iatt *prebuf, struct iatt *postbuf,
 1384                 dict_t *xdata);
 1385 
 1386 int
 1387 dht_fallocate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1388                   int op_errno, struct iatt *prebuf, struct iatt *postbuf,
 1389                   dict_t *xdata);
 1390 
 1391 int
 1392 dht_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1393                  int op_errno, struct iatt *prebuf, struct iatt *postbuf,
 1394                  dict_t *xdata);
 1395 
 1396 int
 1397 dht_fsync_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1398               int op_errno, struct iatt *prebuf, struct iatt *postbuf,
 1399               dict_t *xdata);
 1400 
 1401 int
 1402 dht_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1403               int op_errno, struct iovec *vector, int count, struct iatt *stbuf,
 1404               struct iobref *iobref, dict_t *xdata);
 1405 
 1406 int
 1407 dht_file_attr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
 1408                   int op_errno, struct iatt *stbuf, dict_t *xdata);
 1409 
 1410 int
 1411 dht_file_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
 1412                          int op_ret, int op_errno, dict_t *xdata);
 1413 
 1414 int
 1415 dht_file_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
 1416                       int op_ret, int op_errno, dict_t *xdata);
 1417 
 1418 /* All custom xattr heal functions */
 1419 int
 1420 dht_dir_heal_xattrs(void *data);
 1421 
 1422 int
 1423 dht_dir_heal_xattrs_done(int ret, call_frame_t *sync_frame, void *data);
 1424 
 1425 int32_t
 1426 dht_dict_set_array(dict_t *dict, char *key, int32_t value[], int32_t size);
 1427 
 1428 int
 1429 dht_set_user_xattr(dict_t *dict, char *k, data_t *v, void *data);
 1430 
 1431 void
 1432 dht_dir_set_heal_xattr(xlator_t *this, dht_local_t *local, dict_t *dst,
 1433                        dict_t *src, int *uret, int *uflag);
 1434 
 1435 int
 1436 dht_dir_xattr_heal(xlator_t *this, dht_local_t *local);
 1437 
 1438 int
 1439 dht_common_mark_mdsxattr(call_frame_t *frame, int *errst, int flag);
 1440 
 1441 int
 1442 dht_inode_ctx_mdsvol_get(inode_t *inode, xlator_t *this, xlator_t **mdsvol);
 1443 
 1444 int
 1445 dht_selfheal_dir_setattr(call_frame_t *frame, loc_t *loc, struct iatt *stbuf,
 1446                          int32_t valid, dht_layout_t *layout);
 1447 
 1448 /* Abstract out the DHT-IATT-IN-DICT */
 1449 
 1450 void
 1451 dht_selfheal_layout_new_directory(call_frame_t *frame, loc_t *loc,
 1452                                   dht_layout_t *new_layout);
 1453 
 1454 int
 1455 dht_pt_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *key,
 1456                  dict_t *xdata);
 1457 
 1458 int
 1459 dht_pt_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
 1460                 const char *key, dict_t *xdata);
 1461 
 1462 int32_t
 1463 dht_pt_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
 1464              mode_t umask, dict_t *xdata);
 1465 
 1466 int
 1467 dht_pt_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
 1468               dict_t *xdata);
 1469 
 1470 int32_t
 1471 dht_check_remote_fd_failed_error(dht_local_t *local, int op_ret, int op_errno);
 1472 
 1473 int
 1474 dht_common_xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
 1475                        int32_t op_ret, int32_t op_errno, dict_t *dict,
 1476                        dict_t *xdata);
 1477 
 1478 int32_t
 1479 dht_create_lock(call_frame_t *frame, xlator_t *subvol);
 1480 
 1481 int
 1482 dht_set_parent_layout_in_dict(loc_t *loc, xlator_t *this, dht_local_t *local);
 1483 
 1484 #endif /* _DHT_H */