Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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> |
| 6 | * |
| 7 | * Version: $Id: quotaops.h,v 1.2 1998/01/15 16:22:26 ecd Exp $ |
| 8 | * |
| 9 | */ |
| 10 | #ifndef _LINUX_QUOTAOPS_ |
| 11 | #define _LINUX_QUOTAOPS_ |
| 12 | |
| 13 | #include <linux/config.h> |
| 14 | #include <linux/smp_lock.h> |
| 15 | |
| 16 | #include <linux/fs.h> |
| 17 | |
| 18 | #if defined(CONFIG_QUOTA) |
| 19 | |
| 20 | /* |
| 21 | * declaration of quota_function calls in kernel. |
| 22 | */ |
| 23 | extern void sync_dquots(struct super_block *sb, int type); |
| 24 | |
| 25 | extern int dquot_initialize(struct inode *inode, int type); |
| 26 | extern int dquot_drop(struct inode *inode); |
| 27 | |
| 28 | extern int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc); |
| 29 | extern int dquot_alloc_inode(const struct inode *inode, unsigned long number); |
| 30 | |
| 31 | extern int dquot_free_space(struct inode *inode, qsize_t number); |
| 32 | extern int dquot_free_inode(const struct inode *inode, unsigned long number); |
| 33 | |
| 34 | extern int dquot_transfer(struct inode *inode, struct iattr *iattr); |
| 35 | extern int dquot_commit(struct dquot *dquot); |
| 36 | extern int dquot_acquire(struct dquot *dquot); |
| 37 | extern int dquot_release(struct dquot *dquot); |
| 38 | extern int dquot_commit_info(struct super_block *sb, int type); |
| 39 | extern int dquot_mark_dquot_dirty(struct dquot *dquot); |
| 40 | |
| 41 | extern int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path); |
Christoph Hellwig | 84de856 | 2005-06-23 00:09:16 -0700 | [diff] [blame] | 42 | extern int vfs_quota_on_mount(struct super_block *sb, char *qf_name, |
| 43 | int format_id, int type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | extern int vfs_quota_off(struct super_block *sb, int type); |
| 45 | #define vfs_quota_off_mount(sb, type) vfs_quota_off(sb, type) |
| 46 | extern int vfs_quota_sync(struct super_block *sb, int type); |
| 47 | extern int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); |
| 48 | extern int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); |
| 49 | extern int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di); |
| 50 | extern int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di); |
| 51 | |
| 52 | /* |
| 53 | * Operations supported for diskquotas. |
| 54 | */ |
| 55 | extern struct dquot_operations dquot_operations; |
| 56 | extern struct quotactl_ops vfs_quotactl_ops; |
| 57 | |
| 58 | #define sb_dquot_ops (&dquot_operations) |
| 59 | #define sb_quotactl_ops (&vfs_quotactl_ops) |
| 60 | |
| 61 | /* It is better to call this function outside of any transaction as it might |
| 62 | * need a lot of space in journal for dquot structure allocation. */ |
| 63 | static __inline__ void DQUOT_INIT(struct inode *inode) |
| 64 | { |
| 65 | BUG_ON(!inode->i_sb); |
| 66 | if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) |
| 67 | inode->i_sb->dq_op->initialize(inode, -1); |
| 68 | } |
| 69 | |
| 70 | /* The same as with DQUOT_INIT */ |
| 71 | static __inline__ void DQUOT_DROP(struct inode *inode) |
| 72 | { |
| 73 | /* Here we can get arbitrary inode from clear_inode() so we have |
| 74 | * to be careful. OTOH we don't need locking as quota operations |
| 75 | * are allowed to change only at mount time */ |
| 76 | if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op |
| 77 | && inode->i_sb->dq_op->drop) { |
| 78 | int cnt; |
| 79 | /* Test before calling to rule out calls from proc and such |
| 80 | * where we are not allowed to block. Note that this is |
| 81 | * actually reliable test even without the lock - the caller |
| 82 | * must assure that nobody can come after the DQUOT_DROP and |
| 83 | * add quota pointers back anyway */ |
| 84 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
| 85 | if (inode->i_dquot[cnt] != NODQUOT) |
| 86 | break; |
| 87 | if (cnt < MAXQUOTAS) |
| 88 | inode->i_sb->dq_op->drop(inode); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /* The following allocation/freeing/transfer functions *must* be called inside |
| 93 | * a transaction (deadlocks possible otherwise) */ |
| 94 | static __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) |
| 95 | { |
| 96 | if (sb_any_quota_enabled(inode->i_sb)) { |
| 97 | /* Used space is updated in alloc_space() */ |
| 98 | if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) |
| 99 | return 1; |
| 100 | } |
| 101 | else |
| 102 | inode_add_bytes(inode, nr); |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr) |
| 107 | { |
| 108 | int ret; |
| 109 | if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr))) |
| 110 | mark_inode_dirty(inode); |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | static __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) |
| 115 | { |
| 116 | if (sb_any_quota_enabled(inode->i_sb)) { |
| 117 | /* Used space is updated in alloc_space() */ |
| 118 | if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) |
| 119 | return 1; |
| 120 | } |
| 121 | else |
| 122 | inode_add_bytes(inode, nr); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr) |
| 127 | { |
| 128 | int ret; |
| 129 | if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr))) |
| 130 | mark_inode_dirty(inode); |
| 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode) |
| 135 | { |
| 136 | if (sb_any_quota_enabled(inode->i_sb)) { |
| 137 | DQUOT_INIT(inode); |
| 138 | if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) |
| 139 | return 1; |
| 140 | } |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr) |
| 145 | { |
| 146 | if (sb_any_quota_enabled(inode->i_sb)) |
| 147 | inode->i_sb->dq_op->free_space(inode, nr); |
| 148 | else |
| 149 | inode_sub_bytes(inode, nr); |
| 150 | } |
| 151 | |
| 152 | static __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr) |
| 153 | { |
| 154 | DQUOT_FREE_SPACE_NODIRTY(inode, nr); |
| 155 | mark_inode_dirty(inode); |
| 156 | } |
| 157 | |
| 158 | static __inline__ void DQUOT_FREE_INODE(struct inode *inode) |
| 159 | { |
| 160 | if (sb_any_quota_enabled(inode->i_sb)) |
| 161 | inode->i_sb->dq_op->free_inode(inode, 1); |
| 162 | } |
| 163 | |
| 164 | static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr) |
| 165 | { |
| 166 | if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) { |
| 167 | DQUOT_INIT(inode); |
| 168 | if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA) |
| 169 | return 1; |
| 170 | } |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | /* The following two functions cannot be called inside a transaction */ |
| 175 | #define DQUOT_SYNC(sb) sync_dquots(sb, -1) |
| 176 | |
| 177 | static __inline__ int DQUOT_OFF(struct super_block *sb) |
| 178 | { |
| 179 | int ret = -ENOSYS; |
| 180 | |
| 181 | if (sb_any_quota_enabled(sb) && sb->s_qcop && sb->s_qcop->quota_off) |
| 182 | ret = sb->s_qcop->quota_off(sb, -1); |
| 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | #else |
| 187 | |
| 188 | /* |
| 189 | * NO-OP when quota not configured. |
| 190 | */ |
| 191 | #define sb_dquot_ops (NULL) |
| 192 | #define sb_quotactl_ops (NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | #define DQUOT_INIT(inode) do { } while(0) |
| 194 | #define DQUOT_DROP(inode) do { } while(0) |
| 195 | #define DQUOT_ALLOC_INODE(inode) (0) |
| 196 | #define DQUOT_FREE_INODE(inode) do { } while(0) |
| 197 | #define DQUOT_SYNC(sb) do { } while(0) |
| 198 | #define DQUOT_OFF(sb) do { } while(0) |
| 199 | #define DQUOT_TRANSFER(inode, iattr) (0) |
Adrian Bunk | be586ba | 2005-11-07 00:59:35 -0800 | [diff] [blame] | 200 | static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
| 202 | inode_add_bytes(inode, nr); |
| 203 | return 0; |
| 204 | } |
| 205 | |
Adrian Bunk | be586ba | 2005-11-07 00:59:35 -0800 | [diff] [blame] | 206 | static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
| 208 | DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr); |
| 209 | mark_inode_dirty(inode); |
| 210 | return 0; |
| 211 | } |
| 212 | |
Adrian Bunk | be586ba | 2005-11-07 00:59:35 -0800 | [diff] [blame] | 213 | static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
| 215 | inode_add_bytes(inode, nr); |
| 216 | return 0; |
| 217 | } |
| 218 | |
Adrian Bunk | be586ba | 2005-11-07 00:59:35 -0800 | [diff] [blame] | 219 | static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
| 221 | DQUOT_ALLOC_SPACE_NODIRTY(inode, nr); |
| 222 | mark_inode_dirty(inode); |
| 223 | return 0; |
| 224 | } |
| 225 | |
Adrian Bunk | be586ba | 2005-11-07 00:59:35 -0800 | [diff] [blame] | 226 | static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | inode_sub_bytes(inode, nr); |
| 229 | } |
| 230 | |
Adrian Bunk | be586ba | 2005-11-07 00:59:35 -0800 | [diff] [blame] | 231 | static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
| 233 | DQUOT_FREE_SPACE_NODIRTY(inode, nr); |
| 234 | mark_inode_dirty(inode); |
| 235 | } |
| 236 | |
| 237 | #endif /* CONFIG_QUOTA */ |
| 238 | |
| 239 | #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_PREALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits) |
| 240 | #define DQUOT_PREALLOC_BLOCK(inode, nr) DQUOT_PREALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits) |
| 241 | #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_ALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits) |
| 242 | #define DQUOT_ALLOC_BLOCK(inode, nr) DQUOT_ALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits) |
| 243 | #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) DQUOT_FREE_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits) |
| 244 | #define DQUOT_FREE_BLOCK(inode, nr) DQUOT_FREE_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits) |
| 245 | |
| 246 | #endif /* _LINUX_QUOTAOPS_ */ |