Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 1 | /* |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2 | * fs/f2fs/super.c |
| 3 | * |
| 4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com/ |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/fs.h> |
| 14 | #include <linux/statfs.h> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 15 | #include <linux/buffer_head.h> |
| 16 | #include <linux/backing-dev.h> |
| 17 | #include <linux/kthread.h> |
| 18 | #include <linux/parser.h> |
| 19 | #include <linux/mount.h> |
| 20 | #include <linux/seq_file.h> |
Jaegeuk Kim | 5e176d5 | 2013-06-28 12:47:01 +0900 | [diff] [blame] | 21 | #include <linux/proc_fs.h> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 22 | #include <linux/random.h> |
| 23 | #include <linux/exportfs.h> |
Namjae Jeon | d3ee456 | 2013-03-17 17:26:14 +0900 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 25 | #include <linux/quotaops.h> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 26 | #include <linux/f2fs_fs.h> |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 27 | #include <linux/sysfs.h> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 28 | |
| 29 | #include "f2fs.h" |
| 30 | #include "node.h" |
Jaegeuk Kim | 5ec4e49 | 2013-03-31 13:26:03 +0900 | [diff] [blame] | 31 | #include "segment.h" |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 32 | #include "xattr.h" |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 33 | #include "gc.h" |
Jaegeuk Kim | db9f7c1 | 2014-12-17 20:04:08 -0800 | [diff] [blame] | 34 | #include "trace.h" |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 35 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 36 | #define CREATE_TRACE_POINTS |
| 37 | #include <trace/events/f2fs.h> |
| 38 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 39 | static struct kmem_cache *f2fs_inode_cachep; |
| 40 | |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 41 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 42 | |
| 43 | char *fault_name[FAULT_MAX] = { |
| 44 | [FAULT_KMALLOC] = "kmalloc", |
Jaegeuk Kim | c41f3cc3 | 2016-04-29 16:17:09 -0700 | [diff] [blame] | 45 | [FAULT_PAGE_ALLOC] = "page alloc", |
Jaegeuk Kim | cb78942 | 2016-04-29 16:29:22 -0700 | [diff] [blame] | 46 | [FAULT_ALLOC_NID] = "alloc nid", |
| 47 | [FAULT_ORPHAN] = "orphan", |
| 48 | [FAULT_BLOCK] = "no more block", |
| 49 | [FAULT_DIR_DEPTH] = "too big dir depth", |
Jaegeuk Kim | 53aa6bb | 2016-05-25 15:24:18 -0700 | [diff] [blame] | 50 | [FAULT_EVICT_INODE] = "evict_inode fail", |
Jaegeuk Kim | 14b44d2 | 2017-03-09 15:24:24 -0800 | [diff] [blame] | 51 | [FAULT_TRUNCATE] = "truncate fail", |
Chao Yu | 8b038c7 | 2016-09-18 23:30:07 +0800 | [diff] [blame] | 52 | [FAULT_IO] = "IO error", |
Chao Yu | 0f34802 | 2016-09-26 19:45:55 +0800 | [diff] [blame] | 53 | [FAULT_CHECKPOINT] = "checkpoint error", |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 54 | }; |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 55 | |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 56 | static void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, |
| 57 | unsigned int rate) |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 58 | { |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 59 | struct f2fs_fault_info *ffi = &sbi->fault_info; |
| 60 | |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 61 | if (rate) { |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 62 | atomic_set(&ffi->inject_ops, 0); |
| 63 | ffi->inject_rate = rate; |
| 64 | ffi->inject_type = (1 << FAULT_MAX) - 1; |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 65 | } else { |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 66 | memset(ffi, 0, sizeof(struct f2fs_fault_info)); |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 67 | } |
| 68 | } |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 69 | #endif |
| 70 | |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 71 | /* f2fs-wide shrinker description */ |
| 72 | static struct shrinker f2fs_shrinker_info = { |
| 73 | .scan_objects = f2fs_shrink_scan, |
| 74 | .count_objects = f2fs_shrink_count, |
| 75 | .seeks = DEFAULT_SEEKS, |
| 76 | }; |
| 77 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 78 | enum { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 79 | Opt_gc_background, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 80 | Opt_disable_roll_forward, |
Jaegeuk Kim | 2d834bf | 2015-01-23 18:33:46 -0800 | [diff] [blame] | 81 | Opt_norecovery, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 82 | Opt_discard, |
Chao Yu | 64058be | 2016-07-03 22:05:14 +0800 | [diff] [blame] | 83 | Opt_nodiscard, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 84 | Opt_noheap, |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 85 | Opt_heap, |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 86 | Opt_user_xattr, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 87 | Opt_nouser_xattr, |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 88 | Opt_acl, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 89 | Opt_noacl, |
| 90 | Opt_active_logs, |
| 91 | Opt_disable_ext_identify, |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 92 | Opt_inline_xattr, |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 93 | Opt_noinline_xattr, |
Huajun Li | 8274de7 | 2013-11-10 23:13:17 +0800 | [diff] [blame] | 94 | Opt_inline_data, |
Chao Yu | 5efd3c6 | 2014-09-24 18:16:13 +0800 | [diff] [blame] | 95 | Opt_inline_dentry, |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 96 | Opt_noinline_dentry, |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 97 | Opt_flush_merge, |
Jaegeuk Kim | 69e9e42 | 2016-05-20 22:39:20 -0700 | [diff] [blame] | 98 | Opt_noflush_merge, |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 99 | Opt_nobarrier, |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 100 | Opt_fastboot, |
Chao Yu | 8967215 | 2015-02-05 17:55:51 +0800 | [diff] [blame] | 101 | Opt_extent_cache, |
Jaegeuk Kim | 7daaea2 | 2015-06-25 17:43:04 -0700 | [diff] [blame] | 102 | Opt_noextent_cache, |
Wanpeng Li | 7534279 | 2015-03-24 10:20:27 +0800 | [diff] [blame] | 103 | Opt_noinline_data, |
Chao Yu | 343f40f | 2015-12-16 13:12:16 +0800 | [diff] [blame] | 104 | Opt_data_flush, |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 105 | Opt_mode, |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 106 | Opt_io_size_bits, |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 107 | Opt_fault_injection, |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 108 | Opt_lazytime, |
| 109 | Opt_nolazytime, |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 110 | Opt_usrquota, |
| 111 | Opt_grpquota, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 112 | Opt_err, |
| 113 | }; |
| 114 | |
| 115 | static match_table_t f2fs_tokens = { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 116 | {Opt_gc_background, "background_gc=%s"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 117 | {Opt_disable_roll_forward, "disable_roll_forward"}, |
Jaegeuk Kim | 2d834bf | 2015-01-23 18:33:46 -0800 | [diff] [blame] | 118 | {Opt_norecovery, "norecovery"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 119 | {Opt_discard, "discard"}, |
Chao Yu | 64058be | 2016-07-03 22:05:14 +0800 | [diff] [blame] | 120 | {Opt_nodiscard, "nodiscard"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 121 | {Opt_noheap, "no_heap"}, |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 122 | {Opt_heap, "heap"}, |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 123 | {Opt_user_xattr, "user_xattr"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 124 | {Opt_nouser_xattr, "nouser_xattr"}, |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 125 | {Opt_acl, "acl"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 126 | {Opt_noacl, "noacl"}, |
| 127 | {Opt_active_logs, "active_logs=%u"}, |
| 128 | {Opt_disable_ext_identify, "disable_ext_identify"}, |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 129 | {Opt_inline_xattr, "inline_xattr"}, |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 130 | {Opt_noinline_xattr, "noinline_xattr"}, |
Huajun Li | 8274de7 | 2013-11-10 23:13:17 +0800 | [diff] [blame] | 131 | {Opt_inline_data, "inline_data"}, |
Chao Yu | 5efd3c6 | 2014-09-24 18:16:13 +0800 | [diff] [blame] | 132 | {Opt_inline_dentry, "inline_dentry"}, |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 133 | {Opt_noinline_dentry, "noinline_dentry"}, |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 134 | {Opt_flush_merge, "flush_merge"}, |
Jaegeuk Kim | 69e9e42 | 2016-05-20 22:39:20 -0700 | [diff] [blame] | 135 | {Opt_noflush_merge, "noflush_merge"}, |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 136 | {Opt_nobarrier, "nobarrier"}, |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 137 | {Opt_fastboot, "fastboot"}, |
Chao Yu | 8967215 | 2015-02-05 17:55:51 +0800 | [diff] [blame] | 138 | {Opt_extent_cache, "extent_cache"}, |
Jaegeuk Kim | 7daaea2 | 2015-06-25 17:43:04 -0700 | [diff] [blame] | 139 | {Opt_noextent_cache, "noextent_cache"}, |
Wanpeng Li | 7534279 | 2015-03-24 10:20:27 +0800 | [diff] [blame] | 140 | {Opt_noinline_data, "noinline_data"}, |
Chao Yu | 343f40f | 2015-12-16 13:12:16 +0800 | [diff] [blame] | 141 | {Opt_data_flush, "data_flush"}, |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 142 | {Opt_mode, "mode=%s"}, |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 143 | {Opt_io_size_bits, "io_bits=%u"}, |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 144 | {Opt_fault_injection, "fault_injection=%u"}, |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 145 | {Opt_lazytime, "lazytime"}, |
| 146 | {Opt_nolazytime, "nolazytime"}, |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 147 | {Opt_usrquota, "usrquota"}, |
| 148 | {Opt_grpquota, "grpquota"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 149 | {Opt_err, NULL}, |
| 150 | }; |
| 151 | |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 152 | void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...) |
| 153 | { |
| 154 | struct va_format vaf; |
| 155 | va_list args; |
| 156 | |
| 157 | va_start(args, fmt); |
| 158 | vaf.fmt = fmt; |
| 159 | vaf.va = &args; |
| 160 | printk("%sF2FS-fs (%s): %pV\n", level, sb->s_id, &vaf); |
| 161 | va_end(args); |
| 162 | } |
| 163 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 164 | static void init_once(void *foo) |
| 165 | { |
| 166 | struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; |
| 167 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 168 | inode_init_once(&fi->vfs_inode); |
| 169 | } |
| 170 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 171 | static int parse_options(struct super_block *sb, char *options) |
| 172 | { |
| 173 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Chao Yu | 09d54cd | 2015-06-08 13:20:10 +0800 | [diff] [blame] | 174 | struct request_queue *q; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 175 | substring_t args[MAX_OPT_ARGS]; |
| 176 | char *p, *name; |
| 177 | int arg = 0; |
| 178 | |
| 179 | if (!options) |
| 180 | return 0; |
| 181 | |
| 182 | while ((p = strsep(&options, ",")) != NULL) { |
| 183 | int token; |
| 184 | if (!*p) |
| 185 | continue; |
| 186 | /* |
| 187 | * Initialize args struct so we know whether arg was |
| 188 | * found; some options take optional arguments. |
| 189 | */ |
| 190 | args[0].to = args[0].from = NULL; |
| 191 | token = match_token(p, f2fs_tokens, args); |
| 192 | |
| 193 | switch (token) { |
| 194 | case Opt_gc_background: |
| 195 | name = match_strdup(&args[0]); |
| 196 | |
| 197 | if (!name) |
| 198 | return -ENOMEM; |
Jaegeuk Kim | 6aefd93 | 2015-10-05 11:02:54 -0700 | [diff] [blame] | 199 | if (strlen(name) == 2 && !strncmp(name, "on", 2)) { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 200 | set_opt(sbi, BG_GC); |
Jaegeuk Kim | 6aefd93 | 2015-10-05 11:02:54 -0700 | [diff] [blame] | 201 | clear_opt(sbi, FORCE_FG_GC); |
| 202 | } else if (strlen(name) == 3 && !strncmp(name, "off", 3)) { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 203 | clear_opt(sbi, BG_GC); |
Jaegeuk Kim | 6aefd93 | 2015-10-05 11:02:54 -0700 | [diff] [blame] | 204 | clear_opt(sbi, FORCE_FG_GC); |
| 205 | } else if (strlen(name) == 4 && !strncmp(name, "sync", 4)) { |
| 206 | set_opt(sbi, BG_GC); |
| 207 | set_opt(sbi, FORCE_FG_GC); |
| 208 | } else { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 209 | kfree(name); |
| 210 | return -EINVAL; |
| 211 | } |
| 212 | kfree(name); |
| 213 | break; |
| 214 | case Opt_disable_roll_forward: |
| 215 | set_opt(sbi, DISABLE_ROLL_FORWARD); |
| 216 | break; |
Jaegeuk Kim | 2d834bf | 2015-01-23 18:33:46 -0800 | [diff] [blame] | 217 | case Opt_norecovery: |
| 218 | /* this option mounts f2fs with ro */ |
| 219 | set_opt(sbi, DISABLE_ROLL_FORWARD); |
| 220 | if (!f2fs_readonly(sb)) |
| 221 | return -EINVAL; |
| 222 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 223 | case Opt_discard: |
Chao Yu | 09d54cd | 2015-06-08 13:20:10 +0800 | [diff] [blame] | 224 | q = bdev_get_queue(sb->s_bdev); |
| 225 | if (blk_queue_discard(q)) { |
| 226 | set_opt(sbi, DISCARD); |
Damien Le Moal | 0ab0299 | 2016-10-28 17:45:02 +0900 | [diff] [blame] | 227 | } else if (!f2fs_sb_mounted_blkzoned(sb)) { |
Chao Yu | 09d54cd | 2015-06-08 13:20:10 +0800 | [diff] [blame] | 228 | f2fs_msg(sb, KERN_WARNING, |
| 229 | "mounting with \"discard\" option, but " |
| 230 | "the device does not support discard"); |
| 231 | } |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 232 | break; |
Chao Yu | 64058be | 2016-07-03 22:05:14 +0800 | [diff] [blame] | 233 | case Opt_nodiscard: |
Damien Le Moal | 96ba2de | 2016-10-28 17:45:03 +0900 | [diff] [blame] | 234 | if (f2fs_sb_mounted_blkzoned(sb)) { |
| 235 | f2fs_msg(sb, KERN_WARNING, |
| 236 | "discard is required for zoned block devices"); |
| 237 | return -EINVAL; |
| 238 | } |
Chao Yu | 64058be | 2016-07-03 22:05:14 +0800 | [diff] [blame] | 239 | clear_opt(sbi, DISCARD); |
Damien Le Moal | 487df61 | 2016-10-28 17:44:59 +0900 | [diff] [blame] | 240 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 241 | case Opt_noheap: |
| 242 | set_opt(sbi, NOHEAP); |
| 243 | break; |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 244 | case Opt_heap: |
| 245 | clear_opt(sbi, NOHEAP); |
| 246 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 247 | #ifdef CONFIG_F2FS_FS_XATTR |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 248 | case Opt_user_xattr: |
| 249 | set_opt(sbi, XATTR_USER); |
| 250 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 251 | case Opt_nouser_xattr: |
| 252 | clear_opt(sbi, XATTR_USER); |
| 253 | break; |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 254 | case Opt_inline_xattr: |
| 255 | set_opt(sbi, INLINE_XATTR); |
| 256 | break; |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 257 | case Opt_noinline_xattr: |
| 258 | clear_opt(sbi, INLINE_XATTR); |
| 259 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 260 | #else |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 261 | case Opt_user_xattr: |
| 262 | f2fs_msg(sb, KERN_INFO, |
| 263 | "user_xattr options not supported"); |
| 264 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 265 | case Opt_nouser_xattr: |
| 266 | f2fs_msg(sb, KERN_INFO, |
| 267 | "nouser_xattr options not supported"); |
| 268 | break; |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 269 | case Opt_inline_xattr: |
| 270 | f2fs_msg(sb, KERN_INFO, |
| 271 | "inline_xattr options not supported"); |
| 272 | break; |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 273 | case Opt_noinline_xattr: |
| 274 | f2fs_msg(sb, KERN_INFO, |
| 275 | "noinline_xattr options not supported"); |
| 276 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 277 | #endif |
| 278 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 279 | case Opt_acl: |
| 280 | set_opt(sbi, POSIX_ACL); |
| 281 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 282 | case Opt_noacl: |
| 283 | clear_opt(sbi, POSIX_ACL); |
| 284 | break; |
| 285 | #else |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 286 | case Opt_acl: |
| 287 | f2fs_msg(sb, KERN_INFO, "acl options not supported"); |
| 288 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 289 | case Opt_noacl: |
| 290 | f2fs_msg(sb, KERN_INFO, "noacl options not supported"); |
| 291 | break; |
| 292 | #endif |
| 293 | case Opt_active_logs: |
| 294 | if (args->from && match_int(args, &arg)) |
| 295 | return -EINVAL; |
| 296 | if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE) |
| 297 | return -EINVAL; |
| 298 | sbi->active_logs = arg; |
| 299 | break; |
| 300 | case Opt_disable_ext_identify: |
| 301 | set_opt(sbi, DISABLE_EXT_IDENTIFY); |
| 302 | break; |
Huajun Li | 8274de7 | 2013-11-10 23:13:17 +0800 | [diff] [blame] | 303 | case Opt_inline_data: |
| 304 | set_opt(sbi, INLINE_DATA); |
| 305 | break; |
Chao Yu | 5efd3c6 | 2014-09-24 18:16:13 +0800 | [diff] [blame] | 306 | case Opt_inline_dentry: |
| 307 | set_opt(sbi, INLINE_DENTRY); |
| 308 | break; |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 309 | case Opt_noinline_dentry: |
| 310 | clear_opt(sbi, INLINE_DENTRY); |
| 311 | break; |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 312 | case Opt_flush_merge: |
| 313 | set_opt(sbi, FLUSH_MERGE); |
| 314 | break; |
Jaegeuk Kim | 69e9e42 | 2016-05-20 22:39:20 -0700 | [diff] [blame] | 315 | case Opt_noflush_merge: |
| 316 | clear_opt(sbi, FLUSH_MERGE); |
| 317 | break; |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 318 | case Opt_nobarrier: |
| 319 | set_opt(sbi, NOBARRIER); |
| 320 | break; |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 321 | case Opt_fastboot: |
| 322 | set_opt(sbi, FASTBOOT); |
| 323 | break; |
Chao Yu | 8967215 | 2015-02-05 17:55:51 +0800 | [diff] [blame] | 324 | case Opt_extent_cache: |
| 325 | set_opt(sbi, EXTENT_CACHE); |
| 326 | break; |
Jaegeuk Kim | 7daaea2 | 2015-06-25 17:43:04 -0700 | [diff] [blame] | 327 | case Opt_noextent_cache: |
| 328 | clear_opt(sbi, EXTENT_CACHE); |
| 329 | break; |
Wanpeng Li | 7534279 | 2015-03-24 10:20:27 +0800 | [diff] [blame] | 330 | case Opt_noinline_data: |
| 331 | clear_opt(sbi, INLINE_DATA); |
| 332 | break; |
Chao Yu | 343f40f | 2015-12-16 13:12:16 +0800 | [diff] [blame] | 333 | case Opt_data_flush: |
| 334 | set_opt(sbi, DATA_FLUSH); |
| 335 | break; |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 336 | case Opt_mode: |
| 337 | name = match_strdup(&args[0]); |
| 338 | |
| 339 | if (!name) |
| 340 | return -ENOMEM; |
| 341 | if (strlen(name) == 8 && |
| 342 | !strncmp(name, "adaptive", 8)) { |
Damien Le Moal | 3adc57e | 2016-10-28 17:45:04 +0900 | [diff] [blame] | 343 | if (f2fs_sb_mounted_blkzoned(sb)) { |
| 344 | f2fs_msg(sb, KERN_WARNING, |
| 345 | "adaptive mode is not allowed with " |
| 346 | "zoned block device feature"); |
| 347 | kfree(name); |
| 348 | return -EINVAL; |
| 349 | } |
Jaegeuk Kim | 52763a4 | 2016-06-13 09:47:48 -0700 | [diff] [blame] | 350 | set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE); |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 351 | } else if (strlen(name) == 3 && |
| 352 | !strncmp(name, "lfs", 3)) { |
Jaegeuk Kim | 52763a4 | 2016-06-13 09:47:48 -0700 | [diff] [blame] | 353 | set_opt_mode(sbi, F2FS_MOUNT_LFS); |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 354 | } else { |
| 355 | kfree(name); |
| 356 | return -EINVAL; |
| 357 | } |
| 358 | kfree(name); |
| 359 | break; |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 360 | case Opt_io_size_bits: |
| 361 | if (args->from && match_int(args, &arg)) |
| 362 | return -EINVAL; |
| 363 | if (arg > __ilog2_u32(BIO_MAX_PAGES)) { |
| 364 | f2fs_msg(sb, KERN_WARNING, |
| 365 | "Not support %d, larger than %d", |
| 366 | 1 << arg, BIO_MAX_PAGES); |
| 367 | return -EINVAL; |
| 368 | } |
| 369 | sbi->write_io_size_bits = arg; |
| 370 | break; |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 371 | case Opt_fault_injection: |
| 372 | if (args->from && match_int(args, &arg)) |
| 373 | return -EINVAL; |
| 374 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 375 | f2fs_build_fault_attr(sbi, arg); |
Kaixu Xia | 0cc0dec | 2017-01-27 09:35:37 +0800 | [diff] [blame] | 376 | set_opt(sbi, FAULT_INJECTION); |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 377 | #else |
| 378 | f2fs_msg(sb, KERN_INFO, |
| 379 | "FAULT_INJECTION was not selected"); |
| 380 | #endif |
| 381 | break; |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 382 | case Opt_lazytime: |
| 383 | sb->s_flags |= MS_LAZYTIME; |
| 384 | break; |
| 385 | case Opt_nolazytime: |
| 386 | sb->s_flags &= ~MS_LAZYTIME; |
| 387 | break; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 388 | #ifdef CONFIG_QUOTA |
| 389 | case Opt_usrquota: |
| 390 | set_opt(sbi, USRQUOTA); |
| 391 | break; |
| 392 | case Opt_grpquota: |
| 393 | set_opt(sbi, GRPQUOTA); |
| 394 | break; |
| 395 | #else |
| 396 | case Opt_usrquota: |
| 397 | case Opt_grpquota: |
| 398 | f2fs_msg(sb, KERN_INFO, |
| 399 | "quota operations not supported"); |
| 400 | break; |
| 401 | #endif |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 402 | default: |
| 403 | f2fs_msg(sb, KERN_ERR, |
| 404 | "Unrecognized mount option \"%s\" or missing value", |
| 405 | p); |
| 406 | return -EINVAL; |
| 407 | } |
| 408 | } |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 409 | |
| 410 | if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) { |
| 411 | f2fs_msg(sb, KERN_ERR, |
| 412 | "Should set mode=lfs with %uKB-sized IO", |
| 413 | F2FS_IO_SIZE_KB(sbi)); |
| 414 | return -EINVAL; |
| 415 | } |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 419 | static struct inode *f2fs_alloc_inode(struct super_block *sb) |
| 420 | { |
| 421 | struct f2fs_inode_info *fi; |
| 422 | |
Chao Yu | a0acdfe | 2013-12-05 09:54:00 +0800 | [diff] [blame] | 423 | fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_F2FS_ZERO); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 424 | if (!fi) |
| 425 | return NULL; |
| 426 | |
| 427 | init_once((void *) fi); |
| 428 | |
Masanari Iida | 434720f | 2013-03-19 08:03:35 +0900 | [diff] [blame] | 429 | /* Initialize f2fs-specific inode info */ |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 430 | fi->vfs_inode.i_version = 1; |
Jaegeuk Kim | 204706c | 2016-12-02 15:11:32 -0800 | [diff] [blame] | 431 | atomic_set(&fi->dirty_pages, 0); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 432 | fi->i_current_depth = 1; |
| 433 | fi->i_advise = 0; |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 434 | init_rwsem(&fi->i_sem); |
Chao Yu | 2710fd7 | 2015-12-15 13:30:45 +0800 | [diff] [blame] | 435 | INIT_LIST_HEAD(&fi->dirty_list); |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 436 | INIT_LIST_HEAD(&fi->gdirty_list); |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 437 | INIT_LIST_HEAD(&fi->inmem_pages); |
| 438 | mutex_init(&fi->inmem_lock); |
Chao Yu | 82e0a5a | 2016-07-13 09:18:29 +0800 | [diff] [blame] | 439 | init_rwsem(&fi->dio_rwsem[READ]); |
| 440 | init_rwsem(&fi->dio_rwsem[WRITE]); |
Qiuyang Sun | 5a3a2d8 | 2017-05-18 11:06:45 +0800 | [diff] [blame] | 441 | init_rwsem(&fi->i_mmap_sem); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 442 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 443 | #ifdef CONFIG_QUOTA |
| 444 | memset(&fi->i_dquot, 0, sizeof(fi->i_dquot)); |
| 445 | fi->i_reserved_quota = 0; |
| 446 | #endif |
Jaegeuk Kim | ab9fa66 | 2014-02-27 20:09:05 +0900 | [diff] [blame] | 447 | /* Will be used by directory only */ |
| 448 | fi->i_dir_level = F2FS_SB(sb)->dir_level; |
Chao Yu | f247037 | 2017-07-19 00:19:05 +0800 | [diff] [blame^] | 449 | |
| 450 | fi->i_inline_reserved = DEF_INLINE_RESERVED_SIZE; |
| 451 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 452 | return &fi->vfs_inode; |
| 453 | } |
| 454 | |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 455 | static int f2fs_drop_inode(struct inode *inode) |
| 456 | { |
Hou Pengyang | b8d96a3 | 2017-02-27 13:02:58 +0000 | [diff] [blame] | 457 | int ret; |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 458 | /* |
| 459 | * This is to avoid a deadlock condition like below. |
| 460 | * writeback_single_inode(inode) |
| 461 | * - f2fs_write_data_page |
| 462 | * - f2fs_gc -> iput -> evict |
| 463 | * - inode_wait_for_writeback(inode) |
| 464 | */ |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 465 | if ((!inode_unhashed(inode) && inode->i_state & I_SYNC)) { |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 466 | if (!inode->i_nlink && !is_bad_inode(inode)) { |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 467 | /* to avoid evict_inode call simultaneously */ |
| 468 | atomic_inc(&inode->i_count); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 469 | spin_unlock(&inode->i_lock); |
| 470 | |
| 471 | /* some remained atomic pages should discarded */ |
| 472 | if (f2fs_is_atomic_file(inode)) |
Chao Yu | 29b96b5 | 2016-02-06 14:38:29 +0800 | [diff] [blame] | 473 | drop_inmem_pages(inode); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 474 | |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 475 | /* should remain fi->extent_tree for writepage */ |
| 476 | f2fs_destroy_extent_node(inode); |
| 477 | |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 478 | sb_start_intwrite(inode->i_sb); |
Jaegeuk Kim | fc9581c | 2016-05-20 09:22:03 -0700 | [diff] [blame] | 479 | f2fs_i_size_write(inode, 0); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 480 | |
| 481 | if (F2FS_HAS_BLOCKS(inode)) |
Jaegeuk Kim | 9a449e9 | 2016-06-02 13:49:38 -0700 | [diff] [blame] | 482 | f2fs_truncate(inode); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 483 | |
| 484 | sb_end_intwrite(inode->i_sb); |
| 485 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 486 | fscrypt_put_encryption_info(inode, NULL); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 487 | spin_lock(&inode->i_lock); |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 488 | atomic_dec(&inode->i_count); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 489 | } |
Hou Pengyang | b8d96a3 | 2017-02-27 13:02:58 +0000 | [diff] [blame] | 490 | trace_f2fs_drop_inode(inode, 0); |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 491 | return 0; |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 492 | } |
Hou Pengyang | b8d96a3 | 2017-02-27 13:02:58 +0000 | [diff] [blame] | 493 | ret = generic_drop_inode(inode); |
| 494 | trace_f2fs_drop_inode(inode, ret); |
| 495 | return ret; |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 496 | } |
| 497 | |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 498 | int f2fs_inode_dirtied(struct inode *inode, bool sync) |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 499 | { |
| 500 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 501 | int ret = 0; |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 502 | |
| 503 | spin_lock(&sbi->inode_lock[DIRTY_META]); |
| 504 | if (is_inode_flag_set(inode, FI_DIRTY_INODE)) { |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 505 | ret = 1; |
| 506 | } else { |
| 507 | set_inode_flag(inode, FI_DIRTY_INODE); |
| 508 | stat_inc_dirty_inode(sbi, DIRTY_META); |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 509 | } |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 510 | if (sync && list_empty(&F2FS_I(inode)->gdirty_list)) { |
| 511 | list_add_tail(&F2FS_I(inode)->gdirty_list, |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 512 | &sbi->inode_list[DIRTY_META]); |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 513 | inc_page_count(sbi, F2FS_DIRTY_IMETA); |
| 514 | } |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 515 | spin_unlock(&sbi->inode_lock[DIRTY_META]); |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 516 | return ret; |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | void f2fs_inode_synced(struct inode *inode) |
| 520 | { |
| 521 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 522 | |
| 523 | spin_lock(&sbi->inode_lock[DIRTY_META]); |
| 524 | if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) { |
| 525 | spin_unlock(&sbi->inode_lock[DIRTY_META]); |
| 526 | return; |
| 527 | } |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 528 | if (!list_empty(&F2FS_I(inode)->gdirty_list)) { |
| 529 | list_del_init(&F2FS_I(inode)->gdirty_list); |
| 530 | dec_page_count(sbi, F2FS_DIRTY_IMETA); |
| 531 | } |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 532 | clear_inode_flag(inode, FI_DIRTY_INODE); |
| 533 | clear_inode_flag(inode, FI_AUTO_RECOVER); |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 534 | stat_dec_dirty_inode(F2FS_I_SB(inode), DIRTY_META); |
| 535 | spin_unlock(&sbi->inode_lock[DIRTY_META]); |
| 536 | } |
| 537 | |
Jaegeuk Kim | b378387 | 2013-06-10 09:17:01 +0900 | [diff] [blame] | 538 | /* |
| 539 | * f2fs_dirty_inode() is called from __mark_inode_dirty() |
| 540 | * |
| 541 | * We should call set_dirty_inode to write the dirty inode through write_inode. |
| 542 | */ |
| 543 | static void f2fs_dirty_inode(struct inode *inode, int flags) |
| 544 | { |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 545 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 546 | |
| 547 | if (inode->i_ino == F2FS_NODE_INO(sbi) || |
| 548 | inode->i_ino == F2FS_META_INO(sbi)) |
| 549 | return; |
| 550 | |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 551 | if (flags == I_DIRTY_TIME) |
| 552 | return; |
| 553 | |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 554 | if (is_inode_flag_set(inode, FI_AUTO_RECOVER)) |
| 555 | clear_inode_flag(inode, FI_AUTO_RECOVER); |
| 556 | |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 557 | f2fs_inode_dirtied(inode, false); |
Jaegeuk Kim | b378387 | 2013-06-10 09:17:01 +0900 | [diff] [blame] | 558 | } |
| 559 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 560 | static void f2fs_i_callback(struct rcu_head *head) |
| 561 | { |
| 562 | struct inode *inode = container_of(head, struct inode, i_rcu); |
| 563 | kmem_cache_free(f2fs_inode_cachep, F2FS_I(inode)); |
| 564 | } |
| 565 | |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 566 | static void f2fs_destroy_inode(struct inode *inode) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 567 | { |
| 568 | call_rcu(&inode->i_rcu, f2fs_i_callback); |
| 569 | } |
| 570 | |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 571 | static void destroy_percpu_info(struct f2fs_sb_info *sbi) |
| 572 | { |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 573 | percpu_counter_destroy(&sbi->alloc_valid_block_count); |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 574 | percpu_counter_destroy(&sbi->total_valid_inode_count); |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 577 | static void destroy_device_list(struct f2fs_sb_info *sbi) |
| 578 | { |
| 579 | int i; |
| 580 | |
| 581 | for (i = 0; i < sbi->s_ndevs; i++) { |
| 582 | blkdev_put(FDEV(i).bdev, FMODE_EXCL); |
| 583 | #ifdef CONFIG_BLK_DEV_ZONED |
| 584 | kfree(FDEV(i).blkz_type); |
| 585 | #endif |
| 586 | } |
| 587 | kfree(sbi->devs); |
| 588 | } |
| 589 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 590 | static void f2fs_quota_off_umount(struct super_block *sb); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 591 | static void f2fs_put_super(struct super_block *sb) |
| 592 | { |
| 593 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 594 | int i; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 595 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 596 | f2fs_quota_off_umount(sb); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 597 | |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 598 | /* prevent remaining shrinker jobs */ |
| 599 | mutex_lock(&sbi->umount_mutex); |
| 600 | |
Jaegeuk Kim | 85dc2f2 | 2015-01-14 17:41:41 -0800 | [diff] [blame] | 601 | /* |
| 602 | * We don't need to do checkpoint when superblock is clean. |
| 603 | * But, the previous checkpoint was not done by umount, it needs to do |
| 604 | * clean checkpoint again. |
| 605 | */ |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 606 | if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) || |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 607 | !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { |
Jaegeuk Kim | 75ab4cb | 2014-09-20 21:57:51 -0700 | [diff] [blame] | 608 | struct cp_control cpc = { |
| 609 | .reason = CP_UMOUNT, |
| 610 | }; |
| 611 | write_checkpoint(sbi, &cpc); |
| 612 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 613 | |
Jaegeuk Kim | 4e6a8d9 | 2016-12-29 14:07:53 -0800 | [diff] [blame] | 614 | /* be sure to wait for any on-going discard commands */ |
Chao Yu | d431413 | 2017-04-05 18:19:49 +0800 | [diff] [blame] | 615 | f2fs_wait_discard_bios(sbi); |
Jaegeuk Kim | 4e6a8d9 | 2016-12-29 14:07:53 -0800 | [diff] [blame] | 616 | |
Chao Yu | 663f387 | 2017-06-14 23:00:55 +0800 | [diff] [blame] | 617 | if (f2fs_discard_en(sbi) && !sbi->discard_blks) { |
Chao Yu | 1f43e2a | 2017-04-28 13:56:08 +0800 | [diff] [blame] | 618 | struct cp_control cpc = { |
| 619 | .reason = CP_UMOUNT | CP_TRIMMED, |
| 620 | }; |
| 621 | write_checkpoint(sbi, &cpc); |
| 622 | } |
| 623 | |
Jaegeuk Kim | eca616f | 2015-06-15 14:52:29 -0700 | [diff] [blame] | 624 | /* write_checkpoint can update stat informaion */ |
| 625 | f2fs_destroy_stats(sbi); |
| 626 | |
Jaegeuk Kim | cf779ca | 2014-08-11 18:37:46 -0700 | [diff] [blame] | 627 | /* |
| 628 | * normally superblock is clean, so we need to release this. |
| 629 | * In addition, EIO will skip do checkpoint, we need this as well. |
| 630 | */ |
Jaegeuk Kim | 74ef924 | 2016-05-02 22:09:56 -0700 | [diff] [blame] | 631 | release_ino_entry(sbi, true); |
Jaegeuk Kim | 6f12ac2 | 2014-08-19 09:48:22 -0700 | [diff] [blame] | 632 | |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 633 | f2fs_leave_shrinker(sbi); |
| 634 | mutex_unlock(&sbi->umount_mutex); |
| 635 | |
Jaegeuk Kim | 17c1912 | 2016-01-29 08:57:59 -0800 | [diff] [blame] | 636 | /* our cp_error case, we can wait for any writeback page */ |
Jaegeuk Kim | b9109b0 | 2017-05-10 11:28:38 -0700 | [diff] [blame] | 637 | f2fs_flush_merged_writes(sbi); |
Jaegeuk Kim | 17c1912 | 2016-01-29 08:57:59 -0800 | [diff] [blame] | 638 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 639 | iput(sbi->node_inode); |
| 640 | iput(sbi->meta_inode); |
| 641 | |
| 642 | /* destroy f2fs internal modules */ |
| 643 | destroy_node_manager(sbi); |
| 644 | destroy_segment_manager(sbi); |
| 645 | |
| 646 | kfree(sbi->ckpt); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 647 | |
| 648 | f2fs_exit_sysfs(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 649 | |
| 650 | sb->s_fs_info = NULL; |
Keith Mok | 43b6573 | 2016-03-02 12:04:24 -0800 | [diff] [blame] | 651 | if (sbi->s_chksum_driver) |
| 652 | crypto_free_shash(sbi->s_chksum_driver); |
Yunlei He | b39f0de | 2015-12-15 17:17:20 +0800 | [diff] [blame] | 653 | kfree(sbi->raw_super); |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 654 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 655 | destroy_device_list(sbi); |
Chao Yu | b6895e8 | 2017-02-27 18:43:12 +0800 | [diff] [blame] | 656 | mempool_destroy(sbi->write_io_dummy); |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 657 | destroy_percpu_info(sbi); |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 658 | for (i = 0; i < NR_PAGE_TYPE; i++) |
| 659 | kfree(sbi->write_io[i]); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 660 | kfree(sbi); |
| 661 | } |
| 662 | |
| 663 | int f2fs_sync_fs(struct super_block *sb, int sync) |
| 664 | { |
| 665 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Chao Yu | c34f42e | 2015-12-23 17:50:30 +0800 | [diff] [blame] | 666 | int err = 0; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 667 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 668 | trace_f2fs_sync_fs(sb, sync); |
| 669 | |
Jaegeuk Kim | b747375 | 2013-04-01 08:32:21 +0900 | [diff] [blame] | 670 | if (sync) { |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 671 | struct cp_control cpc; |
| 672 | |
Jaegeuk Kim | 119ee91 | 2015-01-29 11:45:33 -0800 | [diff] [blame] | 673 | cpc.reason = __get_cp_reason(sbi); |
| 674 | |
Jaegeuk Kim | b747375 | 2013-04-01 08:32:21 +0900 | [diff] [blame] | 675 | mutex_lock(&sbi->gc_mutex); |
Chao Yu | c34f42e | 2015-12-23 17:50:30 +0800 | [diff] [blame] | 676 | err = write_checkpoint(sbi, &cpc); |
Jaegeuk Kim | b747375 | 2013-04-01 08:32:21 +0900 | [diff] [blame] | 677 | mutex_unlock(&sbi->gc_mutex); |
Jaegeuk Kim | b747375 | 2013-04-01 08:32:21 +0900 | [diff] [blame] | 678 | } |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 679 | f2fs_trace_ios(NULL, 1); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 680 | |
Chao Yu | c34f42e | 2015-12-23 17:50:30 +0800 | [diff] [blame] | 681 | return err; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 682 | } |
| 683 | |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 684 | static int f2fs_freeze(struct super_block *sb) |
| 685 | { |
Jaegeuk Kim | 77888c1 | 2013-05-20 20:28:47 +0900 | [diff] [blame] | 686 | if (f2fs_readonly(sb)) |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 687 | return 0; |
| 688 | |
Jaegeuk Kim | b4b9d34 | 2016-11-04 14:59:15 -0700 | [diff] [blame] | 689 | /* IO error happened before */ |
| 690 | if (unlikely(f2fs_cp_error(F2FS_SB(sb)))) |
| 691 | return -EIO; |
| 692 | |
| 693 | /* must be clean, since sync_filesystem() was already called */ |
| 694 | if (is_sbi_flag_set(F2FS_SB(sb), SBI_IS_DIRTY)) |
| 695 | return -EINVAL; |
| 696 | return 0; |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | static int f2fs_unfreeze(struct super_block *sb) |
| 700 | { |
| 701 | return 0; |
| 702 | } |
| 703 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 704 | static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 705 | { |
| 706 | struct super_block *sb = dentry->d_sb; |
| 707 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 708 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); |
| 709 | block_t total_count, user_block_count, start_count, ovp_count; |
Jaegeuk Kim | 0cc091d | 2017-06-21 20:55:55 -0700 | [diff] [blame] | 710 | u64 avail_node_count; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 711 | |
| 712 | total_count = le64_to_cpu(sbi->raw_super->block_count); |
| 713 | user_block_count = sbi->user_block_count; |
| 714 | start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); |
| 715 | ovp_count = SM_I(sbi)->ovp_segments << sbi->log_blocks_per_seg; |
| 716 | buf->f_type = F2FS_SUPER_MAGIC; |
| 717 | buf->f_bsize = sbi->blocksize; |
| 718 | |
| 719 | buf->f_blocks = total_count - start_count; |
Chao Yu | 3e6d0b4 | 2016-07-06 14:13:07 +0800 | [diff] [blame] | 720 | buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count; |
Chao Yu | daeb433 | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 721 | buf->f_bavail = user_block_count - valid_user_blocks(sbi) - |
| 722 | sbi->reserved_blocks; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 723 | |
Jaegeuk Kim | 0cc091d | 2017-06-21 20:55:55 -0700 | [diff] [blame] | 724 | avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; |
| 725 | |
| 726 | if (avail_node_count > user_block_count) { |
| 727 | buf->f_files = user_block_count; |
| 728 | buf->f_ffree = buf->f_bavail; |
| 729 | } else { |
| 730 | buf->f_files = avail_node_count; |
| 731 | buf->f_ffree = min(avail_node_count - valid_node_count(sbi), |
| 732 | buf->f_bavail); |
| 733 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 734 | |
Jaegeuk Kim | 5a20d33 | 2013-03-03 13:58:05 +0900 | [diff] [blame] | 735 | buf->f_namelen = F2FS_NAME_LEN; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 736 | buf->f_fsid.val[0] = (u32)id; |
| 737 | buf->f_fsid.val[1] = (u32)(id >> 32); |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | static int f2fs_show_options(struct seq_file *seq, struct dentry *root) |
| 743 | { |
| 744 | struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); |
| 745 | |
Jaegeuk Kim | 6aefd93 | 2015-10-05 11:02:54 -0700 | [diff] [blame] | 746 | if (!f2fs_readonly(sbi->sb) && test_opt(sbi, BG_GC)) { |
| 747 | if (test_opt(sbi, FORCE_FG_GC)) |
| 748 | seq_printf(seq, ",background_gc=%s", "sync"); |
| 749 | else |
| 750 | seq_printf(seq, ",background_gc=%s", "on"); |
| 751 | } else { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 752 | seq_printf(seq, ",background_gc=%s", "off"); |
Jaegeuk Kim | 6aefd93 | 2015-10-05 11:02:54 -0700 | [diff] [blame] | 753 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 754 | if (test_opt(sbi, DISABLE_ROLL_FORWARD)) |
| 755 | seq_puts(seq, ",disable_roll_forward"); |
| 756 | if (test_opt(sbi, DISCARD)) |
| 757 | seq_puts(seq, ",discard"); |
| 758 | if (test_opt(sbi, NOHEAP)) |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 759 | seq_puts(seq, ",no_heap"); |
| 760 | else |
| 761 | seq_puts(seq, ",heap"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 762 | #ifdef CONFIG_F2FS_FS_XATTR |
| 763 | if (test_opt(sbi, XATTR_USER)) |
| 764 | seq_puts(seq, ",user_xattr"); |
| 765 | else |
| 766 | seq_puts(seq, ",nouser_xattr"); |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 767 | if (test_opt(sbi, INLINE_XATTR)) |
| 768 | seq_puts(seq, ",inline_xattr"); |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 769 | else |
| 770 | seq_puts(seq, ",noinline_xattr"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 771 | #endif |
| 772 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
| 773 | if (test_opt(sbi, POSIX_ACL)) |
| 774 | seq_puts(seq, ",acl"); |
| 775 | else |
| 776 | seq_puts(seq, ",noacl"); |
| 777 | #endif |
| 778 | if (test_opt(sbi, DISABLE_EXT_IDENTIFY)) |
Alejandro Martinez Ruiz | aa43507 | 2013-01-25 19:08:59 +0100 | [diff] [blame] | 779 | seq_puts(seq, ",disable_ext_identify"); |
Huajun Li | 8274de7 | 2013-11-10 23:13:17 +0800 | [diff] [blame] | 780 | if (test_opt(sbi, INLINE_DATA)) |
| 781 | seq_puts(seq, ",inline_data"); |
Wanpeng Li | 7534279 | 2015-03-24 10:20:27 +0800 | [diff] [blame] | 782 | else |
| 783 | seq_puts(seq, ",noinline_data"); |
Chao Yu | 5efd3c6 | 2014-09-24 18:16:13 +0800 | [diff] [blame] | 784 | if (test_opt(sbi, INLINE_DENTRY)) |
| 785 | seq_puts(seq, ",inline_dentry"); |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 786 | else |
| 787 | seq_puts(seq, ",noinline_dentry"); |
Gu Zheng | b270ad6 | 2014-04-11 17:49:55 +0800 | [diff] [blame] | 788 | if (!f2fs_readonly(sbi->sb) && test_opt(sbi, FLUSH_MERGE)) |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 789 | seq_puts(seq, ",flush_merge"); |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 790 | if (test_opt(sbi, NOBARRIER)) |
| 791 | seq_puts(seq, ",nobarrier"); |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 792 | if (test_opt(sbi, FASTBOOT)) |
| 793 | seq_puts(seq, ",fastboot"); |
Chao Yu | 8967215 | 2015-02-05 17:55:51 +0800 | [diff] [blame] | 794 | if (test_opt(sbi, EXTENT_CACHE)) |
| 795 | seq_puts(seq, ",extent_cache"); |
Jaegeuk Kim | 7daaea2 | 2015-06-25 17:43:04 -0700 | [diff] [blame] | 796 | else |
| 797 | seq_puts(seq, ",noextent_cache"); |
Chao Yu | 343f40f | 2015-12-16 13:12:16 +0800 | [diff] [blame] | 798 | if (test_opt(sbi, DATA_FLUSH)) |
| 799 | seq_puts(seq, ",data_flush"); |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 800 | |
| 801 | seq_puts(seq, ",mode="); |
| 802 | if (test_opt(sbi, ADAPTIVE)) |
| 803 | seq_puts(seq, "adaptive"); |
| 804 | else if (test_opt(sbi, LFS)) |
| 805 | seq_puts(seq, "lfs"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 806 | seq_printf(seq, ",active_logs=%u", sbi->active_logs); |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 807 | if (F2FS_IO_SIZE_BITS(sbi)) |
| 808 | seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi)); |
Kaixu Xia | 0cc0dec | 2017-01-27 09:35:37 +0800 | [diff] [blame] | 809 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 810 | if (test_opt(sbi, FAULT_INJECTION)) |
Chao Yu | 44529f8 | 2017-06-12 09:44:24 +0800 | [diff] [blame] | 811 | seq_printf(seq, ",fault_injection=%u", |
| 812 | sbi->fault_info.inject_rate); |
Kaixu Xia | 0cc0dec | 2017-01-27 09:35:37 +0800 | [diff] [blame] | 813 | #endif |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 814 | #ifdef CONFIG_QUOTA |
| 815 | if (test_opt(sbi, USRQUOTA)) |
| 816 | seq_puts(seq, ",usrquota"); |
| 817 | if (test_opt(sbi, GRPQUOTA)) |
| 818 | seq_puts(seq, ",grpquota"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 819 | #endif |
| 820 | |
| 821 | return 0; |
| 822 | } |
| 823 | |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 824 | static void default_options(struct f2fs_sb_info *sbi) |
| 825 | { |
| 826 | /* init some FS parameters */ |
| 827 | sbi->active_logs = NR_CURSEG_TYPE; |
| 828 | |
| 829 | set_opt(sbi, BG_GC); |
Chao Yu | 39133a5 | 2017-02-08 17:39:44 +0800 | [diff] [blame] | 830 | set_opt(sbi, INLINE_XATTR); |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 831 | set_opt(sbi, INLINE_DATA); |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 832 | set_opt(sbi, INLINE_DENTRY); |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 833 | set_opt(sbi, EXTENT_CACHE); |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 834 | set_opt(sbi, NOHEAP); |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 835 | sbi->sb->s_flags |= MS_LAZYTIME; |
Jaegeuk Kim | 69e9e42 | 2016-05-20 22:39:20 -0700 | [diff] [blame] | 836 | set_opt(sbi, FLUSH_MERGE); |
Damien Le Moal | 0bfd7a0 | 2016-10-28 17:45:00 +0900 | [diff] [blame] | 837 | if (f2fs_sb_mounted_blkzoned(sbi->sb)) { |
Jaegeuk Kim | 52763a4 | 2016-06-13 09:47:48 -0700 | [diff] [blame] | 838 | set_opt_mode(sbi, F2FS_MOUNT_LFS); |
| 839 | set_opt(sbi, DISCARD); |
| 840 | } else { |
| 841 | set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE); |
| 842 | } |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 843 | |
| 844 | #ifdef CONFIG_F2FS_FS_XATTR |
| 845 | set_opt(sbi, XATTR_USER); |
| 846 | #endif |
| 847 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
| 848 | set_opt(sbi, POSIX_ACL); |
| 849 | #endif |
Chao Yu | 36dbd32 | 2016-09-26 19:45:05 +0800 | [diff] [blame] | 850 | |
| 851 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 852 | f2fs_build_fault_attr(sbi, 0); |
| 853 | #endif |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 854 | } |
| 855 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 856 | static int f2fs_remount(struct super_block *sb, int *flags, char *data) |
| 857 | { |
| 858 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 859 | struct f2fs_mount_info org_mount_opt; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 860 | unsigned long old_sb_flags; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 861 | int err, active_logs; |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 862 | bool need_restart_gc = false; |
| 863 | bool need_stop_gc = false; |
Chao Yu | 9cd81ce | 2015-09-18 16:55:26 +0800 | [diff] [blame] | 864 | bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE); |
Chao Yu | 2443b8b | 2016-09-26 19:45:06 +0800 | [diff] [blame] | 865 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 866 | struct f2fs_fault_info ffi = sbi->fault_info; |
| 867 | #endif |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 868 | |
| 869 | /* |
| 870 | * Save the old mount options in case we |
| 871 | * need to restore them. |
| 872 | */ |
| 873 | org_mount_opt = sbi->mount_opt; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 874 | old_sb_flags = sb->s_flags; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 875 | active_logs = sbi->active_logs; |
| 876 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 877 | /* recover superblocks we couldn't write due to previous RO mount */ |
| 878 | if (!(*flags & MS_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) { |
| 879 | err = f2fs_commit_super(sbi, false); |
| 880 | f2fs_msg(sb, KERN_INFO, |
| 881 | "Try to recover all the superblocks, ret: %d", err); |
| 882 | if (!err) |
| 883 | clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); |
| 884 | } |
| 885 | |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 886 | default_options(sbi); |
Chao Yu | 26666c8 | 2014-09-15 18:04:44 +0800 | [diff] [blame] | 887 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 888 | /* parse mount options */ |
| 889 | err = parse_options(sb, data); |
| 890 | if (err) |
| 891 | goto restore_opts; |
| 892 | |
| 893 | /* |
| 894 | * Previous and new state of filesystem is RO, |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 895 | * so skip checking GC and FLUSH_MERGE conditions. |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 896 | */ |
Chao Yu | 6b2920a | 2014-07-07 11:21:59 +0800 | [diff] [blame] | 897 | if (f2fs_readonly(sb) && (*flags & MS_RDONLY)) |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 898 | goto skip; |
| 899 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 900 | if (!f2fs_readonly(sb) && (*flags & MS_RDONLY)) { |
| 901 | err = dquot_suspend(sb, -1); |
| 902 | if (err < 0) |
| 903 | goto restore_opts; |
| 904 | } else { |
| 905 | /* dquot_resume needs RW */ |
| 906 | sb->s_flags &= ~MS_RDONLY; |
| 907 | dquot_resume(sb, -1); |
| 908 | } |
| 909 | |
Chao Yu | 9cd81ce | 2015-09-18 16:55:26 +0800 | [diff] [blame] | 910 | /* disallow enable/disable extent_cache dynamically */ |
| 911 | if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) { |
| 912 | err = -EINVAL; |
| 913 | f2fs_msg(sbi->sb, KERN_WARNING, |
| 914 | "switch extent_cache option is not allowed"); |
| 915 | goto restore_opts; |
| 916 | } |
| 917 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 918 | /* |
| 919 | * We stop the GC thread if FS is mounted as RO |
| 920 | * or if background_gc = off is passed in mount |
| 921 | * option. Also sync the filesystem. |
| 922 | */ |
| 923 | if ((*flags & MS_RDONLY) || !test_opt(sbi, BG_GC)) { |
| 924 | if (sbi->gc_thread) { |
| 925 | stop_gc_thread(sbi); |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 926 | need_restart_gc = true; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 927 | } |
Chao Yu | aba291b | 2014-11-18 11:17:20 +0800 | [diff] [blame] | 928 | } else if (!sbi->gc_thread) { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 929 | err = start_gc_thread(sbi); |
| 930 | if (err) |
| 931 | goto restore_opts; |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 932 | need_stop_gc = true; |
| 933 | } |
| 934 | |
Jaegeuk Kim | faa0e55 | 2016-03-24 10:29:39 -0700 | [diff] [blame] | 935 | if (*flags & MS_RDONLY) { |
| 936 | writeback_inodes_sb(sb, WB_REASON_SYNC); |
| 937 | sync_inodes_sb(sb); |
| 938 | |
| 939 | set_sbi_flag(sbi, SBI_IS_DIRTY); |
| 940 | set_sbi_flag(sbi, SBI_IS_CLOSE); |
| 941 | f2fs_sync_fs(sb, 1); |
| 942 | clear_sbi_flag(sbi, SBI_IS_CLOSE); |
| 943 | } |
| 944 | |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 945 | /* |
| 946 | * We stop issue flush thread if FS is mounted as RO |
| 947 | * or if flush_merge is not passed in mount option. |
| 948 | */ |
| 949 | if ((*flags & MS_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { |
Jaegeuk Kim | 5eba8c5 | 2016-12-07 16:23:32 -0800 | [diff] [blame] | 950 | clear_opt(sbi, FLUSH_MERGE); |
| 951 | destroy_flush_cmd_control(sbi, false); |
| 952 | } else { |
Gu Zheng | 2163d19 | 2014-04-27 14:21:33 +0800 | [diff] [blame] | 953 | err = create_flush_cmd_control(sbi); |
| 954 | if (err) |
Gu Zheng | a688b9d9e | 2014-04-27 14:21:21 +0800 | [diff] [blame] | 955 | goto restore_gc; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 956 | } |
| 957 | skip: |
| 958 | /* Update the POSIXACL Flag */ |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 959 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 960 | (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0); |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 961 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 962 | return 0; |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 963 | restore_gc: |
| 964 | if (need_restart_gc) { |
| 965 | if (start_gc_thread(sbi)) |
| 966 | f2fs_msg(sbi->sb, KERN_WARNING, |
arter97 | e1c4204 | 2014-08-06 23:22:50 +0900 | [diff] [blame] | 967 | "background gc thread has stopped"); |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 968 | } else if (need_stop_gc) { |
| 969 | stop_gc_thread(sbi); |
| 970 | } |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 971 | restore_opts: |
| 972 | sbi->mount_opt = org_mount_opt; |
| 973 | sbi->active_logs = active_logs; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 974 | sb->s_flags = old_sb_flags; |
Chao Yu | 2443b8b | 2016-09-26 19:45:06 +0800 | [diff] [blame] | 975 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 976 | sbi->fault_info = ffi; |
| 977 | #endif |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 978 | return err; |
| 979 | } |
| 980 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 981 | #ifdef CONFIG_QUOTA |
| 982 | /* Read data from quotafile */ |
| 983 | static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data, |
| 984 | size_t len, loff_t off) |
| 985 | { |
| 986 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 987 | struct address_space *mapping = inode->i_mapping; |
| 988 | block_t blkidx = F2FS_BYTES_TO_BLK(off); |
| 989 | int offset = off & (sb->s_blocksize - 1); |
| 990 | int tocopy; |
| 991 | size_t toread; |
| 992 | loff_t i_size = i_size_read(inode); |
| 993 | struct page *page; |
| 994 | char *kaddr; |
| 995 | |
| 996 | if (off > i_size) |
| 997 | return 0; |
| 998 | |
| 999 | if (off + len > i_size) |
| 1000 | len = i_size - off; |
| 1001 | toread = len; |
| 1002 | while (toread > 0) { |
| 1003 | tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread); |
| 1004 | repeat: |
| 1005 | page = read_mapping_page(mapping, blkidx, NULL); |
| 1006 | if (IS_ERR(page)) |
| 1007 | return PTR_ERR(page); |
| 1008 | |
| 1009 | lock_page(page); |
| 1010 | |
| 1011 | if (unlikely(page->mapping != mapping)) { |
| 1012 | f2fs_put_page(page, 1); |
| 1013 | goto repeat; |
| 1014 | } |
| 1015 | if (unlikely(!PageUptodate(page))) { |
| 1016 | f2fs_put_page(page, 1); |
| 1017 | return -EIO; |
| 1018 | } |
| 1019 | |
| 1020 | kaddr = kmap_atomic(page); |
| 1021 | memcpy(data, kaddr + offset, tocopy); |
| 1022 | kunmap_atomic(kaddr); |
| 1023 | f2fs_put_page(page, 1); |
| 1024 | |
| 1025 | offset = 0; |
| 1026 | toread -= tocopy; |
| 1027 | data += tocopy; |
| 1028 | blkidx++; |
| 1029 | } |
| 1030 | return len; |
| 1031 | } |
| 1032 | |
| 1033 | /* Write to quotafile */ |
| 1034 | static ssize_t f2fs_quota_write(struct super_block *sb, int type, |
| 1035 | const char *data, size_t len, loff_t off) |
| 1036 | { |
| 1037 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 1038 | struct address_space *mapping = inode->i_mapping; |
| 1039 | const struct address_space_operations *a_ops = mapping->a_ops; |
| 1040 | int offset = off & (sb->s_blocksize - 1); |
| 1041 | size_t towrite = len; |
| 1042 | struct page *page; |
| 1043 | char *kaddr; |
| 1044 | int err = 0; |
| 1045 | int tocopy; |
| 1046 | |
| 1047 | while (towrite > 0) { |
| 1048 | tocopy = min_t(unsigned long, sb->s_blocksize - offset, |
| 1049 | towrite); |
| 1050 | |
| 1051 | err = a_ops->write_begin(NULL, mapping, off, tocopy, 0, |
| 1052 | &page, NULL); |
| 1053 | if (unlikely(err)) |
| 1054 | break; |
| 1055 | |
| 1056 | kaddr = kmap_atomic(page); |
| 1057 | memcpy(kaddr + offset, data, tocopy); |
| 1058 | kunmap_atomic(kaddr); |
| 1059 | flush_dcache_page(page); |
| 1060 | |
| 1061 | a_ops->write_end(NULL, mapping, off, tocopy, tocopy, |
| 1062 | page, NULL); |
| 1063 | offset = 0; |
| 1064 | towrite -= tocopy; |
| 1065 | off += tocopy; |
| 1066 | data += tocopy; |
| 1067 | cond_resched(); |
| 1068 | } |
| 1069 | |
| 1070 | if (len == towrite) |
| 1071 | return err; |
| 1072 | inode->i_version++; |
| 1073 | inode->i_mtime = inode->i_ctime = current_time(inode); |
| 1074 | f2fs_mark_inode_dirty_sync(inode, false); |
| 1075 | return len - towrite; |
| 1076 | } |
| 1077 | |
| 1078 | static struct dquot **f2fs_get_dquots(struct inode *inode) |
| 1079 | { |
| 1080 | return F2FS_I(inode)->i_dquot; |
| 1081 | } |
| 1082 | |
| 1083 | static qsize_t *f2fs_get_reserved_space(struct inode *inode) |
| 1084 | { |
| 1085 | return &F2FS_I(inode)->i_reserved_quota; |
| 1086 | } |
| 1087 | |
| 1088 | static int f2fs_quota_sync(struct super_block *sb, int type) |
| 1089 | { |
| 1090 | struct quota_info *dqopt = sb_dqopt(sb); |
| 1091 | int cnt; |
| 1092 | int ret; |
| 1093 | |
| 1094 | ret = dquot_writeback_dquots(sb, type); |
| 1095 | if (ret) |
| 1096 | return ret; |
| 1097 | |
| 1098 | /* |
| 1099 | * Now when everything is written we can discard the pagecache so |
| 1100 | * that userspace sees the changes. |
| 1101 | */ |
| 1102 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
| 1103 | if (type != -1 && cnt != type) |
| 1104 | continue; |
| 1105 | if (!sb_has_quota_active(sb, cnt)) |
| 1106 | continue; |
| 1107 | |
| 1108 | ret = filemap_write_and_wait(dqopt->files[cnt]->i_mapping); |
| 1109 | if (ret) |
| 1110 | return ret; |
| 1111 | |
| 1112 | inode_lock(dqopt->files[cnt]); |
| 1113 | truncate_inode_pages(&dqopt->files[cnt]->i_data, 0); |
| 1114 | inode_unlock(dqopt->files[cnt]); |
| 1115 | } |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
| 1119 | static int f2fs_quota_on(struct super_block *sb, int type, int format_id, |
| 1120 | const struct path *path) |
| 1121 | { |
| 1122 | struct inode *inode; |
| 1123 | int err; |
| 1124 | |
| 1125 | err = f2fs_quota_sync(sb, -1); |
| 1126 | if (err) |
| 1127 | return err; |
| 1128 | |
| 1129 | err = dquot_quota_on(sb, type, format_id, path); |
| 1130 | if (err) |
| 1131 | return err; |
| 1132 | |
| 1133 | inode = d_inode(path->dentry); |
| 1134 | |
| 1135 | inode_lock(inode); |
| 1136 | F2FS_I(inode)->i_flags |= FS_NOATIME_FL | FS_IMMUTABLE_FL; |
| 1137 | inode_set_flags(inode, S_NOATIME | S_IMMUTABLE, |
| 1138 | S_NOATIME | S_IMMUTABLE); |
| 1139 | inode_unlock(inode); |
| 1140 | f2fs_mark_inode_dirty_sync(inode, false); |
| 1141 | |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | static int f2fs_quota_off(struct super_block *sb, int type) |
| 1146 | { |
| 1147 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 1148 | int err; |
| 1149 | |
| 1150 | if (!inode || !igrab(inode)) |
| 1151 | return dquot_quota_off(sb, type); |
| 1152 | |
| 1153 | f2fs_quota_sync(sb, -1); |
| 1154 | |
| 1155 | err = dquot_quota_off(sb, type); |
| 1156 | if (err) |
| 1157 | goto out_put; |
| 1158 | |
| 1159 | inode_lock(inode); |
| 1160 | F2FS_I(inode)->i_flags &= ~(FS_NOATIME_FL | FS_IMMUTABLE_FL); |
| 1161 | inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE); |
| 1162 | inode_unlock(inode); |
| 1163 | f2fs_mark_inode_dirty_sync(inode, false); |
| 1164 | out_put: |
| 1165 | iput(inode); |
| 1166 | return err; |
| 1167 | } |
| 1168 | |
| 1169 | static void f2fs_quota_off_umount(struct super_block *sb) |
| 1170 | { |
| 1171 | int type; |
| 1172 | |
| 1173 | for (type = 0; type < MAXQUOTAS; type++) |
| 1174 | f2fs_quota_off(sb, type); |
| 1175 | } |
| 1176 | |
| 1177 | static const struct dquot_operations f2fs_quota_operations = { |
| 1178 | .get_reserved_space = f2fs_get_reserved_space, |
| 1179 | .write_dquot = dquot_commit, |
| 1180 | .acquire_dquot = dquot_acquire, |
| 1181 | .release_dquot = dquot_release, |
| 1182 | .mark_dirty = dquot_mark_dquot_dirty, |
| 1183 | .write_info = dquot_commit_info, |
| 1184 | .alloc_dquot = dquot_alloc, |
| 1185 | .destroy_dquot = dquot_destroy, |
| 1186 | .get_next_id = dquot_get_next_id, |
| 1187 | }; |
| 1188 | |
| 1189 | static const struct quotactl_ops f2fs_quotactl_ops = { |
| 1190 | .quota_on = f2fs_quota_on, |
| 1191 | .quota_off = f2fs_quota_off, |
| 1192 | .quota_sync = f2fs_quota_sync, |
| 1193 | .get_state = dquot_get_state, |
| 1194 | .set_info = dquot_set_dqinfo, |
| 1195 | .get_dqblk = dquot_get_dqblk, |
| 1196 | .set_dqblk = dquot_set_dqblk, |
| 1197 | .get_nextdqblk = dquot_get_next_dqblk, |
| 1198 | }; |
| 1199 | #else |
| 1200 | static inline void f2fs_quota_off_umount(struct super_block *sb) |
| 1201 | { |
| 1202 | } |
| 1203 | #endif |
| 1204 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1205 | static struct super_operations f2fs_sops = { |
| 1206 | .alloc_inode = f2fs_alloc_inode, |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 1207 | .drop_inode = f2fs_drop_inode, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1208 | .destroy_inode = f2fs_destroy_inode, |
| 1209 | .write_inode = f2fs_write_inode, |
Jaegeuk Kim | b378387 | 2013-06-10 09:17:01 +0900 | [diff] [blame] | 1210 | .dirty_inode = f2fs_dirty_inode, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1211 | .show_options = f2fs_show_options, |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1212 | #ifdef CONFIG_QUOTA |
| 1213 | .quota_read = f2fs_quota_read, |
| 1214 | .quota_write = f2fs_quota_write, |
| 1215 | .get_dquots = f2fs_get_dquots, |
| 1216 | #endif |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1217 | .evict_inode = f2fs_evict_inode, |
| 1218 | .put_super = f2fs_put_super, |
| 1219 | .sync_fs = f2fs_sync_fs, |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 1220 | .freeze_fs = f2fs_freeze, |
| 1221 | .unfreeze_fs = f2fs_unfreeze, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1222 | .statfs = f2fs_statfs, |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 1223 | .remount_fs = f2fs_remount, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1224 | }; |
| 1225 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 1226 | #ifdef CONFIG_F2FS_FS_ENCRYPTION |
| 1227 | static int f2fs_get_context(struct inode *inode, void *ctx, size_t len) |
| 1228 | { |
| 1229 | return f2fs_getxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION, |
| 1230 | F2FS_XATTR_NAME_ENCRYPTION_CONTEXT, |
| 1231 | ctx, len, NULL); |
| 1232 | } |
| 1233 | |
| 1234 | static int f2fs_set_context(struct inode *inode, const void *ctx, size_t len, |
| 1235 | void *fs_data) |
| 1236 | { |
| 1237 | return f2fs_setxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION, |
| 1238 | F2FS_XATTR_NAME_ENCRYPTION_CONTEXT, |
| 1239 | ctx, len, fs_data, XATTR_CREATE); |
| 1240 | } |
| 1241 | |
| 1242 | static unsigned f2fs_max_namelen(struct inode *inode) |
| 1243 | { |
| 1244 | return S_ISLNK(inode->i_mode) ? |
| 1245 | inode->i_sb->s_blocksize : F2FS_NAME_LEN; |
| 1246 | } |
| 1247 | |
Eric Biggers | 6f69f0e | 2017-02-07 12:42:10 -0800 | [diff] [blame] | 1248 | static const struct fscrypt_operations f2fs_cryptops = { |
Eric Biggers | a5d431e | 2017-01-05 13:51:18 -0800 | [diff] [blame] | 1249 | .key_prefix = "f2fs:", |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 1250 | .get_context = f2fs_get_context, |
| 1251 | .set_context = f2fs_set_context, |
| 1252 | .is_encrypted = f2fs_encrypted_inode, |
| 1253 | .empty_dir = f2fs_empty_dir, |
| 1254 | .max_namelen = f2fs_max_namelen, |
| 1255 | }; |
| 1256 | #else |
Eric Biggers | 6f69f0e | 2017-02-07 12:42:10 -0800 | [diff] [blame] | 1257 | static const struct fscrypt_operations f2fs_cryptops = { |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 1258 | .is_encrypted = f2fs_encrypted_inode, |
| 1259 | }; |
| 1260 | #endif |
| 1261 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1262 | static struct inode *f2fs_nfs_get_inode(struct super_block *sb, |
| 1263 | u64 ino, u32 generation) |
| 1264 | { |
| 1265 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1266 | struct inode *inode; |
| 1267 | |
Chao Yu | d6b7d4b | 2014-06-12 13:23:41 +0800 | [diff] [blame] | 1268 | if (check_nid_range(sbi, ino)) |
Chao Yu | 910bb12 | 2014-03-12 17:08:36 +0800 | [diff] [blame] | 1269 | return ERR_PTR(-ESTALE); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1270 | |
| 1271 | /* |
| 1272 | * f2fs_iget isn't quite right if the inode is currently unallocated! |
| 1273 | * However f2fs_iget currently does appropriate checks to handle stale |
| 1274 | * inodes so everything is OK. |
| 1275 | */ |
| 1276 | inode = f2fs_iget(sb, ino); |
| 1277 | if (IS_ERR(inode)) |
| 1278 | return ERR_CAST(inode); |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 1279 | if (unlikely(generation && inode->i_generation != generation)) { |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1280 | /* we didn't find the right inode.. */ |
| 1281 | iput(inode); |
| 1282 | return ERR_PTR(-ESTALE); |
| 1283 | } |
| 1284 | return inode; |
| 1285 | } |
| 1286 | |
| 1287 | static struct dentry *f2fs_fh_to_dentry(struct super_block *sb, struct fid *fid, |
| 1288 | int fh_len, int fh_type) |
| 1289 | { |
| 1290 | return generic_fh_to_dentry(sb, fid, fh_len, fh_type, |
| 1291 | f2fs_nfs_get_inode); |
| 1292 | } |
| 1293 | |
| 1294 | static struct dentry *f2fs_fh_to_parent(struct super_block *sb, struct fid *fid, |
| 1295 | int fh_len, int fh_type) |
| 1296 | { |
| 1297 | return generic_fh_to_parent(sb, fid, fh_len, fh_type, |
| 1298 | f2fs_nfs_get_inode); |
| 1299 | } |
| 1300 | |
| 1301 | static const struct export_operations f2fs_export_ops = { |
| 1302 | .fh_to_dentry = f2fs_fh_to_dentry, |
| 1303 | .fh_to_parent = f2fs_fh_to_parent, |
| 1304 | .get_parent = f2fs_get_parent, |
| 1305 | }; |
| 1306 | |
Chao Yu | e0afc4d | 2015-12-31 14:35:37 +0800 | [diff] [blame] | 1307 | static loff_t max_file_blocks(void) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1308 | { |
Jaegeuk Kim | de93653 | 2013-08-12 21:08:03 +0900 | [diff] [blame] | 1309 | loff_t result = (DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1310 | loff_t leaf_count = ADDRS_PER_BLOCK; |
| 1311 | |
| 1312 | /* two direct node blocks */ |
| 1313 | result += (leaf_count * 2); |
| 1314 | |
| 1315 | /* two indirect node blocks */ |
| 1316 | leaf_count *= NIDS_PER_BLOCK; |
| 1317 | result += (leaf_count * 2); |
| 1318 | |
| 1319 | /* one double indirect node block */ |
| 1320 | leaf_count *= NIDS_PER_BLOCK; |
| 1321 | result += leaf_count; |
| 1322 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1323 | return result; |
| 1324 | } |
| 1325 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1326 | static int __f2fs_commit_super(struct buffer_head *bh, |
| 1327 | struct f2fs_super_block *super) |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1328 | { |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1329 | lock_buffer(bh); |
| 1330 | if (super) |
| 1331 | memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super)); |
| 1332 | set_buffer_uptodate(bh); |
| 1333 | set_buffer_dirty(bh); |
| 1334 | unlock_buffer(bh); |
| 1335 | |
| 1336 | /* it's rare case, we can do fua all the time */ |
Jan Kara | 3adc5fcb | 2017-05-02 17:03:47 +0200 | [diff] [blame] | 1337 | return __sync_dirty_buffer(bh, REQ_SYNC | REQ_PREFLUSH | REQ_FUA); |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1340 | static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1341 | struct buffer_head *bh) |
| 1342 | { |
| 1343 | struct f2fs_super_block *raw_super = (struct f2fs_super_block *) |
| 1344 | (bh->b_data + F2FS_SUPER_OFFSET); |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1345 | struct super_block *sb = sbi->sb; |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1346 | u32 segment0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr); |
| 1347 | u32 cp_blkaddr = le32_to_cpu(raw_super->cp_blkaddr); |
| 1348 | u32 sit_blkaddr = le32_to_cpu(raw_super->sit_blkaddr); |
| 1349 | u32 nat_blkaddr = le32_to_cpu(raw_super->nat_blkaddr); |
| 1350 | u32 ssa_blkaddr = le32_to_cpu(raw_super->ssa_blkaddr); |
| 1351 | u32 main_blkaddr = le32_to_cpu(raw_super->main_blkaddr); |
| 1352 | u32 segment_count_ckpt = le32_to_cpu(raw_super->segment_count_ckpt); |
| 1353 | u32 segment_count_sit = le32_to_cpu(raw_super->segment_count_sit); |
| 1354 | u32 segment_count_nat = le32_to_cpu(raw_super->segment_count_nat); |
| 1355 | u32 segment_count_ssa = le32_to_cpu(raw_super->segment_count_ssa); |
| 1356 | u32 segment_count_main = le32_to_cpu(raw_super->segment_count_main); |
| 1357 | u32 segment_count = le32_to_cpu(raw_super->segment_count); |
| 1358 | u32 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1359 | u64 main_end_blkaddr = main_blkaddr + |
| 1360 | (segment_count_main << log_blocks_per_seg); |
| 1361 | u64 seg_end_blkaddr = segment0_blkaddr + |
| 1362 | (segment_count << log_blocks_per_seg); |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1363 | |
| 1364 | if (segment0_blkaddr != cp_blkaddr) { |
| 1365 | f2fs_msg(sb, KERN_INFO, |
| 1366 | "Mismatch start address, segment0(%u) cp_blkaddr(%u)", |
| 1367 | segment0_blkaddr, cp_blkaddr); |
| 1368 | return true; |
| 1369 | } |
| 1370 | |
| 1371 | if (cp_blkaddr + (segment_count_ckpt << log_blocks_per_seg) != |
| 1372 | sit_blkaddr) { |
| 1373 | f2fs_msg(sb, KERN_INFO, |
| 1374 | "Wrong CP boundary, start(%u) end(%u) blocks(%u)", |
| 1375 | cp_blkaddr, sit_blkaddr, |
| 1376 | segment_count_ckpt << log_blocks_per_seg); |
| 1377 | return true; |
| 1378 | } |
| 1379 | |
| 1380 | if (sit_blkaddr + (segment_count_sit << log_blocks_per_seg) != |
| 1381 | nat_blkaddr) { |
| 1382 | f2fs_msg(sb, KERN_INFO, |
| 1383 | "Wrong SIT boundary, start(%u) end(%u) blocks(%u)", |
| 1384 | sit_blkaddr, nat_blkaddr, |
| 1385 | segment_count_sit << log_blocks_per_seg); |
| 1386 | return true; |
| 1387 | } |
| 1388 | |
| 1389 | if (nat_blkaddr + (segment_count_nat << log_blocks_per_seg) != |
| 1390 | ssa_blkaddr) { |
| 1391 | f2fs_msg(sb, KERN_INFO, |
| 1392 | "Wrong NAT boundary, start(%u) end(%u) blocks(%u)", |
| 1393 | nat_blkaddr, ssa_blkaddr, |
| 1394 | segment_count_nat << log_blocks_per_seg); |
| 1395 | return true; |
| 1396 | } |
| 1397 | |
| 1398 | if (ssa_blkaddr + (segment_count_ssa << log_blocks_per_seg) != |
| 1399 | main_blkaddr) { |
| 1400 | f2fs_msg(sb, KERN_INFO, |
| 1401 | "Wrong SSA boundary, start(%u) end(%u) blocks(%u)", |
| 1402 | ssa_blkaddr, main_blkaddr, |
| 1403 | segment_count_ssa << log_blocks_per_seg); |
| 1404 | return true; |
| 1405 | } |
| 1406 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1407 | if (main_end_blkaddr > seg_end_blkaddr) { |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1408 | f2fs_msg(sb, KERN_INFO, |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1409 | "Wrong MAIN_AREA boundary, start(%u) end(%u) block(%u)", |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1410 | main_blkaddr, |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1411 | segment0_blkaddr + |
| 1412 | (segment_count << log_blocks_per_seg), |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1413 | segment_count_main << log_blocks_per_seg); |
| 1414 | return true; |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1415 | } else if (main_end_blkaddr < seg_end_blkaddr) { |
| 1416 | int err = 0; |
| 1417 | char *res; |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1418 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1419 | /* fix in-memory information all the time */ |
| 1420 | raw_super->segment_count = cpu_to_le32((main_end_blkaddr - |
| 1421 | segment0_blkaddr) >> log_blocks_per_seg); |
| 1422 | |
| 1423 | if (f2fs_readonly(sb) || bdev_read_only(sb->s_bdev)) { |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1424 | set_sbi_flag(sbi, SBI_NEED_SB_WRITE); |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1425 | res = "internally"; |
| 1426 | } else { |
| 1427 | err = __f2fs_commit_super(bh, NULL); |
| 1428 | res = err ? "failed" : "done"; |
| 1429 | } |
| 1430 | f2fs_msg(sb, KERN_INFO, |
| 1431 | "Fix alignment : %s, start(%u) end(%u) block(%u)", |
| 1432 | res, main_blkaddr, |
| 1433 | segment0_blkaddr + |
| 1434 | (segment_count << log_blocks_per_seg), |
| 1435 | segment_count_main << log_blocks_per_seg); |
| 1436 | if (err) |
| 1437 | return true; |
| 1438 | } |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1439 | return false; |
| 1440 | } |
| 1441 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1442 | static int sanity_check_raw_super(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1443 | struct buffer_head *bh) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1444 | { |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1445 | struct f2fs_super_block *raw_super = (struct f2fs_super_block *) |
| 1446 | (bh->b_data + F2FS_SUPER_OFFSET); |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1447 | struct super_block *sb = sbi->sb; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1448 | unsigned int blocksize; |
| 1449 | |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 1450 | if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) { |
| 1451 | f2fs_msg(sb, KERN_INFO, |
| 1452 | "Magic Mismatch, valid(0x%x) - read(0x%x)", |
| 1453 | F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic)); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1454 | return 1; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 1455 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1456 | |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 1457 | /* Currently, support only 4KB page cache size */ |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1458 | if (F2FS_BLKSIZE != PAGE_SIZE) { |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 1459 | f2fs_msg(sb, KERN_INFO, |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 1460 | "Invalid page_cache_size (%lu), supports only 4KB\n", |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1461 | PAGE_SIZE); |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 1462 | return 1; |
| 1463 | } |
| 1464 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1465 | /* Currently, support only 4KB block size */ |
| 1466 | blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 1467 | if (blocksize != F2FS_BLKSIZE) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 1468 | f2fs_msg(sb, KERN_INFO, |
| 1469 | "Invalid blocksize (%u), supports only 4KB\n", |
| 1470 | blocksize); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1471 | return 1; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 1472 | } |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 1473 | |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1474 | /* check log blocks per segment */ |
| 1475 | if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) { |
| 1476 | f2fs_msg(sb, KERN_INFO, |
| 1477 | "Invalid log blocks per segment (%u)\n", |
| 1478 | le32_to_cpu(raw_super->log_blocks_per_seg)); |
| 1479 | return 1; |
| 1480 | } |
| 1481 | |
Chao Yu | 55cf9cb | 2014-09-15 18:01:10 +0800 | [diff] [blame] | 1482 | /* Currently, support 512/1024/2048/4096 bytes sector size */ |
| 1483 | if (le32_to_cpu(raw_super->log_sectorsize) > |
| 1484 | F2FS_MAX_LOG_SECTOR_SIZE || |
| 1485 | le32_to_cpu(raw_super->log_sectorsize) < |
| 1486 | F2FS_MIN_LOG_SECTOR_SIZE) { |
| 1487 | f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize (%u)", |
| 1488 | le32_to_cpu(raw_super->log_sectorsize)); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1489 | return 1; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 1490 | } |
Chao Yu | 55cf9cb | 2014-09-15 18:01:10 +0800 | [diff] [blame] | 1491 | if (le32_to_cpu(raw_super->log_sectors_per_block) + |
| 1492 | le32_to_cpu(raw_super->log_sectorsize) != |
| 1493 | F2FS_MAX_LOG_SECTOR_SIZE) { |
| 1494 | f2fs_msg(sb, KERN_INFO, |
| 1495 | "Invalid log sectors per block(%u) log sectorsize(%u)", |
| 1496 | le32_to_cpu(raw_super->log_sectors_per_block), |
| 1497 | le32_to_cpu(raw_super->log_sectorsize)); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1498 | return 1; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 1499 | } |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1500 | |
| 1501 | /* check reserved ino info */ |
| 1502 | if (le32_to_cpu(raw_super->node_ino) != 1 || |
| 1503 | le32_to_cpu(raw_super->meta_ino) != 2 || |
| 1504 | le32_to_cpu(raw_super->root_ino) != 3) { |
| 1505 | f2fs_msg(sb, KERN_INFO, |
| 1506 | "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)", |
| 1507 | le32_to_cpu(raw_super->node_ino), |
| 1508 | le32_to_cpu(raw_super->meta_ino), |
| 1509 | le32_to_cpu(raw_super->root_ino)); |
| 1510 | return 1; |
| 1511 | } |
| 1512 | |
Jin Qian | b9dd461 | 2017-04-25 16:28:48 -0700 | [diff] [blame] | 1513 | if (le32_to_cpu(raw_super->segment_count) > F2FS_MAX_SEGMENT) { |
| 1514 | f2fs_msg(sb, KERN_INFO, |
| 1515 | "Invalid segment count (%u)", |
| 1516 | le32_to_cpu(raw_super->segment_count)); |
| 1517 | return 1; |
| 1518 | } |
| 1519 | |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1520 | /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */ |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1521 | if (sanity_check_area_boundary(sbi, bh)) |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 1522 | return 1; |
| 1523 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1524 | return 0; |
| 1525 | } |
| 1526 | |
Shawn Lin | 984ec63 | 2016-02-17 11:26:32 +0800 | [diff] [blame] | 1527 | int sanity_check_ckpt(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1528 | { |
| 1529 | unsigned int total, fsmeta; |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 1530 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); |
| 1531 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); |
Jaegeuk Kim | 2040fce8 | 2016-12-05 13:56:04 -0800 | [diff] [blame] | 1532 | unsigned int ovp_segments, reserved_segments; |
Jin Qian | 15d3042 | 2017-05-15 10:45:08 -0700 | [diff] [blame] | 1533 | unsigned int main_segs, blocks_per_seg; |
| 1534 | int i; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1535 | |
| 1536 | total = le32_to_cpu(raw_super->segment_count); |
| 1537 | fsmeta = le32_to_cpu(raw_super->segment_count_ckpt); |
| 1538 | fsmeta += le32_to_cpu(raw_super->segment_count_sit); |
| 1539 | fsmeta += le32_to_cpu(raw_super->segment_count_nat); |
| 1540 | fsmeta += le32_to_cpu(ckpt->rsvd_segment_count); |
| 1541 | fsmeta += le32_to_cpu(raw_super->segment_count_ssa); |
| 1542 | |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 1543 | if (unlikely(fsmeta >= total)) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1544 | return 1; |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 1545 | |
Jaegeuk Kim | 2040fce8 | 2016-12-05 13:56:04 -0800 | [diff] [blame] | 1546 | ovp_segments = le32_to_cpu(ckpt->overprov_segment_count); |
| 1547 | reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count); |
| 1548 | |
| 1549 | if (unlikely(fsmeta < F2FS_MIN_SEGMENTS || |
| 1550 | ovp_segments == 0 || reserved_segments == 0)) { |
| 1551 | f2fs_msg(sbi->sb, KERN_ERR, |
| 1552 | "Wrong layout: check mkfs.f2fs version"); |
| 1553 | return 1; |
| 1554 | } |
| 1555 | |
Jin Qian | 15d3042 | 2017-05-15 10:45:08 -0700 | [diff] [blame] | 1556 | main_segs = le32_to_cpu(raw_super->segment_count_main); |
| 1557 | blocks_per_seg = sbi->blocks_per_seg; |
| 1558 | |
| 1559 | for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { |
| 1560 | if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs || |
| 1561 | le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg) |
| 1562 | return 1; |
| 1563 | } |
| 1564 | for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { |
| 1565 | if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || |
| 1566 | le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) |
| 1567 | return 1; |
| 1568 | } |
| 1569 | |
Jaegeuk Kim | 1e968fd | 2014-08-11 16:49:25 -0700 | [diff] [blame] | 1570 | if (unlikely(f2fs_cp_error(sbi))) { |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 1571 | f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck"); |
| 1572 | return 1; |
| 1573 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1574 | return 0; |
| 1575 | } |
| 1576 | |
| 1577 | static void init_sb_info(struct f2fs_sb_info *sbi) |
| 1578 | { |
| 1579 | struct f2fs_super_block *raw_super = sbi->raw_super; |
Chao Yu | e41e6d7 | 2017-05-19 23:37:00 +0800 | [diff] [blame] | 1580 | int i, j; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1581 | |
| 1582 | sbi->log_sectors_per_block = |
| 1583 | le32_to_cpu(raw_super->log_sectors_per_block); |
| 1584 | sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize); |
| 1585 | sbi->blocksize = 1 << sbi->log_blocksize; |
| 1586 | sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); |
| 1587 | sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg; |
| 1588 | sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); |
| 1589 | sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone); |
| 1590 | sbi->total_sections = le32_to_cpu(raw_super->section_count); |
| 1591 | sbi->total_node_count = |
| 1592 | (le32_to_cpu(raw_super->segment_count_nat) / 2) |
| 1593 | * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK; |
| 1594 | sbi->root_ino_num = le32_to_cpu(raw_super->root_ino); |
| 1595 | sbi->node_ino_num = le32_to_cpu(raw_super->node_ino); |
| 1596 | sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino); |
Jaegeuk Kim | 5ec4e49 | 2013-03-31 13:26:03 +0900 | [diff] [blame] | 1597 | sbi->cur_victim_sec = NULL_SECNO; |
Jaegeuk Kim | b1c57c1 | 2014-01-08 13:45:08 +0900 | [diff] [blame] | 1598 | sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1599 | |
Jaegeuk Kim | ab9fa66 | 2014-02-27 20:09:05 +0900 | [diff] [blame] | 1600 | sbi->dir_level = DEF_DIR_LEVEL; |
Jaegeuk Kim | 6beceb5 | 2016-01-08 15:51:50 -0800 | [diff] [blame] | 1601 | sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; |
Jaegeuk Kim | d0239e1 | 2016-01-08 16:57:48 -0800 | [diff] [blame] | 1602 | sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL; |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 1603 | clear_sbi_flag(sbi, SBI_NEED_FSCK); |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 1604 | |
Jaegeuk Kim | 35782b2 | 2016-10-20 19:09:57 -0700 | [diff] [blame] | 1605 | for (i = 0; i < NR_COUNT_TYPE; i++) |
| 1606 | atomic_set(&sbi->nr_pages[i], 0); |
| 1607 | |
Jaegeuk Kim | 687de7f | 2017-03-28 18:07:38 -0700 | [diff] [blame] | 1608 | atomic_set(&sbi->wb_sync_req, 0); |
| 1609 | |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 1610 | INIT_LIST_HEAD(&sbi->s_list); |
| 1611 | mutex_init(&sbi->umount_mutex); |
Chao Yu | e41e6d7 | 2017-05-19 23:37:00 +0800 | [diff] [blame] | 1612 | for (i = 0; i < NR_PAGE_TYPE - 1; i++) |
| 1613 | for (j = HOT; j < NR_TEMP_TYPE; j++) |
| 1614 | mutex_init(&sbi->wio_mutex[i][j]); |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 1615 | spin_lock_init(&sbi->cp_lock); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1616 | } |
| 1617 | |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 1618 | static int init_percpu_info(struct f2fs_sb_info *sbi) |
| 1619 | { |
Jaegeuk Kim | 35782b2 | 2016-10-20 19:09:57 -0700 | [diff] [blame] | 1620 | int err; |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 1621 | |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 1622 | err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL); |
| 1623 | if (err) |
| 1624 | return err; |
| 1625 | |
| 1626 | return percpu_counter_init(&sbi->total_valid_inode_count, 0, |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 1627 | GFP_KERNEL); |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 1630 | #ifdef CONFIG_BLK_DEV_ZONED |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1631 | static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 1632 | { |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1633 | struct block_device *bdev = FDEV(devi).bdev; |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 1634 | sector_t nr_sectors = bdev->bd_part->nr_sects; |
| 1635 | sector_t sector = 0; |
| 1636 | struct blk_zone *zones; |
| 1637 | unsigned int i, nr_zones; |
| 1638 | unsigned int n = 0; |
| 1639 | int err = -EIO; |
| 1640 | |
| 1641 | if (!f2fs_sb_mounted_blkzoned(sbi->sb)) |
| 1642 | return 0; |
| 1643 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1644 | if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != |
Damien Le Moal | f99e864 | 2017-01-12 07:58:32 -0700 | [diff] [blame] | 1645 | SECTOR_TO_BLOCK(bdev_zone_sectors(bdev))) |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1646 | return -EINVAL; |
Damien Le Moal | f99e864 | 2017-01-12 07:58:32 -0700 | [diff] [blame] | 1647 | sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev)); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1648 | if (sbi->log_blocks_per_blkz && sbi->log_blocks_per_blkz != |
| 1649 | __ilog2_u32(sbi->blocks_per_blkz)) |
| 1650 | return -EINVAL; |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 1651 | sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1652 | FDEV(devi).nr_blkz = SECTOR_TO_BLOCK(nr_sectors) >> |
| 1653 | sbi->log_blocks_per_blkz; |
Damien Le Moal | f99e864 | 2017-01-12 07:58:32 -0700 | [diff] [blame] | 1654 | if (nr_sectors & (bdev_zone_sectors(bdev) - 1)) |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1655 | FDEV(devi).nr_blkz++; |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 1656 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1657 | FDEV(devi).blkz_type = kmalloc(FDEV(devi).nr_blkz, GFP_KERNEL); |
| 1658 | if (!FDEV(devi).blkz_type) |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 1659 | return -ENOMEM; |
| 1660 | |
| 1661 | #define F2FS_REPORT_NR_ZONES 4096 |
| 1662 | |
| 1663 | zones = kcalloc(F2FS_REPORT_NR_ZONES, sizeof(struct blk_zone), |
| 1664 | GFP_KERNEL); |
| 1665 | if (!zones) |
| 1666 | return -ENOMEM; |
| 1667 | |
| 1668 | /* Get block zones type */ |
| 1669 | while (zones && sector < nr_sectors) { |
| 1670 | |
| 1671 | nr_zones = F2FS_REPORT_NR_ZONES; |
| 1672 | err = blkdev_report_zones(bdev, sector, |
| 1673 | zones, &nr_zones, |
| 1674 | GFP_KERNEL); |
| 1675 | if (err) |
| 1676 | break; |
| 1677 | if (!nr_zones) { |
| 1678 | err = -EIO; |
| 1679 | break; |
| 1680 | } |
| 1681 | |
| 1682 | for (i = 0; i < nr_zones; i++) { |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1683 | FDEV(devi).blkz_type[n] = zones[i].type; |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 1684 | sector += zones[i].len; |
| 1685 | n++; |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | kfree(zones); |
| 1690 | |
| 1691 | return err; |
| 1692 | } |
| 1693 | #endif |
| 1694 | |
Gu Zheng | 9076a75 | 2013-10-14 18:47:11 +0800 | [diff] [blame] | 1695 | /* |
| 1696 | * Read f2fs raw super block. |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1697 | * Because we have two copies of super block, so read both of them |
| 1698 | * to get the first valid one. If any one of them is broken, we pass |
| 1699 | * them recovery flag back to the caller. |
Gu Zheng | 9076a75 | 2013-10-14 18:47:11 +0800 | [diff] [blame] | 1700 | */ |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1701 | static int read_raw_super_block(struct f2fs_sb_info *sbi, |
Gu Zheng | 9076a75 | 2013-10-14 18:47:11 +0800 | [diff] [blame] | 1702 | struct f2fs_super_block **raw_super, |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 1703 | int *valid_super_block, int *recovery) |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 1704 | { |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1705 | struct super_block *sb = sbi->sb; |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1706 | int block; |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 1707 | struct buffer_head *bh; |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1708 | struct f2fs_super_block *super; |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 1709 | int err = 0; |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 1710 | |
Yunlei He | b39f0de | 2015-12-15 17:17:20 +0800 | [diff] [blame] | 1711 | super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL); |
| 1712 | if (!super) |
| 1713 | return -ENOMEM; |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1714 | |
| 1715 | for (block = 0; block < 2; block++) { |
| 1716 | bh = sb_bread(sb, block); |
| 1717 | if (!bh) { |
| 1718 | f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock", |
Gu Zheng | 9076a75 | 2013-10-14 18:47:11 +0800 | [diff] [blame] | 1719 | block + 1); |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1720 | err = -EIO; |
| 1721 | continue; |
| 1722 | } |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 1723 | |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1724 | /* sanity checking of raw super */ |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1725 | if (sanity_check_raw_super(sbi, bh)) { |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1726 | f2fs_msg(sb, KERN_ERR, |
| 1727 | "Can't find valid F2FS filesystem in %dth superblock", |
| 1728 | block + 1); |
| 1729 | err = -EINVAL; |
| 1730 | brelse(bh); |
| 1731 | continue; |
| 1732 | } |
| 1733 | |
| 1734 | if (!*raw_super) { |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1735 | memcpy(super, bh->b_data + F2FS_SUPER_OFFSET, |
| 1736 | sizeof(*super)); |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1737 | *valid_super_block = block; |
| 1738 | *raw_super = super; |
| 1739 | } |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 1740 | brelse(bh); |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | /* Fail to read any one of the superblocks*/ |
| 1744 | if (err < 0) |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 1745 | *recovery = 1; |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 1746 | |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 1747 | /* No valid superblock */ |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1748 | if (!*raw_super) |
Yunlei He | b39f0de | 2015-12-15 17:17:20 +0800 | [diff] [blame] | 1749 | kfree(super); |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1750 | else |
| 1751 | err = 0; |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 1752 | |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 1753 | return err; |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 1754 | } |
| 1755 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1756 | int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) |
Jaegeuk Kim | 26d815ad | 2015-04-20 18:49:51 -0700 | [diff] [blame] | 1757 | { |
Jaegeuk Kim | 5d909cd | 2015-12-07 10:16:58 -0800 | [diff] [blame] | 1758 | struct buffer_head *bh; |
Jaegeuk Kim | 26d815ad | 2015-04-20 18:49:51 -0700 | [diff] [blame] | 1759 | int err; |
| 1760 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1761 | if ((recover && f2fs_readonly(sbi->sb)) || |
| 1762 | bdev_read_only(sbi->sb->s_bdev)) { |
| 1763 | set_sbi_flag(sbi, SBI_NEED_SB_WRITE); |
Jaegeuk Kim | f2353d7 | 2016-03-23 10:42:01 -0700 | [diff] [blame] | 1764 | return -EROFS; |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1765 | } |
Jaegeuk Kim | f2353d7 | 2016-03-23 10:42:01 -0700 | [diff] [blame] | 1766 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1767 | /* write back-up superblock first */ |
| 1768 | bh = sb_getblk(sbi->sb, sbi->valid_super_block ? 0: 1); |
Jaegeuk Kim | 5d909cd | 2015-12-07 10:16:58 -0800 | [diff] [blame] | 1769 | if (!bh) |
| 1770 | return -EIO; |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1771 | err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); |
Jaegeuk Kim | 5d909cd | 2015-12-07 10:16:58 -0800 | [diff] [blame] | 1772 | brelse(bh); |
Chao Yu | c5bda1c | 2015-06-08 13:28:03 +0800 | [diff] [blame] | 1773 | |
| 1774 | /* if we are in recovery path, skip writing valid superblock */ |
| 1775 | if (recover || err) |
Jaegeuk Kim | 5d909cd | 2015-12-07 10:16:58 -0800 | [diff] [blame] | 1776 | return err; |
Jaegeuk Kim | 26d815ad | 2015-04-20 18:49:51 -0700 | [diff] [blame] | 1777 | |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 1778 | /* write current valid superblock */ |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 1779 | bh = sb_getblk(sbi->sb, sbi->valid_super_block); |
| 1780 | if (!bh) |
| 1781 | return -EIO; |
| 1782 | err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); |
| 1783 | brelse(bh); |
| 1784 | return err; |
Jaegeuk Kim | 26d815ad | 2015-04-20 18:49:51 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1787 | static int f2fs_scan_devices(struct f2fs_sb_info *sbi) |
| 1788 | { |
| 1789 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 1790 | unsigned int max_devices = MAX_DEVICES; |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1791 | int i; |
| 1792 | |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 1793 | /* Initialize single device information */ |
| 1794 | if (!RDEV(0).path[0]) { |
| 1795 | if (!bdev_is_zoned(sbi->sb->s_bdev)) |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1796 | return 0; |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 1797 | max_devices = 1; |
| 1798 | } |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1799 | |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 1800 | /* |
| 1801 | * Initialize multiple devices information, or single |
| 1802 | * zoned block device information. |
| 1803 | */ |
| 1804 | sbi->devs = kcalloc(max_devices, sizeof(struct f2fs_dev_info), |
| 1805 | GFP_KERNEL); |
| 1806 | if (!sbi->devs) |
| 1807 | return -ENOMEM; |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1808 | |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 1809 | for (i = 0; i < max_devices; i++) { |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1810 | |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 1811 | if (i > 0 && !RDEV(i).path[0]) |
| 1812 | break; |
| 1813 | |
| 1814 | if (max_devices == 1) { |
| 1815 | /* Single zoned block device mount */ |
| 1816 | FDEV(0).bdev = |
| 1817 | blkdev_get_by_dev(sbi->sb->s_bdev->bd_dev, |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1818 | sbi->sb->s_mode, sbi->sb->s_type); |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 1819 | } else { |
| 1820 | /* Multi-device mount */ |
| 1821 | memcpy(FDEV(i).path, RDEV(i).path, MAX_PATH_LEN); |
| 1822 | FDEV(i).total_segments = |
| 1823 | le32_to_cpu(RDEV(i).total_segments); |
| 1824 | if (i == 0) { |
| 1825 | FDEV(i).start_blk = 0; |
| 1826 | FDEV(i).end_blk = FDEV(i).start_blk + |
| 1827 | (FDEV(i).total_segments << |
| 1828 | sbi->log_blocks_per_seg) - 1 + |
| 1829 | le32_to_cpu(raw_super->segment0_blkaddr); |
| 1830 | } else { |
| 1831 | FDEV(i).start_blk = FDEV(i - 1).end_blk + 1; |
| 1832 | FDEV(i).end_blk = FDEV(i).start_blk + |
| 1833 | (FDEV(i).total_segments << |
| 1834 | sbi->log_blocks_per_seg) - 1; |
| 1835 | } |
| 1836 | FDEV(i).bdev = blkdev_get_by_path(FDEV(i).path, |
| 1837 | sbi->sb->s_mode, sbi->sb->s_type); |
| 1838 | } |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1839 | if (IS_ERR(FDEV(i).bdev)) |
| 1840 | return PTR_ERR(FDEV(i).bdev); |
| 1841 | |
| 1842 | /* to release errored devices */ |
| 1843 | sbi->s_ndevs = i + 1; |
| 1844 | |
| 1845 | #ifdef CONFIG_BLK_DEV_ZONED |
| 1846 | if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM && |
| 1847 | !f2fs_sb_mounted_blkzoned(sbi->sb)) { |
| 1848 | f2fs_msg(sbi->sb, KERN_ERR, |
| 1849 | "Zoned block device feature not enabled\n"); |
| 1850 | return -EINVAL; |
| 1851 | } |
| 1852 | if (bdev_zoned_model(FDEV(i).bdev) != BLK_ZONED_NONE) { |
| 1853 | if (init_blkz_info(sbi, i)) { |
| 1854 | f2fs_msg(sbi->sb, KERN_ERR, |
| 1855 | "Failed to initialize F2FS blkzone information"); |
| 1856 | return -EINVAL; |
| 1857 | } |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 1858 | if (max_devices == 1) |
| 1859 | break; |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1860 | f2fs_msg(sbi->sb, KERN_INFO, |
| 1861 | "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)", |
| 1862 | i, FDEV(i).path, |
| 1863 | FDEV(i).total_segments, |
| 1864 | FDEV(i).start_blk, FDEV(i).end_blk, |
| 1865 | bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HA ? |
| 1866 | "Host-aware" : "Host-managed"); |
| 1867 | continue; |
| 1868 | } |
| 1869 | #endif |
| 1870 | f2fs_msg(sbi->sb, KERN_INFO, |
| 1871 | "Mount Device [%2d]: %20s, %8u, %8x - %8x", |
| 1872 | i, FDEV(i).path, |
| 1873 | FDEV(i).total_segments, |
| 1874 | FDEV(i).start_blk, FDEV(i).end_blk); |
| 1875 | } |
Jaegeuk Kim | 0a595eb | 2016-12-14 10:12:56 -0800 | [diff] [blame] | 1876 | f2fs_msg(sbi->sb, KERN_INFO, |
| 1877 | "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi)); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1878 | return 0; |
| 1879 | } |
| 1880 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1881 | static int f2fs_fill_super(struct super_block *sb, void *data, int silent) |
| 1882 | { |
| 1883 | struct f2fs_sb_info *sbi; |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 1884 | struct f2fs_super_block *raw_super; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1885 | struct inode *root; |
Sheng Yong | 99e3e85 | 2016-05-11 17:08:14 +0800 | [diff] [blame] | 1886 | int err; |
Chao Yu | 2adc350 | 2015-03-16 21:08:44 +0800 | [diff] [blame] | 1887 | bool retry = true, need_fsck = false; |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 1888 | char *options = NULL; |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 1889 | int recovery, i, valid_super_block; |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 1890 | struct curseg_info *seg_i; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1891 | |
Jaegeuk Kim | ed2e621 | 2014-08-08 15:37:41 -0700 | [diff] [blame] | 1892 | try_onemore: |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 1893 | err = -EINVAL; |
| 1894 | raw_super = NULL; |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 1895 | valid_super_block = -1; |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 1896 | recovery = 0; |
| 1897 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1898 | /* allocate memory for f2fs-specific super block info */ |
| 1899 | sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); |
| 1900 | if (!sbi) |
| 1901 | return -ENOMEM; |
| 1902 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1903 | sbi->sb = sb; |
| 1904 | |
Keith Mok | 43b6573 | 2016-03-02 12:04:24 -0800 | [diff] [blame] | 1905 | /* Load the checksum driver */ |
| 1906 | sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0); |
| 1907 | if (IS_ERR(sbi->s_chksum_driver)) { |
| 1908 | f2fs_msg(sb, KERN_ERR, "Cannot load crc32 driver."); |
| 1909 | err = PTR_ERR(sbi->s_chksum_driver); |
| 1910 | sbi->s_chksum_driver = NULL; |
| 1911 | goto free_sbi; |
| 1912 | } |
| 1913 | |
Namjae Jeon | ff9234a | 2013-01-12 14:41:13 +0900 | [diff] [blame] | 1914 | /* set a block size */ |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 1915 | if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 1916 | f2fs_msg(sb, KERN_ERR, "unable to set blocksize"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1917 | goto free_sbi; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 1918 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1919 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1920 | err = read_raw_super_block(sbi, &raw_super, &valid_super_block, |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 1921 | &recovery); |
Gu Zheng | 9076a75 | 2013-10-14 18:47:11 +0800 | [diff] [blame] | 1922 | if (err) |
| 1923 | goto free_sbi; |
| 1924 | |
Gu Zheng | 5fb0837 | 2013-06-07 14:16:53 +0800 | [diff] [blame] | 1925 | sb->s_fs_info = sbi; |
Jaegeuk Kim | 52763a4 | 2016-06-13 09:47:48 -0700 | [diff] [blame] | 1926 | sbi->raw_super = raw_super; |
| 1927 | |
Damien Le Moal | d1b959c | 2016-10-28 17:45:01 +0900 | [diff] [blame] | 1928 | /* |
| 1929 | * The BLKZONED feature indicates that the drive was formatted with |
| 1930 | * zone alignment optimization. This is optional for host-aware |
| 1931 | * devices, but mandatory for host-managed zoned block devices. |
| 1932 | */ |
| 1933 | #ifndef CONFIG_BLK_DEV_ZONED |
| 1934 | if (f2fs_sb_mounted_blkzoned(sb)) { |
| 1935 | f2fs_msg(sb, KERN_ERR, |
| 1936 | "Zoned block device support is not enabled\n"); |
Chao Yu | 1727f31 | 2017-06-12 09:44:27 +0800 | [diff] [blame] | 1937 | err = -EOPNOTSUPP; |
Damien Le Moal | d1b959c | 2016-10-28 17:45:01 +0900 | [diff] [blame] | 1938 | goto free_sb_buf; |
| 1939 | } |
Damien Le Moal | d1b959c | 2016-10-28 17:45:01 +0900 | [diff] [blame] | 1940 | #endif |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 1941 | default_options(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1942 | /* parse mount options */ |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 1943 | options = kstrdup((const char *)data, GFP_KERNEL); |
| 1944 | if (data && !options) { |
| 1945 | err = -ENOMEM; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1946 | goto free_sb_buf; |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | err = parse_options(sb, options); |
| 1950 | if (err) |
| 1951 | goto free_options; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1952 | |
Chao Yu | e0afc4d | 2015-12-31 14:35:37 +0800 | [diff] [blame] | 1953 | sbi->max_file_blocks = max_file_blocks(); |
| 1954 | sb->s_maxbytes = sbi->max_file_blocks << |
| 1955 | le32_to_cpu(raw_super->log_blocksize); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1956 | sb->s_max_links = F2FS_LINK_MAX; |
| 1957 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); |
| 1958 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1959 | #ifdef CONFIG_QUOTA |
| 1960 | sb->dq_op = &f2fs_quota_operations; |
| 1961 | sb->s_qcop = &f2fs_quotactl_ops; |
| 1962 | sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP; |
| 1963 | #endif |
| 1964 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1965 | sb->s_op = &f2fs_sops; |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 1966 | sb->s_cop = &f2fs_cryptops; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1967 | sb->s_xattr = f2fs_xattr_handlers; |
| 1968 | sb->s_export_op = &f2fs_export_ops; |
| 1969 | sb->s_magic = F2FS_SUPER_MAGIC; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1970 | sb->s_time_gran = 1; |
| 1971 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
| 1972 | (test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0); |
Christoph Hellwig | 8578709 | 2017-05-10 15:06:33 +0200 | [diff] [blame] | 1973 | memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid)); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1974 | |
| 1975 | /* init f2fs-specific super block info */ |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 1976 | sbi->valid_super_block = valid_super_block; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1977 | mutex_init(&sbi->gc_mutex); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1978 | mutex_init(&sbi->cp_mutex); |
Chao Yu | b3582c6 | 2014-07-03 18:58:39 +0800 | [diff] [blame] | 1979 | init_rwsem(&sbi->node_write); |
Yunlei He | 59c9081 | 2017-03-13 20:22:18 +0800 | [diff] [blame] | 1980 | init_rwsem(&sbi->node_change); |
Jaegeuk Kim | 315df83 | 2015-08-11 12:45:39 -0700 | [diff] [blame] | 1981 | |
| 1982 | /* disallow all the data/node/meta page writes */ |
| 1983 | set_sbi_flag(sbi, SBI_POR_DOING); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1984 | spin_lock_init(&sbi->stat_lock); |
Jaegeuk Kim | 971767c | 2013-11-18 17:16:17 +0900 | [diff] [blame] | 1985 | |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 1986 | for (i = 0; i < NR_PAGE_TYPE; i++) { |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 1987 | int n = (i == META) ? 1: NR_TEMP_TYPE; |
| 1988 | int j; |
| 1989 | |
| 1990 | sbi->write_io[i] = kmalloc(n * sizeof(struct f2fs_bio_info), |
| 1991 | GFP_KERNEL); |
Christophe JAILLET | b63def9 | 2017-06-11 09:21:11 +0200 | [diff] [blame] | 1992 | if (!sbi->write_io[i]) { |
| 1993 | err = -ENOMEM; |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 1994 | goto free_options; |
Christophe JAILLET | b63def9 | 2017-06-11 09:21:11 +0200 | [diff] [blame] | 1995 | } |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 1996 | |
| 1997 | for (j = HOT; j < n; j++) { |
| 1998 | init_rwsem(&sbi->write_io[i][j].io_rwsem); |
| 1999 | sbi->write_io[i][j].sbi = sbi; |
| 2000 | sbi->write_io[i][j].bio = NULL; |
Chao Yu | fb830fc | 2017-05-19 23:37:01 +0800 | [diff] [blame] | 2001 | spin_lock_init(&sbi->write_io[i][j].io_lock); |
| 2002 | INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 2003 | } |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 2004 | } |
Jaegeuk Kim | 971767c | 2013-11-18 17:16:17 +0900 | [diff] [blame] | 2005 | |
Jaegeuk Kim | b873b79 | 2016-08-04 11:38:25 -0700 | [diff] [blame] | 2006 | init_rwsem(&sbi->cp_rwsem); |
Changman Lee | fb51b5e | 2013-11-07 12:48:25 +0900 | [diff] [blame] | 2007 | init_waitqueue_head(&sbi->cp_wait); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2008 | init_sb_info(sbi); |
| 2009 | |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 2010 | err = init_percpu_info(sbi); |
| 2011 | if (err) |
| 2012 | goto free_options; |
| 2013 | |
Jaegeuk Kim | 0a595eb | 2016-12-14 10:12:56 -0800 | [diff] [blame] | 2014 | if (F2FS_IO_SIZE(sbi) > 1) { |
| 2015 | sbi->write_io_dummy = |
Chao Yu | a3ebfe4 | 2017-02-27 18:43:13 +0800 | [diff] [blame] | 2016 | mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); |
Chao Yu | 1727f31 | 2017-06-12 09:44:27 +0800 | [diff] [blame] | 2017 | if (!sbi->write_io_dummy) { |
| 2018 | err = -ENOMEM; |
Jaegeuk Kim | 0a595eb | 2016-12-14 10:12:56 -0800 | [diff] [blame] | 2019 | goto free_options; |
Chao Yu | 1727f31 | 2017-06-12 09:44:27 +0800 | [diff] [blame] | 2020 | } |
Jaegeuk Kim | 0a595eb | 2016-12-14 10:12:56 -0800 | [diff] [blame] | 2021 | } |
| 2022 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2023 | /* get an inode for meta space */ |
| 2024 | sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); |
| 2025 | if (IS_ERR(sbi->meta_inode)) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2026 | f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2027 | err = PTR_ERR(sbi->meta_inode); |
Jaegeuk Kim | 0a595eb | 2016-12-14 10:12:56 -0800 | [diff] [blame] | 2028 | goto free_io_dummy; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | err = get_valid_checkpoint(sbi); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2032 | if (err) { |
| 2033 | f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2034 | goto free_meta_inode; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2035 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2036 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 2037 | /* Initialize device list */ |
| 2038 | err = f2fs_scan_devices(sbi); |
| 2039 | if (err) { |
| 2040 | f2fs_msg(sb, KERN_ERR, "Failed to find devices"); |
| 2041 | goto free_devices; |
| 2042 | } |
| 2043 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2044 | sbi->total_valid_node_count = |
| 2045 | le32_to_cpu(sbi->ckpt->valid_node_count); |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 2046 | percpu_counter_set(&sbi->total_valid_inode_count, |
| 2047 | le32_to_cpu(sbi->ckpt->valid_inode_count)); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2048 | sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); |
| 2049 | sbi->total_valid_block_count = |
| 2050 | le64_to_cpu(sbi->ckpt->valid_block_count); |
| 2051 | sbi->last_valid_block_count = sbi->total_valid_block_count; |
Chao Yu | daeb433 | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 2052 | sbi->reserved_blocks = 0; |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 2053 | |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 2054 | for (i = 0; i < NR_INODE_TYPE; i++) { |
| 2055 | INIT_LIST_HEAD(&sbi->inode_list[i]); |
| 2056 | spin_lock_init(&sbi->inode_lock[i]); |
| 2057 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2058 | |
Chao Yu | 1dcc336 | 2015-02-05 17:57:31 +0800 | [diff] [blame] | 2059 | init_extent_cache_info(sbi); |
| 2060 | |
Jaegeuk Kim | 6451e04 | 2014-07-25 15:47:17 -0700 | [diff] [blame] | 2061 | init_ino_entry_info(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2062 | |
| 2063 | /* setup f2fs internal modules */ |
| 2064 | err = build_segment_manager(sbi); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2065 | if (err) { |
| 2066 | f2fs_msg(sb, KERN_ERR, |
| 2067 | "Failed to initialize F2FS segment manager"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2068 | goto free_sm; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2069 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2070 | err = build_node_manager(sbi); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2071 | if (err) { |
| 2072 | f2fs_msg(sb, KERN_ERR, |
| 2073 | "Failed to initialize F2FS node manager"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2074 | goto free_nm; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2075 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2076 | |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 2077 | /* For write statistics */ |
| 2078 | if (sb->s_bdev->bd_part) |
| 2079 | sbi->sectors_written_start = |
| 2080 | (u64)part_stat_read(sb->s_bdev->bd_part, sectors[1]); |
| 2081 | |
| 2082 | /* Read accumulated write IO statistics if exists */ |
| 2083 | seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); |
| 2084 | if (__exist_node_summaries(sbi)) |
| 2085 | sbi->kbytes_written = |
Shuoran Liu | b2dde6f | 2016-03-29 18:00:15 +0800 | [diff] [blame] | 2086 | le64_to_cpu(seg_i->journal->info.kbytes_written); |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 2087 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2088 | build_gc_manager(sbi); |
| 2089 | |
| 2090 | /* get an inode for node space */ |
| 2091 | sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); |
| 2092 | if (IS_ERR(sbi->node_inode)) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2093 | f2fs_msg(sb, KERN_ERR, "Failed to read node inode"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2094 | err = PTR_ERR(sbi->node_inode); |
| 2095 | goto free_nm; |
| 2096 | } |
| 2097 | |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 2098 | f2fs_join_shrinker(sbi); |
| 2099 | |
Jaegeuk Kim | aa51d08 | 2017-03-07 13:41:22 -0800 | [diff] [blame] | 2100 | err = f2fs_build_stats(sbi); |
| 2101 | if (err) |
| 2102 | goto free_nm; |
| 2103 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2104 | /* if there are nt orphan nodes free them */ |
Chao Yu | 8c14bfa | 2015-08-07 17:58:43 +0800 | [diff] [blame] | 2105 | err = recover_orphan_inodes(sbi); |
| 2106 | if (err) |
| 2107 | goto free_node_inode; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2108 | |
| 2109 | /* read root inode and dentry */ |
| 2110 | root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); |
| 2111 | if (IS_ERR(root)) { |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2112 | f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2113 | err = PTR_ERR(root); |
| 2114 | goto free_node_inode; |
| 2115 | } |
Chao Yu | 8f99a94 | 2013-11-28 15:43:43 +0800 | [diff] [blame] | 2116 | if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { |
Chao Yu | 9d84795 | 2014-07-25 12:55:09 +0800 | [diff] [blame] | 2117 | iput(root); |
Chao Yu | 8f99a94 | 2013-11-28 15:43:43 +0800 | [diff] [blame] | 2118 | err = -EINVAL; |
Chao Yu | 9d84795 | 2014-07-25 12:55:09 +0800 | [diff] [blame] | 2119 | goto free_node_inode; |
Chao Yu | 8f99a94 | 2013-11-28 15:43:43 +0800 | [diff] [blame] | 2120 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2121 | |
| 2122 | sb->s_root = d_make_root(root); /* allocate root dentry */ |
| 2123 | if (!sb->s_root) { |
| 2124 | err = -ENOMEM; |
| 2125 | goto free_root_inode; |
| 2126 | } |
| 2127 | |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2128 | err = f2fs_init_sysfs(sbi); |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 2129 | if (err) |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2130 | goto free_root_inode; |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 2131 | |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 2132 | /* recover fsynced data */ |
| 2133 | if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { |
Jaegeuk Kim | 081d78c | 2015-01-23 19:16:59 -0800 | [diff] [blame] | 2134 | /* |
| 2135 | * mount should be failed, when device has readonly mode, and |
| 2136 | * previous checkpoint was not done by clean system shutdown. |
| 2137 | */ |
| 2138 | if (bdev_read_only(sb->s_bdev) && |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 2139 | !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { |
Jaegeuk Kim | 081d78c | 2015-01-23 19:16:59 -0800 | [diff] [blame] | 2140 | err = -EROFS; |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2141 | goto free_sysfs; |
Jaegeuk Kim | 081d78c | 2015-01-23 19:16:59 -0800 | [diff] [blame] | 2142 | } |
Chao Yu | 2adc350 | 2015-03-16 21:08:44 +0800 | [diff] [blame] | 2143 | |
| 2144 | if (need_fsck) |
| 2145 | set_sbi_flag(sbi, SBI_NEED_FSCK); |
| 2146 | |
Jaegeuk Kim | a468f0e | 2016-09-19 17:55:10 -0700 | [diff] [blame] | 2147 | if (!retry) |
| 2148 | goto skip_recovery; |
| 2149 | |
Jaegeuk Kim | 6781eab | 2016-03-23 16:12:58 -0700 | [diff] [blame] | 2150 | err = recover_fsync_data(sbi, false); |
| 2151 | if (err < 0) { |
Chao Yu | 2adc350 | 2015-03-16 21:08:44 +0800 | [diff] [blame] | 2152 | need_fsck = true; |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 2153 | f2fs_msg(sb, KERN_ERR, |
Sheng Yong | 99e3e85 | 2016-05-11 17:08:14 +0800 | [diff] [blame] | 2154 | "Cannot recover all fsync data errno=%d", err); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2155 | goto free_sysfs; |
Jaegeuk Kim | ed2e621 | 2014-08-08 15:37:41 -0700 | [diff] [blame] | 2156 | } |
Jaegeuk Kim | 6781eab | 2016-03-23 16:12:58 -0700 | [diff] [blame] | 2157 | } else { |
| 2158 | err = recover_fsync_data(sbi, true); |
| 2159 | |
| 2160 | if (!f2fs_readonly(sb) && err > 0) { |
| 2161 | err = -EINVAL; |
| 2162 | f2fs_msg(sb, KERN_ERR, |
| 2163 | "Need to recover fsync data"); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2164 | goto free_sysfs; |
Jaegeuk Kim | 6781eab | 2016-03-23 16:12:58 -0700 | [diff] [blame] | 2165 | } |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 2166 | } |
Jaegeuk Kim | a468f0e | 2016-09-19 17:55:10 -0700 | [diff] [blame] | 2167 | skip_recovery: |
Jaegeuk Kim | 315df83 | 2015-08-11 12:45:39 -0700 | [diff] [blame] | 2168 | /* recover_fsync_data() cleared this already */ |
| 2169 | clear_sbi_flag(sbi, SBI_POR_DOING); |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 2170 | |
| 2171 | /* |
| 2172 | * If filesystem is not mounted as read-only then |
| 2173 | * do start the gc_thread. |
| 2174 | */ |
Chao Yu | 6c02993 | 2014-11-18 11:16:01 +0800 | [diff] [blame] | 2175 | if (test_opt(sbi, BG_GC) && !f2fs_readonly(sb)) { |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 2176 | /* After POR, we can run background GC thread.*/ |
| 2177 | err = start_gc_thread(sbi); |
| 2178 | if (err) |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2179 | goto free_sysfs; |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 2180 | } |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 2181 | kfree(options); |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 2182 | |
| 2183 | /* recover broken superblock */ |
Jaegeuk Kim | f2353d7 | 2016-03-23 10:42:01 -0700 | [diff] [blame] | 2184 | if (recovery) { |
Chao Yu | 41214b3 | 2016-02-22 18:33:20 +0800 | [diff] [blame] | 2185 | err = f2fs_commit_super(sbi, true); |
| 2186 | f2fs_msg(sb, KERN_INFO, |
Sheng Yong | 99e3e85 | 2016-05-11 17:08:14 +0800 | [diff] [blame] | 2187 | "Try to recover %dth superblock, ret: %d", |
Chao Yu | 41214b3 | 2016-02-22 18:33:20 +0800 | [diff] [blame] | 2188 | sbi->valid_super_block ? 1 : 2, err); |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 2189 | } |
| 2190 | |
Jaegeuk Kim | 1200abb | 2017-02-09 13:25:35 -0800 | [diff] [blame] | 2191 | f2fs_msg(sbi->sb, KERN_NOTICE, "Mounted with checkpoint version = %llx", |
| 2192 | cur_cp_version(F2FS_CKPT(sbi))); |
Jaegeuk Kim | 6beceb5 | 2016-01-08 15:51:50 -0800 | [diff] [blame] | 2193 | f2fs_update_time(sbi, CP_TIME); |
Jaegeuk Kim | d0239e1 | 2016-01-08 16:57:48 -0800 | [diff] [blame] | 2194 | f2fs_update_time(sbi, REQ_TIME); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2195 | return 0; |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 2196 | |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2197 | free_sysfs: |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 2198 | f2fs_sync_inode_meta(sbi); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2199 | f2fs_exit_sysfs(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2200 | free_root_inode: |
| 2201 | dput(sb->s_root); |
| 2202 | sb->s_root = NULL; |
| 2203 | free_node_inode: |
Jaegeuk Kim | bb5dada | 2016-09-23 11:29:00 -0700 | [diff] [blame] | 2204 | truncate_inode_pages_final(NODE_MAPPING(sbi)); |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 2205 | mutex_lock(&sbi->umount_mutex); |
Jaegeuk Kim | d41065e | 2016-09-21 11:39:42 -0700 | [diff] [blame] | 2206 | release_ino_entry(sbi, true); |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 2207 | f2fs_leave_shrinker(sbi); |
Jaegeuk Kim | 0992280 | 2016-10-31 14:01:41 -0700 | [diff] [blame] | 2208 | /* |
| 2209 | * Some dirty meta pages can be produced by recover_orphan_inodes() |
| 2210 | * failed by EIO. Then, iput(node_inode) can trigger balance_fs_bg() |
| 2211 | * followed by write_checkpoint() through f2fs_write_node_pages(), which |
| 2212 | * falls into an infinite loop in sync_meta_pages(). |
| 2213 | */ |
| 2214 | truncate_inode_pages_final(META_MAPPING(sbi)); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2215 | iput(sbi->node_inode); |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 2216 | mutex_unlock(&sbi->umount_mutex); |
Jaegeuk Kim | aa51d08 | 2017-03-07 13:41:22 -0800 | [diff] [blame] | 2217 | f2fs_destroy_stats(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2218 | free_nm: |
| 2219 | destroy_node_manager(sbi); |
| 2220 | free_sm: |
| 2221 | destroy_segment_manager(sbi); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 2222 | free_devices: |
| 2223 | destroy_device_list(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2224 | kfree(sbi->ckpt); |
| 2225 | free_meta_inode: |
| 2226 | make_bad_inode(sbi->meta_inode); |
| 2227 | iput(sbi->meta_inode); |
Jaegeuk Kim | 0a595eb | 2016-12-14 10:12:56 -0800 | [diff] [blame] | 2228 | free_io_dummy: |
| 2229 | mempool_destroy(sbi->write_io_dummy); |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 2230 | free_options: |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 2231 | for (i = 0; i < NR_PAGE_TYPE; i++) |
| 2232 | kfree(sbi->write_io[i]); |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 2233 | destroy_percpu_info(sbi); |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 2234 | kfree(options); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2235 | free_sb_buf: |
Yunlei He | b39f0de | 2015-12-15 17:17:20 +0800 | [diff] [blame] | 2236 | kfree(raw_super); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2237 | free_sbi: |
Keith Mok | 43b6573 | 2016-03-02 12:04:24 -0800 | [diff] [blame] | 2238 | if (sbi->s_chksum_driver) |
| 2239 | crypto_free_shash(sbi->s_chksum_driver); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2240 | kfree(sbi); |
Jaegeuk Kim | ed2e621 | 2014-08-08 15:37:41 -0700 | [diff] [blame] | 2241 | |
| 2242 | /* give only one another chance */ |
| 2243 | if (retry) { |
Taehee Yoo | 9df47ba | 2015-04-13 21:48:06 +0900 | [diff] [blame] | 2244 | retry = false; |
Jaegeuk Kim | ed2e621 | 2014-08-08 15:37:41 -0700 | [diff] [blame] | 2245 | shrink_dcache_sb(sb); |
| 2246 | goto try_onemore; |
| 2247 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2248 | return err; |
| 2249 | } |
| 2250 | |
| 2251 | static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags, |
| 2252 | const char *dev_name, void *data) |
| 2253 | { |
| 2254 | return mount_bdev(fs_type, flags, dev_name, data, f2fs_fill_super); |
| 2255 | } |
| 2256 | |
Jaegeuk Kim | 30a5537 | 2015-01-14 16:34:24 -0800 | [diff] [blame] | 2257 | static void kill_f2fs_super(struct super_block *sb) |
| 2258 | { |
Chao Yu | cce1325 | 2017-06-29 23:17:45 +0800 | [diff] [blame] | 2259 | if (sb->s_root) { |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 2260 | set_sbi_flag(F2FS_SB(sb), SBI_IS_CLOSE); |
Chao Yu | cce1325 | 2017-06-29 23:17:45 +0800 | [diff] [blame] | 2261 | stop_gc_thread(F2FS_SB(sb)); |
| 2262 | stop_discard_thread(F2FS_SB(sb)); |
| 2263 | } |
Jaegeuk Kim | 30a5537 | 2015-01-14 16:34:24 -0800 | [diff] [blame] | 2264 | kill_block_super(sb); |
| 2265 | } |
| 2266 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2267 | static struct file_system_type f2fs_fs_type = { |
| 2268 | .owner = THIS_MODULE, |
| 2269 | .name = "f2fs", |
| 2270 | .mount = f2fs_mount, |
Jaegeuk Kim | 30a5537 | 2015-01-14 16:34:24 -0800 | [diff] [blame] | 2271 | .kill_sb = kill_f2fs_super, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2272 | .fs_flags = FS_REQUIRES_DEV, |
| 2273 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 2274 | MODULE_ALIAS_FS("f2fs"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2275 | |
Namjae Jeon | 6e6093a | 2013-01-17 00:08:30 +0900 | [diff] [blame] | 2276 | static int __init init_inodecache(void) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2277 | { |
Vladimir Davydov | 5d09705 | 2016-01-14 15:18:21 -0800 | [diff] [blame] | 2278 | f2fs_inode_cachep = kmem_cache_create("f2fs_inode_cache", |
| 2279 | sizeof(struct f2fs_inode_info), 0, |
| 2280 | SLAB_RECLAIM_ACCOUNT|SLAB_ACCOUNT, NULL); |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 2281 | if (!f2fs_inode_cachep) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2282 | return -ENOMEM; |
| 2283 | return 0; |
| 2284 | } |
| 2285 | |
| 2286 | static void destroy_inodecache(void) |
| 2287 | { |
| 2288 | /* |
| 2289 | * Make sure all delayed rcu free inodes are flushed before we |
| 2290 | * destroy cache. |
| 2291 | */ |
| 2292 | rcu_barrier(); |
| 2293 | kmem_cache_destroy(f2fs_inode_cachep); |
| 2294 | } |
| 2295 | |
| 2296 | static int __init init_f2fs_fs(void) |
| 2297 | { |
| 2298 | int err; |
| 2299 | |
Jaegeuk Kim | c050865 | 2015-01-07 14:07:36 -0800 | [diff] [blame] | 2300 | f2fs_build_trace_ios(); |
| 2301 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2302 | err = init_inodecache(); |
| 2303 | if (err) |
| 2304 | goto fail; |
| 2305 | err = create_node_manager_caches(); |
| 2306 | if (err) |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 2307 | goto free_inodecache; |
Jaegeuk Kim | 7fd9e54 | 2013-11-15 13:55:58 +0900 | [diff] [blame] | 2308 | err = create_segment_manager_caches(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2309 | if (err) |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 2310 | goto free_node_manager_caches; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2311 | err = create_checkpoint_caches(); |
| 2312 | if (err) |
Chao Yu | 0629207 | 2014-12-29 15:56:18 +0800 | [diff] [blame] | 2313 | goto free_segment_manager_caches; |
Chao Yu | 1dcc336 | 2015-02-05 17:57:31 +0800 | [diff] [blame] | 2314 | err = create_extent_cache(); |
| 2315 | if (err) |
| 2316 | goto free_checkpoint_caches; |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2317 | err = f2fs_register_sysfs(); |
| 2318 | if (err) |
Chao Yu | 1dcc336 | 2015-02-05 17:57:31 +0800 | [diff] [blame] | 2319 | goto free_extent_cache; |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 2320 | err = register_shrinker(&f2fs_shrinker_info); |
Jaegeuk Kim | cfc4d97 | 2015-05-15 15:37:24 -0700 | [diff] [blame] | 2321 | if (err) |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2322 | goto free_sysfs; |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 2323 | err = register_filesystem(&f2fs_fs_type); |
| 2324 | if (err) |
| 2325 | goto free_shrinker; |
Chao Yu | 787c7b8c | 2015-10-29 09:13:04 +0800 | [diff] [blame] | 2326 | err = f2fs_create_root_stats(); |
| 2327 | if (err) |
| 2328 | goto free_filesystem; |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 2329 | return 0; |
| 2330 | |
Chao Yu | 787c7b8c | 2015-10-29 09:13:04 +0800 | [diff] [blame] | 2331 | free_filesystem: |
| 2332 | unregister_filesystem(&f2fs_fs_type); |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 2333 | free_shrinker: |
| 2334 | unregister_shrinker(&f2fs_shrinker_info); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2335 | free_sysfs: |
| 2336 | f2fs_unregister_sysfs(); |
Chao Yu | 1dcc336 | 2015-02-05 17:57:31 +0800 | [diff] [blame] | 2337 | free_extent_cache: |
| 2338 | destroy_extent_cache(); |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 2339 | free_checkpoint_caches: |
| 2340 | destroy_checkpoint_caches(); |
Jaegeuk Kim | 7fd9e54 | 2013-11-15 13:55:58 +0900 | [diff] [blame] | 2341 | free_segment_manager_caches: |
| 2342 | destroy_segment_manager_caches(); |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 2343 | free_node_manager_caches: |
| 2344 | destroy_node_manager_caches(); |
| 2345 | free_inodecache: |
| 2346 | destroy_inodecache(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2347 | fail: |
| 2348 | return err; |
| 2349 | } |
| 2350 | |
| 2351 | static void __exit exit_f2fs_fs(void) |
| 2352 | { |
Namjae Jeon | 4589d25 | 2013-01-15 19:58:47 +0900 | [diff] [blame] | 2353 | f2fs_destroy_root_stats(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2354 | unregister_filesystem(&f2fs_fs_type); |
Tiezhu Yang | b8bef79 | 2016-05-18 08:02:25 +0800 | [diff] [blame] | 2355 | unregister_shrinker(&f2fs_shrinker_info); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 2356 | f2fs_unregister_sysfs(); |
Wanpeng Li | fdf6c8b | 2015-03-06 15:00:54 +0800 | [diff] [blame] | 2357 | destroy_extent_cache(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2358 | destroy_checkpoint_caches(); |
Changman Lee | 5dcd8a7 | 2013-12-11 14:32:13 +0900 | [diff] [blame] | 2359 | destroy_segment_manager_caches(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2360 | destroy_node_manager_caches(); |
| 2361 | destroy_inodecache(); |
Jaegeuk Kim | 351f4fb | 2015-01-07 14:09:48 -0800 | [diff] [blame] | 2362 | f2fs_destroy_trace_ios(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | module_init(init_f2fs_fs) |
| 2366 | module_exit(exit_f2fs_fs) |
| 2367 | |
| 2368 | MODULE_AUTHOR("Samsung Electronics's Praesto Team"); |
| 2369 | MODULE_DESCRIPTION("Flash Friendly File System"); |
| 2370 | MODULE_LICENSE("GPL"); |
Jaegeuk Kim | b4b9d34 | 2016-11-04 14:59:15 -0700 | [diff] [blame] | 2371 | |