29 #include <linux/net.h>
30 #include <linux/string.h>
32 #include <linux/slab.h>
35 #include <linux/export.h>
38 #include <scsi/scsi.h>
56 static void core_clear_initiator_node_from_tpg(
72 pr_err(
"%s device entries device pointer is"
73 " NULL, but Initiator has access.\n",
155 if (!tpg->
se_tpg_tfo->tpg_check_demo_mode_write_protect(tpg)) {
168 pr_debug(
"TARGET_CORE[%s]->TPG[%u]_LUN[%u] - Adding %s"
169 " access for LUN in Demo Mode\n",
173 "READ-WRITE" :
"READ-ONLY");
176 lun_access, acl, tpg);
186 static int core_set_queue_depth_for_node(
191 pr_err(
"Queue depth for %s Initiator Node: %s is 0,"
192 "defaulting to 1.\n", tpg->
se_tpg_tfo->get_fabric_name(),
205 for (i = 0; i <
n; i++)
215 a = kzalloc(n *
sizeof(
void*), flags);
218 for (i = 0; i <
n; i++) {
219 a[
i] = kzalloc(size, flags);
232 static int core_create_device_list_for_node(
struct se_node_acl *nacl)
237 nacl->
device_list = array_zalloc(TRANSPORT_MAX_LUNS_PER_TPG,
240 pr_err(
"Unable to allocate memory for"
241 " struct se_node_acl->device_list\n");
251 INIT_LIST_HEAD(&deve->
ua_list);
271 if (!tpg->
se_tpg_tfo->tpg_check_demo_mode(tpg))
274 acl = tpg->
se_tpg_tfo->tpg_alloc_fabric_acl(tpg);
292 tpg->
se_tpg_tfo->set_default_node_attributes(acl);
294 if (core_create_device_list_for_node(acl) < 0) {
295 tpg->
se_tpg_tfo->tpg_release_fabric_acl(tpg, acl);
299 if (core_set_queue_depth_for_node(tpg, acl) < 0) {
301 tpg->
se_tpg_tfo->tpg_release_fabric_acl(tpg, acl);
310 (tpg->
se_tpg_tfo->tpg_check_demo_mode_login_only(tpg) != 1))
318 pr_debug(
"%s_TPG[%u] - Added DYNAMIC ACL with TCQ Depth: %d for %s"
319 " Initiator Node: %s\n", tpg->
se_tpg_tfo->get_fabric_name(),
371 pr_debug(
"%s_TPG[%u] - Replacing dynamic ACL"
372 " for %s\n", tpg->
se_tpg_tfo->get_fabric_name(),
386 pr_err(
"ACL entry for %s Initiator"
387 " Node %s already exists for TPG %u, ignoring"
388 " request.\n", tpg->
se_tpg_tfo->get_fabric_name(),
396 pr_err(
"struct se_node_acl pointer is NULL\n");
419 tpg->
se_tpg_tfo->set_default_node_attributes(acl);
421 if (core_create_device_list_for_node(acl) < 0) {
422 tpg->
se_tpg_tfo->tpg_release_fabric_acl(tpg, acl);
426 if (core_set_queue_depth_for_node(tpg, acl) < 0) {
428 tpg->
se_tpg_tfo->tpg_release_fabric_acl(tpg, acl);
438 pr_debug(
"%s_TPG[%hu] - Added ACL with TCQ Depth: %d for %s"
439 " Initiator Node: %s\n", tpg->
se_tpg_tfo->get_fabric_name(),
499 core_clear_initiator_node_from_tpg(acl, tpg);
502 pr_debug(
"%s_TPG[%hu] - Deleted ACL with TCQ Depth: %d for %s"
503 " Initiator Node: %s\n", tpg->
se_tpg_tfo->get_fabric_name(),
517 unsigned char *initiatorname,
529 pr_err(
"Access Control List entry for %s Initiator"
530 " Node %s does not exists for TPG %hu, ignoring"
531 " request.\n", tpg->
se_tpg_tfo->get_fabric_name(),
548 pr_err(
"Unable to change queue depth for %s"
549 " Initiator Node: %s while session is"
550 " operational. To forcefully change the queue"
551 " depth and force session reinstatement"
552 " use the \"force=1\" parameter.\n",
583 if (core_set_queue_depth_for_node(tpg, acl) < 0) {
608 pr_debug(
"Successfully changed queue depth to: %d for Initiator"
609 " Node: %s on %s Target Portal Group: %u\n", queue_depth,
610 initiatorname, tpg->
se_tpg_tfo->get_fabric_name(),
647 static void core_tpg_release_virtual_lun0(
struct se_portal_group *se_tpg)
658 void *tpg_fabric_ptr,
664 se_tpg->
tpg_lun_list = array_zalloc(TRANSPORT_MAX_LUNS_PER_TPG,
667 pr_err(
"Unable to allocate struct se_portal_group->"
698 if (core_tpg_setup_virtual_lun0(se_tpg) < 0) {
704 spin_lock_bh(&tpg_lock);
706 spin_unlock_bh(&tpg_lock);
708 pr_debug(
"TARGET_CORE[%s]: Allocated %s struct se_portal_group for"
722 pr_debug(
"TARGET_CORE[%s]: Deallocating %s struct se_portal_group"
723 " for endpoint: %s Portal Tag %u\n",
725 "Normal" :
"Discovery", se_tpg->
se_tpg_tfo->get_fabric_name(),
729 spin_lock_bh(&tpg_lock);
731 spin_unlock_bh(&tpg_lock);
749 se_tpg->
se_tpg_tfo->tpg_release_fabric_acl(se_tpg, nacl);
756 core_tpg_release_virtual_lun0(se_tpg);
770 if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) {
771 pr_err(
"%s LUN: %u exceeds TRANSPORT_MAX_LUNS_PER_TPG"
772 "-1: %u for Target Portal Group: %u\n",
782 pr_err(
"TPG Logical Unit Number: %u is already active"
783 " on %s Target Portal Group: %u, ignoring request.\n",
784 unpacked_lun, tpg->
se_tpg_tfo->get_fabric_name(),
814 static void core_tpg_shutdown_lun(
828 if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) {
829 pr_err(
"%s LUN: %u exceeds TRANSPORT_MAX_LUNS_PER_TPG"
830 "-1: %u for Target Portal Group: %u\n",
832 TRANSPORT_MAX_LUNS_PER_TPG-1,
840 pr_err(
"%s Logical Unit Number: %u is not active on"
841 " Target Portal Group: %u, ignoring request.\n",
856 core_tpg_shutdown_lun(tpg, lun);