Whamcloud - gitweb
fa645b833c01372b8eff29adda7db9b0a3183060
[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 int quota_is_on(struct lustre_quota_ctxt *qctxt, struct obd_quotactl *oqctl);
118 int quota_is_off(struct lustre_quota_ctxt *qctxt, struct obd_quotactl *oqctl);
119 void* quota_barrier(struct lustre_quota_ctxt *qctxt,
120                     struct obd_quotactl *oqctl, int isblk);
121 void quota_unbarrier(void *handle);
122 /* quota_master.c */
123 int lustre_dquot_init(void);
124 void lustre_dquot_exit(void);
125 int dqacq_handler(struct obd_device *obd, struct qunit_data *qdata, int opc);
126 int mds_quota_adjust(struct obd_device *obd, const unsigned int qcids[],
127                      const unsigned int qpids[], int rc, int opc);
128 int filter_quota_adjust(struct obd_device *obd, const unsigned int qcids[],
129                         const unsigned int qpids[], int rc, int opc);
130 int init_admin_quotafiles(struct obd_device *obd, struct obd_quotactl *oqctl);
131 int mds_quota_get_version(struct obd_device *obd, lustre_quota_version_t *ver);
132 int mds_quota_invalidate(struct obd_device *obd, struct obd_quotactl *oqctl);
133 int mds_quota_finvalidate(struct obd_device *obd, struct obd_quotactl *oqctl);
134
135 int mds_admin_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl);
136 int mds_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl);
137 int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl);
138 int do_mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl);
139 int mds_admin_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl);
140 int mds_set_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl);
141 int mds_get_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl);
142 int mds_set_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl);
143 int mds_get_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl);
144 int mds_quota_recovery(struct obd_device *obd);
145 int mds_get_obd_quota(struct obd_device *obd, struct obd_quotactl *oqctl);
146 int dquot_create_oqaq(struct lustre_quota_ctxt *qctxt, struct lustre_dquot
147                       *dquot, __u32 ost_num, __u32 mdt_num, int type,
148                       struct quota_adjust_qunit *oqaq);
149 #endif
150
151 /* quota_ctl.c */
152 int mds_quota_ctl(struct obd_device *obd, struct obd_export *exp,
153                   struct obd_quotactl *oqctl);
154 int filter_quota_ctl(struct obd_device *unused, struct obd_export *exp,
155                      struct obd_quotactl *oqctl);
156
157 /* quota_chk.c */
158 int target_quota_check(struct obd_device *obd, struct obd_export *exp,
159                        struct obd_quotactl *oqctl);
160
161 int quota_adjust_slave_lqs(struct quota_adjust_qunit *oqaq, struct
162                           lustre_quota_ctxt *qctxt);
163 #ifdef __KERNEL__
164 int quota_is_set(struct obd_device *obd, const unsigned int id[], int flag);
165 struct lustre_qunit_size *quota_search_lqs(unsigned long long lqs_key,
166                                            struct lustre_quota_ctxt *qctxt,
167                                            int create);
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 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 int lov_quota_adjust_qunit(struct obd_export *exp,
199                            struct quota_adjust_qunit *oqaq,
200                            struct lustre_quota_ctxt *qctxt);
201 int client_quota_ctl(struct obd_device *unused, struct obd_export *exp,
202                      struct obd_quotactl *oqctl);
203 int lmv_quota_ctl(struct obd_device *unused, struct obd_export *exp,
204                   struct obd_quotactl *oqctl);
205 int lov_quota_ctl(struct obd_device *unused, struct obd_export *exp,
206                   struct obd_quotactl *oqctl);
207 int client_quota_check(struct obd_device *unused, struct obd_export *exp,
208                        struct obd_quotactl *oqctl);
209 int lmv_quota_check(struct obd_device *unused, struct obd_export *exp,
210                     struct obd_quotactl *oqctl);
211 int lov_quota_check(struct obd_device *unused, struct obd_export *exp,
212                     struct obd_quotactl *oqctl);
213 int client_quota_poll_check(struct obd_export *exp, struct if_quotacheck *qchk);
214
215 static inline int client_quota_recoverable_error(int rc)
216 {
217         return (rc == -ETIMEDOUT || rc == -EAGAIN);
218 }
219
220 static inline int client_quota_should_resend(int resend, struct client_obd *cli)
221 {
222         return atomic_read(&cli->cl_quota_resends) ?
223                 atomic_read(&cli->cl_quota_resends) > resend : 1;
224 }
225
226 #endif