block: xen-blkback: use API provided by xenbus module to map rings
The xenbus module provides xenbus_map_ring_valloc() and xenbus_map_ring_vfree(). Use these to map the ring pages granted by the frontend. Acked-by: Jens Axboe <jaxboe@fusionio.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
This commit is contained in:
parent
4dcaebbf65
commit
2d073846b8
|
@ -139,7 +139,7 @@ struct xen_blkif {
|
||||||
/* Comms information. */
|
/* Comms information. */
|
||||||
enum blkif_protocol blk_protocol;
|
enum blkif_protocol blk_protocol;
|
||||||
union blkif_back_rings blk_rings;
|
union blkif_back_rings blk_rings;
|
||||||
struct vm_struct *blk_ring_area;
|
void *blk_ring;
|
||||||
/* The VBD attached to this interface. */
|
/* The VBD attached to this interface. */
|
||||||
struct xen_vbd vbd;
|
struct xen_vbd vbd;
|
||||||
/* Back pointer to the backend_info. */
|
/* Back pointer to the backend_info. */
|
||||||
|
@ -163,9 +163,6 @@ struct xen_blkif {
|
||||||
int st_wr_sect;
|
int st_wr_sect;
|
||||||
|
|
||||||
wait_queue_head_t waiting_to_free;
|
wait_queue_head_t waiting_to_free;
|
||||||
|
|
||||||
grant_handle_t shmem_handle;
|
|
||||||
grant_ref_t shmem_ref;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -120,38 +120,6 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
|
||||||
return blkif;
|
return blkif;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int map_frontend_page(struct xen_blkif *blkif, unsigned long shared_page)
|
|
||||||
{
|
|
||||||
struct gnttab_map_grant_ref op;
|
|
||||||
|
|
||||||
gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr,
|
|
||||||
GNTMAP_host_map, shared_page, blkif->domid);
|
|
||||||
|
|
||||||
if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
|
|
||||||
BUG();
|
|
||||||
|
|
||||||
if (op.status) {
|
|
||||||
DPRINTK("Grant table operation failure !\n");
|
|
||||||
return op.status;
|
|
||||||
}
|
|
||||||
|
|
||||||
blkif->shmem_ref = shared_page;
|
|
||||||
blkif->shmem_handle = op.handle;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void unmap_frontend_page(struct xen_blkif *blkif)
|
|
||||||
{
|
|
||||||
struct gnttab_unmap_grant_ref op;
|
|
||||||
|
|
||||||
gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr,
|
|
||||||
GNTMAP_host_map, blkif->shmem_handle);
|
|
||||||
|
|
||||||
if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
|
|
||||||
BUG();
|
|
||||||
}
|
|
||||||
|
|
||||||
static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
|
static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
|
||||||
unsigned int evtchn)
|
unsigned int evtchn)
|
||||||
{
|
{
|
||||||
|
@ -161,35 +129,29 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
|
||||||
if (blkif->irq)
|
if (blkif->irq)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE);
|
err = xenbus_map_ring_valloc(blkif->be->dev, shared_page, &blkif->blk_ring);
|
||||||
if (!blkif->blk_ring_area)
|
if (err < 0)
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
err = map_frontend_page(blkif, shared_page);
|
|
||||||
if (err) {
|
|
||||||
free_vm_area(blkif->blk_ring_area);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
|
||||||
|
|
||||||
switch (blkif->blk_protocol) {
|
switch (blkif->blk_protocol) {
|
||||||
case BLKIF_PROTOCOL_NATIVE:
|
case BLKIF_PROTOCOL_NATIVE:
|
||||||
{
|
{
|
||||||
struct blkif_sring *sring;
|
struct blkif_sring *sring;
|
||||||
sring = (struct blkif_sring *)blkif->blk_ring_area->addr;
|
sring = (struct blkif_sring *)blkif->blk_ring;
|
||||||
BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE);
|
BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BLKIF_PROTOCOL_X86_32:
|
case BLKIF_PROTOCOL_X86_32:
|
||||||
{
|
{
|
||||||
struct blkif_x86_32_sring *sring_x86_32;
|
struct blkif_x86_32_sring *sring_x86_32;
|
||||||
sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring_area->addr;
|
sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring;
|
||||||
BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE);
|
BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BLKIF_PROTOCOL_X86_64:
|
case BLKIF_PROTOCOL_X86_64:
|
||||||
{
|
{
|
||||||
struct blkif_x86_64_sring *sring_x86_64;
|
struct blkif_x86_64_sring *sring_x86_64;
|
||||||
sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring_area->addr;
|
sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring;
|
||||||
BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE);
|
BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -201,8 +163,7 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
|
||||||
xen_blkif_be_int, 0,
|
xen_blkif_be_int, 0,
|
||||||
"blkif-backend", blkif);
|
"blkif-backend", blkif);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
unmap_frontend_page(blkif);
|
xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring);
|
||||||
free_vm_area(blkif->blk_ring_area);
|
|
||||||
blkif->blk_rings.common.sring = NULL;
|
blkif->blk_rings.common.sring = NULL;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -228,8 +189,7 @@ static void xen_blkif_disconnect(struct xen_blkif *blkif)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blkif->blk_rings.common.sring) {
|
if (blkif->blk_rings.common.sring) {
|
||||||
unmap_frontend_page(blkif);
|
xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring);
|
||||||
free_vm_area(blkif->blk_ring_area);
|
|
||||||
blkif->blk_rings.common.sring = NULL;
|
blkif->blk_rings.common.sring = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue