summaryrefslogtreecommitdiffstats
path: root/xlators/features/quota/src/quotad-helpers.c
blob: fd309911474e320607db320a699b7c254a232db4 (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
/*
   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.
*/

#include "quotad-helpers.h"

quotad_aggregator_state_t *
get_quotad_aggregator_state (xlator_t *this, rpcsvc_request_t *req)
{
        quotad_aggregator_state_t *state         = NULL;
	xlator_t                  *active_subvol = NULL;
        quota_priv_t              *priv          = NULL;

        state = (void *)GF_CALLOC (1, sizeof (*state),
                                   gf_quota_mt_aggregator_state_t);
        if (!state)
                return NULL;

	state->this = THIS;
        priv = this->private;

        LOCK (&priv->lock);
        {
                active_subvol = state->active_subvol = FIRST_CHILD (this);
        }
        UNLOCK (&priv->lock);

        if (active_subvol->itable == NULL)
                active_subvol->itable = inode_table_new (4096, active_subvol);

	state->itable = active_subvol->itable;

        state->pool = this->ctx->pool;

        return state;
}

void
quotad_aggregator_free_state (quotad_aggregator_state_t *state)
{
        if (state->xdata)
                dict_unref (state->xdata);

        GF_FREE (state);
}

call_frame_t *
quotad_aggregator_alloc_frame (rpcsvc_request_t *req)
{
        call_frame_t              *frame = NULL;
        quotad_aggregator_state_t *state = NULL;
        xlator_t                  *this  = NULL;

        GF_VALIDATE_OR_GOTO ("server", req, out);
        GF_VALIDATE_OR_GOTO ("server", req->trans, out);
        GF_VALIDATE_OR_GOTO ("server", req->svc, out);
        GF_VALIDATE_OR_GOTO ("server", req->svc->ctx, out);

        this = req->svc->mydata;

        frame = create_frame (this, req->svc->ctx->pool);
        if (!frame)
                goto out;

        state = get_quotad_aggregator_state (this, req);
        if (!state)
                goto out;

        frame->root->state = state;
        frame->root->unique = 0;

        frame->this = this;
out:
        return frame;
}

call_frame_t *
quotad_aggregator_get_frame_from_req (rpcsvc_request_t *req)
{
        call_frame_t *frame  = NULL;
        client_t     *client = NULL;

        GF_VALIDATE_OR_GOTO ("server", req, out);

        frame = quotad_aggregator_alloc_frame (req);
        if (!frame)
                goto out;

        client = req->trans->xl_private;

        frame->root->op       = req->procnum;

        frame->root->unique   = req->xid;

        frame->root->uid      = req->uid;
        frame->root->gid      = req->gid;
        frame->root->pid      = req->pid;

        gf_client_ref (client);
        frame->root->client   = client;

        frame->root->lk_owner = req->lk_owner;

        frame->local = req;
out:
        return frame;
}