Whamcloud - gitweb
LU-1842 quota: add quota disk operations
[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 /* Gather all quota record type in an union that can be used to read any records
36  * from disk. All fields of these records must be 64-bit aligned, otherwise the
37  * OSD layer may swab them incorrectly. */
38 union lquota_rec {
39         struct lquota_glb_rec   lqr_glb_rec;
40         struct lquota_slv_rec   lqr_slv_rec;
41         struct lquota_acct_rec  lqr_acct_rec;
42 };
43
44 /* Index features supported by the global index objects
45  * Only used for migration purpose and should be removed once on-disk migration
46  * is no longer needed */
47 extern struct dt_index_features dt_quota_iusr_features;
48 extern struct dt_index_features dt_quota_busr_features;
49 extern struct dt_index_features dt_quota_igrp_features;
50 extern struct dt_index_features dt_quota_bgrp_features;
51
52 /* Name used in the configuration logs to identify the default metadata pool
53  * (composed of all the MDTs, with pool ID 0) and the default data pool (all
54  * the OSTs, with pool ID 0 too). */
55 #define QUOTA_METAPOOL_NAME   "mdt="
56 #define QUOTA_DATAPOOL_NAME   "ost="
57
58 /*
59  * Quota information attached to a transaction
60  */
61
62 struct lquota_entry;
63
64 struct lquota_id_info {
65         /* quota identifier */
66         union lquota_id          lqi_id;
67
68         /* USRQUOTA or GRPQUOTA for now, could be expanded for
69          * directory quota or other types later.  */
70         int                      lqi_type;
71
72         /* inodes or kbytes to be consumed or released, it could
73          * be negative when releasing space.  */
74         long long                lqi_space;
75
76         /* quota slave entry structure associated with this ID */
77         struct lquota_entry     *lqi_qentry;
78
79         /* whether we are reporting blocks or inodes */
80         bool                     lqi_is_blk;
81 };
82
83 /* Since we enforce only inode quota in meta pool (MDTs), and block quota in
84  * data pool (OSTs), there are at most 4 quota ids being enforced in a single
85  * transaction, which is chown transaction:
86  * original uid and gid, new uid and gid.
87  *
88  * This value might need to be revised when directory quota is added.  */
89 #define QUOTA_MAX_TRANSIDS    4
90
91 /* all qids involved in a single transaction */
92 struct lquota_trans {
93         unsigned short         lqt_id_cnt;
94         struct lquota_id_info  lqt_ids[QUOTA_MAX_TRANSIDS];
95 };
96
97 /* flags for quota local enforcement */
98 #define QUOTA_FL_OVER_USRQUOTA  0x01
99 #define QUOTA_FL_OVER_GRPQUOTA  0x02
100 #define QUOTA_FL_SYNC           0x04
101
102 /*
103  * Quota enforcement support on slaves
104  */
105
106 struct qsd_instance;
107
108 /* The quota slave feature is implemented under the form of a library.
109  * The API is the following:
110  *
111  * - qsd_init(): the user (mostly the OSD layer) should first allocate a qsd
112  *               instance via qsd_init(). This sets up on-disk objects
113  *               associated with the quota slave feature and initiates the quota
114  *               reintegration procedure if needed. qsd_init() should typically
115  *               be called when ->ldo_start is invoked.
116  *
117  * - qsd_fini(): is used to release a qsd_instance structure allocated with
118  *               qsd_init(). This releases all quota slave objects and frees the
119  *               structures associated with the qsd_instance.
120  *
121  * Below are the function prototypes to be used by OSD layer to manage quota
122  * enforcement. Arguments are documented where each function is defined.  */
123
124 struct qsd_instance *qsd_init(const struct lu_env *, char *, struct dt_device *,
125                               cfs_proc_dir_entry_t *);
126
127 void qsd_fini(const struct lu_env *, struct qsd_instance *);
128
129 /* helper function used by MDT & OFD to retrieve quota accounting information
130  * on slave */
131 int lquotactl_slv(const struct lu_env *, struct dt_device *,
132                   struct obd_quotactl *);
133
134 /* XXX: dummy qsd_op_begin() & qsd_op_end(), will be replaced with the real
135  *      one once all the enforcement code landed. */
136 static inline int qsd_op_begin(const struct lu_env *env,
137                                struct qsd_instance *qsd,
138                                struct lquota_trans *trans,
139                                struct lquota_id_info *qi,
140                                int *flags)
141 {
142         return 0;
143 }
144
145 static inline void qsd_op_end(const struct lu_env *env,
146                               struct qsd_instance *qsd,
147                               struct lquota_trans *trans)
148 {
149 }
150
151 #ifdef LPROCFS
152 /* dumb procfs handler which always report success, for backward compatibility
153  * purpose */
154 int lprocfs_quota_rd_type_dumb(char *, char **, off_t, int, int *, void *);
155 int lprocfs_quota_wr_type_dumb(struct file *, const char *, unsigned long,
156                                void *);
157 #endif /* LPROCFS */
158 #endif /* _LUSTRE_LQUOTA_H */