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