Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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