From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kevin Wolf Subject: [PATCH] Add tapdisk-ioemu tool Date: Tue, 08 Apr 2008 11:56:35 +0200 Message-ID: <47FB4153.5020805@suse.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030604030506030606040208" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------030604030506030606040208 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit 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 --------------030604030506030606040208 Content-Type: text/x-patch; name="tapdisk-ioemu.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="tapdisk-ioemu.patch" diff -r ed6bd8daa82b tools/ioemu/Makefile --- a/tools/ioemu/Makefile Tue Apr 1 13:52:44 2008 +++ b/tools/ioemu/Makefile Tue Apr 8 12:16:55 2008 @@ -16,6 +16,10 @@ BASE_CFLAGS += -mcpu=ultrasparc endif CPPFLAGS += -I. -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE +CPPFLAGS += -I$(XEN_ROOT)/tools/libxc +CPPFLAGS += -I$(XEN_ROOT)/tools/blktap/lib +CPPFLAGS += -I$(XEN_ROOT)/tools/xenstore +CPPFLAGS += -I$(XEN_ROOT)/tools/include LIBS= TOOLS=qemu-img$(EXESUF) ifdef CONFIG_STATIC @@ -35,7 +39,7 @@ endif endif -TOOLS= +TOOLS=tapdisk-ioemu all: $(TOOLS) $(DOCS) recurse-all @@ -43,6 +47,9 @@ $(MAKE) -C $(subst subdir-,,$@) all recurse-all: $(patsubst %,subdir-%, $(TARGET_DIRS)) + +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 + $(CC) -DQEMU_TOOL $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $(LDFLAGS) $(BASE_LDFLAGS) -o $@ $^ -lz $(LIBS) 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 $(CC) -DQEMU_TOOL $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $(LDFLAGS) $(BASE_LDFLAGS) -o $@ $^ -lz $(LIBS) @@ -80,7 +87,7 @@ install: all $(if $(BUILD_DOCS),install-doc) mkdir -p "$(DESTDIR)$(bindir)" -# $(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)" + $(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(prefix)/sbin" # mkdir -p "$(DESTDIR)$(datadir)" # for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \ # video.x openbios-sparc32 linux_boot.bin pxe-ne2k_pci.bin \ diff -r ed6bd8daa82b tools/ioemu/cutils.c --- a/tools/ioemu/cutils.c Tue Apr 1 13:52:44 2008 +++ b/tools/ioemu/cutils.c Tue Apr 8 12:16:55 2008 @@ -81,3 +81,38 @@ *ptr = p; return 1; } + +void *get_mmap_addr(unsigned long size) +{ + return NULL; +} + +void qemu_free(void *ptr) +{ + free(ptr); +} + +void *qemu_malloc(size_t size) +{ + return malloc(size); +} + +void *qemu_mallocz(size_t size) +{ + void *ptr; + ptr = qemu_malloc(size); + if (!ptr) + return NULL; + memset(ptr, 0, size); + return ptr; +} + +char *qemu_strdup(const char *str) +{ + char *ptr; + ptr = qemu_malloc(strlen(str) + 1); + if (!ptr) + return NULL; + strcpy(ptr, str); + return ptr; +} diff -r ed6bd8daa82b tools/ioemu/osdep.c --- a/tools/ioemu/osdep.c Tue Apr 1 13:52:44 2008 +++ b/tools/ioemu/osdep.c Tue Apr 8 12:16:55 2008 @@ -44,21 +44,6 @@ #else #include #endif - -void *get_mmap_addr(unsigned long size) -{ - return NULL; -} - -void qemu_free(void *ptr) -{ - free(ptr); -} - -void *qemu_malloc(size_t size) -{ - return malloc(size); -} #if defined(_WIN32) void *qemu_memalign(size_t alignment, size_t size) @@ -216,23 +201,3 @@ } #endif - -void *qemu_mallocz(size_t size) -{ - void *ptr; - ptr = qemu_malloc(size); - if (!ptr) - return NULL; - memset(ptr, 0, size); - return ptr; -} - -char *qemu_strdup(const char *str) -{ - char *ptr; - ptr = qemu_malloc(strlen(str) + 1); - if (!ptr) - return NULL; - strcpy(ptr, str); - return ptr; -} diff -r ed6bd8daa82b tools/ioemu/vl.h --- a/tools/ioemu/vl.h Tue Apr 1 13:52:44 2008 +++ b/tools/ioemu/vl.h Tue Apr 8 12:16:55 2008 @@ -159,7 +159,7 @@ extern FILE *logfile; -#if defined(__i386__) || defined(__x86_64__) +#if (defined(__i386__) || defined(__x86_64__)) && !defined(QEMU_TOOL) #define MAPCACHE uint8_t *qemu_map_cache(target_phys_addr_t phys_addr); void qemu_invalidate_map_cache(void); @@ -1552,7 +1552,9 @@ void timeoffset_get(void); /* xen_platform.c */ +#ifndef QEMU_TOOL void pci_xen_platform_init(PCIBus *bus); +#endif void kqemu_record_dump(void); diff -r ed6bd8daa82b tools/ioemu/tapdisk-ioemu.c --- /dev/null Tue Apr 1 13:52:44 2008 +++ b/tools/ioemu/tapdisk-ioemu.c Tue Apr 8 12:16:55 2008 @@ -0,0 +1,141 @@ +#include +#include +#include +#include +#include +#include + +#include + +extern int init_blktap(void); +extern void qemu_aio_init(void); +extern void qemu_aio_poll(void); +extern void bdrv_init(void); + +extern void *qemu_mallocz(size_t size); +extern void qemu_free(void *ptr); + +int domid = 0; +FILE* logfile; + +void term_printf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); +} + +void term_print_filename(const char *filename) +{ + term_printf(filename); +} + + +typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size); +typedef int IOCanRWHandler(void *opaque); +typedef void IOHandler(void *opaque); + +typedef struct IOHandlerRecord { + int fd; + IOCanRWHandler *fd_read_poll; + IOHandler *fd_read; + IOHandler *fd_write; + int deleted; + void *opaque; + /* temporary data */ + struct pollfd *ufd; + struct IOHandlerRecord *next; +} IOHandlerRecord; + +static IOHandlerRecord *first_io_handler; + +int qemu_set_fd_handler2(int fd, + IOCanRWHandler *fd_read_poll, + IOHandler *fd_read, + IOHandler *fd_write, + void *opaque) +{ + IOHandlerRecord *ioh; + + /* This is a stripped down version of fd handling */ + assert(fd_read_poll == NULL); + assert(fd_write == NULL); + + for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) + if (ioh->fd == fd) + goto found; + + if (!fd_read && !fd_write) + return 0; + + ioh = qemu_mallocz(sizeof(IOHandlerRecord)); + if (!ioh) + return -1; + ioh->next = first_io_handler; + first_io_handler = ioh; + +found: + if (!fd_read && !fd_write) { + ioh->deleted = 1; + } else { + ioh->fd = fd; + ioh->fd_read = fd_read; + ioh->opaque = opaque; + ioh->deleted = 0; + } + + return 0; +} + +int main(void) +{ + IOHandlerRecord *ioh, **pioh; + int max_fd; + fd_set rfds; + struct timeval tv; + + logfile = stderr; + + bdrv_init(); + qemu_aio_init(); + init_blktap(); + + /* + * Main loop: Pass events to the corrsponding handlers and check for + * completed aio operations. + */ + while (1) { + qemu_aio_poll(); + + max_fd = -1; + FD_ZERO(&rfds); + for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) + if (!ioh->deleted) { + FD_SET(ioh->fd, &rfds); + max_fd = max_fd > ioh->fd ? max_fd : ioh->fd; + } + + tv.tv_sec = 0; + tv.tv_usec = 10000; + if (select(max_fd + 1, &rfds, NULL, NULL, &tv) <= 0) + continue; + + /* Call handlers */ + for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) + if (FD_ISSET(ioh->fd, &rfds)) + ioh->fd_read(ioh->opaque); + + /* Remove deleted IO handlers */ + pioh = &first_io_handler; + while (*pioh) { + ioh = *pioh; + if (ioh->deleted) { + *pioh = ioh->next; + qemu_free(ioh); + } else + pioh = &ioh->next; + } + } + return 0; +} --------------030604030506030606040208 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------030604030506030606040208--