diff options
author | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2011-04-20 11:21:43 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2011-04-20 11:58:02 -0400 |
commit | 42c7841d171a2fe32005738dfebd724a90921496 (patch) | |
tree | 6cb19a9a61e98502eb7e3060f61781a6af016866 /drivers/block/xen-blkback | |
parent | 6cd0388cd600a51a8824dc5b34f1107b367b0cac (diff) |
xen-blkback: Inline some of the functions that were moved from vbd/interface.c
Shuffling code around.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/block/xen-blkback')
-rw-r--r-- | drivers/block/xen-blkback/blkback.c | 78 | ||||
-rw-r--r-- | drivers/block/xen-blkback/common.h | 22 | ||||
-rw-r--r-- | drivers/block/xen-blkback/xenbus.c | 58 |
3 files changed, 65 insertions, 93 deletions
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index 63001fac9af2..806c2c947c63 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c | |||
@@ -170,75 +170,9 @@ static void free_req(struct pending_req *req) | |||
170 | * Routines for managing virtual block devices (vbds). | 170 | * Routines for managing virtual block devices (vbds). |
171 | */ | 171 | */ |
172 | 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 | 173 | ||
177 | unsigned long long vbd_size(struct vbd *vbd) | 174 | static int vbd_translate(struct phys_req *req, struct blkif_st *blkif, |
178 | { | 175 | int operation) |
179 | return vbd_sz(vbd); | ||
180 | } | ||
181 | |||
182 | unsigned int vbd_info(struct vbd *vbd) | ||
183 | { | ||
184 | return vbd->type | (vbd->readonly ? VDISK_READONLY : 0); | ||
185 | } | ||
186 | |||
187 | unsigned long vbd_secsize(struct vbd *vbd) | ||
188 | { | ||
189 | return bdev_logical_block_size(vbd->bdev); | ||
190 | } | ||
191 | |||
192 | int 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 | |||
234 | void 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 | |||
241 | int vbd_translate(struct phys_req *req, struct blkif_st *blkif, int operation) | ||
242 | { | 176 | { |
243 | struct vbd *vbd = &blkif->vbd; | 177 | struct vbd *vbd = &blkif->vbd; |
244 | int rc = -EACCES; | 178 | int rc = -EACCES; |
@@ -257,13 +191,13 @@ int vbd_translate(struct phys_req *req, struct blkif_st *blkif, int operation) | |||
257 | return rc; | 191 | return rc; |
258 | } | 192 | } |
259 | 193 | ||
260 | void vbd_resize(struct blkif_st *blkif) | 194 | static void vbd_resize(struct blkif_st *blkif) |
261 | { | 195 | { |
262 | struct vbd *vbd = &blkif->vbd; | 196 | struct vbd *vbd = &blkif->vbd; |
263 | struct xenbus_transaction xbt; | 197 | struct xenbus_transaction xbt; |
264 | int err; | 198 | int err; |
265 | struct xenbus_device *dev = blkback_xenbus(blkif->be); | 199 | struct xenbus_device *dev = blkback_xenbus(blkif->be); |
266 | unsigned long long new_size = vbd_size(vbd); | 200 | unsigned long long new_size = vbd_sz(vbd); |
267 | 201 | ||
268 | printk(KERN_INFO "VBD Resize: Domid: %d, Device: (%d, %d)\n", | 202 | printk(KERN_INFO "VBD Resize: Domid: %d, Device: (%d, %d)\n", |
269 | blkif->domid, MAJOR(vbd->pdevice), MINOR(vbd->pdevice)); | 203 | blkif->domid, MAJOR(vbd->pdevice), MINOR(vbd->pdevice)); |
@@ -276,7 +210,7 @@ again: | |||
276 | return; | 210 | return; |
277 | } | 211 | } |
278 | err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", | 212 | err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", |
279 | vbd_size(vbd)); | 213 | (unsigned long long)vbd_sz(vbd)); |
280 | if (err) { | 214 | if (err) { |
281 | printk(KERN_WARNING "Error writing new size"); | 215 | printk(KERN_WARNING "Error writing new size"); |
282 | goto abort; | 216 | goto abort; |
@@ -344,7 +278,7 @@ int blkif_schedule(void *arg) | |||
344 | while (!kthread_should_stop()) { | 278 | while (!kthread_should_stop()) { |
345 | if (try_to_freeze()) | 279 | if (try_to_freeze()) |
346 | continue; | 280 | continue; |
347 | if (unlikely(vbd->size != vbd_size(vbd))) | 281 | if (unlikely(vbd->size != vbd_sz(vbd))) |
348 | vbd_resize(blkif); | 282 | vbd_resize(blkif); |
349 | 283 | ||
350 | wait_event_interruptible( | 284 | wait_event_interruptible( |
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h index 6257c1106591..4b5acb3e8b24 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h | |||
@@ -95,12 +95,10 @@ struct blkif_st { | |||
95 | grant_ref_t shmem_ref; | 95 | grant_ref_t shmem_ref; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | struct blkif_st *blkif_alloc(domid_t domid); | 98 | |
99 | void blkif_disconnect(struct blkif_st *blkif); | 99 | #define vbd_sz(_v) ((_v)->bdev->bd_part ? \ |
100 | void blkif_free(struct blkif_st *blkif); | 100 | (_v)->bdev->bd_part->nr_sects : \ |
101 | int blkif_map(struct blkif_st *blkif, unsigned long shared_page, | 101 | get_capacity((_v)->bdev->bd_disk)) |
102 | unsigned int evtchn); | ||
103 | void vbd_resize(struct blkif_st *blkif); | ||
104 | 102 | ||
105 | #define blkif_get(_b) (atomic_inc(&(_b)->refcnt)) | 103 | #define blkif_get(_b) (atomic_inc(&(_b)->refcnt)) |
106 | #define blkif_put(_b) \ | 104 | #define blkif_put(_b) \ |
@@ -109,24 +107,12 @@ void vbd_resize(struct blkif_st *blkif); | |||
109 | wake_up(&(_b)->waiting_to_free);\ | 107 | wake_up(&(_b)->waiting_to_free);\ |
110 | } while (0) | 108 | } while (0) |
111 | 109 | ||
112 | /* Create a vbd. */ | ||
113 | int vbd_create(struct blkif_st *blkif, blkif_vdev_t vdevice, unsigned major, | ||
114 | unsigned minor, int readonly, int cdrom); | ||
115 | void vbd_free(struct vbd *vbd); | ||
116 | |||
117 | unsigned long long vbd_size(struct vbd *vbd); | ||
118 | unsigned int vbd_info(struct vbd *vbd); | ||
119 | unsigned long vbd_secsize(struct vbd *vbd); | ||
120 | |||
121 | struct phys_req { | 110 | struct phys_req { |
122 | unsigned short dev; | 111 | unsigned short dev; |
123 | unsigned short nr_sects; | 112 | unsigned short nr_sects; |
124 | struct block_device *bdev; | 113 | struct block_device *bdev; |
125 | blkif_sector_t sector_number; | 114 | blkif_sector_t sector_number; |
126 | }; | 115 | }; |
127 | |||
128 | int vbd_translate(struct phys_req *req, struct blkif_st *blkif, int operation); | ||
129 | |||
130 | int blkif_interface_init(void); | 116 | int blkif_interface_init(void); |
131 | 117 | ||
132 | int blkif_xenbus_init(void); | 118 | int blkif_xenbus_init(void); |
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index c6c5286aa813..75bf49bd365c 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c | |||
@@ -327,6 +327,56 @@ void xenvbd_sysfs_delif(struct xenbus_device *dev) | |||
327 | device_remove_file(&dev->dev, &dev_attr_physical_device); | 327 | device_remove_file(&dev->dev, &dev_attr_physical_device); |
328 | } | 328 | } |
329 | 329 | ||
330 | |||
331 | static void vbd_free(struct vbd *vbd) | ||
332 | { | ||
333 | if (vbd->bdev) | ||
334 | blkdev_put(vbd->bdev, vbd->readonly ? FMODE_READ : FMODE_WRITE); | ||
335 | vbd->bdev = NULL; | ||
336 | } | ||
337 | |||
338 | static int vbd_create(struct blkif_st *blkif, blkif_vdev_t handle, | ||
339 | unsigned major, unsigned minor, int readonly, | ||
340 | int cdrom) | ||
341 | { | ||
342 | struct vbd *vbd; | ||
343 | struct block_device *bdev; | ||
344 | |||
345 | vbd = &blkif->vbd; | ||
346 | vbd->handle = handle; | ||
347 | vbd->readonly = readonly; | ||
348 | vbd->type = 0; | ||
349 | |||
350 | vbd->pdevice = MKDEV(major, minor); | ||
351 | |||
352 | bdev = blkdev_get_by_dev(vbd->pdevice, vbd->readonly ? | ||
353 | FMODE_READ : FMODE_WRITE, NULL); | ||
354 | |||
355 | if (IS_ERR(bdev)) { | ||
356 | DPRINTK("vbd_creat: device %08x could not be opened.\n", | ||
357 | vbd->pdevice); | ||
358 | return -ENOENT; | ||
359 | } | ||
360 | |||
361 | vbd->bdev = bdev; | ||
362 | vbd->size = vbd_sz(vbd); | ||
363 | |||
364 | if (vbd->bdev->bd_disk == NULL) { | ||
365 | DPRINTK("vbd_creat: device %08x doesn't exist.\n", | ||
366 | vbd->pdevice); | ||
367 | vbd_free(vbd); | ||
368 | return -ENOENT; | ||
369 | } | ||
370 | |||
371 | if (vbd->bdev->bd_disk->flags & GENHD_FL_CD || cdrom) | ||
372 | vbd->type |= VDISK_CDROM; | ||
373 | if (vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE) | ||
374 | vbd->type |= VDISK_REMOVABLE; | ||
375 | |||
376 | DPRINTK("Successful creation of handle=%04x (dom=%u)\n", | ||
377 | handle, blkif->domid); | ||
378 | return 0; | ||
379 | } | ||
330 | static int blkback_remove(struct xenbus_device *dev) | 380 | static int blkback_remove(struct xenbus_device *dev) |
331 | { | 381 | { |
332 | struct backend_info *be = dev_get_drvdata(&dev->dev); | 382 | struct backend_info *be = dev_get_drvdata(&dev->dev); |
@@ -595,7 +645,7 @@ again: | |||
595 | goto abort; | 645 | goto abort; |
596 | 646 | ||
597 | err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", | 647 | err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", |
598 | vbd_size(&be->blkif->vbd)); | 648 | (unsigned long long)vbd_sz(&be->blkif->vbd)); |
599 | if (err) { | 649 | if (err) { |
600 | xenbus_dev_fatal(dev, err, "writing %s/sectors", | 650 | xenbus_dev_fatal(dev, err, "writing %s/sectors", |
601 | dev->nodename); | 651 | dev->nodename); |
@@ -604,14 +654,16 @@ again: | |||
604 | 654 | ||
605 | /* FIXME: use a typename instead */ | 655 | /* FIXME: use a typename instead */ |
606 | err = xenbus_printf(xbt, dev->nodename, "info", "%u", | 656 | err = xenbus_printf(xbt, dev->nodename, "info", "%u", |
607 | vbd_info(&be->blkif->vbd)); | 657 | be->blkif->vbd.type | |
658 | (be->blkif->vbd.readonly ? VDISK_READONLY : 0)); | ||
608 | if (err) { | 659 | if (err) { |
609 | xenbus_dev_fatal(dev, err, "writing %s/info", | 660 | xenbus_dev_fatal(dev, err, "writing %s/info", |
610 | dev->nodename); | 661 | dev->nodename); |
611 | goto abort; | 662 | goto abort; |
612 | } | 663 | } |
613 | err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu", | 664 | err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu", |
614 | vbd_secsize(&be->blkif->vbd)); | 665 | (unsigned long) |
666 | bdev_logical_block_size(be->blkif->vbd.bdev)); | ||
615 | if (err) { | 667 | if (err) { |
616 | xenbus_dev_fatal(dev, err, "writing %s/sector-size", | 668 | xenbus_dev_fatal(dev, err, "writing %s/sector-size", |
617 | dev->nodename); | 669 | dev->nodename); |