ia64/xen-unstable

diff extras/mini-os/blkfront.c @ 17042:a905c582a406

Add stubdomain support. See stubdom/README for usage details.

- Move PAGE_SIZE and STACK_SIZE into __PAGE_SIZE and __STACK_SIZE in
arch_limits.h so as to permit getting them from there without
pulling all the internal Mini-OS defines.
- Setup a xen-elf cross-compilation environment in stubdom/cross-root
- Add a POSIX layer on top of Mini-OS by linking against the newlib C
library and lwIP, and implementing the Unixish part in mini-os/lib/sys.c
- Cross-compile zlib and libpci too.
- Add an xs.h-compatible layer on top of Mini-OS' xenbus.
- Cross-compile libxc with an additional xc_minios.c and a few things
disabled.
- Cross-compile ioemu with an additional block-vbd, but without sound,
tpm and other details. A few hacks are needed:
- Align ide and scsi buffers at least on sector size to permit
direct transmission to the block backend. While we are at it, just
page-align it to possibly save a segment. Also, limit the scsi
buffer size because of limitations of the block paravirtualization
protocol.
- Allocate big tables dynamically rather that letting them go to
bss: when Mini-OS gets installed in memory, bss is not lazily
allocated, and doing so during Mini-OS is unnecessarily trick while
we can simply use malloc.
- Had to change the Mini-OS compilation somehow, so as to export
Mini-OS compilation flags to the Makefiles of libxc and ioemu.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Feb 12 14:35:39 2008 +0000 (2008-02-12)
parents 0672d5b11262
children c1003b9e0bb8
line diff
     1.1 --- a/extras/mini-os/blkfront.c	Tue Feb 12 11:37:45 2008 +0000
     1.2 +++ b/extras/mini-os/blkfront.c	Tue Feb 12 14:35:39 2008 +0000
     1.3 @@ -15,6 +15,10 @@
     1.4  #include <lib.h>
     1.5  #include <fcntl.h>
     1.6  
     1.7 +#ifndef HAVE_LIBC
     1.8 +#define strtoul simple_strtoul
     1.9 +#endif
    1.10 +
    1.11  /* Note: we generally don't need to disable IRQs since we hardly do anything in
    1.12   * the interrupt handler.  */
    1.13  
    1.14 @@ -49,6 +53,10 @@ struct blkfront_dev {
    1.15      int mode;
    1.16      int barrier;
    1.17      int flush;
    1.18 +
    1.19 +#ifdef HAVE_LIBC
    1.20 +    int fd;
    1.21 +#endif
    1.22  };
    1.23  
    1.24  static inline int xenblk_rxidx(RING_IDX idx)
    1.25 @@ -58,6 +66,12 @@ static inline int xenblk_rxidx(RING_IDX 
    1.26  
    1.27  void blkfront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
    1.28  {
    1.29 +#ifdef HAVE_LIBC
    1.30 +    struct blkfront_dev *dev = data;
    1.31 +    int fd = dev->fd;
    1.32 +
    1.33 +    files[fd].read = 1;
    1.34 +#endif
    1.35      wake_up(&blkfront_queue);
    1.36  }
    1.37  
    1.38 @@ -148,7 +162,7 @@ done:
    1.39  
    1.40      printk("backend at %s\n", dev->backend);
    1.41  
    1.42 -    dev->handle = simple_strtoul(strrchr(nodename, '/')+1, NULL, 0);
    1.43 +    dev->handle = strtoul(strrchr(nodename, '/')+1, NULL, 0);
    1.44  
    1.45      {
    1.46          char path[strlen(dev->backend) + 1 + 19 + 1];
    1.47 @@ -322,12 +336,16 @@ moretodo:
    1.48      {
    1.49  	rsp = RING_GET_RESPONSE(&dev->ring, cons);
    1.50  
    1.51 +        if (rsp->status != BLKIF_RSP_OKAY)
    1.52 +            printk("block error %d for op %d\n", rsp->status, rsp->operation);
    1.53 +
    1.54          switch (rsp->operation) {
    1.55          case BLKIF_OP_READ:
    1.56          case BLKIF_OP_WRITE:
    1.57          {
    1.58              struct blkfront_aiocb *aiocbp = (void*) (uintptr_t) rsp->id;
    1.59              int j;
    1.60 +
    1.61              for (j = 0; j < aiocbp->n; j++)
    1.62                  gnttab_end_access(aiocbp->gref[j]);
    1.63  
    1.64 @@ -365,6 +383,12 @@ static void blkfront_push_operation(stru
    1.65      i = dev->ring.req_prod_pvt;
    1.66      req = RING_GET_REQUEST(&dev->ring, i);
    1.67      req->operation = op;
    1.68 +    req->nr_segments = 0;
    1.69 +    req->handle = dev->handle;
    1.70 +    /* Not used */
    1.71 +    req->id = 0;
    1.72 +    /* Not needed anyway, but the backend will check it */
    1.73 +    req->sector_number = 0;
    1.74      dev->ring.req_prod_pvt = i + 1;
    1.75      wmb();
    1.76      RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&dev->ring, notify);
    1.77 @@ -375,11 +399,13 @@ void blkfront_sync(struct blkfront_dev *
    1.78  {
    1.79      unsigned long flags;
    1.80  
    1.81 -    if (dev->barrier == 1)
    1.82 -        blkfront_push_operation(dev, BLKIF_OP_WRITE_BARRIER);
    1.83 +    if (dev->mode == O_RDWR) {
    1.84 +        if (dev->barrier == 1)
    1.85 +            blkfront_push_operation(dev, BLKIF_OP_WRITE_BARRIER);
    1.86  
    1.87 -    if (dev->flush == 1)
    1.88 -        blkfront_push_operation(dev, BLKIF_OP_FLUSH_DISKCACHE);
    1.89 +        if (dev->flush == 1)
    1.90 +            blkfront_push_operation(dev, BLKIF_OP_FLUSH_DISKCACHE);
    1.91 +    }
    1.92  
    1.93      /* Note: This won't finish if another thread enqueues requests.  */
    1.94      local_irq_save(flags);
    1.95 @@ -397,3 +423,13 @@ void blkfront_sync(struct blkfront_dev *
    1.96      remove_waiter(w);
    1.97      local_irq_restore(flags);
    1.98  }
    1.99 +
   1.100 +#ifdef HAVE_LIBC
   1.101 +int blkfront_open(struct blkfront_dev *dev)
   1.102 +{
   1.103 +    dev->fd = alloc_fd(FTYPE_BLK);
   1.104 +    printk("blk_open(%s) -> %d\n", dev->nodename, dev->fd);
   1.105 +    files[dev->fd].blk.dev = dev;
   1.106 +    return dev->fd;
   1.107 +}
   1.108 +#endif