"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/xlators/features/marker/src/marker-quota.h" (16 Sep 2020, 5997 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 "marker-quota.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 #ifndef _MARKER_QUOTA_H
   11 #define _MARKER_QUOTA_H
   12 
   13 #include <glusterfs/xlator.h>
   14 #include "marker-mem-types.h"
   15 #include <glusterfs/refcount.h>
   16 #include <glusterfs/quota-common-utils.h>
   17 #include <glusterfs/call-stub.h>
   18 
   19 #define QUOTA_XATTR_PREFIX "trusted.glusterfs"
   20 #define QUOTA_DIRTY_KEY "trusted.glusterfs.quota.dirty"
   21 
   22 #define CONTRIBUTION "contri"
   23 #define QUOTA_KEY_MAX 512
   24 #define READDIR_BUF 4096
   25 
   26 #define QUOTA_ALLOC(var, type, ret)                                            \
   27     do {                                                                       \
   28         ret = 0;                                                               \
   29         var = GF_CALLOC(sizeof(type), 1, gf_marker_mt_##type);                 \
   30         if (!var) {                                                            \
   31             ret = -1;                                                          \
   32         }                                                                      \
   33     } while (0);
   34 
   35 #define QUOTA_ALLOC_OR_GOTO(var, type, ret, label)                             \
   36     do {                                                                       \
   37         var = GF_CALLOC(sizeof(type), 1, gf_marker_mt_##type);                 \
   38         if (!var) {                                                            \
   39             gf_log("", GF_LOG_ERROR, "out of memory");                         \
   40             ret = -1;                                                          \
   41             goto label;                                                        \
   42         }                                                                      \
   43         ret = 0;                                                               \
   44     } while (0);
   45 
   46 #define GET_QUOTA_KEY(_this, var, key, _ret)                                   \
   47     do {                                                                       \
   48         marker_conf_t *_priv = _this->private;                                 \
   49         if (_priv->version > 0)                                                \
   50             _ret = snprintf(var, QUOTA_KEY_MAX, "%s.%d", key, _priv->version); \
   51         else                                                                   \
   52             _ret = snprintf(var, QUOTA_KEY_MAX, "%s", key);                    \
   53     } while (0)
   54 
   55 #define GET_CONTRI_KEY(_this, var, _gfid, _ret)                                \
   56     do {                                                                       \
   57         char _tmp_var[QUOTA_KEY_MAX] = {                                       \
   58             0,                                                                 \
   59         };                                                                     \
   60         if (_gfid != NULL) {                                                   \
   61             char _gfid_unparsed[40];                                           \
   62             gf_uuid_unparse(_gfid, _gfid_unparsed);                            \
   63             _ret = snprintf(_tmp_var, QUOTA_KEY_MAX,                           \
   64                             QUOTA_XATTR_PREFIX ".%s.%s." CONTRIBUTION,         \
   65                             "quota", _gfid_unparsed);                          \
   66         } else {                                                               \
   67             _ret = snprintf(_tmp_var, QUOTA_KEY_MAX,                           \
   68                             QUOTA_XATTR_PREFIX ".%s.." CONTRIBUTION, "quota"); \
   69         }                                                                      \
   70         GET_QUOTA_KEY(_this, var, _tmp_var, _ret);                             \
   71     } while (0)
   72 
   73 #define GET_SIZE_KEY(_this, var, _ret)                                         \
   74     {                                                                          \
   75         GET_QUOTA_KEY(_this, var, QUOTA_SIZE_KEY, _ret);                       \
   76     }
   77 
   78 #define QUOTA_SAFE_INCREMENT(lock, var)                                        \
   79     do {                                                                       \
   80         LOCK(lock);                                                            \
   81         var++;                                                                 \
   82         UNLOCK(lock);                                                          \
   83     } while (0)
   84 
   85 struct quota_inode_ctx {
   86     int64_t size;
   87     int64_t file_count;
   88     int64_t dir_count;
   89     int8_t dirty;
   90     gf_boolean_t create_status;
   91     gf_boolean_t updation_status;
   92     gf_boolean_t dirty_status;
   93     gf_lock_t lock;
   94     struct list_head contribution_head;
   95 };
   96 typedef struct quota_inode_ctx quota_inode_ctx_t;
   97 
   98 struct quota_synctask {
   99     xlator_t *this;
  100     loc_t loc;
  101     quota_meta_t contri;
  102     gf_boolean_t is_static;
  103     uint32_t ia_nlink;
  104     call_stub_t *stub;
  105 };
  106 typedef struct quota_synctask quota_synctask_t;
  107 
  108 struct inode_contribution {
  109     struct list_head contri_list;
  110     int64_t contribution;
  111     int64_t file_count;
  112     int64_t dir_count;
  113     uuid_t gfid;
  114     gf_lock_t lock;
  115     GF_REF_DECL;
  116 };
  117 typedef struct inode_contribution inode_contribution_t;
  118 
  119 int32_t
  120 mq_req_xattr(xlator_t *, loc_t *, dict_t *, char *, char *);
  121 
  122 int32_t
  123 mq_xattr_state(xlator_t *, loc_t *, dict_t *, struct iatt *);
  124 
  125 int
  126 mq_initiate_quota_txn(xlator_t *, loc_t *, struct iatt *);
  127 
  128 int
  129 mq_initiate_quota_blocking_txn(xlator_t *, loc_t *, struct iatt *);
  130 
  131 int
  132 mq_create_xattrs_txn(xlator_t *this, loc_t *loc, struct iatt *buf);
  133 
  134 int32_t
  135 mq_reduce_parent_size_txn(xlator_t *, loc_t *, quota_meta_t *, uint32_t nlink,
  136                           call_stub_t *stub);
  137 
  138 int32_t
  139 mq_forget(xlator_t *, quota_inode_ctx_t *);
  140 #endif