iscsi_target_configfs.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. /*******************************************************************************
  2. * This file contains the configfs implementation for iSCSI Target mode
  3. * from the LIO-Target Project.
  4. *
  5. * (c) Copyright 2007-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/ctype.h>
  21. #include <linux/export.h>
  22. #include <linux/inet.h>
  23. #include <target/target_core_base.h>
  24. #include <target/target_core_fabric.h>
  25. #include <target/iscsi/iscsi_transport.h>
  26. #include <target/iscsi/iscsi_target_core.h>
  27. #include "iscsi_target_parameters.h"
  28. #include "iscsi_target_device.h"
  29. #include "iscsi_target_erl0.h"
  30. #include "iscsi_target_nodeattrib.h"
  31. #include "iscsi_target_tpg.h"
  32. #include "iscsi_target_util.h"
  33. #include "iscsi_target.h"
  34. #include <target/iscsi/iscsi_target_stat.h>
  35. /* Start items for lio_target_portal_cit */
  36. static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
  37. {
  38. return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
  39. }
  40. static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page)
  41. {
  42. struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
  43. struct iscsi_tpg_np *tpg_np_sctp;
  44. ssize_t rb;
  45. tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
  46. if (tpg_np_sctp)
  47. rb = sprintf(page, "1\n");
  48. else
  49. rb = sprintf(page, "0\n");
  50. return rb;
  51. }
  52. static ssize_t lio_target_np_sctp_store(struct config_item *item,
  53. const char *page, size_t count)
  54. {
  55. struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
  56. struct iscsi_np *np;
  57. struct iscsi_portal_group *tpg;
  58. struct iscsi_tpg_np *tpg_np_sctp = NULL;
  59. u32 op;
  60. int ret;
  61. ret = kstrtou32(page, 0, &op);
  62. if (ret)
  63. return ret;
  64. if ((op != 1) && (op != 0)) {
  65. pr_err("Illegal value for tpg_enable: %u\n", op);
  66. return -EINVAL;
  67. }
  68. np = tpg_np->tpg_np;
  69. if (!np) {
  70. pr_err("Unable to locate struct iscsi_np from"
  71. " struct iscsi_tpg_np\n");
  72. return -EINVAL;
  73. }
  74. tpg = tpg_np->tpg;
  75. if (iscsit_get_tpg(tpg) < 0)
  76. return -EINVAL;
  77. if (op) {
  78. /*
  79. * Use existing np->np_sockaddr for SCTP network portal reference
  80. */
  81. tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
  82. tpg_np, ISCSI_SCTP_TCP);
  83. if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
  84. goto out;
  85. } else {
  86. tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
  87. if (!tpg_np_sctp)
  88. goto out;
  89. ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
  90. if (ret < 0)
  91. goto out;
  92. }
  93. iscsit_put_tpg(tpg);
  94. return count;
  95. out:
  96. iscsit_put_tpg(tpg);
  97. return -EINVAL;
  98. }
  99. static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
  100. {
  101. struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
  102. struct iscsi_tpg_np *tpg_np_iser;
  103. ssize_t rb;
  104. tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
  105. if (tpg_np_iser)
  106. rb = sprintf(page, "1\n");
  107. else
  108. rb = sprintf(page, "0\n");
  109. return rb;
  110. }
  111. static ssize_t lio_target_np_iser_store(struct config_item *item,
  112. const char *page, size_t count)
  113. {
  114. struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
  115. struct iscsi_np *np;
  116. struct iscsi_portal_group *tpg;
  117. struct iscsi_tpg_np *tpg_np_iser = NULL;
  118. char *endptr;
  119. u32 op;
  120. int rc = 0;
  121. op = simple_strtoul(page, &endptr, 0);
  122. if ((op != 1) && (op != 0)) {
  123. pr_err("Illegal value for tpg_enable: %u\n", op);
  124. return -EINVAL;
  125. }
  126. np = tpg_np->tpg_np;
  127. if (!np) {
  128. pr_err("Unable to locate struct iscsi_np from"
  129. " struct iscsi_tpg_np\n");
  130. return -EINVAL;
  131. }
  132. tpg = tpg_np->tpg;
  133. if (iscsit_get_tpg(tpg) < 0)
  134. return -EINVAL;
  135. if (op) {
  136. rc = request_module("ib_isert");
  137. if (rc != 0) {
  138. pr_warn("Unable to request_module for ib_isert\n");
  139. rc = 0;
  140. }
  141. tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
  142. tpg_np, ISCSI_INFINIBAND);
  143. if (IS_ERR(tpg_np_iser)) {
  144. rc = PTR_ERR(tpg_np_iser);
  145. goto out;
  146. }
  147. } else {
  148. tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
  149. if (tpg_np_iser) {
  150. rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
  151. if (rc < 0)
  152. goto out;
  153. }
  154. }
  155. iscsit_put_tpg(tpg);
  156. return count;
  157. out:
  158. iscsit_put_tpg(tpg);
  159. return rc;
  160. }
  161. CONFIGFS_ATTR(lio_target_np_, sctp);
  162. CONFIGFS_ATTR(lio_target_np_, iser);
  163. static struct configfs_attribute *lio_target_portal_attrs[] = {
  164. &lio_target_np_attr_sctp,
  165. &lio_target_np_attr_iser,
  166. NULL,
  167. };
  168. /* Stop items for lio_target_portal_cit */
  169. /* Start items for lio_target_np_cit */
  170. #define MAX_PORTAL_LEN 256
  171. static struct se_tpg_np *lio_target_call_addnptotpg(
  172. struct se_portal_group *se_tpg,
  173. struct config_group *group,
  174. const char *name)
  175. {
  176. struct iscsi_portal_group *tpg;
  177. struct iscsi_tpg_np *tpg_np;
  178. char *str, *str2, *ip_str, *port_str;
  179. struct sockaddr_storage sockaddr;
  180. struct sockaddr_in *sock_in;
  181. struct sockaddr_in6 *sock_in6;
  182. unsigned long port;
  183. int ret;
  184. char buf[MAX_PORTAL_LEN + 1];
  185. if (strlen(name) > MAX_PORTAL_LEN) {
  186. pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
  187. (int)strlen(name), MAX_PORTAL_LEN);
  188. return ERR_PTR(-EOVERFLOW);
  189. }
  190. memset(buf, 0, MAX_PORTAL_LEN + 1);
  191. snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
  192. memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
  193. str = strstr(buf, "[");
  194. if (str) {
  195. const char *end;
  196. str2 = strstr(str, "]");
  197. if (!str2) {
  198. pr_err("Unable to locate trailing \"]\""
  199. " in IPv6 iSCSI network portal address\n");
  200. return ERR_PTR(-EINVAL);
  201. }
  202. str++; /* Skip over leading "[" */
  203. *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
  204. str2++; /* Skip over the \0 */
  205. port_str = strstr(str2, ":");
  206. if (!port_str) {
  207. pr_err("Unable to locate \":port\""
  208. " in IPv6 iSCSI network portal address\n");
  209. return ERR_PTR(-EINVAL);
  210. }
  211. *port_str = '\0'; /* Terminate string for IP */
  212. port_str++; /* Skip over ":" */
  213. ret = kstrtoul(port_str, 0, &port);
  214. if (ret < 0) {
  215. pr_err("kstrtoul() failed for port_str: %d\n", ret);
  216. return ERR_PTR(ret);
  217. }
  218. sock_in6 = (struct sockaddr_in6 *)&sockaddr;
  219. sock_in6->sin6_family = AF_INET6;
  220. sock_in6->sin6_port = htons((unsigned short)port);
  221. ret = in6_pton(str, -1,
  222. (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
  223. if (ret <= 0) {
  224. pr_err("in6_pton returned: %d\n", ret);
  225. return ERR_PTR(-EINVAL);
  226. }
  227. } else {
  228. str = ip_str = &buf[0];
  229. port_str = strstr(ip_str, ":");
  230. if (!port_str) {
  231. pr_err("Unable to locate \":port\""
  232. " in IPv4 iSCSI network portal address\n");
  233. return ERR_PTR(-EINVAL);
  234. }
  235. *port_str = '\0'; /* Terminate string for IP */
  236. port_str++; /* Skip over ":" */
  237. ret = kstrtoul(port_str, 0, &port);
  238. if (ret < 0) {
  239. pr_err("kstrtoul() failed for port_str: %d\n", ret);
  240. return ERR_PTR(ret);
  241. }
  242. sock_in = (struct sockaddr_in *)&sockaddr;
  243. sock_in->sin_family = AF_INET;
  244. sock_in->sin_port = htons((unsigned short)port);
  245. sock_in->sin_addr.s_addr = in_aton(ip_str);
  246. }
  247. tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
  248. ret = iscsit_get_tpg(tpg);
  249. if (ret < 0)
  250. return ERR_PTR(-EINVAL);
  251. pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
  252. " PORTAL: %s\n",
  253. config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
  254. tpg->tpgt, name);
  255. /*
  256. * Assume ISCSI_TCP by default. Other network portals for other
  257. * iSCSI fabrics:
  258. *
  259. * Traditional iSCSI over SCTP (initial support)
  260. * iSER/TCP (TODO, hardware available)
  261. * iSER/SCTP (TODO, software emulation with osc-iwarp)
  262. * iSER/IB (TODO, hardware available)
  263. *
  264. * can be enabled with attributes under
  265. * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
  266. *
  267. */
  268. tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
  269. ISCSI_TCP);
  270. if (IS_ERR(tpg_np)) {
  271. iscsit_put_tpg(tpg);
  272. return ERR_CAST(tpg_np);
  273. }
  274. pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
  275. iscsit_put_tpg(tpg);
  276. return &tpg_np->se_tpg_np;
  277. }
  278. static void lio_target_call_delnpfromtpg(
  279. struct se_tpg_np *se_tpg_np)
  280. {
  281. struct iscsi_portal_group *tpg;
  282. struct iscsi_tpg_np *tpg_np;
  283. struct se_portal_group *se_tpg;
  284. int ret;
  285. tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
  286. tpg = tpg_np->tpg;
  287. ret = iscsit_get_tpg(tpg);
  288. if (ret < 0)
  289. return;
  290. se_tpg = &tpg->tpg_se_tpg;
  291. pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
  292. " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
  293. tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
  294. ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
  295. if (ret < 0)
  296. goto out;
  297. pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
  298. out:
  299. iscsit_put_tpg(tpg);
  300. }
  301. /* End items for lio_target_np_cit */
  302. /* Start items for lio_target_nacl_attrib_cit */
  303. #define ISCSI_NACL_ATTR(name) \
  304. static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
  305. char *page) \
  306. { \
  307. struct se_node_acl *se_nacl = attrib_to_nacl(item); \
  308. struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
  309. se_node_acl); \
  310. \
  311. return sprintf(page, "%u\n", nacl->node_attrib.name); \
  312. } \
  313. \
  314. static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
  315. const char *page, size_t count) \
  316. { \
  317. struct se_node_acl *se_nacl = attrib_to_nacl(item); \
  318. struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
  319. se_node_acl); \
  320. u32 val; \
  321. int ret; \
  322. \
  323. ret = kstrtou32(page, 0, &val); \
  324. if (ret) \
  325. return ret; \
  326. ret = iscsit_na_##name(nacl, val); \
  327. if (ret < 0) \
  328. return ret; \
  329. \
  330. return count; \
  331. } \
  332. \
  333. CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
  334. ISCSI_NACL_ATTR(dataout_timeout);
  335. ISCSI_NACL_ATTR(dataout_timeout_retries);
  336. ISCSI_NACL_ATTR(default_erl);
  337. ISCSI_NACL_ATTR(nopin_timeout);
  338. ISCSI_NACL_ATTR(nopin_response_timeout);
  339. ISCSI_NACL_ATTR(random_datain_pdu_offsets);
  340. ISCSI_NACL_ATTR(random_datain_seq_offsets);
  341. ISCSI_NACL_ATTR(random_r2t_offsets);
  342. static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
  343. &iscsi_nacl_attrib_attr_dataout_timeout,
  344. &iscsi_nacl_attrib_attr_dataout_timeout_retries,
  345. &iscsi_nacl_attrib_attr_default_erl,
  346. &iscsi_nacl_attrib_attr_nopin_timeout,
  347. &iscsi_nacl_attrib_attr_nopin_response_timeout,
  348. &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
  349. &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
  350. &iscsi_nacl_attrib_attr_random_r2t_offsets,
  351. NULL,
  352. };
  353. /* End items for lio_target_nacl_attrib_cit */
  354. /* Start items for lio_target_nacl_auth_cit */
  355. #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
  356. static ssize_t __iscsi_##prefix##_##name##_show( \
  357. struct iscsi_node_acl *nacl, \
  358. char *page) \
  359. { \
  360. struct iscsi_node_auth *auth = &nacl->node_auth; \
  361. \
  362. if (!capable(CAP_SYS_ADMIN)) \
  363. return -EPERM; \
  364. return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
  365. } \
  366. \
  367. static ssize_t __iscsi_##prefix##_##name##_store( \
  368. struct iscsi_node_acl *nacl, \
  369. const char *page, \
  370. size_t count) \
  371. { \
  372. struct iscsi_node_auth *auth = &nacl->node_auth; \
  373. \
  374. if (!capable(CAP_SYS_ADMIN)) \
  375. return -EPERM; \
  376. if (count >= sizeof(auth->name)) \
  377. return -EINVAL; \
  378. snprintf(auth->name, sizeof(auth->name), "%s", page); \
  379. if (!strncmp("NULL", auth->name, 4)) \
  380. auth->naf_flags &= ~flags; \
  381. else \
  382. auth->naf_flags |= flags; \
  383. \
  384. if ((auth->naf_flags & NAF_USERID_IN_SET) && \
  385. (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
  386. auth->authenticate_target = 1; \
  387. else \
  388. auth->authenticate_target = 0; \
  389. \
  390. return count; \
  391. }
  392. #define DEF_NACL_AUTH_STR(name, flags) \
  393. __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
  394. static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
  395. char *page) \
  396. { \
  397. struct se_node_acl *nacl = auth_to_nacl(item); \
  398. return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
  399. struct iscsi_node_acl, se_node_acl), page); \
  400. } \
  401. static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
  402. const char *page, size_t count) \
  403. { \
  404. struct se_node_acl *nacl = auth_to_nacl(item); \
  405. return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
  406. struct iscsi_node_acl, se_node_acl), page, count); \
  407. } \
  408. \
  409. CONFIGFS_ATTR(iscsi_nacl_auth_, name)
  410. /*
  411. * One-way authentication userid
  412. */
  413. DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
  414. DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
  415. DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
  416. DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
  417. #define __DEF_NACL_AUTH_INT(prefix, name) \
  418. static ssize_t __iscsi_##prefix##_##name##_show( \
  419. struct iscsi_node_acl *nacl, \
  420. char *page) \
  421. { \
  422. struct iscsi_node_auth *auth = &nacl->node_auth; \
  423. \
  424. if (!capable(CAP_SYS_ADMIN)) \
  425. return -EPERM; \
  426. \
  427. return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
  428. }
  429. #define DEF_NACL_AUTH_INT(name) \
  430. __DEF_NACL_AUTH_INT(nacl_auth, name) \
  431. static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
  432. char *page) \
  433. { \
  434. struct se_node_acl *nacl = auth_to_nacl(item); \
  435. return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
  436. struct iscsi_node_acl, se_node_acl), page); \
  437. } \
  438. \
  439. CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
  440. DEF_NACL_AUTH_INT(authenticate_target);
  441. static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
  442. &iscsi_nacl_auth_attr_userid,
  443. &iscsi_nacl_auth_attr_password,
  444. &iscsi_nacl_auth_attr_authenticate_target,
  445. &iscsi_nacl_auth_attr_userid_mutual,
  446. &iscsi_nacl_auth_attr_password_mutual,
  447. NULL,
  448. };
  449. /* End items for lio_target_nacl_auth_cit */
  450. /* Start items for lio_target_nacl_param_cit */
  451. #define ISCSI_NACL_PARAM(name) \
  452. static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
  453. char *page) \
  454. { \
  455. struct se_node_acl *se_nacl = param_to_nacl(item); \
  456. struct iscsi_session *sess; \
  457. struct se_session *se_sess; \
  458. ssize_t rb; \
  459. \
  460. spin_lock_bh(&se_nacl->nacl_sess_lock); \
  461. se_sess = se_nacl->nacl_sess; \
  462. if (!se_sess) { \
  463. rb = snprintf(page, PAGE_SIZE, \
  464. "No Active iSCSI Session\n"); \
  465. } else { \
  466. sess = se_sess->fabric_sess_ptr; \
  467. rb = snprintf(page, PAGE_SIZE, "%u\n", \
  468. (u32)sess->sess_ops->name); \
  469. } \
  470. spin_unlock_bh(&se_nacl->nacl_sess_lock); \
  471. \
  472. return rb; \
  473. } \
  474. \
  475. CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
  476. ISCSI_NACL_PARAM(MaxConnections);
  477. ISCSI_NACL_PARAM(InitialR2T);
  478. ISCSI_NACL_PARAM(ImmediateData);
  479. ISCSI_NACL_PARAM(MaxBurstLength);
  480. ISCSI_NACL_PARAM(FirstBurstLength);
  481. ISCSI_NACL_PARAM(DefaultTime2Wait);
  482. ISCSI_NACL_PARAM(DefaultTime2Retain);
  483. ISCSI_NACL_PARAM(MaxOutstandingR2T);
  484. ISCSI_NACL_PARAM(DataPDUInOrder);
  485. ISCSI_NACL_PARAM(DataSequenceInOrder);
  486. ISCSI_NACL_PARAM(ErrorRecoveryLevel);
  487. static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
  488. &iscsi_nacl_param_attr_MaxConnections,
  489. &iscsi_nacl_param_attr_InitialR2T,
  490. &iscsi_nacl_param_attr_ImmediateData,
  491. &iscsi_nacl_param_attr_MaxBurstLength,
  492. &iscsi_nacl_param_attr_FirstBurstLength,
  493. &iscsi_nacl_param_attr_DefaultTime2Wait,
  494. &iscsi_nacl_param_attr_DefaultTime2Retain,
  495. &iscsi_nacl_param_attr_MaxOutstandingR2T,
  496. &iscsi_nacl_param_attr_DataPDUInOrder,
  497. &iscsi_nacl_param_attr_DataSequenceInOrder,
  498. &iscsi_nacl_param_attr_ErrorRecoveryLevel,
  499. NULL,
  500. };
  501. /* End items for lio_target_nacl_param_cit */
  502. /* Start items for lio_target_acl_cit */
  503. static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
  504. {
  505. struct se_node_acl *se_nacl = acl_to_nacl(item);
  506. struct iscsi_session *sess;
  507. struct iscsi_conn *conn;
  508. struct se_session *se_sess;
  509. ssize_t rb = 0;
  510. u32 max_cmd_sn;
  511. spin_lock_bh(&se_nacl->nacl_sess_lock);
  512. se_sess = se_nacl->nacl_sess;
  513. if (!se_sess) {
  514. rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
  515. " Endpoint: %s\n", se_nacl->initiatorname);
  516. } else {
  517. sess = se_sess->fabric_sess_ptr;
  518. rb += sprintf(page+rb, "InitiatorName: %s\n",
  519. sess->sess_ops->InitiatorName);
  520. rb += sprintf(page+rb, "InitiatorAlias: %s\n",
  521. sess->sess_ops->InitiatorAlias);
  522. rb += sprintf(page+rb,
  523. "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
  524. sess->sid, sess->isid, sess->tsih);
  525. rb += sprintf(page+rb, "SessionType: %s\n",
  526. (sess->sess_ops->SessionType) ?
  527. "Discovery" : "Normal");
  528. rb += sprintf(page+rb, "Session State: ");
  529. switch (sess->session_state) {
  530. case TARG_SESS_STATE_FREE:
  531. rb += sprintf(page+rb, "TARG_SESS_FREE\n");
  532. break;
  533. case TARG_SESS_STATE_ACTIVE:
  534. rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
  535. break;
  536. case TARG_SESS_STATE_LOGGED_IN:
  537. rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
  538. break;
  539. case TARG_SESS_STATE_FAILED:
  540. rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
  541. break;
  542. case TARG_SESS_STATE_IN_CONTINUE:
  543. rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
  544. break;
  545. default:
  546. rb += sprintf(page+rb, "ERROR: Unknown Session"
  547. " State!\n");
  548. break;
  549. }
  550. rb += sprintf(page+rb, "---------------------[iSCSI Session"
  551. " Values]-----------------------\n");
  552. rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
  553. " : MaxCmdSN : ITT : TTT\n");
  554. max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
  555. rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
  556. " 0x%08x 0x%08x\n",
  557. sess->cmdsn_window,
  558. (max_cmd_sn - sess->exp_cmd_sn) + 1,
  559. sess->exp_cmd_sn, max_cmd_sn,
  560. sess->init_task_tag, sess->targ_xfer_tag);
  561. rb += sprintf(page+rb, "----------------------[iSCSI"
  562. " Connections]-------------------------\n");
  563. spin_lock(&sess->conn_lock);
  564. list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
  565. rb += sprintf(page+rb, "CID: %hu Connection"
  566. " State: ", conn->cid);
  567. switch (conn->conn_state) {
  568. case TARG_CONN_STATE_FREE:
  569. rb += sprintf(page+rb,
  570. "TARG_CONN_STATE_FREE\n");
  571. break;
  572. case TARG_CONN_STATE_XPT_UP:
  573. rb += sprintf(page+rb,
  574. "TARG_CONN_STATE_XPT_UP\n");
  575. break;
  576. case TARG_CONN_STATE_IN_LOGIN:
  577. rb += sprintf(page+rb,
  578. "TARG_CONN_STATE_IN_LOGIN\n");
  579. break;
  580. case TARG_CONN_STATE_LOGGED_IN:
  581. rb += sprintf(page+rb,
  582. "TARG_CONN_STATE_LOGGED_IN\n");
  583. break;
  584. case TARG_CONN_STATE_IN_LOGOUT:
  585. rb += sprintf(page+rb,
  586. "TARG_CONN_STATE_IN_LOGOUT\n");
  587. break;
  588. case TARG_CONN_STATE_LOGOUT_REQUESTED:
  589. rb += sprintf(page+rb,
  590. "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
  591. break;
  592. case TARG_CONN_STATE_CLEANUP_WAIT:
  593. rb += sprintf(page+rb,
  594. "TARG_CONN_STATE_CLEANUP_WAIT\n");
  595. break;
  596. default:
  597. rb += sprintf(page+rb,
  598. "ERROR: Unknown Connection State!\n");
  599. break;
  600. }
  601. rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
  602. (conn->network_transport == ISCSI_TCP) ?
  603. "TCP" : "SCTP");
  604. rb += sprintf(page+rb, " StatSN: 0x%08x\n",
  605. conn->stat_sn);
  606. }
  607. spin_unlock(&sess->conn_lock);
  608. }
  609. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  610. return rb;
  611. }
  612. static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
  613. char *page)
  614. {
  615. return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
  616. }
  617. static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
  618. const char *page, size_t count)
  619. {
  620. struct se_node_acl *se_nacl = acl_to_nacl(item);
  621. struct se_portal_group *se_tpg = se_nacl->se_tpg;
  622. struct iscsi_portal_group *tpg = container_of(se_tpg,
  623. struct iscsi_portal_group, tpg_se_tpg);
  624. struct config_item *acl_ci, *tpg_ci, *wwn_ci;
  625. u32 cmdsn_depth = 0;
  626. int ret;
  627. ret = kstrtou32(page, 0, &cmdsn_depth);
  628. if (ret)
  629. return ret;
  630. if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
  631. pr_err("Passed cmdsn_depth: %u exceeds"
  632. " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
  633. TA_DEFAULT_CMDSN_DEPTH_MAX);
  634. return -EINVAL;
  635. }
  636. acl_ci = &se_nacl->acl_group.cg_item;
  637. if (!acl_ci) {
  638. pr_err("Unable to locatel acl_ci\n");
  639. return -EINVAL;
  640. }
  641. tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
  642. if (!tpg_ci) {
  643. pr_err("Unable to locate tpg_ci\n");
  644. return -EINVAL;
  645. }
  646. wwn_ci = &tpg_ci->ci_group->cg_item;
  647. if (!wwn_ci) {
  648. pr_err("Unable to locate config_item wwn_ci\n");
  649. return -EINVAL;
  650. }
  651. if (iscsit_get_tpg(tpg) < 0)
  652. return -EINVAL;
  653. ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
  654. pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
  655. "InitiatorName: %s\n", config_item_name(wwn_ci),
  656. config_item_name(tpg_ci), cmdsn_depth,
  657. config_item_name(acl_ci));
  658. iscsit_put_tpg(tpg);
  659. return (!ret) ? count : (ssize_t)ret;
  660. }
  661. static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
  662. {
  663. return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
  664. }
  665. static ssize_t lio_target_nacl_tag_store(struct config_item *item,
  666. const char *page, size_t count)
  667. {
  668. struct se_node_acl *se_nacl = acl_to_nacl(item);
  669. int ret;
  670. ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
  671. if (ret < 0)
  672. return ret;
  673. return count;
  674. }
  675. CONFIGFS_ATTR_RO(lio_target_nacl_, info);
  676. CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
  677. CONFIGFS_ATTR(lio_target_nacl_, tag);
  678. static struct configfs_attribute *lio_target_initiator_attrs[] = {
  679. &lio_target_nacl_attr_info,
  680. &lio_target_nacl_attr_cmdsn_depth,
  681. &lio_target_nacl_attr_tag,
  682. NULL,
  683. };
  684. static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
  685. const char *name)
  686. {
  687. struct iscsi_node_acl *acl =
  688. container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
  689. struct config_group *stats_cg = &se_nacl->acl_fabric_stat_group;
  690. stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
  691. GFP_KERNEL);
  692. if (!stats_cg->default_groups) {
  693. pr_err("Unable to allocate memory for"
  694. " stats_cg->default_groups\n");
  695. return -ENOMEM;
  696. }
  697. stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group;
  698. stats_cg->default_groups[1] = NULL;
  699. config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
  700. "iscsi_sess_stats", &iscsi_stat_sess_cit);
  701. return 0;
  702. }
  703. static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl)
  704. {
  705. struct iscsi_node_acl *acl = container_of(se_nacl,
  706. struct iscsi_node_acl, se_node_acl);
  707. struct config_item *df_item;
  708. struct config_group *stats_cg;
  709. int i;
  710. stats_cg = &acl->se_node_acl.acl_fabric_stat_group;
  711. for (i = 0; stats_cg->default_groups[i]; i++) {
  712. df_item = &stats_cg->default_groups[i]->cg_item;
  713. stats_cg->default_groups[i] = NULL;
  714. config_item_put(df_item);
  715. }
  716. kfree(stats_cg->default_groups);
  717. }
  718. /* End items for lio_target_acl_cit */
  719. /* Start items for lio_target_tpg_attrib_cit */
  720. #define DEF_TPG_ATTRIB(name) \
  721. \
  722. static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
  723. char *page) \
  724. { \
  725. struct se_portal_group *se_tpg = attrib_to_tpg(item); \
  726. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  727. struct iscsi_portal_group, tpg_se_tpg); \
  728. ssize_t rb; \
  729. \
  730. if (iscsit_get_tpg(tpg) < 0) \
  731. return -EINVAL; \
  732. \
  733. rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
  734. iscsit_put_tpg(tpg); \
  735. return rb; \
  736. } \
  737. \
  738. static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
  739. const char *page, size_t count) \
  740. { \
  741. struct se_portal_group *se_tpg = attrib_to_tpg(item); \
  742. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  743. struct iscsi_portal_group, tpg_se_tpg); \
  744. u32 val; \
  745. int ret; \
  746. \
  747. if (iscsit_get_tpg(tpg) < 0) \
  748. return -EINVAL; \
  749. \
  750. ret = kstrtou32(page, 0, &val); \
  751. if (ret) \
  752. goto out; \
  753. ret = iscsit_ta_##name(tpg, val); \
  754. if (ret < 0) \
  755. goto out; \
  756. \
  757. iscsit_put_tpg(tpg); \
  758. return count; \
  759. out: \
  760. iscsit_put_tpg(tpg); \
  761. return ret; \
  762. } \
  763. CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
  764. DEF_TPG_ATTRIB(authentication);
  765. DEF_TPG_ATTRIB(login_timeout);
  766. DEF_TPG_ATTRIB(netif_timeout);
  767. DEF_TPG_ATTRIB(generate_node_acls);
  768. DEF_TPG_ATTRIB(default_cmdsn_depth);
  769. DEF_TPG_ATTRIB(cache_dynamic_acls);
  770. DEF_TPG_ATTRIB(demo_mode_write_protect);
  771. DEF_TPG_ATTRIB(prod_mode_write_protect);
  772. DEF_TPG_ATTRIB(demo_mode_discovery);
  773. DEF_TPG_ATTRIB(default_erl);
  774. DEF_TPG_ATTRIB(t10_pi);
  775. DEF_TPG_ATTRIB(fabric_prot_type);
  776. DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
  777. DEF_TPG_ATTRIB(login_keys_workaround);
  778. static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
  779. &iscsi_tpg_attrib_attr_authentication,
  780. &iscsi_tpg_attrib_attr_login_timeout,
  781. &iscsi_tpg_attrib_attr_netif_timeout,
  782. &iscsi_tpg_attrib_attr_generate_node_acls,
  783. &iscsi_tpg_attrib_attr_default_cmdsn_depth,
  784. &iscsi_tpg_attrib_attr_cache_dynamic_acls,
  785. &iscsi_tpg_attrib_attr_demo_mode_write_protect,
  786. &iscsi_tpg_attrib_attr_prod_mode_write_protect,
  787. &iscsi_tpg_attrib_attr_demo_mode_discovery,
  788. &iscsi_tpg_attrib_attr_default_erl,
  789. &iscsi_tpg_attrib_attr_t10_pi,
  790. &iscsi_tpg_attrib_attr_fabric_prot_type,
  791. &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
  792. &iscsi_tpg_attrib_attr_login_keys_workaround,
  793. NULL,
  794. };
  795. /* End items for lio_target_tpg_attrib_cit */
  796. /* Start items for lio_target_tpg_auth_cit */
  797. #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
  798. static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
  799. char *page) \
  800. { \
  801. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  802. struct iscsi_portal_group, tpg_se_tpg); \
  803. struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
  804. \
  805. if (!capable(CAP_SYS_ADMIN)) \
  806. return -EPERM; \
  807. \
  808. return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
  809. } \
  810. \
  811. static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
  812. const char *page, size_t count) \
  813. { \
  814. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  815. struct iscsi_portal_group, tpg_se_tpg); \
  816. struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
  817. \
  818. if (!capable(CAP_SYS_ADMIN)) \
  819. return -EPERM; \
  820. \
  821. snprintf(auth->name, sizeof(auth->name), "%s", page); \
  822. if (!(strncmp("NULL", auth->name, 4))) \
  823. auth->naf_flags &= ~flags; \
  824. else \
  825. auth->naf_flags |= flags; \
  826. \
  827. if ((auth->naf_flags & NAF_USERID_IN_SET) && \
  828. (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
  829. auth->authenticate_target = 1; \
  830. else \
  831. auth->authenticate_target = 0; \
  832. \
  833. return count; \
  834. }
  835. #define DEF_TPG_AUTH_STR(name, flags) \
  836. __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
  837. static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
  838. char *page) \
  839. { \
  840. return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
  841. } \
  842. \
  843. static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
  844. const char *page, size_t count) \
  845. { \
  846. return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
  847. } \
  848. \
  849. CONFIGFS_ATTR(iscsi_tpg_auth_, name);
  850. DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
  851. DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
  852. DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
  853. DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
  854. #define __DEF_TPG_AUTH_INT(prefix, name) \
  855. static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
  856. char *page) \
  857. { \
  858. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  859. struct iscsi_portal_group, tpg_se_tpg); \
  860. struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
  861. \
  862. if (!capable(CAP_SYS_ADMIN)) \
  863. return -EPERM; \
  864. \
  865. return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
  866. }
  867. #define DEF_TPG_AUTH_INT(name) \
  868. __DEF_TPG_AUTH_INT(tpg_auth, name) \
  869. static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
  870. char *page) \
  871. { \
  872. return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
  873. } \
  874. CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
  875. DEF_TPG_AUTH_INT(authenticate_target);
  876. static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
  877. &iscsi_tpg_auth_attr_userid,
  878. &iscsi_tpg_auth_attr_password,
  879. &iscsi_tpg_auth_attr_authenticate_target,
  880. &iscsi_tpg_auth_attr_userid_mutual,
  881. &iscsi_tpg_auth_attr_password_mutual,
  882. NULL,
  883. };
  884. /* End items for lio_target_tpg_auth_cit */
  885. /* Start items for lio_target_tpg_param_cit */
  886. #define DEF_TPG_PARAM(name) \
  887. static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
  888. char *page) \
  889. { \
  890. struct se_portal_group *se_tpg = param_to_tpg(item); \
  891. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  892. struct iscsi_portal_group, tpg_se_tpg); \
  893. struct iscsi_param *param; \
  894. ssize_t rb; \
  895. \
  896. if (iscsit_get_tpg(tpg) < 0) \
  897. return -EINVAL; \
  898. \
  899. param = iscsi_find_param_from_key(__stringify(name), \
  900. tpg->param_list); \
  901. if (!param) { \
  902. iscsit_put_tpg(tpg); \
  903. return -EINVAL; \
  904. } \
  905. rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
  906. \
  907. iscsit_put_tpg(tpg); \
  908. return rb; \
  909. } \
  910. static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
  911. const char *page, size_t count) \
  912. { \
  913. struct se_portal_group *se_tpg = param_to_tpg(item); \
  914. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  915. struct iscsi_portal_group, tpg_se_tpg); \
  916. char *buf; \
  917. int ret, len; \
  918. \
  919. buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
  920. if (!buf) \
  921. return -ENOMEM; \
  922. len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
  923. if (isspace(buf[len-1])) \
  924. buf[len-1] = '\0'; /* Kill newline */ \
  925. \
  926. if (iscsit_get_tpg(tpg) < 0) { \
  927. kfree(buf); \
  928. return -EINVAL; \
  929. } \
  930. \
  931. ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
  932. if (ret < 0) \
  933. goto out; \
  934. \
  935. kfree(buf); \
  936. iscsit_put_tpg(tpg); \
  937. return count; \
  938. out: \
  939. kfree(buf); \
  940. iscsit_put_tpg(tpg); \
  941. return -EINVAL; \
  942. } \
  943. CONFIGFS_ATTR(iscsi_tpg_param_, name)
  944. DEF_TPG_PARAM(AuthMethod);
  945. DEF_TPG_PARAM(HeaderDigest);
  946. DEF_TPG_PARAM(DataDigest);
  947. DEF_TPG_PARAM(MaxConnections);
  948. DEF_TPG_PARAM(TargetAlias);
  949. DEF_TPG_PARAM(InitialR2T);
  950. DEF_TPG_PARAM(ImmediateData);
  951. DEF_TPG_PARAM(MaxRecvDataSegmentLength);
  952. DEF_TPG_PARAM(MaxXmitDataSegmentLength);
  953. DEF_TPG_PARAM(MaxBurstLength);
  954. DEF_TPG_PARAM(FirstBurstLength);
  955. DEF_TPG_PARAM(DefaultTime2Wait);
  956. DEF_TPG_PARAM(DefaultTime2Retain);
  957. DEF_TPG_PARAM(MaxOutstandingR2T);
  958. DEF_TPG_PARAM(DataPDUInOrder);
  959. DEF_TPG_PARAM(DataSequenceInOrder);
  960. DEF_TPG_PARAM(ErrorRecoveryLevel);
  961. DEF_TPG_PARAM(IFMarker);
  962. DEF_TPG_PARAM(OFMarker);
  963. DEF_TPG_PARAM(IFMarkInt);
  964. DEF_TPG_PARAM(OFMarkInt);
  965. static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
  966. &iscsi_tpg_param_attr_AuthMethod,
  967. &iscsi_tpg_param_attr_HeaderDigest,
  968. &iscsi_tpg_param_attr_DataDigest,
  969. &iscsi_tpg_param_attr_MaxConnections,
  970. &iscsi_tpg_param_attr_TargetAlias,
  971. &iscsi_tpg_param_attr_InitialR2T,
  972. &iscsi_tpg_param_attr_ImmediateData,
  973. &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
  974. &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
  975. &iscsi_tpg_param_attr_MaxBurstLength,
  976. &iscsi_tpg_param_attr_FirstBurstLength,
  977. &iscsi_tpg_param_attr_DefaultTime2Wait,
  978. &iscsi_tpg_param_attr_DefaultTime2Retain,
  979. &iscsi_tpg_param_attr_MaxOutstandingR2T,
  980. &iscsi_tpg_param_attr_DataPDUInOrder,
  981. &iscsi_tpg_param_attr_DataSequenceInOrder,
  982. &iscsi_tpg_param_attr_ErrorRecoveryLevel,
  983. &iscsi_tpg_param_attr_IFMarker,
  984. &iscsi_tpg_param_attr_OFMarker,
  985. &iscsi_tpg_param_attr_IFMarkInt,
  986. &iscsi_tpg_param_attr_OFMarkInt,
  987. NULL,
  988. };
  989. /* End items for lio_target_tpg_param_cit */
  990. /* Start items for lio_target_tpg_cit */
  991. static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
  992. {
  993. struct se_portal_group *se_tpg = to_tpg(item);
  994. struct iscsi_portal_group *tpg = container_of(se_tpg,
  995. struct iscsi_portal_group, tpg_se_tpg);
  996. ssize_t len;
  997. spin_lock(&tpg->tpg_state_lock);
  998. len = sprintf(page, "%d\n",
  999. (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
  1000. spin_unlock(&tpg->tpg_state_lock);
  1001. return len;
  1002. }
  1003. static ssize_t lio_target_tpg_enable_store(struct config_item *item,
  1004. const char *page, size_t count)
  1005. {
  1006. struct se_portal_group *se_tpg = to_tpg(item);
  1007. struct iscsi_portal_group *tpg = container_of(se_tpg,
  1008. struct iscsi_portal_group, tpg_se_tpg);
  1009. u32 op;
  1010. int ret;
  1011. ret = kstrtou32(page, 0, &op);
  1012. if (ret)
  1013. return ret;
  1014. if ((op != 1) && (op != 0)) {
  1015. pr_err("Illegal value for tpg_enable: %u\n", op);
  1016. return -EINVAL;
  1017. }
  1018. ret = iscsit_get_tpg(tpg);
  1019. if (ret < 0)
  1020. return -EINVAL;
  1021. if (op) {
  1022. ret = iscsit_tpg_enable_portal_group(tpg);
  1023. if (ret < 0)
  1024. goto out;
  1025. } else {
  1026. /*
  1027. * iscsit_tpg_disable_portal_group() assumes force=1
  1028. */
  1029. ret = iscsit_tpg_disable_portal_group(tpg, 1);
  1030. if (ret < 0)
  1031. goto out;
  1032. }
  1033. iscsit_put_tpg(tpg);
  1034. return count;
  1035. out:
  1036. iscsit_put_tpg(tpg);
  1037. return -EINVAL;
  1038. }
  1039. static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
  1040. char *page)
  1041. {
  1042. return target_show_dynamic_sessions(to_tpg(item), page);
  1043. }
  1044. CONFIGFS_ATTR(lio_target_tpg_, enable);
  1045. CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
  1046. static struct configfs_attribute *lio_target_tpg_attrs[] = {
  1047. &lio_target_tpg_attr_enable,
  1048. &lio_target_tpg_attr_dynamic_sessions,
  1049. NULL,
  1050. };
  1051. /* End items for lio_target_tpg_cit */
  1052. /* Start items for lio_target_tiqn_cit */
  1053. static struct se_portal_group *lio_target_tiqn_addtpg(
  1054. struct se_wwn *wwn,
  1055. struct config_group *group,
  1056. const char *name)
  1057. {
  1058. struct iscsi_portal_group *tpg;
  1059. struct iscsi_tiqn *tiqn;
  1060. char *tpgt_str;
  1061. int ret;
  1062. u16 tpgt;
  1063. tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
  1064. /*
  1065. * Only tpgt_# directory groups can be created below
  1066. * target/iscsi/iqn.superturodiskarry/
  1067. */
  1068. tpgt_str = strstr(name, "tpgt_");
  1069. if (!tpgt_str) {
  1070. pr_err("Unable to locate \"tpgt_#\" directory"
  1071. " group\n");
  1072. return NULL;
  1073. }
  1074. tpgt_str += 5; /* Skip ahead of "tpgt_" */
  1075. ret = kstrtou16(tpgt_str, 0, &tpgt);
  1076. if (ret)
  1077. return NULL;
  1078. tpg = iscsit_alloc_portal_group(tiqn, tpgt);
  1079. if (!tpg)
  1080. return NULL;
  1081. ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
  1082. if (ret < 0)
  1083. goto free_out;
  1084. ret = iscsit_tpg_add_portal_group(tiqn, tpg);
  1085. if (ret != 0)
  1086. goto out;
  1087. pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
  1088. pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
  1089. name);
  1090. return &tpg->tpg_se_tpg;
  1091. out:
  1092. core_tpg_deregister(&tpg->tpg_se_tpg);
  1093. free_out:
  1094. kfree(tpg);
  1095. return NULL;
  1096. }
  1097. static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
  1098. {
  1099. struct iscsi_portal_group *tpg;
  1100. struct iscsi_tiqn *tiqn;
  1101. tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
  1102. tiqn = tpg->tpg_tiqn;
  1103. /*
  1104. * iscsit_tpg_del_portal_group() assumes force=1
  1105. */
  1106. pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
  1107. iscsit_tpg_del_portal_group(tiqn, tpg, 1);
  1108. }
  1109. /* End items for lio_target_tiqn_cit */
  1110. /* Start LIO-Target TIQN struct contig_item lio_target_cit */
  1111. static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
  1112. char *page)
  1113. {
  1114. return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
  1115. }
  1116. CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
  1117. static struct configfs_attribute *lio_target_wwn_attrs[] = {
  1118. &lio_target_wwn_attr_lio_version,
  1119. NULL,
  1120. };
  1121. static struct se_wwn *lio_target_call_coreaddtiqn(
  1122. struct target_fabric_configfs *tf,
  1123. struct config_group *group,
  1124. const char *name)
  1125. {
  1126. struct config_group *stats_cg;
  1127. struct iscsi_tiqn *tiqn;
  1128. tiqn = iscsit_add_tiqn((unsigned char *)name);
  1129. if (IS_ERR(tiqn))
  1130. return ERR_CAST(tiqn);
  1131. /*
  1132. * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group.
  1133. */
  1134. stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
  1135. stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6,
  1136. GFP_KERNEL);
  1137. if (!stats_cg->default_groups) {
  1138. pr_err("Unable to allocate memory for"
  1139. " stats_cg->default_groups\n");
  1140. iscsit_del_tiqn(tiqn);
  1141. return ERR_PTR(-ENOMEM);
  1142. }
  1143. stats_cg->default_groups[0] = &tiqn->tiqn_stat_grps.iscsi_instance_group;
  1144. stats_cg->default_groups[1] = &tiqn->tiqn_stat_grps.iscsi_sess_err_group;
  1145. stats_cg->default_groups[2] = &tiqn->tiqn_stat_grps.iscsi_tgt_attr_group;
  1146. stats_cg->default_groups[3] = &tiqn->tiqn_stat_grps.iscsi_login_stats_group;
  1147. stats_cg->default_groups[4] = &tiqn->tiqn_stat_grps.iscsi_logout_stats_group;
  1148. stats_cg->default_groups[5] = NULL;
  1149. config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
  1150. "iscsi_instance", &iscsi_stat_instance_cit);
  1151. config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
  1152. "iscsi_sess_err", &iscsi_stat_sess_err_cit);
  1153. config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
  1154. "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
  1155. config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
  1156. "iscsi_login_stats", &iscsi_stat_login_cit);
  1157. config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
  1158. "iscsi_logout_stats", &iscsi_stat_logout_cit);
  1159. pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
  1160. pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
  1161. " %s\n", name);
  1162. return &tiqn->tiqn_wwn;
  1163. }
  1164. static void lio_target_call_coredeltiqn(
  1165. struct se_wwn *wwn)
  1166. {
  1167. struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
  1168. struct config_item *df_item;
  1169. struct config_group *stats_cg;
  1170. int i;
  1171. stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
  1172. for (i = 0; stats_cg->default_groups[i]; i++) {
  1173. df_item = &stats_cg->default_groups[i]->cg_item;
  1174. stats_cg->default_groups[i] = NULL;
  1175. config_item_put(df_item);
  1176. }
  1177. kfree(stats_cg->default_groups);
  1178. pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
  1179. tiqn->tiqn);
  1180. iscsit_del_tiqn(tiqn);
  1181. }
  1182. /* End LIO-Target TIQN struct contig_lio_target_cit */
  1183. /* Start lio_target_discovery_auth_cit */
  1184. #define DEF_DISC_AUTH_STR(name, flags) \
  1185. __DEF_NACL_AUTH_STR(disc, name, flags) \
  1186. static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
  1187. { \
  1188. return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
  1189. page); \
  1190. } \
  1191. static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
  1192. const char *page, size_t count) \
  1193. { \
  1194. return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
  1195. page, count); \
  1196. \
  1197. } \
  1198. CONFIGFS_ATTR(iscsi_disc_, name)
  1199. DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
  1200. DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
  1201. DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
  1202. DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
  1203. #define DEF_DISC_AUTH_INT(name) \
  1204. __DEF_NACL_AUTH_INT(disc, name) \
  1205. static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
  1206. { \
  1207. return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
  1208. page); \
  1209. } \
  1210. CONFIGFS_ATTR_RO(iscsi_disc_, name)
  1211. DEF_DISC_AUTH_INT(authenticate_target);
  1212. static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
  1213. char *page)
  1214. {
  1215. struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
  1216. return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
  1217. }
  1218. static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
  1219. const char *page, size_t count)
  1220. {
  1221. struct iscsi_param *param;
  1222. struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
  1223. u32 op;
  1224. int err;
  1225. err = kstrtou32(page, 0, &op);
  1226. if (err)
  1227. return -EINVAL;
  1228. if ((op != 1) && (op != 0)) {
  1229. pr_err("Illegal value for enforce_discovery_auth:"
  1230. " %u\n", op);
  1231. return -EINVAL;
  1232. }
  1233. if (!discovery_tpg) {
  1234. pr_err("iscsit_global->discovery_tpg is NULL\n");
  1235. return -EINVAL;
  1236. }
  1237. param = iscsi_find_param_from_key(AUTHMETHOD,
  1238. discovery_tpg->param_list);
  1239. if (!param)
  1240. return -EINVAL;
  1241. if (op) {
  1242. /*
  1243. * Reset the AuthMethod key to CHAP.
  1244. */
  1245. if (iscsi_update_param_value(param, CHAP) < 0)
  1246. return -EINVAL;
  1247. discovery_tpg->tpg_attrib.authentication = 1;
  1248. iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
  1249. pr_debug("LIO-CORE[0] Successfully enabled"
  1250. " authentication enforcement for iSCSI"
  1251. " Discovery TPG\n");
  1252. } else {
  1253. /*
  1254. * Reset the AuthMethod key to CHAP,None
  1255. */
  1256. if (iscsi_update_param_value(param, "CHAP,None") < 0)
  1257. return -EINVAL;
  1258. discovery_tpg->tpg_attrib.authentication = 0;
  1259. iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
  1260. pr_debug("LIO-CORE[0] Successfully disabled"
  1261. " authentication enforcement for iSCSI"
  1262. " Discovery TPG\n");
  1263. }
  1264. return count;
  1265. }
  1266. CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
  1267. static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
  1268. &iscsi_disc_attr_userid,
  1269. &iscsi_disc_attr_password,
  1270. &iscsi_disc_attr_authenticate_target,
  1271. &iscsi_disc_attr_userid_mutual,
  1272. &iscsi_disc_attr_password_mutual,
  1273. &iscsi_disc_attr_enforce_discovery_auth,
  1274. NULL,
  1275. };
  1276. /* End lio_target_discovery_auth_cit */
  1277. /* Start functions for target_core_fabric_ops */
  1278. static char *iscsi_get_fabric_name(void)
  1279. {
  1280. return "iSCSI";
  1281. }
  1282. static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
  1283. {
  1284. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1285. return cmd->i_state;
  1286. }
  1287. static u32 lio_sess_get_index(struct se_session *se_sess)
  1288. {
  1289. struct iscsi_session *sess = se_sess->fabric_sess_ptr;
  1290. return sess->session_index;
  1291. }
  1292. static u32 lio_sess_get_initiator_sid(
  1293. struct se_session *se_sess,
  1294. unsigned char *buf,
  1295. u32 size)
  1296. {
  1297. struct iscsi_session *sess = se_sess->fabric_sess_ptr;
  1298. /*
  1299. * iSCSI Initiator Session Identifier from RFC-3720.
  1300. */
  1301. return snprintf(buf, size, "%6phN", sess->isid);
  1302. }
  1303. static int lio_queue_data_in(struct se_cmd *se_cmd)
  1304. {
  1305. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1306. cmd->i_state = ISTATE_SEND_DATAIN;
  1307. cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
  1308. return 0;
  1309. }
  1310. static int lio_write_pending(struct se_cmd *se_cmd)
  1311. {
  1312. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1313. struct iscsi_conn *conn = cmd->conn;
  1314. if (!cmd->immediate_data && !cmd->unsolicited_data)
  1315. return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
  1316. return 0;
  1317. }
  1318. static int lio_write_pending_status(struct se_cmd *se_cmd)
  1319. {
  1320. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1321. int ret;
  1322. spin_lock_bh(&cmd->istate_lock);
  1323. ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
  1324. spin_unlock_bh(&cmd->istate_lock);
  1325. return ret;
  1326. }
  1327. static int lio_queue_status(struct se_cmd *se_cmd)
  1328. {
  1329. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1330. cmd->i_state = ISTATE_SEND_STATUS;
  1331. if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
  1332. iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
  1333. return 0;
  1334. }
  1335. cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
  1336. return 0;
  1337. }
  1338. static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
  1339. {
  1340. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1341. cmd->i_state = ISTATE_SEND_TASKMGTRSP;
  1342. iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
  1343. }
  1344. static void lio_aborted_task(struct se_cmd *se_cmd)
  1345. {
  1346. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1347. cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
  1348. }
  1349. static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
  1350. {
  1351. return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
  1352. }
  1353. static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
  1354. {
  1355. return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
  1356. }
  1357. static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
  1358. {
  1359. return iscsi_tpg(se_tpg)->tpgt;
  1360. }
  1361. static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
  1362. {
  1363. return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
  1364. }
  1365. static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
  1366. {
  1367. return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
  1368. }
  1369. static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
  1370. {
  1371. return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
  1372. }
  1373. static int lio_tpg_check_demo_mode_write_protect(
  1374. struct se_portal_group *se_tpg)
  1375. {
  1376. return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
  1377. }
  1378. static int lio_tpg_check_prod_mode_write_protect(
  1379. struct se_portal_group *se_tpg)
  1380. {
  1381. return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
  1382. }
  1383. static int lio_tpg_check_prot_fabric_only(
  1384. struct se_portal_group *se_tpg)
  1385. {
  1386. /*
  1387. * Only report fabric_prot_type if t10_pi has also been enabled
  1388. * for incoming ib_isert sessions.
  1389. */
  1390. if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
  1391. return 0;
  1392. return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
  1393. }
  1394. /*
  1395. * This function calls iscsit_inc_session_usage_count() on the
  1396. * struct iscsi_session in question.
  1397. */
  1398. static int lio_tpg_shutdown_session(struct se_session *se_sess)
  1399. {
  1400. struct iscsi_session *sess = se_sess->fabric_sess_ptr;
  1401. struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
  1402. spin_lock_bh(&se_tpg->session_lock);
  1403. spin_lock(&sess->conn_lock);
  1404. if (atomic_read(&sess->session_fall_back_to_erl0) ||
  1405. atomic_read(&sess->session_logout) ||
  1406. (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
  1407. spin_unlock(&sess->conn_lock);
  1408. spin_unlock_bh(&se_tpg->session_lock);
  1409. return 0;
  1410. }
  1411. atomic_set(&sess->session_reinstatement, 1);
  1412. atomic_set(&sess->session_fall_back_to_erl0, 1);
  1413. spin_unlock(&sess->conn_lock);
  1414. iscsit_stop_time2retain_timer(sess);
  1415. spin_unlock_bh(&se_tpg->session_lock);
  1416. iscsit_stop_session(sess, 1, 1);
  1417. return 1;
  1418. }
  1419. /*
  1420. * Calls iscsit_dec_session_usage_count() as inverse of
  1421. * lio_tpg_shutdown_session()
  1422. */
  1423. static void lio_tpg_close_session(struct se_session *se_sess)
  1424. {
  1425. struct iscsi_session *sess = se_sess->fabric_sess_ptr;
  1426. /*
  1427. * If the iSCSI Session for the iSCSI Initiator Node exists,
  1428. * forcefully shutdown the iSCSI NEXUS.
  1429. */
  1430. iscsit_close_session(sess);
  1431. }
  1432. static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
  1433. {
  1434. return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
  1435. }
  1436. static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
  1437. {
  1438. struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
  1439. se_node_acl);
  1440. struct se_portal_group *se_tpg = se_acl->se_tpg;
  1441. struct iscsi_portal_group *tpg = container_of(se_tpg,
  1442. struct iscsi_portal_group, tpg_se_tpg);
  1443. acl->node_attrib.nacl = acl;
  1444. iscsit_set_default_node_attribues(acl, tpg);
  1445. }
  1446. static int lio_check_stop_free(struct se_cmd *se_cmd)
  1447. {
  1448. return target_put_sess_cmd(se_cmd);
  1449. }
  1450. static void lio_release_cmd(struct se_cmd *se_cmd)
  1451. {
  1452. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1453. pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
  1454. iscsit_release_cmd(cmd);
  1455. }
  1456. const struct target_core_fabric_ops iscsi_ops = {
  1457. .module = THIS_MODULE,
  1458. .name = "iscsi",
  1459. .node_acl_size = sizeof(struct iscsi_node_acl),
  1460. .get_fabric_name = iscsi_get_fabric_name,
  1461. .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
  1462. .tpg_get_tag = lio_tpg_get_tag,
  1463. .tpg_get_default_depth = lio_tpg_get_default_depth,
  1464. .tpg_check_demo_mode = lio_tpg_check_demo_mode,
  1465. .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
  1466. .tpg_check_demo_mode_write_protect =
  1467. lio_tpg_check_demo_mode_write_protect,
  1468. .tpg_check_prod_mode_write_protect =
  1469. lio_tpg_check_prod_mode_write_protect,
  1470. .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
  1471. .tpg_get_inst_index = lio_tpg_get_inst_index,
  1472. .check_stop_free = lio_check_stop_free,
  1473. .release_cmd = lio_release_cmd,
  1474. .shutdown_session = lio_tpg_shutdown_session,
  1475. .close_session = lio_tpg_close_session,
  1476. .sess_get_index = lio_sess_get_index,
  1477. .sess_get_initiator_sid = lio_sess_get_initiator_sid,
  1478. .write_pending = lio_write_pending,
  1479. .write_pending_status = lio_write_pending_status,
  1480. .set_default_node_attributes = lio_set_default_node_attributes,
  1481. .get_cmd_state = iscsi_get_cmd_state,
  1482. .queue_data_in = lio_queue_data_in,
  1483. .queue_status = lio_queue_status,
  1484. .queue_tm_rsp = lio_queue_tm_rsp,
  1485. .aborted_task = lio_aborted_task,
  1486. .fabric_make_wwn = lio_target_call_coreaddtiqn,
  1487. .fabric_drop_wwn = lio_target_call_coredeltiqn,
  1488. .fabric_make_tpg = lio_target_tiqn_addtpg,
  1489. .fabric_drop_tpg = lio_target_tiqn_deltpg,
  1490. .fabric_make_np = lio_target_call_addnptotpg,
  1491. .fabric_drop_np = lio_target_call_delnpfromtpg,
  1492. .fabric_init_nodeacl = lio_target_init_nodeacl,
  1493. .fabric_cleanup_nodeacl = lio_target_cleanup_nodeacl,
  1494. .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
  1495. .tfc_wwn_attrs = lio_target_wwn_attrs,
  1496. .tfc_tpg_base_attrs = lio_target_tpg_attrs,
  1497. .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
  1498. .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
  1499. .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
  1500. .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
  1501. .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
  1502. .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
  1503. .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
  1504. .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,
  1505. };