blob: e38ae53f3529b08b20f5597dc5cd3b25881ad864 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Definitions for diskquota-operations. When diskquota is configured these
3 * macros expand to the right source-code.
4 *
5 * Author: Marco van Wieringen <mvw@planets.elm.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#ifndef _LINUX_QUOTAOPS_
8#define _LINUX_QUOTAOPS_
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/fs.h>
11
Eric Sandeen56246f92010-05-16 09:00:00 -040012#define DQUOT_SPACE_WARN 0x1
13#define DQUOT_SPACE_RESERVE 0x2
Eric Sandeen0e058422010-05-16 10:00:00 -040014#define DQUOT_SPACE_NOFAIL 0x4
Eric Sandeen56246f92010-05-16 09:00:00 -040015
Jan Kara03b06342008-07-25 01:46:52 -070016static inline struct quota_info *sb_dqopt(struct super_block *sb)
17{
18 return &sb->s_dquot;
19}
Jan Kara74abb982008-07-25 01:46:51 -070020
Dmitry Monakhov12755622010-04-08 22:04:20 +040021/* i_mutex must being held */
22static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
23{
24 return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
25 (ia->ia_valid & ATTR_UID && ia->ia_uid != inode->i_uid) ||
26 (ia->ia_valid & ATTR_GID && ia->ia_gid != inode->i_gid);
27}
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#if defined(CONFIG_QUOTA)
30
31/*
32 * declaration of quota_function calls in kernel.
33 */
Dmitry Monakhovc4690702010-02-09 17:53:36 +010034void inode_add_rsv_space(struct inode *inode, qsize_t number);
35void inode_claim_rsv_space(struct inode *inode, qsize_t number);
36void inode_sub_rsv_space(struct inode *inode, qsize_t number);
37
Christoph Hellwig871a2932010-03-03 09:05:07 -050038void dquot_initialize(struct inode *inode);
Christoph Hellwig9f754752010-03-03 09:05:05 -050039void dquot_drop(struct inode *inode);
Jan Kara3d9ea252008-10-10 16:12:23 +020040struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
41void dqput(struct dquot *dquot);
Jan Kara12c77522008-10-20 17:05:00 +020042int dquot_scan_active(struct super_block *sb,
43 int (*fn)(struct dquot *dquot, unsigned long priv),
44 unsigned long priv);
Jan Kara7d9056b2008-11-25 15:31:32 +010045struct dquot *dquot_alloc(struct super_block *sb, int type);
46void dquot_destroy(struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Eric Sandeen56246f92010-05-16 09:00:00 -040048int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags);
49void __dquot_free_space(struct inode *inode, qsize_t number, int flags);
Christoph Hellwig5dd40562010-03-03 09:05:00 -050050
Christoph Hellwig63936dd2010-03-03 09:05:01 -050051int dquot_alloc_inode(const struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Christoph Hellwig5dd40562010-03-03 09:05:00 -050053int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
Christoph Hellwig63936dd2010-03-03 09:05:01 -050054void dquot_free_inode(const struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Jan Karab85f4b82008-07-25 01:46:50 -070056int dquot_commit(struct dquot *dquot);
57int dquot_acquire(struct dquot *dquot);
58int dquot_release(struct dquot *dquot);
59int dquot_commit_info(struct super_block *sb, int type);
60int dquot_mark_dquot_dirty(struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Christoph Hellwig907f4552010-03-03 09:05:06 -050062int dquot_file_open(struct inode *inode, struct file *file);
63
Jan Karab85f4b82008-07-25 01:46:50 -070064int vfs_quota_on(struct super_block *sb, int type, int format_id,
65 char *path, int remount);
Jan Karaf55abc02008-08-20 17:50:32 +020066int vfs_quota_enable(struct inode *inode, int type, int format_id,
67 unsigned int flags);
Al Viro77e69da2008-08-01 04:29:18 -040068int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
69 struct path *path);
Jan Karab85f4b82008-07-25 01:46:50 -070070int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
71 int format_id, int type);
72int vfs_quota_off(struct super_block *sb, int type, int remount);
Jan Karaf55abc02008-08-20 17:50:32 +020073int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
Christoph Hellwig5fb324a2010-02-16 03:44:52 -050074int vfs_quota_sync(struct super_block *sb, int type, int wait);
Jan Karab85f4b82008-07-25 01:46:50 -070075int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
76int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -040077int vfs_get_dqblk(struct super_block *sb, int type, qid_t id,
78 struct fs_disk_quota *di);
Christoph Hellwigc472b432010-05-06 17:05:17 -040079int vfs_set_dqblk(struct super_block *sb, int type, qid_t id,
80 struct fs_disk_quota *di);
Jan Karab85f4b82008-07-25 01:46:50 -070081
Jan Karabc8e5f02010-05-13 19:58:50 +020082int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
Christoph Hellwigb43fa822010-03-03 09:05:03 -050083int dquot_transfer(struct inode *inode, struct iattr *iattr);
Jan Karab85f4b82008-07-25 01:46:50 -070084int vfs_dq_quota_on_remount(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Jan Kara03b06342008-07-25 01:46:52 -070086static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
87{
88 return sb_dqopt(sb)->info + type;
89}
Jan Kara74abb982008-07-25 01:46:51 -070090
91/*
92 * Functions for checking status of quota
93 */
94
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +030095static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -070096{
Jan Karaf55abc02008-08-20 17:50:32 +020097 return sb_dqopt(sb)->flags &
98 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
Jan Kara03b06342008-07-25 01:46:52 -070099}
Jan Kara74abb982008-07-25 01:46:51 -0700100
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300101static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700102{
Jan Karaf55abc02008-08-20 17:50:32 +0200103 return sb_dqopt(sb)->flags &
104 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
Jan Kara03b06342008-07-25 01:46:52 -0700105}
Jan Kara74abb982008-07-25 01:46:51 -0700106
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300107static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700108{
Jan Karaf55abc02008-08-20 17:50:32 +0200109 return sb_dqopt(sb)->flags &
110 dquot_state_flag(DQUOT_SUSPENDED, type);
Jan Kara03b06342008-07-25 01:46:52 -0700111}
Jan Kara74abb982008-07-25 01:46:51 -0700112
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300113static inline unsigned sb_any_quota_suspended(struct super_block *sb)
Jan Kara03b06342008-07-25 01:46:52 -0700114{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300115 unsigned type, tmsk = 0;
116 for (type = 0; type < MAXQUOTAS; type++)
117 tmsk |= sb_has_quota_suspended(sb, type) << type;
118 return tmsk;
Jan Kara03b06342008-07-25 01:46:52 -0700119}
Jan Kara74abb982008-07-25 01:46:51 -0700120
Jan Karaf55abc02008-08-20 17:50:32 +0200121/* Does kernel know about any quota information for given sb + type? */
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300122static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200123{
124 /* Currently if anything is on, then quota usage is on as well */
125 return sb_has_quota_usage_enabled(sb, type);
126}
127
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300128static inline unsigned sb_any_quota_loaded(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200129{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300130 unsigned type, tmsk = 0;
131 for (type = 0; type < MAXQUOTAS; type++)
132 tmsk |= sb_has_quota_loaded(sb, type) << type;
133 return tmsk;
Jan Karaf55abc02008-08-20 17:50:32 +0200134}
135
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300136static inline bool sb_has_quota_active(struct super_block *sb, int type)
Jan Karaf55abc02008-08-20 17:50:32 +0200137{
138 return sb_has_quota_loaded(sb, type) &&
139 !sb_has_quota_suspended(sb, type);
140}
141
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300142static inline unsigned sb_any_quota_active(struct super_block *sb)
Jan Karaf55abc02008-08-20 17:50:32 +0200143{
Dmitry Monakhovad1e6e82010-02-16 08:31:49 +0300144 return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
Jan Karaf55abc02008-08-20 17:50:32 +0200145}
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147/*
148 * Operations supported for diskquotas.
149 */
Alexey Dobriyan61e225d2009-09-21 17:01:08 -0700150extern const struct dquot_operations dquot_operations;
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700151extern const struct quotactl_ops vfs_quotactl_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153#define sb_dquot_ops (&dquot_operations)
154#define sb_quotactl_ops (&vfs_quotactl_ops)
155
Christoph Hellwig850b2012009-04-27 16:43:54 +0200156/* Cannot be called inside a transaction */
Jan Karab85f4b82008-07-25 01:46:50 -0700157static inline int vfs_dq_off(struct super_block *sb, int remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 int ret = -ENOSYS;
160
Jan Kara0ff5af82008-04-28 02:14:33 -0700161 if (sb->s_qcop && sb->s_qcop->quota_off)
162 ret = sb->s_qcop->quota_off(sb, -1, remount);
163 return ret;
164}
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#else
167
Jan Karaf55abc02008-08-20 17:50:32 +0200168static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700169{
170 return 0;
171}
172
Jan Karaf55abc02008-08-20 17:50:32 +0200173static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
Jan Kara03b06342008-07-25 01:46:52 -0700174{
175 return 0;
176}
177
178static inline int sb_has_quota_suspended(struct super_block *sb, int type)
179{
180 return 0;
181}
182
183static inline int sb_any_quota_suspended(struct super_block *sb)
184{
185 return 0;
186}
Jan Kara74abb982008-07-25 01:46:51 -0700187
Jan Karaf55abc02008-08-20 17:50:32 +0200188/* Does kernel know about any quota information for given sb + type? */
189static inline int sb_has_quota_loaded(struct super_block *sb, int type)
190{
191 return 0;
192}
193
194static inline int sb_any_quota_loaded(struct super_block *sb)
195{
196 return 0;
197}
198
199static inline int sb_has_quota_active(struct super_block *sb, int type)
200{
201 return 0;
202}
203
204static inline int sb_any_quota_active(struct super_block *sb)
205{
206 return 0;
207}
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/*
210 * NO-OP when quota not configured.
211 */
212#define sb_dquot_ops (NULL)
213#define sb_quotactl_ops (NULL)
Andrew Morton50f8c372008-04-28 02:14:35 -0700214
Christoph Hellwig871a2932010-03-03 09:05:07 -0500215static inline void dquot_initialize(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700216{
217}
218
Christoph Hellwig9f754752010-03-03 09:05:05 -0500219static inline void dquot_drop(struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700220{
221}
222
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500223static inline int dquot_alloc_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700224{
225 return 0;
226}
227
Christoph Hellwig63936dd2010-03-03 09:05:01 -0500228static inline void dquot_free_inode(const struct inode *inode)
Andrew Morton50f8c372008-04-28 02:14:35 -0700229{
230}
231
Jan Karab85f4b82008-07-25 01:46:50 -0700232static inline int vfs_dq_off(struct super_block *sb, int remount)
Andrew Morton50f8c372008-04-28 02:14:35 -0700233{
234 return 0;
235}
236
Jan Karab85f4b82008-07-25 01:46:50 -0700237static inline int vfs_dq_quota_on_remount(struct super_block *sb)
Andrew Morton50f8c372008-04-28 02:14:35 -0700238{
239 return 0;
240}
241
Christoph Hellwigb43fa822010-03-03 09:05:03 -0500242static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
Andrew Morton50f8c372008-04-28 02:14:35 -0700243{
244 return 0;
245}
246
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500247static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
Eric Sandeen56246f92010-05-16 09:00:00 -0400248 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Eric Sandeen56246f92010-05-16 09:00:00 -0400250 if (!(flags & DQUOT_SPACE_RESERVE))
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500251 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return 0;
253}
254
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500255static inline void __dquot_free_space(struct inode *inode, qsize_t number,
Eric Sandeen56246f92010-05-16 09:00:00 -0400256 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
Eric Sandeen56246f92010-05-16 09:00:00 -0400258 if (!(flags & DQUOT_SPACE_RESERVE))
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500259 inode_sub_bytes(inode, number);
260}
261
262static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
263{
264 inode_add_bytes(inode, number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return 0;
266}
267
Christoph Hellwig871a2932010-03-03 09:05:07 -0500268#define dquot_file_open generic_file_open
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270#endif /* CONFIG_QUOTA */
271
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500272static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700273{
Eric Sandeen56246f92010-05-16 09:00:00 -0400274 return __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN);
Jan Kara03f6e922008-04-28 02:14:32 -0700275}
276
Eric Sandeen0e058422010-05-16 10:00:00 -0400277static inline void dquot_alloc_space_nofail(struct inode *inode, qsize_t nr)
278{
279 __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN|DQUOT_SPACE_NOFAIL);
280 mark_inode_dirty(inode);
Jan Kara03f6e922008-04-28 02:14:32 -0700281}
282
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500283static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700284{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500285 int ret;
286
287 ret = dquot_alloc_space_nodirty(inode, nr);
288 if (!ret)
289 mark_inode_dirty(inode);
290 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700291}
292
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500293static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700294{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500295 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700296}
297
Eric Sandeen0e058422010-05-16 10:00:00 -0400298static inline void dquot_alloc_block_nofail(struct inode *inode, qsize_t nr)
299{
300 dquot_alloc_space_nofail(inode, nr << inode->i_blkbits);
301}
302
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500303static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700304{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500305 return dquot_alloc_space(inode, nr << inode->i_blkbits);
Jan Kara03f6e922008-04-28 02:14:32 -0700306}
307
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500308static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
Mingming Caof18df222009-01-13 16:43:09 +0100309{
Eric Sandeen56246f92010-05-16 09:00:00 -0400310 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0);
Mingming Caof18df222009-01-13 16:43:09 +0100311}
312
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500313static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100314{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500315 int ret;
316
317 ret = dquot_prealloc_block_nodirty(inode, nr);
318 if (!ret)
319 mark_inode_dirty(inode);
320 return ret;
Mingming Cao740d9dc2009-01-13 16:43:14 +0100321}
322
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500323static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
Mingming Cao740d9dc2009-01-13 16:43:14 +0100324{
Eric Sandeen56246f92010-05-16 09:00:00 -0400325 return __dquot_alloc_space(inode, nr << inode->i_blkbits,
326 DQUOT_SPACE_WARN|DQUOT_SPACE_RESERVE);
Mingming Cao740d9dc2009-01-13 16:43:14 +0100327}
328
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500329static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700330{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500331 int ret;
332
333 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
334 if (!ret)
335 mark_inode_dirty(inode);
336 return ret;
Jan Kara03f6e922008-04-28 02:14:32 -0700337}
338
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500339static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
Jan Kara03f6e922008-04-28 02:14:32 -0700340{
Christoph Hellwig5dd40562010-03-03 09:05:00 -0500341 __dquot_free_space(inode, nr, 0);
342}
343
344static inline void dquot_free_space(struct inode *inode, qsize_t nr)
345{
346 dquot_free_space_nodirty(inode, nr);
347 mark_inode_dirty(inode);
348}
349
350static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
351{
352 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
353}
354
355static inline void dquot_free_block(struct inode *inode, qsize_t nr)
356{
357 dquot_free_space(inode, nr << inode->i_blkbits);
358}
359
360static inline void dquot_release_reservation_block(struct inode *inode,
361 qsize_t nr)
362{
Eric Sandeen56246f92010-05-16 09:00:00 -0400363 __dquot_free_space(inode, nr << inode->i_blkbits, DQUOT_SPACE_RESERVE);
Jan Kara03f6e922008-04-28 02:14:32 -0700364}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#endif /* _LINUX_QUOTAOPS_ */