aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext3
diff options
context:
space:
mode:
authorDmitry Monakhov <dmonakhov@openvz.org>2010-02-02 08:05:53 -0500
committerJan Kara <jack@suse.cz>2010-03-04 18:20:20 -0500
commite1f5c67a1994312300ebc41195e6f5bea2f6c065 (patch)
tree98f521004fe9dc83d3662d41ae5323f1286dab11 /fs/ext3
parente3c9643597ac4bd6b5db62b5e7d915f8c8fa34b6 (diff)
ext3: trivial quota cleanup
The patch is aimed to reorganize and simplify quota code a bit. Quota code is itself complex enouth, but we can make it more readable in some places: - Move quota option parsing to separate functions. - Simplify old-quota and journaled-quota mix check. Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/ext3')
-rw-r--r--fs/ext3/super.c121
1 files changed, 67 insertions, 54 deletions
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 7950ff6ec4e8..241c520b3081 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -895,6 +895,63 @@ static ext3_fsblk_t get_sb_block(void **data, struct super_block *sb)
895 return sb_block; 895 return sb_block;
896} 896}
897 897
898#ifdef CONFIG_QUOTA
899static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
900{
901 struct ext3_sb_info *sbi = EXT3_SB(sb);
902 char *qname;
903
904 if (sb_any_quota_loaded(sb) &&
905 !sbi->s_qf_names[qtype]) {
906 ext3_msg(sb, KERN_ERR,
907 "Cannot change journaled "
908 "quota options when quota turned on");
909 return 0;
910 }
911 qname = match_strdup(args);
912 if (!qname) {
913 ext3_msg(sb, KERN_ERR,
914 "Not enough memory for storing quotafile name");
915 return 0;
916 }
917 if (sbi->s_qf_names[qtype] &&
918 strcmp(sbi->s_qf_names[qtype], qname)) {
919 ext3_msg(sb, KERN_ERR,
920 "%s quota file already specified", QTYPE2NAME(qtype));
921 kfree(qname);
922 return 0;
923 }
924 sbi->s_qf_names[qtype] = qname;
925 if (strchr(sbi->s_qf_names[qtype], '/')) {
926 ext3_msg(sb, KERN_ERR,
927 "quotafile must be on filesystem root");
928 kfree(sbi->s_qf_names[qtype]);
929 sbi->s_qf_names[qtype] = NULL;
930 return 0;
931 }
932 set_opt(sbi->s_mount_opt, QUOTA);
933 return 1;
934}
935
936static int clear_qf_name(struct super_block *sb, int qtype) {
937
938 struct ext3_sb_info *sbi = EXT3_SB(sb);
939
940 if (sb_any_quota_loaded(sb) &&
941 sbi->s_qf_names[qtype]) {
942 ext3_msg(sb, KERN_ERR, "Cannot change journaled quota options"
943 " when quota turned on");
944 return 0;
945 }
946 /*
947 * The space will be released later when all options are confirmed
948 * to be correct
949 */
950 sbi->s_qf_names[qtype] = NULL;
951 return 1;
952}
953#endif
954
898static int parse_options (char *options, struct super_block *sb, 955static int parse_options (char *options, struct super_block *sb,
899 unsigned int *inum, unsigned long *journal_devnum, 956 unsigned int *inum, unsigned long *journal_devnum,
900 ext3_fsblk_t *n_blocks_count, int is_remount) 957 ext3_fsblk_t *n_blocks_count, int is_remount)
@@ -905,8 +962,7 @@ static int parse_options (char *options, struct super_block *sb,
905 int data_opt = 0; 962 int data_opt = 0;
906 int option; 963 int option;
907#ifdef CONFIG_QUOTA 964#ifdef CONFIG_QUOTA
908 int qtype, qfmt; 965 int qfmt;
909 char *qname;
910#endif 966#endif
911 967
912 if (!options) 968 if (!options)
@@ -1088,62 +1144,20 @@ static int parse_options (char *options, struct super_block *sb,
1088 break; 1144 break;
1089#ifdef CONFIG_QUOTA 1145#ifdef CONFIG_QUOTA
1090 case Opt_usrjquota: 1146 case Opt_usrjquota:
1091 qtype = USRQUOTA; 1147 if (!set_qf_name(sb, USRQUOTA, &args[0]))
1092 goto set_qf_name;
1093 case Opt_grpjquota:
1094 qtype = GRPQUOTA;
1095set_qf_name:
1096 if (sb_any_quota_loaded(sb) &&
1097 !sbi->s_qf_names[qtype]) {
1098 ext3_msg(sb, KERN_ERR,
1099 "error: cannot change journaled "
1100 "quota options when quota turned on.");
1101 return 0; 1148 return 0;
1102 } 1149 break;
1103 qname = match_strdup(&args[0]); 1150 case Opt_grpjquota:
1104 if (!qname) { 1151 if (!set_qf_name(sb, GRPQUOTA, &args[0]))
1105 ext3_msg(sb, KERN_ERR,
1106 "error: not enough memory for "
1107 "storing quotafile name.");
1108 return 0;
1109 }
1110 if (sbi->s_qf_names[qtype] &&
1111 strcmp(sbi->s_qf_names[qtype], qname)) {
1112 ext3_msg(sb, KERN_ERR,
1113 "error: %s quota file already "
1114 "specified.", QTYPE2NAME(qtype));
1115 kfree(qname);
1116 return 0;
1117 }
1118 sbi->s_qf_names[qtype] = qname;
1119 if (strchr(sbi->s_qf_names[qtype], '/')) {
1120 ext3_msg(sb, KERN_ERR,
1121 "error: quotafile must be on "
1122 "filesystem root.");
1123 kfree(sbi->s_qf_names[qtype]);
1124 sbi->s_qf_names[qtype] = NULL;
1125 return 0; 1152 return 0;
1126 }
1127 set_opt(sbi->s_mount_opt, QUOTA);
1128 break; 1153 break;
1129 case Opt_offusrjquota: 1154 case Opt_offusrjquota:
1130 qtype = USRQUOTA; 1155 if (!clear_qf_name(sb, USRQUOTA))
1131 goto clear_qf_name; 1156 return 0;
1157 break;
1132 case Opt_offgrpjquota: 1158 case Opt_offgrpjquota:
1133 qtype = GRPQUOTA; 1159 if (!clear_qf_name(sb, GRPQUOTA))
1134clear_qf_name:
1135 if (sb_any_quota_loaded(sb) &&
1136 sbi->s_qf_names[qtype]) {
1137 ext3_msg(sb, KERN_ERR, "error: cannot change "
1138 "journaled quota options when "
1139 "quota turned on.");
1140 return 0; 1160 return 0;
1141 }
1142 /*
1143 * The space will be released later when all options
1144 * are confirmed to be correct
1145 */
1146 sbi->s_qf_names[qtype] = NULL;
1147 break; 1161 break;
1148 case Opt_jqfmt_vfsold: 1162 case Opt_jqfmt_vfsold:
1149 qfmt = QFMT_VFS_OLD; 1163 qfmt = QFMT_VFS_OLD;
@@ -1247,8 +1261,7 @@ set_qf_format:
1247 if (test_opt(sb, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA]) 1261 if (test_opt(sb, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA])
1248 clear_opt(sbi->s_mount_opt, GRPQUOTA); 1262 clear_opt(sbi->s_mount_opt, GRPQUOTA);
1249 1263
1250 if ((sbi->s_qf_names[USRQUOTA] && test_opt(sb, GRPQUOTA)) || 1264 if (test_opt(sb, GRPQUOTA) || test_opt(sb, USRQUOTA)) {
1251 (sbi->s_qf_names[GRPQUOTA] && test_opt(sb, USRQUOTA))) {
1252 ext3_msg(sb, KERN_ERR, "error: old and new quota " 1265 ext3_msg(sb, KERN_ERR, "error: old and new quota "
1253 "format mixing."); 1266 "format mixing.");
1254 return 0; 1267 return 0;