ia64/xen-unstable

changeset 11668:460f2c954cca

[BLKTAP] clean up blktap and remove private structure
This patch cleans up the blktap.c code to make it form to the Linux
coding style a little better.

It also removes the private data structure that is only used to store
the index of the tabfds descriptor. Instead the filp->private_data now
points to the descriptor itself.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
author Andrew Warfield <andy@xensource.com>
date Thu Sep 28 11:52:17 2006 -0700 (2006-09-28)
parents f9929b7e009e
children 5f5e3b4c6fba
files linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Thu Sep 28 11:41:23 2006 -0700
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Thu Sep 28 11:52:17 2006 -0700
     1.3 @@ -102,18 +102,12 @@ typedef struct tap_blkif {
     1.4  	blkif_t *blkif;               /*Associate blkif with tapdev          */
     1.5  } tap_blkif_t;
     1.6  
     1.7 -/*Private data struct associated with the inode*/
     1.8 -typedef struct private_info {
     1.9 -	int idx;
    1.10 -} private_info_t;
    1.11 -
    1.12  /*Data struct handed back to userspace for tapdisk device to VBD mapping*/
    1.13  typedef struct domid_translate {
    1.14  	unsigned short domid;
    1.15  	unsigned short busid;
    1.16  } domid_translate_t ;
    1.17  
    1.18 -
    1.19  static domid_translate_t  translate_domid[MAX_TAP_DEV];
    1.20  static tap_blkif_t *tapfds[MAX_TAP_DEV];
    1.21  
    1.22 @@ -200,7 +194,7 @@ static struct grant_handle_pair
    1.23      + (_i)])
    1.24  
    1.25  
    1.26 -static int blktap_read_ufe_ring(int idx); /*local prototypes*/
    1.27 +static int blktap_read_ufe_ring(tap_blkif_t *info); /*local prototypes*/
    1.28  
    1.29  #define BLKTAP_MINOR 0  /*/dev/xen/blktap resides at device number
    1.30  			  major=254, minor numbers begin at 0            */ 
    1.31 @@ -264,7 +258,8 @@ static inline int GET_NEXT_REQ(unsigned 
    1.32  {
    1.33  	int i;
    1.34  	for (i = 0; i < MAX_PENDING_REQS; i++)
    1.35 -		if (idx_map[i] == INVALID_REQ) return i;
    1.36 +		if (idx_map[i] == INVALID_REQ)
    1.37 +			return i;
    1.38  
    1.39  	return INVALID_REQ;
    1.40  }
    1.41 @@ -369,9 +364,8 @@ void signal_tapdisk(int idx)
    1.42  	info = tapfds[idx];
    1.43  	if ( (idx > 0) && (idx < MAX_TAP_DEV) && (info->pid > 0) ) {
    1.44  		ptask = find_task_by_pid(info->pid);
    1.45 -		if (ptask) { 
    1.46 +		if (ptask)
    1.47  			info->status = CLEANSHUTDOWN;
    1.48 - 		}
    1.49  	}
    1.50  	info->blkif = NULL;
    1.51  	return;
    1.52 @@ -382,7 +376,6 @@ static int blktap_open(struct inode *ino
    1.53  	blkif_sring_t *sring;
    1.54  	int idx = iminor(inode) - BLKTAP_MINOR;
    1.55  	tap_blkif_t *info;
    1.56 -	private_info_t *prv;
    1.57  	int i;
    1.58  	
    1.59  	if (tapfds[idx] == NULL) {
    1.60 @@ -410,9 +403,7 @@ static int blktap_open(struct inode *ino
    1.61  	SHARED_RING_INIT(sring);
    1.62  	FRONT_RING_INIT(&info->ufe_ring, sring, PAGE_SIZE);
    1.63  	
    1.64 -	prv = kzalloc(sizeof(private_info_t),GFP_KERNEL);
    1.65 -	prv->idx = idx;
    1.66 -	filp->private_data = prv;
    1.67 +	filp->private_data = info;
    1.68  	info->vma = NULL;
    1.69  
    1.70  	info->idx_map = kmalloc(sizeof(unsigned long) * MAX_PENDING_REQS, 
    1.71 @@ -433,17 +424,16 @@ static int blktap_open(struct inode *ino
    1.72  
    1.73  static int blktap_release(struct inode *inode, struct file *filp)
    1.74  {
    1.75 -	int idx = iminor(inode) - BLKTAP_MINOR;
    1.76 -	tap_blkif_t *info;
    1.77 +	tap_blkif_t *info = filp->private_data;
    1.78  	
    1.79 -	if (tapfds[idx] == NULL) {
    1.80 +	/* can this ever happen? - sdr */
    1.81 +	if (!info) {
    1.82  		WPRINTK("Trying to free device that doesn't exist "
    1.83 -		       "[/dev/xen/blktap%d]\n",idx);
    1.84 +		       "[/dev/xen/blktap%d]\n",iminor(inode) - BLKTAP_MINOR);
    1.85  		return -1;
    1.86  	}
    1.87 -	info = tapfds[idx];
    1.88  	info->dev_inuse = 0;
    1.89 -	DPRINTK("Freeing device [/dev/xen/blktap%d]\n",idx);
    1.90 +	DPRINTK("Freeing device [/dev/xen/blktap%d]\n",info->minor);
    1.91  
    1.92  	/* Free the ring page. */
    1.93  	ClearPageReserved(virt_to_page(info->ufe_ring.sring));
    1.94 @@ -457,8 +447,6 @@ static int blktap_release(struct inode *
    1.95  		info->vma = NULL;
    1.96  	}
    1.97  	
    1.98 -	if (filp->private_data) kfree(filp->private_data);
    1.99 -
   1.100  	if ( (info->status != CLEANSHUTDOWN) && (info->blkif != NULL) ) {
   1.101  		kthread_stop(info->blkif->xenblkd);
   1.102  		info->blkif->xenblkd = NULL;
   1.103 @@ -491,16 +479,12 @@ static int blktap_mmap(struct file *filp
   1.104  	int size;
   1.105  	struct page **map;
   1.106  	int i;
   1.107 -	private_info_t *prv;
   1.108 -	tap_blkif_t *info;
   1.109 +	tap_blkif_t *info = filp->private_data;
   1.110  
   1.111 -	/*Retrieve the dev info*/
   1.112 -	prv = (private_info_t *)filp->private_data;
   1.113 -	if (prv == NULL) {
   1.114 +	if (info == NULL) {
   1.115  		WPRINTK("blktap: mmap, retrieving idx failed\n");
   1.116  		return -ENOMEM;
   1.117  	}
   1.118 -	info = tapfds[prv->idx];
   1.119  	
   1.120  	vma->vm_flags |= VM_RESERVED;
   1.121  	vma->vm_ops = &blktap_vm_ops;
   1.122 @@ -556,20 +540,17 @@ static int blktap_mmap(struct file *filp
   1.123  static int blktap_ioctl(struct inode *inode, struct file *filp,
   1.124                          unsigned int cmd, unsigned long arg)
   1.125  {
   1.126 -	int idx = iminor(inode) - BLKTAP_MINOR;
   1.127 +	tap_blkif_t *info = filp->private_data;
   1.128 +
   1.129  	switch(cmd) {
   1.130  	case BLKTAP_IOCTL_KICK_FE: 
   1.131  	{
   1.132  		/* There are fe messages to process. */
   1.133 -		return blktap_read_ufe_ring(idx);
   1.134 +		return blktap_read_ufe_ring(info);
   1.135  	}
   1.136  	case BLKTAP_IOCTL_SETMODE:
   1.137  	{
   1.138 -		tap_blkif_t *info = tapfds[idx];
   1.139 -		
   1.140 -		if ( (idx > 0) && (idx < MAX_TAP_DEV) 
   1.141 -		     && (tapfds[idx] != NULL) ) 
   1.142 -		{
   1.143 +		if (info) {
   1.144  			if (BLKTAP_MODE_VALID(arg)) {
   1.145  				info->mode = arg;
   1.146  				/* XXX: may need to flush rings here. */
   1.147 @@ -582,11 +563,7 @@ static int blktap_ioctl(struct inode *in
   1.148  	}
   1.149  	case BLKTAP_IOCTL_PRINT_IDXS:
   1.150          {
   1.151 -		tap_blkif_t *info = tapfds[idx];
   1.152 -		
   1.153 -		if ( (idx > 0) && (idx < MAX_TAP_DEV) 
   1.154 -		     && (tapfds[idx] != NULL) ) 
   1.155 -		{
   1.156 +		if (info) {
   1.157  			printk("User Rings: \n-----------\n");
   1.158  			printk("UF: rsp_cons: %2d, req_prod_prv: %2d "
   1.159  				"| req_prod: %2d, rsp_prod: %2d\n",
   1.160 @@ -599,11 +576,7 @@ static int blktap_ioctl(struct inode *in
   1.161          }
   1.162  	case BLKTAP_IOCTL_SENDPID:
   1.163  	{
   1.164 -		tap_blkif_t *info = tapfds[idx];
   1.165 -		
   1.166 -		if ( (idx > 0) && (idx < MAX_TAP_DEV) 
   1.167 -		     && (tapfds[idx] != NULL) ) 
   1.168 -		{
   1.169 +		if (info) {
   1.170  			info->pid = (pid_t)arg;
   1.171  			DPRINTK("blktap: pid received %d\n", 
   1.172  			       info->pid);
   1.173 @@ -631,9 +604,12 @@ static int blktap_ioctl(struct inode *in
   1.174  	case BLKTAP_IOCTL_FREEINTF:
   1.175  	{
   1.176  		unsigned long dev = arg;
   1.177 -		tap_blkif_t *info = NULL;
   1.178  
   1.179 -		if ( (dev > 0) && (dev < MAX_TAP_DEV) ) info = tapfds[dev];
   1.180 +		/* Looking at another device */
   1.181 +		info = NULL;
   1.182 +
   1.183 +		if ( (dev > 0) && (dev < MAX_TAP_DEV) )
   1.184 +			info = tapfds[dev];
   1.185  
   1.186  		if ( (info != NULL) && (info->dev_pending) )
   1.187  			info->dev_pending = 0;
   1.188 @@ -642,12 +618,17 @@ static int blktap_ioctl(struct inode *in
   1.189  	case BLKTAP_IOCTL_MINOR:
   1.190  	{
   1.191  		unsigned long dev = arg;
   1.192 -		tap_blkif_t *info = NULL;
   1.193 +
   1.194 +		/* Looking at another device */
   1.195 +		info = NULL;
   1.196  		
   1.197 -		if ( (dev > 0) && (dev < MAX_TAP_DEV) ) info = tapfds[dev];
   1.198 +		if ( (dev > 0) && (dev < MAX_TAP_DEV) )
   1.199 +			info = tapfds[dev];
   1.200  		
   1.201 -		if (info != NULL) return info->minor;
   1.202 -		else return -1;
   1.203 +		if (info != NULL)
   1.204 +			return info->minor;
   1.205 +		else
   1.206 +			return -1;
   1.207  	}
   1.208  	case BLKTAP_IOCTL_MAJOR:
   1.209  		return BLKTAP_DEV_MAJOR;
   1.210 @@ -662,23 +643,20 @@ static int blktap_ioctl(struct inode *in
   1.211  	return -ENOIOCTLCMD;
   1.212  }
   1.213  
   1.214 -static unsigned int blktap_poll(struct file *file, poll_table *wait)
   1.215 +static unsigned int blktap_poll(struct file *filp, poll_table *wait)
   1.216  {
   1.217 -	private_info_t *prv;
   1.218 -	tap_blkif_t *info;
   1.219 +	tap_blkif_t *info = filp->private_data;
   1.220  	
   1.221 -	/*Retrieve the dev info*/
   1.222 -	prv = (private_info_t *)file->private_data;
   1.223 -	if (prv == NULL) {
   1.224 +	if (!info) {
   1.225  		WPRINTK(" poll, retrieving idx failed\n");
   1.226  		return 0;
   1.227  	}
   1.228 -	
   1.229 -	if (prv->idx == 0) return 0;
   1.230 -	
   1.231 -	info = tapfds[prv->idx];
   1.232 -	
   1.233 -	poll_wait(file, &info->wait, wait);
   1.234 +
   1.235 +	/* do not work on the control device */
   1.236 +	if (!info->minor)
   1.237 +		return 0;
   1.238 +
   1.239 +	poll_wait(filp, &info->wait, wait);
   1.240  	if (info->ufe_ring.req_prod_pvt != info->ufe_ring.sring->req_prod) {
   1.241  		flush_tlb_all();
   1.242  		RING_PUSH_REQUESTS(&info->ufe_ring);
   1.243 @@ -691,11 +669,14 @@ void blktap_kick_user(int idx)
   1.244  {
   1.245  	tap_blkif_t *info;
   1.246  
   1.247 -	if (idx == 0) return;
   1.248 +	if (idx == 0)
   1.249 +		return;
   1.250  	
   1.251  	info = tapfds[idx];
   1.252  	
   1.253 -	if (info != NULL) wake_up_interruptible(&info->wait);
   1.254 +	if (info != NULL)
   1.255 +		wake_up_interruptible(&info->wait);
   1.256 +
   1.257  	return;
   1.258  }
   1.259  
   1.260 @@ -837,7 +818,8 @@ static void req_decrease(void)
   1.261  			mmap_inuse--;
   1.262  		}
   1.263  	}
   1.264 -	if (mmap_inuse == 0) mmap_req_del(mmap_alloc-1);
   1.265 +	if (mmap_inuse == 0)
   1.266 +		mmap_req_del(mmap_alloc-1);
   1.267   done:
   1.268  	spin_unlock_irqrestore(&pending_free_lock, flags);
   1.269  	return;
   1.270 @@ -1002,7 +984,7 @@ int tap_blkif_schedule(void *arg)
   1.271   * COMPLETION CALLBACK -- Called by user level ioctl()
   1.272   */
   1.273  
   1.274 -static int blktap_read_ufe_ring(int idx)
   1.275 +static int blktap_read_ufe_ring(tap_blkif_t *info)
   1.276  {
   1.277  	/* This is called to read responses from the UFE ring. */
   1.278  	RING_IDX i, j, rp;
   1.279 @@ -1010,12 +992,9 @@ static int blktap_read_ufe_ring(int idx)
   1.280  	blkif_t *blkif=NULL;
   1.281  	int pending_idx, usr_idx, mmap_idx;
   1.282  	pending_req_t *pending_req;
   1.283 -	tap_blkif_t *info;
   1.284  	
   1.285 -	info = tapfds[idx];
   1.286 -	if (info == NULL) {
   1.287 +	if (!info)
   1.288  		return 0;
   1.289 -	}
   1.290  
   1.291  	/* We currently only forward packets in INTERCEPT_FE mode. */
   1.292  	if (!(info->mode & BLKTAP_MODE_INTERCEPT_FE))
   1.293 @@ -1063,7 +1042,7 @@ static int blktap_read_ufe_ring(int idx)
   1.294  				>> PAGE_SHIFT;
   1.295  			map[offset] = NULL;
   1.296  		}
   1.297 -		fast_flush_area(pending_req, pending_idx, usr_idx, idx);
   1.298 +		fast_flush_area(pending_req, pending_idx, usr_idx, info->minor);
   1.299  		make_response(blkif, pending_req->id, resp->operation,
   1.300  			      resp->status);
   1.301  		info->idx_map[usr_idx] = INVALID_REQ;