aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/xen-blkback
diff options
context:
space:
mode:
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2011-04-20 10:57:29 -0400
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2011-04-20 11:57:59 -0400
commitee9ff8537eacb4383bf9146df6c21b9301c9baa2 (patch)
tree4899443b2ac14df1e4dec69c1c21e38181fe2c5e /drivers/block/xen-blkback
parentdfc07b13dcacefda6ebdea14584ed8724dc980ef (diff)
xen/blkback: Squash vbd.c,interface.c in blkback.c and xenbus.c respectivly.
Daniel Stodden suggested to eliminate vbd.c and interface.c, inlining the critical bits where they belong, respectively. Leaving only blkback.c for the data- and xenbus.c for the control path. Suggested-by: Daniel Stodden <daniel.stodden@citrix.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/block/xen-blkback')
-rw-r--r--drivers/block/xen-blkback/Makefile2
-rw-r--r--drivers/block/xen-blkback/blkback.c135
-rw-r--r--drivers/block/xen-blkback/interface.c185
-rw-r--r--drivers/block/xen-blkback/vbd.c162
-rw-r--r--drivers/block/xen-blkback/xenbus.c151
5 files changed, 287 insertions, 348 deletions
diff --git a/drivers/block/xen-blkback/Makefile b/drivers/block/xen-blkback/Makefile
index f1ae1ff07a4d..e491c1b76878 100644
--- a/drivers/block/xen-blkback/Makefile
+++ b/drivers/block/xen-blkback/Makefile
@@ -1,3 +1,3 @@
1obj-$(CONFIG_XEN_BLKDEV_BACKEND) := xen-blkback.o 1obj-$(CONFIG_XEN_BLKDEV_BACKEND) := xen-blkback.o
2 2
3xen-blkback-y := blkback.o xenbus.o interface.o vbd.o 3xen-blkback-y := blkback.o xenbus.o
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index 59a2bae0f35e..63001fac9af2 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -167,6 +167,141 @@ static void free_req(struct pending_req *req)
167} 167}
168 168
169/* 169/*
170 * Routines for managing virtual block devices (vbds).
171 */
172
173#define vbd_sz(_v) ((_v)->bdev->bd_part ? \
174 (_v)->bdev->bd_part->nr_sects : \
175 get_capacity((_v)->bdev->bd_disk))
176
177unsigned long long vbd_size(struct vbd *vbd)
178{
179 return vbd_sz(vbd);
180}
181
182unsigned int vbd_info(struct vbd *vbd)
183{
184 return vbd->type | (vbd->readonly ? VDISK_READONLY : 0);
185}
186
187unsigned long vbd_secsize(struct vbd *vbd)
188{
189 return bdev_logical_block_size(vbd->bdev);
190}
191
192int vbd_create(struct blkif_st *blkif, blkif_vdev_t handle, unsigned major,
193 unsigned minor, int readonly, int cdrom)
194{
195 struct vbd *vbd;
196 struct block_device *bdev;
197
198 vbd = &blkif->vbd;
199 vbd->handle = handle;
200 vbd->readonly = readonly;
201 vbd->type = 0;
202
203 vbd->pdevice = MKDEV(major, minor);
204
205 bdev = blkdev_get_by_dev(vbd->pdevice, vbd->readonly ?
206 FMODE_READ : FMODE_WRITE, NULL);
207
208 if (IS_ERR(bdev)) {
209 DPRINTK("vbd_creat: device %08x could not be opened.\n",
210 vbd->pdevice);
211 return -ENOENT;
212 }
213
214 vbd->bdev = bdev;
215 vbd->size = vbd_size(vbd);
216
217 if (vbd->bdev->bd_disk == NULL) {
218 DPRINTK("vbd_creat: device %08x doesn't exist.\n",
219 vbd->pdevice);
220 vbd_free(vbd);
221 return -ENOENT;
222 }
223
224 if (vbd->bdev->bd_disk->flags & GENHD_FL_CD || cdrom)
225 vbd->type |= VDISK_CDROM;
226 if (vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE)
227 vbd->type |= VDISK_REMOVABLE;
228
229 DPRINTK("Successful creation of handle=%04x (dom=%u)\n",
230 handle, blkif->domid);
231 return 0;
232}
233
234void vbd_free(struct vbd *vbd)
235{
236 if (vbd->bdev)
237 blkdev_put(vbd->bdev, vbd->readonly ? FMODE_READ : FMODE_WRITE);
238 vbd->bdev = NULL;
239}
240
241int vbd_translate(struct phys_req *req, struct blkif_st *blkif, int operation)
242{
243 struct vbd *vbd = &blkif->vbd;
244 int rc = -EACCES;
245
246 if ((operation != READ) && vbd->readonly)
247 goto out;
248
249 if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)))
250 goto out;
251
252 req->dev = vbd->pdevice;
253 req->bdev = vbd->bdev;
254 rc = 0;
255
256 out:
257 return rc;
258}
259
260void vbd_resize(struct blkif_st *blkif)
261{
262 struct vbd *vbd = &blkif->vbd;
263 struct xenbus_transaction xbt;
264 int err;
265 struct xenbus_device *dev = blkback_xenbus(blkif->be);
266 unsigned long long new_size = vbd_size(vbd);
267
268 printk(KERN_INFO "VBD Resize: Domid: %d, Device: (%d, %d)\n",
269 blkif->domid, MAJOR(vbd->pdevice), MINOR(vbd->pdevice));
270 printk(KERN_INFO "VBD Resize: new size %llu\n", new_size);
271 vbd->size = new_size;
272again:
273 err = xenbus_transaction_start(&xbt);
274 if (err) {
275 printk(KERN_WARNING "Error starting transaction");
276 return;
277 }
278 err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
279 vbd_size(vbd));
280 if (err) {
281 printk(KERN_WARNING "Error writing new size");
282 goto abort;
283 }
284 /*
285 * Write the current state; we will use this to synchronize
286 * the front-end. If the current state is "connected" the
287 * front-end will get the new size information online.
288 */
289 err = xenbus_printf(xbt, dev->nodename, "state", "%d", dev->state);
290 if (err) {
291 printk(KERN_WARNING "Error writing the state");
292 goto abort;
293 }
294
295 err = xenbus_transaction_end(xbt, 0);
296 if (err == -EAGAIN)
297 goto again;
298 if (err)
299 printk(KERN_WARNING "Error ending transaction");
300abort:
301 xenbus_transaction_end(xbt, 1);
302}
303
304/*
170 * Notification from the guest OS. 305 * Notification from the guest OS.
171 */ 306 */
172static void blkif_notify_work(struct blkif_st *blkif) 307static void blkif_notify_work(struct blkif_st *blkif)
diff --git a/drivers/block/xen-blkback/interface.c b/drivers/block/xen-blkback/interface.c
deleted file mode 100644
index 163aed41e825..000000000000
--- a/drivers/block/xen-blkback/interface.c
+++ /dev/null
@@ -1,185 +0,0 @@
1/******************************************************************************
2 * Block-device interface management.
3 *
4 * Copyright (c) 2004, Keir Fraser
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation; or, when distributed
9 * separately from the Linux kernel or incorporated into other
10 * software packages, subject to the following license:
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this source file (the "Software"), to deal in the Software without
14 * restriction, including without limitation the rights to use, copy, modify,
15 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
16 * and to permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
30
31#include "common.h"
32#include <xen/events.h>
33#include <xen/grant_table.h>
34#include <linux/kthread.h>
35
36static struct kmem_cache *blkif_cachep;
37
38struct blkif_st *blkif_alloc(domid_t domid)
39{
40 struct blkif_st *blkif;
41
42 blkif = kmem_cache_alloc(blkif_cachep, GFP_KERNEL);
43 if (!blkif)
44 return ERR_PTR(-ENOMEM);
45
46 memset(blkif, 0, sizeof(*blkif));
47 blkif->domid = domid;
48 spin_lock_init(&blkif->blk_ring_lock);
49 atomic_set(&blkif->refcnt, 1);
50 init_waitqueue_head(&blkif->wq);
51 blkif->st_print = jiffies;
52 init_waitqueue_head(&blkif->waiting_to_free);
53
54 return blkif;
55}
56
57static int map_frontend_page(struct blkif_st *blkif, unsigned long shared_page)
58{
59 struct gnttab_map_grant_ref op;
60
61 gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr,
62 GNTMAP_host_map, shared_page, blkif->domid);
63
64 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
65 BUG();
66
67 if (op.status) {
68 DPRINTK(" Grant table operation failure !\n");
69 return op.status;
70 }
71
72 blkif->shmem_ref = shared_page;
73 blkif->shmem_handle = op.handle;
74
75 return 0;
76}
77
78static void unmap_frontend_page(struct blkif_st *blkif)
79{
80 struct gnttab_unmap_grant_ref op;
81
82 gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr,
83 GNTMAP_host_map, blkif->shmem_handle);
84
85 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
86 BUG();
87}
88
89int blkif_map(struct blkif_st *blkif, unsigned long shared_page,
90 unsigned int evtchn)
91{
92 int err;
93
94 /* Already connected through? */
95 if (blkif->irq)
96 return 0;
97
98 blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE);
99 if (!blkif->blk_ring_area)
100 return -ENOMEM;
101
102 err = map_frontend_page(blkif, shared_page);
103 if (err) {
104 free_vm_area(blkif->blk_ring_area);
105 return err;
106 }
107
108 switch (blkif->blk_protocol) {
109 case BLKIF_PROTOCOL_NATIVE:
110 {
111 struct blkif_sring *sring;
112 sring = (struct blkif_sring *)blkif->blk_ring_area->addr;
113 BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE);
114 break;
115 }
116 case BLKIF_PROTOCOL_X86_32:
117 {
118 struct blkif_x86_32_sring *sring_x86_32;
119 sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring_area->addr;
120 BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE);
121 break;
122 }
123 case BLKIF_PROTOCOL_X86_64:
124 {
125 struct blkif_x86_64_sring *sring_x86_64;
126 sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring_area->addr;
127 BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE);
128 break;
129 }
130 default:
131 BUG();
132 }
133
134 err = bind_interdomain_evtchn_to_irqhandler(
135 blkif->domid, evtchn, blkif_be_int, 0, "blkif-backend", blkif);
136 if (err < 0) {
137 unmap_frontend_page(blkif);
138 free_vm_area(blkif->blk_ring_area);
139 blkif->blk_rings.common.sring = NULL;
140 return err;
141 }
142 blkif->irq = err;
143
144 return 0;
145}
146
147void blkif_disconnect(struct blkif_st *blkif)
148{
149 if (blkif->xenblkd) {
150 kthread_stop(blkif->xenblkd);
151 blkif->xenblkd = NULL;
152 }
153
154 atomic_dec(&blkif->refcnt);
155 wait_event(blkif->waiting_to_free, atomic_read(&blkif->refcnt) == 0);
156 atomic_inc(&blkif->refcnt);
157
158 if (blkif->irq) {
159 unbind_from_irqhandler(blkif->irq, blkif);
160 blkif->irq = 0;
161 }
162
163 if (blkif->blk_rings.common.sring) {
164 unmap_frontend_page(blkif);
165 free_vm_area(blkif->blk_ring_area);
166 blkif->blk_rings.common.sring = NULL;
167 }
168}
169
170void blkif_free(struct blkif_st *blkif)
171{
172 if (!atomic_dec_and_test(&blkif->refcnt))
173 BUG();
174 kmem_cache_free(blkif_cachep, blkif);
175}
176
177int __init blkif_interface_init(void)
178{
179 blkif_cachep = kmem_cache_create("blkif_cache", sizeof(struct blkif_st),
180 0, 0, NULL);
181 if (!blkif_cachep)
182 return -ENOMEM;
183
184 return 0;
185}
diff --git a/drivers/block/xen-blkback/vbd.c b/drivers/block/xen-blkback/vbd.c
deleted file mode 100644
index d0ff4cf91a34..000000000000
--- a/drivers/block/xen-blkback/vbd.c
+++ /dev/null
@@ -1,162 +0,0 @@
1/******************************************************************************
2 * Routines for managing virtual block devices (VBDs).
3 *
4 * Copyright (c) 2003-2005, Keir Fraser & Steve Hand
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation; or, when distributed
9 * separately from the Linux kernel or incorporated into other
10 * software packages, subject to the following license:
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this source file (the "Software"), to deal in the Software without
14 * restriction, including without limitation the rights to use, copy, modify,
15 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
16 * and to permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
30
31#include "common.h"
32
33#define vbd_sz(_v) ((_v)->bdev->bd_part ? \
34 (_v)->bdev->bd_part->nr_sects : \
35 get_capacity((_v)->bdev->bd_disk))
36
37unsigned long long vbd_size(struct vbd *vbd)
38{
39 return vbd_sz(vbd);
40}
41
42unsigned int vbd_info(struct vbd *vbd)
43{
44 return vbd->type | (vbd->readonly ? VDISK_READONLY : 0);
45}
46
47unsigned long vbd_secsize(struct vbd *vbd)
48{
49 return bdev_logical_block_size(vbd->bdev);
50}
51
52int vbd_create(struct blkif_st *blkif, blkif_vdev_t handle, unsigned major,
53 unsigned minor, int readonly, int cdrom)
54{
55 struct vbd *vbd;
56 struct block_device *bdev;
57
58 vbd = &blkif->vbd;
59 vbd->handle = handle;
60 vbd->readonly = readonly;
61 vbd->type = 0;
62
63 vbd->pdevice = MKDEV(major, minor);
64
65 bdev = blkdev_get_by_dev(vbd->pdevice, vbd->readonly ?
66 FMODE_READ : FMODE_WRITE, NULL);
67
68 if (IS_ERR(bdev)) {
69 DPRINTK("vbd_creat: device %08x could not be opened.\n",
70 vbd->pdevice);
71 return -ENOENT;
72 }
73
74 vbd->bdev = bdev;
75 vbd->size = vbd_size(vbd);
76
77 if (vbd->bdev->bd_disk == NULL) {
78 DPRINTK("vbd_creat: device %08x doesn't exist.\n",
79 vbd->pdevice);
80 vbd_free(vbd);
81 return -ENOENT;
82 }
83
84 if (vbd->bdev->bd_disk->flags & GENHD_FL_CD || cdrom)
85 vbd->type |= VDISK_CDROM;
86 if (vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE)
87 vbd->type |= VDISK_REMOVABLE;
88
89 DPRINTK("Successful creation of handle=%04x (dom=%u)\n",
90 handle, blkif->domid);
91 return 0;
92}
93
94void vbd_free(struct vbd *vbd)
95{
96 if (vbd->bdev)
97 blkdev_put(vbd->bdev, vbd->readonly ? FMODE_READ : FMODE_WRITE);
98 vbd->bdev = NULL;
99}
100
101int vbd_translate(struct phys_req *req, struct blkif_st *blkif, int operation)
102{
103 struct vbd *vbd = &blkif->vbd;
104 int rc = -EACCES;
105
106 if ((operation != READ) && vbd->readonly)
107 goto out;
108
109 if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)))
110 goto out;
111
112 req->dev = vbd->pdevice;
113 req->bdev = vbd->bdev;
114 rc = 0;
115
116 out:
117 return rc;
118}
119
120void vbd_resize(struct blkif_st *blkif)
121{
122 struct vbd *vbd = &blkif->vbd;
123 struct xenbus_transaction xbt;
124 int err;
125 struct xenbus_device *dev = blkback_xenbus(blkif->be);
126 unsigned long long new_size = vbd_size(vbd);
127
128 printk(KERN_INFO "VBD Resize: Domid: %d, Device: (%d, %d)\n",
129 blkif->domid, MAJOR(vbd->pdevice), MINOR(vbd->pdevice));
130 printk(KERN_INFO "VBD Resize: new size %llu\n", new_size);
131 vbd->size = new_size;
132again:
133 err = xenbus_transaction_start(&xbt);
134 if (err) {
135 printk(KERN_WARNING "Error starting transaction");
136 return;
137 }
138 err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
139 vbd_size(vbd));
140 if (err) {
141 printk(KERN_WARNING "Error writing new size");
142 goto abort;
143 }
144 /*
145 * Write the current state; we will use this to synchronize
146 * the front-end. If the current state is "connected" the
147 * front-end will get the new size information online.
148 */
149 err = xenbus_printf(xbt, dev->nodename, "state", "%d", dev->state);
150 if (err) {
151 printk(KERN_WARNING "Error writing the state");
152 goto abort;
153 }
154
155 err = xenbus_transaction_end(xbt, 0);
156 if (err == -EAGAIN)
157 goto again;
158 if (err)
159 printk(KERN_WARNING "Error ending transaction");
160abort:
161 xenbus_transaction_end(xbt, 1);
162}
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index b41ed65db2d3..0c263a248007 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -20,6 +20,8 @@
20#include <stdarg.h> 20#include <stdarg.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/kthread.h> 22#include <linux/kthread.h>
23#include <xen/events.h>
24#include <xen/grant_table.h>
23#include "common.h" 25#include "common.h"
24 26
25#undef DPRINTK 27#undef DPRINTK
@@ -36,6 +38,7 @@ struct backend_info {
36 char *mode; 38 char *mode;
37}; 39};
38 40
41static struct kmem_cache *blkif_cachep;
39static void connect(struct backend_info *); 42static void connect(struct backend_info *);
40static int connect_ring(struct backend_info *); 43static int connect_ring(struct backend_info *);
41static void backend_changed(struct xenbus_watch *, const char **, 44static void backend_changed(struct xenbus_watch *, const char **,
@@ -106,6 +109,154 @@ static void update_blkif_status(struct blkif_st *blkif)
106 } 109 }
107} 110}
108 111
112struct blkif_st *blkif_alloc(domid_t domid)
113{
114 struct blkif_st *blkif;
115
116 blkif = kmem_cache_alloc(blkif_cachep, GFP_KERNEL);
117 if (!blkif)
118 return ERR_PTR(-ENOMEM);
119
120 memset(blkif, 0, sizeof(*blkif));
121 blkif->domid = domid;
122 spin_lock_init(&blkif->blk_ring_lock);
123 atomic_set(&blkif->refcnt, 1);
124 init_waitqueue_head(&blkif->wq);
125 blkif->st_print = jiffies;
126 init_waitqueue_head(&blkif->waiting_to_free);
127
128 return blkif;
129}
130
131static int map_frontend_page(struct blkif_st *blkif, unsigned long shared_page)
132{
133 struct gnttab_map_grant_ref op;
134
135 gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr,
136 GNTMAP_host_map, shared_page, blkif->domid);
137
138 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
139 BUG();
140
141 if (op.status) {
142 DPRINTK(" Grant table operation failure !\n");
143 return op.status;
144 }
145
146 blkif->shmem_ref = shared_page;
147 blkif->shmem_handle = op.handle;
148
149 return 0;
150}
151
152static void unmap_frontend_page(struct blkif_st *blkif)
153{
154 struct gnttab_unmap_grant_ref op;
155
156 gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr,
157 GNTMAP_host_map, blkif->shmem_handle);
158
159 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
160 BUG();
161}
162
163int blkif_map(struct blkif_st *blkif, unsigned long shared_page,
164 unsigned int evtchn)
165{
166 int err;
167
168 /* Already connected through? */
169 if (blkif->irq)
170 return 0;
171
172 blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE);
173 if (!blkif->blk_ring_area)
174 return -ENOMEM;
175
176 err = map_frontend_page(blkif, shared_page);
177 if (err) {
178 free_vm_area(blkif->blk_ring_area);
179 return err;
180 }
181
182 switch (blkif->blk_protocol) {
183 case BLKIF_PROTOCOL_NATIVE:
184 {
185 struct blkif_sring *sring;
186 sring = (struct blkif_sring *)blkif->blk_ring_area->addr;
187 BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE);
188 break;
189 }
190 case BLKIF_PROTOCOL_X86_32:
191 {
192 struct blkif_x86_32_sring *sring_x86_32;
193 sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring_area->addr;
194 BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE);
195 break;
196 }
197 case BLKIF_PROTOCOL_X86_64:
198 {
199 struct blkif_x86_64_sring *sring_x86_64;
200 sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring_area->addr;
201 BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE);
202 break;
203 }
204 default:
205 BUG();
206 }
207
208 err = bind_interdomain_evtchn_to_irqhandler(
209 blkif->domid, evtchn, blkif_be_int, 0, "blkif-backend", blkif);
210 if (err < 0) {
211 unmap_frontend_page(blkif);
212 free_vm_area(blkif->blk_ring_area);
213 blkif->blk_rings.common.sring = NULL;
214 return err;
215 }
216 blkif->irq = err;
217
218 return 0;
219}
220
221void blkif_disconnect(struct blkif_st *blkif)
222{
223 if (blkif->xenblkd) {
224 kthread_stop(blkif->xenblkd);
225 blkif->xenblkd = NULL;
226 }
227
228 atomic_dec(&blkif->refcnt);
229 wait_event(blkif->waiting_to_free, atomic_read(&blkif->refcnt) == 0);
230 atomic_inc(&blkif->refcnt);
231
232 if (blkif->irq) {
233 unbind_from_irqhandler(blkif->irq, blkif);
234 blkif->irq = 0;
235 }
236
237 if (blkif->blk_rings.common.sring) {
238 unmap_frontend_page(blkif);
239 free_vm_area(blkif->blk_ring_area);
240 blkif->blk_rings.common.sring = NULL;
241 }
242}
243
244void blkif_free(struct blkif_st *blkif)
245{
246 if (!atomic_dec_and_test(&blkif->refcnt))
247 BUG();
248 kmem_cache_free(blkif_cachep, blkif);
249}
250
251int __init blkif_interface_init(void)
252{
253 blkif_cachep = kmem_cache_create("blkif_cache", sizeof(struct blkif_st),
254 0, 0, NULL);
255 if (!blkif_cachep)
256 return -ENOMEM;
257
258 return 0;
259}
109 260
110/* 261/*
111 * sysfs interface for VBD I/O requests 262 * sysfs interface for VBD I/O requests