1 From: Jan Kara <jack@suse.cz>
2 References: fate#302681
3 Subject: [PATCH 14/28] quota: Allow negative usage of space and inodes
4 Patch-mainline: 2.6.29?
6 For clustered filesystems, it can happen that space / inode usage goes
7 negative temporarily (because some node is allocating another node
8 is freeing and they are not completely in sync). So let quota code
9 allow this and change qsize_t so a signed type so that we don't
10 underflow the variables.
12 Signed-off-by: Jan Kara <jack@suse.cz>
15 include/linux/quota.h | 3 ++-
16 2 files changed, 6 insertions(+), 3 deletions(-)
18 diff --git a/fs/dquot.c b/fs/dquot.c
19 index 904bd67..f4258fe 100644
22 @@ -845,7 +845,8 @@ static inline void dquot_incr_space(struct dquot *dquot, qsize_t number)
24 static inline void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
26 - if (dquot->dq_dqb.dqb_curinodes > number)
27 + if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
28 + dquot->dq_dqb.dqb_curinodes >= number)
29 dquot->dq_dqb.dqb_curinodes -= number;
31 dquot->dq_dqb.dqb_curinodes = 0;
32 @@ -856,7 +857,8 @@ static inline void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
34 static inline void dquot_decr_space(struct dquot *dquot, qsize_t number)
36 - if (dquot->dq_dqb.dqb_curspace > number)
37 + if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
38 + dquot->dq_dqb.dqb_curspace >= number)
39 dquot->dq_dqb.dqb_curspace -= number;
41 dquot->dq_dqb.dqb_curspace = 0;
42 diff --git a/include/linux/quota.h b/include/linux/quota.h
43 index e05c30d..0ee2a55 100644
44 --- a/include/linux/quota.h
45 +++ b/include/linux/quota.h
46 @@ -170,7 +170,7 @@ enum {
47 #include <asm/atomic.h>
49 typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */
50 -typedef __u64 qsize_t; /* Type in which we store sizes */
51 +typedef __s64 qsize_t; /* Type in which we store sizes */
53 extern spinlock_t dq_data_lock;
55 @@ -338,6 +338,7 @@ enum {
56 * responsible for setting
57 * S_NOQUOTA, S_NOATIME flags
59 +#define DQUOT_NEGATIVE_USAGE (1 << 7) /* Allow negative quota usage */
61 static inline unsigned int dquot_state_flag(unsigned int flags, int type)