Commit 0b950672 authored by Arjan van de Ven's avatar Arjan van de Ven Committed by James Bottomley
Browse files

[SCSI] turn most scsi semaphores into mutexes



the scsi layer is using semaphores in a mutex way, this patch converts
these into using mutexes instead

Signed-off-by: default avatarArjan van de Ven <arjan@infradead.org>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent dacee84b
Loading
Loading
Loading
Loading
+17 −16
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <linux/completion.h>
#include <linux/compat.h>
#include <linux/chio.h>			/* here are all the ioctls */
#include <linux/mutex.h>

#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
@@ -111,7 +112,7 @@ typedef struct {
	u_int               counts[CH_TYPES];
	u_int               unit_attention;
	u_int		    voltags;
	struct semaphore    lock;
	struct mutex	    lock;
} scsi_changer;

static LIST_HEAD(ch_devlist);
@@ -565,7 +566,7 @@ static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest)
	u_char data[16];
	unsigned int i;
	
	down(&ch->lock);
	mutex_lock(&ch->lock);
	for (i = 0; i < ch->counts[type]; i++) {
		if (0 != ch_read_element_status
		    (ch, ch->firsts[type]+i,data)) {
@@ -582,7 +583,7 @@ static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest)
		if (0 != retval)
			break;
	}
	up(&ch->lock);
	mutex_unlock(&ch->lock);
	return retval;
}

@@ -687,11 +688,11 @@ static int ch_ioctl(struct inode * inode, struct file * file,
			dprintk("CHIOPOSITION: invalid parameter\n");
			return -EBADSLT;
		}
		down(&ch->lock);
		mutex_lock(&ch->lock);
		retval = ch_position(ch,0,
				     ch->firsts[pos.cp_type] + pos.cp_unit,
				     pos.cp_flags & CP_INVERT);
		up(&ch->lock);
		mutex_unlock(&ch->lock);
		return retval;
	}
	
@@ -708,12 +709,12 @@ static int ch_ioctl(struct inode * inode, struct file * file,
			return -EBADSLT;
		}
		
		down(&ch->lock);
		mutex_lock(&ch->lock);
		retval = ch_move(ch,0,
				 ch->firsts[mv.cm_fromtype] + mv.cm_fromunit,
				 ch->firsts[mv.cm_totype]   + mv.cm_tounit,
				 mv.cm_flags & CM_INVERT);
		up(&ch->lock);
		mutex_unlock(&ch->lock);
		return retval;
	}

@@ -731,14 +732,14 @@ static int ch_ioctl(struct inode * inode, struct file * file,
			return -EBADSLT;
		}
		
		down(&ch->lock);
		mutex_lock(&ch->lock);
		retval = ch_exchange
			(ch,0,
			 ch->firsts[mv.ce_srctype]  + mv.ce_srcunit,
			 ch->firsts[mv.ce_fdsttype] + mv.ce_fdstunit,
			 ch->firsts[mv.ce_sdsttype] + mv.ce_sdstunit,
			 mv.ce_flags & CE_INVERT1, mv.ce_flags & CE_INVERT2);
		up(&ch->lock);
		mutex_unlock(&ch->lock);
		return retval;
	}

@@ -772,7 +773,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
		buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
		if (!buffer)
			return -ENOMEM;
		down(&ch->lock);
		mutex_lock(&ch->lock);
		
	voltag_retry:
		memset(cmd,0,sizeof(cmd));
@@ -823,7 +824,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
			goto voltag_retry;
		}
		kfree(buffer);
		up(&ch->lock);
		mutex_unlock(&ch->lock);
		
		if (copy_to_user(argp, &cge, sizeof (cge)))
			return -EFAULT;
@@ -832,9 +833,9 @@ static int ch_ioctl(struct inode * inode, struct file * file,

	case CHIOINITELEM:
	{
		down(&ch->lock);
		mutex_lock(&ch->lock);
		retval = ch_init_elem(ch);
		up(&ch->lock);
		mutex_unlock(&ch->lock);
		return retval;
	}
		
@@ -851,12 +852,12 @@ static int ch_ioctl(struct inode * inode, struct file * file,
			return -EBADSLT;
		}
		elem = ch->firsts[csv.csv_type] + csv.csv_unit;
		down(&ch->lock);
		mutex_lock(&ch->lock);
		retval = ch_set_voltag(ch, elem,
				       csv.csv_flags & CSV_AVOLTAG,
				       csv.csv_flags & CSV_CLEARTAG,
				       csv.csv_voltag);
		up(&ch->lock);
		mutex_unlock(&ch->lock);
		return retval;
	}

@@ -929,7 +930,7 @@ static int ch_probe(struct device *dev)
	memset(ch,0,sizeof(*ch));
	ch->minor = ch_devcount;
	sprintf(ch->name,"ch%d",ch->minor);
	init_MUTEX(&ch->lock);
	mutex_init(&ch->lock);
	ch->device = sd;
	ch_readconfig(ch);
	if (init)
+18 −17
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/ioport.h>
#include <linux/mutex.h>

#include <asm/processor.h>	/* for boot_cpu_data */
#include <asm/pgtable.h>
@@ -106,7 +107,7 @@ static dpt_sig_S DPTI_sig = {
 *============================================================================
 */

static DECLARE_MUTEX(adpt_configuration_lock);
static DEFINE_MUTEX(adpt_configuration_lock);

static struct i2o_sys_tbl *sys_tbl = NULL;
static int sys_tbl_ind = 0;
@@ -537,13 +538,13 @@ static int adpt_proc_info(struct Scsi_Host *host, char *buffer, char **start, of
	 */

	// Find HBA (host bus adapter) we are looking for
	down(&adpt_configuration_lock);
	mutex_lock(&adpt_configuration_lock);
	for (pHba = hba_chain; pHba; pHba = pHba->next) {
		if (pHba->host == host) {
			break;	/* found adapter */
		}
	}
	up(&adpt_configuration_lock);
	mutex_unlock(&adpt_configuration_lock);
	if (pHba == NULL) {
		return 0;
	}
@@ -958,7 +959,7 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
	}
	memset(pHba, 0, sizeof(adpt_hba));

	down(&adpt_configuration_lock);
	mutex_lock(&adpt_configuration_lock);

	if(hba_chain != NULL){
		for(p = hba_chain; p->next; p = p->next);
@@ -971,7 +972,7 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
	sprintf(pHba->name, "dpti%d", hba_count);
	hba_count++;
	
	up(&adpt_configuration_lock);
	mutex_unlock(&adpt_configuration_lock);

	pHba->pDev = pDev;
	pHba->base_addr_phys = base_addr0_phys;
@@ -1027,7 +1028,7 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
	struct adpt_device* pNext;


	down(&adpt_configuration_lock);
	mutex_lock(&adpt_configuration_lock);
	// scsi_unregister calls our adpt_release which
	// does a quiese
	if(pHba->host){
@@ -1046,7 +1047,7 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
	}

	hba_count--;
	up(&adpt_configuration_lock);
	mutex_unlock(&adpt_configuration_lock);

	iounmap(pHba->base_addr_virt);
	pci_release_regions(pHba->pDev);
@@ -1549,7 +1550,7 @@ static int adpt_i2o_parse_lct(adpt_hba* pHba)
 
static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d)
{
	down(&adpt_configuration_lock);
	mutex_lock(&adpt_configuration_lock);
	d->controller=pHba;
	d->owner=NULL;
	d->next=pHba->devices;
@@ -1560,7 +1561,7 @@ static int adpt_i2o_install_device(adpt_hba* pHba, struct i2o_device *d)
	pHba->devices=d;
	*d->dev_name = 0;

	up(&adpt_configuration_lock);
	mutex_unlock(&adpt_configuration_lock);
	return 0;
}

@@ -1575,24 +1576,24 @@ static int adpt_open(struct inode *inode, struct file *file)
	if (minor >= hba_count) {
		return -ENXIO;
	}
	down(&adpt_configuration_lock);
	mutex_lock(&adpt_configuration_lock);
	for (pHba = hba_chain; pHba; pHba = pHba->next) {
		if (pHba->unit == minor) {
			break;	/* found adapter */
		}
	}
	if (pHba == NULL) {
		up(&adpt_configuration_lock);
		mutex_unlock(&adpt_configuration_lock);
		return -ENXIO;
	}

//	if(pHba->in_use){
	//	up(&adpt_configuration_lock);
	//	mutex_unlock(&adpt_configuration_lock);
//		return -EBUSY;
//	}

	pHba->in_use = 1;
	up(&adpt_configuration_lock);
	mutex_unlock(&adpt_configuration_lock);

	return 0;
}
@@ -1606,13 +1607,13 @@ static int adpt_close(struct inode *inode, struct file *file)
	if (minor >= hba_count) {
		return -ENXIO;
	}
	down(&adpt_configuration_lock);
	mutex_lock(&adpt_configuration_lock);
	for (pHba = hba_chain; pHba; pHba = pHba->next) {
		if (pHba->unit == minor) {
			break;	/* found adapter */
		}
	}
	up(&adpt_configuration_lock);
	mutex_unlock(&adpt_configuration_lock);
	if (pHba == NULL) {
		return -ENXIO;
	}
@@ -1910,13 +1911,13 @@ static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd,
	if (minor >= DPTI_MAX_HBA){
		return -ENXIO;
	}
	down(&adpt_configuration_lock);
	mutex_lock(&adpt_configuration_lock);
	for (pHba = hba_chain; pHba; pHba = pHba->next) {
		if (pHba->unit == minor) {
			break;	/* found adapter */
		}
	}
	up(&adpt_configuration_lock);
	mutex_unlock(&adpt_configuration_lock);
	if(pHba == NULL){
		return -ENXIO;
	}
+4 −4
Original line number Diff line number Diff line
@@ -156,16 +156,16 @@ EXPORT_SYMBOL(scsi_host_set_state);
void scsi_remove_host(struct Scsi_Host *shost)
{
	unsigned long flags;
	down(&shost->scan_mutex);
	mutex_lock(&shost->scan_mutex);
	spin_lock_irqsave(shost->host_lock, flags);
	if (scsi_host_set_state(shost, SHOST_CANCEL))
		if (scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY)) {
			spin_unlock_irqrestore(shost->host_lock, flags);
			up(&shost->scan_mutex);
			mutex_unlock(&shost->scan_mutex);
			return;
		}
	spin_unlock_irqrestore(shost->host_lock, flags);
	up(&shost->scan_mutex);
	mutex_unlock(&shost->scan_mutex);
	scsi_forget_host(shost);
	scsi_proc_host_rm(shost);

@@ -320,7 +320,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
	INIT_LIST_HEAD(&shost->starved_list);
	init_waitqueue_head(&shost->host_wait);

	init_MUTEX(&shost->scan_mutex);
	mutex_init(&shost->scan_mutex);

	shost->host_no = scsi_host_next_hn++; /* XXX(hch): still racy */
	shost->dma_channel = 0xff;
+19 −18
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <linux/delay.h>
#include <linux/kfifo.h>
#include <linux/scatterlist.h>
#include <linux/mutex.h>
#include <net/tcp.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_device.h>
@@ -2300,10 +2301,10 @@ iscsi_xmitworker(void *data)
	/*
	 * serialize Xmit worker on a per-connection basis.
	 */
	down(&conn->xmitsema);
	mutex_lock(&conn->xmitmutex);
	if (iscsi_data_xmit(conn))
		schedule_work(&conn->xmitwork);
	up(&conn->xmitsema);
	mutex_unlock(&conn->xmitmutex);
}

#define FAILURE_BAD_HOST		1
@@ -2367,11 +2368,11 @@ iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(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_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);
@@ -2531,7 +2532,7 @@ iscsi_conn_create(iscsi_sessionh_t sessionh, uint32_t conn_idx)
		goto max_recv_dlenght_alloc_fail;

	init_timer(&conn->tmabort_timer);
	init_MUTEX(&conn->xmitsema);
	mutex_init(&conn->xmitmutex);
	init_waitqueue_head(&conn->ehwait);

	return iscsi_handle(conn);
@@ -2561,7 +2562,7 @@ iscsi_conn_destroy(iscsi_connh_t connh)
	struct iscsi_conn *conn = iscsi_ptr(connh);
	struct iscsi_session *session = conn->session;

	down(&conn->xmitsema);
	mutex_lock(&conn->xmitmutex);
	set_bit(SUSPEND_BIT, &conn->suspend_tx);
	if (conn->c_stage == ISCSI_CONN_INITIAL_STAGE && conn->sock) {
		struct sock *sk = conn->sock->sk;
@@ -2592,7 +2593,7 @@ iscsi_conn_destroy(iscsi_connh_t connh)
	}
	spin_unlock_bh(&session->lock);

	up(&conn->xmitsema);
	mutex_unlock(&conn->xmitmutex);

	/*
	 * Block until all in-progress commands for this connection
@@ -2796,7 +2797,7 @@ iscsi_conn_stop(iscsi_connh_t connh, int flag)
	set_bit(SUSPEND_BIT, &conn->suspend_rx);
	write_unlock_bh(&sk->sk_callback_lock);

	down(&conn->xmitsema);
	mutex_lock(&conn->xmitmutex);

	spin_lock_irqsave(session->host->host_lock, flags);
	spin_lock(&session->lock);
@@ -2878,7 +2879,7 @@ iscsi_conn_stop(iscsi_connh_t connh, int flag)
			conn->datadgst_en = 0;
		}
	}
	up(&conn->xmitsema);
	mutex_unlock(&conn->xmitmutex);
}

static int
@@ -3029,12 +3030,12 @@ iscsi_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);
	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);
			goto failed;
		}
		spin_unlock_bh(&session->lock);
@@ -3052,7 +3053,7 @@ iscsi_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;
@@ -3107,7 +3108,7 @@ iscsi_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;
@@ -3116,7 +3117,7 @@ iscsi_eh_abort(struct scsi_cmnd *sc)
			spin_unlock_bh(&session->lock);
		}
	}
	up(&conn->xmitsema);
	mutex_unlock(&conn->xmitmutex);


	/*
@@ -3182,7 +3183,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;

@@ -3190,7 +3191,7 @@ exit:
		iscsi_ctask_cleanup(conn, ctask);
		write_unlock_bh(&sk->sk_callback_lock);
	}
	up(&conn->xmitsema);
	mutex_unlock(&conn->xmitmutex);
	return rc;
}

@@ -3601,9 +3602,9 @@ iscsi_conn_send_pdu(iscsi_connh_t connh, struct iscsi_hdr *hdr, char *data,
	struct iscsi_conn *conn = iscsi_ptr(connh);
	int rc;

	down(&conn->xmitsema);
	mutex_lock(&conn->xmitmutex);
	rc = iscsi_conn_send_generic(conn, hdr, data, data_size);
	up(&conn->xmitsema);
	mutex_unlock(&conn->xmitmutex);

	return rc;
}
+1 −1
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ struct iscsi_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, writequeue, *
						 * immqueue, mgmtqueue    */
Loading