~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/f2fs/sysfs.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php