[openib-general] [PATCH] iser: convert semaphore to mutex

Or Gerlitz ogerlitz at voltaire.com
Sun Feb 19 04:56:07 PST 2006


please note that to user iser with 2.6.15 and below kernels 
one needs to copy mutex-backport.h from 
https://openib.org/svn/gen2/trunk/src/linux-kernel/infiniband/include/linux
to be under /usr/src/linux/include/linux

Or.


semaphore to mutex conversion

Signed-off-by: Or Gerlitz <ogerlitz at voltaire.com>


Index: iscsi_iser.h
===================================================================
--- iscsi_iser.h	(revision 5442)
+++ iscsi_iser.h	(revision 5444)
@@ -52,7 +52,14 @@
 #include <linux/list.h>
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
-#include <asm/semaphore.h>
+
+/* XXX remove this compatibility hack when 2.6.16 is released */
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
+#include <linux/mutex-backport.h>
+#else
+#include <linux/mutex.h>
+#endif /* XXX end of hack */
 
 #include <linux/mempool.h>
 #include <linux/uio.h>
@@ -295,7 +302,7 @@ struct iscsi_iser_conn {
 	struct kfifo		     *mgmtqueue;  /* mgmt (control) xmit queue */
 	struct kfifo		     *xmitqueue;  /* data-path cmd queue       */
 	struct work_struct	     xmitwork;	  /* per-conn. xmit workqueue  */
-	struct semaphore	     xmitsema;	  /* serializes connection xmit,
+	struct mutex    	     xmitmutex;	  /* serializes connection xmit,
 						   * access to kfifos:	       *
 						   * xmitqueue,                *
 						   * immqueue, mgmtqueue       */
@@ -401,7 +408,7 @@ struct iser_page_vec {
 };
 
 struct iser_global {
-	struct semaphore  adaptor_list_sem;  /*                   */
+	struct mutex      adaptor_list_mutex;/*                   */
 	struct list_head  adaptor_list;	     /* all iSER adaptors */
 
 	kmem_cache_t *desc_cache;
Index: iser_verbs.c
===================================================================
--- iser_verbs.c	(revision 5442)
+++ iser_verbs.c	(revision 5444)
@@ -240,7 +240,7 @@ struct iser_adaptor *iser_adaptor_find_b
 	struct list_head      *p_list;
 	struct iser_adaptor   *p_adaptor = NULL;
 
-	down(&ig.adaptor_list_sem);
+	mutex_lock(&ig.adaptor_list_mutex);
 
 	p_list = ig.adaptor_list.next;
 	while (p_list != &ig.adaptor_list) {
@@ -267,14 +267,14 @@ struct iser_adaptor *iser_adaptor_find_b
 end:
 	BUG_ON(p_adaptor == NULL);
 	p_adaptor->refcount++;
-	up(&ig.adaptor_list_sem);
+	mutex_unlock(&ig.adaptor_list_mutex);
 	return p_adaptor;
 }
 
 /* if there's no demand for this adaptor, release it */
 static void iser_adaptor_try_release(struct iser_adaptor *p_adaptor)
 {
-	down(&ig.adaptor_list_sem);
+	mutex_lock(&ig.adaptor_list_mutex);
 	p_adaptor->refcount--;
 	iser_err("adaptor %p refcount %d\n",p_adaptor,p_adaptor->refcount);
 	if (!p_adaptor->refcount) {
@@ -282,7 +282,7 @@ static void iser_adaptor_try_release(str
 		list_del(&p_adaptor->ig_list);
 		kfree(p_adaptor);
 	}
-	up(&ig.adaptor_list_sem);
+	mutex_unlock(&ig.adaptor_list_mutex);
 }
 
 /**
Index: iscsi_iser.c
===================================================================
--- iscsi_iser.c	(revision 5442)
+++ iscsi_iser.c	(revision 5444)
@@ -707,10 +707,10 @@ iscsi_iser_xmitworker(void *data)
 	/*
 	 * serialize Xmit worker on a per-connection basis.
 	 */
-	down(&conn->xmitsema);
+	mutex_lock(&conn->xmitmutex);
 	if (iscsi_iser_data_xmit(conn))
 		schedule_work(&conn->xmitwork);
-	up(&conn->xmitsema);
+	mutex_unlock(&conn->xmitmutex);
 }
 
 
@@ -784,11 +784,11 @@ iscsi_iser_queuecommand(struct scsi_cmnd
 		  session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1);
 	spin_unlock(&session->lock);
 
-	if (!in_interrupt() && !down_trylock(&conn->xmitsema)) {
+	if (!in_interrupt() && mutex_trylock(&conn->xmitmutex)) {
 		spin_unlock_irq(host->host_lock);
 		if (iscsi_iser_data_xmit(conn))
 			schedule_work(&conn->xmitwork);
-		up(&conn->xmitsema);
+		mutex_unlock(&conn->xmitmutex);
 		spin_lock_irq(host->host_lock);
 	} else
 		schedule_work(&conn->xmitwork);
@@ -922,7 +922,7 @@ iscsi_iser_conn_create(iscsi_sessionh_t 
 	spin_unlock_bh(&session->lock);
 
 	init_timer(&conn->tmabort_timer);
-	init_MUTEX(&conn->xmitsema);
+	mutex_init(&conn->xmitmutex);
 	init_waitqueue_head(&conn->ehwait);
 	spin_lock_init(&conn->lock);
 
@@ -949,7 +949,7 @@ iscsi_iser_conn_destroy(iscsi_connh_t co
 
 	debug_iser("%s: enter\n", __FUNCTION__);
 
-	down(&conn->xmitsema);
+	mutex_lock(&conn->xmitmutex);
 	set_bit(SUSPEND_BIT, &conn->suspend_tx);
 
 	if (conn->c_stage == ISCSI_CONN_INITIAL_STAGE && conn->sock) {
@@ -968,7 +968,7 @@ iscsi_iser_conn_destroy(iscsi_connh_t co
 	}
 	spin_unlock_bh(&session->lock);
 
-	up(&conn->xmitsema);
+	mutex_unlock(&conn->xmitmutex);
 
 	/*
 	 * Block until all in-progress commands for this connection
@@ -1135,7 +1135,7 @@ iscsi_iser_conn_stop(iscsi_connh_t connh
 
 	BUG_ON(!conn->sock);
 
-	down(&conn->xmitsema);
+	mutex_lock(&conn->xmitmutex);
 
        spin_lock_irqsave(session->host->host_lock, flags);
 	spin_lock(&session->lock);
@@ -1189,7 +1189,7 @@ iscsi_iser_conn_stop(iscsi_connh_t connh
 		sock_release(conn->sock);
 		conn->sock = NULL;
 	}
-       up(&conn->xmitsema);
+       mutex_unlock(&conn->xmitmutex);
 
 	debug_iser("%s: exit\n", __FUNCTION__);
 }
@@ -1353,13 +1353,13 @@ iscsi_iser_eh_abort(struct scsi_cmnd *sc
 	 * 1) connection-level failure;
 	 * 2) recovery due protocol error;
 	 */
-	down(&conn->xmitsema);
+	mutex_lock(&conn->xmitmutex);
 	spin_lock_bh(&session->lock);
 	debug_iser("%s: session->state = %d\n", __FUNCTION__, session->state);
 	if (session->state != ISCSI_STATE_LOGGED_IN) {
 		if (session->state == ISCSI_STATE_TERMINATE) {
 			spin_unlock_bh(&session->lock);
-			up(&conn->xmitsema);
+			mutex_unlock(&conn->xmitmutex);
 			debug_scsi("abort failed becuase session->state == ISCSI_STATE_TERMINATE\n");
 			goto failed;
 		}
@@ -1378,7 +1378,7 @@ iscsi_iser_eh_abort(struct scsi_cmnd *sc
 			 * 2) session was re-open during time out of ctask.
 			 */
 			spin_unlock_bh(&session->lock);
-			up(&conn->xmitsema);
+			mutex_unlock(&conn->xmitmutex);
 			goto success;
 		}
 		conn->tmabort_state = TMABORT_INITIAL;
@@ -1430,7 +1430,7 @@ iscsi_iser_eh_abort(struct scsi_cmnd *sc
 				    conn->tmabort_state == TMABORT_SUCCESS) {
 					conn->tmabort_state = TMABORT_INITIAL;
 					spin_unlock_bh(&session->lock);
-					up(&conn->xmitsema);
+					mutex_unlock(&conn->xmitmutex);
 					goto success;
 				}
 				conn->tmabort_state = TMABORT_INITIAL;
@@ -1440,7 +1440,7 @@ iscsi_iser_eh_abort(struct scsi_cmnd *sc
 			spin_unlock_bh(&session->lock);
 		}
 	}
-	up(&conn->xmitsema);
+	mutex_unlock(&conn->xmitmutex);
 
 	/*
 	 * block eh thread until:
@@ -1517,7 +1517,7 @@ failed:
 exit:
 	del_timer_sync(&conn->tmabort_timer);
 
-	down(&conn->xmitsema);
+	mutex_lock(&conn->xmitmutex);
 	if (conn->sock) {
 		struct sock *sk = conn->sock->sk;
 
@@ -1525,7 +1525,7 @@ exit:
 		iscsi_iser_ctask_cleanup(conn, ctask);
 		write_unlock_bh(&sk->sk_callback_lock);
 	}
-	up(&conn->xmitsema);
+	mutex_unlock(&conn->xmitmutex);
 	debug_iser("%s: exit\n", __FUNCTION__);
 	return rc;
 }
@@ -1793,9 +1793,9 @@ iscsi_iser_conn_send_pdu(iscsi_connh_t c
 	struct iscsi_iser_conn *conn = iscsi_ptr(connh);
 	int rc;
 
-	down(&conn->xmitsema);
+	mutex_lock(&conn->xmitmutex);
 	rc = iscsi_iser_conn_send_generic(connh, hdr, data, data_size);
-	up(&conn->xmitsema);
+	mutex_unlock(&conn->xmitmutex);
 
 	return rc;
 }
@@ -1845,7 +1845,7 @@ static int __init iser_init(void)
 		return -ENOMEM;
 
 	/* adaptor init is called only after the first addr resolution */
-	init_MUTEX(&ig.adaptor_list_sem);
+	mutex_init(&ig.adaptor_list_mutex);
 	INIT_LIST_HEAD(&ig.adaptor_list);
 
 	err = iser_register_sockets();




More information about the general mailing list