Whamcloud - gitweb
LU-6698 kernel: kernel update RHEL 6.6 [2.6.32-504.23.4.el6]
[fs/lustre-release.git] / lustre / include / lustre_quota.h
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, 2014, Intel Corporation.
25  * Use is subject to license terms.
26  */
27
28 #ifndef _LUSTRE_QUOTA_H
29 #define _LUSTRE_QUOTA_H
30
31 /** \defgroup quota quota
32  *
33  */
34
35 #include <linux/fs.h>
36 #include <linux/quota.h>
37 #include <linux/quotaops.h>
38 #include <dt_object.h>
39 #include <lustre_fid.h>
40 #include <lustre_dlm.h>
41
42 #ifndef MAX_IQ_TIME
43 #define MAX_IQ_TIME  604800     /* (7*24*60*60) 1 week */
44 #endif
45
46 #ifndef MAX_DQ_TIME
47 #define MAX_DQ_TIME  604800     /* (7*24*60*60) 1 week */
48 #endif
49
50 struct lquota_id_info;
51 struct lquota_trans;
52
53 /* Gather all quota record type in an union that can be used to read any records
54  * from disk. All fields of these records must be 64-bit aligned, otherwise the
55  * OSD layer may swab them incorrectly. */
56 union lquota_rec {
57         struct lquota_glb_rec   lqr_glb_rec;
58         struct lquota_slv_rec   lqr_slv_rec;
59         struct lquota_acct_rec  lqr_acct_rec;
60 };
61
62 /* Index features supported by the global index objects
63  * Only used for migration purpose and should be removed once on-disk migration
64  * is no longer needed */
65 extern struct dt_index_features dt_quota_iusr_features;
66 extern struct dt_index_features dt_quota_busr_features;
67 extern struct dt_index_features dt_quota_igrp_features;
68 extern struct dt_index_features dt_quota_bgrp_features;
69
70 /* Name used in the configuration logs to identify the default metadata pool
71  * (composed of all the MDTs, with pool ID 0) and the default data pool (all
72  * the OSTs, with pool ID 0 too). */
73 #define QUOTA_METAPOOL_NAME   "mdt="
74 #define QUOTA_DATAPOOL_NAME   "ost="
75
76 /*
77  * Quota Master Target support
78  */
79
80 /* Request handlers for quota master operations.
81  * This is used by the MDT to pass quota/lock requests to the quota master
82  * target. This won't be needed any more once the QMT is a real target and
83  * does not rely any more on the MDT service threads and namespace. */
84 struct qmt_handlers {
85         /* Handle quotactl request from client. */
86         int (*qmth_quotactl)(const struct lu_env *, struct lu_device *,
87                              struct obd_quotactl *);
88
89         /* Handle dqacq/dqrel request from slave. */
90         int (*qmth_dqacq)(const struct lu_env *, struct lu_device *,
91                           struct ptlrpc_request *);
92
93         /* LDLM intent policy associated with quota locks */
94         int (*qmth_intent_policy)(const struct lu_env *, struct lu_device *,
95                                   struct ptlrpc_request *, struct ldlm_lock **,
96                                   int);
97
98         /* Initialize LVB of ldlm resource associated with quota objects */
99         int (*qmth_lvbo_init)(struct lu_device *, struct ldlm_resource *);
100
101         /* Update LVB of ldlm resource associated with quota objects */
102         int (*qmth_lvbo_update)(struct lu_device *, struct ldlm_resource *,
103                                 struct ptlrpc_request *, int);
104
105         /* Return size of LVB to be packed in ldlm message */
106         int (*qmth_lvbo_size)(struct lu_device *, struct ldlm_lock *);
107
108         /* Fill request buffer with lvb */
109         int (*qmth_lvbo_fill)(struct lu_device *, struct ldlm_lock *, void *,
110                               int);
111
112         /* Free lvb associated with ldlm resource */
113         int (*qmth_lvbo_free)(struct lu_device *, struct ldlm_resource *);
114 };
115
116 /* actual handlers are defined in lustre/quota/qmt_handler.c */
117 extern struct qmt_handlers qmt_hdls;
118
119 /*
120  * Quota enforcement support on slaves
121  */
122
123 struct qsd_instance;
124
125 /* The quota slave feature is implemented under the form of a library.
126  * The API is the following:
127  *
128  * - qsd_init(): the user (mostly the OSD layer) should first allocate a qsd
129  *               instance via qsd_init(). This creates all required structures
130  *               to manage quota enforcement for this target and performs all
131  *               low-level initialization which does not involve any lustre
132  *               object. qsd_init() should typically be called when the OSD
133  *               is being set up.
134  *
135  * - qsd_prepare(): This sets up on-disk objects associated with the quota slave
136  *                  feature and initiates the quota reintegration procedure if
137  *                  needed. qsd_prepare() should typically be called when
138  *                  ->ldo_prepare is invoked.
139  *
140  * - qsd_start(): a qsd instance should be started once recovery is completed
141  *                (i.e. when ->ldo_recovery_complete is called). This is used
142  *                to notify the qsd layer that quota should now be enforced
143  *                again via the qsd_op_begin/end functions. The last step of the
144  *                reintegration prodecure (namely usage reconciliation) will be
145  *                completed during start.
146  *
147  * - qsd_fini(): is used to release a qsd_instance structure allocated with
148  *               qsd_init(). This releases all quota slave objects and frees the
149  *               structures associated with the qsd_instance.
150  *
151  * - qsd_op_begin(): is used to enforce quota, it must be called in the
152  *                   declaration of each operation. qsd_op_end() should then be
153  *                   invoked later once all operations have been completed in
154  *                   order to release/adjust the quota space.
155  *                   Running qsd_op_begin() before qsd_start() isn't fatal and
156  *                   will return success.
157  *                   Once qsd_start() has been run, qsd_op_begin() will block
158  *                   until the reintegration procedure is completed.
159  *
160  * - qsd_op_end(): performs the post operation quota processing. This must be
161  *                 called after the operation transaction stopped.
162  *                 While qsd_op_begin() must be invoked each time a new
163  *                 operation is declared, qsd_op_end() should be called only
164  *                 once for the whole transaction.
165  *
166  * - qsd_op_adjust(): triggers pre-acquire/release if necessary.
167  *
168  * Below are the function prototypes to be used by OSD layer to manage quota
169  * enforcement. Arguments are documented where each function is defined.  */
170
171 struct qsd_instance *qsd_init(const struct lu_env *, char *, struct dt_device *,
172                               struct proc_dir_entry *);
173 int qsd_prepare(const struct lu_env *, struct qsd_instance *);
174 int qsd_start(const struct lu_env *, struct qsd_instance *);
175 void qsd_fini(const struct lu_env *, struct qsd_instance *);
176 int qsd_op_begin(const struct lu_env *, struct qsd_instance *,
177                  struct lquota_trans *, struct lquota_id_info *, int *);
178 void qsd_op_end(const struct lu_env *, struct qsd_instance *,
179                 struct lquota_trans *);
180 void qsd_op_adjust(const struct lu_env *, struct qsd_instance *,
181                    union lquota_id *, int);
182
183 /*
184  * Quota information attached to a transaction
185  */
186
187 struct lquota_entry;
188
189 struct lquota_id_info {
190         /* quota identifier */
191         union lquota_id          lqi_id;
192
193         /* USRQUOTA or GRPQUOTA for now, could be expanded for
194          * directory quota or other types later.  */
195         int                      lqi_type;
196
197         /* inodes or kbytes to be consumed or released, it could
198          * be negative when releasing space.  */
199         long long                lqi_space;
200
201         /* quota slave entry structure associated with this ID */
202         struct lquota_entry     *lqi_qentry;
203
204         /* whether we are reporting blocks or inodes */
205         bool                     lqi_is_blk;
206 };
207
208 /* Since we enforce only inode quota in meta pool (MDTs), and block quota in
209  * data pool (OSTs), there are at most 4 quota ids being enforced in a single
210  * transaction, which is chown transaction:
211  * original uid and gid, new uid and gid.
212  *
213  * This value might need to be revised when directory quota is added.  */
214 #define QUOTA_MAX_TRANSIDS    4
215
216 /* all qids involved in a single transaction */
217 struct lquota_trans {
218         unsigned short          lqt_id_cnt;
219         struct lquota_id_info   lqt_ids[QUOTA_MAX_TRANSIDS];
220 };
221
222 /* flags for quota local enforcement */
223 #define QUOTA_FL_OVER_USRQUOTA  0x01
224 #define QUOTA_FL_OVER_GRPQUOTA  0x02
225 #define QUOTA_FL_SYNC           0x04
226
227 #define IS_LQUOTA_RES(res)                                              \
228         (res->lr_name.name[LUSTRE_RES_ID_SEQ_OFF] == FID_SEQ_QUOTA ||   \
229          res->lr_name.name[LUSTRE_RES_ID_SEQ_OFF] == FID_SEQ_QUOTA_GLB)
230
231 /* helper function used by MDT & OFD to retrieve quota accounting information
232  * on slave */
233 int lquotactl_slv(const struct lu_env *, struct dt_device *,
234                   struct obd_quotactl *);
235 /** @} quota */
236 #endif /* _LUSTRE_QUOTA_H */