Blame view

fs/xfs/xfs_dquot.h 5.51 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
4ce3121f6   Nathan Scott   [XFS] Update lice...
2
3
   * Copyright (c) 2000-2005 Silicon Graphics, Inc.
   * All Rights Reserved.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
   *
4ce3121f6   Nathan Scott   [XFS] Update lice...
5
6
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
   * published by the Free Software Foundation.
   *
4ce3121f6   Nathan Scott   [XFS] Update lice...
9
10
11
12
   * This program is distributed in the hope that it would be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
   *
4ce3121f6   Nathan Scott   [XFS] Update lice...
14
15
16
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write the Free Software Foundation,
   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   */
  #ifndef __XFS_DQUOT_H__
  #define __XFS_DQUOT_H__
  
  /*
   * Dquots are structures that hold quota information about a user or a group,
   * much like inodes are for files. In fact, dquots share many characteristics
   * with inodes. However, dquots can also be a centralized resource, relative
   * to a collection of inodes. In this respect, dquots share some characteristics
   * of the superblock.
   * XFS dquots exploit both those in its algorithms. They make every attempt
   * to not be a bottleneck when quotas are on and have minimal impact, if any,
   * when quotas are off.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
  struct xfs_mount;
  struct xfs_trans;
b13664511   Brian Foster   xfs: xfs_dquot pr...
33
34
35
36
37
38
  enum {
  	XFS_QLOWSP_1_PCNT = 0,
  	XFS_QLOWSP_3_PCNT,
  	XFS_QLOWSP_5_PCNT,
  	XFS_QLOWSP_MAX
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
   * The incore dquot structure
   */
  typedef struct xfs_dquot {
74457cf4a   Christoph Hellwig   xfs: remove xfs_d...
43
  	uint		 dq_flags;	/* various flags (XFS_DQ_*) */
f8739c3ce   Christoph Hellwig   xfs: per-filesyst...
44
  	struct list_head q_lru;		/* global free list of dquots */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
47
48
49
50
  	struct xfs_mount*q_mount;	/* filesystem this relates to */
  	struct xfs_trans*q_transp;	/* trans this belongs to currently */
  	uint		 q_nrefs;	/* # active refs from inodes */
  	xfs_daddr_t	 q_blkno;	/* blkno of dquot buffer */
  	int		 q_bufoffset;	/* off of dq in buffer (# dquots) */
  	xfs_fileoff_t	 q_fileoffset;	/* offset in quotas file */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
52
53
54
55
  	xfs_disk_dquot_t q_core;	/* actual usage & quotas */
  	xfs_dq_logitem_t q_logitem;	/* dquot log item */
  	xfs_qcnt_t	 q_res_bcount;	/* total regular nblks used+reserved */
  	xfs_qcnt_t	 q_res_icount;	/* total inos allocd+reserved */
  	xfs_qcnt_t	 q_res_rtbcount;/* total realtime blks used+reserved */
b13664511   Brian Foster   xfs: xfs_dquot pr...
56
57
58
  	xfs_qcnt_t	 q_prealloc_lo_wmark;/* prealloc throttle wmark */
  	xfs_qcnt_t	 q_prealloc_hi_wmark;/* prealloc disabled wmark */
  	int64_t		 q_low_space[XFS_QLOWSP_MAX];
a0b0b8a5b   Christoph Hellwig   xfs: kill mutex_t...
59
  	struct mutex	 q_qlock;	/* quota lock */
e1f49cf20   David Chinner   [XFS] replace dqu...
60
  	struct completion q_flush;	/* flush completion queue */
bc3048e3c   Peter Leckie   [XFS] Clean up dq...
61
62
  	atomic_t          q_pincount;	/* dquot pin count */
  	wait_queue_head_t q_pinwait;	/* dquot pinning wait queue */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
  } xfs_dquot_t;
5bb87a33b   Christoph Hellwig   xfs: lockdep anno...
64
  /*
af901ca18   AndrĂ© Goddard Rosa   tree-wide: fix as...
65
   * Lock hierarchy for q_qlock:
5bb87a33b   Christoph Hellwig   xfs: lockdep anno...
66
67
68
69
70
71
72
   *	XFS_QLOCK_NORMAL is the implicit default,
   * 	XFS_QLOCK_NESTED is the dquot with the higher id in xfs_dqlock2
   */
  enum {
  	XFS_QLOCK_NORMAL = 0,
  	XFS_QLOCK_NESTED,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  /*
e1f49cf20   David Chinner   [XFS] replace dqu...
74
75
76
   * Manage the q_flush completion queue embedded in the dquot.  This completion
   * queue synchronizes processes attempting to flush the in-core dquot back to
   * disk.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
   */
e1f49cf20   David Chinner   [XFS] replace dqu...
78
79
80
81
  static inline void xfs_dqflock(xfs_dquot_t *dqp)
  {
  	wait_for_completion(&dqp->q_flush);
  }
43fd1fce9   Nicholas Mc Guire   xfs: fix implicit...
82
  static inline bool xfs_dqflock_nowait(xfs_dquot_t *dqp)
e1f49cf20   David Chinner   [XFS] replace dqu...
83
84
85
86
87
88
89
90
  {
  	return try_wait_for_completion(&dqp->q_flush);
  }
  
  static inline void xfs_dqfunlock(xfs_dquot_t *dqp)
  {
  	complete(&dqp->q_flush);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91

800b484ec   Christoph Hellwig   xfs: cleanup dquo...
92
93
94
95
96
97
98
99
100
  static inline int xfs_dqlock_nowait(struct xfs_dquot *dqp)
  {
  	return mutex_trylock(&dqp->q_qlock);
  }
  
  static inline void xfs_dqlock(struct xfs_dquot *dqp)
  {
  	mutex_lock(&dqp->q_qlock);
  }
5b03ff1b2   Christoph Hellwig   xfs: remove xfs_t...
101
  static inline void xfs_dqunlock(struct xfs_dquot *dqp)
800b484ec   Christoph Hellwig   xfs: cleanup dquo...
102
103
104
  {
  	mutex_unlock(&dqp->q_qlock);
  }
6967b964c   Chandra Seetharaman   Define a new func...
105
106
107
108
109
110
  static inline int xfs_this_quota_on(struct xfs_mount *mp, int type)
  {
  	switch (type & XFS_DQ_ALLTYPES) {
  	case XFS_DQ_USER:
  		return XFS_IS_UQUOTA_ON(mp);
  	case XFS_DQ_GROUP:
92f8ff73f   Chandra Seetharaman   xfs: Add pquota f...
111
  		return XFS_IS_GQUOTA_ON(mp);
6967b964c   Chandra Seetharaman   Define a new func...
112
  	case XFS_DQ_PROJ:
92f8ff73f   Chandra Seetharaman   xfs: Add pquota f...
113
  		return XFS_IS_PQUOTA_ON(mp);
6967b964c   Chandra Seetharaman   Define a new func...
114
115
116
117
  	default:
  		return 0;
  	}
  }
367314108   Chandra Seetharaman   Define a new func...
118
119
120
121
122
123
  static inline xfs_dquot_t *xfs_inode_dquot(struct xfs_inode *ip, int type)
  {
  	switch (type & XFS_DQ_ALLTYPES) {
  	case XFS_DQ_USER:
  		return ip->i_udquot;
  	case XFS_DQ_GROUP:
367314108   Chandra Seetharaman   Define a new func...
124
  		return ip->i_gdquot;
92f8ff73f   Chandra Seetharaman   xfs: Add pquota f...
125
126
  	case XFS_DQ_PROJ:
  		return ip->i_pdquot;
367314108   Chandra Seetharaman   Define a new func...
127
128
129
130
  	default:
  		return NULL;
  	}
  }
dc06f398f   Brian Foster   xfs: run an eofbl...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  /*
   * Check whether a dquot is under low free space conditions. We assume the quota
   * is enabled and enforced.
   */
  static inline bool xfs_dquot_lowsp(struct xfs_dquot *dqp)
  {
  	int64_t freesp;
  
  	freesp = be64_to_cpu(dqp->q_core.d_blk_hardlimit) - dqp->q_res_bcount;
  	if (freesp < dqp->q_low_space[XFS_QLOWSP_1_PCNT])
  		return true;
  
  	return false;
  }
7201813bf   Christoph Hellwig   xfs: use mutex_is...
145
  #define XFS_DQ_IS_LOCKED(dqp)	(mutex_is_locked(&((dqp)->q_qlock)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146
147
  #define XFS_DQ_IS_DIRTY(dqp)	((dqp)->dq_flags & XFS_DQ_DIRTY)
  #define XFS_QM_ISUDQ(dqp)	((dqp)->dq_flags & XFS_DQ_USER)
c8ad20ffe   Nathan Scott   [XFS] Add support...
148
149
  #define XFS_QM_ISPDQ(dqp)	((dqp)->dq_flags & XFS_DQ_PROJ)
  #define XFS_QM_ISGDQ(dqp)	((dqp)->dq_flags & XFS_DQ_GROUP)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150

7ae444072   Christoph Hellwig   xfs: remove XFS_Q...
151
152
  extern int		xfs_qm_dqread(struct xfs_mount *, xfs_dqid_t, uint,
  					uint, struct xfs_dquot	**);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
  extern void		xfs_qm_dqdestroy(xfs_dquot_t *);
fe7257fd4   Christoph Hellwig   xfs: do not write...
154
  extern int		xfs_qm_dqflush(struct xfs_dquot *, struct xfs_buf **);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
  extern void		xfs_qm_dqunpin_wait(xfs_dquot_t *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
  extern void		xfs_qm_adjust_dqtimers(xfs_mount_t *,
  					xfs_disk_dquot_t *);
4b6eae2e6   Brian Foster   xfs: pass xfs_dqu...
158
159
  extern void		xfs_qm_adjust_dqlimits(struct xfs_mount *,
  					       struct xfs_dquot *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
161
162
  extern int		xfs_qm_dqget(xfs_mount_t *, xfs_inode_t *,
  					xfs_dqid_t, uint, uint, xfs_dquot_t **);
  extern void		xfs_qm_dqput(xfs_dquot_t *);
800b484ec   Christoph Hellwig   xfs: cleanup dquo...
163
164
  
  extern void		xfs_dqlock2(struct xfs_dquot *, struct xfs_dquot *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165

b13664511   Brian Foster   xfs: xfs_dquot pr...
166
  extern void		xfs_dquot_set_prealloc_limits(struct xfs_dquot *);
78e55892d   Christoph Hellwig   xfs: add a xfs_dq...
167
168
169
170
171
172
173
  static inline struct xfs_dquot *xfs_qm_dqhold(struct xfs_dquot *dqp)
  {
  	xfs_dqlock(dqp);
  	dqp->q_nrefs++;
  	xfs_dqunlock(dqp);
  	return dqp;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
174
  #endif /* __XFS_DQUOT_H__ */