Whamcloud - gitweb
b5e4b9d180a234d4dff1b33ed54e9082af6e0c78
[fs/lustre-release.git] / lustre / quota / quota_internal.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, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #ifndef __QUOTA_INTERNAL_H
36 #define __QUOTA_INTERNAL_H
37
38 #include <lustre_quota.h>
39
40 #ifdef HAVE_QUOTA_SUPPORT
41
42 /* QUSG covnert bytes to blocks when counting block quota */
43 #define QUSG(count, isblk)      (isblk ? toqb(count) : count)
44
45 /* This flag is set in qc_stat to distinguish if the current getquota
46  * operation is for quota recovery */
47 #define QUOTA_RECOVERING    0x01
48 #define OBD_LQUOTA_DEVICENAME  "lquota"
49
50 #ifdef __KERNEL__
51
52 #define DQUOT_DEBUG(dquot, fmt, arg...)                                       \
53         CDEBUG(D_QUOTA, "refcnt(%u) id(%u) type(%u) off(%llu) flags(%lu) "    \
54                "bhardlimit("LPU64") curspace("LPU64") ihardlimit("LPU64") "   \
55                "curinodes("LPU64"): " fmt, cfs_atomic_read(&dquot->dq_refcnt),\
56                dquot->dq_id, dquot->dq_type, dquot->dq_off,  dquot->dq_flags, \
57                dquot->dq_dqb.dqb_bhardlimit, dquot->dq_dqb.dqb_curspace,      \
58                dquot->dq_dqb.dqb_ihardlimit, dquot->dq_dqb.dqb_curinodes,     \
59                ## arg);                                                       \
60
61 #define QINFO_DEBUG(qinfo, fmt, arg...)                                       \
62         CDEBUG(D_QUOTA, "files (%p/%p) flags(%lu/%lu) blocks(%u/%u) "         \
63                "free_blk(/%u/%u) free_entry(%u/%u): " fmt,                    \
64                qinfo->qi_files[0], qinfo->qi_files[1],                        \
65                qinfo->qi_info[0].dqi_flags, qinfo->qi_info[1].dqi_flags,      \
66                qinfo->qi_info[0].dqi_blocks, qinfo->qi_info[1].dqi_blocks,    \
67                qinfo->qi_info[0].dqi_free_blk, qinfo->qi_info[1].dqi_free_blk,\
68                qinfo->qi_info[0].dqi_free_entry,                              \
69                qinfo->qi_info[1].dqi_free_entry, ## arg);
70
71 #define QDATA_DEBUG(qd, fmt, arg...)                                          \
72         CDEBUG(D_QUOTA, "id(%u) flag(%u) type(%c) isblk(%c) count("LPU64") "  \
73                "qd_qunit("LPU64"): " fmt, qd->qd_id, qd->qd_flags,            \
74                QDATA_IS_GRP(qd) ? 'g' : 'u', QDATA_IS_BLK(qd) ? 'b': 'i',     \
75                qd->qd_count,                                                  \
76                (QDATA_IS_ADJBLK(qd) | QDATA_IS_ADJINO(qd)) ? qd->qd_qunit : 0,\
77                ## arg);
78
79 #define QAQ_DEBUG(qaq, fmt, arg...)                                           \
80         CDEBUG(D_QUOTA, "id(%u) flag(%u) type(%c) bunit("LPU64") "            \
81                "iunit("LPU64"): " fmt, qaq->qaq_id, qaq->qaq_flags,           \
82                QAQ_IS_GRP(qaq) ? 'g': 'u', qaq->qaq_bunit_sz,                 \
83                qaq->qaq_iunit_sz, ## arg);
84
85 #define LQS_DEBUG(lqs, fmt, arg...)                                           \
86         CDEBUG(D_QUOTA, "lqs(%p) id(%u) flag(%lu) type(%c) bunit(%lu) "       \
87                "btune(%lu) iunit(%lu) itune(%lu) lqs_bwrite_pending(%lu) "    \
88                "lqs_iwrite_pending(%lu) ino_rec(%lld) blk_rec(%lld) "         \
89                "refcount(%d): "                                               \
90                fmt, lqs, lqs->lqs_id, lqs->lqs_flags,                         \
91                LQS_IS_GRP(lqs) ? 'g' : 'u',                                   \
92                lqs->lqs_bunit_sz, lqs->lqs_btune_sz, lqs->lqs_iunit_sz,       \
93                lqs->lqs_itune_sz, lqs->lqs_bwrite_pending,                    \
94                lqs->lqs_iwrite_pending, lqs->lqs_ino_rec,                     \
95                lqs->lqs_blk_rec, cfs_atomic_read(&lqs->lqs_refcount), ## arg);
96
97
98 /* quota_context.c */
99 void qunit_cache_cleanup(void);
100 int qunit_cache_init(void);
101 int qctxt_adjust_qunit(struct obd_device *obd, struct lustre_quota_ctxt *qctxt,
102                        const unsigned int id[], __u32 isblk, int wait,
103                        struct obd_trans_info *oti);
104 int qctxt_wait_pending_dqacq(struct lustre_quota_ctxt *qctxt, unsigned int id,
105                              unsigned short type, int isblk);
106 int qctxt_init(struct obd_device *obd, dqacq_handler_t handler);
107 void qctxt_cleanup(struct lustre_quota_ctxt *qctxt, int force);
108 void qslave_start_recovery(struct obd_device *obd,
109                            struct lustre_quota_ctxt *qctxt);
110 int compute_remquota(struct obd_device *obd,
111                      struct lustre_quota_ctxt *qctxt, struct qunit_data *qdata,
112                      int isblk);
113 int check_qm(struct lustre_quota_ctxt *qctxt);
114 void dqacq_interrupt(struct lustre_quota_ctxt *qctxt);
115 int quota_is_on(struct lustre_quota_ctxt *qctxt, struct obd_quotactl *oqctl);
116 int quota_is_off(struct lustre_quota_ctxt *qctxt, struct obd_quotactl *oqctl);
117 void* quota_barrier(struct lustre_quota_ctxt *qctxt,
118                     struct obd_quotactl *oqctl, int isblk);
119 void quota_unbarrier(void *handle);
120 /* quota_master.c */
121 int lustre_dquot_init(void);
122 void lustre_dquot_exit(void);
123 int dqacq_handler(struct obd_device *obd, struct qunit_data *qdata, int opc);
124 int mds_quota_adjust(struct obd_device *obd, const unsigned int qcids[],
125                      const unsigned int qpids[], int rc, int opc);
126 int filter_quota_adjust(struct obd_device *obd, const unsigned int qcids[],
127                         const unsigned int qpids[], int rc, int opc);
128 int init_admin_quotafiles(struct obd_device *obd, struct obd_quotactl *oqctl);
129 int mds_quota_get_version(struct obd_device *obd, lustre_quota_version_t *ver);
130 int mds_quota_invalidate(struct obd_device *obd, struct obd_quotactl *oqctl);
131 int mds_quota_finvalidate(struct obd_device *obd, struct obd_quotactl *oqctl);
132
133 int mds_admin_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl);
134 int mds_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl);
135 int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl);
136 int do_mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl);
137 int mds_admin_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl);
138 int mds_set_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl);
139 int mds_get_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl);
140 int mds_set_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl);
141 int mds_get_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl);
142 int mds_quota_recovery(struct obd_device *obd);
143 int mds_get_obd_quota(struct obd_device *obd, struct obd_quotactl *oqctl);
144 int dquot_create_oqaq(struct lustre_quota_ctxt *qctxt, struct lustre_dquot
145                       *dquot, __u32 ost_num, __u32 mdt_num, int type,
146                       struct quota_adjust_qunit *oqaq);
147 int generic_quota_on(struct obd_device *, struct obd_quotactl *, int);
148 #endif
149
150 /* quota_ctl.c */
151 int mds_quota_ctl(struct obd_device *obd, struct obd_export *exp,
152                   struct obd_quotactl *oqctl);
153 int filter_quota_ctl(struct obd_device *unused, struct obd_export *exp,
154                      struct obd_quotactl *oqctl);
155
156 /* quota_chk.c */
157 int target_quota_check(struct obd_device *obd, struct obd_export *exp,
158                        struct obd_quotactl *oqctl);
159
160 int quota_adjust_slave_lqs(struct quota_adjust_qunit *oqaq, struct
161                           lustre_quota_ctxt *qctxt);
162 #ifdef __KERNEL__
163 int quota_is_set(struct obd_device *obd, const unsigned int id[], int flag);
164 struct lustre_qunit_size *quota_search_lqs(unsigned long long lqs_key,
165                                            struct lustre_quota_ctxt *qctxt,
166                                            int create);
167 void quota_compute_lqs(struct qunit_data *qdata, struct lustre_qunit_size *lqs,
168                        int is_chk, int is_acq);
169
170
171 extern int quote_get_qdata(struct ptlrpc_request *req, struct qunit_data *qdata,
172                            int is_req, int is_exp);
173 extern int quote_copy_qdata(struct ptlrpc_request *req, struct qunit_data *qdata,
174                             int is_req, int is_exp);
175 int filter_quota_adjust_qunit(struct obd_export *exp,
176                               struct quota_adjust_qunit *oqaq,
177                               struct lustre_quota_ctxt *qctxt,
178                               struct ptlrpc_request_set *rqset);
179 int lquota_proc_setup(struct obd_device *obd, int is_master);
180 int lquota_proc_cleanup(struct lustre_quota_ctxt *qctxt);
181 void build_lqs(struct obd_device *obd);
182
183 extern cfs_proc_dir_entry_t *lquota_type_proc_dir;
184 #endif
185
186 #define LQS_BLK_DECREASE 1
187 #define LQS_BLK_INCREASE 2
188 #define LQS_INO_DECREASE 4
189 #define LQS_INO_INCREASE 8
190
191 /* the return status of quota operation */
192 #define QUOTA_REQ_RETURNED 1
193
194 #endif
195 int client_quota_adjust_qunit(struct obd_export *exp,
196                               struct quota_adjust_qunit *oqaq,
197                               struct lustre_quota_ctxt *qctxt,
198                               struct ptlrpc_request_set *set);
199
200 int lov_quota_adjust_qunit(struct obd_export *exp,
201                            struct quota_adjust_qunit *oqaq,
202                            struct lustre_quota_ctxt *qctxt,
203                            struct ptlrpc_request_set *rqset);
204 int client_quota_ctl(struct obd_device *unused, struct obd_export *exp,
205                      struct obd_quotactl *oqctl);
206 int lmv_quota_ctl(struct obd_device *unused, struct obd_export *exp,
207                   struct obd_quotactl *oqctl);
208 int lov_quota_ctl(struct obd_device *unused, struct obd_export *exp,
209                   struct obd_quotactl *oqctl);
210 int client_quota_check(struct obd_device *unused, struct obd_export *exp,
211                        struct obd_quotactl *oqctl);
212 int lmv_quota_check(struct obd_device *unused, struct obd_export *exp,
213                     struct obd_quotactl *oqctl);
214 int lov_quota_check(struct obd_device *unused, struct obd_export *exp,
215                     struct obd_quotactl *oqctl);
216 int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk);
217
218 #endif