4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
24 * Copyright (c) 2011, 2012, Intel Corporation.
25 * Use is subject to license terms.
28 #ifndef _LUSTRE_QUOTA_H
29 #define _LUSTRE_QUOTA_H
31 /** \defgroup quota quota
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.
44 #include <dt_object.h>
45 #include <lustre_fid.h>
46 #include <lustre_dlm.h>
49 #define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */
53 #define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */
56 struct lquota_id_info;
59 /* Gather all quota record type in an union that can be used to read any records
60 * from disk. All fields of these records must be 64-bit aligned, otherwise the
61 * OSD layer may swab them incorrectly. */
63 struct lquota_glb_rec lqr_glb_rec;
64 struct lquota_slv_rec lqr_slv_rec;
65 struct lquota_acct_rec lqr_acct_rec;
68 /* Index features supported by the global index objects
69 * Only used for migration purpose and should be removed once on-disk migration
70 * is no longer needed */
71 extern struct dt_index_features dt_quota_iusr_features;
72 extern struct dt_index_features dt_quota_busr_features;
73 extern struct dt_index_features dt_quota_igrp_features;
74 extern struct dt_index_features dt_quota_bgrp_features;
76 /* Name used in the configuration logs to identify the default metadata pool
77 * (composed of all the MDTs, with pool ID 0) and the default data pool (all
78 * the OSTs, with pool ID 0 too). */
79 #define QUOTA_METAPOOL_NAME "mdt="
80 #define QUOTA_DATAPOOL_NAME "ost="
83 * Quota Master Target support
86 /* Request handlers for quota master operations.
87 * This is used by the MDT to pass quota/lock requests to the quota master
88 * target. This won't be needed any more once the QMT is a real target and
89 * does not rely any more on the MDT service threads and namespace. */
91 /* Handle quotactl request from client. */
92 int (*qmth_quotactl)(const struct lu_env *, struct lu_device *,
93 struct obd_quotactl *);
95 /* Handle dqacq/dqrel request from slave. */
96 int (*qmth_dqacq)(const struct lu_env *, struct lu_device *,
97 struct ptlrpc_request *);
99 /* LDLM intent policy associated with quota locks */
100 int (*qmth_intent_policy)(const struct lu_env *, struct lu_device *,
101 struct ptlrpc_request *, struct ldlm_lock **,
104 /* Initialize LVB of ldlm resource associated with quota objects */
105 int (*qmth_lvbo_init)(struct lu_device *, struct ldlm_resource *);
107 /* Update LVB of ldlm resource associated with quota objects */
108 int (*qmth_lvbo_update)(struct lu_device *, struct ldlm_resource *,
109 struct ptlrpc_request *, int);
111 /* Return size of LVB to be packed in ldlm message */
112 int (*qmth_lvbo_size)(struct lu_device *, struct ldlm_lock *);
114 /* Fill request buffer with lvb */
115 int (*qmth_lvbo_fill)(struct lu_device *, struct ldlm_lock *, void *,
118 /* Free lvb associated with ldlm resource */
119 int (*qmth_lvbo_free)(struct lu_device *, struct ldlm_resource *);
122 /* actual handlers are defined in lustre/quota/qmt_handler.c */
123 extern struct qmt_handlers qmt_hdls;
126 * Quota enforcement support on slaves
131 /* The quota slave feature is implemented under the form of a library.
132 * The API is the following:
134 * - qsd_init(): the user (mostly the OSD layer) should first allocate a qsd
135 * instance via qsd_init(). This creates all required structures
136 * to manage quota enforcement for this target and performs all
137 * low-level initialization which does not involve any lustre
138 * object. qsd_init() should typically be called when the OSD
141 * - qsd_prepare(): This sets up on-disk objects associated with the quota slave
142 * feature and initiates the quota reintegration procedure if
143 * needed. qsd_prepare() should typically be called when
144 * ->ldo_prepare is invoked.
146 * - qsd_start(): a qsd instance should be started once recovery is completed
147 * (i.e. when ->ldo_recovery_complete is called). This is used
148 * to notify the qsd layer that quota should now be enforced
149 * again via the qsd_op_begin/end functions. The last step of the
150 * reintegration prodecure (namely usage reconciliation) will be
151 * completed during start.
153 * - qsd_fini(): is used to release a qsd_instance structure allocated with
154 * qsd_init(). This releases all quota slave objects and frees the
155 * structures associated with the qsd_instance.
157 * - qsd_op_begin(): is used to enforce quota, it must be called in the
158 * declaration of each operation. qsd_op_end() should then be
159 * invoked later once all operations have been completed in
160 * order to release/adjust the quota space.
161 * Running qsd_op_begin() before qsd_start() isn't fatal and
162 * will return success.
163 * Once qsd_start() has been run, qsd_op_begin() will block
164 * until the reintegration procedure is completed.
166 * - qsd_op_end(): performs the post operation quota processing. This must be
167 * called after the operation transaction stopped.
168 * While qsd_op_begin() must be invoked each time a new
169 * operation is declared, qsd_op_end() should be called only
170 * once for the whole transaction.
172 * - qsd_op_adjust(): triggers pre-acquire/release if necessary.
174 * Below are the function prototypes to be used by OSD layer to manage quota
175 * enforcement. Arguments are documented where each function is defined. */
177 struct qsd_instance *qsd_init(const struct lu_env *, char *, struct dt_device *,
178 cfs_proc_dir_entry_t *);
179 int qsd_prepare(const struct lu_env *, struct qsd_instance *);
180 int qsd_start(const struct lu_env *, struct qsd_instance *);
181 void qsd_fini(const struct lu_env *, struct qsd_instance *);
182 int qsd_op_begin(const struct lu_env *, struct qsd_instance *,
183 struct lquota_trans *, struct lquota_id_info *, int *);
184 void qsd_op_end(const struct lu_env *, struct qsd_instance *,
185 struct lquota_trans *);
186 void qsd_op_adjust(const struct lu_env *, struct qsd_instance *,
187 union lquota_id *, int);
188 /* This is exported for the ldiskfs quota migration only,
189 * see convert_quota_file() */
190 int lquota_disk_write_glb(const struct lu_env *, struct dt_object *,
191 __u64, struct lquota_glb_rec *);
194 * Quota information attached to a transaction
199 struct lquota_id_info {
200 /* quota identifier */
201 union lquota_id lqi_id;
203 /* USRQUOTA or GRPQUOTA for now, could be expanded for
204 * directory quota or other types later. */
207 /* inodes or kbytes to be consumed or released, it could
208 * be negative when releasing space. */
211 /* quota slave entry structure associated with this ID */
212 struct lquota_entry *lqi_qentry;
214 /* whether we are reporting blocks or inodes */
218 /* Since we enforce only inode quota in meta pool (MDTs), and block quota in
219 * data pool (OSTs), there are at most 4 quota ids being enforced in a single
220 * transaction, which is chown transaction:
221 * original uid and gid, new uid and gid.
223 * This value might need to be revised when directory quota is added. */
224 #define QUOTA_MAX_TRANSIDS 4
226 /* all qids involved in a single transaction */
227 struct lquota_trans {
228 unsigned short lqt_id_cnt;
229 struct lquota_id_info lqt_ids[QUOTA_MAX_TRANSIDS];
232 /* flags for quota local enforcement */
233 #define QUOTA_FL_OVER_USRQUOTA 0x01
234 #define QUOTA_FL_OVER_GRPQUOTA 0x02
235 #define QUOTA_FL_SYNC 0x04
237 #define IS_LQUOTA_RES(res) \
238 (res->lr_name.name[LUSTRE_RES_ID_SEQ_OFF] == FID_SEQ_QUOTA || \
239 res->lr_name.name[LUSTRE_RES_ID_SEQ_OFF] == FID_SEQ_QUOTA_GLB)
241 /* helper function used by MDT & OFD to retrieve quota accounting information
243 int lquotactl_slv(const struct lu_env *, struct dt_device *,
244 struct obd_quotactl *);
246 #endif /* _LUSTRE_QUOTA_H */