super.c (1d1df41c5a33359a00e919d54eaebfb789711fdc) super.c (5298d4bfe80f6ae6ae2777bcd1357b0022d98573)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * fs/f2fs/super.c
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 */
8#include <linux/module.h>

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

54 [FAULT_EVICT_INODE] = "evict_inode fail",
55 [FAULT_TRUNCATE] = "truncate fail",
56 [FAULT_READ_IO] = "read IO error",
57 [FAULT_CHECKPOINT] = "checkpoint error",
58 [FAULT_DISCARD] = "discard error",
59 [FAULT_WRITE_IO] = "write IO error",
60 [FAULT_SLAB_ALLOC] = "slab alloc",
61 [FAULT_DQUOT_INIT] = "dquot initialize",
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * fs/f2fs/super.c
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 */
8#include <linux/module.h>

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

54 [FAULT_EVICT_INODE] = "evict_inode fail",
55 [FAULT_TRUNCATE] = "truncate fail",
56 [FAULT_READ_IO] = "read IO error",
57 [FAULT_CHECKPOINT] = "checkpoint error",
58 [FAULT_DISCARD] = "discard error",
59 [FAULT_WRITE_IO] = "write IO error",
60 [FAULT_SLAB_ALLOC] = "slab alloc",
61 [FAULT_DQUOT_INIT] = "dquot initialize",
62 [FAULT_LOCK_OP] = "lock_op",
63};
64
65void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
66 unsigned int type)
67{
68 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
69
70 if (rate) {

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

252 vaf.fmt = printk_skip_level(fmt);
253 vaf.va = &args;
254 printk("%c%cF2FS-fs (%s): %pV\n",
255 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf);
256
257 va_end(args);
258}
259
62};
63
64void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
65 unsigned int type)
66{
67 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
68
69 if (rate) {

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

251 vaf.fmt = printk_skip_level(fmt);
252 vaf.va = &args;
253 printk("%c%cF2FS-fs (%s): %pV\n",
254 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf);
255
256 va_end(args);
257}
258
260#ifdef CONFIG_UNICODE
259#if IS_ENABLED(CONFIG_UNICODE)
261static const struct f2fs_sb_encodings {
262 __u16 magic;
263 char *name;
264 unsigned int version;
265} f2fs_sb_encoding_map[] = {
266 {F2FS_ENC_UTF8_12_1, "utf8", UNICODE_AGE(12, 1, 0)},
267};
268

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

317 make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
318 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
319 from_kuid_munged(&init_user_ns,
320 F2FS_OPTION(sbi).s_resuid),
321 from_kgid_munged(&init_user_ns,
322 F2FS_OPTION(sbi).s_resgid));
323}
324
260static const struct f2fs_sb_encodings {
261 __u16 magic;
262 char *name;
263 unsigned int version;
264} f2fs_sb_encoding_map[] = {
265 {F2FS_ENC_UTF8_12_1, "utf8", UNICODE_AGE(12, 1, 0)},
266};
267

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

316 make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
317 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
318 from_kuid_munged(&init_user_ns,
319 F2FS_OPTION(sbi).s_resuid),
320 from_kgid_munged(&init_user_ns,
321 F2FS_OPTION(sbi).s_resgid));
322}
323
325static inline int adjust_reserved_segment(struct f2fs_sb_info *sbi)
326{
327 unsigned int sec_blks = sbi->blocks_per_seg * sbi->segs_per_sec;
328 unsigned int avg_vblocks;
329 unsigned int wanted_reserved_segments;
330 block_t avail_user_block_count;
331
332 if (!F2FS_IO_ALIGNED(sbi))
333 return 0;
334
335 /* average valid block count in section in worst case */
336 avg_vblocks = sec_blks / F2FS_IO_SIZE(sbi);
337
338 /*
339 * we need enough free space when migrating one section in worst case
340 */
341 wanted_reserved_segments = (F2FS_IO_SIZE(sbi) / avg_vblocks) *
342 reserved_segments(sbi);
343 wanted_reserved_segments -= reserved_segments(sbi);
344
345 avail_user_block_count = sbi->user_block_count -
346 sbi->current_reserved_blocks -
347 F2FS_OPTION(sbi).root_reserved_blocks;
348
349 if (wanted_reserved_segments * sbi->blocks_per_seg >
350 avail_user_block_count) {
351 f2fs_err(sbi, "IO align feature can't grab additional reserved segment: %u, available segments: %u",
352 wanted_reserved_segments,
353 avail_user_block_count >> sbi->log_blocks_per_seg);
354 return -ENOSPC;
355 }
356
357 SM_I(sbi)->additional_reserved_segments = wanted_reserved_segments;
358
359 f2fs_info(sbi, "IO align feature needs additional reserved segment: %u",
360 wanted_reserved_segments);
361
362 return 0;
363}
364
365static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi)
366{
367 if (!F2FS_OPTION(sbi).unusable_cap_perc)
368 return;
369
370 if (F2FS_OPTION(sbi).unusable_cap_perc == 100)
371 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count;
372 else

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

1254 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1255 return -EINVAL;
1256 }
1257 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) {
1258 f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1259 return -EINVAL;
1260 }
1261#endif
324static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi)
325{
326 if (!F2FS_OPTION(sbi).unusable_cap_perc)
327 return;
328
329 if (F2FS_OPTION(sbi).unusable_cap_perc == 100)
330 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count;
331 else

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

1213 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1214 return -EINVAL;
1215 }
1216 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) {
1217 f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1218 return -EINVAL;
1219 }
1220#endif
1262#ifndef CONFIG_UNICODE
1221#if !IS_ENABLED(CONFIG_UNICODE)
1263 if (f2fs_sb_has_casefold(sbi)) {
1264 f2fs_err(sbi,
1265 "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE");
1266 return -EINVAL;
1267 }
1268#endif
1269 /*
1270 * The BLKZONED feature indicates that the drive was formatted with

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

1614 for (i = 0; i < MAXQUOTAS; i++)
1615 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
1616#endif
1617 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
1618 destroy_percpu_info(sbi);
1619 f2fs_destroy_iostat(sbi);
1620 for (i = 0; i < NR_PAGE_TYPE; i++)
1621 kvfree(sbi->write_io[i]);
1222 if (f2fs_sb_has_casefold(sbi)) {
1223 f2fs_err(sbi,
1224 "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE");
1225 return -EINVAL;
1226 }
1227#endif
1228 /*
1229 * The BLKZONED feature indicates that the drive was formatted with

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

1573 for (i = 0; i < MAXQUOTAS; i++)
1574 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
1575#endif
1576 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
1577 destroy_percpu_info(sbi);
1578 f2fs_destroy_iostat(sbi);
1579 for (i = 0; i < NR_PAGE_TYPE; i++)
1580 kvfree(sbi->write_io[i]);
1622#ifdef CONFIG_UNICODE
1581#if IS_ENABLED(CONFIG_UNICODE)
1623 utf8_unload(sb->s_encoding);
1624#endif
1625 kfree(sbi);
1626}
1627
1628int f2fs_sync_fs(struct super_block *sb, int sync)
1629{
1630 struct f2fs_sb_info *sbi = F2FS_SB(sb);

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

3576 sbi->cur_victim_sec = NULL_SECNO;
3577 sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
3578 sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
3579 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
3580 sbi->migration_granularity = sbi->segs_per_sec;
3581 sbi->seq_file_ra_mul = MIN_RA_MUL;
3582 sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE;
3583 sbi->max_fragment_hole = DEF_FRAGMENT_SIZE;
1582 utf8_unload(sb->s_encoding);
1583#endif
1584 kfree(sbi);
1585}
1586
1587int f2fs_sync_fs(struct super_block *sb, int sync)
1588{
1589 struct f2fs_sb_info *sbi = F2FS_SB(sb);

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

3535 sbi->cur_victim_sec = NULL_SECNO;
3536 sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
3537 sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
3538 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
3539 sbi->migration_granularity = sbi->segs_per_sec;
3540 sbi->seq_file_ra_mul = MIN_RA_MUL;
3541 sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE;
3542 sbi->max_fragment_hole = DEF_FRAGMENT_SIZE;
3584 spin_lock_init(&sbi->gc_urgent_high_lock);
3585
3586 sbi->dir_level = DEF_DIR_LEVEL;
3587 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL;
3588 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL;
3589 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL;
3590 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL;
3591 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL;
3592 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] =

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

3898 }
3899 f2fs_info(sbi,
3900 "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi));
3901 return 0;
3902}
3903
3904static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
3905{
3543
3544 sbi->dir_level = DEF_DIR_LEVEL;
3545 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL;
3546 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL;
3547 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL;
3548 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL;
3549 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL;
3550 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] =

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

3856 }
3857 f2fs_info(sbi,
3858 "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi));
3859 return 0;
3860}
3861
3862static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
3863{
3906#ifdef CONFIG_UNICODE
3864#if IS_ENABLED(CONFIG_UNICODE)
3907 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) {
3908 const struct f2fs_sb_encodings *encoding_info;
3909 struct unicode_map *encoding;
3910 __u16 encoding_flags;
3911
3912 encoding_info = f2fs_sb_read_encoding(sbi->raw_super);
3913 if (!encoding_info) {
3914 f2fs_err(sbi,

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

4216 }
4217 err = f2fs_build_node_manager(sbi);
4218 if (err) {
4219 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)",
4220 err);
4221 goto free_nm;
4222 }
4223
3865 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) {
3866 const struct f2fs_sb_encodings *encoding_info;
3867 struct unicode_map *encoding;
3868 __u16 encoding_flags;
3869
3870 encoding_info = f2fs_sb_read_encoding(sbi->raw_super);
3871 if (!encoding_info) {
3872 f2fs_err(sbi,

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

4174 }
4175 err = f2fs_build_node_manager(sbi);
4176 if (err) {
4177 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)",
4178 err);
4179 goto free_nm;
4180 }
4181
4224 err = adjust_reserved_segment(sbi);
4225 if (err)
4226 goto free_nm;
4227
4228 /* For write statistics */
4229 sbi->sectors_written_start = f2fs_get_sectors_written(sbi);
4230
4231 /* Read accumulated write IO statistics if exists */
4232 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
4233 if (__exist_node_summaries(sbi))
4234 sbi->kbytes_written =
4235 le64_to_cpu(seg_i->journal->info.kbytes_written);

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

4453free_percpu:
4454 destroy_percpu_info(sbi);
4455free_iostat:
4456 f2fs_destroy_iostat(sbi);
4457free_bio_info:
4458 for (i = 0; i < NR_PAGE_TYPE; i++)
4459 kvfree(sbi->write_io[i]);
4460
4182 /* For write statistics */
4183 sbi->sectors_written_start = f2fs_get_sectors_written(sbi);
4184
4185 /* Read accumulated write IO statistics if exists */
4186 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
4187 if (__exist_node_summaries(sbi))
4188 sbi->kbytes_written =
4189 le64_to_cpu(seg_i->journal->info.kbytes_written);

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

4407free_percpu:
4408 destroy_percpu_info(sbi);
4409free_iostat:
4410 f2fs_destroy_iostat(sbi);
4411free_bio_info:
4412 for (i = 0; i < NR_PAGE_TYPE; i++)
4413 kvfree(sbi->write_io[i]);
4414
4461#ifdef CONFIG_UNICODE
4415#if IS_ENABLED(CONFIG_UNICODE)
4462 utf8_unload(sb->s_encoding);
4463 sb->s_encoding = NULL;
4464#endif
4465free_options:
4466#ifdef CONFIG_QUOTA
4467 for (i = 0; i < MAXQUOTAS; i++)
4468 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
4469#endif

--- 215 unchanged lines hidden ---
4416 utf8_unload(sb->s_encoding);
4417 sb->s_encoding = NULL;
4418#endif
4419free_options:
4420#ifdef CONFIG_QUOTA
4421 for (i = 0; i < MAXQUOTAS; i++)
4422 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
4423#endif

--- 215 unchanged lines hidden ---