Blame view

fs/quota/quota_v2.c 12.5 KB
09c434b8a   Thomas Gleixner   treewide: Add SPD...
1
  // SPDX-License-Identifier: GPL-2.0-only
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
  /*
   *	vfsv0 quota IO operations on file
   */
  
  #include <linux/errno.h>
  #include <linux/fs.h>
  #include <linux/mount.h>
  #include <linux/dqblk_v2.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
12
13
  #include <linux/kernel.h>
  #include <linux/init.h>
  #include <linux/module.h>
  #include <linux/slab.h>
74abb9890   Jan Kara   quota: move funct...
14
  #include <linux/quotaops.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
16
  
  #include <asm/byteorder.h>
1ccd14b9c   Jan Kara   quota: Split off ...
17
  #include "quota_tree.h"
cf770c137   Jan Kara   quota: Move quota...
18
  #include "quotaio_v2.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
  MODULE_AUTHOR("Jan Kara");
  MODULE_DESCRIPTION("Quota format v2 support");
  MODULE_LICENSE("GPL");
498c60153   Jan Kara   quota: Implement ...
22
23
24
25
26
27
  static void v2r0_mem2diskdqb(void *dp, struct dquot *dquot);
  static void v2r0_disk2memdqb(struct dquot *dquot, void *dp);
  static int v2r0_is_id(void *dp, struct dquot *dquot);
  static void v2r1_mem2diskdqb(void *dp, struct dquot *dquot);
  static void v2r1_disk2memdqb(struct dquot *dquot, void *dp);
  static int v2r1_is_id(void *dp, struct dquot *dquot);
d1b98c23f   Julia Lawall   quota: constify q...
28
  static const struct qtree_fmt_operations v2r0_qtree_ops = {
498c60153   Jan Kara   quota: Implement ...
29
30
31
32
  	.mem2disk_dqblk = v2r0_mem2diskdqb,
  	.disk2mem_dqblk = v2r0_disk2memdqb,
  	.is_id = v2r0_is_id,
  };
d1b98c23f   Julia Lawall   quota: constify q...
33
  static const struct qtree_fmt_operations v2r1_qtree_ops = {
498c60153   Jan Kara   quota: Implement ...
34
35
36
  	.mem2disk_dqblk = v2r1_mem2diskdqb,
  	.disk2mem_dqblk = v2r1_disk2memdqb,
  	.is_id = v2r1_is_id,
1ccd14b9c   Jan Kara   quota: Split off ...
37
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38

12095460f   Jan Kara   quota: Increase s...
39
40
41
42
43
44
45
46
47
48
49
50
  #define QUOTABLOCK_BITS 10
  #define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
  
  static inline qsize_t v2_stoqb(qsize_t space)
  {
  	return (space + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS;
  }
  
  static inline qsize_t v2_qbtos(qsize_t blocks)
  {
  	return blocks << QUOTABLOCK_BITS;
  }
498c60153   Jan Kara   quota: Implement ...
51
52
53
54
55
56
57
58
  static int v2_read_header(struct super_block *sb, int type,
  			  struct v2_disk_dqheader *dqhead)
  {
  	ssize_t size;
  
  	size = sb->s_op->quota_read(sb, type, (char *)dqhead,
  				    sizeof(struct v2_disk_dqheader), 0);
  	if (size != sizeof(struct v2_disk_dqheader)) {
fb5ffb0e1   Jiaying Zhang   quota: Change quo...
59
60
  		quota_error(sb, "Failed header read: expected=%zd got=%zd",
  			    sizeof(struct v2_disk_dqheader), size);
f98bbe37a   Jan Kara   quota: Propagate ...
61
62
63
  		if (size < 0)
  			return size;
  		return -EIO;
498c60153   Jan Kara   quota: Implement ...
64
  	}
f98bbe37a   Jan Kara   quota: Propagate ...
65
  	return 0;
498c60153   Jan Kara   quota: Implement ...
66
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
68
69
70
  /* Check whether given file is really vfsv0 quotafile */
  static int v2_check_quota_file(struct super_block *sb, int type)
  {
  	struct v2_disk_dqheader dqhead;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
  	static const uint quota_magics[] = V2_INITQMAGICS;
  	static const uint quota_versions[] = V2_INITQVERSIONS;
27942ef50   Sascha Hauer   quota: remove tra...
73

f98bbe37a   Jan Kara   quota: Propagate ...
74
  	if (v2_read_header(sb, type, &dqhead))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  	if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type] ||
498c60153   Jan Kara   quota: Implement ...
77
  	    le32_to_cpu(dqhead.dqh_version) > quota_versions[type])
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
81
82
83
84
85
  		return 0;
  	return 1;
  }
  
  /* Read information header from quota file */
  static int v2_read_file_info(struct super_block *sb, int type)
  {
  	struct v2_disk_dqinfo dinfo;
498c60153   Jan Kara   quota: Implement ...
86
  	struct v2_disk_dqheader dqhead;
42fdb8583   Jan Kara   quota: Push dqio_...
87
88
  	struct quota_info *dqopt = sb_dqopt(sb);
  	struct mem_dqinfo *info = &dqopt->info[type];
e3d4d56b9   Jan Kara   quota: Convert un...
89
  	struct qtree_mem_dqinfo *qinfo;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  	ssize_t size;
498c60153   Jan Kara   quota: Implement ...
91
  	unsigned int version;
42fdb8583   Jan Kara   quota: Push dqio_...
92
  	int ret;
498c60153   Jan Kara   quota: Implement ...
93

42fdb8583   Jan Kara   quota: Push dqio_...
94
  	down_read(&dqopt->dqio_sem);
f98bbe37a   Jan Kara   quota: Propagate ...
95
96
  	ret = v2_read_header(sb, type, &dqhead);
  	if (ret < 0)
42fdb8583   Jan Kara   quota: Push dqio_...
97
  		goto out;
498c60153   Jan Kara   quota: Implement ...
98
  	version = le32_to_cpu(dqhead.dqh_version);
869835dfa   Jan Kara   quota: Improve ch...
99
  	if ((info->dqi_fmt_id == QFMT_VFS_V0 && version != 0) ||
42fdb8583   Jan Kara   quota: Push dqio_...
100
  	    (info->dqi_fmt_id == QFMT_VFS_V1 && version != 1)) {
cb8d01b4f   Jan Kara   quota: Fix error ...
101
  		ret = -EINVAL;
42fdb8583   Jan Kara   quota: Push dqio_...
102
103
  		goto out;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
106
107
  
  	size = sb->s_op->quota_read(sb, type, (char *)&dinfo,
  	       sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF);
  	if (size != sizeof(struct v2_disk_dqinfo)) {
fb5ffb0e1   Jiaying Zhang   quota: Change quo...
108
  		quota_error(sb, "Can't read info structure");
f98bbe37a   Jan Kara   quota: Propagate ...
109
110
111
112
  		if (size < 0)
  			ret = size;
  		else
  			ret = -EIO;
42fdb8583   Jan Kara   quota: Push dqio_...
113
  		goto out;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
  	}
e3d4d56b9   Jan Kara   quota: Convert un...
115
116
  	info->dqi_priv = kmalloc(sizeof(struct qtree_mem_dqinfo), GFP_NOFS);
  	if (!info->dqi_priv) {
42fdb8583   Jan Kara   quota: Push dqio_...
117
118
  		ret = -ENOMEM;
  		goto out;
e3d4d56b9   Jan Kara   quota: Convert un...
119
120
  	}
  	qinfo = info->dqi_priv;
498c60153   Jan Kara   quota: Implement ...
121
122
  	if (version == 0) {
  		/* limits are stored as unsigned 32-bit data */
7e08da50c   Jan Kara   quota: Fix maximu...
123
  		info->dqi_max_spc_limit = 0xffffffffLL << QUOTABLOCK_BITS;
b10a08194   Jan Kara   quota: Store maxi...
124
  		info->dqi_max_ino_limit = 0xffffffff;
498c60153   Jan Kara   quota: Implement ...
125
  	} else {
7e08da50c   Jan Kara   quota: Fix maximu...
126
127
128
129
130
131
132
  		/*
  		 * Used space is stored as unsigned 64-bit value in bytes but
  		 * quota core supports only signed 64-bit values so use that
  		 * as a limit
  		 */
  		info->dqi_max_spc_limit = 0x7fffffffffffffffLL; /* 2^63-1 */
  		info->dqi_max_ino_limit = 0x7fffffffffffffffLL;
498c60153   Jan Kara   quota: Implement ...
133
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
135
  	info->dqi_bgrace = le32_to_cpu(dinfo.dqi_bgrace);
  	info->dqi_igrace = le32_to_cpu(dinfo.dqi_igrace);
c119c5b97   Jan Kara   quota: Don't stor...
136
137
  	/* No flags currently supported */
  	info->dqi_flags = 0;
e3d4d56b9   Jan Kara   quota: Convert un...
138
139
140
141
142
143
144
145
  	qinfo->dqi_sb = sb;
  	qinfo->dqi_type = type;
  	qinfo->dqi_blocks = le32_to_cpu(dinfo.dqi_blocks);
  	qinfo->dqi_free_blk = le32_to_cpu(dinfo.dqi_free_blk);
  	qinfo->dqi_free_entry = le32_to_cpu(dinfo.dqi_free_entry);
  	qinfo->dqi_blocksize_bits = V2_DQBLKSIZE_BITS;
  	qinfo->dqi_usable_bs = 1 << V2_DQBLKSIZE_BITS;
  	qinfo->dqi_qtree_depth = qtree_depth(qinfo);
498c60153   Jan Kara   quota: Implement ...
146
147
148
149
150
151
152
  	if (version == 0) {
  		qinfo->dqi_entry_size = sizeof(struct v2r0_disk_dqblk);
  		qinfo->dqi_ops = &v2r0_qtree_ops;
  	} else {
  		qinfo->dqi_entry_size = sizeof(struct v2r1_disk_dqblk);
  		qinfo->dqi_ops = &v2r1_qtree_ops;
  	}
e196311e0   Jan Kara   quota: Sanity-che...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
  	ret = -EUCLEAN;
  	/* Some sanity checks of the read headers... */
  	if ((loff_t)qinfo->dqi_blocks << qinfo->dqi_blocksize_bits >
  	    i_size_read(sb_dqopt(sb)->files[type])) {
  		quota_error(sb, "Number of blocks too big for quota file size (%llu > %llu).",
  		    (loff_t)qinfo->dqi_blocks << qinfo->dqi_blocksize_bits,
  		    i_size_read(sb_dqopt(sb)->files[type]));
  		goto out;
  	}
  	if (qinfo->dqi_free_blk >= qinfo->dqi_blocks) {
  		quota_error(sb, "Free block number too big (%u >= %u).",
  			    qinfo->dqi_free_blk, qinfo->dqi_blocks);
  		goto out;
  	}
  	if (qinfo->dqi_free_entry >= qinfo->dqi_blocks) {
  		quota_error(sb, "Block with free entry too big (%u >= %u).",
  			    qinfo->dqi_free_entry, qinfo->dqi_blocks);
  		goto out;
  	}
42fdb8583   Jan Kara   quota: Push dqio_...
172
173
174
175
  	ret = 0;
  out:
  	up_read(&dqopt->dqio_sem);
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
177
178
179
180
181
  }
  
  /* Write information header to quota file */
  static int v2_write_file_info(struct super_block *sb, int type)
  {
  	struct v2_disk_dqinfo dinfo;
9a8ae30e7   Jan Kara   quota: Push dqio_...
182
183
  	struct quota_info *dqopt = sb_dqopt(sb);
  	struct mem_dqinfo *info = &dqopt->info[type];
e3d4d56b9   Jan Kara   quota: Convert un...
184
  	struct qtree_mem_dqinfo *qinfo = info->dqi_priv;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
185
  	ssize_t size;
9a8ae30e7   Jan Kara   quota: Push dqio_...
186
  	down_write(&dqopt->dqio_sem);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
188
189
190
  	spin_lock(&dq_data_lock);
  	info->dqi_flags &= ~DQF_INFO_DIRTY;
  	dinfo.dqi_bgrace = cpu_to_le32(info->dqi_bgrace);
  	dinfo.dqi_igrace = cpu_to_le32(info->dqi_igrace);
c119c5b97   Jan Kara   quota: Don't stor...
191
192
  	/* No flags currently supported */
  	dinfo.dqi_flags = cpu_to_le32(0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193
  	spin_unlock(&dq_data_lock);
e3d4d56b9   Jan Kara   quota: Convert un...
194
195
196
  	dinfo.dqi_blocks = cpu_to_le32(qinfo->dqi_blocks);
  	dinfo.dqi_free_blk = cpu_to_le32(qinfo->dqi_free_blk);
  	dinfo.dqi_free_entry = cpu_to_le32(qinfo->dqi_free_entry);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
198
  	size = sb->s_op->quota_write(sb, type, (char *)&dinfo,
  	       sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF);
9a8ae30e7   Jan Kara   quota: Push dqio_...
199
  	up_write(&dqopt->dqio_sem);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
200
  	if (size != sizeof(struct v2_disk_dqinfo)) {
fb5ffb0e1   Jiaying Zhang   quota: Change quo...
201
  		quota_error(sb, "Can't write info structure");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
202
203
204
205
  		return -1;
  	}
  	return 0;
  }
498c60153   Jan Kara   quota: Implement ...
206
  static void v2r0_disk2memdqb(struct dquot *dquot, void *dp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
  {
498c60153   Jan Kara   quota: Implement ...
208
  	struct v2r0_disk_dqblk *d = dp, empty;
1ccd14b9c   Jan Kara   quota: Split off ...
209
  	struct mem_dqblk *m = &dquot->dq_dqb;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
210
211
212
213
  	m->dqb_ihardlimit = le32_to_cpu(d->dqb_ihardlimit);
  	m->dqb_isoftlimit = le32_to_cpu(d->dqb_isoftlimit);
  	m->dqb_curinodes = le32_to_cpu(d->dqb_curinodes);
  	m->dqb_itime = le64_to_cpu(d->dqb_itime);
12095460f   Jan Kara   quota: Increase s...
214
215
  	m->dqb_bhardlimit = v2_qbtos(le32_to_cpu(d->dqb_bhardlimit));
  	m->dqb_bsoftlimit = v2_qbtos(le32_to_cpu(d->dqb_bsoftlimit));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
216
217
  	m->dqb_curspace = le64_to_cpu(d->dqb_curspace);
  	m->dqb_btime = le64_to_cpu(d->dqb_btime);
1ccd14b9c   Jan Kara   quota: Split off ...
218
  	/* We need to escape back all-zero structure */
498c60153   Jan Kara   quota: Implement ...
219
  	memset(&empty, 0, sizeof(struct v2r0_disk_dqblk));
1ccd14b9c   Jan Kara   quota: Split off ...
220
  	empty.dqb_itime = cpu_to_le64(1);
498c60153   Jan Kara   quota: Implement ...
221
  	if (!memcmp(&empty, dp, sizeof(struct v2r0_disk_dqblk)))
1ccd14b9c   Jan Kara   quota: Split off ...
222
  		m->dqb_itime = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
  }
498c60153   Jan Kara   quota: Implement ...
224
  static void v2r0_mem2diskdqb(void *dp, struct dquot *dquot)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
225
  {
498c60153   Jan Kara   quota: Implement ...
226
  	struct v2r0_disk_dqblk *d = dp;
1ccd14b9c   Jan Kara   quota: Split off ...
227
228
  	struct mem_dqblk *m = &dquot->dq_dqb;
  	struct qtree_mem_dqinfo *info =
4c376dcae   Eric W. Biederman   userns: Convert s...
229
  			sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
1ccd14b9c   Jan Kara   quota: Split off ...
230

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
231
232
233
234
  	d->dqb_ihardlimit = cpu_to_le32(m->dqb_ihardlimit);
  	d->dqb_isoftlimit = cpu_to_le32(m->dqb_isoftlimit);
  	d->dqb_curinodes = cpu_to_le32(m->dqb_curinodes);
  	d->dqb_itime = cpu_to_le64(m->dqb_itime);
cf770c137   Jan Kara   quota: Move quota...
235
236
  	d->dqb_bhardlimit = cpu_to_le32(v2_stoqb(m->dqb_bhardlimit));
  	d->dqb_bsoftlimit = cpu_to_le32(v2_stoqb(m->dqb_bsoftlimit));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
238
  	d->dqb_curspace = cpu_to_le64(m->dqb_curspace);
  	d->dqb_btime = cpu_to_le64(m->dqb_btime);
4c376dcae   Eric W. Biederman   userns: Convert s...
239
  	d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id));
1ccd14b9c   Jan Kara   quota: Split off ...
240
241
  	if (qtree_entry_unused(info, dp))
  		d->dqb_itime = cpu_to_le64(1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242
  }
498c60153   Jan Kara   quota: Implement ...
243
244
245
246
  static int v2r0_is_id(void *dp, struct dquot *dquot)
  {
  	struct v2r0_disk_dqblk *d = dp;
  	struct qtree_mem_dqinfo *info =
4c376dcae   Eric W. Biederman   userns: Convert s...
247
  			sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
498c60153   Jan Kara   quota: Implement ...
248
249
250
  
  	if (qtree_entry_unused(info, dp))
  		return 0;
4c376dcae   Eric W. Biederman   userns: Convert s...
251
252
253
  	return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type,
  				le32_to_cpu(d->dqb_id)),
  		      dquot->dq_id);
498c60153   Jan Kara   quota: Implement ...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
  }
  
  static void v2r1_disk2memdqb(struct dquot *dquot, void *dp)
  {
  	struct v2r1_disk_dqblk *d = dp, empty;
  	struct mem_dqblk *m = &dquot->dq_dqb;
  
  	m->dqb_ihardlimit = le64_to_cpu(d->dqb_ihardlimit);
  	m->dqb_isoftlimit = le64_to_cpu(d->dqb_isoftlimit);
  	m->dqb_curinodes = le64_to_cpu(d->dqb_curinodes);
  	m->dqb_itime = le64_to_cpu(d->dqb_itime);
  	m->dqb_bhardlimit = v2_qbtos(le64_to_cpu(d->dqb_bhardlimit));
  	m->dqb_bsoftlimit = v2_qbtos(le64_to_cpu(d->dqb_bsoftlimit));
  	m->dqb_curspace = le64_to_cpu(d->dqb_curspace);
  	m->dqb_btime = le64_to_cpu(d->dqb_btime);
  	/* We need to escape back all-zero structure */
  	memset(&empty, 0, sizeof(struct v2r1_disk_dqblk));
  	empty.dqb_itime = cpu_to_le64(1);
  	if (!memcmp(&empty, dp, sizeof(struct v2r1_disk_dqblk)))
  		m->dqb_itime = 0;
  }
  
  static void v2r1_mem2diskdqb(void *dp, struct dquot *dquot)
  {
  	struct v2r1_disk_dqblk *d = dp;
  	struct mem_dqblk *m = &dquot->dq_dqb;
  	struct qtree_mem_dqinfo *info =
4c376dcae   Eric W. Biederman   userns: Convert s...
281
  			sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
498c60153   Jan Kara   quota: Implement ...
282
283
284
285
286
287
288
289
290
  
  	d->dqb_ihardlimit = cpu_to_le64(m->dqb_ihardlimit);
  	d->dqb_isoftlimit = cpu_to_le64(m->dqb_isoftlimit);
  	d->dqb_curinodes = cpu_to_le64(m->dqb_curinodes);
  	d->dqb_itime = cpu_to_le64(m->dqb_itime);
  	d->dqb_bhardlimit = cpu_to_le64(v2_stoqb(m->dqb_bhardlimit));
  	d->dqb_bsoftlimit = cpu_to_le64(v2_stoqb(m->dqb_bsoftlimit));
  	d->dqb_curspace = cpu_to_le64(m->dqb_curspace);
  	d->dqb_btime = cpu_to_le64(m->dqb_btime);
4c376dcae   Eric W. Biederman   userns: Convert s...
291
  	d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id));
3d3dc274c   Eric Dumazet   quota: clear padd...
292
  	d->dqb_pad = 0;
498c60153   Jan Kara   quota: Implement ...
293
294
295
296
297
  	if (qtree_entry_unused(info, dp))
  		d->dqb_itime = cpu_to_le64(1);
  }
  
  static int v2r1_is_id(void *dp, struct dquot *dquot)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
  {
498c60153   Jan Kara   quota: Implement ...
299
  	struct v2r1_disk_dqblk *d = dp;
1ccd14b9c   Jan Kara   quota: Split off ...
300
  	struct qtree_mem_dqinfo *info =
4c376dcae   Eric W. Biederman   userns: Convert s...
301
  			sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302

1ccd14b9c   Jan Kara   quota: Split off ...
303
  	if (qtree_entry_unused(info, dp))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304
  		return 0;
4c376dcae   Eric W. Biederman   userns: Convert s...
305
306
307
  	return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type,
  				le32_to_cpu(d->dqb_id)),
  		      dquot->dq_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
308
  }
1ccd14b9c   Jan Kara   quota: Split off ...
309
  static int v2_read_dquot(struct dquot *dquot)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
  {
e342e38df   Jan Kara   quota: Push dqio_...
311
312
313
314
315
316
317
318
319
  	struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
  	int ret;
  
  	down_read(&dqopt->dqio_sem);
  	ret = qtree_read_dquot(
  			sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv,
  			dquot);
  	up_read(&dqopt->dqio_sem);
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
320
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
321
322
  static int v2_write_dquot(struct dquot *dquot)
  {
8fc32c2b0   Jan Kara   quota: Push dqio_...
323
324
  	struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
  	int ret;
d2faa4151   Jan Kara   quota: Do not acq...
325
326
327
328
329
330
331
332
333
334
335
  	bool alloc = false;
  
  	/*
  	 * If space for dquot is already allocated, we don't need any
  	 * protection as we'll only overwrite the place of dquot. We are
  	 * still protected by concurrent writes of the same dquot by
  	 * dquot->dq_lock.
  	 */
  	if (!dquot->dq_off) {
  		alloc = true;
  		down_write(&dqopt->dqio_sem);
4c6bb6966   Jan Kara   quota: Fix quota ...
336
337
  	} else {
  		down_read(&dqopt->dqio_sem);
d2faa4151   Jan Kara   quota: Do not acq...
338
  	}
8fc32c2b0   Jan Kara   quota: Push dqio_...
339
340
341
  	ret = qtree_write_dquot(
  			sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv,
  			dquot);
d2faa4151   Jan Kara   quota: Do not acq...
342
343
  	if (alloc)
  		up_write(&dqopt->dqio_sem);
4c6bb6966   Jan Kara   quota: Fix quota ...
344
345
  	else
  		up_read(&dqopt->dqio_sem);
8fc32c2b0   Jan Kara   quota: Push dqio_...
346
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
349
  static int v2_release_dquot(struct dquot *dquot)
  {
b9a1a7f4b   Jan Kara   quota: Push dqio_...
350
351
352
353
354
355
356
357
  	struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
  	int ret;
  
  	down_write(&dqopt->dqio_sem);
  	ret = qtree_release_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot);
  	up_write(&dqopt->dqio_sem);
  
  	return ret;
e3d4d56b9   Jan Kara   quota: Convert un...
358
359
360
361
362
363
  }
  
  static int v2_free_file_info(struct super_block *sb, int type)
  {
  	kfree(sb_dqinfo(sb, type)->dqi_priv);
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364
  }
0066373d9   Jan Kara   quota_v2: Impleme...
365
366
  static int v2_get_next_id(struct super_block *sb, struct kqid *qid)
  {
f14618c68   Jan Kara   quota: Push dqio_...
367
368
369
370
371
372
373
  	struct quota_info *dqopt = sb_dqopt(sb);
  	int ret;
  
  	down_read(&dqopt->dqio_sem);
  	ret = qtree_get_next_id(sb_dqinfo(sb, qid->type)->dqi_priv, qid);
  	up_read(&dqopt->dqio_sem);
  	return ret;
0066373d9   Jan Kara   quota_v2: Impleme...
374
  }
1472da5fd   Alexey Dobriyan   const: struct quo...
375
  static const struct quota_format_ops v2_format_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
376
377
378
  	.check_quota_file	= v2_check_quota_file,
  	.read_file_info		= v2_read_file_info,
  	.write_file_info	= v2_write_file_info,
e3d4d56b9   Jan Kara   quota: Convert un...
379
  	.free_file_info		= v2_free_file_info,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
380
381
382
  	.read_dqblk		= v2_read_dquot,
  	.commit_dqblk		= v2_write_dquot,
  	.release_dqblk		= v2_release_dquot,
0066373d9   Jan Kara   quota_v2: Impleme...
383
  	.get_next_id		= v2_get_next_id,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
384
  };
498c60153   Jan Kara   quota: Implement ...
385
  static struct quota_format_type v2r0_quota_format = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
387
388
389
  	.qf_fmt_id	= QFMT_VFS_V0,
  	.qf_ops		= &v2_format_ops,
  	.qf_owner	= THIS_MODULE
  };
498c60153   Jan Kara   quota: Implement ...
390
391
392
393
394
  static struct quota_format_type v2r1_quota_format = {
  	.qf_fmt_id	= QFMT_VFS_V1,
  	.qf_ops		= &v2_format_ops,
  	.qf_owner	= THIS_MODULE
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
395
396
  static int __init init_v2_quota_format(void)
  {
498c60153   Jan Kara   quota: Implement ...
397
398
399
400
401
402
  	int ret;
  
  	ret = register_quota_format(&v2r0_quota_format);
  	if (ret)
  		return ret;
  	return register_quota_format(&v2r1_quota_format);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
403
404
405
406
  }
  
  static void __exit exit_v2_quota_format(void)
  {
498c60153   Jan Kara   quota: Implement ...
407
408
  	unregister_quota_format(&v2r0_quota_format);
  	unregister_quota_format(&v2r1_quota_format);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
411
412
  }
  
  module_init(init_v2_quota_format);
  module_exit(exit_v2_quota_format);