ia64/xen-unstable

changeset 6367:a826ad59b3ea

Drop support for multiple vbds per blkif.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Aug 23 15:43:04 2005 +0000 (2005-08-23)
parents b3eb952c04ee
children 49b67f0f6735
files linux-2.6-xen-sparse/drivers/xen/blkback/common.h linux-2.6-xen-sparse/drivers/xen/blkback/interface.c linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Tue Aug 23 15:26:54 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Tue Aug 23 15:43:04 2005 +0000
     1.3 @@ -48,8 +48,7 @@ typedef struct blkif_st {
     1.4      /* Comms information. */
     1.5      blkif_back_ring_t blk_ring;
     1.6      /* VBDs attached to this interface. */
     1.7 -    rb_root_t         vbd_rb;        /* Mapping from 16-bit vdevices to VBDs.*/
     1.8 -    spinlock_t        vbd_lock;      /* Protects VBD mapping. */
     1.9 +    struct vbd *vbd;
    1.10      /* Private fields. */
    1.11      enum { DISCONNECTED, CONNECTED } status;
    1.12      /*
    1.13 @@ -61,7 +60,6 @@ typedef struct blkif_st {
    1.14      /* Is this a blktap frontend */
    1.15      unsigned int     is_blktap;
    1.16  #endif
    1.17 -    struct blkif_st *hash_next;
    1.18      struct list_head blkdev_list;
    1.19      spinlock_t       blk_ring_lock;
    1.20      atomic_t         refcnt;
    1.21 @@ -77,7 +75,7 @@ void blkif_destroy(blkif_be_destroy_t *d
    1.22  void blkif_connect(blkif_be_connect_t *connect);
    1.23  int  blkif_disconnect(blkif_be_disconnect_t *disconnect, u8 rsp_id);
    1.24  void blkif_disconnect_complete(blkif_t *blkif);
    1.25 -blkif_t *blkif_find(domid_t domid);
    1.26 +blkif_t *alloc_blkif(domid_t domid);
    1.27  void free_blkif(blkif_t *blkif);
    1.28  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn);
    1.29  
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Tue Aug 23 15:26:54 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Tue Aug 23 15:43:04 2005 +0000
     2.3 @@ -13,23 +13,11 @@
     2.4  #define VMALLOC_VMADDR(x) ((unsigned long)(x))
     2.5  #endif
     2.6  
     2.7 -#define BLKIF_HASHSZ 1024
     2.8 -#define BLKIF_HASH(_d) (((int)(_d))&(BLKIF_HASHSZ-1))
     2.9 +static kmem_cache_t *blkif_cachep;
    2.10  
    2.11 -static kmem_cache_t *blkif_cachep;
    2.12 -static blkif_t      *blkif_hash[BLKIF_HASHSZ];
    2.13 -
    2.14 -blkif_t *blkif_find(domid_t domid)
    2.15 +blkif_t *alloc_blkif(domid_t domid)
    2.16  {
    2.17 -    blkif_t *blkif = blkif_hash[BLKIF_HASH(domid)];
    2.18 -
    2.19 -    while (blkif) {
    2.20 -	if (blkif->domid == domid) {
    2.21 -	    blkif_get(blkif);
    2.22 -	    return blkif;
    2.23 -	}
    2.24 -        blkif = blkif->hash_next;
    2.25 -    }
    2.26 +    blkif_t *blkif;
    2.27  
    2.28      blkif = kmem_cache_alloc(blkif_cachep, GFP_KERNEL);
    2.29      if (!blkif)
    2.30 @@ -38,12 +26,9 @@ blkif_t *blkif_find(domid_t domid)
    2.31      memset(blkif, 0, sizeof(*blkif));
    2.32      blkif->domid = domid;
    2.33      blkif->status = DISCONNECTED;
    2.34 -    spin_lock_init(&blkif->vbd_lock);
    2.35      spin_lock_init(&blkif->blk_ring_lock);
    2.36      atomic_set(&blkif->refcnt, 1);
    2.37  
    2.38 -    blkif->hash_next = blkif_hash[BLKIF_HASH(domid)];
    2.39 -    blkif_hash[BLKIF_HASH(domid)] = blkif;
    2.40      return blkif;
    2.41  }
    2.42  
    2.43 @@ -55,7 +40,7 @@ static int map_frontend_page(blkif_t *bl
    2.44      op.flags = GNTMAP_host_map;
    2.45      op.ref = shared_page;
    2.46      op.dom = blkif->domid;
    2.47 -       
    2.48 +
    2.49      BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
    2.50  
    2.51      if (op.handle < 0) {
    2.52 @@ -125,7 +110,6 @@ int blkif_map(blkif_t *blkif, unsigned l
    2.53  
    2.54  void free_blkif(blkif_t *blkif)
    2.55  {
    2.56 -    blkif_t     **pblkif;
    2.57      evtchn_op_t op = { .cmd = EVTCHNOP_close };
    2.58  
    2.59      op.u.close.port = blkif->evtchn;
    2.60 @@ -143,14 +127,6 @@ void free_blkif(blkif_t *blkif)
    2.61  	vfree(blkif->blk_ring.sring);
    2.62      }
    2.63  
    2.64 -    pblkif = &blkif_hash[BLKIF_HASH(blkif->domid)];
    2.65 -    while ( *pblkif != blkif )
    2.66 -    {
    2.67 -	BUG_ON(!*pblkif);
    2.68 -        pblkif = &(*pblkif)->hash_next;
    2.69 -    }
    2.70 -    *pblkif = blkif->hash_next;
    2.71 -    destroy_all_vbds(blkif);
    2.72      kmem_cache_free(blkif_cachep, blkif);
    2.73  }
    2.74  
    2.75 @@ -158,5 +134,4 @@ void __init blkif_interface_init(void)
    2.76  {
    2.77      blkif_cachep = kmem_cache_create("blkif_cache", sizeof(blkif_t), 
    2.78                                       0, 0, NULL, NULL);
    2.79 -    memset(blkif_hash, 0, sizeof(blkif_hash));
    2.80  }
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c	Tue Aug 23 15:26:54 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c	Tue Aug 23 15:43:04 2005 +0000
     3.3 @@ -3,30 +3,27 @@
     3.4   * 
     3.5   * Routines for managing virtual block devices (VBDs).
     3.6   * 
     3.7 - * NOTE: vbd_lock protects updates to the rb_tree against concurrent lookups 
     3.8 - * in vbd_translate.  All other lookups are implicitly protected because the 
     3.9 - * only caller (the control message dispatch routine) serializes the calls.
    3.10 - * 
    3.11   * Copyright (c) 2003-2005, Keir Fraser & Steve Hand
    3.12   */
    3.13  
    3.14  #include "common.h"
    3.15  #include <asm-xen/xenbus.h>
    3.16  
    3.17 -struct vbd { 
    3.18 -    blkif_vdev_t   handle;     /* what the domain refers to this vbd as */
    3.19 +struct vbd {
    3.20 +    blkif_vdev_t   handle;      /* what the domain refers to this vbd as */
    3.21      unsigned char  readonly;    /* Non-zero -> read-only */
    3.22      unsigned char  type;        /* VDISK_xxx */
    3.23      blkif_pdev_t   pdevice;     /* phys device that this vbd maps to */
    3.24      struct block_device *bdev;
    3.25  
    3.26      int active;
    3.27 -    rb_node_t      rb;          /* for linking into R-B tree lookup struct */
    3.28  }; 
    3.29  
    3.30  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    3.31  static inline dev_t vbd_map_devnum(blkif_pdev_t cookie)
    3.32 -{ return MKDEV(cookie>>8, cookie&0xff); }
    3.33 +{
    3.34 +    return MKDEV(BLKIF_MAJOR(cookie), BLKIF_MINOR(cookie));
    3.35 +}
    3.36  #define vbd_sz(_v)   ((_v)->bdev->bd_part ? \
    3.37      (_v)->bdev->bd_part->nr_sects : (_v)->bdev->bd_disk->capacity)
    3.38  #define bdev_put(_b) blkdev_put(_b)
    3.39 @@ -59,7 +56,7 @@ int vbd_is_active(struct vbd *vbd)
    3.40  struct vbd *vbd_create(blkif_t *blkif, blkif_vdev_t handle,
    3.41  		       blkif_pdev_t pdevice, int readonly)
    3.42  {
    3.43 -    struct vbd  *vbd; 
    3.44 +    struct vbd *vbd, *err; 
    3.45  
    3.46      if ( unlikely((vbd = kmalloc(sizeof(struct vbd), GFP_KERNEL)) == NULL) )
    3.47      {
    3.48 @@ -67,6 +64,7 @@ struct vbd *vbd_create(blkif_t *blkif, b
    3.49  	return ERR_PTR(-ENOMEM);
    3.50      }
    3.51  
    3.52 +    blkif->vbd = vbd;
    3.53      vbd->handle   = handle; 
    3.54      vbd->readonly = readonly;
    3.55      vbd->type     = 0;
    3.56 @@ -74,7 +72,6 @@ struct vbd *vbd_create(blkif_t *blkif, b
    3.57  
    3.58      vbd->pdevice  = pdevice;
    3.59  
    3.60 -    /* FIXME: Who frees vbd on failure? --RR */
    3.61  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    3.62      vbd->bdev = open_by_devnum(
    3.63          vbd_map_devnum(vbd->pdevice),
    3.64 @@ -82,136 +79,67 @@ struct vbd *vbd_create(blkif_t *blkif, b
    3.65      if ( IS_ERR(vbd->bdev) )
    3.66      {
    3.67          DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice);
    3.68 -        return ERR_PTR(-ENOENT);
    3.69 +        err = ERR_PTR(-ENOENT);
    3.70 +	goto out;
    3.71      }
    3.72  
    3.73      if ( (vbd->bdev->bd_disk == NULL) )
    3.74      {
    3.75          DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice);
    3.76          bdev_put(vbd->bdev);
    3.77 -        return ERR_PTR(-ENOENT);
    3.78 +        err = ERR_PTR(-ENOENT);
    3.79 +	goto out;
    3.80      }
    3.81  
    3.82      if ( vbd->bdev->bd_disk->flags & GENHD_FL_CD )
    3.83          vbd->type |= VDISK_CDROM;
    3.84      if ( vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE )
    3.85          vbd->type |= VDISK_REMOVABLE;
    3.86 -
    3.87  #else
    3.88      if ( (blk_size[MAJOR(vbd->pdevice)] == NULL) || (vbd_sz(vbd) == 0) )
    3.89      {
    3.90          DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice);
    3.91 -        return ERR_PTR(-ENOENT);
    3.92 +        err = ERR_PTR(-ENOENT);
    3.93 +	goto out;
    3.94      }
    3.95  #endif
    3.96  
    3.97      DPRINTK("Successful creation of handle=%04x (dom=%u)\n",
    3.98              handle, blkif->domid);
    3.99      return vbd;
   3.100 +
   3.101 + out:
   3.102 +    kfree(vbd);
   3.103 +    return err;
   3.104  }
   3.105  
   3.106  void vbd_activate(blkif_t *blkif, struct vbd *vbd)
   3.107  {
   3.108 -    rb_node_t  **rb_p, *rb_parent = NULL;
   3.109 -    struct vbd *i;
   3.110      BUG_ON(vbd_is_active(vbd));
   3.111  
   3.112 -    /* Find where to put it. */
   3.113 -    rb_p = &blkif->vbd_rb.rb_node;
   3.114 -    while ( *rb_p != NULL )
   3.115 -    {
   3.116 -        rb_parent = *rb_p;
   3.117 -        i = rb_entry(rb_parent, struct vbd, rb);
   3.118 -        if ( vbd->handle < i->handle )
   3.119 -        {
   3.120 -            rb_p = &rb_parent->rb_left;
   3.121 -        }
   3.122 -        else if ( vbd->handle > i->handle )
   3.123 -        {
   3.124 -            rb_p = &rb_parent->rb_right;
   3.125 -        }
   3.126 -        else
   3.127 -        {
   3.128 -	    /* We never create two of same vbd, so not possible. */
   3.129 -	    BUG();
   3.130 -        }
   3.131 -    }
   3.132 -
   3.133      /* Now we're active. */
   3.134      vbd->active = 1;
   3.135      blkif_get(blkif);
   3.136 -
   3.137 -    spin_lock(&blkif->vbd_lock);
   3.138 -    rb_link_node(&vbd->rb, rb_parent, rb_p);
   3.139 -    rb_insert_color(&vbd->rb, &blkif->vbd_rb);
   3.140 -    spin_unlock(&blkif->vbd_lock);
   3.141  }
   3.142  
   3.143  void vbd_free(blkif_t *blkif, struct vbd *vbd)
   3.144  {
   3.145      if (vbd_is_active(vbd)) {
   3.146 -	spin_lock(&blkif->vbd_lock);
   3.147 -	rb_erase(&vbd->rb, &blkif->vbd_rb);
   3.148 -	spin_unlock(&blkif->vbd_lock);
   3.149  	blkif_put(blkif);
   3.150      }
   3.151      bdev_put(vbd->bdev);
   3.152      kfree(vbd);
   3.153  }
   3.154  
   3.155 -void destroy_all_vbds(blkif_t *blkif)
   3.156 -{
   3.157 -    struct vbd *vbd;
   3.158 -    rb_node_t  *rb;
   3.159 -
   3.160 -    spin_lock(&blkif->vbd_lock);
   3.161 -
   3.162 -    while ( (rb = blkif->vbd_rb.rb_node) != NULL )
   3.163 -    {
   3.164 -        vbd = rb_entry(rb, struct vbd, rb);
   3.165 -        rb_erase(rb, &blkif->vbd_rb);
   3.166 -        spin_unlock(&blkif->vbd_lock);
   3.167 -        bdev_put(vbd->bdev);
   3.168 -        kfree(vbd);
   3.169 -        spin_lock(&blkif->vbd_lock);
   3.170 -        blkif_put(blkif);
   3.171 -    }
   3.172 -
   3.173 -    spin_unlock(&blkif->vbd_lock);
   3.174 -}
   3.175 -
   3.176  int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation)
   3.177  {
   3.178 -    struct vbd *vbd;
   3.179 -    rb_node_t  *rb;
   3.180 -    int         rc = -EACCES;
   3.181 -
   3.182 -    /* Take the vbd_lock because another thread could be updating the tree. */
   3.183 -    spin_lock(&blkif->vbd_lock);
   3.184 +    struct vbd *vbd = blkif->vbd;
   3.185 +    int rc = -EACCES;
   3.186  
   3.187 -    rb = blkif->vbd_rb.rb_node;
   3.188 -    while ( rb != NULL )
   3.189 -    {
   3.190 -        vbd = rb_entry(rb, struct vbd, rb);
   3.191 -        if ( req->dev < vbd->handle )
   3.192 -            rb = rb->rb_left;
   3.193 -        else if ( req->dev > vbd->handle )
   3.194 -            rb = rb->rb_right;
   3.195 -        else
   3.196 -            goto found;
   3.197 -    }
   3.198 -
   3.199 -    DPRINTK("vbd_translate; domain %u attempted to access "
   3.200 -            "non-existent VBD.\n", blkif->domid);
   3.201 -    rc = -ENODEV;
   3.202 -    goto out;
   3.203 -
   3.204 - found:
   3.205 -
   3.206 -    if ( (operation == WRITE) && vbd->readonly )
   3.207 +    if ((operation == WRITE) && vbd->readonly)
   3.208          goto out;
   3.209  
   3.210 -    if ( unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)) )
   3.211 +    if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)))
   3.212          goto out;
   3.213  
   3.214      req->dev  = vbd->pdevice;
   3.215 @@ -219,6 +147,5 @@ int vbd_translate(struct phys_req *req, 
   3.216      rc = 0;
   3.217  
   3.218   out:
   3.219 -    spin_unlock(&blkif->vbd_lock);
   3.220      return rc;
   3.221  }
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Tue Aug 23 15:26:54 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Tue Aug 23 15:43:04 2005 +0000
     4.3 @@ -228,7 +228,7 @@ static void backend_changed(struct xenbu
     4.4  		p = strrchr(be->frontpath, '/') + 1;
     4.5  		handle = simple_strtoul(p, NULL, 0);
     4.6  
     4.7 -		be->blkif = blkif_find(be->frontend_id);
     4.8 +		be->blkif = alloc_blkif(be->frontend_id);
     4.9  		if (IS_ERR(be->blkif)) {
    4.10  			err = PTR_ERR(be->blkif);
    4.11  			be->blkif = NULL;