diff options
author | David Vrabel <david.vrabel@citrix.com> | 2011-09-29 11:53:30 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2011-10-26 10:02:35 -0400 |
commit | 2d073846b891c3f49c4ea03c5db3ac92f92742f1 (patch) | |
tree | c47dd9015bb072e1d31d1cefdfe9995d8a2388ef /drivers/block/xen-blkback/xenbus.c | |
parent | 4dcaebbf6586d299be8513512a1253f177b803d7 (diff) |
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>
Diffstat (limited to 'drivers/block/xen-blkback/xenbus.c')
-rw-r--r-- | drivers/block/xen-blkback/xenbus.c | 54 |
1 files changed, 7 insertions, 47 deletions
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 5fd2010f7d2b..69233dd42212 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c | |||
@@ -120,38 +120,6 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) | |||
120 | return blkif; | 120 | return blkif; |
121 | } | 121 | } |
122 | 122 | ||
123 | static int map_frontend_page(struct xen_blkif *blkif, unsigned long shared_page) | ||
124 | { | ||
125 | struct gnttab_map_grant_ref op; | ||
126 | |||
127 | gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr, | ||
128 | GNTMAP_host_map, shared_page, blkif->domid); | ||
129 | |||
130 | if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)) | ||
131 | BUG(); | ||
132 | |||
133 | if (op.status) { | ||
134 | DPRINTK("Grant table operation failure !\n"); | ||
135 | return op.status; | ||
136 | } | ||
137 | |||
138 | blkif->shmem_ref = shared_page; | ||
139 | blkif->shmem_handle = op.handle; | ||
140 | |||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | static void unmap_frontend_page(struct xen_blkif *blkif) | ||
145 | { | ||
146 | struct gnttab_unmap_grant_ref op; | ||
147 | |||
148 | gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr, | ||
149 | GNTMAP_host_map, blkif->shmem_handle); | ||
150 | |||
151 | if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)) | ||
152 | BUG(); | ||
153 | } | ||
154 | |||
155 | static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, | 123 | static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, |
156 | unsigned int evtchn) | 124 | unsigned int evtchn) |
157 | { | 125 | { |
@@ -161,35 +129,29 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, | |||
161 | if (blkif->irq) | 129 | if (blkif->irq) |
162 | return 0; | 130 | return 0; |
163 | 131 | ||
164 | blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE); | 132 | err = xenbus_map_ring_valloc(blkif->be->dev, shared_page, &blkif->blk_ring); |
165 | if (!blkif->blk_ring_area) | 133 | if (err < 0) |
166 | return -ENOMEM; | ||
167 | |||
168 | err = map_frontend_page(blkif, shared_page); | ||
169 | if (err) { | ||
170 | free_vm_area(blkif->blk_ring_area); | ||
171 | return err; | 134 | return err; |
172 | } | ||
173 | 135 | ||
174 | switch (blkif->blk_protocol) { | 136 | switch (blkif->blk_protocol) { |
175 | case BLKIF_PROTOCOL_NATIVE: | 137 | case BLKIF_PROTOCOL_NATIVE: |
176 | { | 138 | { |
177 | struct blkif_sring *sring; | 139 | struct blkif_sring *sring; |
178 | sring = (struct blkif_sring *)blkif->blk_ring_area->addr; | 140 | sring = (struct blkif_sring *)blkif->blk_ring; |
179 | BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE); | 141 | BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE); |
180 | break; | 142 | break; |
181 | } | 143 | } |
182 | case BLKIF_PROTOCOL_X86_32: | 144 | case BLKIF_PROTOCOL_X86_32: |
183 | { | 145 | { |
184 | struct blkif_x86_32_sring *sring_x86_32; | 146 | struct blkif_x86_32_sring *sring_x86_32; |
185 | sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring_area->addr; | 147 | sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring; |
186 | BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE); | 148 | BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE); |
187 | break; | 149 | break; |
188 | } | 150 | } |
189 | case BLKIF_PROTOCOL_X86_64: | 151 | case BLKIF_PROTOCOL_X86_64: |
190 | { | 152 | { |
191 | struct blkif_x86_64_sring *sring_x86_64; | 153 | struct blkif_x86_64_sring *sring_x86_64; |
192 | sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring_area->addr; | 154 | sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring; |
193 | BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE); | 155 | BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE); |
194 | break; | 156 | break; |
195 | } | 157 | } |
@@ -201,8 +163,7 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, | |||
201 | xen_blkif_be_int, 0, | 163 | xen_blkif_be_int, 0, |
202 | "blkif-backend", blkif); | 164 | "blkif-backend", blkif); |
203 | if (err < 0) { | 165 | if (err < 0) { |
204 | unmap_frontend_page(blkif); | 166 | xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring); |
205 | free_vm_area(blkif->blk_ring_area); | ||
206 | blkif->blk_rings.common.sring = NULL; | 167 | blkif->blk_rings.common.sring = NULL; |
207 | return err; | 168 | return err; |
208 | } | 169 | } |
@@ -228,8 +189,7 @@ static void xen_blkif_disconnect(struct xen_blkif *blkif) | |||
228 | } | 189 | } |
229 | 190 | ||
230 | if (blkif->blk_rings.common.sring) { | 191 | if (blkif->blk_rings.common.sring) { |
231 | unmap_frontend_page(blkif); | 192 | xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring); |
232 | free_vm_area(blkif->blk_ring_area); | ||
233 | blkif->blk_rings.common.sring = NULL; | 193 | blkif->blk_rings.common.sring = NULL; |
234 | } | 194 | } |
235 | } | 195 | } |