Whamcloud - gitweb
LU-1842 quota: setup/shutdown qmt device
[fs/lustre-release.git] / lustre / quota / qmt_handler.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2012 Intel, Inc.
25  * Use is subject to license terms.
26  *
27  * Author: Johann Lombardi <johann.lombardi@intel.com>
28  * Author: Niu    Yawei    <yawei.niu@intel.com>
29  */
30
31 #ifndef EXPORT_SYMTAB
32 # define EXPORT_SYMTAB
33 #endif
34
35 #define DEBUG_SUBSYSTEM S_LQUOTA
36
37 #include <obd_class.h>
38 #include "qmt_internal.h"
39
40 /*
41  * Handle quotactl request.
42  *
43  * \param env   - is the environment passed by the caller
44  * \param ld    - is the lu device associated with the qmt
45  * \param oqctl - is the quotactl request
46  */
47 static int qmt_quotactl(const struct lu_env *env, struct lu_device *ld,
48                         struct obd_quotactl *oqctl)
49 {
50         struct qmt_device       *qmt = lu2qmt_dev(ld);
51         int                      rc = 0;
52         ENTRY;
53
54         LASSERT(qmt != NULL);
55
56         if (oqctl->qc_type >= MAXQUOTAS)
57                 /* invalid quota type */
58                 RETURN(-EINVAL);
59
60         switch (oqctl->qc_cmd) {
61
62         case Q_GETINFO:
63         case Q_SETINFO:
64         case Q_SETQUOTA:
65                 /* XXX: not implemented yet. */
66                 CERROR("quotactl operation %d not implemented yet\n",
67                        oqctl->qc_cmd);
68                 RETURN(-EOPNOTSUPP);
69
70         case Q_GETQUOTA:
71                 /* XXX: return no limit for now, just for testing purpose */
72                 memset(&oqctl->qc_dqblk, 0, sizeof(struct obd_dqblk));
73                 oqctl->qc_dqblk.dqb_valid = QIF_LIMITS;
74                 rc = 0;
75                 break;
76
77         default:
78                 CERROR("%s: unsupported quotactl command: %d\n",
79                        qmt->qmt_svname, oqctl->qc_cmd);
80                 RETURN(-EFAULT);
81         }
82
83         RETURN(rc);
84 }
85
86 /*
87  * Handle quota request from slave.
88  *
89  * \param env  - is the environment passed by the caller
90  * \param ld   - is the lu device associated with the qmt
91  * \param req  - is the quota acquire request
92  */
93 static int qmt_dqacq(const struct lu_env *env, struct lu_device *ld,
94                      struct ptlrpc_request *req)
95 {
96         struct quota_body       *qbody, *repbody;
97         ENTRY;
98
99         qbody = req_capsule_client_get(&req->rq_pill, &RMF_QUOTA_BODY);
100         if (qbody == NULL)
101                 RETURN(err_serious(-EPROTO));
102
103         repbody = req_capsule_server_get(&req->rq_pill, &RMF_QUOTA_BODY);
104         if (repbody == NULL)
105                 RETURN(err_serious(-EFAULT));
106
107         RETURN(0);
108 }
109
110 /* Vector of quota request handlers. This vector is used by the MDT to forward
111  * requests to the quota master. */
112 struct qmt_handlers qmt_hdls = {
113         /* quota request handlers */
114         .qmth_quotactl          = qmt_quotactl,
115         .qmth_dqacq             = qmt_dqacq,
116
117         /* ldlm handlers */
118         .qmth_intent_policy     = qmt_intent_policy,
119         .qmth_lvbo_init         = qmt_lvbo_init,
120         .qmth_lvbo_update       = qmt_lvbo_update,
121         .qmth_lvbo_size         = qmt_lvbo_size,
122         .qmth_lvbo_fill         = qmt_lvbo_fill,
123         .qmth_lvbo_free         = qmt_lvbo_free,
124 };
125 EXPORT_SYMBOL(qmt_hdls);