orangefs-sysfs.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  1. /*
  2. * Documentation/ABI/stable/orangefs-sysfs:
  3. *
  4. * What: /sys/fs/orangefs/perf_counter_reset
  5. * Date: June 2015
  6. * Contact: Mike Marshall <hubcap@omnibond.com>
  7. * Description:
  8. * echo a 0 or a 1 into perf_counter_reset to
  9. * reset all the counters in
  10. * /sys/fs/orangefs/perf_counters
  11. * except ones with PINT_PERF_PRESERVE set.
  12. *
  13. *
  14. * What: /sys/fs/orangefs/perf_counters/...
  15. * Date: Jun 2015
  16. * Contact: Mike Marshall <hubcap@omnibond.com>
  17. * Description:
  18. * Counters and settings for various caches.
  19. * Read only.
  20. *
  21. *
  22. * What: /sys/fs/orangefs/perf_time_interval_secs
  23. * Date: Jun 2015
  24. * Contact: Mike Marshall <hubcap@omnibond.com>
  25. * Description:
  26. * Length of perf counter intervals in
  27. * seconds.
  28. *
  29. *
  30. * What: /sys/fs/orangefs/perf_history_size
  31. * Date: Jun 2015
  32. * Contact: Mike Marshall <hubcap@omnibond.com>
  33. * Description:
  34. * The perf_counters cache statistics have N, or
  35. * perf_history_size, samples. The default is
  36. * one.
  37. *
  38. * Every perf_time_interval_secs the (first)
  39. * samples are reset.
  40. *
  41. * If N is greater than one, the "current" set
  42. * of samples is reset, and the samples from the
  43. * other N-1 intervals remain available.
  44. *
  45. *
  46. * What: /sys/fs/orangefs/op_timeout_secs
  47. * Date: Jun 2015
  48. * Contact: Mike Marshall <hubcap@omnibond.com>
  49. * Description:
  50. * Service operation timeout in seconds.
  51. *
  52. *
  53. * What: /sys/fs/orangefs/slot_timeout_secs
  54. * Date: Jun 2015
  55. * Contact: Mike Marshall <hubcap@omnibond.com>
  56. * Description:
  57. * "Slot" timeout in seconds. A "slot"
  58. * is an indexed buffer in the shared
  59. * memory segment used for communication
  60. * between the kernel module and userspace.
  61. * Slots are requested and waited for,
  62. * the wait times out after slot_timeout_secs.
  63. *
  64. * What: /sys/fs/orangefs/dcache_timeout_msecs
  65. * Date: Jul 2016
  66. * Contact: Martin Brandenburg <martin@omnibond.com>
  67. * Description:
  68. * Time lookup is valid in milliseconds.
  69. *
  70. * What: /sys/fs/orangefs/getattr_timeout_msecs
  71. * Date: Jul 2016
  72. * Contact: Martin Brandenburg <martin@omnibond.com>
  73. * Description:
  74. * Time getattr is valid in milliseconds.
  75. *
  76. * What: /sys/fs/orangefs/acache/...
  77. * Date: Jun 2015
  78. * Contact: Martin Brandenburg <martin@omnibond.com>
  79. * Description:
  80. * Attribute cache configurable settings.
  81. *
  82. *
  83. * What: /sys/fs/orangefs/ncache/...
  84. * Date: Jun 2015
  85. * Contact: Mike Marshall <hubcap@omnibond.com>
  86. * Description:
  87. * Name cache configurable settings.
  88. *
  89. *
  90. * What: /sys/fs/orangefs/capcache/...
  91. * Date: Jun 2015
  92. * Contact: Mike Marshall <hubcap@omnibond.com>
  93. * Description:
  94. * Capability cache configurable settings.
  95. *
  96. *
  97. * What: /sys/fs/orangefs/ccache/...
  98. * Date: Jun 2015
  99. * Contact: Mike Marshall <hubcap@omnibond.com>
  100. * Description:
  101. * Credential cache configurable settings.
  102. *
  103. */
  104. #include <linux/fs.h>
  105. #include <linux/kobject.h>
  106. #include <linux/string.h>
  107. #include <linux/sysfs.h>
  108. #include <linux/module.h>
  109. #include <linux/init.h>
  110. #include "protocol.h"
  111. #include "orangefs-kernel.h"
  112. #include "orangefs-sysfs.h"
  113. #define ORANGEFS_KOBJ_ID "orangefs"
  114. #define ACACHE_KOBJ_ID "acache"
  115. #define CAPCACHE_KOBJ_ID "capcache"
  116. #define CCACHE_KOBJ_ID "ccache"
  117. #define NCACHE_KOBJ_ID "ncache"
  118. #define PC_KOBJ_ID "pc"
  119. #define STATS_KOBJ_ID "stats"
  120. struct orangefs_obj {
  121. struct kobject kobj;
  122. int op_timeout_secs;
  123. int perf_counter_reset;
  124. int perf_history_size;
  125. int perf_time_interval_secs;
  126. int slot_timeout_secs;
  127. int dcache_timeout_msecs;
  128. int getattr_timeout_msecs;
  129. };
  130. struct acache_orangefs_obj {
  131. struct kobject kobj;
  132. int hard_limit;
  133. int reclaim_percentage;
  134. int soft_limit;
  135. int timeout_msecs;
  136. };
  137. struct capcache_orangefs_obj {
  138. struct kobject kobj;
  139. int hard_limit;
  140. int reclaim_percentage;
  141. int soft_limit;
  142. int timeout_secs;
  143. };
  144. struct ccache_orangefs_obj {
  145. struct kobject kobj;
  146. int hard_limit;
  147. int reclaim_percentage;
  148. int soft_limit;
  149. int timeout_secs;
  150. };
  151. struct ncache_orangefs_obj {
  152. struct kobject kobj;
  153. int hard_limit;
  154. int reclaim_percentage;
  155. int soft_limit;
  156. int timeout_msecs;
  157. };
  158. struct pc_orangefs_obj {
  159. struct kobject kobj;
  160. char *acache;
  161. char *capcache;
  162. char *ncache;
  163. };
  164. struct stats_orangefs_obj {
  165. struct kobject kobj;
  166. int reads;
  167. int writes;
  168. };
  169. struct orangefs_attribute {
  170. struct attribute attr;
  171. ssize_t (*show)(struct orangefs_obj *orangefs_obj,
  172. struct orangefs_attribute *attr,
  173. char *buf);
  174. ssize_t (*store)(struct orangefs_obj *orangefs_obj,
  175. struct orangefs_attribute *attr,
  176. const char *buf,
  177. size_t count);
  178. };
  179. struct acache_orangefs_attribute {
  180. struct attribute attr;
  181. ssize_t (*show)(struct acache_orangefs_obj *acache_orangefs_obj,
  182. struct acache_orangefs_attribute *attr,
  183. char *buf);
  184. ssize_t (*store)(struct acache_orangefs_obj *acache_orangefs_obj,
  185. struct acache_orangefs_attribute *attr,
  186. const char *buf,
  187. size_t count);
  188. };
  189. struct capcache_orangefs_attribute {
  190. struct attribute attr;
  191. ssize_t (*show)(struct capcache_orangefs_obj *capcache_orangefs_obj,
  192. struct capcache_orangefs_attribute *attr,
  193. char *buf);
  194. ssize_t (*store)(struct capcache_orangefs_obj *capcache_orangefs_obj,
  195. struct capcache_orangefs_attribute *attr,
  196. const char *buf,
  197. size_t count);
  198. };
  199. struct ccache_orangefs_attribute {
  200. struct attribute attr;
  201. ssize_t (*show)(struct ccache_orangefs_obj *ccache_orangefs_obj,
  202. struct ccache_orangefs_attribute *attr,
  203. char *buf);
  204. ssize_t (*store)(struct ccache_orangefs_obj *ccache_orangefs_obj,
  205. struct ccache_orangefs_attribute *attr,
  206. const char *buf,
  207. size_t count);
  208. };
  209. struct ncache_orangefs_attribute {
  210. struct attribute attr;
  211. ssize_t (*show)(struct ncache_orangefs_obj *ncache_orangefs_obj,
  212. struct ncache_orangefs_attribute *attr,
  213. char *buf);
  214. ssize_t (*store)(struct ncache_orangefs_obj *ncache_orangefs_obj,
  215. struct ncache_orangefs_attribute *attr,
  216. const char *buf,
  217. size_t count);
  218. };
  219. struct pc_orangefs_attribute {
  220. struct attribute attr;
  221. ssize_t (*show)(struct pc_orangefs_obj *pc_orangefs_obj,
  222. struct pc_orangefs_attribute *attr,
  223. char *buf);
  224. ssize_t (*store)(struct pc_orangefs_obj *pc_orangefs_obj,
  225. struct pc_orangefs_attribute *attr,
  226. const char *buf,
  227. size_t count);
  228. };
  229. struct stats_orangefs_attribute {
  230. struct attribute attr;
  231. ssize_t (*show)(struct stats_orangefs_obj *stats_orangefs_obj,
  232. struct stats_orangefs_attribute *attr,
  233. char *buf);
  234. ssize_t (*store)(struct stats_orangefs_obj *stats_orangefs_obj,
  235. struct stats_orangefs_attribute *attr,
  236. const char *buf,
  237. size_t count);
  238. };
  239. static ssize_t orangefs_attr_show(struct kobject *kobj,
  240. struct attribute *attr,
  241. char *buf)
  242. {
  243. struct orangefs_attribute *attribute;
  244. struct orangefs_obj *orangefs_obj;
  245. int rc;
  246. attribute = container_of(attr, struct orangefs_attribute, attr);
  247. orangefs_obj = container_of(kobj, struct orangefs_obj, kobj);
  248. if (!attribute->show) {
  249. rc = -EIO;
  250. goto out;
  251. }
  252. rc = attribute->show(orangefs_obj, attribute, buf);
  253. out:
  254. return rc;
  255. }
  256. static ssize_t orangefs_attr_store(struct kobject *kobj,
  257. struct attribute *attr,
  258. const char *buf,
  259. size_t len)
  260. {
  261. struct orangefs_attribute *attribute;
  262. struct orangefs_obj *orangefs_obj;
  263. int rc;
  264. gossip_debug(GOSSIP_SYSFS_DEBUG,
  265. "orangefs_attr_store: start\n");
  266. attribute = container_of(attr, struct orangefs_attribute, attr);
  267. orangefs_obj = container_of(kobj, struct orangefs_obj, kobj);
  268. if (!attribute->store) {
  269. rc = -EIO;
  270. goto out;
  271. }
  272. rc = attribute->store(orangefs_obj, attribute, buf, len);
  273. out:
  274. return rc;
  275. }
  276. static const struct sysfs_ops orangefs_sysfs_ops = {
  277. .show = orangefs_attr_show,
  278. .store = orangefs_attr_store,
  279. };
  280. static ssize_t acache_orangefs_attr_show(struct kobject *kobj,
  281. struct attribute *attr,
  282. char *buf)
  283. {
  284. struct acache_orangefs_attribute *attribute;
  285. struct acache_orangefs_obj *acache_orangefs_obj;
  286. int rc;
  287. attribute = container_of(attr, struct acache_orangefs_attribute, attr);
  288. acache_orangefs_obj =
  289. container_of(kobj, struct acache_orangefs_obj, kobj);
  290. if (!attribute->show) {
  291. rc = -EIO;
  292. goto out;
  293. }
  294. rc = attribute->show(acache_orangefs_obj, attribute, buf);
  295. out:
  296. return rc;
  297. }
  298. static ssize_t acache_orangefs_attr_store(struct kobject *kobj,
  299. struct attribute *attr,
  300. const char *buf,
  301. size_t len)
  302. {
  303. struct acache_orangefs_attribute *attribute;
  304. struct acache_orangefs_obj *acache_orangefs_obj;
  305. int rc;
  306. gossip_debug(GOSSIP_SYSFS_DEBUG,
  307. "acache_orangefs_attr_store: start\n");
  308. attribute = container_of(attr, struct acache_orangefs_attribute, attr);
  309. acache_orangefs_obj =
  310. container_of(kobj, struct acache_orangefs_obj, kobj);
  311. if (!attribute->store) {
  312. rc = -EIO;
  313. goto out;
  314. }
  315. rc = attribute->store(acache_orangefs_obj, attribute, buf, len);
  316. out:
  317. return rc;
  318. }
  319. static const struct sysfs_ops acache_orangefs_sysfs_ops = {
  320. .show = acache_orangefs_attr_show,
  321. .store = acache_orangefs_attr_store,
  322. };
  323. static ssize_t capcache_orangefs_attr_show(struct kobject *kobj,
  324. struct attribute *attr,
  325. char *buf)
  326. {
  327. struct capcache_orangefs_attribute *attribute;
  328. struct capcache_orangefs_obj *capcache_orangefs_obj;
  329. int rc;
  330. attribute =
  331. container_of(attr, struct capcache_orangefs_attribute, attr);
  332. capcache_orangefs_obj =
  333. container_of(kobj, struct capcache_orangefs_obj, kobj);
  334. if (!attribute->show) {
  335. rc = -EIO;
  336. goto out;
  337. }
  338. rc = attribute->show(capcache_orangefs_obj, attribute, buf);
  339. out:
  340. return rc;
  341. }
  342. static ssize_t capcache_orangefs_attr_store(struct kobject *kobj,
  343. struct attribute *attr,
  344. const char *buf,
  345. size_t len)
  346. {
  347. struct capcache_orangefs_attribute *attribute;
  348. struct capcache_orangefs_obj *capcache_orangefs_obj;
  349. int rc;
  350. gossip_debug(GOSSIP_SYSFS_DEBUG,
  351. "capcache_orangefs_attr_store: start\n");
  352. attribute =
  353. container_of(attr, struct capcache_orangefs_attribute, attr);
  354. capcache_orangefs_obj =
  355. container_of(kobj, struct capcache_orangefs_obj, kobj);
  356. if (!attribute->store) {
  357. rc = -EIO;
  358. goto out;
  359. }
  360. rc = attribute->store(capcache_orangefs_obj, attribute, buf, len);
  361. out:
  362. return rc;
  363. }
  364. static const struct sysfs_ops capcache_orangefs_sysfs_ops = {
  365. .show = capcache_orangefs_attr_show,
  366. .store = capcache_orangefs_attr_store,
  367. };
  368. static ssize_t ccache_orangefs_attr_show(struct kobject *kobj,
  369. struct attribute *attr,
  370. char *buf)
  371. {
  372. struct ccache_orangefs_attribute *attribute;
  373. struct ccache_orangefs_obj *ccache_orangefs_obj;
  374. int rc;
  375. attribute =
  376. container_of(attr, struct ccache_orangefs_attribute, attr);
  377. ccache_orangefs_obj =
  378. container_of(kobj, struct ccache_orangefs_obj, kobj);
  379. if (!attribute->show) {
  380. rc = -EIO;
  381. goto out;
  382. }
  383. rc = attribute->show(ccache_orangefs_obj, attribute, buf);
  384. out:
  385. return rc;
  386. }
  387. static ssize_t ccache_orangefs_attr_store(struct kobject *kobj,
  388. struct attribute *attr,
  389. const char *buf,
  390. size_t len)
  391. {
  392. struct ccache_orangefs_attribute *attribute;
  393. struct ccache_orangefs_obj *ccache_orangefs_obj;
  394. int rc;
  395. gossip_debug(GOSSIP_SYSFS_DEBUG,
  396. "ccache_orangefs_attr_store: start\n");
  397. attribute =
  398. container_of(attr, struct ccache_orangefs_attribute, attr);
  399. ccache_orangefs_obj =
  400. container_of(kobj, struct ccache_orangefs_obj, kobj);
  401. if (!attribute->store) {
  402. rc = -EIO;
  403. goto out;
  404. }
  405. rc = attribute->store(ccache_orangefs_obj, attribute, buf, len);
  406. out:
  407. return rc;
  408. }
  409. static const struct sysfs_ops ccache_orangefs_sysfs_ops = {
  410. .show = ccache_orangefs_attr_show,
  411. .store = ccache_orangefs_attr_store,
  412. };
  413. static ssize_t ncache_orangefs_attr_show(struct kobject *kobj,
  414. struct attribute *attr,
  415. char *buf)
  416. {
  417. struct ncache_orangefs_attribute *attribute;
  418. struct ncache_orangefs_obj *ncache_orangefs_obj;
  419. int rc;
  420. attribute = container_of(attr, struct ncache_orangefs_attribute, attr);
  421. ncache_orangefs_obj =
  422. container_of(kobj, struct ncache_orangefs_obj, kobj);
  423. if (!attribute->show) {
  424. rc = -EIO;
  425. goto out;
  426. }
  427. rc = attribute->show(ncache_orangefs_obj, attribute, buf);
  428. out:
  429. return rc;
  430. }
  431. static ssize_t ncache_orangefs_attr_store(struct kobject *kobj,
  432. struct attribute *attr,
  433. const char *buf,
  434. size_t len)
  435. {
  436. struct ncache_orangefs_attribute *attribute;
  437. struct ncache_orangefs_obj *ncache_orangefs_obj;
  438. int rc;
  439. gossip_debug(GOSSIP_SYSFS_DEBUG,
  440. "ncache_orangefs_attr_store: start\n");
  441. attribute = container_of(attr, struct ncache_orangefs_attribute, attr);
  442. ncache_orangefs_obj =
  443. container_of(kobj, struct ncache_orangefs_obj, kobj);
  444. if (!attribute->store) {
  445. rc = -EIO;
  446. goto out;
  447. }
  448. rc = attribute->store(ncache_orangefs_obj, attribute, buf, len);
  449. out:
  450. return rc;
  451. }
  452. static const struct sysfs_ops ncache_orangefs_sysfs_ops = {
  453. .show = ncache_orangefs_attr_show,
  454. .store = ncache_orangefs_attr_store,
  455. };
  456. static ssize_t pc_orangefs_attr_show(struct kobject *kobj,
  457. struct attribute *attr,
  458. char *buf)
  459. {
  460. struct pc_orangefs_attribute *attribute;
  461. struct pc_orangefs_obj *pc_orangefs_obj;
  462. int rc;
  463. attribute = container_of(attr, struct pc_orangefs_attribute, attr);
  464. pc_orangefs_obj =
  465. container_of(kobj, struct pc_orangefs_obj, kobj);
  466. if (!attribute->show) {
  467. rc = -EIO;
  468. goto out;
  469. }
  470. rc = attribute->show(pc_orangefs_obj, attribute, buf);
  471. out:
  472. return rc;
  473. }
  474. static const struct sysfs_ops pc_orangefs_sysfs_ops = {
  475. .show = pc_orangefs_attr_show,
  476. };
  477. static ssize_t stats_orangefs_attr_show(struct kobject *kobj,
  478. struct attribute *attr,
  479. char *buf)
  480. {
  481. struct stats_orangefs_attribute *attribute;
  482. struct stats_orangefs_obj *stats_orangefs_obj;
  483. int rc;
  484. attribute = container_of(attr, struct stats_orangefs_attribute, attr);
  485. stats_orangefs_obj =
  486. container_of(kobj, struct stats_orangefs_obj, kobj);
  487. if (!attribute->show) {
  488. rc = -EIO;
  489. goto out;
  490. }
  491. rc = attribute->show(stats_orangefs_obj, attribute, buf);
  492. out:
  493. return rc;
  494. }
  495. static const struct sysfs_ops stats_orangefs_sysfs_ops = {
  496. .show = stats_orangefs_attr_show,
  497. };
  498. static void orangefs_release(struct kobject *kobj)
  499. {
  500. struct orangefs_obj *orangefs_obj;
  501. orangefs_obj = container_of(kobj, struct orangefs_obj, kobj);
  502. kfree(orangefs_obj);
  503. }
  504. static void acache_orangefs_release(struct kobject *kobj)
  505. {
  506. struct acache_orangefs_obj *acache_orangefs_obj;
  507. acache_orangefs_obj =
  508. container_of(kobj, struct acache_orangefs_obj, kobj);
  509. kfree(acache_orangefs_obj);
  510. }
  511. static void capcache_orangefs_release(struct kobject *kobj)
  512. {
  513. struct capcache_orangefs_obj *capcache_orangefs_obj;
  514. capcache_orangefs_obj =
  515. container_of(kobj, struct capcache_orangefs_obj, kobj);
  516. kfree(capcache_orangefs_obj);
  517. }
  518. static void ccache_orangefs_release(struct kobject *kobj)
  519. {
  520. struct ccache_orangefs_obj *ccache_orangefs_obj;
  521. ccache_orangefs_obj =
  522. container_of(kobj, struct ccache_orangefs_obj, kobj);
  523. kfree(ccache_orangefs_obj);
  524. }
  525. static void ncache_orangefs_release(struct kobject *kobj)
  526. {
  527. struct ncache_orangefs_obj *ncache_orangefs_obj;
  528. ncache_orangefs_obj =
  529. container_of(kobj, struct ncache_orangefs_obj, kobj);
  530. kfree(ncache_orangefs_obj);
  531. }
  532. static void pc_orangefs_release(struct kobject *kobj)
  533. {
  534. struct pc_orangefs_obj *pc_orangefs_obj;
  535. pc_orangefs_obj =
  536. container_of(kobj, struct pc_orangefs_obj, kobj);
  537. kfree(pc_orangefs_obj);
  538. }
  539. static void stats_orangefs_release(struct kobject *kobj)
  540. {
  541. struct stats_orangefs_obj *stats_orangefs_obj;
  542. stats_orangefs_obj =
  543. container_of(kobj, struct stats_orangefs_obj, kobj);
  544. kfree(stats_orangefs_obj);
  545. }
  546. static ssize_t sysfs_int_show(char *kobj_id, char *buf, void *attr)
  547. {
  548. int rc = -EIO;
  549. struct orangefs_attribute *orangefs_attr;
  550. struct stats_orangefs_attribute *stats_orangefs_attr;
  551. gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n", kobj_id);
  552. if (!strcmp(kobj_id, ORANGEFS_KOBJ_ID)) {
  553. orangefs_attr = (struct orangefs_attribute *)attr;
  554. if (!strcmp(orangefs_attr->attr.name, "op_timeout_secs")) {
  555. rc = scnprintf(buf,
  556. PAGE_SIZE,
  557. "%d\n",
  558. op_timeout_secs);
  559. goto out;
  560. } else if (!strcmp(orangefs_attr->attr.name,
  561. "slot_timeout_secs")) {
  562. rc = scnprintf(buf,
  563. PAGE_SIZE,
  564. "%d\n",
  565. slot_timeout_secs);
  566. goto out;
  567. } else if (!strcmp(orangefs_attr->attr.name,
  568. "dcache_timeout_msecs")) {
  569. rc = scnprintf(buf,
  570. PAGE_SIZE,
  571. "%d\n",
  572. dcache_timeout_msecs);
  573. goto out;
  574. } else if (!strcmp(orangefs_attr->attr.name,
  575. "getattr_timeout_msecs")) {
  576. rc = scnprintf(buf,
  577. PAGE_SIZE,
  578. "%d\n",
  579. getattr_timeout_msecs);
  580. goto out;
  581. } else {
  582. goto out;
  583. }
  584. } else if (!strcmp(kobj_id, STATS_KOBJ_ID)) {
  585. stats_orangefs_attr = (struct stats_orangefs_attribute *)attr;
  586. if (!strcmp(stats_orangefs_attr->attr.name, "reads")) {
  587. rc = scnprintf(buf,
  588. PAGE_SIZE,
  589. "%lu\n",
  590. g_orangefs_stats.reads);
  591. goto out;
  592. } else if (!strcmp(stats_orangefs_attr->attr.name, "writes")) {
  593. rc = scnprintf(buf,
  594. PAGE_SIZE,
  595. "%lu\n",
  596. g_orangefs_stats.writes);
  597. goto out;
  598. } else {
  599. goto out;
  600. }
  601. }
  602. out:
  603. return rc;
  604. }
  605. static ssize_t int_orangefs_show(struct orangefs_obj *orangefs_obj,
  606. struct orangefs_attribute *attr,
  607. char *buf)
  608. {
  609. int rc;
  610. gossip_debug(GOSSIP_SYSFS_DEBUG,
  611. "int_orangefs_show:start attr->attr.name:%s:\n",
  612. attr->attr.name);
  613. rc = sysfs_int_show(ORANGEFS_KOBJ_ID, buf, (void *) attr);
  614. return rc;
  615. }
  616. static ssize_t int_stats_show(struct stats_orangefs_obj *stats_orangefs_obj,
  617. struct stats_orangefs_attribute *attr,
  618. char *buf)
  619. {
  620. int rc;
  621. gossip_debug(GOSSIP_SYSFS_DEBUG,
  622. "int_stats_show:start attr->attr.name:%s:\n",
  623. attr->attr.name);
  624. rc = sysfs_int_show(STATS_KOBJ_ID, buf, (void *) attr);
  625. return rc;
  626. }
  627. static ssize_t int_store(struct orangefs_obj *orangefs_obj,
  628. struct orangefs_attribute *attr,
  629. const char *buf,
  630. size_t count)
  631. {
  632. int rc = 0;
  633. gossip_debug(GOSSIP_SYSFS_DEBUG,
  634. "int_store: start attr->attr.name:%s: buf:%s:\n",
  635. attr->attr.name, buf);
  636. if (!strcmp(attr->attr.name, "op_timeout_secs")) {
  637. rc = kstrtoint(buf, 0, &op_timeout_secs);
  638. goto out;
  639. } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
  640. rc = kstrtoint(buf, 0, &slot_timeout_secs);
  641. goto out;
  642. } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
  643. rc = kstrtoint(buf, 0, &dcache_timeout_msecs);
  644. goto out;
  645. } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
  646. rc = kstrtoint(buf, 0, &getattr_timeout_msecs);
  647. goto out;
  648. } else {
  649. goto out;
  650. }
  651. out:
  652. if (rc)
  653. rc = -EINVAL;
  654. else
  655. rc = count;
  656. return rc;
  657. }
  658. /*
  659. * obtain attribute values from userspace with a service operation.
  660. */
  661. static int sysfs_service_op_show(char *kobj_id, char *buf, void *attr)
  662. {
  663. struct orangefs_kernel_op_s *new_op = NULL;
  664. int rc = 0;
  665. char *ser_op_type = NULL;
  666. struct orangefs_attribute *orangefs_attr;
  667. struct acache_orangefs_attribute *acache_attr;
  668. struct capcache_orangefs_attribute *capcache_attr;
  669. struct ccache_orangefs_attribute *ccache_attr;
  670. struct ncache_orangefs_attribute *ncache_attr;
  671. struct pc_orangefs_attribute *pc_attr;
  672. __u32 op_alloc_type;
  673. gossip_debug(GOSSIP_SYSFS_DEBUG,
  674. "sysfs_service_op_show: id:%s:\n",
  675. kobj_id);
  676. if (strcmp(kobj_id, PC_KOBJ_ID))
  677. op_alloc_type = ORANGEFS_VFS_OP_PARAM;
  678. else
  679. op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
  680. new_op = op_alloc(op_alloc_type);
  681. if (!new_op)
  682. return -ENOMEM;
  683. /* Can't do a service_operation if the client is not running... */
  684. rc = is_daemon_in_service();
  685. if (rc) {
  686. pr_info("%s: Client not running :%d:\n",
  687. __func__,
  688. is_daemon_in_service());
  689. goto out;
  690. }
  691. if (strcmp(kobj_id, PC_KOBJ_ID))
  692. new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
  693. if (!strcmp(kobj_id, ORANGEFS_KOBJ_ID)) {
  694. orangefs_attr = (struct orangefs_attribute *)attr;
  695. if (!strcmp(orangefs_attr->attr.name, "perf_history_size"))
  696. new_op->upcall.req.param.op =
  697. ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
  698. else if (!strcmp(orangefs_attr->attr.name,
  699. "perf_time_interval_secs"))
  700. new_op->upcall.req.param.op =
  701. ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
  702. else if (!strcmp(orangefs_attr->attr.name,
  703. "perf_counter_reset"))
  704. new_op->upcall.req.param.op =
  705. ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
  706. } else if (!strcmp(kobj_id, ACACHE_KOBJ_ID)) {
  707. acache_attr = (struct acache_orangefs_attribute *)attr;
  708. if (!strcmp(acache_attr->attr.name, "timeout_msecs"))
  709. new_op->upcall.req.param.op =
  710. ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
  711. if (!strcmp(acache_attr->attr.name, "hard_limit"))
  712. new_op->upcall.req.param.op =
  713. ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
  714. if (!strcmp(acache_attr->attr.name, "soft_limit"))
  715. new_op->upcall.req.param.op =
  716. ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
  717. if (!strcmp(acache_attr->attr.name, "reclaim_percentage"))
  718. new_op->upcall.req.param.op =
  719. ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
  720. } else if (!strcmp(kobj_id, CAPCACHE_KOBJ_ID)) {
  721. capcache_attr = (struct capcache_orangefs_attribute *)attr;
  722. if (!strcmp(capcache_attr->attr.name, "timeout_secs"))
  723. new_op->upcall.req.param.op =
  724. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
  725. if (!strcmp(capcache_attr->attr.name, "hard_limit"))
  726. new_op->upcall.req.param.op =
  727. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
  728. if (!strcmp(capcache_attr->attr.name, "soft_limit"))
  729. new_op->upcall.req.param.op =
  730. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
  731. if (!strcmp(capcache_attr->attr.name, "reclaim_percentage"))
  732. new_op->upcall.req.param.op =
  733. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
  734. } else if (!strcmp(kobj_id, CCACHE_KOBJ_ID)) {
  735. ccache_attr = (struct ccache_orangefs_attribute *)attr;
  736. if (!strcmp(ccache_attr->attr.name, "timeout_secs"))
  737. new_op->upcall.req.param.op =
  738. ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
  739. if (!strcmp(ccache_attr->attr.name, "hard_limit"))
  740. new_op->upcall.req.param.op =
  741. ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
  742. if (!strcmp(ccache_attr->attr.name, "soft_limit"))
  743. new_op->upcall.req.param.op =
  744. ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
  745. if (!strcmp(ccache_attr->attr.name, "reclaim_percentage"))
  746. new_op->upcall.req.param.op =
  747. ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
  748. } else if (!strcmp(kobj_id, NCACHE_KOBJ_ID)) {
  749. ncache_attr = (struct ncache_orangefs_attribute *)attr;
  750. if (!strcmp(ncache_attr->attr.name, "timeout_msecs"))
  751. new_op->upcall.req.param.op =
  752. ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
  753. if (!strcmp(ncache_attr->attr.name, "hard_limit"))
  754. new_op->upcall.req.param.op =
  755. ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
  756. if (!strcmp(ncache_attr->attr.name, "soft_limit"))
  757. new_op->upcall.req.param.op =
  758. ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
  759. if (!strcmp(ncache_attr->attr.name, "reclaim_percentage"))
  760. new_op->upcall.req.param.op =
  761. ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
  762. } else if (!strcmp(kobj_id, PC_KOBJ_ID)) {
  763. pc_attr = (struct pc_orangefs_attribute *)attr;
  764. if (!strcmp(pc_attr->attr.name, ACACHE_KOBJ_ID))
  765. new_op->upcall.req.perf_count.type =
  766. ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
  767. if (!strcmp(pc_attr->attr.name, CAPCACHE_KOBJ_ID))
  768. new_op->upcall.req.perf_count.type =
  769. ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
  770. if (!strcmp(pc_attr->attr.name, NCACHE_KOBJ_ID))
  771. new_op->upcall.req.perf_count.type =
  772. ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
  773. } else {
  774. gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
  775. kobj_id);
  776. rc = -EINVAL;
  777. goto out;
  778. }
  779. if (strcmp(kobj_id, PC_KOBJ_ID))
  780. ser_op_type = "orangefs_param";
  781. else
  782. ser_op_type = "orangefs_perf_count";
  783. /*
  784. * The service_operation will return an errno return code on
  785. * error, and zero on success.
  786. */
  787. rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
  788. out:
  789. if (!rc) {
  790. if (strcmp(kobj_id, PC_KOBJ_ID)) {
  791. rc = scnprintf(buf,
  792. PAGE_SIZE,
  793. "%d\n",
  794. (int)new_op->downcall.resp.param.value);
  795. } else {
  796. rc = scnprintf(
  797. buf,
  798. PAGE_SIZE,
  799. "%s",
  800. new_op->downcall.resp.perf_count.buffer);
  801. }
  802. }
  803. op_release(new_op);
  804. return rc;
  805. }
  806. static ssize_t service_orangefs_show(struct orangefs_obj *orangefs_obj,
  807. struct orangefs_attribute *attr,
  808. char *buf)
  809. {
  810. int rc = 0;
  811. rc = sysfs_service_op_show(ORANGEFS_KOBJ_ID, buf, (void *)attr);
  812. return rc;
  813. }
  814. static ssize_t
  815. service_acache_show(struct acache_orangefs_obj *acache_orangefs_obj,
  816. struct acache_orangefs_attribute *attr,
  817. char *buf)
  818. {
  819. int rc = 0;
  820. rc = sysfs_service_op_show(ACACHE_KOBJ_ID, buf, (void *)attr);
  821. return rc;
  822. }
  823. static ssize_t service_capcache_show(struct capcache_orangefs_obj
  824. *capcache_orangefs_obj,
  825. struct capcache_orangefs_attribute *attr,
  826. char *buf)
  827. {
  828. int rc = 0;
  829. rc = sysfs_service_op_show(CAPCACHE_KOBJ_ID, buf, (void *)attr);
  830. return rc;
  831. }
  832. static ssize_t service_ccache_show(struct ccache_orangefs_obj
  833. *ccache_orangefs_obj,
  834. struct ccache_orangefs_attribute *attr,
  835. char *buf)
  836. {
  837. int rc = 0;
  838. rc = sysfs_service_op_show(CCACHE_KOBJ_ID, buf, (void *)attr);
  839. return rc;
  840. }
  841. static ssize_t
  842. service_ncache_show(struct ncache_orangefs_obj *ncache_orangefs_obj,
  843. struct ncache_orangefs_attribute *attr,
  844. char *buf)
  845. {
  846. int rc = 0;
  847. rc = sysfs_service_op_show(NCACHE_KOBJ_ID, buf, (void *)attr);
  848. return rc;
  849. }
  850. static ssize_t
  851. service_pc_show(struct pc_orangefs_obj *pc_orangefs_obj,
  852. struct pc_orangefs_attribute *attr,
  853. char *buf)
  854. {
  855. int rc = 0;
  856. rc = sysfs_service_op_show(PC_KOBJ_ID, buf, (void *)attr);
  857. return rc;
  858. }
  859. /*
  860. * pass attribute values back to userspace with a service operation.
  861. *
  862. * We have to do a memory allocation, an sscanf and a service operation.
  863. * And we have to evaluate what the user entered, to make sure the
  864. * value is within the range supported by the attribute. So, there's
  865. * a lot of return code checking and mapping going on here.
  866. *
  867. * We want to return 1 if we think everything went OK, and
  868. * EINVAL if not.
  869. */
  870. static int sysfs_service_op_store(char *kobj_id, const char *buf, void *attr)
  871. {
  872. struct orangefs_kernel_op_s *new_op = NULL;
  873. int val = 0;
  874. int rc = 0;
  875. struct orangefs_attribute *orangefs_attr;
  876. struct acache_orangefs_attribute *acache_attr;
  877. struct capcache_orangefs_attribute *capcache_attr;
  878. struct ccache_orangefs_attribute *ccache_attr;
  879. struct ncache_orangefs_attribute *ncache_attr;
  880. gossip_debug(GOSSIP_SYSFS_DEBUG,
  881. "sysfs_service_op_store: id:%s:\n",
  882. kobj_id);
  883. new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
  884. if (!new_op)
  885. return -EINVAL; /* sic */
  886. /* Can't do a service_operation if the client is not running... */
  887. rc = is_daemon_in_service();
  888. if (rc) {
  889. pr_info("%s: Client not running :%d:\n",
  890. __func__,
  891. is_daemon_in_service());
  892. goto out;
  893. }
  894. /*
  895. * The value we want to send back to userspace is in buf.
  896. */
  897. rc = kstrtoint(buf, 0, &val);
  898. if (rc)
  899. goto out;
  900. if (!strcmp(kobj_id, ORANGEFS_KOBJ_ID)) {
  901. orangefs_attr = (struct orangefs_attribute *)attr;
  902. if (!strcmp(orangefs_attr->attr.name, "perf_history_size")) {
  903. if (val > 0) {
  904. new_op->upcall.req.param.op =
  905. ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
  906. } else {
  907. rc = 0;
  908. goto out;
  909. }
  910. } else if (!strcmp(orangefs_attr->attr.name,
  911. "perf_time_interval_secs")) {
  912. if (val > 0) {
  913. new_op->upcall.req.param.op =
  914. ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
  915. } else {
  916. rc = 0;
  917. goto out;
  918. }
  919. } else if (!strcmp(orangefs_attr->attr.name,
  920. "perf_counter_reset")) {
  921. if ((val == 0) || (val == 1)) {
  922. new_op->upcall.req.param.op =
  923. ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
  924. } else {
  925. rc = 0;
  926. goto out;
  927. }
  928. }
  929. } else if (!strcmp(kobj_id, ACACHE_KOBJ_ID)) {
  930. acache_attr = (struct acache_orangefs_attribute *)attr;
  931. if (!strcmp(acache_attr->attr.name, "hard_limit")) {
  932. if (val > -1) {
  933. new_op->upcall.req.param.op =
  934. ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
  935. } else {
  936. rc = 0;
  937. goto out;
  938. }
  939. } else if (!strcmp(acache_attr->attr.name, "soft_limit")) {
  940. if (val > -1) {
  941. new_op->upcall.req.param.op =
  942. ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
  943. } else {
  944. rc = 0;
  945. goto out;
  946. }
  947. } else if (!strcmp(acache_attr->attr.name,
  948. "reclaim_percentage")) {
  949. if ((val > -1) && (val < 101)) {
  950. new_op->upcall.req.param.op =
  951. ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
  952. } else {
  953. rc = 0;
  954. goto out;
  955. }
  956. } else if (!strcmp(acache_attr->attr.name, "timeout_msecs")) {
  957. if (val > -1) {
  958. new_op->upcall.req.param.op =
  959. ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
  960. } else {
  961. rc = 0;
  962. goto out;
  963. }
  964. }
  965. } else if (!strcmp(kobj_id, CAPCACHE_KOBJ_ID)) {
  966. capcache_attr = (struct capcache_orangefs_attribute *)attr;
  967. if (!strcmp(capcache_attr->attr.name, "hard_limit")) {
  968. if (val > -1) {
  969. new_op->upcall.req.param.op =
  970. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
  971. } else {
  972. rc = 0;
  973. goto out;
  974. }
  975. } else if (!strcmp(capcache_attr->attr.name, "soft_limit")) {
  976. if (val > -1) {
  977. new_op->upcall.req.param.op =
  978. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
  979. } else {
  980. rc = 0;
  981. goto out;
  982. }
  983. } else if (!strcmp(capcache_attr->attr.name,
  984. "reclaim_percentage")) {
  985. if ((val > -1) && (val < 101)) {
  986. new_op->upcall.req.param.op =
  987. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
  988. } else {
  989. rc = 0;
  990. goto out;
  991. }
  992. } else if (!strcmp(capcache_attr->attr.name, "timeout_secs")) {
  993. if (val > -1) {
  994. new_op->upcall.req.param.op =
  995. ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
  996. } else {
  997. rc = 0;
  998. goto out;
  999. }
  1000. }
  1001. } else if (!strcmp(kobj_id, CCACHE_KOBJ_ID)) {
  1002. ccache_attr = (struct ccache_orangefs_attribute *)attr;
  1003. if (!strcmp(ccache_attr->attr.name, "hard_limit")) {
  1004. if (val > -1) {
  1005. new_op->upcall.req.param.op =
  1006. ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
  1007. } else {
  1008. rc = 0;
  1009. goto out;
  1010. }
  1011. } else if (!strcmp(ccache_attr->attr.name, "soft_limit")) {
  1012. if (val > -1) {
  1013. new_op->upcall.req.param.op =
  1014. ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
  1015. } else {
  1016. rc = 0;
  1017. goto out;
  1018. }
  1019. } else if (!strcmp(ccache_attr->attr.name,
  1020. "reclaim_percentage")) {
  1021. if ((val > -1) && (val < 101)) {
  1022. new_op->upcall.req.param.op =
  1023. ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
  1024. } else {
  1025. rc = 0;
  1026. goto out;
  1027. }
  1028. } else if (!strcmp(ccache_attr->attr.name, "timeout_secs")) {
  1029. if (val > -1) {
  1030. new_op->upcall.req.param.op =
  1031. ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
  1032. } else {
  1033. rc = 0;
  1034. goto out;
  1035. }
  1036. }
  1037. } else if (!strcmp(kobj_id, NCACHE_KOBJ_ID)) {
  1038. ncache_attr = (struct ncache_orangefs_attribute *)attr;
  1039. if (!strcmp(ncache_attr->attr.name, "hard_limit")) {
  1040. if (val > -1) {
  1041. new_op->upcall.req.param.op =
  1042. ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
  1043. } else {
  1044. rc = 0;
  1045. goto out;
  1046. }
  1047. } else if (!strcmp(ncache_attr->attr.name, "soft_limit")) {
  1048. if (val > -1) {
  1049. new_op->upcall.req.param.op =
  1050. ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
  1051. } else {
  1052. rc = 0;
  1053. goto out;
  1054. }
  1055. } else if (!strcmp(ncache_attr->attr.name,
  1056. "reclaim_percentage")) {
  1057. if ((val > -1) && (val < 101)) {
  1058. new_op->upcall.req.param.op =
  1059. ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
  1060. } else {
  1061. rc = 0;
  1062. goto out;
  1063. }
  1064. } else if (!strcmp(ncache_attr->attr.name, "timeout_msecs")) {
  1065. if (val > -1) {
  1066. new_op->upcall.req.param.op =
  1067. ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
  1068. } else {
  1069. rc = 0;
  1070. goto out;
  1071. }
  1072. }
  1073. } else {
  1074. gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
  1075. kobj_id);
  1076. rc = -EINVAL;
  1077. goto out;
  1078. }
  1079. new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
  1080. new_op->upcall.req.param.value = val;
  1081. /*
  1082. * The service_operation will return a errno return code on
  1083. * error, and zero on success.
  1084. */
  1085. rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
  1086. if (rc < 0) {
  1087. gossip_err("sysfs_service_op_store: service op returned:%d:\n",
  1088. rc);
  1089. rc = 0;
  1090. } else {
  1091. rc = 1;
  1092. }
  1093. out:
  1094. op_release(new_op);
  1095. if (rc == -ENOMEM || rc == 0)
  1096. rc = -EINVAL;
  1097. return rc;
  1098. }
  1099. static ssize_t
  1100. service_orangefs_store(struct orangefs_obj *orangefs_obj,
  1101. struct orangefs_attribute *attr,
  1102. const char *buf,
  1103. size_t count)
  1104. {
  1105. int rc = 0;
  1106. rc = sysfs_service_op_store(ORANGEFS_KOBJ_ID, buf, (void *) attr);
  1107. /* rc should have an errno value if the service_op went bad. */
  1108. if (rc == 1)
  1109. rc = count;
  1110. return rc;
  1111. }
  1112. static ssize_t
  1113. service_acache_store(struct acache_orangefs_obj *acache_orangefs_obj,
  1114. struct acache_orangefs_attribute *attr,
  1115. const char *buf,
  1116. size_t count)
  1117. {
  1118. int rc = 0;
  1119. rc = sysfs_service_op_store(ACACHE_KOBJ_ID, buf, (void *) attr);
  1120. /* rc should have an errno value if the service_op went bad. */
  1121. if (rc == 1)
  1122. rc = count;
  1123. return rc;
  1124. }
  1125. static ssize_t
  1126. service_capcache_store(struct capcache_orangefs_obj
  1127. *capcache_orangefs_obj,
  1128. struct capcache_orangefs_attribute *attr,
  1129. const char *buf,
  1130. size_t count)
  1131. {
  1132. int rc = 0;
  1133. rc = sysfs_service_op_store(CAPCACHE_KOBJ_ID, buf, (void *) attr);
  1134. /* rc should have an errno value if the service_op went bad. */
  1135. if (rc == 1)
  1136. rc = count;
  1137. return rc;
  1138. }
  1139. static ssize_t service_ccache_store(struct ccache_orangefs_obj
  1140. *ccache_orangefs_obj,
  1141. struct ccache_orangefs_attribute *attr,
  1142. const char *buf,
  1143. size_t count)
  1144. {
  1145. int rc = 0;
  1146. rc = sysfs_service_op_store(CCACHE_KOBJ_ID, buf, (void *) attr);
  1147. /* rc should have an errno value if the service_op went bad. */
  1148. if (rc == 1)
  1149. rc = count;
  1150. return rc;
  1151. }
  1152. static ssize_t
  1153. service_ncache_store(struct ncache_orangefs_obj *ncache_orangefs_obj,
  1154. struct ncache_orangefs_attribute *attr,
  1155. const char *buf,
  1156. size_t count)
  1157. {
  1158. int rc = 0;
  1159. rc = sysfs_service_op_store(NCACHE_KOBJ_ID, buf, (void *) attr);
  1160. /* rc should have an errno value if the service_op went bad. */
  1161. if (rc == 1)
  1162. rc = count;
  1163. return rc;
  1164. }
  1165. static struct orangefs_attribute op_timeout_secs_attribute =
  1166. __ATTR(op_timeout_secs, 0664, int_orangefs_show, int_store);
  1167. static struct orangefs_attribute slot_timeout_secs_attribute =
  1168. __ATTR(slot_timeout_secs, 0664, int_orangefs_show, int_store);
  1169. static struct orangefs_attribute dcache_timeout_msecs_attribute =
  1170. __ATTR(dcache_timeout_msecs, 0664, int_orangefs_show, int_store);
  1171. static struct orangefs_attribute getattr_timeout_msecs_attribute =
  1172. __ATTR(getattr_timeout_msecs, 0664, int_orangefs_show, int_store);
  1173. static struct orangefs_attribute perf_counter_reset_attribute =
  1174. __ATTR(perf_counter_reset,
  1175. 0664,
  1176. service_orangefs_show,
  1177. service_orangefs_store);
  1178. static struct orangefs_attribute perf_history_size_attribute =
  1179. __ATTR(perf_history_size,
  1180. 0664,
  1181. service_orangefs_show,
  1182. service_orangefs_store);
  1183. static struct orangefs_attribute perf_time_interval_secs_attribute =
  1184. __ATTR(perf_time_interval_secs,
  1185. 0664,
  1186. service_orangefs_show,
  1187. service_orangefs_store);
  1188. static struct attribute *orangefs_default_attrs[] = {
  1189. &op_timeout_secs_attribute.attr,
  1190. &slot_timeout_secs_attribute.attr,
  1191. &dcache_timeout_msecs_attribute.attr,
  1192. &getattr_timeout_msecs_attribute.attr,
  1193. &perf_counter_reset_attribute.attr,
  1194. &perf_history_size_attribute.attr,
  1195. &perf_time_interval_secs_attribute.attr,
  1196. NULL,
  1197. };
  1198. static struct kobj_type orangefs_ktype = {
  1199. .sysfs_ops = &orangefs_sysfs_ops,
  1200. .release = orangefs_release,
  1201. .default_attrs = orangefs_default_attrs,
  1202. };
  1203. static struct acache_orangefs_attribute acache_hard_limit_attribute =
  1204. __ATTR(hard_limit,
  1205. 0664,
  1206. service_acache_show,
  1207. service_acache_store);
  1208. static struct acache_orangefs_attribute acache_reclaim_percent_attribute =
  1209. __ATTR(reclaim_percentage,
  1210. 0664,
  1211. service_acache_show,
  1212. service_acache_store);
  1213. static struct acache_orangefs_attribute acache_soft_limit_attribute =
  1214. __ATTR(soft_limit,
  1215. 0664,
  1216. service_acache_show,
  1217. service_acache_store);
  1218. static struct acache_orangefs_attribute acache_timeout_msecs_attribute =
  1219. __ATTR(timeout_msecs,
  1220. 0664,
  1221. service_acache_show,
  1222. service_acache_store);
  1223. static struct attribute *acache_orangefs_default_attrs[] = {
  1224. &acache_hard_limit_attribute.attr,
  1225. &acache_reclaim_percent_attribute.attr,
  1226. &acache_soft_limit_attribute.attr,
  1227. &acache_timeout_msecs_attribute.attr,
  1228. NULL,
  1229. };
  1230. static struct kobj_type acache_orangefs_ktype = {
  1231. .sysfs_ops = &acache_orangefs_sysfs_ops,
  1232. .release = acache_orangefs_release,
  1233. .default_attrs = acache_orangefs_default_attrs,
  1234. };
  1235. static struct capcache_orangefs_attribute capcache_hard_limit_attribute =
  1236. __ATTR(hard_limit,
  1237. 0664,
  1238. service_capcache_show,
  1239. service_capcache_store);
  1240. static struct capcache_orangefs_attribute capcache_reclaim_percent_attribute =
  1241. __ATTR(reclaim_percentage,
  1242. 0664,
  1243. service_capcache_show,
  1244. service_capcache_store);
  1245. static struct capcache_orangefs_attribute capcache_soft_limit_attribute =
  1246. __ATTR(soft_limit,
  1247. 0664,
  1248. service_capcache_show,
  1249. service_capcache_store);
  1250. static struct capcache_orangefs_attribute capcache_timeout_secs_attribute =
  1251. __ATTR(timeout_secs,
  1252. 0664,
  1253. service_capcache_show,
  1254. service_capcache_store);
  1255. static struct attribute *capcache_orangefs_default_attrs[] = {
  1256. &capcache_hard_limit_attribute.attr,
  1257. &capcache_reclaim_percent_attribute.attr,
  1258. &capcache_soft_limit_attribute.attr,
  1259. &capcache_timeout_secs_attribute.attr,
  1260. NULL,
  1261. };
  1262. static struct kobj_type capcache_orangefs_ktype = {
  1263. .sysfs_ops = &capcache_orangefs_sysfs_ops,
  1264. .release = capcache_orangefs_release,
  1265. .default_attrs = capcache_orangefs_default_attrs,
  1266. };
  1267. static struct ccache_orangefs_attribute ccache_hard_limit_attribute =
  1268. __ATTR(hard_limit,
  1269. 0664,
  1270. service_ccache_show,
  1271. service_ccache_store);
  1272. static struct ccache_orangefs_attribute ccache_reclaim_percent_attribute =
  1273. __ATTR(reclaim_percentage,
  1274. 0664,
  1275. service_ccache_show,
  1276. service_ccache_store);
  1277. static struct ccache_orangefs_attribute ccache_soft_limit_attribute =
  1278. __ATTR(soft_limit,
  1279. 0664,
  1280. service_ccache_show,
  1281. service_ccache_store);
  1282. static struct ccache_orangefs_attribute ccache_timeout_secs_attribute =
  1283. __ATTR(timeout_secs,
  1284. 0664,
  1285. service_ccache_show,
  1286. service_ccache_store);
  1287. static struct attribute *ccache_orangefs_default_attrs[] = {
  1288. &ccache_hard_limit_attribute.attr,
  1289. &ccache_reclaim_percent_attribute.attr,
  1290. &ccache_soft_limit_attribute.attr,
  1291. &ccache_timeout_secs_attribute.attr,
  1292. NULL,
  1293. };
  1294. static struct kobj_type ccache_orangefs_ktype = {
  1295. .sysfs_ops = &ccache_orangefs_sysfs_ops,
  1296. .release = ccache_orangefs_release,
  1297. .default_attrs = ccache_orangefs_default_attrs,
  1298. };
  1299. static struct ncache_orangefs_attribute ncache_hard_limit_attribute =
  1300. __ATTR(hard_limit,
  1301. 0664,
  1302. service_ncache_show,
  1303. service_ncache_store);
  1304. static struct ncache_orangefs_attribute ncache_reclaim_percent_attribute =
  1305. __ATTR(reclaim_percentage,
  1306. 0664,
  1307. service_ncache_show,
  1308. service_ncache_store);
  1309. static struct ncache_orangefs_attribute ncache_soft_limit_attribute =
  1310. __ATTR(soft_limit,
  1311. 0664,
  1312. service_ncache_show,
  1313. service_ncache_store);
  1314. static struct ncache_orangefs_attribute ncache_timeout_msecs_attribute =
  1315. __ATTR(timeout_msecs,
  1316. 0664,
  1317. service_ncache_show,
  1318. service_ncache_store);
  1319. static struct attribute *ncache_orangefs_default_attrs[] = {
  1320. &ncache_hard_limit_attribute.attr,
  1321. &ncache_reclaim_percent_attribute.attr,
  1322. &ncache_soft_limit_attribute.attr,
  1323. &ncache_timeout_msecs_attribute.attr,
  1324. NULL,
  1325. };
  1326. static struct kobj_type ncache_orangefs_ktype = {
  1327. .sysfs_ops = &ncache_orangefs_sysfs_ops,
  1328. .release = ncache_orangefs_release,
  1329. .default_attrs = ncache_orangefs_default_attrs,
  1330. };
  1331. static struct pc_orangefs_attribute pc_acache_attribute =
  1332. __ATTR(acache,
  1333. 0664,
  1334. service_pc_show,
  1335. NULL);
  1336. static struct pc_orangefs_attribute pc_capcache_attribute =
  1337. __ATTR(capcache,
  1338. 0664,
  1339. service_pc_show,
  1340. NULL);
  1341. static struct pc_orangefs_attribute pc_ncache_attribute =
  1342. __ATTR(ncache,
  1343. 0664,
  1344. service_pc_show,
  1345. NULL);
  1346. static struct attribute *pc_orangefs_default_attrs[] = {
  1347. &pc_acache_attribute.attr,
  1348. &pc_capcache_attribute.attr,
  1349. &pc_ncache_attribute.attr,
  1350. NULL,
  1351. };
  1352. static struct kobj_type pc_orangefs_ktype = {
  1353. .sysfs_ops = &pc_orangefs_sysfs_ops,
  1354. .release = pc_orangefs_release,
  1355. .default_attrs = pc_orangefs_default_attrs,
  1356. };
  1357. static struct stats_orangefs_attribute stats_reads_attribute =
  1358. __ATTR(reads,
  1359. 0664,
  1360. int_stats_show,
  1361. NULL);
  1362. static struct stats_orangefs_attribute stats_writes_attribute =
  1363. __ATTR(writes,
  1364. 0664,
  1365. int_stats_show,
  1366. NULL);
  1367. static struct attribute *stats_orangefs_default_attrs[] = {
  1368. &stats_reads_attribute.attr,
  1369. &stats_writes_attribute.attr,
  1370. NULL,
  1371. };
  1372. static struct kobj_type stats_orangefs_ktype = {
  1373. .sysfs_ops = &stats_orangefs_sysfs_ops,
  1374. .release = stats_orangefs_release,
  1375. .default_attrs = stats_orangefs_default_attrs,
  1376. };
  1377. static struct orangefs_obj *orangefs_obj;
  1378. static struct acache_orangefs_obj *acache_orangefs_obj;
  1379. static struct capcache_orangefs_obj *capcache_orangefs_obj;
  1380. static struct ccache_orangefs_obj *ccache_orangefs_obj;
  1381. static struct ncache_orangefs_obj *ncache_orangefs_obj;
  1382. static struct pc_orangefs_obj *pc_orangefs_obj;
  1383. static struct stats_orangefs_obj *stats_orangefs_obj;
  1384. int orangefs_sysfs_init(void)
  1385. {
  1386. int rc = -EINVAL;
  1387. gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
  1388. /* create /sys/fs/orangefs. */
  1389. orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
  1390. if (!orangefs_obj)
  1391. goto out;
  1392. rc = kobject_init_and_add(&orangefs_obj->kobj,
  1393. &orangefs_ktype,
  1394. fs_kobj,
  1395. ORANGEFS_KOBJ_ID);
  1396. if (rc)
  1397. goto ofs_obj_bail;
  1398. kobject_uevent(&orangefs_obj->kobj, KOBJ_ADD);
  1399. /* create /sys/fs/orangefs/acache. */
  1400. acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
  1401. if (!acache_orangefs_obj) {
  1402. rc = -EINVAL;
  1403. goto ofs_obj_bail;
  1404. }
  1405. rc = kobject_init_and_add(&acache_orangefs_obj->kobj,
  1406. &acache_orangefs_ktype,
  1407. &orangefs_obj->kobj,
  1408. ACACHE_KOBJ_ID);
  1409. if (rc)
  1410. goto acache_obj_bail;
  1411. kobject_uevent(&acache_orangefs_obj->kobj, KOBJ_ADD);
  1412. /* create /sys/fs/orangefs/capcache. */
  1413. capcache_orangefs_obj =
  1414. kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
  1415. if (!capcache_orangefs_obj) {
  1416. rc = -EINVAL;
  1417. goto acache_obj_bail;
  1418. }
  1419. rc = kobject_init_and_add(&capcache_orangefs_obj->kobj,
  1420. &capcache_orangefs_ktype,
  1421. &orangefs_obj->kobj,
  1422. CAPCACHE_KOBJ_ID);
  1423. if (rc)
  1424. goto capcache_obj_bail;
  1425. kobject_uevent(&capcache_orangefs_obj->kobj, KOBJ_ADD);
  1426. /* create /sys/fs/orangefs/ccache. */
  1427. ccache_orangefs_obj =
  1428. kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
  1429. if (!ccache_orangefs_obj) {
  1430. rc = -EINVAL;
  1431. goto capcache_obj_bail;
  1432. }
  1433. rc = kobject_init_and_add(&ccache_orangefs_obj->kobj,
  1434. &ccache_orangefs_ktype,
  1435. &orangefs_obj->kobj,
  1436. CCACHE_KOBJ_ID);
  1437. if (rc)
  1438. goto ccache_obj_bail;
  1439. kobject_uevent(&ccache_orangefs_obj->kobj, KOBJ_ADD);
  1440. /* create /sys/fs/orangefs/ncache. */
  1441. ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
  1442. if (!ncache_orangefs_obj) {
  1443. rc = -EINVAL;
  1444. goto ccache_obj_bail;
  1445. }
  1446. rc = kobject_init_and_add(&ncache_orangefs_obj->kobj,
  1447. &ncache_orangefs_ktype,
  1448. &orangefs_obj->kobj,
  1449. NCACHE_KOBJ_ID);
  1450. if (rc)
  1451. goto ncache_obj_bail;
  1452. kobject_uevent(&ncache_orangefs_obj->kobj, KOBJ_ADD);
  1453. /* create /sys/fs/orangefs/perf_counters. */
  1454. pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
  1455. if (!pc_orangefs_obj) {
  1456. rc = -EINVAL;
  1457. goto ncache_obj_bail;
  1458. }
  1459. rc = kobject_init_and_add(&pc_orangefs_obj->kobj,
  1460. &pc_orangefs_ktype,
  1461. &orangefs_obj->kobj,
  1462. "perf_counters");
  1463. if (rc)
  1464. goto pc_obj_bail;
  1465. kobject_uevent(&pc_orangefs_obj->kobj, KOBJ_ADD);
  1466. /* create /sys/fs/orangefs/stats. */
  1467. stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
  1468. if (!stats_orangefs_obj) {
  1469. rc = -EINVAL;
  1470. goto pc_obj_bail;
  1471. }
  1472. rc = kobject_init_and_add(&stats_orangefs_obj->kobj,
  1473. &stats_orangefs_ktype,
  1474. &orangefs_obj->kobj,
  1475. STATS_KOBJ_ID);
  1476. if (rc)
  1477. goto stats_obj_bail;
  1478. kobject_uevent(&stats_orangefs_obj->kobj, KOBJ_ADD);
  1479. goto out;
  1480. stats_obj_bail:
  1481. kobject_put(&stats_orangefs_obj->kobj);
  1482. pc_obj_bail:
  1483. kobject_put(&pc_orangefs_obj->kobj);
  1484. ncache_obj_bail:
  1485. kobject_put(&ncache_orangefs_obj->kobj);
  1486. ccache_obj_bail:
  1487. kobject_put(&ccache_orangefs_obj->kobj);
  1488. capcache_obj_bail:
  1489. kobject_put(&capcache_orangefs_obj->kobj);
  1490. acache_obj_bail:
  1491. kobject_put(&acache_orangefs_obj->kobj);
  1492. ofs_obj_bail:
  1493. kobject_put(&orangefs_obj->kobj);
  1494. out:
  1495. return rc;
  1496. }
  1497. void orangefs_sysfs_exit(void)
  1498. {
  1499. gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
  1500. kobject_put(&acache_orangefs_obj->kobj);
  1501. kobject_put(&capcache_orangefs_obj->kobj);
  1502. kobject_put(&ccache_orangefs_obj->kobj);
  1503. kobject_put(&ncache_orangefs_obj->kobj);
  1504. kobject_put(&pc_orangefs_obj->kobj);
  1505. kobject_put(&stats_orangefs_obj->kobj);
  1506. kobject_put(&orangefs_obj->kobj);
  1507. }