Device model unplug version 2:
PATCH 1/1 Device model unplug version 2:
# HG changeset patch
# User Paul Durrant <[email protected]> # Date 1275491143 -3600
# Node ID 636a452b175a75c79c711760846f7965cb53f14c # Parent 166d7745fdaae8b7f1d77e024c64e5709ffc11d2 Device model unplug version 2:
Version 2 of the interface allows unplugging of individual IDE disks and/or PCI NICs. IO ports 11 and 13 are used to control unplugging. A byte write to port 11 sets the unplug type (1 == IDE, 2 == NIC) and then a subsequent byte write to port 13 tells qemu which device of the current type to unplug.
hw/ide.c +33 -21
@@ -3073,45 +3073,57 @@/* Unplug all of the IDE hard disks, starting at index @start in the table. */ -static void _ide_unplug_harddisks (int start) +void ide_unplug_harddisk (int i) {IDEState *s; -int i, j; +int j;if (!principal_ide_controller) {fprintf (stderr,"No principal controller?\n" );return ; } +/* wait for outstanding aio requests */ qemu_aio_flush (); -for (i = start; 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. */ -for (j =0 ; j < nb_drives; j++) -if (drives_table[j].bdrv == s->bs) - drives_table[j].bdrv =NULL ; -bdrv_flush (s->bs); -bdrv_close (s->bs); - s->bs =NULL ; -ide_reset (s); - } + + s = principal_ide_controller->ide_if + i; +if (!s->bs) +return ;/* drive not present */ + +if (s->is_cdrom) +return ;/* cdrom */ + +/* Is a hard disk, unplug it. */ +for (j =0 ; j < nb_drives; j++) { +if (drives_table[j].bdrv == s->bs) { +fprintf (stderr,"%s: drive %d\n" , __func__, i, j); + drives_table[j].bdrv =NULL ; + } + } + +bdrv_flush (s->bs); +bdrv_close (s->bs); + s->bs =NULL ; +ide_reset (s); }/* Unplug all hard disks except for the primary master (which will almost always be the boot device). */ void ide_unplug_aux_harddisks (void ) { -_ide_unplug_harddisks (1 ); +int i; + +for (i =1 ; i <4 ; i++) +ide_unplug_harddisk (i); }/* Unplug all hard disks, including the boot device. */ -void ide_unplug_harddisks (void ) -{ -_ide_unplug_harddisks (0 ); +void ide_unplug_all_harddisks (void ) +{ +int i; + +for (i =0 ; i <4 ; i++) +ide_unplug_harddisk (i); } static void ide_init2(IDEState *ide_state,
hw/pc.h +2 -1
@@ -162,7 +162,8 @@ qemu_irq *pic);void pci_piix4_ide_init (PCIBus *bus,BlockDriverState **hd_table,int devfn,qemu_irq *pic); -void ide_unplug_harddisks (void ); +void ide_unplug_harddisk (int i); +void ide_unplug_all_harddisks (void );void ide_unplug_aux_harddisks (void );/* ne2000.c */
hw/pci.c +59 -32
110 lines not on this page · raw message
hw/pci.h +1 -0
@@ -268,6 +268,7 @@PCIDevice *pci_nic_init (PCIBus *bus,NICInfo *nd,int devfn,const char *default_model); +void pci_dev_unplug (PCIDevice *dev);void pci_data_write (void *opaque,uint32_t addr,uint32_t val,int len);uint32_t pci_data_read (void *opaque,uint32_t addr,int len);int pci_bus_num (PCIBus *s);
hw/xen_platform.c +32 -6
@@ -49,6 +49,11 @@ {PCIDevice pci_dev; } PCIXenPlatformState; + +static uint8_t unplug_type; + +#define UNPLUG_TYPE_IDE 0x01 +#define UNPLUG_TYPE_NIC 0x02/* We throttle access to dom0 syslog, to avoid DOS attacks. This is modelled as a token bucket, with one token for every byte of log.
@@ -144,9 +149,9 @@unplug, with bit 0 the IDE devices, bit 1 the network devices, and bit 2 the non-primary-master IDE devices. */ if (val &UNPLUG_ALL_IDE_DISKS ) -ide_unplug_harddisks (); +ide_unplug_all_harddisks ();if (val &UNPLUG_ALL_NICS ) { -pci_unplug_netifs (); +pci_unplug_all_netifs ();net_tap_shutdown_all (); }if (val &UNPLUG_AUX_IDE_DISKS ) {
@@ -192,7 +197,8 @@ } } -static void platform_fixed_ioport_write1 (void *opaque,uint32_t addr,uint32_t val) +static void platform_fixed_ioport_write1 (void *opaque,uint32_t addr, +uint32_t val) {switch (addr -0x10 ) {case 0 :/* Platform flags */ {
@@ -209,8 +215,10 @@ }break ; } -case 2 : -/* Send bytes to syslog */ +case 1 :/* Unplug type */ + unplug_type = (uint8_t )val; +break ; +case 2 :/* Send bytes to syslog */ if (val =='\n' || log_buffer_off ==sizeof (log_buffer) -1 ) {/* Flush buffer */ log_buffer[log_buffer_off] =0 ;
@@ -221,6 +229,24 @@ } log_buffer[log_buffer_off++] = val;break ; +case 3 :/* Unplug index */ +switch (unplug_type) { +case UNPLUG_TYPE_IDE : +ide_unplug_harddisk (val); +break ; +case UNPLUG_TYPE_NIC : { +int id; + +if ((id =pci_unplug_nic (val)) >=0 ) +net_tap_shutdown_vlan (id); + +break ; + } +default : +fprintf (logfile,"unrecognized unplug type %02x\n" , + unplug_type); +break ; + } } }
@@ -249,7 +275,7 @@return platform_flags;case 2 :/* Version number */ -return 1 ; +return 2 ;default :return 0xff ; }
i386-dm/helper2.c +2 -2
@@ -580,8 +580,8 @@do_savevm (qemu_file);free (qemu_file); -ide_unplug_harddisks (); -pci_unplug_netifs (); +ide_unplug_all_harddisks (); +pci_unplug_all_netifs ();net_tap_shutdown_all ();xenstore_record_dm_state ("paused" );
net.c +28 -5
@@ -1992,13 +1992,36 @@ } } +static void net_tap_shutdown (struct TAPState *tap) +{ +VLANClientState *vc = tap->vc; + +fprintf (stderr,"%s: model=%s,name=%s\n" , __func__, vc->model, vc->name); + +qemu_set_fd_handler2 (tap->fd,0 ,0 ,0 ,0 ); +close (tap->fd); +} +void net_tap_shutdown_all (void ) { -struct IOHandlerRecord **pioh, *ioh; +struct TAPState *tap; -while (head_net_tap) { -qemu_set_fd_handler2 (head_net_tap->fd,0 ,0 ,0 ,0 ); -close (head_net_tap->fd); - head_net_tap = head_net_tap->next; +for (tap = head_net_tap; tap; tap = tap->next) +net_tap_shutdown (tap); +} + +void net_tap_shutdown_vlan (int id) +{ +struct TAPState *tap; + +for (tap = head_net_tap; tap; tap = tap->next) { +VLANClientState *vc = tap->vc; +VLANState *vlan = vc->vlan; + +if (vlan->id != id) +continue ; + +net_tap_shutdown (tap); } } +
net.h +1 -0
@@ -103,6 +103,7 @@int slirp_is_inited (void );void net_client_check (void );void net_tap_shutdown_all (void ); +void net_tap_shutdown_vlan (int id);void net_host_device_add (const char *device,const char *opts);void net_host_device_remove (int vlan_id,const char *device);
qemu-xen.h +2 -1
@@ -46,7 +46,8 @@void unset_vram_mapping (void *opaque);#endif -void pci_unplug_netifs (void ); +void pci_unplug_all_netifs (void ); +int pci_unplug_nic (int i);void destroy_hvm_domain (void );void unregister_iomem (target_phys_addr_t start);