iscsi_target_nodeattrib.c 7.7 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 <target/target_core_transport.h>
  22. #include "iscsi_target_core.h"
  23. #include "iscsi_target_device.h"
  24. #include "iscsi_target_tpg.h"
  25. #include "iscsi_target_util.h"
  26. #include "iscsi_target_nodeattrib.h"
  27. static inline char *iscsit_na_get_initiatorname(
  28. struct iscsi_node_acl *nacl)
  29. {
  30. struct se_node_acl *se_nacl = &nacl->se_node_acl;
  31. return &se_nacl->initiatorname[0];
  32. }
  33. void iscsit_set_default_node_attribues(
  34. struct iscsi_node_acl *acl)
  35. {
  36. struct iscsi_node_attrib *a = &acl->node_attrib;
  37. a->dataout_timeout = NA_DATAOUT_TIMEOUT;
  38. a->dataout_timeout_retries = NA_DATAOUT_TIMEOUT_RETRIES;
  39. a->nopin_timeout = NA_NOPIN_TIMEOUT;
  40. a->nopin_response_timeout = NA_NOPIN_RESPONSE_TIMEOUT;
  41. a->random_datain_pdu_offsets = NA_RANDOM_DATAIN_PDU_OFFSETS;
  42. a->random_datain_seq_offsets = NA_RANDOM_DATAIN_SEQ_OFFSETS;
  43. a->random_r2t_offsets = NA_RANDOM_R2T_OFFSETS;
  44. a->default_erl = NA_DEFAULT_ERL;
  45. }
  46. extern int iscsit_na_dataout_timeout(
  47. struct iscsi_node_acl *acl,
  48. u32 dataout_timeout)
  49. {
  50. struct iscsi_node_attrib *a = &acl->node_attrib;
  51. if (dataout_timeout > NA_DATAOUT_TIMEOUT_MAX) {
  52. pr_err("Requested DataOut Timeout %u larger than"
  53. " maximum %u\n", dataout_timeout,
  54. NA_DATAOUT_TIMEOUT_MAX);
  55. return -EINVAL;
  56. } else if (dataout_timeout < NA_DATAOUT_TIMEOUT_MIX) {
  57. pr_err("Requested DataOut Timeout %u smaller than"
  58. " minimum %u\n", dataout_timeout,
  59. NA_DATAOUT_TIMEOUT_MIX);
  60. return -EINVAL;
  61. }
  62. a->dataout_timeout = dataout_timeout;
  63. pr_debug("Set DataOut Timeout to %u for Initiator Node"
  64. " %s\n", a->dataout_timeout, iscsit_na_get_initiatorname(acl));
  65. return 0;
  66. }
  67. extern int iscsit_na_dataout_timeout_retries(
  68. struct iscsi_node_acl *acl,
  69. u32 dataout_timeout_retries)
  70. {
  71. struct iscsi_node_attrib *a = &acl->node_attrib;
  72. if (dataout_timeout_retries > NA_DATAOUT_TIMEOUT_RETRIES_MAX) {
  73. pr_err("Requested DataOut Timeout Retries %u larger"
  74. " than maximum %u", dataout_timeout_retries,
  75. NA_DATAOUT_TIMEOUT_RETRIES_MAX);
  76. return -EINVAL;
  77. } else if (dataout_timeout_retries < NA_DATAOUT_TIMEOUT_RETRIES_MIN) {
  78. pr_err("Requested DataOut Timeout Retries %u smaller"
  79. " than minimum %u", dataout_timeout_retries,
  80. NA_DATAOUT_TIMEOUT_RETRIES_MIN);
  81. return -EINVAL;
  82. }
  83. a->dataout_timeout_retries = dataout_timeout_retries;
  84. pr_debug("Set DataOut Timeout Retries to %u for"
  85. " Initiator Node %s\n", a->dataout_timeout_retries,
  86. iscsit_na_get_initiatorname(acl));
  87. return 0;
  88. }
  89. extern int iscsit_na_nopin_timeout(
  90. struct iscsi_node_acl *acl,
  91. u32 nopin_timeout)
  92. {
  93. struct iscsi_node_attrib *a = &acl->node_attrib;
  94. struct iscsi_session *sess;
  95. struct iscsi_conn *conn;
  96. struct se_node_acl *se_nacl = &a->nacl->se_node_acl;
  97. struct se_session *se_sess;
  98. u32 orig_nopin_timeout = a->nopin_timeout;
  99. if (nopin_timeout > NA_NOPIN_TIMEOUT_MAX) {
  100. pr_err("Requested NopIn Timeout %u larger than maximum"
  101. " %u\n", nopin_timeout, NA_NOPIN_TIMEOUT_MAX);
  102. return -EINVAL;
  103. } else if ((nopin_timeout < NA_NOPIN_TIMEOUT_MIN) &&
  104. (nopin_timeout != 0)) {
  105. pr_err("Requested NopIn Timeout %u smaller than"
  106. " minimum %u and not 0\n", nopin_timeout,
  107. NA_NOPIN_TIMEOUT_MIN);
  108. return -EINVAL;
  109. }
  110. a->nopin_timeout = nopin_timeout;
  111. pr_debug("Set NopIn Timeout to %u for Initiator"
  112. " Node %s\n", a->nopin_timeout,
  113. iscsit_na_get_initiatorname(acl));
  114. /*
  115. * Reenable disabled nopin_timeout timer for all iSCSI connections.
  116. */
  117. if (!orig_nopin_timeout) {
  118. spin_lock_bh(&se_nacl->nacl_sess_lock);
  119. se_sess = se_nacl->nacl_sess;
  120. if (se_sess) {
  121. sess = (struct iscsi_session *)se_sess->fabric_sess_ptr;
  122. spin_lock(&sess->conn_lock);
  123. list_for_each_entry(conn, &sess->sess_conn_list,
  124. conn_list) {
  125. if (conn->conn_state !=
  126. TARG_CONN_STATE_LOGGED_IN)
  127. continue;
  128. spin_lock(&conn->nopin_timer_lock);
  129. __iscsit_start_nopin_timer(conn);
  130. spin_unlock(&conn->nopin_timer_lock);
  131. }
  132. spin_unlock(&sess->conn_lock);
  133. }
  134. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  135. }
  136. return 0;
  137. }
  138. extern int iscsit_na_nopin_response_timeout(
  139. struct iscsi_node_acl *acl,
  140. u32 nopin_response_timeout)
  141. {
  142. struct iscsi_node_attrib *a = &acl->node_attrib;
  143. if (nopin_response_timeout > NA_NOPIN_RESPONSE_TIMEOUT_MAX) {
  144. pr_err("Requested NopIn Response Timeout %u larger"
  145. " than maximum %u\n", nopin_response_timeout,
  146. NA_NOPIN_RESPONSE_TIMEOUT_MAX);
  147. return -EINVAL;
  148. } else if (nopin_response_timeout < NA_NOPIN_RESPONSE_TIMEOUT_MIN) {
  149. pr_err("Requested NopIn Response Timeout %u smaller"
  150. " than minimum %u\n", nopin_response_timeout,
  151. NA_NOPIN_RESPONSE_TIMEOUT_MIN);
  152. return -EINVAL;
  153. }
  154. a->nopin_response_timeout = nopin_response_timeout;
  155. pr_debug("Set NopIn Response Timeout to %u for"
  156. " Initiator Node %s\n", a->nopin_timeout,
  157. iscsit_na_get_initiatorname(acl));
  158. return 0;
  159. }
  160. extern int iscsit_na_random_datain_pdu_offsets(
  161. struct iscsi_node_acl *acl,
  162. u32 random_datain_pdu_offsets)
  163. {
  164. struct iscsi_node_attrib *a = &acl->node_attrib;
  165. if (random_datain_pdu_offsets != 0 && random_datain_pdu_offsets != 1) {
  166. pr_err("Requested Random DataIN PDU Offsets: %u not"
  167. " 0 or 1\n", random_datain_pdu_offsets);
  168. return -EINVAL;
  169. }
  170. a->random_datain_pdu_offsets = random_datain_pdu_offsets;
  171. pr_debug("Set Random DataIN PDU Offsets to %u for"
  172. " Initiator Node %s\n", a->random_datain_pdu_offsets,
  173. iscsit_na_get_initiatorname(acl));
  174. return 0;
  175. }
  176. extern int iscsit_na_random_datain_seq_offsets(
  177. struct iscsi_node_acl *acl,
  178. u32 random_datain_seq_offsets)
  179. {
  180. struct iscsi_node_attrib *a = &acl->node_attrib;
  181. if (random_datain_seq_offsets != 0 && random_datain_seq_offsets != 1) {
  182. pr_err("Requested Random DataIN Sequence Offsets: %u"
  183. " not 0 or 1\n", random_datain_seq_offsets);
  184. return -EINVAL;
  185. }
  186. a->random_datain_seq_offsets = random_datain_seq_offsets;
  187. pr_debug("Set Random DataIN Sequence Offsets to %u for"
  188. " Initiator Node %s\n", a->random_datain_seq_offsets,
  189. iscsit_na_get_initiatorname(acl));
  190. return 0;
  191. }
  192. extern int iscsit_na_random_r2t_offsets(
  193. struct iscsi_node_acl *acl,
  194. u32 random_r2t_offsets)
  195. {
  196. struct iscsi_node_attrib *a = &acl->node_attrib;
  197. if (random_r2t_offsets != 0 && random_r2t_offsets != 1) {
  198. pr_err("Requested Random R2T Offsets: %u not"
  199. " 0 or 1\n", random_r2t_offsets);
  200. return -EINVAL;
  201. }
  202. a->random_r2t_offsets = random_r2t_offsets;
  203. pr_debug("Set Random R2T Offsets to %u for"
  204. " Initiator Node %s\n", a->random_r2t_offsets,
  205. iscsit_na_get_initiatorname(acl));
  206. return 0;
  207. }
  208. extern int iscsit_na_default_erl(
  209. struct iscsi_node_acl *acl,
  210. u32 default_erl)
  211. {
  212. struct iscsi_node_attrib *a = &acl->node_attrib;
  213. if (default_erl != 0 && default_erl != 1 && default_erl != 2) {
  214. pr_err("Requested default ERL: %u not 0, 1, or 2\n",
  215. default_erl);
  216. return -EINVAL;
  217. }
  218. a->default_erl = default_erl;
  219. pr_debug("Set use ERL0 flag to %u for Initiator"
  220. " Node %s\n", a->default_erl,
  221. iscsit_na_get_initiatorname(acl));
  222. return 0;
  223. }