Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 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.1 2004-01-28 15:26:25 giacomo 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 void dquot_initialize(struct inode *inode, int type);
26
extern void 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 void dquot_free_space(struct inode *inode, qsize_t number);
32
extern void dquot_free_inode(const struct inode *inode, unsigned long number);
33
 
34
extern int  dquot_transfer(struct inode *inode, struct iattr *iattr);
35
 
36
/*
37
 * Operations supported for diskquotas.
38
 */
39
extern struct dquot_operations dquot_operations;
40
extern struct quotactl_ops vfs_quotactl_ops;
41
 
42
#define sb_dquot_ops (&dquot_operations)
43
#define sb_quotactl_ops (&vfs_quotactl_ops)
44
 
45
static __inline__ void DQUOT_INIT(struct inode *inode)
46
{
47
        if (!inode->i_sb)
48
                BUG();
49
        if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
50
                inode->i_sb->dq_op->initialize(inode, -1);
51
}
52
 
53
static __inline__ void DQUOT_DROP(struct inode *inode)
54
{
55
        if (IS_QUOTAINIT(inode)) {
56
                if (!inode->i_sb)
57
                        BUG();
58
                inode->i_sb->dq_op->drop(inode);        /* Ops must be set when there's any quota... */
59
        }
60
}
61
 
62
static __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
63
{
64
        if (sb_any_quota_enabled(inode->i_sb)) {
65
                /* Used space is updated in alloc_space() */
66
                if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
67
                        return 1;
68
        }
69
        else {
70
                spin_lock(&dq_data_lock);
71
                inode_add_bytes(inode, nr);
72
                spin_unlock(&dq_data_lock);
73
        }
74
        return 0;
75
}
76
 
77
static __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
78
{
79
        int ret;
80
        if (!(ret =  DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
81
                mark_inode_dirty(inode);
82
        return ret;
83
}
84
 
85
static __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
86
{
87
        if (sb_any_quota_enabled(inode->i_sb)) {
88
                /* Used space is updated in alloc_space() */
89
                if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
90
                        return 1;
91
        }
92
        else {
93
                spin_lock(&dq_data_lock);
94
                inode_add_bytes(inode, nr);
95
                spin_unlock(&dq_data_lock);
96
        }
97
        return 0;
98
}
99
 
100
static __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
101
{
102
        int ret;
103
        if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
104
                mark_inode_dirty(inode);
105
        return ret;
106
}
107
 
108
static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode)
109
{
110
        if (sb_any_quota_enabled(inode->i_sb)) {
111
                DQUOT_INIT(inode);
112
                if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
113
                        return 1;
114
        }
115
        return 0;
116
}
117
 
118
static __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
119
{
120
        if (sb_any_quota_enabled(inode->i_sb))
121
                inode->i_sb->dq_op->free_space(inode, nr);
122
        else {
123
                spin_lock(&dq_data_lock);
124
                inode_sub_bytes(inode, nr);
125
                spin_unlock(&dq_data_lock);
126
        }
127
}
128
 
129
static __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
130
{
131
        DQUOT_FREE_SPACE_NODIRTY(inode, nr);
132
        mark_inode_dirty(inode);
133
}
134
 
135
static __inline__ void DQUOT_FREE_INODE(struct inode *inode)
136
{
137
        if (sb_any_quota_enabled(inode->i_sb))
138
                inode->i_sb->dq_op->free_inode(inode, 1);
139
}
140
 
141
static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
142
{
143
        if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
144
                DQUOT_INIT(inode);
145
                if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
146
                        return 1;
147
        }
148
        return 0;
149
}
150
 
151
#define DQUOT_SYNC(sb)  sync_dquots(sb, -1)
152
 
153
static __inline__ int DQUOT_OFF(struct super_block *sb)
154
{
155
        int ret = -ENOSYS;
156
 
157
        if (sb->s_qcop && sb->s_qcop->quota_off)
158
                ret = sb->s_qcop->quota_off(sb, -1);
159
        return ret;
160
}
161
 
162
#else
163
 
164
/*
165
 * NO-OP when quota not configured.
166
 */
167
#define sb_dquot_ops                            (NULL)
168
#define sb_quotactl_ops                         (NULL)
169
#define sync_dquots_dev(dev,type)               (NULL)
170
#define DQUOT_INIT(inode)                       do { } while(0)
171
#define DQUOT_DROP(inode)                       do { } while(0)
172
#define DQUOT_ALLOC_INODE(inode)                (0)
173
#define DQUOT_FREE_INODE(inode)                 do { } while(0)
174
#define DQUOT_SYNC(sb)                          do { } while(0)
175
#define DQUOT_OFF(sb)                           do { } while(0)
176
#define DQUOT_TRANSFER(inode, iattr)            (0)
177
extern __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
178
{
179
        inode_add_bytes(inode, nr);
180
        return 0;
181
}
182
 
183
extern __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
184
{
185
        DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
186
        mark_inode_dirty(inode);
187
        return 0;
188
}
189
 
190
extern __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
191
{
192
        inode_add_bytes(inode, nr);
193
        return 0;
194
}
195
 
196
extern __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
197
{
198
        DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
199
        mark_inode_dirty(inode);
200
        return 0;
201
}
202
 
203
extern __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
204
{
205
        inode_sub_bytes(inode, nr);
206
}
207
 
208
extern __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
209
{
210
        DQUOT_FREE_SPACE_NODIRTY(inode, nr);
211
        mark_inode_dirty(inode);
212
}      
213
 
214
#endif /* CONFIG_QUOTA */
215
 
216
#define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_PREALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
217
#define DQUOT_PREALLOC_BLOCK(inode, nr) DQUOT_PREALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
218
#define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_ALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
219
#define DQUOT_ALLOC_BLOCK(inode, nr) DQUOT_ALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
220
#define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) DQUOT_FREE_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
221
#define DQUOT_FREE_BLOCK(inode, nr) DQUOT_FREE_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
222
 
223
#endif /* _LINUX_QUOTAOPS_ */