ia64/xen-unstable

changeset 1315:a823ac69d295

bitkeeper revision 1.875 (40880cc61MwJ9kqSeEq4GyGu66mQEg)

Consoel fixes and more work on blkdev backend.
author kaf24@scramble.cl.cam.ac.uk
date Thu Apr 22 18:19:50 2004 +0000 (2004-04-22)
parents 33e86963d2a4
children cd4da543a120 fc75c553f56e
files .rootkeys tools/misc/xencons tools/xenctl/lib/console_client.py tools/xend/lib/console.py tools/xend/lib/domain_controller.h tools/xend/lib/manager.py xenolinux-2.4.26-sparse/arch/xen/drivers/console/console.c xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/common.h xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/control.c xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/interface.c xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/vbd.c xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/vblkif.h
line diff
     1.1 --- a/.rootkeys	Thu Apr 22 18:02:56 2004 +0000
     1.2 +++ b/.rootkeys	Thu Apr 22 18:19:50 2004 +0000
     1.3 @@ -680,6 +680,7 @@ 4075806dI5kfeMD5RV-DA0PYoThx_w xenolinux
     1.4  4075806d3fJqqDC1pYYPTZPc575iKg xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/frontend/block.c
     1.5  4075806d4-j7vN0Mn0bklI1cRUX1vQ xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/frontend/block.h
     1.6  4075806dibjCcfuXv6CINMhxWTw3jQ xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/frontend/vbd.c
     1.7 +40880cc6hHg6s2cPHbqPNQxENefjoQ xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/vblkif.h
     1.8  4083dc16-Kd5y9psK_yk161sme5j5Q xenolinux-2.4.26-sparse/arch/xen/drivers/vnetif/Makefile
     1.9  4083dc16UmHXxS9g_UFVnkUpN-oP2Q xenolinux-2.4.26-sparse/arch/xen/drivers/vnetif/backend/Makefile
    1.10  4087cf0d5dudKw_DecIJgOhLlBF_0Q xenolinux-2.4.26-sparse/arch/xen/drivers/vnetif/backend/main.c
     2.1 --- a/tools/misc/xencons	Thu Apr 22 18:02:56 2004 +0000
     2.2 +++ b/tools/misc/xencons	Thu Apr 22 18:19:50 2004 +0000
     2.3 @@ -49,9 +49,6 @@ def __send_to_sock(sock):
     2.4  
     2.5  def connect(host,port):
     2.6      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
     2.7 -    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     2.8 -    sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
     2.9 -                    struct.pack('ii', 0, 0))
    2.10      sock.connect((host,port))
    2.11  
    2.12      oattrs = tcgetattr(0)
     3.1 --- a/tools/xenctl/lib/console_client.py	Thu Apr 22 18:02:56 2004 +0000
     3.2 +++ b/tools/xenctl/lib/console_client.py	Thu Apr 22 18:19:50 2004 +0000
     3.3 @@ -49,9 +49,6 @@ def __send_to_sock(sock):
     3.4  
     3.5  def connect(host,port):
     3.6      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
     3.7 -    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     3.8 -    sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
     3.9 -                    struct.pack('ii', 0, 0))
    3.10      sock.connect((host,port))
    3.11  
    3.12      oattrs = tcgetattr(0)
     4.1 --- a/tools/xend/lib/console.py	Thu Apr 22 18:02:56 2004 +0000
     4.2 +++ b/tools/xend/lib/console.py	Thu Apr 22 18:19:50 2004 +0000
     4.3 @@ -75,8 +75,6 @@ class interface:
     4.4              # Turn the new socket into a non-blocking listener.
     4.5              self.sock.setblocking(False)
     4.6              self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     4.7 -            self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
     4.8 -                                 struct.pack('ii', 0, 0))
     4.9              self.sock.bind(('', self.port))
    4.10              self.sock.listen(1)
    4.11  
    4.12 @@ -99,8 +97,7 @@ class interface:
    4.13          except:
    4.14              return 0
    4.15          sock.setblocking(False)
    4.16 -        sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
    4.17 -                        struct.pack('ii', 0, 0))
    4.18 +        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    4.19  
    4.20          # Close the listening socket.
    4.21          self.sock.close()
     5.1 --- a/tools/xend/lib/domain_controller.h	Thu Apr 22 18:02:56 2004 +0000
     5.2 +++ b/tools/xend/lib/domain_controller.h	Thu Apr 22 18:19:50 2004 +0000
     5.3 @@ -75,9 +75,10 @@ typedef struct {
     5.4   * Message request/response defintions for block-device messages.
     5.5   */
     5.6  
     5.7 -typedef u16 blkif_vdev_t;
     5.8 -typedef u16 blkif_pdev_t;
     5.9 -typedef u64 blkif_sector_t;
    5.10 +#define blkif_vdev_t   u16
    5.11 +#define blkif_pdev_t   u16
    5.12 +#define blkif_sector_t u64
    5.13 +
    5.14  typedef struct {
    5.15      blkif_pdev_t   device;
    5.16      blkif_sector_t sector_start;
    5.17 @@ -104,7 +105,7 @@ typedef struct {
    5.18      /* IN */
    5.19      domid_t        domid;             /* Domain attached to new interface.   */
    5.20      unsigned int   blkif_handle;      /* Domain-specific interface handle.   */
    5.21 -    unsigned int   evtchn_port;       /* Event channel for notifications.    */
    5.22 +    unsigned int   evtchn;            /* Event channel for notifications.    */
    5.23      unsigned long  shmem_frame;       /* Page cont. shared comms window.     */
    5.24      /* OUT */
    5.25      unsigned int   status;
     6.1 --- a/tools/xend/lib/manager.py	Thu Apr 22 18:02:56 2004 +0000
     6.2 +++ b/tools/xend/lib/manager.py	Thu Apr 22 18:19:50 2004 +0000
     6.3 @@ -22,7 +22,7 @@ def new_control_interface(dom, console_p
     6.4      if console_port < 0:
     6.5          console_port = 9600 + port.local_port
     6.6  
     6.7 -    # Create a listenign console interface.
     6.8 +    # Create a listening console interface.
     6.9      con_if = xend.console.interface(console_port, port.local_port)
    6.10      con_if.listen()
    6.11  
     7.1 --- a/xenolinux-2.4.26-sparse/arch/xen/drivers/console/console.c	Thu Apr 22 18:02:56 2004 +0000
     7.2 +++ b/xenolinux-2.4.26-sparse/arch/xen/drivers/console/console.c	Thu Apr 22 18:19:50 2004 +0000
     7.3 @@ -33,7 +33,7 @@
     7.4  #define XEN_TTY_MINOR 123
     7.5  
     7.6  /* The kernel and user-land drivers share a common transmit buffer. */
     7.7 -#define WBUF_SIZE     1024
     7.8 +#define WBUF_SIZE     4096
     7.9  #define WBUF_MASK(_i) ((_i)&(WBUF_SIZE-1))
    7.10  static char wbuf[WBUF_SIZE];
    7.11  static unsigned int wc, wp; /* write_cons, write_prod */
     8.1 --- a/xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/common.h	Thu Apr 22 18:02:56 2004 +0000
     8.2 +++ b/xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/common.h	Thu Apr 22 18:19:50 2004 +0000
     8.3 @@ -12,6 +12,7 @@
     8.4  #include <linux/slab.h>
     8.5  #include <asm/ctrl_if.h>
     8.6  #include <asm/io.h>
     8.7 +#include "../vblkif.h"
     8.8  
     8.9  #ifndef NDEBUG
    8.10  #define ASSERT(_p) \
    8.11 @@ -24,7 +25,7 @@
    8.12  #define DPRINTK(_f, _a...) ((void)0)
    8.13  #endif
    8.14  
    8.15 -typedef struct {
    8.16 +typedef struct blkif_st {
    8.17      /* Unique identifier for this interface. */
    8.18      domid_t          domid;
    8.19      unsigned int     handle;
    8.20 @@ -40,10 +41,13 @@ typedef struct {
    8.21      rb_root_t        vbd_rb;        /* Mapping from 16-bit vdevices to VBDs. */
    8.22      spinlock_t       vbd_lock;      /* Protects VBD mapping. */
    8.23      /* Private fields. */
    8.24 +    struct blkif_st *hash_next;
    8.25      struct list_head blkdev_list;
    8.26      spinlock_t       blk_ring_lock;
    8.27  } blkif_t;
    8.28  
    8.29 +void blkif_create(blkif_create_t *create);
    8.30 +void blkif_destroy(blkif_destroy_t *destroy);
    8.31  blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
    8.32  void blkif_get(blkif_t *blkif);
    8.33  void blkif_put(blkif_t *blkif);
     9.1 --- a/xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/control.c	Thu Apr 22 18:02:56 2004 +0000
     9.2 +++ b/xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/control.c	Thu Apr 22 18:19:50 2004 +0000
     9.3 @@ -57,4 +57,5 @@ static void blkif_ctrlif_rx(ctrl_msg_t *
     9.4  int blkif_ctrlif_init(void)
     9.5  {
     9.6      (void)ctrl_if_register_receiver(CMSG_BLKIF_BE, blkif_ctrlif_rx);
     9.7 +    return 0;
     9.8  }
    10.1 --- a/xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/interface.c	Thu Apr 22 18:02:56 2004 +0000
    10.2 +++ b/xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/interface.c	Thu Apr 22 18:19:50 2004 +0000
    10.3 @@ -16,7 +16,7 @@ static blkif_t *blkif_hash[BLKIF_HASHSZ]
    10.4  
    10.5  blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle)
    10.6  {
    10.7 -    blkif_t *blkif = &blkif_hash[BLKIF_HASH(domid, handle)];
    10.8 +    blkif_t *blkif = blkif_hash[BLKIF_HASH(domid, handle)];
    10.9      while ( (blkif != NULL) && 
   10.10              (blkif->domid != domid) && 
   10.11              (blkif->handle != handle) )
   10.12 @@ -24,7 +24,7 @@ blkif_t *blkif_find_by_handle(domid_t do
   10.13      return blkif;
   10.14  }
   10.15  
   10.16 -static void blkif_create(blkif_create_t *create)
   10.17 +void blkif_create(blkif_create_t *create)
   10.18  {
   10.19      domid_t       domid  = create->domid;
   10.20      unsigned int  handle = create->blkif_handle;
   10.21 @@ -69,7 +69,7 @@ static void blkif_create(blkif_create_t 
   10.22      return;
   10.23  }
   10.24  
   10.25 -static void blkif_destroy(blkif_destroy_t *destroy)
   10.26 +void blkif_destroy(blkif_destroy_t *destroy)
   10.27  {
   10.28      domid_t       domid  = destroy->domid;
   10.29      unsigned int  handle = destroy->blkif_handle;
   10.30 @@ -83,7 +83,7 @@ static void blkif_destroy(blkif_destroy_
   10.31          pblkif = &blkif->hash_next;
   10.32      }
   10.33  
   10.34 -    destroy->status = BLKIF_STATUS_NO_INTERFACE;
   10.35 +    destroy->status = BLKIF_STATUS_INTERFACE_NOT_FOUND;
   10.36      return;
   10.37  
   10.38   found_match:
    11.1 --- a/xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/vbd.c	Thu Apr 22 18:02:56 2004 +0000
    11.2 +++ b/xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/backend/vbd.c	Thu Apr 22 18:19:50 2004 +0000
    11.3 @@ -8,18 +8,25 @@
    11.4  
    11.5  #include "common.h"
    11.6  
    11.7 -long __vbd_create(struct task_struct *p,
    11.8 -                  unsigned short vdevice,
    11.9 -                  unsigned char mode,
   11.10 -                  unsigned char type)
   11.11 +void vbd_create(blkif_vbd_create_t *create) 
   11.12  {
   11.13 -    vbd_t *vbd; 
   11.14 -    rb_node_t **rb_p, *rb_parent = NULL;
   11.15 -    long ret = 0;
   11.16 +    vbd_t       *vbd; 
   11.17 +    rb_node_t  **rb_p, *rb_parent = NULL;
   11.18 +    blkif_t     *blkif;
   11.19 +    blkif_vdev_t vdevice = create->vdevice;
   11.20  
   11.21 -    spin_lock(&p->vbd_lock);
   11.22 +    blkif = blkif_find_by_handle(create->domid, create->blkif_handle);
   11.23 +    if ( unlikely(blkif == NULL) )
   11.24 +    {
   11.25 +        DPRINTK("vbd_create attempted for non-existent blkif (%llu,&u)\n", 
   11.26 +                create->domid, create->blkif_handle); 
   11.27 +        create->status = BLKIF_STATUS_INTERFACE_NOT_FOUND;
   11.28 +        return;
   11.29 +    }
   11.30  
   11.31 -    rb_p = &p->vbd_rb.rb_node;
   11.32 +    spin_lock(&blkif->vbd_lock);
   11.33 +
   11.34 +    rb_p = &blkif->vbd_rb.rb_node;
   11.35      while ( *rb_p != NULL )
   11.36      {
   11.37          rb_parent = *rb_p;
   11.38 @@ -35,7 +42,7 @@ long __vbd_create(struct task_struct *p,
   11.39          else
   11.40          {
   11.41              DPRINTK("vbd_create attempted for already existing vbd\n");
   11.42 -            ret = -EINVAL;
   11.43 +            create->status = BLKIF_STATUS_VBD_EXISTS;
   11.44              goto out;
   11.45          }
   11.46      }
   11.47 @@ -43,60 +50,47 @@ long __vbd_create(struct task_struct *p,
   11.48      if ( unlikely((vbd = kmalloc(sizeof(vbd_t), GFP_KERNEL)) == NULL) )
   11.49      {
   11.50          DPRINTK("vbd_create: out of memory\n");
   11.51 -        ret = -ENOMEM;
   11.52 +        create->status = BLKIF_STATUS_OUT_OF_MEMORY;
   11.53          goto out;
   11.54      }
   11.55  
   11.56      vbd->vdevice = vdevice; 
   11.57 -    vbd->mode    = mode; 
   11.58 -    vbd->type    = type;
   11.59 +    vbd->mode    = create->mode; 
   11.60 +    vbd->type    = VDISK_TYPE_DISK | VDISK_FLAG_VIRT;
   11.61      vbd->extents = NULL; 
   11.62  
   11.63      rb_link_node(&vbd->rb, rb_parent, rb_p);
   11.64 -    rb_insert_color(&vbd->rb, &p->vbd_rb);
   11.65 +    rb_insert_color(&vbd->rb, &blkif->vbd_rb);
   11.66 +
   11.67 +    create->status = BLKIF_STATUS_OKAY;
   11.68  
   11.69   out:
   11.70 -    spin_unlock(&p->vbd_lock);
   11.71 -    return ret; 
   11.72 +    spin_unlock(&blkif->vbd_lock);
   11.73 +    blkif_put(blkif);
   11.74  }
   11.75  
   11.76  
   11.77 -long vbd_create(vbd_create_t *create) 
   11.78 +/* Grow a VBD by appending a new extent. Fails if the VBD doesn't exist. */
   11.79 +void vbd_grow(blkif_vbd_grow_t *grow) 
   11.80  {
   11.81 -    struct task_struct *p;
   11.82 -    long rc;
   11.83 +    blkif_t          *blkif;
   11.84 +    xen_extent_le_t **px, *x; 
   11.85 +    vbd_t            *vbd = NULL;
   11.86 +    rb_node_t        *rb;
   11.87 +    blkif_vdev_t      vdevice = grow->vdevice;
   11.88  
   11.89 -    if ( unlikely(!IS_PRIV(current)) )
   11.90 -        return -EPERM;
   11.91 -
   11.92 -    if ( unlikely((p = find_domain_by_id(create->domain)) == NULL) )
   11.93 +    blkif = blkif_find_by_handle(grow->domid, grow->blkif_handle);
   11.94 +    if ( unlikely(blkif == NULL) )
   11.95      {
   11.96 -        DPRINTK("vbd_create attempted for non-existent domain %llu\n", 
   11.97 -                create->domain); 
   11.98 -        return -EINVAL; 
   11.99 +        DPRINTK("vbd_grow attempted for non-existent blkif (%llu,&u)\n", 
  11.100 +                grow->domid, grow->blkif_handle); 
  11.101 +        grow->status = BLKIF_STATUS_INTERFACE_NOT_FOUND;
  11.102 +        return;
  11.103      }
  11.104  
  11.105 -    rc = __vbd_create(p, create->vdevice, create->mode,
  11.106 -                      XD_TYPE_DISK | XD_FLAG_VIRT);
  11.107 -
  11.108 -    put_task_struct(p);
  11.109 -
  11.110 -    return rc;
  11.111 -}
  11.112 -
  11.113 +    spin_lock(&blkif->vbd_lock);
  11.114  
  11.115 -long __vbd_grow(struct task_struct *p,
  11.116 -                unsigned short vdevice,
  11.117 -                xen_extent_t *extent)
  11.118 -{
  11.119 -    xen_extent_le_t **px, *x; 
  11.120 -    vbd_t *vbd = NULL;
  11.121 -    rb_node_t *rb;
  11.122 -    long ret = 0;
  11.123 -
  11.124 -    spin_lock(&p->vbd_lock);
  11.125 -
  11.126 -    rb = p->vbd_rb.rb_node;
  11.127 +    rb = blkif->vbd_rb.rb_node;
  11.128      while ( rb != NULL )
  11.129      {
  11.130          vbd = rb_entry(rb, vbd_t, rb);
  11.131 @@ -111,95 +105,75 @@ long __vbd_grow(struct task_struct *p,
  11.132      if ( unlikely(vbd == NULL) || unlikely(vbd->vdevice != vdevice) )
  11.133      {
  11.134          DPRINTK("vbd_grow: attempted to append extent to non-existent VBD.\n");
  11.135 -        ret = -EINVAL;
  11.136 +        grow->status = BLKIF_STATUS_VBD_NOT_FOUND;
  11.137          goto out;
  11.138      } 
  11.139  
  11.140      if ( unlikely((x = kmalloc(sizeof(xen_extent_le_t), GFP_KERNEL)) == NULL) )
  11.141      {
  11.142          DPRINTK("vbd_grow: out of memory\n");
  11.143 -        ret = -ENOMEM;
  11.144 +        grow->status = BLKIF_STATUS_OUT_OF_MEMORY;
  11.145          goto out;
  11.146      }
  11.147   
  11.148 -    x->extent.device       = extent->device; 
  11.149 -    x->extent.start_sector = extent->start_sector; 
  11.150 -    x->extent.nr_sectors   = extent->nr_sectors; 
  11.151 -    x->next                = (xen_extent_le_t *)NULL; 
  11.152 +    x->extent.device        = grow->extent.device; 
  11.153 +    x->extent.sector_start  = grow->extent.sector_start; 
  11.154 +    x->extent.sector_length = grow->extent.sector_length; 
  11.155 +    x->next                 = (xen_extent_le_t *)NULL; 
  11.156  
  11.157      for ( px = &vbd->extents; *px != NULL; px = &(*px)->next ) 
  11.158          continue;
  11.159  
  11.160      *px = x;
  11.161  
  11.162 +    grow->status = BLKIF_STATUS_OKAY;
  11.163 +
  11.164   out:
  11.165 -    spin_unlock(&p->vbd_lock);
  11.166 -    return ret;
  11.167 +    spin_unlock(&blkif->vbd_lock);
  11.168 +    blkif_put(blkif);
  11.169  }
  11.170  
  11.171  
  11.172 -/* Grow a VBD by appending a new extent. Fails if the VBD doesn't exist. */
  11.173 -long vbd_grow(vbd_grow_t *grow) 
  11.174 +void vbd_shrink(blkif_vbd_shrink_t *shrink)
  11.175  {
  11.176 -    struct task_struct *p;
  11.177 -    long rc;
  11.178 +    blkif_t          *blkif;
  11.179 +    xen_extent_le_t **px, *x; 
  11.180 +    vbd_t            *vbd = NULL;
  11.181 +    rb_node_t        *rb;
  11.182 +    blkif_vdev_t      vdevice = shrink->vdevice;
  11.183  
  11.184 -    if ( unlikely(!IS_PRIV(current)) )
  11.185 -        return -EPERM; 
  11.186 -
  11.187 -    if ( unlikely((p = find_domain_by_id(grow->domain)) == NULL) )
  11.188 +    blkif = blkif_find_by_handle(shrink->domid, shrink->blkif_handle);
  11.189 +    if ( unlikely(blkif == NULL) )
  11.190      {
  11.191 -        DPRINTK("vbd_grow: attempted for non-existent domain %llu\n", 
  11.192 -                grow->domain); 
  11.193 -        return -EINVAL; 
  11.194 +        DPRINTK("vbd_shrink attempted for non-existent blkif (%llu,&u)\n", 
  11.195 +                shrink->domid, shrink->blkif_handle); 
  11.196 +        shrink->status = BLKIF_STATUS_INTERFACE_NOT_FOUND;
  11.197 +        return;
  11.198      }
  11.199  
  11.200 -    rc = __vbd_grow(p, grow->vdevice, &grow->extent);
  11.201 -
  11.202 -    put_task_struct(p);
  11.203 -
  11.204 -    return rc;
  11.205 -}
  11.206 -
  11.207 +    spin_lock(&blkif->vbd_lock);
  11.208  
  11.209 -long vbd_shrink(vbd_shrink_t *shrink)
  11.210 -{
  11.211 -    struct task_struct *p; 
  11.212 -    xen_extent_le_t **px, *x; 
  11.213 -    vbd_t *vbd = NULL;
  11.214 -    rb_node_t *rb;
  11.215 -    long ret = 0;
  11.216 -
  11.217 -    if ( !IS_PRIV(current) )
  11.218 -        return -EPERM; 
  11.219 -
  11.220 -    if ( (p = find_domain_by_id(shrink->domain)) == NULL )
  11.221 -    {
  11.222 -        DPRINTK("vbd_shrink attempted for non-existent domain %llu\n", 
  11.223 -                shrink->domain); 
  11.224 -        return -EINVAL; 
  11.225 -    }
  11.226 -
  11.227 -    spin_lock(&p->vbd_lock);
  11.228 -
  11.229 -    rb = p->vbd_rb.rb_node;
  11.230 +    rb = blkif->vbd_rb.rb_node;
  11.231      while ( rb != NULL )
  11.232      {
  11.233          vbd = rb_entry(rb, vbd_t, rb);
  11.234 -        if ( shrink->vdevice < vbd->vdevice )
  11.235 +        if ( vdevice < vbd->vdevice )
  11.236              rb = rb->rb_left;
  11.237 -        else if ( shrink->vdevice > vbd->vdevice )
  11.238 +        else if ( vdevice > vbd->vdevice )
  11.239              rb = rb->rb_right;
  11.240          else
  11.241              break;
  11.242      }
  11.243  
  11.244 -    if ( unlikely(vbd == NULL) || 
  11.245 -         unlikely(vbd->vdevice != shrink->vdevice) ||
  11.246 -         unlikely(vbd->extents == NULL) )
  11.247 +    if ( unlikely(vbd == NULL) || unlikely(vbd->vdevice != vdevice) )
  11.248      {
  11.249 -        DPRINTK("vbd_shrink: attempt to remove non-existent extent.\n"); 
  11.250 -        ret = -EINVAL;
  11.251 +        shrink->status = BLKIF_STATUS_VBD_NOT_FOUND;
  11.252 +        goto out;
  11.253 +    }
  11.254 +
  11.255 +    if ( unlikely(vbd->extents == NULL) )
  11.256 +    {
  11.257 +        shrink->status = BLKIF_STATUS_EXTENT_NOT_FOUND;
  11.258          goto out;
  11.259      }
  11.260  
  11.261 @@ -211,147 +185,50 @@ long vbd_shrink(vbd_shrink_t *shrink)
  11.262      *px = x->next;
  11.263      kfree(x);
  11.264  
  11.265 +    shrink->status = BLKIF_STATUS_OKAY;
  11.266 +
  11.267   out:
  11.268 -    spin_unlock(&p->vbd_lock);
  11.269 -    put_task_struct(p);
  11.270 -    return ret; 
  11.271 +    spin_unlock(&blkif->vbd_lock);
  11.272 +    blkif_put(blkif);
  11.273  }
  11.274  
  11.275  
  11.276 -long vbd_setextents(vbd_setextents_t *setextents)
  11.277 +void vbd_destroy(blkif_vbd_destroy_t *destroy) 
  11.278  {
  11.279 -    struct task_struct *p; 
  11.280 -    xen_extent_t e;
  11.281 -    xen_extent_le_t *new_extents, *x, *t; 
  11.282 -    vbd_t *vbd = NULL;
  11.283 -    rb_node_t *rb;
  11.284 -    int i;
  11.285 -    long ret = 0;
  11.286 +    blkif_t         *blkif;
  11.287 +    vbd_t           *vbd;
  11.288 +    rb_node_t       *rb;
  11.289 +    xen_extent_le_t *x, *t;
  11.290 +    blkif_vdev_t     vdevice = destroy->vdevice;
  11.291  
  11.292 -    if ( !IS_PRIV(current) )
  11.293 -        return -EPERM; 
  11.294 -
  11.295 -    if ( (p = find_domain_by_id(setextents->domain)) == NULL )
  11.296 +    blkif = blkif_find_by_handle(destroy->domid, destroy->blkif_handle);
  11.297 +    if ( unlikely(blkif == NULL) )
  11.298      {
  11.299 -        DPRINTK("vbd_setextents attempted for non-existent domain %llu\n", 
  11.300 -                setextents->domain); 
  11.301 -        return -EINVAL; 
  11.302 +        DPRINTK("vbd_destroy attempted for non-existent blkif (%llu,&u)\n", 
  11.303 +                destroy->domid, destroy->blkif_handle); 
  11.304 +        destroy->status = BLKIF_STATUS_INTERFACE_NOT_FOUND;
  11.305 +        return;
  11.306      }
  11.307  
  11.308 -    spin_lock(&p->vbd_lock);
  11.309 +    spin_lock(&blkif->vbd_lock);
  11.310  
  11.311 -    rb = p->vbd_rb.rb_node;
  11.312 +    rb = blkif->vbd_rb.rb_node;
  11.313      while ( rb != NULL )
  11.314      {
  11.315          vbd = rb_entry(rb, vbd_t, rb);
  11.316 -        if ( setextents->vdevice < vbd->vdevice )
  11.317 +        if ( vdevice < vbd->vdevice )
  11.318              rb = rb->rb_left;
  11.319 -        else if ( setextents->vdevice > vbd->vdevice )
  11.320 -            rb = rb->rb_right;
  11.321 -        else
  11.322 -            break;
  11.323 -    }
  11.324 -
  11.325 -    if ( unlikely(vbd == NULL) || 
  11.326 -         unlikely(vbd->vdevice != setextents->vdevice) )
  11.327 -    {
  11.328 -        DPRINTK("vbd_setextents: attempt to modify non-existent VBD.\n"); 
  11.329 -        ret = -EINVAL;
  11.330 -        goto out;
  11.331 -    }
  11.332 -
  11.333 -    /* Construct the new extent list. */
  11.334 -    new_extents = NULL;
  11.335 -    for ( i = setextents->nr_extents - 1; i >= 0; i-- )
  11.336 -    {
  11.337 -        if ( unlikely(copy_from_user(&e, 
  11.338 -                                     &setextents->extents[i], 
  11.339 -                                     sizeof(e)) != 0) )
  11.340 -        {
  11.341 -            DPRINTK("vbd_setextents: copy_from_user failed\n");
  11.342 -            ret = -EFAULT;
  11.343 -            goto free_and_out;
  11.344 -        }
  11.345 -        
  11.346 -        if ( unlikely((x = kmalloc(sizeof(xen_extent_le_t), GFP_KERNEL))
  11.347 -                      == NULL) )
  11.348 -        {
  11.349 -            DPRINTK("vbd_setextents: out of memory\n");
  11.350 -            ret = -ENOMEM;
  11.351 -            goto free_and_out;
  11.352 -        }
  11.353 -        
  11.354 -        x->extent = e;
  11.355 -        x->next   = new_extents;
  11.356 -
  11.357 -        new_extents = x;
  11.358 -    }
  11.359 -
  11.360 -    /* Delete the old extent list _after_ successfully creating the new. */
  11.361 -    for ( x = vbd->extents; x != NULL; x = t )
  11.362 -    {
  11.363 -        t = x->next;
  11.364 -        kfree(x);
  11.365 -    }
  11.366 -
  11.367 -    /* Make the new list visible. */
  11.368 -    vbd->extents = new_extents;
  11.369 -
  11.370 - out:
  11.371 -    spin_unlock(&p->vbd_lock);
  11.372 -    put_task_struct(p);
  11.373 -    return ret;
  11.374 -
  11.375 - free_and_out:
  11.376 -    /* Failed part-way through the new list. Delete all that we managed. */
  11.377 -    for ( x = new_extents; x != NULL; x = t )
  11.378 -    {
  11.379 -        t = x->next;
  11.380 -        kfree(x);
  11.381 -    }
  11.382 -    goto out;
  11.383 -}
  11.384 -
  11.385 -
  11.386 -long vbd_delete(vbd_delete_t *delete) 
  11.387 -{
  11.388 -    struct task_struct *p; 
  11.389 -    vbd_t *vbd;
  11.390 -    rb_node_t *rb;
  11.391 -    xen_extent_le_t *x, *t;
  11.392 -
  11.393 -    if( !IS_PRIV(current) )
  11.394 -        return -EPERM; 
  11.395 -
  11.396 -    if ( (p = find_domain_by_id(delete->domain)) == NULL )
  11.397 -    {
  11.398 -        DPRINTK("vbd_delete attempted for non-existent domain %llu\n", 
  11.399 -                delete->domain); 
  11.400 -        return -EINVAL; 
  11.401 -    }
  11.402 -
  11.403 -    spin_lock(&p->vbd_lock);
  11.404 -
  11.405 -    rb = p->vbd_rb.rb_node;
  11.406 -    while ( rb != NULL )
  11.407 -    {
  11.408 -        vbd = rb_entry(rb, vbd_t, rb);
  11.409 -        if ( delete->vdevice < vbd->vdevice )
  11.410 -            rb = rb->rb_left;
  11.411 -        else if ( delete->vdevice > vbd->vdevice )
  11.412 +        else if ( vdevice > vbd->vdevice )
  11.413              rb = rb->rb_right;
  11.414          else
  11.415              goto found;
  11.416      }
  11.417  
  11.418 -    DPRINTK("vbd_delete attempted for non-existing VBD.\n");
  11.419 -
  11.420 -    spin_unlock(&p->vbd_lock);
  11.421 -    put_task_struct(p);
  11.422 -    return -EINVAL;
  11.423 +    destroy->status = BLKIF_STATUS_VBD_NOT_FOUND;
  11.424 +    goto out;
  11.425  
  11.426   found:
  11.427 -    rb_erase(rb, &p->vbd_rb);
  11.428 +    rb_erase(rb, &blkif->vbd_rb);
  11.429      x = vbd->extents;
  11.430      kfree(vbd);
  11.431  
  11.432 @@ -362,25 +239,25 @@ long vbd_delete(vbd_delete_t *delete)
  11.433          x = t;
  11.434      }
  11.435      
  11.436 -    spin_unlock(&p->vbd_lock);
  11.437 -    put_task_struct(p);
  11.438 -    return 0;
  11.439 + out:
  11.440 +    spin_unlock(&blkif->vbd_lock);
  11.441 +    blkif_put(blkif);
  11.442  }
  11.443  
  11.444  
  11.445 -void destroy_all_vbds(struct task_struct *p)
  11.446 +void destroy_all_vbds(blkif_t *blkif)
  11.447  {
  11.448      vbd_t *vbd;
  11.449      rb_node_t *rb;
  11.450      xen_extent_le_t *x, *t;
  11.451  
  11.452 -    spin_lock(&p->vbd_lock);
  11.453 +    spin_lock(&blkif->vbd_lock);
  11.454  
  11.455 -    while ( (rb = p->vbd_rb.rb_node) != NULL )
  11.456 +    while ( (rb = blkif->vbd_rb.rb_node) != NULL )
  11.457      {
  11.458          vbd = rb_entry(rb, vbd_t, rb);
  11.459  
  11.460 -        rb_erase(rb, &p->vbd_rb);
  11.461 +        rb_erase(rb, &blkif->vbd_rb);
  11.462          x = vbd->extents;
  11.463          kfree(vbd);
  11.464          
  11.465 @@ -392,7 +269,7 @@ void destroy_all_vbds(struct task_struct
  11.466          }          
  11.467      }
  11.468  
  11.469 -    spin_unlock(&p->vbd_lock);
  11.470 +    spin_unlock(&blkif->vbd_lock);
  11.471  }
  11.472  
  11.473  
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/xenolinux-2.4.26-sparse/arch/xen/drivers/vblkif/vblkif.h	Thu Apr 22 18:19:50 2004 +0000
    12.3 @@ -0,0 +1,109 @@
    12.4 +/******************************************************************************
    12.5 + * vblkif.h
    12.6 + * 
    12.7 + * Unified block-device I/O interface for Xen guest OSes.
    12.8 + * 
    12.9 + * Copyright (c) 2003-2004, Keir Fraser
   12.10 + */
   12.11 +
   12.12 +#ifndef __SHARED_VBLKIF_H__
   12.13 +#define __SHARED_VBLKIF_H__
   12.14 +
   12.15 +#define blkif_vdev_t   u16
   12.16 +#define blkif_sector_t u64
   12.17 +
   12.18 +#define BLKIF_OP_READ      0
   12.19 +#define BLKIF_OP_WRITE     1
   12.20 +#define BLKIF_OP_PROBE     2
   12.21 +
   12.22 +/* NB. Ring size must be small enough for sizeof(blk_ring_t) <= PAGE_SIZE. */
   12.23 +#define BLKIF_RING_SIZE        64
   12.24 +
   12.25 +/*
   12.26 + * Maximum scatter/gather segments per request.
   12.27 + * This is carefully chosen so that sizeof(blk_ring_t) <= PAGE_SIZE.
   12.28 + * NB. This could be 12 if the ring indexes weren't stored in the same page.
   12.29 + */
   12.30 +#define BLKIF_REQUEST_MAX_SEGMENTS 11
   12.31 +
   12.32 +typedef struct {
   12.33 +    unsigned char  operation;        /* BLKIF_OP_???                         */
   12.34 +    unsigned char  nr_segments;      /* number of segments (<= MAX_BLK_SEGS) */
   12.35 +    blkif_vdev_t   device;           /* only for read/write requests         */
   12.36 +    unsigned long  id;               /* private guest value, echoed in resp  */
   12.37 +    xen_sector_t   sector_number;    /* start sector idx on disk (r/w only)  */
   12.38 +    /* Least 9 bits is 'nr_sects'. High 23 bits is the address.      */
   12.39 +    unsigned long  buffer_and_sects[MAX_BLK_SEGS];
   12.40 +} blkif_request_t;
   12.41 +
   12.42 +typedef struct {
   12.43 +    unsigned long   id;              /* copied from request */
   12.44 +    unsigned char   operation;       /* copied from request */
   12.45 +    int             status;          /* BLKIF_RSP_???       */
   12.46 +} blkif_response_t;
   12.47 +
   12.48 +#define BLKIF_RSP_ERROR  -1 /* non-specific 'error' */
   12.49 +#define BLKIF_RSP_OKAY    0 /* non-specific 'okay'  */
   12.50 +
   12.51 +/*
   12.52 + * We use a special capitalised type name because it is _essential_ that all 
   12.53 + * arithmetic on indexes is done on an integer type of the correct size.
   12.54 + */
   12.55 +typedef unsigned int BLKIF_RING_IDX;
   12.56 +
   12.57 +/*
   12.58 + * Ring indexes are 'free running'. That is, they are not stored modulo the
   12.59 + * size of the ring buffer. The following macro converts a free-running counter
   12.60 + * into a value that can directly index a ring-buffer array.
   12.61 + */
   12.62 +#define MASK_BLKIF_IDX(_i) ((_i)&(BLKIF_RING_SIZE-1))
   12.63 +
   12.64 +typedef struct {
   12.65 +    BLKIF_RING_IDX req_prod;  /* Request producer. Updated by guest OS. */
   12.66 +    BLKIF_RING_IDX resp_prod; /* Response producer. Updated by Xen.     */
   12.67 +    union {
   12.68 +        blkif_request_t  req;
   12.69 +        blkif_response_t resp;
   12.70 +    } ring[BLKIF_RING_SIZE];
   12.71 +} blkif_ring_t;
   12.72 +
   12.73 +
   12.74 +/*
   12.75 + * BLKIF_OP_PROBE:
   12.76 + * The request format for a probe request is constrained as follows:
   12.77 + *  @operation   == BLKIF_OP_PROBE
   12.78 + *  @nr_segments == size of probe buffer in pages
   12.79 + *  @device      == unused (zero)
   12.80 + *  @id          == any value (echoed in response message)
   12.81 + *  @sector_num  == unused (zero)
   12.82 + *  @buffer_and_sects == list of page-aligned, page-sized buffers.
   12.83 + *                       (i.e., nr_sects == 8).
   12.84 + * 
   12.85 + * The response is a list of vdisk_t elements copied into the out-of-band
   12.86 + * probe buffer. On success the response status field contains the number
   12.87 + * of vdisk_t elements.
   12.88 + */
   12.89 +
   12.90 +/* XXX SMH: Type values below are chosen to match ide_xxx in Linux ide.h. */
   12.91 +#define VDISK_TYPE_FLOPPY  0x00
   12.92 +#define VDISK_TYPE_TAPE    0x01
   12.93 +#define VDISK_TYPE_CDROM   0x05
   12.94 +#define VDISK_TYPE_OPTICAL 0x07
   12.95 +#define VDISK_TYPE_DISK    0x20 
   12.96 +
   12.97 +#define VDISK_TYPE_MASK    0x3F
   12.98 +#define VDISK_TYPE(_x)     ((_x) & VDISK_TYPE_MASK) 
   12.99 +
  12.100 +/* The top two bits of the type field encode various flags. */
  12.101 +#define VDISK_FLAG_RO      0x40
  12.102 +#define VDISK_FLAG_VIRT    0x80
  12.103 +#define VDISK_READONLY(_x) ((_x) & VDISK_FLAG_RO)
  12.104 +#define VDISK_VIRTUAL(_x)  ((_x) & VDISK_FLAG_VIRT) 
  12.105 +
  12.106 +typedef struct {
  12.107 +    blkif_vdev_t   device;       /* Device number (opaque 16 bit value). */
  12.108 +    unsigned short info;         /* Device type and flags (VDISK_*).     */
  12.109 +    xen_sector_t   capacity;     /* Size in terms of 512-byte sectors.   */
  12.110 +} vdisk_t;
  12.111 +
  12.112 +#endif /* __SHARED_VBLKIF_H__ */