Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/kernel.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/slab.h> |
Jan Kara | 74abb98 | 2008-07-25 01:46:51 -0700 | [diff] [blame] | 13 | #include <linux/quotaops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include <asm/byteorder.h> |
| 16 | |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 17 | #include "quota_tree.h" |
Jan Kara | cf770c1 | 2008-09-21 23:17:53 +0200 | [diff] [blame] | 18 | #include "quotaio_v2.h" |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | MODULE_AUTHOR("Jan Kara"); |
| 21 | MODULE_DESCRIPTION("Quota format v2 support"); |
| 22 | MODULE_LICENSE("GPL"); |
| 23 | |
| 24 | #define __QUOTA_V2_PARANOIA |
| 25 | |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 26 | static void v2r0_mem2diskdqb(void *dp, struct dquot *dquot); |
| 27 | static void v2r0_disk2memdqb(struct dquot *dquot, void *dp); |
| 28 | static int v2r0_is_id(void *dp, struct dquot *dquot); |
| 29 | static void v2r1_mem2diskdqb(void *dp, struct dquot *dquot); |
| 30 | static void v2r1_disk2memdqb(struct dquot *dquot, void *dp); |
| 31 | static int v2r1_is_id(void *dp, struct dquot *dquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 33 | static struct qtree_fmt_operations v2r0_qtree_ops = { |
| 34 | .mem2disk_dqblk = v2r0_mem2diskdqb, |
| 35 | .disk2mem_dqblk = v2r0_disk2memdqb, |
| 36 | .is_id = v2r0_is_id, |
| 37 | }; |
| 38 | |
| 39 | static struct qtree_fmt_operations v2r1_qtree_ops = { |
| 40 | .mem2disk_dqblk = v2r1_mem2diskdqb, |
| 41 | .disk2mem_dqblk = v2r1_disk2memdqb, |
| 42 | .is_id = v2r1_is_id, |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 43 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 45 | #define QUOTABLOCK_BITS 10 |
| 46 | #define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS) |
| 47 | |
| 48 | static inline qsize_t v2_stoqb(qsize_t space) |
| 49 | { |
| 50 | return (space + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS; |
| 51 | } |
| 52 | |
| 53 | static inline qsize_t v2_qbtos(qsize_t blocks) |
| 54 | { |
| 55 | return blocks << QUOTABLOCK_BITS; |
| 56 | } |
| 57 | |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 58 | static 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 Zhang | fb5ffb0 | 2010-07-20 16:54:43 +0200 | [diff] [blame] | 66 | quota_error(sb, "Failed header read: expected=%zd got=%zd", |
| 67 | sizeof(struct v2_disk_dqheader), size); |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | return 1; |
| 71 | } |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* Check whether given file is really vfsv0 quotafile */ |
| 74 | static int v2_check_quota_file(struct super_block *sb, int type) |
| 75 | { |
| 76 | struct v2_disk_dqheader dqhead; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static const uint quota_magics[] = V2_INITQMAGICS; |
| 78 | static const uint quota_versions[] = V2_INITQVERSIONS; |
| 79 | |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 80 | if (!v2_read_header(sb, type, &dqhead)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type] || |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 83 | le32_to_cpu(dqhead.dqh_version) > quota_versions[type]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | return 0; |
| 85 | return 1; |
| 86 | } |
| 87 | |
| 88 | /* Read information header from quota file */ |
| 89 | static int v2_read_file_info(struct super_block *sb, int type) |
| 90 | { |
| 91 | struct v2_disk_dqinfo dinfo; |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 92 | struct v2_disk_dqheader dqhead; |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 93 | struct mem_dqinfo *info = sb_dqinfo(sb, type); |
Jan Kara | e3d4d56 | 2008-10-02 18:44:14 +0200 | [diff] [blame] | 94 | struct qtree_mem_dqinfo *qinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | ssize_t size; |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 96 | unsigned int version; |
| 97 | |
| 98 | if (!v2_read_header(sb, type, &dqhead)) |
Jan Kara | 869835d | 2009-12-21 21:57:04 +0100 | [diff] [blame] | 99 | return -1; |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 100 | version = le32_to_cpu(dqhead.dqh_version); |
Jan Kara | 869835d | 2009-12-21 21:57:04 +0100 | [diff] [blame] | 101 | if ((info->dqi_fmt_id == QFMT_VFS_V0 && version != 0) || |
| 102 | (info->dqi_fmt_id == QFMT_VFS_V1 && version != 1)) |
| 103 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | size = sb->s_op->quota_read(sb, type, (char *)&dinfo, |
| 106 | sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF); |
| 107 | if (size != sizeof(struct v2_disk_dqinfo)) { |
Jiaying Zhang | fb5ffb0 | 2010-07-20 16:54:43 +0200 | [diff] [blame] | 108 | quota_error(sb, "Can't read info structure"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | return -1; |
| 110 | } |
Jan Kara | e3d4d56 | 2008-10-02 18:44:14 +0200 | [diff] [blame] | 111 | info->dqi_priv = kmalloc(sizeof(struct qtree_mem_dqinfo), GFP_NOFS); |
| 112 | if (!info->dqi_priv) { |
| 113 | printk(KERN_WARNING |
| 114 | "Not enough memory for quota information structure.\n"); |
Davidlohr Bueso | 7a39de1 | 2011-01-20 15:32:05 -0300 | [diff] [blame] | 115 | return -ENOMEM; |
Jan Kara | e3d4d56 | 2008-10-02 18:44:14 +0200 | [diff] [blame] | 116 | } |
| 117 | qinfo = info->dqi_priv; |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 118 | if (version == 0) { |
| 119 | /* limits are stored as unsigned 32-bit data */ |
Jan Kara | b10a081 | 2014-10-09 16:54:13 +0200 | [diff] [blame] | 120 | info->dqi_max_spc_limit = 0xffffffffULL << QUOTABLOCK_BITS; |
| 121 | info->dqi_max_ino_limit = 0xffffffff; |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 122 | } else { |
Jan Kara | b10a081 | 2014-10-09 16:54:13 +0200 | [diff] [blame] | 123 | /* used space is stored as unsigned 64-bit value in bytes */ |
| 124 | info->dqi_max_spc_limit = 0xffffffffffffffffULL; /* 2^64-1 */ |
| 125 | info->dqi_max_ino_limit = 0xffffffffffffffffULL; |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 126 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | info->dqi_bgrace = le32_to_cpu(dinfo.dqi_bgrace); |
| 128 | info->dqi_igrace = le32_to_cpu(dinfo.dqi_igrace); |
Jan Kara | c119c5b | 2014-11-19 09:03:28 +0100 | [diff] [blame] | 129 | /* No flags currently supported */ |
| 130 | info->dqi_flags = 0; |
Jan Kara | e3d4d56 | 2008-10-02 18:44:14 +0200 | [diff] [blame] | 131 | qinfo->dqi_sb = sb; |
| 132 | qinfo->dqi_type = type; |
| 133 | qinfo->dqi_blocks = le32_to_cpu(dinfo.dqi_blocks); |
| 134 | qinfo->dqi_free_blk = le32_to_cpu(dinfo.dqi_free_blk); |
| 135 | qinfo->dqi_free_entry = le32_to_cpu(dinfo.dqi_free_entry); |
| 136 | qinfo->dqi_blocksize_bits = V2_DQBLKSIZE_BITS; |
| 137 | qinfo->dqi_usable_bs = 1 << V2_DQBLKSIZE_BITS; |
| 138 | qinfo->dqi_qtree_depth = qtree_depth(qinfo); |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 139 | if (version == 0) { |
| 140 | qinfo->dqi_entry_size = sizeof(struct v2r0_disk_dqblk); |
| 141 | qinfo->dqi_ops = &v2r0_qtree_ops; |
| 142 | } else { |
| 143 | qinfo->dqi_entry_size = sizeof(struct v2r1_disk_dqblk); |
| 144 | qinfo->dqi_ops = &v2r1_qtree_ops; |
| 145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | /* Write information header to quota file */ |
| 150 | static int v2_write_file_info(struct super_block *sb, int type) |
| 151 | { |
| 152 | struct v2_disk_dqinfo dinfo; |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 153 | struct mem_dqinfo *info = sb_dqinfo(sb, type); |
Jan Kara | e3d4d56 | 2008-10-02 18:44:14 +0200 | [diff] [blame] | 154 | struct qtree_mem_dqinfo *qinfo = info->dqi_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | ssize_t size; |
| 156 | |
| 157 | spin_lock(&dq_data_lock); |
| 158 | info->dqi_flags &= ~DQF_INFO_DIRTY; |
| 159 | dinfo.dqi_bgrace = cpu_to_le32(info->dqi_bgrace); |
| 160 | dinfo.dqi_igrace = cpu_to_le32(info->dqi_igrace); |
Jan Kara | c119c5b | 2014-11-19 09:03:28 +0100 | [diff] [blame] | 161 | /* No flags currently supported */ |
| 162 | dinfo.dqi_flags = cpu_to_le32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | spin_unlock(&dq_data_lock); |
Jan Kara | e3d4d56 | 2008-10-02 18:44:14 +0200 | [diff] [blame] | 164 | dinfo.dqi_blocks = cpu_to_le32(qinfo->dqi_blocks); |
| 165 | dinfo.dqi_free_blk = cpu_to_le32(qinfo->dqi_free_blk); |
| 166 | dinfo.dqi_free_entry = cpu_to_le32(qinfo->dqi_free_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | size = sb->s_op->quota_write(sb, type, (char *)&dinfo, |
| 168 | sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF); |
| 169 | if (size != sizeof(struct v2_disk_dqinfo)) { |
Jiaying Zhang | fb5ffb0 | 2010-07-20 16:54:43 +0200 | [diff] [blame] | 170 | quota_error(sb, "Can't write info structure"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | return -1; |
| 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 176 | static void v2r0_disk2memdqb(struct dquot *dquot, void *dp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 178 | struct v2r0_disk_dqblk *d = dp, empty; |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 179 | struct mem_dqblk *m = &dquot->dq_dqb; |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | m->dqb_ihardlimit = le32_to_cpu(d->dqb_ihardlimit); |
| 182 | m->dqb_isoftlimit = le32_to_cpu(d->dqb_isoftlimit); |
| 183 | m->dqb_curinodes = le32_to_cpu(d->dqb_curinodes); |
| 184 | m->dqb_itime = le64_to_cpu(d->dqb_itime); |
Jan Kara | 1209546 | 2008-08-20 14:45:12 +0200 | [diff] [blame] | 185 | m->dqb_bhardlimit = v2_qbtos(le32_to_cpu(d->dqb_bhardlimit)); |
| 186 | m->dqb_bsoftlimit = v2_qbtos(le32_to_cpu(d->dqb_bsoftlimit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | m->dqb_curspace = le64_to_cpu(d->dqb_curspace); |
| 188 | m->dqb_btime = le64_to_cpu(d->dqb_btime); |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 189 | /* We need to escape back all-zero structure */ |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 190 | memset(&empty, 0, sizeof(struct v2r0_disk_dqblk)); |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 191 | empty.dqb_itime = cpu_to_le64(1); |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 192 | if (!memcmp(&empty, dp, sizeof(struct v2r0_disk_dqblk))) |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 193 | m->dqb_itime = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 196 | static void v2r0_mem2diskdqb(void *dp, struct dquot *dquot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 198 | struct v2r0_disk_dqblk *d = dp; |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 199 | struct mem_dqblk *m = &dquot->dq_dqb; |
| 200 | struct qtree_mem_dqinfo *info = |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 201 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | d->dqb_ihardlimit = cpu_to_le32(m->dqb_ihardlimit); |
| 204 | d->dqb_isoftlimit = cpu_to_le32(m->dqb_isoftlimit); |
| 205 | d->dqb_curinodes = cpu_to_le32(m->dqb_curinodes); |
| 206 | d->dqb_itime = cpu_to_le64(m->dqb_itime); |
Jan Kara | cf770c1 | 2008-09-21 23:17:53 +0200 | [diff] [blame] | 207 | d->dqb_bhardlimit = cpu_to_le32(v2_stoqb(m->dqb_bhardlimit)); |
| 208 | d->dqb_bsoftlimit = cpu_to_le32(v2_stoqb(m->dqb_bsoftlimit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | d->dqb_curspace = cpu_to_le64(m->dqb_curspace); |
| 210 | d->dqb_btime = cpu_to_le64(m->dqb_btime); |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 211 | d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id)); |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 212 | if (qtree_entry_unused(info, dp)) |
| 213 | d->dqb_itime = cpu_to_le64(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 216 | static int v2r0_is_id(void *dp, struct dquot *dquot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 218 | struct v2r0_disk_dqblk *d = dp; |
| 219 | struct qtree_mem_dqinfo *info = |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 220 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 221 | |
| 222 | if (qtree_entry_unused(info, dp)) |
| 223 | return 0; |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 224 | return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type, |
| 225 | le32_to_cpu(d->dqb_id)), |
| 226 | dquot->dq_id); |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | static void v2r1_disk2memdqb(struct dquot *dquot, void *dp) |
| 230 | { |
| 231 | struct v2r1_disk_dqblk *d = dp, empty; |
| 232 | struct mem_dqblk *m = &dquot->dq_dqb; |
| 233 | |
| 234 | m->dqb_ihardlimit = le64_to_cpu(d->dqb_ihardlimit); |
| 235 | m->dqb_isoftlimit = le64_to_cpu(d->dqb_isoftlimit); |
| 236 | m->dqb_curinodes = le64_to_cpu(d->dqb_curinodes); |
| 237 | m->dqb_itime = le64_to_cpu(d->dqb_itime); |
| 238 | m->dqb_bhardlimit = v2_qbtos(le64_to_cpu(d->dqb_bhardlimit)); |
| 239 | m->dqb_bsoftlimit = v2_qbtos(le64_to_cpu(d->dqb_bsoftlimit)); |
| 240 | m->dqb_curspace = le64_to_cpu(d->dqb_curspace); |
| 241 | m->dqb_btime = le64_to_cpu(d->dqb_btime); |
| 242 | /* We need to escape back all-zero structure */ |
| 243 | memset(&empty, 0, sizeof(struct v2r1_disk_dqblk)); |
| 244 | empty.dqb_itime = cpu_to_le64(1); |
| 245 | if (!memcmp(&empty, dp, sizeof(struct v2r1_disk_dqblk))) |
| 246 | m->dqb_itime = 0; |
| 247 | } |
| 248 | |
| 249 | static void v2r1_mem2diskdqb(void *dp, struct dquot *dquot) |
| 250 | { |
| 251 | struct v2r1_disk_dqblk *d = dp; |
| 252 | struct mem_dqblk *m = &dquot->dq_dqb; |
| 253 | struct qtree_mem_dqinfo *info = |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 254 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 255 | |
| 256 | d->dqb_ihardlimit = cpu_to_le64(m->dqb_ihardlimit); |
| 257 | d->dqb_isoftlimit = cpu_to_le64(m->dqb_isoftlimit); |
| 258 | d->dqb_curinodes = cpu_to_le64(m->dqb_curinodes); |
| 259 | d->dqb_itime = cpu_to_le64(m->dqb_itime); |
| 260 | d->dqb_bhardlimit = cpu_to_le64(v2_stoqb(m->dqb_bhardlimit)); |
| 261 | d->dqb_bsoftlimit = cpu_to_le64(v2_stoqb(m->dqb_bsoftlimit)); |
| 262 | d->dqb_curspace = cpu_to_le64(m->dqb_curspace); |
| 263 | d->dqb_btime = cpu_to_le64(m->dqb_btime); |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 264 | d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id)); |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 265 | if (qtree_entry_unused(info, dp)) |
| 266 | d->dqb_itime = cpu_to_le64(1); |
| 267 | } |
| 268 | |
| 269 | static int v2r1_is_id(void *dp, struct dquot *dquot) |
| 270 | { |
| 271 | struct v2r1_disk_dqblk *d = dp; |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 272 | struct qtree_mem_dqinfo *info = |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 273 | sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 275 | if (qtree_entry_unused(info, dp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | return 0; |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 277 | return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type, |
| 278 | le32_to_cpu(d->dqb_id)), |
| 279 | dquot->dq_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static int v2_read_dquot(struct dquot *dquot) |
| 283 | { |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 284 | return qtree_read_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 287 | static int v2_write_dquot(struct dquot *dquot) |
| 288 | { |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 289 | return qtree_write_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); |
Jan Kara | 1ccd14b | 2008-09-22 05:54:49 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | static int v2_release_dquot(struct dquot *dquot) |
| 293 | { |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 294 | return qtree_release_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); |
Jan Kara | e3d4d56 | 2008-10-02 18:44:14 +0200 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static int v2_free_file_info(struct super_block *sb, int type) |
| 298 | { |
| 299 | kfree(sb_dqinfo(sb, type)->dqi_priv); |
| 300 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Alexey Dobriyan | 1472da5 | 2009-10-16 15:26:03 +0400 | [diff] [blame] | 303 | static const struct quota_format_ops v2_format_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | .check_quota_file = v2_check_quota_file, |
| 305 | .read_file_info = v2_read_file_info, |
| 306 | .write_file_info = v2_write_file_info, |
Jan Kara | e3d4d56 | 2008-10-02 18:44:14 +0200 | [diff] [blame] | 307 | .free_file_info = v2_free_file_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | .read_dqblk = v2_read_dquot, |
| 309 | .commit_dqblk = v2_write_dquot, |
| 310 | .release_dqblk = v2_release_dquot, |
| 311 | }; |
| 312 | |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 313 | static struct quota_format_type v2r0_quota_format = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | .qf_fmt_id = QFMT_VFS_V0, |
| 315 | .qf_ops = &v2_format_ops, |
| 316 | .qf_owner = THIS_MODULE |
| 317 | }; |
| 318 | |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 319 | static struct quota_format_type v2r1_quota_format = { |
| 320 | .qf_fmt_id = QFMT_VFS_V1, |
| 321 | .qf_ops = &v2_format_ops, |
| 322 | .qf_owner = THIS_MODULE |
| 323 | }; |
| 324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | static int __init init_v2_quota_format(void) |
| 326 | { |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 327 | int ret; |
| 328 | |
| 329 | ret = register_quota_format(&v2r0_quota_format); |
| 330 | if (ret) |
| 331 | return ret; |
| 332 | return register_quota_format(&v2r1_quota_format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | static void __exit exit_v2_quota_format(void) |
| 336 | { |
Jan Kara | 498c601 | 2009-11-16 18:09:47 +0100 | [diff] [blame] | 337 | unregister_quota_format(&v2r0_quota_format); |
| 338 | unregister_quota_format(&v2r1_quota_format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | module_init(init_v2_quota_format); |
| 342 | module_exit(exit_v2_quota_format); |