]> xenbits.xensource.com Git - xenclient/ioemu.git/commitdiff
support-hvm-pv-drivers-ioemu-support
authorJean Guyader <jean.guyader@eu.citrix.com>
Mon, 13 Oct 2008 13:00:32 +0000 (14:00 +0100)
committerJean Guyader <jean.guyader@eu.citrix.com>
Mon, 13 Oct 2008 13:01:33 +0000 (14:01 +0100)
hw/ide.c
hw/pci.c
qemu-xen.h
vl.c

index dae6e7f0d3251740387a2091625a1a91ebd01203..e752824a9513d598da1ba914908f5d86f70e6dde 100644 (file)
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -31,6 +31,7 @@
 #include "qemu-timer.h"
 #include "sysemu.h"
 #include "ppc_mac.h"
+#include "exec-all.h"
 
 /* debug IDE devices */
 //#define DEBUG_IDE
@@ -484,6 +485,8 @@ typedef struct PCIIDEState {
     int type; /* see IDE_TYPE_xxx */
 } PCIIDEState;
 
+static PCIIDEState *principal_ide_controller;
+
 
 #if defined(__ia64__)
 #include <xen/hvm/ioreq.h>
@@ -2778,6 +2781,27 @@ static void ide_reset(IDEState *s)
     s->media_changed = 0;
 }
 
+void ide_unplug_harddisks(void)
+{
+    IDEState *s;
+    int i;
+
+    if (!principal_ide_controller) {
+        fprintf(logfile, "No principal controller?\n");
+        return;
+    }
+    for (i = 0; i < 4; i++) {
+        s = principal_ide_controller->ide_if + i;
+        if (!s->bs)
+            continue; /* drive not present */
+        if (s->is_cdrom)
+            continue; /* cdrom */
+        /* Is a hard disk, unplug it. */
+        s->bs = NULL;
+        ide_reset(s);
+    }
+}
+
 struct partition {
        uint8_t boot_ind;               /* 0x80 - active */
        uint8_t head;           /* starting head */
@@ -3290,6 +3314,9 @@ void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
                                            sizeof(PCIIDEState),
                                            -1,
                                            NULL, NULL);
+    if (principal_ide_controller)
+       abort();
+    principal_ide_controller = d;
     d->type = IDE_TYPE_CMD646;
     pci_conf = d->dev.config;
     pci_conf[0x00] = 0x95; // CMD646
@@ -3419,6 +3446,9 @@ void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn,
                                            sizeof(PCIIDEState),
                                            devfn,
                                            NULL, NULL);
+    if (principal_ide_controller)
+       abort();
+    principal_ide_controller = d;
     d->type = IDE_TYPE_PIIX3;
 
     pci_conf = d->dev.config;
index 067fd0cfb15bd17fb3657aa766ac5906486dafd2..4a76bde356d9e56cd49ac692e51145493248978b 100644 (file)
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -664,6 +664,28 @@ void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn)
     }
 }
 
+void pci_unplug_netifs(void)
+{
+    PCIBus *bus;
+    int x;
+
+    /* We only support one PCI bus */
+    for (bus = first_bus; bus; bus = NULL) {
+       for (x = 0; x < 256; x++) {
+           if (bus->devices[x] &&
+               bus->devices[x]->config[0xa] == 0 &&
+               bus->devices[x]->config[0xb] == 2) {
+               /* Found a netif.  Remove it from the bus.  Note that
+                  we don't free it here, since there could still be
+                  references to it floating around.  There are only
+                  ever one or two structures leaked, and it's not
+                  worth finding them all. */
+               bus->devices[x] = NULL;
+           }
+       }
+    }
+}
+
 typedef struct {
     PCIDevice dev;
     PCIBus *bus;
index b7ace3d292e20af518ed112025233eb6afd3536d..3a4869b343c39564ae5d182f3ac097102060aa6a 100644 (file)
@@ -26,7 +26,9 @@ void xen_vga_populate_vram(uint64_t vram_addr);
 void xen_vga_vram_map(uint64_t vram_addr, int copy);
 #endif
 
-
+void ide_unplug_harddisks(void);
+void net_tap_shutdown_all(void);
+void pci_unplug_netifs(void);
 void destroy_hvm_domain(void);
 
 #ifdef __ia64__
diff --git a/vl.c b/vl.c
index e1ac89504016c2039ce02213fd928674fe07bb8b..eaf8cbebfabd10f57c355d3f9fe704789d123a52 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -266,6 +266,20 @@ static int event_pending = 1;
 
 void xenstore_dm_finished_startup(void);
 
+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;
+
 /***********************************************************/
 /* x86 ISA bus support */
 
@@ -4061,6 +4075,7 @@ void do_info_slirp(void)
 typedef struct TAPState {
     VLANClientState *vc;
     int fd;
+    struct TAPState *next;
     char down_script[1024];
     char script_arg[1024];
 } TAPState;
@@ -4098,6 +4113,34 @@ static void tap_send(void *opaque)
     }
 }
 
+static TAPState *head_net_tap;
+
+void net_tap_shutdown_all(void)
+{
+    struct IOHandlerRecord **pioh, *ioh;
+
+    while (head_net_tap) {
+       pioh = &first_io_handler;
+       for (;;) {
+           ioh = *pioh;
+           if (ioh == NULL)
+               break;
+           if (ioh->fd == head_net_tap->fd) {
+               *pioh = ioh->next;
+               qemu_free(ioh);
+               break;
+           }
+           pioh = &ioh->next;
+       }
+       if (!ioh)
+           fprintf(stderr,
+                   "warning: can't find iohandler for %d to close it properly.\n",
+                   head_net_tap->fd);
+       close(head_net_tap->fd);
+       head_net_tap = head_net_tap->next;
+    }
+}
+
 /* fd support */
 
 static TAPState *net_tap_fd_init(VLANState *vlan, int fd)
@@ -4109,6 +4152,8 @@ static TAPState *net_tap_fd_init(VLANState *vlan, int fd)
         return NULL;
     s->fd = fd;
     s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
+    s->next = head_net_tap;
+    head_net_tap = s;
     qemu_set_fd_handler(s->fd, tap_send, NULL, s);
     snprintf(s->vc->info_str, sizeof(s->vc->info_str), "tap: fd=%d", fd);
     return s;
@@ -5669,20 +5714,6 @@ static void dumb_display_init(DisplayState *ds)
 
 #define MAX_IO_HANDLERS 64
 
-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;
-
 /* XXX: fd_read_poll should be suppressed, but an API change is
    necessary in the character devices to suppress fd_can_read(). */
 int qemu_set_fd_handler2(int fd,