Chao Yu | 7c1a000 | 2018-09-12 09:16:07 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 2 | /* |
| 3 | * f2fs sysfs interface |
| 4 | * |
| 5 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 6 | * http://www.samsung.com/ |
| 7 | * Copyright (c) 2017 Chao Yu <chao@kernel.org> |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 8 | */ |
Randy Dunlap | cb15d1e | 2018-07-06 20:50:57 -0700 | [diff] [blame] | 9 | #include <linux/compiler.h> |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 10 | #include <linux/proc_fs.h> |
| 11 | #include <linux/f2fs_fs.h> |
Jaegeuk Kim | 299aa41 | 2017-07-13 17:45:21 -0700 | [diff] [blame] | 12 | #include <linux/seq_file.h> |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 13 | |
| 14 | #include "f2fs.h" |
| 15 | #include "segment.h" |
| 16 | #include "gc.h" |
| 17 | |
| 18 | static struct proc_dir_entry *f2fs_proc_root; |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 19 | |
| 20 | /* Sysfs support for f2fs */ |
| 21 | enum { |
| 22 | GC_THREAD, /* struct f2fs_gc_thread */ |
| 23 | SM_INFO, /* struct f2fs_sm_info */ |
| 24 | DCC_INFO, /* struct discard_cmd_control */ |
| 25 | NM_INFO, /* struct f2fs_nm_info */ |
| 26 | F2FS_SBI, /* struct f2fs_sb_info */ |
| 27 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 28 | FAULT_INFO_RATE, /* struct f2fs_fault_info */ |
| 29 | FAULT_INFO_TYPE, /* struct f2fs_fault_info */ |
| 30 | #endif |
Yunlong Song | 80d4214 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 31 | RESERVED_BLOCKS, /* struct f2fs_sb_info */ |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | struct f2fs_attr { |
| 35 | struct attribute attr; |
| 36 | ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *); |
| 37 | ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *, |
| 38 | const char *, size_t); |
| 39 | int struct_type; |
| 40 | int offset; |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 41 | int id; |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type) |
| 45 | { |
| 46 | if (struct_type == GC_THREAD) |
| 47 | return (unsigned char *)sbi->gc_thread; |
| 48 | else if (struct_type == SM_INFO) |
| 49 | return (unsigned char *)SM_I(sbi); |
| 50 | else if (struct_type == DCC_INFO) |
| 51 | return (unsigned char *)SM_I(sbi)->dcc_info; |
| 52 | else if (struct_type == NM_INFO) |
| 53 | return (unsigned char *)NM_I(sbi); |
Chao Yu | daeb433 | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 54 | else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS) |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 55 | return (unsigned char *)sbi; |
| 56 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 57 | else if (struct_type == FAULT_INFO_RATE || |
| 58 | struct_type == FAULT_INFO_TYPE) |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 59 | return (unsigned char *)&F2FS_OPTION(sbi).fault_info; |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 60 | #endif |
| 61 | return NULL; |
| 62 | } |
| 63 | |
Jaegeuk Kim | 8f1572f | 2017-10-24 09:46:54 +0200 | [diff] [blame] | 64 | static ssize_t dirty_segments_show(struct f2fs_attr *a, |
| 65 | struct f2fs_sb_info *sbi, char *buf) |
| 66 | { |
| 67 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
| 68 | (unsigned long long)(dirty_segments(sbi))); |
| 69 | } |
| 70 | |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 71 | static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a, |
| 72 | struct f2fs_sb_info *sbi, char *buf) |
| 73 | { |
| 74 | struct super_block *sb = sbi->sb; |
| 75 | |
| 76 | if (!sb->s_bdev->bd_part) |
| 77 | return snprintf(buf, PAGE_SIZE, "0\n"); |
| 78 | |
| 79 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
| 80 | (unsigned long long)(sbi->kbytes_written + |
| 81 | BD_PART_WRITTEN(sbi))); |
| 82 | } |
| 83 | |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 84 | static ssize_t features_show(struct f2fs_attr *a, |
| 85 | struct f2fs_sb_info *sbi, char *buf) |
| 86 | { |
| 87 | struct super_block *sb = sbi->sb; |
| 88 | int len = 0; |
| 89 | |
| 90 | if (!sb->s_bdev->bd_part) |
| 91 | return snprintf(buf, PAGE_SIZE, "0\n"); |
| 92 | |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 93 | if (f2fs_sb_has_encrypt(sbi)) |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 94 | len += snprintf(buf, PAGE_SIZE - len, "%s", |
| 95 | "encryption"); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 96 | if (f2fs_sb_has_blkzoned(sbi)) |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 97 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 98 | len ? ", " : "", "blkzoned"); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 99 | if (f2fs_sb_has_extra_attr(sbi)) |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 100 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 101 | len ? ", " : "", "extra_attr"); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 102 | if (f2fs_sb_has_project_quota(sbi)) |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 103 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 104 | len ? ", " : "", "projquota"); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 105 | if (f2fs_sb_has_inode_chksum(sbi)) |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 106 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 107 | len ? ", " : "", "inode_checksum"); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 108 | if (f2fs_sb_has_flexible_inline_xattr(sbi)) |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 109 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 110 | len ? ", " : "", "flexible_inline_xattr"); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 111 | if (f2fs_sb_has_quota_ino(sbi)) |
Jaegeuk Kim | 234a968 | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 112 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 113 | len ? ", " : "", "quota_ino"); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 114 | if (f2fs_sb_has_inode_crtime(sbi)) |
Chao Yu | 1c1d35d | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 115 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 116 | len ? ", " : "", "inode_crtime"); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 117 | if (f2fs_sb_has_lost_found(sbi)) |
Sheng Yong | b7c409d | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 118 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 119 | len ? ", " : "", "lost_found"); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 120 | if (f2fs_sb_has_sb_chksum(sbi)) |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 121 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 122 | len ? ", " : "", "sb_checksum"); |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 123 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 124 | return len; |
| 125 | } |
| 126 | |
Yunlong Song | 80d4214 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 127 | static ssize_t current_reserved_blocks_show(struct f2fs_attr *a, |
| 128 | struct f2fs_sb_info *sbi, char *buf) |
| 129 | { |
| 130 | return snprintf(buf, PAGE_SIZE, "%u\n", sbi->current_reserved_blocks); |
| 131 | } |
| 132 | |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 133 | static ssize_t f2fs_sbi_show(struct f2fs_attr *a, |
| 134 | struct f2fs_sb_info *sbi, char *buf) |
| 135 | { |
| 136 | unsigned char *ptr = NULL; |
| 137 | unsigned int *ui; |
| 138 | |
| 139 | ptr = __struct_ptr(sbi, a->struct_type); |
| 140 | if (!ptr) |
| 141 | return -EINVAL; |
| 142 | |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 143 | if (!strcmp(a->attr.name, "extension_list")) { |
| 144 | __u8 (*extlist)[F2FS_EXTENSION_LEN] = |
| 145 | sbi->raw_super->extension_list; |
Chao Yu | b6a06cb | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 146 | int cold_count = le32_to_cpu(sbi->raw_super->extension_count); |
| 147 | int hot_count = sbi->raw_super->hot_ext_count; |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 148 | int len = 0, i; |
| 149 | |
Chao Yu | b6a06cb | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 150 | len += snprintf(buf + len, PAGE_SIZE - len, |
Colin Ian King | 4580038 | 2018-04-30 16:27:44 +0100 | [diff] [blame] | 151 | "cold file extension:\n"); |
Chao Yu | b6a06cb | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 152 | for (i = 0; i < cold_count; i++) |
| 153 | len += snprintf(buf + len, PAGE_SIZE - len, "%s\n", |
| 154 | extlist[i]); |
| 155 | |
| 156 | len += snprintf(buf + len, PAGE_SIZE - len, |
Colin Ian King | 4580038 | 2018-04-30 16:27:44 +0100 | [diff] [blame] | 157 | "hot file extension:\n"); |
Chao Yu | b6a06cb | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 158 | for (i = cold_count; i < cold_count + hot_count; i++) |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 159 | len += snprintf(buf + len, PAGE_SIZE - len, "%s\n", |
| 160 | extlist[i]); |
| 161 | return len; |
| 162 | } |
| 163 | |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 164 | ui = (unsigned int *)(ptr + a->offset); |
| 165 | |
| 166 | return snprintf(buf, PAGE_SIZE, "%u\n", *ui); |
| 167 | } |
| 168 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 169 | static ssize_t __sbi_store(struct f2fs_attr *a, |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 170 | struct f2fs_sb_info *sbi, |
| 171 | const char *buf, size_t count) |
| 172 | { |
| 173 | unsigned char *ptr; |
| 174 | unsigned long t; |
| 175 | unsigned int *ui; |
| 176 | ssize_t ret; |
| 177 | |
| 178 | ptr = __struct_ptr(sbi, a->struct_type); |
| 179 | if (!ptr) |
| 180 | return -EINVAL; |
| 181 | |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 182 | if (!strcmp(a->attr.name, "extension_list")) { |
| 183 | const char *name = strim((char *)buf); |
Chao Yu | b6a06cb | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 184 | bool set = true, hot; |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 185 | |
Chao Yu | b6a06cb | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 186 | if (!strncmp(name, "[h]", 3)) |
| 187 | hot = true; |
| 188 | else if (!strncmp(name, "[c]", 3)) |
| 189 | hot = false; |
| 190 | else |
| 191 | return -EINVAL; |
| 192 | |
| 193 | name += 3; |
| 194 | |
| 195 | if (*name == '!') { |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 196 | name++; |
| 197 | set = false; |
| 198 | } |
| 199 | |
| 200 | if (strlen(name) >= F2FS_EXTENSION_LEN) |
| 201 | return -EINVAL; |
| 202 | |
| 203 | down_write(&sbi->sb_lock); |
| 204 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 205 | ret = f2fs_update_extension_list(sbi, name, hot, set); |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 206 | if (ret) |
| 207 | goto out; |
| 208 | |
| 209 | ret = f2fs_commit_super(sbi, false); |
| 210 | if (ret) |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 211 | f2fs_update_extension_list(sbi, name, hot, !set); |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 212 | out: |
| 213 | up_write(&sbi->sb_lock); |
| 214 | return ret ? ret : count; |
| 215 | } |
| 216 | |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 217 | ui = (unsigned int *)(ptr + a->offset); |
| 218 | |
| 219 | ret = kstrtoul(skip_spaces(buf), 0, &t); |
| 220 | if (ret < 0) |
| 221 | return ret; |
| 222 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 223 | if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX)) |
| 224 | return -EINVAL; |
| 225 | #endif |
Chao Yu | daeb433 | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 226 | if (a->struct_type == RESERVED_BLOCKS) { |
| 227 | spin_lock(&sbi->stat_lock); |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 228 | if (t > (unsigned long)(sbi->user_block_count - |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 229 | F2FS_OPTION(sbi).root_reserved_blocks)) { |
Chao Yu | daeb433 | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 230 | spin_unlock(&sbi->stat_lock); |
| 231 | return -EINVAL; |
| 232 | } |
| 233 | *ui = t; |
Yunlong Song | 80d4214 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 234 | sbi->current_reserved_blocks = min(sbi->reserved_blocks, |
| 235 | sbi->user_block_count - valid_user_blocks(sbi)); |
Chao Yu | daeb433 | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 236 | spin_unlock(&sbi->stat_lock); |
| 237 | return count; |
| 238 | } |
Chao Yu | 969d1b1 | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 239 | |
| 240 | if (!strcmp(a->attr.name, "discard_granularity")) { |
Chao Yu | 969d1b1 | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 241 | if (t == 0 || t > MAX_PLIST_NUM) |
| 242 | return -EINVAL; |
| 243 | if (t == *ui) |
| 244 | return count; |
Chao Yu | 80647e5 | 2017-09-12 14:25:35 +0800 | [diff] [blame] | 245 | *ui = t; |
Chao Yu | 969d1b1 | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 246 | return count; |
| 247 | } |
| 248 | |
Chao Yu | 3465557 | 2018-10-25 16:19:28 +0800 | [diff] [blame^] | 249 | if (!strcmp(a->attr.name, "migration_granularity")) { |
| 250 | if (t == 0 || t > sbi->segs_per_sec) |
| 251 | return -EINVAL; |
| 252 | } |
| 253 | |
Chao Yu | 377224c | 2018-04-09 10:25:23 +0800 | [diff] [blame] | 254 | if (!strcmp(a->attr.name, "trim_sections")) |
| 255 | return -EINVAL; |
| 256 | |
Jaegeuk Kim | 5b0e953 | 2018-05-07 14:22:40 -0700 | [diff] [blame] | 257 | if (!strcmp(a->attr.name, "gc_urgent")) { |
| 258 | if (t >= 1) { |
| 259 | sbi->gc_mode = GC_URGENT; |
| 260 | if (sbi->gc_thread) { |
Sheng Yong | a690eff | 2018-08-05 12:45:35 +0800 | [diff] [blame] | 261 | sbi->gc_thread->gc_wake = 1; |
Jaegeuk Kim | 5b0e953 | 2018-05-07 14:22:40 -0700 | [diff] [blame] | 262 | wake_up_interruptible_all( |
| 263 | &sbi->gc_thread->gc_wait_queue_head); |
| 264 | wake_up_discard_thread(sbi, true); |
| 265 | } |
| 266 | } else { |
| 267 | sbi->gc_mode = GC_NORMAL; |
| 268 | } |
| 269 | return count; |
| 270 | } |
| 271 | if (!strcmp(a->attr.name, "gc_idle")) { |
| 272 | if (t == GC_IDLE_CB) |
| 273 | sbi->gc_mode = GC_IDLE_CB; |
| 274 | else if (t == GC_IDLE_GREEDY) |
| 275 | sbi->gc_mode = GC_IDLE_GREEDY; |
| 276 | else |
| 277 | sbi->gc_mode = GC_NORMAL; |
| 278 | return count; |
| 279 | } |
| 280 | |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 281 | *ui = t; |
Chao Yu | b0af6d4 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 282 | |
| 283 | if (!strcmp(a->attr.name, "iostat_enable") && *ui == 0) |
| 284 | f2fs_reset_iostat(sbi); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 285 | return count; |
| 286 | } |
| 287 | |
Chao Yu | 250dbf5 | 2018-05-28 16:57:32 +0800 | [diff] [blame] | 288 | static ssize_t f2fs_sbi_store(struct f2fs_attr *a, |
| 289 | struct f2fs_sb_info *sbi, |
| 290 | const char *buf, size_t count) |
| 291 | { |
| 292 | ssize_t ret; |
| 293 | bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") || |
| 294 | a->struct_type == GC_THREAD); |
| 295 | |
Jaegeuk Kim | a1933c0 | 2018-07-15 09:58:08 +0900 | [diff] [blame] | 296 | if (gc_entry) { |
| 297 | if (!down_read_trylock(&sbi->sb->s_umount)) |
| 298 | return -EAGAIN; |
| 299 | } |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 300 | ret = __sbi_store(a, sbi, buf, count); |
Chao Yu | 250dbf5 | 2018-05-28 16:57:32 +0800 | [diff] [blame] | 301 | if (gc_entry) |
| 302 | up_read(&sbi->sb->s_umount); |
| 303 | |
| 304 | return ret; |
| 305 | } |
| 306 | |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 307 | static ssize_t f2fs_attr_show(struct kobject *kobj, |
| 308 | struct attribute *attr, char *buf) |
| 309 | { |
| 310 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 311 | s_kobj); |
| 312 | struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); |
| 313 | |
| 314 | return a->show ? a->show(a, sbi, buf) : 0; |
| 315 | } |
| 316 | |
| 317 | static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr, |
| 318 | const char *buf, size_t len) |
| 319 | { |
| 320 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 321 | s_kobj); |
| 322 | struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); |
| 323 | |
| 324 | return a->store ? a->store(a, sbi, buf, len) : 0; |
| 325 | } |
| 326 | |
| 327 | static void f2fs_sb_release(struct kobject *kobj) |
| 328 | { |
| 329 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 330 | s_kobj); |
| 331 | complete(&sbi->s_kobj_unregister); |
| 332 | } |
| 333 | |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 334 | enum feat_id { |
| 335 | FEAT_CRYPTO = 0, |
| 336 | FEAT_BLKZONED, |
| 337 | FEAT_ATOMIC_WRITE, |
| 338 | FEAT_EXTRA_ATTR, |
| 339 | FEAT_PROJECT_QUOTA, |
| 340 | FEAT_INODE_CHECKSUM, |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 341 | FEAT_FLEXIBLE_INLINE_XATTR, |
Jaegeuk Kim | 234a968 | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 342 | FEAT_QUOTA_INO, |
Chao Yu | 1c1d35d | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 343 | FEAT_INODE_CRTIME, |
Sheng Yong | b7c409d | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 344 | FEAT_LOST_FOUND, |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 345 | FEAT_SB_CHECKSUM, |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 346 | }; |
| 347 | |
| 348 | static ssize_t f2fs_feature_show(struct f2fs_attr *a, |
| 349 | struct f2fs_sb_info *sbi, char *buf) |
| 350 | { |
| 351 | switch (a->id) { |
| 352 | case FEAT_CRYPTO: |
| 353 | case FEAT_BLKZONED: |
| 354 | case FEAT_ATOMIC_WRITE: |
| 355 | case FEAT_EXTRA_ATTR: |
| 356 | case FEAT_PROJECT_QUOTA: |
| 357 | case FEAT_INODE_CHECKSUM: |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 358 | case FEAT_FLEXIBLE_INLINE_XATTR: |
Jaegeuk Kim | 234a968 | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 359 | case FEAT_QUOTA_INO: |
Chao Yu | 1c1d35d | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 360 | case FEAT_INODE_CRTIME: |
Sheng Yong | b7c409d | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 361 | case FEAT_LOST_FOUND: |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 362 | case FEAT_SB_CHECKSUM: |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 363 | return snprintf(buf, PAGE_SIZE, "supported\n"); |
| 364 | } |
| 365 | return 0; |
| 366 | } |
| 367 | |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 368 | #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \ |
| 369 | static struct f2fs_attr f2fs_attr_##_name = { \ |
| 370 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 371 | .show = _show, \ |
| 372 | .store = _store, \ |
| 373 | .struct_type = _struct_type, \ |
| 374 | .offset = _offset \ |
| 375 | } |
| 376 | |
| 377 | #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \ |
| 378 | F2FS_ATTR_OFFSET(struct_type, name, 0644, \ |
| 379 | f2fs_sbi_show, f2fs_sbi_store, \ |
| 380 | offsetof(struct struct_name, elname)) |
| 381 | |
| 382 | #define F2FS_GENERAL_RO_ATTR(name) \ |
| 383 | static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL) |
| 384 | |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 385 | #define F2FS_FEATURE_RO_ATTR(_name, _id) \ |
| 386 | static struct f2fs_attr f2fs_attr_##_name = { \ |
| 387 | .attr = {.name = __stringify(_name), .mode = 0444 }, \ |
| 388 | .show = f2fs_feature_show, \ |
| 389 | .id = _id, \ |
| 390 | } |
| 391 | |
Jaegeuk Kim | d9872a6 | 2017-08-06 22:09:00 -0700 | [diff] [blame] | 392 | F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time, |
| 393 | urgent_sleep_time); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 394 | F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time); |
| 395 | F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time); |
| 396 | F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); |
Jaegeuk Kim | 5b0e953 | 2018-05-07 14:22:40 -0700 | [diff] [blame] | 397 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode); |
| 398 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 399 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); |
| 400 | F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards); |
Chao Yu | 969d1b1 | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 401 | F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity); |
Chao Yu | daeb433 | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 402 | F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 403 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections); |
| 404 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); |
| 405 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); |
| 406 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks); |
Jaegeuk Kim | 853137c | 2018-08-09 17:53:34 -0700 | [diff] [blame] | 407 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 408 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks); |
Chao Yu | a2a12b6 | 2017-10-28 16:52:33 +0800 | [diff] [blame] | 409 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 410 | F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh); |
| 411 | F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages); |
| 412 | F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio); |
| 413 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); |
Chao Yu | 3465557 | 2018-10-25 16:19:28 +0800 | [diff] [blame^] | 414 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 415 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); |
| 416 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]); |
| 417 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]); |
Sahitya Tummala | a7d10cf | 2018-09-19 14:18:47 +0530 | [diff] [blame] | 418 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval, |
| 419 | interval_time[DISCARD_TIME]); |
| 420 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]); |
Chao Yu | b0af6d4 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 421 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable); |
Sheng Yong | f6df8f2 | 2017-11-22 18:23:38 +0800 | [diff] [blame] | 422 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra); |
Jaegeuk Kim | 1ad71a2 | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 423 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold); |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 424 | F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 425 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 426 | F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate); |
| 427 | F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type); |
| 428 | #endif |
Jaegeuk Kim | 8f1572f | 2017-10-24 09:46:54 +0200 | [diff] [blame] | 429 | F2FS_GENERAL_RO_ATTR(dirty_segments); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 430 | F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 431 | F2FS_GENERAL_RO_ATTR(features); |
Yunlong Song | 80d4214 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 432 | F2FS_GENERAL_RO_ATTR(current_reserved_blocks); |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 433 | |
| 434 | #ifdef CONFIG_F2FS_FS_ENCRYPTION |
| 435 | F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO); |
| 436 | #endif |
| 437 | #ifdef CONFIG_BLK_DEV_ZONED |
| 438 | F2FS_FEATURE_RO_ATTR(block_zoned, FEAT_BLKZONED); |
| 439 | #endif |
| 440 | F2FS_FEATURE_RO_ATTR(atomic_write, FEAT_ATOMIC_WRITE); |
| 441 | F2FS_FEATURE_RO_ATTR(extra_attr, FEAT_EXTRA_ATTR); |
| 442 | F2FS_FEATURE_RO_ATTR(project_quota, FEAT_PROJECT_QUOTA); |
| 443 | F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM); |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 444 | F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR); |
Jaegeuk Kim | 234a968 | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 445 | F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO); |
Chao Yu | 1c1d35d | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 446 | F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME); |
Sheng Yong | b7c409d | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 447 | F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND); |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 448 | F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 449 | |
| 450 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) |
| 451 | static struct attribute *f2fs_attrs[] = { |
Jaegeuk Kim | d9872a6 | 2017-08-06 22:09:00 -0700 | [diff] [blame] | 452 | ATTR_LIST(gc_urgent_sleep_time), |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 453 | ATTR_LIST(gc_min_sleep_time), |
| 454 | ATTR_LIST(gc_max_sleep_time), |
| 455 | ATTR_LIST(gc_no_gc_sleep_time), |
| 456 | ATTR_LIST(gc_idle), |
Jaegeuk Kim | d9872a6 | 2017-08-06 22:09:00 -0700 | [diff] [blame] | 457 | ATTR_LIST(gc_urgent), |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 458 | ATTR_LIST(reclaim_segments), |
| 459 | ATTR_LIST(max_small_discards), |
Chao Yu | 969d1b1 | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 460 | ATTR_LIST(discard_granularity), |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 461 | ATTR_LIST(batched_trim_sections), |
| 462 | ATTR_LIST(ipu_policy), |
| 463 | ATTR_LIST(min_ipu_util), |
| 464 | ATTR_LIST(min_fsync_blocks), |
Jaegeuk Kim | 853137c | 2018-08-09 17:53:34 -0700 | [diff] [blame] | 465 | ATTR_LIST(min_seq_blocks), |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 466 | ATTR_LIST(min_hot_blocks), |
Chao Yu | a2a12b6 | 2017-10-28 16:52:33 +0800 | [diff] [blame] | 467 | ATTR_LIST(min_ssr_sections), |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 468 | ATTR_LIST(max_victim_search), |
Chao Yu | 3465557 | 2018-10-25 16:19:28 +0800 | [diff] [blame^] | 469 | ATTR_LIST(migration_granularity), |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 470 | ATTR_LIST(dir_level), |
| 471 | ATTR_LIST(ram_thresh), |
| 472 | ATTR_LIST(ra_nid_pages), |
| 473 | ATTR_LIST(dirty_nats_ratio), |
| 474 | ATTR_LIST(cp_interval), |
| 475 | ATTR_LIST(idle_interval), |
Sahitya Tummala | a7d10cf | 2018-09-19 14:18:47 +0530 | [diff] [blame] | 476 | ATTR_LIST(discard_idle_interval), |
| 477 | ATTR_LIST(gc_idle_interval), |
Chao Yu | b0af6d4 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 478 | ATTR_LIST(iostat_enable), |
Sheng Yong | f6df8f2 | 2017-11-22 18:23:38 +0800 | [diff] [blame] | 479 | ATTR_LIST(readdir_ra), |
Jaegeuk Kim | 1ad71a2 | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 480 | ATTR_LIST(gc_pin_file_thresh), |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 481 | ATTR_LIST(extension_list), |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 482 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 483 | ATTR_LIST(inject_rate), |
| 484 | ATTR_LIST(inject_type), |
| 485 | #endif |
Jaegeuk Kim | 8f1572f | 2017-10-24 09:46:54 +0200 | [diff] [blame] | 486 | ATTR_LIST(dirty_segments), |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 487 | ATTR_LIST(lifetime_write_kbytes), |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 488 | ATTR_LIST(features), |
Chao Yu | daeb433 | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 489 | ATTR_LIST(reserved_blocks), |
Yunlong Song | 80d4214 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 490 | ATTR_LIST(current_reserved_blocks), |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 491 | NULL, |
| 492 | }; |
| 493 | |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 494 | static struct attribute *f2fs_feat_attrs[] = { |
| 495 | #ifdef CONFIG_F2FS_FS_ENCRYPTION |
| 496 | ATTR_LIST(encryption), |
| 497 | #endif |
| 498 | #ifdef CONFIG_BLK_DEV_ZONED |
| 499 | ATTR_LIST(block_zoned), |
| 500 | #endif |
| 501 | ATTR_LIST(atomic_write), |
| 502 | ATTR_LIST(extra_attr), |
| 503 | ATTR_LIST(project_quota), |
| 504 | ATTR_LIST(inode_checksum), |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 505 | ATTR_LIST(flexible_inline_xattr), |
Jaegeuk Kim | 234a968 | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 506 | ATTR_LIST(quota_ino), |
Chao Yu | 1c1d35d | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 507 | ATTR_LIST(inode_crtime), |
Sheng Yong | b7c409d | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 508 | ATTR_LIST(lost_found), |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 509 | ATTR_LIST(sb_checksum), |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 510 | NULL, |
| 511 | }; |
| 512 | |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 513 | static const struct sysfs_ops f2fs_attr_ops = { |
| 514 | .show = f2fs_attr_show, |
| 515 | .store = f2fs_attr_store, |
| 516 | }; |
| 517 | |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 518 | static struct kobj_type f2fs_sb_ktype = { |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 519 | .default_attrs = f2fs_attrs, |
| 520 | .sysfs_ops = &f2fs_attr_ops, |
| 521 | .release = f2fs_sb_release, |
| 522 | }; |
| 523 | |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 524 | static struct kobj_type f2fs_ktype = { |
| 525 | .sysfs_ops = &f2fs_attr_ops, |
| 526 | }; |
| 527 | |
| 528 | static struct kset f2fs_kset = { |
| 529 | .kobj = {.ktype = &f2fs_ktype}, |
| 530 | }; |
| 531 | |
| 532 | static struct kobj_type f2fs_feat_ktype = { |
| 533 | .default_attrs = f2fs_feat_attrs, |
| 534 | .sysfs_ops = &f2fs_attr_ops, |
| 535 | }; |
| 536 | |
| 537 | static struct kobject f2fs_feat = { |
| 538 | .kset = &f2fs_kset, |
| 539 | }; |
| 540 | |
Randy Dunlap | cb15d1e | 2018-07-06 20:50:57 -0700 | [diff] [blame] | 541 | static int __maybe_unused segment_info_seq_show(struct seq_file *seq, |
| 542 | void *offset) |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 543 | { |
| 544 | struct super_block *sb = seq->private; |
| 545 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 546 | unsigned int total_segs = |
| 547 | le32_to_cpu(sbi->raw_super->segment_count_main); |
| 548 | int i; |
| 549 | |
| 550 | seq_puts(seq, "format: segment_type|valid_blocks\n" |
| 551 | "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); |
| 552 | |
| 553 | for (i = 0; i < total_segs; i++) { |
| 554 | struct seg_entry *se = get_seg_entry(sbi, i); |
| 555 | |
| 556 | if ((i % 10) == 0) |
| 557 | seq_printf(seq, "%-10d", i); |
| 558 | seq_printf(seq, "%d|%-3u", se->type, |
| 559 | get_valid_blocks(sbi, i, false)); |
| 560 | if ((i % 10) == 9 || i == (total_segs - 1)) |
| 561 | seq_putc(seq, '\n'); |
| 562 | else |
| 563 | seq_putc(seq, ' '); |
| 564 | } |
| 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
Randy Dunlap | cb15d1e | 2018-07-06 20:50:57 -0700 | [diff] [blame] | 569 | static int __maybe_unused segment_bits_seq_show(struct seq_file *seq, |
| 570 | void *offset) |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 571 | { |
| 572 | struct super_block *sb = seq->private; |
| 573 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 574 | unsigned int total_segs = |
| 575 | le32_to_cpu(sbi->raw_super->segment_count_main); |
| 576 | int i, j; |
| 577 | |
| 578 | seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n" |
| 579 | "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); |
| 580 | |
| 581 | for (i = 0; i < total_segs; i++) { |
| 582 | struct seg_entry *se = get_seg_entry(sbi, i); |
| 583 | |
| 584 | seq_printf(seq, "%-10d", i); |
| 585 | seq_printf(seq, "%d|%-3u|", se->type, |
| 586 | get_valid_blocks(sbi, i, false)); |
| 587 | for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++) |
| 588 | seq_printf(seq, " %.2x", se->cur_valid_map[j]); |
| 589 | seq_putc(seq, '\n'); |
| 590 | } |
| 591 | return 0; |
| 592 | } |
| 593 | |
Randy Dunlap | cb15d1e | 2018-07-06 20:50:57 -0700 | [diff] [blame] | 594 | static int __maybe_unused iostat_info_seq_show(struct seq_file *seq, |
| 595 | void *offset) |
Chao Yu | b0af6d4 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 596 | { |
| 597 | struct super_block *sb = seq->private; |
| 598 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 599 | time64_t now = ktime_get_real_seconds(); |
| 600 | |
| 601 | if (!sbi->iostat_enable) |
| 602 | return 0; |
| 603 | |
| 604 | seq_printf(seq, "time: %-16llu\n", now); |
| 605 | |
| 606 | /* print app IOs */ |
| 607 | seq_printf(seq, "app buffered: %-16llu\n", |
| 608 | sbi->write_iostat[APP_BUFFERED_IO]); |
| 609 | seq_printf(seq, "app direct: %-16llu\n", |
| 610 | sbi->write_iostat[APP_DIRECT_IO]); |
| 611 | seq_printf(seq, "app mapped: %-16llu\n", |
| 612 | sbi->write_iostat[APP_MAPPED_IO]); |
| 613 | |
| 614 | /* print fs IOs */ |
| 615 | seq_printf(seq, "fs data: %-16llu\n", |
| 616 | sbi->write_iostat[FS_DATA_IO]); |
| 617 | seq_printf(seq, "fs node: %-16llu\n", |
| 618 | sbi->write_iostat[FS_NODE_IO]); |
| 619 | seq_printf(seq, "fs meta: %-16llu\n", |
| 620 | sbi->write_iostat[FS_META_IO]); |
| 621 | seq_printf(seq, "fs gc data: %-16llu\n", |
| 622 | sbi->write_iostat[FS_GC_DATA_IO]); |
| 623 | seq_printf(seq, "fs gc node: %-16llu\n", |
| 624 | sbi->write_iostat[FS_GC_NODE_IO]); |
| 625 | seq_printf(seq, "fs cp data: %-16llu\n", |
| 626 | sbi->write_iostat[FS_CP_DATA_IO]); |
| 627 | seq_printf(seq, "fs cp node: %-16llu\n", |
| 628 | sbi->write_iostat[FS_CP_NODE_IO]); |
| 629 | seq_printf(seq, "fs cp meta: %-16llu\n", |
| 630 | sbi->write_iostat[FS_CP_META_IO]); |
| 631 | seq_printf(seq, "fs discard: %-16llu\n", |
| 632 | sbi->write_iostat[FS_DISCARD]); |
| 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
Yunlong Song | 970e348 | 2018-07-23 22:10:22 +0800 | [diff] [blame] | 637 | static int __maybe_unused victim_bits_seq_show(struct seq_file *seq, |
| 638 | void *offset) |
| 639 | { |
| 640 | struct super_block *sb = seq->private; |
| 641 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 642 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); |
| 643 | int i; |
| 644 | |
| 645 | seq_puts(seq, "format: victim_secmap bitmaps\n"); |
| 646 | |
| 647 | for (i = 0; i < MAIN_SECS(sbi); i++) { |
| 648 | if ((i % 10) == 0) |
| 649 | seq_printf(seq, "%-10d", i); |
| 650 | seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0); |
| 651 | if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1)) |
| 652 | seq_putc(seq, '\n'); |
| 653 | else |
| 654 | seq_putc(seq, ' '); |
| 655 | } |
| 656 | return 0; |
| 657 | } |
| 658 | |
Jaegeuk Kim | dc6b205 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 659 | int __init f2fs_init_sysfs(void) |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 660 | { |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 661 | int ret; |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 662 | |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 663 | kobject_set_name(&f2fs_kset.kobj, "f2fs"); |
| 664 | f2fs_kset.kobj.parent = fs_kobj; |
| 665 | ret = kset_register(&f2fs_kset); |
| 666 | if (ret) |
| 667 | return ret; |
| 668 | |
| 669 | ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype, |
| 670 | NULL, "features"); |
| 671 | if (ret) |
| 672 | kset_unregister(&f2fs_kset); |
| 673 | else |
| 674 | f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); |
| 675 | return ret; |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 676 | } |
| 677 | |
Jaegeuk Kim | dc6b205 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 678 | void f2fs_exit_sysfs(void) |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 679 | { |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 680 | kobject_put(&f2fs_feat); |
| 681 | kset_unregister(&f2fs_kset); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 682 | remove_proc_entry("fs/f2fs", NULL); |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 683 | f2fs_proc_root = NULL; |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 684 | } |
| 685 | |
Jaegeuk Kim | dc6b205 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 686 | int f2fs_register_sysfs(struct f2fs_sb_info *sbi) |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 687 | { |
| 688 | struct super_block *sb = sbi->sb; |
| 689 | int err; |
| 690 | |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 691 | sbi->s_kobj.kset = &f2fs_kset; |
| 692 | init_completion(&sbi->s_kobj_unregister); |
| 693 | err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL, |
| 694 | "%s", sb->s_id); |
| 695 | if (err) |
| 696 | return err; |
| 697 | |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 698 | if (f2fs_proc_root) |
| 699 | sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); |
| 700 | |
| 701 | if (sbi->s_proc) { |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 702 | proc_create_single_data("segment_info", S_IRUGO, sbi->s_proc, |
| 703 | segment_info_seq_show, sb); |
| 704 | proc_create_single_data("segment_bits", S_IRUGO, sbi->s_proc, |
| 705 | segment_bits_seq_show, sb); |
| 706 | proc_create_single_data("iostat_info", S_IRUGO, sbi->s_proc, |
| 707 | iostat_info_seq_show, sb); |
Yunlong Song | 970e348 | 2018-07-23 22:10:22 +0800 | [diff] [blame] | 708 | proc_create_single_data("victim_bits", S_IRUGO, sbi->s_proc, |
| 709 | victim_bits_seq_show, sb); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 710 | } |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 711 | return 0; |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 712 | } |
| 713 | |
Jaegeuk Kim | dc6b205 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 714 | void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 715 | { |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 716 | if (sbi->s_proc) { |
Chao Yu | b0af6d4 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 717 | remove_proc_entry("iostat_info", sbi->s_proc); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 718 | remove_proc_entry("segment_info", sbi->s_proc); |
| 719 | remove_proc_entry("segment_bits", sbi->s_proc); |
Yunlong Song | 970e348 | 2018-07-23 22:10:22 +0800 | [diff] [blame] | 720 | remove_proc_entry("victim_bits", sbi->s_proc); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 721 | remove_proc_entry(sbi->sb->s_id, f2fs_proc_root); |
| 722 | } |
Jaegeuk Kim | bf9e697 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 723 | kobject_del(&sbi->s_kobj); |
Chao Yu | 8ceffcb | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 724 | } |