direct-io.hg

changeset 5674:287583627544

Attached is a patch that fully 'grant-table-ifies' the block front and
backends. It is necessary to do a make clean in the tools directory and
then rebuild the tree.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Jul 06 08:50:11 2005 +0000 (2005-07-06)
parents bc8cab407197
children 189c87adf876 b3a27d7ef999
files linux-2.6.11-xen-sparse/drivers/xen/blkback/common.h linux-2.6.11-xen-sparse/drivers/xen/blkback/interface.c linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c tools/python/xen/lowlevel/xu/xu.c tools/python/xen/xend/server/blkif.py xen/include/public/dom0_ops.h xen/include/public/io/domain_controller.h
line diff
     1.1 --- a/linux-2.6.11-xen-sparse/drivers/xen/blkback/common.h	Wed Jul 06 08:47:34 2005 +0000
     1.2 +++ b/linux-2.6.11-xen-sparse/drivers/xen/blkback/common.h	Wed Jul 06 08:50:11 2005 +0000
     1.3 @@ -65,6 +65,11 @@ typedef struct blkif_st {
     1.4      atomic_t         refcnt;
     1.5  
     1.6      struct work_struct work;
     1.7 +#ifdef CONFIG_XEN_BLKDEV_GRANT
     1.8 +    u16 shmem_handle;
     1.9 +    memory_t shmem_vaddr;
    1.10 +    grant_ref_t shmem_ref;
    1.11 +#endif
    1.12  } blkif_t;
    1.13  
    1.14  void blkif_create(blkif_be_create_t *create);
     2.1 --- a/linux-2.6.11-xen-sparse/drivers/xen/blkback/interface.c	Wed Jul 06 08:47:34 2005 +0000
     2.2 +++ b/linux-2.6.11-xen-sparse/drivers/xen/blkback/interface.c	Wed Jul 06 08:50:11 2005 +0000
     2.3 @@ -39,6 +39,23 @@ static void __blkif_disconnect_complete(
     2.4       * must still be notified to the remote driver.
     2.5       */
     2.6      unbind_evtchn_from_irq(blkif->evtchn);
     2.7 +
     2.8 +#ifdef CONFIG_XEN_BLKDEV_GRANT
     2.9 +    {
    2.10 +        /*
    2.11 +         * Release the shared memory page.
    2.12 +         */
    2.13 +        struct gnttab_unmap_grant_ref op;
    2.14 +
    2.15 +        op.host_virt_addr = blkif->shmem_vaddr;
    2.16 +        op.handle         = blkif->shmem_handle;
    2.17 +        op.dev_bus_addr   = 0;
    2.18 +
    2.19 +        if(unlikely(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))) {
    2.20 +            BUG();
    2.21 +        }
    2.22 +    }
    2.23 +#endif
    2.24      vfree(blkif->blk_ring.sring);
    2.25  
    2.26      /* Construct the deferred response message. */
    2.27 @@ -154,8 +171,12 @@ void blkif_connect(blkif_be_connect_t *c
    2.28      unsigned int   evtchn = connect->evtchn;
    2.29      unsigned long  shmem_frame = connect->shmem_frame;
    2.30      struct vm_struct *vma;
    2.31 +#ifdef CONFIG_XEN_BLKDEV_GRANT
    2.32 +    int ref = connect->shmem_ref;
    2.33 +#else
    2.34      pgprot_t       prot;
    2.35      int            error;
    2.36 +#endif
    2.37      blkif_t       *blkif;
    2.38      blkif_sring_t *sring;
    2.39  
    2.40 @@ -174,6 +195,7 @@ void blkif_connect(blkif_be_connect_t *c
    2.41          return;
    2.42      }
    2.43  
    2.44 +#ifndef CONFIG_XEN_BLKDEV_GRANT
    2.45      prot = __pgprot(_KERNPG_TABLE);
    2.46      error = direct_remap_area_pages(&init_mm, VMALLOC_VMADDR(vma->addr),
    2.47                                      shmem_frame<<PAGE_SHIFT, PAGE_SIZE,
    2.48 @@ -189,6 +211,36 @@ void blkif_connect(blkif_be_connect_t *c
    2.49          vfree(vma->addr);
    2.50          return;
    2.51      }
    2.52 +#else
    2.53 +    { /* Map: Use the Grant table reference */
    2.54 +        struct gnttab_map_grant_ref op;
    2.55 +        op.host_virt_addr = VMALLOC_VMADDR(vma->addr);
    2.56 +        op.flags          = GNTMAP_host_map;
    2.57 +        op.ref            = ref;
    2.58 +        op.dom            = domid;
    2.59 +       
    2.60 +        if(unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))) {
    2.61 +            BUG();
    2.62 +        }
    2.63 +       
    2.64 +        handle = op.handle;
    2.65 +       
    2.66 +        if (op.handle < 0) {
    2.67 +            DPRINTK(" Grant table operation failure !\n");
    2.68 +            connect->status = BLKIF_BE_STATUS_MAPPING_ERROR;
    2.69 +            vfree(vma->addr);
    2.70 +            return;
    2.71 +        }
    2.72 +
    2.73 +        phys_to_machine_mapping[__pa(VMALLOC_VMADDR(vma->addr)) >>
    2.74 +                                PAGE_SHIFT] =
    2.75 +                      FOREIGN_FRAME(shmem_frame);
    2.76 +
    2.77 +        blkif->shmem_ref = ref;
    2.78 +        blkif->shmem_handle = handle;
    2.79 +        blkif->shmem_vaddr = VMALLOC_VMADDR(vma->addr);
    2.80 +    }
    2.81 +#endif
    2.82  
    2.83      if ( blkif->status != DISCONNECTED )
    2.84      {
     3.1 --- a/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c	Wed Jul 06 08:47:34 2005 +0000
     3.2 +++ b/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c	Wed Jul 06 08:50:11 2005 +0000
     3.3 @@ -1136,6 +1136,12 @@ static void blkif_send_interface_connect
     3.4      msg->handle      = 0;
     3.5      msg->shmem_frame = (virt_to_machine(blk_ring.sring) >> PAGE_SHIFT);
     3.6      
     3.7 +#ifdef CONFIG_XEN_BLKDEV_GRANT
     3.8 +    msg->shmem_ref   = gnttab_claim_grant_reference( &gref_head, gref_terminal );
     3.9 +    ASSERT( msg->shmem_ref != -ENOSPC );
    3.10 +    gnttab_grant_foreign_access_ref ( msg->shmem_ref , rdomid, msg->shmem_frame, 0 );
    3.11 +#endif
    3.12 +
    3.13      ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
    3.14  }
    3.15  
    3.16 @@ -1261,9 +1267,6 @@ static void blkif_connect(blkif_fe_inter
    3.17  
    3.18      blkif_evtchn = status->evtchn;
    3.19      blkif_irq    = bind_evtchn_to_irq(blkif_evtchn);
    3.20 -#ifdef CONFIG_XEN_BLKDEV_GRANT
    3.21 -    rdomid       = status->domid;
    3.22 -#endif
    3.23  
    3.24      err = request_irq(blkif_irq, blkif_int, SA_SAMPLE_RANDOM, "blkif", NULL);
    3.25      if ( err )
    3.26 @@ -1300,6 +1303,10 @@ static void unexpected(blkif_fe_interfac
    3.27  
    3.28  static void blkif_status(blkif_fe_interface_status_t *status)
    3.29  {
    3.30 +#ifdef CONFIG_XEN_BLKDEV_GRANT
    3.31 +    rdomid       = status->domid; /* need to set rdomid early */
    3.32 +#endif
    3.33 +
    3.34      if ( status->handle != blkif_handle )
    3.35      {
    3.36          WPRINTK(" Invalid blkif: handle=%u\n", status->handle);
     4.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Wed Jul 06 08:47:34 2005 +0000
     4.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Wed Jul 06 08:50:11 2005 +0000
     4.3 @@ -594,6 +594,7 @@ static PyObject *xu_message_get_payload(
     4.4      case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_CONNECT):
     4.5          C2P(blkif_fe_interface_connect_t, handle,      Int, Long);
     4.6          C2P(blkif_fe_interface_connect_t, shmem_frame, Int, Long);
     4.7 +        C2P(blkif_fe_interface_connect_t, shmem_ref  , Int, Long);
     4.8          return dict;
     4.9      case TYPE(CMSG_BLKIF_FE, CMSG_BLKIF_FE_INTERFACE_DISCONNECT):
    4.10          C2P(blkif_fe_interface_disconnect_t, handle, Int, Long);
    4.11 @@ -612,6 +613,7 @@ static PyObject *xu_message_get_payload(
    4.12          C2P(blkif_be_connect_t, domid,        Int, Long);
    4.13          C2P(blkif_be_connect_t, blkif_handle, Int, Long);
    4.14          C2P(blkif_be_connect_t, shmem_frame,  Int, Long);
    4.15 +        C2P(blkif_be_connect_t, shmem_ref,    Int, Long);
    4.16          C2P(blkif_be_connect_t, evtchn,       Int, Long);
    4.17          C2P(blkif_be_connect_t, status,       Int, Long);
    4.18          return dict;
    4.19 @@ -842,6 +844,7 @@ static PyObject *xu_message_new(PyObject
    4.20          P2C(blkif_be_connect_t, domid,        u32);
    4.21          P2C(blkif_be_connect_t, blkif_handle, u32);
    4.22          P2C(blkif_be_connect_t, shmem_frame,  memory_t);
    4.23 +        P2C(blkif_be_connect_t, shmem_ref,    u32);
    4.24          P2C(blkif_be_connect_t, evtchn,       u16);
    4.25          break;
    4.26      case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_DISCONNECT):
     5.1 --- a/tools/python/xen/xend/server/blkif.py	Wed Jul 06 08:47:34 2005 +0000
     5.2 +++ b/tools/python/xen/xend/server/blkif.py	Wed Jul 06 08:50:11 2005 +0000
     5.3 @@ -126,7 +126,8 @@ class BlkifBackend:
     5.4                        { 'domid'        : self.frontendDomain,
     5.5                          'blkif_handle' : self.id,
     5.6                          'evtchn'       : self.getEventChannelBackend(),
     5.7 -                        'shmem_frame'  : val['shmem_frame'] })
     5.8 +                        'shmem_frame'  : val['shmem_frame'],
     5.9 +                        'shmem_ref'    : val['shmem_ref'] })
    5.10          msg = self.backendChannel.requestResponse(msg)
    5.11          #todo: check return status
    5.12          val = unpackMsg('blkif_be_connect_t', msg)
     6.1 --- a/xen/include/public/dom0_ops.h	Wed Jul 06 08:47:34 2005 +0000
     6.2 +++ b/xen/include/public/dom0_ops.h	Wed Jul 06 08:50:11 2005 +0000
     6.3 @@ -19,7 +19,7 @@
     6.4   * This makes sure that old versions of dom0 tools will stop working in a
     6.5   * well-defined way (rather than crashing the machine, for instance).
     6.6   */
     6.7 -#define DOM0_INTERFACE_VERSION   0xAAAA100B
     6.8 +#define DOM0_INTERFACE_VERSION   0xAAAA100C
     6.9  
    6.10  /************************************************************************/
    6.11  
     7.1 --- a/xen/include/public/io/domain_controller.h	Wed Jul 06 08:47:34 2005 +0000
     7.2 +++ b/xen/include/public/io/domain_controller.h	Wed Jul 06 08:50:11 2005 +0000
     7.3 @@ -140,6 +140,7 @@ typedef struct blkif_fe_driver_status {
     7.4  typedef struct blkif_fe_interface_connect {
     7.5      u32      handle;
     7.6      memory_t shmem_frame;
     7.7 +    int      shmem_ref;
     7.8  } blkif_fe_interface_connect_t;
     7.9  
    7.10  /*
    7.11 @@ -249,6 +250,7 @@ typedef struct blkif_be_connect {
    7.12      domid_t    domid;         /* Domain attached to new interface.   */
    7.13      u32        blkif_handle;  /* Domain-specific interface handle.   */
    7.14      memory_t   shmem_frame;   /* Page cont. shared comms window.     */
    7.15 +    int        shmem_ref;     /* Grant table reference.              */
    7.16      u32        evtchn;        /* Event channel for notifications.    */
    7.17      /* OUT */
    7.18      u32        status;