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