target_core_stat.c 37 KB

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