Skip to content

Commit

Permalink
scsi: iscsi: Add iscsi_cls_conn refcount helpers
Browse files Browse the repository at this point in the history
[ Upstream commit b1d19e8c92cfb0ded180ef3376c20e130414e067 ]

There are a couple places where we could free the iscsi_cls_conn while it's
still in use. This adds some helpers to get/put a refcount on the struct
and converts an exiting user. Subsequent commits will then use the helpers
to fix 2 bugs in the eh code.

Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Lee Duncan <[email protected]>
Signed-off-by: Mike Christie <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
mikechristie authored and gregkh committed Jul 20, 2021
1 parent 1fa1489 commit 83bd5f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 2 additions & 5 deletions drivers/scsi/libiscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,6 @@ void iscsi_session_failure(struct iscsi_session *session,
enum iscsi_err err)
{
struct iscsi_conn *conn;
struct device *dev;

spin_lock_bh(&session->frwd_lock);
conn = session->leadconn;
Expand All @@ -1393,10 +1392,8 @@ void iscsi_session_failure(struct iscsi_session *session,
return;
}

dev = get_device(&conn->cls_conn->dev);
iscsi_get_conn(conn->cls_conn);
spin_unlock_bh(&session->frwd_lock);
if (!dev)
return;
/*
* if the host is being removed bypass the connection
* recovery initialization because we are going to kill
Expand All @@ -1406,7 +1403,7 @@ void iscsi_session_failure(struct iscsi_session *session,
iscsi_conn_error_event(conn->cls_conn, err);
else
iscsi_conn_failure(conn, err);
put_device(dev);
iscsi_put_conn(conn->cls_conn);
}
EXPORT_SYMBOL_GPL(iscsi_session_failure);

Expand Down
12 changes: 12 additions & 0 deletions drivers/scsi/scsi_transport_iscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,18 @@ int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
}
EXPORT_SYMBOL_GPL(iscsi_destroy_conn);

void iscsi_put_conn(struct iscsi_cls_conn *conn)
{
put_device(&conn->dev);
}
EXPORT_SYMBOL_GPL(iscsi_put_conn);

void iscsi_get_conn(struct iscsi_cls_conn *conn)
{
get_device(&conn->dev);
}
EXPORT_SYMBOL_GPL(iscsi_get_conn);

/*
* iscsi interface functions
*/
Expand Down
2 changes: 2 additions & 0 deletions include/scsi/scsi_transport_iscsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ extern void iscsi_free_session(struct iscsi_cls_session *session);
extern int iscsi_destroy_session(struct iscsi_cls_session *session);
extern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess,
int dd_size, uint32_t cid);
extern void iscsi_put_conn(struct iscsi_cls_conn *conn);
extern void iscsi_get_conn(struct iscsi_cls_conn *conn);
extern int iscsi_destroy_conn(struct iscsi_cls_conn *conn);
extern void iscsi_unblock_session(struct iscsi_cls_session *session);
extern void iscsi_block_session(struct iscsi_cls_session *session);
Expand Down

0 comments on commit 83bd5f1

Please sign in to comment.