ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c @ 8614:bd606783c6bf

remove unnecessary macro bdev_put which is an alias to blkdev_put.

Signed-off-by: Vincent Hanquez <vincent@xensource.com>
author vhanquez@kneesa.uk.xensource.com
date Mon Jan 16 21:13:29 2006 +0000 (2006-01-16)
parents 8c3ed250366c
children fd9b2c1bb577
line source
1 /******************************************************************************
2 * blkback/vbd.c
3 *
4 * Routines for managing virtual block devices (VBDs).
5 *
6 * Copyright (c) 2003-2005, Keir Fraser & Steve Hand
7 */
9 #include "common.h"
10 #include <asm-xen/xenbus.h>
12 #define vbd_sz(_v) ((_v)->bdev->bd_part ? \
13 (_v)->bdev->bd_part->nr_sects : (_v)->bdev->bd_disk->capacity)
15 unsigned long vbd_size(struct vbd *vbd)
16 {
17 return vbd_sz(vbd);
18 }
20 unsigned int vbd_info(struct vbd *vbd)
21 {
22 return vbd->type | (vbd->readonly?VDISK_READONLY:0);
23 }
25 unsigned long vbd_secsize(struct vbd *vbd)
26 {
27 return bdev_hardsect_size(vbd->bdev);
28 }
30 int vbd_create(blkif_t *blkif, blkif_vdev_t handle, unsigned major,
31 unsigned minor, int readonly)
32 {
33 struct vbd *vbd;
35 vbd = &blkif->vbd;
36 vbd->handle = handle;
37 vbd->readonly = readonly;
38 vbd->type = 0;
40 vbd->pdevice = MKDEV(major, minor);
42 vbd->bdev = open_by_devnum(
43 vbd->pdevice,
44 vbd->readonly ? FMODE_READ : FMODE_WRITE);
45 if (IS_ERR(vbd->bdev)) {
46 DPRINTK("vbd_creat: device %08x doesn't exist.\n",
47 vbd->pdevice);
48 return -ENOENT;
49 }
51 if (vbd->bdev->bd_disk == NULL) {
52 DPRINTK("vbd_creat: device %08x doesn't exist.\n",
53 vbd->pdevice);
54 vbd_free(vbd);
55 return -ENOENT;
56 }
58 if (vbd->bdev->bd_disk->flags & GENHD_FL_CD)
59 vbd->type |= VDISK_CDROM;
60 if (vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE)
61 vbd->type |= VDISK_REMOVABLE;
63 DPRINTK("Successful creation of handle=%04x (dom=%u)\n",
64 handle, blkif->domid);
65 return 0;
66 }
68 void vbd_free(struct vbd *vbd)
69 {
70 if (vbd->bdev)
71 blkdev_put(vbd->bdev);
72 vbd->bdev = NULL;
73 }
75 int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation)
76 {
77 struct vbd *vbd = &blkif->vbd;
78 int rc = -EACCES;
80 if ((operation == WRITE) && vbd->readonly)
81 goto out;
83 if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)))
84 goto out;
86 req->dev = vbd->pdevice;
87 req->bdev = vbd->bdev;
88 rc = 0;
90 out:
91 return rc;
92 }
94 /*
95 * Local variables:
96 * c-file-style: "linux"
97 * indent-tabs-mode: t
98 * c-indent-level: 8
99 * c-basic-offset: 8
100 * tab-width: 8
101 * End:
102 */