On Mon, 2017-01-16 at 12:35 -0800, Himanshu Madhani wrote:
> /*
> * Adds an extra ref to allow to drop hw lock after adding sess to the list.
> * Caller must put it.
> @@ -839,93 +1103,65 @@ static struct fc_port *qlt_create_sess(
> bool local)
> {
> struct qla_hw_data *ha = vha->hw;
> - struct fc_port *sess;
> + struct fc_port *sess = fcport;
> unsigned long flags;
>
> - /* Check to avoid double sessions */
> - spin_lock_irqsave(>tgt.sess_lock, flags);
> - list_for_each_entry(sess, >vp_fcports, list) {
> - if (!memcmp(sess->port_name, fcport->port_name, WWN_SIZE)) {
> - ql_dbg(ql_dbg_tgt_mgt, vha, 0xf005,
> - "Double sess %p found (s_id %x:%x:%x, "
> - "loop_id %d), updating to d_id %x:%x:%x, "
> - "loop_id %d", sess, sess->d_id.b.domain,
> - sess->d_id.b.al_pa, sess->d_id.b.area,
> - sess->loop_id, fcport->d_id.b.domain,
> - fcport->d_id.b.al_pa, fcport->d_id.b.area,
> - fcport->loop_id);
> -
> - /* Cannot undelete at this point */
> - if (sess->deleted == QLA_SESS_DELETION_IN_PROGRESS) {
> - spin_unlock_irqrestore(>tgt.sess_lock,
> - flags);
> - return NULL;
> - }
> -
> - if (sess->deleted)
> - qlt_undelete_sess(sess);
> -
> - if (!sess->se_sess) {
> - if
> (ha->tgt.tgt_ops->check_initiator_node_acl(vha,
> - >port_name[0], sess) < 0) {
> -
> spin_unlock_irqrestore(>tgt.sess_lock, flags);
> - return NULL;
> - }
> - }
> -
> - kref_get(>sess_kref);
> - ha->tgt.tgt_ops->update_sess(sess, fcport->d_id,
> fcport->loop_id,
> - (fcport->flags &
> FCF_CONF_COMP_SUPPORTED));
> -
> - if (sess->local && !local)
> - sess->local = 0;
> -
> - qlt_do_generation_tick(vha, >generation);
> -
> - spin_unlock_irqrestore(>tgt.sess_lock, flags);
> + if (vha->vha_tgt.qla_tgt && vha->vha_tgt.qla_tgt->tgt_stop)
> + return NULL;
>
> - return sess;
> + if (fcport->se_sess) {
> + if (!kref_get_unless_zero(>sess_kref)) {
> + ql_dbg(ql_dbg_disc, vha, 0x,
> + "%s: kref_get_unless_zero failed for %8phC\n",
> + __func__, sess->port_name);
> + return NULL;
> }
> - }
> - spin_unlock_irqrestore(>tgt.sess_lock, flags);
> -
> - sess = kzalloc(sizeof(*sess), GFP_KERNEL);
> - if (!sess) {
> - ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04a,
> - "qla_target(%u): session allocation failed, all commands "
> - "from port %8phC will be refused", vha->vp_idx,
> - fcport->port_name);
> -
> - return NULL;
> + return fcport;
> }
> sess->tgt = vha->vha_tgt.qla_tgt;
> - sess->vha = vha;
> - sess->d_id = fcport->d_id;
> - sess->loop_id = fcport->loop_id;
> sess->local = local;
> - kref_init(>sess_kref);
> - INIT_LIST_HEAD(>del_list_entry);
>
> - /* Under normal circumstances we want to logout from firmware when
> + /*
> + * Under normal circumstances we want to logout from firmware when
>* session eventually ends and release corresponding nport handle.
>* In the exception cases (e.g. when new PLOGI is waiting) corresponding
> - * code will adjust these flags as necessary. */
> + * code will adjust these flags as necessary.
> + */
> sess->logout_on_delete = 1;
> sess->keep_nport_handle = 0;
> + sess->logout_completed = 0;
>
> - ql_dbg(ql_dbg_tgt_mgt, vha, 0xf006,
> - "Adding sess %p to tgt %p via ->check_initiator_node_acl()\n",
> - sess, vha->vha_tgt.qla_tgt);
> + if (ha->tgt.tgt_ops->check_initiator_node_acl(vha,
> + >port_name[0], sess) < 0) {
> + ql_dbg(ql_dbg_tgt_mgt, vha, 0x,
> + "(%d) %8phC check_initiator_node_acl failed\n",
> + vha->vp_idx, fcport->port_name);
> + return NULL;
> + } else {
> + kref_init(>sess_kref);
> + /*
> + * Take an extra reference to ->sess_kref here to handle
> + * fc_port access across ->tgt.sess_lock reaquire.
> + */
> + if (!kref_get_unless_zero(>sess_kref)) {
> + ql_dbg(ql_dbg_disc, vha,