iscsi_target_nodeattrib.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*******************************************************************************
  2. * This file contains the main functions related to Initiator Node Attributes.
  3. *
  4. * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
  5. *
  6. * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
  7. *
  8. * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. ******************************************************************************/
  20. #include <target/target_core_base.h>
  21. #include "iscsi_target_core.h"
  22. #include "iscsi_target_device.h"
  23. #include "iscsi_target_tpg.h"
  24. #include "iscsi_target_util.h"
  25. #include "iscsi_target_nodeattrib.h"
  26. static inline char *iscsit_na_get_initiatorname(
  27. struct iscsi_node_acl *nacl)
  28. {
  29. struct se_node_acl *se_nacl = &nacl->se_node_acl;
  30. return &se_nacl->initiatorname[0];
  31. }
  32. void iscsit_set_default_node_attribues(
  33. struct iscsi_node_acl *acl)
  34. {
  35. struct iscsi_node_attrib *a = &acl->node_attrib;
  36. a->dataout_timeout = NA_DATAOUT_TIMEOUT;
  37. a->dataout_timeout_retries = NA_DATAOUT_TIMEOUT_RETRIES;
  38. a->nopin_timeout = NA_NOPIN_TIMEOUT;
  39. a->nopin_response_timeout = NA_NOPIN_RESPONSE_TIMEOUT;
  40. a->random_datain_pdu_offsets = NA_RANDOM_DATAIN_PDU_OFFSETS;
  41. a->random_datain_seq_offsets = NA_RANDOM_DATAIN_SEQ_OFFSETS;
  42. a->random_r2t_offsets = NA_RANDOM_R2T_OFFSETS;
  43. a->default_erl = NA_DEFAULT_ERL;
  44. }
  45. int iscsit_na_dataout_timeout(
  46. struct iscsi_node_acl *acl,
  47. u32 dataout_timeout)
  48. {
  49. struct iscsi_node_attrib *a = &acl->node_attrib;
  50. if (dataout_timeout > NA_DATAOUT_TIMEOUT_MAX) {
  51. pr_err("Requested DataOut Timeout %u larger than"
  52. " maximum %u\n", dataout_timeout,
  53. NA_DATAOUT_TIMEOUT_MAX);
  54. return -EINVAL;
  55. } else if (dataout_timeout < NA_DATAOUT_TIMEOUT_MIX) {
  56. pr_err("Requested DataOut Timeout %u smaller than"
  57. " minimum %u\n", dataout_timeout,
  58. NA_DATAOUT_TIMEOUT_MIX);
  59. return -EINVAL;
  60. }
  61. a->dataout_timeout = dataout_timeout;
  62. pr_debug("Set DataOut Timeout to %u for Initiator Node"
  63. " %s\n", a->dataout_timeout, iscsit_na_get_initiatorname(acl));
  64. return 0;
  65. }
  66. int iscsit_na_dataout_timeout_retries(
  67. struct iscsi_node_acl *acl,
  68. u32 dataout_timeout_retries)
  69. {
  70. struct iscsi_node_attrib *a = &acl->node_attrib;
  71. if (dataout_timeout_retries > NA_DATAOUT_TIMEOUT_RETRIES_MAX) {
  72. pr_err("Requested DataOut Timeout Retries %u larger"
  73. " than maximum %u", dataout_timeout_retries,
  74. NA_DATAOUT_TIMEOUT_RETRIES_MAX);
  75. return -EINVAL;
  76. } else if (dataout_timeout_retries < NA_DATAOUT_TIMEOUT_RETRIES_MIN) {
  77. pr_err("Requested DataOut Timeout Retries %u smaller"
  78. " than minimum %u", dataout_timeout_retries,
  79. NA_DATAOUT_TIMEOUT_RETRIES_MIN);
  80. return -EINVAL;
  81. }
  82. a->dataout_timeout_retries = dataout_timeout_retries;
  83. pr_debug("Set DataOut Timeout Retries to %u for"
  84. " Initiator Node %s\n", a->dataout_timeout_retries,
  85. iscsit_na_get_initiatorname(acl));
  86. return 0;
  87. }
  88. int iscsit_na_nopin_timeout(
  89. struct iscsi_node_acl *acl,
  90. u32 nopin_timeout)
  91. {
  92. struct iscsi_node_attrib *a = &acl->node_attrib;
  93. struct iscsi_session *sess;
  94. struct iscsi_conn *conn;
  95. struct se_node_acl *se_nacl = &a->nacl->se_node_acl;
  96. struct se_session *se_sess;
  97. u32 orig_nopin_timeout = a->nopin_timeout;
  98. if (nopin_timeout > NA_NOPIN_TIMEOUT_MAX) {
  99. pr_err("Requested NopIn Timeout %u larger than maximum"
  100. " %u\n", nopin_timeout, NA_NOPIN_TIMEOUT_MAX);
  101. return -EINVAL;
  102. } else if ((nopin_timeout < NA_NOPIN_TIMEOUT_MIN) &&
  103. (nopin_timeout != 0)) {
  104. pr_err("Requested NopIn Timeout %u smaller than"
  105. " minimum %u and not 0\n", nopin_timeout,
  106. NA_NOPIN_TIMEOUT_MIN);
  107. return -EINVAL;
  108. }
  109. a->nopin_timeout = nopin_timeout;
  110. pr_debug("Set NopIn Timeout to %u for Initiator"
  111. " Node %s\n", a->nopin_timeout,
  112. iscsit_na_get_initiatorname(acl));
  113. /*
  114. * Reenable disabled nopin_timeout timer for all iSCSI connections.
  115. */
  116. if (!orig_nopin_timeout) {
  117. spin_lock_bh(&se_nacl->nacl_sess_lock);
  118. se_sess = se_nacl->nacl_sess;
  119. if (se_sess) {
  120. sess = se_sess->fabric_sess_ptr;
  121. spin_lock(&sess->conn_lock);
  122. list_for_each_entry(conn, &sess->sess_conn_list,
  123. conn_list) {
  124. if (conn->conn_state !=
  125. TARG_CONN_STATE_LOGGED_IN)
  126. continue;
  127. spin_lock(&conn->nopin_timer_lock);
  128. __iscsit_start_nopin_timer(conn);
  129. spin_unlock(&conn->nopin_timer_lock);
  130. }
  131. spin_unlock(&sess->conn_lock);
  132. }
  133. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  134. }
  135. return 0;
  136. }
  137. int iscsit_na_nopin_response_timeout(
  138. struct iscsi_node_acl *acl,
  139. u32 nopin_response_timeout)
  140. {
  141. struct iscsi_node_attrib *a = &acl->node_attrib;
  142. if (nopin_response_timeout > NA_NOPIN_RESPONSE_TIMEOUT_MAX) {
  143. pr_err("Requested NopIn Response Timeout %u larger"
  144. " than maximum %u\n", nopin_response_timeout,
  145. NA_NOPIN_RESPONSE_TIMEOUT_MAX);
  146. return -EINVAL;
  147. } else if (nopin_response_timeout < NA_NOPIN_RESPONSE_TIMEOUT_MIN) {
  148. pr_err("Requested NopIn Response Timeout %u smaller"
  149. " than minimum %u\n", nopin_response_timeout,
  150. NA_NOPIN_RESPONSE_TIMEOUT_MIN);
  151. return -EINVAL;
  152. }
  153. a->nopin_response_timeout = nopin_response_timeout;
  154. pr_debug("Set NopIn Response Timeout to %u for"
  155. " Initiator Node %s\n", a->nopin_timeout,
  156. iscsit_na_get_initiatorname(acl));
  157. return 0;
  158. }
  159. int iscsit_na_random_datain_pdu_offsets(
  160. struct iscsi_node_acl *acl,
  161. u32 random_datain_pdu_offsets)
  162. {
  163. struct iscsi_node_attrib *a = &acl->node_attrib;
  164. if (random_datain_pdu_offsets != 0 && random_datain_pdu_offsets != 1) {
  165. pr_err("Requested Random DataIN PDU Offsets: %u not"
  166. " 0 or 1\n", random_datain_pdu_offsets);
  167. return -EINVAL;
  168. }
  169. a->random_datain_pdu_offsets = random_datain_pdu_offsets;
  170. pr_debug("Set Random DataIN PDU Offsets to %u for"
  171. " Initiator Node %s\n", a->random_datain_pdu_offsets,
  172. iscsit_na_get_initiatorname(acl));
  173. return 0;
  174. }
  175. int iscsit_na_random_datain_seq_offsets(
  176. struct iscsi_node_acl *acl,
  177. u32 random_datain_seq_offsets)
  178. {
  179. struct iscsi_node_attrib *a = &acl->node_attrib;
  180. if (random_datain_seq_offsets != 0 && random_datain_seq_offsets != 1) {
  181. pr_err("Requested Random DataIN Sequence Offsets: %u"
  182. " not 0 or 1\n", random_datain_seq_offsets);
  183. return -EINVAL;
  184. }
  185. a->random_datain_seq_offsets = random_datain_seq_offsets;
  186. pr_debug("Set Random DataIN Sequence Offsets to %u for"
  187. " Initiator Node %s\n", a->random_datain_seq_offsets,
  188. iscsit_na_get_initiatorname(acl));
  189. return 0;
  190. }
  191. int iscsit_na_random_r2t_offsets(
  192. struct iscsi_node_acl *acl,
  193. u32 random_r2t_offsets)
  194. {
  195. struct iscsi_node_attrib *a = &acl->node_attrib;
  196. if (random_r2t_offsets != 0 && random_r2t_offsets != 1) {
  197. pr_err("Requested Random R2T Offsets: %u not"
  198. " 0 or 1\n", random_r2t_offsets);
  199. return -EINVAL;
  200. }
  201. a->random_r2t_offsets = random_r2t_offsets;
  202. pr_debug("Set Random R2T Offsets to %u for"
  203. " Initiator Node %s\n", a->random_r2t_offsets,
  204. iscsit_na_get_initiatorname(acl));
  205. return 0;
  206. }
  207. int iscsit_na_default_erl(
  208. struct iscsi_node_acl *acl,
  209. u32 default_erl)
  210. {
  211. struct iscsi_node_attrib *a = &acl->node_attrib;
  212. if (default_erl != 0 && default_erl != 1 && default_erl != 2) {
  213. pr_err("Requested default ERL: %u not 0, 1, or 2\n",
  214. default_erl);
  215. return -EINVAL;
  216. }
  217. a->default_erl = default_erl;
  218. pr_debug("Set use ERL0 flag to %u for Initiator"
  219. " Node %s\n", a->default_erl,
  220. iscsit_na_get_initiatorname(acl));
  221. return 0;
  222. }