/* Copyright (c) 2008-2012 Red Hat, Inc. This file is part of GlusterFS. This file is licensed to you under your choice of the GNU Lesser General Public License, version 3 or any later version (LGPLv3 or later), or the GNU General Public License, version 2 (GPLv2), in all cases as published by the Free Software Foundation. */ #ifndef _CONFIG_H #define _CONFIG_H #include "config.h" #endif #include "xlator.h" #include "call-stub.h" #include "defaults.h" #include "byte-order.h" #include "common-utils.h" #include "quota-mem-types.h" #define QUOTA_XATTR_PREFIX "trusted." #define DIRTY "dirty" #define SIZE "size" #define CONTRIBUTION "contri" #define VAL_LENGTH 8 #define READDIR_BUF 4096 #define QUOTA_UPDATE_USAGE_KEY "quota-update-usage" #define QUOTA_LIMIT_KEY "trusted.glusterfs.quota.limit-set" #define QUOTA_WIND_IF_DISABLED(quota_on, frame, this, fop, params ...) \ do { \ if (!quota_on) { \ STACK_WIND_TAIL (frame, FIRST_CHILD(this), \ FIRST_CHILD(this)->fops->fop, \ params); \ return 0; \ } \ } while (0) #define DID_REACH_LIMIT(lim, prev_size, cur_size) \ ((cur_size) >= (lim) && (prev_size) < (lim)) #define QUOTA_SAFE_INCREMENT(lock, var) \ do { \ LOCK (lock); \ var ++; \ UNLOCK (lock); \ } while (0) #define QUOTA_SAFE_DECREMENT(lock, var) \ do { \ LOCK (lock); \ var --; \ UNLOCK (lock); \ } while (0) #define QUOTA_ALLOC_OR_GOTO(var, type, label) \ do { \ var = GF_CALLOC (sizeof (type), 1, \ gf_quota_mt_##type); \ if (!var) { \ gf_log ("", GF_LOG_ERROR, \ "out of memory"); \ ret = -1; \ goto label; \ } \ } while (0); #define QUOTA_STACK_UNWIND(fop, frame, params...) \ do { \ quota_local_t *_local = NULL; \ xlator_t *_this = NULL; \ if (frame) { \ _local = frame->local; \ _this = frame->this; \ frame->local = NULL; \ } \ STACK_UNWIND_STRICT (fop, frame, params); \ quota_local_cleanup (_this, _local); \ } while (0) #define QUOTA_FREE_CONTRIBUTION_NODE(_contribution) \ do { \ list_del (&_contribution->contri_list); \ GF_FREE (_contribution); \ } while (0) #define GET_CONTRI_KEY(var, _vol_name, _gfid, _ret) \ do { \ char _gfid_unparsed[40]; \ uuid_unparse (_gfid, _gfid_unparsed); \ _ret = gf_asprintf (var, QUOTA_XATTR_PREFIX \ "%s.%s." CONTRIBUTION, \ _vol_name, _gfid_unparsed); \ } while (0) #define GET_CONTRI_KEY_OR_GOTO(var, _vol_name, _gfid, label) \ do { \ GET_CONTRI_KEY(var, _vol_name, _gfid, ret); \ if (ret == -1) \ goto label; \ } while (0) #define GET_DIRTY_KEY_OR_GOTO(var, _vol_name, label) \ do { \ ret = gf_asprintf (var, QUOTA_XATTR_PREFIX \ "%s." DIRTY, _vol_name); \ if (ret == -1) \ goto label; \ } while (0) struct quota_dentry { char *name; uuid_t par; struct list_head next; }; typedef struct quota_dentry quota_dentry_t; struct quota_inode_ctx { int64_t size; int64_t hard_lim; int64_t soft_lim; struct iatt buf; struct list_head parents; struct timeval tv; struct timeval prev_log; gf_lock_t lock; }; typedef struct quota_inode_ctx quota_inode_ctx_t; struct quota_local { gf_lock_t lock; uint32_t validate_count; uint32_t link_count; loc_t loc; loc_t oldloc; loc_t newloc; loc_t validate_loc; int64_t delta; int32_t op_ret; int32_t op_errno; int64_t size; char just_validated; inode_t *inode; call_stub_t *stub; }; typedef struct quota_local quota_local_t; struct qd_vols_conf { char *name; inode_table_t *itable; uint32_t log_timeout; gf_boolean_t threads_status; double default_soft_lim; gf_lock_t lock; loc_t root_loc; uint32_t soft_timeout; uint32_t hard_timeout; struct list_head limit_head; call_frame_t *frame; }; typedef struct qd_vols_conf qd_vols_conf_t; struct quota_priv { double default_soft_lim; uint32_t log_timeout; uint32_t soft_timeout; uint32_t hard_timeout; gf_boolean_t quota_on; gf_boolean_t consider_statfs; qd_vols_conf_t **qd_vols_conf; gf_lock_t lock; }; typedef struct quota_priv quota_priv_t; struct limits { struct list_head limit_list; char *path; int64_t value; uuid_t gfid; int64_t prev_size; struct timeval prev_log_tv; int64_t hard_lim; int64_t soft_lim; struct timeval expire; uint32_t timeout; }; typedef struct limits limits_t;