Whamcloud - gitweb
LU-1818 quota: en/disable quota enforcement via conf_param
[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 /* QUSG covnert bytes to blocks when counting block quota */
41 #define QUSG(count, isblk)      (isblk ? toqb(count) : count)
42
43 /* This flag is set in qc_stat to distinguish if the current getquota
44  * operation is for quota recovery */
45 #define QUOTA_RECOVERING    0x01
46 #define OBD_LQUOTA_DEVICENAME  "lquota"
47
48 #ifdef __KERNEL__
49
50 #define DQUOT_DEBUG(dquot, fmt, arg...)                                       \
51         CDEBUG(D_QUOTA, "refcnt(%u) id(%u) type(%u) off(%llu) flags(%lu) "    \
52                "bhardlimit("LPU64") curspace("LPU64") ihardlimit("LPU64") "   \
53                "curinodes("LPU64"): " fmt, cfs_atomic_read(&dquot->dq_refcnt),\
54                dquot->dq_id, dquot->dq_type, dquot->dq_off,  dquot->dq_flags, \
55                dquot->dq_dqb.dqb_bhardlimit, dquot->dq_dqb.dqb_curspace,      \
56                dquot->dq_dqb.dqb_ihardlimit, dquot->dq_dqb.dqb_curinodes,     \
57                ## arg);                                                       \
58
59 #define QINFO_DEBUG(qinfo, fmt, arg...)                                       \
60         CDEBUG(D_QUOTA, "files (%p/%p) flags(%lu/%lu) blocks(%u/%u) "         \
61                "free_blk(/%u/%u) free_entry(%u/%u): " fmt,                    \
62                qinfo->qi_files[0], qinfo->qi_files[1],                        \
63                qinfo->qi_info[0].dqi_flags, qinfo->qi_info[1].dqi_flags,      \
64                qinfo->qi_info[0].dqi_blocks, qinfo->qi_info[1].dqi_blocks,    \
65                qinfo->qi_info[0].dqi_free_blk, qinfo->qi_info[1].dqi_free_blk,\
66                qinfo->qi_info[0].dqi_free_entry,                              \
67                qinfo->qi_info[1].dqi_free_entry, ## arg);
68
69 #define QDATA_DEBUG(qd, fmt, arg...)                                          \
70         CDEBUG(D_QUOTA, "id(%u) flag(%u) type(%c) isblk(%c) count("LPU64") "  \
71                "qd_qunit("LPU64"): " fmt, qd->qd_id, qd->qd_flags,            \
72                QDATA_IS_GRP(qd) ? 'g' : 'u', QDATA_IS_BLK(qd) ? 'b': 'i',     \
73                qd->qd_count,                                                  \
74                (QDATA_IS_ADJBLK(qd) | QDATA_IS_ADJINO(qd)) ? qd->qd_qunit : 0,\
75                ## arg);
76
77 #define QAQ_DEBUG(qaq, fmt, arg...)                                           \
78         CDEBUG(D_QUOTA, "id(%u) flag(%u) type(%c) bunit("LPU64") "            \
79                "iunit("LPU64"): " fmt, qaq->qaq_id, qaq->qaq_flags,           \
80                QAQ_IS_GRP(qaq) ? 'g': 'u', qaq->qaq_bunit_sz,                 \
81                qaq->qaq_iunit_sz, ## arg);
82
83 #define LQS_DEBUG(lqs, fmt, arg...)                                           \
84         CDEBUG(D_QUOTA, "lqs(%p) id(%u) flag(%lu) type(%c) bunit(%lu) "       \
85                "btune(%lu) iunit(%lu) itune(%lu) lqs_bwrite_pending(%lu) "    \
86                "lqs_iwrite_pending(%lu) ino_rec(%lld) blk_rec(%lld) "         \
87                "refcount(%d): "                                               \
88                fmt, lqs, lqs->lqs_id, lqs->lqs_flags,                         \
89                LQS_IS_GRP(lqs) ? 'g' : 'u',                                   \
90                lqs->lqs_bunit_sz, lqs->lqs_btune_sz, lqs->lqs_iunit_sz,       \
91                lqs->lqs_itune_sz, lqs->lqs_bwrite_pending,                    \
92                lqs->lqs_iwrite_pending, lqs->lqs_ino_rec,                     \
93                lqs->lqs_blk_rec, cfs_atomic_read(&lqs->lqs_refcount), ## arg);
94
95
96 /* quota_context.c */
97 void qunit_cache_cleanup(void);
98 int qunit_cache_init(void);
99 int qctxt_adjust_qunit(struct obd_device *obd, struct lustre_quota_ctxt *qctxt,
100                        const unsigned int id[], __u32 isblk, int wait,
101                        struct obd_trans_info *oti);
102 int qctxt_wait_pending_dqacq(struct lustre_quota_ctxt *qctxt, unsigned int id,
103                              unsigned short type, int isblk);
104 int qctxt_init(struct obd_device *obd, dqacq_handler_t handler);
105 void qctxt_cleanup(struct lustre_quota_ctxt *qctxt, int force);
106 void qslave_start_recovery(struct obd_device *obd,
107                            struct lustre_quota_ctxt *qctxt);
108 int compute_remquota(struct obd_device *obd,
109                      struct lustre_quota_ctxt *qctxt, struct qunit_data *qdata,
110                      int isblk);
111 int check_qm(struct lustre_quota_ctxt *qctxt);
112 void dqacq_interrupt(struct lustre_quota_ctxt *qctxt);
113 int quota_is_on(struct lustre_quota_ctxt *qctxt, struct obd_quotactl *oqctl);
114 int quota_is_off(struct lustre_quota_ctxt *qctxt, struct obd_quotactl *oqctl);
115 void* quota_barrier(struct lustre_quota_ctxt *qctxt,
116                     struct obd_quotactl *oqctl, int isblk);
117 void quota_unbarrier(void *handle);
118 /* quota_master.c */
119 int lustre_dquot_init(void);
120 void lustre_dquot_exit(void);
121 int dqacq_handler(struct obd_device *obd, struct qunit_data *qdata, int opc);
122 int mds_quota_adjust(struct obd_device *obd, const unsigned int qcids[],
123                      const unsigned int qpids[], int rc, int opc);
124 int filter_quota_adjust(struct obd_device *obd, const unsigned int qcids[],
125                         const unsigned int qpids[], int rc, int opc);
126 int init_admin_quotafiles(struct obd_device *obd, struct obd_quotactl *oqctl);
127 int mds_quota_get_version(struct obd_device *obd, lustre_quota_version_t *ver);
128 int mds_quota_invalidate(struct obd_device *obd, struct obd_quotactl *oqctl);
129 int mds_quota_finvalidate(struct obd_device *obd, struct obd_quotactl *oqctl);
130
131 int mds_admin_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl);
132 int mds_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl);
133 int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl);
134 int do_mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl);
135 int mds_admin_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl);
136 int mds_set_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl);
137 int mds_get_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl);
138 int mds_set_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl);
139 int mds_get_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl);
140 int mds_quota_recovery(struct obd_device *obd);
141 int mds_get_obd_quota(struct obd_device *obd, struct obd_quotactl *oqctl);
142 int dquot_create_oqaq(struct lustre_quota_ctxt *qctxt, struct lustre_dquot
143                       *dquot, __u32 ost_num, __u32 mdt_num, int type,
144                       struct quota_adjust_qunit *oqaq);
145 int generic_quota_on(struct obd_device *, struct obd_quotactl *, int);
146 #endif
147
148 /* quota_ctl.c */
149 int mds_quota_ctl(struct obd_device *obd, struct obd_export *exp,
150                   struct obd_quotactl *oqctl);
151 int filter_quota_ctl(struct obd_device *unused, struct obd_export *exp,
152                      struct obd_quotactl *oqctl);
153
154 /* quota_chk.c */
155 int target_quota_check(struct obd_device *obd, struct obd_export *exp,
156                        struct obd_quotactl *oqctl);
157
158 int quota_adjust_slave_lqs(struct quota_adjust_qunit *oqaq, struct
159                           lustre_quota_ctxt *qctxt);
160 #ifdef __KERNEL__
161 int quota_is_set(struct obd_device *obd, const unsigned int id[], int flag);
162 struct lustre_qunit_size *quota_search_lqs(unsigned long long lqs_key,
163                                            struct lustre_quota_ctxt *qctxt,
164                                            int create);
165 void quota_compute_lqs(struct qunit_data *qdata, struct lustre_qunit_size *lqs,
166                        int is_chk, int is_acq);
167
168
169 extern int quote_get_qdata(struct ptlrpc_request *req, struct qunit_data *qdata,
170                            int is_req, int is_exp);
171 extern int quote_copy_qdata(struct ptlrpc_request *req, struct qunit_data *qdata,
172                             int is_req, int is_exp);
173 int filter_quota_adjust_qunit(struct obd_export *exp,
174                               struct quota_adjust_qunit *oqaq,
175                               struct lustre_quota_ctxt *qctxt,
176                               struct ptlrpc_request_set *rqset);
177 int lquota_proc_setup(struct obd_device *obd, int is_master);
178 int lquota_proc_cleanup(struct lustre_quota_ctxt *qctxt);
179 void build_lqs(struct obd_device *obd);
180
181 extern cfs_proc_dir_entry_t *lquota_type_proc_dir;
182 #endif
183
184 #define LQS_BLK_DECREASE 1
185 #define LQS_BLK_INCREASE 2
186 #define LQS_INO_DECREASE 4
187 #define LQS_INO_INCREASE 8
188
189 /* the return status of quota operation */
190 #define QUOTA_REQ_RETURNED 1
191
192 #endif