Contents of /trunk/kernel26-xen/patches-2.6.25-r1/1046-2.6.25-xen-blkback-cdrom.patch
Parent Directory | Revision Log
Revision 609 -
(show annotations)
(download)
Fri May 23 17:35:37 2008 UTC (16 years, 4 months ago) by niro
File size: 8772 byte(s)
Fri May 23 17:35:37 2008 UTC (16 years, 4 months ago) by niro
File size: 8772 byte(s)
-using opensuse xen patchset, updated kernel configs
1 | Subject: CDROM removable media-present attribute plus handling code |
2 | From: plc@novell.com |
3 | Patch-mainline: obsolete |
4 | References: 159907 |
5 | |
6 | Index: head-2007-10-15/drivers/xen/blkback/Makefile |
7 | =================================================================== |
8 | --- head-2007-10-15.orig/drivers/xen/blkback/Makefile 2007-10-22 10:47:58.000000000 +0200 |
9 | +++ head-2007-10-15/drivers/xen/blkback/Makefile 2007-08-07 10:14:50.000000000 +0200 |
10 | @@ -1,3 +1,3 @@ |
11 | obj-$(CONFIG_XEN_BLKDEV_BACKEND) := blkbk.o |
12 | |
13 | -blkbk-y := blkback.o xenbus.o interface.o vbd.o |
14 | +blkbk-y := blkback.o xenbus.o interface.o vbd.o cdrom.o |
15 | Index: head-2007-10-15/drivers/xen/blkback/cdrom.c |
16 | =================================================================== |
17 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 |
18 | +++ head-2007-10-15/drivers/xen/blkback/cdrom.c 2007-08-07 10:14:50.000000000 +0200 |
19 | @@ -0,0 +1,169 @@ |
20 | +/****************************************************************************** |
21 | + * blkback/cdrom.c |
22 | + * |
23 | + * Routines for managing cdrom watch and media-present attribute of a |
24 | + * cdrom type virtual block device (VBD). |
25 | + * |
26 | + * Copyright (c) 2003-2005, Keir Fraser & Steve Hand |
27 | + * Copyright (c) 2007 Pat Campbell |
28 | + * |
29 | + * This program is free software; you can redistribute it and/or |
30 | + * modify it under the terms of the GNU General Public License version 2 |
31 | + * as published by the Free Software Foundation; or, when distributed |
32 | + * separately from the Linux kernel or incorporated into other |
33 | + * software packages, subject to the following license: |
34 | + * |
35 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
36 | + * of this source file (the "Software"), to deal in the Software without |
37 | + * restriction, including without limitation the rights to use, copy, modify, |
38 | + * merge, publish, distribute, sublicense, and/or sell copies of the Software, |
39 | + * and to permit persons to whom the Software is furnished to do so, subject to |
40 | + * the following conditions: |
41 | + * |
42 | + * The above copyright notice and this permission notice shall be included in |
43 | + * all copies or substantial portions of the Software. |
44 | + * |
45 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
46 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
47 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
48 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
49 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
50 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
51 | + * IN THE SOFTWARE. |
52 | + */ |
53 | + |
54 | +#include "common.h" |
55 | + |
56 | +#undef DPRINTK |
57 | +#define DPRINTK(_f, _a...) \ |
58 | + printk("(%s() file=%s, line=%d) " _f "\n", \ |
59 | + __PRETTY_FUNCTION__, __FILE__ , __LINE__ , ##_a ) |
60 | + |
61 | + |
62 | +#define MEDIA_PRESENT "media-present" |
63 | + |
64 | +static void cdrom_media_changed(struct xenbus_watch *, const char **, unsigned int); |
65 | + |
66 | +/** |
67 | + * Writes media-present=1 attribute for the given vbd device if not |
68 | + * already there |
69 | + */ |
70 | +static int cdrom_xenstore_write_media_present(struct backend_info *be) |
71 | +{ |
72 | + struct xenbus_device *dev = be->dev; |
73 | + struct xenbus_transaction xbt; |
74 | + int err; |
75 | + int media_present; |
76 | + |
77 | + DPRINTK(" "); |
78 | + |
79 | + err = xenbus_scanf(XBT_NIL, dev->nodename, MEDIA_PRESENT, "%d", |
80 | + &media_present); |
81 | + if ( 0 < err) { |
82 | + DPRINTK("already written err%d", err); |
83 | + return(0); |
84 | + } |
85 | + media_present = 1; |
86 | + |
87 | +again: |
88 | + err = xenbus_transaction_start(&xbt); |
89 | + if (err) { |
90 | + xenbus_dev_fatal(dev, err, "starting transaction"); |
91 | + return(-1); |
92 | + } |
93 | + |
94 | + err = xenbus_printf(xbt, dev->nodename, MEDIA_PRESENT, "%d", media_present ); |
95 | + if (err) { |
96 | + xenbus_dev_fatal(dev, err, "writing %s/%s", |
97 | + dev->nodename, MEDIA_PRESENT); |
98 | + goto abort; |
99 | + } |
100 | + err = xenbus_transaction_end(xbt, 0); |
101 | + if (err == -EAGAIN) |
102 | + goto again; |
103 | + if (err) |
104 | + xenbus_dev_fatal(dev, err, "ending transaction"); |
105 | + return(0); |
106 | + abort: |
107 | + xenbus_transaction_end(xbt, 1); |
108 | + return(-1); |
109 | +} |
110 | + |
111 | +/** |
112 | + * |
113 | + */ |
114 | +int cdrom_is_type(struct backend_info *be) |
115 | +{ |
116 | + DPRINTK( "type:%x", be->blkif->vbd.type ); |
117 | + if ( be->blkif->vbd.type & VDISK_CDROM && be->blkif->vbd.type & GENHD_FL_REMOVABLE){ |
118 | + return(1); |
119 | + } |
120 | + return(0); |
121 | +} |
122 | + |
123 | +/** |
124 | + * |
125 | + */ |
126 | +void cdrom_add_media_watch(struct backend_info *be) |
127 | +{ |
128 | + struct xenbus_device *dev = be->dev; |
129 | + int err; |
130 | + |
131 | + DPRINTK( "nodename:%s", dev->nodename); |
132 | + if (cdrom_is_type(be)) { |
133 | + DPRINTK("is a cdrom"); |
134 | + if ( cdrom_xenstore_write_media_present(be) == 0 ) { |
135 | + DPRINTK( "xenstore wrote OK"); |
136 | + err = xenbus_watch_path2(dev, dev->nodename, MEDIA_PRESENT, |
137 | + &be->backend_cdrom_watch, cdrom_media_changed); |
138 | + if (err) { |
139 | + DPRINTK( "media_present watch add failed" ); |
140 | + } |
141 | + } |
142 | + } |
143 | +} |
144 | + |
145 | +/** |
146 | + * Callback received when the "media_present" xenstore node is changed |
147 | + */ |
148 | +static void cdrom_media_changed(struct xenbus_watch *watch, |
149 | + const char **vec, unsigned int len) |
150 | +{ |
151 | + int err; |
152 | + unsigned media_present; |
153 | + struct backend_info *be |
154 | + = container_of(watch, struct backend_info, backend_cdrom_watch); |
155 | + struct xenbus_device *dev = be->dev; |
156 | + |
157 | + DPRINTK(" "); |
158 | + |
159 | + if ( !(cdrom_is_type(be))) { |
160 | + DPRINTK("callback not for a cdrom" ); |
161 | + return; |
162 | + } |
163 | + |
164 | + err = xenbus_scanf(XBT_NIL, dev->nodename, MEDIA_PRESENT, "%d", |
165 | + &media_present); |
166 | + if (err == 0 || err == -ENOENT) { |
167 | + DPRINTK("xenbus_read of cdrom media_present node error:%d",err); |
168 | + return; |
169 | + } |
170 | + |
171 | + if (media_present == 0) { |
172 | + vbd_free(&be->blkif->vbd); |
173 | + } |
174 | + else { |
175 | + char *p = strrchr(dev->otherend, '/') + 1; |
176 | + long handle = simple_strtoul(p, NULL, 0); |
177 | + |
178 | + if (be->blkif->vbd.bdev == NULL) { |
179 | + err = vbd_create(be->blkif, handle, be->major, be->minor, |
180 | + (NULL == strchr(be->mode, 'w'))); |
181 | + if (err) { |
182 | + be->major = be->minor = 0; |
183 | + xenbus_dev_fatal(dev, err, "creating vbd structure"); |
184 | + return; |
185 | + } |
186 | + } |
187 | + } |
188 | +} |
189 | Index: head-2007-10-15/drivers/xen/blkback/common.h |
190 | =================================================================== |
191 | --- head-2007-10-15.orig/drivers/xen/blkback/common.h 2007-10-19 16:00:18.000000000 +0200 |
192 | +++ head-2007-10-15/drivers/xen/blkback/common.h 2007-10-19 16:03:26.000000000 +0200 |
193 | @@ -96,6 +96,17 @@ typedef struct blkif_st { |
194 | grant_ref_t shmem_ref; |
195 | } blkif_t; |
196 | |
197 | +struct backend_info |
198 | +{ |
199 | + struct xenbus_device *dev; |
200 | + blkif_t *blkif; |
201 | + struct xenbus_watch backend_watch; |
202 | + struct xenbus_watch backend_cdrom_watch; |
203 | + unsigned major; |
204 | + unsigned minor; |
205 | + char *mode; |
206 | +}; |
207 | + |
208 | blkif_t *blkif_alloc(domid_t domid); |
209 | void blkif_disconnect(blkif_t *blkif); |
210 | void blkif_free(blkif_t *blkif); |
211 | @@ -136,4 +147,8 @@ int blkif_schedule(void *arg); |
212 | int blkback_barrier(struct xenbus_transaction xbt, |
213 | struct backend_info *be, int state); |
214 | |
215 | +/* cdrom media change */ |
216 | +int cdrom_is_type(struct backend_info *be); |
217 | +void cdrom_add_media_watch(struct backend_info *be); |
218 | + |
219 | #endif /* __BLKIF__BACKEND__COMMON_H__ */ |
220 | Index: head-2007-10-15/drivers/xen/blkback/vbd.c |
221 | =================================================================== |
222 | --- head-2007-10-15.orig/drivers/xen/blkback/vbd.c 2007-10-22 10:47:58.000000000 +0200 |
223 | +++ head-2007-10-15/drivers/xen/blkback/vbd.c 2007-08-07 10:14:50.000000000 +0200 |
224 | @@ -106,6 +106,9 @@ int vbd_translate(struct phys_req *req, |
225 | if ((operation != READ) && vbd->readonly) |
226 | goto out; |
227 | |
228 | + if (vbd->bdev == NULL) |
229 | + goto out; |
230 | + |
231 | if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd))) |
232 | goto out; |
233 | |
234 | Index: head-2007-10-15/drivers/xen/blkback/xenbus.c |
235 | =================================================================== |
236 | --- head-2007-10-15.orig/drivers/xen/blkback/xenbus.c 2007-10-22 10:50:20.000000000 +0200 |
237 | +++ head-2007-10-15/drivers/xen/blkback/xenbus.c 2007-10-22 10:50:35.000000000 +0200 |
238 | @@ -28,16 +28,6 @@ |
239 | pr_debug("blkback/xenbus (%s:%d) " fmt ".\n", \ |
240 | __FUNCTION__, __LINE__, ##args) |
241 | |
242 | -struct backend_info |
243 | -{ |
244 | - struct xenbus_device *dev; |
245 | - blkif_t *blkif; |
246 | - struct xenbus_watch backend_watch; |
247 | - unsigned major; |
248 | - unsigned minor; |
249 | - char *mode; |
250 | -}; |
251 | - |
252 | static void connect(struct backend_info *); |
253 | static int connect_ring(struct backend_info *); |
254 | static void backend_changed(struct xenbus_watch *, const char **, |
255 | @@ -183,6 +173,12 @@ static int blkback_remove(struct xenbus_ |
256 | be->backend_watch.node = NULL; |
257 | } |
258 | |
259 | + if (be->backend_cdrom_watch.node) { |
260 | + unregister_xenbus_watch(&be->backend_cdrom_watch); |
261 | + kfree(be->backend_cdrom_watch.node); |
262 | + be->backend_cdrom_watch.node = NULL; |
263 | + } |
264 | + |
265 | if (be->blkif) { |
266 | blkif_disconnect(be->blkif); |
267 | vbd_free(&be->blkif->vbd); |
268 | @@ -331,6 +327,9 @@ static void backend_changed(struct xenbu |
269 | |
270 | /* We're potentially connected now */ |
271 | update_blkif_status(be->blkif); |
272 | + |
273 | + /* Add watch for cdrom media status if necessay */ |
274 | + cdrom_add_media_watch(be); |
275 | } |
276 | } |
277 |