sysfs.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. /*
  2. * sysfs.c - sysfs support implementation.
  3. *
  4. * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation.
  5. * Copyright (C) 2014 HGST, Inc., a Western Digital Company.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * Written by Vyacheslav Dubeyko <[email protected]>
  18. */
  19. #include <linux/kobject.h>
  20. #include "nilfs.h"
  21. #include "mdt.h"
  22. #include "sufile.h"
  23. #include "cpfile.h"
  24. #include "sysfs.h"
  25. /* /sys/fs/<nilfs>/ */
  26. static struct kset *nilfs_kset;
  27. #define NILFS_SHOW_TIME(time_t_val, buf) ({ \
  28. struct tm res; \
  29. int count = 0; \
  30. time_to_tm(time_t_val, 0, &res); \
  31. res.tm_year += 1900; \
  32. res.tm_mon += 1; \
  33. count = scnprintf(buf, PAGE_SIZE, \
  34. "%ld-%.2d-%.2d %.2d:%.2d:%.2d\n", \
  35. res.tm_year, res.tm_mon, res.tm_mday, \
  36. res.tm_hour, res.tm_min, res.tm_sec);\
  37. count; \
  38. })
  39. #define NILFS_DEV_INT_GROUP_OPS(name, parent_name) \
  40. static ssize_t nilfs_##name##_attr_show(struct kobject *kobj, \
  41. struct attribute *attr, char *buf) \
  42. { \
  43. struct the_nilfs *nilfs = container_of(kobj->parent, \
  44. struct the_nilfs, \
  45. ns_##parent_name##_kobj); \
  46. struct nilfs_##name##_attr *a = container_of(attr, \
  47. struct nilfs_##name##_attr, \
  48. attr); \
  49. return a->show ? a->show(a, nilfs, buf) : 0; \
  50. } \
  51. static ssize_t nilfs_##name##_attr_store(struct kobject *kobj, \
  52. struct attribute *attr, \
  53. const char *buf, size_t len) \
  54. { \
  55. struct the_nilfs *nilfs = container_of(kobj->parent, \
  56. struct the_nilfs, \
  57. ns_##parent_name##_kobj); \
  58. struct nilfs_##name##_attr *a = container_of(attr, \
  59. struct nilfs_##name##_attr, \
  60. attr); \
  61. return a->store ? a->store(a, nilfs, buf, len) : 0; \
  62. } \
  63. static const struct sysfs_ops nilfs_##name##_attr_ops = { \
  64. .show = nilfs_##name##_attr_show, \
  65. .store = nilfs_##name##_attr_store, \
  66. }
  67. #define NILFS_DEV_INT_GROUP_TYPE(name, parent_name) \
  68. static void nilfs_##name##_attr_release(struct kobject *kobj) \
  69. { \
  70. struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \
  71. struct the_nilfs *nilfs = container_of(kobj->parent, \
  72. struct the_nilfs, \
  73. ns_##parent_name##_kobj); \
  74. subgroups = nilfs->ns_##parent_name##_subgroups; \
  75. complete(&subgroups->sg_##name##_kobj_unregister); \
  76. } \
  77. static struct kobj_type nilfs_##name##_ktype = { \
  78. .default_attrs = nilfs_##name##_attrs, \
  79. .sysfs_ops = &nilfs_##name##_attr_ops, \
  80. .release = nilfs_##name##_attr_release, \
  81. }
  82. #define NILFS_DEV_INT_GROUP_FNS(name, parent_name) \
  83. static int nilfs_sysfs_create_##name##_group(struct the_nilfs *nilfs) \
  84. { \
  85. struct kobject *parent; \
  86. struct kobject *kobj; \
  87. struct completion *kobj_unregister; \
  88. struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \
  89. int err; \
  90. subgroups = nilfs->ns_##parent_name##_subgroups; \
  91. kobj = &subgroups->sg_##name##_kobj; \
  92. kobj_unregister = &subgroups->sg_##name##_kobj_unregister; \
  93. parent = &nilfs->ns_##parent_name##_kobj; \
  94. kobj->kset = nilfs_kset; \
  95. init_completion(kobj_unregister); \
  96. err = kobject_init_and_add(kobj, &nilfs_##name##_ktype, parent, \
  97. #name); \
  98. if (err) \
  99. return err; \
  100. return 0; \
  101. } \
  102. static void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \
  103. { \
  104. kobject_del(&nilfs->ns_##parent_name##_subgroups->sg_##name##_kobj); \
  105. }
  106. /************************************************************************
  107. * NILFS snapshot attrs *
  108. ************************************************************************/
  109. static ssize_t
  110. nilfs_snapshot_inodes_count_show(struct nilfs_snapshot_attr *attr,
  111. struct nilfs_root *root, char *buf)
  112. {
  113. return snprintf(buf, PAGE_SIZE, "%llu\n",
  114. (unsigned long long)atomic64_read(&root->inodes_count));
  115. }
  116. static ssize_t
  117. nilfs_snapshot_blocks_count_show(struct nilfs_snapshot_attr *attr,
  118. struct nilfs_root *root, char *buf)
  119. {
  120. return snprintf(buf, PAGE_SIZE, "%llu\n",
  121. (unsigned long long)atomic64_read(&root->blocks_count));
  122. }
  123. static const char snapshot_readme_str[] =
  124. "The group contains details about mounted snapshot.\n\n"
  125. "(1) inodes_count\n\tshow number of inodes for snapshot.\n\n"
  126. "(2) blocks_count\n\tshow number of blocks for snapshot.\n\n";
  127. static ssize_t
  128. nilfs_snapshot_README_show(struct nilfs_snapshot_attr *attr,
  129. struct nilfs_root *root, char *buf)
  130. {
  131. return snprintf(buf, PAGE_SIZE, snapshot_readme_str);
  132. }
  133. NILFS_SNAPSHOT_RO_ATTR(inodes_count);
  134. NILFS_SNAPSHOT_RO_ATTR(blocks_count);
  135. NILFS_SNAPSHOT_RO_ATTR(README);
  136. static struct attribute *nilfs_snapshot_attrs[] = {
  137. NILFS_SNAPSHOT_ATTR_LIST(inodes_count),
  138. NILFS_SNAPSHOT_ATTR_LIST(blocks_count),
  139. NILFS_SNAPSHOT_ATTR_LIST(README),
  140. NULL,
  141. };
  142. static ssize_t nilfs_snapshot_attr_show(struct kobject *kobj,
  143. struct attribute *attr, char *buf)
  144. {
  145. struct nilfs_root *root =
  146. container_of(kobj, struct nilfs_root, snapshot_kobj);
  147. struct nilfs_snapshot_attr *a =
  148. container_of(attr, struct nilfs_snapshot_attr, attr);
  149. return a->show ? a->show(a, root, buf) : 0;
  150. }
  151. static ssize_t nilfs_snapshot_attr_store(struct kobject *kobj,
  152. struct attribute *attr,
  153. const char *buf, size_t len)
  154. {
  155. struct nilfs_root *root =
  156. container_of(kobj, struct nilfs_root, snapshot_kobj);
  157. struct nilfs_snapshot_attr *a =
  158. container_of(attr, struct nilfs_snapshot_attr, attr);
  159. return a->store ? a->store(a, root, buf, len) : 0;
  160. }
  161. static void nilfs_snapshot_attr_release(struct kobject *kobj)
  162. {
  163. struct nilfs_root *root = container_of(kobj, struct nilfs_root,
  164. snapshot_kobj);
  165. complete(&root->snapshot_kobj_unregister);
  166. }
  167. static const struct sysfs_ops nilfs_snapshot_attr_ops = {
  168. .show = nilfs_snapshot_attr_show,
  169. .store = nilfs_snapshot_attr_store,
  170. };
  171. static struct kobj_type nilfs_snapshot_ktype = {
  172. .default_attrs = nilfs_snapshot_attrs,
  173. .sysfs_ops = &nilfs_snapshot_attr_ops,
  174. .release = nilfs_snapshot_attr_release,
  175. };
  176. int nilfs_sysfs_create_snapshot_group(struct nilfs_root *root)
  177. {
  178. struct the_nilfs *nilfs;
  179. struct kobject *parent;
  180. int err;
  181. nilfs = root->nilfs;
  182. parent = &nilfs->ns_dev_subgroups->sg_mounted_snapshots_kobj;
  183. root->snapshot_kobj.kset = nilfs_kset;
  184. init_completion(&root->snapshot_kobj_unregister);
  185. if (root->cno == NILFS_CPTREE_CURRENT_CNO) {
  186. err = kobject_init_and_add(&root->snapshot_kobj,
  187. &nilfs_snapshot_ktype,
  188. &nilfs->ns_dev_kobj,
  189. "current_checkpoint");
  190. } else {
  191. err = kobject_init_and_add(&root->snapshot_kobj,
  192. &nilfs_snapshot_ktype,
  193. parent,
  194. "%llu", root->cno);
  195. }
  196. if (err)
  197. return err;
  198. return 0;
  199. }
  200. void nilfs_sysfs_delete_snapshot_group(struct nilfs_root *root)
  201. {
  202. kobject_del(&root->snapshot_kobj);
  203. }
  204. /************************************************************************
  205. * NILFS mounted snapshots attrs *
  206. ************************************************************************/
  207. static const char mounted_snapshots_readme_str[] =
  208. "The mounted_snapshots group contains group for\n"
  209. "every mounted snapshot.\n";
  210. static ssize_t
  211. nilfs_mounted_snapshots_README_show(struct nilfs_mounted_snapshots_attr *attr,
  212. struct the_nilfs *nilfs, char *buf)
  213. {
  214. return snprintf(buf, PAGE_SIZE, mounted_snapshots_readme_str);
  215. }
  216. NILFS_MOUNTED_SNAPSHOTS_RO_ATTR(README);
  217. static struct attribute *nilfs_mounted_snapshots_attrs[] = {
  218. NILFS_MOUNTED_SNAPSHOTS_ATTR_LIST(README),
  219. NULL,
  220. };
  221. NILFS_DEV_INT_GROUP_OPS(mounted_snapshots, dev);
  222. NILFS_DEV_INT_GROUP_TYPE(mounted_snapshots, dev);
  223. NILFS_DEV_INT_GROUP_FNS(mounted_snapshots, dev);
  224. /************************************************************************
  225. * NILFS checkpoints attrs *
  226. ************************************************************************/
  227. static ssize_t
  228. nilfs_checkpoints_checkpoints_number_show(struct nilfs_checkpoints_attr *attr,
  229. struct the_nilfs *nilfs,
  230. char *buf)
  231. {
  232. __u64 ncheckpoints;
  233. struct nilfs_cpstat cpstat;
  234. int err;
  235. down_read(&nilfs->ns_segctor_sem);
  236. err = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat);
  237. up_read(&nilfs->ns_segctor_sem);
  238. if (err < 0) {
  239. nilfs_msg(nilfs->ns_sb, KERN_ERR,
  240. "unable to get checkpoint stat: err=%d", err);
  241. return err;
  242. }
  243. ncheckpoints = cpstat.cs_ncps;
  244. return snprintf(buf, PAGE_SIZE, "%llu\n", ncheckpoints);
  245. }
  246. static ssize_t
  247. nilfs_checkpoints_snapshots_number_show(struct nilfs_checkpoints_attr *attr,
  248. struct the_nilfs *nilfs,
  249. char *buf)
  250. {
  251. __u64 nsnapshots;
  252. struct nilfs_cpstat cpstat;
  253. int err;
  254. down_read(&nilfs->ns_segctor_sem);
  255. err = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat);
  256. up_read(&nilfs->ns_segctor_sem);
  257. if (err < 0) {
  258. nilfs_msg(nilfs->ns_sb, KERN_ERR,
  259. "unable to get checkpoint stat: err=%d", err);
  260. return err;
  261. }
  262. nsnapshots = cpstat.cs_nsss;
  263. return snprintf(buf, PAGE_SIZE, "%llu\n", nsnapshots);
  264. }
  265. static ssize_t
  266. nilfs_checkpoints_last_seg_checkpoint_show(struct nilfs_checkpoints_attr *attr,
  267. struct the_nilfs *nilfs,
  268. char *buf)
  269. {
  270. __u64 last_cno;
  271. spin_lock(&nilfs->ns_last_segment_lock);
  272. last_cno = nilfs->ns_last_cno;
  273. spin_unlock(&nilfs->ns_last_segment_lock);
  274. return snprintf(buf, PAGE_SIZE, "%llu\n", last_cno);
  275. }
  276. static ssize_t
  277. nilfs_checkpoints_next_checkpoint_show(struct nilfs_checkpoints_attr *attr,
  278. struct the_nilfs *nilfs,
  279. char *buf)
  280. {
  281. __u64 cno;
  282. down_read(&nilfs->ns_segctor_sem);
  283. cno = nilfs->ns_cno;
  284. up_read(&nilfs->ns_segctor_sem);
  285. return snprintf(buf, PAGE_SIZE, "%llu\n", cno);
  286. }
  287. static const char checkpoints_readme_str[] =
  288. "The checkpoints group contains attributes that describe\n"
  289. "details about volume's checkpoints.\n\n"
  290. "(1) checkpoints_number\n\tshow number of checkpoints on volume.\n\n"
  291. "(2) snapshots_number\n\tshow number of snapshots on volume.\n\n"
  292. "(3) last_seg_checkpoint\n"
  293. "\tshow checkpoint number of the latest segment.\n\n"
  294. "(4) next_checkpoint\n\tshow next checkpoint number.\n\n";
  295. static ssize_t
  296. nilfs_checkpoints_README_show(struct nilfs_checkpoints_attr *attr,
  297. struct the_nilfs *nilfs, char *buf)
  298. {
  299. return snprintf(buf, PAGE_SIZE, checkpoints_readme_str);
  300. }
  301. NILFS_CHECKPOINTS_RO_ATTR(checkpoints_number);
  302. NILFS_CHECKPOINTS_RO_ATTR(snapshots_number);
  303. NILFS_CHECKPOINTS_RO_ATTR(last_seg_checkpoint);
  304. NILFS_CHECKPOINTS_RO_ATTR(next_checkpoint);
  305. NILFS_CHECKPOINTS_RO_ATTR(README);
  306. static struct attribute *nilfs_checkpoints_attrs[] = {
  307. NILFS_CHECKPOINTS_ATTR_LIST(checkpoints_number),
  308. NILFS_CHECKPOINTS_ATTR_LIST(snapshots_number),
  309. NILFS_CHECKPOINTS_ATTR_LIST(last_seg_checkpoint),
  310. NILFS_CHECKPOINTS_ATTR_LIST(next_checkpoint),
  311. NILFS_CHECKPOINTS_ATTR_LIST(README),
  312. NULL,
  313. };
  314. NILFS_DEV_INT_GROUP_OPS(checkpoints, dev);
  315. NILFS_DEV_INT_GROUP_TYPE(checkpoints, dev);
  316. NILFS_DEV_INT_GROUP_FNS(checkpoints, dev);
  317. /************************************************************************
  318. * NILFS segments attrs *
  319. ************************************************************************/
  320. static ssize_t
  321. nilfs_segments_segments_number_show(struct nilfs_segments_attr *attr,
  322. struct the_nilfs *nilfs,
  323. char *buf)
  324. {
  325. return snprintf(buf, PAGE_SIZE, "%lu\n", nilfs->ns_nsegments);
  326. }
  327. static ssize_t
  328. nilfs_segments_blocks_per_segment_show(struct nilfs_segments_attr *attr,
  329. struct the_nilfs *nilfs,
  330. char *buf)
  331. {
  332. return snprintf(buf, PAGE_SIZE, "%lu\n", nilfs->ns_blocks_per_segment);
  333. }
  334. static ssize_t
  335. nilfs_segments_clean_segments_show(struct nilfs_segments_attr *attr,
  336. struct the_nilfs *nilfs,
  337. char *buf)
  338. {
  339. unsigned long ncleansegs;
  340. down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
  341. ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile);
  342. up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
  343. return snprintf(buf, PAGE_SIZE, "%lu\n", ncleansegs);
  344. }
  345. static ssize_t
  346. nilfs_segments_dirty_segments_show(struct nilfs_segments_attr *attr,
  347. struct the_nilfs *nilfs,
  348. char *buf)
  349. {
  350. struct nilfs_sustat sustat;
  351. int err;
  352. down_read(&nilfs->ns_segctor_sem);
  353. err = nilfs_sufile_get_stat(nilfs->ns_sufile, &sustat);
  354. up_read(&nilfs->ns_segctor_sem);
  355. if (err < 0) {
  356. nilfs_msg(nilfs->ns_sb, KERN_ERR,
  357. "unable to get segment stat: err=%d", err);
  358. return err;
  359. }
  360. return snprintf(buf, PAGE_SIZE, "%llu\n", sustat.ss_ndirtysegs);
  361. }
  362. static const char segments_readme_str[] =
  363. "The segments group contains attributes that describe\n"
  364. "details about volume's segments.\n\n"
  365. "(1) segments_number\n\tshow number of segments on volume.\n\n"
  366. "(2) blocks_per_segment\n\tshow number of blocks in segment.\n\n"
  367. "(3) clean_segments\n\tshow count of clean segments.\n\n"
  368. "(4) dirty_segments\n\tshow count of dirty segments.\n\n";
  369. static ssize_t
  370. nilfs_segments_README_show(struct nilfs_segments_attr *attr,
  371. struct the_nilfs *nilfs,
  372. char *buf)
  373. {
  374. return snprintf(buf, PAGE_SIZE, segments_readme_str);
  375. }
  376. NILFS_SEGMENTS_RO_ATTR(segments_number);
  377. NILFS_SEGMENTS_RO_ATTR(blocks_per_segment);
  378. NILFS_SEGMENTS_RO_ATTR(clean_segments);
  379. NILFS_SEGMENTS_RO_ATTR(dirty_segments);
  380. NILFS_SEGMENTS_RO_ATTR(README);
  381. static struct attribute *nilfs_segments_attrs[] = {
  382. NILFS_SEGMENTS_ATTR_LIST(segments_number),
  383. NILFS_SEGMENTS_ATTR_LIST(blocks_per_segment),
  384. NILFS_SEGMENTS_ATTR_LIST(clean_segments),
  385. NILFS_SEGMENTS_ATTR_LIST(dirty_segments),
  386. NILFS_SEGMENTS_ATTR_LIST(README),
  387. NULL,
  388. };
  389. NILFS_DEV_INT_GROUP_OPS(segments, dev);
  390. NILFS_DEV_INT_GROUP_TYPE(segments, dev);
  391. NILFS_DEV_INT_GROUP_FNS(segments, dev);
  392. /************************************************************************
  393. * NILFS segctor attrs *
  394. ************************************************************************/
  395. static ssize_t
  396. nilfs_segctor_last_pseg_block_show(struct nilfs_segctor_attr *attr,
  397. struct the_nilfs *nilfs,
  398. char *buf)
  399. {
  400. sector_t last_pseg;
  401. spin_lock(&nilfs->ns_last_segment_lock);
  402. last_pseg = nilfs->ns_last_pseg;
  403. spin_unlock(&nilfs->ns_last_segment_lock);
  404. return snprintf(buf, PAGE_SIZE, "%llu\n",
  405. (unsigned long long)last_pseg);
  406. }
  407. static ssize_t
  408. nilfs_segctor_last_seg_sequence_show(struct nilfs_segctor_attr *attr,
  409. struct the_nilfs *nilfs,
  410. char *buf)
  411. {
  412. u64 last_seq;
  413. spin_lock(&nilfs->ns_last_segment_lock);
  414. last_seq = nilfs->ns_last_seq;
  415. spin_unlock(&nilfs->ns_last_segment_lock);
  416. return snprintf(buf, PAGE_SIZE, "%llu\n", last_seq);
  417. }
  418. static ssize_t
  419. nilfs_segctor_last_seg_checkpoint_show(struct nilfs_segctor_attr *attr,
  420. struct the_nilfs *nilfs,
  421. char *buf)
  422. {
  423. __u64 last_cno;
  424. spin_lock(&nilfs->ns_last_segment_lock);
  425. last_cno = nilfs->ns_last_cno;
  426. spin_unlock(&nilfs->ns_last_segment_lock);
  427. return snprintf(buf, PAGE_SIZE, "%llu\n", last_cno);
  428. }
  429. static ssize_t
  430. nilfs_segctor_current_seg_sequence_show(struct nilfs_segctor_attr *attr,
  431. struct the_nilfs *nilfs,
  432. char *buf)
  433. {
  434. u64 seg_seq;
  435. down_read(&nilfs->ns_segctor_sem);
  436. seg_seq = nilfs->ns_seg_seq;
  437. up_read(&nilfs->ns_segctor_sem);
  438. return snprintf(buf, PAGE_SIZE, "%llu\n", seg_seq);
  439. }
  440. static ssize_t
  441. nilfs_segctor_current_last_full_seg_show(struct nilfs_segctor_attr *attr,
  442. struct the_nilfs *nilfs,
  443. char *buf)
  444. {
  445. __u64 segnum;
  446. down_read(&nilfs->ns_segctor_sem);
  447. segnum = nilfs->ns_segnum;
  448. up_read(&nilfs->ns_segctor_sem);
  449. return snprintf(buf, PAGE_SIZE, "%llu\n", segnum);
  450. }
  451. static ssize_t
  452. nilfs_segctor_next_full_seg_show(struct nilfs_segctor_attr *attr,
  453. struct the_nilfs *nilfs,
  454. char *buf)
  455. {
  456. __u64 nextnum;
  457. down_read(&nilfs->ns_segctor_sem);
  458. nextnum = nilfs->ns_nextnum;
  459. up_read(&nilfs->ns_segctor_sem);
  460. return snprintf(buf, PAGE_SIZE, "%llu\n", nextnum);
  461. }
  462. static ssize_t
  463. nilfs_segctor_next_pseg_offset_show(struct nilfs_segctor_attr *attr,
  464. struct the_nilfs *nilfs,
  465. char *buf)
  466. {
  467. unsigned long pseg_offset;
  468. down_read(&nilfs->ns_segctor_sem);
  469. pseg_offset = nilfs->ns_pseg_offset;
  470. up_read(&nilfs->ns_segctor_sem);
  471. return snprintf(buf, PAGE_SIZE, "%lu\n", pseg_offset);
  472. }
  473. static ssize_t
  474. nilfs_segctor_next_checkpoint_show(struct nilfs_segctor_attr *attr,
  475. struct the_nilfs *nilfs,
  476. char *buf)
  477. {
  478. __u64 cno;
  479. down_read(&nilfs->ns_segctor_sem);
  480. cno = nilfs->ns_cno;
  481. up_read(&nilfs->ns_segctor_sem);
  482. return snprintf(buf, PAGE_SIZE, "%llu\n", cno);
  483. }
  484. static ssize_t
  485. nilfs_segctor_last_seg_write_time_show(struct nilfs_segctor_attr *attr,
  486. struct the_nilfs *nilfs,
  487. char *buf)
  488. {
  489. time_t ctime;
  490. down_read(&nilfs->ns_segctor_sem);
  491. ctime = nilfs->ns_ctime;
  492. up_read(&nilfs->ns_segctor_sem);
  493. return NILFS_SHOW_TIME(ctime, buf);
  494. }
  495. static ssize_t
  496. nilfs_segctor_last_seg_write_time_secs_show(struct nilfs_segctor_attr *attr,
  497. struct the_nilfs *nilfs,
  498. char *buf)
  499. {
  500. time_t ctime;
  501. down_read(&nilfs->ns_segctor_sem);
  502. ctime = nilfs->ns_ctime;
  503. up_read(&nilfs->ns_segctor_sem);
  504. return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)ctime);
  505. }
  506. static ssize_t
  507. nilfs_segctor_last_nongc_write_time_show(struct nilfs_segctor_attr *attr,
  508. struct the_nilfs *nilfs,
  509. char *buf)
  510. {
  511. time_t nongc_ctime;
  512. down_read(&nilfs->ns_segctor_sem);
  513. nongc_ctime = nilfs->ns_nongc_ctime;
  514. up_read(&nilfs->ns_segctor_sem);
  515. return NILFS_SHOW_TIME(nongc_ctime, buf);
  516. }
  517. static ssize_t
  518. nilfs_segctor_last_nongc_write_time_secs_show(struct nilfs_segctor_attr *attr,
  519. struct the_nilfs *nilfs,
  520. char *buf)
  521. {
  522. time_t nongc_ctime;
  523. down_read(&nilfs->ns_segctor_sem);
  524. nongc_ctime = nilfs->ns_nongc_ctime;
  525. up_read(&nilfs->ns_segctor_sem);
  526. return snprintf(buf, PAGE_SIZE, "%llu\n",
  527. (unsigned long long)nongc_ctime);
  528. }
  529. static ssize_t
  530. nilfs_segctor_dirty_data_blocks_count_show(struct nilfs_segctor_attr *attr,
  531. struct the_nilfs *nilfs,
  532. char *buf)
  533. {
  534. u32 ndirtyblks;
  535. down_read(&nilfs->ns_segctor_sem);
  536. ndirtyblks = atomic_read(&nilfs->ns_ndirtyblks);
  537. up_read(&nilfs->ns_segctor_sem);
  538. return snprintf(buf, PAGE_SIZE, "%u\n", ndirtyblks);
  539. }
  540. static const char segctor_readme_str[] =
  541. "The segctor group contains attributes that describe\n"
  542. "segctor thread activity details.\n\n"
  543. "(1) last_pseg_block\n"
  544. "\tshow start block number of the latest segment.\n\n"
  545. "(2) last_seg_sequence\n"
  546. "\tshow sequence value of the latest segment.\n\n"
  547. "(3) last_seg_checkpoint\n"
  548. "\tshow checkpoint number of the latest segment.\n\n"
  549. "(4) current_seg_sequence\n\tshow segment sequence counter.\n\n"
  550. "(5) current_last_full_seg\n"
  551. "\tshow index number of the latest full segment.\n\n"
  552. "(6) next_full_seg\n"
  553. "\tshow index number of the full segment index to be used next.\n\n"
  554. "(7) next_pseg_offset\n"
  555. "\tshow offset of next partial segment in the current full segment.\n\n"
  556. "(8) next_checkpoint\n\tshow next checkpoint number.\n\n"
  557. "(9) last_seg_write_time\n"
  558. "\tshow write time of the last segment in human-readable format.\n\n"
  559. "(10) last_seg_write_time_secs\n"
  560. "\tshow write time of the last segment in seconds.\n\n"
  561. "(11) last_nongc_write_time\n"
  562. "\tshow write time of the last segment not for cleaner operation "
  563. "in human-readable format.\n\n"
  564. "(12) last_nongc_write_time_secs\n"
  565. "\tshow write time of the last segment not for cleaner operation "
  566. "in seconds.\n\n"
  567. "(13) dirty_data_blocks_count\n"
  568. "\tshow number of dirty data blocks.\n\n";
  569. static ssize_t
  570. nilfs_segctor_README_show(struct nilfs_segctor_attr *attr,
  571. struct the_nilfs *nilfs, char *buf)
  572. {
  573. return snprintf(buf, PAGE_SIZE, segctor_readme_str);
  574. }
  575. NILFS_SEGCTOR_RO_ATTR(last_pseg_block);
  576. NILFS_SEGCTOR_RO_ATTR(last_seg_sequence);
  577. NILFS_SEGCTOR_RO_ATTR(last_seg_checkpoint);
  578. NILFS_SEGCTOR_RO_ATTR(current_seg_sequence);
  579. NILFS_SEGCTOR_RO_ATTR(current_last_full_seg);
  580. NILFS_SEGCTOR_RO_ATTR(next_full_seg);
  581. NILFS_SEGCTOR_RO_ATTR(next_pseg_offset);
  582. NILFS_SEGCTOR_RO_ATTR(next_checkpoint);
  583. NILFS_SEGCTOR_RO_ATTR(last_seg_write_time);
  584. NILFS_SEGCTOR_RO_ATTR(last_seg_write_time_secs);
  585. NILFS_SEGCTOR_RO_ATTR(last_nongc_write_time);
  586. NILFS_SEGCTOR_RO_ATTR(last_nongc_write_time_secs);
  587. NILFS_SEGCTOR_RO_ATTR(dirty_data_blocks_count);
  588. NILFS_SEGCTOR_RO_ATTR(README);
  589. static struct attribute *nilfs_segctor_attrs[] = {
  590. NILFS_SEGCTOR_ATTR_LIST(last_pseg_block),
  591. NILFS_SEGCTOR_ATTR_LIST(last_seg_sequence),
  592. NILFS_SEGCTOR_ATTR_LIST(last_seg_checkpoint),
  593. NILFS_SEGCTOR_ATTR_LIST(current_seg_sequence),
  594. NILFS_SEGCTOR_ATTR_LIST(current_last_full_seg),
  595. NILFS_SEGCTOR_ATTR_LIST(next_full_seg),
  596. NILFS_SEGCTOR_ATTR_LIST(next_pseg_offset),
  597. NILFS_SEGCTOR_ATTR_LIST(next_checkpoint),
  598. NILFS_SEGCTOR_ATTR_LIST(last_seg_write_time),
  599. NILFS_SEGCTOR_ATTR_LIST(last_seg_write_time_secs),
  600. NILFS_SEGCTOR_ATTR_LIST(last_nongc_write_time),
  601. NILFS_SEGCTOR_ATTR_LIST(last_nongc_write_time_secs),
  602. NILFS_SEGCTOR_ATTR_LIST(dirty_data_blocks_count),
  603. NILFS_SEGCTOR_ATTR_LIST(README),
  604. NULL,
  605. };
  606. NILFS_DEV_INT_GROUP_OPS(segctor, dev);
  607. NILFS_DEV_INT_GROUP_TYPE(segctor, dev);
  608. NILFS_DEV_INT_GROUP_FNS(segctor, dev);
  609. /************************************************************************
  610. * NILFS superblock attrs *
  611. ************************************************************************/
  612. static ssize_t
  613. nilfs_superblock_sb_write_time_show(struct nilfs_superblock_attr *attr,
  614. struct the_nilfs *nilfs,
  615. char *buf)
  616. {
  617. time_t sbwtime;
  618. down_read(&nilfs->ns_sem);
  619. sbwtime = nilfs->ns_sbwtime;
  620. up_read(&nilfs->ns_sem);
  621. return NILFS_SHOW_TIME(sbwtime, buf);
  622. }
  623. static ssize_t
  624. nilfs_superblock_sb_write_time_secs_show(struct nilfs_superblock_attr *attr,
  625. struct the_nilfs *nilfs,
  626. char *buf)
  627. {
  628. time_t sbwtime;
  629. down_read(&nilfs->ns_sem);
  630. sbwtime = nilfs->ns_sbwtime;
  631. up_read(&nilfs->ns_sem);
  632. return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)sbwtime);
  633. }
  634. static ssize_t
  635. nilfs_superblock_sb_write_count_show(struct nilfs_superblock_attr *attr,
  636. struct the_nilfs *nilfs,
  637. char *buf)
  638. {
  639. unsigned int sbwcount;
  640. down_read(&nilfs->ns_sem);
  641. sbwcount = nilfs->ns_sbwcount;
  642. up_read(&nilfs->ns_sem);
  643. return snprintf(buf, PAGE_SIZE, "%u\n", sbwcount);
  644. }
  645. static ssize_t
  646. nilfs_superblock_sb_update_frequency_show(struct nilfs_superblock_attr *attr,
  647. struct the_nilfs *nilfs,
  648. char *buf)
  649. {
  650. unsigned int sb_update_freq;
  651. down_read(&nilfs->ns_sem);
  652. sb_update_freq = nilfs->ns_sb_update_freq;
  653. up_read(&nilfs->ns_sem);
  654. return snprintf(buf, PAGE_SIZE, "%u\n", sb_update_freq);
  655. }
  656. static ssize_t
  657. nilfs_superblock_sb_update_frequency_store(struct nilfs_superblock_attr *attr,
  658. struct the_nilfs *nilfs,
  659. const char *buf, size_t count)
  660. {
  661. unsigned int val;
  662. int err;
  663. err = kstrtouint(skip_spaces(buf), 0, &val);
  664. if (err) {
  665. nilfs_msg(nilfs->ns_sb, KERN_ERR,
  666. "unable to convert string: err=%d", err);
  667. return err;
  668. }
  669. if (val < NILFS_SB_FREQ) {
  670. val = NILFS_SB_FREQ;
  671. nilfs_msg(nilfs->ns_sb, KERN_WARNING,
  672. "superblock update frequency cannot be lesser than 10 seconds");
  673. }
  674. down_write(&nilfs->ns_sem);
  675. nilfs->ns_sb_update_freq = val;
  676. up_write(&nilfs->ns_sem);
  677. return count;
  678. }
  679. static const char sb_readme_str[] =
  680. "The superblock group contains attributes that describe\n"
  681. "superblock's details.\n\n"
  682. "(1) sb_write_time\n\tshow previous write time of super block "
  683. "in human-readable format.\n\n"
  684. "(2) sb_write_time_secs\n\tshow previous write time of super block "
  685. "in seconds.\n\n"
  686. "(3) sb_write_count\n\tshow write count of super block.\n\n"
  687. "(4) sb_update_frequency\n"
  688. "\tshow/set interval of periodical update of superblock (in seconds).\n\n"
  689. "\tYou can set preferable frequency of superblock update by command:\n\n"
  690. "\t'echo <val> > /sys/fs/<nilfs>/<dev>/superblock/sb_update_frequency'\n";
  691. static ssize_t
  692. nilfs_superblock_README_show(struct nilfs_superblock_attr *attr,
  693. struct the_nilfs *nilfs, char *buf)
  694. {
  695. return snprintf(buf, PAGE_SIZE, sb_readme_str);
  696. }
  697. NILFS_SUPERBLOCK_RO_ATTR(sb_write_time);
  698. NILFS_SUPERBLOCK_RO_ATTR(sb_write_time_secs);
  699. NILFS_SUPERBLOCK_RO_ATTR(sb_write_count);
  700. NILFS_SUPERBLOCK_RW_ATTR(sb_update_frequency);
  701. NILFS_SUPERBLOCK_RO_ATTR(README);
  702. static struct attribute *nilfs_superblock_attrs[] = {
  703. NILFS_SUPERBLOCK_ATTR_LIST(sb_write_time),
  704. NILFS_SUPERBLOCK_ATTR_LIST(sb_write_time_secs),
  705. NILFS_SUPERBLOCK_ATTR_LIST(sb_write_count),
  706. NILFS_SUPERBLOCK_ATTR_LIST(sb_update_frequency),
  707. NILFS_SUPERBLOCK_ATTR_LIST(README),
  708. NULL,
  709. };
  710. NILFS_DEV_INT_GROUP_OPS(superblock, dev);
  711. NILFS_DEV_INT_GROUP_TYPE(superblock, dev);
  712. NILFS_DEV_INT_GROUP_FNS(superblock, dev);
  713. /************************************************************************
  714. * NILFS device attrs *
  715. ************************************************************************/
  716. static
  717. ssize_t nilfs_dev_revision_show(struct nilfs_dev_attr *attr,
  718. struct the_nilfs *nilfs,
  719. char *buf)
  720. {
  721. struct nilfs_super_block **sbp = nilfs->ns_sbp;
  722. u32 major = le32_to_cpu(sbp[0]->s_rev_level);
  723. u16 minor = le16_to_cpu(sbp[0]->s_minor_rev_level);
  724. return snprintf(buf, PAGE_SIZE, "%d.%d\n", major, minor);
  725. }
  726. static
  727. ssize_t nilfs_dev_blocksize_show(struct nilfs_dev_attr *attr,
  728. struct the_nilfs *nilfs,
  729. char *buf)
  730. {
  731. return snprintf(buf, PAGE_SIZE, "%u\n", nilfs->ns_blocksize);
  732. }
  733. static
  734. ssize_t nilfs_dev_device_size_show(struct nilfs_dev_attr *attr,
  735. struct the_nilfs *nilfs,
  736. char *buf)
  737. {
  738. struct nilfs_super_block **sbp = nilfs->ns_sbp;
  739. u64 dev_size = le64_to_cpu(sbp[0]->s_dev_size);
  740. return snprintf(buf, PAGE_SIZE, "%llu\n", dev_size);
  741. }
  742. static
  743. ssize_t nilfs_dev_free_blocks_show(struct nilfs_dev_attr *attr,
  744. struct the_nilfs *nilfs,
  745. char *buf)
  746. {
  747. sector_t free_blocks = 0;
  748. nilfs_count_free_blocks(nilfs, &free_blocks);
  749. return snprintf(buf, PAGE_SIZE, "%llu\n",
  750. (unsigned long long)free_blocks);
  751. }
  752. static
  753. ssize_t nilfs_dev_uuid_show(struct nilfs_dev_attr *attr,
  754. struct the_nilfs *nilfs,
  755. char *buf)
  756. {
  757. struct nilfs_super_block **sbp = nilfs->ns_sbp;
  758. return snprintf(buf, PAGE_SIZE, "%pUb\n", sbp[0]->s_uuid);
  759. }
  760. static
  761. ssize_t nilfs_dev_volume_name_show(struct nilfs_dev_attr *attr,
  762. struct the_nilfs *nilfs,
  763. char *buf)
  764. {
  765. struct nilfs_super_block **sbp = nilfs->ns_sbp;
  766. return scnprintf(buf, sizeof(sbp[0]->s_volume_name), "%s\n",
  767. sbp[0]->s_volume_name);
  768. }
  769. static const char dev_readme_str[] =
  770. "The <device> group contains attributes that describe file system\n"
  771. "partition's details.\n\n"
  772. "(1) revision\n\tshow NILFS file system revision.\n\n"
  773. "(2) blocksize\n\tshow volume block size in bytes.\n\n"
  774. "(3) device_size\n\tshow volume size in bytes.\n\n"
  775. "(4) free_blocks\n\tshow count of free blocks on volume.\n\n"
  776. "(5) uuid\n\tshow volume's UUID.\n\n"
  777. "(6) volume_name\n\tshow volume's name.\n\n";
  778. static ssize_t nilfs_dev_README_show(struct nilfs_dev_attr *attr,
  779. struct the_nilfs *nilfs,
  780. char *buf)
  781. {
  782. return snprintf(buf, PAGE_SIZE, dev_readme_str);
  783. }
  784. NILFS_DEV_RO_ATTR(revision);
  785. NILFS_DEV_RO_ATTR(blocksize);
  786. NILFS_DEV_RO_ATTR(device_size);
  787. NILFS_DEV_RO_ATTR(free_blocks);
  788. NILFS_DEV_RO_ATTR(uuid);
  789. NILFS_DEV_RO_ATTR(volume_name);
  790. NILFS_DEV_RO_ATTR(README);
  791. static struct attribute *nilfs_dev_attrs[] = {
  792. NILFS_DEV_ATTR_LIST(revision),
  793. NILFS_DEV_ATTR_LIST(blocksize),
  794. NILFS_DEV_ATTR_LIST(device_size),
  795. NILFS_DEV_ATTR_LIST(free_blocks),
  796. NILFS_DEV_ATTR_LIST(uuid),
  797. NILFS_DEV_ATTR_LIST(volume_name),
  798. NILFS_DEV_ATTR_LIST(README),
  799. NULL,
  800. };
  801. static ssize_t nilfs_dev_attr_show(struct kobject *kobj,
  802. struct attribute *attr, char *buf)
  803. {
  804. struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
  805. ns_dev_kobj);
  806. struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr,
  807. attr);
  808. return a->show ? a->show(a, nilfs, buf) : 0;
  809. }
  810. static ssize_t nilfs_dev_attr_store(struct kobject *kobj,
  811. struct attribute *attr,
  812. const char *buf, size_t len)
  813. {
  814. struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
  815. ns_dev_kobj);
  816. struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr,
  817. attr);
  818. return a->store ? a->store(a, nilfs, buf, len) : 0;
  819. }
  820. static void nilfs_dev_attr_release(struct kobject *kobj)
  821. {
  822. struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
  823. ns_dev_kobj);
  824. complete(&nilfs->ns_dev_kobj_unregister);
  825. }
  826. static const struct sysfs_ops nilfs_dev_attr_ops = {
  827. .show = nilfs_dev_attr_show,
  828. .store = nilfs_dev_attr_store,
  829. };
  830. static struct kobj_type nilfs_dev_ktype = {
  831. .default_attrs = nilfs_dev_attrs,
  832. .sysfs_ops = &nilfs_dev_attr_ops,
  833. .release = nilfs_dev_attr_release,
  834. };
  835. int nilfs_sysfs_create_device_group(struct super_block *sb)
  836. {
  837. struct the_nilfs *nilfs = sb->s_fs_info;
  838. size_t devgrp_size = sizeof(struct nilfs_sysfs_dev_subgroups);
  839. int err;
  840. nilfs->ns_dev_subgroups = kzalloc(devgrp_size, GFP_KERNEL);
  841. if (unlikely(!nilfs->ns_dev_subgroups)) {
  842. err = -ENOMEM;
  843. nilfs_msg(sb, KERN_ERR,
  844. "unable to allocate memory for device group");
  845. goto failed_create_device_group;
  846. }
  847. nilfs->ns_dev_kobj.kset = nilfs_kset;
  848. init_completion(&nilfs->ns_dev_kobj_unregister);
  849. err = kobject_init_and_add(&nilfs->ns_dev_kobj, &nilfs_dev_ktype, NULL,
  850. "%s", sb->s_id);
  851. if (err)
  852. goto free_dev_subgroups;
  853. err = nilfs_sysfs_create_mounted_snapshots_group(nilfs);
  854. if (err)
  855. goto cleanup_dev_kobject;
  856. err = nilfs_sysfs_create_checkpoints_group(nilfs);
  857. if (err)
  858. goto delete_mounted_snapshots_group;
  859. err = nilfs_sysfs_create_segments_group(nilfs);
  860. if (err)
  861. goto delete_checkpoints_group;
  862. err = nilfs_sysfs_create_superblock_group(nilfs);
  863. if (err)
  864. goto delete_segments_group;
  865. err = nilfs_sysfs_create_segctor_group(nilfs);
  866. if (err)
  867. goto delete_superblock_group;
  868. return 0;
  869. delete_superblock_group:
  870. nilfs_sysfs_delete_superblock_group(nilfs);
  871. delete_segments_group:
  872. nilfs_sysfs_delete_segments_group(nilfs);
  873. delete_checkpoints_group:
  874. nilfs_sysfs_delete_checkpoints_group(nilfs);
  875. delete_mounted_snapshots_group:
  876. nilfs_sysfs_delete_mounted_snapshots_group(nilfs);
  877. cleanup_dev_kobject:
  878. kobject_del(&nilfs->ns_dev_kobj);
  879. free_dev_subgroups:
  880. kfree(nilfs->ns_dev_subgroups);
  881. failed_create_device_group:
  882. return err;
  883. }
  884. void nilfs_sysfs_delete_device_group(struct the_nilfs *nilfs)
  885. {
  886. nilfs_sysfs_delete_mounted_snapshots_group(nilfs);
  887. nilfs_sysfs_delete_checkpoints_group(nilfs);
  888. nilfs_sysfs_delete_segments_group(nilfs);
  889. nilfs_sysfs_delete_superblock_group(nilfs);
  890. nilfs_sysfs_delete_segctor_group(nilfs);
  891. kobject_del(&nilfs->ns_dev_kobj);
  892. kfree(nilfs->ns_dev_subgroups);
  893. }
  894. /************************************************************************
  895. * NILFS feature attrs *
  896. ************************************************************************/
  897. static ssize_t nilfs_feature_revision_show(struct kobject *kobj,
  898. struct attribute *attr, char *buf)
  899. {
  900. return snprintf(buf, PAGE_SIZE, "%d.%d\n",
  901. NILFS_CURRENT_REV, NILFS_MINOR_REV);
  902. }
  903. static const char features_readme_str[] =
  904. "The features group contains attributes that describe NILFS file\n"
  905. "system driver features.\n\n"
  906. "(1) revision\n\tshow current revision of NILFS file system driver.\n";
  907. static ssize_t nilfs_feature_README_show(struct kobject *kobj,
  908. struct attribute *attr,
  909. char *buf)
  910. {
  911. return snprintf(buf, PAGE_SIZE, features_readme_str);
  912. }
  913. NILFS_FEATURE_RO_ATTR(revision);
  914. NILFS_FEATURE_RO_ATTR(README);
  915. static struct attribute *nilfs_feature_attrs[] = {
  916. NILFS_FEATURE_ATTR_LIST(revision),
  917. NILFS_FEATURE_ATTR_LIST(README),
  918. NULL,
  919. };
  920. static const struct attribute_group nilfs_feature_attr_group = {
  921. .name = "features",
  922. .attrs = nilfs_feature_attrs,
  923. };
  924. int __init nilfs_sysfs_init(void)
  925. {
  926. int err;
  927. nilfs_kset = kset_create_and_add(NILFS_ROOT_GROUP_NAME, NULL, fs_kobj);
  928. if (!nilfs_kset) {
  929. err = -ENOMEM;
  930. nilfs_msg(NULL, KERN_ERR,
  931. "unable to create sysfs entry: err=%d", err);
  932. goto failed_sysfs_init;
  933. }
  934. err = sysfs_create_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
  935. if (unlikely(err)) {
  936. nilfs_msg(NULL, KERN_ERR,
  937. "unable to create feature group: err=%d", err);
  938. goto cleanup_sysfs_init;
  939. }
  940. return 0;
  941. cleanup_sysfs_init:
  942. kset_unregister(nilfs_kset);
  943. failed_sysfs_init:
  944. return err;
  945. }
  946. void nilfs_sysfs_exit(void)
  947. {
  948. sysfs_remove_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
  949. kset_unregister(nilfs_kset);
  950. }