ia64/linux-2.6.18-xen.hg

annotate drivers/xen/blkback/vbd.c @ 869:271d9b9bee40

xen: miscellaneous cleanup

- add two missing unwind annotations
- mark remaining struct file_operations instances const
- use get_capacity() instead of raw access to the capacity field
- use assert_spin_locked() instead of BUG_ON(!spin_is_locked())
- use clear_tsk_thread_flag() instead of clear_ti_thread_flag()
- remove dead variable cpu_state

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu May 14 10:08:10 2009 +0100 (2009-05-14)
parents e5f0712d7520
children
rev   line source
ian@26 1 /******************************************************************************
ian@26 2 * blkback/vbd.c
ian@26 3 *
ian@26 4 * Routines for managing virtual block devices (VBDs).
ian@26 5 *
ian@26 6 * Copyright (c) 2003-2005, Keir Fraser & Steve Hand
ian@26 7 *
ian@26 8 * This program is free software; you can redistribute it and/or
ian@26 9 * modify it under the terms of the GNU General Public License version 2
ian@26 10 * as published by the Free Software Foundation; or, when distributed
ian@26 11 * separately from the Linux kernel or incorporated into other
ian@26 12 * software packages, subject to the following license:
ian@26 13 *
ian@26 14 * Permission is hereby granted, free of charge, to any person obtaining a copy
ian@26 15 * of this source file (the "Software"), to deal in the Software without
ian@26 16 * restriction, including without limitation the rights to use, copy, modify,
ian@26 17 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
ian@26 18 * and to permit persons to whom the Software is furnished to do so, subject to
ian@26 19 * the following conditions:
ian@26 20 *
ian@26 21 * The above copyright notice and this permission notice shall be included in
ian@26 22 * all copies or substantial portions of the Software.
ian@26 23 *
ian@26 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ian@26 25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ian@26 26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ian@26 27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ian@26 28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
ian@26 29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
ian@26 30 * IN THE SOFTWARE.
ian@26 31 */
ian@26 32
ian@26 33 #include "common.h"
ian@26 34
ian@26 35 #define vbd_sz(_v) ((_v)->bdev->bd_part ? \
keir@869 36 (_v)->bdev->bd_part->nr_sects : get_capacity((_v)->bdev->bd_disk))
ian@26 37
ian@26 38 unsigned long long vbd_size(struct vbd *vbd)
ian@26 39 {
ian@26 40 return vbd_sz(vbd);
ian@26 41 }
ian@26 42
ian@26 43 unsigned int vbd_info(struct vbd *vbd)
ian@26 44 {
ian@26 45 return vbd->type | (vbd->readonly?VDISK_READONLY:0);
ian@26 46 }
ian@26 47
ian@26 48 unsigned long vbd_secsize(struct vbd *vbd)
ian@26 49 {
ian@26 50 return bdev_hardsect_size(vbd->bdev);
ian@26 51 }
ian@26 52
ian@26 53 int vbd_create(blkif_t *blkif, blkif_vdev_t handle, unsigned major,
keir@521 54 unsigned minor, int readonly, int cdrom)
ian@26 55 {
ian@26 56 struct vbd *vbd;
ian@26 57 struct block_device *bdev;
ian@26 58
ian@26 59 vbd = &blkif->vbd;
ian@26 60 vbd->handle = handle;
ian@26 61 vbd->readonly = readonly;
ian@26 62 vbd->type = 0;
ian@26 63
ian@26 64 vbd->pdevice = MKDEV(major, minor);
ian@26 65
ian@26 66 bdev = open_by_devnum(vbd->pdevice,
ian@26 67 vbd->readonly ? FMODE_READ : FMODE_WRITE);
ian@26 68
ian@26 69 if (IS_ERR(bdev)) {
ian@26 70 DPRINTK("vbd_creat: device %08x could not be opened.\n",
ian@26 71 vbd->pdevice);
ian@26 72 return -ENOENT;
ian@26 73 }
ian@26 74
ian@26 75 vbd->bdev = bdev;
ian@26 76
ian@26 77 if (vbd->bdev->bd_disk == NULL) {
ian@26 78 DPRINTK("vbd_creat: device %08x doesn't exist.\n",
ian@26 79 vbd->pdevice);
ian@26 80 vbd_free(vbd);
ian@26 81 return -ENOENT;
ian@26 82 }
ian@26 83
keir@521 84 if (vbd->bdev->bd_disk->flags & GENHD_FL_CD || cdrom)
ian@26 85 vbd->type |= VDISK_CDROM;
ian@26 86 if (vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE)
ian@26 87 vbd->type |= VDISK_REMOVABLE;
ian@26 88
ian@26 89 DPRINTK("Successful creation of handle=%04x (dom=%u)\n",
ian@26 90 handle, blkif->domid);
ian@26 91 return 0;
ian@26 92 }
ian@26 93
ian@26 94 void vbd_free(struct vbd *vbd)
ian@26 95 {
ian@26 96 if (vbd->bdev)
ian@26 97 blkdev_put(vbd->bdev);
ian@26 98 vbd->bdev = NULL;
ian@26 99 }
ian@26 100
ian@26 101 int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation)
ian@26 102 {
ian@26 103 struct vbd *vbd = &blkif->vbd;
ian@26 104 int rc = -EACCES;
ian@26 105
ian@26 106 if ((operation != READ) && vbd->readonly)
ian@26 107 goto out;
ian@26 108
ian@26 109 if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)))
ian@26 110 goto out;
ian@26 111
ian@26 112 req->dev = vbd->pdevice;
ian@26 113 req->bdev = vbd->bdev;
ian@26 114 rc = 0;
ian@26 115
ian@26 116 out:
ian@26 117 return rc;
ian@26 118 }