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