Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

Pull ext4 updates from Ted Ts'o:
"Convert ext4 to use the new mount API, and add support for the
FS_IOC_GETFSLABEL and FS_IOC_SETFSLABEL ioctls.

In addition the usual large number of clean ups and bug fixes, in
particular for the fast_commit feature"

* tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (48 commits)
ext4: don't use the orphan list when migrating an inode
ext4: use BUG_ON instead of if condition followed by BUG
ext4: fix a copy and paste typo
ext4: set csum seed in tmp inode while migrating to extents
ext4: remove unnecessary 'offset' assignment
ext4: remove redundant o_start statement
ext4: drop an always true check
ext4: remove unused assignments
ext4: remove redundant statement
ext4: remove useless resetting io_end_size in mpage_process_page()
ext4: allow to change s_last_trim_minblks via sysfs
ext4: change s_last_trim_minblks type to unsigned long
ext4: implement support for get/set fs label
ext4: only set EXT4_MOUNT_QUOTA when journalled quota file is specified
ext4: don't use kfree() on rcu protected pointer sbi->s_qf_names
ext4: avoid trim error on fs with small groups
ext4: fix an use-after-free issue about data=journal writeback mode
ext4: fix null-ptr-deref in '__ext4_journal_ensure_credits'
ext4: initialize err_blk before calling __ext4_get_inode_loc
ext4: fix a possible ABBA deadlock due to busy PA
...

+1860 -1089
-2
fs/ext4/acl.c
··· 246 246 handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits); 247 247 if (IS_ERR(handle)) 248 248 return PTR_ERR(handle); 249 - ext4_fc_start_update(inode); 250 249 251 250 if ((type == ACL_TYPE_ACCESS) && acl) { 252 251 error = posix_acl_update_mode(mnt_userns, inode, &mode, &acl); ··· 263 264 } 264 265 out_stop: 265 266 ext4_journal_stop(handle); 266 - ext4_fc_stop_update(inode); 267 267 if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 268 268 goto retry; 269 269 return error;
-1
fs/ext4/dir.c
··· 303 303 goto done; 304 304 brelse(bh); 305 305 bh = NULL; 306 - offset = 0; 307 306 } 308 307 done: 309 308 err = 0;
+13 -9
fs/ext4/ext4.h
··· 1298 1298 /* Metadata checksum algorithm codes */ 1299 1299 #define EXT4_CRC32C_CHKSUM 1 1300 1300 1301 + #define EXT4_LABEL_MAX 16 1302 + 1301 1303 /* 1302 1304 * Structure of the super block 1303 1305 */ ··· 1349 1347 /*60*/ __le32 s_feature_incompat; /* incompatible feature set */ 1350 1348 __le32 s_feature_ro_compat; /* readonly-compatible feature set */ 1351 1349 /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */ 1352 - /*78*/ char s_volume_name[16]; /* volume name */ 1350 + /*78*/ char s_volume_name[EXT4_LABEL_MAX]; /* volume name */ 1353 1351 /*88*/ char s_last_mounted[64] __nonstring; /* directory where last mounted */ 1354 1352 /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ 1355 1353 /* ··· 1663 1661 struct task_struct *s_mmp_tsk; 1664 1662 1665 1663 /* record the last minlen when FITRIM is called. */ 1666 - atomic_t s_last_trim_minblks; 1664 + unsigned long s_last_trim_minblks; 1667 1665 1668 1666 /* Reference to checksum algorithm driver via cryptoapi */ 1669 1667 struct crypto_shash *s_chksum_driver; ··· 1727 1725 */ 1728 1726 struct work_struct s_error_work; 1729 1727 1730 - /* Ext4 fast commit stuff */ 1728 + /* Ext4 fast commit sub transaction ID */ 1731 1729 atomic_t s_fc_subtid; 1732 - atomic_t s_fc_ineligible_updates; 1730 + 1733 1731 /* 1734 1732 * After commit starts, the main queue gets locked, and the further 1735 1733 * updates get added in the staging queue. ··· 1749 1747 spinlock_t s_fc_lock; 1750 1748 struct buffer_head *s_fc_bh; 1751 1749 struct ext4_fc_stats s_fc_stats; 1752 - u64 s_fc_avg_commit_time; 1753 1750 #ifdef CONFIG_EXT4_DEBUG 1754 1751 int s_fc_debug_max_replay; 1755 1752 #endif ··· 2400 2399 2401 2400 static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize) 2402 2401 { 2403 - if ((len > blocksize) || (blocksize > (1 << 18)) || (len & 3)) 2404 - BUG(); 2402 + BUG_ON((len > blocksize) || (blocksize > (1 << 18)) || (len & 3)); 2405 2403 #if (PAGE_SIZE >= 65536) 2406 2404 if (len < 65536) 2407 2405 return cpu_to_le16(len); ··· 2926 2926 void ext4_fc_track_create(handle_t *handle, struct dentry *dentry); 2927 2927 void ext4_fc_track_inode(handle_t *handle, struct inode *inode); 2928 2928 void ext4_fc_mark_ineligible(struct super_block *sb, int reason); 2929 - void ext4_fc_start_ineligible(struct super_block *sb, int reason); 2930 - void ext4_fc_stop_ineligible(struct super_block *sb); 2931 2929 void ext4_fc_start_update(struct inode *inode); 2932 2930 void ext4_fc_stop_update(struct inode *inode); 2933 2931 void ext4_fc_del(struct inode *inode); ··· 2933 2935 void ext4_fc_replay_cleanup(struct super_block *sb); 2934 2936 int ext4_fc_commit(journal_t *journal, tid_t commit_tid); 2935 2937 int __init ext4_fc_init_dentry_cache(void); 2938 + void ext4_fc_destroy_dentry_cache(void); 2936 2939 2937 2940 /* mballoc.c */ 2938 2941 extern const struct seq_operations ext4_mb_seq_groups_ops; ··· 3095 3096 struct ext4_super_block *es, 3096 3097 ext4_fsblk_t n_blocks_count); 3097 3098 extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count); 3099 + extern unsigned int ext4_list_backups(struct super_block *sb, 3100 + unsigned int *three, unsigned int *five, 3101 + unsigned int *seven); 3098 3102 3099 3103 /* super.c */ 3100 3104 extern struct buffer_head *ext4_sb_bread(struct super_block *sb, ··· 3112 3110 extern void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block); 3113 3111 extern int ext4_seq_options_show(struct seq_file *seq, void *offset); 3114 3112 extern int ext4_calculate_overhead(struct super_block *sb); 3113 + extern __le32 ext4_superblock_csum(struct super_block *sb, 3114 + struct ext4_super_block *es); 3115 3115 extern void ext4_superblock_csum_set(struct super_block *sb); 3116 3116 extern int ext4_alloc_flex_bg_array(struct super_block *sb, 3117 3117 ext4_group_t ngroup);
+2
fs/ext4/ext4_jbd2.c
··· 162 162 { 163 163 if (!ext4_handle_valid(handle)) 164 164 return 0; 165 + if (is_handle_aborted(handle)) 166 + return -EROFS; 165 167 if (jbd2_handle_buffer_credits(handle) >= check_cred && 166 168 handle->h_revoke_credits >= revoke_cred) 167 169 return 0;
+3 -13
fs/ext4/extents.c
··· 1496 1496 EXT4_ERROR_INODE(inode, 1497 1497 "ix (%d) != EXT_FIRST_INDEX (%d) (depth %d)!", 1498 1498 ix != NULL ? le32_to_cpu(ix->ei_block) : 0, 1499 - EXT_FIRST_INDEX(path[depth].p_hdr) != NULL ? 1500 - le32_to_cpu(EXT_FIRST_INDEX(path[depth].p_hdr)->ei_block) : 0, 1499 + le32_to_cpu(EXT_FIRST_INDEX(path[depth].p_hdr)->ei_block), 1501 1500 depth); 1502 1501 return -EFSCORRUPTED; 1503 1502 } ··· 2024 2025 + ext4_ext_get_actual_len(newext)); 2025 2026 if (unwritten) 2026 2027 ext4_ext_mark_unwritten(ex); 2027 - eh = path[depth].p_hdr; 2028 2028 nearex = ex; 2029 2029 goto merge; 2030 2030 } ··· 2052 2054 + ext4_ext_get_actual_len(newext)); 2053 2055 if (unwritten) 2054 2056 ext4_ext_mark_unwritten(ex); 2055 - eh = path[depth].p_hdr; 2056 2057 nearex = ex; 2057 2058 goto merge; 2058 2059 } ··· 4644 4647 ret = ext4_mark_inode_dirty(handle, inode); 4645 4648 if (unlikely(ret)) 4646 4649 goto out_handle; 4647 - ext4_fc_track_range(handle, inode, offset >> inode->i_sb->s_blocksize_bits, 4648 - (offset + len - 1) >> inode->i_sb->s_blocksize_bits); 4649 4650 /* Zero out partial block at the edges of the range */ 4650 4651 ret = ext4_zero_partial_blocks(handle, inode, offset, len); 4651 4652 if (ret >= 0) ··· 4691 4696 FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | 4692 4697 FALLOC_FL_INSERT_RANGE)) 4693 4698 return -EOPNOTSUPP; 4694 - 4695 - ext4_fc_start_update(inode); 4696 4699 4697 4700 if (mode & FALLOC_FL_PUNCH_HOLE) { 4698 4701 ret = ext4_punch_hole(inode, offset, len); ··· 4755 4762 inode_unlock(inode); 4756 4763 trace_ext4_fallocate_exit(inode, offset, max_blocks, ret); 4757 4764 exit: 4758 - ext4_fc_stop_update(inode); 4759 4765 return ret; 4760 4766 } 4761 4767 ··· 5336 5344 ret = PTR_ERR(handle); 5337 5345 goto out_mmap; 5338 5346 } 5339 - ext4_fc_start_ineligible(sb, EXT4_FC_REASON_FALLOC_RANGE); 5347 + ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_FALLOC_RANGE); 5340 5348 5341 5349 down_write(&EXT4_I(inode)->i_data_sem); 5342 5350 ext4_discard_preallocations(inode, 0); ··· 5375 5383 5376 5384 out_stop: 5377 5385 ext4_journal_stop(handle); 5378 - ext4_fc_stop_ineligible(sb); 5379 5386 out_mmap: 5380 5387 filemap_invalidate_unlock(mapping); 5381 5388 out_mutex: ··· 5476 5485 ret = PTR_ERR(handle); 5477 5486 goto out_mmap; 5478 5487 } 5479 - ext4_fc_start_ineligible(sb, EXT4_FC_REASON_FALLOC_RANGE); 5488 + ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_FALLOC_RANGE); 5480 5489 5481 5490 /* Expand file to avoid data loss if there is error while shifting */ 5482 5491 inode->i_size += len; ··· 5551 5560 5552 5561 out_stop: 5553 5562 ext4_journal_stop(handle); 5554 - ext4_fc_stop_ineligible(sb); 5555 5563 out_mmap: 5556 5564 filemap_invalidate_unlock(mapping); 5557 5565 out_mutex:
+86 -121
fs/ext4/fast_commit.c
··· 65 65 * 66 66 * Fast Commit Ineligibility 67 67 * ------------------------- 68 + * 68 69 * Not all operations are supported by fast commits today (e.g extended 69 - * attributes). Fast commit ineligibility is marked by calling one of the 70 - * two following functions: 71 - * 72 - * - ext4_fc_mark_ineligible(): This makes next fast commit operation to fall 73 - * back to full commit. This is useful in case of transient errors. 74 - * 75 - * - ext4_fc_start_ineligible() and ext4_fc_stop_ineligible() - This makes all 76 - * the fast commits happening between ext4_fc_start_ineligible() and 77 - * ext4_fc_stop_ineligible() and one fast commit after the call to 78 - * ext4_fc_stop_ineligible() to fall back to full commits. It is important to 79 - * make one more fast commit to fall back to full commit after stop call so 80 - * that it guaranteed that the fast commit ineligible operation contained 81 - * within ext4_fc_start_ineligible() and ext4_fc_stop_ineligible() is 82 - * followed by at least 1 full commit. 70 + * attributes). Fast commit ineligibility is marked by calling 71 + * ext4_fc_mark_ineligible(): This makes next fast commit operation to fall back 72 + * to full commit. 83 73 * 84 74 * Atomicity of commits 85 75 * -------------------- ··· 156 166 * fast commit recovery even if that area is invalidated by later full 157 167 * commits. 158 168 * 159 - * 1) Make fast commit atomic updates more fine grained. Today, a fast commit 160 - * eligible update must be protected within ext4_fc_start_update() and 161 - * ext4_fc_stop_update(). These routines are called at much higher 162 - * routines. This can be made more fine grained by combining with 163 - * ext4_journal_start(). 169 + * 1) Fast commit's commit path locks the entire file system during fast 170 + * commit. This has significant performance penalty. Instead of that, we 171 + * should use ext4_fc_start/stop_update functions to start inode level 172 + * updates from ext4_journal_start/stop. Once we do that we can drop file 173 + * system locking during commit path. 164 174 * 165 - * 2) Same above for ext4_fc_start_ineligible() and ext4_fc_stop_ineligible() 166 - * 167 - * 3) Handle more ineligible cases. 175 + * 2) Handle more ineligible cases. 168 176 */ 169 177 170 178 #include <trace/events/ext4.h> ··· 317 329 } 318 330 319 331 /* 320 - * Start a fast commit ineligible update. Any commits that happen while 321 - * such an operation is in progress fall back to full commits. 322 - */ 323 - void ext4_fc_start_ineligible(struct super_block *sb, int reason) 324 - { 325 - struct ext4_sb_info *sbi = EXT4_SB(sb); 326 - 327 - if (!test_opt2(sb, JOURNAL_FAST_COMMIT) || 328 - (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) 329 - return; 330 - 331 - WARN_ON(reason >= EXT4_FC_REASON_MAX); 332 - sbi->s_fc_stats.fc_ineligible_reason_count[reason]++; 333 - atomic_inc(&sbi->s_fc_ineligible_updates); 334 - } 335 - 336 - /* 337 - * Stop a fast commit ineligible update. We set EXT4_MF_FC_INELIGIBLE flag here 338 - * to ensure that after stopping the ineligible update, at least one full 339 - * commit takes place. 340 - */ 341 - void ext4_fc_stop_ineligible(struct super_block *sb) 342 - { 343 - if (!test_opt2(sb, JOURNAL_FAST_COMMIT) || 344 - (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) 345 - return; 346 - 347 - ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE); 348 - atomic_dec(&EXT4_SB(sb)->s_fc_ineligible_updates); 349 - } 350 - 351 - static inline int ext4_fc_is_ineligible(struct super_block *sb) 352 - { 353 - return (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE) || 354 - atomic_read(&EXT4_SB(sb)->s_fc_ineligible_updates)); 355 - } 356 - 357 - /* 358 332 * Generic fast commit tracking function. If this is the first time this we are 359 333 * called after a full commit, we initialize fast commit fields and then call 360 334 * __fc_track_fn() with update = 0. If we have already been called after a full ··· 341 391 (sbi->s_mount_state & EXT4_FC_REPLAY)) 342 392 return -EOPNOTSUPP; 343 393 344 - if (ext4_fc_is_ineligible(inode->i_sb)) 394 + if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE)) 345 395 return -EINVAL; 346 396 347 397 tid = handle->h_transaction->t_tid; ··· 746 796 ext4_fc_memcpy(sb, dst, &fcd, sizeof(fcd), crc); 747 797 dst += sizeof(fcd); 748 798 ext4_fc_memcpy(sb, dst, fc_dentry->fcd_name.name, dlen, crc); 749 - dst += dlen; 750 799 751 800 return true; 752 801 } ··· 1072 1123 return ret; 1073 1124 } 1074 1125 1126 + static void ext4_fc_update_stats(struct super_block *sb, int status, 1127 + u64 commit_time, int nblks) 1128 + { 1129 + struct ext4_fc_stats *stats = &EXT4_SB(sb)->s_fc_stats; 1130 + 1131 + jbd_debug(1, "Fast commit ended with status = %d", status); 1132 + if (status == EXT4_FC_STATUS_OK) { 1133 + stats->fc_num_commits++; 1134 + stats->fc_numblks += nblks; 1135 + if (likely(stats->s_fc_avg_commit_time)) 1136 + stats->s_fc_avg_commit_time = 1137 + (commit_time + 1138 + stats->s_fc_avg_commit_time * 3) / 4; 1139 + else 1140 + stats->s_fc_avg_commit_time = commit_time; 1141 + } else if (status == EXT4_FC_STATUS_FAILED || 1142 + status == EXT4_FC_STATUS_INELIGIBLE) { 1143 + if (status == EXT4_FC_STATUS_FAILED) 1144 + stats->fc_failed_commits++; 1145 + stats->fc_ineligible_commits++; 1146 + } else { 1147 + stats->fc_skipped_commits++; 1148 + } 1149 + trace_ext4_fc_commit_stop(sb, nblks, status); 1150 + } 1151 + 1075 1152 /* 1076 1153 * The main commit entry point. Performs a fast commit for transaction 1077 1154 * commit_tid if needed. If it's not possible to perform a fast commit ··· 1110 1135 struct ext4_sb_info *sbi = EXT4_SB(sb); 1111 1136 int nblks = 0, ret, bsize = journal->j_blocksize; 1112 1137 int subtid = atomic_read(&sbi->s_fc_subtid); 1113 - int reason = EXT4_FC_REASON_OK, fc_bufs_before = 0; 1138 + int status = EXT4_FC_STATUS_OK, fc_bufs_before = 0; 1114 1139 ktime_t start_time, commit_time; 1115 1140 1116 1141 trace_ext4_fc_commit_start(sb); 1117 1142 1118 1143 start_time = ktime_get(); 1119 1144 1120 - if (!test_opt2(sb, JOURNAL_FAST_COMMIT) || 1121 - (ext4_fc_is_ineligible(sb))) { 1122 - reason = EXT4_FC_REASON_INELIGIBLE; 1123 - goto out; 1124 - } 1145 + if (!test_opt2(sb, JOURNAL_FAST_COMMIT)) 1146 + return jbd2_complete_transaction(journal, commit_tid); 1125 1147 1126 1148 restart_fc: 1127 1149 ret = jbd2_fc_begin_commit(journal, commit_tid); ··· 1127 1155 if (atomic_read(&sbi->s_fc_subtid) <= subtid && 1128 1156 commit_tid > journal->j_commit_sequence) 1129 1157 goto restart_fc; 1130 - reason = EXT4_FC_REASON_ALREADY_COMMITTED; 1131 - goto out; 1158 + ext4_fc_update_stats(sb, EXT4_FC_STATUS_SKIPPED, 0, 0); 1159 + return 0; 1132 1160 } else if (ret) { 1133 - sbi->s_fc_stats.fc_ineligible_reason_count[EXT4_FC_COMMIT_FAILED]++; 1134 - reason = EXT4_FC_REASON_FC_START_FAILED; 1135 - goto out; 1161 + /* 1162 + * Commit couldn't start. Just update stats and perform a 1163 + * full commit. 1164 + */ 1165 + ext4_fc_update_stats(sb, EXT4_FC_STATUS_FAILED, 0, 0); 1166 + return jbd2_complete_transaction(journal, commit_tid); 1167 + } 1168 + 1169 + /* 1170 + * After establishing journal barrier via jbd2_fc_begin_commit(), check 1171 + * if we are fast commit ineligible. 1172 + */ 1173 + if (ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE)) { 1174 + status = EXT4_FC_STATUS_INELIGIBLE; 1175 + goto fallback; 1136 1176 } 1137 1177 1138 1178 fc_bufs_before = (sbi->s_fc_bytes + bsize - 1) / bsize; 1139 1179 ret = ext4_fc_perform_commit(journal); 1140 1180 if (ret < 0) { 1141 - sbi->s_fc_stats.fc_ineligible_reason_count[EXT4_FC_COMMIT_FAILED]++; 1142 - reason = EXT4_FC_REASON_FC_FAILED; 1143 - goto out; 1181 + status = EXT4_FC_STATUS_FAILED; 1182 + goto fallback; 1144 1183 } 1145 1184 nblks = (sbi->s_fc_bytes + bsize - 1) / bsize - fc_bufs_before; 1146 1185 ret = jbd2_fc_wait_bufs(journal, nblks); 1147 1186 if (ret < 0) { 1148 - sbi->s_fc_stats.fc_ineligible_reason_count[EXT4_FC_COMMIT_FAILED]++; 1149 - reason = EXT4_FC_REASON_FC_FAILED; 1150 - goto out; 1187 + status = EXT4_FC_STATUS_FAILED; 1188 + goto fallback; 1151 1189 } 1152 1190 atomic_inc(&sbi->s_fc_subtid); 1153 - jbd2_fc_end_commit(journal); 1154 - out: 1155 - /* Has any ineligible update happened since we started? */ 1156 - if (reason == EXT4_FC_REASON_OK && ext4_fc_is_ineligible(sb)) { 1157 - sbi->s_fc_stats.fc_ineligible_reason_count[EXT4_FC_COMMIT_FAILED]++; 1158 - reason = EXT4_FC_REASON_INELIGIBLE; 1159 - } 1160 - 1161 - spin_lock(&sbi->s_fc_lock); 1162 - if (reason != EXT4_FC_REASON_OK && 1163 - reason != EXT4_FC_REASON_ALREADY_COMMITTED) { 1164 - sbi->s_fc_stats.fc_ineligible_commits++; 1165 - } else { 1166 - sbi->s_fc_stats.fc_num_commits++; 1167 - sbi->s_fc_stats.fc_numblks += nblks; 1168 - } 1169 - spin_unlock(&sbi->s_fc_lock); 1170 - nblks = (reason == EXT4_FC_REASON_OK) ? nblks : 0; 1171 - trace_ext4_fc_commit_stop(sb, nblks, reason); 1172 - commit_time = ktime_to_ns(ktime_sub(ktime_get(), start_time)); 1191 + ret = jbd2_fc_end_commit(journal); 1173 1192 /* 1174 - * weight the commit time higher than the average time so we don't 1175 - * react too strongly to vast changes in the commit time 1193 + * weight the commit time higher than the average time so we 1194 + * don't react too strongly to vast changes in the commit time 1176 1195 */ 1177 - if (likely(sbi->s_fc_avg_commit_time)) 1178 - sbi->s_fc_avg_commit_time = (commit_time + 1179 - sbi->s_fc_avg_commit_time * 3) / 4; 1180 - else 1181 - sbi->s_fc_avg_commit_time = commit_time; 1182 - jbd_debug(1, 1183 - "Fast commit ended with blks = %d, reason = %d, subtid - %d", 1184 - nblks, reason, subtid); 1185 - if (reason == EXT4_FC_REASON_FC_FAILED) 1186 - return jbd2_fc_end_commit_fallback(journal); 1187 - if (reason == EXT4_FC_REASON_FC_START_FAILED || 1188 - reason == EXT4_FC_REASON_INELIGIBLE) 1189 - return jbd2_complete_transaction(journal, commit_tid); 1190 - return 0; 1196 + commit_time = ktime_to_ns(ktime_sub(ktime_get(), start_time)); 1197 + ext4_fc_update_stats(sb, status, commit_time, nblks); 1198 + return ret; 1199 + 1200 + fallback: 1201 + ret = jbd2_fc_end_commit_fallback(journal); 1202 + ext4_fc_update_stats(sb, status, 0, 0); 1203 + return ret; 1191 1204 } 1192 1205 1193 1206 /* ··· 1769 1812 } 1770 1813 } 1771 1814 1772 - ret = ext4_punch_hole(inode, 1773 - le32_to_cpu(lrange.fc_lblk) << sb->s_blocksize_bits, 1774 - le32_to_cpu(lrange.fc_len) << sb->s_blocksize_bits); 1775 - if (ret) 1776 - jbd_debug(1, "ext4_punch_hole returned %d", ret); 1815 + down_write(&EXT4_I(inode)->i_data_sem); 1816 + ret = ext4_ext_remove_space(inode, lrange.fc_lblk, 1817 + lrange.fc_lblk + lrange.fc_len - 1); 1818 + up_write(&EXT4_I(inode)->i_data_sem); 1819 + if (ret) { 1820 + iput(inode); 1821 + return 0; 1822 + } 1777 1823 ext4_ext_replay_shrink_inode(inode, 1778 1824 i_size_read(inode) >> sb->s_blocksize_bits); 1779 1825 ext4_mark_inode_dirty(NULL, inode); ··· 2133 2173 "fc stats:\n%ld commits\n%ld ineligible\n%ld numblks\n%lluus avg_commit_time\n", 2134 2174 stats->fc_num_commits, stats->fc_ineligible_commits, 2135 2175 stats->fc_numblks, 2136 - div_u64(sbi->s_fc_avg_commit_time, 1000)); 2176 + div_u64(stats->s_fc_avg_commit_time, 1000)); 2137 2177 seq_puts(seq, "Ineligible reasons:\n"); 2138 2178 for (i = 0; i < EXT4_FC_REASON_MAX; i++) 2139 2179 seq_printf(seq, "\"%s\":\t%d\n", fc_ineligible_reasons[i], ··· 2151 2191 return -ENOMEM; 2152 2192 2153 2193 return 0; 2194 + } 2195 + 2196 + void ext4_fc_destroy_dentry_cache(void) 2197 + { 2198 + kmem_cache_destroy(ext4_fc_dentry_cachep); 2154 2199 }
+13 -12
fs/ext4/fast_commit.h
··· 71 71 }; 72 72 73 73 /* 74 - * Fast commit reason codes 74 + * Fast commit status codes 75 75 */ 76 76 enum { 77 - /* 78 - * Commit status codes: 79 - */ 80 - EXT4_FC_REASON_OK = 0, 81 - EXT4_FC_REASON_INELIGIBLE, 82 - EXT4_FC_REASON_ALREADY_COMMITTED, 83 - EXT4_FC_REASON_FC_START_FAILED, 84 - EXT4_FC_REASON_FC_FAILED, 77 + EXT4_FC_STATUS_OK = 0, 78 + EXT4_FC_STATUS_INELIGIBLE, 79 + EXT4_FC_STATUS_SKIPPED, 80 + EXT4_FC_STATUS_FAILED, 81 + }; 85 82 86 - /* 87 - * Fast commit ineligiblity reasons: 88 - */ 83 + /* 84 + * Fast commit ineligiblity reasons: 85 + */ 86 + enum { 89 87 EXT4_FC_REASON_XATTR = 0, 90 88 EXT4_FC_REASON_CROSS_RENAME, 91 89 EXT4_FC_REASON_JOURNAL_FLAG_CHANGE, ··· 115 117 unsigned int fc_ineligible_reason_count[EXT4_FC_REASON_MAX]; 116 118 unsigned long fc_num_commits; 117 119 unsigned long fc_ineligible_commits; 120 + unsigned long fc_failed_commits; 121 + unsigned long fc_skipped_commits; 118 122 unsigned long fc_numblks; 123 + u64 s_fc_avg_commit_time; 119 124 }; 120 125 121 126 #define EXT4_FC_REPLAY_REALLOC_INCREMENT 4
-4
fs/ext4/file.c
··· 259 259 if (iocb->ki_flags & IOCB_NOWAIT) 260 260 return -EOPNOTSUPP; 261 261 262 - ext4_fc_start_update(inode); 263 262 inode_lock(inode); 264 263 ret = ext4_write_checks(iocb, from); 265 264 if (ret <= 0) ··· 270 271 271 272 out: 272 273 inode_unlock(inode); 273 - ext4_fc_stop_update(inode); 274 274 if (likely(ret > 0)) { 275 275 iocb->ki_pos += ret; 276 276 ret = generic_write_sync(iocb, ret); ··· 550 552 goto out; 551 553 } 552 554 553 - ext4_fc_start_update(inode); 554 555 ret = ext4_orphan_add(handle, inode); 555 - ext4_fc_stop_update(inode); 556 556 if (ret) { 557 557 ext4_journal_stop(handle); 558 558 goto out;
+18 -42
fs/ext4/inode.c
··· 741 741 if (ret) 742 742 return ret; 743 743 } 744 - ext4_fc_track_range(handle, inode, map->m_lblk, 745 - map->m_lblk + map->m_len - 1); 746 744 } 747 - 745 + if (retval > 0 && (map->m_flags & EXT4_MAP_UNWRITTEN || 746 + map->m_flags & EXT4_MAP_MAPPED)) 747 + ext4_fc_track_range(handle, inode, map->m_lblk, 748 + map->m_lblk + map->m_len - 1); 748 749 if (retval < 0) 749 750 ext_debug(inode, "failed with err %d\n", retval); 750 751 return retval; ··· 1845 1844 return 0; 1846 1845 } 1847 1846 1848 - static int bget_one(handle_t *handle, struct inode *inode, 1849 - struct buffer_head *bh) 1850 - { 1851 - get_bh(bh); 1852 - return 0; 1853 - } 1854 - 1855 - static int bput_one(handle_t *handle, struct inode *inode, 1856 - struct buffer_head *bh) 1857 - { 1858 - put_bh(bh); 1859 - return 0; 1860 - } 1861 - 1862 1847 static int __ext4_journalled_writepage(struct page *page, 1863 1848 unsigned int len) 1864 1849 { 1865 1850 struct address_space *mapping = page->mapping; 1866 1851 struct inode *inode = mapping->host; 1867 - struct buffer_head *page_bufs = NULL; 1868 1852 handle_t *handle = NULL; 1869 1853 int ret = 0, err = 0; 1870 1854 int inline_data = ext4_has_inline_data(inode); 1871 1855 struct buffer_head *inode_bh = NULL; 1856 + loff_t size; 1872 1857 1873 1858 ClearPageChecked(page); 1874 1859 ··· 1864 1877 inode_bh = ext4_journalled_write_inline_data(inode, len, page); 1865 1878 if (inode_bh == NULL) 1866 1879 goto out; 1867 - } else { 1868 - page_bufs = page_buffers(page); 1869 - if (!page_bufs) { 1870 - BUG(); 1871 - goto out; 1872 - } 1873 - ext4_walk_page_buffers(handle, inode, page_bufs, 0, len, 1874 - NULL, bget_one); 1875 1880 } 1876 1881 /* 1877 1882 * We need to release the page lock before we start the ··· 1884 1905 1885 1906 lock_page(page); 1886 1907 put_page(page); 1887 - if (page->mapping != mapping) { 1908 + size = i_size_read(inode); 1909 + if (page->mapping != mapping || page_offset(page) > size) { 1888 1910 /* The page got truncated from under us */ 1889 1911 ext4_journal_stop(handle); 1890 1912 ret = 0; ··· 1895 1915 if (inline_data) { 1896 1916 ret = ext4_mark_inode_dirty(handle, inode); 1897 1917 } else { 1918 + struct buffer_head *page_bufs = page_buffers(page); 1919 + 1920 + if (page->index == size >> PAGE_SHIFT) 1921 + len = size & ~PAGE_MASK; 1922 + else 1923 + len = PAGE_SIZE; 1924 + 1898 1925 ret = ext4_walk_page_buffers(handle, inode, page_bufs, 0, len, 1899 1926 NULL, do_journal_get_write_access); 1900 1927 ··· 1922 1935 out: 1923 1936 unlock_page(page); 1924 1937 out_no_pagelock: 1925 - if (!inline_data && page_bufs) 1926 - ext4_walk_page_buffers(NULL, inode, page_bufs, 0, len, 1927 - NULL, bput_one); 1928 1938 brelse(inode_bh); 1929 1939 return ret; 1930 1940 } ··· 2241 2257 mpd->map.m_len = 0; 2242 2258 mpd->map.m_flags = 0; 2243 2259 io_end_vec->size += io_end_size; 2244 - io_end_size = 0; 2245 2260 2246 2261 err = mpage_process_page_bufs(mpd, head, bh, lblk); 2247 2262 if (err > 0) ··· 2265 2282 } while (lblk++, (bh = bh->b_this_page) != head); 2266 2283 2267 2284 io_end_vec->size += io_end_size; 2268 - io_end_size = 0; 2269 2285 *map_bh = false; 2270 2286 out: 2271 2287 *m_lblk = lblk; ··· 4505 4523 static int __ext4_get_inode_loc_noinmem(struct inode *inode, 4506 4524 struct ext4_iloc *iloc) 4507 4525 { 4508 - ext4_fsblk_t err_blk; 4526 + ext4_fsblk_t err_blk = 0; 4509 4527 int ret; 4510 4528 4511 4529 ret = __ext4_get_inode_loc(inode->i_sb, inode->i_ino, NULL, iloc, ··· 4520 4538 4521 4539 int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc) 4522 4540 { 4523 - ext4_fsblk_t err_blk; 4541 + ext4_fsblk_t err_blk = 0; 4524 4542 int ret; 4525 4543 4526 4544 ret = __ext4_get_inode_loc(inode->i_sb, inode->i_ino, inode, iloc, ··· 5302 5320 if (error) 5303 5321 return error; 5304 5322 } 5305 - ext4_fc_start_update(inode); 5323 + 5306 5324 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) || 5307 5325 (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) { 5308 5326 handle_t *handle; ··· 5326 5344 5327 5345 if (error) { 5328 5346 ext4_journal_stop(handle); 5329 - ext4_fc_stop_update(inode); 5330 5347 return error; 5331 5348 } 5332 5349 /* Update corresponding info in inode so that everything is in ··· 5337 5356 error = ext4_mark_inode_dirty(handle, inode); 5338 5357 ext4_journal_stop(handle); 5339 5358 if (unlikely(error)) { 5340 - ext4_fc_stop_update(inode); 5341 5359 return error; 5342 5360 } 5343 5361 } ··· 5350 5370 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 5351 5371 5352 5372 if (attr->ia_size > sbi->s_bitmap_maxbytes) { 5353 - ext4_fc_stop_update(inode); 5354 5373 return -EFBIG; 5355 5374 } 5356 5375 } 5357 5376 if (!S_ISREG(inode->i_mode)) { 5358 - ext4_fc_stop_update(inode); 5359 5377 return -EINVAL; 5360 5378 } 5361 5379 ··· 5405 5427 ext4_fc_track_range(handle, inode, 5406 5428 (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >> 5407 5429 inode->i_sb->s_blocksize_bits, 5408 - (oldsize > 0 ? oldsize - 1 : 0) >> 5409 - inode->i_sb->s_blocksize_bits); 5430 + EXT_MAX_BLOCKS - 1); 5410 5431 else 5411 5432 ext4_fc_track_range( 5412 5433 handle, inode, ··· 5476 5499 ext4_std_error(inode->i_sb, error); 5477 5500 if (!error) 5478 5501 error = rc; 5479 - ext4_fc_stop_update(inode); 5480 5502 return error; 5481 5503 } 5482 5504
+311 -13
fs/ext4/ioctl.c
··· 27 27 #include "fsmap.h" 28 28 #include <trace/events/ext4.h> 29 29 30 + typedef void ext4_update_sb_callback(struct ext4_super_block *es, 31 + const void *arg); 32 + 33 + /* 34 + * Superblock modification callback function for changing file system 35 + * label 36 + */ 37 + static void ext4_sb_setlabel(struct ext4_super_block *es, const void *arg) 38 + { 39 + /* Sanity check, this should never happen */ 40 + BUILD_BUG_ON(sizeof(es->s_volume_name) < EXT4_LABEL_MAX); 41 + 42 + memcpy(es->s_volume_name, (char *)arg, EXT4_LABEL_MAX); 43 + } 44 + 45 + static 46 + int ext4_update_primary_sb(struct super_block *sb, handle_t *handle, 47 + ext4_update_sb_callback func, 48 + const void *arg) 49 + { 50 + int err = 0; 51 + struct ext4_sb_info *sbi = EXT4_SB(sb); 52 + struct buffer_head *bh = sbi->s_sbh; 53 + struct ext4_super_block *es = sbi->s_es; 54 + 55 + trace_ext4_update_sb(sb, bh->b_blocknr, 1); 56 + 57 + BUFFER_TRACE(bh, "get_write_access"); 58 + err = ext4_journal_get_write_access(handle, sb, 59 + bh, 60 + EXT4_JTR_NONE); 61 + if (err) 62 + goto out_err; 63 + 64 + lock_buffer(bh); 65 + func(es, arg); 66 + ext4_superblock_csum_set(sb); 67 + unlock_buffer(bh); 68 + 69 + if (buffer_write_io_error(bh) || !buffer_uptodate(bh)) { 70 + ext4_msg(sbi->s_sb, KERN_ERR, "previous I/O error to " 71 + "superblock detected"); 72 + clear_buffer_write_io_error(bh); 73 + set_buffer_uptodate(bh); 74 + } 75 + 76 + err = ext4_handle_dirty_metadata(handle, NULL, bh); 77 + if (err) 78 + goto out_err; 79 + err = sync_dirty_buffer(bh); 80 + out_err: 81 + ext4_std_error(sb, err); 82 + return err; 83 + } 84 + 85 + /* 86 + * Update one backup superblock in the group 'grp' using the callback 87 + * function 'func' and argument 'arg'. If the handle is NULL the 88 + * modification is not journalled. 89 + * 90 + * Returns: 0 when no modification was done (no superblock in the group) 91 + * 1 when the modification was successful 92 + * <0 on error 93 + */ 94 + static int ext4_update_backup_sb(struct super_block *sb, 95 + handle_t *handle, ext4_group_t grp, 96 + ext4_update_sb_callback func, const void *arg) 97 + { 98 + int err = 0; 99 + ext4_fsblk_t sb_block; 100 + struct buffer_head *bh; 101 + unsigned long offset = 0; 102 + struct ext4_super_block *es; 103 + 104 + if (!ext4_bg_has_super(sb, grp)) 105 + return 0; 106 + 107 + /* 108 + * For the group 0 there is always 1k padding, so we have 109 + * either adjust offset, or sb_block depending on blocksize 110 + */ 111 + if (grp == 0) { 112 + sb_block = 1 * EXT4_MIN_BLOCK_SIZE; 113 + offset = do_div(sb_block, sb->s_blocksize); 114 + } else { 115 + sb_block = ext4_group_first_block_no(sb, grp); 116 + offset = 0; 117 + } 118 + 119 + trace_ext4_update_sb(sb, sb_block, handle ? 1 : 0); 120 + 121 + bh = ext4_sb_bread(sb, sb_block, 0); 122 + if (IS_ERR(bh)) 123 + return PTR_ERR(bh); 124 + 125 + if (handle) { 126 + BUFFER_TRACE(bh, "get_write_access"); 127 + err = ext4_journal_get_write_access(handle, sb, 128 + bh, 129 + EXT4_JTR_NONE); 130 + if (err) 131 + goto out_bh; 132 + } 133 + 134 + es = (struct ext4_super_block *) (bh->b_data + offset); 135 + lock_buffer(bh); 136 + if (ext4_has_metadata_csum(sb) && 137 + es->s_checksum != ext4_superblock_csum(sb, es)) { 138 + ext4_msg(sb, KERN_ERR, "Invalid checksum for backup " 139 + "superblock %llu\n", sb_block); 140 + unlock_buffer(bh); 141 + err = -EFSBADCRC; 142 + goto out_bh; 143 + } 144 + func(es, arg); 145 + if (ext4_has_metadata_csum(sb)) 146 + es->s_checksum = ext4_superblock_csum(sb, es); 147 + set_buffer_uptodate(bh); 148 + unlock_buffer(bh); 149 + 150 + if (err) 151 + goto out_bh; 152 + 153 + if (handle) { 154 + err = ext4_handle_dirty_metadata(handle, NULL, bh); 155 + if (err) 156 + goto out_bh; 157 + } else { 158 + BUFFER_TRACE(bh, "marking dirty"); 159 + mark_buffer_dirty(bh); 160 + } 161 + err = sync_dirty_buffer(bh); 162 + 163 + out_bh: 164 + brelse(bh); 165 + ext4_std_error(sb, err); 166 + return (err) ? err : 1; 167 + } 168 + 169 + /* 170 + * Update primary and backup superblocks using the provided function 171 + * func and argument arg. 172 + * 173 + * Only the primary superblock and at most two backup superblock 174 + * modifications are journalled; the rest is modified without journal. 175 + * This is safe because e2fsck will re-write them if there is a problem, 176 + * and we're very unlikely to ever need more than two backups. 177 + */ 178 + static 179 + int ext4_update_superblocks_fn(struct super_block *sb, 180 + ext4_update_sb_callback func, 181 + const void *arg) 182 + { 183 + handle_t *handle; 184 + ext4_group_t ngroups; 185 + unsigned int three = 1; 186 + unsigned int five = 5; 187 + unsigned int seven = 7; 188 + int err = 0, ret, i; 189 + ext4_group_t grp, primary_grp; 190 + struct ext4_sb_info *sbi = EXT4_SB(sb); 191 + 192 + /* 193 + * We can't update superblocks while the online resize is running 194 + */ 195 + if (test_and_set_bit_lock(EXT4_FLAGS_RESIZING, 196 + &sbi->s_ext4_flags)) { 197 + ext4_msg(sb, KERN_ERR, "Can't modify superblock while" 198 + "performing online resize"); 199 + return -EBUSY; 200 + } 201 + 202 + /* 203 + * We're only going to update primary superblock and two 204 + * backup superblocks in this transaction. 205 + */ 206 + handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 3); 207 + if (IS_ERR(handle)) { 208 + err = PTR_ERR(handle); 209 + goto out; 210 + } 211 + 212 + /* Update primary superblock */ 213 + err = ext4_update_primary_sb(sb, handle, func, arg); 214 + if (err) { 215 + ext4_msg(sb, KERN_ERR, "Failed to update primary " 216 + "superblock"); 217 + goto out_journal; 218 + } 219 + 220 + primary_grp = ext4_get_group_number(sb, sbi->s_sbh->b_blocknr); 221 + ngroups = ext4_get_groups_count(sb); 222 + 223 + /* 224 + * Update backup superblocks. We have to start from group 0 225 + * because it might not be where the primary superblock is 226 + * if the fs is mounted with -o sb=<backup_sb_block> 227 + */ 228 + i = 0; 229 + grp = 0; 230 + while (grp < ngroups) { 231 + /* Skip primary superblock */ 232 + if (grp == primary_grp) 233 + goto next_grp; 234 + 235 + ret = ext4_update_backup_sb(sb, handle, grp, func, arg); 236 + if (ret < 0) { 237 + /* Ignore bad checksum; try to update next sb */ 238 + if (ret == -EFSBADCRC) 239 + goto next_grp; 240 + err = ret; 241 + goto out_journal; 242 + } 243 + 244 + i += ret; 245 + if (handle && i > 1) { 246 + /* 247 + * We're only journalling primary superblock and 248 + * two backup superblocks; the rest is not 249 + * journalled. 250 + */ 251 + err = ext4_journal_stop(handle); 252 + if (err) 253 + goto out; 254 + handle = NULL; 255 + } 256 + next_grp: 257 + grp = ext4_list_backups(sb, &three, &five, &seven); 258 + } 259 + 260 + out_journal: 261 + if (handle) { 262 + ret = ext4_journal_stop(handle); 263 + if (ret && !err) 264 + err = ret; 265 + } 266 + out: 267 + clear_bit_unlock(EXT4_FLAGS_RESIZING, &sbi->s_ext4_flags); 268 + smp_mb__after_atomic(); 269 + return err ? err : 0; 270 + } 271 + 30 272 /** 31 273 * Swap memory between @a and @b for @len bytes. 32 274 * ··· 411 169 err = -EINVAL; 412 170 goto err_out; 413 171 } 414 - ext4_fc_start_ineligible(sb, EXT4_FC_REASON_SWAP_BOOT); 172 + ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_SWAP_BOOT); 415 173 416 174 /* Protect extent tree against block allocations via delalloc */ 417 175 ext4_double_down_write_data_sem(inode, inode_bl); ··· 494 252 495 253 err_out1: 496 254 ext4_journal_stop(handle); 497 - ext4_fc_stop_ineligible(sb); 498 255 ext4_double_up_write_data_sem(inode, inode_bl); 499 256 500 257 err_out: ··· 984 743 u32 flags = fa->flags; 985 744 int err = -EOPNOTSUPP; 986 745 987 - ext4_fc_start_update(inode); 988 746 if (flags & ~EXT4_FL_USER_VISIBLE) 989 747 goto out; 990 748 ··· 1004 764 goto out; 1005 765 err = ext4_ioctl_setproject(inode, fa->fsx_projid); 1006 766 out: 1007 - ext4_fc_stop_update(inode); 1008 767 return err; 1009 768 } 1010 769 ··· 1087 848 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 1088 849 1089 850 return err; 851 + } 852 + 853 + static int ext4_ioctl_setlabel(struct file *filp, const char __user *user_label) 854 + { 855 + size_t len; 856 + int ret = 0; 857 + char new_label[EXT4_LABEL_MAX + 1]; 858 + struct super_block *sb = file_inode(filp)->i_sb; 859 + 860 + if (!capable(CAP_SYS_ADMIN)) 861 + return -EPERM; 862 + 863 + /* 864 + * Copy the maximum length allowed for ext4 label with one more to 865 + * find the required terminating null byte in order to test the 866 + * label length. The on disk label doesn't need to be null terminated. 867 + */ 868 + if (copy_from_user(new_label, user_label, EXT4_LABEL_MAX + 1)) 869 + return -EFAULT; 870 + 871 + len = strnlen(new_label, EXT4_LABEL_MAX + 1); 872 + if (len > EXT4_LABEL_MAX) 873 + return -EINVAL; 874 + 875 + /* 876 + * Clear the buffer after the new label 877 + */ 878 + memset(new_label + len, 0, EXT4_LABEL_MAX - len); 879 + 880 + ret = mnt_want_write_file(filp); 881 + if (ret) 882 + return ret; 883 + 884 + ret = ext4_update_superblocks_fn(sb, ext4_sb_setlabel, new_label); 885 + 886 + mnt_drop_write_file(filp); 887 + return ret; 888 + } 889 + 890 + static int ext4_ioctl_getlabel(struct ext4_sb_info *sbi, char __user *user_label) 891 + { 892 + char label[EXT4_LABEL_MAX + 1]; 893 + 894 + /* 895 + * EXT4_LABEL_MAX must always be smaller than FSLABEL_MAX because 896 + * FSLABEL_MAX must include terminating null byte, while s_volume_name 897 + * does not have to. 898 + */ 899 + BUILD_BUG_ON(EXT4_LABEL_MAX >= FSLABEL_MAX); 900 + 901 + memset(label, 0, sizeof(label)); 902 + lock_buffer(sbi->s_sbh); 903 + strncpy(label, sbi->s_es->s_volume_name, EXT4_LABEL_MAX); 904 + unlock_buffer(sbi->s_sbh); 905 + 906 + if (copy_to_user(user_label, label, sizeof(label))) 907 + return -EFAULT; 908 + return 0; 1090 909 } 1091 910 1092 911 static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ··· 1414 1117 sizeof(range))) 1415 1118 return -EFAULT; 1416 1119 1417 - range.minlen = max((unsigned int)range.minlen, 1418 - q->limits.discard_granularity); 1419 1120 ret = ext4_trim_fs(sb, &range); 1420 1121 if (ret < 0) 1421 1122 return ret; ··· 1561 1266 case EXT4_IOC_CHECKPOINT: 1562 1267 return ext4_ioctl_checkpoint(filp, arg); 1563 1268 1269 + case FS_IOC_GETFSLABEL: 1270 + return ext4_ioctl_getlabel(EXT4_SB(sb), (void __user *)arg); 1271 + 1272 + case FS_IOC_SETFSLABEL: 1273 + return ext4_ioctl_setlabel(filp, 1274 + (const void __user *)arg); 1275 + 1564 1276 default: 1565 1277 return -ENOTTY; 1566 1278 } ··· 1575 1273 1576 1274 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 1577 1275 { 1578 - long ret; 1579 - 1580 - ext4_fc_start_update(file_inode(filp)); 1581 - ret = __ext4_ioctl(filp, cmd, arg); 1582 - ext4_fc_stop_update(file_inode(filp)); 1583 - 1584 - return ret; 1276 + return __ext4_ioctl(filp, cmd, arg); 1585 1277 } 1586 1278 1587 1279 #ifdef CONFIG_COMPAT ··· 1643 1347 case EXT4_IOC_GETSTATE: 1644 1348 case EXT4_IOC_GET_ES_CACHE: 1645 1349 case EXT4_IOC_CHECKPOINT: 1350 + case FS_IOC_GETFSLABEL: 1351 + case FS_IOC_SETFSLABEL: 1646 1352 break; 1647 1353 default: 1648 1354 return -ENOIOCTLCMD;
+28 -24
fs/ext4/mballoc.c
··· 4814 4814 */ 4815 4815 static noinline_for_stack int 4816 4816 ext4_mb_discard_group_preallocations(struct super_block *sb, 4817 - ext4_group_t group, int needed) 4817 + ext4_group_t group, int *busy) 4818 4818 { 4819 4819 struct ext4_group_info *grp = ext4_get_group_info(sb, group); 4820 4820 struct buffer_head *bitmap_bh = NULL; ··· 4822 4822 struct list_head list; 4823 4823 struct ext4_buddy e4b; 4824 4824 int err; 4825 - int busy = 0; 4826 - int free, free_total = 0; 4825 + int free = 0; 4827 4826 4828 4827 mb_debug(sb, "discard preallocation for group %u\n", group); 4829 4828 if (list_empty(&grp->bb_prealloc_list)) ··· 4845 4846 goto out_dbg; 4846 4847 } 4847 4848 4848 - if (needed == 0) 4849 - needed = EXT4_CLUSTERS_PER_GROUP(sb) + 1; 4850 - 4851 4849 INIT_LIST_HEAD(&list); 4852 - repeat: 4853 - free = 0; 4854 4850 ext4_lock_group(sb, group); 4855 4851 list_for_each_entry_safe(pa, tmp, 4856 4852 &grp->bb_prealloc_list, pa_group_list) { 4857 4853 spin_lock(&pa->pa_lock); 4858 4854 if (atomic_read(&pa->pa_count)) { 4859 4855 spin_unlock(&pa->pa_lock); 4860 - busy = 1; 4856 + *busy = 1; 4861 4857 continue; 4862 4858 } 4863 4859 if (pa->pa_deleted) { ··· 4892 4898 call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); 4893 4899 } 4894 4900 4895 - free_total += free; 4896 - 4897 - /* if we still need more blocks and some PAs were used, try again */ 4898 - if (free_total < needed && busy) { 4899 - ext4_unlock_group(sb, group); 4900 - cond_resched(); 4901 - busy = 0; 4902 - goto repeat; 4903 - } 4904 4901 ext4_unlock_group(sb, group); 4905 4902 ext4_mb_unload_buddy(&e4b); 4906 4903 put_bh(bitmap_bh); 4907 4904 out_dbg: 4908 4905 mb_debug(sb, "discarded (%d) blocks preallocated for group %u bb_free (%d)\n", 4909 - free_total, group, grp->bb_free); 4910 - return free_total; 4906 + free, group, grp->bb_free); 4907 + return free; 4911 4908 } 4912 4909 4913 4910 /* ··· 5440 5455 { 5441 5456 ext4_group_t i, ngroups = ext4_get_groups_count(sb); 5442 5457 int ret; 5443 - int freed = 0; 5458 + int freed = 0, busy = 0; 5459 + int retry = 0; 5444 5460 5445 5461 trace_ext4_mb_discard_preallocations(sb, needed); 5462 + 5463 + if (needed == 0) 5464 + needed = EXT4_CLUSTERS_PER_GROUP(sb) + 1; 5465 + repeat: 5446 5466 for (i = 0; i < ngroups && needed > 0; i++) { 5447 - ret = ext4_mb_discard_group_preallocations(sb, i, needed); 5467 + ret = ext4_mb_discard_group_preallocations(sb, i, &busy); 5448 5468 freed += ret; 5449 5469 needed -= ret; 5470 + cond_resched(); 5471 + } 5472 + 5473 + if (needed > 0 && busy && ++retry < 3) { 5474 + busy = 0; 5475 + goto repeat; 5450 5476 } 5451 5477 5452 5478 return freed; ··· 6369 6373 ext4_lock_group(sb, group); 6370 6374 6371 6375 if (!EXT4_MB_GRP_WAS_TRIMMED(e4b.bd_info) || 6372 - minblocks < atomic_read(&EXT4_SB(sb)->s_last_trim_minblks)) { 6376 + minblocks < EXT4_SB(sb)->s_last_trim_minblks) { 6373 6377 ret = ext4_try_to_trim_range(sb, &e4b, start, max, minblocks); 6374 6378 if (ret >= 0) 6375 6379 EXT4_MB_GRP_SET_TRIMMED(e4b.bd_info); ··· 6400 6404 */ 6401 6405 int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) 6402 6406 { 6407 + struct request_queue *q = bdev_get_queue(sb->s_bdev); 6403 6408 struct ext4_group_info *grp; 6404 6409 ext4_group_t group, first_group, last_group; 6405 6410 ext4_grpblk_t cnt = 0, first_cluster, last_cluster; ··· 6419 6422 start >= max_blks || 6420 6423 range->len < sb->s_blocksize) 6421 6424 return -EINVAL; 6425 + /* No point to try to trim less than discard granularity */ 6426 + if (range->minlen < q->limits.discard_granularity) { 6427 + minlen = EXT4_NUM_B2C(EXT4_SB(sb), 6428 + q->limits.discard_granularity >> sb->s_blocksize_bits); 6429 + if (minlen > EXT4_CLUSTERS_PER_GROUP(sb)) 6430 + goto out; 6431 + } 6422 6432 if (end >= max_blks) 6423 6433 end = max_blks - 1; 6424 6434 if (end <= first_data_blk) ··· 6478 6474 } 6479 6475 6480 6476 if (!ret) 6481 - atomic_set(&EXT4_SB(sb)->s_last_trim_minblks, minlen); 6477 + EXT4_SB(sb)->s_last_trim_minblks = minlen; 6482 6478 6483 6479 out: 6484 6480 range->len = EXT4_C2B(EXT4_SB(sb), trimmed) << sb->s_blocksize_bits;
+11 -12
fs/ext4/migrate.c
··· 437 437 percpu_down_write(&sbi->s_writepages_rwsem); 438 438 439 439 /* 440 - * Worst case we can touch the allocation bitmaps, a bgd 441 - * block, and a block to link in the orphan list. We do need 442 - * need to worry about credits for modifying the quota inode. 440 + * Worst case we can touch the allocation bitmaps and a block 441 + * group descriptor block. We do need need to worry about 442 + * credits for modifying the quota inode. 443 443 */ 444 444 handle = ext4_journal_start(inode, EXT4_HT_MIGRATE, 445 - 4 + EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb)); 445 + 3 + EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb)); 446 446 447 447 if (IS_ERR(handle)) { 448 448 retval = PTR_ERR(handle); ··· 459 459 ext4_journal_stop(handle); 460 460 goto out_unlock; 461 461 } 462 + /* 463 + * Use the correct seed for checksum (i.e. the seed from 'inode'). This 464 + * is so that the metadata blocks will have the correct checksum after 465 + * the migration. 466 + */ 467 + ei = EXT4_I(inode); 468 + EXT4_I(tmp_inode)->i_csum_seed = ei->i_csum_seed; 462 469 i_size_write(tmp_inode, i_size_read(inode)); 463 470 /* 464 471 * Set the i_nlink to zero so it will be deleted later ··· 474 467 clear_nlink(tmp_inode); 475 468 476 469 ext4_ext_tree_init(handle, tmp_inode); 477 - ext4_orphan_add(handle, tmp_inode); 478 470 ext4_journal_stop(handle); 479 471 480 472 /* ··· 498 492 499 493 handle = ext4_journal_start(inode, EXT4_HT_MIGRATE, 1); 500 494 if (IS_ERR(handle)) { 501 - /* 502 - * It is impossible to update on-disk structures without 503 - * a handle, so just rollback in-core changes and live other 504 - * work to orphan_list_cleanup() 505 - */ 506 - ext4_orphan_del(NULL, tmp_inode); 507 495 retval = PTR_ERR(handle); 508 496 goto out_tmp_inode; 509 497 } 510 498 511 - ei = EXT4_I(inode); 512 499 i_data = ei->i_data; 513 500 memset(&lb, 0, sizeof(lb)); 514 501
-1
fs/ext4/move_extent.c
··· 632 632 /* Check hole before the start pos */ 633 633 if (cur_blk + cur_len - 1 < o_start) { 634 634 if (next_blk == EXT_MAX_BLOCKS) { 635 - o_start = o_end; 636 635 ret = -ENODATA; 637 636 goto out; 638 637 }
+15 -4
fs/ext4/resize.c
··· 717 717 * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ... 718 718 * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ... 719 719 */ 720 - static unsigned ext4_list_backups(struct super_block *sb, unsigned *three, 721 - unsigned *five, unsigned *seven) 720 + unsigned int ext4_list_backups(struct super_block *sb, unsigned int *three, 721 + unsigned int *five, unsigned int *seven) 722 722 { 723 - unsigned *min = three; 723 + struct ext4_super_block *es = EXT4_SB(sb)->s_es; 724 + unsigned int *min = three; 724 725 int mult = 3; 725 - unsigned ret; 726 + unsigned int ret; 727 + 728 + if (ext4_has_feature_sparse_super2(sb)) { 729 + do { 730 + if (*min > 2) 731 + return UINT_MAX; 732 + ret = le32_to_cpu(es->s_backup_bgs[*min - 1]); 733 + *min += 1; 734 + } while (!ret); 735 + return ret; 736 + } 726 737 727 738 if (!ext4_has_feature_sparse_super(sb)) { 728 739 ret = *min;
+1292 -805
fs/ext4/super.c
··· 47 47 #include <linux/kthread.h> 48 48 #include <linux/freezer.h> 49 49 #include <linux/fsnotify.h> 50 + #include <linux/fs_context.h> 51 + #include <linux/fs_parser.h> 50 52 51 53 #include "ext4.h" 52 54 #include "ext4_extents.h" /* Needed for trace points definition */ ··· 75 73 static int ext4_clear_journal_err(struct super_block *sb, 76 74 struct ext4_super_block *es); 77 75 static int ext4_sync_fs(struct super_block *sb, int wait); 78 - static int ext4_remount(struct super_block *sb, int *flags, char *data); 79 76 static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf); 80 77 static int ext4_unfreeze(struct super_block *sb); 81 78 static int ext4_freeze(struct super_block *sb); 82 - static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags, 83 - const char *dev_name, void *data); 84 79 static inline int ext2_feature_set_ok(struct super_block *sb); 85 80 static inline int ext3_feature_set_ok(struct super_block *sb); 86 81 static void ext4_destroy_lazyinit_thread(void); ··· 85 86 static void ext4_clear_request_list(void); 86 87 static struct inode *ext4_get_journal_inode(struct super_block *sb, 87 88 unsigned int journal_inum); 89 + static int ext4_validate_options(struct fs_context *fc); 90 + static int ext4_check_opt_consistency(struct fs_context *fc, 91 + struct super_block *sb); 92 + static int ext4_apply_options(struct fs_context *fc, struct super_block *sb); 93 + static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param); 94 + static int ext4_get_tree(struct fs_context *fc); 95 + static int ext4_reconfigure(struct fs_context *fc); 96 + static void ext4_fc_free(struct fs_context *fc); 97 + static int ext4_init_fs_context(struct fs_context *fc); 98 + static const struct fs_parameter_spec ext4_param_specs[]; 88 99 89 100 /* 90 101 * Lock ordering ··· 122 113 * transaction start -> page lock(s) -> i_data_sem (rw) 123 114 */ 124 115 116 + static const struct fs_context_operations ext4_context_ops = { 117 + .parse_param = ext4_parse_param, 118 + .get_tree = ext4_get_tree, 119 + .reconfigure = ext4_reconfigure, 120 + .free = ext4_fc_free, 121 + }; 122 + 123 + 125 124 #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT2) 126 125 static struct file_system_type ext2_fs_type = { 127 - .owner = THIS_MODULE, 128 - .name = "ext2", 129 - .mount = ext4_mount, 130 - .kill_sb = kill_block_super, 131 - .fs_flags = FS_REQUIRES_DEV, 126 + .owner = THIS_MODULE, 127 + .name = "ext2", 128 + .init_fs_context = ext4_init_fs_context, 129 + .parameters = ext4_param_specs, 130 + .kill_sb = kill_block_super, 131 + .fs_flags = FS_REQUIRES_DEV, 132 132 }; 133 133 MODULE_ALIAS_FS("ext2"); 134 134 MODULE_ALIAS("ext2"); ··· 148 130 149 131 150 132 static struct file_system_type ext3_fs_type = { 151 - .owner = THIS_MODULE, 152 - .name = "ext3", 153 - .mount = ext4_mount, 154 - .kill_sb = kill_block_super, 155 - .fs_flags = FS_REQUIRES_DEV, 133 + .owner = THIS_MODULE, 134 + .name = "ext3", 135 + .init_fs_context = ext4_init_fs_context, 136 + .parameters = ext4_param_specs, 137 + .kill_sb = kill_block_super, 138 + .fs_flags = FS_REQUIRES_DEV, 156 139 }; 157 140 MODULE_ALIAS_FS("ext3"); 158 141 MODULE_ALIAS("ext3"); ··· 279 260 return es->s_checksum_type == EXT4_CRC32C_CHKSUM; 280 261 } 281 262 282 - static __le32 ext4_superblock_csum(struct super_block *sb, 283 - struct ext4_super_block *es) 263 + __le32 ext4_superblock_csum(struct super_block *sb, 264 + struct ext4_super_block *es) 284 265 { 285 266 struct ext4_sb_info *sbi = EXT4_SB(sb); 286 267 int offset = offsetof(struct ext4_super_block, s_checksum); ··· 931 912 struct va_format vaf; 932 913 va_list args; 933 914 934 - atomic_inc(&EXT4_SB(sb)->s_msg_count); 935 - if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state), "EXT4-fs")) 936 - return; 915 + if (sb) { 916 + atomic_inc(&EXT4_SB(sb)->s_msg_count); 917 + if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state), 918 + "EXT4-fs")) 919 + return; 920 + } 937 921 938 922 va_start(args, fmt); 939 923 vaf.fmt = fmt; 940 924 vaf.va = &args; 941 - printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf); 925 + if (sb) 926 + printk("%sEXT4-fs (%s): %pV\n", prefix, sb->s_id, &vaf); 927 + else 928 + printk("%sEXT4-fs: %pV\n", prefix, &vaf); 942 929 va_end(args); 943 930 } 944 931 ··· 1672 1647 .freeze_fs = ext4_freeze, 1673 1648 .unfreeze_fs = ext4_unfreeze, 1674 1649 .statfs = ext4_statfs, 1675 - .remount_fs = ext4_remount, 1676 1650 .show_options = ext4_show_options, 1677 1651 #ifdef CONFIG_QUOTA 1678 1652 .quota_read = ext4_quota_read, ··· 1689 1665 1690 1666 enum { 1691 1667 Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid, 1692 - Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro, 1668 + Opt_resgid, Opt_resuid, Opt_sb, 1693 1669 Opt_nouid32, Opt_debug, Opt_removed, 1694 1670 Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, 1695 1671 Opt_auto_da_alloc, Opt_noauto_da_alloc, Opt_noload, ··· 1698 1674 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, 1699 1675 Opt_data_err_abort, Opt_data_err_ignore, Opt_test_dummy_encryption, 1700 1676 Opt_inlinecrypt, 1701 - Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, 1702 - Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota, 1677 + Opt_usrjquota, Opt_grpjquota, Opt_quota, 1703 1678 Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err, 1704 1679 Opt_usrquota, Opt_grpquota, Opt_prjquota, Opt_i_version, 1705 1680 Opt_dax, Opt_dax_always, Opt_dax_inode, Opt_dax_never, 1706 1681 Opt_stripe, Opt_delalloc, Opt_nodelalloc, Opt_warn_on_error, 1707 - Opt_nowarn_on_error, Opt_mblk_io_submit, 1708 - Opt_lazytime, Opt_nolazytime, Opt_debug_want_extra_isize, 1682 + Opt_nowarn_on_error, Opt_mblk_io_submit, Opt_debug_want_extra_isize, 1709 1683 Opt_nomblk_io_submit, Opt_block_validity, Opt_noblock_validity, 1710 1684 Opt_inode_readahead_blks, Opt_journal_ioprio, 1711 1685 Opt_dioread_nolock, Opt_dioread_lock, 1712 1686 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable, 1713 1687 Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache, 1714 1688 Opt_no_prefetch_block_bitmaps, Opt_mb_optimize_scan, 1689 + Opt_errors, Opt_data, Opt_data_err, Opt_jqfmt, Opt_dax_type, 1715 1690 #ifdef CONFIG_EXT4_DEBUG 1716 1691 Opt_fc_debug_max_replay, Opt_fc_debug_force 1717 1692 #endif 1718 1693 }; 1719 1694 1720 - static const match_table_t tokens = { 1721 - {Opt_bsd_df, "bsddf"}, 1722 - {Opt_minix_df, "minixdf"}, 1723 - {Opt_grpid, "grpid"}, 1724 - {Opt_grpid, "bsdgroups"}, 1725 - {Opt_nogrpid, "nogrpid"}, 1726 - {Opt_nogrpid, "sysvgroups"}, 1727 - {Opt_resgid, "resgid=%u"}, 1728 - {Opt_resuid, "resuid=%u"}, 1729 - {Opt_sb, "sb=%u"}, 1730 - {Opt_err_cont, "errors=continue"}, 1731 - {Opt_err_panic, "errors=panic"}, 1732 - {Opt_err_ro, "errors=remount-ro"}, 1733 - {Opt_nouid32, "nouid32"}, 1734 - {Opt_debug, "debug"}, 1735 - {Opt_removed, "oldalloc"}, 1736 - {Opt_removed, "orlov"}, 1737 - {Opt_user_xattr, "user_xattr"}, 1738 - {Opt_nouser_xattr, "nouser_xattr"}, 1739 - {Opt_acl, "acl"}, 1740 - {Opt_noacl, "noacl"}, 1741 - {Opt_noload, "norecovery"}, 1742 - {Opt_noload, "noload"}, 1743 - {Opt_removed, "nobh"}, 1744 - {Opt_removed, "bh"}, 1745 - {Opt_commit, "commit=%u"}, 1746 - {Opt_min_batch_time, "min_batch_time=%u"}, 1747 - {Opt_max_batch_time, "max_batch_time=%u"}, 1748 - {Opt_journal_dev, "journal_dev=%u"}, 1749 - {Opt_journal_path, "journal_path=%s"}, 1750 - {Opt_journal_checksum, "journal_checksum"}, 1751 - {Opt_nojournal_checksum, "nojournal_checksum"}, 1752 - {Opt_journal_async_commit, "journal_async_commit"}, 1753 - {Opt_abort, "abort"}, 1754 - {Opt_data_journal, "data=journal"}, 1755 - {Opt_data_ordered, "data=ordered"}, 1756 - {Opt_data_writeback, "data=writeback"}, 1757 - {Opt_data_err_abort, "data_err=abort"}, 1758 - {Opt_data_err_ignore, "data_err=ignore"}, 1759 - {Opt_offusrjquota, "usrjquota="}, 1760 - {Opt_usrjquota, "usrjquota=%s"}, 1761 - {Opt_offgrpjquota, "grpjquota="}, 1762 - {Opt_grpjquota, "grpjquota=%s"}, 1763 - {Opt_jqfmt_vfsold, "jqfmt=vfsold"}, 1764 - {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, 1765 - {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, 1766 - {Opt_grpquota, "grpquota"}, 1767 - {Opt_noquota, "noquota"}, 1768 - {Opt_quota, "quota"}, 1769 - {Opt_usrquota, "usrquota"}, 1770 - {Opt_prjquota, "prjquota"}, 1771 - {Opt_barrier, "barrier=%u"}, 1772 - {Opt_barrier, "barrier"}, 1773 - {Opt_nobarrier, "nobarrier"}, 1774 - {Opt_i_version, "i_version"}, 1775 - {Opt_dax, "dax"}, 1776 - {Opt_dax_always, "dax=always"}, 1777 - {Opt_dax_inode, "dax=inode"}, 1778 - {Opt_dax_never, "dax=never"}, 1779 - {Opt_stripe, "stripe=%u"}, 1780 - {Opt_delalloc, "delalloc"}, 1781 - {Opt_warn_on_error, "warn_on_error"}, 1782 - {Opt_nowarn_on_error, "nowarn_on_error"}, 1783 - {Opt_lazytime, "lazytime"}, 1784 - {Opt_nolazytime, "nolazytime"}, 1785 - {Opt_debug_want_extra_isize, "debug_want_extra_isize=%u"}, 1786 - {Opt_nodelalloc, "nodelalloc"}, 1787 - {Opt_removed, "mblk_io_submit"}, 1788 - {Opt_removed, "nomblk_io_submit"}, 1789 - {Opt_block_validity, "block_validity"}, 1790 - {Opt_noblock_validity, "noblock_validity"}, 1791 - {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, 1792 - {Opt_journal_ioprio, "journal_ioprio=%u"}, 1793 - {Opt_auto_da_alloc, "auto_da_alloc=%u"}, 1794 - {Opt_auto_da_alloc, "auto_da_alloc"}, 1795 - {Opt_noauto_da_alloc, "noauto_da_alloc"}, 1796 - {Opt_dioread_nolock, "dioread_nolock"}, 1797 - {Opt_dioread_lock, "nodioread_nolock"}, 1798 - {Opt_dioread_lock, "dioread_lock"}, 1799 - {Opt_discard, "discard"}, 1800 - {Opt_nodiscard, "nodiscard"}, 1801 - {Opt_init_itable, "init_itable=%u"}, 1802 - {Opt_init_itable, "init_itable"}, 1803 - {Opt_noinit_itable, "noinit_itable"}, 1804 - #ifdef CONFIG_EXT4_DEBUG 1805 - {Opt_fc_debug_force, "fc_debug_force"}, 1806 - {Opt_fc_debug_max_replay, "fc_debug_max_replay=%u"}, 1807 - #endif 1808 - {Opt_max_dir_size_kb, "max_dir_size_kb=%u"}, 1809 - {Opt_test_dummy_encryption, "test_dummy_encryption=%s"}, 1810 - {Opt_test_dummy_encryption, "test_dummy_encryption"}, 1811 - {Opt_inlinecrypt, "inlinecrypt"}, 1812 - {Opt_nombcache, "nombcache"}, 1813 - {Opt_nombcache, "no_mbcache"}, /* for backward compatibility */ 1814 - {Opt_removed, "prefetch_block_bitmaps"}, 1815 - {Opt_no_prefetch_block_bitmaps, "no_prefetch_block_bitmaps"}, 1816 - {Opt_mb_optimize_scan, "mb_optimize_scan=%d"}, 1817 - {Opt_removed, "check=none"}, /* mount option from ext2/3 */ 1818 - {Opt_removed, "nocheck"}, /* mount option from ext2/3 */ 1819 - {Opt_removed, "reservation"}, /* mount option from ext2/3 */ 1820 - {Opt_removed, "noreservation"}, /* mount option from ext2/3 */ 1821 - {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */ 1822 - {Opt_err, NULL}, 1695 + static const struct constant_table ext4_param_errors[] = { 1696 + {"continue", EXT4_MOUNT_ERRORS_CONT}, 1697 + {"panic", EXT4_MOUNT_ERRORS_PANIC}, 1698 + {"remount-ro", EXT4_MOUNT_ERRORS_RO}, 1699 + {} 1823 1700 }; 1824 1701 1825 - static ext4_fsblk_t get_sb_block(void **data) 1826 - { 1827 - ext4_fsblk_t sb_block; 1828 - char *options = (char *) *data; 1702 + static const struct constant_table ext4_param_data[] = { 1703 + {"journal", EXT4_MOUNT_JOURNAL_DATA}, 1704 + {"ordered", EXT4_MOUNT_ORDERED_DATA}, 1705 + {"writeback", EXT4_MOUNT_WRITEBACK_DATA}, 1706 + {} 1707 + }; 1829 1708 1830 - if (!options || strncmp(options, "sb=", 3) != 0) 1831 - return 1; /* Default location */ 1709 + static const struct constant_table ext4_param_data_err[] = { 1710 + {"abort", Opt_data_err_abort}, 1711 + {"ignore", Opt_data_err_ignore}, 1712 + {} 1713 + }; 1832 1714 1833 - options += 3; 1834 - /* TODO: use simple_strtoll with >32bit ext4 */ 1835 - sb_block = simple_strtoul(options, &options, 0); 1836 - if (*options && *options != ',') { 1837 - printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n", 1838 - (char *) *data); 1839 - return 1; 1840 - } 1841 - if (*options == ',') 1842 - options++; 1843 - *data = (void *) options; 1715 + static const struct constant_table ext4_param_jqfmt[] = { 1716 + {"vfsold", QFMT_VFS_OLD}, 1717 + {"vfsv0", QFMT_VFS_V0}, 1718 + {"vfsv1", QFMT_VFS_V1}, 1719 + {} 1720 + }; 1844 1721 1845 - return sb_block; 1846 - } 1722 + static const struct constant_table ext4_param_dax[] = { 1723 + {"always", Opt_dax_always}, 1724 + {"inode", Opt_dax_inode}, 1725 + {"never", Opt_dax_never}, 1726 + {} 1727 + }; 1728 + 1729 + /* String parameter that allows empty argument */ 1730 + #define fsparam_string_empty(NAME, OPT) \ 1731 + __fsparam(fs_param_is_string, NAME, OPT, fs_param_can_be_empty, NULL) 1732 + 1733 + /* 1734 + * Mount option specification 1735 + * We don't use fsparam_flag_no because of the way we set the 1736 + * options and the way we show them in _ext4_show_options(). To 1737 + * keep the changes to a minimum, let's keep the negative options 1738 + * separate for now. 1739 + */ 1740 + static const struct fs_parameter_spec ext4_param_specs[] = { 1741 + fsparam_flag ("bsddf", Opt_bsd_df), 1742 + fsparam_flag ("minixdf", Opt_minix_df), 1743 + fsparam_flag ("grpid", Opt_grpid), 1744 + fsparam_flag ("bsdgroups", Opt_grpid), 1745 + fsparam_flag ("nogrpid", Opt_nogrpid), 1746 + fsparam_flag ("sysvgroups", Opt_nogrpid), 1747 + fsparam_u32 ("resgid", Opt_resgid), 1748 + fsparam_u32 ("resuid", Opt_resuid), 1749 + fsparam_u32 ("sb", Opt_sb), 1750 + fsparam_enum ("errors", Opt_errors, ext4_param_errors), 1751 + fsparam_flag ("nouid32", Opt_nouid32), 1752 + fsparam_flag ("debug", Opt_debug), 1753 + fsparam_flag ("oldalloc", Opt_removed), 1754 + fsparam_flag ("orlov", Opt_removed), 1755 + fsparam_flag ("user_xattr", Opt_user_xattr), 1756 + fsparam_flag ("nouser_xattr", Opt_nouser_xattr), 1757 + fsparam_flag ("acl", Opt_acl), 1758 + fsparam_flag ("noacl", Opt_noacl), 1759 + fsparam_flag ("norecovery", Opt_noload), 1760 + fsparam_flag ("noload", Opt_noload), 1761 + fsparam_flag ("bh", Opt_removed), 1762 + fsparam_flag ("nobh", Opt_removed), 1763 + fsparam_u32 ("commit", Opt_commit), 1764 + fsparam_u32 ("min_batch_time", Opt_min_batch_time), 1765 + fsparam_u32 ("max_batch_time", Opt_max_batch_time), 1766 + fsparam_u32 ("journal_dev", Opt_journal_dev), 1767 + fsparam_bdev ("journal_path", Opt_journal_path), 1768 + fsparam_flag ("journal_checksum", Opt_journal_checksum), 1769 + fsparam_flag ("nojournal_checksum", Opt_nojournal_checksum), 1770 + fsparam_flag ("journal_async_commit",Opt_journal_async_commit), 1771 + fsparam_flag ("abort", Opt_abort), 1772 + fsparam_enum ("data", Opt_data, ext4_param_data), 1773 + fsparam_enum ("data_err", Opt_data_err, 1774 + ext4_param_data_err), 1775 + fsparam_string_empty 1776 + ("usrjquota", Opt_usrjquota), 1777 + fsparam_string_empty 1778 + ("grpjquota", Opt_grpjquota), 1779 + fsparam_enum ("jqfmt", Opt_jqfmt, ext4_param_jqfmt), 1780 + fsparam_flag ("grpquota", Opt_grpquota), 1781 + fsparam_flag ("quota", Opt_quota), 1782 + fsparam_flag ("noquota", Opt_noquota), 1783 + fsparam_flag ("usrquota", Opt_usrquota), 1784 + fsparam_flag ("prjquota", Opt_prjquota), 1785 + fsparam_flag ("barrier", Opt_barrier), 1786 + fsparam_u32 ("barrier", Opt_barrier), 1787 + fsparam_flag ("nobarrier", Opt_nobarrier), 1788 + fsparam_flag ("i_version", Opt_i_version), 1789 + fsparam_flag ("dax", Opt_dax), 1790 + fsparam_enum ("dax", Opt_dax_type, ext4_param_dax), 1791 + fsparam_u32 ("stripe", Opt_stripe), 1792 + fsparam_flag ("delalloc", Opt_delalloc), 1793 + fsparam_flag ("nodelalloc", Opt_nodelalloc), 1794 + fsparam_flag ("warn_on_error", Opt_warn_on_error), 1795 + fsparam_flag ("nowarn_on_error", Opt_nowarn_on_error), 1796 + fsparam_u32 ("debug_want_extra_isize", 1797 + Opt_debug_want_extra_isize), 1798 + fsparam_flag ("mblk_io_submit", Opt_removed), 1799 + fsparam_flag ("nomblk_io_submit", Opt_removed), 1800 + fsparam_flag ("block_validity", Opt_block_validity), 1801 + fsparam_flag ("noblock_validity", Opt_noblock_validity), 1802 + fsparam_u32 ("inode_readahead_blks", 1803 + Opt_inode_readahead_blks), 1804 + fsparam_u32 ("journal_ioprio", Opt_journal_ioprio), 1805 + fsparam_u32 ("auto_da_alloc", Opt_auto_da_alloc), 1806 + fsparam_flag ("auto_da_alloc", Opt_auto_da_alloc), 1807 + fsparam_flag ("noauto_da_alloc", Opt_noauto_da_alloc), 1808 + fsparam_flag ("dioread_nolock", Opt_dioread_nolock), 1809 + fsparam_flag ("nodioread_nolock", Opt_dioread_lock), 1810 + fsparam_flag ("dioread_lock", Opt_dioread_lock), 1811 + fsparam_flag ("discard", Opt_discard), 1812 + fsparam_flag ("nodiscard", Opt_nodiscard), 1813 + fsparam_u32 ("init_itable", Opt_init_itable), 1814 + fsparam_flag ("init_itable", Opt_init_itable), 1815 + fsparam_flag ("noinit_itable", Opt_noinit_itable), 1816 + #ifdef CONFIG_EXT4_DEBUG 1817 + fsparam_flag ("fc_debug_force", Opt_fc_debug_force), 1818 + fsparam_u32 ("fc_debug_max_replay", Opt_fc_debug_max_replay), 1819 + #endif 1820 + fsparam_u32 ("max_dir_size_kb", Opt_max_dir_size_kb), 1821 + fsparam_flag ("test_dummy_encryption", 1822 + Opt_test_dummy_encryption), 1823 + fsparam_string ("test_dummy_encryption", 1824 + Opt_test_dummy_encryption), 1825 + fsparam_flag ("inlinecrypt", Opt_inlinecrypt), 1826 + fsparam_flag ("nombcache", Opt_nombcache), 1827 + fsparam_flag ("no_mbcache", Opt_nombcache), /* for backward compatibility */ 1828 + fsparam_flag ("prefetch_block_bitmaps", 1829 + Opt_removed), 1830 + fsparam_flag ("no_prefetch_block_bitmaps", 1831 + Opt_no_prefetch_block_bitmaps), 1832 + fsparam_s32 ("mb_optimize_scan", Opt_mb_optimize_scan), 1833 + fsparam_string ("check", Opt_removed), /* mount option from ext2/3 */ 1834 + fsparam_flag ("nocheck", Opt_removed), /* mount option from ext2/3 */ 1835 + fsparam_flag ("reservation", Opt_removed), /* mount option from ext2/3 */ 1836 + fsparam_flag ("noreservation", Opt_removed), /* mount option from ext2/3 */ 1837 + fsparam_u32 ("journal", Opt_removed), /* mount option from ext2/3 */ 1838 + {} 1839 + }; 1847 1840 1848 1841 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) 1849 1842 #define DEFAULT_MB_OPTIMIZE_SCAN (-1) ··· 1869 1828 "Mount option \"%s\" will be removed by %s\n" 1870 1829 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n"; 1871 1830 1872 - #ifdef CONFIG_QUOTA 1873 - static int set_qf_name(struct super_block *sb, int qtype, substring_t *args) 1874 - { 1875 - struct ext4_sb_info *sbi = EXT4_SB(sb); 1876 - char *qname, *old_qname = get_qf_name(sb, sbi, qtype); 1877 - int ret = -1; 1878 - 1879 - if (sb_any_quota_loaded(sb) && !old_qname) { 1880 - ext4_msg(sb, KERN_ERR, 1881 - "Cannot change journaled " 1882 - "quota options when quota turned on"); 1883 - return -1; 1884 - } 1885 - if (ext4_has_feature_quota(sb)) { 1886 - ext4_msg(sb, KERN_INFO, "Journaled quota options " 1887 - "ignored when QUOTA feature is enabled"); 1888 - return 1; 1889 - } 1890 - qname = match_strdup(args); 1891 - if (!qname) { 1892 - ext4_msg(sb, KERN_ERR, 1893 - "Not enough memory for storing quotafile name"); 1894 - return -1; 1895 - } 1896 - if (old_qname) { 1897 - if (strcmp(old_qname, qname) == 0) 1898 - ret = 1; 1899 - else 1900 - ext4_msg(sb, KERN_ERR, 1901 - "%s quota file already specified", 1902 - QTYPE2NAME(qtype)); 1903 - goto errout; 1904 - } 1905 - if (strchr(qname, '/')) { 1906 - ext4_msg(sb, KERN_ERR, 1907 - "quotafile must be on filesystem root"); 1908 - goto errout; 1909 - } 1910 - rcu_assign_pointer(sbi->s_qf_names[qtype], qname); 1911 - set_opt(sb, QUOTA); 1912 - return 1; 1913 - errout: 1914 - kfree(qname); 1915 - return ret; 1916 - } 1917 - 1918 - static int clear_qf_name(struct super_block *sb, int qtype) 1919 - { 1920 - 1921 - struct ext4_sb_info *sbi = EXT4_SB(sb); 1922 - char *old_qname = get_qf_name(sb, sbi, qtype); 1923 - 1924 - if (sb_any_quota_loaded(sb) && old_qname) { 1925 - ext4_msg(sb, KERN_ERR, "Cannot change journaled quota options" 1926 - " when quota turned on"); 1927 - return -1; 1928 - } 1929 - rcu_assign_pointer(sbi->s_qf_names[qtype], NULL); 1930 - synchronize_rcu(); 1931 - kfree(old_qname); 1932 - return 1; 1933 - } 1934 - #endif 1935 - 1936 1831 #define MOPT_SET 0x0001 1937 1832 #define MOPT_CLEAR 0x0002 1938 1833 #define MOPT_NOSUPPORT 0x0004 1939 1834 #define MOPT_EXPLICIT 0x0008 1940 - #define MOPT_CLEAR_ERR 0x0010 1941 - #define MOPT_GTE0 0x0020 1942 1835 #ifdef CONFIG_QUOTA 1943 1836 #define MOPT_Q 0 1944 - #define MOPT_QFMT 0x0040 1837 + #define MOPT_QFMT 0x0010 1945 1838 #else 1946 1839 #define MOPT_Q MOPT_NOSUPPORT 1947 1840 #define MOPT_QFMT MOPT_NOSUPPORT 1948 1841 #endif 1949 - #define MOPT_DATAJ 0x0080 1950 - #define MOPT_NO_EXT2 0x0100 1951 - #define MOPT_NO_EXT3 0x0200 1842 + #define MOPT_NO_EXT2 0x0020 1843 + #define MOPT_NO_EXT3 0x0040 1952 1844 #define MOPT_EXT4_ONLY (MOPT_NO_EXT2 | MOPT_NO_EXT3) 1953 - #define MOPT_STRING 0x0400 1954 - #define MOPT_SKIP 0x0800 1955 - #define MOPT_2 0x1000 1845 + #define MOPT_SKIP 0x0080 1846 + #define MOPT_2 0x0100 1956 1847 1957 1848 static const struct mount_opts { 1958 1849 int token; ··· 1917 1944 EXT4_MOUNT_JOURNAL_CHECKSUM), 1918 1945 MOPT_EXT4_ONLY | MOPT_SET | MOPT_EXPLICIT}, 1919 1946 {Opt_noload, EXT4_MOUNT_NOLOAD, MOPT_NO_EXT2 | MOPT_SET}, 1920 - {Opt_err_panic, EXT4_MOUNT_ERRORS_PANIC, MOPT_SET | MOPT_CLEAR_ERR}, 1921 - {Opt_err_ro, EXT4_MOUNT_ERRORS_RO, MOPT_SET | MOPT_CLEAR_ERR}, 1922 - {Opt_err_cont, EXT4_MOUNT_ERRORS_CONT, MOPT_SET | MOPT_CLEAR_ERR}, 1923 - {Opt_data_err_abort, EXT4_MOUNT_DATA_ERR_ABORT, 1924 - MOPT_NO_EXT2}, 1925 - {Opt_data_err_ignore, EXT4_MOUNT_DATA_ERR_ABORT, 1926 - MOPT_NO_EXT2}, 1947 + {Opt_data_err, EXT4_MOUNT_DATA_ERR_ABORT, MOPT_NO_EXT2}, 1927 1948 {Opt_barrier, EXT4_MOUNT_BARRIER, MOPT_SET}, 1928 1949 {Opt_nobarrier, EXT4_MOUNT_BARRIER, MOPT_CLEAR}, 1929 1950 {Opt_noauto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_SET}, 1930 1951 {Opt_auto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_CLEAR}, 1931 1952 {Opt_noinit_itable, EXT4_MOUNT_INIT_INODE_TABLE, MOPT_CLEAR}, 1932 - {Opt_commit, 0, MOPT_GTE0}, 1933 - {Opt_max_batch_time, 0, MOPT_GTE0}, 1934 - {Opt_min_batch_time, 0, MOPT_GTE0}, 1935 - {Opt_inode_readahead_blks, 0, MOPT_GTE0}, 1936 - {Opt_init_itable, 0, MOPT_GTE0}, 1937 - {Opt_dax, EXT4_MOUNT_DAX_ALWAYS, MOPT_SET | MOPT_SKIP}, 1938 - {Opt_dax_always, EXT4_MOUNT_DAX_ALWAYS, 1939 - MOPT_EXT4_ONLY | MOPT_SET | MOPT_SKIP}, 1940 - {Opt_dax_inode, EXT4_MOUNT2_DAX_INODE, 1941 - MOPT_EXT4_ONLY | MOPT_SET | MOPT_SKIP}, 1942 - {Opt_dax_never, EXT4_MOUNT2_DAX_NEVER, 1943 - MOPT_EXT4_ONLY | MOPT_SET | MOPT_SKIP}, 1944 - {Opt_stripe, 0, MOPT_GTE0}, 1945 - {Opt_resuid, 0, MOPT_GTE0}, 1946 - {Opt_resgid, 0, MOPT_GTE0}, 1947 - {Opt_journal_dev, 0, MOPT_NO_EXT2 | MOPT_GTE0}, 1948 - {Opt_journal_path, 0, MOPT_NO_EXT2 | MOPT_STRING}, 1949 - {Opt_journal_ioprio, 0, MOPT_NO_EXT2 | MOPT_GTE0}, 1950 - {Opt_data_journal, EXT4_MOUNT_JOURNAL_DATA, MOPT_NO_EXT2 | MOPT_DATAJ}, 1951 - {Opt_data_ordered, EXT4_MOUNT_ORDERED_DATA, MOPT_NO_EXT2 | MOPT_DATAJ}, 1952 - {Opt_data_writeback, EXT4_MOUNT_WRITEBACK_DATA, 1953 - MOPT_NO_EXT2 | MOPT_DATAJ}, 1953 + {Opt_dax_type, 0, MOPT_EXT4_ONLY}, 1954 + {Opt_journal_dev, 0, MOPT_NO_EXT2}, 1955 + {Opt_journal_path, 0, MOPT_NO_EXT2}, 1956 + {Opt_journal_ioprio, 0, MOPT_NO_EXT2}, 1957 + {Opt_data, 0, MOPT_NO_EXT2}, 1954 1958 {Opt_user_xattr, EXT4_MOUNT_XATTR_USER, MOPT_SET}, 1955 1959 {Opt_nouser_xattr, EXT4_MOUNT_XATTR_USER, MOPT_CLEAR}, 1956 1960 #ifdef CONFIG_EXT4_FS_POSIX_ACL ··· 1939 1989 #endif 1940 1990 {Opt_nouid32, EXT4_MOUNT_NO_UID32, MOPT_SET}, 1941 1991 {Opt_debug, EXT4_MOUNT_DEBUG, MOPT_SET}, 1942 - {Opt_debug_want_extra_isize, 0, MOPT_GTE0}, 1943 1992 {Opt_quota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA, MOPT_SET | MOPT_Q}, 1944 1993 {Opt_usrquota, EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA, 1945 1994 MOPT_SET | MOPT_Q}, ··· 1949 2000 {Opt_noquota, (EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA | 1950 2001 EXT4_MOUNT_GRPQUOTA | EXT4_MOUNT_PRJQUOTA), 1951 2002 MOPT_CLEAR | MOPT_Q}, 1952 - {Opt_usrjquota, 0, MOPT_Q | MOPT_STRING}, 1953 - {Opt_grpjquota, 0, MOPT_Q | MOPT_STRING}, 1954 - {Opt_offusrjquota, 0, MOPT_Q}, 1955 - {Opt_offgrpjquota, 0, MOPT_Q}, 1956 - {Opt_jqfmt_vfsold, QFMT_VFS_OLD, MOPT_QFMT}, 1957 - {Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT}, 1958 - {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT}, 1959 - {Opt_max_dir_size_kb, 0, MOPT_GTE0}, 1960 - {Opt_test_dummy_encryption, 0, MOPT_STRING}, 2003 + {Opt_usrjquota, 0, MOPT_Q}, 2004 + {Opt_grpjquota, 0, MOPT_Q}, 2005 + {Opt_jqfmt, 0, MOPT_QFMT}, 1961 2006 {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET}, 1962 2007 {Opt_no_prefetch_block_bitmaps, EXT4_MOUNT_NO_PREFETCH_BLOCK_BITMAPS, 1963 2008 MOPT_SET}, 1964 - {Opt_mb_optimize_scan, EXT4_MOUNT2_MB_OPTIMIZE_SCAN, MOPT_GTE0}, 1965 2009 #ifdef CONFIG_EXT4_DEBUG 1966 2010 {Opt_fc_debug_force, EXT4_MOUNT2_JOURNAL_FAST_COMMIT, 1967 2011 MOPT_SET | MOPT_2 | MOPT_EXT4_ONLY}, 1968 - {Opt_fc_debug_max_replay, 0, MOPT_GTE0}, 1969 2012 #endif 1970 2013 {Opt_err, 0, 0} 1971 2014 }; ··· 1992 2051 } 1993 2052 #endif 1994 2053 1995 - static int ext4_set_test_dummy_encryption(struct super_block *sb, 1996 - const char *opt, 1997 - const substring_t *arg, 1998 - bool is_remount) 2054 + static int ext4_set_test_dummy_encryption(struct super_block *sb, char *arg) 1999 2055 { 2000 2056 #ifdef CONFIG_FS_ENCRYPTION 2001 2057 struct ext4_sb_info *sbi = EXT4_SB(sb); 2002 2058 int err; 2003 2059 2060 + err = fscrypt_set_test_dummy_encryption(sb, arg, 2061 + &sbi->s_dummy_enc_policy); 2062 + if (err) { 2063 + ext4_msg(sb, KERN_WARNING, 2064 + "Error while setting test dummy encryption [%d]", err); 2065 + return err; 2066 + } 2067 + ext4_msg(sb, KERN_WARNING, "Test dummy encryption mode enabled"); 2068 + #endif 2069 + return 0; 2070 + } 2071 + 2072 + #define EXT4_SPEC_JQUOTA (1 << 0) 2073 + #define EXT4_SPEC_JQFMT (1 << 1) 2074 + #define EXT4_SPEC_DATAJ (1 << 2) 2075 + #define EXT4_SPEC_SB_BLOCK (1 << 3) 2076 + #define EXT4_SPEC_JOURNAL_DEV (1 << 4) 2077 + #define EXT4_SPEC_JOURNAL_IOPRIO (1 << 5) 2078 + #define EXT4_SPEC_DUMMY_ENCRYPTION (1 << 6) 2079 + #define EXT4_SPEC_s_want_extra_isize (1 << 7) 2080 + #define EXT4_SPEC_s_max_batch_time (1 << 8) 2081 + #define EXT4_SPEC_s_min_batch_time (1 << 9) 2082 + #define EXT4_SPEC_s_inode_readahead_blks (1 << 10) 2083 + #define EXT4_SPEC_s_li_wait_mult (1 << 11) 2084 + #define EXT4_SPEC_s_max_dir_size_kb (1 << 12) 2085 + #define EXT4_SPEC_s_stripe (1 << 13) 2086 + #define EXT4_SPEC_s_resuid (1 << 14) 2087 + #define EXT4_SPEC_s_resgid (1 << 15) 2088 + #define EXT4_SPEC_s_commit_interval (1 << 16) 2089 + #define EXT4_SPEC_s_fc_debug_max_replay (1 << 17) 2090 + #define EXT4_SPEC_s_sb_block (1 << 18) 2091 + 2092 + struct ext4_fs_context { 2093 + char *s_qf_names[EXT4_MAXQUOTAS]; 2094 + char *test_dummy_enc_arg; 2095 + int s_jquota_fmt; /* Format of quota to use */ 2096 + int mb_optimize_scan; 2097 + #ifdef CONFIG_EXT4_DEBUG 2098 + int s_fc_debug_max_replay; 2099 + #endif 2100 + unsigned short qname_spec; 2101 + unsigned long vals_s_flags; /* Bits to set in s_flags */ 2102 + unsigned long mask_s_flags; /* Bits changed in s_flags */ 2103 + unsigned long journal_devnum; 2104 + unsigned long s_commit_interval; 2105 + unsigned long s_stripe; 2106 + unsigned int s_inode_readahead_blks; 2107 + unsigned int s_want_extra_isize; 2108 + unsigned int s_li_wait_mult; 2109 + unsigned int s_max_dir_size_kb; 2110 + unsigned int journal_ioprio; 2111 + unsigned int vals_s_mount_opt; 2112 + unsigned int mask_s_mount_opt; 2113 + unsigned int vals_s_mount_opt2; 2114 + unsigned int mask_s_mount_opt2; 2115 + unsigned int vals_s_mount_flags; 2116 + unsigned int mask_s_mount_flags; 2117 + unsigned int opt_flags; /* MOPT flags */ 2118 + unsigned int spec; 2119 + u32 s_max_batch_time; 2120 + u32 s_min_batch_time; 2121 + kuid_t s_resuid; 2122 + kgid_t s_resgid; 2123 + ext4_fsblk_t s_sb_block; 2124 + }; 2125 + 2126 + static void ext4_fc_free(struct fs_context *fc) 2127 + { 2128 + struct ext4_fs_context *ctx = fc->fs_private; 2129 + int i; 2130 + 2131 + if (!ctx) 2132 + return; 2133 + 2134 + for (i = 0; i < EXT4_MAXQUOTAS; i++) 2135 + kfree(ctx->s_qf_names[i]); 2136 + 2137 + kfree(ctx->test_dummy_enc_arg); 2138 + kfree(ctx); 2139 + } 2140 + 2141 + int ext4_init_fs_context(struct fs_context *fc) 2142 + { 2143 + struct ext4_fs_context *ctx; 2144 + 2145 + ctx = kzalloc(sizeof(struct ext4_fs_context), GFP_KERNEL); 2146 + if (!ctx) 2147 + return -ENOMEM; 2148 + 2149 + fc->fs_private = ctx; 2150 + fc->ops = &ext4_context_ops; 2151 + 2152 + return 0; 2153 + } 2154 + 2155 + #ifdef CONFIG_QUOTA 2156 + /* 2157 + * Note the name of the specified quota file. 2158 + */ 2159 + static int note_qf_name(struct fs_context *fc, int qtype, 2160 + struct fs_parameter *param) 2161 + { 2162 + struct ext4_fs_context *ctx = fc->fs_private; 2163 + char *qname; 2164 + 2165 + if (param->size < 1) { 2166 + ext4_msg(NULL, KERN_ERR, "Missing quota name"); 2167 + return -EINVAL; 2168 + } 2169 + if (strchr(param->string, '/')) { 2170 + ext4_msg(NULL, KERN_ERR, 2171 + "quotafile must be on filesystem root"); 2172 + return -EINVAL; 2173 + } 2174 + if (ctx->s_qf_names[qtype]) { 2175 + if (strcmp(ctx->s_qf_names[qtype], param->string) != 0) { 2176 + ext4_msg(NULL, KERN_ERR, 2177 + "%s quota file already specified", 2178 + QTYPE2NAME(qtype)); 2179 + return -EINVAL; 2180 + } 2181 + return 0; 2182 + } 2183 + 2184 + qname = kmemdup_nul(param->string, param->size, GFP_KERNEL); 2185 + if (!qname) { 2186 + ext4_msg(NULL, KERN_ERR, 2187 + "Not enough memory for storing quotafile name"); 2188 + return -ENOMEM; 2189 + } 2190 + ctx->s_qf_names[qtype] = qname; 2191 + ctx->qname_spec |= 1 << qtype; 2192 + ctx->spec |= EXT4_SPEC_JQUOTA; 2193 + return 0; 2194 + } 2195 + 2196 + /* 2197 + * Clear the name of the specified quota file. 2198 + */ 2199 + static int unnote_qf_name(struct fs_context *fc, int qtype) 2200 + { 2201 + struct ext4_fs_context *ctx = fc->fs_private; 2202 + 2203 + if (ctx->s_qf_names[qtype]) 2204 + kfree(ctx->s_qf_names[qtype]); 2205 + 2206 + ctx->s_qf_names[qtype] = NULL; 2207 + ctx->qname_spec |= 1 << qtype; 2208 + ctx->spec |= EXT4_SPEC_JQUOTA; 2209 + return 0; 2210 + } 2211 + #endif 2212 + 2213 + #define EXT4_SET_CTX(name) \ 2214 + static inline void ctx_set_##name(struct ext4_fs_context *ctx, \ 2215 + unsigned long flag) \ 2216 + { \ 2217 + ctx->mask_s_##name |= flag; \ 2218 + ctx->vals_s_##name |= flag; \ 2219 + } \ 2220 + static inline void ctx_clear_##name(struct ext4_fs_context *ctx, \ 2221 + unsigned long flag) \ 2222 + { \ 2223 + ctx->mask_s_##name |= flag; \ 2224 + ctx->vals_s_##name &= ~flag; \ 2225 + } \ 2226 + static inline unsigned long \ 2227 + ctx_test_##name(struct ext4_fs_context *ctx, unsigned long flag) \ 2228 + { \ 2229 + return (ctx->vals_s_##name & flag); \ 2230 + } \ 2231 + 2232 + EXT4_SET_CTX(flags); 2233 + EXT4_SET_CTX(mount_opt); 2234 + EXT4_SET_CTX(mount_opt2); 2235 + EXT4_SET_CTX(mount_flags); 2236 + 2237 + static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param) 2238 + { 2239 + struct ext4_fs_context *ctx = fc->fs_private; 2240 + struct fs_parse_result result; 2241 + const struct mount_opts *m; 2242 + int is_remount; 2243 + kuid_t uid; 2244 + kgid_t gid; 2245 + int token; 2246 + 2247 + token = fs_parse(fc, ext4_param_specs, param, &result); 2248 + if (token < 0) 2249 + return token; 2250 + is_remount = fc->purpose == FS_CONTEXT_FOR_RECONFIGURE; 2251 + 2252 + for (m = ext4_mount_opts; m->token != Opt_err; m++) 2253 + if (token == m->token) 2254 + break; 2255 + 2256 + ctx->opt_flags |= m->flags; 2257 + 2258 + if (m->flags & MOPT_EXPLICIT) { 2259 + if (m->mount_opt & EXT4_MOUNT_DELALLOC) { 2260 + ctx_set_mount_opt2(ctx, EXT4_MOUNT2_EXPLICIT_DELALLOC); 2261 + } else if (m->mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) { 2262 + ctx_set_mount_opt2(ctx, 2263 + EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM); 2264 + } else 2265 + return -EINVAL; 2266 + } 2267 + 2268 + if (m->flags & MOPT_NOSUPPORT) { 2269 + ext4_msg(NULL, KERN_ERR, "%s option not supported", 2270 + param->key); 2271 + return 0; 2272 + } 2273 + 2274 + switch (token) { 2275 + #ifdef CONFIG_QUOTA 2276 + case Opt_usrjquota: 2277 + if (!*param->string) 2278 + return unnote_qf_name(fc, USRQUOTA); 2279 + else 2280 + return note_qf_name(fc, USRQUOTA, param); 2281 + case Opt_grpjquota: 2282 + if (!*param->string) 2283 + return unnote_qf_name(fc, GRPQUOTA); 2284 + else 2285 + return note_qf_name(fc, GRPQUOTA, param); 2286 + #endif 2287 + case Opt_noacl: 2288 + case Opt_nouser_xattr: 2289 + ext4_msg(NULL, KERN_WARNING, deprecated_msg, param->key, "3.5"); 2290 + break; 2291 + case Opt_sb: 2292 + if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) { 2293 + ext4_msg(NULL, KERN_WARNING, 2294 + "Ignoring %s option on remount", param->key); 2295 + } else { 2296 + ctx->s_sb_block = result.uint_32; 2297 + ctx->spec |= EXT4_SPEC_s_sb_block; 2298 + } 2299 + return 0; 2300 + case Opt_removed: 2301 + ext4_msg(NULL, KERN_WARNING, "Ignoring removed %s option", 2302 + param->key); 2303 + return 0; 2304 + case Opt_abort: 2305 + ctx_set_mount_flags(ctx, EXT4_MF_FS_ABORTED); 2306 + return 0; 2307 + case Opt_i_version: 2308 + ext4_msg(NULL, KERN_WARNING, deprecated_msg, param->key, "5.20"); 2309 + ext4_msg(NULL, KERN_WARNING, "Use iversion instead\n"); 2310 + ctx_set_flags(ctx, SB_I_VERSION); 2311 + return 0; 2312 + case Opt_inlinecrypt: 2313 + #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT 2314 + ctx_set_flags(ctx, SB_INLINECRYPT); 2315 + #else 2316 + ext4_msg(NULL, KERN_ERR, "inline encryption not supported"); 2317 + #endif 2318 + return 0; 2319 + case Opt_errors: 2320 + ctx_clear_mount_opt(ctx, EXT4_MOUNT_ERRORS_MASK); 2321 + ctx_set_mount_opt(ctx, result.uint_32); 2322 + return 0; 2323 + #ifdef CONFIG_QUOTA 2324 + case Opt_jqfmt: 2325 + ctx->s_jquota_fmt = result.uint_32; 2326 + ctx->spec |= EXT4_SPEC_JQFMT; 2327 + return 0; 2328 + #endif 2329 + case Opt_data: 2330 + ctx_clear_mount_opt(ctx, EXT4_MOUNT_DATA_FLAGS); 2331 + ctx_set_mount_opt(ctx, result.uint_32); 2332 + ctx->spec |= EXT4_SPEC_DATAJ; 2333 + return 0; 2334 + case Opt_commit: 2335 + if (result.uint_32 == 0) 2336 + ctx->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE; 2337 + else if (result.uint_32 > INT_MAX / HZ) { 2338 + ext4_msg(NULL, KERN_ERR, 2339 + "Invalid commit interval %d, " 2340 + "must be smaller than %d", 2341 + result.uint_32, INT_MAX / HZ); 2342 + return -EINVAL; 2343 + } 2344 + ctx->s_commit_interval = HZ * result.uint_32; 2345 + ctx->spec |= EXT4_SPEC_s_commit_interval; 2346 + return 0; 2347 + case Opt_debug_want_extra_isize: 2348 + if ((result.uint_32 & 1) || (result.uint_32 < 4)) { 2349 + ext4_msg(NULL, KERN_ERR, 2350 + "Invalid want_extra_isize %d", result.uint_32); 2351 + return -EINVAL; 2352 + } 2353 + ctx->s_want_extra_isize = result.uint_32; 2354 + ctx->spec |= EXT4_SPEC_s_want_extra_isize; 2355 + return 0; 2356 + case Opt_max_batch_time: 2357 + ctx->s_max_batch_time = result.uint_32; 2358 + ctx->spec |= EXT4_SPEC_s_max_batch_time; 2359 + return 0; 2360 + case Opt_min_batch_time: 2361 + ctx->s_min_batch_time = result.uint_32; 2362 + ctx->spec |= EXT4_SPEC_s_min_batch_time; 2363 + return 0; 2364 + case Opt_inode_readahead_blks: 2365 + if (result.uint_32 && 2366 + (result.uint_32 > (1 << 30) || 2367 + !is_power_of_2(result.uint_32))) { 2368 + ext4_msg(NULL, KERN_ERR, 2369 + "EXT4-fs: inode_readahead_blks must be " 2370 + "0 or a power of 2 smaller than 2^31"); 2371 + return -EINVAL; 2372 + } 2373 + ctx->s_inode_readahead_blks = result.uint_32; 2374 + ctx->spec |= EXT4_SPEC_s_inode_readahead_blks; 2375 + return 0; 2376 + case Opt_init_itable: 2377 + ctx_set_mount_opt(ctx, EXT4_MOUNT_INIT_INODE_TABLE); 2378 + ctx->s_li_wait_mult = EXT4_DEF_LI_WAIT_MULT; 2379 + if (param->type == fs_value_is_string) 2380 + ctx->s_li_wait_mult = result.uint_32; 2381 + ctx->spec |= EXT4_SPEC_s_li_wait_mult; 2382 + return 0; 2383 + case Opt_max_dir_size_kb: 2384 + ctx->s_max_dir_size_kb = result.uint_32; 2385 + ctx->spec |= EXT4_SPEC_s_max_dir_size_kb; 2386 + return 0; 2387 + #ifdef CONFIG_EXT4_DEBUG 2388 + case Opt_fc_debug_max_replay: 2389 + ctx->s_fc_debug_max_replay = result.uint_32; 2390 + ctx->spec |= EXT4_SPEC_s_fc_debug_max_replay; 2391 + return 0; 2392 + #endif 2393 + case Opt_stripe: 2394 + ctx->s_stripe = result.uint_32; 2395 + ctx->spec |= EXT4_SPEC_s_stripe; 2396 + return 0; 2397 + case Opt_resuid: 2398 + uid = make_kuid(current_user_ns(), result.uint_32); 2399 + if (!uid_valid(uid)) { 2400 + ext4_msg(NULL, KERN_ERR, "Invalid uid value %d", 2401 + result.uint_32); 2402 + return -EINVAL; 2403 + } 2404 + ctx->s_resuid = uid; 2405 + ctx->spec |= EXT4_SPEC_s_resuid; 2406 + return 0; 2407 + case Opt_resgid: 2408 + gid = make_kgid(current_user_ns(), result.uint_32); 2409 + if (!gid_valid(gid)) { 2410 + ext4_msg(NULL, KERN_ERR, "Invalid gid value %d", 2411 + result.uint_32); 2412 + return -EINVAL; 2413 + } 2414 + ctx->s_resgid = gid; 2415 + ctx->spec |= EXT4_SPEC_s_resgid; 2416 + return 0; 2417 + case Opt_journal_dev: 2418 + if (is_remount) { 2419 + ext4_msg(NULL, KERN_ERR, 2420 + "Cannot specify journal on remount"); 2421 + return -EINVAL; 2422 + } 2423 + ctx->journal_devnum = result.uint_32; 2424 + ctx->spec |= EXT4_SPEC_JOURNAL_DEV; 2425 + return 0; 2426 + case Opt_journal_path: 2427 + { 2428 + struct inode *journal_inode; 2429 + struct path path; 2430 + int error; 2431 + 2432 + if (is_remount) { 2433 + ext4_msg(NULL, KERN_ERR, 2434 + "Cannot specify journal on remount"); 2435 + return -EINVAL; 2436 + } 2437 + 2438 + error = fs_lookup_param(fc, param, 1, &path); 2439 + if (error) { 2440 + ext4_msg(NULL, KERN_ERR, "error: could not find " 2441 + "journal device path"); 2442 + return -EINVAL; 2443 + } 2444 + 2445 + journal_inode = d_inode(path.dentry); 2446 + ctx->journal_devnum = new_encode_dev(journal_inode->i_rdev); 2447 + ctx->spec |= EXT4_SPEC_JOURNAL_DEV; 2448 + path_put(&path); 2449 + return 0; 2450 + } 2451 + case Opt_journal_ioprio: 2452 + if (result.uint_32 > 7) { 2453 + ext4_msg(NULL, KERN_ERR, "Invalid journal IO priority" 2454 + " (must be 0-7)"); 2455 + return -EINVAL; 2456 + } 2457 + ctx->journal_ioprio = 2458 + IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, result.uint_32); 2459 + ctx->spec |= EXT4_SPEC_JOURNAL_IOPRIO; 2460 + return 0; 2461 + case Opt_test_dummy_encryption: 2462 + #ifdef CONFIG_FS_ENCRYPTION 2463 + if (param->type == fs_value_is_flag) { 2464 + ctx->spec |= EXT4_SPEC_DUMMY_ENCRYPTION; 2465 + ctx->test_dummy_enc_arg = NULL; 2466 + return 0; 2467 + } 2468 + if (*param->string && 2469 + !(!strcmp(param->string, "v1") || 2470 + !strcmp(param->string, "v2"))) { 2471 + ext4_msg(NULL, KERN_WARNING, 2472 + "Value of option \"%s\" is unrecognized", 2473 + param->key); 2474 + return -EINVAL; 2475 + } 2476 + ctx->spec |= EXT4_SPEC_DUMMY_ENCRYPTION; 2477 + ctx->test_dummy_enc_arg = kmemdup_nul(param->string, param->size, 2478 + GFP_KERNEL); 2479 + #else 2480 + ext4_msg(NULL, KERN_WARNING, 2481 + "Test dummy encryption mount option ignored"); 2482 + #endif 2483 + return 0; 2484 + case Opt_dax: 2485 + case Opt_dax_type: 2486 + #ifdef CONFIG_FS_DAX 2487 + { 2488 + int type = (token == Opt_dax) ? 2489 + Opt_dax : result.uint_32; 2490 + 2491 + switch (type) { 2492 + case Opt_dax: 2493 + case Opt_dax_always: 2494 + ctx_set_mount_opt(ctx, EXT4_MOUNT_DAX_ALWAYS); 2495 + ctx_clear_mount_opt2(ctx, EXT4_MOUNT2_DAX_NEVER); 2496 + break; 2497 + case Opt_dax_never: 2498 + ctx_set_mount_opt2(ctx, EXT4_MOUNT2_DAX_NEVER); 2499 + ctx_clear_mount_opt(ctx, EXT4_MOUNT_DAX_ALWAYS); 2500 + break; 2501 + case Opt_dax_inode: 2502 + ctx_clear_mount_opt(ctx, EXT4_MOUNT_DAX_ALWAYS); 2503 + ctx_clear_mount_opt2(ctx, EXT4_MOUNT2_DAX_NEVER); 2504 + /* Strictly for printing options */ 2505 + ctx_set_mount_opt2(ctx, EXT4_MOUNT2_DAX_INODE); 2506 + break; 2507 + } 2508 + return 0; 2509 + } 2510 + #else 2511 + ext4_msg(NULL, KERN_INFO, "dax option not supported"); 2512 + return -EINVAL; 2513 + #endif 2514 + case Opt_data_err: 2515 + if (result.uint_32 == Opt_data_err_abort) 2516 + ctx_set_mount_opt(ctx, m->mount_opt); 2517 + else if (result.uint_32 == Opt_data_err_ignore) 2518 + ctx_clear_mount_opt(ctx, m->mount_opt); 2519 + return 0; 2520 + case Opt_mb_optimize_scan: 2521 + if (result.int_32 != 0 && result.int_32 != 1) { 2522 + ext4_msg(NULL, KERN_WARNING, 2523 + "mb_optimize_scan should be set to 0 or 1."); 2524 + return -EINVAL; 2525 + } 2526 + ctx->mb_optimize_scan = result.int_32; 2527 + return 0; 2528 + } 2529 + 2530 + /* 2531 + * At this point we should only be getting options requiring MOPT_SET, 2532 + * or MOPT_CLEAR. Anything else is a bug 2533 + */ 2534 + if (m->token == Opt_err) { 2535 + ext4_msg(NULL, KERN_WARNING, "buggy handling of option %s", 2536 + param->key); 2537 + WARN_ON(1); 2538 + return -EINVAL; 2539 + } 2540 + 2541 + else { 2542 + unsigned int set = 0; 2543 + 2544 + if ((param->type == fs_value_is_flag) || 2545 + result.uint_32 > 0) 2546 + set = 1; 2547 + 2548 + if (m->flags & MOPT_CLEAR) 2549 + set = !set; 2550 + else if (unlikely(!(m->flags & MOPT_SET))) { 2551 + ext4_msg(NULL, KERN_WARNING, 2552 + "buggy handling of option %s", 2553 + param->key); 2554 + WARN_ON(1); 2555 + return -EINVAL; 2556 + } 2557 + if (m->flags & MOPT_2) { 2558 + if (set != 0) 2559 + ctx_set_mount_opt2(ctx, m->mount_opt); 2560 + else 2561 + ctx_clear_mount_opt2(ctx, m->mount_opt); 2562 + } else { 2563 + if (set != 0) 2564 + ctx_set_mount_opt(ctx, m->mount_opt); 2565 + else 2566 + ctx_clear_mount_opt(ctx, m->mount_opt); 2567 + } 2568 + } 2569 + 2570 + return 0; 2571 + } 2572 + 2573 + static int parse_options(struct fs_context *fc, char *options) 2574 + { 2575 + struct fs_parameter param; 2576 + int ret; 2577 + char *key; 2578 + 2579 + if (!options) 2580 + return 0; 2581 + 2582 + while ((key = strsep(&options, ",")) != NULL) { 2583 + if (*key) { 2584 + size_t v_len = 0; 2585 + char *value = strchr(key, '='); 2586 + 2587 + param.type = fs_value_is_flag; 2588 + param.string = NULL; 2589 + 2590 + if (value) { 2591 + if (value == key) 2592 + continue; 2593 + 2594 + *value++ = 0; 2595 + v_len = strlen(value); 2596 + param.string = kmemdup_nul(value, v_len, 2597 + GFP_KERNEL); 2598 + if (!param.string) 2599 + return -ENOMEM; 2600 + param.type = fs_value_is_string; 2601 + } 2602 + 2603 + param.key = key; 2604 + param.size = v_len; 2605 + 2606 + ret = ext4_parse_param(fc, &param); 2607 + if (param.string) 2608 + kfree(param.string); 2609 + if (ret < 0) 2610 + return ret; 2611 + } 2612 + } 2613 + 2614 + ret = ext4_validate_options(fc); 2615 + if (ret < 0) 2616 + return ret; 2617 + 2618 + return 0; 2619 + } 2620 + 2621 + static int parse_apply_sb_mount_options(struct super_block *sb, 2622 + struct ext4_fs_context *m_ctx) 2623 + { 2624 + struct ext4_sb_info *sbi = EXT4_SB(sb); 2625 + char *s_mount_opts = NULL; 2626 + struct ext4_fs_context *s_ctx = NULL; 2627 + struct fs_context *fc = NULL; 2628 + int ret = -ENOMEM; 2629 + 2630 + if (!sbi->s_es->s_mount_opts[0]) 2631 + return 0; 2632 + 2633 + s_mount_opts = kstrndup(sbi->s_es->s_mount_opts, 2634 + sizeof(sbi->s_es->s_mount_opts), 2635 + GFP_KERNEL); 2636 + if (!s_mount_opts) 2637 + return ret; 2638 + 2639 + fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL); 2640 + if (!fc) 2641 + goto out_free; 2642 + 2643 + s_ctx = kzalloc(sizeof(struct ext4_fs_context), GFP_KERNEL); 2644 + if (!s_ctx) 2645 + goto out_free; 2646 + 2647 + fc->fs_private = s_ctx; 2648 + fc->s_fs_info = sbi; 2649 + 2650 + ret = parse_options(fc, s_mount_opts); 2651 + if (ret < 0) 2652 + goto parse_failed; 2653 + 2654 + ret = ext4_check_opt_consistency(fc, sb); 2655 + if (ret < 0) { 2656 + parse_failed: 2657 + ext4_msg(sb, KERN_WARNING, 2658 + "failed to parse options in superblock: %s", 2659 + s_mount_opts); 2660 + ret = 0; 2661 + goto out_free; 2662 + } 2663 + 2664 + if (s_ctx->spec & EXT4_SPEC_JOURNAL_DEV) 2665 + m_ctx->journal_devnum = s_ctx->journal_devnum; 2666 + if (s_ctx->spec & EXT4_SPEC_JOURNAL_IOPRIO) 2667 + m_ctx->journal_ioprio = s_ctx->journal_ioprio; 2668 + 2669 + ret = ext4_apply_options(fc, sb); 2670 + 2671 + out_free: 2672 + kfree(s_ctx); 2673 + kfree(fc); 2674 + kfree(s_mount_opts); 2675 + return ret; 2676 + } 2677 + 2678 + static void ext4_apply_quota_options(struct fs_context *fc, 2679 + struct super_block *sb) 2680 + { 2681 + #ifdef CONFIG_QUOTA 2682 + bool quota_feature = ext4_has_feature_quota(sb); 2683 + struct ext4_fs_context *ctx = fc->fs_private; 2684 + struct ext4_sb_info *sbi = EXT4_SB(sb); 2685 + char *qname; 2686 + int i; 2687 + 2688 + if (quota_feature) 2689 + return; 2690 + 2691 + if (ctx->spec & EXT4_SPEC_JQUOTA) { 2692 + for (i = 0; i < EXT4_MAXQUOTAS; i++) { 2693 + if (!(ctx->qname_spec & (1 << i))) 2694 + continue; 2695 + 2696 + qname = ctx->s_qf_names[i]; /* May be NULL */ 2697 + if (qname) 2698 + set_opt(sb, QUOTA); 2699 + ctx->s_qf_names[i] = NULL; 2700 + qname = rcu_replace_pointer(sbi->s_qf_names[i], qname, 2701 + lockdep_is_held(&sb->s_umount)); 2702 + if (qname) 2703 + kfree_rcu(qname); 2704 + } 2705 + } 2706 + 2707 + if (ctx->spec & EXT4_SPEC_JQFMT) 2708 + sbi->s_jquota_fmt = ctx->s_jquota_fmt; 2709 + #endif 2710 + } 2711 + 2712 + /* 2713 + * Check quota settings consistency. 2714 + */ 2715 + static int ext4_check_quota_consistency(struct fs_context *fc, 2716 + struct super_block *sb) 2717 + { 2718 + #ifdef CONFIG_QUOTA 2719 + struct ext4_fs_context *ctx = fc->fs_private; 2720 + struct ext4_sb_info *sbi = EXT4_SB(sb); 2721 + bool quota_feature = ext4_has_feature_quota(sb); 2722 + bool quota_loaded = sb_any_quota_loaded(sb); 2723 + bool usr_qf_name, grp_qf_name, usrquota, grpquota; 2724 + int quota_flags, i; 2725 + 2726 + /* 2727 + * We do the test below only for project quotas. 'usrquota' and 2728 + * 'grpquota' mount options are allowed even without quota feature 2729 + * to support legacy quotas in quota files. 2730 + */ 2731 + if (ctx_test_mount_opt(ctx, EXT4_MOUNT_PRJQUOTA) && 2732 + !ext4_has_feature_project(sb)) { 2733 + ext4_msg(NULL, KERN_ERR, "Project quota feature not enabled. " 2734 + "Cannot enable project quota enforcement."); 2735 + return -EINVAL; 2736 + } 2737 + 2738 + quota_flags = EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA | 2739 + EXT4_MOUNT_GRPQUOTA | EXT4_MOUNT_PRJQUOTA; 2740 + if (quota_loaded && 2741 + ctx->mask_s_mount_opt & quota_flags && 2742 + !ctx_test_mount_opt(ctx, quota_flags)) 2743 + goto err_quota_change; 2744 + 2745 + if (ctx->spec & EXT4_SPEC_JQUOTA) { 2746 + 2747 + for (i = 0; i < EXT4_MAXQUOTAS; i++) { 2748 + if (!(ctx->qname_spec & (1 << i))) 2749 + continue; 2750 + 2751 + if (quota_loaded && 2752 + !!sbi->s_qf_names[i] != !!ctx->s_qf_names[i]) 2753 + goto err_jquota_change; 2754 + 2755 + if (sbi->s_qf_names[i] && ctx->s_qf_names[i] && 2756 + strcmp(get_qf_name(sb, sbi, i), 2757 + ctx->s_qf_names[i]) != 0) 2758 + goto err_jquota_specified; 2759 + } 2760 + 2761 + if (quota_feature) { 2762 + ext4_msg(NULL, KERN_INFO, 2763 + "Journaled quota options ignored when " 2764 + "QUOTA feature is enabled"); 2765 + return 0; 2766 + } 2767 + } 2768 + 2769 + if (ctx->spec & EXT4_SPEC_JQFMT) { 2770 + if (sbi->s_jquota_fmt != ctx->s_jquota_fmt && quota_loaded) 2771 + goto err_jquota_change; 2772 + if (quota_feature) { 2773 + ext4_msg(NULL, KERN_INFO, "Quota format mount options " 2774 + "ignored when QUOTA feature is enabled"); 2775 + return 0; 2776 + } 2777 + } 2778 + 2779 + /* Make sure we don't mix old and new quota format */ 2780 + usr_qf_name = (get_qf_name(sb, sbi, USRQUOTA) || 2781 + ctx->s_qf_names[USRQUOTA]); 2782 + grp_qf_name = (get_qf_name(sb, sbi, GRPQUOTA) || 2783 + ctx->s_qf_names[GRPQUOTA]); 2784 + 2785 + usrquota = (ctx_test_mount_opt(ctx, EXT4_MOUNT_USRQUOTA) || 2786 + test_opt(sb, USRQUOTA)); 2787 + 2788 + grpquota = (ctx_test_mount_opt(ctx, EXT4_MOUNT_GRPQUOTA) || 2789 + test_opt(sb, GRPQUOTA)); 2790 + 2791 + if (usr_qf_name) { 2792 + ctx_clear_mount_opt(ctx, EXT4_MOUNT_USRQUOTA); 2793 + usrquota = false; 2794 + } 2795 + if (grp_qf_name) { 2796 + ctx_clear_mount_opt(ctx, EXT4_MOUNT_GRPQUOTA); 2797 + grpquota = false; 2798 + } 2799 + 2800 + if (usr_qf_name || grp_qf_name) { 2801 + if (usrquota || grpquota) { 2802 + ext4_msg(NULL, KERN_ERR, "old and new quota " 2803 + "format mixing"); 2804 + return -EINVAL; 2805 + } 2806 + 2807 + if (!(ctx->spec & EXT4_SPEC_JQFMT || sbi->s_jquota_fmt)) { 2808 + ext4_msg(NULL, KERN_ERR, "journaled quota format " 2809 + "not specified"); 2810 + return -EINVAL; 2811 + } 2812 + } 2813 + 2814 + return 0; 2815 + 2816 + err_quota_change: 2817 + ext4_msg(NULL, KERN_ERR, 2818 + "Cannot change quota options when quota turned on"); 2819 + return -EINVAL; 2820 + err_jquota_change: 2821 + ext4_msg(NULL, KERN_ERR, "Cannot change journaled quota " 2822 + "options when quota turned on"); 2823 + return -EINVAL; 2824 + err_jquota_specified: 2825 + ext4_msg(NULL, KERN_ERR, "%s quota file already specified", 2826 + QTYPE2NAME(i)); 2827 + return -EINVAL; 2828 + #else 2829 + return 0; 2830 + #endif 2831 + } 2832 + 2833 + static int ext4_check_opt_consistency(struct fs_context *fc, 2834 + struct super_block *sb) 2835 + { 2836 + struct ext4_fs_context *ctx = fc->fs_private; 2837 + struct ext4_sb_info *sbi = fc->s_fs_info; 2838 + int is_remount = fc->purpose == FS_CONTEXT_FOR_RECONFIGURE; 2839 + 2840 + if ((ctx->opt_flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) { 2841 + ext4_msg(NULL, KERN_ERR, 2842 + "Mount option(s) incompatible with ext2"); 2843 + return -EINVAL; 2844 + } 2845 + if ((ctx->opt_flags & MOPT_NO_EXT3) && IS_EXT3_SB(sb)) { 2846 + ext4_msg(NULL, KERN_ERR, 2847 + "Mount option(s) incompatible with ext3"); 2848 + return -EINVAL; 2849 + } 2850 + 2851 + if (ctx->s_want_extra_isize > 2852 + (sbi->s_inode_size - EXT4_GOOD_OLD_INODE_SIZE)) { 2853 + ext4_msg(NULL, KERN_ERR, 2854 + "Invalid want_extra_isize %d", 2855 + ctx->s_want_extra_isize); 2856 + return -EINVAL; 2857 + } 2858 + 2859 + if (ctx_test_mount_opt(ctx, EXT4_MOUNT_DIOREAD_NOLOCK)) { 2860 + int blocksize = 2861 + BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size); 2862 + if (blocksize < PAGE_SIZE) 2863 + ext4_msg(NULL, KERN_WARNING, "Warning: mounting with an " 2864 + "experimental mount option 'dioread_nolock' " 2865 + "for blocksize < PAGE_SIZE"); 2866 + } 2867 + 2868 + #ifdef CONFIG_FS_ENCRYPTION 2004 2869 /* 2005 2870 * This mount option is just for testing, and it's not worthwhile to 2006 2871 * implement the extra complexity (e.g. RCU protection) that would be 2007 2872 * needed to allow it to be set or changed during remount. We do allow 2008 2873 * it to be specified during remount, but only if there is no change. 2009 2874 */ 2010 - if (is_remount && !sbi->s_dummy_enc_policy.policy) { 2011 - ext4_msg(sb, KERN_WARNING, 2875 + if ((ctx->spec & EXT4_SPEC_DUMMY_ENCRYPTION) && 2876 + is_remount && !sbi->s_dummy_enc_policy.policy) { 2877 + ext4_msg(NULL, KERN_WARNING, 2012 2878 "Can't set test_dummy_encryption on remount"); 2013 2879 return -1; 2014 2880 } 2015 - err = fscrypt_set_test_dummy_encryption(sb, arg->from, 2016 - &sbi->s_dummy_enc_policy); 2017 - if (err) { 2018 - if (err == -EEXIST) 2019 - ext4_msg(sb, KERN_WARNING, 2020 - "Can't change test_dummy_encryption on remount"); 2021 - else if (err == -EINVAL) 2022 - ext4_msg(sb, KERN_WARNING, 2023 - "Value of option \"%s\" is unrecognized", opt); 2024 - else 2025 - ext4_msg(sb, KERN_WARNING, 2026 - "Error processing option \"%s\" [%d]", 2027 - opt, err); 2028 - return -1; 2029 - } 2030 - ext4_msg(sb, KERN_WARNING, "Test dummy encryption mode enabled"); 2031 - #else 2032 - ext4_msg(sb, KERN_WARNING, 2033 - "Test dummy encryption mount option ignored"); 2034 2881 #endif 2035 - return 1; 2882 + 2883 + if ((ctx->spec & EXT4_SPEC_DATAJ) && is_remount) { 2884 + if (!sbi->s_journal) { 2885 + ext4_msg(NULL, KERN_WARNING, 2886 + "Remounting file system with no journal " 2887 + "so ignoring journalled data option"); 2888 + ctx_clear_mount_opt(ctx, EXT4_MOUNT_DATA_FLAGS); 2889 + } else if (ctx_test_mount_opt(ctx, EXT4_MOUNT_DATA_FLAGS) != 2890 + test_opt(sb, DATA_FLAGS)) { 2891 + ext4_msg(NULL, KERN_ERR, "Cannot change data mode " 2892 + "on remount"); 2893 + return -EINVAL; 2894 + } 2895 + } 2896 + 2897 + if (is_remount) { 2898 + if (ctx_test_mount_opt(ctx, EXT4_MOUNT_DAX_ALWAYS) && 2899 + (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)) { 2900 + ext4_msg(NULL, KERN_ERR, "can't mount with " 2901 + "both data=journal and dax"); 2902 + return -EINVAL; 2903 + } 2904 + 2905 + if (ctx_test_mount_opt(ctx, EXT4_MOUNT_DAX_ALWAYS) && 2906 + (!(sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) || 2907 + (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER))) { 2908 + fail_dax_change_remount: 2909 + ext4_msg(NULL, KERN_ERR, "can't change " 2910 + "dax mount option while remounting"); 2911 + return -EINVAL; 2912 + } else if (ctx_test_mount_opt2(ctx, EXT4_MOUNT2_DAX_NEVER) && 2913 + (!(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) || 2914 + (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS))) { 2915 + goto fail_dax_change_remount; 2916 + } else if (ctx_test_mount_opt2(ctx, EXT4_MOUNT2_DAX_INODE) && 2917 + ((sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) || 2918 + (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) || 2919 + !(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_INODE))) { 2920 + goto fail_dax_change_remount; 2921 + } 2922 + } 2923 + 2924 + return ext4_check_quota_consistency(fc, sb); 2036 2925 } 2037 2926 2038 - struct ext4_parsed_options { 2039 - unsigned long journal_devnum; 2040 - unsigned int journal_ioprio; 2041 - int mb_optimize_scan; 2042 - }; 2043 - 2044 - static int handle_mount_opt(struct super_block *sb, char *opt, int token, 2045 - substring_t *args, struct ext4_parsed_options *parsed_opts, 2046 - int is_remount) 2927 + static int ext4_apply_options(struct fs_context *fc, struct super_block *sb) 2047 2928 { 2048 - struct ext4_sb_info *sbi = EXT4_SB(sb); 2049 - const struct mount_opts *m; 2050 - kuid_t uid; 2051 - kgid_t gid; 2052 - int arg = 0; 2929 + struct ext4_fs_context *ctx = fc->fs_private; 2930 + struct ext4_sb_info *sbi = fc->s_fs_info; 2931 + int ret = 0; 2053 2932 2054 - #ifdef CONFIG_QUOTA 2055 - if (token == Opt_usrjquota) 2056 - return set_qf_name(sb, USRQUOTA, &args[0]); 2057 - else if (token == Opt_grpjquota) 2058 - return set_qf_name(sb, GRPQUOTA, &args[0]); 2059 - else if (token == Opt_offusrjquota) 2060 - return clear_qf_name(sb, USRQUOTA); 2061 - else if (token == Opt_offgrpjquota) 2062 - return clear_qf_name(sb, GRPQUOTA); 2063 - #endif 2064 - switch (token) { 2065 - case Opt_noacl: 2066 - case Opt_nouser_xattr: 2067 - ext4_msg(sb, KERN_WARNING, deprecated_msg, opt, "3.5"); 2068 - break; 2069 - case Opt_sb: 2070 - return 1; /* handled by get_sb_block() */ 2071 - case Opt_removed: 2072 - ext4_msg(sb, KERN_WARNING, "Ignoring removed %s option", opt); 2073 - return 1; 2074 - case Opt_abort: 2075 - ext4_set_mount_flag(sb, EXT4_MF_FS_ABORTED); 2076 - return 1; 2077 - case Opt_i_version: 2078 - sb->s_flags |= SB_I_VERSION; 2079 - return 1; 2080 - case Opt_lazytime: 2081 - sb->s_flags |= SB_LAZYTIME; 2082 - return 1; 2083 - case Opt_nolazytime: 2084 - sb->s_flags &= ~SB_LAZYTIME; 2085 - return 1; 2086 - case Opt_inlinecrypt: 2087 - #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT 2088 - sb->s_flags |= SB_INLINECRYPT; 2089 - #else 2090 - ext4_msg(sb, KERN_ERR, "inline encryption not supported"); 2091 - #endif 2092 - return 1; 2093 - } 2933 + sbi->s_mount_opt &= ~ctx->mask_s_mount_opt; 2934 + sbi->s_mount_opt |= ctx->vals_s_mount_opt; 2935 + sbi->s_mount_opt2 &= ~ctx->mask_s_mount_opt2; 2936 + sbi->s_mount_opt2 |= ctx->vals_s_mount_opt2; 2937 + sbi->s_mount_flags &= ~ctx->mask_s_mount_flags; 2938 + sbi->s_mount_flags |= ctx->vals_s_mount_flags; 2939 + sb->s_flags &= ~ctx->mask_s_flags; 2940 + sb->s_flags |= ctx->vals_s_flags; 2094 2941 2095 - for (m = ext4_mount_opts; m->token != Opt_err; m++) 2096 - if (token == m->token) 2097 - break; 2098 - 2099 - if (m->token == Opt_err) { 2100 - ext4_msg(sb, KERN_ERR, "Unrecognized mount option \"%s\" " 2101 - "or missing value", opt); 2102 - return -1; 2103 - } 2104 - 2105 - if ((m->flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) { 2106 - ext4_msg(sb, KERN_ERR, 2107 - "Mount option \"%s\" incompatible with ext2", opt); 2108 - return -1; 2109 - } 2110 - if ((m->flags & MOPT_NO_EXT3) && IS_EXT3_SB(sb)) { 2111 - ext4_msg(sb, KERN_ERR, 2112 - "Mount option \"%s\" incompatible with ext3", opt); 2113 - return -1; 2114 - } 2115 - 2116 - if (args->from && !(m->flags & MOPT_STRING) && match_int(args, &arg)) 2117 - return -1; 2118 - if (args->from && (m->flags & MOPT_GTE0) && (arg < 0)) 2119 - return -1; 2120 - if (m->flags & MOPT_EXPLICIT) { 2121 - if (m->mount_opt & EXT4_MOUNT_DELALLOC) { 2122 - set_opt2(sb, EXPLICIT_DELALLOC); 2123 - } else if (m->mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) { 2124 - set_opt2(sb, EXPLICIT_JOURNAL_CHECKSUM); 2125 - } else 2126 - return -1; 2127 - } 2128 - if (m->flags & MOPT_CLEAR_ERR) 2129 - clear_opt(sb, ERRORS_MASK); 2130 - if (token == Opt_noquota && sb_any_quota_loaded(sb)) { 2131 - ext4_msg(sb, KERN_ERR, "Cannot change quota " 2132 - "options when quota turned on"); 2133 - return -1; 2134 - } 2135 - 2136 - if (m->flags & MOPT_NOSUPPORT) { 2137 - ext4_msg(sb, KERN_ERR, "%s option not supported", opt); 2138 - } else if (token == Opt_commit) { 2139 - if (arg == 0) 2140 - arg = JBD2_DEFAULT_MAX_COMMIT_AGE; 2141 - else if (arg > INT_MAX / HZ) { 2142 - ext4_msg(sb, KERN_ERR, 2143 - "Invalid commit interval %d, " 2144 - "must be smaller than %d", 2145 - arg, INT_MAX / HZ); 2146 - return -1; 2147 - } 2148 - sbi->s_commit_interval = HZ * arg; 2149 - } else if (token == Opt_debug_want_extra_isize) { 2150 - if ((arg & 1) || 2151 - (arg < 4) || 2152 - (arg > (sbi->s_inode_size - EXT4_GOOD_OLD_INODE_SIZE))) { 2153 - ext4_msg(sb, KERN_ERR, 2154 - "Invalid want_extra_isize %d", arg); 2155 - return -1; 2156 - } 2157 - sbi->s_want_extra_isize = arg; 2158 - } else if (token == Opt_max_batch_time) { 2159 - sbi->s_max_batch_time = arg; 2160 - } else if (token == Opt_min_batch_time) { 2161 - sbi->s_min_batch_time = arg; 2162 - } else if (token == Opt_inode_readahead_blks) { 2163 - if (arg && (arg > (1 << 30) || !is_power_of_2(arg))) { 2164 - ext4_msg(sb, KERN_ERR, 2165 - "EXT4-fs: inode_readahead_blks must be " 2166 - "0 or a power of 2 smaller than 2^31"); 2167 - return -1; 2168 - } 2169 - sbi->s_inode_readahead_blks = arg; 2170 - } else if (token == Opt_init_itable) { 2171 - set_opt(sb, INIT_INODE_TABLE); 2172 - if (!args->from) 2173 - arg = EXT4_DEF_LI_WAIT_MULT; 2174 - sbi->s_li_wait_mult = arg; 2175 - } else if (token == Opt_max_dir_size_kb) { 2176 - sbi->s_max_dir_size_kb = arg; 2177 - #ifdef CONFIG_EXT4_DEBUG 2178 - } else if (token == Opt_fc_debug_max_replay) { 2179 - sbi->s_fc_debug_max_replay = arg; 2180 - #endif 2181 - } else if (token == Opt_stripe) { 2182 - sbi->s_stripe = arg; 2183 - } else if (token == Opt_resuid) { 2184 - uid = make_kuid(current_user_ns(), arg); 2185 - if (!uid_valid(uid)) { 2186 - ext4_msg(sb, KERN_ERR, "Invalid uid value %d", arg); 2187 - return -1; 2188 - } 2189 - sbi->s_resuid = uid; 2190 - } else if (token == Opt_resgid) { 2191 - gid = make_kgid(current_user_ns(), arg); 2192 - if (!gid_valid(gid)) { 2193 - ext4_msg(sb, KERN_ERR, "Invalid gid value %d", arg); 2194 - return -1; 2195 - } 2196 - sbi->s_resgid = gid; 2197 - } else if (token == Opt_journal_dev) { 2198 - if (is_remount) { 2199 - ext4_msg(sb, KERN_ERR, 2200 - "Cannot specify journal on remount"); 2201 - return -1; 2202 - } 2203 - parsed_opts->journal_devnum = arg; 2204 - } else if (token == Opt_journal_path) { 2205 - char *journal_path; 2206 - struct inode *journal_inode; 2207 - struct path path; 2208 - int error; 2209 - 2210 - if (is_remount) { 2211 - ext4_msg(sb, KERN_ERR, 2212 - "Cannot specify journal on remount"); 2213 - return -1; 2214 - } 2215 - journal_path = match_strdup(&args[0]); 2216 - if (!journal_path) { 2217 - ext4_msg(sb, KERN_ERR, "error: could not dup " 2218 - "journal device string"); 2219 - return -1; 2220 - } 2221 - 2222 - error = kern_path(journal_path, LOOKUP_FOLLOW, &path); 2223 - if (error) { 2224 - ext4_msg(sb, KERN_ERR, "error: could not find " 2225 - "journal device path: error %d", error); 2226 - kfree(journal_path); 2227 - return -1; 2228 - } 2229 - 2230 - journal_inode = d_inode(path.dentry); 2231 - if (!S_ISBLK(journal_inode->i_mode)) { 2232 - ext4_msg(sb, KERN_ERR, "error: journal path %s " 2233 - "is not a block device", journal_path); 2234 - path_put(&path); 2235 - kfree(journal_path); 2236 - return -1; 2237 - } 2238 - 2239 - parsed_opts->journal_devnum = new_encode_dev(journal_inode->i_rdev); 2240 - path_put(&path); 2241 - kfree(journal_path); 2242 - } else if (token == Opt_journal_ioprio) { 2243 - if (arg > 7) { 2244 - ext4_msg(sb, KERN_ERR, "Invalid journal IO priority" 2245 - " (must be 0-7)"); 2246 - return -1; 2247 - } 2248 - parsed_opts->journal_ioprio = 2249 - IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg); 2250 - } else if (token == Opt_test_dummy_encryption) { 2251 - return ext4_set_test_dummy_encryption(sb, opt, &args[0], 2252 - is_remount); 2253 - } else if (m->flags & MOPT_DATAJ) { 2254 - if (is_remount) { 2255 - if (!sbi->s_journal) 2256 - ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option"); 2257 - else if (test_opt(sb, DATA_FLAGS) != m->mount_opt) { 2258 - ext4_msg(sb, KERN_ERR, 2259 - "Cannot change data mode on remount"); 2260 - return -1; 2261 - } 2262 - } else { 2263 - clear_opt(sb, DATA_FLAGS); 2264 - sbi->s_mount_opt |= m->mount_opt; 2265 - } 2266 - #ifdef CONFIG_QUOTA 2267 - } else if (m->flags & MOPT_QFMT) { 2268 - if (sb_any_quota_loaded(sb) && 2269 - sbi->s_jquota_fmt != m->mount_opt) { 2270 - ext4_msg(sb, KERN_ERR, "Cannot change journaled " 2271 - "quota options when quota turned on"); 2272 - return -1; 2273 - } 2274 - if (ext4_has_feature_quota(sb)) { 2275 - ext4_msg(sb, KERN_INFO, 2276 - "Quota format mount options ignored " 2277 - "when QUOTA feature is enabled"); 2278 - return 1; 2279 - } 2280 - sbi->s_jquota_fmt = m->mount_opt; 2281 - #endif 2282 - } else if (token == Opt_dax || token == Opt_dax_always || 2283 - token == Opt_dax_inode || token == Opt_dax_never) { 2284 - #ifdef CONFIG_FS_DAX 2285 - switch (token) { 2286 - case Opt_dax: 2287 - case Opt_dax_always: 2288 - if (is_remount && 2289 - (!(sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) || 2290 - (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER))) { 2291 - fail_dax_change_remount: 2292 - ext4_msg(sb, KERN_ERR, "can't change " 2293 - "dax mount option while remounting"); 2294 - return -1; 2295 - } 2296 - if (is_remount && 2297 - (test_opt(sb, DATA_FLAGS) == 2298 - EXT4_MOUNT_JOURNAL_DATA)) { 2299 - ext4_msg(sb, KERN_ERR, "can't mount with " 2300 - "both data=journal and dax"); 2301 - return -1; 2302 - } 2303 - ext4_msg(sb, KERN_WARNING, 2304 - "DAX enabled. Warning: EXPERIMENTAL, use at your own risk"); 2305 - sbi->s_mount_opt |= EXT4_MOUNT_DAX_ALWAYS; 2306 - sbi->s_mount_opt2 &= ~EXT4_MOUNT2_DAX_NEVER; 2307 - break; 2308 - case Opt_dax_never: 2309 - if (is_remount && 2310 - (!(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) || 2311 - (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS))) 2312 - goto fail_dax_change_remount; 2313 - sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_NEVER; 2314 - sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS; 2315 - break; 2316 - case Opt_dax_inode: 2317 - if (is_remount && 2318 - ((sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) || 2319 - (sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_NEVER) || 2320 - !(sbi->s_mount_opt2 & EXT4_MOUNT2_DAX_INODE))) 2321 - goto fail_dax_change_remount; 2322 - sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS; 2323 - sbi->s_mount_opt2 &= ~EXT4_MOUNT2_DAX_NEVER; 2324 - /* Strictly for printing options */ 2325 - sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_INODE; 2326 - break; 2327 - } 2328 - #else 2329 - ext4_msg(sb, KERN_INFO, "dax option not supported"); 2330 - sbi->s_mount_opt2 |= EXT4_MOUNT2_DAX_NEVER; 2331 - sbi->s_mount_opt &= ~EXT4_MOUNT_DAX_ALWAYS; 2332 - return -1; 2333 - #endif 2334 - } else if (token == Opt_data_err_abort) { 2335 - sbi->s_mount_opt |= m->mount_opt; 2336 - } else if (token == Opt_data_err_ignore) { 2337 - sbi->s_mount_opt &= ~m->mount_opt; 2338 - } else if (token == Opt_mb_optimize_scan) { 2339 - if (arg != 0 && arg != 1) { 2340 - ext4_msg(sb, KERN_WARNING, 2341 - "mb_optimize_scan should be set to 0 or 1."); 2342 - return -1; 2343 - } 2344 - parsed_opts->mb_optimize_scan = arg; 2345 - } else { 2346 - if (!args->from) 2347 - arg = 1; 2348 - if (m->flags & MOPT_CLEAR) 2349 - arg = !arg; 2350 - else if (unlikely(!(m->flags & MOPT_SET))) { 2351 - ext4_msg(sb, KERN_WARNING, 2352 - "buggy handling of option %s", opt); 2353 - WARN_ON(1); 2354 - return -1; 2355 - } 2356 - if (m->flags & MOPT_2) { 2357 - if (arg != 0) 2358 - sbi->s_mount_opt2 |= m->mount_opt; 2359 - else 2360 - sbi->s_mount_opt2 &= ~m->mount_opt; 2361 - } else { 2362 - if (arg != 0) 2363 - sbi->s_mount_opt |= m->mount_opt; 2364 - else 2365 - sbi->s_mount_opt &= ~m->mount_opt; 2366 - } 2367 - } 2368 - return 1; 2369 - } 2370 - 2371 - static int parse_options(char *options, struct super_block *sb, 2372 - struct ext4_parsed_options *ret_opts, 2373 - int is_remount) 2374 - { 2375 - struct ext4_sb_info __maybe_unused *sbi = EXT4_SB(sb); 2376 - char *p, __maybe_unused *usr_qf_name, __maybe_unused *grp_qf_name; 2377 - substring_t args[MAX_OPT_ARGS]; 2378 - int token; 2379 - 2380 - if (!options) 2381 - return 1; 2382 - 2383 - while ((p = strsep(&options, ",")) != NULL) { 2384 - if (!*p) 2385 - continue; 2386 - /* 2387 - * Initialize args struct so we know whether arg was 2388 - * found; some options take optional arguments. 2389 - */ 2390 - args[0].to = args[0].from = NULL; 2391 - token = match_token(p, tokens, args); 2392 - if (handle_mount_opt(sb, p, token, args, ret_opts, 2393 - is_remount) < 0) 2394 - return 0; 2395 - } 2396 - #ifdef CONFIG_QUOTA 2397 2942 /* 2398 - * We do the test below only for project quotas. 'usrquota' and 2399 - * 'grpquota' mount options are allowed even without quota feature 2400 - * to support legacy quotas in quota files. 2943 + * i_version differs from common mount option iversion so we have 2944 + * to let vfs know that it was set, otherwise it would get cleared 2945 + * on remount 2401 2946 */ 2402 - if (test_opt(sb, PRJQUOTA) && !ext4_has_feature_project(sb)) { 2403 - ext4_msg(sb, KERN_ERR, "Project quota feature not enabled. " 2404 - "Cannot enable project quota enforcement."); 2405 - return 0; 2406 - } 2407 - usr_qf_name = get_qf_name(sb, sbi, USRQUOTA); 2408 - grp_qf_name = get_qf_name(sb, sbi, GRPQUOTA); 2947 + if (ctx->mask_s_flags & SB_I_VERSION) 2948 + fc->sb_flags |= SB_I_VERSION; 2949 + 2950 + #define APPLY(X) ({ if (ctx->spec & EXT4_SPEC_##X) sbi->X = ctx->X; }) 2951 + APPLY(s_commit_interval); 2952 + APPLY(s_stripe); 2953 + APPLY(s_max_batch_time); 2954 + APPLY(s_min_batch_time); 2955 + APPLY(s_want_extra_isize); 2956 + APPLY(s_inode_readahead_blks); 2957 + APPLY(s_max_dir_size_kb); 2958 + APPLY(s_li_wait_mult); 2959 + APPLY(s_resgid); 2960 + APPLY(s_resuid); 2961 + 2962 + #ifdef CONFIG_EXT4_DEBUG 2963 + APPLY(s_fc_debug_max_replay); 2964 + #endif 2965 + 2966 + ext4_apply_quota_options(fc, sb); 2967 + 2968 + if (ctx->spec & EXT4_SPEC_DUMMY_ENCRYPTION) 2969 + ret = ext4_set_test_dummy_encryption(sb, ctx->test_dummy_enc_arg); 2970 + 2971 + return ret; 2972 + } 2973 + 2974 + 2975 + static int ext4_validate_options(struct fs_context *fc) 2976 + { 2977 + #ifdef CONFIG_QUOTA 2978 + struct ext4_fs_context *ctx = fc->fs_private; 2979 + char *usr_qf_name, *grp_qf_name; 2980 + 2981 + usr_qf_name = ctx->s_qf_names[USRQUOTA]; 2982 + grp_qf_name = ctx->s_qf_names[GRPQUOTA]; 2983 + 2409 2984 if (usr_qf_name || grp_qf_name) { 2410 - if (test_opt(sb, USRQUOTA) && usr_qf_name) 2411 - clear_opt(sb, USRQUOTA); 2985 + if (ctx_test_mount_opt(ctx, EXT4_MOUNT_USRQUOTA) && usr_qf_name) 2986 + ctx_clear_mount_opt(ctx, EXT4_MOUNT_USRQUOTA); 2412 2987 2413 - if (test_opt(sb, GRPQUOTA) && grp_qf_name) 2414 - clear_opt(sb, GRPQUOTA); 2988 + if (ctx_test_mount_opt(ctx, EXT4_MOUNT_GRPQUOTA) && grp_qf_name) 2989 + ctx_clear_mount_opt(ctx, EXT4_MOUNT_GRPQUOTA); 2415 2990 2416 - if (test_opt(sb, GRPQUOTA) || test_opt(sb, USRQUOTA)) { 2417 - ext4_msg(sb, KERN_ERR, "old and new quota " 2418 - "format mixing"); 2419 - return 0; 2420 - } 2421 - 2422 - if (!sbi->s_jquota_fmt) { 2423 - ext4_msg(sb, KERN_ERR, "journaled quota format " 2424 - "not specified"); 2425 - return 0; 2991 + if (ctx_test_mount_opt(ctx, EXT4_MOUNT_USRQUOTA) || 2992 + ctx_test_mount_opt(ctx, EXT4_MOUNT_GRPQUOTA)) { 2993 + ext4_msg(NULL, KERN_ERR, "old and new quota " 2994 + "format mixing"); 2995 + return -EINVAL; 2426 2996 } 2427 2997 } 2428 2998 #endif 2429 - if (test_opt(sb, DIOREAD_NOLOCK)) { 2430 - int blocksize = 2431 - BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size); 2432 - if (blocksize < PAGE_SIZE) 2433 - ext4_msg(sb, KERN_WARNING, "Warning: mounting with an " 2434 - "experimental mount option 'dioread_nolock' " 2435 - "for blocksize < PAGE_SIZE"); 2436 - } 2437 2999 return 1; 2438 3000 } 2439 3001 ··· 2977 2533 2978 2534 static const char *token2str(int token) 2979 2535 { 2980 - const struct match_token *t; 2536 + const struct fs_parameter_spec *spec; 2981 2537 2982 - for (t = tokens; t->token != Opt_err; t++) 2983 - if (t->token == token && !strchr(t->pattern, '=')) 2538 + for (spec = ext4_param_specs; spec->name != NULL; spec++) 2539 + if (spec->opt == token && !spec->type) 2984 2540 break; 2985 - return t->pattern; 2541 + return spec->name; 2986 2542 } 2987 2543 2988 2544 /* ··· 3008 2564 for (m = ext4_mount_opts; m->token != Opt_err; m++) { 3009 2565 int want_set = m->flags & MOPT_SET; 3010 2566 if (((m->flags & (MOPT_SET|MOPT_CLEAR)) == 0) || 3011 - (m->flags & MOPT_CLEAR_ERR) || m->flags & MOPT_SKIP) 2567 + m->flags & MOPT_SKIP) 3012 2568 continue; 3013 2569 if (!nodefs && !(m->mount_opt & (sbi->s_mount_opt ^ def_mount_opt))) 3014 2570 continue; /* skip if same as the default */ ··· 4320 3876 sbi->s_journal_triggers[type].tr_triggers.t_frozen = trigger; 4321 3877 } 4322 3878 4323 - static int ext4_fill_super(struct super_block *sb, void *data, int silent) 3879 + static void ext4_free_sbi(struct ext4_sb_info *sbi) 4324 3880 { 4325 - struct dax_device *dax_dev = fs_dax_get_by_bdev(sb->s_bdev); 4326 - char *orig_data = kstrdup(data, GFP_KERNEL); 3881 + if (!sbi) 3882 + return; 3883 + 3884 + kfree(sbi->s_blockgroup_lock); 3885 + fs_put_dax(sbi->s_daxdev); 3886 + kfree(sbi); 3887 + } 3888 + 3889 + static struct ext4_sb_info *ext4_alloc_sbi(struct super_block *sb) 3890 + { 3891 + struct ext4_sb_info *sbi; 3892 + 3893 + sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 3894 + if (!sbi) 3895 + return NULL; 3896 + 3897 + sbi->s_daxdev = fs_dax_get_by_bdev(sb->s_bdev); 3898 + 3899 + sbi->s_blockgroup_lock = 3900 + kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); 3901 + 3902 + if (!sbi->s_blockgroup_lock) 3903 + goto err_out; 3904 + 3905 + sb->s_fs_info = sbi; 3906 + sbi->s_sb = sb; 3907 + return sbi; 3908 + err_out: 3909 + fs_put_dax(sbi->s_daxdev); 3910 + kfree(sbi); 3911 + return NULL; 3912 + } 3913 + 3914 + static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) 3915 + { 4327 3916 struct buffer_head *bh, **group_desc; 4328 3917 struct ext4_super_block *es = NULL; 4329 - struct ext4_sb_info *sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 3918 + struct ext4_sb_info *sbi = EXT4_SB(sb); 4330 3919 struct flex_groups **flex_groups; 4331 3920 ext4_fsblk_t block; 4332 - ext4_fsblk_t sb_block = get_sb_block(&data); 4333 3921 ext4_fsblk_t logical_sb_block; 4334 3922 unsigned long offset = 0; 4335 3923 unsigned long def_mount_opts; 4336 3924 struct inode *root; 4337 - const char *descr; 4338 3925 int ret = -ENOMEM; 4339 3926 int blocksize, clustersize; 4340 3927 unsigned int db_count; ··· 4374 3899 __u64 blocks_count; 4375 3900 int err = 0; 4376 3901 ext4_group_t first_not_zeroed; 4377 - struct ext4_parsed_options parsed_opts; 3902 + struct ext4_fs_context *ctx = fc->fs_private; 3903 + int silent = fc->sb_flags & SB_SILENT; 4378 3904 4379 3905 /* Set defaults for the variables that will be set during parsing */ 4380 - parsed_opts.journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 4381 - parsed_opts.journal_devnum = 0; 4382 - parsed_opts.mb_optimize_scan = DEFAULT_MB_OPTIMIZE_SCAN; 3906 + ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 3907 + ctx->mb_optimize_scan = DEFAULT_MB_OPTIMIZE_SCAN; 4383 3908 4384 - if ((data && !orig_data) || !sbi) 4385 - goto out_free_base; 4386 - 4387 - sbi->s_daxdev = dax_dev; 4388 - sbi->s_blockgroup_lock = 4389 - kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); 4390 - if (!sbi->s_blockgroup_lock) 4391 - goto out_free_base; 4392 - 4393 - sb->s_fs_info = sbi; 4394 - sbi->s_sb = sb; 4395 3909 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; 4396 - sbi->s_sb_block = sb_block; 4397 3910 sbi->s_sectors_written_start = 4398 3911 part_stat_read(sb->s_bdev, sectors[STAT_WRITE]); 4399 - 4400 - /* Cleanup superblock name */ 4401 - strreplace(sb->s_id, '/', '!'); 4402 3912 4403 3913 /* -EINVAL is default */ 4404 3914 ret = -EINVAL; ··· 4398 3938 * block sizes. We need to calculate the offset from buffer start. 4399 3939 */ 4400 3940 if (blocksize != EXT4_MIN_BLOCK_SIZE) { 4401 - logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; 3941 + logical_sb_block = sbi->s_sb_block * EXT4_MIN_BLOCK_SIZE; 4402 3942 offset = do_div(logical_sb_block, blocksize); 4403 3943 } else { 4404 - logical_sb_block = sb_block; 3944 + logical_sb_block = sbi->s_sb_block; 4405 3945 } 4406 3946 4407 3947 bh = ext4_sb_bread_unmovable(sb, logical_sb_block); ··· 4606 4146 } 4607 4147 } 4608 4148 4609 - if (sbi->s_es->s_mount_opts[0]) { 4610 - char *s_mount_opts = kstrndup(sbi->s_es->s_mount_opts, 4611 - sizeof(sbi->s_es->s_mount_opts), 4612 - GFP_KERNEL); 4613 - if (!s_mount_opts) 4614 - goto failed_mount; 4615 - if (!parse_options(s_mount_opts, sb, &parsed_opts, 0)) { 4616 - ext4_msg(sb, KERN_WARNING, 4617 - "failed to parse options in superblock: %s", 4618 - s_mount_opts); 4619 - } 4620 - kfree(s_mount_opts); 4621 - } 4149 + err = parse_apply_sb_mount_options(sb, ctx); 4150 + if (err < 0) 4151 + goto failed_mount; 4152 + 4622 4153 sbi->s_def_mount_opt = sbi->s_mount_opt; 4623 - if (!parse_options((char *) data, sb, &parsed_opts, 0)) 4154 + 4155 + err = ext4_check_opt_consistency(fc, sb); 4156 + if (err < 0) 4157 + goto failed_mount; 4158 + 4159 + err = ext4_apply_options(fc, sb); 4160 + if (err < 0) 4624 4161 goto failed_mount; 4625 4162 4626 4163 #ifdef CONFIG_UNICODE ··· 4756 4299 goto failed_mount; 4757 4300 } 4758 4301 4759 - if (dax_supported(dax_dev, sb->s_bdev, blocksize, 0, 4302 + if (dax_supported(sbi->s_daxdev, sb->s_bdev, blocksize, 0, 4760 4303 bdev_nr_sectors(sb->s_bdev))) 4761 4304 set_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags); 4762 4305 ··· 4794 4337 goto failed_mount; 4795 4338 } 4796 4339 4797 - logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE; 4340 + logical_sb_block = sbi->s_sb_block * EXT4_MIN_BLOCK_SIZE; 4798 4341 offset = do_div(logical_sb_block, blocksize); 4799 4342 bh = ext4_sb_bread_unmovable(sb, logical_sb_block); 4800 4343 if (IS_ERR(bh)) { ··· 5077 4620 5078 4621 /* Initialize fast commit stuff */ 5079 4622 atomic_set(&sbi->s_fc_subtid, 0); 5080 - atomic_set(&sbi->s_fc_ineligible_updates, 0); 5081 4623 INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_MAIN]); 5082 4624 INIT_LIST_HEAD(&sbi->s_fc_q[FC_Q_STAGING]); 5083 4625 INIT_LIST_HEAD(&sbi->s_fc_dentry_q[FC_Q_MAIN]); ··· 5109 4653 * root first: it may be modified in the journal! 5110 4654 */ 5111 4655 if (!test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) { 5112 - err = ext4_load_journal(sb, es, parsed_opts.journal_devnum); 4656 + err = ext4_load_journal(sb, es, ctx->journal_devnum); 5113 4657 if (err) 5114 4658 goto failed_mount3a; 5115 4659 } else if (test_opt(sb, NOLOAD) && !sb_rdonly(sb) && ··· 5209 4753 goto failed_mount_wq; 5210 4754 } 5211 4755 5212 - set_task_ioprio(sbi->s_journal->j_task, parsed_opts.journal_ioprio); 4756 + set_task_ioprio(sbi->s_journal->j_task, ctx->journal_ioprio); 5213 4757 5214 4758 sbi->s_journal->j_submit_inode_data_buffers = 5215 4759 ext4_journal_submit_inode_data_buffers; ··· 5321 4865 * turned off by passing "mb_optimize_scan=0". This can also be 5322 4866 * turned on forcefully by passing "mb_optimize_scan=1". 5323 4867 */ 5324 - if (parsed_opts.mb_optimize_scan == 1) 4868 + if (ctx->mb_optimize_scan == 1) 5325 4869 set_opt2(sb, MB_OPTIMIZE_SCAN); 5326 - else if (parsed_opts.mb_optimize_scan == 0) 4870 + else if (ctx->mb_optimize_scan == 0) 5327 4871 clear_opt2(sb, MB_OPTIMIZE_SCAN); 5328 4872 else if (sbi->s_groups_count >= MB_DEFAULT_LINEAR_SCAN_THRESHOLD) 5329 4873 set_opt2(sb, MB_OPTIMIZE_SCAN); ··· 5425 4969 if (err) 5426 4970 goto failed_mount9; 5427 4971 } 5428 - if (EXT4_SB(sb)->s_journal) { 5429 - if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 5430 - descr = " journalled data mode"; 5431 - else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) 5432 - descr = " ordered data mode"; 5433 - else 5434 - descr = " writeback data mode"; 5435 - } else 5436 - descr = "out journal"; 5437 4972 5438 4973 if (test_opt(sb, DISCARD)) { 5439 4974 struct request_queue *q = bdev_get_queue(sb->s_bdev); ··· 5433 4986 "mounting with \"discard\" option, but " 5434 4987 "the device does not support discard"); 5435 4988 } 5436 - 5437 - if (___ratelimit(&ext4_mount_msg_ratelimit, "EXT4-fs mount")) 5438 - ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. " 5439 - "Opts: %.*s%s%s. Quota mode: %s.", descr, 5440 - (int) sizeof(sbi->s_es->s_mount_opts), 5441 - sbi->s_es->s_mount_opts, 5442 - *sbi->s_es->s_mount_opts ? "; " : "", orig_data, 5443 - ext4_quota_mode(sb)); 5444 4989 5445 4990 if (es->s_error_count) 5446 4991 mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */ ··· 5444 5005 atomic_set(&sbi->s_warning_count, 0); 5445 5006 atomic_set(&sbi->s_msg_count, 0); 5446 5007 5447 - kfree(orig_data); 5448 5008 return 0; 5449 5009 5450 5010 cantfind_ext4: ··· 5529 5091 ext4_blkdev_remove(sbi); 5530 5092 out_fail: 5531 5093 sb->s_fs_info = NULL; 5532 - kfree(sbi->s_blockgroup_lock); 5533 - out_free_base: 5534 - kfree(sbi); 5535 - kfree(orig_data); 5536 - fs_put_dax(dax_dev); 5537 5094 return err ? err : ret; 5095 + } 5096 + 5097 + static int ext4_fill_super(struct super_block *sb, struct fs_context *fc) 5098 + { 5099 + struct ext4_fs_context *ctx = fc->fs_private; 5100 + struct ext4_sb_info *sbi; 5101 + const char *descr; 5102 + int ret; 5103 + 5104 + sbi = ext4_alloc_sbi(sb); 5105 + if (!sbi) 5106 + ret = -ENOMEM; 5107 + 5108 + fc->s_fs_info = sbi; 5109 + 5110 + /* Cleanup superblock name */ 5111 + strreplace(sb->s_id, '/', '!'); 5112 + 5113 + sbi->s_sb_block = 1; /* Default super block location */ 5114 + if (ctx->spec & EXT4_SPEC_s_sb_block) 5115 + sbi->s_sb_block = ctx->s_sb_block; 5116 + 5117 + ret = __ext4_fill_super(fc, sb); 5118 + if (ret < 0) 5119 + goto free_sbi; 5120 + 5121 + if (sbi->s_journal) { 5122 + if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 5123 + descr = " journalled data mode"; 5124 + else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) 5125 + descr = " ordered data mode"; 5126 + else 5127 + descr = " writeback data mode"; 5128 + } else 5129 + descr = "out journal"; 5130 + 5131 + if (___ratelimit(&ext4_mount_msg_ratelimit, "EXT4-fs mount")) 5132 + ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. " 5133 + "Quota mode: %s.", descr, ext4_quota_mode(sb)); 5134 + 5135 + return 0; 5136 + 5137 + free_sbi: 5138 + ext4_free_sbi(sbi); 5139 + fc->s_fs_info = NULL; 5140 + return ret; 5141 + } 5142 + 5143 + static int ext4_get_tree(struct fs_context *fc) 5144 + { 5145 + return get_tree_bdev(fc, ext4_fill_super); 5538 5146 } 5539 5147 5540 5148 /* ··· 6211 5727 #endif 6212 5728 }; 6213 5729 6214 - static int ext4_remount(struct super_block *sb, int *flags, char *data) 5730 + static int __ext4_remount(struct fs_context *fc, struct super_block *sb) 6215 5731 { 5732 + struct ext4_fs_context *ctx = fc->fs_private; 6216 5733 struct ext4_super_block *es; 6217 5734 struct ext4_sb_info *sbi = EXT4_SB(sb); 6218 - unsigned long old_sb_flags, vfs_flags; 5735 + unsigned long old_sb_flags; 6219 5736 struct ext4_mount_options old_opts; 6220 5737 ext4_group_t g; 6221 5738 int err = 0; ··· 6225 5740 int i, j; 6226 5741 char *to_free[EXT4_MAXQUOTAS]; 6227 5742 #endif 6228 - char *orig_data = kstrdup(data, GFP_KERNEL); 6229 - struct ext4_parsed_options parsed_opts; 6230 5743 6231 - parsed_opts.journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 6232 - parsed_opts.journal_devnum = 0; 6233 - 6234 - if (data && !orig_data) 6235 - return -ENOMEM; 5744 + ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO; 6236 5745 6237 5746 /* Store the original options */ 6238 5747 old_sb_flags = sb->s_flags; ··· 6247 5768 if (!old_opts.s_qf_names[i]) { 6248 5769 for (j = 0; j < i; j++) 6249 5770 kfree(old_opts.s_qf_names[j]); 6250 - kfree(orig_data); 6251 5771 return -ENOMEM; 6252 5772 } 6253 5773 } else 6254 5774 old_opts.s_qf_names[i] = NULL; 6255 5775 #endif 6256 5776 if (sbi->s_journal && sbi->s_journal->j_task->io_context) 6257 - parsed_opts.journal_ioprio = 5777 + ctx->journal_ioprio = 6258 5778 sbi->s_journal->j_task->io_context->ioprio; 6259 5779 6260 - /* 6261 - * Some options can be enabled by ext4 and/or by VFS mount flag 6262 - * either way we need to make sure it matches in both *flags and 6263 - * s_flags. Copy those selected flags from *flags to s_flags 6264 - */ 6265 - vfs_flags = SB_LAZYTIME | SB_I_VERSION; 6266 - sb->s_flags = (sb->s_flags & ~vfs_flags) | (*flags & vfs_flags); 6267 - 6268 - if (!parse_options(data, sb, &parsed_opts, 1)) { 6269 - err = -EINVAL; 6270 - goto restore_opts; 6271 - } 5780 + ext4_apply_options(fc, sb); 6272 5781 6273 5782 if ((old_opts.s_mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) ^ 6274 5783 test_opt(sb, JOURNAL_CHECKSUM)) { ··· 6303 5836 6304 5837 if (sbi->s_journal) { 6305 5838 ext4_init_journal_params(sb, sbi->s_journal); 6306 - set_task_ioprio(sbi->s_journal->j_task, parsed_opts.journal_ioprio); 5839 + set_task_ioprio(sbi->s_journal->j_task, ctx->journal_ioprio); 6307 5840 } 6308 5841 6309 5842 /* Flush outstanding errors before changing fs state */ 6310 5843 flush_work(&sbi->s_error_work); 6311 5844 6312 - if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) { 5845 + if ((bool)(fc->sb_flags & SB_RDONLY) != sb_rdonly(sb)) { 6313 5846 if (ext4_test_mount_flag(sb, EXT4_MF_FS_ABORTED)) { 6314 5847 err = -EROFS; 6315 5848 goto restore_opts; 6316 5849 } 6317 5850 6318 - if (*flags & SB_RDONLY) { 5851 + if (fc->sb_flags & SB_RDONLY) { 6319 5852 err = sync_filesystem(sb); 6320 5853 if (err < 0) 6321 5854 goto restore_opts; ··· 6463 5996 if (!ext4_has_feature_mmp(sb) || sb_rdonly(sb)) 6464 5997 ext4_stop_mmpd(sbi); 6465 5998 6466 - /* 6467 - * Some options can be enabled by ext4 and/or by VFS mount flag 6468 - * either way we need to make sure it matches in both *flags and 6469 - * s_flags. Copy those selected flags from s_flags to *flags 6470 - */ 6471 - *flags = (*flags & ~vfs_flags) | (sb->s_flags & vfs_flags); 6472 - 6473 - ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s. Quota mode: %s.", 6474 - orig_data, ext4_quota_mode(sb)); 6475 - kfree(orig_data); 6476 5999 return 0; 6477 6000 6478 6001 restore_opts: ··· 6488 6031 #endif 6489 6032 if (!ext4_has_feature_mmp(sb) || sb_rdonly(sb)) 6490 6033 ext4_stop_mmpd(sbi); 6491 - kfree(orig_data); 6492 6034 return err; 6035 + } 6036 + 6037 + static int ext4_reconfigure(struct fs_context *fc) 6038 + { 6039 + struct super_block *sb = fc->root->d_sb; 6040 + int ret; 6041 + 6042 + fc->s_fs_info = EXT4_SB(sb); 6043 + 6044 + ret = ext4_check_opt_consistency(fc, sb); 6045 + if (ret < 0) 6046 + return ret; 6047 + 6048 + ret = __ext4_remount(fc, sb); 6049 + if (ret < 0) 6050 + return ret; 6051 + 6052 + ext4_msg(sb, KERN_INFO, "re-mounted. Quota mode: %s.", 6053 + ext4_quota_mode(sb)); 6054 + 6055 + return 0; 6493 6056 } 6494 6057 6495 6058 #ifdef CONFIG_QUOTA ··· 6752 6275 6753 6276 lockdep_set_quota_inode(path->dentry->d_inode, I_DATA_SEM_QUOTA); 6754 6277 err = dquot_quota_on(sb, type, format_id, path); 6755 - if (err) { 6756 - lockdep_set_quota_inode(path->dentry->d_inode, 6757 - I_DATA_SEM_NORMAL); 6758 - } else { 6278 + if (!err) { 6759 6279 struct inode *inode = d_inode(path->dentry); 6760 6280 handle_t *handle; 6761 6281 ··· 6772 6298 ext4_journal_stop(handle); 6773 6299 unlock_inode: 6774 6300 inode_unlock(inode); 6301 + if (err) 6302 + dquot_quota_off(sb, type); 6775 6303 } 6304 + if (err) 6305 + lockdep_set_quota_inode(path->dentry->d_inode, 6306 + I_DATA_SEM_NORMAL); 6776 6307 return err; 6777 6308 } 6778 6309 ··· 6840 6361 "Failed to enable quota tracking " 6841 6362 "(type=%d, err=%d). Please run " 6842 6363 "e2fsck to fix.", type, err); 6843 - for (type--; type >= 0; type--) 6364 + for (type--; type >= 0; type--) { 6365 + struct inode *inode; 6366 + 6367 + inode = sb_dqopt(sb)->files[type]; 6368 + if (inode) 6369 + inode = igrab(inode); 6844 6370 dquot_quota_off(sb, type); 6371 + if (inode) { 6372 + lockdep_set_quota_inode(inode, 6373 + I_DATA_SEM_NORMAL); 6374 + iput(inode); 6375 + } 6376 + } 6845 6377 6846 6378 return err; 6847 6379 } ··· 6956 6466 struct buffer_head *bh; 6957 6467 handle_t *handle = journal_current_handle(); 6958 6468 6959 - if (EXT4_SB(sb)->s_journal && !handle) { 6469 + if (!handle) { 6960 6470 ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)" 6961 6471 " cancelled because transaction is not started", 6962 6472 (unsigned long long)off, (unsigned long long)len); ··· 7006 6516 return err ? err : len; 7007 6517 } 7008 6518 #endif 7009 - 7010 - static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags, 7011 - const char *dev_name, void *data) 7012 - { 7013 - return mount_bdev(fs_type, flags, dev_name, data, ext4_fill_super); 7014 - } 7015 6519 7016 6520 #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT2) 7017 6521 static inline void register_as_ext2(void) ··· 7064 6580 } 7065 6581 7066 6582 static struct file_system_type ext4_fs_type = { 7067 - .owner = THIS_MODULE, 7068 - .name = "ext4", 7069 - .mount = ext4_mount, 7070 - .kill_sb = kill_block_super, 7071 - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, 6583 + .owner = THIS_MODULE, 6584 + .name = "ext4", 6585 + .init_fs_context = ext4_init_fs_context, 6586 + .parameters = ext4_param_specs, 6587 + .kill_sb = kill_block_super, 6588 + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, 7072 6589 }; 7073 6590 MODULE_ALIAS_FS("ext4"); 7074 6591 ··· 7134 6649 out: 7135 6650 unregister_as_ext2(); 7136 6651 unregister_as_ext3(); 6652 + ext4_fc_destroy_dentry_cache(); 7137 6653 out05: 7138 6654 destroy_inodecache(); 7139 6655 out1: ··· 7161 6675 unregister_as_ext2(); 7162 6676 unregister_as_ext3(); 7163 6677 unregister_filesystem(&ext4_fs_type); 6678 + ext4_fc_destroy_dentry_cache(); 7164 6679 destroy_inodecache(); 7165 6680 ext4_exit_mballoc(); 7166 6681 ext4_exit_sysfs();
+19 -17
fs/ext4/sysfs.c
··· 63 63 { 64 64 struct super_block *sb = sbi->s_buddy_cache->i_sb; 65 65 66 - return snprintf(buf, PAGE_SIZE, "%lu\n", 66 + return sysfs_emit(buf, "%lu\n", 67 67 (part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - 68 68 sbi->s_sectors_written_start) >> 1); 69 69 } ··· 72 72 { 73 73 struct super_block *sb = sbi->s_buddy_cache->i_sb; 74 74 75 - return snprintf(buf, PAGE_SIZE, "%llu\n", 75 + return sysfs_emit(buf, "%llu\n", 76 76 (unsigned long long)(sbi->s_kbytes_written + 77 77 ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - 78 78 EXT4_SB(sb)->s_sectors_written_start) >> 1))); ··· 130 130 static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf) 131 131 { 132 132 if (!sbi->s_journal) 133 - return snprintf(buf, PAGE_SIZE, "<none>\n"); 134 - return snprintf(buf, PAGE_SIZE, "%d\n", 133 + return sysfs_emit(buf, "<none>\n"); 134 + return sysfs_emit(buf, "%d\n", 135 135 task_pid_vnr(sbi->s_journal->j_task)); 136 136 } 137 137 ··· 245 245 EXT4_ATTR(journal_task, 0444, journal_task); 246 246 EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch); 247 247 EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit); 248 + EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks); 248 249 249 250 static unsigned int old_bump_val = 128; 250 251 EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val); ··· 296 295 #endif 297 296 ATTR_LIST(mb_prefetch), 298 297 ATTR_LIST(mb_prefetch_limit), 298 + ATTR_LIST(last_trim_minblks), 299 299 NULL, 300 300 }; 301 301 ATTRIBUTE_GROUPS(ext4); ··· 359 357 360 358 static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi) 361 359 { 362 - return snprintf(buf, PAGE_SIZE, "%lld\n", 360 + return sysfs_emit(buf, "%lld\n", 363 361 ((time64_t)hi << 32) + le32_to_cpu(lo)); 364 362 } 365 363 ··· 376 374 377 375 switch (a->attr_id) { 378 376 case attr_delayed_allocation_blocks: 379 - return snprintf(buf, PAGE_SIZE, "%llu\n", 377 + return sysfs_emit(buf, "%llu\n", 380 378 (s64) EXT4_C2B(sbi, 381 379 percpu_counter_sum(&sbi->s_dirtyclusters_counter))); 382 380 case attr_session_write_kbytes: ··· 384 382 case attr_lifetime_write_kbytes: 385 383 return lifetime_write_kbytes_show(sbi, buf); 386 384 case attr_reserved_clusters: 387 - return snprintf(buf, PAGE_SIZE, "%llu\n", 385 + return sysfs_emit(buf, "%llu\n", 388 386 (unsigned long long) 389 387 atomic64_read(&sbi->s_resv_clusters)); 390 388 case attr_sra_exceeded_retry_limit: 391 - return snprintf(buf, PAGE_SIZE, "%llu\n", 389 + return sysfs_emit(buf, "%llu\n", 392 390 (unsigned long long) 393 391 percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit)); 394 392 case attr_inode_readahead: ··· 396 394 if (!ptr) 397 395 return 0; 398 396 if (a->attr_ptr == ptr_ext4_super_block_offset) 399 - return snprintf(buf, PAGE_SIZE, "%u\n", 397 + return sysfs_emit(buf, "%u\n", 400 398 le32_to_cpup(ptr)); 401 399 else 402 - return snprintf(buf, PAGE_SIZE, "%u\n", 400 + return sysfs_emit(buf, "%u\n", 403 401 *((unsigned int *) ptr)); 404 402 case attr_pointer_ul: 405 403 if (!ptr) 406 404 return 0; 407 - return snprintf(buf, PAGE_SIZE, "%lu\n", 405 + return sysfs_emit(buf, "%lu\n", 408 406 *((unsigned long *) ptr)); 409 407 case attr_pointer_u8: 410 408 if (!ptr) 411 409 return 0; 412 - return snprintf(buf, PAGE_SIZE, "%u\n", 410 + return sysfs_emit(buf, "%u\n", 413 411 *((unsigned char *) ptr)); 414 412 case attr_pointer_u64: 415 413 if (!ptr) 416 414 return 0; 417 415 if (a->attr_ptr == ptr_ext4_super_block_offset) 418 - return snprintf(buf, PAGE_SIZE, "%llu\n", 416 + return sysfs_emit(buf, "%llu\n", 419 417 le64_to_cpup(ptr)); 420 418 else 421 - return snprintf(buf, PAGE_SIZE, "%llu\n", 419 + return sysfs_emit(buf, "%llu\n", 422 420 *((unsigned long long *) ptr)); 423 421 case attr_pointer_string: 424 422 if (!ptr) 425 423 return 0; 426 - return snprintf(buf, PAGE_SIZE, "%.*s\n", a->attr_size, 424 + return sysfs_emit(buf, "%.*s\n", a->attr_size, 427 425 (char *) ptr); 428 426 case attr_pointer_atomic: 429 427 if (!ptr) 430 428 return 0; 431 - return snprintf(buf, PAGE_SIZE, "%d\n", 429 + return sysfs_emit(buf, "%d\n", 432 430 atomic_read((atomic_t *) ptr)); 433 431 case attr_feature: 434 - return snprintf(buf, PAGE_SIZE, "supported\n"); 432 + return sysfs_emit(buf, "supported\n"); 435 433 case attr_first_error_time: 436 434 return print_tstamp(buf, sbi->s_es, s_first_error_time); 437 435 case attr_last_error_time:
+23 -8
fs/fs_parser.c
··· 199 199 int b; 200 200 if (param->type != fs_value_is_string) 201 201 return fs_param_bad_value(log, param); 202 + if (!*param->string && (p->flags & fs_param_can_be_empty)) 203 + return 0; 202 204 b = lookup_constant(bool_names, param->string, -1); 203 205 if (b == -1) 204 206 return fs_param_bad_value(log, param); ··· 213 211 struct fs_parameter *param, struct fs_parse_result *result) 214 212 { 215 213 int base = (unsigned long)p->data; 216 - if (param->type != fs_value_is_string || 217 - kstrtouint(param->string, base, &result->uint_32) < 0) 214 + if (param->type != fs_value_is_string) 215 + return fs_param_bad_value(log, param); 216 + if (!*param->string && (p->flags & fs_param_can_be_empty)) 217 + return 0; 218 + if (kstrtouint(param->string, base, &result->uint_32) < 0) 218 219 return fs_param_bad_value(log, param); 219 220 return 0; 220 221 } ··· 226 221 int fs_param_is_s32(struct p_log *log, const struct fs_parameter_spec *p, 227 222 struct fs_parameter *param, struct fs_parse_result *result) 228 223 { 229 - if (param->type != fs_value_is_string || 230 - kstrtoint(param->string, 0, &result->int_32) < 0) 224 + if (param->type != fs_value_is_string) 225 + return fs_param_bad_value(log, param); 226 + if (!*param->string && (p->flags & fs_param_can_be_empty)) 227 + return 0; 228 + if (kstrtoint(param->string, 0, &result->int_32) < 0) 231 229 return fs_param_bad_value(log, param); 232 230 return 0; 233 231 } ··· 239 231 int fs_param_is_u64(struct p_log *log, const struct fs_parameter_spec *p, 240 232 struct fs_parameter *param, struct fs_parse_result *result) 241 233 { 242 - if (param->type != fs_value_is_string || 243 - kstrtoull(param->string, 0, &result->uint_64) < 0) 234 + if (param->type != fs_value_is_string) 235 + return fs_param_bad_value(log, param); 236 + if (!*param->string && (p->flags & fs_param_can_be_empty)) 237 + return 0; 238 + if (kstrtoull(param->string, 0, &result->uint_64) < 0) 244 239 return fs_param_bad_value(log, param); 245 240 return 0; 246 241 } ··· 255 244 const struct constant_table *c; 256 245 if (param->type != fs_value_is_string) 257 246 return fs_param_bad_value(log, param); 247 + if (!*param->string && (p->flags & fs_param_can_be_empty)) 248 + return 0; 258 249 c = __lookup_constant(p->data, param->string); 259 250 if (!c) 260 251 return fs_param_bad_value(log, param); ··· 268 255 int fs_param_is_string(struct p_log *log, const struct fs_parameter_spec *p, 269 256 struct fs_parameter *param, struct fs_parse_result *result) 270 257 { 271 - if (param->type != fs_value_is_string || !*param->string) 258 + if (param->type != fs_value_is_string || 259 + (!*param->string && !(p->flags & fs_param_can_be_empty))) 272 260 return fs_param_bad_value(log, param); 273 261 return 0; 274 262 } ··· 289 275 { 290 276 switch (param->type) { 291 277 case fs_value_is_string: 292 - if (kstrtouint(param->string, 0, &result->uint_32) < 0) 278 + if ((!*param->string && !(p->flags & fs_param_can_be_empty)) || 279 + kstrtouint(param->string, 0, &result->uint_32) < 0) 293 280 break; 294 281 if (result->uint_32 <= INT_MAX) 295 282 return 0;
+2
fs/jbd2/journal.c
··· 757 757 } 758 758 journal->j_flags |= JBD2_FAST_COMMIT_ONGOING; 759 759 write_unlock(&journal->j_state_lock); 760 + jbd2_journal_lock_updates(journal); 760 761 761 762 return 0; 762 763 } ··· 769 768 */ 770 769 static int __jbd2_fc_end_commit(journal_t *journal, tid_t tid, bool fallback) 771 770 { 771 + jbd2_journal_unlock_updates(journal); 772 772 if (journal->j_fc_cleanup_callback) 773 773 journal->j_fc_cleanup_callback(journal, 0); 774 774 write_lock(&journal->j_state_lock);
+1 -1
include/linux/fs_parser.h
··· 42 42 u8 opt; /* Option number (returned by fs_parse()) */ 43 43 unsigned short flags; 44 44 #define fs_param_neg_with_no 0x0002 /* "noxxx" is negative param */ 45 - #define fs_param_neg_with_empty 0x0004 /* "xxx=" is negative param */ 45 + #define fs_param_can_be_empty 0x0004 /* "xxx=" is allowed */ 46 46 #define fs_param_deprecated 0x0008 /* The param is deprecated */ 47 47 const void *data; 48 48 };
+23
include/trace/events/ext4.h
··· 2837 2837 __entry->end) 2838 2838 ); 2839 2839 2840 + TRACE_EVENT(ext4_update_sb, 2841 + TP_PROTO(struct super_block *sb, ext4_fsblk_t fsblk, 2842 + unsigned int flags), 2843 + 2844 + TP_ARGS(sb, fsblk, flags), 2845 + 2846 + TP_STRUCT__entry( 2847 + __field(dev_t, dev) 2848 + __field(ext4_fsblk_t, fsblk) 2849 + __field(unsigned int, flags) 2850 + ), 2851 + 2852 + TP_fast_assign( 2853 + __entry->dev = sb->s_dev; 2854 + __entry->fsblk = fsblk; 2855 + __entry->flags = flags; 2856 + ), 2857 + 2858 + TP_printk("dev %d,%d fsblk %llu flags %u", 2859 + MAJOR(__entry->dev), MINOR(__entry->dev), 2860 + __entry->fsblk, __entry->flags) 2861 + ); 2862 + 2840 2863 #endif /* _TRACE_EXT4_H */ 2841 2864 2842 2865 /* This part must be outside protection */