IDE and live migration fun
cover IDE and live migration fun
Patch 1 describes the real problem that I was going to solve. While fixing this, I stumbled across some more migration problems that are included in this series. Some refactoring is still left to do after this, but I'd prefer to keep this series with the hard stuff short.
This is the test case that I was using:
$ cat blkdebug.conf [inject-error] state = "2" event = "read_aio" errno = "7" immediately = "off" once = "on"
[set-state]
state = "1"
event = "read_aio"new_state = "2"
[set-state]
state = "2"
event = "read_aio"new_state = "3"
$ x86_64-softmmu/qemu-system-x86_64 -drive file=blkdebug:blkdebug.conf:disk.qcow2,rerror=stop,werror=stop -incoming tcp::1028 $ x86_64-softmmu/qemu-system-x86_64 -drive file=blkdebug:blkdebug.conf:disk.qcow2,rerror=stop,werror=stop (qemu) migrate tcp::1028
Please note that you need to use a qcow2 image, or the blkdebug events won't be triggered. Expected result: The very first read from the disk (BIOS reading the MBR) fails and stops the VM. I migrate while the VM is stopped, so that the request is queued for resubmission. After continuing, the VM should work just as normal.
Kevin Wolf (3):
ide: Split error status from status register
ide: Fix ide_drive_pio_state_needed()
ide: Add forgotten VMSTATE_END_OF_LIST in subsection
hw/ide/core.c | 32 +++++++++++++++++++++- hw/ide/internal.h | 8 ++++++ hw/ide/pci.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++----- hw/ide/pci.h | 4 +++ 4 files changed, 108 insertions(+), 9 deletions(-)
Signature · 1 line
1.7.5.2
PATCH 1/3 ide: Split error status from status register
When adding the werror=stop mode, some flags were added to s->status which are used to determine what kind of operation should be restarted when the VM is continued.
Unfortunately, it turns out that s->status is in fact a device register and as such is visible to the guest (some of the abused bits are even writable for the guest).
For migration we keep on using the old VMState field (renamed to migration_compat_status) if the status register doesn't use any of the previously abused bits. If it does, we use a subsection with a clean copy of the status register.
The error status is always sent in a subsection if there is any error. It can't use the old field because errors happen even without PCI.
--- hw/ide/core.c | 28 +++++++++++++++++++- hw/ide/internal.h | 8 ++++++ hw/ide/pci.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++----- hw/ide/pci.h | 4 +++ 4 files changed, 105 insertions(+), 8 deletions(-)
hw/ide/core.c +27 -1
@@ -446,7 +446,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op)if ((error ==ENOSPC && action ==BLOCK_ERR_STOP_ENOSPC ) || action ==BLOCK_ERR_STOP_ANY ) { s->bus->dma->ops->set_unit (s->bus->dma, s->unit); - s->bus->dma->ops->add_status (s->bus->dma, op); + s->bus->error_status = op;bdrv_mon_event (s->bs,BDRV_ACTION_STOP , is_read);vm_stop (VMSTOP_DISKFULL ); }else {
@@ -1847,6 +1847,13 @@ static bool ide_atapi_gesn_needed(void *opaque)return s->events.new_media || s->events.eject_request; } +static bool ide_error_needed (void *opaque) +{ +IDEBus *bus = opaque; + +return (bus->error_status !=0 ); +} +/* Fields for GET_EVENT_STATUS_NOTIFICATION ATAPI command */ const VMStateDescription vmstate_ide_atapi_gesn_state = { .name ="ide_drive/atapi/gesn_state" ,
@@ -1921,6 +1928,17 @@ const VMStateDescription vmstate_ide_drive = { } }; +const VMStateDescription vmstate_ide_error_status = { + .name ="ide_bus/error" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_INT32 (error_status, IDEBus), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_ide_bus = { .name ="ide_bus" , .version_id =1 ,
@@ -1930,6 +1948,14 @@ const VMStateDescription vmstate_ide_bus = { VMSTATE_UINT8(cmd, IDEBus), VMSTATE_UINT8(unit, IDEBus),VMSTATE_END_OF_LIST () + }, + .subsections = (VMStateSubsection []) { + { + .vmsd = &vmstate_ide_error_status, + .needed = ide_error_needed, + }, { +/* empty */ + } } };
hw/ide/internal.h +8 -0
@@ -486,6 +486,8 @@ struct IDEBus {uint8_t unit;uint8_t cmd;qemu_irq irq; + +int error_status; };struct IDEDevice {
@@ -505,11 +507,17 @@ struct IDEDeviceInfo {#define BM_STATUS_DMAING 0x01#define BM_STATUS_ERROR 0x02#define BM_STATUS_INT 0x04 + +/* FIXME These are not status register bits */ #define BM_STATUS_DMA_RETRY 0x08#define BM_STATUS_PIO_RETRY 0x10#define BM_STATUS_RETRY_READ 0x20#define BM_STATUS_RETRY_FLUSH 0x40 +#define BM_MIGRATION_COMPAT_STATUS_BITS \ + (BM_STATUS_DMA_RETRY | BM_STATUS_PIO_RETRY | \ + BM_STATUS_RETRY_READ | BM_STATUS_RETRY_FLUSH) +#define BM_CMD_START 0x01#define BM_CMD_READ 0x08
hw/ide/pci.c +66 -7
127 lines not on this page · raw message
hw/ide/pci.h +4 -0
@@ -22,6 +22,10 @@ typedef struct BMDMAState {IORange addr_ioport;QEMUBH *bh;qemu_irq irq; + +/* Bit 0-2 and 7: BM status register +* Bit 3-6: bus->error_status */ +uint8_t migration_compat_status; } BMDMAState; typedef struct PCIIDEState {
Signature · 1 line
1.7.5.2
PATCH 2/3 ide: Fix ide_drive_pio_state_needed()
In reply to Kevin WolfWhen a failed PIO request caused the VM to stop, we still need to transfer the PIO state even though DRQ=0 at this point.
--- hw/ide/core.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
hw/ide/core.c +2 -1
@@ -1837,7 +1837,8 @@ static bool ide_drive_pio_state_needed(void *opaque) {IDEState *s = opaque; -return (s->status &DRQ_STAT ) !=0 ; +return ((s->status &DRQ_STAT ) !=0 ) + || (s->bus->error_status &BM_STATUS_PIO_RETRY ); }static bool ide_atapi_gesn_needed (void *opaque)
Signature · 1 line
1.7.5.2
PATCH 3/3 ide: Add forgotten VMSTATE_END_OF_LIST in subsection
In reply to Kevin Wolf--- hw/ide/core.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/ide/core.c +1 -0
@@ -1864,6 +1864,7 @@ const VMStateDescription vmstate_ide_atapi_gesn_state = { .fields = (VMStateField []) {VMSTATE_BOOL (events.new_media, IDEState),VMSTATE_BOOL (events.eject_request, IDEState), +VMSTATE_END_OF_LIST () } };
Signature · 1 line
1.7.5.2
Re: [Qemu-devel] [PATCH 1/3] ide: Split error status from status register
In reply to Kevin WolfQuoted 6 lines · Kevin Wolf
hw/ide/pci.c +6
-0+/* This function accesses bm->bus->error_status which is loaded only after +* BMDMA itself. This is why the function is called from ide_pci_post_load +* instead of being registered with VMState where it would run too early. */ +static int ide_bmdma_post_load (void *opaque,int version_id) +{ +BMDMAState *bm = opaque;
hw/ide/pci.c static bool ide_bmdma_current_needed(void *opaque) · line 396
Quoted 10 lines
hw/ide/pci.c +10
-0+uint8_t abused_bits =BM_MIGRATION_COMPAT_STATUS_BITS ; + +if (bm->status ==0 ) { + bm->status = bm->migration_compat_status& ~abused_bits; + bm->bus->error_status |= bm->migration_compat_status& abused_bits; + } + +return 0 ; +} +
Why the if?
Otherwise looks good.
Paolo
Re: [Qemu-devel] [PATCH 1/3] ide: Split error status from status register
Am 09.06.2011 15:27, schrieb Paolo Bonzini:
Quoted 11 lines · Kevin Wolf
Quoted 10 lines
hw/ide/pci.c +10
-0+/* This function accesses bm->bus->error_status which is loaded only after +* BMDMA itself. This is why the function is called from ide_pci_post_load +* instead of being registered with VMState where it would run too early. */ +static int ide_bmdma_post_load (void *opaque,int version_id) +{ +BMDMAState *bm = opaque; +uint8_t abused_bits =BM_MIGRATION_COMPAT_STATUS_BITS ; + +if (bm->status ==0 ) { + bm->status = bm->migration_compat_status& ~abused_bits;
Quoted 8 lines
hw/ide/pci.c static bool ide_bmdma_current_needed(void *opaque) · line 396
Quoted 6 lines
hw/ide/pci.c +6
-0+ bm->bus->error_status |= bm->migration_compat_status& abused_bits; + } + +return 0 ; +} +Why the if?
I think you're right. We could enable it unconditionally (and change the bm->status line from = to |=), but anyway it's redundant if the subsections are present, so it wouldn't make a difference.
Kevin
Re: [Qemu-devel] [PATCH 1/3] ide: Split error status from status register
Quoted 3 lines · Kevin Wolf
I think you're right. We could enable it unconditionally (and change the
bm->statusline from = to |=), but anyway it's redundant if the subsections are present, so it wouldn't make a difference.
Yes, I was thinking the same.
Paolo