Merge tag 'rtc-5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
[linux-block.git] / include / linux / quotaops.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2/*
3 * Definitions for diskquota-operations. When diskquota is configured these
4 * macros expand to the right source-code.
5 *
6 * Author: Marco van Wieringen <mvw@planets.elm.net>
1da177e4
LT
7 */
8#ifndef _LINUX_QUOTAOPS_
9#define _LINUX_QUOTAOPS_
10
1da177e4
LT
11#include <linux/fs.h>
12
56246f9a
ES
13#define DQUOT_SPACE_WARN 0x1
14#define DQUOT_SPACE_RESERVE 0x2
0e05842b 15#define DQUOT_SPACE_NOFAIL 0x4
56246f9a 16
03b06343
JK
17static inline struct quota_info *sb_dqopt(struct super_block *sb)
18{
19 return &sb->s_dquot;
20}
74abb989 21
12755627
DM
22/* i_mutex must being held */
23static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
24{
6565c182 25 return (ia->ia_valid & ATTR_SIZE) ||
8e96e3b7
EB
26 (ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
27 (ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
12755627
DM
28}
29
1da177e4
LT
30#if defined(CONFIG_QUOTA)
31
fb5ffb0e
JZ
32#define quota_error(sb, fmt, args...) \
33 __quota_error((sb), __func__, fmt , ## args)
34
b9075fa9 35extern __printf(3, 4)
055adcbd
JP
36void __quota_error(struct super_block *sb, const char *func,
37 const char *fmt, ...);
fb5ffb0e 38
1da177e4
LT
39/*
40 * declaration of quota_function calls in kernel.
41 */
6184fc0b 42int dquot_initialize(struct inode *inode);
b8cb5a54 43bool dquot_initialize_needed(struct inode *inode);
9f754758 44void dquot_drop(struct inode *inode);
aca645a6 45struct dquot *dqget(struct super_block *sb, struct kqid qid);
9f985cb6
JK
46static inline struct dquot *dqgrab(struct dquot *dquot)
47{
48 /* Make sure someone else has active reference to dquot */
49 WARN_ON_ONCE(!atomic_read(&dquot->dq_count));
50 WARN_ON_ONCE(!test_bit(DQ_ACTIVE_B, &dquot->dq_flags));
51 atomic_inc(&dquot->dq_count);
52 return dquot;
53}
df4bb5d1
DM
54
55static inline bool dquot_is_busy(struct dquot *dquot)
56{
57 if (test_bit(DQ_MOD_B, &dquot->dq_flags))
58 return true;
59 if (atomic_read(&dquot->dq_count) > 1)
60 return true;
61 return false;
62}
63
3d9ea253 64void dqput(struct dquot *dquot);
12c77527
JK
65int dquot_scan_active(struct super_block *sb,
66 int (*fn)(struct dquot *dquot, unsigned long priv),
67 unsigned long priv);
7d9056ba
JK
68struct dquot *dquot_alloc(struct super_block *sb, int type);
69void dquot_destroy(struct dquot *dquot);
b85f4b87 70
56246f9a
ES
71int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags);
72void __dquot_free_space(struct inode *inode, qsize_t number, int flags);
b85f4b87 73
6bab3596 74int dquot_alloc_inode(struct inode *inode);
740d9dcd 75
5dd4056d 76int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
6bab3596 77void dquot_free_inode(struct inode *inode);
1c8924eb 78void dquot_reclaim_space_nodirty(struct inode *inode, qsize_t number);
b85f4b87 79
0f0dd62f
CH
80int dquot_disable(struct super_block *sb, int type, unsigned int flags);
81/* Suspend quotas on remount RO */
82static inline int dquot_suspend(struct super_block *sb, int type)
83{
84 return dquot_disable(sb, type, DQUOT_SUSPENDED);
85}
86int dquot_resume(struct super_block *sb, int type);
87
b85f4b87
JK
88int dquot_commit(struct dquot *dquot);
89int dquot_acquire(struct dquot *dquot);
90int dquot_release(struct dquot *dquot);
91int dquot_commit_info(struct super_block *sb, int type);
be6257b2 92int dquot_get_next_id(struct super_block *sb, struct kqid *qid);
b85f4b87
JK
93int dquot_mark_dquot_dirty(struct dquot *dquot);
94
907f4554
CH
95int dquot_file_open(struct inode *inode, struct file *file);
96
c7d3d283
JK
97int dquot_load_quota_sb(struct super_block *sb, int type, int format_id,
98 unsigned int flags);
dc19432a 99int dquot_load_quota_inode(struct inode *inode, int type, int format_id,
f55abc0f 100 unsigned int flags);
f00c9e44 101int dquot_quota_on(struct super_block *sb, int type, int format_id,
8c54ca9c 102 const struct path *path);
287a8095 103int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
b85f4b87 104 int format_id, int type);
287a8095 105int dquot_quota_off(struct super_block *sb, int type);
ceed1723
JK
106int dquot_writeback_dquots(struct super_block *sb, int type);
107int dquot_quota_sync(struct super_block *sb, int type);
0a240339 108int dquot_get_state(struct super_block *sb, struct qc_state *state);
5eacb2ac 109int dquot_set_dqinfo(struct super_block *sb, int type, struct qc_info *ii);
74a8a103 110int dquot_get_dqblk(struct super_block *sb, struct kqid id,
14bf61ff 111 struct qc_dqblk *di);
be6257b2
JK
112int dquot_get_next_dqblk(struct super_block *sb, struct kqid *id,
113 struct qc_dqblk *di);
74a8a103 114int dquot_set_dqblk(struct super_block *sb, struct kqid id,
14bf61ff 115 struct qc_dqblk *di);
b85f4b87 116
bc8e5f07 117int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
b43fa828 118int dquot_transfer(struct inode *inode, struct iattr *iattr);
1da177e4 119
03b06343
JK
120static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
121{
122 return sb_dqopt(sb)->info + type;
123}
74abb989
JK
124
125/*
126 * Functions for checking status of quota
127 */
128
ad1e6e8d 129static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
03b06343 130{
f55abc0f
JK
131 return sb_dqopt(sb)->flags &
132 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
03b06343 133}
74abb989 134
ad1e6e8d 135static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
03b06343 136{
f55abc0f
JK
137 return sb_dqopt(sb)->flags &
138 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
03b06343 139}
74abb989 140
ad1e6e8d 141static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
03b06343 142{
f55abc0f
JK
143 return sb_dqopt(sb)->flags &
144 dquot_state_flag(DQUOT_SUSPENDED, type);
03b06343 145}
74abb989 146
ad1e6e8d 147static inline unsigned sb_any_quota_suspended(struct super_block *sb)
03b06343 148{
78197024 149 return dquot_state_types(sb_dqopt(sb)->flags, DQUOT_SUSPENDED);
03b06343 150}
74abb989 151
f55abc0f 152/* Does kernel know about any quota information for given sb + type? */
ad1e6e8d 153static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
f55abc0f
JK
154{
155 /* Currently if anything is on, then quota usage is on as well */
156 return sb_has_quota_usage_enabled(sb, type);
157}
158
ad1e6e8d 159static inline unsigned sb_any_quota_loaded(struct super_block *sb)
f55abc0f 160{
78197024 161 return dquot_state_types(sb_dqopt(sb)->flags, DQUOT_USAGE_ENABLED);
f55abc0f
JK
162}
163
ad1e6e8d 164static inline bool sb_has_quota_active(struct super_block *sb, int type)
f55abc0f
JK
165{
166 return sb_has_quota_loaded(sb, type) &&
167 !sb_has_quota_suspended(sb, type);
168}
169
1da177e4
LT
170/*
171 * Operations supported for diskquotas.
172 */
61e225dc 173extern const struct dquot_operations dquot_operations;
3e2af67e 174extern const struct quotactl_ops dquot_quotactl_sysfile_ops;
0ff5af83 175
1da177e4
LT
176#else
177
f55abc0f 178static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
03b06343
JK
179{
180 return 0;
181}
182
f55abc0f 183static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
03b06343
JK
184{
185 return 0;
186}
187
188static inline int sb_has_quota_suspended(struct super_block *sb, int type)
189{
190 return 0;
191}
192
193static inline int sb_any_quota_suspended(struct super_block *sb)
194{
195 return 0;
196}
74abb989 197
f55abc0f
JK
198/* Does kernel know about any quota information for given sb + type? */
199static inline int sb_has_quota_loaded(struct super_block *sb, int type)
200{
201 return 0;
202}
203
204static inline int sb_any_quota_loaded(struct super_block *sb)
205{
206 return 0;
207}
208
209static inline int sb_has_quota_active(struct super_block *sb, int type)
210{
211 return 0;
212}
213
6184fc0b 214static inline int dquot_initialize(struct inode *inode)
50f8c370 215{
6184fc0b 216 return 0;
50f8c370
AM
217}
218
b8cb5a54
TE
219static inline bool dquot_initialize_needed(struct inode *inode)
220{
221 return false;
222}
223
9f754758 224static inline void dquot_drop(struct inode *inode)
50f8c370
AM
225{
226}
227
6bab3596 228static inline int dquot_alloc_inode(struct inode *inode)
50f8c370
AM
229{
230 return 0;
231}
232
6bab3596 233static inline void dquot_free_inode(struct inode *inode)
50f8c370
AM
234{
235}
236
b43fa828 237static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
50f8c370
AM
238{
239 return 0;
240}
241
5dd4056d 242static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
56246f9a 243 int flags)
1da177e4 244{
56246f9a 245 if (!(flags & DQUOT_SPACE_RESERVE))
5dd4056d 246 inode_add_bytes(inode, number);
1da177e4
LT
247 return 0;
248}
249
5dd4056d 250static inline void __dquot_free_space(struct inode *inode, qsize_t number,
56246f9a 251 int flags)
1da177e4 252{
56246f9a 253 if (!(flags & DQUOT_SPACE_RESERVE))
5dd4056d 254 inode_sub_bytes(inode, number);
1da177e4
LT
255}
256
5dd4056d 257static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
1da177e4 258{
5dd4056d 259 inode_add_bytes(inode, number);
1da177e4
LT
260 return 0;
261}
262
1c8924eb
JK
263static inline int dquot_reclaim_space_nodirty(struct inode *inode,
264 qsize_t number)
265{
266 inode_sub_bytes(inode, number);
267 return 0;
268}
269
0f0dd62f
CH
270static inline int dquot_disable(struct super_block *sb, int type,
271 unsigned int flags)
272{
273 return 0;
274}
275
276static inline int dquot_suspend(struct super_block *sb, int type)
277{
278 return 0;
279}
280
281static inline int dquot_resume(struct super_block *sb, int type)
282{
283 return 0;
1da177e4
LT
284}
285
871a2931
CH
286#define dquot_file_open generic_file_open
287
ceed1723
JK
288static inline int dquot_writeback_dquots(struct super_block *sb, int type)
289{
290 return 0;
291}
292
5dd4056d
CH
293#endif /* CONFIG_QUOTA */
294
295static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
1da177e4 296{
56246f9a 297 return __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN);
1da177e4
LT
298}
299
0e05842b
ES
300static inline void dquot_alloc_space_nofail(struct inode *inode, qsize_t nr)
301{
302 __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN|DQUOT_SPACE_NOFAIL);
43d2932d 303 mark_inode_dirty_sync(inode);
1da177e4
LT
304}
305
5dd4056d 306static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
f18df228 307{
5dd4056d
CH
308 int ret;
309
310 ret = dquot_alloc_space_nodirty(inode, nr);
d530148a
SL
311 if (!ret) {
312 /*
313 * Mark inode fully dirty. Since we are allocating blocks, inode
314 * would become fully dirty soon anyway and it reportedly
250df6ed 315 * reduces lock contention.
d530148a
SL
316 */
317 mark_inode_dirty(inode);
318 }
5dd4056d 319 return ret;
f18df228
MC
320}
321
5dd4056d 322static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
740d9dcd 323{
5dd4056d 324 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
740d9dcd
MC
325}
326
0e05842b
ES
327static inline void dquot_alloc_block_nofail(struct inode *inode, qsize_t nr)
328{
329 dquot_alloc_space_nofail(inode, nr << inode->i_blkbits);
330}
331
5dd4056d 332static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
740d9dcd 333{
5dd4056d 334 return dquot_alloc_space(inode, nr << inode->i_blkbits);
740d9dcd
MC
335}
336
5dd4056d 337static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
1da177e4 338{
56246f9a 339 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0);
1da177e4
LT
340}
341
5dd4056d 342static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
1da177e4 343{
5dd4056d 344 int ret;
1da177e4 345
5dd4056d
CH
346 ret = dquot_prealloc_block_nodirty(inode, nr);
347 if (!ret)
43d2932d 348 mark_inode_dirty_sync(inode);
5dd4056d 349 return ret;
03f6e92b
JK
350}
351
5dd4056d 352static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
03f6e92b 353{
56246f9a
ES
354 return __dquot_alloc_space(inode, nr << inode->i_blkbits,
355 DQUOT_SPACE_WARN|DQUOT_SPACE_RESERVE);
03f6e92b
JK
356}
357
5dd4056d 358static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
03f6e92b 359{
5dd4056d 360 int ret;
03f6e92b 361
5dd4056d
CH
362 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
363 if (!ret)
43d2932d 364 mark_inode_dirty_sync(inode);
5dd4056d 365 return ret;
03f6e92b
JK
366}
367
1c8924eb
JK
368static inline void dquot_reclaim_block(struct inode *inode, qsize_t nr)
369{
370 dquot_reclaim_space_nodirty(inode, nr << inode->i_blkbits);
371 mark_inode_dirty_sync(inode);
372}
373
5dd4056d 374static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
f18df228 375{
5dd4056d 376 __dquot_free_space(inode, nr, 0);
f18df228
MC
377}
378
5dd4056d 379static inline void dquot_free_space(struct inode *inode, qsize_t nr)
740d9dcd 380{
5dd4056d 381 dquot_free_space_nodirty(inode, nr);
43d2932d 382 mark_inode_dirty_sync(inode);
740d9dcd
MC
383}
384
5dd4056d 385static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
740d9dcd 386{
5dd4056d 387 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
740d9dcd
MC
388}
389
5dd4056d 390static inline void dquot_free_block(struct inode *inode, qsize_t nr)
03f6e92b 391{
5dd4056d 392 dquot_free_space(inode, nr << inode->i_blkbits);
03f6e92b
JK
393}
394
5dd4056d
CH
395static inline void dquot_release_reservation_block(struct inode *inode,
396 qsize_t nr)
03f6e92b 397{
56246f9a 398 __dquot_free_space(inode, nr << inode->i_blkbits, DQUOT_SPACE_RESERVE);
03f6e92b 399}
1da177e4 400
d3b86324
JK
401unsigned int qtype_enforce_flag(int type);
402
1da177e4 403#endif /* _LINUX_QUOTAOPS_ */