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