super.c (ef5fd681d5159d64c464715d657660f0151c7419) super.c (ed318a6cc0b620440e65f48eb527dc3df7269ce4)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/ext4/super.c
4 *
5 * Copyright (C) 1992, 1993, 1994, 1995
6 * Remy Card (card@masi.ibp.fr)
7 * Laboratoire MASI - Institut Blaise Pascal
8 * Universite Pierre et Marie Curie (Paris VI)

--- 1092 unchanged lines hidden (view full) ---

1101 * superblock, we need to actually destroy the kobject.
1102 */
1103 kobject_put(&sbi->s_kobj);
1104 wait_for_completion(&sbi->s_kobj_unregister);
1105 if (sbi->s_chksum_driver)
1106 crypto_free_shash(sbi->s_chksum_driver);
1107 kfree(sbi->s_blockgroup_lock);
1108 fs_put_dax(sbi->s_daxdev);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/ext4/super.c
4 *
5 * Copyright (C) 1992, 1993, 1994, 1995
6 * Remy Card (card@masi.ibp.fr)
7 * Laboratoire MASI - Institut Blaise Pascal
8 * Universite Pierre et Marie Curie (Paris VI)

--- 1092 unchanged lines hidden (view full) ---

1101 * superblock, we need to actually destroy the kobject.
1102 */
1103 kobject_put(&sbi->s_kobj);
1104 wait_for_completion(&sbi->s_kobj_unregister);
1105 if (sbi->s_chksum_driver)
1106 crypto_free_shash(sbi->s_chksum_driver);
1107 kfree(sbi->s_blockgroup_lock);
1108 fs_put_dax(sbi->s_daxdev);
1109 fscrypt_free_dummy_context(&sbi->s_dummy_enc_ctx);
1109#ifdef CONFIG_UNICODE
1110 utf8_unload(sbi->s_encoding);
1111#endif
1112 kfree(sbi);
1113}
1114
1115static struct kmem_cache *ext4_inode_cachep;
1116

--- 267 unchanged lines hidden (view full) ---

1384
1385 if (res == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
1386 goto retry;
1387 if (!res)
1388 res = res2;
1389 return res;
1390}
1391
1110#ifdef CONFIG_UNICODE
1111 utf8_unload(sbi->s_encoding);
1112#endif
1113 kfree(sbi);
1114}
1115
1116static struct kmem_cache *ext4_inode_cachep;
1117

--- 267 unchanged lines hidden (view full) ---

1385
1386 if (res == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
1387 goto retry;
1388 if (!res)
1389 res = res2;
1390 return res;
1391}
1392
1392static bool ext4_dummy_context(struct inode *inode)
1393static const union fscrypt_context *
1394ext4_get_dummy_context(struct super_block *sb)
1393{
1395{
1394 return DUMMY_ENCRYPTION_ENABLED(EXT4_SB(inode->i_sb));
1396 return EXT4_SB(sb)->s_dummy_enc_ctx.ctx;
1395}
1396
1397static bool ext4_has_stable_inodes(struct super_block *sb)
1398{
1399 return ext4_has_feature_stable_inodes(sb);
1400}
1401
1402static void ext4_get_ino_and_lblk_bits(struct super_block *sb,
1403 int *ino_bits_ret, int *lblk_bits_ret)
1404{
1405 *ino_bits_ret = 8 * sizeof(EXT4_SB(sb)->s_es->s_inodes_count);
1406 *lblk_bits_ret = 8 * sizeof(ext4_lblk_t);
1407}
1408
1409static const struct fscrypt_operations ext4_cryptops = {
1410 .key_prefix = "ext4:",
1411 .get_context = ext4_get_context,
1412 .set_context = ext4_set_context,
1397}
1398
1399static bool ext4_has_stable_inodes(struct super_block *sb)
1400{
1401 return ext4_has_feature_stable_inodes(sb);
1402}
1403
1404static void ext4_get_ino_and_lblk_bits(struct super_block *sb,
1405 int *ino_bits_ret, int *lblk_bits_ret)
1406{
1407 *ino_bits_ret = 8 * sizeof(EXT4_SB(sb)->s_es->s_inodes_count);
1408 *lblk_bits_ret = 8 * sizeof(ext4_lblk_t);
1409}
1410
1411static const struct fscrypt_operations ext4_cryptops = {
1412 .key_prefix = "ext4:",
1413 .get_context = ext4_get_context,
1414 .set_context = ext4_set_context,
1413 .dummy_context = ext4_dummy_context,
1415 .get_dummy_context = ext4_get_dummy_context,
1414 .empty_dir = ext4_empty_dir,
1415 .max_namelen = EXT4_NAME_LEN,
1416 .has_stable_inodes = ext4_has_stable_inodes,
1417 .get_ino_and_lblk_bits = ext4_get_ino_and_lblk_bits,
1418};
1419#endif
1420
1421#ifdef CONFIG_QUOTA

--- 178 unchanged lines hidden (view full) ---

1600 {Opt_dioread_lock, "nodioread_nolock"},
1601 {Opt_dioread_lock, "dioread_lock"},
1602 {Opt_discard, "discard"},
1603 {Opt_nodiscard, "nodiscard"},
1604 {Opt_init_itable, "init_itable=%u"},
1605 {Opt_init_itable, "init_itable"},
1606 {Opt_noinit_itable, "noinit_itable"},
1607 {Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
1416 .empty_dir = ext4_empty_dir,
1417 .max_namelen = EXT4_NAME_LEN,
1418 .has_stable_inodes = ext4_has_stable_inodes,
1419 .get_ino_and_lblk_bits = ext4_get_ino_and_lblk_bits,
1420};
1421#endif
1422
1423#ifdef CONFIG_QUOTA

--- 178 unchanged lines hidden (view full) ---

1602 {Opt_dioread_lock, "nodioread_nolock"},
1603 {Opt_dioread_lock, "dioread_lock"},
1604 {Opt_discard, "discard"},
1605 {Opt_nodiscard, "nodiscard"},
1606 {Opt_init_itable, "init_itable=%u"},
1607 {Opt_init_itable, "init_itable"},
1608 {Opt_noinit_itable, "noinit_itable"},
1609 {Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
1610 {Opt_test_dummy_encryption, "test_dummy_encryption=%s"},
1608 {Opt_test_dummy_encryption, "test_dummy_encryption"},
1609 {Opt_nombcache, "nombcache"},
1610 {Opt_nombcache, "no_mbcache"}, /* for backward compatibility */
1611 {Opt_removed, "check=none"}, /* mount option from ext2/3 */
1612 {Opt_removed, "nocheck"}, /* mount option from ext2/3 */
1613 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
1614 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
1615 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */

--- 195 unchanged lines hidden (view full) ---

1811 {Opt_usrjquota, 0, MOPT_Q},
1812 {Opt_grpjquota, 0, MOPT_Q},
1813 {Opt_offusrjquota, 0, MOPT_Q},
1814 {Opt_offgrpjquota, 0, MOPT_Q},
1815 {Opt_jqfmt_vfsold, QFMT_VFS_OLD, MOPT_QFMT},
1816 {Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT},
1817 {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
1818 {Opt_max_dir_size_kb, 0, MOPT_GTE0},
1611 {Opt_test_dummy_encryption, "test_dummy_encryption"},
1612 {Opt_nombcache, "nombcache"},
1613 {Opt_nombcache, "no_mbcache"}, /* for backward compatibility */
1614 {Opt_removed, "check=none"}, /* mount option from ext2/3 */
1615 {Opt_removed, "nocheck"}, /* mount option from ext2/3 */
1616 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
1617 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
1618 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */

--- 195 unchanged lines hidden (view full) ---

1814 {Opt_usrjquota, 0, MOPT_Q},
1815 {Opt_grpjquota, 0, MOPT_Q},
1816 {Opt_offusrjquota, 0, MOPT_Q},
1817 {Opt_offgrpjquota, 0, MOPT_Q},
1818 {Opt_jqfmt_vfsold, QFMT_VFS_OLD, MOPT_QFMT},
1819 {Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT},
1820 {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
1821 {Opt_max_dir_size_kb, 0, MOPT_GTE0},
1819 {Opt_test_dummy_encryption, 0, MOPT_GTE0},
1822 {Opt_test_dummy_encryption, 0, MOPT_STRING},
1820 {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
1821 {Opt_err, 0, 0}
1822};
1823
1824#ifdef CONFIG_UNICODE
1825static const struct ext4_sb_encodings {
1826 __u16 magic;
1827 char *name;

--- 18 unchanged lines hidden (view full) ---

1846
1847 *encoding = &ext4_sb_encoding_map[i];
1848 *flags = le16_to_cpu(es->s_encoding_flags);
1849
1850 return 0;
1851}
1852#endif
1853
1823 {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
1824 {Opt_err, 0, 0}
1825};
1826
1827#ifdef CONFIG_UNICODE
1828static const struct ext4_sb_encodings {
1829 __u16 magic;
1830 char *name;

--- 18 unchanged lines hidden (view full) ---

1849
1850 *encoding = &ext4_sb_encoding_map[i];
1851 *flags = le16_to_cpu(es->s_encoding_flags);
1852
1853 return 0;
1854}
1855#endif
1856
1857static int ext4_set_test_dummy_encryption(struct super_block *sb,
1858 const char *opt,
1859 const substring_t *arg,
1860 bool is_remount)
1861{
1862#ifdef CONFIG_FS_ENCRYPTION
1863 struct ext4_sb_info *sbi = EXT4_SB(sb);
1864 int err;
1865
1866 /*
1867 * This mount option is just for testing, and it's not worthwhile to
1868 * implement the extra complexity (e.g. RCU protection) that would be
1869 * needed to allow it to be set or changed during remount. We do allow
1870 * it to be specified during remount, but only if there is no change.
1871 */
1872 if (is_remount && !sbi->s_dummy_enc_ctx.ctx) {
1873 ext4_msg(sb, KERN_WARNING,
1874 "Can't set test_dummy_encryption on remount");
1875 return -1;
1876 }
1877 err = fscrypt_set_test_dummy_encryption(sb, arg, &sbi->s_dummy_enc_ctx);
1878 if (err) {
1879 if (err == -EEXIST)
1880 ext4_msg(sb, KERN_WARNING,
1881 "Can't change test_dummy_encryption on remount");
1882 else if (err == -EINVAL)
1883 ext4_msg(sb, KERN_WARNING,
1884 "Value of option \"%s\" is unrecognized", opt);
1885 else
1886 ext4_msg(sb, KERN_WARNING,
1887 "Error processing option \"%s\" [%d]",
1888 opt, err);
1889 return -1;
1890 }
1891 ext4_msg(sb, KERN_WARNING, "Test dummy encryption mode enabled");
1892#else
1893 ext4_msg(sb, KERN_WARNING,
1894 "Test dummy encryption mount option ignored");
1895#endif
1896 return 1;
1897}
1898
1854static int handle_mount_opt(struct super_block *sb, char *opt, int token,
1855 substring_t *args, unsigned long *journal_devnum,
1856 unsigned int *journal_ioprio, int is_remount)
1857{
1858 struct ext4_sb_info *sbi = EXT4_SB(sb);
1859 const struct mount_opts *m;
1860 kuid_t uid;
1861 kgid_t gid;

--- 180 unchanged lines hidden (view full) ---

2042 if (arg > 7) {
2043 ext4_msg(sb, KERN_ERR, "Invalid journal IO priority"
2044 " (must be 0-7)");
2045 return -1;
2046 }
2047 *journal_ioprio =
2048 IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
2049 } else if (token == Opt_test_dummy_encryption) {
1899static int handle_mount_opt(struct super_block *sb, char *opt, int token,
1900 substring_t *args, unsigned long *journal_devnum,
1901 unsigned int *journal_ioprio, int is_remount)
1902{
1903 struct ext4_sb_info *sbi = EXT4_SB(sb);
1904 const struct mount_opts *m;
1905 kuid_t uid;
1906 kgid_t gid;

--- 180 unchanged lines hidden (view full) ---

2087 if (arg > 7) {
2088 ext4_msg(sb, KERN_ERR, "Invalid journal IO priority"
2089 " (must be 0-7)");
2090 return -1;
2091 }
2092 *journal_ioprio =
2093 IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
2094 } else if (token == Opt_test_dummy_encryption) {
2050#ifdef CONFIG_FS_ENCRYPTION
2051 sbi->s_mount_flags |= EXT4_MF_TEST_DUMMY_ENCRYPTION;
2052 ext4_msg(sb, KERN_WARNING,
2053 "Test dummy encryption mode enabled");
2054#else
2055 ext4_msg(sb, KERN_WARNING,
2056 "Test dummy encryption mount option ignored");
2057#endif
2095 return ext4_set_test_dummy_encryption(sb, opt, &args[0],
2096 is_remount);
2058 } else if (m->flags & MOPT_DATAJ) {
2059 if (is_remount) {
2060 if (!sbi->s_journal)
2061 ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option");
2062 else if (test_opt(sb, DATA_FLAGS) != m->mount_opt) {
2063 ext4_msg(sb, KERN_ERR,
2064 "Cannot change data mode on remount");
2065 return -1;

--- 240 unchanged lines hidden (view full) ---

2306
2307 if (test_opt(sb, INIT_INODE_TABLE) && (nodefs ||
2308 (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT)))
2309 SEQ_OPTS_PRINT("init_itable=%u", sbi->s_li_wait_mult);
2310 if (nodefs || sbi->s_max_dir_size_kb)
2311 SEQ_OPTS_PRINT("max_dir_size_kb=%u", sbi->s_max_dir_size_kb);
2312 if (test_opt(sb, DATA_ERR_ABORT))
2313 SEQ_OPTS_PUTS("data_err=abort");
2097 } else if (m->flags & MOPT_DATAJ) {
2098 if (is_remount) {
2099 if (!sbi->s_journal)
2100 ext4_msg(sb, KERN_WARNING, "Remounting file system with no journal so ignoring journalled data option");
2101 else if (test_opt(sb, DATA_FLAGS) != m->mount_opt) {
2102 ext4_msg(sb, KERN_ERR,
2103 "Cannot change data mode on remount");
2104 return -1;

--- 240 unchanged lines hidden (view full) ---

2345
2346 if (test_opt(sb, INIT_INODE_TABLE) && (nodefs ||
2347 (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT)))
2348 SEQ_OPTS_PRINT("init_itable=%u", sbi->s_li_wait_mult);
2349 if (nodefs || sbi->s_max_dir_size_kb)
2350 SEQ_OPTS_PRINT("max_dir_size_kb=%u", sbi->s_max_dir_size_kb);
2351 if (test_opt(sb, DATA_ERR_ABORT))
2352 SEQ_OPTS_PUTS("data_err=abort");
2314 if (DUMMY_ENCRYPTION_ENABLED(sbi))
2315 SEQ_OPTS_PUTS("test_dummy_encryption");
2316
2353
2354 fscrypt_show_test_dummy_encryption(seq, sep, sb);
2355
2317 ext4_show_quota_options(seq, sb);
2318 return 0;
2319}
2320
2321static int ext4_show_options(struct seq_file *seq, struct dentry *root)
2322{
2323 return _ext4_show_options(seq, root->d_sb, 0);
2324}

--- 1349 unchanged lines hidden (view full) ---

3674 unsigned long journal_devnum = 0;
3675 unsigned long def_mount_opts;
3676 struct inode *root;
3677 const char *descr;
3678 int ret = -ENOMEM;
3679 int blocksize, clustersize;
3680 unsigned int db_count;
3681 unsigned int i;
2356 ext4_show_quota_options(seq, sb);
2357 return 0;
2358}
2359
2360static int ext4_show_options(struct seq_file *seq, struct dentry *root)
2361{
2362 return _ext4_show_options(seq, root->d_sb, 0);
2363}

--- 1349 unchanged lines hidden (view full) ---

3713 unsigned long journal_devnum = 0;
3714 unsigned long def_mount_opts;
3715 struct inode *root;
3716 const char *descr;
3717 int ret = -ENOMEM;
3718 int blocksize, clustersize;
3719 unsigned int db_count;
3720 unsigned int i;
3682 int needs_recovery, has_huge_files;
3721 int needs_recovery, has_huge_files, has_bigalloc;
3683 __u64 blocks_count;
3684 int err = 0;
3685 unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
3686 ext4_group_t first_not_zeroed;
3687
3688 if ((data && !orig_data) || !sbi)
3689 goto out_free_base;
3690

--- 275 unchanged lines hidden (view full) ---

3966
3967 sbi->s_encoding = encoding;
3968 sbi->s_encoding_flags = encoding_flags;
3969 }
3970#endif
3971
3972 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
3973 printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, and O_DIRECT support!\n");
3722 __u64 blocks_count;
3723 int err = 0;
3724 unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
3725 ext4_group_t first_not_zeroed;
3726
3727 if ((data && !orig_data) || !sbi)
3728 goto out_free_base;
3729

--- 275 unchanged lines hidden (view full) ---

4005
4006 sbi->s_encoding = encoding;
4007 sbi->s_encoding_flags = encoding_flags;
4008 }
4009#endif
4010
4011 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
4012 printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, and O_DIRECT support!\n");
3974 /* can't mount with both data=journal and dioread_nolock. */
3975 clear_opt(sb, DIOREAD_NOLOCK);
3976 if (test_opt2(sb, EXPLICIT_DELALLOC)) {
3977 ext4_msg(sb, KERN_ERR, "can't mount with "
3978 "both data=journal and delalloc");
3979 goto failed_mount;
3980 }
4013 clear_opt(sb, DIOREAD_NOLOCK);
4014 if (test_opt2(sb, EXPLICIT_DELALLOC)) {
4015 ext4_msg(sb, KERN_ERR, "can't mount with "
4016 "both data=journal and delalloc");
4017 goto failed_mount;
4018 }
4019 if (test_opt(sb, DIOREAD_NOLOCK)) {
4020 ext4_msg(sb, KERN_ERR, "can't mount with "
4021 "both data=journal and dioread_nolock");
4022 goto failed_mount;
4023 }
3981 if (test_opt(sb, DAX)) {
3982 ext4_msg(sb, KERN_ERR, "can't mount with "
3983 "both data=journal and dax");
3984 goto failed_mount;
3985 }
3986 if (ext4_has_feature_encrypt(sb)) {
3987 ext4_msg(sb, KERN_WARNING,
3988 "encrypted files will use data=ordered "

--- 200 unchanged lines hidden (view full) ---

4189 es->s_flags |=
4190 cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
4191#endif
4192 }
4193 }
4194
4195 /* Handle clustersize */
4196 clustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);
4024 if (test_opt(sb, DAX)) {
4025 ext4_msg(sb, KERN_ERR, "can't mount with "
4026 "both data=journal and dax");
4027 goto failed_mount;
4028 }
4029 if (ext4_has_feature_encrypt(sb)) {
4030 ext4_msg(sb, KERN_WARNING,
4031 "encrypted files will use data=ordered "

--- 200 unchanged lines hidden (view full) ---

4232 es->s_flags |=
4233 cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
4234#endif
4235 }
4236 }
4237
4238 /* Handle clustersize */
4239 clustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);
4197 if (ext4_has_feature_bigalloc(sb)) {
4240 has_bigalloc = ext4_has_feature_bigalloc(sb);
4241 if (has_bigalloc) {
4198 if (clustersize < blocksize) {
4199 ext4_msg(sb, KERN_ERR,
4200 "cluster size (%d) smaller than "
4201 "block size (%d)", clustersize, blocksize);
4202 goto failed_mount;
4203 }
4204 sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -
4205 le32_to_cpu(es->s_log_block_size);

--- 564 unchanged lines hidden (view full) ---

4770#ifdef CONFIG_UNICODE
4771 utf8_unload(sbi->s_encoding);
4772#endif
4773
4774#ifdef CONFIG_QUOTA
4775 for (i = 0; i < EXT4_MAXQUOTAS; i++)
4776 kfree(get_qf_name(sb, sbi, i));
4777#endif
4242 if (clustersize < blocksize) {
4243 ext4_msg(sb, KERN_ERR,
4244 "cluster size (%d) smaller than "
4245 "block size (%d)", clustersize, blocksize);
4246 goto failed_mount;
4247 }
4248 sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -
4249 le32_to_cpu(es->s_log_block_size);

--- 564 unchanged lines hidden (view full) ---

4814#ifdef CONFIG_UNICODE
4815 utf8_unload(sbi->s_encoding);
4816#endif
4817
4818#ifdef CONFIG_QUOTA
4819 for (i = 0; i < EXT4_MAXQUOTAS; i++)
4820 kfree(get_qf_name(sb, sbi, i));
4821#endif
4822 fscrypt_free_dummy_context(&sbi->s_dummy_enc_ctx);
4778 ext4_blkdev_remove(sbi);
4779 brelse(bh);
4780out_fail:
4781 sb->s_fs_info = NULL;
4782 kfree(sbi->s_blockgroup_lock);
4783out_free_base:
4784 kfree(sbi);
4785 kfree(orig_data);

--- 1485 unchanged lines hidden ---
4823 ext4_blkdev_remove(sbi);
4824 brelse(bh);
4825out_fail:
4826 sb->s_fs_info = NULL;
4827 kfree(sbi->s_blockgroup_lock);
4828out_free_base:
4829 kfree(sbi);
4830 kfree(orig_data);

--- 1485 unchanged lines hidden ---