ia64/xen-unstable

view tools/ioemu/patches/xenstore-block-device-config @ 10950:955f02563a13

[qemu patches] Update patches for changeset 10921:4c2fab8f8c34.

Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author chris@kneesaa.uk.xensource.com
date Thu Aug 03 18:34:03 2006 +0100 (2006-08-03)
parents
children 7e914d9cd7e6
line source
1 Index: ioemu/Makefile.target
2 ===================================================================
3 --- ioemu.orig/Makefile.target 2006-08-03 17:57:38.861210420 +0100
4 +++ ioemu/Makefile.target 2006-08-03 17:58:02.317549891 +0100
5 @@ -336,6 +336,7 @@
6 VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o
7 VL_OBJS+= cirrus_vga.o mixeng.o parallel.o
8 VL_OBJS+= piix4acpi.o
9 +VL_OBJS+= xenstore.o
10 DEFINES += -DHAS_AUDIO
11 endif
12 ifeq ($(TARGET_BASE_ARCH), ppc)
13 Index: ioemu/xenstore.c
14 ===================================================================
15 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
16 +++ ioemu/xenstore.c 2006-08-03 17:58:02.326548870 +0100
17 @@ -0,0 +1,187 @@
18 +/*
19 + * This file is subject to the terms and conditions of the GNU General
20 + * Public License. See the file "COPYING" in the main directory of
21 + * this archive for more details.
22 + *
23 + * Copyright (C) 2006 Christian Limpach
24 + * Copyright (C) 2006 XenSource Ltd.
25 + *
26 + */
27 +
28 +#include "vl.h"
29 +#include "block_int.h"
30 +
31 +static struct xs_handle *xsh = NULL;
32 +static char *hd_filename[MAX_DISKS];
33 +static QEMUTimer *insert_timer = NULL;
34 +
35 +static int pasprintf(char **buf, const char *fmt, ...)
36 +{
37 + va_list ap;
38 + int ret = 0;
39 +
40 + if (*buf)
41 + free(*buf);
42 + va_start(ap, fmt);
43 + if (vasprintf(buf, fmt, ap) == -1) {
44 + buf = NULL;
45 + ret = -1;
46 + }
47 + va_end(ap);
48 + return ret;
49 +}
50 +
51 +static void insert_media(void *opaque)
52 +{
53 + int i;
54 +
55 + for (i = 0; i < MAX_DISKS; i++) {
56 + if (hd_filename[i]) {
57 + do_change(bs_table[i]->device_name, hd_filename[i]);
58 + free(hd_filename[i]);
59 + hd_filename[i] = NULL;
60 + }
61 + }
62 +}
63 +
64 +void xenstore_check_new_media_present(int timeout)
65 +{
66 +
67 + if (insert_timer == NULL)
68 + insert_timer = qemu_new_timer(rt_clock, insert_media, NULL);
69 + qemu_mod_timer(insert_timer, qemu_get_clock(rt_clock) + timeout);
70 +}
71 +
72 +void xenstore_parse_domain_config(int domid)
73 +{
74 + char **e = NULL;
75 + char *buf = NULL, *path;
76 + char *bpath = NULL, *dev = NULL, *params = NULL, *type = NULL;
77 + int i;
78 + unsigned int len, num, hd_index;
79 +
80 + for(i = 0; i < MAX_DISKS; i++)
81 + hd_filename[i] = NULL;
82 +
83 + xsh = xs_daemon_open();
84 + if (xsh == NULL) {
85 + fprintf(logfile, "Could not contact xenstore for domain config\n");
86 + return;
87 + }
88 +
89 + path = xs_get_domain_path(xsh, domid);
90 + if (path == NULL) {
91 + fprintf(logfile, "xs_get_domain_path() error\n");
92 + goto out;
93 + }
94 +
95 + if (pasprintf(&buf, "%s/device/vbd", path) == -1)
96 + goto out;
97 +
98 + e = xs_directory(xsh, XBT_NULL, buf, &num);
99 + if (e == NULL)
100 + goto out;
101 +
102 + for (i = 0; i < num; i++) {
103 + /* read the backend path */
104 + if (pasprintf(&buf, "%s/device/vbd/%s/backend", path, e[i]) == -1)
105 + continue;
106 + free(bpath);
107 + bpath = xs_read(xsh, XBT_NULL, buf, &len);
108 + if (bpath == NULL)
109 + continue;
110 + /* read the name of the device */
111 + if (pasprintf(&buf, "%s/dev", bpath) == -1)
112 + continue;
113 + free(dev);
114 + dev = xs_read(xsh, XBT_NULL, buf, &len);
115 + if (dev == NULL)
116 + continue;
117 + if (strncmp(dev, "hd", 2) || strlen(dev) != 3)
118 + continue;
119 + hd_index = dev[2] - 'a';
120 + if (hd_index > MAX_DISKS)
121 + continue;
122 + /* read the type of the device */
123 + if (pasprintf(&buf, "%s/device/vbd/%s/device-type", path, e[i]) == -1)
124 + continue;
125 + free(type);
126 + type = xs_read(xsh, XBT_NULL, buf, &len);
127 + /* read params to get the patch of the image -- read it last
128 + * so that we have its path in buf when setting up the
129 + * watch */
130 + if (pasprintf(&buf, "%s/params", bpath) == -1)
131 + continue;
132 + free(params);
133 + params = xs_read(xsh, XBT_NULL, buf, &len);
134 + if (params == NULL)
135 + continue;
136 + if (params[0]) {
137 + hd_filename[hd_index] = params; /* strdup() */
138 + params = NULL; /* don't free params on re-use */
139 + }
140 + bs_table[hd_index] = bdrv_new(dev);
141 + /* check if it is a cdrom */
142 + if (type && !strcmp(type, "cdrom")) {
143 + bdrv_set_type_hint(bs_table[hd_index], BDRV_TYPE_CDROM);
144 + xs_watch(xsh, buf, dev);
145 + }
146 + if (hd_filename[hd_index]) {
147 + if (bdrv_open(bs_table[hd_index], hd_filename[hd_index],
148 + 0 /* snapshot */) < 0)
149 + fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
150 + hd_filename[hd_index]);
151 + }
152 + }
153 +
154 + out:
155 + free(type);
156 + free(params);
157 + free(dev);
158 + free(bpath);
159 + free(buf);
160 + free(path);
161 + free(e);
162 + return;
163 +}
164 +
165 +int xenstore_fd(void)
166 +{
167 + if (xsh)
168 + return xs_fileno(xsh);
169 + return -1;
170 +}
171 +
172 +void xenstore_process_event(void *opaque)
173 +{
174 + char **vec, *image = NULL;
175 + unsigned int len, num, hd_index;
176 +
177 + vec = xs_read_watch(xsh, &num);
178 + if (!vec)
179 + return;
180 +
181 + if (strncmp(vec[XS_WATCH_TOKEN], "hd", 2) ||
182 + strlen(vec[XS_WATCH_TOKEN]) != 3)
183 + goto out;
184 + hd_index = vec[XS_WATCH_TOKEN][2] - 'a';
185 + image = xs_read(xsh, XBT_NULL, vec[XS_WATCH_PATH], &len);
186 + if (image == NULL || !strcmp(image, bs_table[hd_index]->filename))
187 + goto out; /* gone or identical */
188 +
189 + do_eject(0, vec[XS_WATCH_TOKEN]);
190 + bs_table[hd_index]->filename[0] = 0;
191 + if (hd_filename[hd_index]) {
192 + free(hd_filename[hd_index]);
193 + hd_filename[hd_index] = NULL;
194 + }
195 +
196 + if (image[0]) {
197 + hd_filename[hd_index] = strdup(image);
198 + xenstore_check_new_media_present(5000);
199 + }
200 +
201 + out:
202 + free(image);
203 + free(vec);
204 +}
205 Index: ioemu/vl.c
206 ===================================================================
207 --- ioemu.orig/vl.c 2006-08-03 17:57:38.867209740 +0100
208 +++ ioemu/vl.c 2006-08-03 17:58:02.323549210 +0100
209 @@ -4709,9 +4709,11 @@
210 "Standard options:\n"
211 "-M machine select emulated machine (-M ? for list)\n"
212 "-fda/-fdb file use 'file' as floppy disk 0/1 image\n"
213 +#ifndef CONFIG_DM
214 "-hda/-hdb file use 'file' as IDE hard disk 0/1 image\n"
215 "-hdc/-hdd file use 'file' as IDE hard disk 2/3 image\n"
216 "-cdrom file use 'file' as IDE cdrom image (cdrom is ide1 master)\n"
217 +#endif /* !CONFIG_DM */
218 "-boot [a|c|d] boot on floppy (a), hard disk (c) or CD-ROM (d)\n"
219 "-snapshot write to temporary files instead of disk image files\n"
220 "-m megs set virtual RAM size to megs MB [default=%d]\n"
221 @@ -4841,11 +4843,13 @@
222 QEMU_OPTION_M,
223 QEMU_OPTION_fda,
224 QEMU_OPTION_fdb,
225 +#ifndef CONFIG_DM
226 QEMU_OPTION_hda,
227 QEMU_OPTION_hdb,
228 QEMU_OPTION_hdc,
229 QEMU_OPTION_hdd,
230 QEMU_OPTION_cdrom,
231 +#endif /* !CONFIG_DM */
232 QEMU_OPTION_boot,
233 QEMU_OPTION_snapshot,
234 QEMU_OPTION_m,
235 @@ -4911,11 +4915,13 @@
236 { "M", HAS_ARG, QEMU_OPTION_M },
237 { "fda", HAS_ARG, QEMU_OPTION_fda },
238 { "fdb", HAS_ARG, QEMU_OPTION_fdb },
239 +#ifndef CONFIG_DM
240 { "hda", HAS_ARG, QEMU_OPTION_hda },
241 { "hdb", HAS_ARG, QEMU_OPTION_hdb },
242 { "hdc", HAS_ARG, QEMU_OPTION_hdc },
243 { "hdd", HAS_ARG, QEMU_OPTION_hdd },
244 { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
245 +#endif /* !CONFIG_DM */
246 { "boot", HAS_ARG, QEMU_OPTION_boot },
247 { "snapshot", 0, QEMU_OPTION_snapshot },
248 { "m", HAS_ARG, QEMU_OPTION_m },
249 @@ -5250,10 +5256,16 @@
250 #ifdef CONFIG_GDBSTUB
251 int use_gdbstub, gdbstub_port;
252 #endif
253 - int i, cdrom_index;
254 + int i;
255 +#ifndef CONFIG_DM
256 + int cdrom_index;
257 +#endif /* !CONFIG_DM */
258 int snapshot, linux_boot;
259 const char *initrd_filename;
260 - const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
261 +#ifndef CONFIG_DM
262 + const char *hd_filename[MAX_DISKS];
263 +#endif /* !CONFIG_DM */
264 + const char *fd_filename[MAX_FD];
265 const char *kernel_filename, *kernel_cmdline;
266 DisplayState *ds = &display_state;
267 int cyls, heads, secs, translation;
268 @@ -5288,8 +5300,10 @@
269 initrd_filename = NULL;
270 for(i = 0; i < MAX_FD; i++)
271 fd_filename[i] = NULL;
272 +#ifndef CONFIG_DM
273 for(i = 0; i < MAX_DISKS; i++)
274 hd_filename[i] = NULL;
275 +#endif /* !CONFIG_DM */
276 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
277 vga_ram_size = VGA_RAM_SIZE;
278 bios_size = BIOS_SIZE;
279 @@ -5302,11 +5316,13 @@
280 vncviewer = 0;
281 kernel_filename = NULL;
282 kernel_cmdline = "";
283 +#ifndef CONFIG_DM
284 #ifdef TARGET_PPC
285 cdrom_index = 1;
286 #else
287 cdrom_index = 2;
288 #endif
289 +#endif /* !CONFIG_DM */
290 cyls = heads = secs = 0;
291 translation = BIOS_ATA_TRANSLATION_AUTO;
292 pstrcpy(monitor_device, sizeof(monitor_device), "vc");
293 @@ -5339,7 +5355,11 @@
294 break;
295 r = argv[optind];
296 if (r[0] != '-') {
297 +#ifndef CONFIG_DM
298 hd_filename[0] = argv[optind++];
299 +#else
300 + help();
301 +#endif /* !CONFIG_DM */
302 } else {
303 const QEMUOption *popt;
305 @@ -5383,6 +5403,7 @@
306 case QEMU_OPTION_initrd:
307 initrd_filename = optarg;
308 break;
309 +#ifndef CONFIG_DM
310 case QEMU_OPTION_hda:
311 case QEMU_OPTION_hdb:
312 case QEMU_OPTION_hdc:
313 @@ -5395,6 +5416,7 @@
314 cdrom_index = -1;
315 }
316 break;
317 +#endif /* !CONFIG_DM */
318 case QEMU_OPTION_snapshot:
319 snapshot = 1;
320 break;
321 @@ -5447,11 +5469,13 @@
322 case QEMU_OPTION_append:
323 kernel_cmdline = optarg;
324 break;
325 +#ifndef CONFIG_DM
326 case QEMU_OPTION_cdrom:
327 if (cdrom_index >= 0) {
328 hd_filename[cdrom_index] = optarg;
329 }
330 break;
331 +#endif /* !CONFIG_DM */
332 case QEMU_OPTION_boot:
333 boot_device = optarg[0];
334 if (boot_device != 'a' &&
335 @@ -5690,12 +5714,18 @@
336 }
337 }
339 +#ifdef CONFIG_DM
340 + bdrv_init();
341 + xenstore_parse_domain_config(domid);
342 +#endif /* CONFIG_DM */
343 +
344 #ifdef USE_KQEMU
345 if (smp_cpus > 1)
346 kqemu_allowed = 0;
347 #endif
348 linux_boot = (kernel_filename != NULL);
350 +#ifndef CONFIG_DM
351 if (!linux_boot &&
352 hd_filename[0] == '\0' &&
353 (cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') &&
354 @@ -5709,6 +5739,7 @@
355 else
356 boot_device = 'd';
357 }
358 +#endif /* !CONFIG_DM */
360 #if !defined(CONFIG_SOFTMMU)
361 /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
362 @@ -5848,6 +5879,7 @@
364 #endif /* !CONFIG_DM */
366 +#ifndef CONFIG_DM
367 /* we always create the cdrom drive, even if no disk is there */
368 bdrv_init();
369 if (cdrom_index >= 0) {
370 @@ -5874,6 +5906,7 @@
371 }
372 }
373 }
374 +#endif /* !CONFIG_DM */
376 /* we always create at least one floppy disk */
377 fd_table[0] = bdrv_new("fda");
378 @@ -6009,6 +6042,8 @@
379 #endif
380 init_timers();
382 + qemu_set_fd_handler(xenstore_fd(), xenstore_process_event, NULL, NULL);
383 +
384 machine->init(ram_size, vga_ram_size, boot_device,
385 ds, fd_filename, snapshot,
386 kernel_filename, kernel_cmdline, initrd_filename,
387 Index: ioemu/monitor.c
388 ===================================================================
389 --- ioemu.orig/monitor.c 2006-08-03 17:57:38.864210080 +0100
390 +++ ioemu/monitor.c 2006-08-03 17:58:02.321549437 +0100
391 @@ -24,6 +24,7 @@
392 #include "vl.h"
393 #include "disas.h"
394 #include <dirent.h>
395 +#include "block_int.h"
397 //#define DEBUG
398 //#define DEBUG_COMPLETION
399 @@ -328,7 +329,7 @@
400 return 0;
401 }
403 -static void do_eject(int force, const char *filename)
404 +void do_eject(int force, const char *filename)
405 {
406 BlockDriverState *bs;
408 @@ -340,7 +341,7 @@
409 eject_device(bs, force);
410 }
412 -static void do_change(const char *device, const char *filename)
413 +void do_change(const char *device, const char *filename)
414 {
415 BlockDriverState *bs;
416 int i;
417 Index: ioemu/block.c
418 ===================================================================
419 --- ioemu.orig/block.c 2006-08-03 17:57:38.861210420 +0100
420 +++ ioemu/block.c 2006-08-03 17:58:02.318549777 +0100
421 @@ -750,6 +750,7 @@
422 static void raw_close(BlockDriverState *bs)
423 {
424 BDRVRawState *s = bs->opaque;
425 + bs->total_sectors = 0;
426 close(s->fd);
427 }
429 Index: ioemu/vl.h
430 ===================================================================
431 --- ioemu.orig/vl.h 2006-08-03 17:57:38.868209627 +0100
432 +++ ioemu/vl.h 2006-08-03 17:58:02.324549097 +0100
433 @@ -1092,6 +1092,8 @@
434 void term_print_help(void);
435 void monitor_readline(const char *prompt, int is_password,
436 char *buf, int buf_size);
437 +void do_eject(int force, const char *filename);
438 +void do_change(const char *device, const char *filename);
440 /* readline.c */
441 typedef void ReadLineFunc(void *opaque, const char *str);
442 @@ -1104,6 +1106,13 @@
443 void readline_start(const char *prompt, int is_password,
444 ReadLineFunc *readline_func, void *opaque);
446 +/* xenstore.c */
447 +void xenstore_parse_domain_config(int domid);
448 +int xenstore_fd(void);
449 +void xenstore_process_event(void *opaque);
450 +void xenstore_check_new_media_present(int timeout);
451 +
452 +
453 void kqemu_record_dump(void);
455 extern char domain_name[];
456 Index: ioemu/hw/ide.c
457 ===================================================================
458 --- ioemu.orig/hw/ide.c 2006-08-03 17:57:38.863210194 +0100
459 +++ ioemu/hw/ide.c 2006-08-03 17:58:02.319549664 +0100
460 @@ -1279,6 +1279,7 @@
461 } else {
462 ide_atapi_cmd_error(s, SENSE_NOT_READY,
463 ASC_MEDIUM_NOT_PRESENT);
464 + xenstore_check_new_media_present(1000);
465 }
466 break;
467 case GPCMD_MODE_SENSE_10: