[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Manual merge.



ChangeSet 1.1484, 2005/05/20 15:17:35+01:00, kaf24@xxxxxxxxxxxxxxxxxxxx

        Manual merge.



 vbd.c |  446 +++++++++++-------------------------------------------------------
 1 files changed, 75 insertions(+), 371 deletions(-)


diff -Nru a/linux-2.6.11-xen-sparse/drivers/xen/blkback/vbd.c 
b/linux-2.6.11-xen-sparse/drivers/xen/blkback/vbd.c
--- a/linux-2.6.11-xen-sparse/drivers/xen/blkback/vbd.c 2005-05-20 11:02:05 
-04:00
+++ b/linux-2.6.11-xen-sparse/drivers/xen/blkback/vbd.c 2005-05-20 11:02:05 
-04:00
@@ -7,21 +7,34 @@
  * in vbd_translate.  All other lookups are implicitly protected because the 
  * only caller (the control message dispatch routine) serializes the calls.
  * 
- * Copyright (c) 2003-2004, Keir Fraser & Steve Hand
+ * Copyright (c) 2003-2005, Keir Fraser & Steve Hand
  */
 
 #include "common.h"
 
+struct vbd { 
+    blkif_vdev_t   vdevice;     /* what the domain refers to this vbd as */
+    unsigned char  readonly;    /* Non-zero -> read-only */
+    unsigned char  type;        /* VDISK_TYPE_xxx */
+    blkif_pdev_t   pdevice;     /* phys device that this vbd maps to */
+    struct block_device *bdev;
+    rb_node_t      rb;          /* for linking into R-B tree lookup struct */
+}; 
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-static dev_t vbd_map_devnum(blkif_pdev_t);
+static inline dev_t vbd_map_devnum(blkif_pdev_t cookie)
+{ return MKDEV(cookie>>8, cookie&0xff); }
+#define vbd_sz(_v)   ((_v)->bdev->bd_part ? \
+    (_v)->bdev->bd_part->nr_sects : (_v)->bdev->bd_disk->capacity)
 #define bdev_put(_b) blkdev_put(_b)
 #else
+#define vbd_sz(_v)   (blk_size[MAJOR((_v)->pdevice)][MINOR((_v)->pdevice)]*2)
 #define bdev_put(_b) ((void)0)
 #endif
 
 void vbd_create(blkif_be_vbd_create_t *create) 
 {
-    vbd_t       *vbd; 
+    struct vbd  *vbd; 
     rb_node_t  **rb_p, *rb_parent = NULL;
     blkif_t     *blkif;
     blkif_vdev_t vdevice = create->vdevice;
@@ -39,7 +52,7 @@
     while ( *rb_p != NULL )
     {
         rb_parent = *rb_p;
-        vbd = rb_entry(rb_parent, vbd_t, rb);
+        vbd = rb_entry(rb_parent, struct vbd, rb);
         if ( vdevice < vbd->vdevice )
         {
             rb_p = &rb_parent->rb_left;
@@ -56,7 +69,7 @@
         }
     }
 
-    if ( unlikely((vbd = kmalloc(sizeof(vbd_t), GFP_KERNEL)) == NULL) )
+    if ( unlikely((vbd = kmalloc(sizeof(struct vbd), GFP_KERNEL)) == NULL) )
     {
         DPRINTK("vbd_create: out of memory\n");
         create->status = BLKIF_BE_STATUS_OUT_OF_MEMORY;
@@ -65,216 +78,54 @@
 
     vbd->vdevice  = vdevice; 
     vbd->readonly = create->readonly;
-    vbd->type     = VDISK_TYPE_DISK;
-    vbd->extents  = NULL; 
-
-    spin_lock(&blkif->vbd_lock);
-    rb_link_node(&vbd->rb, rb_parent, rb_p);
-    rb_insert_color(&vbd->rb, &blkif->vbd_rb);
-    spin_unlock(&blkif->vbd_lock);
-
-    DPRINTK("Successful creation of vdev=%04x (dom=%u)\n",
-            vdevice, create->domid);
-    create->status = BLKIF_BE_STATUS_OKAY;
-}
-
-
-/* Grow a VBD by appending a new extent. Fails if the VBD doesn't exist. */
-void vbd_grow(blkif_be_vbd_grow_t *grow) 
-{
-    blkif_t            *blkif;
-    blkif_extent_le_t **px, *x; 
-    vbd_t              *vbd = NULL;
-    rb_node_t          *rb;
-    blkif_vdev_t        vdevice = grow->vdevice;
-    unsigned long       sz;
-
-    blkif = blkif_find_by_handle(grow->domid, grow->blkif_handle);
-    if ( unlikely(blkif == NULL) )
-    {
-        DPRINTK("vbd_grow attempted for non-existent blkif (%u,%u)\n", 
-                grow->domid, grow->blkif_handle); 
-        grow->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND;
-        return;
-    }
-
-    rb = blkif->vbd_rb.rb_node;
-    while ( rb != NULL )
-    {
-        vbd = rb_entry(rb, vbd_t, rb);
-        if ( vdevice < vbd->vdevice )
-            rb = rb->rb_left;
-        else if ( vdevice > vbd->vdevice )
-            rb = rb->rb_right;
-        else
-            break;
-    }
-
-    if ( unlikely(vbd == NULL) || unlikely(vbd->vdevice != vdevice) )
-    {
-        DPRINTK("vbd_grow: attempted to append extent to non-existent VBD.\n");
-        grow->status = BLKIF_BE_STATUS_VBD_NOT_FOUND;
-        return;
-    } 
-
-    if ( grow->extent.sector_start > 0 )
-    {
-        DPRINTK("vbd_grow: dev %08x start not zero.\n", grow->extent.device);
-        grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND;
-        return;
-    }
-
-    if ( unlikely((x = kmalloc(sizeof(blkif_extent_le_t), 
-                               GFP_KERNEL)) == NULL) )
-    {
-        DPRINTK("vbd_grow: out of memory\n");
-        grow->status = BLKIF_BE_STATUS_OUT_OF_MEMORY;
-        return;
-    }
+    vbd->type     = VDISK_TYPE_DISK | VDISK_FLAG_VIRT;
 
     /* Mask to 16-bit for compatibility with old tools */
-    x->extent.device        = grow->extent.device & 0xffff;
-    x->extent.sector_start  = grow->extent.sector_start;
-    x->extent.sector_length = grow->extent.sector_length;
-    x->next                 = (blkif_extent_le_t *)NULL;
+    vbd->pdevice  = create->pdevice & 0xffff;
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-    x->bdev = open_by_devnum(vbd_map_devnum(x->extent.device),
-                             vbd->readonly ? FMODE_READ : FMODE_WRITE);
-    if ( IS_ERR(x->bdev) )
-    {
-        DPRINTK("vbd_grow: device %08x doesn't exist.\n", x->extent.device);
-        grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND;
-        goto out;
-    }
-    /* XXXcl maybe bd_claim? */
-
-    if ( (x->bdev->bd_disk == NULL) )
-    {
-        DPRINTK("vbd_grow: device %08x doesn't exist.\n", x->extent.device);
-        grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND;
-        bdev_put(x->bdev);
-        goto out;
-    }
-
-    /* get size in sectors */   
-    if ( x->bdev->bd_part )
-        sz = x->bdev->bd_part->nr_sects;
-    else
-        sz = x->bdev->bd_disk->capacity;
-
-    vbd->type = (x->bdev->bd_disk->flags & GENHD_FL_CD) ?
-        VDISK_TYPE_CDROM : VDISK_TYPE_DISK;
-
-#else
-    if( !blk_size[MAJOR(x->extent.device)] )
-    {
-        DPRINTK("vbd_grow: device %08x doesn't exist.\n", x->extent.device);
-        grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND;
-        goto out;
-    }
-    
-    /* convert blocks (1KB) to sectors */
-    sz = blk_size[MAJOR(x->extent.device)][MINOR(x->extent.device)] * 2;    
-    
-    if ( sz == 0 )
+    vbd->bdev = open_by_devnum(
+        vbd_map_devnum(vbd->pdevice),
+        vbd->readonly ? FMODE_READ : FMODE_WRITE);
+    if ( IS_ERR(vbd->bdev) )
     {
-        DPRINTK("vbd_grow: device %08x zero size!\n", x->extent.device);
-        grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND;
-        goto out;
-    }
-#endif
-
-    /*
-     * NB. This test assumes sector_start == 0, which is always the case
-     * in Xen 1.3. In fact the whole grow/shrink interface could do with
-     * some simplification.
-     */
-    if ( x->extent.sector_length > sz )
-        x->extent.sector_length = sz;
-    
-    DPRINTK("vbd_grow: requested_len %llu actual_len %lu\n", 
-            x->extent.sector_length, sz);
-
-    for ( px = &vbd->extents; *px != NULL; px = &(*px)->next ) 
-        continue;
-    
-    *px = x; /* ATOMIC: no need for vbd_lock. */
-
-    DPRINTK("Successful grow of vdev=%04x (dom=%u)\n",
-            vdevice, grow->domid);
-    
-    grow->status = BLKIF_BE_STATUS_OKAY;
-    return;
-
- out:
-    kfree(x);
-}
-
-
-void vbd_shrink(blkif_be_vbd_shrink_t *shrink)
-{
-    blkif_t            *blkif;
-    blkif_extent_le_t **px, *x; 
-    vbd_t              *vbd = NULL;
-    rb_node_t          *rb;
-    blkif_vdev_t        vdevice = shrink->vdevice;
-
-    blkif = blkif_find_by_handle(shrink->domid, shrink->blkif_handle);
-    if ( unlikely(blkif == NULL) )
-    {
-        DPRINTK("vbd_shrink attempted for non-existent blkif (%u,%u)\n", 
-                shrink->domid, shrink->blkif_handle); 
-        shrink->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND;
+        DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice);
+        create->status = BLKIF_BE_STATUS_PHYSDEV_NOT_FOUND;
         return;
     }
 
-    rb = blkif->vbd_rb.rb_node;
-    while ( rb != NULL )
-    {
-        vbd = rb_entry(rb, vbd_t, rb);
-        if ( vdevice < vbd->vdevice )
-            rb = rb->rb_left;
-        else if ( vdevice > vbd->vdevice )
-            rb = rb->rb_right;
-        else
-            break;
-    }
-
-    if ( unlikely(vbd == NULL) || unlikely(vbd->vdevice != vdevice) )
+    if ( (vbd->bdev->bd_disk == NULL) )
     {

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.