iscsi_target_nodeattrib.c 7.5 KB

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