target_core_stat.c 53 KB

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