public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Christie <michael.christie@oracle.com>
To: Wenchao Hao <haowenchao@huawei.com>,
	Lee Duncan <lduncan@suse.com>, Chris Leech <cleech@redhat.com>,
	"James E . J . Bottomley" <jejb@linux.ibm.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Steffen Maier <maier@linux.ibm.com>,
	liuzhiqiang26@huawei.com, linfeilong@huawei.com
Subject: Re: [PATCH v5] scsi:iscsi: Fix multiple iscsi session unbind event sent to userspace
Date: Thu, 27 Oct 2022 16:02:26 -0500	[thread overview]
Message-ID: <cc9faad6-223f-23b2-2fcc-4b58916d13f0@oracle.com> (raw)
In-Reply-To: <20221028020026.2870104-1-haowenchao@huawei.com>

On 10/27/22 9:00 PM, Wenchao Hao wrote:
> @@ -1779,6 +1803,7 @@ static int iscsi_user_scan_session(struct device *dev, void *data)
>  		goto user_scan_exit;
>  	}
>  	id = session->target_id;
> +	session->target_state = ISCSI_SESSION_TARGET_BOUND;
>  	spin_unlock_irqrestore(&session->lock, flags);
>  
>  	if (id != ISCSI_MAX_TARGET) {
> @@ -1899,6 +1924,7 @@ static void __iscsi_unblock_session(struct work_struct *work)
>  	cancel_delayed_work_sync(&session->recovery_work);
>  	spin_lock_irqsave(&session->lock, flags);
>  	session->state = ISCSI_SESSION_LOGGED_IN;
> +	session->target_state = ISCSI_SESSION_TARGET_ALLOCATED;

I think there are 2 issues with setting this to ISCSI_SESSION_TARGET_ALLOCATED
here.

1. We allocated the target_id in iscsi_add_session so it's weird to set
the state late above.
2. We call the above function when we relogin, so it overwrites 
ISCSI_SESSION_TARGET_BOUND.

I think we can just do:

@@ -1785,7 +1785,12 @@ static int iscsi_user_scan_session(struct device *dev, void *data)
 		if ((scan_data->channel == SCAN_WILD_CARD ||
 		     scan_data->channel == 0) &&
 		    (scan_data->id == SCAN_WILD_CARD ||
-		     scan_data->id == id))
+		     scan_data->id == id)) {
+
+			spin_lock_irqsave(&session->lock, flags);
+			session->target_state = ISCSI_SESSION_TARGET_SCANNED;
+			spin_unlock_irqsave(&session->lock, flags);
+
 			scsi_scan_target(&session->dev, 0, id,
 					 scan_data->lun, scan_data->rescan);
 	}
@@ -1972,6 +1977,7 @@ static void __iscsi_unbind_session(struct work_struct *work)
 		goto unbind_session_exit;
 	}
 
+	session->target_state = ISCSI_SESSION_TARGET_UNBINDING;
 	target_id = session->target_id;
 	session->target_id = ISCSI_MAX_TARGET;
 	spin_unlock_irqrestore(&session->lock, flags);
@@ -1983,6 +1989,10 @@ static void __iscsi_unbind_session(struct work_struct *work)
 		ida_free(&iscsi_sess_ida, target_id);
 
 unbind_session_exit:
+	spin_lock_irqsave(&session->lock, flags);
+	session->target_state = ISCSI_SESSION_TARGET_UNBOUND;
+	spin_unlock_irqrestore(&session->lock, flags);
+
 	iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
 	ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n");
 }
@@ -2061,6 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
 		session->ida_used = true;
 	} else
 		session->target_id = target_id;
+	session->target_state = ISCSI_SESSION_TARGET_ID_ALLOCATED;
 
 	dev_set_name(&session->dev, "session%u", session->sid);
 	err = device_add(&session->dev);


then in userspace we can do:

1. if have conn in sysfs
	if session->target_state == ISCSI_SESSION_TARGET_ID_ALLOCATED
		if conn->state == ISCSI_CONN_UP
			/*
			 * we did the initial login and did a ISCSI_UEVENT_START_CONN
			 * but crashed/restarted
			 * before we were able to scan.
			 */
			sync session and scan session
		else
			/*
			 * the initial login didn't happen so
			 * just cleanup the kernel. Note: we could also
			 * finish setting the conn up but it probably doesn't
			 * come up enough to do this.
			 */

	else if session->target_state == ISCSI_SESSION_TARGET_SCANNED
		do normal sync
	else if session->target_state == ISCSI_SESSION_TARGET_REMOVING
		wait for state to change to ISCSI_SESSION_TARGET_UNBOUND
		or setup session/conn in userspace so we can wait for
		ISCSI_KEVENT_UNBIND_SESSION then cleanup session/conn.
	else if session->target_state == ISCSI_SESSION_TARGET_UNBOUND
		cleanup session/conn based on their state and what's in sysfs

   if no conn in sysfs
	cleanup session


If we are in agreement, then you can take my code above and merge it into
your patch and resubmit in one patch.

  parent reply	other threads:[~2022-10-27 21:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28  2:00 [PATCH v5] scsi:iscsi: Fix multiple iscsi session unbind event sent to userspace Wenchao Hao
2022-10-27 16:18 ` Lee Duncan
2022-10-28  9:45   ` Wenchao Hao
2022-10-28 15:05     ` Lee Duncan
2022-11-07 12:35       ` Wenchao Hao
2022-10-27 21:02 ` Mike Christie [this message]
2022-10-28  9:49   ` Wenchao Hao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc9faad6-223f-23b2-2fcc-4b58916d13f0@oracle.com \
    --to=michael.christie@oracle.com \
    --cc=cleech@redhat.com \
    --cc=haowenchao@huawei.com \
    --cc=jejb@linux.ibm.com \
    --cc=lduncan@suse.com \
    --cc=linfeilong@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=liuzhiqiang26@huawei.com \
    --cc=maier@linux.ibm.com \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox