0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _LINUX_QUOTAOPS_
0009 #define _LINUX_QUOTAOPS_
0010
0011 #include <linux/fs.h>
0012
0013 #define DQUOT_SPACE_WARN 0x1
0014 #define DQUOT_SPACE_RESERVE 0x2
0015 #define DQUOT_SPACE_NOFAIL 0x4
0016
0017 static inline struct quota_info *sb_dqopt(struct super_block *sb)
0018 {
0019 return &sb->s_dquot;
0020 }
0021
0022
0023 static inline bool is_quota_modification(struct user_namespace *mnt_userns,
0024 struct inode *inode, struct iattr *ia)
0025 {
0026 return ((ia->ia_valid & ATTR_SIZE) ||
0027 i_uid_needs_update(mnt_userns, ia, inode) ||
0028 i_gid_needs_update(mnt_userns, ia, inode));
0029 }
0030
0031 #if defined(CONFIG_QUOTA)
0032
0033 #define quota_error(sb, fmt, args...) \
0034 __quota_error((sb), __func__, fmt , ## args)
0035
0036 extern __printf(3, 4)
0037 void __quota_error(struct super_block *sb, const char *func,
0038 const char *fmt, ...);
0039
0040
0041
0042
0043 int dquot_initialize(struct inode *inode);
0044 bool dquot_initialize_needed(struct inode *inode);
0045 void dquot_drop(struct inode *inode);
0046 struct dquot *dqget(struct super_block *sb, struct kqid qid);
0047 static inline struct dquot *dqgrab(struct dquot *dquot)
0048 {
0049
0050 WARN_ON_ONCE(!atomic_read(&dquot->dq_count));
0051 WARN_ON_ONCE(!test_bit(DQ_ACTIVE_B, &dquot->dq_flags));
0052 atomic_inc(&dquot->dq_count);
0053 return dquot;
0054 }
0055
0056 static inline bool dquot_is_busy(struct dquot *dquot)
0057 {
0058 if (test_bit(DQ_MOD_B, &dquot->dq_flags))
0059 return true;
0060 if (atomic_read(&dquot->dq_count) > 1)
0061 return true;
0062 return false;
0063 }
0064
0065 void dqput(struct dquot *dquot);
0066 int dquot_scan_active(struct super_block *sb,
0067 int (*fn)(struct dquot *dquot, unsigned long priv),
0068 unsigned long priv);
0069 struct dquot *dquot_alloc(struct super_block *sb, int type);
0070 void dquot_destroy(struct dquot *dquot);
0071
0072 int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags);
0073 void __dquot_free_space(struct inode *inode, qsize_t number, int flags);
0074
0075 int dquot_alloc_inode(struct inode *inode);
0076
0077 int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
0078 void dquot_free_inode(struct inode *inode);
0079 void dquot_reclaim_space_nodirty(struct inode *inode, qsize_t number);
0080
0081 int dquot_disable(struct super_block *sb, int type, unsigned int flags);
0082
0083 static inline int dquot_suspend(struct super_block *sb, int type)
0084 {
0085 return dquot_disable(sb, type, DQUOT_SUSPENDED);
0086 }
0087 int dquot_resume(struct super_block *sb, int type);
0088
0089 int dquot_commit(struct dquot *dquot);
0090 int dquot_acquire(struct dquot *dquot);
0091 int dquot_release(struct dquot *dquot);
0092 int dquot_commit_info(struct super_block *sb, int type);
0093 int dquot_get_next_id(struct super_block *sb, struct kqid *qid);
0094 int dquot_mark_dquot_dirty(struct dquot *dquot);
0095
0096 int dquot_file_open(struct inode *inode, struct file *file);
0097
0098 int dquot_load_quota_sb(struct super_block *sb, int type, int format_id,
0099 unsigned int flags);
0100 int dquot_load_quota_inode(struct inode *inode, int type, int format_id,
0101 unsigned int flags);
0102 int dquot_quota_on(struct super_block *sb, int type, int format_id,
0103 const struct path *path);
0104 int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
0105 int format_id, int type);
0106 int dquot_quota_off(struct super_block *sb, int type);
0107 int dquot_writeback_dquots(struct super_block *sb, int type);
0108 int dquot_quota_sync(struct super_block *sb, int type);
0109 int dquot_get_state(struct super_block *sb, struct qc_state *state);
0110 int dquot_set_dqinfo(struct super_block *sb, int type, struct qc_info *ii);
0111 int dquot_get_dqblk(struct super_block *sb, struct kqid id,
0112 struct qc_dqblk *di);
0113 int dquot_get_next_dqblk(struct super_block *sb, struct kqid *id,
0114 struct qc_dqblk *di);
0115 int dquot_set_dqblk(struct super_block *sb, struct kqid id,
0116 struct qc_dqblk *di);
0117
0118 int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
0119 int dquot_transfer(struct user_namespace *mnt_userns, struct inode *inode,
0120 struct iattr *iattr);
0121
0122 static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
0123 {
0124 return sb_dqopt(sb)->info + type;
0125 }
0126
0127
0128
0129
0130
0131 static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
0132 {
0133 return sb_dqopt(sb)->flags &
0134 dquot_state_flag(DQUOT_USAGE_ENABLED, type);
0135 }
0136
0137 static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
0138 {
0139 return sb_dqopt(sb)->flags &
0140 dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
0141 }
0142
0143 static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
0144 {
0145 return sb_dqopt(sb)->flags &
0146 dquot_state_flag(DQUOT_SUSPENDED, type);
0147 }
0148
0149 static inline unsigned sb_any_quota_suspended(struct super_block *sb)
0150 {
0151 return dquot_state_types(sb_dqopt(sb)->flags, DQUOT_SUSPENDED);
0152 }
0153
0154
0155 static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
0156 {
0157
0158 return sb_has_quota_usage_enabled(sb, type);
0159 }
0160
0161 static inline unsigned sb_any_quota_loaded(struct super_block *sb)
0162 {
0163 return dquot_state_types(sb_dqopt(sb)->flags, DQUOT_USAGE_ENABLED);
0164 }
0165
0166 static inline bool sb_has_quota_active(struct super_block *sb, int type)
0167 {
0168 return sb_has_quota_loaded(sb, type) &&
0169 !sb_has_quota_suspended(sb, type);
0170 }
0171
0172
0173
0174
0175 extern const struct dquot_operations dquot_operations;
0176 extern const struct quotactl_ops dquot_quotactl_sysfile_ops;
0177
0178 #else
0179
0180 static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
0181 {
0182 return 0;
0183 }
0184
0185 static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
0186 {
0187 return 0;
0188 }
0189
0190 static inline int sb_has_quota_suspended(struct super_block *sb, int type)
0191 {
0192 return 0;
0193 }
0194
0195 static inline int sb_any_quota_suspended(struct super_block *sb)
0196 {
0197 return 0;
0198 }
0199
0200
0201 static inline int sb_has_quota_loaded(struct super_block *sb, int type)
0202 {
0203 return 0;
0204 }
0205
0206 static inline int sb_any_quota_loaded(struct super_block *sb)
0207 {
0208 return 0;
0209 }
0210
0211 static inline int sb_has_quota_active(struct super_block *sb, int type)
0212 {
0213 return 0;
0214 }
0215
0216 static inline int dquot_initialize(struct inode *inode)
0217 {
0218 return 0;
0219 }
0220
0221 static inline bool dquot_initialize_needed(struct inode *inode)
0222 {
0223 return false;
0224 }
0225
0226 static inline void dquot_drop(struct inode *inode)
0227 {
0228 }
0229
0230 static inline int dquot_alloc_inode(struct inode *inode)
0231 {
0232 return 0;
0233 }
0234
0235 static inline void dquot_free_inode(struct inode *inode)
0236 {
0237 }
0238
0239 static inline int dquot_transfer(struct user_namespace *mnt_userns,
0240 struct inode *inode, struct iattr *iattr)
0241 {
0242 return 0;
0243 }
0244
0245 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
0246 int flags)
0247 {
0248 if (!(flags & DQUOT_SPACE_RESERVE))
0249 inode_add_bytes(inode, number);
0250 return 0;
0251 }
0252
0253 static inline void __dquot_free_space(struct inode *inode, qsize_t number,
0254 int flags)
0255 {
0256 if (!(flags & DQUOT_SPACE_RESERVE))
0257 inode_sub_bytes(inode, number);
0258 }
0259
0260 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
0261 {
0262 inode_add_bytes(inode, number);
0263 return 0;
0264 }
0265
0266 static inline int dquot_reclaim_space_nodirty(struct inode *inode,
0267 qsize_t number)
0268 {
0269 inode_sub_bytes(inode, number);
0270 return 0;
0271 }
0272
0273 static inline int dquot_disable(struct super_block *sb, int type,
0274 unsigned int flags)
0275 {
0276 return 0;
0277 }
0278
0279 static inline int dquot_suspend(struct super_block *sb, int type)
0280 {
0281 return 0;
0282 }
0283
0284 static inline int dquot_resume(struct super_block *sb, int type)
0285 {
0286 return 0;
0287 }
0288
0289 #define dquot_file_open generic_file_open
0290
0291 static inline int dquot_writeback_dquots(struct super_block *sb, int type)
0292 {
0293 return 0;
0294 }
0295
0296 #endif
0297
0298 static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
0299 {
0300 return __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN);
0301 }
0302
0303 static inline void dquot_alloc_space_nofail(struct inode *inode, qsize_t nr)
0304 {
0305 __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN|DQUOT_SPACE_NOFAIL);
0306 mark_inode_dirty_sync(inode);
0307 }
0308
0309 static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
0310 {
0311 int ret;
0312
0313 ret = dquot_alloc_space_nodirty(inode, nr);
0314 if (!ret) {
0315
0316
0317
0318
0319
0320 mark_inode_dirty(inode);
0321 }
0322 return ret;
0323 }
0324
0325 static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
0326 {
0327 return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
0328 }
0329
0330 static inline void dquot_alloc_block_nofail(struct inode *inode, qsize_t nr)
0331 {
0332 dquot_alloc_space_nofail(inode, nr << inode->i_blkbits);
0333 }
0334
0335 static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
0336 {
0337 return dquot_alloc_space(inode, nr << inode->i_blkbits);
0338 }
0339
0340 static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
0341 {
0342 return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0);
0343 }
0344
0345 static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
0346 {
0347 int ret;
0348
0349 ret = dquot_prealloc_block_nodirty(inode, nr);
0350 if (!ret)
0351 mark_inode_dirty_sync(inode);
0352 return ret;
0353 }
0354
0355 static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
0356 {
0357 return __dquot_alloc_space(inode, nr << inode->i_blkbits,
0358 DQUOT_SPACE_WARN|DQUOT_SPACE_RESERVE);
0359 }
0360
0361 static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
0362 {
0363 int ret;
0364
0365 ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
0366 if (!ret)
0367 mark_inode_dirty_sync(inode);
0368 return ret;
0369 }
0370
0371 static inline void dquot_reclaim_block(struct inode *inode, qsize_t nr)
0372 {
0373 dquot_reclaim_space_nodirty(inode, nr << inode->i_blkbits);
0374 mark_inode_dirty_sync(inode);
0375 }
0376
0377 static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
0378 {
0379 __dquot_free_space(inode, nr, 0);
0380 }
0381
0382 static inline void dquot_free_space(struct inode *inode, qsize_t nr)
0383 {
0384 dquot_free_space_nodirty(inode, nr);
0385 mark_inode_dirty_sync(inode);
0386 }
0387
0388 static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
0389 {
0390 dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
0391 }
0392
0393 static inline void dquot_free_block(struct inode *inode, qsize_t nr)
0394 {
0395 dquot_free_space(inode, nr << inode->i_blkbits);
0396 }
0397
0398 static inline void dquot_release_reservation_block(struct inode *inode,
0399 qsize_t nr)
0400 {
0401 __dquot_free_space(inode, nr << inode->i_blkbits, DQUOT_SPACE_RESERVE);
0402 }
0403
0404 unsigned int qtype_enforce_flag(int type);
0405
0406 #endif