blob: 21a8bdf7cfec692adf52012e1f61bcd521ab92c7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * vfsv0 quota IO operations on file
3 */
4
5#include <linux/errno.h>
6#include <linux/fs.h>
7#include <linux/mount.h>
8#include <linux/dqblk_v2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/kernel.h>
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/slab.h>
Jan Kara74abb982008-07-25 01:46:51 -070013#include <linux/quotaops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include <asm/byteorder.h>
16
Jan Kara1ccd14b2008-09-22 05:54:49 +020017#include "quota_tree.h"
Jan Karacf770c12008-09-21 23:17:53 +020018#include "quotaio_v2.h"
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020MODULE_AUTHOR("Jan Kara");
21MODULE_DESCRIPTION("Quota format v2 support");
22MODULE_LICENSE("GPL");
23
24#define __QUOTA_V2_PARANOIA
25
Jan Kara498c6012009-11-16 18:09:47 +010026static void v2r0_mem2diskdqb(void *dp, struct dquot *dquot);
27static void v2r0_disk2memdqb(struct dquot *dquot, void *dp);
28static int v2r0_is_id(void *dp, struct dquot *dquot);
29static void v2r1_mem2diskdqb(void *dp, struct dquot *dquot);
30static void v2r1_disk2memdqb(struct dquot *dquot, void *dp);
31static int v2r1_is_id(void *dp, struct dquot *dquot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Julia Lawalld1b98c22016-01-01 08:53:37 +010033static const struct qtree_fmt_operations v2r0_qtree_ops = {
Jan Kara498c6012009-11-16 18:09:47 +010034 .mem2disk_dqblk = v2r0_mem2diskdqb,
35 .disk2mem_dqblk = v2r0_disk2memdqb,
36 .is_id = v2r0_is_id,
37};
38
Julia Lawalld1b98c22016-01-01 08:53:37 +010039static const struct qtree_fmt_operations v2r1_qtree_ops = {
Jan Kara498c6012009-11-16 18:09:47 +010040 .mem2disk_dqblk = v2r1_mem2diskdqb,
41 .disk2mem_dqblk = v2r1_disk2memdqb,
42 .is_id = v2r1_is_id,
Jan Kara1ccd14b2008-09-22 05:54:49 +020043};
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Jan Kara12095462008-08-20 14:45:12 +020045#define QUOTABLOCK_BITS 10
46#define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
47
48static inline qsize_t v2_stoqb(qsize_t space)
49{
50 return (space + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS;
51}
52
53static inline qsize_t v2_qbtos(qsize_t blocks)
54{
55 return blocks << QUOTABLOCK_BITS;
56}
57
Jan Kara498c6012009-11-16 18:09:47 +010058static int v2_read_header(struct super_block *sb, int type,
59 struct v2_disk_dqheader *dqhead)
60{
61 ssize_t size;
62
63 size = sb->s_op->quota_read(sb, type, (char *)dqhead,
64 sizeof(struct v2_disk_dqheader), 0);
65 if (size != sizeof(struct v2_disk_dqheader)) {
Jiaying Zhangfb5ffb02010-07-20 16:54:43 +020066 quota_error(sb, "Failed header read: expected=%zd got=%zd",
67 sizeof(struct v2_disk_dqheader), size);
Jan Kara498c6012009-11-16 18:09:47 +010068 return 0;
69 }
70 return 1;
71}
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* Check whether given file is really vfsv0 quotafile */
74static int v2_check_quota_file(struct super_block *sb, int type)
75{
76 struct v2_disk_dqheader dqhead;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 static const uint quota_magics[] = V2_INITQMAGICS;
78 static const uint quota_versions[] = V2_INITQVERSIONS;
79
Jan Kara498c6012009-11-16 18:09:47 +010080 if (!v2_read_header(sb, type, &dqhead))
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type] ||
Jan Kara498c6012009-11-16 18:09:47 +010083 le32_to_cpu(dqhead.dqh_version) > quota_versions[type])
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 return 0;
85 return 1;
86}
87
88/* Read information header from quota file */
89static int v2_read_file_info(struct super_block *sb, int type)
90{
91 struct v2_disk_dqinfo dinfo;
Jan Kara498c6012009-11-16 18:09:47 +010092 struct v2_disk_dqheader dqhead;
Jan Kara42fdb852017-06-09 08:59:46 +020093 struct quota_info *dqopt = sb_dqopt(sb);
94 struct mem_dqinfo *info = &dqopt->info[type];
Jan Karae3d4d562008-10-02 18:44:14 +020095 struct qtree_mem_dqinfo *qinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 ssize_t size;
Jan Kara498c6012009-11-16 18:09:47 +010097 unsigned int version;
Jan Kara42fdb852017-06-09 08:59:46 +020098 int ret;
Jan Kara498c6012009-11-16 18:09:47 +010099
Jan Kara42fdb852017-06-09 08:59:46 +0200100 down_read(&dqopt->dqio_sem);
101 if (!v2_read_header(sb, type, &dqhead)) {
Jan Karacb8d01b2017-06-09 09:04:47 +0200102 ret = -EIO;
Jan Kara42fdb852017-06-09 08:59:46 +0200103 goto out;
104 }
Jan Kara498c6012009-11-16 18:09:47 +0100105 version = le32_to_cpu(dqhead.dqh_version);
Jan Kara869835d2009-12-21 21:57:04 +0100106 if ((info->dqi_fmt_id == QFMT_VFS_V0 && version != 0) ||
Jan Kara42fdb852017-06-09 08:59:46 +0200107 (info->dqi_fmt_id == QFMT_VFS_V1 && version != 1)) {
Jan Karacb8d01b2017-06-09 09:04:47 +0200108 ret = -EINVAL;
Jan Kara42fdb852017-06-09 08:59:46 +0200109 goto out;
110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112 size = sb->s_op->quota_read(sb, type, (char *)&dinfo,
113 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF);
114 if (size != sizeof(struct v2_disk_dqinfo)) {
Jiaying Zhangfb5ffb02010-07-20 16:54:43 +0200115 quota_error(sb, "Can't read info structure");
Jan Karacb8d01b2017-06-09 09:04:47 +0200116 ret = -EIO;
Jan Kara42fdb852017-06-09 08:59:46 +0200117 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
Jan Karae3d4d562008-10-02 18:44:14 +0200119 info->dqi_priv = kmalloc(sizeof(struct qtree_mem_dqinfo), GFP_NOFS);
120 if (!info->dqi_priv) {
121 printk(KERN_WARNING
122 "Not enough memory for quota information structure.\n");
Jan Kara42fdb852017-06-09 08:59:46 +0200123 ret = -ENOMEM;
124 goto out;
Jan Karae3d4d562008-10-02 18:44:14 +0200125 }
126 qinfo = info->dqi_priv;
Jan Kara498c6012009-11-16 18:09:47 +0100127 if (version == 0) {
128 /* limits are stored as unsigned 32-bit data */
Jan Kara7e08da52015-03-04 14:42:02 +0100129 info->dqi_max_spc_limit = 0xffffffffLL << QUOTABLOCK_BITS;
Jan Karab10a0812014-10-09 16:54:13 +0200130 info->dqi_max_ino_limit = 0xffffffff;
Jan Kara498c6012009-11-16 18:09:47 +0100131 } else {
Jan Kara7e08da52015-03-04 14:42:02 +0100132 /*
133 * Used space is stored as unsigned 64-bit value in bytes but
134 * quota core supports only signed 64-bit values so use that
135 * as a limit
136 */
137 info->dqi_max_spc_limit = 0x7fffffffffffffffLL; /* 2^63-1 */
138 info->dqi_max_ino_limit = 0x7fffffffffffffffLL;
Jan Kara498c6012009-11-16 18:09:47 +0100139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 info->dqi_bgrace = le32_to_cpu(dinfo.dqi_bgrace);
141 info->dqi_igrace = le32_to_cpu(dinfo.dqi_igrace);
Jan Karac119c5b2014-11-19 09:03:28 +0100142 /* No flags currently supported */
143 info->dqi_flags = 0;
Jan Karae3d4d562008-10-02 18:44:14 +0200144 qinfo->dqi_sb = sb;
145 qinfo->dqi_type = type;
146 qinfo->dqi_blocks = le32_to_cpu(dinfo.dqi_blocks);
147 qinfo->dqi_free_blk = le32_to_cpu(dinfo.dqi_free_blk);
148 qinfo->dqi_free_entry = le32_to_cpu(dinfo.dqi_free_entry);
149 qinfo->dqi_blocksize_bits = V2_DQBLKSIZE_BITS;
150 qinfo->dqi_usable_bs = 1 << V2_DQBLKSIZE_BITS;
151 qinfo->dqi_qtree_depth = qtree_depth(qinfo);
Jan Kara498c6012009-11-16 18:09:47 +0100152 if (version == 0) {
153 qinfo->dqi_entry_size = sizeof(struct v2r0_disk_dqblk);
154 qinfo->dqi_ops = &v2r0_qtree_ops;
155 } else {
156 qinfo->dqi_entry_size = sizeof(struct v2r1_disk_dqblk);
157 qinfo->dqi_ops = &v2r1_qtree_ops;
158 }
Jan Kara42fdb852017-06-09 08:59:46 +0200159 ret = 0;
160out:
161 up_read(&dqopt->dqio_sem);
162 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165/* Write information header to quota file */
166static int v2_write_file_info(struct super_block *sb, int type)
167{
168 struct v2_disk_dqinfo dinfo;
Jan Kara9a8ae302017-06-09 08:45:43 +0200169 struct quota_info *dqopt = sb_dqopt(sb);
170 struct mem_dqinfo *info = &dqopt->info[type];
Jan Karae3d4d562008-10-02 18:44:14 +0200171 struct qtree_mem_dqinfo *qinfo = info->dqi_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 ssize_t size;
173
Jan Kara9a8ae302017-06-09 08:45:43 +0200174 down_write(&dqopt->dqio_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 spin_lock(&dq_data_lock);
176 info->dqi_flags &= ~DQF_INFO_DIRTY;
177 dinfo.dqi_bgrace = cpu_to_le32(info->dqi_bgrace);
178 dinfo.dqi_igrace = cpu_to_le32(info->dqi_igrace);
Jan Karac119c5b2014-11-19 09:03:28 +0100179 /* No flags currently supported */
180 dinfo.dqi_flags = cpu_to_le32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 spin_unlock(&dq_data_lock);
Jan Karae3d4d562008-10-02 18:44:14 +0200182 dinfo.dqi_blocks = cpu_to_le32(qinfo->dqi_blocks);
183 dinfo.dqi_free_blk = cpu_to_le32(qinfo->dqi_free_blk);
184 dinfo.dqi_free_entry = cpu_to_le32(qinfo->dqi_free_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 size = sb->s_op->quota_write(sb, type, (char *)&dinfo,
186 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF);
Jan Kara9a8ae302017-06-09 08:45:43 +0200187 up_write(&dqopt->dqio_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 if (size != sizeof(struct v2_disk_dqinfo)) {
Jiaying Zhangfb5ffb02010-07-20 16:54:43 +0200189 quota_error(sb, "Can't write info structure");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 return -1;
191 }
192 return 0;
193}
194
Jan Kara498c6012009-11-16 18:09:47 +0100195static void v2r0_disk2memdqb(struct dquot *dquot, void *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Jan Kara498c6012009-11-16 18:09:47 +0100197 struct v2r0_disk_dqblk *d = dp, empty;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200198 struct mem_dqblk *m = &dquot->dq_dqb;
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 m->dqb_ihardlimit = le32_to_cpu(d->dqb_ihardlimit);
201 m->dqb_isoftlimit = le32_to_cpu(d->dqb_isoftlimit);
202 m->dqb_curinodes = le32_to_cpu(d->dqb_curinodes);
203 m->dqb_itime = le64_to_cpu(d->dqb_itime);
Jan Kara12095462008-08-20 14:45:12 +0200204 m->dqb_bhardlimit = v2_qbtos(le32_to_cpu(d->dqb_bhardlimit));
205 m->dqb_bsoftlimit = v2_qbtos(le32_to_cpu(d->dqb_bsoftlimit));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 m->dqb_curspace = le64_to_cpu(d->dqb_curspace);
207 m->dqb_btime = le64_to_cpu(d->dqb_btime);
Jan Kara1ccd14b2008-09-22 05:54:49 +0200208 /* We need to escape back all-zero structure */
Jan Kara498c6012009-11-16 18:09:47 +0100209 memset(&empty, 0, sizeof(struct v2r0_disk_dqblk));
Jan Kara1ccd14b2008-09-22 05:54:49 +0200210 empty.dqb_itime = cpu_to_le64(1);
Jan Kara498c6012009-11-16 18:09:47 +0100211 if (!memcmp(&empty, dp, sizeof(struct v2r0_disk_dqblk)))
Jan Kara1ccd14b2008-09-22 05:54:49 +0200212 m->dqb_itime = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
Jan Kara498c6012009-11-16 18:09:47 +0100215static void v2r0_mem2diskdqb(void *dp, struct dquot *dquot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Jan Kara498c6012009-11-16 18:09:47 +0100217 struct v2r0_disk_dqblk *d = dp;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200218 struct mem_dqblk *m = &dquot->dq_dqb;
219 struct qtree_mem_dqinfo *info =
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700220 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 d->dqb_ihardlimit = cpu_to_le32(m->dqb_ihardlimit);
223 d->dqb_isoftlimit = cpu_to_le32(m->dqb_isoftlimit);
224 d->dqb_curinodes = cpu_to_le32(m->dqb_curinodes);
225 d->dqb_itime = cpu_to_le64(m->dqb_itime);
Jan Karacf770c12008-09-21 23:17:53 +0200226 d->dqb_bhardlimit = cpu_to_le32(v2_stoqb(m->dqb_bhardlimit));
227 d->dqb_bsoftlimit = cpu_to_le32(v2_stoqb(m->dqb_bsoftlimit));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 d->dqb_curspace = cpu_to_le64(m->dqb_curspace);
229 d->dqb_btime = cpu_to_le64(m->dqb_btime);
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700230 d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id));
Jan Kara1ccd14b2008-09-22 05:54:49 +0200231 if (qtree_entry_unused(info, dp))
232 d->dqb_itime = cpu_to_le64(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
Jan Kara498c6012009-11-16 18:09:47 +0100235static int v2r0_is_id(void *dp, struct dquot *dquot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Jan Kara498c6012009-11-16 18:09:47 +0100237 struct v2r0_disk_dqblk *d = dp;
238 struct qtree_mem_dqinfo *info =
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700239 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
Jan Kara498c6012009-11-16 18:09:47 +0100240
241 if (qtree_entry_unused(info, dp))
242 return 0;
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700243 return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type,
244 le32_to_cpu(d->dqb_id)),
245 dquot->dq_id);
Jan Kara498c6012009-11-16 18:09:47 +0100246}
247
248static void v2r1_disk2memdqb(struct dquot *dquot, void *dp)
249{
250 struct v2r1_disk_dqblk *d = dp, empty;
251 struct mem_dqblk *m = &dquot->dq_dqb;
252
253 m->dqb_ihardlimit = le64_to_cpu(d->dqb_ihardlimit);
254 m->dqb_isoftlimit = le64_to_cpu(d->dqb_isoftlimit);
255 m->dqb_curinodes = le64_to_cpu(d->dqb_curinodes);
256 m->dqb_itime = le64_to_cpu(d->dqb_itime);
257 m->dqb_bhardlimit = v2_qbtos(le64_to_cpu(d->dqb_bhardlimit));
258 m->dqb_bsoftlimit = v2_qbtos(le64_to_cpu(d->dqb_bsoftlimit));
259 m->dqb_curspace = le64_to_cpu(d->dqb_curspace);
260 m->dqb_btime = le64_to_cpu(d->dqb_btime);
261 /* We need to escape back all-zero structure */
262 memset(&empty, 0, sizeof(struct v2r1_disk_dqblk));
263 empty.dqb_itime = cpu_to_le64(1);
264 if (!memcmp(&empty, dp, sizeof(struct v2r1_disk_dqblk)))
265 m->dqb_itime = 0;
266}
267
268static void v2r1_mem2diskdqb(void *dp, struct dquot *dquot)
269{
270 struct v2r1_disk_dqblk *d = dp;
271 struct mem_dqblk *m = &dquot->dq_dqb;
272 struct qtree_mem_dqinfo *info =
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700273 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
Jan Kara498c6012009-11-16 18:09:47 +0100274
275 d->dqb_ihardlimit = cpu_to_le64(m->dqb_ihardlimit);
276 d->dqb_isoftlimit = cpu_to_le64(m->dqb_isoftlimit);
277 d->dqb_curinodes = cpu_to_le64(m->dqb_curinodes);
278 d->dqb_itime = cpu_to_le64(m->dqb_itime);
279 d->dqb_bhardlimit = cpu_to_le64(v2_stoqb(m->dqb_bhardlimit));
280 d->dqb_bsoftlimit = cpu_to_le64(v2_stoqb(m->dqb_bsoftlimit));
281 d->dqb_curspace = cpu_to_le64(m->dqb_curspace);
282 d->dqb_btime = cpu_to_le64(m->dqb_btime);
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700283 d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id));
Jan Kara498c6012009-11-16 18:09:47 +0100284 if (qtree_entry_unused(info, dp))
285 d->dqb_itime = cpu_to_le64(1);
286}
287
288static int v2r1_is_id(void *dp, struct dquot *dquot)
289{
290 struct v2r1_disk_dqblk *d = dp;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200291 struct qtree_mem_dqinfo *info =
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700292 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Jan Kara1ccd14b2008-09-22 05:54:49 +0200294 if (qtree_entry_unused(info, dp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 return 0;
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700296 return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type,
297 le32_to_cpu(d->dqb_id)),
298 dquot->dq_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
301static int v2_read_dquot(struct dquot *dquot)
302{
Jan Karae342e382017-06-08 15:30:45 +0200303 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
304 int ret;
305
306 down_read(&dqopt->dqio_sem);
307 ret = qtree_read_dquot(
308 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv,
309 dquot);
310 up_read(&dqopt->dqio_sem);
311 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
Jan Kara1ccd14b2008-09-22 05:54:49 +0200314static int v2_write_dquot(struct dquot *dquot)
315{
Jan Kara8fc32c22017-06-08 15:48:16 +0200316 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
317 int ret;
Jan Karad2faa412017-06-08 16:09:46 +0200318 bool alloc = false;
Jan Kara8fc32c22017-06-08 15:48:16 +0200319
Jan Karad2faa412017-06-08 16:09:46 +0200320 /*
321 * If space for dquot is already allocated, we don't need any
322 * protection as we'll only overwrite the place of dquot. We are
323 * still protected by concurrent writes of the same dquot by
324 * dquot->dq_lock.
325 */
326 if (!dquot->dq_off) {
327 alloc = true;
328 down_write(&dqopt->dqio_sem);
329 }
Jan Kara8fc32c22017-06-08 15:48:16 +0200330 ret = qtree_write_dquot(
331 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv,
332 dquot);
Jan Karad2faa412017-06-08 16:09:46 +0200333 if (alloc)
334 up_write(&dqopt->dqio_sem);
Jan Kara8fc32c22017-06-08 15:48:16 +0200335 return ret;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200336}
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338static int v2_release_dquot(struct dquot *dquot)
339{
Jan Karab9a1a7f2017-06-08 17:20:36 +0200340 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
341 int ret;
342
343 down_write(&dqopt->dqio_sem);
344 ret = qtree_release_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot);
345 up_write(&dqopt->dqio_sem);
346
347 return ret;
Jan Karae3d4d562008-10-02 18:44:14 +0200348}
349
350static int v2_free_file_info(struct super_block *sb, int type)
351{
352 kfree(sb_dqinfo(sb, type)->dqi_priv);
353 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
Jan Kara00663732016-01-25 20:39:27 +0100356static int v2_get_next_id(struct super_block *sb, struct kqid *qid)
357{
Jan Karaf14618c2017-06-09 08:36:16 +0200358 struct quota_info *dqopt = sb_dqopt(sb);
359 int ret;
360
361 down_read(&dqopt->dqio_sem);
362 ret = qtree_get_next_id(sb_dqinfo(sb, qid->type)->dqi_priv, qid);
363 up_read(&dqopt->dqio_sem);
364 return ret;
Jan Kara00663732016-01-25 20:39:27 +0100365}
366
Alexey Dobriyan1472da52009-10-16 15:26:03 +0400367static const struct quota_format_ops v2_format_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 .check_quota_file = v2_check_quota_file,
369 .read_file_info = v2_read_file_info,
370 .write_file_info = v2_write_file_info,
Jan Karae3d4d562008-10-02 18:44:14 +0200371 .free_file_info = v2_free_file_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 .read_dqblk = v2_read_dquot,
373 .commit_dqblk = v2_write_dquot,
374 .release_dqblk = v2_release_dquot,
Jan Kara00663732016-01-25 20:39:27 +0100375 .get_next_id = v2_get_next_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376};
377
Jan Kara498c6012009-11-16 18:09:47 +0100378static struct quota_format_type v2r0_quota_format = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 .qf_fmt_id = QFMT_VFS_V0,
380 .qf_ops = &v2_format_ops,
381 .qf_owner = THIS_MODULE
382};
383
Jan Kara498c6012009-11-16 18:09:47 +0100384static struct quota_format_type v2r1_quota_format = {
385 .qf_fmt_id = QFMT_VFS_V1,
386 .qf_ops = &v2_format_ops,
387 .qf_owner = THIS_MODULE
388};
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390static int __init init_v2_quota_format(void)
391{
Jan Kara498c6012009-11-16 18:09:47 +0100392 int ret;
393
394 ret = register_quota_format(&v2r0_quota_format);
395 if (ret)
396 return ret;
397 return register_quota_format(&v2r1_quota_format);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
400static void __exit exit_v2_quota_format(void)
401{
Jan Kara498c6012009-11-16 18:09:47 +0100402 unregister_quota_format(&v2r0_quota_format);
403 unregister_quota_format(&v2r1_quota_format);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
405
406module_init(init_v2_quota_format);
407module_exit(exit_v2_quota_format);