glusterfs

Форк
0
245 строк · 5.3 Кб
1
/*
2
   Copyright (c) 2013 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
#include "quota.h"
11
#include "quotad-aggregator.h"
12

13
int
14
qd_notify(xlator_t *this, int32_t event, void *data, ...)
15
{
16
    switch (event) {
17
        case GF_EVENT_PARENT_UP:
18
            quotad_aggregator_init(this);
19
    }
20

21
    default_notify(this, event, data);
22
    return 0;
23
}
24

25
int32_t
26
mem_acct_init(xlator_t *this)
27
{
28
    int ret = -1;
29

30
    if (!this)
31
        return ret;
32

33
    ret = xlator_mem_acct_init(this, gf_quota_mt_end);
34

35
    if (0 != ret) {
36
        gf_log(this->name, GF_LOG_WARNING,
37
               "Memory accounting "
38
               "init failed");
39
        return ret;
40
    }
41

42
    return ret;
43
}
44

45
int32_t
46
qd_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
47
              int32_t op_errno, inode_t *inode, struct iatt *buf, dict_t *xdata,
48
              struct iatt *postparent)
49
{
50
    quotad_aggregator_lookup_cbk_t lookup_cbk = NULL;
51
    gfs3_lookup_rsp rsp = {
52
        0,
53
    };
54

55
    lookup_cbk = cookie;
56

57
    rsp.op_ret = op_ret;
58
    rsp.op_errno = op_errno;
59

60
    gf_stat_from_iatt(&rsp.postparent, postparent);
61

62
    GF_PROTOCOL_DICT_SERIALIZE(this, xdata, (&rsp.xdata.xdata_val),
63
                               rsp.xdata.xdata_len, rsp.op_errno, out);
64

65
    gf_stat_from_iatt(&rsp.stat, buf);
66

67
out:
68
    lookup_cbk(this, frame, &rsp);
69

70
    GF_FREE(rsp.xdata.xdata_val);
71

72
    inode_unref(inode);
73

74
    return 0;
75
}
76

77
xlator_t *
78
qd_find_subvol(xlator_t *this, char *volume_uuid)
79
{
80
    xlator_list_t *child = NULL;
81
    xlator_t *subvol = NULL;
82
    char key[1024];
83
    int keylen = 0;
84
    char *optstr = NULL;
85

86
    if (!this || !volume_uuid)
87
        goto out;
88

89
    for (child = this->children; child; child = child->next) {
90
        keylen = snprintf(key, sizeof(key), "%s.volume-id",
91
                          child->xlator->name);
92
        if (dict_get_strn(this->options, key, keylen, &optstr) < 0)
93
            continue;
94

95
        if (strcmp(optstr, volume_uuid) == 0) {
96
            subvol = child->xlator;
97
            break;
98
        }
99
    }
100

101
out:
102
    return subvol;
103
}
104

105
int
106
qd_nameless_lookup(xlator_t *this, call_frame_t *frame, char *gfid,
107
                   dict_t *xdata, char *volume_uuid,
108
                   quotad_aggregator_lookup_cbk_t lookup_cbk)
109
{
110
    gfs3_lookup_rsp rsp = {
111
        0,
112
    };
113
    int op_errno = 0, ret = -1;
114
    loc_t loc = {
115
        0,
116
    };
117
    quotad_aggregator_state_t *state = NULL;
118
    xlator_t *subvol = NULL;
119

120
    state = frame->root->state;
121

122
    frame->root->op = GF_FOP_LOOKUP;
123

124
    loc.inode = inode_new(state->itable);
125
    if (loc.inode == NULL) {
126
        op_errno = ENOMEM;
127
        goto out;
128
    }
129

130
    memcpy(loc.gfid, gfid, 16);
131

132
    ret = dict_set_int8(xdata, QUOTA_READ_ONLY_KEY, 1);
133
    if (ret < 0) {
134
        gf_msg(this->name, GF_LOG_WARNING, ENOMEM, Q_MSG_ENOMEM,
135
               "dict set failed");
136
        ret = -ENOMEM;
137
        goto out;
138
    }
139

140
    subvol = qd_find_subvol(this, volume_uuid);
141
    if (subvol == NULL) {
142
        op_errno = EINVAL;
143
        goto out;
144
    }
145

146
    STACK_WIND_COOKIE(frame, qd_lookup_cbk, lookup_cbk, subvol,
147
                      subvol->fops->lookup, &loc, xdata);
148
    return 0;
149

150
out:
151
    rsp.op_ret = -1;
152
    rsp.op_errno = op_errno;
153

154
    lookup_cbk(this, frame, &rsp);
155

156
    inode_unref(loc.inode);
157
    return 0;
158
}
159

160
int
161
qd_reconfigure(xlator_t *this, dict_t *options)
162
{
163
    /* As of now quotad is restarted upon alteration of volfile */
164
    return 0;
165
}
166

167
void
168
qd_fini(xlator_t *this)
169
{
170
    quota_priv_t *priv = NULL;
171

172
    if (this == NULL || this->private == NULL)
173
        goto out;
174

175
    priv = this->private;
176

177
    if (priv->rpcsvc) {
178
        GF_FREE(priv->rpcsvc);
179
        priv->rpcsvc = NULL;
180
    }
181

182
    GF_FREE(priv);
183

184
out:
185
    return;
186
}
187

188
int32_t
189
qd_init(xlator_t *this)
190
{
191
    int32_t ret = -1;
192
    quota_priv_t *priv = NULL;
193

194
    if (NULL == this->children) {
195
        gf_log(this->name, GF_LOG_ERROR,
196
               "FATAL: quota (%s) not configured for min of 1 child",
197
               this->name);
198
        ret = -1;
199
        goto err;
200
    }
201

202
    QUOTA_ALLOC_OR_GOTO(priv, quota_priv_t, err);
203
    LOCK_INIT(&priv->lock);
204

205
    this->private = priv;
206

207
    ret = 0;
208
err:
209
    if (ret) {
210
        GF_FREE(priv);
211
    }
212
    return ret;
213
}
214

215
struct xlator_fops fops = {};
216

217
struct xlator_cbks cbks = {};
218

219
struct volume_options options[] = {
220
    {.key = {"transport-type"},
221
     .value = {"rpc", "rpc-over-rdma", "tcp", "socket", "ib-verbs", "unix",
222
               "ib-sdp", "tcp/server", "ib-verbs/server", "rdma",
223
               "rdma*([ \t]),*([ \t])socket", "rdma*([ \t]),*([ \t])tcp",
224
               "tcp*([ \t]),*([ \t])rdma", "socket*([ \t]),*([ \t])rdma"},
225
     .type = GF_OPTION_TYPE_STR},
226
    {
227
        .key = {"transport.*"},
228
        .type = GF_OPTION_TYPE_ANY,
229
    },
230
    {.key = {NULL}},
231
};
232

233
xlator_api_t xlator_api = {
234
    .init = qd_init,
235
    .fini = qd_fini,
236
    .reconfigure = qd_reconfigure,
237
    .notify = qd_notify,
238
    .mem_acct_init = mem_acct_init,
239
    .op_version = {1},
240
    .fops = &fops,
241
    .cbks = &cbks,
242
    .options = options,
243
    .identifier = "quotad",
244
    .category = GF_MAINTAINED,
245
};
246

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.