ia64/linux-2.6.18-xen.hg

changeset 590:c4134d1a3e3f

pvSCSI: Clean up code

Signed-off-by: Tomonari Horikoshi <t.horikoshi@jp.fujitsu.com>
Signed-off-by: Jun Kamada <kama@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jul 03 13:40:02 2008 +0100 (2008-07-03)
parents 920abc7b20ac
children cdadea74443c
files drivers/xen/scsiback/common.h drivers/xen/scsiback/interface.c drivers/xen/scsiback/scsiback.c
line diff
     1.1 --- a/drivers/xen/scsiback/common.h	Thu Jul 03 13:36:53 2008 +0100
     1.2 +++ b/drivers/xen/scsiback/common.h	Thu Jul 03 13:40:02 2008 +0100
     1.3 @@ -112,8 +112,6 @@ typedef struct {
     1.4  
     1.5  	uint16_t rqid;
     1.6  	
     1.7 -	vscsiif_request_t *ring_req;
     1.8 -	
     1.9  	uint8_t nr_segments;
    1.10  	uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE];
    1.11  	uint8_t cmd_len;
    1.12 @@ -123,7 +121,7 @@ typedef struct {
    1.13  	
    1.14  	uint32_t request_bufflen;
    1.15  	struct scatterlist *sgl;
    1.16 -	grant_ref_t gref[VSCSIIF_SENSE_BUFFERSIZE];
    1.17 +	grant_ref_t gref[VSCSIIF_SG_TABLESIZE];
    1.18  
    1.19  	int32_t rslt;
    1.20  	uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
     2.1 --- a/drivers/xen/scsiback/interface.c	Thu Jul 03 13:36:53 2008 +0100
     2.2 +++ b/drivers/xen/scsiback/interface.c	Thu Jul 03 13:40:02 2008 +0100
     2.3 @@ -80,7 +80,7 @@ static int map_frontend_page( struct vsc
     2.4  	info->shmem_ref    = ring_ref;
     2.5  	info->shmem_handle = op.handle;
     2.6  
     2.7 -	return 0;
     2.8 +	return (GNTST_okay);
     2.9  }
    2.10  
    2.11  static void unmap_frontend_page(struct vscsibk_info *info)
     3.1 --- a/drivers/xen/scsiback/scsiback.c	Thu Jul 03 13:36:53 2008 +0100
     3.2 +++ b/drivers/xen/scsiback/scsiback.c	Thu Jul 03 13:40:02 2008 +0100
     3.3 @@ -46,8 +46,6 @@
     3.4  #include "common.h"
     3.5  
     3.6  
     3.7 -#define  NO_ASYNC  1 /*!aync*/
     3.8 -
     3.9  struct list_head pending_free;
    3.10  DEFINE_SPINLOCK(pending_free_lock);
    3.11  DECLARE_WAIT_QUEUE_HEAD(pending_free_wq);
    3.12 @@ -207,20 +205,12 @@ static void scsiback_print_status(char *
    3.13  }
    3.14  
    3.15  
    3.16 -#ifdef NO_ASYNC /*!async*/
    3.17  static void scsiback_cmd_done(struct request *req, int errors)
    3.18  {
    3.19  	pending_req_t *pending_req = req->end_io_data;
    3.20  	unsigned char *sense_buffer;
    3.21  
    3.22  	sense_buffer = req->sense;
    3.23 -#else
    3.24 -static void scsiback_cmd_done(void *data, char *sense_buffer,
    3.25 -				int errors, int resid)
    3.26 -{
    3.27 -	pending_req_t *pending_req = data;
    3.28 -	struct scsi_device *sdev = pending_req->sdev;
    3.29 -#endif
    3.30  
    3.31  	if (errors != 0) {
    3.32  		if (log_print_stat)
    3.33 @@ -233,9 +223,7 @@ static void scsiback_cmd_done(void *data
    3.34  	scsiback_do_resp_with_sense(sense_buffer, errors, pending_req);
    3.35  	scsiback_put(pending_req->info);
    3.36  
    3.37 -#ifdef NO_ASYNC /*!async*/
    3.38  	__blk_put_request(req->q, req);
    3.39 -#endif
    3.40  }
    3.41  
    3.42  
    3.43 @@ -310,8 +298,6 @@ fail_flush:
    3.44  	return -ENOMEM;
    3.45  }
    3.46  
    3.47 -#ifdef NO_ASYNC /*!async*/
    3.48 -
    3.49  /* quoted scsi_lib.c/scsi_merge_bio */
    3.50  static int scsiback_merge_bio(struct request *rq, struct bio *bio)
    3.51  {
    3.52 @@ -422,7 +408,6 @@ free_bios:
    3.53  	return err;
    3.54  }
    3.55  
    3.56 -#endif
    3.57  
    3.58  void scsiback_cmd_exec(pending_req_t *pending_req)
    3.59  {
    3.60 @@ -430,14 +415,8 @@ void scsiback_cmd_exec(pending_req_t *pe
    3.61  	int data_dir = (int)pending_req->sc_data_direction;
    3.62  	unsigned int nr_segments = (unsigned int)pending_req->nr_segments;
    3.63  	unsigned int timeout;
    3.64 -
    3.65 -#ifdef NO_ASYNC /*!async*/
    3.66  	struct request *rq;
    3.67  	int write;
    3.68 -#else
    3.69 -	int err = 0;
    3.70 -	unsigned int data_len = pending_req->request_bufflen;
    3.71 -#endif
    3.72  
    3.73  	DPRINTK("%s\n",__FUNCTION__);
    3.74  
    3.75 @@ -447,7 +426,6 @@ void scsiback_cmd_exec(pending_req_t *pe
    3.76  	else
    3.77  		timeout = VSCSIIF_TIMEOUT;
    3.78  
    3.79 -#ifdef NO_ASYNC /*!async*/
    3.80  	write = (data_dir == DMA_TO_DEVICE);
    3.81  	rq = blk_get_request(pending_req->sdev->request_queue, write, GFP_KERNEL);
    3.82  
    3.83 @@ -474,18 +452,6 @@ void scsiback_cmd_exec(pending_req_t *pe
    3.84  
    3.85  	scsiback_get(pending_req->info);
    3.86  	blk_execute_rq_nowait(rq->q, NULL, rq, 1, scsiback_cmd_done);
    3.87 -#else   /*async*/
    3.88 -
    3.89 -	scsiback_get(pending_req->info);
    3.90 -	err = scsi_execute_async(pending_req->sdev, &(pending_req->cmnd[0]),
    3.91 -		cmd_len, data_dir, pending_req->sgl, data_len, nr_segments, timeout, 0,
    3.92 -		pending_req, scsiback_cmd_done, GFP_KERNEL);
    3.93 -
    3.94 -	if (err) {
    3.95 -		scsiback_do_resp_with_sense(NULL, (DRIVER_ERROR << 24), pending_req);
    3.96 -	}
    3.97 -
    3.98 -#endif    /*async*/
    3.99  
   3.100  	return ;
   3.101  }
   3.102 @@ -531,6 +497,7 @@ static int prepare_pending_reqs(struct v
   3.103  	vir.tgt = ring_req->id;
   3.104  	vir.lun = ring_req->lun;
   3.105  
   3.106 +	rmb();
   3.107  	sdev = scsiback_do_translation(info, &vir);
   3.108  	if (!sdev) {
   3.109  		pending_req->sdev = NULL;
   3.110 @@ -541,34 +508,37 @@ static int prepare_pending_reqs(struct v
   3.111  	pending_req->sdev = sdev;
   3.112  
   3.113  	/* request range check from frontend */
   3.114 -	if ((ring_req->sc_data_direction != DMA_BIDIRECTIONAL) &&
   3.115 -		(ring_req->sc_data_direction != DMA_TO_DEVICE) &&
   3.116 -		(ring_req->sc_data_direction != DMA_FROM_DEVICE) &&
   3.117 -		(ring_req->sc_data_direction != DMA_NONE)) {
   3.118 +	pending_req->sc_data_direction = ring_req->sc_data_direction;
   3.119 +	rmb();
   3.120 +	if ((pending_req->sc_data_direction != DMA_BIDIRECTIONAL) &&
   3.121 +		(pending_req->sc_data_direction != DMA_TO_DEVICE) &&
   3.122 +		(pending_req->sc_data_direction != DMA_FROM_DEVICE) &&
   3.123 +		(pending_req->sc_data_direction != DMA_NONE)) {
   3.124  		DPRINTK("scsiback: invalid parameter data_dir = %d\n",
   3.125 -			ring_req->sc_data_direction);
   3.126 +			pending_req->sc_data_direction);
   3.127  		err = -EINVAL;
   3.128  		goto invald_value;
   3.129  	}
   3.130  
   3.131 -	if (ring_req->nr_segments > VSCSIIF_SG_TABLESIZE) {
   3.132 +	pending_req->nr_segments = ring_req->nr_segments;
   3.133 +	rmb();
   3.134 +	if (pending_req->nr_segments > VSCSIIF_SG_TABLESIZE) {
   3.135  		DPRINTK("scsiback: invalid parameter nr_seg = %d\n",
   3.136 -			ring_req->nr_segments);
   3.137 +			pending_req->nr_segments);
   3.138  		err = -EINVAL;
   3.139  		goto invald_value;
   3.140  	}
   3.141 -	pending_req->nr_segments = ring_req->nr_segments;
   3.142  
   3.143 -	if (ring_req->cmd_len > VSCSIIF_MAX_COMMAND_SIZE) {
   3.144 +	pending_req->cmd_len = ring_req->cmd_len;
   3.145 +	rmb();
   3.146 +	if (pending_req->cmd_len > VSCSIIF_MAX_COMMAND_SIZE) {
   3.147  		DPRINTK("scsiback: invalid parameter cmd_len = %d\n",
   3.148 -			ring_req->cmd_len);
   3.149 +			pending_req->cmd_len);
   3.150  		err = -EINVAL;
   3.151  		goto invald_value;
   3.152  	}
   3.153 -	memcpy(pending_req->cmnd, ring_req->cmnd, ring_req->cmd_len);
   3.154 -	pending_req->cmd_len = ring_req->cmd_len;
   3.155 +	memcpy(pending_req->cmnd, ring_req->cmnd, pending_req->cmd_len);
   3.156  	
   3.157 -	pending_req->sc_data_direction = ring_req->sc_data_direction;
   3.158  	pending_req->timeout_per_command = ring_req->timeout_per_command;
   3.159  
   3.160  	if(scsiback_gnttab_data_map(ring_req, pending_req)) {