WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] ioemu: Add tapdisk-ioemu tool

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] ioemu: Add tapdisk-ioemu tool
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 09 Apr 2008 06:50:11 -0700
Delivery-date: Wed, 09 Apr 2008 06:50:08 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1207651287 -3600
# Node ID e1962ac0fb1c03fe4e7d65130e75dd0670eccad6
# Parent  af1d20b86b02bf463690e8af61e77ddf169c4c6c
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@xxxxxxx>
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 .hgignore                   |    1 
 tools/ioemu/Makefile        |   11 ++-
 tools/ioemu/osdep.c         |    1 
 tools/ioemu/tapdisk-ioemu.c |  141 ++++++++++++++++++++++++++++++++++++++++++++
 tools/ioemu/vl.h            |    4 -
 5 files changed, 154 insertions(+), 4 deletions(-)

diff -r af1d20b86b02 -r e1962ac0fb1c .hgignore
--- a/.hgignore Tue Apr 08 09:57:37 2008 +0100
+++ b/.hgignore Tue Apr 08 11:41:27 2008 +0100
@@ -150,6 +150,7 @@
 ^tools/ioemu/qemu-tech\.html$
 ^tools/ioemu/qemu\.1$
 ^tools/ioemu/qemu\.pod$
+^tools/ioemu/tapdisk-ioemu$
 ^tools/libxc/ia64/asm/.*\.h$
 ^tools/libxc/ia64/acpi/.*\.h$
 ^tools/libxc/ia64/acpi/platform/.*\.h$
diff -r af1d20b86b02 -r e1962ac0fb1c tools/ioemu/Makefile
--- a/tools/ioemu/Makefile      Tue Apr 08 09:57:37 2008 +0100
+++ b/tools/ioemu/Makefile      Tue Apr 08 11:41:27 2008 +0100
@@ -35,7 +35,7 @@ endif
 endif
 endif
 
-TOOLS=
+TOOLS=tapdisk-ioemu
 
 all: $(TOOLS) $(DOCS) recurse-all
 
@@ -43,6 +43,13 @@ subdir-%:
        $(MAKE) -C $(subst subdir-,,$@) all
 
 recurse-all: $(patsubst %,subdir-%, $(TARGET_DIRS))
+
+tapdisk-ioemu: CPPFLAGS += -I$(XEN_ROOT)/tools/libxc
+tapdisk-ioemu: CPPFLAGS += -I$(XEN_ROOT)/tools/blktap/lib
+tapdisk-ioemu: CPPFLAGS += -I$(XEN_ROOT)/tools/xenstore
+tapdisk-ioemu: CPPFLAGS += -I$(XEN_ROOT)/tools/include
+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
+       $(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 @@ endif
 
 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 af1d20b86b02 -r e1962ac0fb1c tools/ioemu/osdep.c
--- a/tools/ioemu/osdep.c       Tue Apr 08 09:57:37 2008 +0100
+++ b/tools/ioemu/osdep.c       Tue Apr 08 11:41:27 2008 +0100
@@ -32,7 +32,6 @@
 #include <sys/statvfs.h>
 #endif
 
-#include "cpu.h"
 #if defined(USE_KQEMU)
 #include "vl.h"
 #endif
diff -r af1d20b86b02 -r e1962ac0fb1c tools/ioemu/tapdisk-ioemu.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/ioemu/tapdisk-ioemu.c       Tue Apr 08 11:41:27 2008 +0100
@@ -0,0 +1,141 @@
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <signal.h>
+
+#include <assert.h>
+
+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;
+}
diff -r af1d20b86b02 -r e1962ac0fb1c tools/ioemu/vl.h
--- a/tools/ioemu/vl.h  Tue Apr 08 09:57:37 2008 +0100
+++ b/tools/ioemu/vl.h  Tue Apr 08 11:41:27 2008 +0100
@@ -159,7 +159,7 @@ extern FILE *logfile;
 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);
@@ -1553,7 +1553,9 @@ void timeoffset_get(void);
 void timeoffset_get(void);
 
 /* xen_platform.c */
+#ifndef QEMU_TOOL
 void pci_xen_platform_init(PCIBus *bus);
+#endif
 
 
 void kqemu_record_dump(void);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] ioemu: Add tapdisk-ioemu tool, Xen patchbot-unstable <=