ia64/xen-unstable

changeset 5319:0078804371c0

bitkeeper revision 1.1665.1.6 (42a1b3f6-O_jFlmQorlf72427fTfmw)

bug fixes to tap and parallax.

Signed-off-by: andrew.warfield@cl.cam.ac.uk
author akw27@arcadians.cl.cam.ac.uk
date Sat Jun 04 14:00:22 2005 +0000 (2005-06-04)
parents 0b862197be40
children 58a236cc6900
files linux-2.6.11-xen-sparse/drivers/xen/blktap/blktap_controlmsg.c linux-2.6.11-xen-sparse/drivers/xen/blktap/blktap_datapath.c tools/blktap/blktaplib.c tools/blktap/parallax.c tools/blktap/radix.c tools/blktap/vdi.c tools/blktap/vdi.h
line diff
     1.1 --- a/linux-2.6.11-xen-sparse/drivers/xen/blktap/blktap_controlmsg.c	Sat Jun 04 13:07:05 2005 +0000
     1.2 +++ b/linux-2.6.11-xen-sparse/drivers/xen/blktap/blktap_controlmsg.c	Sat Jun 04 14:00:22 2005 +0000
     1.3 @@ -443,6 +443,7 @@ void blkif_ctrlif_rx(ctrl_msg_t *msg, un
     1.4               (blktap_mode & BLKTAP_MODE_COPY_FE) ) {
     1.5              
     1.6              blktap_write_ctrl_ring(msg);
     1.7 +            blktap_kick_user();
     1.8          }
     1.9          
    1.10          switch ( msg->subtype )
     2.1 --- a/linux-2.6.11-xen-sparse/drivers/xen/blktap/blktap_datapath.c	Sat Jun 04 13:07:05 2005 +0000
     2.2 +++ b/linux-2.6.11-xen-sparse/drivers/xen/blktap/blktap_datapath.c	Sat Jun 04 14:00:22 2005 +0000
     2.3 @@ -82,6 +82,8 @@ static inline unsigned long MAKE_ID(domi
     2.4  
     2.5  /*-----[ Ring helpers ]---------------------------------------------------*/
     2.6  
     2.7 +static void maybe_trigger_blktap_schedule(void);
     2.8 +
     2.9  inline int write_resp_to_fe_ring(blkif_t *blkif, blkif_response_t *rsp)
    2.10  {
    2.11      blkif_response_t *resp_d;
    2.12 @@ -125,6 +127,9 @@ void kick_fe_domain(blkif_t *blkif)
    2.13      RING_PUSH_RESPONSES(&blkif->blk_ring);
    2.14      notify_via_evtchn(blkif->evtchn);
    2.15      DPRINTK("notified FE(dom %u)\n", blkif->domid);
    2.16 +
    2.17 +    /* We just feed up a batch of request slots... */
    2.18 +    maybe_trigger_blktap_schedule();
    2.19      
    2.20  }
    2.21  
    2.22 @@ -219,15 +224,10 @@ static int blkio_schedule(void *arg)
    2.23                  add_to_blkdev_list_tail(blkif);
    2.24              blkif_put(blkif);
    2.25          }
    2.26 -
    2.27 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    2.28 -        /* Push the batch through to disc. */
    2.29 -        run_task_queue(&tq_disk);
    2.30 -#endif
    2.31      }
    2.32  }
    2.33  
    2.34 -static void maybe_trigger_blkio_schedule(void)
    2.35 +static void maybe_trigger_blktap_schedule(void)
    2.36  {
    2.37      /*
    2.38       * Needed so that two processes, who together make the following predicate
    2.39 @@ -236,7 +236,7 @@ static void maybe_trigger_blkio_schedule
    2.40       */
    2.41      smp_mb();
    2.42  
    2.43 -    if ( (NR_ACTIVE_REQS < (MAX_ACTIVE_REQS)) && /* XXX!!! was M_A_R/2*/
    2.44 +    if ( (NR_ACTIVE_REQS < (MAX_ACTIVE_REQS/2)) &&
    2.45           !list_empty(&blkio_schedule_list) ) 
    2.46          wake_up(&blkio_schedule_wait);
    2.47  }
    2.48 @@ -262,7 +262,7 @@ irqreturn_t blkif_ptfe_int(int irq, void
    2.49      blkif_t *blkif = dev_id;
    2.50  
    2.51      add_to_blkdev_list_tail(blkif);
    2.52 -    maybe_trigger_blkio_schedule();
    2.53 +    maybe_trigger_blktap_schedule();
    2.54      return IRQ_HANDLED;
    2.55  }
    2.56  
    2.57 @@ -280,8 +280,6 @@ static int do_block_io_op(blkif_t *blkif
    2.58      int more_to_do = 0;
    2.59      int notify_be = 0, notify_user = 0;
    2.60      
    2.61 -    DPRINTK("PT got FE interrupt.\n");
    2.62 -
    2.63      if (NR_ACTIVE_REQS == MAX_ACTIVE_REQS) return 1;
    2.64      
    2.65      /* lock both rings */
     3.1 --- a/tools/blktap/blktaplib.c	Sat Jun 04 13:07:05 2005 +0000
     3.2 +++ b/tools/blktap/blktaplib.c	Sat Jun 04 14:00:22 2005 +0000
     3.3 @@ -34,7 +34,7 @@
     3.4  #else
     3.5  #define DPRINTF(_f, _a...) ((void)0)
     3.6  #endif
     3.7 -#define DEBUG_RING_IDXS 1
     3.8 +#define DEBUG_RING_IDXS 0
     3.9  
    3.10  #define POLLRDNORM     0x040 
    3.11  
    3.12 @@ -171,27 +171,27 @@ void print_hooks(void)
    3.13      response_hook_t *rsp_hook;
    3.14      ctrl_hook_t     *ctrl_hook;
    3.15      
    3.16 -    printf("Control Hooks:\n");
    3.17 +    DPRINTF("Control Hooks:\n");
    3.18      ctrl_hook = ctrl_hook_chain;
    3.19      while (ctrl_hook != NULL)
    3.20      {
    3.21 -        printf("  [0x%p] %s\n", ctrl_hook->func, ctrl_hook->name);
    3.22 +        DPRINTF("  [0x%p] %s\n", ctrl_hook->func, ctrl_hook->name);
    3.23          ctrl_hook = ctrl_hook->next;
    3.24      }
    3.25      
    3.26 -    printf("Request Hooks:\n");
    3.27 +    DPRINTF("Request Hooks:\n");
    3.28      req_hook = request_hook_chain;
    3.29      while (req_hook != NULL)
    3.30      {
    3.31 -        printf("  [0x%p] %s\n", req_hook->func, req_hook->name);
    3.32 +        DPRINTF("  [0x%p] %s\n", req_hook->func, req_hook->name);
    3.33          req_hook = req_hook->next;
    3.34      }
    3.35      
    3.36 -    printf("Response Hooks:\n");
    3.37 +    DPRINTF("Response Hooks:\n");
    3.38      rsp_hook = response_hook_chain;
    3.39      while (rsp_hook != NULL)
    3.40      {
    3.41 -        printf("  [0x%p] %s\n", rsp_hook->func, rsp_hook->name);
    3.42 +        DPRINTF("  [0x%p] %s\n", rsp_hook->func, rsp_hook->name);
    3.43          rsp_hook = rsp_hook->next;
    3.44      }
    3.45  }
    3.46 @@ -300,7 +300,7 @@ int blktap_attach_poll(int fd, short eve
    3.47      ph->events      = events;
    3.48      ph->active      = 1;
    3.49      
    3.50 -    printf("Added fd %d at ph index %d, now %d phs.\n", fd, ph_cons-1, 
    3.51 +    DPRINTF("Added fd %d at ph index %d, now %d phs.\n", fd, ph_cons-1, 
    3.52              nr_pollhooks());
    3.53      
    3.54      return 0;
    3.55 @@ -318,7 +318,7 @@ void blktap_detach_poll(int fd)
    3.56              break;
    3.57          }
    3.58          
    3.59 -    printf("Removed fd %d at ph index %d, now %d phs.\n", fd, i, 
    3.60 +    DPRINTF("Removed fd %d at ph index %d, now %d phs.\n", fd, i, 
    3.61              nr_pollhooks());
    3.62  }
    3.63  
    3.64 @@ -337,7 +337,6 @@ void pollhook_init(void)
    3.65  
    3.66  void __attribute__ ((constructor)) blktaplib_init(void)
    3.67  {
    3.68 -    printf("[[ C O N S T R U C T O R ]]\n");
    3.69      pollhook_init();
    3.70  }
    3.71  
    3.72 @@ -385,7 +384,7 @@ int blktap_listen(void)
    3.73  
    3.74      /* assign the rings to the mapped memory */
    3.75      csring = (ctrl_sring_t *)blktap_mem;
    3.76 -    BACK_RING_INIT(&ctrl_ring, csring, CONTROL_RING_MEM);
    3.77 +    BACK_RING_INIT(&ctrl_ring, csring, PAGE_SIZE);
    3.78      
    3.79      sring = (blkif_sring_t *)((unsigned long)blktap_mem + PAGE_SIZE);
    3.80      FRONT_RING_INIT(&be_ring, sring, PAGE_SIZE);
    3.81 @@ -393,10 +392,7 @@ int blktap_listen(void)
    3.82      sring = (blkif_sring_t *)((unsigned long)blktap_mem + (2 *PAGE_SIZE));
    3.83      BACK_RING_INIT(&fe_ring, sring, PAGE_SIZE);
    3.84  
    3.85 -    mmap_vstart = (unsigned long)blktap_mem + (BLKTAP_RING_PAGES << PAGE_SHIFT);
    3.86 -    
    3.87 -    printf("fe_ring mapped at: %p\n", fe_ring.sring);
    3.88 -    printf("be_ring mapped at: %p\n", be_ring.sring);
    3.89 +    mmap_vstart = (unsigned long)blktap_mem +(BLKTAP_RING_PAGES << PAGE_SHIFT);
    3.90  
    3.91      ioctl(fd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE );
    3.92  
    3.93 @@ -560,7 +556,9 @@ void got_sig_bus() {
    3.94  }
    3.95  
    3.96  void got_sig_int() {
    3.97 -    printf("quitting -- returning to passthrough mode.\n");
    3.98 +    DPRINTF("quitting -- returning to passthrough mode.\n");
    3.99      if (fd > 0) ioctl(fd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_PASSTHROUGH );
   3.100 +    close(fd);
   3.101 +    fd = 0;
   3.102      exit(0);
   3.103  } 
     4.1 --- a/tools/blktap/parallax.c	Sat Jun 04 13:07:05 2005 +0000
     4.2 +++ b/tools/blktap/parallax.c	Sat Jun 04 14:00:22 2005 +0000
     4.3 @@ -88,17 +88,14 @@ void blkif_create(blkif_be_create_t *cre
     4.4      blkif->domid  = domid;
     4.5      blkif->handle = handle;
     4.6      blkif->status = DISCONNECTED;
     4.7 -/*
     4.8 -    spin_lock_init(&blkif->vbd_lock);
     4.9 -    spin_lock_init(&blkif->blk_ring_lock);
    4.10 -    atomic_set(&blkif->refcnt, 0);
    4.11 -*/
    4.12 +
    4.13      pblkif = &blkif_hash[BLKIF_HASH(domid, handle)];
    4.14      while ( *pblkif != NULL )
    4.15      {
    4.16          if ( ((*pblkif)->domid == domid) && ((*pblkif)->handle == handle) )
    4.17          {
    4.18 -            DPRINTF("Could not create blkif: already exists\n");
    4.19 +            DPRINTF("Could not create blkif: already exists (%d,%d)\n",
    4.20 +                domid, handle);
    4.21              create->status = BLKIF_BE_STATUS_INTERFACE_EXISTS;
    4.22              free(blkif);
    4.23              return;
    4.24 @@ -142,7 +139,6 @@ void blkif_destroy(blkif_be_destroy_t *d
    4.25  
    4.26   destroy:
    4.27      *pblkif = blkif->hash_next;
    4.28 -    /* destroy_all_vbds(blkif); */
    4.29      free(blkif);
    4.30      destroy->status = BLKIF_BE_STATUS_OKAY;
    4.31  }
    4.32 @@ -184,10 +180,38 @@ void vbd_create(blkif_be_vbd_create_t *c
    4.33          vdip = &(*vdip)->next;
    4.34      *vdip = vdi;
    4.35      
    4.36 -    DPRINTF("vbd_grow: happy return!\n"); 
    4.37 +    DPRINTF("blkif_create succeeded\n"); 
    4.38      create->status = BLKIF_BE_STATUS_OKAY;
    4.39  }
    4.40  
    4.41 +void vbd_destroy(blkif_be_vbd_destroy_t *destroy)
    4.42 +{
    4.43 +    blkif_t            *blkif;
    4.44 +    vdi_t              *vdi, **vdip;
    4.45 +    blkif_vdev_t        vdevice = destroy->vdevice;
    4.46 +    
    4.47 +    blkif = blkif_find_by_handle(destroy->domid, destroy->blkif_handle);
    4.48 +    if ( blkif == NULL )
    4.49 +    {
    4.50 +        DPRINTF("vbd_destroy attempted for non-existent blkif (%u,%u)\n", 
    4.51 +                destroy->domid, destroy->blkif_handle); 
    4.52 +        destroy->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND;
    4.53 +        return;
    4.54 +    }
    4.55 +
    4.56 +    vdip = &blkif->vdi_hash[VDI_HASH(vdevice)];
    4.57 +    while ((*vdip != NULL) && ((*vdip)->vdevice != vdevice))
    4.58 +        vdip = &(*vdip)->next;
    4.59 +
    4.60 +    if (*vdip != NULL) 
    4.61 +    {
    4.62 +        vdi = *vdip;
    4.63 +        *vdip = vdi->next;
    4.64 +        vdi_put(vdi);
    4.65 +    }
    4.66 +        
    4.67 +}
    4.68 +
    4.69  int parallax_control(control_msg_t *msg)
    4.70  {
    4.71      domid_t  domid;
    4.72 @@ -220,6 +244,20 @@ int parallax_control(control_msg_t *msg)
    4.73              goto parse_error;
    4.74          vbd_create((blkif_be_vbd_create_t *)msg->msg);
    4.75          break;
    4.76 +        
    4.77 +    case CMSG_BLKIF_BE_VBD_DESTROY:
    4.78 +        if ( msg->length != sizeof(blkif_be_vbd_destroy_t) )
    4.79 +            goto parse_error;
    4.80 +        vbd_destroy((blkif_be_vbd_destroy_t *)msg->msg);
    4.81 +        break;
    4.82 +
    4.83 +    case CMSG_BLKIF_BE_CONNECT:
    4.84 +    case CMSG_BLKIF_BE_DISCONNECT:
    4.85 +        /* we don't manage the device channel, the tap does. */
    4.86 +        break;
    4.87 +
    4.88 +    default:
    4.89 +        goto parse_error;
    4.90      }
    4.91      return 0;
    4.92  parse_error:
    4.93 @@ -480,7 +518,7 @@ int parallax_write(blkif_request_t *req,
    4.94                  sector, blkif_first_sect(req->frame_and_sects[i]),
    4.95                  blkif_last_sect (req->frame_and_sects[i]),
    4.96                  vblock, gblock, size); 
    4.97 -        
    4.98 +      
    4.99          /* XXX: For now we just freak out if they try to write a   */
   4.100          /* non block-sized, block-aligned page.                    */
   4.101          
   4.102 @@ -516,8 +554,6 @@ int parallax_request(blkif_request_t *re
   4.103      blkif_response_t *rsp;
   4.104      domid_t  dom   = ID_TO_DOM(req->id);
   4.105      blkif_t *blkif = blkif_find_by_handle(dom, 0);
   4.106 -
   4.107 -    //DPRINTF("parallax_request: req=%p, dom=%d, blkif=%p\n", req, dom, blkif); 
   4.108      
   4.109      if (blkif == NULL)
   4.110          goto err;
   4.111 @@ -535,14 +571,15 @@ int parallax_request(blkif_request_t *re
   4.112          return parallax_write(req, blkif);
   4.113          
   4.114      } else {
   4.115 +        printf("Unknown request message type!\n");
   4.116          /* Unknown operation */
   4.117          goto err;
   4.118      }
   4.119      
   4.120  err:
   4.121      rsp = (blkif_response_t *)req;
   4.122 +    rsp->operation = req->operation;
   4.123      rsp->id = req->id;
   4.124 -    rsp->operation = req->operation;
   4.125      rsp->status = BLKIF_RSP_ERROR;
   4.126      return BLKTAP_RESPOND;  
   4.127  }
     5.1 --- a/tools/blktap/radix.c	Sat Jun 04 13:07:05 2005 +0000
     5.2 +++ b/tools/blktap/radix.c	Sat Jun 04 14:00:22 2005 +0000
     5.3 @@ -49,7 +49,6 @@ rcache_t *rcache[RCHASH_SIZE];
     5.4  void __rcache_init(void)
     5.5  {
     5.6      int i;
     5.7 -printf("rcache_init!\n");
     5.8  
     5.9      for (i=0; i<RCHASH_SIZE; i++)
    5.10          rcache[i] = NULL;
     6.1 --- a/tools/blktap/vdi.c	Sat Jun 04 13:07:05 2005 +0000
     6.2 +++ b/tools/blktap/vdi.c	Sat Jun 04 14:00:22 2005 +0000
     6.3 @@ -128,6 +128,9 @@ vdi_t *vdi_create(snap_id_t *parent_snap
     6.4      return vdi;
     6.5  }
     6.6  
     6.7 +/* vdi_get and vdi_put currently act more like alloc/free -- they don't 
     6.8 + * do refcount-based allocation.  
     6.9 + */
    6.10  vdi_t *vdi_get(u64 vdi_id)
    6.11  {
    6.12      u64 vdi_blk;
    6.13 @@ -152,6 +155,12 @@ vdi_t *vdi_get(u64 vdi_id)
    6.14      return vdi;
    6.15  }
    6.16  
    6.17 +void vdi_put(vdi_t *vdi)
    6.18 +{
    6.19 +    free(vdi->radix_lock);
    6.20 +    freeblock(vdi);
    6.21 +}
    6.22 +
    6.23  u64 vdi_lookup_block(vdi_t *vdi, u64 vdi_block, int *writable)
    6.24  {
    6.25      u64 gblock;
     7.1 --- a/tools/blktap/vdi.h	Sat Jun 04 13:07:05 2005 +0000
     7.2 +++ b/tools/blktap/vdi.h	Sat Jun 04 14:00:22 2005 +0000
     7.3 @@ -27,7 +27,7 @@ typedef struct vdi {
     7.4      snap_id_t   snap;             /* next snapshot slot for this VDI         */
     7.5      struct vdi *next;             /* used to hash-chain in blkif.            */
     7.6      blkif_vdev_t vdevice;         /* currently mounted as...                 */
     7.7 -    struct radix_lock *radix_lock;/* per-line L1 RW lock for parallel reqs   */ 
     7.8 +    struct radix_lock *radix_lock;/* per-line L1 RW lock for parallel reqs   */
     7.9      char        name[VDI_NAME_SZ];/* human readable vdi name                 */
    7.10  } vdi_t;
    7.11  
    7.12 @@ -42,6 +42,7 @@ typedef struct vdi_registry {
    7.13  int __init_vdi(void);
    7.14  
    7.15  vdi_t *vdi_get(u64 vdi_id);
    7.16 +void vdi_put(vdi_t *vdi);
    7.17  vdi_registry_t *get_vdi_registry(void);
    7.18  vdi_t *vdi_create(snap_id_t *parent_snap, char *name);
    7.19  u64 vdi_lookup_block(vdi_t *vdi, u64 vdi_block, int *writable);