target_core_stat.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795
  1. /*******************************************************************************
  2. * Filename: target_core_stat.c
  3. *
  4. * Copyright (c) 2011 Rising Tide Systems
  5. * Copyright (c) 2011 Linux-iSCSI.org
  6. *
  7. * Modern ConfigFS group context specific statistics based on original
  8. * target_core_mib.c code
  9. *
  10. * Copyright (c) 2006-2007 SBE, Inc. All Rights Reserved.
  11. *
  12. * Nicholas A. Bellinger <nab@linux-iscsi.org>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. *
  28. ******************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/delay.h>
  32. #include <linux/timer.h>
  33. #include <linux/string.h>
  34. #include <generated/utsrelease.h>
  35. #include <linux/utsname.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/seq_file.h>
  38. #include <linux/blkdev.h>
  39. #include <linux/configfs.h>
  40. #include <scsi/scsi.h>
  41. #include <scsi/scsi_device.h>
  42. #include <scsi/scsi_host.h>
  43. #include <target/target_core_base.h>
  44. #include <target/target_core_backend.h>
  45. #include <target/target_core_fabric.h>
  46. #include <target/target_core_configfs.h>
  47. #include <target/configfs_macros.h>
  48. #include "target_core_internal.h"
  49. #ifndef INITIAL_JIFFIES
  50. #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
  51. #endif
  52. #define NONE "None"
  53. #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
  54. #define SCSI_LU_INDEX 1
  55. #define LU_COUNT 1
  56. /*
  57. * SCSI Device Table
  58. */
  59. CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev, se_dev_stat_grps);
  60. #define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \
  61. static struct target_stat_scsi_dev_attribute \
  62. target_stat_scsi_dev_##_name = \
  63. __CONFIGFS_EATTR(_name, _mode, \
  64. target_stat_scsi_dev_show_attr_##_name, \
  65. target_stat_scsi_dev_store_attr_##_name);
  66. #define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
  67. static struct target_stat_scsi_dev_attribute \
  68. target_stat_scsi_dev_##_name = \
  69. __CONFIGFS_EATTR_RO(_name, \
  70. target_stat_scsi_dev_show_attr_##_name);
  71. static ssize_t target_stat_scsi_dev_show_attr_inst(
  72. struct se_dev_stat_grps *sgrps, char *page)
  73. {
  74. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  75. struct se_subsystem_dev, dev_stat_grps);
  76. struct se_hba *hba = se_subdev->se_dev_hba;
  77. struct se_device *dev = se_subdev->se_dev_ptr;
  78. if (!dev)
  79. return -ENODEV;
  80. return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  81. }
  82. DEV_STAT_SCSI_DEV_ATTR_RO(inst);
  83. static ssize_t target_stat_scsi_dev_show_attr_indx(
  84. struct se_dev_stat_grps *sgrps, char *page)
  85. {
  86. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  87. struct se_subsystem_dev, dev_stat_grps);
  88. struct se_device *dev = se_subdev->se_dev_ptr;
  89. if (!dev)
  90. return -ENODEV;
  91. return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
  92. }
  93. DEV_STAT_SCSI_DEV_ATTR_RO(indx);
  94. static ssize_t target_stat_scsi_dev_show_attr_role(
  95. struct se_dev_stat_grps *sgrps, char *page)
  96. {
  97. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  98. struct se_subsystem_dev, dev_stat_grps);
  99. struct se_device *dev = se_subdev->se_dev_ptr;
  100. if (!dev)
  101. return -ENODEV;
  102. return snprintf(page, PAGE_SIZE, "Target\n");
  103. }
  104. DEV_STAT_SCSI_DEV_ATTR_RO(role);
  105. static ssize_t target_stat_scsi_dev_show_attr_ports(
  106. struct se_dev_stat_grps *sgrps, char *page)
  107. {
  108. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  109. struct se_subsystem_dev, dev_stat_grps);
  110. struct se_device *dev = se_subdev->se_dev_ptr;
  111. if (!dev)
  112. return -ENODEV;
  113. return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_port_count);
  114. }
  115. DEV_STAT_SCSI_DEV_ATTR_RO(ports);
  116. CONFIGFS_EATTR_OPS(target_stat_scsi_dev, se_dev_stat_grps, scsi_dev_group);
  117. static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
  118. &target_stat_scsi_dev_inst.attr,
  119. &target_stat_scsi_dev_indx.attr,
  120. &target_stat_scsi_dev_role.attr,
  121. &target_stat_scsi_dev_ports.attr,
  122. NULL,
  123. };
  124. static struct configfs_item_operations target_stat_scsi_dev_attrib_ops = {
  125. .show_attribute = target_stat_scsi_dev_attr_show,
  126. .store_attribute = target_stat_scsi_dev_attr_store,
  127. };
  128. static struct config_item_type target_stat_scsi_dev_cit = {
  129. .ct_item_ops = &target_stat_scsi_dev_attrib_ops,
  130. .ct_attrs = target_stat_scsi_dev_attrs,
  131. .ct_owner = THIS_MODULE,
  132. };
  133. /*
  134. * SCSI Target Device Table
  135. */
  136. CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev, se_dev_stat_grps);
  137. #define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
  138. static struct target_stat_scsi_tgt_dev_attribute \
  139. target_stat_scsi_tgt_dev_##_name = \
  140. __CONFIGFS_EATTR(_name, _mode, \
  141. target_stat_scsi_tgt_dev_show_attr_##_name, \
  142. target_stat_scsi_tgt_dev_store_attr_##_name);
  143. #define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
  144. static struct target_stat_scsi_tgt_dev_attribute \
  145. target_stat_scsi_tgt_dev_##_name = \
  146. __CONFIGFS_EATTR_RO(_name, \
  147. target_stat_scsi_tgt_dev_show_attr_##_name);
  148. static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
  149. struct se_dev_stat_grps *sgrps, char *page)
  150. {
  151. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  152. struct se_subsystem_dev, dev_stat_grps);
  153. struct se_hba *hba = se_subdev->se_dev_hba;
  154. struct se_device *dev = se_subdev->se_dev_ptr;
  155. if (!dev)
  156. return -ENODEV;
  157. return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  158. }
  159. DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst);
  160. static ssize_t target_stat_scsi_tgt_dev_show_attr_indx(
  161. struct se_dev_stat_grps *sgrps, char *page)
  162. {
  163. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  164. struct se_subsystem_dev, dev_stat_grps);
  165. struct se_device *dev = se_subdev->se_dev_ptr;
  166. if (!dev)
  167. return -ENODEV;
  168. return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
  169. }
  170. DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx);
  171. static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus(
  172. struct se_dev_stat_grps *sgrps, char *page)
  173. {
  174. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  175. struct se_subsystem_dev, dev_stat_grps);
  176. struct se_device *dev = se_subdev->se_dev_ptr;
  177. if (!dev)
  178. return -ENODEV;
  179. return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
  180. }
  181. DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus);
  182. static ssize_t target_stat_scsi_tgt_dev_show_attr_status(
  183. struct se_dev_stat_grps *sgrps, char *page)
  184. {
  185. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  186. struct se_subsystem_dev, dev_stat_grps);
  187. struct se_device *dev = se_subdev->se_dev_ptr;
  188. char status[16];
  189. if (!dev)
  190. return -ENODEV;
  191. switch (dev->dev_status) {
  192. case TRANSPORT_DEVICE_ACTIVATED:
  193. strcpy(status, "activated");
  194. break;
  195. case TRANSPORT_DEVICE_DEACTIVATED:
  196. strcpy(status, "deactivated");
  197. break;
  198. case TRANSPORT_DEVICE_SHUTDOWN:
  199. strcpy(status, "shutdown");
  200. break;
  201. case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
  202. case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
  203. strcpy(status, "offline");
  204. break;
  205. default:
  206. sprintf(status, "unknown(%d)", dev->dev_status);
  207. break;
  208. }
  209. return snprintf(page, PAGE_SIZE, "%s\n", status);
  210. }
  211. DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status);
  212. static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus(
  213. struct se_dev_stat_grps *sgrps, char *page)
  214. {
  215. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  216. struct se_subsystem_dev, dev_stat_grps);
  217. struct se_device *dev = se_subdev->se_dev_ptr;
  218. int non_accessible_lus;
  219. if (!dev)
  220. return -ENODEV;
  221. switch (dev->dev_status) {
  222. case TRANSPORT_DEVICE_ACTIVATED:
  223. non_accessible_lus = 0;
  224. break;
  225. case TRANSPORT_DEVICE_DEACTIVATED:
  226. case TRANSPORT_DEVICE_SHUTDOWN:
  227. case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
  228. case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
  229. default:
  230. non_accessible_lus = 1;
  231. break;
  232. }
  233. return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
  234. }
  235. DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus);
  236. static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
  237. struct se_dev_stat_grps *sgrps, char *page)
  238. {
  239. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  240. struct se_subsystem_dev, dev_stat_grps);
  241. struct se_device *dev = se_subdev->se_dev_ptr;
  242. if (!dev)
  243. return -ENODEV;
  244. return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
  245. }
  246. DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets);
  247. CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev, se_dev_stat_grps, scsi_tgt_dev_group);
  248. static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
  249. &target_stat_scsi_tgt_dev_inst.attr,
  250. &target_stat_scsi_tgt_dev_indx.attr,
  251. &target_stat_scsi_tgt_dev_num_lus.attr,
  252. &target_stat_scsi_tgt_dev_status.attr,
  253. &target_stat_scsi_tgt_dev_non_access_lus.attr,
  254. &target_stat_scsi_tgt_dev_resets.attr,
  255. NULL,
  256. };
  257. static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops = {
  258. .show_attribute = target_stat_scsi_tgt_dev_attr_show,
  259. .store_attribute = target_stat_scsi_tgt_dev_attr_store,
  260. };
  261. static struct config_item_type target_stat_scsi_tgt_dev_cit = {
  262. .ct_item_ops = &target_stat_scsi_tgt_dev_attrib_ops,
  263. .ct_attrs = target_stat_scsi_tgt_dev_attrs,
  264. .ct_owner = THIS_MODULE,
  265. };
  266. /*
  267. * SCSI Logical Unit Table
  268. */
  269. CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu, se_dev_stat_grps);
  270. #define DEV_STAT_SCSI_LU_ATTR(_name, _mode) \
  271. static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
  272. __CONFIGFS_EATTR(_name, _mode, \
  273. target_stat_scsi_lu_show_attr_##_name, \
  274. target_stat_scsi_lu_store_attr_##_name);
  275. #define DEV_STAT_SCSI_LU_ATTR_RO(_name) \
  276. static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
  277. __CONFIGFS_EATTR_RO(_name, \
  278. target_stat_scsi_lu_show_attr_##_name);
  279. static ssize_t target_stat_scsi_lu_show_attr_inst(
  280. struct se_dev_stat_grps *sgrps, char *page)
  281. {
  282. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  283. struct se_subsystem_dev, dev_stat_grps);
  284. struct se_hba *hba = se_subdev->se_dev_hba;
  285. struct se_device *dev = se_subdev->se_dev_ptr;
  286. if (!dev)
  287. return -ENODEV;
  288. return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  289. }
  290. DEV_STAT_SCSI_LU_ATTR_RO(inst);
  291. static ssize_t target_stat_scsi_lu_show_attr_dev(
  292. struct se_dev_stat_grps *sgrps, char *page)
  293. {
  294. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  295. struct se_subsystem_dev, dev_stat_grps);
  296. struct se_device *dev = se_subdev->se_dev_ptr;
  297. if (!dev)
  298. return -ENODEV;
  299. return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
  300. }
  301. DEV_STAT_SCSI_LU_ATTR_RO(dev);
  302. static ssize_t target_stat_scsi_lu_show_attr_indx(
  303. struct se_dev_stat_grps *sgrps, char *page)
  304. {
  305. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  306. struct se_subsystem_dev, dev_stat_grps);
  307. struct se_device *dev = se_subdev->se_dev_ptr;
  308. if (!dev)
  309. return -ENODEV;
  310. return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
  311. }
  312. DEV_STAT_SCSI_LU_ATTR_RO(indx);
  313. static ssize_t target_stat_scsi_lu_show_attr_lun(
  314. struct se_dev_stat_grps *sgrps, char *page)
  315. {
  316. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  317. struct se_subsystem_dev, dev_stat_grps);
  318. struct se_device *dev = se_subdev->se_dev_ptr;
  319. if (!dev)
  320. return -ENODEV;
  321. /* FIXME: scsiLuDefaultLun */
  322. return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
  323. }
  324. DEV_STAT_SCSI_LU_ATTR_RO(lun);
  325. static ssize_t target_stat_scsi_lu_show_attr_lu_name(
  326. struct se_dev_stat_grps *sgrps, char *page)
  327. {
  328. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  329. struct se_subsystem_dev, dev_stat_grps);
  330. struct se_device *dev = se_subdev->se_dev_ptr;
  331. if (!dev)
  332. return -ENODEV;
  333. /* scsiLuWwnName */
  334. return snprintf(page, PAGE_SIZE, "%s\n",
  335. (strlen(dev->se_sub_dev->t10_wwn.unit_serial)) ?
  336. dev->se_sub_dev->t10_wwn.unit_serial : "None");
  337. }
  338. DEV_STAT_SCSI_LU_ATTR_RO(lu_name);
  339. static ssize_t target_stat_scsi_lu_show_attr_vend(
  340. struct se_dev_stat_grps *sgrps, char *page)
  341. {
  342. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  343. struct se_subsystem_dev, dev_stat_grps);
  344. struct se_device *dev = se_subdev->se_dev_ptr;
  345. int i;
  346. char str[sizeof(dev->se_sub_dev->t10_wwn.vendor)+1];
  347. if (!dev)
  348. return -ENODEV;
  349. /* scsiLuVendorId */
  350. for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.vendor); i++)
  351. str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.vendor[i]) ?
  352. dev->se_sub_dev->t10_wwn.vendor[i] : ' ';
  353. str[i] = '\0';
  354. return snprintf(page, PAGE_SIZE, "%s\n", str);
  355. }
  356. DEV_STAT_SCSI_LU_ATTR_RO(vend);
  357. static ssize_t target_stat_scsi_lu_show_attr_prod(
  358. struct se_dev_stat_grps *sgrps, char *page)
  359. {
  360. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  361. struct se_subsystem_dev, dev_stat_grps);
  362. struct se_device *dev = se_subdev->se_dev_ptr;
  363. int i;
  364. char str[sizeof(dev->se_sub_dev->t10_wwn.model)+1];
  365. if (!dev)
  366. return -ENODEV;
  367. /* scsiLuProductId */
  368. for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.vendor); i++)
  369. str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.model[i]) ?
  370. dev->se_sub_dev->t10_wwn.model[i] : ' ';
  371. str[i] = '\0';
  372. return snprintf(page, PAGE_SIZE, "%s\n", str);
  373. }
  374. DEV_STAT_SCSI_LU_ATTR_RO(prod);
  375. static ssize_t target_stat_scsi_lu_show_attr_rev(
  376. struct se_dev_stat_grps *sgrps, char *page)
  377. {
  378. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  379. struct se_subsystem_dev, dev_stat_grps);
  380. struct se_device *dev = se_subdev->se_dev_ptr;
  381. int i;
  382. char str[sizeof(dev->se_sub_dev->t10_wwn.revision)+1];
  383. if (!dev)
  384. return -ENODEV;
  385. /* scsiLuRevisionId */
  386. for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.revision); i++)
  387. str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.revision[i]) ?
  388. dev->se_sub_dev->t10_wwn.revision[i] : ' ';
  389. str[i] = '\0';
  390. return snprintf(page, PAGE_SIZE, "%s\n", str);
  391. }
  392. DEV_STAT_SCSI_LU_ATTR_RO(rev);
  393. static ssize_t target_stat_scsi_lu_show_attr_dev_type(
  394. struct se_dev_stat_grps *sgrps, char *page)
  395. {
  396. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  397. struct se_subsystem_dev, dev_stat_grps);
  398. struct se_device *dev = se_subdev->se_dev_ptr;
  399. if (!dev)
  400. return -ENODEV;
  401. /* scsiLuPeripheralType */
  402. return snprintf(page, PAGE_SIZE, "%u\n",
  403. dev->transport->get_device_type(dev));
  404. }
  405. DEV_STAT_SCSI_LU_ATTR_RO(dev_type);
  406. static ssize_t target_stat_scsi_lu_show_attr_status(
  407. struct se_dev_stat_grps *sgrps, char *page)
  408. {
  409. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  410. struct se_subsystem_dev, dev_stat_grps);
  411. struct se_device *dev = se_subdev->se_dev_ptr;
  412. if (!dev)
  413. return -ENODEV;
  414. /* scsiLuStatus */
  415. return snprintf(page, PAGE_SIZE, "%s\n",
  416. (dev->dev_status == TRANSPORT_DEVICE_ACTIVATED) ?
  417. "available" : "notavailable");
  418. }
  419. DEV_STAT_SCSI_LU_ATTR_RO(status);
  420. static ssize_t target_stat_scsi_lu_show_attr_state_bit(
  421. struct se_dev_stat_grps *sgrps, char *page)
  422. {
  423. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  424. struct se_subsystem_dev, dev_stat_grps);
  425. struct se_device *dev = se_subdev->se_dev_ptr;
  426. if (!dev)
  427. return -ENODEV;
  428. /* scsiLuState */
  429. return snprintf(page, PAGE_SIZE, "exposed\n");
  430. }
  431. DEV_STAT_SCSI_LU_ATTR_RO(state_bit);
  432. static ssize_t target_stat_scsi_lu_show_attr_num_cmds(
  433. struct se_dev_stat_grps *sgrps, char *page)
  434. {
  435. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  436. struct se_subsystem_dev, dev_stat_grps);
  437. struct se_device *dev = se_subdev->se_dev_ptr;
  438. if (!dev)
  439. return -ENODEV;
  440. /* scsiLuNumCommands */
  441. return snprintf(page, PAGE_SIZE, "%llu\n",
  442. (unsigned long long)dev->num_cmds);
  443. }
  444. DEV_STAT_SCSI_LU_ATTR_RO(num_cmds);
  445. static ssize_t target_stat_scsi_lu_show_attr_read_mbytes(
  446. struct se_dev_stat_grps *sgrps, char *page)
  447. {
  448. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  449. struct se_subsystem_dev, dev_stat_grps);
  450. struct se_device *dev = se_subdev->se_dev_ptr;
  451. if (!dev)
  452. return -ENODEV;
  453. /* scsiLuReadMegaBytes */
  454. return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->read_bytes >> 20));
  455. }
  456. DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);
  457. static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
  458. struct se_dev_stat_grps *sgrps, char *page)
  459. {
  460. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  461. struct se_subsystem_dev, dev_stat_grps);
  462. struct se_device *dev = se_subdev->se_dev_ptr;
  463. if (!dev)
  464. return -ENODEV;
  465. /* scsiLuWrittenMegaBytes */
  466. return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->write_bytes >> 20));
  467. }
  468. DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);
  469. static ssize_t target_stat_scsi_lu_show_attr_resets(
  470. struct se_dev_stat_grps *sgrps, char *page)
  471. {
  472. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  473. struct se_subsystem_dev, dev_stat_grps);
  474. struct se_device *dev = se_subdev->se_dev_ptr;
  475. if (!dev)
  476. return -ENODEV;
  477. /* scsiLuInResets */
  478. return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
  479. }
  480. DEV_STAT_SCSI_LU_ATTR_RO(resets);
  481. static ssize_t target_stat_scsi_lu_show_attr_full_stat(
  482. struct se_dev_stat_grps *sgrps, char *page)
  483. {
  484. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  485. struct se_subsystem_dev, dev_stat_grps);
  486. struct se_device *dev = se_subdev->se_dev_ptr;
  487. if (!dev)
  488. return -ENODEV;
  489. /* FIXME: scsiLuOutTaskSetFullStatus */
  490. return snprintf(page, PAGE_SIZE, "%u\n", 0);
  491. }
  492. DEV_STAT_SCSI_LU_ATTR_RO(full_stat);
  493. static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds(
  494. struct se_dev_stat_grps *sgrps, char *page)
  495. {
  496. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  497. struct se_subsystem_dev, dev_stat_grps);
  498. struct se_device *dev = se_subdev->se_dev_ptr;
  499. if (!dev)
  500. return -ENODEV;
  501. /* FIXME: scsiLuHSInCommands */
  502. return snprintf(page, PAGE_SIZE, "%u\n", 0);
  503. }
  504. DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds);
  505. static ssize_t target_stat_scsi_lu_show_attr_creation_time(
  506. struct se_dev_stat_grps *sgrps, char *page)
  507. {
  508. struct se_subsystem_dev *se_subdev = container_of(sgrps,
  509. struct se_subsystem_dev, dev_stat_grps);
  510. struct se_device *dev = se_subdev->se_dev_ptr;
  511. if (!dev)
  512. return -ENODEV;
  513. /* scsiLuCreationTime */
  514. return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
  515. INITIAL_JIFFIES) * 100 / HZ));
  516. }
  517. DEV_STAT_SCSI_LU_ATTR_RO(creation_time);
  518. CONFIGFS_EATTR_OPS(target_stat_scsi_lu, se_dev_stat_grps, scsi_lu_group);
  519. static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
  520. &target_stat_scsi_lu_inst.attr,
  521. &target_stat_scsi_lu_dev.attr,
  522. &target_stat_scsi_lu_indx.attr,
  523. &target_stat_scsi_lu_lun.attr,
  524. &target_stat_scsi_lu_lu_name.attr,
  525. &target_stat_scsi_lu_vend.attr,
  526. &target_stat_scsi_lu_prod.attr,
  527. &target_stat_scsi_lu_rev.attr,
  528. &target_stat_scsi_lu_dev_type.attr,
  529. &target_stat_scsi_lu_status.attr,
  530. &target_stat_scsi_lu_state_bit.attr,
  531. &target_stat_scsi_lu_num_cmds.attr,
  532. &target_stat_scsi_lu_read_mbytes.attr,
  533. &target_stat_scsi_lu_write_mbytes.attr,
  534. &target_stat_scsi_lu_resets.attr,
  535. &target_stat_scsi_lu_full_stat.attr,
  536. &target_stat_scsi_lu_hs_num_cmds.attr,
  537. &target_stat_scsi_lu_creation_time.attr,
  538. NULL,
  539. };
  540. static struct configfs_item_operations target_stat_scsi_lu_attrib_ops = {
  541. .show_attribute = target_stat_scsi_lu_attr_show,
  542. .store_attribute = target_stat_scsi_lu_attr_store,
  543. };
  544. static struct config_item_type target_stat_scsi_lu_cit = {
  545. .ct_item_ops = &target_stat_scsi_lu_attrib_ops,
  546. .ct_attrs = target_stat_scsi_lu_attrs,
  547. .ct_owner = THIS_MODULE,
  548. };
  549. /*
  550. * Called from target_core_configfs.c:target_core_make_subdev() to setup
  551. * the target statistics groups + configfs CITs located in target_core_stat.c
  552. */
  553. void target_stat_setup_dev_default_groups(struct se_subsystem_dev *se_subdev)
  554. {
  555. struct config_group *dev_stat_grp = &se_subdev->dev_stat_grps.stat_group;
  556. config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_dev_group,
  557. "scsi_dev", &target_stat_scsi_dev_cit);
  558. config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_tgt_dev_group,
  559. "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
  560. config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_lu_group,
  561. "scsi_lu", &target_stat_scsi_lu_cit);
  562. dev_stat_grp->default_groups[0] = &se_subdev->dev_stat_grps.scsi_dev_group;
  563. dev_stat_grp->default_groups[1] = &se_subdev->dev_stat_grps.scsi_tgt_dev_group;
  564. dev_stat_grp->default_groups[2] = &se_subdev->dev_stat_grps.scsi_lu_group;
  565. dev_stat_grp->default_groups[3] = NULL;
  566. }
  567. /*
  568. * SCSI Port Table
  569. */
  570. CONFIGFS_EATTR_STRUCT(target_stat_scsi_port, se_port_stat_grps);
  571. #define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \
  572. static struct target_stat_scsi_port_attribute \
  573. target_stat_scsi_port_##_name = \
  574. __CONFIGFS_EATTR(_name, _mode, \
  575. target_stat_scsi_port_show_attr_##_name, \
  576. target_stat_scsi_port_store_attr_##_name);
  577. #define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
  578. static struct target_stat_scsi_port_attribute \
  579. target_stat_scsi_port_##_name = \
  580. __CONFIGFS_EATTR_RO(_name, \
  581. target_stat_scsi_port_show_attr_##_name);
  582. static ssize_t target_stat_scsi_port_show_attr_inst(
  583. struct se_port_stat_grps *pgrps, char *page)
  584. {
  585. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  586. struct se_port *sep;
  587. struct se_device *dev = lun->lun_se_dev;
  588. struct se_hba *hba;
  589. ssize_t ret;
  590. spin_lock(&lun->lun_sep_lock);
  591. sep = lun->lun_sep;
  592. if (!sep) {
  593. spin_unlock(&lun->lun_sep_lock);
  594. return -ENODEV;
  595. }
  596. hba = dev->se_hba;
  597. ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  598. spin_unlock(&lun->lun_sep_lock);
  599. return ret;
  600. }
  601. DEV_STAT_SCSI_PORT_ATTR_RO(inst);
  602. static ssize_t target_stat_scsi_port_show_attr_dev(
  603. struct se_port_stat_grps *pgrps, char *page)
  604. {
  605. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  606. struct se_port *sep;
  607. struct se_device *dev = lun->lun_se_dev;
  608. ssize_t ret;
  609. spin_lock(&lun->lun_sep_lock);
  610. sep = lun->lun_sep;
  611. if (!sep) {
  612. spin_unlock(&lun->lun_sep_lock);
  613. return -ENODEV;
  614. }
  615. ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
  616. spin_unlock(&lun->lun_sep_lock);
  617. return ret;
  618. }
  619. DEV_STAT_SCSI_PORT_ATTR_RO(dev);
  620. static ssize_t target_stat_scsi_port_show_attr_indx(
  621. struct se_port_stat_grps *pgrps, char *page)
  622. {
  623. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  624. struct se_port *sep;
  625. ssize_t ret;
  626. spin_lock(&lun->lun_sep_lock);
  627. sep = lun->lun_sep;
  628. if (!sep) {
  629. spin_unlock(&lun->lun_sep_lock);
  630. return -ENODEV;
  631. }
  632. ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
  633. spin_unlock(&lun->lun_sep_lock);
  634. return ret;
  635. }
  636. DEV_STAT_SCSI_PORT_ATTR_RO(indx);
  637. static ssize_t target_stat_scsi_port_show_attr_role(
  638. struct se_port_stat_grps *pgrps, char *page)
  639. {
  640. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  641. struct se_device *dev = lun->lun_se_dev;
  642. struct se_port *sep;
  643. ssize_t ret;
  644. if (!dev)
  645. return -ENODEV;
  646. spin_lock(&lun->lun_sep_lock);
  647. sep = lun->lun_sep;
  648. if (!sep) {
  649. spin_unlock(&lun->lun_sep_lock);
  650. return -ENODEV;
  651. }
  652. ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
  653. spin_unlock(&lun->lun_sep_lock);
  654. return ret;
  655. }
  656. DEV_STAT_SCSI_PORT_ATTR_RO(role);
  657. static ssize_t target_stat_scsi_port_show_attr_busy_count(
  658. struct se_port_stat_grps *pgrps, char *page)
  659. {
  660. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  661. struct se_port *sep;
  662. ssize_t ret;
  663. spin_lock(&lun->lun_sep_lock);
  664. sep = lun->lun_sep;
  665. if (!sep) {
  666. spin_unlock(&lun->lun_sep_lock);
  667. return -ENODEV;
  668. }
  669. /* FIXME: scsiPortBusyStatuses */
  670. ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
  671. spin_unlock(&lun->lun_sep_lock);
  672. return ret;
  673. }
  674. DEV_STAT_SCSI_PORT_ATTR_RO(busy_count);
  675. CONFIGFS_EATTR_OPS(target_stat_scsi_port, se_port_stat_grps, scsi_port_group);
  676. static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
  677. &target_stat_scsi_port_inst.attr,
  678. &target_stat_scsi_port_dev.attr,
  679. &target_stat_scsi_port_indx.attr,
  680. &target_stat_scsi_port_role.attr,
  681. &target_stat_scsi_port_busy_count.attr,
  682. NULL,
  683. };
  684. static struct configfs_item_operations target_stat_scsi_port_attrib_ops = {
  685. .show_attribute = target_stat_scsi_port_attr_show,
  686. .store_attribute = target_stat_scsi_port_attr_store,
  687. };
  688. static struct config_item_type target_stat_scsi_port_cit = {
  689. .ct_item_ops = &target_stat_scsi_port_attrib_ops,
  690. .ct_attrs = target_stat_scsi_port_attrs,
  691. .ct_owner = THIS_MODULE,
  692. };
  693. /*
  694. * SCSI Target Port Table
  695. */
  696. CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port, se_port_stat_grps);
  697. #define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \
  698. static struct target_stat_scsi_tgt_port_attribute \
  699. target_stat_scsi_tgt_port_##_name = \
  700. __CONFIGFS_EATTR(_name, _mode, \
  701. target_stat_scsi_tgt_port_show_attr_##_name, \
  702. target_stat_scsi_tgt_port_store_attr_##_name);
  703. #define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \
  704. static struct target_stat_scsi_tgt_port_attribute \
  705. target_stat_scsi_tgt_port_##_name = \
  706. __CONFIGFS_EATTR_RO(_name, \
  707. target_stat_scsi_tgt_port_show_attr_##_name);
  708. static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
  709. struct se_port_stat_grps *pgrps, char *page)
  710. {
  711. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  712. struct se_device *dev = lun->lun_se_dev;
  713. struct se_port *sep;
  714. struct se_hba *hba;
  715. ssize_t ret;
  716. spin_lock(&lun->lun_sep_lock);
  717. sep = lun->lun_sep;
  718. if (!sep) {
  719. spin_unlock(&lun->lun_sep_lock);
  720. return -ENODEV;
  721. }
  722. hba = dev->se_hba;
  723. ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  724. spin_unlock(&lun->lun_sep_lock);
  725. return ret;
  726. }
  727. DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst);
  728. static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
  729. struct se_port_stat_grps *pgrps, char *page)
  730. {
  731. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  732. struct se_device *dev = lun->lun_se_dev;
  733. struct se_port *sep;
  734. ssize_t ret;
  735. spin_lock(&lun->lun_sep_lock);
  736. sep = lun->lun_sep;
  737. if (!sep) {
  738. spin_unlock(&lun->lun_sep_lock);
  739. return -ENODEV;
  740. }
  741. ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
  742. spin_unlock(&lun->lun_sep_lock);
  743. return ret;
  744. }
  745. DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev);
  746. static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
  747. struct se_port_stat_grps *pgrps, char *page)
  748. {
  749. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  750. struct se_port *sep;
  751. ssize_t ret;
  752. spin_lock(&lun->lun_sep_lock);
  753. sep = lun->lun_sep;
  754. if (!sep) {
  755. spin_unlock(&lun->lun_sep_lock);
  756. return -ENODEV;
  757. }
  758. ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
  759. spin_unlock(&lun->lun_sep_lock);
  760. return ret;
  761. }
  762. DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx);
  763. static ssize_t target_stat_scsi_tgt_port_show_attr_name(
  764. struct se_port_stat_grps *pgrps, char *page)
  765. {
  766. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  767. struct se_port *sep;
  768. struct se_portal_group *tpg;
  769. ssize_t ret;
  770. spin_lock(&lun->lun_sep_lock);
  771. sep = lun->lun_sep;
  772. if (!sep) {
  773. spin_unlock(&lun->lun_sep_lock);
  774. return -ENODEV;
  775. }
  776. tpg = sep->sep_tpg;
  777. ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
  778. tpg->se_tpg_tfo->get_fabric_name(), sep->sep_index);
  779. spin_unlock(&lun->lun_sep_lock);
  780. return ret;
  781. }
  782. DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name);
  783. static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
  784. struct se_port_stat_grps *pgrps, char *page)
  785. {
  786. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  787. struct se_port *sep;
  788. struct se_portal_group *tpg;
  789. ssize_t ret;
  790. spin_lock(&lun->lun_sep_lock);
  791. sep = lun->lun_sep;
  792. if (!sep) {
  793. spin_unlock(&lun->lun_sep_lock);
  794. return -ENODEV;
  795. }
  796. tpg = sep->sep_tpg;
  797. ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
  798. tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
  799. tpg->se_tpg_tfo->tpg_get_tag(tpg));
  800. spin_unlock(&lun->lun_sep_lock);
  801. return ret;
  802. }
  803. DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index);
  804. static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
  805. struct se_port_stat_grps *pgrps, char *page)
  806. {
  807. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  808. struct se_port *sep;
  809. ssize_t ret;
  810. spin_lock(&lun->lun_sep_lock);
  811. sep = lun->lun_sep;
  812. if (!sep) {
  813. spin_unlock(&lun->lun_sep_lock);
  814. return -ENODEV;
  815. }
  816. ret = snprintf(page, PAGE_SIZE, "%llu\n", sep->sep_stats.cmd_pdus);
  817. spin_unlock(&lun->lun_sep_lock);
  818. return ret;
  819. }
  820. DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds);
  821. static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
  822. struct se_port_stat_grps *pgrps, char *page)
  823. {
  824. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  825. struct se_port *sep;
  826. ssize_t ret;
  827. spin_lock(&lun->lun_sep_lock);
  828. sep = lun->lun_sep;
  829. if (!sep) {
  830. spin_unlock(&lun->lun_sep_lock);
  831. return -ENODEV;
  832. }
  833. ret = snprintf(page, PAGE_SIZE, "%u\n",
  834. (u32)(sep->sep_stats.rx_data_octets >> 20));
  835. spin_unlock(&lun->lun_sep_lock);
  836. return ret;
  837. }
  838. DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes);
  839. static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
  840. struct se_port_stat_grps *pgrps, char *page)
  841. {
  842. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  843. struct se_port *sep;
  844. ssize_t ret;
  845. spin_lock(&lun->lun_sep_lock);
  846. sep = lun->lun_sep;
  847. if (!sep) {
  848. spin_unlock(&lun->lun_sep_lock);
  849. return -ENODEV;
  850. }
  851. ret = snprintf(page, PAGE_SIZE, "%u\n",
  852. (u32)(sep->sep_stats.tx_data_octets >> 20));
  853. spin_unlock(&lun->lun_sep_lock);
  854. return ret;
  855. }
  856. DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes);
  857. static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
  858. struct se_port_stat_grps *pgrps, char *page)
  859. {
  860. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  861. struct se_port *sep;
  862. ssize_t ret;
  863. spin_lock(&lun->lun_sep_lock);
  864. sep = lun->lun_sep;
  865. if (!sep) {
  866. spin_unlock(&lun->lun_sep_lock);
  867. return -ENODEV;
  868. }
  869. /* FIXME: scsiTgtPortHsInCommands */
  870. ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
  871. spin_unlock(&lun->lun_sep_lock);
  872. return ret;
  873. }
  874. DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds);
  875. CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps,
  876. scsi_tgt_port_group);
  877. static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
  878. &target_stat_scsi_tgt_port_inst.attr,
  879. &target_stat_scsi_tgt_port_dev.attr,
  880. &target_stat_scsi_tgt_port_indx.attr,
  881. &target_stat_scsi_tgt_port_name.attr,
  882. &target_stat_scsi_tgt_port_port_index.attr,
  883. &target_stat_scsi_tgt_port_in_cmds.attr,
  884. &target_stat_scsi_tgt_port_write_mbytes.attr,
  885. &target_stat_scsi_tgt_port_read_mbytes.attr,
  886. &target_stat_scsi_tgt_port_hs_in_cmds.attr,
  887. NULL,
  888. };
  889. static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = {
  890. .show_attribute = target_stat_scsi_tgt_port_attr_show,
  891. .store_attribute = target_stat_scsi_tgt_port_attr_store,
  892. };
  893. static struct config_item_type target_stat_scsi_tgt_port_cit = {
  894. .ct_item_ops = &target_stat_scsi_tgt_port_attrib_ops,
  895. .ct_attrs = target_stat_scsi_tgt_port_attrs,
  896. .ct_owner = THIS_MODULE,
  897. };
  898. /*
  899. * SCSI Transport Table
  900. o */
  901. CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps);
  902. #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \
  903. static struct target_stat_scsi_transport_attribute \
  904. target_stat_scsi_transport_##_name = \
  905. __CONFIGFS_EATTR(_name, _mode, \
  906. target_stat_scsi_transport_show_attr_##_name, \
  907. target_stat_scsi_transport_store_attr_##_name);
  908. #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \
  909. static struct target_stat_scsi_transport_attribute \
  910. target_stat_scsi_transport_##_name = \
  911. __CONFIGFS_EATTR_RO(_name, \
  912. target_stat_scsi_transport_show_attr_##_name);
  913. static ssize_t target_stat_scsi_transport_show_attr_inst(
  914. struct se_port_stat_grps *pgrps, char *page)
  915. {
  916. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  917. struct se_device *dev = lun->lun_se_dev;
  918. struct se_port *sep;
  919. struct se_hba *hba;
  920. ssize_t ret;
  921. spin_lock(&lun->lun_sep_lock);
  922. sep = lun->lun_sep;
  923. if (!sep) {
  924. spin_unlock(&lun->lun_sep_lock);
  925. return -ENODEV;
  926. }
  927. hba = dev->se_hba;
  928. ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  929. spin_unlock(&lun->lun_sep_lock);
  930. return ret;
  931. }
  932. DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst);
  933. static ssize_t target_stat_scsi_transport_show_attr_device(
  934. struct se_port_stat_grps *pgrps, char *page)
  935. {
  936. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  937. struct se_port *sep;
  938. struct se_portal_group *tpg;
  939. ssize_t ret;
  940. spin_lock(&lun->lun_sep_lock);
  941. sep = lun->lun_sep;
  942. if (!sep) {
  943. spin_unlock(&lun->lun_sep_lock);
  944. return -ENODEV;
  945. }
  946. tpg = sep->sep_tpg;
  947. /* scsiTransportType */
  948. ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
  949. tpg->se_tpg_tfo->get_fabric_name());
  950. spin_unlock(&lun->lun_sep_lock);
  951. return ret;
  952. }
  953. DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device);
  954. static ssize_t target_stat_scsi_transport_show_attr_indx(
  955. struct se_port_stat_grps *pgrps, char *page)
  956. {
  957. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  958. struct se_port *sep;
  959. struct se_portal_group *tpg;
  960. ssize_t ret;
  961. spin_lock(&lun->lun_sep_lock);
  962. sep = lun->lun_sep;
  963. if (!sep) {
  964. spin_unlock(&lun->lun_sep_lock);
  965. return -ENODEV;
  966. }
  967. tpg = sep->sep_tpg;
  968. ret = snprintf(page, PAGE_SIZE, "%u\n",
  969. tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
  970. spin_unlock(&lun->lun_sep_lock);
  971. return ret;
  972. }
  973. DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx);
  974. static ssize_t target_stat_scsi_transport_show_attr_dev_name(
  975. struct se_port_stat_grps *pgrps, char *page)
  976. {
  977. struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
  978. struct se_device *dev = lun->lun_se_dev;
  979. struct se_port *sep;
  980. struct se_portal_group *tpg;
  981. struct t10_wwn *wwn;
  982. ssize_t ret;
  983. spin_lock(&lun->lun_sep_lock);
  984. sep = lun->lun_sep;
  985. if (!sep) {
  986. spin_unlock(&lun->lun_sep_lock);
  987. return -ENODEV;
  988. }
  989. tpg = sep->sep_tpg;
  990. wwn = &dev->se_sub_dev->t10_wwn;
  991. /* scsiTransportDevName */
  992. ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
  993. tpg->se_tpg_tfo->tpg_get_wwn(tpg),
  994. (strlen(wwn->unit_serial)) ? wwn->unit_serial :
  995. wwn->vendor);
  996. spin_unlock(&lun->lun_sep_lock);
  997. return ret;
  998. }
  999. DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name);
  1000. CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps,
  1001. scsi_transport_group);
  1002. static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
  1003. &target_stat_scsi_transport_inst.attr,
  1004. &target_stat_scsi_transport_device.attr,
  1005. &target_stat_scsi_transport_indx.attr,
  1006. &target_stat_scsi_transport_dev_name.attr,
  1007. NULL,
  1008. };
  1009. static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = {
  1010. .show_attribute = target_stat_scsi_transport_attr_show,
  1011. .store_attribute = target_stat_scsi_transport_attr_store,
  1012. };
  1013. static struct config_item_type target_stat_scsi_transport_cit = {
  1014. .ct_item_ops = &target_stat_scsi_transport_attrib_ops,
  1015. .ct_attrs = target_stat_scsi_transport_attrs,
  1016. .ct_owner = THIS_MODULE,
  1017. };
  1018. /*
  1019. * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
  1020. * the target port statistics groups + configfs CITs located in target_core_stat.c
  1021. */
  1022. void target_stat_setup_port_default_groups(struct se_lun *lun)
  1023. {
  1024. struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group;
  1025. config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
  1026. "scsi_port", &target_stat_scsi_port_cit);
  1027. config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
  1028. "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
  1029. config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
  1030. "scsi_transport", &target_stat_scsi_transport_cit);
  1031. port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group;
  1032. port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group;
  1033. port_stat_grp->default_groups[2] = &lun->port_stat_grps.scsi_transport_group;
  1034. port_stat_grp->default_groups[3] = NULL;
  1035. }
  1036. /*
  1037. * SCSI Authorized Initiator Table
  1038. */
  1039. CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps);
  1040. #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \
  1041. static struct target_stat_scsi_auth_intr_attribute \
  1042. target_stat_scsi_auth_intr_##_name = \
  1043. __CONFIGFS_EATTR(_name, _mode, \
  1044. target_stat_scsi_auth_intr_show_attr_##_name, \
  1045. target_stat_scsi_auth_intr_store_attr_##_name);
  1046. #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \
  1047. static struct target_stat_scsi_auth_intr_attribute \
  1048. target_stat_scsi_auth_intr_##_name = \
  1049. __CONFIGFS_EATTR_RO(_name, \
  1050. target_stat_scsi_auth_intr_show_attr_##_name);
  1051. static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
  1052. struct se_ml_stat_grps *lgrps, char *page)
  1053. {
  1054. struct se_lun_acl *lacl = container_of(lgrps,
  1055. struct se_lun_acl, ml_stat_grps);
  1056. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1057. struct se_dev_entry *deve;
  1058. struct se_portal_group *tpg;
  1059. ssize_t ret;
  1060. spin_lock_irq(&nacl->device_list_lock);
  1061. deve = nacl->device_list[lacl->mapped_lun];
  1062. if (!deve->se_lun || !deve->se_lun_acl) {
  1063. spin_unlock_irq(&nacl->device_list_lock);
  1064. return -ENODEV;
  1065. }
  1066. tpg = nacl->se_tpg;
  1067. /* scsiInstIndex */
  1068. ret = snprintf(page, PAGE_SIZE, "%u\n",
  1069. tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
  1070. spin_unlock_irq(&nacl->device_list_lock);
  1071. return ret;
  1072. }
  1073. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst);
  1074. static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
  1075. struct se_ml_stat_grps *lgrps, char *page)
  1076. {
  1077. struct se_lun_acl *lacl = container_of(lgrps,
  1078. struct se_lun_acl, ml_stat_grps);
  1079. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1080. struct se_dev_entry *deve;
  1081. struct se_lun *lun;
  1082. ssize_t ret;
  1083. spin_lock_irq(&nacl->device_list_lock);
  1084. deve = nacl->device_list[lacl->mapped_lun];
  1085. if (!deve->se_lun || !deve->se_lun_acl) {
  1086. spin_unlock_irq(&nacl->device_list_lock);
  1087. return -ENODEV;
  1088. }
  1089. lun = deve->se_lun;
  1090. /* scsiDeviceIndex */
  1091. ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
  1092. spin_unlock_irq(&nacl->device_list_lock);
  1093. return ret;
  1094. }
  1095. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev);
  1096. static ssize_t target_stat_scsi_auth_intr_show_attr_port(
  1097. struct se_ml_stat_grps *lgrps, char *page)
  1098. {
  1099. struct se_lun_acl *lacl = container_of(lgrps,
  1100. struct se_lun_acl, ml_stat_grps);
  1101. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1102. struct se_dev_entry *deve;
  1103. struct se_portal_group *tpg;
  1104. ssize_t ret;
  1105. spin_lock_irq(&nacl->device_list_lock);
  1106. deve = nacl->device_list[lacl->mapped_lun];
  1107. if (!deve->se_lun || !deve->se_lun_acl) {
  1108. spin_unlock_irq(&nacl->device_list_lock);
  1109. return -ENODEV;
  1110. }
  1111. tpg = nacl->se_tpg;
  1112. /* scsiAuthIntrTgtPortIndex */
  1113. ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
  1114. spin_unlock_irq(&nacl->device_list_lock);
  1115. return ret;
  1116. }
  1117. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port);
  1118. static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
  1119. struct se_ml_stat_grps *lgrps, char *page)
  1120. {
  1121. struct se_lun_acl *lacl = container_of(lgrps,
  1122. struct se_lun_acl, ml_stat_grps);
  1123. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1124. struct se_dev_entry *deve;
  1125. ssize_t ret;
  1126. spin_lock_irq(&nacl->device_list_lock);
  1127. deve = nacl->device_list[lacl->mapped_lun];
  1128. if (!deve->se_lun || !deve->se_lun_acl) {
  1129. spin_unlock_irq(&nacl->device_list_lock);
  1130. return -ENODEV;
  1131. }
  1132. /* scsiAuthIntrIndex */
  1133. ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
  1134. spin_unlock_irq(&nacl->device_list_lock);
  1135. return ret;
  1136. }
  1137. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx);
  1138. static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
  1139. struct se_ml_stat_grps *lgrps, char *page)
  1140. {
  1141. struct se_lun_acl *lacl = container_of(lgrps,
  1142. struct se_lun_acl, ml_stat_grps);
  1143. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1144. struct se_dev_entry *deve;
  1145. ssize_t ret;
  1146. spin_lock_irq(&nacl->device_list_lock);
  1147. deve = nacl->device_list[lacl->mapped_lun];
  1148. if (!deve->se_lun || !deve->se_lun_acl) {
  1149. spin_unlock_irq(&nacl->device_list_lock);
  1150. return -ENODEV;
  1151. }
  1152. /* scsiAuthIntrDevOrPort */
  1153. ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
  1154. spin_unlock_irq(&nacl->device_list_lock);
  1155. return ret;
  1156. }
  1157. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port);
  1158. static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
  1159. struct se_ml_stat_grps *lgrps, char *page)
  1160. {
  1161. struct se_lun_acl *lacl = container_of(lgrps,
  1162. struct se_lun_acl, ml_stat_grps);
  1163. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1164. struct se_dev_entry *deve;
  1165. ssize_t ret;
  1166. spin_lock_irq(&nacl->device_list_lock);
  1167. deve = nacl->device_list[lacl->mapped_lun];
  1168. if (!deve->se_lun || !deve->se_lun_acl) {
  1169. spin_unlock_irq(&nacl->device_list_lock);
  1170. return -ENODEV;
  1171. }
  1172. /* scsiAuthIntrName */
  1173. ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
  1174. spin_unlock_irq(&nacl->device_list_lock);
  1175. return ret;
  1176. }
  1177. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name);
  1178. static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
  1179. struct se_ml_stat_grps *lgrps, char *page)
  1180. {
  1181. struct se_lun_acl *lacl = container_of(lgrps,
  1182. struct se_lun_acl, ml_stat_grps);
  1183. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1184. struct se_dev_entry *deve;
  1185. ssize_t ret;
  1186. spin_lock_irq(&nacl->device_list_lock);
  1187. deve = nacl->device_list[lacl->mapped_lun];
  1188. if (!deve->se_lun || !deve->se_lun_acl) {
  1189. spin_unlock_irq(&nacl->device_list_lock);
  1190. return -ENODEV;
  1191. }
  1192. /* FIXME: scsiAuthIntrLunMapIndex */
  1193. ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
  1194. spin_unlock_irq(&nacl->device_list_lock);
  1195. return ret;
  1196. }
  1197. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx);
  1198. static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
  1199. struct se_ml_stat_grps *lgrps, char *page)
  1200. {
  1201. struct se_lun_acl *lacl = container_of(lgrps,
  1202. struct se_lun_acl, ml_stat_grps);
  1203. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1204. struct se_dev_entry *deve;
  1205. ssize_t ret;
  1206. spin_lock_irq(&nacl->device_list_lock);
  1207. deve = nacl->device_list[lacl->mapped_lun];
  1208. if (!deve->se_lun || !deve->se_lun_acl) {
  1209. spin_unlock_irq(&nacl->device_list_lock);
  1210. return -ENODEV;
  1211. }
  1212. /* scsiAuthIntrAttachedTimes */
  1213. ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
  1214. spin_unlock_irq(&nacl->device_list_lock);
  1215. return ret;
  1216. }
  1217. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count);
  1218. static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
  1219. struct se_ml_stat_grps *lgrps, char *page)
  1220. {
  1221. struct se_lun_acl *lacl = container_of(lgrps,
  1222. struct se_lun_acl, ml_stat_grps);
  1223. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1224. struct se_dev_entry *deve;
  1225. ssize_t ret;
  1226. spin_lock_irq(&nacl->device_list_lock);
  1227. deve = nacl->device_list[lacl->mapped_lun];
  1228. if (!deve->se_lun || !deve->se_lun_acl) {
  1229. spin_unlock_irq(&nacl->device_list_lock);
  1230. return -ENODEV;
  1231. }
  1232. /* scsiAuthIntrOutCommands */
  1233. ret = snprintf(page, PAGE_SIZE, "%u\n", deve->total_cmds);
  1234. spin_unlock_irq(&nacl->device_list_lock);
  1235. return ret;
  1236. }
  1237. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds);
  1238. static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
  1239. struct se_ml_stat_grps *lgrps, char *page)
  1240. {
  1241. struct se_lun_acl *lacl = container_of(lgrps,
  1242. struct se_lun_acl, ml_stat_grps);
  1243. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1244. struct se_dev_entry *deve;
  1245. ssize_t ret;
  1246. spin_lock_irq(&nacl->device_list_lock);
  1247. deve = nacl->device_list[lacl->mapped_lun];
  1248. if (!deve->se_lun || !deve->se_lun_acl) {
  1249. spin_unlock_irq(&nacl->device_list_lock);
  1250. return -ENODEV;
  1251. }
  1252. /* scsiAuthIntrReadMegaBytes */
  1253. ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->read_bytes >> 20));
  1254. spin_unlock_irq(&nacl->device_list_lock);
  1255. return ret;
  1256. }
  1257. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes);
  1258. static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
  1259. struct se_ml_stat_grps *lgrps, char *page)
  1260. {
  1261. struct se_lun_acl *lacl = container_of(lgrps,
  1262. struct se_lun_acl, ml_stat_grps);
  1263. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1264. struct se_dev_entry *deve;
  1265. ssize_t ret;
  1266. spin_lock_irq(&nacl->device_list_lock);
  1267. deve = nacl->device_list[lacl->mapped_lun];
  1268. if (!deve->se_lun || !deve->se_lun_acl) {
  1269. spin_unlock_irq(&nacl->device_list_lock);
  1270. return -ENODEV;
  1271. }
  1272. /* scsiAuthIntrWrittenMegaBytes */
  1273. ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->write_bytes >> 20));
  1274. spin_unlock_irq(&nacl->device_list_lock);
  1275. return ret;
  1276. }
  1277. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes);
  1278. static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
  1279. struct se_ml_stat_grps *lgrps, char *page)
  1280. {
  1281. struct se_lun_acl *lacl = container_of(lgrps,
  1282. struct se_lun_acl, ml_stat_grps);
  1283. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1284. struct se_dev_entry *deve;
  1285. ssize_t ret;
  1286. spin_lock_irq(&nacl->device_list_lock);
  1287. deve = nacl->device_list[lacl->mapped_lun];
  1288. if (!deve->se_lun || !deve->se_lun_acl) {
  1289. spin_unlock_irq(&nacl->device_list_lock);
  1290. return -ENODEV;
  1291. }
  1292. /* FIXME: scsiAuthIntrHSOutCommands */
  1293. ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
  1294. spin_unlock_irq(&nacl->device_list_lock);
  1295. return ret;
  1296. }
  1297. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds);
  1298. static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
  1299. struct se_ml_stat_grps *lgrps, char *page)
  1300. {
  1301. struct se_lun_acl *lacl = container_of(lgrps,
  1302. struct se_lun_acl, ml_stat_grps);
  1303. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1304. struct se_dev_entry *deve;
  1305. ssize_t ret;
  1306. spin_lock_irq(&nacl->device_list_lock);
  1307. deve = nacl->device_list[lacl->mapped_lun];
  1308. if (!deve->se_lun || !deve->se_lun_acl) {
  1309. spin_unlock_irq(&nacl->device_list_lock);
  1310. return -ENODEV;
  1311. }
  1312. /* scsiAuthIntrLastCreation */
  1313. ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
  1314. INITIAL_JIFFIES) * 100 / HZ));
  1315. spin_unlock_irq(&nacl->device_list_lock);
  1316. return ret;
  1317. }
  1318. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time);
  1319. static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
  1320. struct se_ml_stat_grps *lgrps, char *page)
  1321. {
  1322. struct se_lun_acl *lacl = container_of(lgrps,
  1323. struct se_lun_acl, ml_stat_grps);
  1324. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1325. struct se_dev_entry *deve;
  1326. ssize_t ret;
  1327. spin_lock_irq(&nacl->device_list_lock);
  1328. deve = nacl->device_list[lacl->mapped_lun];
  1329. if (!deve->se_lun || !deve->se_lun_acl) {
  1330. spin_unlock_irq(&nacl->device_list_lock);
  1331. return -ENODEV;
  1332. }
  1333. /* FIXME: scsiAuthIntrRowStatus */
  1334. ret = snprintf(page, PAGE_SIZE, "Ready\n");
  1335. spin_unlock_irq(&nacl->device_list_lock);
  1336. return ret;
  1337. }
  1338. DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status);
  1339. CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps,
  1340. scsi_auth_intr_group);
  1341. static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
  1342. &target_stat_scsi_auth_intr_inst.attr,
  1343. &target_stat_scsi_auth_intr_dev.attr,
  1344. &target_stat_scsi_auth_intr_port.attr,
  1345. &target_stat_scsi_auth_intr_indx.attr,
  1346. &target_stat_scsi_auth_intr_dev_or_port.attr,
  1347. &target_stat_scsi_auth_intr_intr_name.attr,
  1348. &target_stat_scsi_auth_intr_map_indx.attr,
  1349. &target_stat_scsi_auth_intr_att_count.attr,
  1350. &target_stat_scsi_auth_intr_num_cmds.attr,
  1351. &target_stat_scsi_auth_intr_read_mbytes.attr,
  1352. &target_stat_scsi_auth_intr_write_mbytes.attr,
  1353. &target_stat_scsi_auth_intr_hs_num_cmds.attr,
  1354. &target_stat_scsi_auth_intr_creation_time.attr,
  1355. &target_stat_scsi_auth_intr_row_status.attr,
  1356. NULL,
  1357. };
  1358. static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = {
  1359. .show_attribute = target_stat_scsi_auth_intr_attr_show,
  1360. .store_attribute = target_stat_scsi_auth_intr_attr_store,
  1361. };
  1362. static struct config_item_type target_stat_scsi_auth_intr_cit = {
  1363. .ct_item_ops = &target_stat_scsi_auth_intr_attrib_ops,
  1364. .ct_attrs = target_stat_scsi_auth_intr_attrs,
  1365. .ct_owner = THIS_MODULE,
  1366. };
  1367. /*
  1368. * SCSI Attached Initiator Port Table
  1369. */
  1370. CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps);
  1371. #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \
  1372. static struct target_stat_scsi_att_intr_port_attribute \
  1373. target_stat_scsi_att_intr_port_##_name = \
  1374. __CONFIGFS_EATTR(_name, _mode, \
  1375. target_stat_scsi_att_intr_port_show_attr_##_name, \
  1376. target_stat_scsi_att_intr_port_store_attr_##_name);
  1377. #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \
  1378. static struct target_stat_scsi_att_intr_port_attribute \
  1379. target_stat_scsi_att_intr_port_##_name = \
  1380. __CONFIGFS_EATTR_RO(_name, \
  1381. target_stat_scsi_att_intr_port_show_attr_##_name);
  1382. static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
  1383. struct se_ml_stat_grps *lgrps, char *page)
  1384. {
  1385. struct se_lun_acl *lacl = container_of(lgrps,
  1386. struct se_lun_acl, ml_stat_grps);
  1387. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1388. struct se_dev_entry *deve;
  1389. struct se_portal_group *tpg;
  1390. ssize_t ret;
  1391. spin_lock_irq(&nacl->device_list_lock);
  1392. deve = nacl->device_list[lacl->mapped_lun];
  1393. if (!deve->se_lun || !deve->se_lun_acl) {
  1394. spin_unlock_irq(&nacl->device_list_lock);
  1395. return -ENODEV;
  1396. }
  1397. tpg = nacl->se_tpg;
  1398. /* scsiInstIndex */
  1399. ret = snprintf(page, PAGE_SIZE, "%u\n",
  1400. tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
  1401. spin_unlock_irq(&nacl->device_list_lock);
  1402. return ret;
  1403. }
  1404. DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst);
  1405. static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
  1406. struct se_ml_stat_grps *lgrps, char *page)
  1407. {
  1408. struct se_lun_acl *lacl = container_of(lgrps,
  1409. struct se_lun_acl, ml_stat_grps);
  1410. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1411. struct se_dev_entry *deve;
  1412. struct se_lun *lun;
  1413. ssize_t ret;
  1414. spin_lock_irq(&nacl->device_list_lock);
  1415. deve = nacl->device_list[lacl->mapped_lun];
  1416. if (!deve->se_lun || !deve->se_lun_acl) {
  1417. spin_unlock_irq(&nacl->device_list_lock);
  1418. return -ENODEV;
  1419. }
  1420. lun = deve->se_lun;
  1421. /* scsiDeviceIndex */
  1422. ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
  1423. spin_unlock_irq(&nacl->device_list_lock);
  1424. return ret;
  1425. }
  1426. DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev);
  1427. static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
  1428. struct se_ml_stat_grps *lgrps, char *page)
  1429. {
  1430. struct se_lun_acl *lacl = container_of(lgrps,
  1431. struct se_lun_acl, ml_stat_grps);
  1432. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1433. struct se_dev_entry *deve;
  1434. struct se_portal_group *tpg;
  1435. ssize_t ret;
  1436. spin_lock_irq(&nacl->device_list_lock);
  1437. deve = nacl->device_list[lacl->mapped_lun];
  1438. if (!deve->se_lun || !deve->se_lun_acl) {
  1439. spin_unlock_irq(&nacl->device_list_lock);
  1440. return -ENODEV;
  1441. }
  1442. tpg = nacl->se_tpg;
  1443. /* scsiPortIndex */
  1444. ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
  1445. spin_unlock_irq(&nacl->device_list_lock);
  1446. return ret;
  1447. }
  1448. DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port);
  1449. static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
  1450. struct se_ml_stat_grps *lgrps, char *page)
  1451. {
  1452. struct se_lun_acl *lacl = container_of(lgrps,
  1453. struct se_lun_acl, ml_stat_grps);
  1454. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1455. struct se_session *se_sess;
  1456. struct se_portal_group *tpg;
  1457. ssize_t ret;
  1458. spin_lock_irq(&nacl->nacl_sess_lock);
  1459. se_sess = nacl->nacl_sess;
  1460. if (!se_sess) {
  1461. spin_unlock_irq(&nacl->nacl_sess_lock);
  1462. return -ENODEV;
  1463. }
  1464. tpg = nacl->se_tpg;
  1465. /* scsiAttIntrPortIndex */
  1466. ret = snprintf(page, PAGE_SIZE, "%u\n",
  1467. tpg->se_tpg_tfo->sess_get_index(se_sess));
  1468. spin_unlock_irq(&nacl->nacl_sess_lock);
  1469. return ret;
  1470. }
  1471. DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx);
  1472. static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
  1473. struct se_ml_stat_grps *lgrps, char *page)
  1474. {
  1475. struct se_lun_acl *lacl = container_of(lgrps,
  1476. struct se_lun_acl, ml_stat_grps);
  1477. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1478. struct se_dev_entry *deve;
  1479. ssize_t ret;
  1480. spin_lock_irq(&nacl->device_list_lock);
  1481. deve = nacl->device_list[lacl->mapped_lun];
  1482. if (!deve->se_lun || !deve->se_lun_acl) {
  1483. spin_unlock_irq(&nacl->device_list_lock);
  1484. return -ENODEV;
  1485. }
  1486. /* scsiAttIntrPortAuthIntrIdx */
  1487. ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
  1488. spin_unlock_irq(&nacl->device_list_lock);
  1489. return ret;
  1490. }
  1491. DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
  1492. static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
  1493. struct se_ml_stat_grps *lgrps, char *page)
  1494. {
  1495. struct se_lun_acl *lacl = container_of(lgrps,
  1496. struct se_lun_acl, ml_stat_grps);
  1497. struct se_node_acl *nacl = lacl->se_lun_nacl;
  1498. struct se_session *se_sess;
  1499. struct se_portal_group *tpg;
  1500. ssize_t ret;
  1501. unsigned char buf[64];
  1502. spin_lock_irq(&nacl->nacl_sess_lock);
  1503. se_sess = nacl->nacl_sess;
  1504. if (!se_sess) {
  1505. spin_unlock_irq(&nacl->nacl_sess_lock);
  1506. return -ENODEV;
  1507. }
  1508. tpg = nacl->se_tpg;
  1509. /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
  1510. memset(buf, 0, 64);
  1511. if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
  1512. tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
  1513. ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
  1514. spin_unlock_irq(&nacl->nacl_sess_lock);
  1515. return ret;
  1516. }
  1517. DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident);
  1518. CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps,
  1519. scsi_att_intr_port_group);
  1520. static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
  1521. &target_stat_scsi_att_intr_port_inst.attr,
  1522. &target_stat_scsi_att_intr_port_dev.attr,
  1523. &target_stat_scsi_att_intr_port_port.attr,
  1524. &target_stat_scsi_att_intr_port_indx.attr,
  1525. &target_stat_scsi_att_intr_port_port_auth_indx.attr,
  1526. &target_stat_scsi_att_intr_port_port_ident.attr,
  1527. NULL,
  1528. };
  1529. static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = {
  1530. .show_attribute = target_stat_scsi_att_intr_port_attr_show,
  1531. .store_attribute = target_stat_scsi_att_intr_port_attr_store,
  1532. };
  1533. static struct config_item_type target_stat_scsi_att_intr_port_cit = {
  1534. .ct_item_ops = &target_stat_scsi_att_intr_port_attrib_ops,
  1535. .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
  1536. .ct_owner = THIS_MODULE,
  1537. };
  1538. /*
  1539. * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
  1540. * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
  1541. */
  1542. void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
  1543. {
  1544. struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group;
  1545. config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
  1546. "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
  1547. config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
  1548. "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
  1549. ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group;
  1550. ml_stat_grp->default_groups[1] = &lacl->ml_stat_grps.scsi_att_intr_port_group;
  1551. ml_stat_grp->default_groups[2] = NULL;
  1552. }