orangefs-sysfs.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Documentation/ABI/stable/sysfs-fs-orangefs:
  4. *
  5. * What: /sys/fs/orangefs/perf_counter_reset
  6. * Date: June 2015
  7. * Contact: Mike Marshall <[email protected]>
  8. * Description:
  9. * echo a 0 or a 1 into perf_counter_reset to
  10. * reset all the counters in
  11. * /sys/fs/orangefs/perf_counters
  12. * except ones with PINT_PERF_PRESERVE set.
  13. *
  14. *
  15. * What: /sys/fs/orangefs/perf_counters/...
  16. * Date: Jun 2015
  17. * Contact: Mike Marshall <[email protected]>
  18. * Description:
  19. * Counters and settings for various caches.
  20. * Read only.
  21. *
  22. *
  23. * What: /sys/fs/orangefs/perf_time_interval_secs
  24. * Date: Jun 2015
  25. * Contact: Mike Marshall <[email protected]>
  26. * Description:
  27. * Length of perf counter intervals in
  28. * seconds.
  29. *
  30. *
  31. * What: /sys/fs/orangefs/perf_history_size
  32. * Date: Jun 2015
  33. * Contact: Mike Marshall <[email protected]>
  34. * Description:
  35. * The perf_counters cache statistics have N, or
  36. * perf_history_size, samples. The default is
  37. * one.
  38. *
  39. * Every perf_time_interval_secs the (first)
  40. * samples are reset.
  41. *
  42. * If N is greater than one, the "current" set
  43. * of samples is reset, and the samples from the
  44. * other N-1 intervals remain available.
  45. *
  46. *
  47. * What: /sys/fs/orangefs/op_timeout_secs
  48. * Date: Jun 2015
  49. * Contact: Mike Marshall <[email protected]>
  50. * Description:
  51. * Service operation timeout in seconds.
  52. *
  53. *
  54. * What: /sys/fs/orangefs/slot_timeout_secs
  55. * Date: Jun 2015
  56. * Contact: Mike Marshall <[email protected]>
  57. * Description:
  58. * "Slot" timeout in seconds. A "slot"
  59. * is an indexed buffer in the shared
  60. * memory segment used for communication
  61. * between the kernel module and userspace.
  62. * Slots are requested and waited for,
  63. * the wait times out after slot_timeout_secs.
  64. *
  65. * What: /sys/fs/orangefs/cache_timeout_msecs
  66. * Date: Mar 2018
  67. * Contact: Martin Brandenburg <[email protected]>
  68. * Description:
  69. * Time in milliseconds between which
  70. * orangefs_revalidate_mapping will invalidate the page
  71. * cache.
  72. *
  73. * What: /sys/fs/orangefs/dcache_timeout_msecs
  74. * Date: Jul 2016
  75. * Contact: Martin Brandenburg <[email protected]>
  76. * Description:
  77. * Time lookup is valid in milliseconds.
  78. *
  79. * What: /sys/fs/orangefs/getattr_timeout_msecs
  80. * Date: Jul 2016
  81. * Contact: Martin Brandenburg <[email protected]>
  82. * Description:
  83. * Time getattr is valid in milliseconds.
  84. *
  85. * What: /sys/fs/orangefs/readahead_count
  86. * Date: Aug 2016
  87. * Contact: Martin Brandenburg <[email protected]>
  88. * Description:
  89. * Readahead cache buffer count.
  90. *
  91. * What: /sys/fs/orangefs/readahead_size
  92. * Date: Aug 2016
  93. * Contact: Martin Brandenburg <[email protected]>
  94. * Description:
  95. * Readahead cache buffer size.
  96. *
  97. * What: /sys/fs/orangefs/readahead_count_size
  98. * Date: Aug 2016
  99. * Contact: Martin Brandenburg <[email protected]>
  100. * Description:
  101. * Readahead cache buffer count and size.
  102. *
  103. * What: /sys/fs/orangefs/readahead_readcnt
  104. * Date: Jan 2017
  105. * Contact: Martin Brandenburg <[email protected]>
  106. * Description:
  107. * Number of buffers (in multiples of readahead_size)
  108. * which can be read ahead for a single file at once.
  109. *
  110. * What: /sys/fs/orangefs/acache/...
  111. * Date: Jun 2015
  112. * Contact: Martin Brandenburg <[email protected]>
  113. * Description:
  114. * Attribute cache configurable settings.
  115. *
  116. *
  117. * What: /sys/fs/orangefs/ncache/...
  118. * Date: Jun 2015
  119. * Contact: Mike Marshall <[email protected]>
  120. * Description:
  121. * Name cache configurable settings.
  122. *
  123. *
  124. * What: /sys/fs/orangefs/capcache/...
  125. * Date: Jun 2015
  126. * Contact: Mike Marshall <[email protected]>
  127. * Description:
  128. * Capability cache configurable settings.
  129. *
  130. *
  131. * What: /sys/fs/orangefs/ccache/...
  132. * Date: Jun 2015
  133. * Contact: Mike Marshall <[email protected]>
  134. * Description:
  135. * Credential cache configurable settings.
  136. *
  137. */
  138. #include <linux/fs.h>
  139. #include <linux/kobject.h>
  140. #include <linux/string.h>
  141. #include <linux/sysfs.h>
  142. #include <linux/module.h>
  143. #include <linux/init.h>
  144. #include "protocol.h"
  145. #include "orangefs-kernel.h"
  146. #include "orangefs-sysfs.h"
  147. #define ORANGEFS_KOBJ_ID "orangefs"
  148. #define ACACHE_KOBJ_ID "acache"
  149. #define CAPCACHE_KOBJ_ID "capcache"
  150. #define CCACHE_KOBJ_ID "ccache"
  151. #define NCACHE_KOBJ_ID "ncache"
  152. #define PC_KOBJ_ID "pc"
  153. #define STATS_KOBJ_ID "stats"
  154. /*
  155. * Every item calls orangefs_attr_show and orangefs_attr_store through
  156. * orangefs_sysfs_ops. They look at the orangefs_attributes further below to
  157. * call one of sysfs_int_show, sysfs_int_store, sysfs_service_op_show, or
  158. * sysfs_service_op_store.
  159. */
  160. struct orangefs_attribute {
  161. struct attribute attr;
  162. ssize_t (*show)(struct kobject *kobj,
  163. struct orangefs_attribute *attr,
  164. char *buf);
  165. ssize_t (*store)(struct kobject *kobj,
  166. struct orangefs_attribute *attr,
  167. const char *buf,
  168. size_t count);
  169. };
  170. static ssize_t orangefs_attr_show(struct kobject *kobj,
  171. struct attribute *attr,
  172. char *buf)
  173. {
  174. struct orangefs_attribute *attribute;
  175. attribute = container_of(attr, struct orangefs_attribute, attr);
  176. if (!attribute->show)
  177. return -EIO;
  178. return attribute->show(kobj, attribute, buf);
  179. }
  180. static ssize_t orangefs_attr_store(struct kobject *kobj,
  181. struct attribute *attr,
  182. const char *buf,
  183. size_t len)
  184. {
  185. struct orangefs_attribute *attribute;
  186. if (!strcmp(kobj->name, PC_KOBJ_ID) ||
  187. !strcmp(kobj->name, STATS_KOBJ_ID))
  188. return -EPERM;
  189. attribute = container_of(attr, struct orangefs_attribute, attr);
  190. if (!attribute->store)
  191. return -EIO;
  192. return attribute->store(kobj, attribute, buf, len);
  193. }
  194. static const struct sysfs_ops orangefs_sysfs_ops = {
  195. .show = orangefs_attr_show,
  196. .store = orangefs_attr_store,
  197. };
  198. static ssize_t sysfs_int_show(struct kobject *kobj,
  199. struct orangefs_attribute *attr, char *buf)
  200. {
  201. int rc = -EIO;
  202. gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n",
  203. kobj->name);
  204. if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
  205. if (!strcmp(attr->attr.name, "op_timeout_secs")) {
  206. rc = scnprintf(buf,
  207. PAGE_SIZE,
  208. "%d\n",
  209. op_timeout_secs);
  210. goto out;
  211. } else if (!strcmp(attr->attr.name,
  212. "slot_timeout_secs")) {
  213. rc = scnprintf(buf,
  214. PAGE_SIZE,
  215. "%d\n",
  216. slot_timeout_secs);
  217. goto out;
  218. } else if (!strcmp(attr->attr.name,
  219. "cache_timeout_msecs")) {
  220. rc = scnprintf(buf,
  221. PAGE_SIZE,
  222. "%d\n",
  223. orangefs_cache_timeout_msecs);
  224. goto out;
  225. } else if (!strcmp(attr->attr.name,
  226. "dcache_timeout_msecs")) {
  227. rc = scnprintf(buf,
  228. PAGE_SIZE,
  229. "%d\n",
  230. orangefs_dcache_timeout_msecs);
  231. goto out;
  232. } else if (!strcmp(attr->attr.name,
  233. "getattr_timeout_msecs")) {
  234. rc = scnprintf(buf,
  235. PAGE_SIZE,
  236. "%d\n",
  237. orangefs_getattr_timeout_msecs);
  238. goto out;
  239. } else {
  240. goto out;
  241. }
  242. } else if (!strcmp(kobj->name, STATS_KOBJ_ID)) {
  243. if (!strcmp(attr->attr.name, "reads")) {
  244. rc = scnprintf(buf,
  245. PAGE_SIZE,
  246. "%lu\n",
  247. orangefs_stats.reads);
  248. goto out;
  249. } else if (!strcmp(attr->attr.name, "writes")) {
  250. rc = scnprintf(buf,
  251. PAGE_SIZE,
  252. "%lu\n",
  253. orangefs_stats.writes);
  254. goto out;
  255. } else {
  256. goto out;
  257. }
  258. }
  259. out:
  260. return rc;
  261. }
  262. static ssize_t sysfs_int_store(struct kobject *kobj,
  263. struct orangefs_attribute *attr, const char *buf, size_t count)
  264. {
  265. int rc = 0;
  266. gossip_debug(GOSSIP_SYSFS_DEBUG,
  267. "sysfs_int_store: start attr->attr.name:%s: buf:%s:\n",
  268. attr->attr.name, buf);
  269. if (!strcmp(attr->attr.name, "op_timeout_secs")) {
  270. rc = kstrtoint(buf, 0, &op_timeout_secs);
  271. goto out;
  272. } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
  273. rc = kstrtoint(buf, 0, &slot_timeout_secs);
  274. goto out;
  275. } else if (!strcmp(attr->attr.name, "cache_timeout_msecs")) {
  276. rc = kstrtoint(buf, 0, &orangefs_cache_timeout_msecs);
  277. goto out;
  278. } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
  279. rc = kstrtoint(buf, 0, &orangefs_dcache_timeout_msecs);
  280. goto out;
  281. } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
  282. rc = kstrtoint(buf, 0, &orangefs_getattr_timeout_msecs);
  283. goto out;
  284. } else {
  285. goto out;
  286. }
  287. out:
  288. if (rc)
  289. rc = -EINVAL;
  290. else
  291. rc = count;
  292. return rc;
  293. }
  294. /*
  295. * obtain attribute values from userspace with a service operation.
  296. */
  297. static ssize_t sysfs_service_op_show(struct kobject *kobj,
  298. struct orangefs_attribute *attr, char *buf)
  299. {
  300. struct orangefs_kernel_op_s *new_op = NULL;
  301. int rc = 0;
  302. char *ser_op_type = NULL;
  303. __u32 op_alloc_type;
  304. gossip_debug(GOSSIP_SYSFS_DEBUG,
  305. "sysfs_service_op_show: id:%s:\n",
  306. kobj->name);
  307. if (strcmp(kobj->name, PC_KOBJ_ID))
  308. op_alloc_type = ORANGEFS_VFS_OP_PARAM;
  309. else
  310. op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
  311. new_op = op_alloc(op_alloc_type);
  312. if (!new_op)
  313. return -ENOMEM;
  314. /* Can't do a service_operation if the client is not running... */
  315. rc = is_daemon_in_service();
  316. if (rc) {
  317. pr_info_ratelimited("%s: Client not running :%d:\n",
  318. __func__,
  319. is_daemon_in_service());
  320. goto out;
  321. }
  322. if (strcmp(kobj->name, PC_KOBJ_ID))
  323. new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
  324. if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
  325. /* Drop unsupported requests first. */
  326. if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) &&
  327. (!strcmp(attr->attr.name, "readahead_count") ||
  328. !strcmp(attr->attr.name, "readahead_size") ||
  329. !strcmp(attr->attr.name, "readahead_count_size") ||
  330. !strcmp(attr->attr.name, "readahead_readcnt"))) {
  331. rc = -EINVAL;
  332. goto out;
  333. }
  334. if (!strcmp(attr->attr.name, "perf_history_size"))
  335. new_op->upcall.req.param.op =
  336. ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
  337. else if (!strcmp(attr->attr.name,
  338. "perf_time_interval_secs"))
  339. new_op->upcall.req.param.op =
  340. ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
  341. else if (!strcmp(attr->attr.name,
  342. "perf_counter_reset"))
  343. new_op->upcall.req.param.op =
  344. ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
  345. else if (!strcmp(attr->attr.name,
  346. "readahead_count"))
  347. new_op->upcall.req.param.op =
  348. ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
  349. else if (!strcmp(attr->attr.name,
  350. "readahead_size"))
  351. new_op->upcall.req.param.op =
  352. ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
  353. else if (!strcmp(attr->attr.name,
  354. "readahead_count_size"))
  355. new_op->upcall.req.param.op =
  356. ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
  357. else if (!strcmp(attr->attr.name,
  358. "readahead_readcnt"))
  359. new_op->upcall.req.param.op =
  360. ORANGEFS_PARAM_REQUEST_OP_READAHEAD_READCNT;
  361. } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
  362. if (!strcmp(attr->attr.name, "timeout_msecs"))
  363. new_op->upcall.req.param.op =
  364. ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
  365. if (!strcmp(attr->attr.name, "hard_limit"))
  366. new_op->upcall.req.param.op =
  367. ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
  368. if (!strcmp(attr->attr.name, "soft_limit"))
  369. new_op->upcall.req.param.op =
  370. ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
  371. if (!strcmp(attr->attr.name, "reclaim_percentage"))
  372. new_op->upcall.req.param.op =
  373. ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
  374. } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
  375. if (!strcmp(attr->attr.name, "timeout_secs"))
  376. new_op->upcall.req.param.op =
  377. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
  378. if (!strcmp(attr->attr.name, "hard_limit"))
  379. new_op->upcall.req.param.op =
  380. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
  381. if (!strcmp(attr->attr.name, "soft_limit"))
  382. new_op->upcall.req.param.op =
  383. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
  384. if (!strcmp(attr->attr.name, "reclaim_percentage"))
  385. new_op->upcall.req.param.op =
  386. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
  387. } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
  388. if (!strcmp(attr->attr.name, "timeout_secs"))
  389. new_op->upcall.req.param.op =
  390. ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
  391. if (!strcmp(attr->attr.name, "hard_limit"))
  392. new_op->upcall.req.param.op =
  393. ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
  394. if (!strcmp(attr->attr.name, "soft_limit"))
  395. new_op->upcall.req.param.op =
  396. ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
  397. if (!strcmp(attr->attr.name, "reclaim_percentage"))
  398. new_op->upcall.req.param.op =
  399. ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
  400. } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
  401. if (!strcmp(attr->attr.name, "timeout_msecs"))
  402. new_op->upcall.req.param.op =
  403. ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
  404. if (!strcmp(attr->attr.name, "hard_limit"))
  405. new_op->upcall.req.param.op =
  406. ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
  407. if (!strcmp(attr->attr.name, "soft_limit"))
  408. new_op->upcall.req.param.op =
  409. ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
  410. if (!strcmp(attr->attr.name, "reclaim_percentage"))
  411. new_op->upcall.req.param.op =
  412. ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
  413. } else if (!strcmp(kobj->name, PC_KOBJ_ID)) {
  414. if (!strcmp(attr->attr.name, ACACHE_KOBJ_ID))
  415. new_op->upcall.req.perf_count.type =
  416. ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
  417. if (!strcmp(attr->attr.name, CAPCACHE_KOBJ_ID))
  418. new_op->upcall.req.perf_count.type =
  419. ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
  420. if (!strcmp(attr->attr.name, NCACHE_KOBJ_ID))
  421. new_op->upcall.req.perf_count.type =
  422. ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
  423. } else {
  424. gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
  425. kobj->name);
  426. rc = -EINVAL;
  427. goto out;
  428. }
  429. if (strcmp(kobj->name, PC_KOBJ_ID))
  430. ser_op_type = "orangefs_param";
  431. else
  432. ser_op_type = "orangefs_perf_count";
  433. /*
  434. * The service_operation will return an errno return code on
  435. * error, and zero on success.
  436. */
  437. rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
  438. out:
  439. if (!rc) {
  440. if (strcmp(kobj->name, PC_KOBJ_ID)) {
  441. if (new_op->upcall.req.param.op ==
  442. ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
  443. rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
  444. (int)new_op->downcall.resp.param.u.
  445. value32[0],
  446. (int)new_op->downcall.resp.param.u.
  447. value32[1]);
  448. } else {
  449. rc = scnprintf(buf, PAGE_SIZE, "%d\n",
  450. (int)new_op->downcall.resp.param.u.value64);
  451. }
  452. } else {
  453. rc = scnprintf(
  454. buf,
  455. PAGE_SIZE,
  456. "%s",
  457. new_op->downcall.resp.perf_count.buffer);
  458. }
  459. }
  460. op_release(new_op);
  461. return rc;
  462. }
  463. /*
  464. * pass attribute values back to userspace with a service operation.
  465. *
  466. * We have to do a memory allocation, an sscanf and a service operation.
  467. * And we have to evaluate what the user entered, to make sure the
  468. * value is within the range supported by the attribute. So, there's
  469. * a lot of return code checking and mapping going on here.
  470. *
  471. * We want to return 1 if we think everything went OK, and
  472. * EINVAL if not.
  473. */
  474. static ssize_t sysfs_service_op_store(struct kobject *kobj,
  475. struct orangefs_attribute *attr, const char *buf, size_t count)
  476. {
  477. struct orangefs_kernel_op_s *new_op = NULL;
  478. int val = 0;
  479. int rc = 0;
  480. gossip_debug(GOSSIP_SYSFS_DEBUG,
  481. "sysfs_service_op_store: id:%s:\n",
  482. kobj->name);
  483. new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
  484. if (!new_op)
  485. return -EINVAL; /* sic */
  486. /* Can't do a service_operation if the client is not running... */
  487. rc = is_daemon_in_service();
  488. if (rc) {
  489. pr_info("%s: Client not running :%d:\n",
  490. __func__,
  491. is_daemon_in_service());
  492. goto out;
  493. }
  494. /*
  495. * The value we want to send back to userspace is in buf, unless this
  496. * there are two parameters, which is specially handled below.
  497. */
  498. if (strcmp(kobj->name, ORANGEFS_KOBJ_ID) ||
  499. strcmp(attr->attr.name, "readahead_count_size")) {
  500. rc = kstrtoint(buf, 0, &val);
  501. if (rc)
  502. goto out;
  503. }
  504. new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
  505. if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
  506. /* Drop unsupported requests first. */
  507. if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) &&
  508. (!strcmp(attr->attr.name, "readahead_count") ||
  509. !strcmp(attr->attr.name, "readahead_size") ||
  510. !strcmp(attr->attr.name, "readahead_count_size") ||
  511. !strcmp(attr->attr.name, "readahead_readcnt"))) {
  512. rc = -EINVAL;
  513. goto out;
  514. }
  515. if (!strcmp(attr->attr.name, "perf_history_size")) {
  516. if (val > 0) {
  517. new_op->upcall.req.param.op =
  518. ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
  519. } else {
  520. rc = 0;
  521. goto out;
  522. }
  523. } else if (!strcmp(attr->attr.name,
  524. "perf_time_interval_secs")) {
  525. if (val > 0) {
  526. new_op->upcall.req.param.op =
  527. ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
  528. } else {
  529. rc = 0;
  530. goto out;
  531. }
  532. } else if (!strcmp(attr->attr.name,
  533. "perf_counter_reset")) {
  534. if ((val == 0) || (val == 1)) {
  535. new_op->upcall.req.param.op =
  536. ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
  537. } else {
  538. rc = 0;
  539. goto out;
  540. }
  541. } else if (!strcmp(attr->attr.name,
  542. "readahead_count")) {
  543. if ((val >= 0)) {
  544. new_op->upcall.req.param.op =
  545. ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
  546. } else {
  547. rc = 0;
  548. goto out;
  549. }
  550. } else if (!strcmp(attr->attr.name,
  551. "readahead_size")) {
  552. if ((val >= 0)) {
  553. new_op->upcall.req.param.op =
  554. ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
  555. } else {
  556. rc = 0;
  557. goto out;
  558. }
  559. } else if (!strcmp(attr->attr.name,
  560. "readahead_count_size")) {
  561. int val1, val2;
  562. rc = sscanf(buf, "%d %d", &val1, &val2);
  563. if (rc < 2) {
  564. rc = 0;
  565. goto out;
  566. }
  567. if ((val1 >= 0) && (val2 >= 0)) {
  568. new_op->upcall.req.param.op =
  569. ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
  570. } else {
  571. rc = 0;
  572. goto out;
  573. }
  574. new_op->upcall.req.param.u.value32[0] = val1;
  575. new_op->upcall.req.param.u.value32[1] = val2;
  576. goto value_set;
  577. } else if (!strcmp(attr->attr.name,
  578. "readahead_readcnt")) {
  579. if ((val >= 0)) {
  580. new_op->upcall.req.param.op =
  581. ORANGEFS_PARAM_REQUEST_OP_READAHEAD_READCNT;
  582. } else {
  583. rc = 0;
  584. goto out;
  585. }
  586. }
  587. } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
  588. if (!strcmp(attr->attr.name, "hard_limit")) {
  589. if (val > -1) {
  590. new_op->upcall.req.param.op =
  591. ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
  592. } else {
  593. rc = 0;
  594. goto out;
  595. }
  596. } else if (!strcmp(attr->attr.name, "soft_limit")) {
  597. if (val > -1) {
  598. new_op->upcall.req.param.op =
  599. ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
  600. } else {
  601. rc = 0;
  602. goto out;
  603. }
  604. } else if (!strcmp(attr->attr.name,
  605. "reclaim_percentage")) {
  606. if ((val > -1) && (val < 101)) {
  607. new_op->upcall.req.param.op =
  608. ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
  609. } else {
  610. rc = 0;
  611. goto out;
  612. }
  613. } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
  614. if (val > -1) {
  615. new_op->upcall.req.param.op =
  616. ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
  617. } else {
  618. rc = 0;
  619. goto out;
  620. }
  621. }
  622. } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
  623. if (!strcmp(attr->attr.name, "hard_limit")) {
  624. if (val > -1) {
  625. new_op->upcall.req.param.op =
  626. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
  627. } else {
  628. rc = 0;
  629. goto out;
  630. }
  631. } else if (!strcmp(attr->attr.name, "soft_limit")) {
  632. if (val > -1) {
  633. new_op->upcall.req.param.op =
  634. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
  635. } else {
  636. rc = 0;
  637. goto out;
  638. }
  639. } else if (!strcmp(attr->attr.name,
  640. "reclaim_percentage")) {
  641. if ((val > -1) && (val < 101)) {
  642. new_op->upcall.req.param.op =
  643. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
  644. } else {
  645. rc = 0;
  646. goto out;
  647. }
  648. } else if (!strcmp(attr->attr.name, "timeout_secs")) {
  649. if (val > -1) {
  650. new_op->upcall.req.param.op =
  651. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
  652. } else {
  653. rc = 0;
  654. goto out;
  655. }
  656. }
  657. } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
  658. if (!strcmp(attr->attr.name, "hard_limit")) {
  659. if (val > -1) {
  660. new_op->upcall.req.param.op =
  661. ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
  662. } else {
  663. rc = 0;
  664. goto out;
  665. }
  666. } else if (!strcmp(attr->attr.name, "soft_limit")) {
  667. if (val > -1) {
  668. new_op->upcall.req.param.op =
  669. ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
  670. } else {
  671. rc = 0;
  672. goto out;
  673. }
  674. } else if (!strcmp(attr->attr.name,
  675. "reclaim_percentage")) {
  676. if ((val > -1) && (val < 101)) {
  677. new_op->upcall.req.param.op =
  678. ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
  679. } else {
  680. rc = 0;
  681. goto out;
  682. }
  683. } else if (!strcmp(attr->attr.name, "timeout_secs")) {
  684. if (val > -1) {
  685. new_op->upcall.req.param.op =
  686. ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
  687. } else {
  688. rc = 0;
  689. goto out;
  690. }
  691. }
  692. } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
  693. if (!strcmp(attr->attr.name, "hard_limit")) {
  694. if (val > -1) {
  695. new_op->upcall.req.param.op =
  696. ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
  697. } else {
  698. rc = 0;
  699. goto out;
  700. }
  701. } else if (!strcmp(attr->attr.name, "soft_limit")) {
  702. if (val > -1) {
  703. new_op->upcall.req.param.op =
  704. ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
  705. } else {
  706. rc = 0;
  707. goto out;
  708. }
  709. } else if (!strcmp(attr->attr.name,
  710. "reclaim_percentage")) {
  711. if ((val > -1) && (val < 101)) {
  712. new_op->upcall.req.param.op =
  713. ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
  714. } else {
  715. rc = 0;
  716. goto out;
  717. }
  718. } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
  719. if (val > -1) {
  720. new_op->upcall.req.param.op =
  721. ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
  722. } else {
  723. rc = 0;
  724. goto out;
  725. }
  726. }
  727. } else {
  728. gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
  729. kobj->name);
  730. rc = -EINVAL;
  731. goto out;
  732. }
  733. new_op->upcall.req.param.u.value64 = val;
  734. value_set:
  735. /*
  736. * The service_operation will return a errno return code on
  737. * error, and zero on success.
  738. */
  739. rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
  740. if (rc < 0) {
  741. gossip_err("sysfs_service_op_store: service op returned:%d:\n",
  742. rc);
  743. rc = 0;
  744. } else {
  745. rc = count;
  746. }
  747. out:
  748. op_release(new_op);
  749. if (rc == -ENOMEM || rc == 0)
  750. rc = -EINVAL;
  751. return rc;
  752. }
  753. static struct orangefs_attribute op_timeout_secs_attribute =
  754. __ATTR(op_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
  755. static struct orangefs_attribute slot_timeout_secs_attribute =
  756. __ATTR(slot_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
  757. static struct orangefs_attribute cache_timeout_msecs_attribute =
  758. __ATTR(cache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
  759. static struct orangefs_attribute dcache_timeout_msecs_attribute =
  760. __ATTR(dcache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
  761. static struct orangefs_attribute getattr_timeout_msecs_attribute =
  762. __ATTR(getattr_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
  763. static struct orangefs_attribute readahead_count_attribute =
  764. __ATTR(readahead_count, 0664, sysfs_service_op_show,
  765. sysfs_service_op_store);
  766. static struct orangefs_attribute readahead_size_attribute =
  767. __ATTR(readahead_size, 0664, sysfs_service_op_show,
  768. sysfs_service_op_store);
  769. static struct orangefs_attribute readahead_count_size_attribute =
  770. __ATTR(readahead_count_size, 0664, sysfs_service_op_show,
  771. sysfs_service_op_store);
  772. static struct orangefs_attribute readahead_readcnt_attribute =
  773. __ATTR(readahead_readcnt, 0664, sysfs_service_op_show,
  774. sysfs_service_op_store);
  775. static struct orangefs_attribute perf_counter_reset_attribute =
  776. __ATTR(perf_counter_reset,
  777. 0664,
  778. sysfs_service_op_show,
  779. sysfs_service_op_store);
  780. static struct orangefs_attribute perf_history_size_attribute =
  781. __ATTR(perf_history_size,
  782. 0664,
  783. sysfs_service_op_show,
  784. sysfs_service_op_store);
  785. static struct orangefs_attribute perf_time_interval_secs_attribute =
  786. __ATTR(perf_time_interval_secs,
  787. 0664,
  788. sysfs_service_op_show,
  789. sysfs_service_op_store);
  790. static struct attribute *orangefs_default_attrs[] = {
  791. &op_timeout_secs_attribute.attr,
  792. &slot_timeout_secs_attribute.attr,
  793. &cache_timeout_msecs_attribute.attr,
  794. &dcache_timeout_msecs_attribute.attr,
  795. &getattr_timeout_msecs_attribute.attr,
  796. &readahead_count_attribute.attr,
  797. &readahead_size_attribute.attr,
  798. &readahead_count_size_attribute.attr,
  799. &readahead_readcnt_attribute.attr,
  800. &perf_counter_reset_attribute.attr,
  801. &perf_history_size_attribute.attr,
  802. &perf_time_interval_secs_attribute.attr,
  803. NULL,
  804. };
  805. ATTRIBUTE_GROUPS(orangefs_default);
  806. static struct kobject *orangefs_obj;
  807. static void orangefs_obj_release(struct kobject *kobj)
  808. {
  809. kfree(orangefs_obj);
  810. orangefs_obj = NULL;
  811. }
  812. static struct kobj_type orangefs_ktype = {
  813. .sysfs_ops = &orangefs_sysfs_ops,
  814. .default_groups = orangefs_default_groups,
  815. .release = orangefs_obj_release,
  816. };
  817. static struct orangefs_attribute acache_hard_limit_attribute =
  818. __ATTR(hard_limit,
  819. 0664,
  820. sysfs_service_op_show,
  821. sysfs_service_op_store);
  822. static struct orangefs_attribute acache_reclaim_percent_attribute =
  823. __ATTR(reclaim_percentage,
  824. 0664,
  825. sysfs_service_op_show,
  826. sysfs_service_op_store);
  827. static struct orangefs_attribute acache_soft_limit_attribute =
  828. __ATTR(soft_limit,
  829. 0664,
  830. sysfs_service_op_show,
  831. sysfs_service_op_store);
  832. static struct orangefs_attribute acache_timeout_msecs_attribute =
  833. __ATTR(timeout_msecs,
  834. 0664,
  835. sysfs_service_op_show,
  836. sysfs_service_op_store);
  837. static struct attribute *acache_orangefs_default_attrs[] = {
  838. &acache_hard_limit_attribute.attr,
  839. &acache_reclaim_percent_attribute.attr,
  840. &acache_soft_limit_attribute.attr,
  841. &acache_timeout_msecs_attribute.attr,
  842. NULL,
  843. };
  844. ATTRIBUTE_GROUPS(acache_orangefs_default);
  845. static struct kobject *acache_orangefs_obj;
  846. static void acache_orangefs_obj_release(struct kobject *kobj)
  847. {
  848. kfree(acache_orangefs_obj);
  849. acache_orangefs_obj = NULL;
  850. }
  851. static struct kobj_type acache_orangefs_ktype = {
  852. .sysfs_ops = &orangefs_sysfs_ops,
  853. .default_groups = acache_orangefs_default_groups,
  854. .release = acache_orangefs_obj_release,
  855. };
  856. static struct orangefs_attribute capcache_hard_limit_attribute =
  857. __ATTR(hard_limit,
  858. 0664,
  859. sysfs_service_op_show,
  860. sysfs_service_op_store);
  861. static struct orangefs_attribute capcache_reclaim_percent_attribute =
  862. __ATTR(reclaim_percentage,
  863. 0664,
  864. sysfs_service_op_show,
  865. sysfs_service_op_store);
  866. static struct orangefs_attribute capcache_soft_limit_attribute =
  867. __ATTR(soft_limit,
  868. 0664,
  869. sysfs_service_op_show,
  870. sysfs_service_op_store);
  871. static struct orangefs_attribute capcache_timeout_secs_attribute =
  872. __ATTR(timeout_secs,
  873. 0664,
  874. sysfs_service_op_show,
  875. sysfs_service_op_store);
  876. static struct attribute *capcache_orangefs_default_attrs[] = {
  877. &capcache_hard_limit_attribute.attr,
  878. &capcache_reclaim_percent_attribute.attr,
  879. &capcache_soft_limit_attribute.attr,
  880. &capcache_timeout_secs_attribute.attr,
  881. NULL,
  882. };
  883. ATTRIBUTE_GROUPS(capcache_orangefs_default);
  884. static struct kobject *capcache_orangefs_obj;
  885. static void capcache_orangefs_obj_release(struct kobject *kobj)
  886. {
  887. kfree(capcache_orangefs_obj);
  888. capcache_orangefs_obj = NULL;
  889. }
  890. static struct kobj_type capcache_orangefs_ktype = {
  891. .sysfs_ops = &orangefs_sysfs_ops,
  892. .default_groups = capcache_orangefs_default_groups,
  893. .release = capcache_orangefs_obj_release,
  894. };
  895. static struct orangefs_attribute ccache_hard_limit_attribute =
  896. __ATTR(hard_limit,
  897. 0664,
  898. sysfs_service_op_show,
  899. sysfs_service_op_store);
  900. static struct orangefs_attribute ccache_reclaim_percent_attribute =
  901. __ATTR(reclaim_percentage,
  902. 0664,
  903. sysfs_service_op_show,
  904. sysfs_service_op_store);
  905. static struct orangefs_attribute ccache_soft_limit_attribute =
  906. __ATTR(soft_limit,
  907. 0664,
  908. sysfs_service_op_show,
  909. sysfs_service_op_store);
  910. static struct orangefs_attribute ccache_timeout_secs_attribute =
  911. __ATTR(timeout_secs,
  912. 0664,
  913. sysfs_service_op_show,
  914. sysfs_service_op_store);
  915. static struct attribute *ccache_orangefs_default_attrs[] = {
  916. &ccache_hard_limit_attribute.attr,
  917. &ccache_reclaim_percent_attribute.attr,
  918. &ccache_soft_limit_attribute.attr,
  919. &ccache_timeout_secs_attribute.attr,
  920. NULL,
  921. };
  922. ATTRIBUTE_GROUPS(ccache_orangefs_default);
  923. static struct kobject *ccache_orangefs_obj;
  924. static void ccache_orangefs_obj_release(struct kobject *kobj)
  925. {
  926. kfree(ccache_orangefs_obj);
  927. ccache_orangefs_obj = NULL;
  928. }
  929. static struct kobj_type ccache_orangefs_ktype = {
  930. .sysfs_ops = &orangefs_sysfs_ops,
  931. .default_groups = ccache_orangefs_default_groups,
  932. .release = ccache_orangefs_obj_release,
  933. };
  934. static struct orangefs_attribute ncache_hard_limit_attribute =
  935. __ATTR(hard_limit,
  936. 0664,
  937. sysfs_service_op_show,
  938. sysfs_service_op_store);
  939. static struct orangefs_attribute ncache_reclaim_percent_attribute =
  940. __ATTR(reclaim_percentage,
  941. 0664,
  942. sysfs_service_op_show,
  943. sysfs_service_op_store);
  944. static struct orangefs_attribute ncache_soft_limit_attribute =
  945. __ATTR(soft_limit,
  946. 0664,
  947. sysfs_service_op_show,
  948. sysfs_service_op_store);
  949. static struct orangefs_attribute ncache_timeout_msecs_attribute =
  950. __ATTR(timeout_msecs,
  951. 0664,
  952. sysfs_service_op_show,
  953. sysfs_service_op_store);
  954. static struct attribute *ncache_orangefs_default_attrs[] = {
  955. &ncache_hard_limit_attribute.attr,
  956. &ncache_reclaim_percent_attribute.attr,
  957. &ncache_soft_limit_attribute.attr,
  958. &ncache_timeout_msecs_attribute.attr,
  959. NULL,
  960. };
  961. ATTRIBUTE_GROUPS(ncache_orangefs_default);
  962. static struct kobject *ncache_orangefs_obj;
  963. static void ncache_orangefs_obj_release(struct kobject *kobj)
  964. {
  965. kfree(ncache_orangefs_obj);
  966. ncache_orangefs_obj = NULL;
  967. }
  968. static struct kobj_type ncache_orangefs_ktype = {
  969. .sysfs_ops = &orangefs_sysfs_ops,
  970. .default_groups = ncache_orangefs_default_groups,
  971. .release = ncache_orangefs_obj_release,
  972. };
  973. static struct orangefs_attribute pc_acache_attribute =
  974. __ATTR(acache,
  975. 0664,
  976. sysfs_service_op_show,
  977. NULL);
  978. static struct orangefs_attribute pc_capcache_attribute =
  979. __ATTR(capcache,
  980. 0664,
  981. sysfs_service_op_show,
  982. NULL);
  983. static struct orangefs_attribute pc_ncache_attribute =
  984. __ATTR(ncache,
  985. 0664,
  986. sysfs_service_op_show,
  987. NULL);
  988. static struct attribute *pc_orangefs_default_attrs[] = {
  989. &pc_acache_attribute.attr,
  990. &pc_capcache_attribute.attr,
  991. &pc_ncache_attribute.attr,
  992. NULL,
  993. };
  994. ATTRIBUTE_GROUPS(pc_orangefs_default);
  995. static struct kobject *pc_orangefs_obj;
  996. static void pc_orangefs_obj_release(struct kobject *kobj)
  997. {
  998. kfree(pc_orangefs_obj);
  999. pc_orangefs_obj = NULL;
  1000. }
  1001. static struct kobj_type pc_orangefs_ktype = {
  1002. .sysfs_ops = &orangefs_sysfs_ops,
  1003. .default_groups = pc_orangefs_default_groups,
  1004. .release = pc_orangefs_obj_release,
  1005. };
  1006. static struct orangefs_attribute stats_reads_attribute =
  1007. __ATTR(reads,
  1008. 0664,
  1009. sysfs_int_show,
  1010. NULL);
  1011. static struct orangefs_attribute stats_writes_attribute =
  1012. __ATTR(writes,
  1013. 0664,
  1014. sysfs_int_show,
  1015. NULL);
  1016. static struct attribute *stats_orangefs_default_attrs[] = {
  1017. &stats_reads_attribute.attr,
  1018. &stats_writes_attribute.attr,
  1019. NULL,
  1020. };
  1021. ATTRIBUTE_GROUPS(stats_orangefs_default);
  1022. static struct kobject *stats_orangefs_obj;
  1023. static void stats_orangefs_obj_release(struct kobject *kobj)
  1024. {
  1025. kfree(stats_orangefs_obj);
  1026. stats_orangefs_obj = NULL;
  1027. }
  1028. static struct kobj_type stats_orangefs_ktype = {
  1029. .sysfs_ops = &orangefs_sysfs_ops,
  1030. .default_groups = stats_orangefs_default_groups,
  1031. .release = stats_orangefs_obj_release,
  1032. };
  1033. int orangefs_sysfs_init(void)
  1034. {
  1035. int rc = -EINVAL;
  1036. gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
  1037. /* create /sys/fs/orangefs. */
  1038. orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
  1039. if (!orangefs_obj)
  1040. goto out;
  1041. rc = kobject_init_and_add(orangefs_obj,
  1042. &orangefs_ktype,
  1043. fs_kobj,
  1044. ORANGEFS_KOBJ_ID);
  1045. if (rc)
  1046. goto ofs_obj_bail;
  1047. kobject_uevent(orangefs_obj, KOBJ_ADD);
  1048. /* create /sys/fs/orangefs/acache. */
  1049. acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
  1050. if (!acache_orangefs_obj) {
  1051. rc = -EINVAL;
  1052. goto ofs_obj_bail;
  1053. }
  1054. rc = kobject_init_and_add(acache_orangefs_obj,
  1055. &acache_orangefs_ktype,
  1056. orangefs_obj,
  1057. ACACHE_KOBJ_ID);
  1058. if (rc)
  1059. goto acache_obj_bail;
  1060. kobject_uevent(acache_orangefs_obj, KOBJ_ADD);
  1061. /* create /sys/fs/orangefs/capcache. */
  1062. capcache_orangefs_obj =
  1063. kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
  1064. if (!capcache_orangefs_obj) {
  1065. rc = -EINVAL;
  1066. goto acache_obj_bail;
  1067. }
  1068. rc = kobject_init_and_add(capcache_orangefs_obj,
  1069. &capcache_orangefs_ktype,
  1070. orangefs_obj,
  1071. CAPCACHE_KOBJ_ID);
  1072. if (rc)
  1073. goto capcache_obj_bail;
  1074. kobject_uevent(capcache_orangefs_obj, KOBJ_ADD);
  1075. /* create /sys/fs/orangefs/ccache. */
  1076. ccache_orangefs_obj =
  1077. kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
  1078. if (!ccache_orangefs_obj) {
  1079. rc = -EINVAL;
  1080. goto capcache_obj_bail;
  1081. }
  1082. rc = kobject_init_and_add(ccache_orangefs_obj,
  1083. &ccache_orangefs_ktype,
  1084. orangefs_obj,
  1085. CCACHE_KOBJ_ID);
  1086. if (rc)
  1087. goto ccache_obj_bail;
  1088. kobject_uevent(ccache_orangefs_obj, KOBJ_ADD);
  1089. /* create /sys/fs/orangefs/ncache. */
  1090. ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
  1091. if (!ncache_orangefs_obj) {
  1092. rc = -EINVAL;
  1093. goto ccache_obj_bail;
  1094. }
  1095. rc = kobject_init_and_add(ncache_orangefs_obj,
  1096. &ncache_orangefs_ktype,
  1097. orangefs_obj,
  1098. NCACHE_KOBJ_ID);
  1099. if (rc)
  1100. goto ncache_obj_bail;
  1101. kobject_uevent(ncache_orangefs_obj, KOBJ_ADD);
  1102. /* create /sys/fs/orangefs/perf_counters. */
  1103. pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
  1104. if (!pc_orangefs_obj) {
  1105. rc = -EINVAL;
  1106. goto ncache_obj_bail;
  1107. }
  1108. rc = kobject_init_and_add(pc_orangefs_obj,
  1109. &pc_orangefs_ktype,
  1110. orangefs_obj,
  1111. "perf_counters");
  1112. if (rc)
  1113. goto pc_obj_bail;
  1114. kobject_uevent(pc_orangefs_obj, KOBJ_ADD);
  1115. /* create /sys/fs/orangefs/stats. */
  1116. stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
  1117. if (!stats_orangefs_obj) {
  1118. rc = -EINVAL;
  1119. goto pc_obj_bail;
  1120. }
  1121. rc = kobject_init_and_add(stats_orangefs_obj,
  1122. &stats_orangefs_ktype,
  1123. orangefs_obj,
  1124. STATS_KOBJ_ID);
  1125. if (rc)
  1126. goto stats_obj_bail;
  1127. kobject_uevent(stats_orangefs_obj, KOBJ_ADD);
  1128. goto out;
  1129. stats_obj_bail:
  1130. kobject_put(stats_orangefs_obj);
  1131. pc_obj_bail:
  1132. kobject_put(pc_orangefs_obj);
  1133. ncache_obj_bail:
  1134. kobject_put(ncache_orangefs_obj);
  1135. ccache_obj_bail:
  1136. kobject_put(ccache_orangefs_obj);
  1137. capcache_obj_bail:
  1138. kobject_put(capcache_orangefs_obj);
  1139. acache_obj_bail:
  1140. kobject_put(acache_orangefs_obj);
  1141. ofs_obj_bail:
  1142. kobject_put(orangefs_obj);
  1143. out:
  1144. return rc;
  1145. }
  1146. void orangefs_sysfs_exit(void)
  1147. {
  1148. gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
  1149. kobject_put(acache_orangefs_obj);
  1150. kobject_put(capcache_orangefs_obj);
  1151. kobject_put(ccache_orangefs_obj);
  1152. kobject_put(ncache_orangefs_obj);
  1153. kobject_put(pc_orangefs_obj);
  1154. kobject_put(stats_orangefs_obj);
  1155. kobject_put(orangefs_obj);
  1156. }