iscsi_target_stat.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. /*******************************************************************************
  2. * Modern ConfigFS group context specific iSCSI statistics based on original
  3. * iscsi_target_mib.c code
  4. *
  5. * Copyright (c) 2011-2013 Datera, Inc.
  6. *
  7. * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. ******************************************************************************/
  19. #include <linux/configfs.h>
  20. #include <linux/export.h>
  21. #include <scsi/iscsi_proto.h>
  22. #include <target/target_core_base.h>
  23. #include <target/configfs_macros.h>
  24. #include <target/iscsi/iscsi_target_core.h>
  25. #include "iscsi_target_parameters.h"
  26. #include "iscsi_target_device.h"
  27. #include "iscsi_target_tpg.h"
  28. #include "iscsi_target_util.h"
  29. #include <target/iscsi/iscsi_target_stat.h>
  30. #ifndef INITIAL_JIFFIES
  31. #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
  32. #endif
  33. /* Instance Attributes Table */
  34. #define ISCSI_INST_NUM_NODES 1
  35. #define ISCSI_INST_DESCR "Storage Engine Target"
  36. #define ISCSI_INST_LAST_FAILURE_TYPE 0
  37. #define ISCSI_DISCONTINUITY_TIME 0
  38. #define ISCSI_NODE_INDEX 1
  39. #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
  40. /****************************************************************************
  41. * iSCSI MIB Tables
  42. ****************************************************************************/
  43. /*
  44. * Instance Attributes Table
  45. */
  46. CONFIGFS_EATTR_STRUCT(iscsi_stat_instance, iscsi_wwn_stat_grps);
  47. #define ISCSI_STAT_INSTANCE_ATTR(_name, _mode) \
  48. static struct iscsi_stat_instance_attribute \
  49. iscsi_stat_instance_##_name = \
  50. __CONFIGFS_EATTR(_name, _mode, \
  51. iscsi_stat_instance_show_attr_##_name, \
  52. iscsi_stat_instance_store_attr_##_name);
  53. #define ISCSI_STAT_INSTANCE_ATTR_RO(_name) \
  54. static struct iscsi_stat_instance_attribute \
  55. iscsi_stat_instance_##_name = \
  56. __CONFIGFS_EATTR_RO(_name, \
  57. iscsi_stat_instance_show_attr_##_name);
  58. static ssize_t iscsi_stat_instance_show_attr_inst(
  59. struct iscsi_wwn_stat_grps *igrps, char *page)
  60. {
  61. struct iscsi_tiqn *tiqn = container_of(igrps,
  62. struct iscsi_tiqn, tiqn_stat_grps);
  63. return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
  64. }
  65. ISCSI_STAT_INSTANCE_ATTR_RO(inst);
  66. static ssize_t iscsi_stat_instance_show_attr_min_ver(
  67. struct iscsi_wwn_stat_grps *igrps, char *page)
  68. {
  69. return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
  70. }
  71. ISCSI_STAT_INSTANCE_ATTR_RO(min_ver);
  72. static ssize_t iscsi_stat_instance_show_attr_max_ver(
  73. struct iscsi_wwn_stat_grps *igrps, char *page)
  74. {
  75. return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
  76. }
  77. ISCSI_STAT_INSTANCE_ATTR_RO(max_ver);
  78. static ssize_t iscsi_stat_instance_show_attr_portals(
  79. struct iscsi_wwn_stat_grps *igrps, char *page)
  80. {
  81. struct iscsi_tiqn *tiqn = container_of(igrps,
  82. struct iscsi_tiqn, tiqn_stat_grps);
  83. return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_num_tpg_nps);
  84. }
  85. ISCSI_STAT_INSTANCE_ATTR_RO(portals);
  86. static ssize_t iscsi_stat_instance_show_attr_nodes(
  87. struct iscsi_wwn_stat_grps *igrps, char *page)
  88. {
  89. return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES);
  90. }
  91. ISCSI_STAT_INSTANCE_ATTR_RO(nodes);
  92. static ssize_t iscsi_stat_instance_show_attr_sessions(
  93. struct iscsi_wwn_stat_grps *igrps, char *page)
  94. {
  95. struct iscsi_tiqn *tiqn = container_of(igrps,
  96. struct iscsi_tiqn, tiqn_stat_grps);
  97. return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_nsessions);
  98. }
  99. ISCSI_STAT_INSTANCE_ATTR_RO(sessions);
  100. static ssize_t iscsi_stat_instance_show_attr_fail_sess(
  101. struct iscsi_wwn_stat_grps *igrps, char *page)
  102. {
  103. struct iscsi_tiqn *tiqn = container_of(igrps,
  104. struct iscsi_tiqn, tiqn_stat_grps);
  105. struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
  106. u32 sess_err_count;
  107. spin_lock_bh(&sess_err->lock);
  108. sess_err_count = (sess_err->digest_errors +
  109. sess_err->cxn_timeout_errors +
  110. sess_err->pdu_format_errors);
  111. spin_unlock_bh(&sess_err->lock);
  112. return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count);
  113. }
  114. ISCSI_STAT_INSTANCE_ATTR_RO(fail_sess);
  115. static ssize_t iscsi_stat_instance_show_attr_fail_type(
  116. struct iscsi_wwn_stat_grps *igrps, char *page)
  117. {
  118. struct iscsi_tiqn *tiqn = container_of(igrps,
  119. struct iscsi_tiqn, tiqn_stat_grps);
  120. struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
  121. return snprintf(page, PAGE_SIZE, "%u\n",
  122. sess_err->last_sess_failure_type);
  123. }
  124. ISCSI_STAT_INSTANCE_ATTR_RO(fail_type);
  125. static ssize_t iscsi_stat_instance_show_attr_fail_rem_name(
  126. struct iscsi_wwn_stat_grps *igrps, char *page)
  127. {
  128. struct iscsi_tiqn *tiqn = container_of(igrps,
  129. struct iscsi_tiqn, tiqn_stat_grps);
  130. struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
  131. return snprintf(page, PAGE_SIZE, "%s\n",
  132. sess_err->last_sess_fail_rem_name[0] ?
  133. sess_err->last_sess_fail_rem_name : NONE);
  134. }
  135. ISCSI_STAT_INSTANCE_ATTR_RO(fail_rem_name);
  136. static ssize_t iscsi_stat_instance_show_attr_disc_time(
  137. struct iscsi_wwn_stat_grps *igrps, char *page)
  138. {
  139. return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME);
  140. }
  141. ISCSI_STAT_INSTANCE_ATTR_RO(disc_time);
  142. static ssize_t iscsi_stat_instance_show_attr_description(
  143. struct iscsi_wwn_stat_grps *igrps, char *page)
  144. {
  145. return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR);
  146. }
  147. ISCSI_STAT_INSTANCE_ATTR_RO(description);
  148. static ssize_t iscsi_stat_instance_show_attr_vendor(
  149. struct iscsi_wwn_stat_grps *igrps, char *page)
  150. {
  151. return snprintf(page, PAGE_SIZE, "Datera, Inc. iSCSI-Target\n");
  152. }
  153. ISCSI_STAT_INSTANCE_ATTR_RO(vendor);
  154. static ssize_t iscsi_stat_instance_show_attr_version(
  155. struct iscsi_wwn_stat_grps *igrps, char *page)
  156. {
  157. return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION);
  158. }
  159. ISCSI_STAT_INSTANCE_ATTR_RO(version);
  160. CONFIGFS_EATTR_OPS(iscsi_stat_instance, iscsi_wwn_stat_grps,
  161. iscsi_instance_group);
  162. static struct configfs_attribute *iscsi_stat_instance_attrs[] = {
  163. &iscsi_stat_instance_inst.attr,
  164. &iscsi_stat_instance_min_ver.attr,
  165. &iscsi_stat_instance_max_ver.attr,
  166. &iscsi_stat_instance_portals.attr,
  167. &iscsi_stat_instance_nodes.attr,
  168. &iscsi_stat_instance_sessions.attr,
  169. &iscsi_stat_instance_fail_sess.attr,
  170. &iscsi_stat_instance_fail_type.attr,
  171. &iscsi_stat_instance_fail_rem_name.attr,
  172. &iscsi_stat_instance_disc_time.attr,
  173. &iscsi_stat_instance_description.attr,
  174. &iscsi_stat_instance_vendor.attr,
  175. &iscsi_stat_instance_version.attr,
  176. NULL,
  177. };
  178. static struct configfs_item_operations iscsi_stat_instance_item_ops = {
  179. .show_attribute = iscsi_stat_instance_attr_show,
  180. .store_attribute = iscsi_stat_instance_attr_store,
  181. };
  182. struct config_item_type iscsi_stat_instance_cit = {
  183. .ct_item_ops = &iscsi_stat_instance_item_ops,
  184. .ct_attrs = iscsi_stat_instance_attrs,
  185. .ct_owner = THIS_MODULE,
  186. };
  187. /*
  188. * Instance Session Failure Stats Table
  189. */
  190. CONFIGFS_EATTR_STRUCT(iscsi_stat_sess_err, iscsi_wwn_stat_grps);
  191. #define ISCSI_STAT_SESS_ERR_ATTR(_name, _mode) \
  192. static struct iscsi_stat_sess_err_attribute \
  193. iscsi_stat_sess_err_##_name = \
  194. __CONFIGFS_EATTR(_name, _mode, \
  195. iscsi_stat_sess_err_show_attr_##_name, \
  196. iscsi_stat_sess_err_store_attr_##_name);
  197. #define ISCSI_STAT_SESS_ERR_ATTR_RO(_name) \
  198. static struct iscsi_stat_sess_err_attribute \
  199. iscsi_stat_sess_err_##_name = \
  200. __CONFIGFS_EATTR_RO(_name, \
  201. iscsi_stat_sess_err_show_attr_##_name);
  202. static ssize_t iscsi_stat_sess_err_show_attr_inst(
  203. struct iscsi_wwn_stat_grps *igrps, char *page)
  204. {
  205. struct iscsi_tiqn *tiqn = container_of(igrps,
  206. struct iscsi_tiqn, tiqn_stat_grps);
  207. return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
  208. }
  209. ISCSI_STAT_SESS_ERR_ATTR_RO(inst);
  210. static ssize_t iscsi_stat_sess_err_show_attr_digest_errors(
  211. struct iscsi_wwn_stat_grps *igrps, char *page)
  212. {
  213. struct iscsi_tiqn *tiqn = container_of(igrps,
  214. struct iscsi_tiqn, tiqn_stat_grps);
  215. struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
  216. return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors);
  217. }
  218. ISCSI_STAT_SESS_ERR_ATTR_RO(digest_errors);
  219. static ssize_t iscsi_stat_sess_err_show_attr_cxn_errors(
  220. struct iscsi_wwn_stat_grps *igrps, char *page)
  221. {
  222. struct iscsi_tiqn *tiqn = container_of(igrps,
  223. struct iscsi_tiqn, tiqn_stat_grps);
  224. struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
  225. return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors);
  226. }
  227. ISCSI_STAT_SESS_ERR_ATTR_RO(cxn_errors);
  228. static ssize_t iscsi_stat_sess_err_show_attr_format_errors(
  229. struct iscsi_wwn_stat_grps *igrps, char *page)
  230. {
  231. struct iscsi_tiqn *tiqn = container_of(igrps,
  232. struct iscsi_tiqn, tiqn_stat_grps);
  233. struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
  234. return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors);
  235. }
  236. ISCSI_STAT_SESS_ERR_ATTR_RO(format_errors);
  237. CONFIGFS_EATTR_OPS(iscsi_stat_sess_err, iscsi_wwn_stat_grps,
  238. iscsi_sess_err_group);
  239. static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = {
  240. &iscsi_stat_sess_err_inst.attr,
  241. &iscsi_stat_sess_err_digest_errors.attr,
  242. &iscsi_stat_sess_err_cxn_errors.attr,
  243. &iscsi_stat_sess_err_format_errors.attr,
  244. NULL,
  245. };
  246. static struct configfs_item_operations iscsi_stat_sess_err_item_ops = {
  247. .show_attribute = iscsi_stat_sess_err_attr_show,
  248. .store_attribute = iscsi_stat_sess_err_attr_store,
  249. };
  250. struct config_item_type iscsi_stat_sess_err_cit = {
  251. .ct_item_ops = &iscsi_stat_sess_err_item_ops,
  252. .ct_attrs = iscsi_stat_sess_err_attrs,
  253. .ct_owner = THIS_MODULE,
  254. };
  255. /*
  256. * Target Attributes Table
  257. */
  258. CONFIGFS_EATTR_STRUCT(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps);
  259. #define ISCSI_STAT_TGT_ATTR(_name, _mode) \
  260. static struct iscsi_stat_tgt_attr_attribute \
  261. iscsi_stat_tgt_attr_##_name = \
  262. __CONFIGFS_EATTR(_name, _mode, \
  263. iscsi_stat_tgt-attr_show_attr_##_name, \
  264. iscsi_stat_tgt_attr_store_attr_##_name);
  265. #define ISCSI_STAT_TGT_ATTR_RO(_name) \
  266. static struct iscsi_stat_tgt_attr_attribute \
  267. iscsi_stat_tgt_attr_##_name = \
  268. __CONFIGFS_EATTR_RO(_name, \
  269. iscsi_stat_tgt_attr_show_attr_##_name);
  270. static ssize_t iscsi_stat_tgt_attr_show_attr_inst(
  271. struct iscsi_wwn_stat_grps *igrps, char *page)
  272. {
  273. struct iscsi_tiqn *tiqn = container_of(igrps,
  274. struct iscsi_tiqn, tiqn_stat_grps);
  275. return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
  276. }
  277. ISCSI_STAT_TGT_ATTR_RO(inst);
  278. static ssize_t iscsi_stat_tgt_attr_show_attr_indx(
  279. struct iscsi_wwn_stat_grps *igrps, char *page)
  280. {
  281. return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
  282. }
  283. ISCSI_STAT_TGT_ATTR_RO(indx);
  284. static ssize_t iscsi_stat_tgt_attr_show_attr_login_fails(
  285. struct iscsi_wwn_stat_grps *igrps, char *page)
  286. {
  287. struct iscsi_tiqn *tiqn = container_of(igrps,
  288. struct iscsi_tiqn, tiqn_stat_grps);
  289. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  290. u32 fail_count;
  291. spin_lock(&lstat->lock);
  292. fail_count = (lstat->redirects + lstat->authorize_fails +
  293. lstat->authenticate_fails + lstat->negotiate_fails +
  294. lstat->other_fails);
  295. spin_unlock(&lstat->lock);
  296. return snprintf(page, PAGE_SIZE, "%u\n", fail_count);
  297. }
  298. ISCSI_STAT_TGT_ATTR_RO(login_fails);
  299. static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_time(
  300. struct iscsi_wwn_stat_grps *igrps, char *page)
  301. {
  302. struct iscsi_tiqn *tiqn = container_of(igrps,
  303. struct iscsi_tiqn, tiqn_stat_grps);
  304. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  305. u32 last_fail_time;
  306. spin_lock(&lstat->lock);
  307. last_fail_time = lstat->last_fail_time ?
  308. (u32)(((u32)lstat->last_fail_time -
  309. INITIAL_JIFFIES) * 100 / HZ) : 0;
  310. spin_unlock(&lstat->lock);
  311. return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time);
  312. }
  313. ISCSI_STAT_TGT_ATTR_RO(last_fail_time);
  314. static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_type(
  315. struct iscsi_wwn_stat_grps *igrps, char *page)
  316. {
  317. struct iscsi_tiqn *tiqn = container_of(igrps,
  318. struct iscsi_tiqn, tiqn_stat_grps);
  319. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  320. u32 last_fail_type;
  321. spin_lock(&lstat->lock);
  322. last_fail_type = lstat->last_fail_type;
  323. spin_unlock(&lstat->lock);
  324. return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type);
  325. }
  326. ISCSI_STAT_TGT_ATTR_RO(last_fail_type);
  327. static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_name(
  328. struct iscsi_wwn_stat_grps *igrps, char *page)
  329. {
  330. struct iscsi_tiqn *tiqn = container_of(igrps,
  331. struct iscsi_tiqn, tiqn_stat_grps);
  332. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  333. unsigned char buf[224];
  334. spin_lock(&lstat->lock);
  335. snprintf(buf, 224, "%s", lstat->last_intr_fail_name[0] ?
  336. lstat->last_intr_fail_name : NONE);
  337. spin_unlock(&lstat->lock);
  338. return snprintf(page, PAGE_SIZE, "%s\n", buf);
  339. }
  340. ISCSI_STAT_TGT_ATTR_RO(fail_intr_name);
  341. static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr_type(
  342. struct iscsi_wwn_stat_grps *igrps, char *page)
  343. {
  344. struct iscsi_tiqn *tiqn = container_of(igrps,
  345. struct iscsi_tiqn, tiqn_stat_grps);
  346. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  347. int ret;
  348. spin_lock(&lstat->lock);
  349. if (lstat->last_intr_fail_ip_family == AF_INET6)
  350. ret = snprintf(page, PAGE_SIZE, "ipv6\n");
  351. else
  352. ret = snprintf(page, PAGE_SIZE, "ipv4\n");
  353. spin_unlock(&lstat->lock);
  354. return ret;
  355. }
  356. ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr_type);
  357. static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr(
  358. struct iscsi_wwn_stat_grps *igrps, char *page)
  359. {
  360. struct iscsi_tiqn *tiqn = container_of(igrps,
  361. struct iscsi_tiqn, tiqn_stat_grps);
  362. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  363. int ret;
  364. spin_lock(&lstat->lock);
  365. ret = snprintf(page, PAGE_SIZE, "%s\n", lstat->last_intr_fail_ip_addr);
  366. spin_unlock(&lstat->lock);
  367. return ret;
  368. }
  369. ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr);
  370. CONFIGFS_EATTR_OPS(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps,
  371. iscsi_tgt_attr_group);
  372. static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = {
  373. &iscsi_stat_tgt_attr_inst.attr,
  374. &iscsi_stat_tgt_attr_indx.attr,
  375. &iscsi_stat_tgt_attr_login_fails.attr,
  376. &iscsi_stat_tgt_attr_last_fail_time.attr,
  377. &iscsi_stat_tgt_attr_last_fail_type.attr,
  378. &iscsi_stat_tgt_attr_fail_intr_name.attr,
  379. &iscsi_stat_tgt_attr_fail_intr_addr_type.attr,
  380. &iscsi_stat_tgt_attr_fail_intr_addr.attr,
  381. NULL,
  382. };
  383. static struct configfs_item_operations iscsi_stat_tgt_attr_item_ops = {
  384. .show_attribute = iscsi_stat_tgt_attr_attr_show,
  385. .store_attribute = iscsi_stat_tgt_attr_attr_store,
  386. };
  387. struct config_item_type iscsi_stat_tgt_attr_cit = {
  388. .ct_item_ops = &iscsi_stat_tgt_attr_item_ops,
  389. .ct_attrs = iscsi_stat_tgt_attr_attrs,
  390. .ct_owner = THIS_MODULE,
  391. };
  392. /*
  393. * Target Login Stats Table
  394. */
  395. CONFIGFS_EATTR_STRUCT(iscsi_stat_login, iscsi_wwn_stat_grps);
  396. #define ISCSI_STAT_LOGIN(_name, _mode) \
  397. static struct iscsi_stat_login_attribute \
  398. iscsi_stat_login_##_name = \
  399. __CONFIGFS_EATTR(_name, _mode, \
  400. iscsi_stat_login_show_attr_##_name, \
  401. iscsi_stat_login_store_attr_##_name);
  402. #define ISCSI_STAT_LOGIN_RO(_name) \
  403. static struct iscsi_stat_login_attribute \
  404. iscsi_stat_login_##_name = \
  405. __CONFIGFS_EATTR_RO(_name, \
  406. iscsi_stat_login_show_attr_##_name);
  407. static ssize_t iscsi_stat_login_show_attr_inst(
  408. struct iscsi_wwn_stat_grps *igrps, char *page)
  409. {
  410. struct iscsi_tiqn *tiqn = container_of(igrps,
  411. struct iscsi_tiqn, tiqn_stat_grps);
  412. return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
  413. }
  414. ISCSI_STAT_LOGIN_RO(inst);
  415. static ssize_t iscsi_stat_login_show_attr_indx(
  416. struct iscsi_wwn_stat_grps *igrps, char *page)
  417. {
  418. return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
  419. }
  420. ISCSI_STAT_LOGIN_RO(indx);
  421. static ssize_t iscsi_stat_login_show_attr_accepts(
  422. struct iscsi_wwn_stat_grps *igrps, char *page)
  423. {
  424. struct iscsi_tiqn *tiqn = container_of(igrps,
  425. struct iscsi_tiqn, tiqn_stat_grps);
  426. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  427. ssize_t ret;
  428. spin_lock(&lstat->lock);
  429. ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->accepts);
  430. spin_unlock(&lstat->lock);
  431. return ret;
  432. }
  433. ISCSI_STAT_LOGIN_RO(accepts);
  434. static ssize_t iscsi_stat_login_show_attr_other_fails(
  435. struct iscsi_wwn_stat_grps *igrps, char *page)
  436. {
  437. struct iscsi_tiqn *tiqn = container_of(igrps,
  438. struct iscsi_tiqn, tiqn_stat_grps);
  439. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  440. ssize_t ret;
  441. spin_lock(&lstat->lock);
  442. ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->other_fails);
  443. spin_unlock(&lstat->lock);
  444. return ret;
  445. }
  446. ISCSI_STAT_LOGIN_RO(other_fails);
  447. static ssize_t iscsi_stat_login_show_attr_redirects(
  448. struct iscsi_wwn_stat_grps *igrps, char *page)
  449. {
  450. struct iscsi_tiqn *tiqn = container_of(igrps,
  451. struct iscsi_tiqn, tiqn_stat_grps);
  452. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  453. ssize_t ret;
  454. spin_lock(&lstat->lock);
  455. ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->redirects);
  456. spin_unlock(&lstat->lock);
  457. return ret;
  458. }
  459. ISCSI_STAT_LOGIN_RO(redirects);
  460. static ssize_t iscsi_stat_login_show_attr_authorize_fails(
  461. struct iscsi_wwn_stat_grps *igrps, char *page)
  462. {
  463. struct iscsi_tiqn *tiqn = container_of(igrps,
  464. struct iscsi_tiqn, tiqn_stat_grps);
  465. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  466. ssize_t ret;
  467. spin_lock(&lstat->lock);
  468. ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authorize_fails);
  469. spin_unlock(&lstat->lock);
  470. return ret;
  471. }
  472. ISCSI_STAT_LOGIN_RO(authorize_fails);
  473. static ssize_t iscsi_stat_login_show_attr_authenticate_fails(
  474. struct iscsi_wwn_stat_grps *igrps, char *page)
  475. {
  476. struct iscsi_tiqn *tiqn = container_of(igrps,
  477. struct iscsi_tiqn, tiqn_stat_grps);
  478. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  479. ssize_t ret;
  480. spin_lock(&lstat->lock);
  481. ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authenticate_fails);
  482. spin_unlock(&lstat->lock);
  483. return ret;
  484. }
  485. ISCSI_STAT_LOGIN_RO(authenticate_fails);
  486. static ssize_t iscsi_stat_login_show_attr_negotiate_fails(
  487. struct iscsi_wwn_stat_grps *igrps, char *page)
  488. {
  489. struct iscsi_tiqn *tiqn = container_of(igrps,
  490. struct iscsi_tiqn, tiqn_stat_grps);
  491. struct iscsi_login_stats *lstat = &tiqn->login_stats;
  492. ssize_t ret;
  493. spin_lock(&lstat->lock);
  494. ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->negotiate_fails);
  495. spin_unlock(&lstat->lock);
  496. return ret;
  497. }
  498. ISCSI_STAT_LOGIN_RO(negotiate_fails);
  499. CONFIGFS_EATTR_OPS(iscsi_stat_login, iscsi_wwn_stat_grps,
  500. iscsi_login_stats_group);
  501. static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = {
  502. &iscsi_stat_login_inst.attr,
  503. &iscsi_stat_login_indx.attr,
  504. &iscsi_stat_login_accepts.attr,
  505. &iscsi_stat_login_other_fails.attr,
  506. &iscsi_stat_login_redirects.attr,
  507. &iscsi_stat_login_authorize_fails.attr,
  508. &iscsi_stat_login_authenticate_fails.attr,
  509. &iscsi_stat_login_negotiate_fails.attr,
  510. NULL,
  511. };
  512. static struct configfs_item_operations iscsi_stat_login_stats_item_ops = {
  513. .show_attribute = iscsi_stat_login_attr_show,
  514. .store_attribute = iscsi_stat_login_attr_store,
  515. };
  516. struct config_item_type iscsi_stat_login_cit = {
  517. .ct_item_ops = &iscsi_stat_login_stats_item_ops,
  518. .ct_attrs = iscsi_stat_login_stats_attrs,
  519. .ct_owner = THIS_MODULE,
  520. };
  521. /*
  522. * Target Logout Stats Table
  523. */
  524. CONFIGFS_EATTR_STRUCT(iscsi_stat_logout, iscsi_wwn_stat_grps);
  525. #define ISCSI_STAT_LOGOUT(_name, _mode) \
  526. static struct iscsi_stat_logout_attribute \
  527. iscsi_stat_logout_##_name = \
  528. __CONFIGFS_EATTR(_name, _mode, \
  529. iscsi_stat_logout_show_attr_##_name, \
  530. iscsi_stat_logout_store_attr_##_name);
  531. #define ISCSI_STAT_LOGOUT_RO(_name) \
  532. static struct iscsi_stat_logout_attribute \
  533. iscsi_stat_logout_##_name = \
  534. __CONFIGFS_EATTR_RO(_name, \
  535. iscsi_stat_logout_show_attr_##_name);
  536. static ssize_t iscsi_stat_logout_show_attr_inst(
  537. struct iscsi_wwn_stat_grps *igrps, char *page)
  538. {
  539. struct iscsi_tiqn *tiqn = container_of(igrps,
  540. struct iscsi_tiqn, tiqn_stat_grps);
  541. return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
  542. }
  543. ISCSI_STAT_LOGOUT_RO(inst);
  544. static ssize_t iscsi_stat_logout_show_attr_indx(
  545. struct iscsi_wwn_stat_grps *igrps, char *page)
  546. {
  547. return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
  548. }
  549. ISCSI_STAT_LOGOUT_RO(indx);
  550. static ssize_t iscsi_stat_logout_show_attr_normal_logouts(
  551. struct iscsi_wwn_stat_grps *igrps, char *page)
  552. {
  553. struct iscsi_tiqn *tiqn = container_of(igrps,
  554. struct iscsi_tiqn, tiqn_stat_grps);
  555. struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
  556. return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts);
  557. }
  558. ISCSI_STAT_LOGOUT_RO(normal_logouts);
  559. static ssize_t iscsi_stat_logout_show_attr_abnormal_logouts(
  560. struct iscsi_wwn_stat_grps *igrps, char *page)
  561. {
  562. struct iscsi_tiqn *tiqn = container_of(igrps,
  563. struct iscsi_tiqn, tiqn_stat_grps);
  564. struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
  565. return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts);
  566. }
  567. ISCSI_STAT_LOGOUT_RO(abnormal_logouts);
  568. CONFIGFS_EATTR_OPS(iscsi_stat_logout, iscsi_wwn_stat_grps,
  569. iscsi_logout_stats_group);
  570. static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = {
  571. &iscsi_stat_logout_inst.attr,
  572. &iscsi_stat_logout_indx.attr,
  573. &iscsi_stat_logout_normal_logouts.attr,
  574. &iscsi_stat_logout_abnormal_logouts.attr,
  575. NULL,
  576. };
  577. static struct configfs_item_operations iscsi_stat_logout_stats_item_ops = {
  578. .show_attribute = iscsi_stat_logout_attr_show,
  579. .store_attribute = iscsi_stat_logout_attr_store,
  580. };
  581. struct config_item_type iscsi_stat_logout_cit = {
  582. .ct_item_ops = &iscsi_stat_logout_stats_item_ops,
  583. .ct_attrs = iscsi_stat_logout_stats_attrs,
  584. .ct_owner = THIS_MODULE,
  585. };
  586. /*
  587. * Session Stats Table
  588. */
  589. CONFIGFS_EATTR_STRUCT(iscsi_stat_sess, iscsi_node_stat_grps);
  590. #define ISCSI_STAT_SESS(_name, _mode) \
  591. static struct iscsi_stat_sess_attribute \
  592. iscsi_stat_sess_##_name = \
  593. __CONFIGFS_EATTR(_name, _mode, \
  594. iscsi_stat_sess_show_attr_##_name, \
  595. iscsi_stat_sess_store_attr_##_name);
  596. #define ISCSI_STAT_SESS_RO(_name) \
  597. static struct iscsi_stat_sess_attribute \
  598. iscsi_stat_sess_##_name = \
  599. __CONFIGFS_EATTR_RO(_name, \
  600. iscsi_stat_sess_show_attr_##_name);
  601. static ssize_t iscsi_stat_sess_show_attr_inst(
  602. struct iscsi_node_stat_grps *igrps, char *page)
  603. {
  604. struct iscsi_node_acl *acl = container_of(igrps,
  605. struct iscsi_node_acl, node_stat_grps);
  606. struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn;
  607. struct iscsi_tiqn *tiqn = container_of(wwn,
  608. struct iscsi_tiqn, tiqn_wwn);
  609. return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
  610. }
  611. ISCSI_STAT_SESS_RO(inst);
  612. static ssize_t iscsi_stat_sess_show_attr_node(
  613. struct iscsi_node_stat_grps *igrps, char *page)
  614. {
  615. struct iscsi_node_acl *acl = container_of(igrps,
  616. struct iscsi_node_acl, node_stat_grps);
  617. struct se_node_acl *se_nacl = &acl->se_node_acl;
  618. struct iscsi_session *sess;
  619. struct se_session *se_sess;
  620. ssize_t ret = 0;
  621. spin_lock_bh(&se_nacl->nacl_sess_lock);
  622. se_sess = se_nacl->nacl_sess;
  623. if (se_sess) {
  624. sess = se_sess->fabric_sess_ptr;
  625. if (sess)
  626. ret = snprintf(page, PAGE_SIZE, "%u\n",
  627. sess->sess_ops->SessionType ? 0 : ISCSI_NODE_INDEX);
  628. }
  629. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  630. return ret;
  631. }
  632. ISCSI_STAT_SESS_RO(node);
  633. static ssize_t iscsi_stat_sess_show_attr_indx(
  634. struct iscsi_node_stat_grps *igrps, char *page)
  635. {
  636. struct iscsi_node_acl *acl = container_of(igrps,
  637. struct iscsi_node_acl, node_stat_grps);
  638. struct se_node_acl *se_nacl = &acl->se_node_acl;
  639. struct iscsi_session *sess;
  640. struct se_session *se_sess;
  641. ssize_t ret = 0;
  642. spin_lock_bh(&se_nacl->nacl_sess_lock);
  643. se_sess = se_nacl->nacl_sess;
  644. if (se_sess) {
  645. sess = se_sess->fabric_sess_ptr;
  646. if (sess)
  647. ret = snprintf(page, PAGE_SIZE, "%u\n",
  648. sess->session_index);
  649. }
  650. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  651. return ret;
  652. }
  653. ISCSI_STAT_SESS_RO(indx);
  654. static ssize_t iscsi_stat_sess_show_attr_cmd_pdus(
  655. struct iscsi_node_stat_grps *igrps, char *page)
  656. {
  657. struct iscsi_node_acl *acl = container_of(igrps,
  658. struct iscsi_node_acl, node_stat_grps);
  659. struct se_node_acl *se_nacl = &acl->se_node_acl;
  660. struct iscsi_session *sess;
  661. struct se_session *se_sess;
  662. ssize_t ret = 0;
  663. spin_lock_bh(&se_nacl->nacl_sess_lock);
  664. se_sess = se_nacl->nacl_sess;
  665. if (se_sess) {
  666. sess = se_sess->fabric_sess_ptr;
  667. if (sess)
  668. ret = snprintf(page, PAGE_SIZE, "%lu\n",
  669. atomic_long_read(&sess->cmd_pdus));
  670. }
  671. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  672. return ret;
  673. }
  674. ISCSI_STAT_SESS_RO(cmd_pdus);
  675. static ssize_t iscsi_stat_sess_show_attr_rsp_pdus(
  676. struct iscsi_node_stat_grps *igrps, char *page)
  677. {
  678. struct iscsi_node_acl *acl = container_of(igrps,
  679. struct iscsi_node_acl, node_stat_grps);
  680. struct se_node_acl *se_nacl = &acl->se_node_acl;
  681. struct iscsi_session *sess;
  682. struct se_session *se_sess;
  683. ssize_t ret = 0;
  684. spin_lock_bh(&se_nacl->nacl_sess_lock);
  685. se_sess = se_nacl->nacl_sess;
  686. if (se_sess) {
  687. sess = se_sess->fabric_sess_ptr;
  688. if (sess)
  689. ret = snprintf(page, PAGE_SIZE, "%lu\n",
  690. atomic_long_read(&sess->rsp_pdus));
  691. }
  692. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  693. return ret;
  694. }
  695. ISCSI_STAT_SESS_RO(rsp_pdus);
  696. static ssize_t iscsi_stat_sess_show_attr_txdata_octs(
  697. struct iscsi_node_stat_grps *igrps, char *page)
  698. {
  699. struct iscsi_node_acl *acl = container_of(igrps,
  700. struct iscsi_node_acl, node_stat_grps);
  701. struct se_node_acl *se_nacl = &acl->se_node_acl;
  702. struct iscsi_session *sess;
  703. struct se_session *se_sess;
  704. ssize_t ret = 0;
  705. spin_lock_bh(&se_nacl->nacl_sess_lock);
  706. se_sess = se_nacl->nacl_sess;
  707. if (se_sess) {
  708. sess = se_sess->fabric_sess_ptr;
  709. if (sess)
  710. ret = snprintf(page, PAGE_SIZE, "%lu\n",
  711. atomic_long_read(&sess->tx_data_octets));
  712. }
  713. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  714. return ret;
  715. }
  716. ISCSI_STAT_SESS_RO(txdata_octs);
  717. static ssize_t iscsi_stat_sess_show_attr_rxdata_octs(
  718. struct iscsi_node_stat_grps *igrps, char *page)
  719. {
  720. struct iscsi_node_acl *acl = container_of(igrps,
  721. struct iscsi_node_acl, node_stat_grps);
  722. struct se_node_acl *se_nacl = &acl->se_node_acl;
  723. struct iscsi_session *sess;
  724. struct se_session *se_sess;
  725. ssize_t ret = 0;
  726. spin_lock_bh(&se_nacl->nacl_sess_lock);
  727. se_sess = se_nacl->nacl_sess;
  728. if (se_sess) {
  729. sess = se_sess->fabric_sess_ptr;
  730. if (sess)
  731. ret = snprintf(page, PAGE_SIZE, "%lu\n",
  732. atomic_long_read(&sess->rx_data_octets));
  733. }
  734. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  735. return ret;
  736. }
  737. ISCSI_STAT_SESS_RO(rxdata_octs);
  738. static ssize_t iscsi_stat_sess_show_attr_conn_digest_errors(
  739. struct iscsi_node_stat_grps *igrps, char *page)
  740. {
  741. struct iscsi_node_acl *acl = container_of(igrps,
  742. struct iscsi_node_acl, node_stat_grps);
  743. struct se_node_acl *se_nacl = &acl->se_node_acl;
  744. struct iscsi_session *sess;
  745. struct se_session *se_sess;
  746. ssize_t ret = 0;
  747. spin_lock_bh(&se_nacl->nacl_sess_lock);
  748. se_sess = se_nacl->nacl_sess;
  749. if (se_sess) {
  750. sess = se_sess->fabric_sess_ptr;
  751. if (sess)
  752. ret = snprintf(page, PAGE_SIZE, "%lu\n",
  753. atomic_long_read(&sess->conn_digest_errors));
  754. }
  755. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  756. return ret;
  757. }
  758. ISCSI_STAT_SESS_RO(conn_digest_errors);
  759. static ssize_t iscsi_stat_sess_show_attr_conn_timeout_errors(
  760. struct iscsi_node_stat_grps *igrps, char *page)
  761. {
  762. struct iscsi_node_acl *acl = container_of(igrps,
  763. struct iscsi_node_acl, node_stat_grps);
  764. struct se_node_acl *se_nacl = &acl->se_node_acl;
  765. struct iscsi_session *sess;
  766. struct se_session *se_sess;
  767. ssize_t ret = 0;
  768. spin_lock_bh(&se_nacl->nacl_sess_lock);
  769. se_sess = se_nacl->nacl_sess;
  770. if (se_sess) {
  771. sess = se_sess->fabric_sess_ptr;
  772. if (sess)
  773. ret = snprintf(page, PAGE_SIZE, "%lu\n",
  774. atomic_long_read(&sess->conn_timeout_errors));
  775. }
  776. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  777. return ret;
  778. }
  779. ISCSI_STAT_SESS_RO(conn_timeout_errors);
  780. CONFIGFS_EATTR_OPS(iscsi_stat_sess, iscsi_node_stat_grps,
  781. iscsi_sess_stats_group);
  782. static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = {
  783. &iscsi_stat_sess_inst.attr,
  784. &iscsi_stat_sess_node.attr,
  785. &iscsi_stat_sess_indx.attr,
  786. &iscsi_stat_sess_cmd_pdus.attr,
  787. &iscsi_stat_sess_rsp_pdus.attr,
  788. &iscsi_stat_sess_txdata_octs.attr,
  789. &iscsi_stat_sess_rxdata_octs.attr,
  790. &iscsi_stat_sess_conn_digest_errors.attr,
  791. &iscsi_stat_sess_conn_timeout_errors.attr,
  792. NULL,
  793. };
  794. static struct configfs_item_operations iscsi_stat_sess_stats_item_ops = {
  795. .show_attribute = iscsi_stat_sess_attr_show,
  796. .store_attribute = iscsi_stat_sess_attr_store,
  797. };
  798. struct config_item_type iscsi_stat_sess_cit = {
  799. .ct_item_ops = &iscsi_stat_sess_stats_item_ops,
  800. .ct_attrs = iscsi_stat_sess_stats_attrs,
  801. .ct_owner = THIS_MODULE,
  802. };