ia64/xen-unstable
changeset 17405:e1962ac0fb1c
ioemu: Add tapdisk-ioemu tool
Currently, tap:ioemu can only be used for domains which have a device
model running. This isn't the case for all domains. The most important
of the missing domains is Dom0 which needs acces e.g. to extract the
kernel from the domain's image.
tapdisk-ioemu is a tool compiled from ioemu source plus a small
wrapper which handles tap:ioemu access for domains without device
model (currently Dom0). You must start tapdisk-ioemu manually before
trying to attach a tap:ioemu disk to Dom0 at the moment. A patch to
blktapctrl will follow to automatically start tapdisk-ioemu when
needed.
Signed-off-by: Kevin Wolf <kwolf@suse.de>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
Currently, tap:ioemu can only be used for domains which have a device
model running. This isn't the case for all domains. The most important
of the missing domains is Dom0 which needs acces e.g. to extract the
kernel from the domain's image.
tapdisk-ioemu is a tool compiled from ioemu source plus a small
wrapper which handles tap:ioemu access for domains without device
model (currently Dom0). You must start tapdisk-ioemu manually before
trying to attach a tap:ioemu disk to Dom0 at the moment. A patch to
blktapctrl will follow to automatically start tapdisk-ioemu when
needed.
Signed-off-by: Kevin Wolf <kwolf@suse.de>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Tue Apr 08 11:41:27 2008 +0100 (2008-04-08) |
parents | af1d20b86b02 |
children | 9b635405ef90 |
files | .hgignore tools/ioemu/Makefile tools/ioemu/osdep.c tools/ioemu/tapdisk-ioemu.c tools/ioemu/vl.h |
line diff
1.1 --- a/.hgignore Tue Apr 08 09:57:37 2008 +0100 1.2 +++ b/.hgignore Tue Apr 08 11:41:27 2008 +0100 1.3 @@ -150,6 +150,7 @@ 1.4 ^tools/ioemu/qemu-tech\.html$ 1.5 ^tools/ioemu/qemu\.1$ 1.6 ^tools/ioemu/qemu\.pod$ 1.7 +^tools/ioemu/tapdisk-ioemu$ 1.8 ^tools/libxc/ia64/asm/.*\.h$ 1.9 ^tools/libxc/ia64/acpi/.*\.h$ 1.10 ^tools/libxc/ia64/acpi/platform/.*\.h$
2.1 --- a/tools/ioemu/Makefile Tue Apr 08 09:57:37 2008 +0100 2.2 +++ b/tools/ioemu/Makefile Tue Apr 08 11:41:27 2008 +0100 2.3 @@ -35,7 +35,7 @@ endif 2.4 endif 2.5 endif 2.6 2.7 -TOOLS= 2.8 +TOOLS=tapdisk-ioemu 2.9 2.10 all: $(TOOLS) $(DOCS) recurse-all 2.11 2.12 @@ -44,6 +44,13 @@ subdir-%: 2.13 2.14 recurse-all: $(patsubst %,subdir-%, $(TARGET_DIRS)) 2.15 2.16 +tapdisk-ioemu: CPPFLAGS += -I$(XEN_ROOT)/tools/libxc 2.17 +tapdisk-ioemu: CPPFLAGS += -I$(XEN_ROOT)/tools/blktap/lib 2.18 +tapdisk-ioemu: CPPFLAGS += -I$(XEN_ROOT)/tools/xenstore 2.19 +tapdisk-ioemu: CPPFLAGS += -I$(XEN_ROOT)/tools/include 2.20 +tapdisk-ioemu: tapdisk-ioemu.c cutils.c block.c block-raw.c block-cow.c block-qcow.c aes.c block-vmdk.c block-cloop.c block-dmg.c block-bochs.c block-vpc.c block-vvfat.c block-qcow2.c hw/xen_blktap.c osdep.c 2.21 + $(CC) -DQEMU_TOOL $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $(LDFLAGS) $(BASE_LDFLAGS) -o $@ $^ -lz $(LIBS) 2.22 + 2.23 qemu-img$(EXESUF): qemu-img.c cutils.c block.c block-raw.c block-cow.c block-qcow.c aes.c block-vmdk.c block-cloop.c block-dmg.c block-bochs.c block-vpc.c block-vvfat.c block-qcow2.c 2.24 $(CC) -DQEMU_TOOL $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $(LDFLAGS) $(BASE_LDFLAGS) -o $@ $^ -lz $(LIBS) 2.25 2.26 @@ -80,7 +87,7 @@ endif 2.27 2.28 install: all $(if $(BUILD_DOCS),install-doc) 2.29 mkdir -p "$(DESTDIR)$(bindir)" 2.30 -# $(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)" 2.31 + $(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(prefix)/sbin" 2.32 # mkdir -p "$(DESTDIR)$(datadir)" 2.33 # for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \ 2.34 # video.x openbios-sparc32 linux_boot.bin pxe-ne2k_pci.bin \
3.1 --- a/tools/ioemu/osdep.c Tue Apr 08 09:57:37 2008 +0100 3.2 +++ b/tools/ioemu/osdep.c Tue Apr 08 11:41:27 2008 +0100 3.3 @@ -32,7 +32,6 @@ 3.4 #include <sys/statvfs.h> 3.5 #endif 3.6 3.7 -#include "cpu.h" 3.8 #if defined(USE_KQEMU) 3.9 #include "vl.h" 3.10 #endif
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/tools/ioemu/tapdisk-ioemu.c Tue Apr 08 11:41:27 2008 +0100 4.3 @@ -0,0 +1,141 @@ 4.4 +#include <stdlib.h> 4.5 +#include <stdarg.h> 4.6 +#include <stdio.h> 4.7 +#include <string.h> 4.8 +#include <stdint.h> 4.9 +#include <signal.h> 4.10 + 4.11 +#include <assert.h> 4.12 + 4.13 +extern int init_blktap(void); 4.14 +extern void qemu_aio_init(void); 4.15 +extern void qemu_aio_poll(void); 4.16 +extern void bdrv_init(void); 4.17 + 4.18 +extern void *qemu_mallocz(size_t size); 4.19 +extern void qemu_free(void *ptr); 4.20 + 4.21 +int domid = 0; 4.22 +FILE* logfile; 4.23 + 4.24 +void term_printf(const char *fmt, ...) 4.25 +{ 4.26 + va_list ap; 4.27 + va_start(ap, fmt); 4.28 + vprintf(fmt, ap); 4.29 + va_end(ap); 4.30 +} 4.31 + 4.32 +void term_print_filename(const char *filename) 4.33 +{ 4.34 + term_printf(filename); 4.35 +} 4.36 + 4.37 + 4.38 +typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size); 4.39 +typedef int IOCanRWHandler(void *opaque); 4.40 +typedef void IOHandler(void *opaque); 4.41 + 4.42 +typedef struct IOHandlerRecord { 4.43 + int fd; 4.44 + IOCanRWHandler *fd_read_poll; 4.45 + IOHandler *fd_read; 4.46 + IOHandler *fd_write; 4.47 + int deleted; 4.48 + void *opaque; 4.49 + /* temporary data */ 4.50 + struct pollfd *ufd; 4.51 + struct IOHandlerRecord *next; 4.52 +} IOHandlerRecord; 4.53 + 4.54 +static IOHandlerRecord *first_io_handler; 4.55 + 4.56 +int qemu_set_fd_handler2(int fd, 4.57 + IOCanRWHandler *fd_read_poll, 4.58 + IOHandler *fd_read, 4.59 + IOHandler *fd_write, 4.60 + void *opaque) 4.61 +{ 4.62 + IOHandlerRecord *ioh; 4.63 + 4.64 + /* This is a stripped down version of fd handling */ 4.65 + assert(fd_read_poll == NULL); 4.66 + assert(fd_write == NULL); 4.67 + 4.68 + for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) 4.69 + if (ioh->fd == fd) 4.70 + goto found; 4.71 + 4.72 + if (!fd_read && !fd_write) 4.73 + return 0; 4.74 + 4.75 + ioh = qemu_mallocz(sizeof(IOHandlerRecord)); 4.76 + if (!ioh) 4.77 + return -1; 4.78 + ioh->next = first_io_handler; 4.79 + first_io_handler = ioh; 4.80 + 4.81 +found: 4.82 + if (!fd_read && !fd_write) { 4.83 + ioh->deleted = 1; 4.84 + } else { 4.85 + ioh->fd = fd; 4.86 + ioh->fd_read = fd_read; 4.87 + ioh->opaque = opaque; 4.88 + ioh->deleted = 0; 4.89 + } 4.90 + 4.91 + return 0; 4.92 +} 4.93 + 4.94 +int main(void) 4.95 +{ 4.96 + IOHandlerRecord *ioh, **pioh; 4.97 + int max_fd; 4.98 + fd_set rfds; 4.99 + struct timeval tv; 4.100 + 4.101 + logfile = stderr; 4.102 + 4.103 + bdrv_init(); 4.104 + qemu_aio_init(); 4.105 + init_blktap(); 4.106 + 4.107 + /* 4.108 + * Main loop: Pass events to the corrsponding handlers and check for 4.109 + * completed aio operations. 4.110 + */ 4.111 + while (1) { 4.112 + qemu_aio_poll(); 4.113 + 4.114 + max_fd = -1; 4.115 + FD_ZERO(&rfds); 4.116 + for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) 4.117 + if (!ioh->deleted) { 4.118 + FD_SET(ioh->fd, &rfds); 4.119 + max_fd = max_fd > ioh->fd ? max_fd : ioh->fd; 4.120 + } 4.121 + 4.122 + tv.tv_sec = 0; 4.123 + tv.tv_usec = 10000; 4.124 + if (select(max_fd + 1, &rfds, NULL, NULL, &tv) <= 0) 4.125 + continue; 4.126 + 4.127 + /* Call handlers */ 4.128 + for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) 4.129 + if (FD_ISSET(ioh->fd, &rfds)) 4.130 + ioh->fd_read(ioh->opaque); 4.131 + 4.132 + /* Remove deleted IO handlers */ 4.133 + pioh = &first_io_handler; 4.134 + while (*pioh) { 4.135 + ioh = *pioh; 4.136 + if (ioh->deleted) { 4.137 + *pioh = ioh->next; 4.138 + qemu_free(ioh); 4.139 + } else 4.140 + pioh = &ioh->next; 4.141 + } 4.142 + } 4.143 + return 0; 4.144 +}
5.1 --- a/tools/ioemu/vl.h Tue Apr 08 09:57:37 2008 +0100 5.2 +++ b/tools/ioemu/vl.h Tue Apr 08 11:41:27 2008 +0100 5.3 @@ -159,7 +159,7 @@ extern void *shared_vram; 5.4 extern FILE *logfile; 5.5 5.6 5.7 -#if defined(__i386__) || defined(__x86_64__) 5.8 +#if (defined(__i386__) || defined(__x86_64__)) && !defined(QEMU_TOOL) 5.9 #define MAPCACHE 5.10 uint8_t *qemu_map_cache(target_phys_addr_t phys_addr); 5.11 void qemu_invalidate_map_cache(void); 5.12 @@ -1553,7 +1553,9 @@ extern long time_offset; 5.13 void timeoffset_get(void); 5.14 5.15 /* xen_platform.c */ 5.16 +#ifndef QEMU_TOOL 5.17 void pci_xen_platform_init(PCIBus *bus); 5.18 +#endif 5.19 5.20 5.21 void kqemu_record_dump(void);