1 ext4: trivial quota cleanup
3 The patch is aimed to reorganize and simplify quota src code.
4 Quota code is itself complex enouth, but we can make it more readable
6 - Move quota option parsing to separate functions.
7 - Simplify old-quota and journaled-quota mix check.
8 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
9 index 6459bb7..7c4b742 100644
12 @@ -1172,6 +1172,63 @@ static ext4_fsblk_t get_sb_block(void **data)
14 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
17 +static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
19 + struct ext4_sb_info *sbi = EXT4_SB(sb);
22 + if (sb_any_quota_loaded(sb) &&
23 + !sbi->s_qf_names[qtype]) {
24 + ext4_msg(sb, KERN_ERR,
25 + "Cannot change journaled "
26 + "quota options when quota turned on");
29 + qname = match_strdup(args);
31 + ext4_msg(sb, KERN_ERR,
32 + "Not enough memory for storing quotafile name");
35 + if (sbi->s_qf_names[qtype] &&
36 + strcmp(sbi->s_qf_names[qtype], qname)) {
37 + ext4_msg(sb, KERN_ERR,
38 + "%s quota file already specified", QTYPE2NAME(qtype));
42 + sbi->s_qf_names[qtype] = qname;
43 + if (strchr(sbi->s_qf_names[qtype], '/')) {
44 + ext4_msg(sb, KERN_ERR,
45 + "quotafile must be on filesystem root");
46 + kfree(sbi->s_qf_names[qtype]);
47 + sbi->s_qf_names[qtype] = NULL;
50 + set_opt(sbi->s_mount_opt, QUOTA);
54 +static int clear_qf_name(struct super_block *sb, int qtype) {
56 + struct ext4_sb_info *sbi = EXT4_SB(sb);
58 + if (sb_any_quota_loaded(sb) &&
59 + sbi->s_qf_names[qtype]) {
60 + ext4_msg(sb, KERN_ERR, "Cannot change journaled quota options"
61 + " when quota turned on");
65 + * The space will be released later when all options are confirmed
68 + sbi->s_qf_names[qtype] = NULL;
73 static int parse_options(char *options, struct super_block *sb,
74 unsigned long *journal_devnum,
75 unsigned int *journal_ioprio,
76 @@ -1183,8 +1240,7 @@ static int parse_options(char *options, struct super_block *sb,
86 @@ -1360,63 +1416,22 @@ static int parse_options(char *options, struct super_block *sb,
95 - if (sb_any_quota_loaded(sb) &&
96 - !sbi->s_qf_names[qtype]) {
97 - ext4_msg(sb, KERN_ERR,
98 - "Cannot change journaled "
99 - "quota options when quota turned on");
102 - qname = match_strdup(&args[0]);
104 - ext4_msg(sb, KERN_ERR,
105 - "Not enough memory for "
106 - "storing quotafile name");
107 + if (!set_qf_name(sb, USRQUOTA, &args[0]))
110 - if (sbi->s_qf_names[qtype] &&
111 - strcmp(sbi->s_qf_names[qtype], qname)) {
112 - ext4_msg(sb, KERN_ERR,
113 - "%s quota file already "
114 - "specified", QTYPE2NAME(qtype));
118 - sbi->s_qf_names[qtype] = qname;
119 - if (strchr(sbi->s_qf_names[qtype], '/')) {
120 - ext4_msg(sb, KERN_ERR,
121 - "quotafile must be on "
122 - "filesystem root");
123 - kfree(sbi->s_qf_names[qtype]);
124 - sbi->s_qf_names[qtype] = NULL;
126 + case Opt_grpjquota:
127 + if (!set_qf_name(sb, GRPQUOTA, &args[0]))
130 - set_opt(sbi->s_mount_opt, QUOTA);
132 case Opt_offusrjquota:
134 - goto clear_qf_name;
135 + if (!clear_qf_name(sb, USRQUOTA))
138 case Opt_offgrpjquota:
141 - if (sb_any_quota_loaded(sb) &&
142 - sbi->s_qf_names[qtype]) {
143 - ext4_msg(sb, KERN_ERR, "Cannot change "
144 - "journaled quota options when "
145 - "quota turned on");
146 + if (!clear_qf_name(sb, GRPQUOTA))
150 - * The space will be released later when all options
151 - * are confirmed to be correct
153 - sbi->s_qf_names[qtype] = NULL;
156 case Opt_jqfmt_vfsold:
159 @@ -1577,8 +1592,8 @@ set_qf_format:
160 if (test_opt(sb, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA])
161 clear_opt(sbi->s_mount_opt, GRPQUOTA);
163 - if ((sbi->s_qf_names[USRQUOTA] && test_opt(sb, GRPQUOTA)) ||
164 - (sbi->s_qf_names[GRPQUOTA] && test_opt(sb, USRQUOTA))) {
165 + if (sbi->s_mount_opt & (EXT4_MOUNT_USRQUOTA |
166 + EXT4_MOUNT_GRPQUOTA)) {
167 ext4_msg(sb, KERN_ERR, "old and new quota "