Browse Source

IB/iser: Protect tasks cleanup in case IB device was already released

Bailout in case a task cleanup (iscsi_iser_cleanup_task) is called
after the IB device was removed (DEVICE_REMOVAL CM event).  We also
call iscsi_conn_stop with a lock taken to prevent DEVICE_REMOVAL and
tasks cleanup from racing.

Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Ariel Nahum <arieln@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
Sagi Grimberg 11 years ago
parent
commit
3a940daf6f
1 changed files with 7 additions and 1 deletions
  1. 7 1
      drivers/infiniband/ulp/iser/iscsi_iser.c

+ 7 - 1
drivers/infiniband/ulp/iser/iscsi_iser.c

@@ -293,6 +293,10 @@ static void iscsi_iser_cleanup_task(struct iscsi_task *task)
 	struct iser_conn       *iser_conn	  = task->conn->dd_data;
 	struct iser_conn       *iser_conn	  = task->conn->dd_data;
 	struct iser_device *device = iser_conn->ib_conn.device;
 	struct iser_device *device = iser_conn->ib_conn.device;
 
 
+	/* DEVICE_REMOVAL event might have already released the device */
+	if (!device)
+		return;
+
 	ib_dma_unmap_single(device->ib_device,
 	ib_dma_unmap_single(device->ib_device,
 		tx_desc->dma_addr, ISER_HEADERS_LEN, DMA_TO_DEVICE);
 		tx_desc->dma_addr, ISER_HEADERS_LEN, DMA_TO_DEVICE);
 
 
@@ -407,7 +411,6 @@ iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
 	struct iser_conn *iser_conn = conn->dd_data;
 	struct iser_conn *iser_conn = conn->dd_data;
 
 
 	iser_dbg("stopping iscsi_conn: %p, iser_conn: %p\n", conn, iser_conn);
 	iser_dbg("stopping iscsi_conn: %p, iser_conn: %p\n", conn, iser_conn);
-	iscsi_conn_stop(cls_conn, flag);
 
 
 	/*
 	/*
 	 * Userspace may have goofed up and not bound the connection or
 	 * Userspace may have goofed up and not bound the connection or
@@ -415,6 +418,7 @@ iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
 	 */
 	 */
 	if (iser_conn) {
 	if (iser_conn) {
 		mutex_lock(&iser_conn->state_mutex);
 		mutex_lock(&iser_conn->state_mutex);
+		iscsi_conn_stop(cls_conn, flag);
 		iser_conn_terminate(iser_conn);
 		iser_conn_terminate(iser_conn);
 
 
 		/* unbind */
 		/* unbind */
@@ -423,6 +427,8 @@ iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
 
 
 		complete(&iser_conn->stop_completion);
 		complete(&iser_conn->stop_completion);
 		mutex_unlock(&iser_conn->state_mutex);
 		mutex_unlock(&iser_conn->state_mutex);
+	} else {
+		iscsi_conn_stop(cls_conn, flag);
 	}
 	}
 }
 }