Commit e162cfb07b7bee2d4527b860f13de39429733dfa
1 parent
6dc2d0da
Actually check read/write errors in IDE (Ian Jackson).
This patch makes the ide emulation actually take notice of
error returns from bdrv_write and bdrv_aio_{read,write}.
(Cherry picked from qemu-xen e0e7a0afe0e324a1f7d64c240f567b15dbe454cf,
first posted to qemu-devel Wed, 20 Feb 2008 15:26:41 +0000)
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5368 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
32 additions
and
2 deletions
hw/ide.c
| ... | ... | @@ -817,6 +817,11 @@ static void ide_set_sector(IDEState *s, int64_t sector_num) |
| 817 | 817 | } |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | +static void ide_rw_error(IDEState *s) { | |
| 821 | + ide_abort_command(s); | |
| 822 | + ide_set_irq(s); | |
| 823 | +} | |
| 824 | + | |
| 820 | 825 | static void ide_sector_read(IDEState *s) |
| 821 | 826 | { |
| 822 | 827 | int64_t sector_num; |
| ... | ... | @@ -836,6 +841,10 @@ static void ide_sector_read(IDEState *s) |
| 836 | 841 | if (n > s->req_nb_sectors) |
| 837 | 842 | n = s->req_nb_sectors; |
| 838 | 843 | ret = bdrv_read(s->bs, sector_num, s->io_buffer, n); |
| 844 | + if (ret != 0) { | |
| 845 | + ide_rw_error(s); | |
| 846 | + return; | |
| 847 | + } | |
| 839 | 848 | ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read); |
| 840 | 849 | ide_set_irq(s); |
| 841 | 850 | ide_set_sector(s, sector_num + n); |
| ... | ... | @@ -843,6 +852,14 @@ static void ide_sector_read(IDEState *s) |
| 843 | 852 | } |
| 844 | 853 | } |
| 845 | 854 | |
| 855 | +static void ide_dma_error(IDEState *s) | |
| 856 | +{ | |
| 857 | + ide_transfer_stop(s); | |
| 858 | + s->error = ABRT_ERR; | |
| 859 | + s->status = READY_STAT | ERR_STAT; | |
| 860 | + ide_set_irq(s); | |
| 861 | +} | |
| 862 | + | |
| 846 | 863 | /* return 0 if buffer completed */ |
| 847 | 864 | static int dma_buf_rw(BMDMAState *bm, int is_write) |
| 848 | 865 | { |
| ... | ... | @@ -891,7 +908,6 @@ static int dma_buf_rw(BMDMAState *bm, int is_write) |
| 891 | 908 | return 1; |
| 892 | 909 | } |
| 893 | 910 | |
| 894 | -/* XXX: handle errors */ | |
| 895 | 911 | static void ide_read_dma_cb(void *opaque, int ret) |
| 896 | 912 | { |
| 897 | 913 | BMDMAState *bm = opaque; |
| ... | ... | @@ -899,6 +915,11 @@ static void ide_read_dma_cb(void *opaque, int ret) |
| 899 | 915 | int n; |
| 900 | 916 | int64_t sector_num; |
| 901 | 917 | |
| 918 | + if (ret < 0) { | |
| 919 | + ide_dma_error(s); | |
| 920 | + return; | |
| 921 | + } | |
| 922 | + | |
| 902 | 923 | n = s->io_buffer_size >> 9; |
| 903 | 924 | sector_num = ide_get_sector(s); |
| 904 | 925 | if (n > 0) { |
| ... | ... | @@ -963,6 +984,11 @@ static void ide_sector_write(IDEState *s) |
| 963 | 984 | if (n > s->req_nb_sectors) |
| 964 | 985 | n = s->req_nb_sectors; |
| 965 | 986 | ret = bdrv_write(s->bs, sector_num, s->io_buffer, n); |
| 987 | + if (ret != 0) { | |
| 988 | + ide_rw_error(s); | |
| 989 | + return; | |
| 990 | + } | |
| 991 | + | |
| 966 | 992 | s->nsector -= n; |
| 967 | 993 | if (s->nsector == 0) { |
| 968 | 994 | /* no more sectors to write */ |
| ... | ... | @@ -992,7 +1018,6 @@ static void ide_sector_write(IDEState *s) |
| 992 | 1018 | } |
| 993 | 1019 | } |
| 994 | 1020 | |
| 995 | -/* XXX: handle errors */ | |
| 996 | 1021 | static void ide_write_dma_cb(void *opaque, int ret) |
| 997 | 1022 | { |
| 998 | 1023 | BMDMAState *bm = opaque; |
| ... | ... | @@ -1000,6 +1025,11 @@ static void ide_write_dma_cb(void *opaque, int ret) |
| 1000 | 1025 | int n; |
| 1001 | 1026 | int64_t sector_num; |
| 1002 | 1027 | |
| 1028 | + if (ret < 0) { | |
| 1029 | + ide_dma_error(s); | |
| 1030 | + return; | |
| 1031 | + } | |
| 1032 | + | |
| 1003 | 1033 | n = s->io_buffer_size >> 9; |
| 1004 | 1034 | sector_num = ide_get_sector(s); |
| 1005 | 1035 | if (n > 0) { | ... | ... |