Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 1 | /* |
| 2 | * f2fs sysfs interface |
| 3 | * |
| 4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com/ |
| 6 | * Copyright (c) 2017 Chao Yu <chao@kernel.org> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
Randy Dunlap | bc1ad77 | 2018-07-06 20:50:57 -0700 | [diff] [blame] | 12 | #include <linux/compiler.h> |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 13 | #include <linux/proc_fs.h> |
| 14 | #include <linux/f2fs_fs.h> |
Jaegeuk Kim | df72684 | 2017-07-13 17:45:21 -0700 | [diff] [blame] | 15 | #include <linux/seq_file.h> |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 16 | |
| 17 | #include "f2fs.h" |
| 18 | #include "segment.h" |
| 19 | #include "gc.h" |
| 20 | |
| 21 | static struct proc_dir_entry *f2fs_proc_root; |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 22 | |
| 23 | /* Sysfs support for f2fs */ |
| 24 | enum { |
| 25 | GC_THREAD, /* struct f2fs_gc_thread */ |
| 26 | SM_INFO, /* struct f2fs_sm_info */ |
| 27 | DCC_INFO, /* struct discard_cmd_control */ |
| 28 | NM_INFO, /* struct f2fs_nm_info */ |
| 29 | F2FS_SBI, /* struct f2fs_sb_info */ |
| 30 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 31 | FAULT_INFO_RATE, /* struct f2fs_fault_info */ |
| 32 | FAULT_INFO_TYPE, /* struct f2fs_fault_info */ |
| 33 | #endif |
Yunlong Song | 68ab6f8 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 34 | RESERVED_BLOCKS, /* struct f2fs_sb_info */ |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | struct f2fs_attr { |
| 38 | struct attribute attr; |
| 39 | ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *); |
| 40 | ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *, |
| 41 | const char *, size_t); |
| 42 | int struct_type; |
| 43 | int offset; |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 44 | int id; |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type) |
| 48 | { |
| 49 | if (struct_type == GC_THREAD) |
| 50 | return (unsigned char *)sbi->gc_thread; |
| 51 | else if (struct_type == SM_INFO) |
| 52 | return (unsigned char *)SM_I(sbi); |
| 53 | else if (struct_type == DCC_INFO) |
| 54 | return (unsigned char *)SM_I(sbi)->dcc_info; |
| 55 | else if (struct_type == NM_INFO) |
| 56 | return (unsigned char *)NM_I(sbi); |
Chao Yu | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 57 | else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS) |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 58 | return (unsigned char *)sbi; |
| 59 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 60 | else if (struct_type == FAULT_INFO_RATE || |
| 61 | struct_type == FAULT_INFO_TYPE) |
Chao Yu | e9a50e6 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 62 | return (unsigned char *)&F2FS_OPTION(sbi).fault_info; |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 63 | #endif |
| 64 | return NULL; |
| 65 | } |
| 66 | |
Jaegeuk Kim | af1cc1e | 2017-10-24 09:46:54 +0200 | [diff] [blame] | 67 | static ssize_t dirty_segments_show(struct f2fs_attr *a, |
| 68 | struct f2fs_sb_info *sbi, char *buf) |
| 69 | { |
| 70 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
| 71 | (unsigned long long)(dirty_segments(sbi))); |
| 72 | } |
| 73 | |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 74 | static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a, |
| 75 | struct f2fs_sb_info *sbi, char *buf) |
| 76 | { |
| 77 | struct super_block *sb = sbi->sb; |
| 78 | |
| 79 | if (!sb->s_bdev->bd_part) |
| 80 | return snprintf(buf, PAGE_SIZE, "0\n"); |
| 81 | |
| 82 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
| 83 | (unsigned long long)(sbi->kbytes_written + |
| 84 | BD_PART_WRITTEN(sbi))); |
| 85 | } |
| 86 | |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 87 | static ssize_t features_show(struct f2fs_attr *a, |
| 88 | struct f2fs_sb_info *sbi, char *buf) |
| 89 | { |
| 90 | struct super_block *sb = sbi->sb; |
| 91 | int len = 0; |
| 92 | |
| 93 | if (!sb->s_bdev->bd_part) |
| 94 | return snprintf(buf, PAGE_SIZE, "0\n"); |
| 95 | |
Sheng Yong | 770611e | 2018-02-06 12:31:17 +0800 | [diff] [blame] | 96 | if (f2fs_sb_has_encrypt(sb)) |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 97 | len += snprintf(buf, PAGE_SIZE - len, "%s", |
| 98 | "encryption"); |
Sheng Yong | 770611e | 2018-02-06 12:31:17 +0800 | [diff] [blame] | 99 | if (f2fs_sb_has_blkzoned(sb)) |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 100 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 101 | len ? ", " : "", "blkzoned"); |
| 102 | if (f2fs_sb_has_extra_attr(sb)) |
| 103 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 104 | len ? ", " : "", "extra_attr"); |
| 105 | if (f2fs_sb_has_project_quota(sb)) |
| 106 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 107 | len ? ", " : "", "projquota"); |
| 108 | if (f2fs_sb_has_inode_chksum(sb)) |
| 109 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 110 | len ? ", " : "", "inode_checksum"); |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 111 | if (f2fs_sb_has_flexible_inline_xattr(sb)) |
| 112 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 113 | len ? ", " : "", "flexible_inline_xattr"); |
Jaegeuk Kim | d4c292d | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 114 | if (f2fs_sb_has_quota_ino(sb)) |
| 115 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 116 | len ? ", " : "", "quota_ino"); |
Chao Yu | 71f8f04 | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 117 | if (f2fs_sb_has_inode_crtime(sb)) |
| 118 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 119 | len ? ", " : "", "inode_crtime"); |
Sheng Yong | 9b880fe | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 120 | if (f2fs_sb_has_lost_found(sb)) |
| 121 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 122 | len ? ", " : "", "lost_found"); |
Jaegeuk Kim | 3b3d1b8 | 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 | 68ab6f8 | 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 | 57fb30c | 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 | 1e72cb2 | 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 | ac734c4 | 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 | 1e72cb2 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 148 | int len = 0, i; |
| 149 | |
Chao Yu | ac734c4 | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 150 | len += snprintf(buf + len, PAGE_SIZE - len, |
Colin Ian King | 0aca14f | 2018-04-30 16:27:44 +0100 | [diff] [blame] | 151 | "cold file extension:\n"); |
Chao Yu | ac734c4 | 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 | 0aca14f | 2018-04-30 16:27:44 +0100 | [diff] [blame] | 157 | "hot file extension:\n"); |
Chao Yu | ac734c4 | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 158 | for (i = cold_count; i < cold_count + hot_count; i++) |
Chao Yu | 1e72cb2 | 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 | 57fb30c | 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 | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 169 | static ssize_t __sbi_store(struct f2fs_attr *a, |
Chao Yu | 57fb30c | 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 | 1e72cb2 | 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 | ac734c4 | 2018-02-28 17:07:27 +0800 | [diff] [blame] | 184 | bool set = true, hot; |
Chao Yu | 1e72cb2 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 185 | |
Chao Yu | ac734c4 | 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 | 1e72cb2 | 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 | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 205 | ret = f2fs_update_extension_list(sbi, name, hot, set); |
Chao Yu | 1e72cb2 | 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 | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 211 | f2fs_update_extension_list(sbi, name, hot, !set); |
Chao Yu | 1e72cb2 | 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 | 57fb30c | 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 | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 226 | if (a->struct_type == RESERVED_BLOCKS) { |
| 227 | spin_lock(&sbi->stat_lock); |
Jaegeuk Kim | 5fee540 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 228 | if (t > (unsigned long)(sbi->user_block_count - |
Chao Yu | e9a50e6 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 229 | F2FS_OPTION(sbi).root_reserved_blocks)) { |
Chao Yu | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 230 | spin_unlock(&sbi->stat_lock); |
| 231 | return -EINVAL; |
| 232 | } |
| 233 | *ui = t; |
Yunlong Song | 68ab6f8 | 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 | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 236 | spin_unlock(&sbi->stat_lock); |
| 237 | return count; |
| 238 | } |
Chao Yu | efe24da | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 239 | |
| 240 | if (!strcmp(a->attr.name, "discard_granularity")) { |
Chao Yu | efe24da | 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 | d1c363b | 2017-09-12 14:25:35 +0800 | [diff] [blame] | 245 | *ui = t; |
Chao Yu | efe24da | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 246 | return count; |
| 247 | } |
| 248 | |
Chao Yu | 0357a0f | 2018-04-09 10:25:23 +0800 | [diff] [blame] | 249 | if (!strcmp(a->attr.name, "trim_sections")) |
| 250 | return -EINVAL; |
| 251 | |
Jaegeuk Kim | 0390d83 | 2018-05-07 14:22:40 -0700 | [diff] [blame] | 252 | if (!strcmp(a->attr.name, "gc_urgent")) { |
| 253 | if (t >= 1) { |
| 254 | sbi->gc_mode = GC_URGENT; |
| 255 | if (sbi->gc_thread) { |
| 256 | wake_up_interruptible_all( |
| 257 | &sbi->gc_thread->gc_wait_queue_head); |
| 258 | wake_up_discard_thread(sbi, true); |
| 259 | } |
| 260 | } else { |
| 261 | sbi->gc_mode = GC_NORMAL; |
| 262 | } |
| 263 | return count; |
| 264 | } |
| 265 | if (!strcmp(a->attr.name, "gc_idle")) { |
| 266 | if (t == GC_IDLE_CB) |
| 267 | sbi->gc_mode = GC_IDLE_CB; |
| 268 | else if (t == GC_IDLE_GREEDY) |
| 269 | sbi->gc_mode = GC_IDLE_GREEDY; |
| 270 | else |
| 271 | sbi->gc_mode = GC_NORMAL; |
| 272 | return count; |
| 273 | } |
| 274 | |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 275 | *ui = t; |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 276 | |
| 277 | if (!strcmp(a->attr.name, "iostat_enable") && *ui == 0) |
| 278 | f2fs_reset_iostat(sbi); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 279 | return count; |
| 280 | } |
| 281 | |
Chao Yu | b9921f0 | 2018-05-28 16:57:32 +0800 | [diff] [blame] | 282 | static ssize_t f2fs_sbi_store(struct f2fs_attr *a, |
| 283 | struct f2fs_sb_info *sbi, |
| 284 | const char *buf, size_t count) |
| 285 | { |
| 286 | ssize_t ret; |
| 287 | bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") || |
| 288 | a->struct_type == GC_THREAD); |
| 289 | |
Jaegeuk Kim | 1d1f79d | 2018-07-15 09:58:08 +0900 | [diff] [blame] | 290 | if (gc_entry) { |
| 291 | if (!down_read_trylock(&sbi->sb->s_umount)) |
| 292 | return -EAGAIN; |
| 293 | } |
Chao Yu | 6b4d6a8 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 294 | ret = __sbi_store(a, sbi, buf, count); |
Chao Yu | b9921f0 | 2018-05-28 16:57:32 +0800 | [diff] [blame] | 295 | if (gc_entry) |
| 296 | up_read(&sbi->sb->s_umount); |
| 297 | |
| 298 | return ret; |
| 299 | } |
| 300 | |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 301 | static ssize_t f2fs_attr_show(struct kobject *kobj, |
| 302 | struct attribute *attr, char *buf) |
| 303 | { |
| 304 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 305 | s_kobj); |
| 306 | struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); |
| 307 | |
| 308 | return a->show ? a->show(a, sbi, buf) : 0; |
| 309 | } |
| 310 | |
| 311 | static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr, |
| 312 | const char *buf, size_t len) |
| 313 | { |
| 314 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 315 | s_kobj); |
| 316 | struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); |
| 317 | |
| 318 | return a->store ? a->store(a, sbi, buf, len) : 0; |
| 319 | } |
| 320 | |
| 321 | static void f2fs_sb_release(struct kobject *kobj) |
| 322 | { |
| 323 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 324 | s_kobj); |
| 325 | complete(&sbi->s_kobj_unregister); |
| 326 | } |
| 327 | |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 328 | enum feat_id { |
| 329 | FEAT_CRYPTO = 0, |
| 330 | FEAT_BLKZONED, |
| 331 | FEAT_ATOMIC_WRITE, |
| 332 | FEAT_EXTRA_ATTR, |
| 333 | FEAT_PROJECT_QUOTA, |
| 334 | FEAT_INODE_CHECKSUM, |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 335 | FEAT_FLEXIBLE_INLINE_XATTR, |
Jaegeuk Kim | d4c292d | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 336 | FEAT_QUOTA_INO, |
Chao Yu | 71f8f04 | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 337 | FEAT_INODE_CRTIME, |
Sheng Yong | 9b880fe | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 338 | FEAT_LOST_FOUND, |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | static ssize_t f2fs_feature_show(struct f2fs_attr *a, |
| 342 | struct f2fs_sb_info *sbi, char *buf) |
| 343 | { |
| 344 | switch (a->id) { |
| 345 | case FEAT_CRYPTO: |
| 346 | case FEAT_BLKZONED: |
| 347 | case FEAT_ATOMIC_WRITE: |
| 348 | case FEAT_EXTRA_ATTR: |
| 349 | case FEAT_PROJECT_QUOTA: |
| 350 | case FEAT_INODE_CHECKSUM: |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 351 | case FEAT_FLEXIBLE_INLINE_XATTR: |
Jaegeuk Kim | d4c292d | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 352 | case FEAT_QUOTA_INO: |
Chao Yu | 71f8f04 | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 353 | case FEAT_INODE_CRTIME: |
Sheng Yong | 9b880fe | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 354 | case FEAT_LOST_FOUND: |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 355 | return snprintf(buf, PAGE_SIZE, "supported\n"); |
| 356 | } |
| 357 | return 0; |
| 358 | } |
| 359 | |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 360 | #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \ |
| 361 | static struct f2fs_attr f2fs_attr_##_name = { \ |
| 362 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 363 | .show = _show, \ |
| 364 | .store = _store, \ |
| 365 | .struct_type = _struct_type, \ |
| 366 | .offset = _offset \ |
| 367 | } |
| 368 | |
| 369 | #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \ |
| 370 | F2FS_ATTR_OFFSET(struct_type, name, 0644, \ |
| 371 | f2fs_sbi_show, f2fs_sbi_store, \ |
| 372 | offsetof(struct struct_name, elname)) |
| 373 | |
| 374 | #define F2FS_GENERAL_RO_ATTR(name) \ |
| 375 | static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL) |
| 376 | |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 377 | #define F2FS_FEATURE_RO_ATTR(_name, _id) \ |
| 378 | static struct f2fs_attr f2fs_attr_##_name = { \ |
| 379 | .attr = {.name = __stringify(_name), .mode = 0444 }, \ |
| 380 | .show = f2fs_feature_show, \ |
| 381 | .id = _id, \ |
| 382 | } |
| 383 | |
Jaegeuk Kim | bd2ffc2 | 2017-08-06 22:09:00 -0700 | [diff] [blame] | 384 | F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time, |
| 385 | urgent_sleep_time); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 386 | F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time); |
| 387 | F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time); |
| 388 | F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); |
Jaegeuk Kim | 0390d83 | 2018-05-07 14:22:40 -0700 | [diff] [blame] | 389 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode); |
| 390 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 391 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); |
| 392 | F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards); |
Chao Yu | efe24da | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 393 | F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity); |
Chao Yu | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 394 | F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 395 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections); |
| 396 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); |
| 397 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); |
| 398 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks); |
| 399 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks); |
Chao Yu | b9f7387 | 2017-10-28 16:52:33 +0800 | [diff] [blame] | 400 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 401 | F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh); |
| 402 | F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages); |
| 403 | F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio); |
| 404 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); |
| 405 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); |
| 406 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]); |
| 407 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]); |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 408 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable); |
Sheng Yong | 1ed7533 | 2017-11-22 18:23:38 +0800 | [diff] [blame] | 409 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra); |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 410 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold); |
Chao Yu | 1e72cb2 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 411 | F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 412 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 413 | F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate); |
| 414 | F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type); |
| 415 | #endif |
Jaegeuk Kim | af1cc1e | 2017-10-24 09:46:54 +0200 | [diff] [blame] | 416 | F2FS_GENERAL_RO_ATTR(dirty_segments); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 417 | F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 418 | F2FS_GENERAL_RO_ATTR(features); |
Yunlong Song | 68ab6f8 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 419 | F2FS_GENERAL_RO_ATTR(current_reserved_blocks); |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 420 | |
| 421 | #ifdef CONFIG_F2FS_FS_ENCRYPTION |
| 422 | F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO); |
| 423 | #endif |
| 424 | #ifdef CONFIG_BLK_DEV_ZONED |
| 425 | F2FS_FEATURE_RO_ATTR(block_zoned, FEAT_BLKZONED); |
| 426 | #endif |
| 427 | F2FS_FEATURE_RO_ATTR(atomic_write, FEAT_ATOMIC_WRITE); |
| 428 | F2FS_FEATURE_RO_ATTR(extra_attr, FEAT_EXTRA_ATTR); |
| 429 | F2FS_FEATURE_RO_ATTR(project_quota, FEAT_PROJECT_QUOTA); |
| 430 | F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM); |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 431 | F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR); |
Jaegeuk Kim | d4c292d | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 432 | F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO); |
Chao Yu | 71f8f04 | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 433 | F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME); |
Sheng Yong | 9b880fe | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 434 | F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 435 | |
| 436 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) |
| 437 | static struct attribute *f2fs_attrs[] = { |
Jaegeuk Kim | bd2ffc2 | 2017-08-06 22:09:00 -0700 | [diff] [blame] | 438 | ATTR_LIST(gc_urgent_sleep_time), |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 439 | ATTR_LIST(gc_min_sleep_time), |
| 440 | ATTR_LIST(gc_max_sleep_time), |
| 441 | ATTR_LIST(gc_no_gc_sleep_time), |
| 442 | ATTR_LIST(gc_idle), |
Jaegeuk Kim | bd2ffc2 | 2017-08-06 22:09:00 -0700 | [diff] [blame] | 443 | ATTR_LIST(gc_urgent), |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 444 | ATTR_LIST(reclaim_segments), |
| 445 | ATTR_LIST(max_small_discards), |
Chao Yu | efe24da | 2017-08-07 23:09:56 +0800 | [diff] [blame] | 446 | ATTR_LIST(discard_granularity), |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 447 | ATTR_LIST(batched_trim_sections), |
| 448 | ATTR_LIST(ipu_policy), |
| 449 | ATTR_LIST(min_ipu_util), |
| 450 | ATTR_LIST(min_fsync_blocks), |
| 451 | ATTR_LIST(min_hot_blocks), |
Chao Yu | b9f7387 | 2017-10-28 16:52:33 +0800 | [diff] [blame] | 452 | ATTR_LIST(min_ssr_sections), |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 453 | ATTR_LIST(max_victim_search), |
| 454 | ATTR_LIST(dir_level), |
| 455 | ATTR_LIST(ram_thresh), |
| 456 | ATTR_LIST(ra_nid_pages), |
| 457 | ATTR_LIST(dirty_nats_ratio), |
| 458 | ATTR_LIST(cp_interval), |
| 459 | ATTR_LIST(idle_interval), |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 460 | ATTR_LIST(iostat_enable), |
Sheng Yong | 1ed7533 | 2017-11-22 18:23:38 +0800 | [diff] [blame] | 461 | ATTR_LIST(readdir_ra), |
Jaegeuk Kim | 9ce3d6b | 2017-12-07 16:25:39 -0800 | [diff] [blame] | 462 | ATTR_LIST(gc_pin_file_thresh), |
Chao Yu | 1e72cb2 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 463 | ATTR_LIST(extension_list), |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 464 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 465 | ATTR_LIST(inject_rate), |
| 466 | ATTR_LIST(inject_type), |
| 467 | #endif |
Jaegeuk Kim | af1cc1e | 2017-10-24 09:46:54 +0200 | [diff] [blame] | 468 | ATTR_LIST(dirty_segments), |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 469 | ATTR_LIST(lifetime_write_kbytes), |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 470 | ATTR_LIST(features), |
Chao Yu | 026bd9d | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 471 | ATTR_LIST(reserved_blocks), |
Yunlong Song | 68ab6f8 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 472 | ATTR_LIST(current_reserved_blocks), |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 473 | NULL, |
| 474 | }; |
| 475 | |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 476 | static struct attribute *f2fs_feat_attrs[] = { |
| 477 | #ifdef CONFIG_F2FS_FS_ENCRYPTION |
| 478 | ATTR_LIST(encryption), |
| 479 | #endif |
| 480 | #ifdef CONFIG_BLK_DEV_ZONED |
| 481 | ATTR_LIST(block_zoned), |
| 482 | #endif |
| 483 | ATTR_LIST(atomic_write), |
| 484 | ATTR_LIST(extra_attr), |
| 485 | ATTR_LIST(project_quota), |
| 486 | ATTR_LIST(inode_checksum), |
Chao Yu | 50ffaa9 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 487 | ATTR_LIST(flexible_inline_xattr), |
Jaegeuk Kim | d4c292d | 2017-10-05 21:03:06 -0700 | [diff] [blame] | 488 | ATTR_LIST(quota_ino), |
Chao Yu | 71f8f04 | 2018-01-25 14:54:42 +0800 | [diff] [blame] | 489 | ATTR_LIST(inode_crtime), |
Sheng Yong | 9b880fe | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 490 | ATTR_LIST(lost_found), |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 491 | NULL, |
| 492 | }; |
| 493 | |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 494 | static const struct sysfs_ops f2fs_attr_ops = { |
| 495 | .show = f2fs_attr_show, |
| 496 | .store = f2fs_attr_store, |
| 497 | }; |
| 498 | |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 499 | static struct kobj_type f2fs_sb_ktype = { |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 500 | .default_attrs = f2fs_attrs, |
| 501 | .sysfs_ops = &f2fs_attr_ops, |
| 502 | .release = f2fs_sb_release, |
| 503 | }; |
| 504 | |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 505 | static struct kobj_type f2fs_ktype = { |
| 506 | .sysfs_ops = &f2fs_attr_ops, |
| 507 | }; |
| 508 | |
| 509 | static struct kset f2fs_kset = { |
| 510 | .kobj = {.ktype = &f2fs_ktype}, |
| 511 | }; |
| 512 | |
| 513 | static struct kobj_type f2fs_feat_ktype = { |
| 514 | .default_attrs = f2fs_feat_attrs, |
| 515 | .sysfs_ops = &f2fs_attr_ops, |
| 516 | }; |
| 517 | |
| 518 | static struct kobject f2fs_feat = { |
| 519 | .kset = &f2fs_kset, |
| 520 | }; |
| 521 | |
Randy Dunlap | bc1ad77 | 2018-07-06 20:50:57 -0700 | [diff] [blame] | 522 | static int __maybe_unused segment_info_seq_show(struct seq_file *seq, |
| 523 | void *offset) |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 524 | { |
| 525 | struct super_block *sb = seq->private; |
| 526 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 527 | unsigned int total_segs = |
| 528 | le32_to_cpu(sbi->raw_super->segment_count_main); |
| 529 | int i; |
| 530 | |
| 531 | seq_puts(seq, "format: segment_type|valid_blocks\n" |
| 532 | "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); |
| 533 | |
| 534 | for (i = 0; i < total_segs; i++) { |
| 535 | struct seg_entry *se = get_seg_entry(sbi, i); |
| 536 | |
| 537 | if ((i % 10) == 0) |
| 538 | seq_printf(seq, "%-10d", i); |
| 539 | seq_printf(seq, "%d|%-3u", se->type, |
| 540 | get_valid_blocks(sbi, i, false)); |
| 541 | if ((i % 10) == 9 || i == (total_segs - 1)) |
| 542 | seq_putc(seq, '\n'); |
| 543 | else |
| 544 | seq_putc(seq, ' '); |
| 545 | } |
| 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | |
Randy Dunlap | bc1ad77 | 2018-07-06 20:50:57 -0700 | [diff] [blame] | 550 | static int __maybe_unused segment_bits_seq_show(struct seq_file *seq, |
| 551 | void *offset) |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 552 | { |
| 553 | struct super_block *sb = seq->private; |
| 554 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 555 | unsigned int total_segs = |
| 556 | le32_to_cpu(sbi->raw_super->segment_count_main); |
| 557 | int i, j; |
| 558 | |
| 559 | seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n" |
| 560 | "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n"); |
| 561 | |
| 562 | for (i = 0; i < total_segs; i++) { |
| 563 | struct seg_entry *se = get_seg_entry(sbi, i); |
| 564 | |
| 565 | seq_printf(seq, "%-10d", i); |
| 566 | seq_printf(seq, "%d|%-3u|", se->type, |
| 567 | get_valid_blocks(sbi, i, false)); |
| 568 | for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++) |
| 569 | seq_printf(seq, " %.2x", se->cur_valid_map[j]); |
| 570 | seq_putc(seq, '\n'); |
| 571 | } |
| 572 | return 0; |
| 573 | } |
| 574 | |
Randy Dunlap | bc1ad77 | 2018-07-06 20:50:57 -0700 | [diff] [blame] | 575 | static int __maybe_unused iostat_info_seq_show(struct seq_file *seq, |
| 576 | void *offset) |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 577 | { |
| 578 | struct super_block *sb = seq->private; |
| 579 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 580 | time64_t now = ktime_get_real_seconds(); |
| 581 | |
| 582 | if (!sbi->iostat_enable) |
| 583 | return 0; |
| 584 | |
| 585 | seq_printf(seq, "time: %-16llu\n", now); |
| 586 | |
| 587 | /* print app IOs */ |
| 588 | seq_printf(seq, "app buffered: %-16llu\n", |
| 589 | sbi->write_iostat[APP_BUFFERED_IO]); |
| 590 | seq_printf(seq, "app direct: %-16llu\n", |
| 591 | sbi->write_iostat[APP_DIRECT_IO]); |
| 592 | seq_printf(seq, "app mapped: %-16llu\n", |
| 593 | sbi->write_iostat[APP_MAPPED_IO]); |
| 594 | |
| 595 | /* print fs IOs */ |
| 596 | seq_printf(seq, "fs data: %-16llu\n", |
| 597 | sbi->write_iostat[FS_DATA_IO]); |
| 598 | seq_printf(seq, "fs node: %-16llu\n", |
| 599 | sbi->write_iostat[FS_NODE_IO]); |
| 600 | seq_printf(seq, "fs meta: %-16llu\n", |
| 601 | sbi->write_iostat[FS_META_IO]); |
| 602 | seq_printf(seq, "fs gc data: %-16llu\n", |
| 603 | sbi->write_iostat[FS_GC_DATA_IO]); |
| 604 | seq_printf(seq, "fs gc node: %-16llu\n", |
| 605 | sbi->write_iostat[FS_GC_NODE_IO]); |
| 606 | seq_printf(seq, "fs cp data: %-16llu\n", |
| 607 | sbi->write_iostat[FS_CP_DATA_IO]); |
| 608 | seq_printf(seq, "fs cp node: %-16llu\n", |
| 609 | sbi->write_iostat[FS_CP_NODE_IO]); |
| 610 | seq_printf(seq, "fs cp meta: %-16llu\n", |
| 611 | sbi->write_iostat[FS_CP_META_IO]); |
| 612 | seq_printf(seq, "fs discard: %-16llu\n", |
| 613 | sbi->write_iostat[FS_DISCARD]); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
Yunlong Song | 1373478 | 2018-07-23 22:10:22 +0800 | [diff] [blame^] | 618 | static int __maybe_unused victim_bits_seq_show(struct seq_file *seq, |
| 619 | void *offset) |
| 620 | { |
| 621 | struct super_block *sb = seq->private; |
| 622 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 623 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); |
| 624 | int i; |
| 625 | |
| 626 | seq_puts(seq, "format: victim_secmap bitmaps\n"); |
| 627 | |
| 628 | for (i = 0; i < MAIN_SECS(sbi); i++) { |
| 629 | if ((i % 10) == 0) |
| 630 | seq_printf(seq, "%-10d", i); |
| 631 | seq_printf(seq, "%d", test_bit(i, dirty_i->victim_secmap) ? 1 : 0); |
| 632 | if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1)) |
| 633 | seq_putc(seq, '\n'); |
| 634 | else |
| 635 | seq_putc(seq, ' '); |
| 636 | } |
| 637 | return 0; |
| 638 | } |
| 639 | |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 640 | #define F2FS_PROC_FILE_DEF(_name) \ |
| 641 | static int _name##_open_fs(struct inode *inode, struct file *file) \ |
| 642 | { \ |
| 643 | return single_open(file, _name##_seq_show, PDE_DATA(inode)); \ |
| 644 | } \ |
| 645 | \ |
| 646 | static const struct file_operations f2fs_seq_##_name##_fops = { \ |
| 647 | .open = _name##_open_fs, \ |
| 648 | .read = seq_read, \ |
| 649 | .llseek = seq_lseek, \ |
| 650 | .release = single_release, \ |
| 651 | }; |
| 652 | |
| 653 | F2FS_PROC_FILE_DEF(segment_info); |
| 654 | F2FS_PROC_FILE_DEF(segment_bits); |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 655 | F2FS_PROC_FILE_DEF(iostat_info); |
Yunlong Song | 1373478 | 2018-07-23 22:10:22 +0800 | [diff] [blame^] | 656 | F2FS_PROC_FILE_DEF(victim_bits); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 657 | |
Jaegeuk Kim | 883d553 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 658 | int __init f2fs_init_sysfs(void) |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 659 | { |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 660 | int ret; |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 661 | |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 662 | kobject_set_name(&f2fs_kset.kobj, "f2fs"); |
| 663 | f2fs_kset.kobj.parent = fs_kobj; |
| 664 | ret = kset_register(&f2fs_kset); |
| 665 | if (ret) |
| 666 | return ret; |
| 667 | |
| 668 | ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype, |
| 669 | NULL, "features"); |
| 670 | if (ret) |
| 671 | kset_unregister(&f2fs_kset); |
| 672 | else |
| 673 | f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); |
| 674 | return ret; |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 675 | } |
| 676 | |
Jaegeuk Kim | 883d553 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 677 | void f2fs_exit_sysfs(void) |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 678 | { |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 679 | kobject_put(&f2fs_feat); |
| 680 | kset_unregister(&f2fs_kset); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 681 | remove_proc_entry("fs/f2fs", NULL); |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 682 | f2fs_proc_root = NULL; |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 683 | } |
| 684 | |
Jaegeuk Kim | 883d553 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 685 | int f2fs_register_sysfs(struct f2fs_sb_info *sbi) |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 686 | { |
| 687 | struct super_block *sb = sbi->sb; |
| 688 | int err; |
| 689 | |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 690 | sbi->s_kobj.kset = &f2fs_kset; |
| 691 | init_completion(&sbi->s_kobj_unregister); |
| 692 | err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL, |
| 693 | "%s", sb->s_id); |
| 694 | if (err) |
| 695 | return err; |
| 696 | |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 697 | if (f2fs_proc_root) |
| 698 | sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); |
| 699 | |
| 700 | if (sbi->s_proc) { |
| 701 | proc_create_data("segment_info", S_IRUGO, sbi->s_proc, |
| 702 | &f2fs_seq_segment_info_fops, sb); |
| 703 | proc_create_data("segment_bits", S_IRUGO, sbi->s_proc, |
| 704 | &f2fs_seq_segment_bits_fops, sb); |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 705 | proc_create_data("iostat_info", S_IRUGO, sbi->s_proc, |
| 706 | &f2fs_seq_iostat_info_fops, sb); |
Yunlong Song | 1373478 | 2018-07-23 22:10:22 +0800 | [diff] [blame^] | 707 | proc_create_data("victim_bits", S_IRUGO, sbi->s_proc, |
| 708 | &f2fs_seq_victim_bits_fops, sb); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 709 | } |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 710 | return 0; |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 711 | } |
| 712 | |
Jaegeuk Kim | 883d553 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 713 | void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 714 | { |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 715 | if (sbi->s_proc) { |
Chao Yu | c0fe488 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 716 | remove_proc_entry("iostat_info", sbi->s_proc); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 717 | remove_proc_entry("segment_info", sbi->s_proc); |
| 718 | remove_proc_entry("segment_bits", sbi->s_proc); |
Yunlong Song | 1373478 | 2018-07-23 22:10:22 +0800 | [diff] [blame^] | 719 | remove_proc_entry("victim_bits", sbi->s_proc); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 720 | remove_proc_entry(sbi->sb->s_id, f2fs_proc_root); |
| 721 | } |
Jaegeuk Kim | 3b3d1b8 | 2017-07-21 17:14:09 -0700 | [diff] [blame] | 722 | kobject_del(&sbi->s_kobj); |
Chao Yu | 57fb30c | 2017-06-14 17:39:47 +0800 | [diff] [blame] | 723 | } |