ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/blkback/common.h @ 10029:019411cc3ae5

Fix blkif and netif backend teardown -- do not remove devices from
sysfs (and hence trigger hotplug callbacks) until the devices really
are dead. This fixes a bug where the deferred code to free a blk
device was running concurrently with a hotplug-remove callback which
would try to reclaim the underlying storage. In some cases the race
would be lost and the hotplug script would fail.

Thanks to the Zhu Han at Intel for finding the root cause of this
long-term and annoying bug!

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed May 10 13:27:17 2006 +0100 (2006-05-10)
parents 24d25894f071
children 48c0f5489d44
line source
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License version 2
4 * as published by the Free Software Foundation; or, when distributed
5 * separately from the Linux kernel or incorporated into other
6 * software packages, subject to the following license:
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this source file (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy, modify,
11 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
12 * and to permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * IN THE SOFTWARE.
25 */
27 #ifndef __BLKIF__BACKEND__COMMON_H__
28 #define __BLKIF__BACKEND__COMMON_H__
30 #include <linux/config.h>
31 #include <linux/version.h>
32 #include <linux/module.h>
33 #include <linux/interrupt.h>
34 #include <linux/slab.h>
35 #include <linux/blkdev.h>
36 #include <linux/vmalloc.h>
37 #include <linux/wait.h>
38 #include <asm/io.h>
39 #include <asm/setup.h>
40 #include <asm/pgalloc.h>
41 #include <xen/evtchn.h>
42 #include <asm/hypervisor.h>
43 #include <xen/interface/io/blkif.h>
44 #include <xen/interface/io/ring.h>
45 #include <xen/gnttab.h>
46 #include <xen/driver_util.h>
48 #define DPRINTK(_f, _a...) pr_debug("(file=%s, line=%d) " _f, \
49 __FILE__ , __LINE__ , ## _a )
51 struct vbd {
52 blkif_vdev_t handle; /* what the domain refers to this vbd as */
53 unsigned char readonly; /* Non-zero -> read-only */
54 unsigned char type; /* VDISK_xxx */
55 u32 pdevice; /* phys device that this vbd maps to */
56 struct block_device *bdev;
57 };
59 struct backend_info;
61 typedef struct blkif_st {
62 /* Unique identifier for this interface. */
63 domid_t domid;
64 unsigned int handle;
65 /* Physical parameters of the comms window. */
66 unsigned int evtchn;
67 unsigned int irq;
68 /* Comms information. */
69 blkif_back_ring_t blk_ring;
70 struct vm_struct *blk_ring_area;
71 /* The VBD attached to this interface. */
72 struct vbd vbd;
73 /* Back pointer to the backend_info. */
74 struct backend_info *be;
75 /* Private fields. */
76 #ifdef CONFIG_XEN_BLKDEV_TAP_BE
77 /* Is this a blktap frontend */
78 unsigned int is_blktap;
79 #endif
80 spinlock_t blk_ring_lock;
81 atomic_t refcnt;
83 wait_queue_head_t wq;
84 struct task_struct *xenblkd;
85 unsigned int waiting_reqs;
86 request_queue_t *plug;
88 /* statistics */
89 unsigned long st_print;
90 int st_rd_req;
91 int st_wr_req;
92 int st_oo_req;
94 wait_queue_head_t waiting_to_free;
96 grant_handle_t shmem_handle;
97 grant_ref_t shmem_ref;
98 } blkif_t;
100 blkif_t *blkif_alloc(domid_t domid);
101 void blkif_free(blkif_t *blkif);
102 int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn);
104 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
105 #define blkif_put(_b) \
106 do { \
107 if (atomic_dec_and_test(&(_b)->refcnt)) \
108 wake_up(&(_b)->waiting_to_free);\
109 } while (0)
111 /* Create a vbd. */
112 int vbd_create(blkif_t *blkif, blkif_vdev_t vdevice, unsigned major,
113 unsigned minor, int readonly);
114 void vbd_free(struct vbd *vbd);
116 unsigned long vbd_size(struct vbd *vbd);
117 unsigned int vbd_info(struct vbd *vbd);
118 unsigned long vbd_secsize(struct vbd *vbd);
120 struct phys_req {
121 unsigned short dev;
122 unsigned short nr_sects;
123 struct block_device *bdev;
124 blkif_sector_t sector_number;
125 };
127 int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation);
129 void blkif_interface_init(void);
131 void blkif_xenbus_init(void);
133 irqreturn_t blkif_be_int(int irq, void *dev_id, struct pt_regs *regs);
134 int blkif_schedule(void *arg);
136 #endif /* __BLKIF__BACKEND__COMMON_H__ */
138 /*
139 * Local variables:
140 * c-file-style: "linux"
141 * indent-tabs-mode: t
142 * c-indent-level: 8
143 * c-basic-offset: 8
144 * tab-width: 8
145 * End:
146 */