Skip to content

Commit cbd2283

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: iscsi: Fix offload conn cleanup when iscsid restarts
When userspace restarts during boot or upgrades it won't know about the offload driver's endpoint and connection mappings. iscsid will start by cleaning up the old session by doing a stop_conn call. Later, if we are able to create a new connection, we clean up the old endpoint during the binding stage. The problem is that if we do stop_conn before doing the ep_disconnect call offload, drivers can still be executing I/O. We then might free tasks from the under the card/driver. This moves the ep_disconnect call to before we do the stop_conn call for this case. It will then work and look like a normal recovery/cleanup procedure from the driver's point of view. Link: https://lore.kernel.org/r/20220408001314.5014-3-michael.christie@oracle.com Tested-by: Manish Rangankar <mrangankar@marvell.com> Reviewed-by: Lee Duncan <lduncan@suse.com> Reviewed-by: Chris Leech <cleech@redhat.com> Signed-off-by: Mike Christie <michael.christie@oracle.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent c34f95e commit cbd2283

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

drivers/scsi/scsi_transport_iscsi.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,23 @@ static void iscsi_ep_disconnect(struct iscsi_cls_conn *conn, bool is_active)
22362236
ISCSI_DBG_TRANS_CONN(conn, "disconnect ep done.\n");
22372237
}
22382238

2239+
static void iscsi_if_disconnect_bound_ep(struct iscsi_cls_conn *conn,
2240+
struct iscsi_endpoint *ep,
2241+
bool is_active)
2242+
{
2243+
/* Check if this was a conn error and the kernel took ownership */
2244+
if (!test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2245+
iscsi_ep_disconnect(conn, is_active);
2246+
} else {
2247+
ISCSI_DBG_TRANS_CONN(conn, "flush kernel conn cleanup.\n");
2248+
mutex_unlock(&conn->ep_mutex);
2249+
2250+
flush_work(&conn->cleanup_work);
2251+
2252+
mutex_lock(&conn->ep_mutex);
2253+
}
2254+
}
2255+
22392256
static int iscsi_if_stop_conn(struct iscsi_transport *transport,
22402257
struct iscsi_uevent *ev)
22412258
{
@@ -2256,6 +2273,16 @@ static int iscsi_if_stop_conn(struct iscsi_transport *transport,
22562273
cancel_work_sync(&conn->cleanup_work);
22572274
iscsi_stop_conn(conn, flag);
22582275
} else {
2276+
/*
2277+
* For offload, when iscsid is restarted it won't know about
2278+
* existing endpoints so it can't do a ep_disconnect. We clean
2279+
* it up here for userspace.
2280+
*/
2281+
mutex_lock(&conn->ep_mutex);
2282+
if (conn->ep)
2283+
iscsi_if_disconnect_bound_ep(conn, conn->ep, true);
2284+
mutex_unlock(&conn->ep_mutex);
2285+
22592286
/*
22602287
* Figure out if it was the kernel or userspace initiating this.
22612288
*/
@@ -2984,16 +3011,7 @@ static int iscsi_if_ep_disconnect(struct iscsi_transport *transport,
29843011
}
29853012

29863013
mutex_lock(&conn->ep_mutex);
2987-
/* Check if this was a conn error and the kernel took ownership */
2988-
if (test_bit(ISCSI_CLS_CONN_BIT_CLEANUP, &conn->flags)) {
2989-
ISCSI_DBG_TRANS_CONN(conn, "flush kernel conn cleanup.\n");
2990-
mutex_unlock(&conn->ep_mutex);
2991-
2992-
flush_work(&conn->cleanup_work);
2993-
goto put_ep;
2994-
}
2995-
2996-
iscsi_ep_disconnect(conn, false);
3014+
iscsi_if_disconnect_bound_ep(conn, ep, false);
29973015
mutex_unlock(&conn->ep_mutex);
29983016
put_ep:
29993017
iscsi_put_endpoint(ep);
@@ -3704,16 +3722,6 @@ static int iscsi_if_transport_conn(struct iscsi_transport *transport,
37043722

37053723
switch (nlh->nlmsg_type) {
37063724
case ISCSI_UEVENT_BIND_CONN:
3707-
if (conn->ep) {
3708-
/*
3709-
* For offload boot support where iscsid is restarted
3710-
* during the pivot root stage, the ep will be intact
3711-
* here when the new iscsid instance starts up and
3712-
* reconnects.
3713-
*/
3714-
iscsi_ep_disconnect(conn, true);
3715-
}
3716-
37173725
session = iscsi_session_lookup(ev->u.b_conn.sid);
37183726
if (!session) {
37193727
err = -EINVAL;

0 commit comments

Comments
 (0)