iscsi_target_configfs.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810
  1. /*******************************************************************************
  2. * This file contains the configfs implementation for iSCSI Target mode
  3. * from the LIO-Target Project.
  4. *
  5. * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
  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 <linux/inet.h>
  24. #include <target/target_core_base.h>
  25. #include <target/target_core_fabric.h>
  26. #include <target/target_core_fabric_configfs.h>
  27. #include <target/target_core_configfs.h>
  28. #include <target/configfs_macros.h>
  29. #include "iscsi_target_core.h"
  30. #include "iscsi_target_parameters.h"
  31. #include "iscsi_target_device.h"
  32. #include "iscsi_target_erl0.h"
  33. #include "iscsi_target_nodeattrib.h"
  34. #include "iscsi_target_tpg.h"
  35. #include "iscsi_target_util.h"
  36. #include "iscsi_target.h"
  37. #include "iscsi_target_stat.h"
  38. #include "iscsi_target_configfs.h"
  39. struct target_fabric_configfs *lio_target_fabric_configfs;
  40. struct lio_target_configfs_attribute {
  41. struct configfs_attribute attr;
  42. ssize_t (*show)(void *, char *);
  43. ssize_t (*store)(void *, const char *, size_t);
  44. };
  45. /* Start items for lio_target_portal_cit */
  46. static ssize_t lio_target_np_show_sctp(
  47. struct se_tpg_np *se_tpg_np,
  48. char *page)
  49. {
  50. struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
  51. struct iscsi_tpg_np, se_tpg_np);
  52. struct iscsi_tpg_np *tpg_np_sctp;
  53. ssize_t rb;
  54. tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
  55. if (tpg_np_sctp)
  56. rb = sprintf(page, "1\n");
  57. else
  58. rb = sprintf(page, "0\n");
  59. return rb;
  60. }
  61. static ssize_t lio_target_np_store_sctp(
  62. struct se_tpg_np *se_tpg_np,
  63. const char *page,
  64. size_t count)
  65. {
  66. struct iscsi_np *np;
  67. struct iscsi_portal_group *tpg;
  68. struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
  69. struct iscsi_tpg_np, se_tpg_np);
  70. struct iscsi_tpg_np *tpg_np_sctp = NULL;
  71. char *endptr;
  72. u32 op;
  73. int ret;
  74. op = simple_strtoul(page, &endptr, 0);
  75. if ((op != 1) && (op != 0)) {
  76. pr_err("Illegal value for tpg_enable: %u\n", op);
  77. return -EINVAL;
  78. }
  79. np = tpg_np->tpg_np;
  80. if (!np) {
  81. pr_err("Unable to locate struct iscsi_np from"
  82. " struct iscsi_tpg_np\n");
  83. return -EINVAL;
  84. }
  85. tpg = tpg_np->tpg;
  86. if (iscsit_get_tpg(tpg) < 0)
  87. return -EINVAL;
  88. if (op) {
  89. /*
  90. * Use existing np->np_sockaddr for SCTP network portal reference
  91. */
  92. tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
  93. np->np_ip, tpg_np, ISCSI_SCTP_TCP);
  94. if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
  95. goto out;
  96. } else {
  97. tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
  98. if (!tpg_np_sctp)
  99. goto out;
  100. ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
  101. if (ret < 0)
  102. goto out;
  103. }
  104. iscsit_put_tpg(tpg);
  105. return count;
  106. out:
  107. iscsit_put_tpg(tpg);
  108. return -EINVAL;
  109. }
  110. TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR);
  111. static struct configfs_attribute *lio_target_portal_attrs[] = {
  112. &lio_target_np_sctp.attr,
  113. NULL,
  114. };
  115. /* Stop items for lio_target_portal_cit */
  116. /* Start items for lio_target_np_cit */
  117. #define MAX_PORTAL_LEN 256
  118. struct se_tpg_np *lio_target_call_addnptotpg(
  119. struct se_portal_group *se_tpg,
  120. struct config_group *group,
  121. const char *name)
  122. {
  123. struct iscsi_portal_group *tpg;
  124. struct iscsi_tpg_np *tpg_np;
  125. char *str, *str2, *ip_str, *port_str;
  126. struct __kernel_sockaddr_storage sockaddr;
  127. struct sockaddr_in *sock_in;
  128. struct sockaddr_in6 *sock_in6;
  129. unsigned long port;
  130. int ret;
  131. char buf[MAX_PORTAL_LEN + 1];
  132. if (strlen(name) > MAX_PORTAL_LEN) {
  133. pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
  134. (int)strlen(name), MAX_PORTAL_LEN);
  135. return ERR_PTR(-EOVERFLOW);
  136. }
  137. memset(buf, 0, MAX_PORTAL_LEN + 1);
  138. snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
  139. memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage));
  140. str = strstr(buf, "[");
  141. if (str) {
  142. const char *end;
  143. str2 = strstr(str, "]");
  144. if (!str2) {
  145. pr_err("Unable to locate trailing \"]\""
  146. " in IPv6 iSCSI network portal address\n");
  147. return ERR_PTR(-EINVAL);
  148. }
  149. str++; /* Skip over leading "[" */
  150. *str2 = '\0'; /* Terminate the IPv6 address */
  151. str2++; /* Skip over the "]" */
  152. port_str = strstr(str2, ":");
  153. if (!port_str) {
  154. pr_err("Unable to locate \":port\""
  155. " in IPv6 iSCSI network portal address\n");
  156. return ERR_PTR(-EINVAL);
  157. }
  158. *port_str = '\0'; /* Terminate string for IP */
  159. port_str++; /* Skip over ":" */
  160. ret = strict_strtoul(port_str, 0, &port);
  161. if (ret < 0) {
  162. pr_err("strict_strtoul() failed for port_str: %d\n", ret);
  163. return ERR_PTR(ret);
  164. }
  165. sock_in6 = (struct sockaddr_in6 *)&sockaddr;
  166. sock_in6->sin6_family = AF_INET6;
  167. sock_in6->sin6_port = htons((unsigned short)port);
  168. ret = in6_pton(str, IPV6_ADDRESS_SPACE,
  169. (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
  170. if (ret <= 0) {
  171. pr_err("in6_pton returned: %d\n", ret);
  172. return ERR_PTR(-EINVAL);
  173. }
  174. } else {
  175. str = ip_str = &buf[0];
  176. port_str = strstr(ip_str, ":");
  177. if (!port_str) {
  178. pr_err("Unable to locate \":port\""
  179. " in IPv4 iSCSI network portal address\n");
  180. return ERR_PTR(-EINVAL);
  181. }
  182. *port_str = '\0'; /* Terminate string for IP */
  183. port_str++; /* Skip over ":" */
  184. ret = strict_strtoul(port_str, 0, &port);
  185. if (ret < 0) {
  186. pr_err("strict_strtoul() failed for port_str: %d\n", ret);
  187. return ERR_PTR(ret);
  188. }
  189. sock_in = (struct sockaddr_in *)&sockaddr;
  190. sock_in->sin_family = AF_INET;
  191. sock_in->sin_port = htons((unsigned short)port);
  192. sock_in->sin_addr.s_addr = in_aton(ip_str);
  193. }
  194. tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
  195. ret = iscsit_get_tpg(tpg);
  196. if (ret < 0)
  197. return ERR_PTR(-EINVAL);
  198. pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
  199. " PORTAL: %s\n",
  200. config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
  201. tpg->tpgt, name);
  202. /*
  203. * Assume ISCSI_TCP by default. Other network portals for other
  204. * iSCSI fabrics:
  205. *
  206. * Traditional iSCSI over SCTP (initial support)
  207. * iSER/TCP (TODO, hardware available)
  208. * iSER/SCTP (TODO, software emulation with osc-iwarp)
  209. * iSER/IB (TODO, hardware available)
  210. *
  211. * can be enabled with atributes under
  212. * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
  213. *
  214. */
  215. tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, str, NULL,
  216. ISCSI_TCP);
  217. if (IS_ERR(tpg_np)) {
  218. iscsit_put_tpg(tpg);
  219. return ERR_CAST(tpg_np);
  220. }
  221. pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
  222. iscsit_put_tpg(tpg);
  223. return &tpg_np->se_tpg_np;
  224. }
  225. static void lio_target_call_delnpfromtpg(
  226. struct se_tpg_np *se_tpg_np)
  227. {
  228. struct iscsi_portal_group *tpg;
  229. struct iscsi_tpg_np *tpg_np;
  230. struct se_portal_group *se_tpg;
  231. int ret;
  232. tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
  233. tpg = tpg_np->tpg;
  234. ret = iscsit_get_tpg(tpg);
  235. if (ret < 0)
  236. return;
  237. se_tpg = &tpg->tpg_se_tpg;
  238. pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
  239. " PORTAL: %s:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
  240. tpg->tpgt, tpg_np->tpg_np->np_ip, tpg_np->tpg_np->np_port);
  241. ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
  242. if (ret < 0)
  243. goto out;
  244. pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
  245. out:
  246. iscsit_put_tpg(tpg);
  247. }
  248. /* End items for lio_target_np_cit */
  249. /* Start items for lio_target_nacl_attrib_cit */
  250. #define DEF_NACL_ATTRIB(name) \
  251. static ssize_t iscsi_nacl_attrib_show_##name( \
  252. struct se_node_acl *se_nacl, \
  253. char *page) \
  254. { \
  255. struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
  256. se_node_acl); \
  257. \
  258. return sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \
  259. } \
  260. \
  261. static ssize_t iscsi_nacl_attrib_store_##name( \
  262. struct se_node_acl *se_nacl, \
  263. const char *page, \
  264. size_t count) \
  265. { \
  266. struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
  267. se_node_acl); \
  268. char *endptr; \
  269. u32 val; \
  270. int ret; \
  271. \
  272. val = simple_strtoul(page, &endptr, 0); \
  273. ret = iscsit_na_##name(nacl, val); \
  274. if (ret < 0) \
  275. return ret; \
  276. \
  277. return count; \
  278. }
  279. #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode);
  280. /*
  281. * Define iscsi_node_attrib_s_dataout_timeout
  282. */
  283. DEF_NACL_ATTRIB(dataout_timeout);
  284. NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR);
  285. /*
  286. * Define iscsi_node_attrib_s_dataout_timeout_retries
  287. */
  288. DEF_NACL_ATTRIB(dataout_timeout_retries);
  289. NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR);
  290. /*
  291. * Define iscsi_node_attrib_s_default_erl
  292. */
  293. DEF_NACL_ATTRIB(default_erl);
  294. NACL_ATTR(default_erl, S_IRUGO | S_IWUSR);
  295. /*
  296. * Define iscsi_node_attrib_s_nopin_timeout
  297. */
  298. DEF_NACL_ATTRIB(nopin_timeout);
  299. NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR);
  300. /*
  301. * Define iscsi_node_attrib_s_nopin_response_timeout
  302. */
  303. DEF_NACL_ATTRIB(nopin_response_timeout);
  304. NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR);
  305. /*
  306. * Define iscsi_node_attrib_s_random_datain_pdu_offsets
  307. */
  308. DEF_NACL_ATTRIB(random_datain_pdu_offsets);
  309. NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR);
  310. /*
  311. * Define iscsi_node_attrib_s_random_datain_seq_offsets
  312. */
  313. DEF_NACL_ATTRIB(random_datain_seq_offsets);
  314. NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR);
  315. /*
  316. * Define iscsi_node_attrib_s_random_r2t_offsets
  317. */
  318. DEF_NACL_ATTRIB(random_r2t_offsets);
  319. NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR);
  320. static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
  321. &iscsi_nacl_attrib_dataout_timeout.attr,
  322. &iscsi_nacl_attrib_dataout_timeout_retries.attr,
  323. &iscsi_nacl_attrib_default_erl.attr,
  324. &iscsi_nacl_attrib_nopin_timeout.attr,
  325. &iscsi_nacl_attrib_nopin_response_timeout.attr,
  326. &iscsi_nacl_attrib_random_datain_pdu_offsets.attr,
  327. &iscsi_nacl_attrib_random_datain_seq_offsets.attr,
  328. &iscsi_nacl_attrib_random_r2t_offsets.attr,
  329. NULL,
  330. };
  331. /* End items for lio_target_nacl_attrib_cit */
  332. /* Start items for lio_target_nacl_auth_cit */
  333. #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
  334. static ssize_t __iscsi_##prefix##_show_##name( \
  335. struct iscsi_node_acl *nacl, \
  336. char *page) \
  337. { \
  338. struct iscsi_node_auth *auth = &nacl->node_auth; \
  339. \
  340. if (!capable(CAP_SYS_ADMIN)) \
  341. return -EPERM; \
  342. return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
  343. } \
  344. \
  345. static ssize_t __iscsi_##prefix##_store_##name( \
  346. struct iscsi_node_acl *nacl, \
  347. const char *page, \
  348. size_t count) \
  349. { \
  350. struct iscsi_node_auth *auth = &nacl->node_auth; \
  351. \
  352. if (!capable(CAP_SYS_ADMIN)) \
  353. return -EPERM; \
  354. \
  355. snprintf(auth->name, PAGE_SIZE, "%s", page); \
  356. if (!strncmp("NULL", auth->name, 4)) \
  357. auth->naf_flags &= ~flags; \
  358. else \
  359. auth->naf_flags |= flags; \
  360. \
  361. if ((auth->naf_flags & NAF_USERID_IN_SET) && \
  362. (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
  363. auth->authenticate_target = 1; \
  364. else \
  365. auth->authenticate_target = 0; \
  366. \
  367. return count; \
  368. }
  369. #define __DEF_NACL_AUTH_INT(prefix, name) \
  370. static ssize_t __iscsi_##prefix##_show_##name( \
  371. struct iscsi_node_acl *nacl, \
  372. char *page) \
  373. { \
  374. struct iscsi_node_auth *auth = &nacl->node_auth; \
  375. \
  376. if (!capable(CAP_SYS_ADMIN)) \
  377. return -EPERM; \
  378. \
  379. return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
  380. }
  381. #define DEF_NACL_AUTH_STR(name, flags) \
  382. __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
  383. static ssize_t iscsi_nacl_auth_show_##name( \
  384. struct se_node_acl *nacl, \
  385. char *page) \
  386. { \
  387. return __iscsi_nacl_auth_show_##name(container_of(nacl, \
  388. struct iscsi_node_acl, se_node_acl), page); \
  389. } \
  390. static ssize_t iscsi_nacl_auth_store_##name( \
  391. struct se_node_acl *nacl, \
  392. const char *page, \
  393. size_t count) \
  394. { \
  395. return __iscsi_nacl_auth_store_##name(container_of(nacl, \
  396. struct iscsi_node_acl, se_node_acl), page, count); \
  397. }
  398. #define DEF_NACL_AUTH_INT(name) \
  399. __DEF_NACL_AUTH_INT(nacl_auth, name) \
  400. static ssize_t iscsi_nacl_auth_show_##name( \
  401. struct se_node_acl *nacl, \
  402. char *page) \
  403. { \
  404. return __iscsi_nacl_auth_show_##name(container_of(nacl, \
  405. struct iscsi_node_acl, se_node_acl), page); \
  406. }
  407. #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode);
  408. #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name);
  409. /*
  410. * One-way authentication userid
  411. */
  412. DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
  413. AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
  414. /*
  415. * One-way authentication password
  416. */
  417. DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
  418. AUTH_ATTR(password, S_IRUGO | S_IWUSR);
  419. /*
  420. * Enforce mutual authentication
  421. */
  422. DEF_NACL_AUTH_INT(authenticate_target);
  423. AUTH_ATTR_RO(authenticate_target);
  424. /*
  425. * Mutual authentication userid
  426. */
  427. DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
  428. AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
  429. /*
  430. * Mutual authentication password
  431. */
  432. DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
  433. AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
  434. static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
  435. &iscsi_nacl_auth_userid.attr,
  436. &iscsi_nacl_auth_password.attr,
  437. &iscsi_nacl_auth_authenticate_target.attr,
  438. &iscsi_nacl_auth_userid_mutual.attr,
  439. &iscsi_nacl_auth_password_mutual.attr,
  440. NULL,
  441. };
  442. /* End items for lio_target_nacl_auth_cit */
  443. /* Start items for lio_target_nacl_param_cit */
  444. #define DEF_NACL_PARAM(name) \
  445. static ssize_t iscsi_nacl_param_show_##name( \
  446. struct se_node_acl *se_nacl, \
  447. char *page) \
  448. { \
  449. struct iscsi_session *sess; \
  450. struct se_session *se_sess; \
  451. ssize_t rb; \
  452. \
  453. spin_lock_bh(&se_nacl->nacl_sess_lock); \
  454. se_sess = se_nacl->nacl_sess; \
  455. if (!se_sess) { \
  456. rb = snprintf(page, PAGE_SIZE, \
  457. "No Active iSCSI Session\n"); \
  458. } else { \
  459. sess = se_sess->fabric_sess_ptr; \
  460. rb = snprintf(page, PAGE_SIZE, "%u\n", \
  461. (u32)sess->sess_ops->name); \
  462. } \
  463. spin_unlock_bh(&se_nacl->nacl_sess_lock); \
  464. \
  465. return rb; \
  466. }
  467. #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name);
  468. DEF_NACL_PARAM(MaxConnections);
  469. NACL_PARAM_ATTR(MaxConnections);
  470. DEF_NACL_PARAM(InitialR2T);
  471. NACL_PARAM_ATTR(InitialR2T);
  472. DEF_NACL_PARAM(ImmediateData);
  473. NACL_PARAM_ATTR(ImmediateData);
  474. DEF_NACL_PARAM(MaxBurstLength);
  475. NACL_PARAM_ATTR(MaxBurstLength);
  476. DEF_NACL_PARAM(FirstBurstLength);
  477. NACL_PARAM_ATTR(FirstBurstLength);
  478. DEF_NACL_PARAM(DefaultTime2Wait);
  479. NACL_PARAM_ATTR(DefaultTime2Wait);
  480. DEF_NACL_PARAM(DefaultTime2Retain);
  481. NACL_PARAM_ATTR(DefaultTime2Retain);
  482. DEF_NACL_PARAM(MaxOutstandingR2T);
  483. NACL_PARAM_ATTR(MaxOutstandingR2T);
  484. DEF_NACL_PARAM(DataPDUInOrder);
  485. NACL_PARAM_ATTR(DataPDUInOrder);
  486. DEF_NACL_PARAM(DataSequenceInOrder);
  487. NACL_PARAM_ATTR(DataSequenceInOrder);
  488. DEF_NACL_PARAM(ErrorRecoveryLevel);
  489. NACL_PARAM_ATTR(ErrorRecoveryLevel);
  490. static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
  491. &iscsi_nacl_param_MaxConnections.attr,
  492. &iscsi_nacl_param_InitialR2T.attr,
  493. &iscsi_nacl_param_ImmediateData.attr,
  494. &iscsi_nacl_param_MaxBurstLength.attr,
  495. &iscsi_nacl_param_FirstBurstLength.attr,
  496. &iscsi_nacl_param_DefaultTime2Wait.attr,
  497. &iscsi_nacl_param_DefaultTime2Retain.attr,
  498. &iscsi_nacl_param_MaxOutstandingR2T.attr,
  499. &iscsi_nacl_param_DataPDUInOrder.attr,
  500. &iscsi_nacl_param_DataSequenceInOrder.attr,
  501. &iscsi_nacl_param_ErrorRecoveryLevel.attr,
  502. NULL,
  503. };
  504. /* End items for lio_target_nacl_param_cit */
  505. /* Start items for lio_target_acl_cit */
  506. static ssize_t lio_target_nacl_show_info(
  507. struct se_node_acl *se_nacl,
  508. char *page)
  509. {
  510. struct iscsi_session *sess;
  511. struct iscsi_conn *conn;
  512. struct se_session *se_sess;
  513. ssize_t rb = 0;
  514. spin_lock_bh(&se_nacl->nacl_sess_lock);
  515. se_sess = se_nacl->nacl_sess;
  516. if (!se_sess) {
  517. rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
  518. " Endpoint: %s\n", se_nacl->initiatorname);
  519. } else {
  520. sess = se_sess->fabric_sess_ptr;
  521. if (sess->sess_ops->InitiatorName)
  522. rb += sprintf(page+rb, "InitiatorName: %s\n",
  523. sess->sess_ops->InitiatorName);
  524. if (sess->sess_ops->InitiatorAlias)
  525. rb += sprintf(page+rb, "InitiatorAlias: %s\n",
  526. sess->sess_ops->InitiatorAlias);
  527. rb += sprintf(page+rb, "LIO Session ID: %u "
  528. "ISID: 0x%02x %02x %02x %02x %02x %02x "
  529. "TSIH: %hu ", sess->sid,
  530. sess->isid[0], sess->isid[1], sess->isid[2],
  531. sess->isid[3], sess->isid[4], sess->isid[5],
  532. sess->tsih);
  533. rb += sprintf(page+rb, "SessionType: %s\n",
  534. (sess->sess_ops->SessionType) ?
  535. "Discovery" : "Normal");
  536. rb += sprintf(page+rb, "Session State: ");
  537. switch (sess->session_state) {
  538. case TARG_SESS_STATE_FREE:
  539. rb += sprintf(page+rb, "TARG_SESS_FREE\n");
  540. break;
  541. case TARG_SESS_STATE_ACTIVE:
  542. rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
  543. break;
  544. case TARG_SESS_STATE_LOGGED_IN:
  545. rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
  546. break;
  547. case TARG_SESS_STATE_FAILED:
  548. rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
  549. break;
  550. case TARG_SESS_STATE_IN_CONTINUE:
  551. rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
  552. break;
  553. default:
  554. rb += sprintf(page+rb, "ERROR: Unknown Session"
  555. " State!\n");
  556. break;
  557. }
  558. rb += sprintf(page+rb, "---------------------[iSCSI Session"
  559. " Values]-----------------------\n");
  560. rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
  561. " : MaxCmdSN : ITT : TTT\n");
  562. rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
  563. " 0x%08x 0x%08x\n",
  564. sess->cmdsn_window,
  565. (sess->max_cmd_sn - sess->exp_cmd_sn) + 1,
  566. sess->exp_cmd_sn, sess->max_cmd_sn,
  567. sess->init_task_tag, sess->targ_xfer_tag);
  568. rb += sprintf(page+rb, "----------------------[iSCSI"
  569. " Connections]-------------------------\n");
  570. spin_lock(&sess->conn_lock);
  571. list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
  572. rb += sprintf(page+rb, "CID: %hu Connection"
  573. " State: ", conn->cid);
  574. switch (conn->conn_state) {
  575. case TARG_CONN_STATE_FREE:
  576. rb += sprintf(page+rb,
  577. "TARG_CONN_STATE_FREE\n");
  578. break;
  579. case TARG_CONN_STATE_XPT_UP:
  580. rb += sprintf(page+rb,
  581. "TARG_CONN_STATE_XPT_UP\n");
  582. break;
  583. case TARG_CONN_STATE_IN_LOGIN:
  584. rb += sprintf(page+rb,
  585. "TARG_CONN_STATE_IN_LOGIN\n");
  586. break;
  587. case TARG_CONN_STATE_LOGGED_IN:
  588. rb += sprintf(page+rb,
  589. "TARG_CONN_STATE_LOGGED_IN\n");
  590. break;
  591. case TARG_CONN_STATE_IN_LOGOUT:
  592. rb += sprintf(page+rb,
  593. "TARG_CONN_STATE_IN_LOGOUT\n");
  594. break;
  595. case TARG_CONN_STATE_LOGOUT_REQUESTED:
  596. rb += sprintf(page+rb,
  597. "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
  598. break;
  599. case TARG_CONN_STATE_CLEANUP_WAIT:
  600. rb += sprintf(page+rb,
  601. "TARG_CONN_STATE_CLEANUP_WAIT\n");
  602. break;
  603. default:
  604. rb += sprintf(page+rb,
  605. "ERROR: Unknown Connection State!\n");
  606. break;
  607. }
  608. rb += sprintf(page+rb, " Address %s %s", conn->login_ip,
  609. (conn->network_transport == ISCSI_TCP) ?
  610. "TCP" : "SCTP");
  611. rb += sprintf(page+rb, " StatSN: 0x%08x\n",
  612. conn->stat_sn);
  613. }
  614. spin_unlock(&sess->conn_lock);
  615. }
  616. spin_unlock_bh(&se_nacl->nacl_sess_lock);
  617. return rb;
  618. }
  619. TF_NACL_BASE_ATTR_RO(lio_target, info);
  620. static ssize_t lio_target_nacl_show_cmdsn_depth(
  621. struct se_node_acl *se_nacl,
  622. char *page)
  623. {
  624. return sprintf(page, "%u\n", se_nacl->queue_depth);
  625. }
  626. static ssize_t lio_target_nacl_store_cmdsn_depth(
  627. struct se_node_acl *se_nacl,
  628. const char *page,
  629. size_t count)
  630. {
  631. struct se_portal_group *se_tpg = se_nacl->se_tpg;
  632. struct iscsi_portal_group *tpg = container_of(se_tpg,
  633. struct iscsi_portal_group, tpg_se_tpg);
  634. struct config_item *acl_ci, *tpg_ci, *wwn_ci;
  635. char *endptr;
  636. u32 cmdsn_depth = 0;
  637. int ret;
  638. cmdsn_depth = simple_strtoul(page, &endptr, 0);
  639. if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
  640. pr_err("Passed cmdsn_depth: %u exceeds"
  641. " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
  642. TA_DEFAULT_CMDSN_DEPTH_MAX);
  643. return -EINVAL;
  644. }
  645. acl_ci = &se_nacl->acl_group.cg_item;
  646. if (!acl_ci) {
  647. pr_err("Unable to locatel acl_ci\n");
  648. return -EINVAL;
  649. }
  650. tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
  651. if (!tpg_ci) {
  652. pr_err("Unable to locate tpg_ci\n");
  653. return -EINVAL;
  654. }
  655. wwn_ci = &tpg_ci->ci_group->cg_item;
  656. if (!wwn_ci) {
  657. pr_err("Unable to locate config_item wwn_ci\n");
  658. return -EINVAL;
  659. }
  660. if (iscsit_get_tpg(tpg) < 0)
  661. return -EINVAL;
  662. /*
  663. * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1
  664. */
  665. ret = iscsit_tpg_set_initiator_node_queue_depth(tpg,
  666. config_item_name(acl_ci), cmdsn_depth, 1);
  667. pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
  668. "InitiatorName: %s\n", config_item_name(wwn_ci),
  669. config_item_name(tpg_ci), cmdsn_depth,
  670. config_item_name(acl_ci));
  671. iscsit_put_tpg(tpg);
  672. return (!ret) ? count : (ssize_t)ret;
  673. }
  674. TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR);
  675. static struct configfs_attribute *lio_target_initiator_attrs[] = {
  676. &lio_target_nacl_info.attr,
  677. &lio_target_nacl_cmdsn_depth.attr,
  678. NULL,
  679. };
  680. static struct se_node_acl *lio_tpg_alloc_fabric_acl(
  681. struct se_portal_group *se_tpg)
  682. {
  683. struct iscsi_node_acl *acl;
  684. acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL);
  685. if (!acl) {
  686. pr_err("Unable to allocate memory for struct iscsi_node_acl\n");
  687. return NULL;
  688. }
  689. return &acl->se_node_acl;
  690. }
  691. static struct se_node_acl *lio_target_make_nodeacl(
  692. struct se_portal_group *se_tpg,
  693. struct config_group *group,
  694. const char *name)
  695. {
  696. struct config_group *stats_cg;
  697. struct iscsi_node_acl *acl;
  698. struct se_node_acl *se_nacl_new, *se_nacl;
  699. struct iscsi_portal_group *tpg = container_of(se_tpg,
  700. struct iscsi_portal_group, tpg_se_tpg);
  701. u32 cmdsn_depth;
  702. se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg);
  703. if (!se_nacl_new)
  704. return ERR_PTR(-ENOMEM);
  705. cmdsn_depth = ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth;
  706. /*
  707. * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
  708. * when converting a NdoeACL from demo mode -> explict
  709. */
  710. se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
  711. name, cmdsn_depth);
  712. if (IS_ERR(se_nacl))
  713. return se_nacl;
  714. acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
  715. stats_cg = &se_nacl->acl_fabric_stat_group;
  716. stats_cg->default_groups = kzalloc(sizeof(struct config_group) * 2,
  717. GFP_KERNEL);
  718. if (!stats_cg->default_groups) {
  719. pr_err("Unable to allocate memory for"
  720. " stats_cg->default_groups\n");
  721. core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
  722. kfree(acl);
  723. return ERR_PTR(-ENOMEM);
  724. }
  725. stats_cg->default_groups[0] = &NODE_STAT_GRPS(acl)->iscsi_sess_stats_group;
  726. stats_cg->default_groups[1] = NULL;
  727. config_group_init_type_name(&NODE_STAT_GRPS(acl)->iscsi_sess_stats_group,
  728. "iscsi_sess_stats", &iscsi_stat_sess_cit);
  729. return se_nacl;
  730. }
  731. static void lio_target_drop_nodeacl(
  732. struct se_node_acl *se_nacl)
  733. {
  734. struct se_portal_group *se_tpg = se_nacl->se_tpg;
  735. struct iscsi_node_acl *acl = container_of(se_nacl,
  736. struct iscsi_node_acl, se_node_acl);
  737. struct config_item *df_item;
  738. struct config_group *stats_cg;
  739. int i;
  740. stats_cg = &acl->se_node_acl.acl_fabric_stat_group;
  741. for (i = 0; stats_cg->default_groups[i]; i++) {
  742. df_item = &stats_cg->default_groups[i]->cg_item;
  743. stats_cg->default_groups[i] = NULL;
  744. config_item_put(df_item);
  745. }
  746. kfree(stats_cg->default_groups);
  747. core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
  748. kfree(acl);
  749. }
  750. /* End items for lio_target_acl_cit */
  751. /* Start items for lio_target_tpg_attrib_cit */
  752. #define DEF_TPG_ATTRIB(name) \
  753. \
  754. static ssize_t iscsi_tpg_attrib_show_##name( \
  755. struct se_portal_group *se_tpg, \
  756. char *page) \
  757. { \
  758. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  759. struct iscsi_portal_group, tpg_se_tpg); \
  760. ssize_t rb; \
  761. \
  762. if (iscsit_get_tpg(tpg) < 0) \
  763. return -EINVAL; \
  764. \
  765. rb = sprintf(page, "%u\n", ISCSI_TPG_ATTRIB(tpg)->name); \
  766. iscsit_put_tpg(tpg); \
  767. return rb; \
  768. } \
  769. \
  770. static ssize_t iscsi_tpg_attrib_store_##name( \
  771. struct se_portal_group *se_tpg, \
  772. const char *page, \
  773. size_t count) \
  774. { \
  775. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  776. struct iscsi_portal_group, tpg_se_tpg); \
  777. char *endptr; \
  778. u32 val; \
  779. int ret; \
  780. \
  781. if (iscsit_get_tpg(tpg) < 0) \
  782. return -EINVAL; \
  783. \
  784. val = simple_strtoul(page, &endptr, 0); \
  785. ret = iscsit_ta_##name(tpg, val); \
  786. if (ret < 0) \
  787. goto out; \
  788. \
  789. iscsit_put_tpg(tpg); \
  790. return count; \
  791. out: \
  792. iscsit_put_tpg(tpg); \
  793. return ret; \
  794. }
  795. #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
  796. /*
  797. * Define iscsi_tpg_attrib_s_authentication
  798. */
  799. DEF_TPG_ATTRIB(authentication);
  800. TPG_ATTR(authentication, S_IRUGO | S_IWUSR);
  801. /*
  802. * Define iscsi_tpg_attrib_s_login_timeout
  803. */
  804. DEF_TPG_ATTRIB(login_timeout);
  805. TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR);
  806. /*
  807. * Define iscsi_tpg_attrib_s_netif_timeout
  808. */
  809. DEF_TPG_ATTRIB(netif_timeout);
  810. TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR);
  811. /*
  812. * Define iscsi_tpg_attrib_s_generate_node_acls
  813. */
  814. DEF_TPG_ATTRIB(generate_node_acls);
  815. TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
  816. /*
  817. * Define iscsi_tpg_attrib_s_default_cmdsn_depth
  818. */
  819. DEF_TPG_ATTRIB(default_cmdsn_depth);
  820. TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR);
  821. /*
  822. Define iscsi_tpg_attrib_s_cache_dynamic_acls
  823. */
  824. DEF_TPG_ATTRIB(cache_dynamic_acls);
  825. TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
  826. /*
  827. * Define iscsi_tpg_attrib_s_demo_mode_write_protect
  828. */
  829. DEF_TPG_ATTRIB(demo_mode_write_protect);
  830. TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
  831. /*
  832. * Define iscsi_tpg_attrib_s_prod_mode_write_protect
  833. */
  834. DEF_TPG_ATTRIB(prod_mode_write_protect);
  835. TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
  836. static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
  837. &iscsi_tpg_attrib_authentication.attr,
  838. &iscsi_tpg_attrib_login_timeout.attr,
  839. &iscsi_tpg_attrib_netif_timeout.attr,
  840. &iscsi_tpg_attrib_generate_node_acls.attr,
  841. &iscsi_tpg_attrib_default_cmdsn_depth.attr,
  842. &iscsi_tpg_attrib_cache_dynamic_acls.attr,
  843. &iscsi_tpg_attrib_demo_mode_write_protect.attr,
  844. &iscsi_tpg_attrib_prod_mode_write_protect.attr,
  845. NULL,
  846. };
  847. /* End items for lio_target_tpg_attrib_cit */
  848. /* Start items for lio_target_tpg_param_cit */
  849. #define DEF_TPG_PARAM(name) \
  850. static ssize_t iscsi_tpg_param_show_##name( \
  851. struct se_portal_group *se_tpg, \
  852. char *page) \
  853. { \
  854. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  855. struct iscsi_portal_group, tpg_se_tpg); \
  856. struct iscsi_param *param; \
  857. ssize_t rb; \
  858. \
  859. if (iscsit_get_tpg(tpg) < 0) \
  860. return -EINVAL; \
  861. \
  862. param = iscsi_find_param_from_key(__stringify(name), \
  863. tpg->param_list); \
  864. if (!param) { \
  865. iscsit_put_tpg(tpg); \
  866. return -EINVAL; \
  867. } \
  868. rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
  869. \
  870. iscsit_put_tpg(tpg); \
  871. return rb; \
  872. } \
  873. static ssize_t iscsi_tpg_param_store_##name( \
  874. struct se_portal_group *se_tpg, \
  875. const char *page, \
  876. size_t count) \
  877. { \
  878. struct iscsi_portal_group *tpg = container_of(se_tpg, \
  879. struct iscsi_portal_group, tpg_se_tpg); \
  880. char *buf; \
  881. int ret; \
  882. \
  883. buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
  884. if (!buf) \
  885. return -ENOMEM; \
  886. snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
  887. buf[strlen(buf)-1] = '\0'; /* Kill newline */ \
  888. \
  889. if (iscsit_get_tpg(tpg) < 0) { \
  890. kfree(buf); \
  891. return -EINVAL; \
  892. } \
  893. \
  894. ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
  895. if (ret < 0) \
  896. goto out; \
  897. \
  898. kfree(buf); \
  899. iscsit_put_tpg(tpg); \
  900. return count; \
  901. out: \
  902. kfree(buf); \
  903. iscsit_put_tpg(tpg); \
  904. return -EINVAL; \
  905. }
  906. #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
  907. DEF_TPG_PARAM(AuthMethod);
  908. TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR);
  909. DEF_TPG_PARAM(HeaderDigest);
  910. TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR);
  911. DEF_TPG_PARAM(DataDigest);
  912. TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR);
  913. DEF_TPG_PARAM(MaxConnections);
  914. TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR);
  915. DEF_TPG_PARAM(TargetAlias);
  916. TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR);
  917. DEF_TPG_PARAM(InitialR2T);
  918. TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR);
  919. DEF_TPG_PARAM(ImmediateData);
  920. TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR);
  921. DEF_TPG_PARAM(MaxRecvDataSegmentLength);
  922. TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR);
  923. DEF_TPG_PARAM(MaxBurstLength);
  924. TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR);
  925. DEF_TPG_PARAM(FirstBurstLength);
  926. TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR);
  927. DEF_TPG_PARAM(DefaultTime2Wait);
  928. TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR);
  929. DEF_TPG_PARAM(DefaultTime2Retain);
  930. TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR);
  931. DEF_TPG_PARAM(MaxOutstandingR2T);
  932. TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR);
  933. DEF_TPG_PARAM(DataPDUInOrder);
  934. TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR);
  935. DEF_TPG_PARAM(DataSequenceInOrder);
  936. TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR);
  937. DEF_TPG_PARAM(ErrorRecoveryLevel);
  938. TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR);
  939. DEF_TPG_PARAM(IFMarker);
  940. TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR);
  941. DEF_TPG_PARAM(OFMarker);
  942. TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR);
  943. DEF_TPG_PARAM(IFMarkInt);
  944. TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR);
  945. DEF_TPG_PARAM(OFMarkInt);
  946. TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR);
  947. static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
  948. &iscsi_tpg_param_AuthMethod.attr,
  949. &iscsi_tpg_param_HeaderDigest.attr,
  950. &iscsi_tpg_param_DataDigest.attr,
  951. &iscsi_tpg_param_MaxConnections.attr,
  952. &iscsi_tpg_param_TargetAlias.attr,
  953. &iscsi_tpg_param_InitialR2T.attr,
  954. &iscsi_tpg_param_ImmediateData.attr,
  955. &iscsi_tpg_param_MaxRecvDataSegmentLength.attr,
  956. &iscsi_tpg_param_MaxBurstLength.attr,
  957. &iscsi_tpg_param_FirstBurstLength.attr,
  958. &iscsi_tpg_param_DefaultTime2Wait.attr,
  959. &iscsi_tpg_param_DefaultTime2Retain.attr,
  960. &iscsi_tpg_param_MaxOutstandingR2T.attr,
  961. &iscsi_tpg_param_DataPDUInOrder.attr,
  962. &iscsi_tpg_param_DataSequenceInOrder.attr,
  963. &iscsi_tpg_param_ErrorRecoveryLevel.attr,
  964. &iscsi_tpg_param_IFMarker.attr,
  965. &iscsi_tpg_param_OFMarker.attr,
  966. &iscsi_tpg_param_IFMarkInt.attr,
  967. &iscsi_tpg_param_OFMarkInt.attr,
  968. NULL,
  969. };
  970. /* End items for lio_target_tpg_param_cit */
  971. /* Start items for lio_target_tpg_cit */
  972. static ssize_t lio_target_tpg_show_enable(
  973. struct se_portal_group *se_tpg,
  974. char *page)
  975. {
  976. struct iscsi_portal_group *tpg = container_of(se_tpg,
  977. struct iscsi_portal_group, tpg_se_tpg);
  978. ssize_t len;
  979. spin_lock(&tpg->tpg_state_lock);
  980. len = sprintf(page, "%d\n",
  981. (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
  982. spin_unlock(&tpg->tpg_state_lock);
  983. return len;
  984. }
  985. static ssize_t lio_target_tpg_store_enable(
  986. struct se_portal_group *se_tpg,
  987. const char *page,
  988. size_t count)
  989. {
  990. struct iscsi_portal_group *tpg = container_of(se_tpg,
  991. struct iscsi_portal_group, tpg_se_tpg);
  992. char *endptr;
  993. u32 op;
  994. int ret = 0;
  995. op = simple_strtoul(page, &endptr, 0);
  996. if ((op != 1) && (op != 0)) {
  997. pr_err("Illegal value for tpg_enable: %u\n", op);
  998. return -EINVAL;
  999. }
  1000. ret = iscsit_get_tpg(tpg);
  1001. if (ret < 0)
  1002. return -EINVAL;
  1003. if (op) {
  1004. ret = iscsit_tpg_enable_portal_group(tpg);
  1005. if (ret < 0)
  1006. goto out;
  1007. } else {
  1008. /*
  1009. * iscsit_tpg_disable_portal_group() assumes force=1
  1010. */
  1011. ret = iscsit_tpg_disable_portal_group(tpg, 1);
  1012. if (ret < 0)
  1013. goto out;
  1014. }
  1015. iscsit_put_tpg(tpg);
  1016. return count;
  1017. out:
  1018. iscsit_put_tpg(tpg);
  1019. return -EINVAL;
  1020. }
  1021. TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR);
  1022. static struct configfs_attribute *lio_target_tpg_attrs[] = {
  1023. &lio_target_tpg_enable.attr,
  1024. NULL,
  1025. };
  1026. /* End items for lio_target_tpg_cit */
  1027. /* Start items for lio_target_tiqn_cit */
  1028. struct se_portal_group *lio_target_tiqn_addtpg(
  1029. struct se_wwn *wwn,
  1030. struct config_group *group,
  1031. const char *name)
  1032. {
  1033. struct iscsi_portal_group *tpg;
  1034. struct iscsi_tiqn *tiqn;
  1035. char *tpgt_str, *end_ptr;
  1036. int ret = 0;
  1037. unsigned short int tpgt;
  1038. tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
  1039. /*
  1040. * Only tpgt_# directory groups can be created below
  1041. * target/iscsi/iqn.superturodiskarry/
  1042. */
  1043. tpgt_str = strstr(name, "tpgt_");
  1044. if (!tpgt_str) {
  1045. pr_err("Unable to locate \"tpgt_#\" directory"
  1046. " group\n");
  1047. return NULL;
  1048. }
  1049. tpgt_str += 5; /* Skip ahead of "tpgt_" */
  1050. tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
  1051. tpg = iscsit_alloc_portal_group(tiqn, tpgt);
  1052. if (!tpg)
  1053. return NULL;
  1054. ret = core_tpg_register(
  1055. &lio_target_fabric_configfs->tf_ops,
  1056. wwn, &tpg->tpg_se_tpg, tpg,
  1057. TRANSPORT_TPG_TYPE_NORMAL);
  1058. if (ret < 0)
  1059. return NULL;
  1060. ret = iscsit_tpg_add_portal_group(tiqn, tpg);
  1061. if (ret != 0)
  1062. goto out;
  1063. pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
  1064. pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
  1065. name);
  1066. return &tpg->tpg_se_tpg;
  1067. out:
  1068. core_tpg_deregister(&tpg->tpg_se_tpg);
  1069. kfree(tpg);
  1070. return NULL;
  1071. }
  1072. void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
  1073. {
  1074. struct iscsi_portal_group *tpg;
  1075. struct iscsi_tiqn *tiqn;
  1076. tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
  1077. tiqn = tpg->tpg_tiqn;
  1078. /*
  1079. * iscsit_tpg_del_portal_group() assumes force=1
  1080. */
  1081. pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
  1082. iscsit_tpg_del_portal_group(tiqn, tpg, 1);
  1083. }
  1084. /* End items for lio_target_tiqn_cit */
  1085. /* Start LIO-Target TIQN struct contig_item lio_target_cit */
  1086. static ssize_t lio_target_wwn_show_attr_lio_version(
  1087. struct target_fabric_configfs *tf,
  1088. char *page)
  1089. {
  1090. return sprintf(page, "RisingTide Systems Linux-iSCSI Target "ISCSIT_VERSION"\n");
  1091. }
  1092. TF_WWN_ATTR_RO(lio_target, lio_version);
  1093. static struct configfs_attribute *lio_target_wwn_attrs[] = {
  1094. &lio_target_wwn_lio_version.attr,
  1095. NULL,
  1096. };
  1097. struct se_wwn *lio_target_call_coreaddtiqn(
  1098. struct target_fabric_configfs *tf,
  1099. struct config_group *group,
  1100. const char *name)
  1101. {
  1102. struct config_group *stats_cg;
  1103. struct iscsi_tiqn *tiqn;
  1104. tiqn = iscsit_add_tiqn((unsigned char *)name);
  1105. if (IS_ERR(tiqn))
  1106. return ERR_CAST(tiqn);
  1107. /*
  1108. * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group.
  1109. */
  1110. stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
  1111. stats_cg->default_groups = kzalloc(sizeof(struct config_group) * 6,
  1112. GFP_KERNEL);
  1113. if (!stats_cg->default_groups) {
  1114. pr_err("Unable to allocate memory for"
  1115. " stats_cg->default_groups\n");
  1116. iscsit_del_tiqn(tiqn);
  1117. return ERR_PTR(-ENOMEM);
  1118. }
  1119. stats_cg->default_groups[0] = &WWN_STAT_GRPS(tiqn)->iscsi_instance_group;
  1120. stats_cg->default_groups[1] = &WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group;
  1121. stats_cg->default_groups[2] = &WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group;
  1122. stats_cg->default_groups[3] = &WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group;
  1123. stats_cg->default_groups[4] = &WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group;
  1124. stats_cg->default_groups[5] = NULL;
  1125. config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_instance_group,
  1126. "iscsi_instance", &iscsi_stat_instance_cit);
  1127. config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group,
  1128. "iscsi_sess_err", &iscsi_stat_sess_err_cit);
  1129. config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group,
  1130. "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
  1131. config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group,
  1132. "iscsi_login_stats", &iscsi_stat_login_cit);
  1133. config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group,
  1134. "iscsi_logout_stats", &iscsi_stat_logout_cit);
  1135. pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
  1136. pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
  1137. " %s\n", name);
  1138. return &tiqn->tiqn_wwn;
  1139. }
  1140. void lio_target_call_coredeltiqn(
  1141. struct se_wwn *wwn)
  1142. {
  1143. struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
  1144. struct config_item *df_item;
  1145. struct config_group *stats_cg;
  1146. int i;
  1147. stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
  1148. for (i = 0; stats_cg->default_groups[i]; i++) {
  1149. df_item = &stats_cg->default_groups[i]->cg_item;
  1150. stats_cg->default_groups[i] = NULL;
  1151. config_item_put(df_item);
  1152. }
  1153. kfree(stats_cg->default_groups);
  1154. pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
  1155. tiqn->tiqn);
  1156. iscsit_del_tiqn(tiqn);
  1157. }
  1158. /* End LIO-Target TIQN struct contig_lio_target_cit */
  1159. /* Start lio_target_discovery_auth_cit */
  1160. #define DEF_DISC_AUTH_STR(name, flags) \
  1161. __DEF_NACL_AUTH_STR(disc, name, flags) \
  1162. static ssize_t iscsi_disc_show_##name( \
  1163. struct target_fabric_configfs *tf, \
  1164. char *page) \
  1165. { \
  1166. return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
  1167. page); \
  1168. } \
  1169. static ssize_t iscsi_disc_store_##name( \
  1170. struct target_fabric_configfs *tf, \
  1171. const char *page, \
  1172. size_t count) \
  1173. { \
  1174. return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \
  1175. page, count); \
  1176. }
  1177. #define DEF_DISC_AUTH_INT(name) \
  1178. __DEF_NACL_AUTH_INT(disc, name) \
  1179. static ssize_t iscsi_disc_show_##name( \
  1180. struct target_fabric_configfs *tf, \
  1181. char *page) \
  1182. { \
  1183. return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
  1184. page); \
  1185. }
  1186. #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode)
  1187. #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name)
  1188. /*
  1189. * One-way authentication userid
  1190. */
  1191. DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
  1192. DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
  1193. /*
  1194. * One-way authentication password
  1195. */
  1196. DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
  1197. DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
  1198. /*
  1199. * Enforce mutual authentication
  1200. */
  1201. DEF_DISC_AUTH_INT(authenticate_target);
  1202. DISC_AUTH_ATTR_RO(authenticate_target);
  1203. /*
  1204. * Mutual authentication userid
  1205. */
  1206. DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
  1207. DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
  1208. /*
  1209. * Mutual authentication password
  1210. */
  1211. DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
  1212. DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
  1213. /*
  1214. * enforce_discovery_auth
  1215. */
  1216. static ssize_t iscsi_disc_show_enforce_discovery_auth(
  1217. struct target_fabric_configfs *tf,
  1218. char *page)
  1219. {
  1220. struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
  1221. return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
  1222. }
  1223. static ssize_t iscsi_disc_store_enforce_discovery_auth(
  1224. struct target_fabric_configfs *tf,
  1225. const char *page,
  1226. size_t count)
  1227. {
  1228. struct iscsi_param *param;
  1229. struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
  1230. char *endptr;
  1231. u32 op;
  1232. op = simple_strtoul(page, &endptr, 0);
  1233. if ((op != 1) && (op != 0)) {
  1234. pr_err("Illegal value for enforce_discovery_auth:"
  1235. " %u\n", op);
  1236. return -EINVAL;
  1237. }
  1238. if (!discovery_tpg) {
  1239. pr_err("iscsit_global->discovery_tpg is NULL\n");
  1240. return -EINVAL;
  1241. }
  1242. param = iscsi_find_param_from_key(AUTHMETHOD,
  1243. discovery_tpg->param_list);
  1244. if (!param)
  1245. return -EINVAL;
  1246. if (op) {
  1247. /*
  1248. * Reset the AuthMethod key to CHAP.
  1249. */
  1250. if (iscsi_update_param_value(param, CHAP) < 0)
  1251. return -EINVAL;
  1252. discovery_tpg->tpg_attrib.authentication = 1;
  1253. iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
  1254. pr_debug("LIO-CORE[0] Successfully enabled"
  1255. " authentication enforcement for iSCSI"
  1256. " Discovery TPG\n");
  1257. } else {
  1258. /*
  1259. * Reset the AuthMethod key to CHAP,None
  1260. */
  1261. if (iscsi_update_param_value(param, "CHAP,None") < 0)
  1262. return -EINVAL;
  1263. discovery_tpg->tpg_attrib.authentication = 0;
  1264. iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
  1265. pr_debug("LIO-CORE[0] Successfully disabled"
  1266. " authentication enforcement for iSCSI"
  1267. " Discovery TPG\n");
  1268. }
  1269. return count;
  1270. }
  1271. DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR);
  1272. static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
  1273. &iscsi_disc_userid.attr,
  1274. &iscsi_disc_password.attr,
  1275. &iscsi_disc_authenticate_target.attr,
  1276. &iscsi_disc_userid_mutual.attr,
  1277. &iscsi_disc_password_mutual.attr,
  1278. &iscsi_disc_enforce_discovery_auth.attr,
  1279. NULL,
  1280. };
  1281. /* End lio_target_discovery_auth_cit */
  1282. /* Start functions for target_core_fabric_ops */
  1283. static char *iscsi_get_fabric_name(void)
  1284. {
  1285. return "iSCSI";
  1286. }
  1287. static u32 iscsi_get_task_tag(struct se_cmd *se_cmd)
  1288. {
  1289. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1290. return cmd->init_task_tag;
  1291. }
  1292. static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
  1293. {
  1294. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1295. return cmd->i_state;
  1296. }
  1297. static u32 lio_sess_get_index(struct se_session *se_sess)
  1298. {
  1299. struct iscsi_session *sess = se_sess->fabric_sess_ptr;
  1300. return sess->session_index;
  1301. }
  1302. static u32 lio_sess_get_initiator_sid(
  1303. struct se_session *se_sess,
  1304. unsigned char *buf,
  1305. u32 size)
  1306. {
  1307. struct iscsi_session *sess = se_sess->fabric_sess_ptr;
  1308. /*
  1309. * iSCSI Initiator Session Identifier from RFC-3720.
  1310. */
  1311. return snprintf(buf, size, "%02x%02x%02x%02x%02x%02x",
  1312. sess->isid[0], sess->isid[1], sess->isid[2],
  1313. sess->isid[3], sess->isid[4], sess->isid[5]);
  1314. }
  1315. static int lio_queue_data_in(struct se_cmd *se_cmd)
  1316. {
  1317. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1318. cmd->i_state = ISTATE_SEND_DATAIN;
  1319. iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
  1320. return 0;
  1321. }
  1322. static int lio_write_pending(struct se_cmd *se_cmd)
  1323. {
  1324. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1325. if (!cmd->immediate_data && !cmd->unsolicited_data)
  1326. return iscsit_build_r2ts_for_cmd(cmd, cmd->conn, false);
  1327. return 0;
  1328. }
  1329. static int lio_write_pending_status(struct se_cmd *se_cmd)
  1330. {
  1331. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1332. int ret;
  1333. spin_lock_bh(&cmd->istate_lock);
  1334. ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
  1335. spin_unlock_bh(&cmd->istate_lock);
  1336. return ret;
  1337. }
  1338. static int lio_queue_status(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_STATUS;
  1342. iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
  1343. return 0;
  1344. }
  1345. static u16 lio_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)
  1346. {
  1347. unsigned char *buffer = se_cmd->sense_buffer;
  1348. /*
  1349. * From RFC-3720 10.4.7. Data Segment - Sense and Response Data Segment
  1350. * 16-bit SenseLength.
  1351. */
  1352. buffer[0] = ((sense_length >> 8) & 0xff);
  1353. buffer[1] = (sense_length & 0xff);
  1354. /*
  1355. * Return two byte offset into allocated sense_buffer.
  1356. */
  1357. return 2;
  1358. }
  1359. static u16 lio_get_fabric_sense_len(void)
  1360. {
  1361. /*
  1362. * Return two byte offset into allocated sense_buffer.
  1363. */
  1364. return 2;
  1365. }
  1366. static int lio_queue_tm_rsp(struct se_cmd *se_cmd)
  1367. {
  1368. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1369. cmd->i_state = ISTATE_SEND_TASKMGTRSP;
  1370. iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
  1371. return 0;
  1372. }
  1373. static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
  1374. {
  1375. struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
  1376. return &tpg->tpg_tiqn->tiqn[0];
  1377. }
  1378. static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
  1379. {
  1380. struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
  1381. return tpg->tpgt;
  1382. }
  1383. static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
  1384. {
  1385. struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
  1386. return ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth;
  1387. }
  1388. static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
  1389. {
  1390. struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
  1391. return ISCSI_TPG_ATTRIB(tpg)->generate_node_acls;
  1392. }
  1393. static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
  1394. {
  1395. struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
  1396. return ISCSI_TPG_ATTRIB(tpg)->cache_dynamic_acls;
  1397. }
  1398. static int lio_tpg_check_demo_mode_write_protect(
  1399. struct se_portal_group *se_tpg)
  1400. {
  1401. struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
  1402. return ISCSI_TPG_ATTRIB(tpg)->demo_mode_write_protect;
  1403. }
  1404. static int lio_tpg_check_prod_mode_write_protect(
  1405. struct se_portal_group *se_tpg)
  1406. {
  1407. struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
  1408. return ISCSI_TPG_ATTRIB(tpg)->prod_mode_write_protect;
  1409. }
  1410. static void lio_tpg_release_fabric_acl(
  1411. struct se_portal_group *se_tpg,
  1412. struct se_node_acl *se_acl)
  1413. {
  1414. struct iscsi_node_acl *acl = container_of(se_acl,
  1415. struct iscsi_node_acl, se_node_acl);
  1416. kfree(acl);
  1417. }
  1418. /*
  1419. * Called with spin_lock_bh(struct se_portal_group->session_lock) held..
  1420. *
  1421. * Also, this function calls iscsit_inc_session_usage_count() on the
  1422. * struct iscsi_session in question.
  1423. */
  1424. static int lio_tpg_shutdown_session(struct se_session *se_sess)
  1425. {
  1426. struct iscsi_session *sess = se_sess->fabric_sess_ptr;
  1427. spin_lock(&sess->conn_lock);
  1428. if (atomic_read(&sess->session_fall_back_to_erl0) ||
  1429. atomic_read(&sess->session_logout) ||
  1430. (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
  1431. spin_unlock(&sess->conn_lock);
  1432. return 0;
  1433. }
  1434. atomic_set(&sess->session_reinstatement, 1);
  1435. spin_unlock(&sess->conn_lock);
  1436. iscsit_stop_time2retain_timer(sess);
  1437. iscsit_stop_session(sess, 1, 1);
  1438. return 1;
  1439. }
  1440. /*
  1441. * Calls iscsit_dec_session_usage_count() as inverse of
  1442. * lio_tpg_shutdown_session()
  1443. */
  1444. static void lio_tpg_close_session(struct se_session *se_sess)
  1445. {
  1446. struct iscsi_session *sess = se_sess->fabric_sess_ptr;
  1447. /*
  1448. * If the iSCSI Session for the iSCSI Initiator Node exists,
  1449. * forcefully shutdown the iSCSI NEXUS.
  1450. */
  1451. iscsit_close_session(sess);
  1452. }
  1453. static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
  1454. {
  1455. struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
  1456. return tpg->tpg_tiqn->tiqn_index;
  1457. }
  1458. static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
  1459. {
  1460. struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
  1461. se_node_acl);
  1462. ISCSI_NODE_ATTRIB(acl)->nacl = acl;
  1463. iscsit_set_default_node_attribues(acl);
  1464. }
  1465. static void lio_release_cmd(struct se_cmd *se_cmd)
  1466. {
  1467. struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
  1468. iscsit_release_cmd(cmd);
  1469. }
  1470. /* End functions for target_core_fabric_ops */
  1471. int iscsi_target_register_configfs(void)
  1472. {
  1473. struct target_fabric_configfs *fabric;
  1474. int ret;
  1475. lio_target_fabric_configfs = NULL;
  1476. fabric = target_fabric_configfs_init(THIS_MODULE, "iscsi");
  1477. if (IS_ERR(fabric)) {
  1478. pr_err("target_fabric_configfs_init() for"
  1479. " LIO-Target failed!\n");
  1480. return PTR_ERR(fabric);
  1481. }
  1482. /*
  1483. * Setup the fabric API of function pointers used by target_core_mod..
  1484. */
  1485. fabric->tf_ops.get_fabric_name = &iscsi_get_fabric_name;
  1486. fabric->tf_ops.get_fabric_proto_ident = &iscsi_get_fabric_proto_ident;
  1487. fabric->tf_ops.tpg_get_wwn = &lio_tpg_get_endpoint_wwn;
  1488. fabric->tf_ops.tpg_get_tag = &lio_tpg_get_tag;
  1489. fabric->tf_ops.tpg_get_default_depth = &lio_tpg_get_default_depth;
  1490. fabric->tf_ops.tpg_get_pr_transport_id = &iscsi_get_pr_transport_id;
  1491. fabric->tf_ops.tpg_get_pr_transport_id_len =
  1492. &iscsi_get_pr_transport_id_len;
  1493. fabric->tf_ops.tpg_parse_pr_out_transport_id =
  1494. &iscsi_parse_pr_out_transport_id;
  1495. fabric->tf_ops.tpg_check_demo_mode = &lio_tpg_check_demo_mode;
  1496. fabric->tf_ops.tpg_check_demo_mode_cache =
  1497. &lio_tpg_check_demo_mode_cache;
  1498. fabric->tf_ops.tpg_check_demo_mode_write_protect =
  1499. &lio_tpg_check_demo_mode_write_protect;
  1500. fabric->tf_ops.tpg_check_prod_mode_write_protect =
  1501. &lio_tpg_check_prod_mode_write_protect;
  1502. fabric->tf_ops.tpg_alloc_fabric_acl = &lio_tpg_alloc_fabric_acl;
  1503. fabric->tf_ops.tpg_release_fabric_acl = &lio_tpg_release_fabric_acl;
  1504. fabric->tf_ops.tpg_get_inst_index = &lio_tpg_get_inst_index;
  1505. fabric->tf_ops.release_cmd = &lio_release_cmd;
  1506. fabric->tf_ops.shutdown_session = &lio_tpg_shutdown_session;
  1507. fabric->tf_ops.close_session = &lio_tpg_close_session;
  1508. fabric->tf_ops.sess_get_index = &lio_sess_get_index;
  1509. fabric->tf_ops.sess_get_initiator_sid = &lio_sess_get_initiator_sid;
  1510. fabric->tf_ops.write_pending = &lio_write_pending;
  1511. fabric->tf_ops.write_pending_status = &lio_write_pending_status;
  1512. fabric->tf_ops.set_default_node_attributes =
  1513. &lio_set_default_node_attributes;
  1514. fabric->tf_ops.get_task_tag = &iscsi_get_task_tag;
  1515. fabric->tf_ops.get_cmd_state = &iscsi_get_cmd_state;
  1516. fabric->tf_ops.queue_data_in = &lio_queue_data_in;
  1517. fabric->tf_ops.queue_status = &lio_queue_status;
  1518. fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp;
  1519. fabric->tf_ops.set_fabric_sense_len = &lio_set_fabric_sense_len;
  1520. fabric->tf_ops.get_fabric_sense_len = &lio_get_fabric_sense_len;
  1521. /*
  1522. * Setup function pointers for generic logic in target_core_fabric_configfs.c
  1523. */
  1524. fabric->tf_ops.fabric_make_wwn = &lio_target_call_coreaddtiqn;
  1525. fabric->tf_ops.fabric_drop_wwn = &lio_target_call_coredeltiqn;
  1526. fabric->tf_ops.fabric_make_tpg = &lio_target_tiqn_addtpg;
  1527. fabric->tf_ops.fabric_drop_tpg = &lio_target_tiqn_deltpg;
  1528. fabric->tf_ops.fabric_post_link = NULL;
  1529. fabric->tf_ops.fabric_pre_unlink = NULL;
  1530. fabric->tf_ops.fabric_make_np = &lio_target_call_addnptotpg;
  1531. fabric->tf_ops.fabric_drop_np = &lio_target_call_delnpfromtpg;
  1532. fabric->tf_ops.fabric_make_nodeacl = &lio_target_make_nodeacl;
  1533. fabric->tf_ops.fabric_drop_nodeacl = &lio_target_drop_nodeacl;
  1534. /*
  1535. * Setup default attribute lists for various fabric->tf_cit_tmpl
  1536. * sturct config_item_type's
  1537. */
  1538. TF_CIT_TMPL(fabric)->tfc_discovery_cit.ct_attrs = lio_target_discovery_auth_attrs;
  1539. TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = lio_target_wwn_attrs;
  1540. TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = lio_target_tpg_attrs;
  1541. TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = lio_target_tpg_attrib_attrs;
  1542. TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = lio_target_tpg_param_attrs;
  1543. TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = lio_target_portal_attrs;
  1544. TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = lio_target_initiator_attrs;
  1545. TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = lio_target_nacl_attrib_attrs;
  1546. TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = lio_target_nacl_auth_attrs;
  1547. TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = lio_target_nacl_param_attrs;
  1548. ret = target_fabric_configfs_register(fabric);
  1549. if (ret < 0) {
  1550. pr_err("target_fabric_configfs_register() for"
  1551. " LIO-Target failed!\n");
  1552. target_fabric_configfs_free(fabric);
  1553. return ret;
  1554. }
  1555. lio_target_fabric_configfs = fabric;
  1556. pr_debug("LIO_TARGET[0] - Set fabric ->"
  1557. " lio_target_fabric_configfs\n");
  1558. return 0;
  1559. }
  1560. void iscsi_target_deregister_configfs(void)
  1561. {
  1562. if (!lio_target_fabric_configfs)
  1563. return;
  1564. /*
  1565. * Shutdown discovery sessions and disable discovery TPG
  1566. */
  1567. if (iscsit_global->discovery_tpg)
  1568. iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1);
  1569. target_fabric_configfs_deregister(lio_target_fabric_configfs);
  1570. lio_target_fabric_configfs = NULL;
  1571. pr_debug("LIO_TARGET[0] - Cleared"
  1572. " lio_target_fabric_configfs\n");
  1573. }