| 1 | // SPDX-License-Identifier: GPL-2.0 |
| 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> |
| 8 | */ |
| 9 | #include <linux/compiler.h> |
| 10 | #include <linux/proc_fs.h> |
| 11 | #include <linux/f2fs_fs.h> |
| 12 | #include <linux/seq_file.h> |
| 13 | #include <linux/unicode.h> |
| 14 | #include <linux/ioprio.h> |
| 15 | #include <linux/sysfs.h> |
| 16 | |
| 17 | #include "f2fs.h" |
| 18 | #include "segment.h" |
| 19 | #include "gc.h" |
| 20 | #include "iostat.h" |
| 21 | #include <trace/events/f2fs.h> |
| 22 | |
| 23 | static struct proc_dir_entry *f2fs_proc_root; |
| 24 | |
| 25 | /* Sysfs support for f2fs */ |
| 26 | enum { |
| 27 | GC_THREAD, /* struct f2fs_gc_thread */ |
| 28 | SM_INFO, /* struct f2fs_sm_info */ |
| 29 | DCC_INFO, /* struct discard_cmd_control */ |
| 30 | NM_INFO, /* struct f2fs_nm_info */ |
| 31 | F2FS_SBI, /* struct f2fs_sb_info */ |
| 32 | #ifdef CONFIG_F2FS_STAT_FS |
| 33 | STAT_INFO, /* struct f2fs_stat_info */ |
| 34 | #endif |
| 35 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 36 | FAULT_INFO_RATE, /* struct f2fs_fault_info */ |
| 37 | FAULT_INFO_TYPE, /* struct f2fs_fault_info */ |
| 38 | #endif |
| 39 | RESERVED_BLOCKS, /* struct f2fs_sb_info */ |
| 40 | CPRC_INFO, /* struct ckpt_req_control */ |
| 41 | ATGC_INFO, /* struct atgc_management */ |
| 42 | }; |
| 43 | |
| 44 | static const char *gc_mode_names[MAX_GC_MODE] = { |
| 45 | "GC_NORMAL" , |
| 46 | "GC_IDLE_CB" , |
| 47 | "GC_IDLE_GREEDY" , |
| 48 | "GC_IDLE_AT" , |
| 49 | "GC_URGENT_HIGH" , |
| 50 | "GC_URGENT_LOW" , |
| 51 | "GC_URGENT_MID" |
| 52 | }; |
| 53 | |
| 54 | struct f2fs_attr { |
| 55 | struct attribute attr; |
| 56 | ssize_t (*show)(struct f2fs_attr *a, struct f2fs_sb_info *sbi, char *buf); |
| 57 | ssize_t (*store)(struct f2fs_attr *a, struct f2fs_sb_info *sbi, |
| 58 | const char *buf, size_t len); |
| 59 | int struct_type; |
| 60 | int offset; |
| 61 | int id; |
| 62 | }; |
| 63 | |
| 64 | struct f2fs_base_attr { |
| 65 | struct attribute attr; |
| 66 | ssize_t (*show)(struct f2fs_base_attr *a, char *buf); |
| 67 | ssize_t (*store)(struct f2fs_base_attr *a, const char *buf, size_t len); |
| 68 | }; |
| 69 | |
| 70 | static ssize_t f2fs_sbi_show(struct f2fs_attr *a, |
| 71 | struct f2fs_sb_info *sbi, char *buf); |
| 72 | |
| 73 | static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type) |
| 74 | { |
| 75 | if (struct_type == GC_THREAD) |
| 76 | return (unsigned char *)sbi->gc_thread; |
| 77 | else if (struct_type == SM_INFO) |
| 78 | return (unsigned char *)SM_I(sbi); |
| 79 | else if (struct_type == DCC_INFO) |
| 80 | return (unsigned char *)SM_I(sbi)->dcc_info; |
| 81 | else if (struct_type == NM_INFO) |
| 82 | return (unsigned char *)NM_I(sbi); |
| 83 | else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS) |
| 84 | return (unsigned char *)sbi; |
| 85 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 86 | else if (struct_type == FAULT_INFO_RATE || |
| 87 | struct_type == FAULT_INFO_TYPE) |
| 88 | return (unsigned char *)&F2FS_OPTION(sbi).fault_info; |
| 89 | #endif |
| 90 | #ifdef CONFIG_F2FS_STAT_FS |
| 91 | else if (struct_type == STAT_INFO) |
| 92 | return (unsigned char *)F2FS_STAT(sbi); |
| 93 | #endif |
| 94 | else if (struct_type == CPRC_INFO) |
| 95 | return (unsigned char *)&sbi->cprc_info; |
| 96 | else if (struct_type == ATGC_INFO) |
| 97 | return (unsigned char *)&sbi->am; |
| 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | static ssize_t dirty_segments_show(struct f2fs_attr *a, |
| 102 | struct f2fs_sb_info *sbi, char *buf) |
| 103 | { |
| 104 | return sysfs_emit(buf, fmt: "%llu\n" , |
| 105 | (unsigned long long)(dirty_segments(sbi))); |
| 106 | } |
| 107 | |
| 108 | static ssize_t free_segments_show(struct f2fs_attr *a, |
| 109 | struct f2fs_sb_info *sbi, char *buf) |
| 110 | { |
| 111 | return sysfs_emit(buf, fmt: "%llu\n" , |
| 112 | (unsigned long long)(free_segments(sbi))); |
| 113 | } |
| 114 | |
| 115 | static ssize_t ovp_segments_show(struct f2fs_attr *a, |
| 116 | struct f2fs_sb_info *sbi, char *buf) |
| 117 | { |
| 118 | return sysfs_emit(buf, fmt: "%llu\n" , |
| 119 | (unsigned long long)(overprovision_segments(sbi))); |
| 120 | } |
| 121 | |
| 122 | static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a, |
| 123 | struct f2fs_sb_info *sbi, char *buf) |
| 124 | { |
| 125 | return sysfs_emit(buf, fmt: "%llu\n" , |
| 126 | (unsigned long long)(sbi->kbytes_written + |
| 127 | ((f2fs_get_sectors_written(sbi) - |
| 128 | sbi->sectors_written_start) >> 1))); |
| 129 | } |
| 130 | |
| 131 | static ssize_t sb_status_show(struct f2fs_attr *a, |
| 132 | struct f2fs_sb_info *sbi, char *buf) |
| 133 | { |
| 134 | return sysfs_emit(buf, fmt: "%lx\n" , sbi->s_flag); |
| 135 | } |
| 136 | |
| 137 | static ssize_t cp_status_show(struct f2fs_attr *a, |
| 138 | struct f2fs_sb_info *sbi, char *buf) |
| 139 | { |
| 140 | return sysfs_emit(buf, fmt: "%x\n" , le32_to_cpu(F2FS_CKPT(sbi)->ckpt_flags)); |
| 141 | } |
| 142 | |
| 143 | static ssize_t pending_discard_show(struct f2fs_attr *a, |
| 144 | struct f2fs_sb_info *sbi, char *buf) |
| 145 | { |
| 146 | if (!SM_I(sbi)->dcc_info) |
| 147 | return -EINVAL; |
| 148 | return sysfs_emit(buf, fmt: "%llu\n" , (unsigned long long)atomic_read( |
| 149 | v: &SM_I(sbi)->dcc_info->discard_cmd_cnt)); |
| 150 | } |
| 151 | |
| 152 | static ssize_t issued_discard_show(struct f2fs_attr *a, |
| 153 | struct f2fs_sb_info *sbi, char *buf) |
| 154 | { |
| 155 | if (!SM_I(sbi)->dcc_info) |
| 156 | return -EINVAL; |
| 157 | return sysfs_emit(buf, fmt: "%llu\n" , (unsigned long long)atomic_read( |
| 158 | v: &SM_I(sbi)->dcc_info->issued_discard)); |
| 159 | } |
| 160 | |
| 161 | static ssize_t queued_discard_show(struct f2fs_attr *a, |
| 162 | struct f2fs_sb_info *sbi, char *buf) |
| 163 | { |
| 164 | if (!SM_I(sbi)->dcc_info) |
| 165 | return -EINVAL; |
| 166 | return sysfs_emit(buf, fmt: "%llu\n" , (unsigned long long)atomic_read( |
| 167 | v: &SM_I(sbi)->dcc_info->queued_discard)); |
| 168 | } |
| 169 | |
| 170 | static ssize_t undiscard_blks_show(struct f2fs_attr *a, |
| 171 | struct f2fs_sb_info *sbi, char *buf) |
| 172 | { |
| 173 | if (!SM_I(sbi)->dcc_info) |
| 174 | return -EINVAL; |
| 175 | return sysfs_emit(buf, fmt: "%u\n" , |
| 176 | SM_I(sbi)->dcc_info->undiscard_blks); |
| 177 | } |
| 178 | |
| 179 | static ssize_t atgc_enabled_show(struct f2fs_attr *a, |
| 180 | struct f2fs_sb_info *sbi, char *buf) |
| 181 | { |
| 182 | return sysfs_emit(buf, fmt: "%d\n" , sbi->am.atgc_enabled ? 1 : 0); |
| 183 | } |
| 184 | |
| 185 | static ssize_t gc_mode_show(struct f2fs_attr *a, |
| 186 | struct f2fs_sb_info *sbi, char *buf) |
| 187 | { |
| 188 | return sysfs_emit(buf, fmt: "%s\n" , gc_mode_names[sbi->gc_mode]); |
| 189 | } |
| 190 | |
| 191 | static ssize_t features_show(struct f2fs_attr *a, |
| 192 | struct f2fs_sb_info *sbi, char *buf) |
| 193 | { |
| 194 | int len = 0; |
| 195 | |
| 196 | if (f2fs_sb_has_encrypt(sbi)) |
| 197 | len += sysfs_emit_at(buf, at: len, fmt: "%s" , |
| 198 | "encryption" ); |
| 199 | if (f2fs_sb_has_blkzoned(sbi)) |
| 200 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 201 | len ? ", " : "" , "blkzoned" ); |
| 202 | if (f2fs_sb_has_extra_attr(sbi)) |
| 203 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 204 | len ? ", " : "" , "extra_attr" ); |
| 205 | if (f2fs_sb_has_project_quota(sbi)) |
| 206 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 207 | len ? ", " : "" , "projquota" ); |
| 208 | if (f2fs_sb_has_inode_chksum(sbi)) |
| 209 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 210 | len ? ", " : "" , "inode_checksum" ); |
| 211 | if (f2fs_sb_has_flexible_inline_xattr(sbi)) |
| 212 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 213 | len ? ", " : "" , "flexible_inline_xattr" ); |
| 214 | if (f2fs_sb_has_quota_ino(sbi)) |
| 215 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 216 | len ? ", " : "" , "quota_ino" ); |
| 217 | if (f2fs_sb_has_inode_crtime(sbi)) |
| 218 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 219 | len ? ", " : "" , "inode_crtime" ); |
| 220 | if (f2fs_sb_has_lost_found(sbi)) |
| 221 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 222 | len ? ", " : "" , "lost_found" ); |
| 223 | if (f2fs_sb_has_verity(sbi)) |
| 224 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 225 | len ? ", " : "" , "verity" ); |
| 226 | if (f2fs_sb_has_sb_chksum(sbi)) |
| 227 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 228 | len ? ", " : "" , "sb_checksum" ); |
| 229 | if (f2fs_sb_has_casefold(sbi)) |
| 230 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 231 | len ? ", " : "" , "casefold" ); |
| 232 | if (f2fs_sb_has_readonly(sbi)) |
| 233 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 234 | len ? ", " : "" , "readonly" ); |
| 235 | if (f2fs_sb_has_compression(sbi)) |
| 236 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 237 | len ? ", " : "" , "compression" ); |
| 238 | if (f2fs_sb_has_packed_ssa(sbi)) |
| 239 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 240 | len ? ", " : "" , "packed_ssa" ); |
| 241 | len += sysfs_emit_at(buf, at: len, fmt: "%s%s" , |
| 242 | len ? ", " : "" , "pin_file" ); |
| 243 | len += sysfs_emit_at(buf, at: len, fmt: "\n" ); |
| 244 | return len; |
| 245 | } |
| 246 | |
| 247 | static ssize_t current_reserved_blocks_show(struct f2fs_attr *a, |
| 248 | struct f2fs_sb_info *sbi, char *buf) |
| 249 | { |
| 250 | return sysfs_emit(buf, fmt: "%u\n" , sbi->current_reserved_blocks); |
| 251 | } |
| 252 | |
| 253 | static ssize_t unusable_show(struct f2fs_attr *a, |
| 254 | struct f2fs_sb_info *sbi, char *buf) |
| 255 | { |
| 256 | block_t unusable; |
| 257 | |
| 258 | if (test_opt(sbi, DISABLE_CHECKPOINT)) |
| 259 | unusable = sbi->unusable_block_count; |
| 260 | else |
| 261 | unusable = f2fs_get_unusable_blocks(sbi); |
| 262 | return sysfs_emit(buf, fmt: "%llu\n" , (unsigned long long)unusable); |
| 263 | } |
| 264 | |
| 265 | static ssize_t encoding_show(struct f2fs_attr *a, |
| 266 | struct f2fs_sb_info *sbi, char *buf) |
| 267 | { |
| 268 | #if IS_ENABLED(CONFIG_UNICODE) |
| 269 | struct super_block *sb = sbi->sb; |
| 270 | |
| 271 | if (f2fs_sb_has_casefold(sbi)) |
| 272 | return sysfs_emit(buf, fmt: "UTF-8 (%d.%d.%d)\n" , |
| 273 | (sb->s_encoding->version >> 16) & 0xff, |
| 274 | (sb->s_encoding->version >> 8) & 0xff, |
| 275 | sb->s_encoding->version & 0xff); |
| 276 | #endif |
| 277 | return sysfs_emit(buf, fmt: "(none)\n" ); |
| 278 | } |
| 279 | |
| 280 | static ssize_t encoding_flags_show(struct f2fs_attr *a, |
| 281 | struct f2fs_sb_info *sbi, char *buf) |
| 282 | { |
| 283 | return sysfs_emit(buf, fmt: "%x\n" , |
| 284 | le16_to_cpu(F2FS_RAW_SUPER(sbi)->s_encoding_flags)); |
| 285 | } |
| 286 | |
| 287 | static ssize_t effective_lookup_mode_show(struct f2fs_attr *a, |
| 288 | struct f2fs_sb_info *sbi, char *buf) |
| 289 | { |
| 290 | switch (F2FS_OPTION(sbi).lookup_mode) { |
| 291 | case LOOKUP_PERF: |
| 292 | return sysfs_emit(buf, fmt: "perf\n" ); |
| 293 | case LOOKUP_COMPAT: |
| 294 | return sysfs_emit(buf, fmt: "compat\n" ); |
| 295 | case LOOKUP_AUTO: |
| 296 | if (sb_no_casefold_compat_fallback(sbi->sb)) |
| 297 | return sysfs_emit(buf, fmt: "auto:perf\n" ); |
| 298 | return sysfs_emit(buf, fmt: "auto:compat\n" ); |
| 299 | } |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | static ssize_t mounted_time_sec_show(struct f2fs_attr *a, |
| 304 | struct f2fs_sb_info *sbi, char *buf) |
| 305 | { |
| 306 | return sysfs_emit(buf, fmt: "%llu\n" , SIT_I(sbi)->mounted_time); |
| 307 | } |
| 308 | |
| 309 | #ifdef CONFIG_F2FS_STAT_FS |
| 310 | static ssize_t moved_blocks_foreground_show(struct f2fs_attr *a, |
| 311 | struct f2fs_sb_info *sbi, char *buf) |
| 312 | { |
| 313 | struct f2fs_stat_info *si = F2FS_STAT(sbi); |
| 314 | |
| 315 | return sysfs_emit(buf, fmt: "%llu\n" , |
| 316 | (unsigned long long)(si->tot_blks - |
| 317 | (si->bg_data_blks + si->bg_node_blks))); |
| 318 | } |
| 319 | |
| 320 | static ssize_t moved_blocks_background_show(struct f2fs_attr *a, |
| 321 | struct f2fs_sb_info *sbi, char *buf) |
| 322 | { |
| 323 | struct f2fs_stat_info *si = F2FS_STAT(sbi); |
| 324 | |
| 325 | return sysfs_emit(buf, fmt: "%llu\n" , |
| 326 | (unsigned long long)(si->bg_data_blks + si->bg_node_blks)); |
| 327 | } |
| 328 | |
| 329 | static ssize_t avg_vblocks_show(struct f2fs_attr *a, |
| 330 | struct f2fs_sb_info *sbi, char *buf) |
| 331 | { |
| 332 | struct f2fs_stat_info *si = F2FS_STAT(sbi); |
| 333 | |
| 334 | si->dirty_count = dirty_segments(sbi); |
| 335 | f2fs_update_sit_info(sbi); |
| 336 | return sysfs_emit(buf, fmt: "%llu\n" , (unsigned long long)(si->avg_vblocks)); |
| 337 | } |
| 338 | #endif |
| 339 | |
| 340 | static ssize_t main_blkaddr_show(struct f2fs_attr *a, |
| 341 | struct f2fs_sb_info *sbi, char *buf) |
| 342 | { |
| 343 | return sysfs_emit(buf, fmt: "%llu\n" , |
| 344 | (unsigned long long)MAIN_BLKADDR(sbi)); |
| 345 | } |
| 346 | |
| 347 | static ssize_t f2fs_sbi_show(struct f2fs_attr *a, |
| 348 | struct f2fs_sb_info *sbi, char *buf) |
| 349 | { |
| 350 | unsigned char *ptr = NULL; |
| 351 | unsigned int *ui; |
| 352 | |
| 353 | ptr = __struct_ptr(sbi, struct_type: a->struct_type); |
| 354 | if (!ptr) |
| 355 | return -EINVAL; |
| 356 | |
| 357 | if (!strcmp(a->attr.name, "extension_list" )) { |
| 358 | __u8 (*extlist)[F2FS_EXTENSION_LEN] = |
| 359 | sbi->raw_super->extension_list; |
| 360 | int cold_count = le32_to_cpu(sbi->raw_super->extension_count); |
| 361 | int hot_count = sbi->raw_super->hot_ext_count; |
| 362 | int len = 0, i; |
| 363 | |
| 364 | len += sysfs_emit_at(buf, at: len, fmt: "cold file extension:\n" ); |
| 365 | for (i = 0; i < cold_count; i++) |
| 366 | len += sysfs_emit_at(buf, at: len, fmt: "%s\n" , extlist[i]); |
| 367 | |
| 368 | len += sysfs_emit_at(buf, at: len, fmt: "hot file extension:\n" ); |
| 369 | for (i = cold_count; i < cold_count + hot_count; i++) |
| 370 | len += sysfs_emit_at(buf, at: len, fmt: "%s\n" , extlist[i]); |
| 371 | |
| 372 | return len; |
| 373 | } |
| 374 | |
| 375 | if (!strcmp(a->attr.name, "ckpt_thread_ioprio" )) { |
| 376 | struct ckpt_req_control *cprc = &sbi->cprc_info; |
| 377 | int class = IOPRIO_PRIO_CLASS(cprc->ckpt_thread_ioprio); |
| 378 | int level = IOPRIO_PRIO_LEVEL(cprc->ckpt_thread_ioprio); |
| 379 | |
| 380 | if (class != IOPRIO_CLASS_RT && class != IOPRIO_CLASS_BE) |
| 381 | return -EINVAL; |
| 382 | |
| 383 | return sysfs_emit(buf, fmt: "%s,%d\n" , |
| 384 | class == IOPRIO_CLASS_RT ? "rt" : "be" , level); |
| 385 | } |
| 386 | |
| 387 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
| 388 | if (!strcmp(a->attr.name, "compr_written_block" )) |
| 389 | return sysfs_emit(buf, fmt: "%llu\n" , sbi->compr_written_block); |
| 390 | |
| 391 | if (!strcmp(a->attr.name, "compr_saved_block" )) |
| 392 | return sysfs_emit(buf, fmt: "%llu\n" , sbi->compr_saved_block); |
| 393 | |
| 394 | if (!strcmp(a->attr.name, "compr_new_inode" )) |
| 395 | return sysfs_emit(buf, fmt: "%u\n" , sbi->compr_new_inode); |
| 396 | #endif |
| 397 | |
| 398 | if (!strcmp(a->attr.name, "gc_segment_mode" )) |
| 399 | return sysfs_emit(buf, fmt: "%u\n" , sbi->gc_segment_mode); |
| 400 | |
| 401 | if (!strcmp(a->attr.name, "gc_reclaimed_segments" )) { |
| 402 | return sysfs_emit(buf, fmt: "%u\n" , |
| 403 | sbi->gc_reclaimed_segs[sbi->gc_segment_mode]); |
| 404 | } |
| 405 | |
| 406 | if (!strcmp(a->attr.name, "current_atomic_write" )) { |
| 407 | s64 current_write = atomic64_read(v: &sbi->current_atomic_write); |
| 408 | |
| 409 | return sysfs_emit(buf, fmt: "%lld\n" , current_write); |
| 410 | } |
| 411 | |
| 412 | if (!strcmp(a->attr.name, "peak_atomic_write" )) |
| 413 | return sysfs_emit(buf, fmt: "%lld\n" , sbi->peak_atomic_write); |
| 414 | |
| 415 | if (!strcmp(a->attr.name, "committed_atomic_block" )) |
| 416 | return sysfs_emit(buf, fmt: "%llu\n" , sbi->committed_atomic_block); |
| 417 | |
| 418 | if (!strcmp(a->attr.name, "revoked_atomic_block" )) |
| 419 | return sysfs_emit(buf, fmt: "%llu\n" , sbi->revoked_atomic_block); |
| 420 | |
| 421 | #ifdef CONFIG_F2FS_STAT_FS |
| 422 | if (!strcmp(a->attr.name, "cp_foreground_calls" )) |
| 423 | return sysfs_emit(buf, fmt: "%d\n" , |
| 424 | atomic_read(v: &sbi->cp_call_count[TOTAL_CALL]) - |
| 425 | atomic_read(v: &sbi->cp_call_count[BACKGROUND])); |
| 426 | if (!strcmp(a->attr.name, "cp_background_calls" )) |
| 427 | return sysfs_emit(buf, fmt: "%d\n" , |
| 428 | atomic_read(v: &sbi->cp_call_count[BACKGROUND])); |
| 429 | #endif |
| 430 | |
| 431 | ui = (unsigned int *)(ptr + a->offset); |
| 432 | |
| 433 | return sysfs_emit(buf, fmt: "%u\n" , *ui); |
| 434 | } |
| 435 | |
| 436 | static ssize_t __sbi_store(struct f2fs_attr *a, |
| 437 | struct f2fs_sb_info *sbi, |
| 438 | const char *buf, size_t count) |
| 439 | { |
| 440 | unsigned char *ptr; |
| 441 | unsigned long t; |
| 442 | unsigned int *ui; |
| 443 | ssize_t ret; |
| 444 | |
| 445 | ptr = __struct_ptr(sbi, struct_type: a->struct_type); |
| 446 | if (!ptr) |
| 447 | return -EINVAL; |
| 448 | |
| 449 | if (!strcmp(a->attr.name, "extension_list" )) { |
| 450 | const char *name = strim((char *)buf); |
| 451 | bool set = true, hot; |
| 452 | |
| 453 | if (!strncmp(name, "[h]" , 3)) |
| 454 | hot = true; |
| 455 | else if (!strncmp(name, "[c]" , 3)) |
| 456 | hot = false; |
| 457 | else |
| 458 | return -EINVAL; |
| 459 | |
| 460 | name += 3; |
| 461 | |
| 462 | if (*name == '!') { |
| 463 | name++; |
| 464 | set = false; |
| 465 | } |
| 466 | |
| 467 | if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN) |
| 468 | return -EINVAL; |
| 469 | |
| 470 | f2fs_down_write(sem: &sbi->sb_lock); |
| 471 | |
| 472 | ret = f2fs_update_extension_list(sbi, name, hot, set); |
| 473 | if (ret) |
| 474 | goto out; |
| 475 | |
| 476 | ret = f2fs_commit_super(sbi, recover: false); |
| 477 | if (ret) |
| 478 | f2fs_update_extension_list(sbi, name, hot, set: !set); |
| 479 | out: |
| 480 | f2fs_up_write(sem: &sbi->sb_lock); |
| 481 | return ret ? ret : count; |
| 482 | } |
| 483 | |
| 484 | if (!strcmp(a->attr.name, "ckpt_thread_ioprio" )) { |
| 485 | const char *name = strim((char *)buf); |
| 486 | struct ckpt_req_control *cprc = &sbi->cprc_info; |
| 487 | int class; |
| 488 | long level; |
| 489 | int ret; |
| 490 | |
| 491 | if (!strncmp(name, "rt," , 3)) |
| 492 | class = IOPRIO_CLASS_RT; |
| 493 | else if (!strncmp(name, "be," , 3)) |
| 494 | class = IOPRIO_CLASS_BE; |
| 495 | else |
| 496 | return -EINVAL; |
| 497 | |
| 498 | name += 3; |
| 499 | ret = kstrtol(s: name, base: 10, res: &level); |
| 500 | if (ret) |
| 501 | return ret; |
| 502 | if (level >= IOPRIO_NR_LEVELS || level < 0) |
| 503 | return -EINVAL; |
| 504 | |
| 505 | cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, level); |
| 506 | if (test_opt(sbi, MERGE_CHECKPOINT)) { |
| 507 | ret = set_task_ioprio(task: cprc->f2fs_issue_ckpt, |
| 508 | ioprio: cprc->ckpt_thread_ioprio); |
| 509 | if (ret) |
| 510 | return ret; |
| 511 | } |
| 512 | |
| 513 | return count; |
| 514 | } |
| 515 | |
| 516 | ui = (unsigned int *)(ptr + a->offset); |
| 517 | |
| 518 | ret = kstrtoul(s: skip_spaces(buf), base: 0, res: &t); |
| 519 | if (ret < 0) |
| 520 | return ret; |
| 521 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 522 | if (a->struct_type == FAULT_INFO_TYPE) { |
| 523 | if (f2fs_build_fault_attr(sbi, rate: 0, type: t, fo: FAULT_TYPE)) |
| 524 | return -EINVAL; |
| 525 | return count; |
| 526 | } |
| 527 | if (a->struct_type == FAULT_INFO_RATE) { |
| 528 | if (f2fs_build_fault_attr(sbi, rate: t, type: 0, fo: FAULT_RATE)) |
| 529 | return -EINVAL; |
| 530 | return count; |
| 531 | } |
| 532 | #endif |
| 533 | if (a->struct_type == RESERVED_BLOCKS) { |
| 534 | spin_lock(lock: &sbi->stat_lock); |
| 535 | if (t > (unsigned long)(sbi->user_block_count - |
| 536 | F2FS_OPTION(sbi).root_reserved_blocks)) { |
| 537 | spin_unlock(lock: &sbi->stat_lock); |
| 538 | return -EINVAL; |
| 539 | } |
| 540 | *ui = t; |
| 541 | sbi->current_reserved_blocks = min(sbi->reserved_blocks, |
| 542 | sbi->user_block_count - valid_user_blocks(sbi)); |
| 543 | spin_unlock(lock: &sbi->stat_lock); |
| 544 | return count; |
| 545 | } |
| 546 | |
| 547 | if (!strcmp(a->attr.name, "discard_io_aware_gran" )) { |
| 548 | if (t > MAX_PLIST_NUM) |
| 549 | return -EINVAL; |
| 550 | if (!f2fs_block_unit_discard(sbi)) |
| 551 | return -EINVAL; |
| 552 | if (t == *ui) |
| 553 | return count; |
| 554 | *ui = t; |
| 555 | return count; |
| 556 | } |
| 557 | |
| 558 | if (!strcmp(a->attr.name, "discard_granularity" )) { |
| 559 | if (t == 0 || t > MAX_PLIST_NUM) |
| 560 | return -EINVAL; |
| 561 | if (!f2fs_block_unit_discard(sbi)) |
| 562 | return -EINVAL; |
| 563 | if (t == *ui) |
| 564 | return count; |
| 565 | *ui = t; |
| 566 | return count; |
| 567 | } |
| 568 | |
| 569 | if (!strcmp(a->attr.name, "max_ordered_discard" )) { |
| 570 | if (t == 0 || t > MAX_PLIST_NUM) |
| 571 | return -EINVAL; |
| 572 | if (!f2fs_block_unit_discard(sbi)) |
| 573 | return -EINVAL; |
| 574 | *ui = t; |
| 575 | return count; |
| 576 | } |
| 577 | |
| 578 | if (!strcmp(a->attr.name, "discard_urgent_util" )) { |
| 579 | if (t > 100) |
| 580 | return -EINVAL; |
| 581 | *ui = t; |
| 582 | return count; |
| 583 | } |
| 584 | |
| 585 | if (!strcmp(a->attr.name, "discard_io_aware" )) { |
| 586 | if (t >= DPOLICY_IO_AWARE_MAX) |
| 587 | return -EINVAL; |
| 588 | *ui = t; |
| 589 | return count; |
| 590 | } |
| 591 | |
| 592 | if (!strcmp(a->attr.name, "migration_granularity" )) { |
| 593 | if (t == 0 || t > SEGS_PER_SEC(sbi)) |
| 594 | return -EINVAL; |
| 595 | } |
| 596 | |
| 597 | if (!strcmp(a->attr.name, "migration_window_granularity" )) { |
| 598 | if (t == 0 || t > SEGS_PER_SEC(sbi)) |
| 599 | return -EINVAL; |
| 600 | } |
| 601 | |
| 602 | if (!strcmp(a->attr.name, "gc_urgent" )) { |
| 603 | if (t == 0) { |
| 604 | sbi->gc_mode = GC_NORMAL; |
| 605 | } else if (t == 1) { |
| 606 | sbi->gc_mode = GC_URGENT_HIGH; |
| 607 | if (sbi->gc_thread) { |
| 608 | sbi->gc_thread->gc_wake = true; |
| 609 | wake_up_interruptible_all( |
| 610 | &sbi->gc_thread->gc_wait_queue_head); |
| 611 | wake_up_discard_thread(sbi, force: true); |
| 612 | } |
| 613 | } else if (t == 2) { |
| 614 | sbi->gc_mode = GC_URGENT_LOW; |
| 615 | } else if (t == 3) { |
| 616 | sbi->gc_mode = GC_URGENT_MID; |
| 617 | if (sbi->gc_thread) { |
| 618 | sbi->gc_thread->gc_wake = true; |
| 619 | wake_up_interruptible_all( |
| 620 | &sbi->gc_thread->gc_wait_queue_head); |
| 621 | } |
| 622 | } else { |
| 623 | return -EINVAL; |
| 624 | } |
| 625 | return count; |
| 626 | } |
| 627 | if (!strcmp(a->attr.name, "gc_idle" )) { |
| 628 | if (t == GC_IDLE_CB) { |
| 629 | sbi->gc_mode = GC_IDLE_CB; |
| 630 | } else if (t == GC_IDLE_GREEDY) { |
| 631 | sbi->gc_mode = GC_IDLE_GREEDY; |
| 632 | } else if (t == GC_IDLE_AT) { |
| 633 | if (!sbi->am.atgc_enabled) |
| 634 | return -EINVAL; |
| 635 | sbi->gc_mode = GC_IDLE_AT; |
| 636 | } else { |
| 637 | sbi->gc_mode = GC_NORMAL; |
| 638 | } |
| 639 | return count; |
| 640 | } |
| 641 | |
| 642 | if (!strcmp(a->attr.name, "gc_remaining_trials" )) { |
| 643 | spin_lock(lock: &sbi->gc_remaining_trials_lock); |
| 644 | sbi->gc_remaining_trials = t; |
| 645 | spin_unlock(lock: &sbi->gc_remaining_trials_lock); |
| 646 | |
| 647 | return count; |
| 648 | } |
| 649 | |
| 650 | if (!strcmp(a->attr.name, "gc_no_zoned_gc_percent" )) { |
| 651 | if (t > 100) |
| 652 | return -EINVAL; |
| 653 | *ui = (unsigned int)t; |
| 654 | return count; |
| 655 | } |
| 656 | |
| 657 | if (!strcmp(a->attr.name, "gc_boost_zoned_gc_percent" )) { |
| 658 | if (t > 100) |
| 659 | return -EINVAL; |
| 660 | *ui = (unsigned int)t; |
| 661 | return count; |
| 662 | } |
| 663 | |
| 664 | if (!strcmp(a->attr.name, "gc_valid_thresh_ratio" )) { |
| 665 | if (t > 100) |
| 666 | return -EINVAL; |
| 667 | *ui = (unsigned int)t; |
| 668 | return count; |
| 669 | } |
| 670 | |
| 671 | #ifdef CONFIG_F2FS_IOSTAT |
| 672 | if (!strcmp(a->attr.name, "iostat_enable" )) { |
| 673 | sbi->iostat_enable = !!t; |
| 674 | if (!sbi->iostat_enable) |
| 675 | f2fs_reset_iostat(sbi); |
| 676 | return count; |
| 677 | } |
| 678 | |
| 679 | if (!strcmp(a->attr.name, "iostat_period_ms" )) { |
| 680 | if (t < MIN_IOSTAT_PERIOD_MS || t > MAX_IOSTAT_PERIOD_MS) |
| 681 | return -EINVAL; |
| 682 | spin_lock_irq(lock: &sbi->iostat_lock); |
| 683 | sbi->iostat_period_ms = (unsigned int)t; |
| 684 | spin_unlock_irq(lock: &sbi->iostat_lock); |
| 685 | return count; |
| 686 | } |
| 687 | #endif |
| 688 | |
| 689 | #ifdef CONFIG_BLK_DEV_ZONED |
| 690 | if (!strcmp(a->attr.name, "blkzone_alloc_policy" )) { |
| 691 | if (t < BLKZONE_ALLOC_PRIOR_SEQ || t > BLKZONE_ALLOC_PRIOR_CONV) |
| 692 | return -EINVAL; |
| 693 | sbi->blkzone_alloc_policy = t; |
| 694 | return count; |
| 695 | } |
| 696 | #endif |
| 697 | |
| 698 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
| 699 | if (!strcmp(a->attr.name, "compr_written_block" ) || |
| 700 | !strcmp(a->attr.name, "compr_saved_block" )) { |
| 701 | if (t != 0) |
| 702 | return -EINVAL; |
| 703 | sbi->compr_written_block = 0; |
| 704 | sbi->compr_saved_block = 0; |
| 705 | return count; |
| 706 | } |
| 707 | |
| 708 | if (!strcmp(a->attr.name, "compr_new_inode" )) { |
| 709 | if (t != 0) |
| 710 | return -EINVAL; |
| 711 | sbi->compr_new_inode = 0; |
| 712 | return count; |
| 713 | } |
| 714 | |
| 715 | if (!strcmp(a->attr.name, "compress_percent" )) { |
| 716 | if (t == 0 || t > 100) |
| 717 | return -EINVAL; |
| 718 | *ui = t; |
| 719 | return count; |
| 720 | } |
| 721 | |
| 722 | if (!strcmp(a->attr.name, "compress_watermark" )) { |
| 723 | if (t == 0 || t > 100) |
| 724 | return -EINVAL; |
| 725 | *ui = t; |
| 726 | return count; |
| 727 | } |
| 728 | #endif |
| 729 | |
| 730 | if (!strcmp(a->attr.name, "atgc_candidate_ratio" )) { |
| 731 | if (t > 100) |
| 732 | return -EINVAL; |
| 733 | sbi->am.candidate_ratio = t; |
| 734 | return count; |
| 735 | } |
| 736 | |
| 737 | if (!strcmp(a->attr.name, "atgc_age_weight" )) { |
| 738 | if (t > 100) |
| 739 | return -EINVAL; |
| 740 | sbi->am.age_weight = t; |
| 741 | return count; |
| 742 | } |
| 743 | |
| 744 | if (!strcmp(a->attr.name, "gc_segment_mode" )) { |
| 745 | if (t < MAX_GC_MODE) |
| 746 | sbi->gc_segment_mode = t; |
| 747 | else |
| 748 | return -EINVAL; |
| 749 | return count; |
| 750 | } |
| 751 | |
| 752 | if (!strcmp(a->attr.name, "gc_pin_file_threshold" )) { |
| 753 | if (t > MAX_GC_FAILED_PINNED_FILES) |
| 754 | return -EINVAL; |
| 755 | sbi->gc_pin_file_threshold = t; |
| 756 | return count; |
| 757 | } |
| 758 | |
| 759 | if (!strcmp(a->attr.name, "gc_reclaimed_segments" )) { |
| 760 | if (t != 0) |
| 761 | return -EINVAL; |
| 762 | sbi->gc_reclaimed_segs[sbi->gc_segment_mode] = 0; |
| 763 | return count; |
| 764 | } |
| 765 | |
| 766 | if (!strcmp(a->attr.name, "seq_file_ra_mul" )) { |
| 767 | if (t >= MIN_RA_MUL && t <= MAX_RA_MUL) |
| 768 | sbi->seq_file_ra_mul = t; |
| 769 | else |
| 770 | return -EINVAL; |
| 771 | return count; |
| 772 | } |
| 773 | |
| 774 | if (!strcmp(a->attr.name, "max_fragment_chunk" )) { |
| 775 | if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE) |
| 776 | sbi->max_fragment_chunk = t; |
| 777 | else |
| 778 | return -EINVAL; |
| 779 | return count; |
| 780 | } |
| 781 | |
| 782 | if (!strcmp(a->attr.name, "max_fragment_hole" )) { |
| 783 | if (t >= MIN_FRAGMENT_SIZE && t <= MAX_FRAGMENT_SIZE) |
| 784 | sbi->max_fragment_hole = t; |
| 785 | else |
| 786 | return -EINVAL; |
| 787 | return count; |
| 788 | } |
| 789 | |
| 790 | if (!strcmp(a->attr.name, "peak_atomic_write" )) { |
| 791 | if (t != 0) |
| 792 | return -EINVAL; |
| 793 | sbi->peak_atomic_write = 0; |
| 794 | return count; |
| 795 | } |
| 796 | |
| 797 | if (!strcmp(a->attr.name, "committed_atomic_block" )) { |
| 798 | if (t != 0) |
| 799 | return -EINVAL; |
| 800 | sbi->committed_atomic_block = 0; |
| 801 | return count; |
| 802 | } |
| 803 | |
| 804 | if (!strcmp(a->attr.name, "revoked_atomic_block" )) { |
| 805 | if (t != 0) |
| 806 | return -EINVAL; |
| 807 | sbi->revoked_atomic_block = 0; |
| 808 | return count; |
| 809 | } |
| 810 | |
| 811 | if (!strcmp(a->attr.name, "readdir_ra" )) { |
| 812 | sbi->readdir_ra = !!t; |
| 813 | return count; |
| 814 | } |
| 815 | |
| 816 | if (!strcmp(a->attr.name, "hot_data_age_threshold" )) { |
| 817 | if (t == 0 || t >= sbi->warm_data_age_threshold) |
| 818 | return -EINVAL; |
| 819 | if (t == *ui) |
| 820 | return count; |
| 821 | *ui = (unsigned int)t; |
| 822 | return count; |
| 823 | } |
| 824 | |
| 825 | if (!strcmp(a->attr.name, "warm_data_age_threshold" )) { |
| 826 | if (t <= sbi->hot_data_age_threshold) |
| 827 | return -EINVAL; |
| 828 | if (t == *ui) |
| 829 | return count; |
| 830 | *ui = (unsigned int)t; |
| 831 | return count; |
| 832 | } |
| 833 | |
| 834 | if (!strcmp(a->attr.name, "last_age_weight" )) { |
| 835 | if (t > 100) |
| 836 | return -EINVAL; |
| 837 | if (t == *ui) |
| 838 | return count; |
| 839 | *ui = (unsigned int)t; |
| 840 | return count; |
| 841 | } |
| 842 | |
| 843 | if (!strcmp(a->attr.name, "max_read_extent_count" )) { |
| 844 | if (t > UINT_MAX) |
| 845 | return -EINVAL; |
| 846 | *ui = (unsigned int)t; |
| 847 | return count; |
| 848 | } |
| 849 | |
| 850 | if (!strcmp(a->attr.name, "ipu_policy" )) { |
| 851 | if (t >= BIT(F2FS_IPU_MAX)) |
| 852 | return -EINVAL; |
| 853 | /* allow F2FS_IPU_NOCACHE only for IPU in the pinned file */ |
| 854 | if (f2fs_lfs_mode(sbi) && (t & ~BIT(F2FS_IPU_NOCACHE))) |
| 855 | return -EINVAL; |
| 856 | SM_I(sbi)->ipu_policy = (unsigned int)t; |
| 857 | return count; |
| 858 | } |
| 859 | |
| 860 | if (!strcmp(a->attr.name, "dir_level" )) { |
| 861 | if (t > MAX_DIR_HASH_DEPTH) |
| 862 | return -EINVAL; |
| 863 | sbi->dir_level = t; |
| 864 | return count; |
| 865 | } |
| 866 | |
| 867 | if (!strcmp(a->attr.name, "reserved_pin_section" )) { |
| 868 | if (t > GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi))) |
| 869 | return -EINVAL; |
| 870 | *ui = (unsigned int)t; |
| 871 | return count; |
| 872 | } |
| 873 | |
| 874 | if (!strcmp(a->attr.name, "gc_boost_gc_multiple" )) { |
| 875 | if (t < 1 || t > SEGS_PER_SEC(sbi)) |
| 876 | return -EINVAL; |
| 877 | sbi->gc_thread->boost_gc_multiple = (unsigned int)t; |
| 878 | return count; |
| 879 | } |
| 880 | |
| 881 | if (!strcmp(a->attr.name, "gc_boost_gc_greedy" )) { |
| 882 | if (t > GC_GREEDY) |
| 883 | return -EINVAL; |
| 884 | sbi->gc_thread->boost_gc_greedy = (unsigned int)t; |
| 885 | return count; |
| 886 | } |
| 887 | |
| 888 | if (!strcmp(a->attr.name, "bggc_io_aware" )) { |
| 889 | if (t < AWARE_ALL_IO || t > AWARE_NONE) |
| 890 | return -EINVAL; |
| 891 | sbi->bggc_io_aware = t; |
| 892 | return count; |
| 893 | } |
| 894 | |
| 895 | if (!strcmp(a->attr.name, "allocate_section_hint" )) { |
| 896 | if (t < 0 || t > MAIN_SECS(sbi)) |
| 897 | return -EINVAL; |
| 898 | sbi->allocate_section_hint = t; |
| 899 | return count; |
| 900 | } |
| 901 | |
| 902 | if (!strcmp(a->attr.name, "allocate_section_policy" )) { |
| 903 | if (t < ALLOCATE_FORWARD_NOHINT || t > ALLOCATE_FORWARD_FROM_HINT) |
| 904 | return -EINVAL; |
| 905 | sbi->allocate_section_policy = t; |
| 906 | return count; |
| 907 | } |
| 908 | |
| 909 | *ui = (unsigned int)t; |
| 910 | |
| 911 | return count; |
| 912 | } |
| 913 | |
| 914 | static ssize_t f2fs_sbi_store(struct f2fs_attr *a, |
| 915 | struct f2fs_sb_info *sbi, |
| 916 | const char *buf, size_t count) |
| 917 | { |
| 918 | ssize_t ret; |
| 919 | bool gc_entry = (!strcmp(a->attr.name, "gc_urgent" ) || |
| 920 | a->struct_type == GC_THREAD); |
| 921 | |
| 922 | if (gc_entry) { |
| 923 | if (!down_read_trylock(sem: &sbi->sb->s_umount)) |
| 924 | return -EAGAIN; |
| 925 | } |
| 926 | ret = __sbi_store(a, sbi, buf, count); |
| 927 | if (gc_entry) |
| 928 | up_read(sem: &sbi->sb->s_umount); |
| 929 | |
| 930 | return ret; |
| 931 | } |
| 932 | |
| 933 | static ssize_t f2fs_attr_show(struct kobject *kobj, |
| 934 | struct attribute *attr, char *buf) |
| 935 | { |
| 936 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 937 | s_kobj); |
| 938 | struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); |
| 939 | |
| 940 | return a->show ? a->show(a, sbi, buf) : 0; |
| 941 | } |
| 942 | |
| 943 | static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr, |
| 944 | const char *buf, size_t len) |
| 945 | { |
| 946 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 947 | s_kobj); |
| 948 | struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); |
| 949 | |
| 950 | return a->store ? a->store(a, sbi, buf, len) : 0; |
| 951 | } |
| 952 | |
| 953 | static void f2fs_sb_release(struct kobject *kobj) |
| 954 | { |
| 955 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 956 | s_kobj); |
| 957 | complete(&sbi->s_kobj_unregister); |
| 958 | } |
| 959 | |
| 960 | static ssize_t f2fs_base_attr_show(struct kobject *kobj, |
| 961 | struct attribute *attr, char *buf) |
| 962 | { |
| 963 | struct f2fs_base_attr *a = container_of(attr, |
| 964 | struct f2fs_base_attr, attr); |
| 965 | |
| 966 | return a->show ? a->show(a, buf) : 0; |
| 967 | } |
| 968 | |
| 969 | static ssize_t f2fs_base_attr_store(struct kobject *kobj, |
| 970 | struct attribute *attr, |
| 971 | const char *buf, size_t len) |
| 972 | { |
| 973 | struct f2fs_base_attr *a = container_of(attr, |
| 974 | struct f2fs_base_attr, attr); |
| 975 | |
| 976 | return a->store ? a->store(a, buf, len) : 0; |
| 977 | } |
| 978 | |
| 979 | /* |
| 980 | * Note that there are three feature list entries: |
| 981 | * 1) /sys/fs/f2fs/features |
| 982 | * : shows runtime features supported by in-kernel f2fs along with Kconfig. |
| 983 | * - ref. F2FS_FEATURE_RO_ATTR() |
| 984 | * |
| 985 | * 2) /sys/fs/f2fs/$s_id/features <deprecated> |
| 986 | * : shows on-disk features enabled by mkfs.f2fs, used for old kernels. This |
| 987 | * won't add new feature anymore, and thus, users should check entries in 3) |
| 988 | * instead of this 2). |
| 989 | * |
| 990 | * 3) /sys/fs/f2fs/$s_id/feature_list |
| 991 | * : shows on-disk features enabled by mkfs.f2fs per instance, which follows |
| 992 | * sysfs entry rule where each entry should expose single value. |
| 993 | * This list covers old feature list provided by 2) and beyond. Therefore, |
| 994 | * please add new on-disk feature in this list only. |
| 995 | * - ref. F2FS_SB_FEATURE_RO_ATTR() |
| 996 | */ |
| 997 | static ssize_t f2fs_feature_show(struct f2fs_base_attr *a, char *buf) |
| 998 | { |
| 999 | return sysfs_emit(buf, fmt: "supported\n" ); |
| 1000 | } |
| 1001 | |
| 1002 | #define F2FS_FEATURE_RO_ATTR(_name) \ |
| 1003 | static struct f2fs_base_attr f2fs_base_attr_##_name = { \ |
| 1004 | .attr = {.name = __stringify(_name), .mode = 0444 }, \ |
| 1005 | .show = f2fs_feature_show, \ |
| 1006 | } |
| 1007 | |
| 1008 | static ssize_t f2fs_tune_show(struct f2fs_base_attr *a, char *buf) |
| 1009 | { |
| 1010 | unsigned int res = 0; |
| 1011 | |
| 1012 | if (!strcmp(a->attr.name, "reclaim_caches_kb" )) |
| 1013 | res = f2fs_donate_files(); |
| 1014 | |
| 1015 | return sysfs_emit(buf, fmt: "%u\n" , res); |
| 1016 | } |
| 1017 | |
| 1018 | static ssize_t f2fs_tune_store(struct f2fs_base_attr *a, |
| 1019 | const char *buf, size_t count) |
| 1020 | { |
| 1021 | unsigned long t; |
| 1022 | int ret; |
| 1023 | |
| 1024 | ret = kstrtoul(s: skip_spaces(buf), base: 0, res: &t); |
| 1025 | if (ret) |
| 1026 | return ret; |
| 1027 | |
| 1028 | if (!strcmp(a->attr.name, "reclaim_caches_kb" )) |
| 1029 | f2fs_reclaim_caches(reclaim_caches_kb: t); |
| 1030 | |
| 1031 | return count; |
| 1032 | } |
| 1033 | |
| 1034 | #define F2FS_TUNE_RW_ATTR(_name) \ |
| 1035 | static struct f2fs_base_attr f2fs_base_attr_##_name = { \ |
| 1036 | .attr = {.name = __stringify(_name), .mode = 0644 }, \ |
| 1037 | .show = f2fs_tune_show, \ |
| 1038 | .store = f2fs_tune_store, \ |
| 1039 | } |
| 1040 | |
| 1041 | static ssize_t f2fs_sb_feature_show(struct f2fs_attr *a, |
| 1042 | struct f2fs_sb_info *sbi, char *buf) |
| 1043 | { |
| 1044 | if (F2FS_HAS_FEATURE(sbi, a->id)) |
| 1045 | return sysfs_emit(buf, fmt: "supported\n" ); |
| 1046 | return sysfs_emit(buf, fmt: "unsupported\n" ); |
| 1047 | } |
| 1048 | |
| 1049 | #define F2FS_SB_FEATURE_RO_ATTR(_name, _feat) \ |
| 1050 | static struct f2fs_attr f2fs_attr_sb_##_name = { \ |
| 1051 | .attr = {.name = __stringify(_name), .mode = 0444 }, \ |
| 1052 | .show = f2fs_sb_feature_show, \ |
| 1053 | .id = F2FS_FEATURE_##_feat, \ |
| 1054 | } |
| 1055 | |
| 1056 | #define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \ |
| 1057 | static struct f2fs_attr f2fs_attr_##_name = { \ |
| 1058 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 1059 | .show = _show, \ |
| 1060 | .store = _store, \ |
| 1061 | .struct_type = _struct_type, \ |
| 1062 | .offset = _offset \ |
| 1063 | } |
| 1064 | |
| 1065 | #define F2FS_RO_ATTR(struct_type, struct_name, name, elname) \ |
| 1066 | F2FS_ATTR_OFFSET(struct_type, name, 0444, \ |
| 1067 | f2fs_sbi_show, NULL, \ |
| 1068 | offsetof(struct struct_name, elname)) |
| 1069 | |
| 1070 | #define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \ |
| 1071 | F2FS_ATTR_OFFSET(struct_type, name, 0644, \ |
| 1072 | f2fs_sbi_show, f2fs_sbi_store, \ |
| 1073 | offsetof(struct struct_name, elname)) |
| 1074 | |
| 1075 | #define F2FS_GENERAL_RO_ATTR(name) \ |
| 1076 | static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL) |
| 1077 | |
| 1078 | #ifdef CONFIG_F2FS_STAT_FS |
| 1079 | #define STAT_INFO_RO_ATTR(name, elname) \ |
| 1080 | F2FS_RO_ATTR(STAT_INFO, f2fs_stat_info, name, elname) |
| 1081 | #endif |
| 1082 | |
| 1083 | #define GC_THREAD_RW_ATTR(name, elname) \ |
| 1084 | F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, name, elname) |
| 1085 | |
| 1086 | #define SM_INFO_RW_ATTR(name, elname) \ |
| 1087 | F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, name, elname) |
| 1088 | |
| 1089 | #define SM_INFO_GENERAL_RW_ATTR(elname) \ |
| 1090 | SM_INFO_RW_ATTR(elname, elname) |
| 1091 | |
| 1092 | #define DCC_INFO_RW_ATTR(name, elname) \ |
| 1093 | F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, name, elname) |
| 1094 | |
| 1095 | #define DCC_INFO_GENERAL_RW_ATTR(elname) \ |
| 1096 | DCC_INFO_RW_ATTR(elname, elname) |
| 1097 | |
| 1098 | #define NM_INFO_RW_ATTR(name, elname) \ |
| 1099 | F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, name, elname) |
| 1100 | |
| 1101 | #define NM_INFO_GENERAL_RW_ATTR(elname) \ |
| 1102 | NM_INFO_RW_ATTR(elname, elname) |
| 1103 | |
| 1104 | #define F2FS_SBI_RW_ATTR(name, elname) \ |
| 1105 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, name, elname) |
| 1106 | |
| 1107 | #define F2FS_SBI_GENERAL_RW_ATTR(elname) \ |
| 1108 | F2FS_SBI_RW_ATTR(elname, elname) |
| 1109 | |
| 1110 | #define F2FS_SBI_GENERAL_RO_ATTR(elname) \ |
| 1111 | F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, elname, elname) |
| 1112 | |
| 1113 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 1114 | #define FAULT_INFO_GENERAL_RW_ATTR(type, elname) \ |
| 1115 | F2FS_RW_ATTR(type, f2fs_fault_info, elname, elname) |
| 1116 | #endif |
| 1117 | |
| 1118 | #define RESERVED_BLOCKS_GENERAL_RW_ATTR(elname) \ |
| 1119 | F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, elname, elname) |
| 1120 | |
| 1121 | #define CPRC_INFO_GENERAL_RW_ATTR(elname) \ |
| 1122 | F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, elname, elname) |
| 1123 | |
| 1124 | #define ATGC_INFO_RW_ATTR(name, elname) \ |
| 1125 | F2FS_RW_ATTR(ATGC_INFO, atgc_management, name, elname) |
| 1126 | |
| 1127 | /* GC_THREAD ATTR */ |
| 1128 | GC_THREAD_RW_ATTR(gc_urgent_sleep_time, urgent_sleep_time); |
| 1129 | GC_THREAD_RW_ATTR(gc_min_sleep_time, min_sleep_time); |
| 1130 | GC_THREAD_RW_ATTR(gc_max_sleep_time, max_sleep_time); |
| 1131 | GC_THREAD_RW_ATTR(gc_no_gc_sleep_time, no_gc_sleep_time); |
| 1132 | GC_THREAD_RW_ATTR(gc_no_zoned_gc_percent, no_zoned_gc_percent); |
| 1133 | GC_THREAD_RW_ATTR(gc_boost_zoned_gc_percent, boost_zoned_gc_percent); |
| 1134 | GC_THREAD_RW_ATTR(gc_valid_thresh_ratio, valid_thresh_ratio); |
| 1135 | GC_THREAD_RW_ATTR(gc_boost_gc_multiple, boost_gc_multiple); |
| 1136 | GC_THREAD_RW_ATTR(gc_boost_gc_greedy, boost_gc_greedy); |
| 1137 | |
| 1138 | /* SM_INFO ATTR */ |
| 1139 | SM_INFO_RW_ATTR(reclaim_segments, rec_prefree_segments); |
| 1140 | SM_INFO_GENERAL_RW_ATTR(ipu_policy); |
| 1141 | SM_INFO_GENERAL_RW_ATTR(min_ipu_util); |
| 1142 | SM_INFO_GENERAL_RW_ATTR(min_fsync_blocks); |
| 1143 | SM_INFO_GENERAL_RW_ATTR(min_seq_blocks); |
| 1144 | SM_INFO_GENERAL_RW_ATTR(min_hot_blocks); |
| 1145 | SM_INFO_GENERAL_RW_ATTR(min_ssr_sections); |
| 1146 | SM_INFO_GENERAL_RW_ATTR(reserved_segments); |
| 1147 | |
| 1148 | /* DCC_INFO ATTR */ |
| 1149 | DCC_INFO_RW_ATTR(max_small_discards, max_discards); |
| 1150 | DCC_INFO_GENERAL_RW_ATTR(max_discard_request); |
| 1151 | DCC_INFO_GENERAL_RW_ATTR(min_discard_issue_time); |
| 1152 | DCC_INFO_GENERAL_RW_ATTR(mid_discard_issue_time); |
| 1153 | DCC_INFO_GENERAL_RW_ATTR(max_discard_issue_time); |
| 1154 | DCC_INFO_GENERAL_RW_ATTR(discard_io_aware_gran); |
| 1155 | DCC_INFO_GENERAL_RW_ATTR(discard_urgent_util); |
| 1156 | DCC_INFO_GENERAL_RW_ATTR(discard_granularity); |
| 1157 | DCC_INFO_GENERAL_RW_ATTR(max_ordered_discard); |
| 1158 | DCC_INFO_GENERAL_RW_ATTR(discard_io_aware); |
| 1159 | |
| 1160 | /* NM_INFO ATTR */ |
| 1161 | NM_INFO_RW_ATTR(max_roll_forward_node_blocks, max_rf_node_blocks); |
| 1162 | NM_INFO_GENERAL_RW_ATTR(ram_thresh); |
| 1163 | NM_INFO_GENERAL_RW_ATTR(ra_nid_pages); |
| 1164 | NM_INFO_GENERAL_RW_ATTR(dirty_nats_ratio); |
| 1165 | |
| 1166 | /* F2FS_SBI ATTR */ |
| 1167 | F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list); |
| 1168 | F2FS_SBI_RW_ATTR(gc_idle, gc_mode); |
| 1169 | F2FS_SBI_RW_ATTR(gc_urgent, gc_mode); |
| 1170 | F2FS_SBI_RW_ATTR(cp_interval, interval_time[CP_TIME]); |
| 1171 | F2FS_SBI_RW_ATTR(idle_interval, interval_time[REQ_TIME]); |
| 1172 | F2FS_SBI_RW_ATTR(discard_idle_interval, interval_time[DISCARD_TIME]); |
| 1173 | F2FS_SBI_RW_ATTR(gc_idle_interval, interval_time[GC_TIME]); |
| 1174 | F2FS_SBI_RW_ATTR(umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]); |
| 1175 | F2FS_SBI_RW_ATTR(gc_pin_file_thresh, gc_pin_file_threshold); |
| 1176 | F2FS_SBI_RW_ATTR(gc_reclaimed_segments, gc_reclaimed_segs); |
| 1177 | F2FS_SBI_GENERAL_RW_ATTR(max_victim_search); |
| 1178 | F2FS_SBI_GENERAL_RW_ATTR(migration_granularity); |
| 1179 | F2FS_SBI_GENERAL_RW_ATTR(migration_window_granularity); |
| 1180 | F2FS_SBI_GENERAL_RW_ATTR(dir_level); |
| 1181 | F2FS_SBI_GENERAL_RW_ATTR(allocate_section_hint); |
| 1182 | F2FS_SBI_GENERAL_RW_ATTR(allocate_section_policy); |
| 1183 | #ifdef CONFIG_F2FS_IOSTAT |
| 1184 | F2FS_SBI_GENERAL_RW_ATTR(iostat_enable); |
| 1185 | F2FS_SBI_GENERAL_RW_ATTR(iostat_period_ms); |
| 1186 | #endif |
| 1187 | F2FS_SBI_GENERAL_RW_ATTR(readdir_ra); |
| 1188 | F2FS_SBI_GENERAL_RW_ATTR(max_io_bytes); |
| 1189 | F2FS_SBI_GENERAL_RW_ATTR(data_io_flag); |
| 1190 | F2FS_SBI_GENERAL_RW_ATTR(node_io_flag); |
| 1191 | F2FS_SBI_GENERAL_RW_ATTR(gc_remaining_trials); |
| 1192 | F2FS_SBI_GENERAL_RW_ATTR(seq_file_ra_mul); |
| 1193 | F2FS_SBI_GENERAL_RW_ATTR(gc_segment_mode); |
| 1194 | F2FS_SBI_GENERAL_RW_ATTR(max_fragment_chunk); |
| 1195 | F2FS_SBI_GENERAL_RW_ATTR(max_fragment_hole); |
| 1196 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
| 1197 | F2FS_SBI_GENERAL_RW_ATTR(compr_written_block); |
| 1198 | F2FS_SBI_GENERAL_RW_ATTR(compr_saved_block); |
| 1199 | F2FS_SBI_GENERAL_RW_ATTR(compr_new_inode); |
| 1200 | F2FS_SBI_GENERAL_RW_ATTR(compress_percent); |
| 1201 | F2FS_SBI_GENERAL_RW_ATTR(compress_watermark); |
| 1202 | #endif |
| 1203 | /* atomic write */ |
| 1204 | F2FS_SBI_GENERAL_RO_ATTR(current_atomic_write); |
| 1205 | F2FS_SBI_GENERAL_RW_ATTR(peak_atomic_write); |
| 1206 | F2FS_SBI_GENERAL_RW_ATTR(committed_atomic_block); |
| 1207 | F2FS_SBI_GENERAL_RW_ATTR(revoked_atomic_block); |
| 1208 | /* block age extent cache */ |
| 1209 | F2FS_SBI_GENERAL_RW_ATTR(hot_data_age_threshold); |
| 1210 | F2FS_SBI_GENERAL_RW_ATTR(warm_data_age_threshold); |
| 1211 | F2FS_SBI_GENERAL_RW_ATTR(last_age_weight); |
| 1212 | /* read extent cache */ |
| 1213 | F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count); |
| 1214 | #ifdef CONFIG_BLK_DEV_ZONED |
| 1215 | F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec); |
| 1216 | F2FS_SBI_GENERAL_RO_ATTR(max_open_zones); |
| 1217 | F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy); |
| 1218 | #endif |
| 1219 | F2FS_SBI_GENERAL_RW_ATTR(carve_out); |
| 1220 | F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section); |
| 1221 | F2FS_SBI_GENERAL_RW_ATTR(bggc_io_aware); |
| 1222 | |
| 1223 | /* STAT_INFO ATTR */ |
| 1224 | #ifdef CONFIG_F2FS_STAT_FS |
| 1225 | STAT_INFO_RO_ATTR(cp_foreground_calls, cp_call_count[FOREGROUND]); |
| 1226 | STAT_INFO_RO_ATTR(cp_background_calls, cp_call_count[BACKGROUND]); |
| 1227 | STAT_INFO_RO_ATTR(gc_foreground_calls, gc_call_count[FOREGROUND]); |
| 1228 | STAT_INFO_RO_ATTR(gc_background_calls, gc_call_count[BACKGROUND]); |
| 1229 | #endif |
| 1230 | |
| 1231 | /* FAULT_INFO ATTR */ |
| 1232 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 1233 | FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_RATE, inject_rate); |
| 1234 | FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_TYPE, inject_type); |
| 1235 | #endif |
| 1236 | |
| 1237 | /* RESERVED_BLOCKS ATTR */ |
| 1238 | RESERVED_BLOCKS_GENERAL_RW_ATTR(reserved_blocks); |
| 1239 | |
| 1240 | /* CPRC_INFO ATTR */ |
| 1241 | CPRC_INFO_GENERAL_RW_ATTR(ckpt_thread_ioprio); |
| 1242 | |
| 1243 | /* ATGC_INFO ATTR */ |
| 1244 | ATGC_INFO_RW_ATTR(atgc_candidate_ratio, candidate_ratio); |
| 1245 | ATGC_INFO_RW_ATTR(atgc_candidate_count, max_candidate_count); |
| 1246 | ATGC_INFO_RW_ATTR(atgc_age_weight, age_weight); |
| 1247 | ATGC_INFO_RW_ATTR(atgc_age_threshold, age_threshold); |
| 1248 | |
| 1249 | F2FS_GENERAL_RO_ATTR(dirty_segments); |
| 1250 | F2FS_GENERAL_RO_ATTR(free_segments); |
| 1251 | F2FS_GENERAL_RO_ATTR(ovp_segments); |
| 1252 | F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); |
| 1253 | F2FS_GENERAL_RO_ATTR(features); |
| 1254 | F2FS_GENERAL_RO_ATTR(current_reserved_blocks); |
| 1255 | F2FS_GENERAL_RO_ATTR(unusable); |
| 1256 | F2FS_GENERAL_RO_ATTR(encoding); |
| 1257 | F2FS_GENERAL_RO_ATTR(encoding_flags); |
| 1258 | F2FS_GENERAL_RO_ATTR(effective_lookup_mode); |
| 1259 | F2FS_GENERAL_RO_ATTR(mounted_time_sec); |
| 1260 | F2FS_GENERAL_RO_ATTR(main_blkaddr); |
| 1261 | F2FS_GENERAL_RO_ATTR(pending_discard); |
| 1262 | F2FS_GENERAL_RO_ATTR(atgc_enabled); |
| 1263 | F2FS_GENERAL_RO_ATTR(gc_mode); |
| 1264 | #ifdef CONFIG_F2FS_STAT_FS |
| 1265 | F2FS_GENERAL_RO_ATTR(moved_blocks_background); |
| 1266 | F2FS_GENERAL_RO_ATTR(moved_blocks_foreground); |
| 1267 | F2FS_GENERAL_RO_ATTR(avg_vblocks); |
| 1268 | #endif |
| 1269 | |
| 1270 | #ifdef CONFIG_FS_ENCRYPTION |
| 1271 | F2FS_FEATURE_RO_ATTR(encryption); |
| 1272 | F2FS_FEATURE_RO_ATTR(test_dummy_encryption_v2); |
| 1273 | #if IS_ENABLED(CONFIG_UNICODE) |
| 1274 | F2FS_FEATURE_RO_ATTR(encrypted_casefold); |
| 1275 | #endif |
| 1276 | #endif /* CONFIG_FS_ENCRYPTION */ |
| 1277 | #ifdef CONFIG_BLK_DEV_ZONED |
| 1278 | F2FS_FEATURE_RO_ATTR(block_zoned); |
| 1279 | #endif |
| 1280 | F2FS_FEATURE_RO_ATTR(atomic_write); |
| 1281 | F2FS_FEATURE_RO_ATTR(extra_attr); |
| 1282 | F2FS_FEATURE_RO_ATTR(project_quota); |
| 1283 | F2FS_FEATURE_RO_ATTR(inode_checksum); |
| 1284 | F2FS_FEATURE_RO_ATTR(flexible_inline_xattr); |
| 1285 | F2FS_FEATURE_RO_ATTR(quota_ino); |
| 1286 | F2FS_FEATURE_RO_ATTR(inode_crtime); |
| 1287 | F2FS_FEATURE_RO_ATTR(lost_found); |
| 1288 | #ifdef CONFIG_FS_VERITY |
| 1289 | F2FS_FEATURE_RO_ATTR(verity); |
| 1290 | #endif |
| 1291 | F2FS_FEATURE_RO_ATTR(sb_checksum); |
| 1292 | #if IS_ENABLED(CONFIG_UNICODE) |
| 1293 | F2FS_FEATURE_RO_ATTR(casefold); |
| 1294 | #endif |
| 1295 | F2FS_FEATURE_RO_ATTR(readonly); |
| 1296 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
| 1297 | F2FS_FEATURE_RO_ATTR(compression); |
| 1298 | #endif |
| 1299 | F2FS_FEATURE_RO_ATTR(pin_file); |
| 1300 | #ifdef CONFIG_UNICODE |
| 1301 | F2FS_FEATURE_RO_ATTR(linear_lookup); |
| 1302 | #endif |
| 1303 | F2FS_FEATURE_RO_ATTR(packed_ssa); |
| 1304 | |
| 1305 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) |
| 1306 | static struct attribute *f2fs_attrs[] = { |
| 1307 | ATTR_LIST(gc_urgent_sleep_time), |
| 1308 | ATTR_LIST(gc_min_sleep_time), |
| 1309 | ATTR_LIST(gc_max_sleep_time), |
| 1310 | ATTR_LIST(gc_no_gc_sleep_time), |
| 1311 | ATTR_LIST(gc_no_zoned_gc_percent), |
| 1312 | ATTR_LIST(gc_boost_zoned_gc_percent), |
| 1313 | ATTR_LIST(gc_valid_thresh_ratio), |
| 1314 | ATTR_LIST(gc_boost_gc_multiple), |
| 1315 | ATTR_LIST(gc_boost_gc_greedy), |
| 1316 | ATTR_LIST(gc_idle), |
| 1317 | ATTR_LIST(gc_urgent), |
| 1318 | ATTR_LIST(reclaim_segments), |
| 1319 | ATTR_LIST(main_blkaddr), |
| 1320 | ATTR_LIST(max_small_discards), |
| 1321 | ATTR_LIST(max_discard_request), |
| 1322 | ATTR_LIST(min_discard_issue_time), |
| 1323 | ATTR_LIST(mid_discard_issue_time), |
| 1324 | ATTR_LIST(max_discard_issue_time), |
| 1325 | ATTR_LIST(discard_io_aware_gran), |
| 1326 | ATTR_LIST(discard_urgent_util), |
| 1327 | ATTR_LIST(discard_granularity), |
| 1328 | ATTR_LIST(max_ordered_discard), |
| 1329 | ATTR_LIST(discard_io_aware), |
| 1330 | ATTR_LIST(pending_discard), |
| 1331 | ATTR_LIST(gc_mode), |
| 1332 | ATTR_LIST(ipu_policy), |
| 1333 | ATTR_LIST(min_ipu_util), |
| 1334 | ATTR_LIST(min_fsync_blocks), |
| 1335 | ATTR_LIST(min_seq_blocks), |
| 1336 | ATTR_LIST(min_hot_blocks), |
| 1337 | ATTR_LIST(min_ssr_sections), |
| 1338 | ATTR_LIST(reserved_segments), |
| 1339 | ATTR_LIST(max_victim_search), |
| 1340 | ATTR_LIST(migration_granularity), |
| 1341 | ATTR_LIST(migration_window_granularity), |
| 1342 | ATTR_LIST(dir_level), |
| 1343 | ATTR_LIST(ram_thresh), |
| 1344 | ATTR_LIST(ra_nid_pages), |
| 1345 | ATTR_LIST(dirty_nats_ratio), |
| 1346 | ATTR_LIST(max_roll_forward_node_blocks), |
| 1347 | ATTR_LIST(cp_interval), |
| 1348 | ATTR_LIST(idle_interval), |
| 1349 | ATTR_LIST(discard_idle_interval), |
| 1350 | ATTR_LIST(gc_idle_interval), |
| 1351 | ATTR_LIST(umount_discard_timeout), |
| 1352 | ATTR_LIST(bggc_io_aware), |
| 1353 | #ifdef CONFIG_F2FS_IOSTAT |
| 1354 | ATTR_LIST(iostat_enable), |
| 1355 | ATTR_LIST(iostat_period_ms), |
| 1356 | #endif |
| 1357 | ATTR_LIST(readdir_ra), |
| 1358 | ATTR_LIST(max_io_bytes), |
| 1359 | ATTR_LIST(gc_pin_file_thresh), |
| 1360 | ATTR_LIST(extension_list), |
| 1361 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 1362 | ATTR_LIST(inject_rate), |
| 1363 | ATTR_LIST(inject_type), |
| 1364 | #endif |
| 1365 | ATTR_LIST(data_io_flag), |
| 1366 | ATTR_LIST(node_io_flag), |
| 1367 | ATTR_LIST(gc_remaining_trials), |
| 1368 | ATTR_LIST(ckpt_thread_ioprio), |
| 1369 | ATTR_LIST(dirty_segments), |
| 1370 | ATTR_LIST(free_segments), |
| 1371 | ATTR_LIST(ovp_segments), |
| 1372 | ATTR_LIST(unusable), |
| 1373 | ATTR_LIST(lifetime_write_kbytes), |
| 1374 | ATTR_LIST(features), |
| 1375 | ATTR_LIST(reserved_blocks), |
| 1376 | ATTR_LIST(current_reserved_blocks), |
| 1377 | ATTR_LIST(encoding), |
| 1378 | ATTR_LIST(encoding_flags), |
| 1379 | ATTR_LIST(effective_lookup_mode), |
| 1380 | ATTR_LIST(mounted_time_sec), |
| 1381 | #ifdef CONFIG_F2FS_STAT_FS |
| 1382 | ATTR_LIST(cp_foreground_calls), |
| 1383 | ATTR_LIST(cp_background_calls), |
| 1384 | ATTR_LIST(gc_foreground_calls), |
| 1385 | ATTR_LIST(gc_background_calls), |
| 1386 | ATTR_LIST(moved_blocks_foreground), |
| 1387 | ATTR_LIST(moved_blocks_background), |
| 1388 | ATTR_LIST(avg_vblocks), |
| 1389 | #endif |
| 1390 | #ifdef CONFIG_BLK_DEV_ZONED |
| 1391 | ATTR_LIST(unusable_blocks_per_sec), |
| 1392 | ATTR_LIST(max_open_zones), |
| 1393 | ATTR_LIST(blkzone_alloc_policy), |
| 1394 | #endif |
| 1395 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
| 1396 | ATTR_LIST(compr_written_block), |
| 1397 | ATTR_LIST(compr_saved_block), |
| 1398 | ATTR_LIST(compr_new_inode), |
| 1399 | ATTR_LIST(compress_percent), |
| 1400 | ATTR_LIST(compress_watermark), |
| 1401 | #endif |
| 1402 | /* For ATGC */ |
| 1403 | ATTR_LIST(atgc_candidate_ratio), |
| 1404 | ATTR_LIST(atgc_candidate_count), |
| 1405 | ATTR_LIST(atgc_age_weight), |
| 1406 | ATTR_LIST(atgc_age_threshold), |
| 1407 | ATTR_LIST(atgc_enabled), |
| 1408 | ATTR_LIST(seq_file_ra_mul), |
| 1409 | ATTR_LIST(gc_segment_mode), |
| 1410 | ATTR_LIST(gc_reclaimed_segments), |
| 1411 | ATTR_LIST(max_fragment_chunk), |
| 1412 | ATTR_LIST(max_fragment_hole), |
| 1413 | ATTR_LIST(current_atomic_write), |
| 1414 | ATTR_LIST(peak_atomic_write), |
| 1415 | ATTR_LIST(committed_atomic_block), |
| 1416 | ATTR_LIST(revoked_atomic_block), |
| 1417 | ATTR_LIST(hot_data_age_threshold), |
| 1418 | ATTR_LIST(warm_data_age_threshold), |
| 1419 | ATTR_LIST(last_age_weight), |
| 1420 | ATTR_LIST(max_read_extent_count), |
| 1421 | ATTR_LIST(carve_out), |
| 1422 | ATTR_LIST(reserved_pin_section), |
| 1423 | ATTR_LIST(allocate_section_hint), |
| 1424 | ATTR_LIST(allocate_section_policy), |
| 1425 | NULL, |
| 1426 | }; |
| 1427 | ATTRIBUTE_GROUPS(f2fs); |
| 1428 | |
| 1429 | #define BASE_ATTR_LIST(name) (&f2fs_base_attr_##name.attr) |
| 1430 | static struct attribute *f2fs_feat_attrs[] = { |
| 1431 | #ifdef CONFIG_FS_ENCRYPTION |
| 1432 | BASE_ATTR_LIST(encryption), |
| 1433 | BASE_ATTR_LIST(test_dummy_encryption_v2), |
| 1434 | #if IS_ENABLED(CONFIG_UNICODE) |
| 1435 | BASE_ATTR_LIST(encrypted_casefold), |
| 1436 | #endif |
| 1437 | #endif /* CONFIG_FS_ENCRYPTION */ |
| 1438 | #ifdef CONFIG_BLK_DEV_ZONED |
| 1439 | BASE_ATTR_LIST(block_zoned), |
| 1440 | #endif |
| 1441 | BASE_ATTR_LIST(atomic_write), |
| 1442 | BASE_ATTR_LIST(extra_attr), |
| 1443 | BASE_ATTR_LIST(project_quota), |
| 1444 | BASE_ATTR_LIST(inode_checksum), |
| 1445 | BASE_ATTR_LIST(flexible_inline_xattr), |
| 1446 | BASE_ATTR_LIST(quota_ino), |
| 1447 | BASE_ATTR_LIST(inode_crtime), |
| 1448 | BASE_ATTR_LIST(lost_found), |
| 1449 | #ifdef CONFIG_FS_VERITY |
| 1450 | BASE_ATTR_LIST(verity), |
| 1451 | #endif |
| 1452 | BASE_ATTR_LIST(sb_checksum), |
| 1453 | #if IS_ENABLED(CONFIG_UNICODE) |
| 1454 | BASE_ATTR_LIST(casefold), |
| 1455 | #endif |
| 1456 | BASE_ATTR_LIST(readonly), |
| 1457 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
| 1458 | BASE_ATTR_LIST(compression), |
| 1459 | #endif |
| 1460 | BASE_ATTR_LIST(pin_file), |
| 1461 | #ifdef CONFIG_UNICODE |
| 1462 | BASE_ATTR_LIST(linear_lookup), |
| 1463 | #endif |
| 1464 | BASE_ATTR_LIST(packed_ssa), |
| 1465 | NULL, |
| 1466 | }; |
| 1467 | ATTRIBUTE_GROUPS(f2fs_feat); |
| 1468 | |
| 1469 | F2FS_GENERAL_RO_ATTR(sb_status); |
| 1470 | F2FS_GENERAL_RO_ATTR(cp_status); |
| 1471 | F2FS_GENERAL_RO_ATTR(issued_discard); |
| 1472 | F2FS_GENERAL_RO_ATTR(queued_discard); |
| 1473 | F2FS_GENERAL_RO_ATTR(undiscard_blks); |
| 1474 | |
| 1475 | static struct attribute *f2fs_stat_attrs[] = { |
| 1476 | ATTR_LIST(sb_status), |
| 1477 | ATTR_LIST(cp_status), |
| 1478 | ATTR_LIST(issued_discard), |
| 1479 | ATTR_LIST(queued_discard), |
| 1480 | ATTR_LIST(undiscard_blks), |
| 1481 | NULL, |
| 1482 | }; |
| 1483 | ATTRIBUTE_GROUPS(f2fs_stat); |
| 1484 | |
| 1485 | F2FS_SB_FEATURE_RO_ATTR(encryption, ENCRYPT); |
| 1486 | F2FS_SB_FEATURE_RO_ATTR(block_zoned, BLKZONED); |
| 1487 | F2FS_SB_FEATURE_RO_ATTR(extra_attr, EXTRA_ATTR); |
| 1488 | F2FS_SB_FEATURE_RO_ATTR(project_quota, PRJQUOTA); |
| 1489 | F2FS_SB_FEATURE_RO_ATTR(inode_checksum, INODE_CHKSUM); |
| 1490 | F2FS_SB_FEATURE_RO_ATTR(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); |
| 1491 | F2FS_SB_FEATURE_RO_ATTR(quota_ino, QUOTA_INO); |
| 1492 | F2FS_SB_FEATURE_RO_ATTR(inode_crtime, INODE_CRTIME); |
| 1493 | F2FS_SB_FEATURE_RO_ATTR(lost_found, LOST_FOUND); |
| 1494 | F2FS_SB_FEATURE_RO_ATTR(verity, VERITY); |
| 1495 | F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM); |
| 1496 | F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD); |
| 1497 | F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION); |
| 1498 | F2FS_SB_FEATURE_RO_ATTR(readonly, RO); |
| 1499 | F2FS_SB_FEATURE_RO_ATTR(device_alias, DEVICE_ALIAS); |
| 1500 | F2FS_SB_FEATURE_RO_ATTR(packed_ssa, PACKED_SSA); |
| 1501 | |
| 1502 | static struct attribute *f2fs_sb_feat_attrs[] = { |
| 1503 | ATTR_LIST(sb_encryption), |
| 1504 | ATTR_LIST(sb_block_zoned), |
| 1505 | ATTR_LIST(sb_extra_attr), |
| 1506 | ATTR_LIST(sb_project_quota), |
| 1507 | ATTR_LIST(sb_inode_checksum), |
| 1508 | ATTR_LIST(sb_flexible_inline_xattr), |
| 1509 | ATTR_LIST(sb_quota_ino), |
| 1510 | ATTR_LIST(sb_inode_crtime), |
| 1511 | ATTR_LIST(sb_lost_found), |
| 1512 | ATTR_LIST(sb_verity), |
| 1513 | ATTR_LIST(sb_sb_checksum), |
| 1514 | ATTR_LIST(sb_casefold), |
| 1515 | ATTR_LIST(sb_compression), |
| 1516 | ATTR_LIST(sb_readonly), |
| 1517 | ATTR_LIST(sb_device_alias), |
| 1518 | ATTR_LIST(sb_packed_ssa), |
| 1519 | NULL, |
| 1520 | }; |
| 1521 | ATTRIBUTE_GROUPS(f2fs_sb_feat); |
| 1522 | |
| 1523 | F2FS_TUNE_RW_ATTR(reclaim_caches_kb); |
| 1524 | |
| 1525 | static struct attribute *f2fs_tune_attrs[] = { |
| 1526 | BASE_ATTR_LIST(reclaim_caches_kb), |
| 1527 | NULL, |
| 1528 | }; |
| 1529 | ATTRIBUTE_GROUPS(f2fs_tune); |
| 1530 | |
| 1531 | static const struct sysfs_ops f2fs_attr_ops = { |
| 1532 | .show = f2fs_attr_show, |
| 1533 | .store = f2fs_attr_store, |
| 1534 | }; |
| 1535 | |
| 1536 | static const struct kobj_type f2fs_sb_ktype = { |
| 1537 | .default_groups = f2fs_groups, |
| 1538 | .sysfs_ops = &f2fs_attr_ops, |
| 1539 | .release = f2fs_sb_release, |
| 1540 | }; |
| 1541 | |
| 1542 | static const struct kobj_type f2fs_ktype = { |
| 1543 | .sysfs_ops = &f2fs_attr_ops, |
| 1544 | }; |
| 1545 | |
| 1546 | static struct kset f2fs_kset = { |
| 1547 | .kobj = {.ktype = &f2fs_ktype}, |
| 1548 | }; |
| 1549 | |
| 1550 | static const struct sysfs_ops f2fs_feat_attr_ops = { |
| 1551 | .show = f2fs_base_attr_show, |
| 1552 | .store = f2fs_base_attr_store, |
| 1553 | }; |
| 1554 | |
| 1555 | static const struct kobj_type f2fs_feat_ktype = { |
| 1556 | .default_groups = f2fs_feat_groups, |
| 1557 | .sysfs_ops = &f2fs_feat_attr_ops, |
| 1558 | }; |
| 1559 | |
| 1560 | static struct kobject f2fs_feat = { |
| 1561 | .kset = &f2fs_kset, |
| 1562 | }; |
| 1563 | |
| 1564 | static const struct sysfs_ops f2fs_tune_attr_ops = { |
| 1565 | .show = f2fs_base_attr_show, |
| 1566 | .store = f2fs_base_attr_store, |
| 1567 | }; |
| 1568 | |
| 1569 | static const struct kobj_type f2fs_tune_ktype = { |
| 1570 | .default_groups = f2fs_tune_groups, |
| 1571 | .sysfs_ops = &f2fs_tune_attr_ops, |
| 1572 | }; |
| 1573 | |
| 1574 | static struct kobject f2fs_tune = { |
| 1575 | .kset = &f2fs_kset, |
| 1576 | }; |
| 1577 | |
| 1578 | static ssize_t f2fs_stat_attr_show(struct kobject *kobj, |
| 1579 | struct attribute *attr, char *buf) |
| 1580 | { |
| 1581 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 1582 | s_stat_kobj); |
| 1583 | struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); |
| 1584 | |
| 1585 | return a->show ? a->show(a, sbi, buf) : 0; |
| 1586 | } |
| 1587 | |
| 1588 | static ssize_t f2fs_stat_attr_store(struct kobject *kobj, struct attribute *attr, |
| 1589 | const char *buf, size_t len) |
| 1590 | { |
| 1591 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 1592 | s_stat_kobj); |
| 1593 | struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); |
| 1594 | |
| 1595 | return a->store ? a->store(a, sbi, buf, len) : 0; |
| 1596 | } |
| 1597 | |
| 1598 | static void f2fs_stat_kobj_release(struct kobject *kobj) |
| 1599 | { |
| 1600 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 1601 | s_stat_kobj); |
| 1602 | complete(&sbi->s_stat_kobj_unregister); |
| 1603 | } |
| 1604 | |
| 1605 | static const struct sysfs_ops f2fs_stat_attr_ops = { |
| 1606 | .show = f2fs_stat_attr_show, |
| 1607 | .store = f2fs_stat_attr_store, |
| 1608 | }; |
| 1609 | |
| 1610 | static const struct kobj_type f2fs_stat_ktype = { |
| 1611 | .default_groups = f2fs_stat_groups, |
| 1612 | .sysfs_ops = &f2fs_stat_attr_ops, |
| 1613 | .release = f2fs_stat_kobj_release, |
| 1614 | }; |
| 1615 | |
| 1616 | static ssize_t f2fs_sb_feat_attr_show(struct kobject *kobj, |
| 1617 | struct attribute *attr, char *buf) |
| 1618 | { |
| 1619 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 1620 | s_feature_list_kobj); |
| 1621 | struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); |
| 1622 | |
| 1623 | return a->show ? a->show(a, sbi, buf) : 0; |
| 1624 | } |
| 1625 | |
| 1626 | static void f2fs_feature_list_kobj_release(struct kobject *kobj) |
| 1627 | { |
| 1628 | struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, |
| 1629 | s_feature_list_kobj); |
| 1630 | complete(&sbi->s_feature_list_kobj_unregister); |
| 1631 | } |
| 1632 | |
| 1633 | static const struct sysfs_ops f2fs_feature_list_attr_ops = { |
| 1634 | .show = f2fs_sb_feat_attr_show, |
| 1635 | }; |
| 1636 | |
| 1637 | static const struct kobj_type f2fs_feature_list_ktype = { |
| 1638 | .default_groups = f2fs_sb_feat_groups, |
| 1639 | .sysfs_ops = &f2fs_feature_list_attr_ops, |
| 1640 | .release = f2fs_feature_list_kobj_release, |
| 1641 | }; |
| 1642 | |
| 1643 | static int __maybe_unused segment_info_seq_show(struct seq_file *seq, |
| 1644 | void *offset) |
| 1645 | { |
| 1646 | struct super_block *sb = seq->private; |
| 1647 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1648 | unsigned int total_segs = |
| 1649 | le32_to_cpu(sbi->raw_super->segment_count_main); |
| 1650 | int i; |
| 1651 | |
| 1652 | seq_puts(m: seq, s: "format: segment_type|valid_blocks\n" |
| 1653 | "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n" ); |
| 1654 | |
| 1655 | for (i = 0; i < total_segs; i++) { |
| 1656 | struct seg_entry *se = get_seg_entry(sbi, segno: i); |
| 1657 | |
| 1658 | if ((i % 10) == 0) |
| 1659 | seq_printf(m: seq, fmt: "%-10d" , i); |
| 1660 | seq_printf(m: seq, fmt: "%d|%-3u" , se->type, se->valid_blocks); |
| 1661 | if ((i % 10) == 9 || i == (total_segs - 1)) |
| 1662 | seq_putc(m: seq, c: '\n'); |
| 1663 | else |
| 1664 | seq_putc(m: seq, c: ' '); |
| 1665 | } |
| 1666 | |
| 1667 | return 0; |
| 1668 | } |
| 1669 | |
| 1670 | static int __maybe_unused segment_bits_seq_show(struct seq_file *seq, |
| 1671 | void *offset) |
| 1672 | { |
| 1673 | struct super_block *sb = seq->private; |
| 1674 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1675 | unsigned int total_segs = |
| 1676 | le32_to_cpu(sbi->raw_super->segment_count_main); |
| 1677 | int i, j; |
| 1678 | |
| 1679 | seq_puts(m: seq, s: "format: segment_type|valid_blocks|bitmaps|mtime\n" |
| 1680 | "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n" ); |
| 1681 | |
| 1682 | for (i = 0; i < total_segs; i++) { |
| 1683 | struct seg_entry *se = get_seg_entry(sbi, segno: i); |
| 1684 | |
| 1685 | seq_printf(m: seq, fmt: "%-10d" , i); |
| 1686 | seq_printf(m: seq, fmt: "%d|%-3u|" , se->type, se->valid_blocks); |
| 1687 | for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++) |
| 1688 | seq_printf(m: seq, fmt: " %.2x" , se->cur_valid_map[j]); |
| 1689 | seq_printf(m: seq, fmt: "| %llx" , se->mtime); |
| 1690 | seq_putc(m: seq, c: '\n'); |
| 1691 | } |
| 1692 | return 0; |
| 1693 | } |
| 1694 | |
| 1695 | static int __maybe_unused victim_bits_seq_show(struct seq_file *seq, |
| 1696 | void *offset) |
| 1697 | { |
| 1698 | struct super_block *sb = seq->private; |
| 1699 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1700 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); |
| 1701 | int i; |
| 1702 | |
| 1703 | seq_puts(m: seq, s: "format: victim_secmap bitmaps\n" ); |
| 1704 | |
| 1705 | for (i = 0; i < MAIN_SECS(sbi); i++) { |
| 1706 | if ((i % 10) == 0) |
| 1707 | seq_printf(m: seq, fmt: "%-10d" , i); |
| 1708 | seq_printf(m: seq, fmt: "%d" , test_bit(i, dirty_i->victim_secmap) ? 1 : 0); |
| 1709 | if ((i % 10) == 9 || i == (MAIN_SECS(sbi) - 1)) |
| 1710 | seq_putc(m: seq, c: '\n'); |
| 1711 | else |
| 1712 | seq_putc(m: seq, c: ' '); |
| 1713 | } |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
| 1717 | static int __maybe_unused discard_plist_seq_show(struct seq_file *seq, |
| 1718 | void *offset) |
| 1719 | { |
| 1720 | struct super_block *sb = seq->private; |
| 1721 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1722 | struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; |
| 1723 | int i, count; |
| 1724 | |
| 1725 | seq_puts(m: seq, s: "Discard pend list(Show diacrd_cmd count on each entry, .:not exist):\n" ); |
| 1726 | if (!f2fs_realtime_discard_enable(sbi)) |
| 1727 | return 0; |
| 1728 | |
| 1729 | if (dcc) { |
| 1730 | mutex_lock(&dcc->cmd_lock); |
| 1731 | for (i = 0; i < MAX_PLIST_NUM; i++) { |
| 1732 | struct list_head *pend_list; |
| 1733 | struct discard_cmd *dc, *tmp; |
| 1734 | |
| 1735 | if (i % 8 == 0) |
| 1736 | seq_printf(m: seq, fmt: " %-3d" , i); |
| 1737 | count = 0; |
| 1738 | pend_list = &dcc->pend_list[i]; |
| 1739 | list_for_each_entry_safe(dc, tmp, pend_list, list) |
| 1740 | count++; |
| 1741 | if (count) |
| 1742 | seq_printf(m: seq, fmt: " %7d" , count); |
| 1743 | else |
| 1744 | seq_puts(m: seq, s: " ." ); |
| 1745 | if (i % 8 == 7) |
| 1746 | seq_putc(m: seq, c: '\n'); |
| 1747 | } |
| 1748 | seq_putc(m: seq, c: '\n'); |
| 1749 | mutex_unlock(lock: &dcc->cmd_lock); |
| 1750 | } |
| 1751 | |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | static int __maybe_unused disk_map_seq_show(struct seq_file *seq, |
| 1756 | void *offset) |
| 1757 | { |
| 1758 | struct super_block *sb = seq->private; |
| 1759 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1760 | int i; |
| 1761 | |
| 1762 | seq_printf(m: seq, fmt: "Address Layout : %5luB Block address (# of Segments)\n" , |
| 1763 | F2FS_BLKSIZE); |
| 1764 | seq_printf(m: seq, fmt: " SB : %12s\n" , "0/1024B" ); |
| 1765 | seq_printf(m: seq, fmt: " seg0_blkaddr : 0x%010x\n" , SEG0_BLKADDR(sbi)); |
| 1766 | seq_printf(m: seq, fmt: " Checkpoint : 0x%010x (%10d)\n" , |
| 1767 | le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr), 2); |
| 1768 | seq_printf(m: seq, fmt: " SIT : 0x%010x (%10d)\n" , |
| 1769 | SIT_I(sbi)->sit_base_addr, |
| 1770 | le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_sit)); |
| 1771 | seq_printf(m: seq, fmt: " NAT : 0x%010x (%10d)\n" , |
| 1772 | NM_I(sbi)->nat_blkaddr, |
| 1773 | le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_nat)); |
| 1774 | seq_printf(m: seq, fmt: " SSA : 0x%010x (%10d)\n" , |
| 1775 | SM_I(sbi)->ssa_blkaddr, |
| 1776 | le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_ssa)); |
| 1777 | seq_printf(m: seq, fmt: " Main : 0x%010x (%10d)\n" , |
| 1778 | SM_I(sbi)->main_blkaddr, |
| 1779 | le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main)); |
| 1780 | seq_printf(m: seq, fmt: " Block size : %12lu KB\n" , F2FS_BLKSIZE >> 10); |
| 1781 | seq_printf(m: seq, fmt: " Segment size : %12d MB\n" , |
| 1782 | (BLKS_PER_SEG(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); |
| 1783 | seq_printf(m: seq, fmt: " Segs/Sections : %12d\n" , |
| 1784 | SEGS_PER_SEC(sbi)); |
| 1785 | seq_printf(m: seq, fmt: " Section size : %12d MB\n" , |
| 1786 | (BLKS_PER_SEC(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); |
| 1787 | seq_printf(m: seq, fmt: " # of Sections : %12d\n" , |
| 1788 | le32_to_cpu(F2FS_RAW_SUPER(sbi)->section_count)); |
| 1789 | |
| 1790 | if (!f2fs_is_multi_device(sbi)) |
| 1791 | return 0; |
| 1792 | |
| 1793 | seq_puts(m: seq, s: "\nDisk Map for multi devices:\n" ); |
| 1794 | for (i = 0; i < sbi->s_ndevs; i++) |
| 1795 | seq_printf(m: seq, fmt: "Disk:%2d (zoned=%d): 0x%010x - 0x%010x on %s\n" , |
| 1796 | i, bdev_is_zoned(FDEV(i).bdev), |
| 1797 | FDEV(i).start_blk, FDEV(i).end_blk, |
| 1798 | FDEV(i).path); |
| 1799 | return 0; |
| 1800 | } |
| 1801 | |
| 1802 | static int __maybe_unused donation_list_seq_show(struct seq_file *seq, |
| 1803 | void *offset) |
| 1804 | { |
| 1805 | struct super_block *sb = seq->private; |
| 1806 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1807 | struct inode *inode; |
| 1808 | struct f2fs_inode_info *fi; |
| 1809 | struct dentry *dentry; |
| 1810 | char *buf, *path; |
| 1811 | int i; |
| 1812 | |
| 1813 | buf = f2fs_getname(sbi); |
| 1814 | if (!buf) |
| 1815 | return 0; |
| 1816 | |
| 1817 | seq_printf(m: seq, fmt: "Donation List\n" ); |
| 1818 | seq_printf(m: seq, fmt: " # of files : %u\n" , sbi->donate_files); |
| 1819 | seq_printf(m: seq, fmt: " %-50s %10s %20s %20s %22s\n" , |
| 1820 | "File path" , "Status" , "Donation offset (kb)" , |
| 1821 | "Donation size (kb)" , "File cached size (kb)" ); |
| 1822 | seq_printf(m: seq, fmt: "---\n" ); |
| 1823 | |
| 1824 | for (i = 0; i < sbi->donate_files; i++) { |
| 1825 | spin_lock(lock: &sbi->inode_lock[DONATE_INODE]); |
| 1826 | if (list_empty(head: &sbi->inode_list[DONATE_INODE])) { |
| 1827 | spin_unlock(lock: &sbi->inode_lock[DONATE_INODE]); |
| 1828 | break; |
| 1829 | } |
| 1830 | fi = list_first_entry(&sbi->inode_list[DONATE_INODE], |
| 1831 | struct f2fs_inode_info, gdonate_list); |
| 1832 | list_move_tail(list: &fi->gdonate_list, head: &sbi->inode_list[DONATE_INODE]); |
| 1833 | inode = igrab(&fi->vfs_inode); |
| 1834 | spin_unlock(lock: &sbi->inode_lock[DONATE_INODE]); |
| 1835 | |
| 1836 | if (!inode) |
| 1837 | continue; |
| 1838 | |
| 1839 | inode_lock_shared(inode); |
| 1840 | |
| 1841 | dentry = d_find_alias(inode); |
| 1842 | if (!dentry) { |
| 1843 | path = NULL; |
| 1844 | } else { |
| 1845 | path = dentry_path_raw(dentry, buf, PATH_MAX); |
| 1846 | if (IS_ERR(ptr: path)) |
| 1847 | goto next; |
| 1848 | } |
| 1849 | seq_printf(m: seq, fmt: " %-50s %10s %20llu %20llu %22llu\n" , |
| 1850 | path ? path : "<unlinked>" , |
| 1851 | is_inode_flag_set(inode, flag: FI_DONATE_FINISHED) ? |
| 1852 | "Evicted" : "Donated" , |
| 1853 | (loff_t)fi->donate_start << (PAGE_SHIFT - 10), |
| 1854 | (loff_t)(fi->donate_end + 1) << (PAGE_SHIFT - 10), |
| 1855 | (loff_t)inode->i_mapping->nrpages << (PAGE_SHIFT - 10)); |
| 1856 | next: |
| 1857 | dput(dentry); |
| 1858 | inode_unlock_shared(inode); |
| 1859 | iput(inode); |
| 1860 | } |
| 1861 | f2fs_putname(buf); |
| 1862 | return 0; |
| 1863 | } |
| 1864 | |
| 1865 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 1866 | static int __maybe_unused inject_stats_seq_show(struct seq_file *seq, |
| 1867 | void *offset) |
| 1868 | { |
| 1869 | struct super_block *sb = seq->private; |
| 1870 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1871 | struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; |
| 1872 | int i; |
| 1873 | |
| 1874 | seq_puts(m: seq, s: "fault_type injected_count\n" ); |
| 1875 | |
| 1876 | for (i = 0; i < FAULT_MAX; i++) |
| 1877 | seq_printf(m: seq, fmt: "%-24s%-10u\n" , f2fs_fault_name[i], |
| 1878 | ffi->inject_count[i]); |
| 1879 | return 0; |
| 1880 | } |
| 1881 | #endif |
| 1882 | |
| 1883 | int __init f2fs_init_sysfs(void) |
| 1884 | { |
| 1885 | int ret; |
| 1886 | |
| 1887 | kobject_set_name(kobj: &f2fs_kset.kobj, name: "f2fs" ); |
| 1888 | f2fs_kset.kobj.parent = fs_kobj; |
| 1889 | ret = kset_register(kset: &f2fs_kset); |
| 1890 | if (ret) |
| 1891 | return ret; |
| 1892 | |
| 1893 | ret = kobject_init_and_add(kobj: &f2fs_feat, ktype: &f2fs_feat_ktype, |
| 1894 | NULL, fmt: "features" ); |
| 1895 | if (ret) |
| 1896 | goto put_kobject; |
| 1897 | |
| 1898 | ret = kobject_init_and_add(kobj: &f2fs_tune, ktype: &f2fs_tune_ktype, |
| 1899 | NULL, fmt: "tuning" ); |
| 1900 | if (ret) |
| 1901 | goto put_kobject; |
| 1902 | |
| 1903 | f2fs_proc_root = proc_mkdir("fs/f2fs" , NULL); |
| 1904 | if (!f2fs_proc_root) { |
| 1905 | ret = -ENOMEM; |
| 1906 | goto put_kobject; |
| 1907 | } |
| 1908 | |
| 1909 | return 0; |
| 1910 | |
| 1911 | put_kobject: |
| 1912 | kobject_put(kobj: &f2fs_tune); |
| 1913 | kobject_put(kobj: &f2fs_feat); |
| 1914 | kset_unregister(kset: &f2fs_kset); |
| 1915 | return ret; |
| 1916 | } |
| 1917 | |
| 1918 | void f2fs_exit_sysfs(void) |
| 1919 | { |
| 1920 | kobject_put(kobj: &f2fs_tune); |
| 1921 | kobject_put(kobj: &f2fs_feat); |
| 1922 | kset_unregister(kset: &f2fs_kset); |
| 1923 | remove_proc_entry("fs/f2fs" , NULL); |
| 1924 | f2fs_proc_root = NULL; |
| 1925 | } |
| 1926 | |
| 1927 | int f2fs_register_sysfs(struct f2fs_sb_info *sbi) |
| 1928 | { |
| 1929 | struct super_block *sb = sbi->sb; |
| 1930 | int err; |
| 1931 | |
| 1932 | sbi->s_kobj.kset = &f2fs_kset; |
| 1933 | init_completion(x: &sbi->s_kobj_unregister); |
| 1934 | err = kobject_init_and_add(kobj: &sbi->s_kobj, ktype: &f2fs_sb_ktype, NULL, |
| 1935 | fmt: "%s" , sb->s_id); |
| 1936 | if (err) |
| 1937 | goto put_sb_kobj; |
| 1938 | |
| 1939 | sbi->s_stat_kobj.kset = &f2fs_kset; |
| 1940 | init_completion(x: &sbi->s_stat_kobj_unregister); |
| 1941 | err = kobject_init_and_add(kobj: &sbi->s_stat_kobj, ktype: &f2fs_stat_ktype, |
| 1942 | parent: &sbi->s_kobj, fmt: "stat" ); |
| 1943 | if (err) |
| 1944 | goto put_stat_kobj; |
| 1945 | |
| 1946 | sbi->s_feature_list_kobj.kset = &f2fs_kset; |
| 1947 | init_completion(x: &sbi->s_feature_list_kobj_unregister); |
| 1948 | err = kobject_init_and_add(kobj: &sbi->s_feature_list_kobj, |
| 1949 | ktype: &f2fs_feature_list_ktype, |
| 1950 | parent: &sbi->s_kobj, fmt: "feature_list" ); |
| 1951 | if (err) |
| 1952 | goto put_feature_list_kobj; |
| 1953 | |
| 1954 | sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); |
| 1955 | if (!sbi->s_proc) { |
| 1956 | err = -ENOMEM; |
| 1957 | goto put_feature_list_kobj; |
| 1958 | } |
| 1959 | |
| 1960 | proc_create_single_data(name: "segment_info" , mode: 0444, parent: sbi->s_proc, |
| 1961 | show: segment_info_seq_show, data: sb); |
| 1962 | proc_create_single_data(name: "segment_bits" , mode: 0444, parent: sbi->s_proc, |
| 1963 | show: segment_bits_seq_show, data: sb); |
| 1964 | #ifdef CONFIG_F2FS_IOSTAT |
| 1965 | proc_create_single_data(name: "iostat_info" , mode: 0444, parent: sbi->s_proc, |
| 1966 | show: iostat_info_seq_show, data: sb); |
| 1967 | #endif |
| 1968 | proc_create_single_data(name: "victim_bits" , mode: 0444, parent: sbi->s_proc, |
| 1969 | show: victim_bits_seq_show, data: sb); |
| 1970 | proc_create_single_data(name: "discard_plist_info" , mode: 0444, parent: sbi->s_proc, |
| 1971 | show: discard_plist_seq_show, data: sb); |
| 1972 | proc_create_single_data(name: "disk_map" , mode: 0444, parent: sbi->s_proc, |
| 1973 | show: disk_map_seq_show, data: sb); |
| 1974 | proc_create_single_data(name: "donation_list" , mode: 0444, parent: sbi->s_proc, |
| 1975 | show: donation_list_seq_show, data: sb); |
| 1976 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
| 1977 | proc_create_single_data(name: "inject_stats" , mode: 0444, parent: sbi->s_proc, |
| 1978 | show: inject_stats_seq_show, data: sb); |
| 1979 | #endif |
| 1980 | return 0; |
| 1981 | put_feature_list_kobj: |
| 1982 | kobject_put(kobj: &sbi->s_feature_list_kobj); |
| 1983 | wait_for_completion(&sbi->s_feature_list_kobj_unregister); |
| 1984 | put_stat_kobj: |
| 1985 | kobject_put(kobj: &sbi->s_stat_kobj); |
| 1986 | wait_for_completion(&sbi->s_stat_kobj_unregister); |
| 1987 | put_sb_kobj: |
| 1988 | kobject_put(kobj: &sbi->s_kobj); |
| 1989 | wait_for_completion(&sbi->s_kobj_unregister); |
| 1990 | return err; |
| 1991 | } |
| 1992 | |
| 1993 | void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) |
| 1994 | { |
| 1995 | remove_proc_subtree(sbi->sb->s_id, f2fs_proc_root); |
| 1996 | |
| 1997 | kobject_put(kobj: &sbi->s_stat_kobj); |
| 1998 | wait_for_completion(&sbi->s_stat_kobj_unregister); |
| 1999 | kobject_put(kobj: &sbi->s_feature_list_kobj); |
| 2000 | wait_for_completion(&sbi->s_feature_list_kobj_unregister); |
| 2001 | |
| 2002 | kobject_put(kobj: &sbi->s_kobj); |
| 2003 | wait_for_completion(&sbi->s_kobj_unregister); |
| 2004 | } |
| 2005 | |