blob: c0187cda2c1ed3ff65b449a74aa71c05ca29eb58 [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 Karaf98bbe32017-08-17 19:20:28 +020068 if (size < 0)
69 return size;
70 return -EIO;
Jan Kara498c6012009-11-16 18:09:47 +010071 }
Jan Karaf98bbe32017-08-17 19:20:28 +020072 return 0;
Jan Kara498c6012009-11-16 18:09:47 +010073}
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/* Check whether given file is really vfsv0 quotafile */
76static int v2_check_quota_file(struct super_block *sb, int type)
77{
78 struct v2_disk_dqheader dqhead;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 static const uint quota_magics[] = V2_INITQMAGICS;
80 static const uint quota_versions[] = V2_INITQVERSIONS;
81
Jan Karaf98bbe32017-08-17 19:20:28 +020082 if (v2_read_header(sb, type, &dqhead))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type] ||
Jan Kara498c6012009-11-16 18:09:47 +010085 le32_to_cpu(dqhead.dqh_version) > quota_versions[type])
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return 0;
87 return 1;
88}
89
90/* Read information header from quota file */
91static int v2_read_file_info(struct super_block *sb, int type)
92{
93 struct v2_disk_dqinfo dinfo;
Jan Kara498c6012009-11-16 18:09:47 +010094 struct v2_disk_dqheader dqhead;
Jan Kara42fdb852017-06-09 08:59:46 +020095 struct quota_info *dqopt = sb_dqopt(sb);
96 struct mem_dqinfo *info = &dqopt->info[type];
Jan Karae3d4d562008-10-02 18:44:14 +020097 struct qtree_mem_dqinfo *qinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 ssize_t size;
Jan Kara498c6012009-11-16 18:09:47 +010099 unsigned int version;
Jan Kara42fdb852017-06-09 08:59:46 +0200100 int ret;
Jan Kara498c6012009-11-16 18:09:47 +0100101
Jan Kara42fdb852017-06-09 08:59:46 +0200102 down_read(&dqopt->dqio_sem);
Jan Karaf98bbe32017-08-17 19:20:28 +0200103 ret = v2_read_header(sb, type, &dqhead);
104 if (ret < 0)
Jan Kara42fdb852017-06-09 08:59:46 +0200105 goto out;
Jan Kara498c6012009-11-16 18:09:47 +0100106 version = le32_to_cpu(dqhead.dqh_version);
Jan Kara869835d2009-12-21 21:57:04 +0100107 if ((info->dqi_fmt_id == QFMT_VFS_V0 && version != 0) ||
Jan Kara42fdb852017-06-09 08:59:46 +0200108 (info->dqi_fmt_id == QFMT_VFS_V1 && version != 1)) {
Jan Karacb8d01b2017-06-09 09:04:47 +0200109 ret = -EINVAL;
Jan Kara42fdb852017-06-09 08:59:46 +0200110 goto out;
111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 size = sb->s_op->quota_read(sb, type, (char *)&dinfo,
114 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF);
115 if (size != sizeof(struct v2_disk_dqinfo)) {
Jiaying Zhangfb5ffb02010-07-20 16:54:43 +0200116 quota_error(sb, "Can't read info structure");
Jan Karaf98bbe32017-08-17 19:20:28 +0200117 if (size < 0)
118 ret = size;
119 else
120 ret = -EIO;
Jan Kara42fdb852017-06-09 08:59:46 +0200121 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
Jan Karae3d4d562008-10-02 18:44:14 +0200123 info->dqi_priv = kmalloc(sizeof(struct qtree_mem_dqinfo), GFP_NOFS);
124 if (!info->dqi_priv) {
Jan Kara42fdb852017-06-09 08:59:46 +0200125 ret = -ENOMEM;
126 goto out;
Jan Karae3d4d562008-10-02 18:44:14 +0200127 }
128 qinfo = info->dqi_priv;
Jan Kara498c6012009-11-16 18:09:47 +0100129 if (version == 0) {
130 /* limits are stored as unsigned 32-bit data */
Jan Kara7e08da52015-03-04 14:42:02 +0100131 info->dqi_max_spc_limit = 0xffffffffLL << QUOTABLOCK_BITS;
Jan Karab10a0812014-10-09 16:54:13 +0200132 info->dqi_max_ino_limit = 0xffffffff;
Jan Kara498c6012009-11-16 18:09:47 +0100133 } else {
Jan Kara7e08da52015-03-04 14:42:02 +0100134 /*
135 * Used space is stored as unsigned 64-bit value in bytes but
136 * quota core supports only signed 64-bit values so use that
137 * as a limit
138 */
139 info->dqi_max_spc_limit = 0x7fffffffffffffffLL; /* 2^63-1 */
140 info->dqi_max_ino_limit = 0x7fffffffffffffffLL;
Jan Kara498c6012009-11-16 18:09:47 +0100141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 info->dqi_bgrace = le32_to_cpu(dinfo.dqi_bgrace);
143 info->dqi_igrace = le32_to_cpu(dinfo.dqi_igrace);
Jan Karac119c5b2014-11-19 09:03:28 +0100144 /* No flags currently supported */
145 info->dqi_flags = 0;
Jan Karae3d4d562008-10-02 18:44:14 +0200146 qinfo->dqi_sb = sb;
147 qinfo->dqi_type = type;
148 qinfo->dqi_blocks = le32_to_cpu(dinfo.dqi_blocks);
149 qinfo->dqi_free_blk = le32_to_cpu(dinfo.dqi_free_blk);
150 qinfo->dqi_free_entry = le32_to_cpu(dinfo.dqi_free_entry);
151 qinfo->dqi_blocksize_bits = V2_DQBLKSIZE_BITS;
152 qinfo->dqi_usable_bs = 1 << V2_DQBLKSIZE_BITS;
153 qinfo->dqi_qtree_depth = qtree_depth(qinfo);
Jan Kara498c6012009-11-16 18:09:47 +0100154 if (version == 0) {
155 qinfo->dqi_entry_size = sizeof(struct v2r0_disk_dqblk);
156 qinfo->dqi_ops = &v2r0_qtree_ops;
157 } else {
158 qinfo->dqi_entry_size = sizeof(struct v2r1_disk_dqblk);
159 qinfo->dqi_ops = &v2r1_qtree_ops;
160 }
Jan Kara42fdb852017-06-09 08:59:46 +0200161 ret = 0;
162out:
163 up_read(&dqopt->dqio_sem);
164 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}
166
167/* Write information header to quota file */
168static int v2_write_file_info(struct super_block *sb, int type)
169{
170 struct v2_disk_dqinfo dinfo;
Jan Kara9a8ae302017-06-09 08:45:43 +0200171 struct quota_info *dqopt = sb_dqopt(sb);
172 struct mem_dqinfo *info = &dqopt->info[type];
Jan Karae3d4d562008-10-02 18:44:14 +0200173 struct qtree_mem_dqinfo *qinfo = info->dqi_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 ssize_t size;
175
Jan Kara9a8ae302017-06-09 08:45:43 +0200176 down_write(&dqopt->dqio_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 spin_lock(&dq_data_lock);
178 info->dqi_flags &= ~DQF_INFO_DIRTY;
179 dinfo.dqi_bgrace = cpu_to_le32(info->dqi_bgrace);
180 dinfo.dqi_igrace = cpu_to_le32(info->dqi_igrace);
Jan Karac119c5b2014-11-19 09:03:28 +0100181 /* No flags currently supported */
182 dinfo.dqi_flags = cpu_to_le32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 spin_unlock(&dq_data_lock);
Jan Karae3d4d562008-10-02 18:44:14 +0200184 dinfo.dqi_blocks = cpu_to_le32(qinfo->dqi_blocks);
185 dinfo.dqi_free_blk = cpu_to_le32(qinfo->dqi_free_blk);
186 dinfo.dqi_free_entry = cpu_to_le32(qinfo->dqi_free_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 size = sb->s_op->quota_write(sb, type, (char *)&dinfo,
188 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF);
Jan Kara9a8ae302017-06-09 08:45:43 +0200189 up_write(&dqopt->dqio_sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (size != sizeof(struct v2_disk_dqinfo)) {
Jiaying Zhangfb5ffb02010-07-20 16:54:43 +0200191 quota_error(sb, "Can't write info structure");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return -1;
193 }
194 return 0;
195}
196
Jan Kara498c6012009-11-16 18:09:47 +0100197static void v2r0_disk2memdqb(struct dquot *dquot, void *dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Jan Kara498c6012009-11-16 18:09:47 +0100199 struct v2r0_disk_dqblk *d = dp, empty;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200200 struct mem_dqblk *m = &dquot->dq_dqb;
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 m->dqb_ihardlimit = le32_to_cpu(d->dqb_ihardlimit);
203 m->dqb_isoftlimit = le32_to_cpu(d->dqb_isoftlimit);
204 m->dqb_curinodes = le32_to_cpu(d->dqb_curinodes);
205 m->dqb_itime = le64_to_cpu(d->dqb_itime);
Jan Kara12095462008-08-20 14:45:12 +0200206 m->dqb_bhardlimit = v2_qbtos(le32_to_cpu(d->dqb_bhardlimit));
207 m->dqb_bsoftlimit = v2_qbtos(le32_to_cpu(d->dqb_bsoftlimit));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 m->dqb_curspace = le64_to_cpu(d->dqb_curspace);
209 m->dqb_btime = le64_to_cpu(d->dqb_btime);
Jan Kara1ccd14b2008-09-22 05:54:49 +0200210 /* We need to escape back all-zero structure */
Jan Kara498c6012009-11-16 18:09:47 +0100211 memset(&empty, 0, sizeof(struct v2r0_disk_dqblk));
Jan Kara1ccd14b2008-09-22 05:54:49 +0200212 empty.dqb_itime = cpu_to_le64(1);
Jan Kara498c6012009-11-16 18:09:47 +0100213 if (!memcmp(&empty, dp, sizeof(struct v2r0_disk_dqblk)))
Jan Kara1ccd14b2008-09-22 05:54:49 +0200214 m->dqb_itime = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
Jan Kara498c6012009-11-16 18:09:47 +0100217static void v2r0_mem2diskdqb(void *dp, struct dquot *dquot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Jan Kara498c6012009-11-16 18:09:47 +0100219 struct v2r0_disk_dqblk *d = dp;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200220 struct mem_dqblk *m = &dquot->dq_dqb;
221 struct qtree_mem_dqinfo *info =
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700222 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 d->dqb_ihardlimit = cpu_to_le32(m->dqb_ihardlimit);
225 d->dqb_isoftlimit = cpu_to_le32(m->dqb_isoftlimit);
226 d->dqb_curinodes = cpu_to_le32(m->dqb_curinodes);
227 d->dqb_itime = cpu_to_le64(m->dqb_itime);
Jan Karacf770c12008-09-21 23:17:53 +0200228 d->dqb_bhardlimit = cpu_to_le32(v2_stoqb(m->dqb_bhardlimit));
229 d->dqb_bsoftlimit = cpu_to_le32(v2_stoqb(m->dqb_bsoftlimit));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 d->dqb_curspace = cpu_to_le64(m->dqb_curspace);
231 d->dqb_btime = cpu_to_le64(m->dqb_btime);
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700232 d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id));
Jan Kara1ccd14b2008-09-22 05:54:49 +0200233 if (qtree_entry_unused(info, dp))
234 d->dqb_itime = cpu_to_le64(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
Jan Kara498c6012009-11-16 18:09:47 +0100237static int v2r0_is_id(void *dp, struct dquot *dquot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
Jan Kara498c6012009-11-16 18:09:47 +0100239 struct v2r0_disk_dqblk *d = dp;
240 struct qtree_mem_dqinfo *info =
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700241 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
Jan Kara498c6012009-11-16 18:09:47 +0100242
243 if (qtree_entry_unused(info, dp))
244 return 0;
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700245 return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type,
246 le32_to_cpu(d->dqb_id)),
247 dquot->dq_id);
Jan Kara498c6012009-11-16 18:09:47 +0100248}
249
250static void v2r1_disk2memdqb(struct dquot *dquot, void *dp)
251{
252 struct v2r1_disk_dqblk *d = dp, empty;
253 struct mem_dqblk *m = &dquot->dq_dqb;
254
255 m->dqb_ihardlimit = le64_to_cpu(d->dqb_ihardlimit);
256 m->dqb_isoftlimit = le64_to_cpu(d->dqb_isoftlimit);
257 m->dqb_curinodes = le64_to_cpu(d->dqb_curinodes);
258 m->dqb_itime = le64_to_cpu(d->dqb_itime);
259 m->dqb_bhardlimit = v2_qbtos(le64_to_cpu(d->dqb_bhardlimit));
260 m->dqb_bsoftlimit = v2_qbtos(le64_to_cpu(d->dqb_bsoftlimit));
261 m->dqb_curspace = le64_to_cpu(d->dqb_curspace);
262 m->dqb_btime = le64_to_cpu(d->dqb_btime);
263 /* We need to escape back all-zero structure */
264 memset(&empty, 0, sizeof(struct v2r1_disk_dqblk));
265 empty.dqb_itime = cpu_to_le64(1);
266 if (!memcmp(&empty, dp, sizeof(struct v2r1_disk_dqblk)))
267 m->dqb_itime = 0;
268}
269
270static void v2r1_mem2diskdqb(void *dp, struct dquot *dquot)
271{
272 struct v2r1_disk_dqblk *d = dp;
273 struct mem_dqblk *m = &dquot->dq_dqb;
274 struct qtree_mem_dqinfo *info =
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700275 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
Jan Kara498c6012009-11-16 18:09:47 +0100276
277 d->dqb_ihardlimit = cpu_to_le64(m->dqb_ihardlimit);
278 d->dqb_isoftlimit = cpu_to_le64(m->dqb_isoftlimit);
279 d->dqb_curinodes = cpu_to_le64(m->dqb_curinodes);
280 d->dqb_itime = cpu_to_le64(m->dqb_itime);
281 d->dqb_bhardlimit = cpu_to_le64(v2_stoqb(m->dqb_bhardlimit));
282 d->dqb_bsoftlimit = cpu_to_le64(v2_stoqb(m->dqb_bsoftlimit));
283 d->dqb_curspace = cpu_to_le64(m->dqb_curspace);
284 d->dqb_btime = cpu_to_le64(m->dqb_btime);
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700285 d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id));
Jan Kara498c6012009-11-16 18:09:47 +0100286 if (qtree_entry_unused(info, dp))
287 d->dqb_itime = cpu_to_le64(1);
288}
289
290static int v2r1_is_id(void *dp, struct dquot *dquot)
291{
292 struct v2r1_disk_dqblk *d = dp;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200293 struct qtree_mem_dqinfo *info =
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700294 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Jan Kara1ccd14b2008-09-22 05:54:49 +0200296 if (qtree_entry_unused(info, dp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 return 0;
Eric W. Biederman4c376dc2012-09-16 03:56:19 -0700298 return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type,
299 le32_to_cpu(d->dqb_id)),
300 dquot->dq_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
303static int v2_read_dquot(struct dquot *dquot)
304{
Jan Karae342e382017-06-08 15:30:45 +0200305 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
306 int ret;
307
308 down_read(&dqopt->dqio_sem);
309 ret = qtree_read_dquot(
310 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv,
311 dquot);
312 up_read(&dqopt->dqio_sem);
313 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
Jan Kara1ccd14b2008-09-22 05:54:49 +0200316static int v2_write_dquot(struct dquot *dquot)
317{
Jan Kara8fc32c22017-06-08 15:48:16 +0200318 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
319 int ret;
Jan Karad2faa412017-06-08 16:09:46 +0200320 bool alloc = false;
Jan Kara8fc32c22017-06-08 15:48:16 +0200321
Jan Karad2faa412017-06-08 16:09:46 +0200322 /*
323 * If space for dquot is already allocated, we don't need any
324 * protection as we'll only overwrite the place of dquot. We are
325 * still protected by concurrent writes of the same dquot by
326 * dquot->dq_lock.
327 */
328 if (!dquot->dq_off) {
329 alloc = true;
330 down_write(&dqopt->dqio_sem);
331 }
Jan Kara8fc32c22017-06-08 15:48:16 +0200332 ret = qtree_write_dquot(
333 sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv,
334 dquot);
Jan Karad2faa412017-06-08 16:09:46 +0200335 if (alloc)
336 up_write(&dqopt->dqio_sem);
Jan Kara8fc32c22017-06-08 15:48:16 +0200337 return ret;
Jan Kara1ccd14b2008-09-22 05:54:49 +0200338}
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340static int v2_release_dquot(struct dquot *dquot)
341{
Jan Karab9a1a7f2017-06-08 17:20:36 +0200342 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
343 int ret;
344
345 down_write(&dqopt->dqio_sem);
346 ret = qtree_release_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot);
347 up_write(&dqopt->dqio_sem);
348
349 return ret;
Jan Karae3d4d562008-10-02 18:44:14 +0200350}
351
352static int v2_free_file_info(struct super_block *sb, int type)
353{
354 kfree(sb_dqinfo(sb, type)->dqi_priv);
355 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356}
357
Jan Kara00663732016-01-25 20:39:27 +0100358static int v2_get_next_id(struct super_block *sb, struct kqid *qid)
359{
Jan Karaf14618c2017-06-09 08:36:16 +0200360 struct quota_info *dqopt = sb_dqopt(sb);
361 int ret;
362
363 down_read(&dqopt->dqio_sem);
364 ret = qtree_get_next_id(sb_dqinfo(sb, qid->type)->dqi_priv, qid);
365 up_read(&dqopt->dqio_sem);
366 return ret;
Jan Kara00663732016-01-25 20:39:27 +0100367}
368
Alexey Dobriyan1472da52009-10-16 15:26:03 +0400369static const struct quota_format_ops v2_format_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 .check_quota_file = v2_check_quota_file,
371 .read_file_info = v2_read_file_info,
372 .write_file_info = v2_write_file_info,
Jan Karae3d4d562008-10-02 18:44:14 +0200373 .free_file_info = v2_free_file_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 .read_dqblk = v2_read_dquot,
375 .commit_dqblk = v2_write_dquot,
376 .release_dqblk = v2_release_dquot,
Jan Kara00663732016-01-25 20:39:27 +0100377 .get_next_id = v2_get_next_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378};
379
Jan Kara498c6012009-11-16 18:09:47 +0100380static struct quota_format_type v2r0_quota_format = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 .qf_fmt_id = QFMT_VFS_V0,
382 .qf_ops = &v2_format_ops,
383 .qf_owner = THIS_MODULE
384};
385
Jan Kara498c6012009-11-16 18:09:47 +0100386static struct quota_format_type v2r1_quota_format = {
387 .qf_fmt_id = QFMT_VFS_V1,
388 .qf_ops = &v2_format_ops,
389 .qf_owner = THIS_MODULE
390};
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392static int __init init_v2_quota_format(void)
393{
Jan Kara498c6012009-11-16 18:09:47 +0100394 int ret;
395
396 ret = register_quota_format(&v2r0_quota_format);
397 if (ret)
398 return ret;
399 return register_quota_format(&v2r1_quota_format);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
402static void __exit exit_v2_quota_format(void)
403{
Jan Kara498c6012009-11-16 18:09:47 +0100404 unregister_quota_format(&v2r0_quota_format);
405 unregister_quota_format(&v2r1_quota_format);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406}
407
408module_init(init_v2_quota_format);
409module_exit(exit_v2_quota_format);