summaryrefslogtreecommitdiffstats
path: root/xlators/features/marker/src/marker-quota.h
blob: 39e67e97f5c784d93f5f2f7bf298dee58f2fd800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
   Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
   This file is part of GlusterFS.

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

#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#include "xlator.h"
#include "marker-mem-types.h"
#include "refcount.h"
#include "quota-common-utils.h"

#define QUOTA_XATTR_PREFIX "trusted.glusterfs"
#define QUOTA_DIRTY_KEY "trusted.glusterfs.quota.dirty"

#define CONTRIBUTION  "contri"
#define CONTRI_KEY_MAX 512
#define READDIR_BUF 4096


#define QUOTA_STACK_DESTROY(_frame, _this)              \
        do {                                            \
                quota_local_t *_local = NULL;           \
                _local = _frame->local;                 \
                _frame->local = NULL;                   \
                STACK_DESTROY (_frame->root);           \
                mq_local_unref (_this, _local);         \
        } while (0)


#define QUOTA_ALLOC(var, type, ret)                     \
        do {                                            \
                ret = 0;                                \
                var = GF_CALLOC (sizeof (type), 1,      \
                                 gf_marker_mt_##type);  \
                if (!var) {                             \
                        ret = -1;                       \
                }                                       \
        } while (0);

#define QUOTA_ALLOC_OR_GOTO(var, type, ret, label)      \
        do {                                            \
                var = GF_CALLOC (sizeof (type), 1,      \
                                 gf_marker_mt_##type);  \
                if (!var) {                             \
                        gf_log ("", GF_LOG_ERROR,       \
                                "out of memory");       \
                        ret = -1;                       \
                        goto label;                     \
                }                                       \
                ret = 0;                                \
        } while (0);

#define GET_CONTRI_KEY(var, _gfid, _ret)                                  \
        do {                                                              \
                if (_gfid != NULL) {                                      \
                        char _gfid_unparsed[40];                          \
                        gf_uuid_unparse (_gfid, _gfid_unparsed);          \
                        _ret = snprintf (var, CONTRI_KEY_MAX,             \
                                         QUOTA_XATTR_PREFIX               \
                                         ".%s.%s." CONTRIBUTION, "quota", \
                                         _gfid_unparsed);                 \
                } else {                                                  \
                        _ret = snprintf (var, CONTRI_KEY_MAX,             \
                                         QUOTA_XATTR_PREFIX               \
                                         ".%s.." CONTRIBUTION, "quota");  \
                }                                                         \
        } while (0)

#define QUOTA_SAFE_INCREMENT(lock, var)         \
        do {                                    \
                LOCK (lock);                    \
                var ++;                         \
                UNLOCK (lock);                  \
        } while (0)

struct quota_inode_ctx {
        int64_t                size;
        int64_t                file_count;
        int64_t                dir_count;
        int8_t                 dirty;
        gf_boolean_t           create_status;
        gf_boolean_t           updation_status;
        gf_boolean_t           dirty_status;
        gf_lock_t              lock;
        struct list_head       contribution_head;
};
typedef struct quota_inode_ctx quota_inode_ctx_t;

struct quota_synctask {
        xlator_t      *this;
        loc_t          loc;
        quota_meta_t   contri;
        gf_boolean_t   is_static;
};
typedef struct quota_synctask quota_synctask_t;

struct inode_contribution {
        struct list_head contri_list;
        int64_t          contribution;
        int64_t          file_count;
        int64_t          dir_count;
        uuid_t           gfid;
        gf_lock_t        lock;
        GF_REF_DECL;
};
typedef struct inode_contribution inode_contribution_t;

int32_t
mq_req_xattr (xlator_t *, loc_t *, dict_t *, char *);

int32_t
mq_xattr_state (xlator_t *, loc_t *, dict_t *, struct iatt);

int
mq_initiate_quota_txn (xlator_t *, loc_t *, struct iatt *);

int
mq_initiate_quota_blocking_txn (xlator_t *, loc_t *, struct iatt *);

int
mq_create_xattrs_txn (xlator_t *this, loc_t *loc, struct iatt *buf);

int32_t
mq_reduce_parent_size_txn (xlator_t *, loc_t *, quota_meta_t *);

int32_t
mq_forget (xlator_t *, quota_inode_ctx_t *);
#endif