target_core_stat.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. /*******************************************************************************
  2. * Filename: target_core_stat.c
  3. *
  4. * Modern ConfigFS group context specific statistics based on original
  5. * target_core_mib.c code
  6. *
  7. * (c) Copyright 2006-2013 Datera, Inc.
  8. *
  9. * Nicholas A. Bellinger <nab@linux-iscsi.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24. *
  25. ******************************************************************************/
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/delay.h>
  29. #include <linux/timer.h>
  30. #include <linux/string.h>
  31. #include <linux/utsname.h>
  32. #include <linux/proc_fs.h>
  33. #include <linux/seq_file.h>
  34. #include <linux/configfs.h>
  35. #include <target/target_core_base.h>
  36. #include <target/target_core_backend.h>
  37. #include <target/target_core_fabric.h>
  38. #include "target_core_internal.h"
  39. #ifndef INITIAL_JIFFIES
  40. #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
  41. #endif
  42. #define NONE "None"
  43. #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
  44. #define SCSI_LU_INDEX 1
  45. #define LU_COUNT 1
  46. /*
  47. * SCSI Device Table
  48. */
  49. static struct se_device *to_stat_dev(struct config_item *item)
  50. {
  51. struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
  52. struct se_dev_stat_grps, scsi_dev_group);
  53. return container_of(sgrps, struct se_device, dev_stat_grps);
  54. }
  55. static ssize_t target_stat_inst_show(struct config_item *item, char *page)
  56. {
  57. struct se_hba *hba = to_stat_dev(item)->se_hba;
  58. return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  59. }
  60. static ssize_t target_stat_indx_show(struct config_item *item, char *page)
  61. {
  62. return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->dev_index);
  63. }
  64. static ssize_t target_stat_role_show(struct config_item *item, char *page)
  65. {
  66. return snprintf(page, PAGE_SIZE, "Target\n");
  67. }
  68. static ssize_t target_stat_ports_show(struct config_item *item, char *page)
  69. {
  70. return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->export_count);
  71. }
  72. CONFIGFS_ATTR_RO(target_stat_, inst);
  73. CONFIGFS_ATTR_RO(target_stat_, indx);
  74. CONFIGFS_ATTR_RO(target_stat_, role);
  75. CONFIGFS_ATTR_RO(target_stat_, ports);
  76. static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
  77. &target_stat_attr_inst,
  78. &target_stat_attr_indx,
  79. &target_stat_attr_role,
  80. &target_stat_attr_ports,
  81. NULL,
  82. };
  83. static struct config_item_type target_stat_scsi_dev_cit = {
  84. .ct_attrs = target_stat_scsi_dev_attrs,
  85. .ct_owner = THIS_MODULE,
  86. };
  87. /*
  88. * SCSI Target Device Table
  89. */
  90. static struct se_device *to_stat_tgt_dev(struct config_item *item)
  91. {
  92. struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
  93. struct se_dev_stat_grps, scsi_tgt_dev_group);
  94. return container_of(sgrps, struct se_device, dev_stat_grps);
  95. }
  96. static ssize_t target_stat_tgt_inst_show(struct config_item *item, char *page)
  97. {
  98. struct se_hba *hba = to_stat_tgt_dev(item)->se_hba;
  99. return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  100. }
  101. static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page)
  102. {
  103. return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index);
  104. }
  105. static ssize_t target_stat_tgt_num_lus_show(struct config_item *item,
  106. char *page)
  107. {
  108. return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
  109. }
  110. static ssize_t target_stat_tgt_status_show(struct config_item *item,
  111. char *page)
  112. {
  113. if (to_stat_tgt_dev(item)->export_count)
  114. return snprintf(page, PAGE_SIZE, "activated");
  115. else
  116. return snprintf(page, PAGE_SIZE, "deactivated");
  117. }
  118. static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item,
  119. char *page)
  120. {
  121. int non_accessible_lus;
  122. if (to_stat_tgt_dev(item)->export_count)
  123. non_accessible_lus = 0;
  124. else
  125. non_accessible_lus = 1;
  126. return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
  127. }
  128. static ssize_t target_stat_tgt_resets_show(struct config_item *item,
  129. char *page)
  130. {
  131. return snprintf(page, PAGE_SIZE, "%lu\n",
  132. atomic_long_read(&to_stat_tgt_dev(item)->num_resets));
  133. }
  134. CONFIGFS_ATTR_RO(target_stat_tgt_, inst);
  135. CONFIGFS_ATTR_RO(target_stat_tgt_, indx);
  136. CONFIGFS_ATTR_RO(target_stat_tgt_, num_lus);
  137. CONFIGFS_ATTR_RO(target_stat_tgt_, status);
  138. CONFIGFS_ATTR_RO(target_stat_tgt_, non_access_lus);
  139. CONFIGFS_ATTR_RO(target_stat_tgt_, resets);
  140. static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
  141. &target_stat_tgt_attr_inst,
  142. &target_stat_tgt_attr_indx,
  143. &target_stat_tgt_attr_num_lus,
  144. &target_stat_tgt_attr_status,
  145. &target_stat_tgt_attr_non_access_lus,
  146. &target_stat_tgt_attr_resets,
  147. NULL,
  148. };
  149. static struct config_item_type target_stat_scsi_tgt_dev_cit = {
  150. .ct_attrs = target_stat_scsi_tgt_dev_attrs,
  151. .ct_owner = THIS_MODULE,
  152. };
  153. /*
  154. * SCSI Logical Unit Table
  155. */
  156. static struct se_device *to_stat_lu_dev(struct config_item *item)
  157. {
  158. struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
  159. struct se_dev_stat_grps, scsi_lu_group);
  160. return container_of(sgrps, struct se_device, dev_stat_grps);
  161. }
  162. static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page)
  163. {
  164. struct se_hba *hba = to_stat_lu_dev(item)->se_hba;
  165. return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  166. }
  167. static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page)
  168. {
  169. return snprintf(page, PAGE_SIZE, "%u\n",
  170. to_stat_lu_dev(item)->dev_index);
  171. }
  172. static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page)
  173. {
  174. return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
  175. }
  176. static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page)
  177. {
  178. /* FIXME: scsiLuDefaultLun */
  179. return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
  180. }
  181. static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page)
  182. {
  183. struct se_device *dev = to_stat_lu_dev(item);
  184. /* scsiLuWwnName */
  185. return snprintf(page, PAGE_SIZE, "%s\n",
  186. (strlen(dev->t10_wwn.unit_serial)) ?
  187. dev->t10_wwn.unit_serial : "None");
  188. }
  189. static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page)
  190. {
  191. struct se_device *dev = to_stat_lu_dev(item);
  192. int i;
  193. char str[sizeof(dev->t10_wwn.vendor)+1];
  194. /* scsiLuVendorId */
  195. for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++)
  196. str[i] = ISPRINT(dev->t10_wwn.vendor[i]) ?
  197. dev->t10_wwn.vendor[i] : ' ';
  198. str[i] = '\0';
  199. return snprintf(page, PAGE_SIZE, "%s\n", str);
  200. }
  201. static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page)
  202. {
  203. struct se_device *dev = to_stat_lu_dev(item);
  204. int i;
  205. char str[sizeof(dev->t10_wwn.model)+1];
  206. /* scsiLuProductId */
  207. for (i = 0; i < sizeof(dev->t10_wwn.model); i++)
  208. str[i] = ISPRINT(dev->t10_wwn.model[i]) ?
  209. dev->t10_wwn.model[i] : ' ';
  210. str[i] = '\0';
  211. return snprintf(page, PAGE_SIZE, "%s\n", str);
  212. }
  213. static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page)
  214. {
  215. struct se_device *dev = to_stat_lu_dev(item);
  216. int i;
  217. char str[sizeof(dev->t10_wwn.revision)+1];
  218. /* scsiLuRevisionId */
  219. for (i = 0; i < sizeof(dev->t10_wwn.revision); i++)
  220. str[i] = ISPRINT(dev->t10_wwn.revision[i]) ?
  221. dev->t10_wwn.revision[i] : ' ';
  222. str[i] = '\0';
  223. return snprintf(page, PAGE_SIZE, "%s\n", str);
  224. }
  225. static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page)
  226. {
  227. struct se_device *dev = to_stat_lu_dev(item);
  228. /* scsiLuPeripheralType */
  229. return snprintf(page, PAGE_SIZE, "%u\n",
  230. dev->transport->get_device_type(dev));
  231. }
  232. static ssize_t target_stat_lu_status_show(struct config_item *item, char *page)
  233. {
  234. struct se_device *dev = to_stat_lu_dev(item);
  235. /* scsiLuStatus */
  236. return snprintf(page, PAGE_SIZE, "%s\n",
  237. (dev->export_count) ? "available" : "notavailable");
  238. }
  239. static ssize_t target_stat_lu_state_bit_show(struct config_item *item,
  240. char *page)
  241. {
  242. /* scsiLuState */
  243. return snprintf(page, PAGE_SIZE, "exposed\n");
  244. }
  245. static ssize_t target_stat_lu_num_cmds_show(struct config_item *item,
  246. char *page)
  247. {
  248. struct se_device *dev = to_stat_lu_dev(item);
  249. /* scsiLuNumCommands */
  250. return snprintf(page, PAGE_SIZE, "%lu\n",
  251. atomic_long_read(&dev->num_cmds));
  252. }
  253. static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,
  254. char *page)
  255. {
  256. struct se_device *dev = to_stat_lu_dev(item);
  257. /* scsiLuReadMegaBytes */
  258. return snprintf(page, PAGE_SIZE, "%lu\n",
  259. atomic_long_read(&dev->read_bytes) >> 20);
  260. }
  261. static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,
  262. char *page)
  263. {
  264. struct se_device *dev = to_stat_lu_dev(item);
  265. /* scsiLuWrittenMegaBytes */
  266. return snprintf(page, PAGE_SIZE, "%lu\n",
  267. atomic_long_read(&dev->write_bytes) >> 20);
  268. }
  269. static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page)
  270. {
  271. struct se_device *dev = to_stat_lu_dev(item);
  272. /* scsiLuInResets */
  273. return snprintf(page, PAGE_SIZE, "%lu\n",
  274. atomic_long_read(&dev->num_resets));
  275. }
  276. static ssize_t target_stat_lu_full_stat_show(struct config_item *item,
  277. char *page)
  278. {
  279. /* FIXME: scsiLuOutTaskSetFullStatus */
  280. return snprintf(page, PAGE_SIZE, "%u\n", 0);
  281. }
  282. static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item,
  283. char *page)
  284. {
  285. /* FIXME: scsiLuHSInCommands */
  286. return snprintf(page, PAGE_SIZE, "%u\n", 0);
  287. }
  288. static ssize_t target_stat_lu_creation_time_show(struct config_item *item,
  289. char *page)
  290. {
  291. struct se_device *dev = to_stat_lu_dev(item);
  292. /* scsiLuCreationTime */
  293. return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
  294. INITIAL_JIFFIES) * 100 / HZ));
  295. }
  296. CONFIGFS_ATTR_RO(target_stat_lu_, inst);
  297. CONFIGFS_ATTR_RO(target_stat_lu_, dev);
  298. CONFIGFS_ATTR_RO(target_stat_lu_, indx);
  299. CONFIGFS_ATTR_RO(target_stat_lu_, lun);
  300. CONFIGFS_ATTR_RO(target_stat_lu_, lu_name);
  301. CONFIGFS_ATTR_RO(target_stat_lu_, vend);
  302. CONFIGFS_ATTR_RO(target_stat_lu_, prod);
  303. CONFIGFS_ATTR_RO(target_stat_lu_, rev);
  304. CONFIGFS_ATTR_RO(target_stat_lu_, dev_type);
  305. CONFIGFS_ATTR_RO(target_stat_lu_, status);
  306. CONFIGFS_ATTR_RO(target_stat_lu_, state_bit);
  307. CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds);
  308. CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes);
  309. CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes);
  310. CONFIGFS_ATTR_RO(target_stat_lu_, resets);
  311. CONFIGFS_ATTR_RO(target_stat_lu_, full_stat);
  312. CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds);
  313. CONFIGFS_ATTR_RO(target_stat_lu_, creation_time);
  314. static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
  315. &target_stat_lu_attr_inst,
  316. &target_stat_lu_attr_dev,
  317. &target_stat_lu_attr_indx,
  318. &target_stat_lu_attr_lun,
  319. &target_stat_lu_attr_lu_name,
  320. &target_stat_lu_attr_vend,
  321. &target_stat_lu_attr_prod,
  322. &target_stat_lu_attr_rev,
  323. &target_stat_lu_attr_dev_type,
  324. &target_stat_lu_attr_status,
  325. &target_stat_lu_attr_state_bit,
  326. &target_stat_lu_attr_num_cmds,
  327. &target_stat_lu_attr_read_mbytes,
  328. &target_stat_lu_attr_write_mbytes,
  329. &target_stat_lu_attr_resets,
  330. &target_stat_lu_attr_full_stat,
  331. &target_stat_lu_attr_hs_num_cmds,
  332. &target_stat_lu_attr_creation_time,
  333. NULL,
  334. };
  335. static struct config_item_type target_stat_scsi_lu_cit = {
  336. .ct_attrs = target_stat_scsi_lu_attrs,
  337. .ct_owner = THIS_MODULE,
  338. };
  339. /*
  340. * Called from target_core_configfs.c:target_core_make_subdev() to setup
  341. * the target statistics groups + configfs CITs located in target_core_stat.c
  342. */
  343. void target_stat_setup_dev_default_groups(struct se_device *dev)
  344. {
  345. config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
  346. "scsi_dev", &target_stat_scsi_dev_cit);
  347. configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group,
  348. &dev->dev_stat_grps.stat_group);
  349. config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
  350. "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
  351. configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group,
  352. &dev->dev_stat_grps.stat_group);
  353. config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
  354. "scsi_lu", &target_stat_scsi_lu_cit);
  355. configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group,
  356. &dev->dev_stat_grps.stat_group);
  357. }
  358. /*
  359. * SCSI Port Table
  360. */
  361. static struct se_lun *to_stat_port(struct config_item *item)
  362. {
  363. struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
  364. struct se_port_stat_grps, scsi_port_group);
  365. return container_of(pgrps, struct se_lun, port_stat_grps);
  366. }
  367. static ssize_t target_stat_port_inst_show(struct config_item *item, char *page)
  368. {
  369. struct se_lun *lun = to_stat_port(item);
  370. struct se_device *dev;
  371. ssize_t ret = -ENODEV;
  372. rcu_read_lock();
  373. dev = rcu_dereference(lun->lun_se_dev);
  374. if (dev)
  375. ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
  376. rcu_read_unlock();
  377. return ret;
  378. }
  379. static ssize_t target_stat_port_dev_show(struct config_item *item, char *page)
  380. {
  381. struct se_lun *lun = to_stat_port(item);
  382. struct se_device *dev;
  383. ssize_t ret = -ENODEV;
  384. rcu_read_lock();
  385. dev = rcu_dereference(lun->lun_se_dev);
  386. if (dev)
  387. ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
  388. rcu_read_unlock();
  389. return ret;
  390. }
  391. static ssize_t target_stat_port_indx_show(struct config_item *item, char *page)
  392. {
  393. struct se_lun *lun = to_stat_port(item);
  394. struct se_device *dev;
  395. ssize_t ret = -ENODEV;
  396. rcu_read_lock();
  397. dev = rcu_dereference(lun->lun_se_dev);
  398. if (dev)
  399. ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
  400. rcu_read_unlock();
  401. return ret;
  402. }
  403. static ssize_t target_stat_port_role_show(struct config_item *item, char *page)
  404. {
  405. struct se_lun *lun = to_stat_port(item);
  406. struct se_device *dev;
  407. ssize_t ret = -ENODEV;
  408. rcu_read_lock();
  409. dev = rcu_dereference(lun->lun_se_dev);
  410. if (dev)
  411. ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
  412. rcu_read_unlock();
  413. return ret;
  414. }
  415. static ssize_t target_stat_port_busy_count_show(struct config_item *item,
  416. char *page)
  417. {
  418. struct se_lun *lun = to_stat_port(item);
  419. struct se_device *dev;
  420. ssize_t ret = -ENODEV;
  421. rcu_read_lock();
  422. dev = rcu_dereference(lun->lun_se_dev);
  423. if (dev) {
  424. /* FIXME: scsiPortBusyStatuses */
  425. ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
  426. }
  427. rcu_read_unlock();
  428. return ret;
  429. }
  430. CONFIGFS_ATTR_RO(target_stat_port_, inst);
  431. CONFIGFS_ATTR_RO(target_stat_port_, dev);
  432. CONFIGFS_ATTR_RO(target_stat_port_, indx);
  433. CONFIGFS_ATTR_RO(target_stat_port_, role);
  434. CONFIGFS_ATTR_RO(target_stat_port_, busy_count);
  435. static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
  436. &target_stat_port_attr_inst,
  437. &target_stat_port_attr_dev,
  438. &target_stat_port_attr_indx,
  439. &target_stat_port_attr_role,
  440. &target_stat_port_attr_busy_count,
  441. NULL,
  442. };
  443. static struct config_item_type target_stat_scsi_port_cit = {
  444. .ct_attrs = target_stat_scsi_port_attrs,
  445. .ct_owner = THIS_MODULE,
  446. };
  447. /*
  448. * SCSI Target Port Table
  449. */
  450. static struct se_lun *to_stat_tgt_port(struct config_item *item)
  451. {
  452. struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
  453. struct se_port_stat_grps, scsi_tgt_port_group);
  454. return container_of(pgrps, struct se_lun, port_stat_grps);
  455. }
  456. static ssize_t target_stat_tgt_port_inst_show(struct config_item *item,
  457. char *page)
  458. {
  459. struct se_lun *lun = to_stat_tgt_port(item);
  460. struct se_device *dev;
  461. ssize_t ret = -ENODEV;
  462. rcu_read_lock();
  463. dev = rcu_dereference(lun->lun_se_dev);
  464. if (dev)
  465. ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
  466. rcu_read_unlock();
  467. return ret;
  468. }
  469. static ssize_t target_stat_tgt_port_dev_show(struct config_item *item,
  470. char *page)
  471. {
  472. struct se_lun *lun = to_stat_tgt_port(item);
  473. struct se_device *dev;
  474. ssize_t ret = -ENODEV;
  475. rcu_read_lock();
  476. dev = rcu_dereference(lun->lun_se_dev);
  477. if (dev)
  478. ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
  479. rcu_read_unlock();
  480. return ret;
  481. }
  482. static ssize_t target_stat_tgt_port_indx_show(struct config_item *item,
  483. char *page)
  484. {
  485. struct se_lun *lun = to_stat_tgt_port(item);
  486. struct se_device *dev;
  487. ssize_t ret = -ENODEV;
  488. rcu_read_lock();
  489. dev = rcu_dereference(lun->lun_se_dev);
  490. if (dev)
  491. ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
  492. rcu_read_unlock();
  493. return ret;
  494. }
  495. static ssize_t target_stat_tgt_port_name_show(struct config_item *item,
  496. char *page)
  497. {
  498. struct se_lun *lun = to_stat_tgt_port(item);
  499. struct se_portal_group *tpg = lun->lun_tpg;
  500. struct se_device *dev;
  501. ssize_t ret = -ENODEV;
  502. rcu_read_lock();
  503. dev = rcu_dereference(lun->lun_se_dev);
  504. if (dev)
  505. ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
  506. tpg->se_tpg_tfo->get_fabric_name(),
  507. lun->lun_rtpi);
  508. rcu_read_unlock();
  509. return ret;
  510. }
  511. static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item,
  512. char *page)
  513. {
  514. struct se_lun *lun = to_stat_tgt_port(item);
  515. struct se_portal_group *tpg = lun->lun_tpg;
  516. struct se_device *dev;
  517. ssize_t ret = -ENODEV;
  518. rcu_read_lock();
  519. dev = rcu_dereference(lun->lun_se_dev);
  520. if (dev)
  521. ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
  522. tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
  523. tpg->se_tpg_tfo->tpg_get_tag(tpg));
  524. rcu_read_unlock();
  525. return ret;
  526. }
  527. static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item,
  528. char *page)
  529. {
  530. struct se_lun *lun = to_stat_tgt_port(item);
  531. struct se_device *dev;
  532. ssize_t ret = -ENODEV;
  533. rcu_read_lock();
  534. dev = rcu_dereference(lun->lun_se_dev);
  535. if (dev)
  536. ret = snprintf(page, PAGE_SIZE, "%lu\n",
  537. atomic_long_read(&lun->lun_stats.cmd_pdus));
  538. rcu_read_unlock();
  539. return ret;
  540. }
  541. static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item,
  542. char *page)
  543. {
  544. struct se_lun *lun = to_stat_tgt_port(item);
  545. struct se_device *dev;
  546. ssize_t ret = -ENODEV;
  547. rcu_read_lock();
  548. dev = rcu_dereference(lun->lun_se_dev);
  549. if (dev)
  550. ret = snprintf(page, PAGE_SIZE, "%u\n",
  551. (u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20));
  552. rcu_read_unlock();
  553. return ret;
  554. }
  555. static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item,
  556. char *page)
  557. {
  558. struct se_lun *lun = to_stat_tgt_port(item);
  559. struct se_device *dev;
  560. ssize_t ret = -ENODEV;
  561. rcu_read_lock();
  562. dev = rcu_dereference(lun->lun_se_dev);
  563. if (dev)
  564. ret = snprintf(page, PAGE_SIZE, "%u\n",
  565. (u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20));
  566. rcu_read_unlock();
  567. return ret;
  568. }
  569. static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
  570. char *page)
  571. {
  572. struct se_lun *lun = to_stat_tgt_port(item);
  573. struct se_device *dev;
  574. ssize_t ret = -ENODEV;
  575. rcu_read_lock();
  576. dev = rcu_dereference(lun->lun_se_dev);
  577. if (dev) {
  578. /* FIXME: scsiTgtPortHsInCommands */
  579. ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
  580. }
  581. rcu_read_unlock();
  582. return ret;
  583. }
  584. CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst);
  585. CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev);
  586. CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx);
  587. CONFIGFS_ATTR_RO(target_stat_tgt_port_, name);
  588. CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index);
  589. CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds);
  590. CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes);
  591. CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes);
  592. CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds);
  593. static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
  594. &target_stat_tgt_port_attr_inst,
  595. &target_stat_tgt_port_attr_dev,
  596. &target_stat_tgt_port_attr_indx,
  597. &target_stat_tgt_port_attr_name,
  598. &target_stat_tgt_port_attr_port_index,
  599. &target_stat_tgt_port_attr_in_cmds,
  600. &target_stat_tgt_port_attr_write_mbytes,
  601. &target_stat_tgt_port_attr_read_mbytes,
  602. &target_stat_tgt_port_attr_hs_in_cmds,
  603. NULL,
  604. };
  605. static struct config_item_type target_stat_scsi_tgt_port_cit = {
  606. .ct_attrs = target_stat_scsi_tgt_port_attrs,
  607. .ct_owner = THIS_MODULE,
  608. };
  609. /*
  610. * SCSI Transport Table
  611. */
  612. static struct se_lun *to_transport_stat(struct config_item *item)
  613. {
  614. struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
  615. struct se_port_stat_grps, scsi_transport_group);
  616. return container_of(pgrps, struct se_lun, port_stat_grps);
  617. }
  618. static ssize_t target_stat_transport_inst_show(struct config_item *item,
  619. char *page)
  620. {
  621. struct se_lun *lun = to_transport_stat(item);
  622. struct se_device *dev;
  623. ssize_t ret = -ENODEV;
  624. rcu_read_lock();
  625. dev = rcu_dereference(lun->lun_se_dev);
  626. if (dev)
  627. ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
  628. rcu_read_unlock();
  629. return ret;
  630. }
  631. static ssize_t target_stat_transport_device_show(struct config_item *item,
  632. char *page)
  633. {
  634. struct se_lun *lun = to_transport_stat(item);
  635. struct se_device *dev;
  636. struct se_portal_group *tpg = lun->lun_tpg;
  637. ssize_t ret = -ENODEV;
  638. rcu_read_lock();
  639. dev = rcu_dereference(lun->lun_se_dev);
  640. if (dev) {
  641. /* scsiTransportType */
  642. ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
  643. tpg->se_tpg_tfo->get_fabric_name());
  644. }
  645. rcu_read_unlock();
  646. return ret;
  647. }
  648. static ssize_t target_stat_transport_indx_show(struct config_item *item,
  649. char *page)
  650. {
  651. struct se_lun *lun = to_transport_stat(item);
  652. struct se_device *dev;
  653. struct se_portal_group *tpg = lun->lun_tpg;
  654. ssize_t ret = -ENODEV;
  655. rcu_read_lock();
  656. dev = rcu_dereference(lun->lun_se_dev);
  657. if (dev)
  658. ret = snprintf(page, PAGE_SIZE, "%u\n",
  659. tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
  660. rcu_read_unlock();
  661. return ret;
  662. }
  663. static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
  664. char *page)
  665. {
  666. struct se_lun *lun = to_transport_stat(item);
  667. struct se_device *dev;
  668. struct se_portal_group *tpg = lun->lun_tpg;
  669. struct t10_wwn *wwn;
  670. ssize_t ret = -ENODEV;
  671. rcu_read_lock();
  672. dev = rcu_dereference(lun->lun_se_dev);
  673. if (dev) {
  674. wwn = &dev->t10_wwn;
  675. /* scsiTransportDevName */
  676. ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
  677. tpg->se_tpg_tfo->tpg_get_wwn(tpg),
  678. (strlen(wwn->unit_serial)) ? wwn->unit_serial :
  679. wwn->vendor);
  680. }
  681. rcu_read_unlock();
  682. return ret;
  683. }
  684. CONFIGFS_ATTR_RO(target_stat_transport_, inst);
  685. CONFIGFS_ATTR_RO(target_stat_transport_, device);
  686. CONFIGFS_ATTR_RO(target_stat_transport_, indx);
  687. CONFIGFS_ATTR_RO(target_stat_transport_, dev_name);
  688. static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
  689. &target_stat_transport_attr_inst,
  690. &target_stat_transport_attr_device,
  691. &target_stat_transport_attr_indx,
  692. &target_stat_transport_attr_dev_name,
  693. NULL,
  694. };
  695. static struct config_item_type target_stat_scsi_transport_cit = {
  696. .ct_attrs = target_stat_scsi_transport_attrs,
  697. .ct_owner = THIS_MODULE,
  698. };
  699. /*
  700. * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
  701. * the target port statistics groups + configfs CITs located in target_core_stat.c
  702. */
  703. void target_stat_setup_port_default_groups(struct se_lun *lun)
  704. {
  705. config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
  706. "scsi_port", &target_stat_scsi_port_cit);
  707. configfs_add_default_group(&lun->port_stat_grps.scsi_port_group,
  708. &lun->port_stat_grps.stat_group);
  709. config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
  710. "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
  711. configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group,
  712. &lun->port_stat_grps.stat_group);
  713. config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
  714. "scsi_transport", &target_stat_scsi_transport_cit);
  715. configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group,
  716. &lun->port_stat_grps.stat_group);
  717. }
  718. /*
  719. * SCSI Authorized Initiator Table
  720. */
  721. static struct se_lun_acl *auth_to_lacl(struct config_item *item)
  722. {
  723. struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
  724. struct se_ml_stat_grps, scsi_auth_intr_group);
  725. return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
  726. }
  727. static ssize_t target_stat_auth_inst_show(struct config_item *item,
  728. char *page)
  729. {
  730. struct se_lun_acl *lacl = auth_to_lacl(item);
  731. struct se_node_acl *nacl = lacl->se_lun_nacl;
  732. struct se_dev_entry *deve;
  733. struct se_portal_group *tpg;
  734. ssize_t ret;
  735. rcu_read_lock();
  736. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  737. if (!deve) {
  738. rcu_read_unlock();
  739. return -ENODEV;
  740. }
  741. tpg = nacl->se_tpg;
  742. /* scsiInstIndex */
  743. ret = snprintf(page, PAGE_SIZE, "%u\n",
  744. tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
  745. rcu_read_unlock();
  746. return ret;
  747. }
  748. static ssize_t target_stat_auth_dev_show(struct config_item *item,
  749. char *page)
  750. {
  751. struct se_lun_acl *lacl = auth_to_lacl(item);
  752. struct se_node_acl *nacl = lacl->se_lun_nacl;
  753. struct se_dev_entry *deve;
  754. struct se_lun *lun;
  755. ssize_t ret;
  756. rcu_read_lock();
  757. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  758. if (!deve) {
  759. rcu_read_unlock();
  760. return -ENODEV;
  761. }
  762. lun = rcu_dereference(deve->se_lun);
  763. /* scsiDeviceIndex */
  764. ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
  765. rcu_read_unlock();
  766. return ret;
  767. }
  768. static ssize_t target_stat_auth_port_show(struct config_item *item,
  769. char *page)
  770. {
  771. struct se_lun_acl *lacl = auth_to_lacl(item);
  772. struct se_node_acl *nacl = lacl->se_lun_nacl;
  773. struct se_dev_entry *deve;
  774. struct se_portal_group *tpg;
  775. ssize_t ret;
  776. rcu_read_lock();
  777. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  778. if (!deve) {
  779. rcu_read_unlock();
  780. return -ENODEV;
  781. }
  782. tpg = nacl->se_tpg;
  783. /* scsiAuthIntrTgtPortIndex */
  784. ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
  785. rcu_read_unlock();
  786. return ret;
  787. }
  788. static ssize_t target_stat_auth_indx_show(struct config_item *item,
  789. char *page)
  790. {
  791. struct se_lun_acl *lacl = auth_to_lacl(item);
  792. struct se_node_acl *nacl = lacl->se_lun_nacl;
  793. struct se_dev_entry *deve;
  794. ssize_t ret;
  795. rcu_read_lock();
  796. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  797. if (!deve) {
  798. rcu_read_unlock();
  799. return -ENODEV;
  800. }
  801. /* scsiAuthIntrIndex */
  802. ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
  803. rcu_read_unlock();
  804. return ret;
  805. }
  806. static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item,
  807. char *page)
  808. {
  809. struct se_lun_acl *lacl = auth_to_lacl(item);
  810. struct se_node_acl *nacl = lacl->se_lun_nacl;
  811. struct se_dev_entry *deve;
  812. ssize_t ret;
  813. rcu_read_lock();
  814. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  815. if (!deve) {
  816. rcu_read_unlock();
  817. return -ENODEV;
  818. }
  819. /* scsiAuthIntrDevOrPort */
  820. ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
  821. rcu_read_unlock();
  822. return ret;
  823. }
  824. static ssize_t target_stat_auth_intr_name_show(struct config_item *item,
  825. char *page)
  826. {
  827. struct se_lun_acl *lacl = auth_to_lacl(item);
  828. struct se_node_acl *nacl = lacl->se_lun_nacl;
  829. struct se_dev_entry *deve;
  830. ssize_t ret;
  831. rcu_read_lock();
  832. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  833. if (!deve) {
  834. rcu_read_unlock();
  835. return -ENODEV;
  836. }
  837. /* scsiAuthIntrName */
  838. ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
  839. rcu_read_unlock();
  840. return ret;
  841. }
  842. static ssize_t target_stat_auth_map_indx_show(struct config_item *item,
  843. char *page)
  844. {
  845. struct se_lun_acl *lacl = auth_to_lacl(item);
  846. struct se_node_acl *nacl = lacl->se_lun_nacl;
  847. struct se_dev_entry *deve;
  848. ssize_t ret;
  849. rcu_read_lock();
  850. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  851. if (!deve) {
  852. rcu_read_unlock();
  853. return -ENODEV;
  854. }
  855. /* FIXME: scsiAuthIntrLunMapIndex */
  856. ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
  857. rcu_read_unlock();
  858. return ret;
  859. }
  860. static ssize_t target_stat_auth_att_count_show(struct config_item *item,
  861. char *page)
  862. {
  863. struct se_lun_acl *lacl = auth_to_lacl(item);
  864. struct se_node_acl *nacl = lacl->se_lun_nacl;
  865. struct se_dev_entry *deve;
  866. ssize_t ret;
  867. rcu_read_lock();
  868. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  869. if (!deve) {
  870. rcu_read_unlock();
  871. return -ENODEV;
  872. }
  873. /* scsiAuthIntrAttachedTimes */
  874. ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
  875. rcu_read_unlock();
  876. return ret;
  877. }
  878. static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,
  879. char *page)
  880. {
  881. struct se_lun_acl *lacl = auth_to_lacl(item);
  882. struct se_node_acl *nacl = lacl->se_lun_nacl;
  883. struct se_dev_entry *deve;
  884. ssize_t ret;
  885. rcu_read_lock();
  886. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  887. if (!deve) {
  888. rcu_read_unlock();
  889. return -ENODEV;
  890. }
  891. /* scsiAuthIntrOutCommands */
  892. ret = snprintf(page, PAGE_SIZE, "%lu\n",
  893. atomic_long_read(&deve->total_cmds));
  894. rcu_read_unlock();
  895. return ret;
  896. }
  897. static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,
  898. char *page)
  899. {
  900. struct se_lun_acl *lacl = auth_to_lacl(item);
  901. struct se_node_acl *nacl = lacl->se_lun_nacl;
  902. struct se_dev_entry *deve;
  903. ssize_t ret;
  904. rcu_read_lock();
  905. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  906. if (!deve) {
  907. rcu_read_unlock();
  908. return -ENODEV;
  909. }
  910. /* scsiAuthIntrReadMegaBytes */
  911. ret = snprintf(page, PAGE_SIZE, "%u\n",
  912. (u32)(atomic_long_read(&deve->read_bytes) >> 20));
  913. rcu_read_unlock();
  914. return ret;
  915. }
  916. static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,
  917. char *page)
  918. {
  919. struct se_lun_acl *lacl = auth_to_lacl(item);
  920. struct se_node_acl *nacl = lacl->se_lun_nacl;
  921. struct se_dev_entry *deve;
  922. ssize_t ret;
  923. rcu_read_lock();
  924. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  925. if (!deve) {
  926. rcu_read_unlock();
  927. return -ENODEV;
  928. }
  929. /* scsiAuthIntrWrittenMegaBytes */
  930. ret = snprintf(page, PAGE_SIZE, "%u\n",
  931. (u32)(atomic_long_read(&deve->write_bytes) >> 20));
  932. rcu_read_unlock();
  933. return ret;
  934. }
  935. static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item,
  936. char *page)
  937. {
  938. struct se_lun_acl *lacl = auth_to_lacl(item);
  939. struct se_node_acl *nacl = lacl->se_lun_nacl;
  940. struct se_dev_entry *deve;
  941. ssize_t ret;
  942. rcu_read_lock();
  943. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  944. if (!deve) {
  945. rcu_read_unlock();
  946. return -ENODEV;
  947. }
  948. /* FIXME: scsiAuthIntrHSOutCommands */
  949. ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
  950. rcu_read_unlock();
  951. return ret;
  952. }
  953. static ssize_t target_stat_auth_creation_time_show(struct config_item *item,
  954. char *page)
  955. {
  956. struct se_lun_acl *lacl = auth_to_lacl(item);
  957. struct se_node_acl *nacl = lacl->se_lun_nacl;
  958. struct se_dev_entry *deve;
  959. ssize_t ret;
  960. rcu_read_lock();
  961. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  962. if (!deve) {
  963. rcu_read_unlock();
  964. return -ENODEV;
  965. }
  966. /* scsiAuthIntrLastCreation */
  967. ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
  968. INITIAL_JIFFIES) * 100 / HZ));
  969. rcu_read_unlock();
  970. return ret;
  971. }
  972. static ssize_t target_stat_auth_row_status_show(struct config_item *item,
  973. char *page)
  974. {
  975. struct se_lun_acl *lacl = auth_to_lacl(item);
  976. struct se_node_acl *nacl = lacl->se_lun_nacl;
  977. struct se_dev_entry *deve;
  978. ssize_t ret;
  979. rcu_read_lock();
  980. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  981. if (!deve) {
  982. rcu_read_unlock();
  983. return -ENODEV;
  984. }
  985. /* FIXME: scsiAuthIntrRowStatus */
  986. ret = snprintf(page, PAGE_SIZE, "Ready\n");
  987. rcu_read_unlock();
  988. return ret;
  989. }
  990. CONFIGFS_ATTR_RO(target_stat_auth_, inst);
  991. CONFIGFS_ATTR_RO(target_stat_auth_, dev);
  992. CONFIGFS_ATTR_RO(target_stat_auth_, port);
  993. CONFIGFS_ATTR_RO(target_stat_auth_, indx);
  994. CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port);
  995. CONFIGFS_ATTR_RO(target_stat_auth_, intr_name);
  996. CONFIGFS_ATTR_RO(target_stat_auth_, map_indx);
  997. CONFIGFS_ATTR_RO(target_stat_auth_, att_count);
  998. CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds);
  999. CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes);
  1000. CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes);
  1001. CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds);
  1002. CONFIGFS_ATTR_RO(target_stat_auth_, creation_time);
  1003. CONFIGFS_ATTR_RO(target_stat_auth_, row_status);
  1004. static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
  1005. &target_stat_auth_attr_inst,
  1006. &target_stat_auth_attr_dev,
  1007. &target_stat_auth_attr_port,
  1008. &target_stat_auth_attr_indx,
  1009. &target_stat_auth_attr_dev_or_port,
  1010. &target_stat_auth_attr_intr_name,
  1011. &target_stat_auth_attr_map_indx,
  1012. &target_stat_auth_attr_att_count,
  1013. &target_stat_auth_attr_num_cmds,
  1014. &target_stat_auth_attr_read_mbytes,
  1015. &target_stat_auth_attr_write_mbytes,
  1016. &target_stat_auth_attr_hs_num_cmds,
  1017. &target_stat_auth_attr_creation_time,
  1018. &target_stat_auth_attr_row_status,
  1019. NULL,
  1020. };
  1021. static struct config_item_type target_stat_scsi_auth_intr_cit = {
  1022. .ct_attrs = target_stat_scsi_auth_intr_attrs,
  1023. .ct_owner = THIS_MODULE,
  1024. };
  1025. /*
  1026. * SCSI Attached Initiator Port Table
  1027. */
  1028. static struct se_lun_acl *iport_to_lacl(struct config_item *item)
  1029. {
  1030. struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
  1031. struct se_ml_stat_grps, scsi_att_intr_port_group);
  1032. return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
  1033. }
  1034. static ssize_t target_stat_iport_inst_show(struct config_item *item,
  1035. char *page)
  1036. {
  1037. struct se_lun_acl *lacl = iport_to_lacl(item);
  1038. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1039. struct se_dev_entry *deve;
  1040. struct se_portal_group *tpg;
  1041. ssize_t ret;
  1042. rcu_read_lock();
  1043. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  1044. if (!deve) {
  1045. rcu_read_unlock();
  1046. return -ENODEV;
  1047. }
  1048. tpg = nacl->se_tpg;
  1049. /* scsiInstIndex */
  1050. ret = snprintf(page, PAGE_SIZE, "%u\n",
  1051. tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
  1052. rcu_read_unlock();
  1053. return ret;
  1054. }
  1055. static ssize_t target_stat_iport_dev_show(struct config_item *item,
  1056. char *page)
  1057. {
  1058. struct se_lun_acl *lacl = iport_to_lacl(item);
  1059. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1060. struct se_dev_entry *deve;
  1061. struct se_lun *lun;
  1062. ssize_t ret;
  1063. rcu_read_lock();
  1064. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  1065. if (!deve) {
  1066. rcu_read_unlock();
  1067. return -ENODEV;
  1068. }
  1069. lun = rcu_dereference(deve->se_lun);
  1070. /* scsiDeviceIndex */
  1071. ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
  1072. rcu_read_unlock();
  1073. return ret;
  1074. }
  1075. static ssize_t target_stat_iport_port_show(struct config_item *item,
  1076. char *page)
  1077. {
  1078. struct se_lun_acl *lacl = iport_to_lacl(item);
  1079. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1080. struct se_dev_entry *deve;
  1081. struct se_portal_group *tpg;
  1082. ssize_t ret;
  1083. rcu_read_lock();
  1084. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  1085. if (!deve) {
  1086. rcu_read_unlock();
  1087. return -ENODEV;
  1088. }
  1089. tpg = nacl->se_tpg;
  1090. /* scsiPortIndex */
  1091. ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
  1092. rcu_read_unlock();
  1093. return ret;
  1094. }
  1095. static ssize_t target_stat_iport_indx_show(struct config_item *item,
  1096. char *page)
  1097. {
  1098. struct se_lun_acl *lacl = iport_to_lacl(item);
  1099. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1100. struct se_session *se_sess;
  1101. struct se_portal_group *tpg;
  1102. ssize_t ret;
  1103. spin_lock_irq(&nacl->nacl_sess_lock);
  1104. se_sess = nacl->nacl_sess;
  1105. if (!se_sess) {
  1106. spin_unlock_irq(&nacl->nacl_sess_lock);
  1107. return -ENODEV;
  1108. }
  1109. tpg = nacl->se_tpg;
  1110. /* scsiAttIntrPortIndex */
  1111. ret = snprintf(page, PAGE_SIZE, "%u\n",
  1112. tpg->se_tpg_tfo->sess_get_index(se_sess));
  1113. spin_unlock_irq(&nacl->nacl_sess_lock);
  1114. return ret;
  1115. }
  1116. static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item,
  1117. char *page)
  1118. {
  1119. struct se_lun_acl *lacl = iport_to_lacl(item);
  1120. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1121. struct se_dev_entry *deve;
  1122. ssize_t ret;
  1123. rcu_read_lock();
  1124. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  1125. if (!deve) {
  1126. rcu_read_unlock();
  1127. return -ENODEV;
  1128. }
  1129. /* scsiAttIntrPortAuthIntrIdx */
  1130. ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
  1131. rcu_read_unlock();
  1132. return ret;
  1133. }
  1134. static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
  1135. char *page)
  1136. {
  1137. struct se_lun_acl *lacl = iport_to_lacl(item);
  1138. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1139. struct se_session *se_sess;
  1140. struct se_portal_group *tpg;
  1141. ssize_t ret;
  1142. unsigned char buf[64];
  1143. spin_lock_irq(&nacl->nacl_sess_lock);
  1144. se_sess = nacl->nacl_sess;
  1145. if (!se_sess) {
  1146. spin_unlock_irq(&nacl->nacl_sess_lock);
  1147. return -ENODEV;
  1148. }
  1149. tpg = nacl->se_tpg;
  1150. /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
  1151. memset(buf, 0, 64);
  1152. if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
  1153. tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
  1154. ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
  1155. spin_unlock_irq(&nacl->nacl_sess_lock);
  1156. return ret;
  1157. }
  1158. CONFIGFS_ATTR_RO(target_stat_iport_, inst);
  1159. CONFIGFS_ATTR_RO(target_stat_iport_, dev);
  1160. CONFIGFS_ATTR_RO(target_stat_iport_, port);
  1161. CONFIGFS_ATTR_RO(target_stat_iport_, indx);
  1162. CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx);
  1163. CONFIGFS_ATTR_RO(target_stat_iport_, port_ident);
  1164. static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
  1165. &target_stat_iport_attr_inst,
  1166. &target_stat_iport_attr_dev,
  1167. &target_stat_iport_attr_port,
  1168. &target_stat_iport_attr_indx,
  1169. &target_stat_iport_attr_port_auth_indx,
  1170. &target_stat_iport_attr_port_ident,
  1171. NULL,
  1172. };
  1173. static struct config_item_type target_stat_scsi_att_intr_port_cit = {
  1174. .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
  1175. .ct_owner = THIS_MODULE,
  1176. };
  1177. /*
  1178. * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
  1179. * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
  1180. */
  1181. void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
  1182. {
  1183. config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
  1184. "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
  1185. configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group,
  1186. &lacl->ml_stat_grps.stat_group);
  1187. config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
  1188. "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
  1189. configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group,
  1190. &lacl->ml_stat_grps.stat_group);
  1191. }