OSDN Git Service

iscsi-target: fix iscsit_del_np deadlock on unload
[uclinux-h8/linux.git] / drivers / target / iscsi / iscsi_target_login.c
index ca31fa1..5e71ac6 100644 (file)
@@ -249,6 +249,28 @@ static void iscsi_login_set_conn_values(
        mutex_unlock(&auth_id_lock);
 }
 
+static __printf(2, 3) int iscsi_change_param_sprintf(
+       struct iscsi_conn *conn,
+       const char *fmt, ...)
+{
+       va_list args;
+       unsigned char buf[64];
+
+       memset(buf, 0, sizeof buf);
+
+       va_start(args, fmt);
+       vsnprintf(buf, sizeof buf, fmt, args);
+       va_end(args);
+
+       if (iscsi_change_param_value(buf, conn->param_list, 0) < 0) {
+               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
+                               ISCSI_LOGIN_STATUS_NO_RESOURCES);
+               return -1;
+       }
+
+       return 0;
+}
+
 /*
  *     This is the leading connection of a new session,
  *     or session reinstatement.
@@ -339,7 +361,6 @@ static int iscsi_login_zero_tsih_s2(
 {
        struct iscsi_node_attrib *na;
        struct iscsi_session *sess = conn->sess;
-       unsigned char buf[32];
        bool iser = false;
 
        sess->tpg = conn->tpg;
@@ -380,26 +401,16 @@ static int iscsi_login_zero_tsih_s2(
         *
         * In our case, we have already located the struct iscsi_tiqn at this point.
         */
-       memset(buf, 0, 32);
-       sprintf(buf, "TargetPortalGroupTag=%hu", sess->tpg->tpgt);
-       if (iscsi_change_param_value(buf, conn->param_list, 0) < 0) {
-               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-                               ISCSI_LOGIN_STATUS_NO_RESOURCES);
+       if (iscsi_change_param_sprintf(conn, "TargetPortalGroupTag=%hu", sess->tpg->tpgt))
                return -1;
-       }
 
        /*
         * Workaround for Initiators that have broken connection recovery logic.
         *
         * "We would really like to get rid of this." Linux-iSCSI.org team
         */
-       memset(buf, 0, 32);
-       sprintf(buf, "ErrorRecoveryLevel=%d", na->default_erl);
-       if (iscsi_change_param_value(buf, conn->param_list, 0) < 0) {
-               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-                               ISCSI_LOGIN_STATUS_NO_RESOURCES);
+       if (iscsi_change_param_sprintf(conn, "ErrorRecoveryLevel=%d", na->default_erl))
                return -1;
-       }
 
        if (iscsi_login_disable_FIM_keys(conn->param_list, conn) < 0)
                return -1;
@@ -411,12 +422,9 @@ static int iscsi_login_zero_tsih_s2(
                unsigned long mrdsl, off;
                int rc;
 
-               sprintf(buf, "RDMAExtensions=Yes");
-               if (iscsi_change_param_value(buf, conn->param_list, 0) < 0) {
-                       iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-                               ISCSI_LOGIN_STATUS_NO_RESOURCES);
+               if (iscsi_change_param_sprintf(conn, "RDMAExtensions=Yes"))
                        return -1;
-               }
+
                /*
                 * Make MaxRecvDataSegmentLength PAGE_SIZE aligned for
                 * Immediate Data + Unsolicitied Data-OUT if necessary..
@@ -446,12 +454,8 @@ static int iscsi_login_zero_tsih_s2(
                pr_warn("Aligning ISER MaxRecvDataSegmentLength: %lu down"
                        " to PAGE_SIZE\n", mrdsl);
 
-               sprintf(buf, "MaxRecvDataSegmentLength=%lu\n", mrdsl);
-               if (iscsi_change_param_value(buf, conn->param_list, 0) < 0) {
-                       iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-                               ISCSI_LOGIN_STATUS_NO_RESOURCES);
+               if (iscsi_change_param_sprintf(conn, "MaxRecvDataSegmentLength=%lu\n", mrdsl))
                        return -1;
-               }
                /*
                 * ISER currently requires that ImmediateData + Unsolicited
                 * Data be disabled when protection / signature MRs are enabled.
@@ -461,19 +465,12 @@ check_prot:
                   (TARGET_PROT_DOUT_STRIP | TARGET_PROT_DOUT_PASS |
                    TARGET_PROT_DOUT_INSERT)) {
 
-                       sprintf(buf, "ImmediateData=No");
-                       if (iscsi_change_param_value(buf, conn->param_list, 0) < 0) {
-                               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-                                                   ISCSI_LOGIN_STATUS_NO_RESOURCES);
+                       if (iscsi_change_param_sprintf(conn, "ImmediateData=No"))
                                return -1;
-                       }
 
-                       sprintf(buf, "InitialR2T=Yes");
-                       if (iscsi_change_param_value(buf, conn->param_list, 0) < 0) {
-                               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-                                                   ISCSI_LOGIN_STATUS_NO_RESOURCES);
+                       if (iscsi_change_param_sprintf(conn, "InitialR2T=Yes"))
                                return -1;
-                       }
+
                        pr_debug("Forcing ImmediateData=No + InitialR2T=Yes for"
                                 " T10-PI enabled ISER session\n");
                }
@@ -618,13 +615,8 @@ static int iscsi_login_non_zero_tsih_s2(
         *
         * In our case, we have already located the struct iscsi_tiqn at this point.
         */
-       memset(buf, 0, 32);
-       sprintf(buf, "TargetPortalGroupTag=%hu", sess->tpg->tpgt);
-       if (iscsi_change_param_value(buf, conn->param_list, 0) < 0) {
-               iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-                               ISCSI_LOGIN_STATUS_NO_RESOURCES);
+       if (iscsi_change_param_sprintf(conn, "TargetPortalGroupTag=%hu", sess->tpg->tpgt))
                return -1;
-       }
 
        return iscsi_login_disable_FIM_keys(conn->param_list, conn);
 }
@@ -1153,7 +1145,7 @@ iscsit_conn_set_transport(struct iscsi_conn *conn, struct iscsit_transport *t)
 void iscsi_target_login_sess_out(struct iscsi_conn *conn,
                struct iscsi_np *np, bool zero_tsih, bool new_sess)
 {
-       if (new_sess == false)
+       if (!new_sess)
                goto old_sess_out;
 
        pr_err("iSCSI Login negotiation failed.\n");
@@ -1224,7 +1216,7 @@ old_sess_out:
 static int __iscsi_target_login_thread(struct iscsi_np *np)
 {
        u8 *buffer, zero_tsih = 0;
-       int ret = 0, rc, stop;
+       int ret = 0, rc;
        struct iscsi_conn *conn = NULL;
        struct iscsi_login *login;
        struct iscsi_portal_group *tpg = NULL;
@@ -1238,6 +1230,9 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
        if (np->np_thread_state == ISCSI_NP_THREAD_RESET) {
                np->np_thread_state = ISCSI_NP_THREAD_ACTIVE;
                complete(&np->np_restart_comp);
+       } else if (np->np_thread_state == ISCSI_NP_THREAD_SHUTDOWN) {
+               spin_unlock_bh(&np->np_thread_lock);
+               goto exit;
        } else {
                np->np_thread_state = ISCSI_NP_THREAD_ACTIVE;
        }
@@ -1430,10 +1425,8 @@ old_sess_out:
        }
 
 out:
-       stop = kthread_should_stop();
-       /* Wait for another socket.. */
-       if (!stop)
-               return 1;
+       return 1;
+
 exit:
        iscsi_stop_login_thread_timer(np);
        spin_lock_bh(&np->np_thread_lock);
@@ -1450,7 +1443,7 @@ int iscsi_target_login_thread(void *arg)
 
        allow_signal(SIGINT);
 
-       while (!kthread_should_stop()) {
+       while (1) {
                ret = __iscsi_target_login_thread(np);
                /*
                 * We break and exit here unless another sock_accept() call