sysfs.c 57 KB

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