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