Document update
[ct-quota-pq.git] / ext4-quota-cleanup
blob67f798f412a8d5d0d2161712f7fdf4f81006270d
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
5 in some places:
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
10 --- a/fs/ext4/super.c
11 +++ b/fs/ext4/super.c
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))
16 +#ifdef CONFIG_QUOTA
17 +static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
19 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
20 +       char *qname;
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");
27 +               return 0;
28 +       }
29 +       qname = match_strdup(args);
30 +       if (!qname) {
31 +               ext4_msg(sb, KERN_ERR,
32 +                       "Not enough memory for storing quotafile name");
33 +               return 0;
34 +       }
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));
39 +               kfree(qname);
40 +               return 0;
41 +       }
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;
48 +               return 0;
49 +       }
50 +       set_opt(sbi->s_mount_opt, QUOTA);
51 +       return 1;
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");
62 +               return 0;
63 +       }
64 +       /*
65 +        * The space will be released later when all options are confirmed
66 +        * to be correct
67 +        */
68 +       sbi->s_qf_names[qtype] = NULL;
69 +       return 1;
71 +#endif
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,
77         int data_opt = 0;
78         int option;
79  #ifdef CONFIG_QUOTA
80 -       int qtype, qfmt;
81 -       char *qname;
82 +       int qfmt;
83  #endif
85         if (!options)
86 @@ -1360,63 +1416,22 @@ static int parse_options(char *options, struct super_block *sb,
87                         break;
88  #ifdef CONFIG_QUOTA
89                 case Opt_usrjquota:
90 -                       qtype = USRQUOTA;
91 -                       goto set_qf_name;
92 -               case Opt_grpjquota:
93 -                       qtype = GRPQUOTA;
94 -set_qf_name:
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");
100 -                               return 0;
101 -                       }
102 -                       qname = match_strdup(&args[0]);
103 -                       if (!qname) {
104 -                               ext4_msg(sb, KERN_ERR,
105 -                                       "Not enough memory for "
106 -                                       "storing quotafile name");
107 +                       if (!set_qf_name(sb, USRQUOTA, &args[0]))
108                                 return 0;
109 -                       }
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));
115 -                               kfree(qname);
116 -                               return 0;
117 -                       }
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;
125 +                       break;
126 +               case Opt_grpjquota:
127 +                       if (!set_qf_name(sb, GRPQUOTA, &args[0]))
128                                 return 0;
129 -                       }
130 -                       set_opt(sbi->s_mount_opt, QUOTA);
131                         break;
132                 case Opt_offusrjquota:
133 -                       qtype = USRQUOTA;
134 -                       goto clear_qf_name;
135 +                       if (!clear_qf_name(sb, USRQUOTA))
136 +                               return 0;
137 +                       break;
138                 case Opt_offgrpjquota:
139 -                       qtype = GRPQUOTA;
140 -clear_qf_name:
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))
147                                 return 0;
148 -                       }
149 -                       /*
150 -                        * The space will be released later when all options
151 -                        * are confirmed to be correct
152 -                        */
153 -                       sbi->s_qf_names[qtype] = NULL;
154                         break;
156                 case Opt_jqfmt_vfsold:
157                         qfmt = QFMT_VFS_OLD;
158                         goto set_qf_format;
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 "
168                                         "format mixing");
169                         return 0;