Deleted Added
full compact
ctl_frontend_iscsi.c (268690) ctl_frontend_iscsi.c (268691)
1/*-
2 * Copyright (c) 2012 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
1/*-
2 * Copyright (c) 2012 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Edward Tomasz Napierala under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268690 2014-07-15 17:12:37Z mav $
29 * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268691 2014-07-15 17:13:49Z mav $
30 */
31
32/*
33 * CTL frontend for the iSCSI protocol.
34 */
35
36#include <sys/cdefs.h>
30 */
31
32/*
33 * CTL frontend for the iSCSI protocol.
34 */
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268690 2014-07-15 17:12:37Z mav $");
37__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268691 2014-07-15 17:13:49Z mav $");
38
39#include <sys/param.h>
40#include <sys/capability.h>
41#include <sys/condvar.h>
42#include <sys/file.h>
43#include <sys/kernel.h>
44#include <sys/kthread.h>
45#include <sys/lock.h>

--- 1040 unchanged lines hidden (view full) ---

1086 */
1087 for (;;) {
1088 refcount_acquire(&cs->cs_outstanding_ctl_pdus);
1089 last = refcount_release(&cs->cs_outstanding_ctl_pdus);
1090 if (last != 0)
1091 break;
1092 CFISCSI_SESSION_WARN(cs, "waiting for CTL to terminate tasks, "
1093 "%d remaining", cs->cs_outstanding_ctl_pdus);
38
39#include <sys/param.h>
40#include <sys/capability.h>
41#include <sys/condvar.h>
42#include <sys/file.h>
43#include <sys/kernel.h>
44#include <sys/kthread.h>
45#include <sys/lock.h>

--- 1040 unchanged lines hidden (view full) ---

1086 */
1087 for (;;) {
1088 refcount_acquire(&cs->cs_outstanding_ctl_pdus);
1089 last = refcount_release(&cs->cs_outstanding_ctl_pdus);
1090 if (last != 0)
1091 break;
1092 CFISCSI_SESSION_WARN(cs, "waiting for CTL to terminate tasks, "
1093 "%d remaining", cs->cs_outstanding_ctl_pdus);
1094 pause("cfiscsi_terminate", hz / 100);
1094 tsleep(__DEVOLATILE(void *, &cs->cs_outstanding_ctl_pdus),
1095 0, "cfiscsi_terminate", hz / 100);
1095 }
1096}
1097
1098static void
1099cfiscsi_maintenance_thread(void *arg)
1100{
1101 struct cfiscsi_session *cs;
1102

--- 300 unchanged lines hidden (view full) ---

1403 ct->ct_state);
1404 return (retval);
1405}
1406
1407static void
1408cfiscsi_ioctl_handoff(struct ctl_iscsi *ci)
1409{
1410 struct cfiscsi_softc *softc;
1096 }
1097}
1098
1099static void
1100cfiscsi_maintenance_thread(void *arg)
1101{
1102 struct cfiscsi_session *cs;
1103

--- 300 unchanged lines hidden (view full) ---

1404 ct->ct_state);
1405 return (retval);
1406}
1407
1408static void
1409cfiscsi_ioctl_handoff(struct ctl_iscsi *ci)
1410{
1411 struct cfiscsi_softc *softc;
1411 struct cfiscsi_session *cs;
1412 struct cfiscsi_session *cs, *cs2;
1412 struct cfiscsi_target *ct;
1413 struct ctl_iscsi_handoff_params *cihp;
1414 int error;
1415
1416 cihp = (struct ctl_iscsi_handoff_params *)&(ci->data);
1417 softc = &cfiscsi_softc;
1418
1419 CFISCSI_DEBUG("new connection from %s (%s) to %s",

--- 79 unchanged lines hidden (view full) ---

1499 memcpy(cs->cs_initiator_isid,
1500 cihp->initiator_isid, sizeof(cs->cs_initiator_isid));
1501 snprintf(cs->cs_initiator_id, sizeof(cs->cs_initiator_id),
1502 "%s,i,0x%02x%02x%02x%02x%02x%02x", cs->cs_initiator_name,
1503 cihp->initiator_isid[0], cihp->initiator_isid[1],
1504 cihp->initiator_isid[2], cihp->initiator_isid[3],
1505 cihp->initiator_isid[4], cihp->initiator_isid[5]);
1506
1413 struct cfiscsi_target *ct;
1414 struct ctl_iscsi_handoff_params *cihp;
1415 int error;
1416
1417 cihp = (struct ctl_iscsi_handoff_params *)&(ci->data);
1418 softc = &cfiscsi_softc;
1419
1420 CFISCSI_DEBUG("new connection from %s (%s) to %s",

--- 79 unchanged lines hidden (view full) ---

1500 memcpy(cs->cs_initiator_isid,
1501 cihp->initiator_isid, sizeof(cs->cs_initiator_isid));
1502 snprintf(cs->cs_initiator_id, sizeof(cs->cs_initiator_id),
1503 "%s,i,0x%02x%02x%02x%02x%02x%02x", cs->cs_initiator_name,
1504 cihp->initiator_isid[0], cihp->initiator_isid[1],
1505 cihp->initiator_isid[2], cihp->initiator_isid[3],
1506 cihp->initiator_isid[4], cihp->initiator_isid[5]);
1507
1508 refcount_acquire(&cs->cs_outstanding_ctl_pdus);
1509restart:
1510 if (!cs->cs_terminating) {
1511 mtx_lock(&softc->lock);
1512 TAILQ_FOREACH(cs2, &softc->sessions, cs_next) {
1513 if (cs2 != cs && cs2->cs_tasks_aborted == false &&
1514 cs->cs_target == cs2->cs_target &&
1515 cs->cs_portal_group_tag == cs2->cs_portal_group_tag &&
1516 strcmp(cs->cs_initiator_id, cs2->cs_initiator_id) == 0) {
1517 cfiscsi_session_terminate(cs2);
1518 mtx_unlock(&softc->lock);
1519 pause("cfiscsi_reinstate", 1);
1520 goto restart;
1521 }
1522 }
1523 mtx_unlock(&softc->lock);
1524 }
1525
1526 /*
1527 * Register initiator with CTL.
1528 */
1529 cfiscsi_session_register_initiator(cs);
1530
1507#ifdef ICL_KERNEL_PROXY
1508 if (cihp->socket > 0) {
1509#endif
1510 error = icl_conn_handoff(cs->cs_conn, cihp->socket);
1511 if (error != 0) {
1531#ifdef ICL_KERNEL_PROXY
1532 if (cihp->socket > 0) {
1533#endif
1534 error = icl_conn_handoff(cs->cs_conn, cihp->socket);
1535 if (error != 0) {
1512 cfiscsi_session_delete(cs);
1536 cfiscsi_session_terminate(cs);
1537 refcount_release(&cs->cs_outstanding_ctl_pdus);
1513 ci->status = CTL_ISCSI_ERROR;
1514 snprintf(ci->error_str, sizeof(ci->error_str),
1515 "%s: icl_conn_handoff failed with error %d",
1516 __func__, error);
1517 return;
1518 }
1519#ifdef ICL_KERNEL_PROXY
1520 }
1521#endif
1522
1538 ci->status = CTL_ISCSI_ERROR;
1539 snprintf(ci->error_str, sizeof(ci->error_str),
1540 "%s: icl_conn_handoff failed with error %d",
1541 __func__, error);
1542 return;
1543 }
1544#ifdef ICL_KERNEL_PROXY
1545 }
1546#endif
1547
1523 /*
1524 * Register initiator with CTL.
1525 */
1526 cfiscsi_session_register_initiator(cs);
1527
1528#ifdef ICL_KERNEL_PROXY
1529 cs->cs_login_phase = false;
1530
1531 /*
1532 * First PDU of the Full Feature phase has likely already arrived.
1533 * We have to pick it up and execute properly.
1534 */
1535 if (cs->cs_login_pdu != NULL) {
1536 CFISCSI_SESSION_DEBUG(cs, "picking up first PDU");
1537 cfiscsi_pdu_handle(cs->cs_login_pdu);
1538 cs->cs_login_pdu = NULL;
1539 }
1540#endif
1541
1548#ifdef ICL_KERNEL_PROXY
1549 cs->cs_login_phase = false;
1550
1551 /*
1552 * First PDU of the Full Feature phase has likely already arrived.
1553 * We have to pick it up and execute properly.
1554 */
1555 if (cs->cs_login_pdu != NULL) {
1556 CFISCSI_SESSION_DEBUG(cs, "picking up first PDU");
1557 cfiscsi_pdu_handle(cs->cs_login_pdu);
1558 cs->cs_login_pdu = NULL;
1559 }
1560#endif
1561
1562 refcount_release(&cs->cs_outstanding_ctl_pdus);
1542 ci->status = CTL_ISCSI_OK;
1543}
1544
1545static void
1546cfiscsi_ioctl_list(struct ctl_iscsi *ci)
1547{
1548 struct ctl_iscsi_list_params *cilp;
1549 struct cfiscsi_session *cs;

--- 1292 unchanged lines hidden (view full) ---

2842 ("invalid CTL status %#x", io->io_hdr.status));
2843
2844 if (io->io_hdr.io_type == CTL_IO_TASK &&
2845 io->taskio.task_action == CTL_TASK_I_T_NEXUS_RESET) {
2846 /*
2847 * Implicit task termination has just completed; nothing to do.
2848 */
2849 cs = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr;
1563 ci->status = CTL_ISCSI_OK;
1564}
1565
1566static void
1567cfiscsi_ioctl_list(struct ctl_iscsi *ci)
1568{
1569 struct ctl_iscsi_list_params *cilp;
1570 struct cfiscsi_session *cs;

--- 1292 unchanged lines hidden (view full) ---

2863 ("invalid CTL status %#x", io->io_hdr.status));
2864
2865 if (io->io_hdr.io_type == CTL_IO_TASK &&
2866 io->taskio.task_action == CTL_TASK_I_T_NEXUS_RESET) {
2867 /*
2868 * Implicit task termination has just completed; nothing to do.
2869 */
2870 cs = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr;
2871 cs->cs_tasks_aborted = true;
2850 refcount_release(&cs->cs_outstanding_ctl_pdus);
2872 refcount_release(&cs->cs_outstanding_ctl_pdus);
2873 wakeup(__DEVOLATILE(void *, &cs->cs_outstanding_ctl_pdus));
2851 ctl_free_io(io);
2852 return;
2853 }
2854
2855 request = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr;
2856 cs = PDU_SESSION(request);
2857 refcount_release(&cs->cs_outstanding_ctl_pdus);
2858

--- 12 unchanged lines hidden ---
2874 ctl_free_io(io);
2875 return;
2876 }
2877
2878 request = io->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr;
2879 cs = PDU_SESSION(request);
2880 refcount_release(&cs->cs_outstanding_ctl_pdus);
2881

--- 12 unchanged lines hidden ---