]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/quotaops.h
LSM: generalize flag passing to security_capable
[mirror_ubuntu-bionic-kernel.git] / include / linux / quotaops.h
1 /* SPDX-License-Identifier: GPL-2.0 */
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>
7 */
8 #ifndef _LINUX_QUOTAOPS_
9 #define _LINUX_QUOTAOPS_
10
11 #include <linux/fs.h>
12
13 #define DQUOT_SPACE_WARN 0x1
14 #define DQUOT_SPACE_RESERVE 0x2
15 #define DQUOT_SPACE_NOFAIL 0x4
16
17 static inline struct quota_info *sb_dqopt(struct super_block *sb)
18 {
19 return &sb->s_dquot;
20 }
21
22 /* i_mutex must being held */
23 static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
24 {
25 return (ia->ia_valid & ATTR_SIZE) ||
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));
28 }
29
30 #if defined(CONFIG_QUOTA)
31
32 #define quota_error(sb, fmt, args...) \
33 __quota_error((sb), __func__, fmt , ## args)
34
35 extern __printf(3, 4)
36 void __quota_error(struct super_block *sb, const char *func,
37 const char *fmt, ...);
38
39 /*
40 * declaration of quota_function calls in kernel.
41 */
42 int dquot_initialize(struct inode *inode);
43 bool dquot_initialize_needed(struct inode *inode);
44 void dquot_drop(struct inode *inode);
45 struct dquot *dqget(struct super_block *sb, struct kqid qid);
46 static 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 }
54
55 static 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
64 void dqput(struct dquot *dquot);
65 int dquot_scan_active(struct super_block *sb,
66 int (*fn)(struct dquot *dquot, unsigned long priv),
67 unsigned long priv);
68 struct dquot *dquot_alloc(struct super_block *sb, int type);
69 void dquot_destroy(struct dquot *dquot);
70
71 int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags);
72 void __dquot_free_space(struct inode *inode, qsize_t number, int flags);
73
74 int dquot_alloc_inode(struct inode *inode);
75
76 int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
77 void dquot_free_inode(struct inode *inode);
78 void dquot_reclaim_space_nodirty(struct inode *inode, qsize_t number);
79
80 int dquot_disable(struct super_block *sb, int type, unsigned int flags);
81 /* Suspend quotas on remount RO */
82 static inline int dquot_suspend(struct super_block *sb, int type)
83 {
84 return dquot_disable(sb, type, DQUOT_SUSPENDED);
85 }
86 int dquot_resume(struct super_block *sb, int type);
87
88 int dquot_commit(struct dquot *dquot);
89 int dquot_acquire(struct dquot *dquot);
90 int dquot_release(struct dquot *dquot);
91 int dquot_commit_info(struct super_block *sb, int type);
92 int dquot_get_next_id(struct super_block *sb, struct kqid *qid);
93 int dquot_mark_dquot_dirty(struct dquot *dquot);
94
95 int dquot_file_open(struct inode *inode, struct file *file);
96
97 int dquot_enable(struct inode *inode, int type, int format_id,
98 unsigned int flags);
99 int dquot_quota_on(struct super_block *sb, int type, int format_id,
100 const struct path *path);
101 int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
102 int format_id, int type);
103 int dquot_quota_off(struct super_block *sb, int type);
104 int dquot_writeback_dquots(struct super_block *sb, int type);
105 int dquot_quota_sync(struct super_block *sb, int type);
106 int dquot_get_state(struct super_block *sb, struct qc_state *state);
107 int dquot_set_dqinfo(struct super_block *sb, int type, struct qc_info *ii);
108 int dquot_get_dqblk(struct super_block *sb, struct kqid id,
109 struct qc_dqblk *di);
110 int dquot_get_next_dqblk(struct super_block *sb, struct kqid *id,
111 struct qc_dqblk *di);
112 int dquot_set_dqblk(struct super_block *sb, struct kqid id,
113 struct qc_dqblk *di);
114
115 int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
116 int dquot_transfer(struct inode *inode, struct iattr *iattr);
117
118 static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
119 {
120 return sb_dqopt(sb)->info + type;
121 }
122
123 /*
124 * Functions for checking status of quota
125 */
126
127 static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
128 {
129 return sb_dqopt(sb)->flags &
130 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
131 }
132
133 static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
134 {
135 return sb_dqopt(sb)->flags &
136 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
137 }
138
139 static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
140 {
141 return sb_dqopt(sb)->flags &
142 dquot_state_flag(DQUOT_SUSPENDED, type);
143 }
144
145 static inline unsigned sb_any_quota_suspended(struct super_block *sb)
146 {
147 return dquot_state_types(sb_dqopt(sb)->flags, DQUOT_SUSPENDED);
148 }
149
150 /* Does kernel know about any quota information for given sb + type? */
151 static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
152 {
153 /* Currently if anything is on, then quota usage is on as well */
154 return sb_has_quota_usage_enabled(sb, type);
155 }
156
157 static inline unsigned sb_any_quota_loaded(struct super_block *sb)
158 {
159 return dquot_state_types(sb_dqopt(sb)->flags, DQUOT_USAGE_ENABLED);
160 }
161
162 static inline bool sb_has_quota_active(struct super_block *sb, int type)
163 {
164 return sb_has_quota_loaded(sb, type) &&
165 !sb_has_quota_suspended(sb, type);
166 }
167
168 /*
169 * Operations supported for diskquotas.
170 */
171 extern const struct dquot_operations dquot_operations;
172 extern const struct quotactl_ops dquot_quotactl_sysfile_ops;
173
174 #else
175
176 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
177 {
178 return 0;
179 }
180
181 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
182 {
183 return 0;
184 }
185
186 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
187 {
188 return 0;
189 }
190
191 static inline int sb_any_quota_suspended(struct super_block *sb)
192 {
193 return 0;
194 }
195
196 /* Does kernel know about any quota information for given sb + type? */
197 static inline int sb_has_quota_loaded(struct super_block *sb, int type)
198 {
199 return 0;
200 }
201
202 static inline int sb_any_quota_loaded(struct super_block *sb)
203 {
204 return 0;
205 }
206
207 static inline int sb_has_quota_active(struct super_block *sb, int type)
208 {
209 return 0;
210 }
211
212 static inline int dquot_initialize(struct inode *inode)
213 {
214 return 0;
215 }
216
217 static inline bool dquot_initialize_needed(struct inode *inode)
218 {
219 return false;
220 }
221
222 static inline void dquot_drop(struct inode *inode)
223 {
224 }
225
226 static inline int dquot_alloc_inode(struct inode *inode)
227 {
228 return 0;
229 }
230
231 static inline void dquot_free_inode(struct inode *inode)
232 {
233 }
234
235 static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
236 {
237 return 0;
238 }
239
240 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
241 int flags)
242 {
243 if (!(flags & DQUOT_SPACE_RESERVE))
244 inode_add_bytes(inode, number);
245 return 0;
246 }
247
248 static inline void __dquot_free_space(struct inode *inode, qsize_t number,
249 int flags)
250 {
251 if (!(flags & DQUOT_SPACE_RESERVE))
252 inode_sub_bytes(inode, number);
253 }
254
255 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
256 {
257 inode_add_bytes(inode, number);
258 return 0;
259 }
260
261 static inline int dquot_reclaim_space_nodirty(struct inode *inode,
262 qsize_t number)
263 {
264 inode_sub_bytes(inode, number);
265 return 0;
266 }
267
268 static inline int dquot_disable(struct super_block *sb, int type,
269 unsigned int flags)
270 {
271 return 0;
272 }
273
274 static inline int dquot_suspend(struct super_block *sb, int type)
275 {
276 return 0;
277 }
278
279 static inline int dquot_resume(struct super_block *sb, int type)
280 {
281 return 0;
282 }
283
284 #define dquot_file_open generic_file_open
285
286 static inline int dquot_writeback_dquots(struct super_block *sb, int type)
287 {
288 return 0;
289 }
290
291 #endif /* CONFIG_QUOTA */
292
293 static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
294 {
295 return __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN);
296 }
297
298 static inline void dquot_alloc_space_nofail(struct inode *inode, qsize_t nr)
299 {
300 __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN|DQUOT_SPACE_NOFAIL);
301 mark_inode_dirty_sync(inode);
302 }
303
304 static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
305 {
306 int ret;
307
308 ret = dquot_alloc_space_nodirty(inode, nr);
309 if (!ret) {
310 /*
311 * Mark inode fully dirty. Since we are allocating blocks, inode
312 * would become fully dirty soon anyway and it reportedly
313 * reduces lock contention.
314 */
315 mark_inode_dirty(inode);
316 }
317 return ret;
318 }
319
320 static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
321 {
322 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
323 }
324
325 static inline void dquot_alloc_block_nofail(struct inode *inode, qsize_t nr)
326 {
327 dquot_alloc_space_nofail(inode, nr << inode->i_blkbits);
328 }
329
330 static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
331 {
332 return dquot_alloc_space(inode, nr << inode->i_blkbits);
333 }
334
335 static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
336 {
337 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0);
338 }
339
340 static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
341 {
342 int ret;
343
344 ret = dquot_prealloc_block_nodirty(inode, nr);
345 if (!ret)
346 mark_inode_dirty_sync(inode);
347 return ret;
348 }
349
350 static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
351 {
352 return __dquot_alloc_space(inode, nr << inode->i_blkbits,
353 DQUOT_SPACE_WARN|DQUOT_SPACE_RESERVE);
354 }
355
356 static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
357 {
358 int ret;
359
360 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
361 if (!ret)
362 mark_inode_dirty_sync(inode);
363 return ret;
364 }
365
366 static inline void dquot_reclaim_block(struct inode *inode, qsize_t nr)
367 {
368 dquot_reclaim_space_nodirty(inode, nr << inode->i_blkbits);
369 mark_inode_dirty_sync(inode);
370 }
371
372 static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
373 {
374 __dquot_free_space(inode, nr, 0);
375 }
376
377 static inline void dquot_free_space(struct inode *inode, qsize_t nr)
378 {
379 dquot_free_space_nodirty(inode, nr);
380 mark_inode_dirty_sync(inode);
381 }
382
383 static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
384 {
385 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
386 }
387
388 static inline void dquot_free_block(struct inode *inode, qsize_t nr)
389 {
390 dquot_free_space(inode, nr << inode->i_blkbits);
391 }
392
393 static inline void dquot_release_reservation_block(struct inode *inode,
394 qsize_t nr)
395 {
396 __dquot_free_space(inode, nr << inode->i_blkbits, DQUOT_SPACE_RESERVE);
397 }
398
399 unsigned int qtype_enforce_flag(int type);
400
401 #endif /* _LINUX_QUOTAOPS_ */