iscsi_target_stat.c 28 KB

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